{% extends "base.html.twig" %}

{% trans_default_domain 'core' %}

{% block actionheader %}

{% endblock %}

{% block searchform %}{% endblock %}

{% block body %}

    {{ form_start(form) }}

    <article class="invoice-like">

        <header id="invoice-like-title">
            {% block invoice_actions %}{% endblock %}
            {% block invoice_label %}{% endblock %}
        </header>
        <div class="box pad box-warning">

            <div class="box-header with-border">

                <div class="btn-group">

                    <a href="{{ path('guiaremision_index') }}" class="btn btn-app">
                        <i class="glyphicon glyphicon-list-alt"></i>
                        Listado
                    </a>
                    <a href="{{ path('guiaremision_add') }}" class="btn btn-app">
                        <i class="glyphicon glyphicon-file"></i>
                        Nuevo
                    </a>

                    <button type="button" class="btn btn-app" data-toggle="modal" data-target="#myModal"
                            onclick='verPdf("{{ path('guiaremision_show_pdf_preview',{ 'id': entity.id , 'slug': entity.slug}) }}")'>
                        <i class="fa fa-file-pdf-o"></i>Pdf
                    </button>

                    <button type="button" class="btn btn-app" onclick="imprimir('hola')">
                        <i class="fa fa-print"></i>Imprimir
                    </button>

                    {% if entity.autorizado == true %}
                        <a href="{{ path('guiaremision_download_xml', {'id': entity.id, 'slug': entity.slug}) }}" class="btn btn-app" name="Form-xml"><span
                                    class="fa fa-file-text"></span> XML
                        </a>
                    {% endif %}

                    {% if entity.anulado == false %}
                        {% include "Core/comprobguia.show.html.twig" with {'entity': entity} %}
                    {% endif %}

                    {#
                    REVISAR IMPORTANTE SHARA
                    <form action="{{ path('invoice_email', {'id': entity.id}) }}" method="post">
                        <input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
                        <button type="submit" class="btn btn-default btn-warning"><span
                                    class="glyphicon glyphicon-envelope"></span> {% trans %}show.email{% endtrans %}</button>
                    </form>
                    #}


                </div>

            </div>
            <div class="box-body">
                {% if entity.anulado %}
                    <div class="container-fluid">
                        <div class="row text-center">
                            <div class="col-md-12">
                                <h2 style="color: red">ANULADO EN EL SISTEMA WEB</h2>
                            </div>
                        </div>
                    </div>
                {% endif %}

                {% include "Core/emisor.show.html.twig" with {'entity': entity} %}

                <div class="row">
                    <div id="invoice-like-customer-data" class="col-md-12">

                        <h3>Guía Remisión</h3>

                        <div class="row">
                            <div class="col-md-3 clearfix">
                                <label>Serie:</label>
                                {{ entity.serie }}
                            </div>
                            <div class="col-md-3 clearfix">
                                <label>Número:</label>
                                {{ entity.label }}
                            </div>
                            <div class="col-md-3 clearfix">
                                <label>Fecha:</label>
                                {{ entity.issueDate |date("d/m/Y") }}
                            </div>

                        </div>
                        <div class="row">
                            <div class="col-md-6 clearfix">
                                <label>Transportista:</label>
                                {{ entity.transportistaName }}
                            </div>
                            <div class="col-md-6 clearfix">
                                <label>{% trans %}abstract_invoice.show.customer_identification{% endtrans %}:</label>
                                {{ entity.transportistaIdentification }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6 clearfix">
                                <label>Placa:</label>
                                {{ entity.transportistaPlaca|nl2br }}
                            </div>
                            <div class="col-md-6 clearfix">
                                <label>{% trans %}abstract_invoice.show.customer_email{% endtrans %}:</label>
                                {{ entity.transportistaEmail }}
                            </div>

                        </div>
                        <div class="row">
                            <div class="col-md-9 clearfix">
                                <label>Dirección Partida:</label>
                                {{ entity.direccionpPartida }}
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6 clearfix">
                                <label>Fecha Inicio:</label>
                                {{ entity.feciniTransporte |date("d/m/Y") }}
                            </div>
                            <div class="col-md-6 clearfix">
                                <label>Fecha final:</label>
                                {{ entity.fecfinTransporte |date("d/m/Y") }}
                            </div>
                        </div>
                    </div>

                </div>

                <div class="row">
                    <div class="col-md-12">

                        <h3>Destinatarios</h3>

                        {% for item in entity.destinatarios %}
                            <div class="row">
                                <div class="col-md-6 clearfix">
                                    <label>Nombre:</label>
                                    {{ item.customername }}
                                </div>
                                <div class="col-md-6 clearfix">
                                    <label>Identificación</label>
                                    {{ item.customerIdentification }}
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-4 clearfix">
                                    <label>Dirección Destino:</label>
                                    {{ item.dirdestino }}
                                </div>
                                <div class="col-md-4 clearfix">
                                    <label>Motivo Traslado</label>
                                    {{ item.motivotraslado }}
                                </div>
                                <div class="col-md-4 clearfix">
                                    <label>Ruta</label>
                                    {{ item.ruta }}
                                </div>
                            </div>

                        <table id="invoice-like-items" class="table table-condensed table-striped align-middle">
                            <thead>
                            <tr>
                                <th class="">Descripción</th>
                                <th class="col-md-1 cell-align-center">{% trans %}item.show.quantity{% endtrans %}</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for itemguia in item.items %}
                                <tr>
                                    <td>
                                        {{ itemguia.description }}
                                    </td>
                                    <td class="cell-align-center">
                                        {{ itemguia.quantity }}
                                    </td>

                                </tr>

                            {% endfor %}
                            </tbody>
                        </table>
                        {% endfor %}

                    </div>
                </div>

                <div id="invoice-like-notes" class="row">

                    <div class="col-md-12" style="word-wrap: break-word;">
                        <label>{% trans %}abstract_invoice.show.notes{% endtrans %}:</label>
                        <p>{{ entity.notes|nl2br }}</p>
                    </div>
                </div>

                <div id="invoice-like-notes" class="row">

                    <div class="col-md-12" style="word-wrap: break-word;">
                        <label>Observación:</label>
                        <p>{{ entity.note1|nl2br }}</p>
                    </div>
                </div>

                <div class="entity-actions clearfix">
                    {% block invoice_edit_actions %}{% endblock %}
                </div>

            </div>
        </div>
    </article>

    {% include "Core/email.show.html.twig" with {'entity': entity} %}

    {{ form_rest(form) }}
    {{ form_end(form) }}

    <form method="get" action="#" id="printJS-form">
        <div id="myDiv" style="display: none">


            <h3>Factura</h3>

            <div class="row">
                Numero: {{ entity.serie }} - {{ entity.label }}
            </div>
            <div class="row">
                Fecha: {{ entity.issueDate |date("d/m/Y") }}
            </div>
            <div class="row">
                Cliente: {{ entity.transportistaName }}
            </div>
            <div class="row">
                RUC / Cédula: {{ entity.transportistaIdentification }}
            </div>
            <div class="row">
                Placa: {{ entity.transportistaPlaca }}
            </div>
            <div class="row">
                Email: {{ entity.transportistaEmail }}
            </div>
            <div class="row">
                Clave acceso: {{ entity.claveAcceso }}
            </div>

            <div class="row">

                <table id="invoice-like-items" class="col-md-5">
                    <thead>
                    <tr>
                        <th class="">{% trans %}item.show.description{% endtrans %}</th>
                        <th class="col-sd-1 cell-align-center">{% trans %}item.show.quantity{% endtrans %}</th>
                        <th class="col-sd-2 cell-align-right">{% trans %}item.show.unitary_cost{% endtrans %}</th>
                        <th class="col-sd-2 cell-align-right">{% trans %}item.show.discount{% endtrans %}</th>
                        {# <th class="col-md-1 cell-align-center">{% trans %}item.show.taxes{% endtrans %}</th>#}
                        <th colspan="2" class="cell-align-right">{% trans %}item.show.total{% endtrans %}</th>
                    </tr>
                    </thead>
                    <tbody>
                    {#{% for item in entity.destinatarios %}
                        {{ include('GuiaRemision/Item/show.html.twig', { 'item': item, 'currency': currency }) }}
                    {% endfor %}#}
                    </tbody>
                </table>

            </div>

        </div>
    </form>

    <script>

        function PrintDiv(id) {
            var data = document.getElementById(id).innerHTML;
            var myWindow = window.open('', 'my div', 'height=400,width=600');
            myWindow.document.write('<html><head><title>my div</title>');
            /*optional stylesheet*/ //myWindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
            myWindow.document.write('</head><body >');
            myWindow.document.write(data);
            myWindow.document.write('</body></html>');
            myWindow.document.close(); // necessary for IE >= 10

            myWindow.onload = function () { // necessary if the div contain images

                myWindow.focus(); // necessary for IE >= 10
                myWindow.print();
                myWindow.close();
            };
        }


        function imprimir(pdf_url) {


            //e.preventDefault(); // if you have a URL in the link
            $("#myDiv").show();// and $("#dv1").hide();
            printJS({printable: 'printJS-form', type: 'html', style: '.rowtotal { left: 200px; position: relative; }' })
            $("#myDiv").hide();
            //window.print();

            /*$("#pdfFrame").contents().find("body").html("");
            */
/*
            var settings = {
                "url": "http://localhost:8087/jsonprint",
                "method": "POST",
                "timeout": 0,
                "headers": {
                    "Content-Type": "application/json",
                    "Accept": "application/json",
                    "Access-Control-Allow-Origin": "*",
                    "Access-Control-Allow-Methods": "GET,POST,PUT,DELETE,OPTIONS",
                    "Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With",
                    "Access-Control-Allow-Credentials": "true"
                },
                "data": "{ 'email': 'james@example.com', 'nombre': 'nombre cliente', 'fecha': '01/07/2022', 'ruc': '1234578962', 'Active': true, 'CreatedDate': '2013-01-20T00:00:00Z', 'items': [ {'descripcion': 'james@example.com','cantidad': '1.00','unitario': '89.788'}, {'descripcion': 'james@example.com','cantidad': '1.00','unitario': '89.788'} ], 'basedoce': '12.58', 'basecero': '2.68', 'iva': '0.12', 'descuento': '1.00', 'total': '25.89', 'subtotal': '25.87' }",
            };

            $.ajax(settings).done(function (response) {
                alert(response);
            });
*/

           /* let url = "http://localhost:8087/jsonprint";
            $.ajax({
                type: "POST",
                url: url,
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                data: "{ 'email': 'james@example.com', 'nombre': 'nombre cliente', 'fecha': '01/07/2022', 'ruc': '1234578962', 'Active': true, 'CreatedDate': '2013-01-20T00:00:00Z', 'items': [ {'descripcion': 'james@example.com','cantidad': '1.00','unitario': '89.788'}, {'descripcion': 'james@example.com','cantidad': '1.00','unitario': '89.788'} ], 'basedoce': '12.58', 'basecero': '2.68', 'iva': '0.12', 'descuento': '1.00', 'total': '25.89', 'subtotal': '25.87' }",
                success: function (data) {
                    if(data.error === true)
                        alert(data.message);
                    else
                        console.log(data.message);
                },
                error: function (ui) {
                    console.log(data.responseText);
                },
                async: true,
                beforeSend: function () {
                    //$body.addClass("loading");
                },
                complete: function () {

                },
            });

*/

        };




    </script>



{% endblock %}

