<div class="container" id="appCarritoVer" v-cloak>
    <input type="hidden" value="2" id="modulo">
    <input type="hidden" value="<?= $cliente['cli_id'] ?>" id="id_cliente_fac">
    <input type="hidden" value="<?= $factura['fm_id'] ?>" id="id_fac">
    <input type="hidden" id="ruta_documento" value="facturacioncajaeditar">
    <div class="page-inner">
        <div class="row">
            <div class="col">
                <div class="d-flex justify-content-between">
                    <div class="col-5 pl-0 row-card-no-pd mr-3" style="margin-bottom: 0; padding-top: 0; padding-bottom: 0">
                        <div class="list-group list-group-messages list-group-flush">
                            <div class="list-group-item unread">
                                <div class="list-group-item-figure">
                                    <div class="avatar">
                                        <span class="avatar-title rounded-circle border border-white bg-info"><?= strtoupper($cliente['cli_razon_social'][0]); ?></span>
                                    </div>
                                </div>
                                <div class="list-group-item-body pl-3 pl-md-4">
                                    <div class="row">
                                        <div class="col-12 col-lg-10">
                                            <h4 class="list-group-item-title">
                                                <span id="cabecera_cliente"><?= $cliente['cli_razon_social'] ?> <?= $cliente['cli_dni'] ?></span>
                                                <a href="#" data-toggle="modal" data-target="#modal_buscar_cliente_generico"><span class="fa fa-edit"></span></a>
                                                <span title="<?= ($factura['fm_descontado']) ? 'DESCONTADA' : 'SIN DESCONTAR'  ?>" class="fa-2x <?= ($factura['fm_descontado']) ? 'fas fa-cart-arrow-down' : 'fas fa-shopping-cart' ?>"></span>
                                            </h4>
                                        </div>
                                        <div class="col-12 col-lg-10">
                                            <h5 class="list-group-item-title text-warning">
                                                VENTAS - FACTURA
                                                <div class="<?= ($doc_pendientes > 1) ? 'text-danger' : 'text-dark' ?>">
                                                    <small>Pendientes: <?= $doc_pendientes ?></small>
                                                    <?php if ($cliente['grup_id']) : ?>
                                                        <small> Venta Al <?= $cliente['grup_nombre'] ?> <?= $cliente['grup_descuento'] ?>%</small>
                                                    <?php endif; ?>
                                                </div>
                                            </h5>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-7 p-0">
                        <div class="row">
                            <div class="col">
                                <div class="form-group">
                                    <label for="fecha">Fecha</label>
                                    <input type="date" id="fecha" class="form-control" value="<?= date('Y-m-d', strtotime($factura['fm_fecha'])) ?>" disabled>
                                </div>
                            </div>
                            <div class="col">
                                <div class="form-group">
                                    <label for="almacen">Almacén</label>
                                    <select id="almacen" v-model="almacen_predeterminado" class="form-control" disabled>
                                        <option disabled value="">Seleccione un elemento</option>
                                        <?php foreach ($almacenes as $row) : ?>
                                            <option value="<?= $row['alm_id'] ?>" <?= ($factura['fm_almid'] == $row['alm_id']) ? 'selected' : '' ?>><?= $row['alm_nombre'] ?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="col">
                                <div class="form-group">
                                    <label for="divisa">Divisa</label>
                                    <select id="divisa" class="form-control" disabled>
                                        <option value="div_nombre_master">{{ div_nombre_master }}</option>
                                    </select>
                                </div>
                            </div>
                            <div class="col">
                                <div class="form-group">
                                    <label for="serie">Serie</label>
                                    <select id="serie" v-model="serie_predeterminada" class="form-control form-control" disabled>
                                        <option disabled value="">Seleccione un elemento</option>
                                        <?php foreach ($series as $row) : ?>
                                            <option value="<?= $row['ser_id'] ?>"><?= $row['ser_descripcion'] ?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-12 mt-3">
                <nav>
                    <div class="nav nav-tabs" role="tablist">
                        <a class="nav-item nav-link active" data-toggle="tab" href="#nav-lista" role="tab" aria-controls="nav-home" aria-selected="true">Factura <span class="badge badge-info ml-2"> #<?= $factura['fm_correlativo'] ?></span></a>
                        <?php if ($per_pagar) : ?>
                            <a class="nav-item nav-link" data-toggle="tab" href="#nav-pagos" role="tab" aria-controls="nav-pagos" aria-selected="false"><i class="fas fa-file-invoice-dollar"></i> Pagos</a>
                        <?php endif; ?>
                        <a class="nav-item nav-link" data-toggle="tab" href="#nav-rutadocumento" role="tab" aria-controls="nav-rutadocumento" aria-selected="false"><i class="flaticon-stopwatch"></i> Historial</a>
                    </div>
                </nav>
                <div class="tab-content mt-2">
                    <div class="tab-pane fade show active" id="nav-lista" role="tabpanel" aria-labelledby="nav-home-tab">
                        <div class="row row-card-no-pd">
                            <div class="col-12 mt-2 mb-2">
                                <div class="d-flex justify-content-end">
                                    <a class="btn btn-info btn-round btn-border btn-sm mr-2" href="<?= url('ventascaja') ?>" target="_blank" style="max-height: 2rem;"><i class="fas fa-reply"></i> Ventas</a>
                                    <button type="button" class="btn btn-info btn-round btn-border btn-sm mr-2" @click="modalImprimir" style="max-height: 2rem;"><i class="fa fa-print"></i> Imprimir</button>
                                    <button type="button" class="btn btn-info btn-round btn-sm mr-2" disabled style="max-height: 2rem;">Guardar</button>
                                    <?php if ($anular_doc) : ?>
                                        <button type="button" class="btn btn-danger btn-round btn-sm mr-2" @click="modalAnular" style="max-height: 2rem;">Anular</button>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <div class="col-6">
                            </div>
                            <div class="col-12 mt-2">
                                <div class="scroll" style="height: 300px;width: 100%;padding: 0;margin: 0;overflow-y: scroll;overflow-x: hidden;">
                                    <div class="table-responsive">
                                        <table class="bg-white table-bordered-bd-black" cellspacing="1" cellpadding="1" width="100%" tabindex="2">
                                            <thead>
                                                <tr class="text-center">
                                                    <th>Código</th>
                                                    <th>Descripción</th>
                                                    <th>Precio</th>
                                                    <th>Cantidad</th>
                                                    <th>Dto. %</th>
                                                    <th>Neto</th>
                                                    <th>IVA</th>
                                                    <th>Total</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr v-for="row in carrito" class="text-right">
                                                    <td width="8%" class="text-center">{{ row.codigo }}</td>
                                                    <td class="text-left" style="padding-left:5px;">{{ row.nombre }}</td>
                                                    <td width="13%">{{ moneda(row.precio, money.locale, money.prefix, money.precision) }}</td>
                                                    <td width="7%">{{ row.cantidad }}</td>
                                                    <td width="7%">{{ row.descuento }}</td>
                                                    <td width="12%">{{ moneda(row.neto, money.locale, money.prefix, money.precision) }}</td>
                                                    <td width="7%">
                                                        <select id="impuestos" class="form-control text-center input-border-bottom" v-model="row.id_iva" disabled>
                                                            <?php foreach ($impuestos as $row) : ?>
                                                                <option value="<?= $row['imp_id'] ?>"><?= $row['imp_descripcion'] ?></option>
                                                            <?php endforeach; ?>
                                                        </select>
                                                    </td>
                                                    <td width="12%" class="text-right">{{ moneda(row.total, money.locale, money.prefix, money.precision) }}</td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row row-card-no-pd">
                            <div class="col-12" style="padding-left: 30%;">
                                <div class="table-responsive ">
                                    <table class="bg-white table-bordered-bd-black" cellspacing="1" cellpadding="2" width="100%" tabindex="2">
                                        <thead>
                                            <tr class="text-center">
                                                <th>Subtotal</th>
                                                <th width="10%">Dto. %</th>
                                                <th>Neto</th>
                                                <th>IVA</th>
                                                <th>Total</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr class="text-right">
                                                <td width="20%">{{ moneda(subtotal, money.locale, money.prefix, money.precision) }}</td>
                                                <td width="20%">{{ descuento }}</td>
                                                <td width="20%">{{ moneda(neto, money.locale, money.prefix, money.precision) }}</td>
                                                <td width="20%">{{ iva }}</td>
                                                <td width="20%">{{ moneda(total, money.locale, money.prefix, money.precision) }}</td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="row mt-3 row-card-no-pd">
                            <div class="col">
                                <div class="form-group form-group-default">
                                    <label>Observaciones</label>
                                    <textarea class="form-control" rows="3" disabled><?= $factura['fm_observaciones'] ?></textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane" id="nav-pagos" role="tabpanel" aria-labelledby="nav-pagos-tab">
                        <div class="card">
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-sm-12">
                                        <?php if ($per_pagar) : ?>
                                            <div class="row d-flex justify-content-end ">
                                                <a class="btn btn-secondary btn-sm  btn-border btn-round mr-3" href="#" @click.prevent="modalCrearCredito">Crédito</a>
                                                <a class="btn btn-info btn-sm btn-round mr-3" href="#" @click.prevent="modalPagar">Pagar</a>
                                            </div>
                                        <?php endif; ?>
                                        <div class="table-responsive">
                                            <table class="table table-bordered table-bordered-bd-black mt-3">
                                                <thead>
                                                    <tr>
                                                        <th>Fecha</th>
                                                        <th>Divisa</th>
                                                        <th>Total</th>
                                                        <th>Restante</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <tr>
                                                        <td>{{ factura.fecha }}</td>
                                                        <td>{{ div_nombre_master }}</td>
                                                        <td>{{ moneda(total, money.locale, money.prefix, money.precision) }}</td>
                                                        <td>{{ moneda(restante_original, money.locale, money.prefix, money.precision) }}</td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                                <div class="table-responsive">
                                    <table class="table table-bordered table-bordered-bd-black mt-3">
                                        <thead>
                                            <tr>
                                                <th></th>
                                                <th>Fecha</th>
                                                <th>Cuenta</th>
                                                <th>Método</th>
                                                <th>Monto</th>
                                                <th>Factor</th>
                                                <th>Conversión</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr v-for="row in abonos" :class="[row.fab_retiro == 1 ? 'bg-danger': '', row.credito == '1' ? 'bg-secondary': '']">
                                                <td class="text-center">
                                                    <?php if ($eliminar_pago) : ?>
                                                        <a v-if="row.fab_retiro==0 && row.credito != '1'" href="#" @click.prevent="eliminarPago(row.fab_id)">
                                                            <i class="fa fa-trash text-danger"></i>
                                                        </a>
                                                    <?php endif; ?>
                                                </td>
                                                <td>{{ row.fab_fecha }}</td>
                                                <td>{{ row.bc_alias }} {{ row.bc_tipo }}</td>
                                                <td>{{ row.mp_nombre }}</td>
                                                <td>{{ row.fab_monto }}</td>
                                                <td>{{ row.fab_factor }}</td>
                                                <td>{{ row.fab_conversion }}</td>
                                            </tr>
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <th></th>
                                                <th></th>
                                                <th></th>
                                                <th></th>
                                                <th></th>
                                                <th class="text-right">Total</th>
                                                <th>{{ moneda(total_pagado, money.locale, money.prefix, money.precision) }}</th>
                                            </tr>
                                        </tfoot>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="tab-pane" id="nav-rutadocumento" role="tabpanel" aria-labelledby="nav-documentos">
                        <div class="card">
                            <div class="card-body">
                                <ul class="list-group">
                                    <li class="list-group-item">Creditos</li>
                                </ul>
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <th>Estatus</th>
                                            <th>Documento</th>
                                            <th>Fecha</th>
                                            <th>Monto</th>
                                            <th>Observaciones</th>
                                            <th>Imprimir</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr v-for="row in creditosFactura">
                                            <td>
                                                <i :title="row.estatus ? 'Finalizado' : 'Activo'" :class="row.estatus ? 'text-warning fas fa-info-circle' : 'text-success fas fa-check-circle'"></i>
                                            </td>
                                            <td>{{ row.correlativo }}</td>
                                            <td>{{ row.fecha }}</td>
                                            <td>{{ row.monto }}</td>
                                            <td>{{ row.observaciones }}</td>
                                            <td>
                                                <a href="" @click.prevent="modalImprimirCredito(row.id)" title="Imprimir"><i class="fas fa-print btn" style="padding: .65rem;"></i></a>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php if ($per_pagar) : ?>
        <?php include 'app/notasdeentregaeditar/vista/modalpagar.php'; ?>
    <?php endif; ?>
    <?php if ($anular_doc) : ?>
        <?php include 'app/notasdeentregaeditar/vista/modal_anular.php' ?>
    <?php endif; ?>
    <?php include 'app/poseditar/vista/modal_imprimir.php' ?>
    <?php include 'app/poseditar/vista/modal_imprimir_credito.php' ?>
    <?php include 'app/notasdeentregaeditar/vista/modal_nuevo_credito.php' ?>
</div>

<script src="<?= asset('assets/underscore-min.js') ?>"></script>
<script src="<?= asset('assets/vue-the-mask.js') ?>"></script>
<script src="<?= asset('assets/v-money.js') ?>"></script>
<script src="<?= asset('assetsvuejs/facturacioncaja/ver.js') ?>"></script>

<link rel="stylesheet" href="<?= asset('assets/vue-select.css') ?>">
<script src="<?= asset('assets/vue-select.js') ?>"></script>
<?php include 'app/notasdeentrega/vista/guardar_cambiar_cliente_editar.php' ?>
