<?php
$s_Border = "0";
$s_Width  = "";
?>
<?php if( $b_NoExpExcel ){ ?>
<style>
label
{
    margin-right: 0;
}
.grid
{
    border: 1px solid #77d5f7;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 5px;
}
.grid th 
{
    border-color: #77d5f7;
    background-color: #0a7db1;
    font-weight: normal;
    font-size: 11px;
    font-family: Verdana,Arial,sans-serif;
    height: 24px;
    padding: 0 2px;
}
.grid td 
{
    border-left: 0 none;
    border-right-color: #77d5f7;
    border-right-style: solid;
    border-right-width: 1px;
    border-bottom-color: #77d5f7;
    border-bottom-style: solid;
    border-bottom-width: 1px;
    padding: 0 2px;
    /*white-space: pre;*/
    height: 22px;
    /*border: 1px solid #77d5f7;*/
}
</style>
<?php } ?>
<?php
if( !$b_NoExpExcel )
{
    $s_Border = "1";
    $s_Width  = "10px";
}
?>
<table>
    <tr>
        <th colspan="2">FORMATO 14.1: REGISTRO DE VENTAS E INGRESOS</th>
    </tr>
    <tr>
        <th>Ejercicio :</th>
        <td><?=$s_Ejercicio?></td>
    </tr>
    <tr>
        <th>Periodo :</th>
        <td><?=Constantes::$a_meses[$s_Periodo]?></td>
    </tr>
    <tr>
        <th>Nombre de la Empresa:</th>
        <td><?=$o_GSS_CompaniaBN->getDescripcionCorta()?></td>
    </tr>
    <tr>
        <th>RUC:</th>
        <td><?=$o_GSS_CompaniaBN->getRuc()?></td>
    </tr>
</table>

<table class="grid" cellspacing="0" cellpadding="0" border="<?=$s_Border?>" align="center" width="" style="border-bottom: medium none; margin-top: 10px; table-layout: fixed;">
    <thead>
        <tr>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2">N&deg; OPERACI&Oacute;N</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2">FECHA EMISI&Oacute;N</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2">FECHA VENCIMIENTO</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" colspan="3">COMPROBANTE DE PAGO</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" colspan="3">INFORMACION DEL CLIENTE</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2">VALOR EXPORTACI&Oacute;N</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2">BASE IMPONIBLE O GRAVADA</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" colspan="2">IMPORTE EXON. INAFECTA</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2">I.S.C</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2">IGV</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2">ICBPER</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2">OTROS TRIBUTOS</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2">IMPORTE TOTAL</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2">TIPO DE CAMBIO</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" colspan="4">REFERENCIA DEL COMPROBANTE DE PAGO</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2">TOTAL US$</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2">CTA. CLIENTE</th>
            <th style="text-align:center; border-bottom: 1px solid #77d5f7; border-right: 1px solid #77d5f7;" rowspan="2">CONCEPTO</th>
        </tr>
        <tr>
            <th width="<?=$s_Width?>" style="text-align:center; border-right: 1px solid #77d5f7;">TIPO</th>
            <th width="<?=$s_Width?>" style="text-align:center;  border-right: 1px solid #77d5f7;">SERIE</th>
            <th width="<?=$s_Width?>" style="text-align:center;  border-right: 1px solid #77d5f7;">NUMERO</th>
            
            <th width="<?=$s_Width?>" style="text-align:center;  border-right: 1px solid #77d5f7;">TIPO</th>
            <th width="<?=$s_Width?>" style="text-align:center;  border-right: 1px solid #77d5f7;">NUMERO</th>
            <th width="<?=$s_Width?>" style="text-align:center;  border-right: 1px solid #77d5f7;">APELLIDOS O RAZ&Oacute;N SOCIAL</th>
            
            <th width="<?=$s_Width?>" style="text-align:center;  border-right: 1px solid #77d5f7;">EXONERADA</th> <!-- Importe Exon. Inafecta -->
            <th width="<?=$s_Width?>" style="text-align:center;  border-right: 1px solid #77d5f7;">INAFECTA</th>  <!-- Importe Exon. Inafecta -->
            
            <th width="<?=$s_Width?>" style="text-align:center;  border-right: 1px solid #77d5f7;">FECHA</th>
            <th width="<?=$s_Width?>" style="text-align:center;  border-right: 1px solid #77d5f7;">TIPO</th>
            <th width="<?=$s_Width?>" style="text-align:center;  border-right: 1px solid #77d5f7;">SERIE</th>
            <th width="<?=$s_Width?>" style="text-align:center;  border-right: 1px solid #77d5f7;">NUMERO</th>
        </tr>
    </thead>
    <tbody id="content_all_row">
        <?php 
        $f_SumaTotalExportacion   = 0;
        $f_SumaTotalBaseImponible = 0;
        $f_SumaTotalImpuesto      = 0;
        $f_SumaTotalImporteTotal  = 0;
        $f_SumaTotalImporteDolar  = 0;
        ?>
        <?php foreach ( $a_VTA_Documento as $i_Key => $o_VTA_DocumentoBN ){ ?>
            <?php
            $s_TipoVenta = "VENTA DE MERCADERIA";
            $s_CuentaContable = "701101";
            
            $b_ControlImpuesto = $o_VTA_DocumentoBN->esGravadaConImpuesto();
            
            $f_TipodeCambio = GSS_TipoCambioFN::getStaticTipoCambioVenta( substr( $o_VTA_DocumentoBN->getFechaDocumento(), 0, 10 ) );
            
            $f_MontoExportacion     = 0;
            $f_MontoBaseImponible   = 0;   //BASE IMPONIBLE O GRAVADA
            $f_MontoExonerado       = "";
            $f_MontoInafecta        = "";
            $f_MontoIGV             = 0;
            $f_MontoTotal           = 0;
            $f_MontoDolares         = 0;
            
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            $a_SunatTpDoc = array( "RUC" => 6, "DNI" => 1, "" => "-", "OTRO" => "-", "EXP" => 0 );
            $o_MST_PersonaMastBN = $o_VTA_DocumentoBN->getObjectCliente();
            $s_TipoDocumentoSunat = $o_MST_PersonaMastBN->getTipoDocumentoSunat();
            $s_ClienteRUC         = $o_VTA_DocumentoBN->getClienteRUC();
            switch ( $o_VTA_DocumentoBN->getTipoVenta() )
            {
                case "MER":
                    $f_MontoExportacion       = 0;
                    $f_MontoExonerado         = "";
                    if( $b_ControlImpuesto )
                    {
                        $f_MontoBaseImponible = $o_VTA_DocumentoBN->getMontoAfectoMN() - $o_VTA_DocumentoBN->getMontoDescuentosMN();   //BASE IMPONIBLE O GRAVADA
                    }
                    else
                    {
                        $f_MontoInafecta      = $o_VTA_DocumentoBN->getMontoNoAfectoMN();
                    }
                    $f_MontoIGV               = $o_VTA_DocumentoBN->getMontoImpuestoMN();
                    $f_MontoTotal             = $o_VTA_DocumentoBN->getMontoTotalMN();
                    
                    if( $o_VTA_DocumentoBN->getMonedaDocumento() == "EX" )
                    {
                        $f_MontoTotal             = round( $o_VTA_DocumentoBN->getMontoTotal() * $f_TipodeCambio, 2 );
                        if( $b_ControlImpuesto )
                        {
                            $f_MontoBaseImponible = round( ( $o_VTA_DocumentoBN->getMontoAfecto() - $o_VTA_DocumentoBN->getMontoDescuentos() ) * $f_TipodeCambio, 2 );   //BASE IMPONIBLE O GRAVADA
                            $f_MontoIGV           = round( $f_MontoTotal - $f_MontoBaseImponible, 2 );
                        }
                        else
                        {
                            $f_MontoInafecta      = round( $o_VTA_DocumentoBN->getMontoNoAfecto() * $f_TipodeCambio, 2 );
                        }
                        
                        $f_MontoDolares           = $o_VTA_DocumentoBN->getMontoTotal();
                    }
                    else
                    {
                        $f_TipodeCambio = 1;
                    }
                break;
                case "EXP":
                    $s_TipoDocumentoSunat = "0";
                    $s_ClienteRUC         = $o_MST_PersonaMastBN->getIdPersona();
                    
                    $f_MontoExportacion   = $o_VTA_DocumentoBN->getMontoSubTotalMN();
                    $f_MontoBaseImponible = 0;   //BASE IMPONIBLE O GRAVADA
                    $f_MontoExonerado     = "";
                    $f_MontoInafecta      = "";
                    $f_MontoIGV           = $o_VTA_DocumentoBN->getMontoImpuestoMN();
                    $f_MontoTotal         = $o_VTA_DocumentoBN->getMontoTotalMN();
                    
                    if( $o_VTA_DocumentoBN->getMonedaDocumento() == "EX" )
                    {
                        $f_MontoTotal         = round( $o_VTA_DocumentoBN->getMontoTotal() * $f_TipodeCambio, 2 );
                        $f_MontoExportacion   = round( $o_VTA_DocumentoBN->getMontoSubTotal() * $f_TipodeCambio, 2 );
                        $f_MontoBaseImponible = 0;   //BASE IMPONIBLE O GRAVADA
                        $f_MontoExonerado     = "";
                        $f_MontoInafecta      = "";
                        $f_MontoIGV           = 0;
                     
                        $f_MontoDolares       = $o_VTA_DocumentoBN->getMontoTotal();
                    }
                    else
                    {
                        $f_TipodeCambio = 1;
                    }
                break;
            }
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //FORMA DE PAGO
            $s_FormaPago = $o_VTA_DocumentoBN->getIdFormaPago();
            if( $o_VTA_DocumentoBN->getIdFormaPago() != "008" )
            {
                $s_FormaPago = "";
            }
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            
            if( $o_VTA_DocumentoBN->getEstado() == "AN" )
            {
                $s_TipoVenta = "ANULADO";
                $s_CuentaContable = "";
                
                $f_MontoExportacion     = 0;
                $f_MontoBaseImponible   = 0;
                $f_MontoExonerado       = 0;
                $f_MontoInafecta        = 0;
                $f_MontoIGV             = 0;
                $f_MontoTotal           = 0;
            }
            
            $f_SumaTotalExportacion   = $f_SumaTotalExportacion + $f_MontoExportacion;
            $f_SumaTotalBaseImponible = $f_SumaTotalBaseImponible + $f_MontoBaseImponible;
            $f_SumaTotalImpuesto      = $f_SumaTotalImpuesto + $f_MontoIGV;
            $f_SumaTotalImporteTotal  = $f_SumaTotalImporteTotal + $f_MontoTotal;
            $f_SumaTotalImporteDolar  = $f_SumaTotalImporteDolar + $f_MontoDolares;
            ?>
        <tr class="content_row">
            <td align="center"><label class="labelData"> <?=$o_VTA_DocumentoBN->getNumeroDocumento()?> </label></td>
            <td align="center" nowrap="nowrap"><label class="labelData"> <?=substr( $o_VTA_DocumentoBN->getFechaDocumento(), 0, 10 )?> </label></td>
            <td align="center" nowrap="nowrap"><label class="labelData"> <?=substr( $o_VTA_DocumentoBN->getFechaVencimiento(), 0, 10 )?> </label></td>
            <td align="center"><label class="labelData"> <?=$o_VTA_DocumentoBN->getObjectTipoDocumento()->getCodigoFiscal()?> </label></td>
            <td align="center"><label class="labelData"> <?=$o_VTA_DocumentoBN->getDocumentoSerie()?> </label></td>
            <td align="center"><label class="labelData"> <?=$o_VTA_DocumentoBN->getDocumentoNumero()?> </label></td>
            <td align="center"><label class="labelData"> <?=$s_TipoDocumentoSunat?> </label></td>
            <td align="center"><label class="labelData"> <?=$s_ClienteRUC?> </label></td>
            <td align="center" nowrap="nowrap"><label class="labelData"> <?=$o_VTA_DocumentoBN->getClienteNombre()?> </label></td>
            <td align="center"><label class="labelData"> <?=$f_MontoExportacion ? number_format( $f_MontoExportacion, 2 ) : ""?> </label></td>
            <td align="center"><label class="labelData"> <?=$f_MontoBaseImponible ? number_format( $f_MontoBaseImponible, 2 ) : ""?> </label></td>
            <td align="center"><label class="labelData"> <?=$f_MontoExonerado ? number_format( $f_MontoExonerado, 2 ) : ""?> </label></td>
            <td align="center"><label class="labelData"> <?=$f_MontoInafecta ? number_format( $f_MontoInafecta, 2 ) : ""?> </label></td>
            <td align="center"><label class="labelData"> &nbsp; </label></td>
            <td align="center"><label class="labelData"> <?=number_format( $f_MontoIGV, 2 )?> </label></td>
            <td align="center"><label class="labelData"> &nbsp; </label></td>
            <td align="center"><label class="labelData"> &nbsp; </label></td>
            <td align="center"><label class="labelData"> <?=number_format( $f_MontoTotal, 2 )?> </label></td>
            <td align="center"><label class="labelData"> <?=$f_TipodeCambio?> </label></td>
            <td align="center"><label class="labelData"> &nbsp; </label></td>
            <td align="center"><label class="labelData"> &nbsp; </label></td>
            <td align="center"><label class="labelData"> &nbsp; </label></td>
            <td align="center"><label class="labelData"> &nbsp; </label></td>
            <td align="center"><label class="labelData"> <?=$f_MontoDolares ? number_format( $f_MontoDolares, 2 ) : ""?> </label></td>
            <td align="center"><label class="labelData"> <?=$s_CuentaContable?> </label></td>
            <td align="center" nowrap="nowrap"><label class="labelData"> <?=$s_TipoVenta?> </label></td>
        </tr>
        <?php } ?>
        
        <tr>
            <td colspan="9" align="right"><b>TOTALES</b></td>
            <td align="center"><?=number_format( $f_SumaTotalExportacion, 2 )?></td>
            <td align="center"><?=number_format( $f_SumaTotalBaseImponible, 2 )?></td>
            <td align="center">&nbsp;</td>
            <td align="center">&nbsp;</td>
            <td align="center">&nbsp;</td>
            <td align="center"><?=number_format( $f_SumaTotalImpuesto, 2 )?></td>
            <td align="center">&nbsp;</td>
            <td align="center">&nbsp;</td>
            <td align="center"><?=number_format( $f_SumaTotalImporteTotal, 2 )?></td>
            <td align="center">&nbsp;</td>
            <td align="center">&nbsp;</td>
            <td align="center">&nbsp;</td>
            <td align="center">&nbsp;</td>
            <td align="center">&nbsp;</td>
            <td align="center"><?=number_format( $f_SumaTotalImporteDolar, 2 )?></td>
            <td align="center">&nbsp;</td>
            <td align="center">&nbsp;</td>
        </tr>
        
    </tbody>
</table>