<!doctype html>
<html class="no-js" lang="">

<head>
  <meta charset="utf-8">
  <title>Descargar Nota Electronica</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <style>
        *,
        *::before,
        *::after {
            box-sizing: border-box;
        }

        /**
        Use a more readable tab size (opinionated).
        */

        :root {
            -moz-tab-size: 4;
            tab-size: 4;
        }

        /**
        1. Correct the line height in all browsers.
        2. Prevent adjustments of font size after orientation changes in iOS.
        */

        html {
            line-height: 1.15; /* 1 */
            -webkit-text-size-adjust: 100%; /* 2 */
        }

        /*
        Sections
        ========
        */

        /**
        Remove the margin in all browsers.
        */

        body {
            margin: 0;
        }

        /**
        Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)
        */

        body {
            font-family:
                system-ui,
                -apple-system, /* Firefox supports this but not yet `system-ui` */
                'Segoe UI',
                Roboto,
                Helvetica,
                Arial,
                sans-serif,
                'Apple Color Emoji',
                'Segoe UI Emoji';
        }

        /*
        Grouping content
        ================
        */

        /**
        1. Add the correct height in Firefox.
        2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)
        */

        hr {
            height: 0; /* 1 */
            color: inherit; /* 2 */
        }

        /*
        Text-level semantics
        ====================
        */

        /**
        Add the correct text decoration in Chrome, Edge, and Safari.
        */

        abbr[title] {
            text-decoration: underline dotted;
        }

        /**
        Add the correct font weight in Edge and Safari.
        */

        b,
        strong {
            font-weight: bolder;
        }

        /**
        1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)
        2. Correct the odd 'em' font sizing in all browsers.
        */

        code,
        kbd,
        samp,
        pre {
            font-family:
                ui-monospace,
                SFMono-Regular,
                Consolas,
                'Liberation Mono',
                Menlo,
                monospace; /* 1 */
            font-size: 1em; /* 2 */
        }

        /**
        Add the correct font size in all browsers.
        */

        small {
            font-size: 80%;
        }

        /**
        Prevent 'sub' and 'sup' elements from affecting the line height in all browsers.
        */

        sub,
        sup {
            font-size: 75%;
            line-height: 0;
            position: relative;
            vertical-align: baseline;
        }

        sub {
            bottom: -0.25em;
        }

        sup {
            top: -0.5em;
        }

        /*
        Tabular data
        ============
        */

        /**
        1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)
        2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)
        */

        table {
            text-indent: 0; /* 1 */
            border-color: inherit; /* 2 */
        }

        /*
        Forms
        =====
        */

        /**
        1. Change the font styles in all browsers.
        2. Remove the margin in Firefox and Safari.
        */

        button,
        input,
        optgroup,
        select,
        textarea {
            font-family: inherit; /* 1 */
            font-size: 100%; /* 1 */
            line-height: 1.15; /* 1 */
            margin: 0; /* 2 */
        }

        /**
        Remove the inheritance of text transform in Edge and Firefox.
        1. Remove the inheritance of text transform in Firefox.
        */

        button,
        select { /* 1 */
            text-transform: none;
        }

        /**
        Correct the inability to style clickable types in iOS and Safari.
        */

        button,
        [type='button'],
        [type='reset'],
        [type='submit'] {
            -webkit-appearance: button;
        }

        /**
        Remove the inner border and padding in Firefox.
        */

        ::-moz-focus-inner {
            border-style: none;
            padding: 0;
        }

        /**
        Restore the focus styles unset by the previous rule.
        */

        :-moz-focusring {
            outline: 1px dotted ButtonText;
        }

        /**
        Remove the additional ':invalid' styles in Firefox.
        See: https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737
        */

        :-moz-ui-invalid {
            box-shadow: none;
        }

        /**
        Remove the padding so developers are not caught out when they zero out 'fieldset' elements in all browsers.
        */

        legend {
            padding: 0;
        }

        /**
        Add the correct vertical alignment in Chrome and Firefox.
        */

        progress {
            vertical-align: baseline;
        }

        /**
        Correct the cursor style of increment and decrement buttons in Safari.
        */

        ::-webkit-inner-spin-button,
        ::-webkit-outer-spin-button {
            height: auto;
        }

        /**
        1. Correct the odd appearance in Chrome and Safari.
        2. Correct the outline style in Safari.
        */

        [type='search'] {
            -webkit-appearance: textfield; /* 1 */
            outline-offset: -2px; /* 2 */
        }

        /**
        Remove the inner padding in Chrome and Safari on macOS.
        */

        ::-webkit-search-decoration {
            -webkit-appearance: none;
        }

        /**
        1. Correct the inability to style clickable types in iOS and Safari.
        2. Change font properties to 'inherit' in Safari.
        */

        ::-webkit-file-upload-button {
            -webkit-appearance: button; /* 1 */
            font: inherit; /* 2 */
        }

        /*
        Interactive
        ===========
        */

        /*
        Add the correct display in Chrome and Safari.
        */

        summary {
            display: list-item;
        }
            </style>
        <style>
            body {
        font-size: 13px;
        }

        table {
        width: 100%;
        border-collapse: collapse;
        }

        table tr td {
        padding: 0;
        }

        table tr td:last-child {
        text-align: right;
        }

        .bold {
        font-weight: bold;
        }

        .right {
        text-align: right;
        }

        .large {
        font-size: 1.2em;
        }

        .total {
        font-weight: bold;
        color: #fb7578;
        }

        .logo-container {
        margin: 20px 0 30px 0;
        }

        .invoice-info-container {
        font-size: 0.875em;
        }
        .invoice-info-container td {
        padding: 4px 0;
        }

        .client-name {
        font-size: 1.5em;
        vertical-align: top;
        }

        .line-items-container {
        margin: 15px 0;
        font-size: 0.875em;
        }

        .line-items-container th {
        text-align: left;
        color: #999;
        border-bottom: 2px solid #ddd;
        padding: 10px 0 15px 0;
        font-size: 0.75em;
        text-transform: uppercase;
        }

        .line-items-container th:last-child {
        text-align: right;
        }

        .line-items-container td {
        padding: 5px 0;
        }

        /* .line-items-container tbody tr:first-child td {
        padding-top: 10px;
        } */

        .line-items-container.has-bottom-border tbody tr:last-child td {
        padding-bottom: 25px;
        border-bottom: 2px solid #ddd;
        }

        .line-items-container.has-bottom-border {
        margin-bottom: 0;
        }

        .line-items-container th.heading-quantity {
        width: 50px;
        }
        .line-items-container th.heading-price {
        text-align: right;
        width: 100px;
        }
        .line-items-container th.heading-subtotal {
        width: 100px;
        }

        .payment-info {
        width: 38%;
        font-size: 1em;
        line-height: 1.5;
        text-transform: uppercase;
        }

        .footer {
        margin-top: 30px;
        }

        .footer-thanks {
        font-size: 1.125em;
        }

        .footer-thanks img {
        display: inline-block;
        position: relative;
        top: 1px;
        width: 16px;
        margin-right: 4px;
        }

        .footer-info {
        float: right;
        margin-top: 5px;
        font-size: 0.75em;
        color: #ccc;
        }

        .footer-info span {
        padding: 0 5px;
        color: black;
        }

        .footer-info span:last-child {
        padding-right: 0;
        }

        .page-container {
        display: none;
        }
        .page-break {
            page-break-after: always;
        }

        .number-clausulas{
            /* display: -webkit-inline-box;
            display: -webkit-box; */
        }
        .number-clausulas p{
            margin: 0;
            text-align: justify;
            font-size: 0.76rem; /*0.68rem*/;
        }
        .number-clausulas strong{
            float: left;
            font-size: 0.76rem; /*0.68rem*/;
        }
        .number-clausulas ul li{
            font-size: 0.76rem; /*0.68rem*/;
        }
        .place-date{
            text-align: right;
        }
        .place-date p{
            /* font-size: small; */
            font-size: 0.6rem;
        }
  </style>
</head>
<body>

<div class="web-container">

  <!-- See invoice.html! It is injected here... -->
  <div class="page-container">
    Page
    <span class="page"></span>
    of
    <span class="pages"></span>
  </div>

  <div class="logo-container">
    <table>
        <tbody>
            <tr>
                @php
                    $company = \App\Models\Company::first();
                @endphp

                <td style="padding: 0 !important;border-bottom:none;vertical-align:top;">
                    <strong>{{ $company->razon_social ?? 'Mi Empresa' }}</strong>
                    <br>
                    @if(!empty($company->razon_social_comercial))
                        <small>{{ $company->razon_social_comercial }}</small>
                        <br>
                    @endif
                    @if(!empty($company->n_document))
                        <small>RUC: {{ $company->n_document }}</small>
                        <br>
                    @endif
                    @if(!empty($company->address))
                        <small>{{ $company->address }}</small>
                        <br>
                    @endif
                    @if(!empty($company->phone))
                        <small>Tel: {{ $company->phone }}</small>
                        <br>
                    @endif
                    @if(!empty($company->email))
                        <small>{{ $company->email }}</small>
                    @endif
                </td>
                <td style="padding: 0 !important;border-bottom:none; text-align:right; vertical-align:top;">
                    N° {{$electronic_note->doc_nota == '07' ? 'NOTA DE CREDITO' : 'NOTA DE DEBITO'}}: <strong>#{{$electronic_note->n_operacion}}</strong>
                    <br>
                    <small>{{ $electronic_note->created_at->format('Y/m/d') }}</small>
                </td>
            </tr>
        </tbody>
    </table>
  </div>
  <div style="clear:both;"></div>
  <table class="invoice-info-container">
    <tr>
        <td>
            N° {{$electronic_note->doc_nota == '07' ? 'NOTA DE CREDITO' : 'NOTA DE DEBITO'}}: <strong>#{{$electronic_note->n_operacion}}</strong>
        </td>

        <td>
          FECHA DE EMISIÓN: {{$electronic_note->created_at->format("Y/m/d")}}
        </td>
    </tr>
    <div class="" style="display: block;width:100%;border:1px solid black;height:1px;"></div>
    <tr>
      <td class="">
        <b>Datos del cliente: </b>
        <br>
        <br>
        CLIENTE: {{$electronic_note->client->full_name}}
            <br>
            DEPART./PROVINCIA CLIENTE: <strong>{{$electronic_note->client->region}}/{{$electronic_note->client->provincia}}/{{$electronic_note->client->distrito}}</strong>
      </td>
      <td>
        {{$electronic_note->client->type_document}}:  {{$electronic_note->client->n_document}}
      </td>
    </tr>
    <tr>
        <td>TIPO CLIENTE: {{$electronic_note->client->type_client == 1 ? 'CLIENTE FINAL' : 'CLIENTE EMPRESA'}}</td>
        <td>TELÉFONO: {{$electronic_note->client->phone}}</td>
    </tr>
    <div class="" style="display: block;width:100%;border:1px solid black;height:1px;"></div>
    <tr>
        <td>
         RESPONSABLE: <strong> {{$electronic_note->user->name.' '.$electronic_note->user->surname}}</strong>
        </td>
        <td>
            TELÉFONO: {{$electronic_note->user->phone}}
        </td>
    </tr>

  </table>

  <table class="line-items-container">
    <thead>
      <tr>
        <th class="heading-quantity">Qty</th>
        <th class="heading-description">Descripción</th>
        <th class="heading-price">Precio Final</th>
        <th class="heading-price">Subtotal</th>
      </tr>
    </thead>
    <tbody>
        @foreach ($electronic_note->details as $detail)
            <tr>
                <td>{{$detail->quantity}}</td>
                <td>
                    {{$detail->product->title}}<br>
                    Categoria: {{$detail->product->categorie->name}}<br>
                    Descripción: {{$detail->description}}
                </td>
                <td class="right"> {{$electronic_note->currency}} {{$detail->price_final}}</td>
                <td class="right"> {{$electronic_note->currency}} {{$detail->subtotal}}</td>
                {{-- [11].includes(sale_detail.tip_afe_igv) == 0 --}}
            </tr>
        @endforeach
    </tbody>
  </table>


  <table class="line-items-container has-bottom-border">
    <thead>
      <tr>
        <th>Tipo de Nota</th>
        <th>Fecha Emisión</th>
        <th>Información de Pago</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="payment-info">
            @php
                $type_nota = "";
                if($electronic_note->doc_nota == '07'){
                    switch ($electronic_note->type_nota) {
                        case '01':
                            $type_nota = "Anulación de la operación";
                            break;
                        case '02':
                            $type_nota = "Anulación por error en el RUC";
                            break;
                        case '03':
                            $type_nota = "Corrección por error en la descripción";
                            break;
                        case '04':
                            $type_nota = "Descuento global";
                            break;
                        case '05':
                            $type_nota = "Descuento por ítem";
                            break;
                        case '06':
                            $type_nota = "Devolución total";
                            break;
                        case '07':
                            $type_nota = "Devolución por ítem";
                            break;
                        case '12':
                            $type_nota = "Ajustes afectos al IVAP";
                            break;
                        default:
                            # code...
                            break;
                    }
                }else{
                    switch ($electronic_note->type_nota) {
                        case '01':
                            $type_nota = "Intereses por mora";
                            break;
                        case '02':
                            $type_nota = "Aumento en el valor";
                            break;
                        case '03':
                            $type_nota = "Penalidades/ otros conceptos";
                            break;
                        default:
                            # code...
                            break;
                    }
                }

            @endphp
            {{$type_nota}}
        </td>
        <td class="large">{{$electronic_note->created_at ? Carbon\Carbon::parse($electronic_note->created_at)->format("Y/m/d h:i A") : NULL}}</td>
        @php
            $discount_global_general = 0;
            if($electronic_note->discount_global){
                $discount_global_general += $electronic_note->discount_global;
            }
            if($electronic_note->amount_anticipo){
                $discount_global_general += $electronic_note->amount_anticipo;
            }
            $calc_enable = true;
            if($electronic_note->doc_nota == '08' && $electronic_note->type_nota != '02'){
                $calc_enable = false;
            }
            $retencion_total = 0;$percepcion_total = 0;
            if($calc_enable){
                if ($electronic_note->retencion_igv == 3) {
                    $percepcion_total = round(($electronic_note->total * 0.04),2);  
                }
                switch ($electronic_note->retencion_igv) {
                    case 1://Retención
                        $retencion_total = round(($electronic_note->total * 0.03),2);
                        break;
                    case 2://Detracción
                        $retencion_total = round(($electronic_note->total * 0.04),2);
                        break;
                    // case 3://Percepción
                    //     $retencion_total = round(($sale->total * 0.04),2);  
                    //     break;    
                    default:
                        break;
                }
            }

            $icbper_total = $electronic_note->details->sum('icbper');
            $isc_total = $electronic_note->details->sum('isc');

            $getTotalSales = ($electronic_note->total + $icbper_total + $isc_total + $percepcion_total) - ($discount_global_general + $electronic_note->igv_discount_general + $retencion_total);
            
            $getSubTotalSale = $electronic_note->subtotal - $discount_global_general;

            // $IGV_PERCEPCION = 0;
            // if($electronic_note->retencion_igv == 3 && $retencion_total > 0){
            //     $IGV_PERCEPCION = round($retencion_total*0.18,2);
            // }
            $getIgvTotal = $electronic_note->igv - $electronic_note->igv_discount_general; //- $IGV_PERCEPCION;
        @endphp
        <td class="payment-info">
            <div class="large total">
                DESCUENTO: - {{$electronic_note->currency}} {{$electronic_note->discount + $electronic_note->discount_global}}
                <br>
                @if ($electronic_note->amount_anticipo > 0)
                    ANTICIPO: - {{$electronic_note->currency}} {{$electronic_note->amount_anticipo}}
                    <br>
                @endif
                SUBTOTAL: {{$electronic_note->currency}} {{$getSubTotalSale}}
                @if ($isc_total > 0)
                    <br>
                    ISC: {{$electronic_note->currency}} {{$isc_total}}
                @endif
                <br>
                IGV: {{$electronic_note->currency}} {{$getIgvTotal}}
                <br>
                TOTAL: {{$electronic_note->currency}} {{ $getTotalSales}}
            </div>
            @switch($calc_enable && $electronic_note->retencion_igv)
                @case(1)
                    <div>
                        RETENCIÓN: <strong>{{$electronic_note->currency}} {{round(($electronic_note->total * 0.03),2)}} </strong>
                    </div>
                    @break
                @case(2)
                    <div>
                        DETRACCIÓN: <strong>{{$electronic_note->currency}} {{round(($electronic_note->total * 0.04),2)}} </strong>
                    </div>
                    @break
                @case(3)
                    <div>
                        PERCEPCIÓN: <strong>{{$electronic_note->currency}} {{round(($electronic_note->total * 0.04),2)}} </strong>
                    </div>
                    @break
                @default
                    
            @endswitch
            @if ($icbper_total > 0)
            <div>
                ICPER: <strong>{{$electronic_note->currency}} {{round($icbper_total,2)}}</strong>
            </div>
            @endif
            <div>
              ADELANTADO: <strong>{{$electronic_note->currency}} {{$electronic_note->paid_out}}</strong>
            </div>
            <div>
              SALDO: <strong>{{$electronic_note->currency}} {{$electronic_note->debt}}</strong>
            </div>
        </td>
    </tbody>
  </table>

    <div class="footer">
        <div class="footer-info">
            <span> DESCRIPCIÓN MOTIVO: {{$electronic_note->description_motivo}} </span>
        </div>
    </div>

</div>


</body></html>
