{% extends 'VGMWOBundle::layout.html.twig' %}

{% block stylesheets %}
    {{ parent() }}
    <link href="{{ asset('bundles/vgmwo/css/bootstrap-datetimepicker.css') }}" rel="stylesheet" media="screen">
    <link href="https://cdn.datatables.net/buttons/1.0.3/css/buttons.dataTables.min.css" rel="stylesheet" media="screen">
{% endblock %}
{% block content %}
    <div class="container">
        <div class="form-group container-fluid">
            <div class="row">
                {% block workorder_data %}
                    {% include "VGMWOBundle:WorkOrder/Show_parts:workorder_data.html.twig" %}
                {% endblock workorder_data %}
                {% block workorder_stocks %}
                    {% include "VGMWOBundle:WorkOrder/Show_parts:workorder_stocks.html.twig" %}
                {% endblock workorder_stocks %}
            </div>
        </div>
        <div class="row container-fluid text-right" style="margin-bottom: 3vmin;">
            {#<a class="btn btn-primary" href="#"
               data-bind="click: chosenwo().update_myself">
                Update
            </a>#}
            <a class="btn btn-primary" href="#"
               data-bind="click: chosenwo().update_myself_back">
                Update{# & <span class="glyphicon glyphicon-list"></span>#}
            </a>
            <a class="btn btn-warning" href="{{ path('workorders_consulting') }}">
                Cancel
            </a>
        </div>
    </div>
    <!-- Modals -->
    <!-- Stock Showing Wizard-->
    {% block stock_showing %}
        {% include "VGMWOBundle:WorkOrder/ModalPanels:modal_show_stock.html.twig" %}
    {% endblock stock_showing %}
    <!-- Saved Message-->
    <div class="modal fade bs-example-modal-lg"
         id="saved-message"
         tabindex="-1"
         role="dialog"
         aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span>
                        <span class="sr-only">Cancel</span>
                    </button>
                    <h4 class="modal-title">Success!!!</h4>
                </div>
                <div class="modal-body">
                    <div class="container-fluid"
                         style="padding: 0px;">
                        <div style="font-size: 18px;">
                            <p>All data have been saved successfully!</p>
                            <p class="text-muted">Todos los datos fueron guardados correctamente!</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {% block message %}{% include "VGMWOBundle:Menssage:message.html.twig" %}{% endblock message %}
    {% block stock_invoices_manager %}{% include "VGMWOBundle:WorkOrder/ModalPanels:modal_invoice_references.html.twig" %}{% endblock stock_invoices_manager %}
{% endblock %}

{% block javascripts %}
    {{ parent() }}
    <script type="text/javascript" src="{{ asset('bundles/vgmwo/js/bootstrap-datetimepicker.js') }}"></script>
    <script type="text/javascript" src="{{ asset('bundles/vgmwo/js/jquery/jquery.inputmask.js') }}"></script>
    <script type="text/javascript" src="{{ asset('bundles/vgmwo/js/customized/utils/knockout.plugins.js') }}"></script>
    <script type="text/javascript" src="{{ asset('bundles/vgmwo/js/customized/utils/message.modal.js') }}"></script>
    <script type="text/javascript" src="{{ asset('bundles/vgmwo/js/customized/utils/util.lists.js') }}"></script>
    <script type="text/javascript" src="{{ asset('bundles/vgmwo/js/customized/validations/OnChangeValidations.js') }}"></script>
    <script type="text/javascript" src="{{ asset('bundles/vgmwo/js/customized/WorkOrders/workorder.showing.js') }}"></script>
    <script type="text/javascript" HIDDEN="hidden">
        $(document).ready(function(){
            loadPageFeatures();
            $('#wo-number').on('change keyup', function() {var regex = /^([1-9][0-9]{0,3})$/gm;
                var sanitized = regex.test($(this).val()) ? $(this).val() : $(this).val().substr(0,$(this).val().length-1);
                $(this).val(sanitized);});
        });
        function go_home_list(){window.location.href="{{path('workorders_consulting')}}";}
        function get_workorder_support_id_url(){return "{{ path('get_wo_support_by_id') }}";}
        function get_search_4_stock_url(){return "{{ path('find_stocks4workorder') }}";}
        function get_workorder_check_existence_url(){return "{{ path('check_creating_exist') }}";}
        function get_workorder_update_url(){return "{{ path('update_workorder') }}";}
        function get_save_stock_url(){return "{{ path('save_stock') }}";}
        function get_workorder_obs_url(){return "{{ path('workorder_get_my_obs') }}";}
        function get_workorder_tasks_url(){return "{{ path('workorder_get_my_tasks') }}";}
        function get_workorder_stocks_url(){return "{{ path('workorder_get_my_stocks') }}";}
        function get_workorder_invoices_url(){return "{{ path('workorder_get_my_invoices') }}";}
        viewModel.LoadData = ko.dependentObservable(function() {
            {% if next_wo_number %}viewModel.current_wo_number_to_creation("{{next_wo_number}}");{% endif %}
            //Getting support data
            if(viewModel.chosenwo() == null){
                        {% if supervisors %}var tsups=[];{% for sup in supervisors %}tsups.push({id:"{{ sup.id }}",name:"{{ sup }}",code:"{{ sup.workercode }}"});{% endfor %}viewModel.supervisors(tsups);{% endif %}
                        {% if units %}var tunis=[];{% for unit in units %}tunis.push({id:"{{ unit.id }}",name: "{{ unit.name }}",fullname:"{{ unit }}"});{% endfor %}viewModel.units(tunis);{% endif %}
                        {% if equipments %}var teqts=[];{% for eqt in equipments %}teqts.push({id:"{{ eqt.id }}",name:"{{ eqt }}",code:"{{ eqt.code }}",multiple_wos:{% if eqt.multiplewos %}true{% else %}false{% endif %}});{% endfor %}viewModel.equipments(teqts);{% endif %}
                        {% if departments %}var tdeps=[];{% for dep in departments %}tdeps.push({id:"{{ dep.id }}",name:"{{ dep }}"});{% endfor %}viewModel.departments(tdeps);{% endif %}
                        {% if clients %}var tclients=[];{% for client in clients %}tclients.push({id:"{{ client.id }}",name:"{{ client }}"});{% endfor %}viewModel.clients(tclients);{% endif %}
                        {% if salest %}var ttsales=[];{% for tsale in salest %}ttsales.push({id:"{{ tsale.id }}",name:"{{ tsale.saletype }}"});{% endfor %}viewModel.t_sales(ttsales);{% endif %}
                        {% if workst %}var ttworks=[];{% for twork in workst %}ttworks.push({id:"{{ twork.id }}",name:"{{ twork.worktype }}"});{% endfor %}viewModel.t_works(ttworks);{% endif %}
                viewModel.stocks_status(["Current","Rented","Sold","Hold","Closed"]);
                viewModel.wo_status(["Current","Rented","Sold","Hold","Out","Closed"]);
                viewModel.task_status(["Canceled","Complete","Current","Hold"]);
                viewModel.chosenwo(new workorder("{{ entity.id }}", "{{ entity.getImageUrl() }}", "{{ entity.number }}",
                        "{{ entity.origin }}", "{{ entity.getEquipment() ? entity.getEquipment().id : null }}", "{{ entity.stockquantity }}",
                        "{{ entity.createdat ? entity.createdat|date("m/d/Y") : null }}",
                        "{{ entity.startedat ? entity.startedat|date("m/d/Y") : null }}",
                        "{{ entity.price ? entity.price : null }}", "{{ entity.deliverydate ? entity.deliverydate|date("m/d/Y") : null }}",
                        "{{ entity.readyat ? entity.readyat|date("m/d/Y") : null }}",
                        "{{ entity.getSupervisor() ? entity.getSupervisor().id : null }}",
                        "{{ entity.getClient() ? entity.getClient().id : null }}",
                        "{{ entity.getSaletype() ? entity.getSaletype().id : null }}",
                        "{{ entity.getWorktype() ? entity.getWorktype().id : null }}", "{{ entity.status }}",
                        null,
                        "{{ cost ? cost : null }}",
                        "{{ entity.xprice ? entity.xprice : null }}"));
                {% if entity.createdby %}viewModel.chosenwo().creator_id("{{ entity.createdby.id }}");viewModel.chosenwo().creator_name("{{ entity.createdby }}");{% endif %}
                {% if entity.obs|length > 0 %}viewModel.chosenwo().get_my_obs();{% endif %}{% if entity.stocksfull|length > 0 %}viewModel.chosenwo().get_my_stocks();{% endif %}
                {% if entity.invoicerefs|length > 0 %}viewModel.chosenwo().get_my_invoices();{% endif %}{% if entity.tasks|length > 0 %}viewModel.chosenwo().get_my_tasks();{% endif %}
            }}, viewModel);ko.applyBindings(viewModel, document.getElementById("content-body"));
    </script>{% endblock %}