<?php 
include ("../../_init.php"); 
$customer_id = isset($request->get['customer_id']) ? $request->get['customer_id'] : 0;
?>
<form class="form-horizontal" id="checkout-form" action="place_order.php">
  <input type="hidden" name="invoice-id" value="{{ invoiceId }}">
  <input type="hidden" name="customer-id" value="{{ customerId }}">
  <input type="hidden" name="salesman-id" value="{{ salesmanId }}">
  <input type="hidden" name="customer-mobile-number" value="{{ customerMobileNumber }}">
  <!-- pmethod-id = TIPO DE COMPROBANTE: 2=venta/factura, 12=remito -->
  <input type="hidden" name="pmethod-id" value="{{ pmethodId }}">
  <input type="hidden" name="is_installment_order" value="{{ isInstallmentOrder }}">
  <input type="hidden" name="qref" id="qRefInput" value="{{ qRef }}">

  <div class="bootbox-body">
    <div class="table-selection">
      
      <!-- Fila real con 3 columnas que suman 12 -->
    

        <!-- Col 2: pago / cheques / d�lares / dep�sito -->
        <div class="col-lg-8 col-md-8 col-sm-8 checkout-payment-option bootboox-container">
         
		  
		 
            <?php $inc = 0;foreach(get_pmethods() as $pmethod) :?>
              <a class="text-left list-group-item pmethod_item" id="pmethod_<?php echo $pmethod['pmethod_id']; ?>"
                 href="javascript:void(0)"
                 <?php echo $inc == 0 ? 'ng-init="selectPaymentMethod('.$pmethod['pmethod_id'].',\''.$pmethod['code_name'].'\')"' : null;?>
                 ng-click="selectPaymentMethod('<?php echo $pmethod['pmethod_id']; ?>', '<?php echo $pmethod['code_name']; ?>')"
                 onClick="return false;">
                <span class="fa fa-fw fa-angle-double-right"></span>
                <b><?php echo $pmethod['name']; ?>
                <?php if (strtolower($pmethod['code_name']) == 'credit'):
                  $customer_balance = get_customer_balance($customer_id); ?>
                  <span ng-init="customerBalance='<?php echo $customer_balance;?>'">
                    (<?php echo get_currency_symbol();?><?php echo currency_format($customer_balance);?>)
                  </span>
                <?php endif; ?></b>
              </a>
            <?php $inc++;endforeach; ?>
         

            <h4 ng-show="pmethodId" class="text-center title">
              <?php echo trans('text_pmethod'); ?>: <b>{{ pmethodName }}</b>
            </h4>

          

            <div class="input-group input-group-lg pmethod-field-wrapper">
              <span class="input-group-addon"><?php echo trans('text_pay_amount'); ?></span>
              <input id="paid-amount" class="form-control" type="text" name="paid-amount" ng-model="paidAmount"
                     onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"
                     onKeyUp="if(this.value<0){this.value='1';}" readonly>
            </div>

            <div class="mt-5">
              <div class="input-group input-group-xs pmethod-field-wrapper">
                <span class="input-group-addon hidden-sm"><span class="fa fa-pencil"></span></span>
                <input type="text" name="invoice-note" class="form-control invoice-note" value="{{ invoiceNote }}" placeholder="<?php echo trans('placeholder_note_here');?>">
              </div>

              <!-- CONTRAPARTIDA A CUENTA -->
              <div class="mt-5">
                <div class="input-group input-group-xs pmethod-field-wrapper">
                  <span class="input-group-addon hidden-sm">CONTRAPARTIDA A CUENTA</span>
                </div>
              </div>

              <table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <th><div align="left">Importe a cuenta en Pesos</div></th>
                  <td><input type="text" id="importe-acuentaPesos" name="importe-acuentaPesos" ng-model="importeacuentaPesos" class="form-control invoice-note" /></td>
               
                  <th><strong>Importe a cuenta en DOLARES U$</strong></th>
                  <td>
                    <input type="text" id="importe-acuenta" name="importe-acuenta"
                           class="form-control invoice-note"
                           value="{{ importeacuentaPesos < 1 ? importeacuentaPesos : importeacuentaPesos / cotizacionDolar | formatDecimal:4 }}"
                           readonly/>
                  </td>
               
                  <th><div align="left"><strong>Cotizacion de esta venta</strong></div></th>
                  <td>
                    <?php
                      $statement = db()->prepare("SELECT `taxrate`FROM `taxrates` WHERE `taxrate_id` = ?");
                      $statement->execute(array(6));
                      $source = $statement->fetch(PDO::FETCH_ASSOC);
                      $taxrate = $source['taxrate'];
                    ?>
                    <input type="text" id="cotizacion-dolar" name="cotizacion-dolar" ng-model="cotizacionDolar" class="form-control invoice-note" value="1">
                    <small>Dolar Oficial Hoy: <?php echo $taxrate; ?></small>
                  </td>
                </tr>
              </table>

              <!-- CAJA CHEQUE (din�mica con arrays) -->
              <div class="mt-5">
                <div class="input-group input-group-xs pmethod-field-wrapper">
                  <span class="input-group-addon hidden-sm">CAJA CHEQUE</span>
                </div>
              </div>
              <div class="table-responsive">
                <table id="tabla-cheques" class="table table-condensed" width="100%">
                  <thead>
                    <tr>
                      <th>#</th>
                      <th><?php echo trans('Numero de Cheque');?></th>
                      <th><?php echo trans('Fecha de emision');?></th>
                      <th>Fecha de cobro</th>
                      <th>CUIT</th>
                      <th>Tipo</th>
                      <th>Banco</th>
                      <th>Observaciones</th>
                      <th><?php echo trans('Importe Cheque');?></th>
                      <th></th>
                    </tr>
                  </thead>
                  <tbody id="cheques-body">
                    <tr>
                      <td>1</td>
                      <td><input name="numero-cheque[]" type="text" class="form-control invoice-note" placeholder="<?php echo trans('Numero de Cheque');?>"></td>
                      <td><input name="fecha-cheque[]" type="date" class="form-control invoice-note" placeholder="<?php echo trans('Fecha de emision');?>"></td>
                      <td><input name="fecha-pago-cheque[]" type="date" class="form-control invoice-note" placeholder="Fecha de cobro"></td>
                      <td><input name="cuit-cheque[]" type="text" class="form-control invoice-note" placeholder="CUIT"></td>
                      <td>
                        <select name="tipo-cheque[]" class="form-control invoice-note">
                          <option value="">--</option>
                          <option value="17">Echeq</option>
                          <option value="2">Fisico</option>
                        </select>
                      </td>
                      <td><input name="banco-cheque[]" type="text" class="form-control invoice-note" placeholder="Banco"></td>
                      <td><input name="observaciones-cheque[]" type="text" class="form-control invoice-note" placeholder="Observaciones"></td>
                      <td><input name="importe-cheque[]" type="text" class="form-control invoice-note" placeholder="<?php echo trans('Importe Cheque');?>"></td>
                      <td><button type="button" class="btn btn-xs btn-primary" onclick="agregarChequeFila()"><span class="fa fa-plus"></span></button></td>
                    </tr>
                  </tbody>
                </table>
              </div>

              <!-- CAJA PESOS -->
              <div class="mt-5">
                <div class="input-group input-group-xs pmethod-field-wrapper">
                  <span class="input-group-addon hidden-sm">CAJA PESOS MOSTRADOR</span>
                </div>
              </div>
              <table width="100%" border="0" cellspacing="0">
                <tr>
                  <th>IMPORTE MONEDA CORRIENTE PESOS</th>
                  <td>
                    <input type="text" id="importe-efectivo" name="importe-efectivo" ng-model="importePesos" class="form-control invoice-note" placeholder="Importe en Pesos (usar NEGATIVO para vuelto)" />
                  </td>
                </tr>
              </table>

              <!-- CAJA D�LAR -->
              <div class="mt-5">
                <div class="input-group input-group-xs pmethod-field-wrapper">
                  <span class="input-group-addon hidden-sm">CAJA MONEDA EXTRANJERA DOLAR</span>
                </div>
              </div>
              <table width="100%" border="0" cellspacing="0">
                <tr>
                  <th>IMPORTE MONEDA EXTRANJERA</th>
                  <td>
                    <input type="text" id="importe-dolar"  name="importe-dolar" ng-model="importeDolar" class="form-control invoice-note" placeholder="<?php echo trans('Importe en dolares');?>" />
                  </td>
               
                  <th>COTIZACION BILLETE</th>
                  <td>
                    <input type="text" id="cotizacion-billete" name="cotizacion-billete" ng-model="cotizacionBillete" class="form-control invoice-note" placeholder="<?php echo trans('Cotizacion Billete MExt');?>" />
                  </td>
                </tr>
              </table>
              <div class="mt-5">
                <button type="button" class="btn btn-link" onclick="autocompletarVuelto()">
                  Calcular vuelto en pesos (auto)
                </button>
              </div>

              <!-- DEP�SITO / TRANSFERENCIA -->
              <div class="mt-5">
                <div class="input-group input-group-xs pmethod-field-wrapper">
                  <span class="input-group-addon hidden-sm">Deposito o transferencias bancarias</span>
                </div>
              </div>
              <table width="100%" border="0" cellspacing="0">
                <tr>
                  <th>Caja deposito</th>
                  <td>
                    <input type="text" id="importe-deposito"  name="importe-deposito" ng-model="importedeposito" class="form-control invoice-note" placeholder="<?php echo trans('Importe del deposito');?>" />
                  </td>
                  <th>Numero de Transaccion</th>
                  <td>
                    <input type="text" id="numero-deposito"  name="numero-deposito" class="form-control invoice-note" placeholder="<?php echo trans('Numero de transaccion');?>" />
                  </td>
                </tr>
              </table>

              <!-- SALDO A FAVOR -->
              <div class="mt-5">
                <div class="input-group input-group-xs pmethod-field-wrapper">
                  
                  <input type="hidden" name="favor-cuenta" class="form-control invoice-note" value="" placeholder="<?php echo trans('Importe a favor a cuenta en pesos');?>">
                </div>
              </div>

              <div bind-html-compile="rawPaymentMethodHtml"></div>

              <?php if(INSTALLMENT && (user_group_id() == 1 || has_permission('access', 'create_installment'))):?>
                <h4 ng-show="isInstallmentOrder" class="text-center"><?php echo trans('title_installment_details'); ?></h4>
                <div ng-show="isInstallmentOrder" class="panel panel-default mt-5">
                  <div class="panel-body">
                    <div class="form-group">
                      <label for="installment_duration" class="col-sm-4 control-label"><?php echo trans('label_duration'); ?></label>
                      <div class="col-sm-6">
                        <input type="text" id="installment_duration" name="installment_duration"  ng-model="installmentDuration" class="form-control text-right" onclick="this.select();" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" onKeyUp="if(this.value<0){this.value='1';}">
                      </div>
                      <div class="col-sm-2"><i><?php echo trans('text_days'); ?></i></div>
                    </div>
                    <div class="form-group">
                      <label for="installment_interval_count" class="col-sm-4 control-label"><?php echo trans('label_interval'); ?></label>
                      <div class="col-sm-6">
                        <input type="text" id="installment_interval_count" name="installment_interval_count" ng-model="installmentIntervalCount" class="form-control text-right" onclick="this.select();" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" onKeyUp="if(this.value<0){this.value='1';}">
                      </div>
                      <div class="col-sm-2 text-left"><i><?php echo trans('text_days'); ?></i></div>
                    </div>
                    <div class="form-group">
                      <label for="installment_count" class="col-sm-4 control-label"><?php echo trans('label_total_installment'); ?></label>
                      <div class="col-sm-6">
                        <input type="text" id="installment_count" name="installment_count" value="{{ installmentDuration/installmentIntervalCount | formatDecimal:2 }}" class="form-control text-right" readonly>
                      </div>
                    </div>
                    <div class="form-group">
                      <label for="installment_interest_percentage" class="col-sm-4 control-label"><?php echo trans('label_interest_percentage'); ?></label>
                      <div class="col-sm-6">
                        <input type="text" id="installment_interest_percentage" name="installment_interest_percentage" ng-model="installmentInterestPercentage" class="form-control text-right" onclick="this.select();" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" onKeyUp="if(this.value<0){this.value='1';}">
                      </div>
                      <div class="col-sm-2">%</div>
                    </div>
                    <div class="form-group">
                      <label for="installment_interest_amount" class="col-sm-4 control-label"><?php echo trans('label_interest_amount'); ?></label>
                      <div class="col-sm-6">
                        <input type="text" id="installment_interest_amount" name="installment_interest_amount" value="{{ installmentInterestAmount | formatDecimal:2}}" class="form-control text-right" readonly>
                      </div>
                    </div>
                  </div>
                </div>
              <?php endif;?>

            </div>
        
        </div><!-- /col 2 -->

        <!-- Col 3: items del comprobante -->
        <div class="col-lg-4 col-md-4 col-sm-4 order-details bootboox-container">
          <div class="text-center"><h4><?php echo trans('text_order_details'); ?></h4></div>
          <div class="table-responsive" style="max-height:70vh; overflow:auto;">
            <table class="table table-bordered table-striped table-condensed">
              <tbody>
                <tr ng-repeat="items in itemArray">
                  <td class="text-center w-10">
                    <input type="hidden" name="product-item['{{ items.id }}'][p_type]" value="{{ items.pType }}">
                    <input type="hidden" name="product-item['{{ items.id }}'][item_id]" value="{{ items.id }}">
                    <input type="hidden" name="product-item['{{ items.id }}'][category_id]" value="{{ items.categoryId }}">
                    <input type="hidden" name="product-item['{{ items.id }}'][sup_id]" value="{{ items.supId }}">
                    <input type="hidden" name="product-item['{{ items.id }}'][item_name]" value="{{ items.name }}">
                    <input type="hidden" name="product-item['{{ items.id }}'][item_price]" value="{{ items.price  | formatDecimal:2 }}">
                    <input type="hidden" name="product-item['{{ items.id }}'][item_quantity]" value="{{ items.quantity }}">
                    <input type="hidden" name="product-item['{{ items.id }}'][item_total]" value="{{ items.subTotal  | formatDecimal:2 }}">
                    {{ $index+1 }}
                  </td>
                  <td class="w-70">{{ items.name }} (x{{ items.quantity }} {{ items.unitName }})</td>
                  <td class="text-right w-20">{{ items.subTotal  | formatDecimal:2 }}</td>
                </tr>
              </tbody>
              <tfoot>
                <tr>
                  <th class="text-right w-60" colspan="2"><?php echo trans('label_subtotal'); ?></th>
                  <input type="hidden" name="sub-total" value="{{ totalAmount }}">
                  <td class="text-right w-40">{{ totalAmount  | formatDecimal:2 }}</td>
                </tr>
                <tr>
                  <th class="text-right w-60"  colspan="2">
                    <?php echo trans('label_discount'); ?> {{ discountType  == 'percentage' ? '('+discountAmount+'%)' : '' }}
                  </th>
                  <input type="hidden" name="discount-type" value="{{ discountType }}">
                  <input type="hidden" name="discount-amount" value="{{ discountType  == 'percentage' ? _percentage(totalAmount, discountAmount) : discountAmount }}">
                  <td class="text-right w-40">{{ discountType  == 'percentage' ? (_percentage(totalAmount, discountAmount) | formatDecimal:2) : (discountAmount | formatDecimal:2) }}</td>
                </tr>
                <tr>
                  <th class="text-right w-60" colspan="2"><?php echo trans('label_order_tax'); ?></th>
                  <input type="hidden" name="tax-amount" value="{{ taxAmount }}">
                  <td class="text-right w-40">{{ taxAmount  | formatDecimal:2 }}</td>
                </tr>
                <tr>
                  <th class="text-right w-60"  colspan="2">
                    <?php echo trans('label_shipping_charge'); ?> {{ shippingType  == 'percentage' ? '('+shippingAmount+'%)' : '' }}
                  </th>
                  <input type="hidden" name="shipping-type" value="{{ shippingType }}">
                  <input type="hidden" name="shipping-amount" value="{{ shippingType  == 'percentage' ? _percentage(totalAmount, shippingAmount) : shippingAmount }}">
                  <td class="text-right w-40">{{ shippingType  == 'percentage' ? (_percentage(totalAmount, shippingAmount) | formatDecimal:2) : (shippingAmount | formatDecimal:2) }}</td>
                </tr>
                <tr>
                  <th class="text-right w-60"  colspan="2"><?php echo trans('label_others_charge'); ?></th>
                  <input type="hidden" name="others-charge" value="{{ othersCharge }}">
                  <td class="text-right w-40">{{ othersCharge | formatDecimal:2 }}</td>
                </tr>
                <?php if(INSTALLMENT):?>
                  <tr>
                    <th class="text-right w-60" colspan="2"><?php echo trans('label_interest_amount'); ?></th>
                    <td class="text-right w-40">{{ installmentInterestAmount  | formatDecimal:2 }}</td>
                  </tr>
                <?php endif;?>
                <tr>
                  <th class="text-right w-60" colspan="2"><?php echo trans('label_previous_due'); ?></th>
                  <input type="hidden" name="previous-due" value="{{ dueAmount }}">
                  <td class="text-right w-40">{{ dueAmount  | formatDecimal:2 }}</td>
                </tr>
                <tr>
                  <th class="text-right w-60" colspan="2">
                    <?php echo trans('label_payable_amount'); ?> <small>({{ totalItem }} items)</small>
                  </th>
                  <input type="hidden" name="payable-amount" value="{{ totalPayable }}">
                  <td class="text-right w-40">{{ totalPayable  | formatDecimal:2 }}</td>
                </tr>
                <tr>
                  <th class="text-right w-60" colspan="2"><?php echo trans('label_paid_amount'); ?></th>
                  <td class="text-right w-40">{{ paidAmount | formatDecimal:2 }}</td>
                </tr>
                <tr>
                  <th class="text-right w-60" colspan="2"><?php echo trans('label_due_amount'); ?></th>
                  <td class="text-right w-40">{{ totalPayable < paidAmount ? totalPayable : totalPayable - paidAmount | formatDecimal:2 }}</td>
                </tr>
                <tr>
                  <th class="text-right w-60" colspan="2"><?php echo trans('label_balance'); ?></th>
                  <td class="text-right w-40">{{ totalPayable < paidAmount ? paidAmount - totalPayable  : 0 | formatDecimal:2 }}</td>
                </tr>
                <tr>
                  <td colspan="3">
                    <div class="btn-group" role="group">
                      <a ng-hide="isInstallmentOrder" ng-click="checkoutWithFullPaid()" onClick="return false;" class="btn btn-success btn-md full-paid">
                        <span class="fa fa-fw fa-money"></span> <?php echo trans('Aceptar'); ?>
                      </a>
                    </div>
                  </td>
                </tr>
                <tr ng-show="invoiceNote"><td colspan="3">&nbsp;</td></tr>
                <tr ng-show="invoiceNote" class="active">
                  <td colspan="3"><b><?php echo trans('label_note'); ?>:</b> {{ invoiceNote }}</td>
                </tr>
              </tfoot>
            </table>
          </div>
        </div><!-- /col 3 -->

      </div><!-- /row -->
    </div>
  </div>
</form>

<script>
// Advertencia por qref
setTimeout(function() {
  var qRefValue = document.getElementById('qRefInput').value;
  document.getElementById('advertencia').style.display = (qRefValue != 0) ? 'block' : 'none';
}, 100);

// Utils num�ricos
function toNum(v) {
  if (v === null || v === undefined) return 0;
  if (typeof v !== 'string') v = String(v);
  v = v.replace(/\s+/g,'').replace(',', '.');
  var n = parseFloat(v);
  return isNaN(n) ? 0 : n;
}

// Agregar/eliminar filas de cheques
function agregarChequeFila() {
  var tbody = document.getElementById('cheques-body');
  var idx = tbody.rows.length + 1;
  var tr = document.createElement('tr');
  tr.innerHTML =
    '<td>'+idx+'</td>'+
    '<td><input name="numero-cheque[]" type="text" class="form-control invoice-note" placeholder="<?php echo trans('Numero de Cheque');?>"></td>'+
    '<td><input name="fecha-cheque[]" type="date" class="form-control invoice-note" placeholder="<?php echo trans('Fecha de emision');?>"></td>'+
    '<td><input name="fecha-pago-cheque[]" type="date" class="form-control invoice-note" placeholder="Fecha de cobro"></td>'+
    '<td><input name="cuit-cheque[]" type="text" class="form-control invoice-note" placeholder="CUIT"></td>'+
    '<td><select name="tipo-cheque[]" class="form-control invoice-note">'+
        '<option value="">--</option>'+
        '<option value="16">Echeq</option>'+
        '<option value="2">Fisico</option>'+
        
      '</select></td>'+
    '<td><input name="banco-cheque[]" type="text" class="form-control invoice-note" placeholder="Banco"></td>'+
    '<td><input name="observaciones-cheque[]" type="text" class="form-control invoice-note" placeholder="Observaciones"></td>'+
    '<td><input name="importe-cheque[]" type="text" class="form-control invoice-note" placeholder="<?php echo trans('Importe Cheque');?>"></td>'+
    '<td><button type="button" class="btn btn-xs btn-danger" onclick="eliminarChequeFila(this)"><span class="fa fa-trash"></span></button></td>';
  tbody.appendChild(tr);
}
function eliminarChequeFila(btn) {
  var tr = btn.closest('tr');
  tr.parentNode.removeChild(tr);
  var rows = document.querySelectorAll('#cheques-body tr');
  rows.forEach(function(r, i){ r.cells[0].innerText = (i+1); });
}

// Vuelto autom�tico (efectivo puede ser NEGATIVO)
function autocompletarVuelto(){
  var form   = document.getElementById('checkout-form');
  var total  = toNum(form.querySelector('input[name="payable-amount"]').value);
  var usd    = toNum(document.getElementById('importe-dolar').value);
  var cotBil = toNum(document.getElementById('cotizacion-billete').value);
  var dep    = toNum(document.getElementById('importe-deposito').value);
  var acuUSD = toNum(document.getElementById('importe-acuenta').value);
  var cot    = toNum(document.getElementById('cotizacion-dolar').value);
  var cheqs  = document.getElementsByName('importe-cheque[]'); var sumCh=0;
  for (var i=0;i<cheqs.length;i++) sumCh+=toNum(cheqs[i].value);
  var sinEfectivo = sumCh + dep + (usd*cotBil) + (acuUSD*cot);
  var vuelto = total - sinEfectivo;
  document.getElementById('importe-efectivo').value = vuelto.toFixed(2);
  alert('Vuelto propuesto en efectivo (pesos): ' + vuelto.toFixed(2));
}

// Validador de contrapartida y cotizaci�n
(function attachValidator(){
  var form = document.getElementById('checkout-form');
  if (!form) return;

  form.addEventListener('submit', function(ev){
    var docType            = parseInt((form.querySelector('input[name="pmethod-id"]')?.value)||'0',10);
    var totalComprobante   = toNum(form.querySelector('input[name="payable-amount"]')?.value);
    var cotizacionDolar    = toNum(document.getElementById('cotizacion-dolar')?.value);
    var cotizacionBillete  = toNum(document.getElementById('cotizacion-billete')?.value);
    var importeEfectivo    = toNum(document.getElementById('importe-efectivo')?.value);
    var importeDeposito    = toNum(document.getElementById('importe-deposito')?.value);
    var importeDolar       = toNum(document.getElementById('importe-dolar')?.value);
    var importeAcuentaUSD  = toNum(document.getElementById('importe-acuenta')?.value);

    if (cotizacionDolar === 0) {
      ev.preventDefault();
      alert('ATENCI�N: La cotizaci�n de esta venta no puede ser 0.');
      return false;
    }
    if (cotizacionDolar === 1 && importeAcuentaUSD > 0) {
      ev.preventDefault();
      alert('ATENCI�N: Si hay importe a cuenta, la cotizaci�n no puede ser 1. Debe ser el valor del d�lar oficial.');
      return false;
    }

    var chequesImportes = document.getElementsByName('importe-cheque[]');
    var totalChequesARS = 0;
    for (var i=0;i<chequesImportes.length;i++){
      totalChequesARS += toNum(chequesImportes[i].value);
    }

    var contrapartidaARS =
        totalChequesARS
      + importeEfectivo
      + importeDeposito
      + (importeDolar * cotizacionBillete)
      + (importeAcuentaUSD * cotizacionDolar);

    if (docType === 2 && importeAcuentaUSD === 0) {
      var diff = totalComprobante - contrapartidaARS;
      if (Math.abs(diff) > 0.20) {
        ev.preventDefault();
        alert(
          'ERROR: La contrapartida no coincide con el total.\n' +
          'Total Comprobante: ' + totalComprobante.toFixed(2) + '\n' +
          'Contrapartida: ' + contrapartidaARS.toFixed(2) + '\n' +
          'Diferencia: ' + diff.toFixed(2)
        );
        return false;
      }
    }
    return true;
  });
})();
</script>
