<style type="text/css">
@media print {
    @page {
    margin-top: 1.3cm;
    margin-bottom: 3cm;
    font-family: 'Montserrat';
  }
  *{
    box-sizing: border-box;
  }
  .table-tree{
    width:100%;
    text-align:left;
    padding-left:10px !important;
    font-size: 11px;
    border-collapse: collapse;
    border-spacing: 0;
    border: 1px solid #3f8cc5;
    font-family: 'Montserrat', Arial;
  }
  .table-tree th{
    padding-top:5px;
    padding-bottom:5px;
    border: 1px solid #3f8cc5;
  }

  .bg-blue{background-color: #3f8cc5;
  }

  .table-tree th, td{
    border-left: 0;
    border-right: 0;
    margin: 0;
    padding: 3px 5px;
    border: 1px solid #3f8cc5;
    font-family: 'Montserrat', Arial;
  }
  .ze{background: #CCC}
  .box-pad,.box-pad *{
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
  }
  .tre td{
    border:none;
  }
  .level-1{
    padding-left:5px !important;
  }
  .level-2{
    padding-left: 20px !important;
  }
  .level-3{
    padding-left: 35px !important;
  }
  .level-4{
    padding-left: 50px !important;
  }
  .txt-right{
    text-align: right !important;
  }
  .tittle{
    width: 100%;
    margin: 0 0 10px 0;
    float: left;
    text-align: center;
    font-family: 'Montserrat', Arial;
  }
  .tittle h6{
    /*border-bottom:2px solid #000;*/
    text-decoration: underline;
    width: 200px;
    max-width: 330px;
    font-size: 16px;
    margin: 10px auto;
  }
  .date{
    width: 25%;
    float: left;
    font-size: 11px;
    padding-left: 5px;
    font-weight: 600;
    text-align: left;
    padding-bottom: 3px;
  }
  .date span{
    width: 200px;
    display: inline-block;
  }
  .clear{
    clear: both;
  }
  .cell-left{
    text-align: left !important;
  }
  .cell-right{
    text-align: right !important;
  }
  .br-top{
    /*border-top: 1px solid #000 !important;
    border-bottom: 1px solid #000 !important;*/
  }
  .br-line{
   /*border-bottom:1px solid #000 !important;*/
   font-weight: bold;
   font-size: 12px;
  }

  td .br-line{
    width: 20%;
  }
  .space{
    width: 100%;
    float: left;
    clear: both;
    height: 5px;
  }
  .col-12{
    width: 100%;
  }
  .col-6{
    width: 50%;
  }
  .col-9{
    width: 75%
  }
  .col-3{
    width:25%;
  }
  .f-l{
    float: left;
  }
  .f-r{
    float: right;
  }
  .txt-right{
    text-align: right;
  }
  .txt-left{
    text-align: left;
  }
  .x-space{
    box-sizing: border-box;
  }
  .bg-w{
    background: #FFF !important;
  }
  .footer {
    width:100%;
    float:left;
    font-size:11px;
    position:absolute;
    bottom:0px;
    left:0px;
    text-align:center !important;
    line-height:18px;
    border-top: 1px dotted #000;
    padding: 5px;
  }
  .span1{
    width: 80px !important;
    display: inline-block;
    float: left;
  }
  .span2{
    width: 80px !important;
    display: inline-block;
    float: left;
  }
  .span3{
    width: auto !important;
    display: inline-block;
    float: left;
  }
  .span5{
    width: 25%;
    display: inline-block;
    float: right;
  }

    .span6{
    width: 35%;
    display: inline-block;
    float: right;
  }
  .f-l{
    float: left;
  }
  .div-ct{
    width: 500px !important;
    text-align: center !important;
    margin: 0 auto !important;
  }
}
.bold{
  font-weight: bold;
}

</style>
<div id="finance-account-trialbal">
    <div class="container">
      <div class="col-md-12">
                <div class="col-md-9">&nbsp;</div>
                <div class="col-md-3 span6" style="float:right; margin-left: 5rem;">
                   <!--  <img src="http://blueskyerp.me/bluesky/images/logo-bsk.png"> -->
                   <?php echo CHtml::image('images/logo/'.Yii::app()->user->pdf_company_logo,'',array('class'=>'heading-img')); ?>
                </div>
              </div>

            <div class="heading tittle">
                    <div><h2><?php echo Yii::app()->user->master_company_name;?></h2></div>
            </div>
  </div>
      <div class="tittle"><h6>VAT Summary</h6></div>
       <div class="container-fluid">
        <div class="col-md-12">
                <div class="col-md-9"></div>
                <div class="col-md-3">
                               <table class="table-tree" style="width: 100%;float: right; margin-left: 45rem;">
                      <tr>
                        <td width="50%">Date From</td>
                        <td width="50%"><?php echo date('d/m/Y',strtotime($date_from)); ?></td>
                      </tr>
                       <tr>
                        <td width="50%">Date To</td>
                        <td width="50%"><?php echo date('d/m/Y',strtotime($date_to)); ?></td>
                      </tr>
                  </table><br><br>
                </div>

        </div>
        </div>
  <table class="table-tree">
    <thead>
    <tr class="bg-blue">
      <td class="br-line cell-left" width="20%">Outbound</td>
      <td class="br-line cell-right" width="20%">Sales</td>
      <td class="br-line cell-right" width="20%">Tax Category</td>
      <td class="br-line cell-right" width="20%">Tax Amount</td>
      <td class="br-line cell-right" width="20%">Net Amount</td>
    </tr>
    </thead>
    <?php
    $sales_total=0;
    $sales_tax_total=0;
    $sales_net_total=0;
    $sale_model=new MasInvoiceType();
    $sale_model = $sale_model->findAll(array('condition'=>'inv_type="sales"'));
    foreach ($sale_model as $each){   
        $sale_price_sql ='SELECT SUM( (grand_total-total_tax_amount)*exchange_rate )as net_amount,SUM(total_tax_amount*exchange_rate) AS tax_amount
            FROM crm_invoice I             
            WHERE I.invoice_type="'.$each['id'].'"
                AND invoice_date >="'.$date_from .'"
                AND invoice_date <="'.$date_to .'"';
        $sale_row = Yii::app()->db->createCommand($sale_price_sql)->queryRow();
        $creditnote_sql ='SELECT IFNULL(SUM( (CN.credited_amount-CN.total_tax_amount)*CN.exchange_rate ),0)as credit_net_amount,IFNULL(SUM(CN.total_tax_amount*CN.exchange_rate),0) AS credit_tax_amount
            FROM crm_creditnote CN LEFT JOIN crm_invoice I ON CN.invoice_id = I.id 
            LEFT JOIN crm_customer CU ON CU.id = I.company_id       
            LEFT JOIN crm_mas_emirates_list EL ON EL.id = CU.customer_emirates_name
            WHERE I.invoice_type="'.$each['id'].'"
                AND CN.credit_date >="'.$date_from .'"
                AND CN.credit_date <="'.$date_to .'" GROUP BY CU.customer_emirates_name';
        $credit_row = Yii::app()->db->createCommand($creditnote_sql)->queryRow();
        $sale_sum = $sale_row['net_amount']-$credit_row['credit_net_amount'];
        $sale_tax_amount=$sale_row['tax_amount']-$credit_row['credit_tax_amount'];
        // if($sale_sum > 0)
        //   $sales_tax_percent=($sale_tax_amount/$sale_sum)*100;
        // else
        //   $sales_tax_percen = 0;
        $sale_net=$sale_sum+$sale_tax_amount;
        $sales_total+=$sale_sum;
        $sales_tax_total+=$sale_tax_amount;
        $sales_net_total+=$sale_net;
    
        ?>
    <tr>
        <td class="cell-"><?php echo $each['inv_name'];?></td>
        <td class="cell-right"><?php echo Yii::app()->numberFormatter->formatCurrency($sale_sum,"");  ?></td>
        <!-- <td class="cell-right"><?php //echo Yii::app()->numberFormatter->formatCurrency($sales_tax_percent,"");  ?></td> -->
      
             <td class="cell-right"><?php echo Yii::app()->numberFormatter->formatCurrency($sale_tax_amount,""); ?></td>
            <td class="cell-right"><?php echo Yii::app()->numberFormatter->formatCurrency($sale_net,""); ?></td>
       
     
     
      
    </tr>
    <?php }    ?>
    <tr>  
        <td class="cell-right br-top" ><b>Total</b></td> 
        <td class="cell-right br-top"><b><?php echo Yii::app()->numberFormatter->formatCurrency($sales_total,""); ?></b></td>
        <!-- <td class="cell-right br-top"><b> </b></td> -->
        <td class="cell-right br-top"><b><?php echo Yii::app()->numberFormatter->formatCurrency($sales_tax_total,""); ?></b></td>
        <td class="cell-right br-top"><b><?php echo Yii::app()->numberFormatter->formatCurrency($sales_net_total,""); ?></b></td>
    </tr>
  </table>
      <br/><br/>
      <table class="table-tree">
    <thead>
    <tr class="bg-blue">
      <td class="br-line cell-left"  width="20%">Inbound</td>
      <td class="br-line cell-right"  width="20%">Purchase</td>
      <td class="br-line cell-right" width="20%">Tax Category</td>
      <td class="br-line cell-right"  width="20%">Tax Amount</td>
      <td class="br-line cell-right"  width="20%">Net Amount</td>
    </tr>
    </thead>
    <?php
    $pur_total=0;
    $pur_tax_total=0;
    $pur_net_total=0;
    $pur_model=new MasInvoiceType();
    $pur_model = $pur_model->findAll(array('condition'=>'inv_type="purchase"'));
    foreach ($pur_model as $each){   
         $pur_price_sql ='SELECT SUM( (grand_total-total_tax_amount)*exchange_rate ) as net_amount,SUM(total_tax_amount*exchange_rate) AS tax_amount
            FROM crm_purchasinginvoice WHERE invoice_type="'.$each['id'].'" AND invoice_date >="'.$date_from .'" AND invoice_date <="'.$date_to .'"';
        $pur_row = Yii::app()->db->createCommand($pur_price_sql)->queryRow();
        $debitnote_sql ='SELECT IFNULL(SUM( (DN.debited_amount-DN.total_tax_amount)*DN.exchange_rate ),0)as debit_net_amount,IFNULL(SUM(DN.total_tax_amount*DN.exchange_rate),0) AS debit_tax_amount
                FROM crm_purchasing_debit_note DN LEFT JOIN crm_purchasinginvoice PI ON DN.purchasing_invoice_id = PI.id                     
                WHERE PI.invoice_type="'.$each['id'].'"
                AND DN.debited_date >="'.$date_from .'"
                AND DN.debited_date <="'.$date_to .'"';
        $debit_row = Yii::app()->db->createCommand($debitnote_sql)->queryRow();
        $pur_sum =$pur_row['net_amount']-$debit_row['debit_net_amount'];
        $pur_tax_amount=$pur_row['tax_amount']-$debit_row['debit_tax_amount'];
        if($pur_sum > 0)
           $pur_tax_percent=($pur_tax_amount/$pur_sum)*100;
        else
           $pur_tax_percent = 0;
        $pur_net=$pur_sum+$pur_tax_amount;
        $pur_total+=$pur_sum;
        $pur_tax_total+=$pur_tax_amount;
        $pur_net_total+=$pur_net;
        ?>
    <tr>
        <td class="cell-"><?php echo $each['inv_name'];?></td>
        <td class="cell-right"><?php echo Yii::app()->numberFormatter->formatCurrency($pur_sum,"");?></td>
        <!-- <td class="cell-right"><?php // echo Yii::app()->numberFormatter->formatCurrency($pur_tax_percent,"");  ?></td> -->
              <td class="cell-right"><?php echo Yii::app()->numberFormatter->formatCurrency($pur_tax_amount,""); ?></td>
            <td class="cell-right"><?php echo Yii::app()->numberFormatter->formatCurrency($pur_net,""); ?></td>
       
     
     
      
    </tr>
    <?php }    ?>
    <tr>  
        <td class="cell-right br-top" ><b>Total</b></td> 
        <td class="cell-right br-top"><b><?php echo Yii::app()->numberFormatter->formatCurrency($pur_total,""); ?></b></td>
        <!-- <td class="cell-right br-top"><b> </b></td> -->
        <td class="cell-right br-top"><b><?php echo Yii::app()->numberFormatter->formatCurrency($pur_tax_total,""); ?></b></td>
        <td class="cell-right br-top"><b><?php echo Yii::app()->numberFormatter->formatCurrency($pur_net_total,""); ?></b></td>
    </tr>
  </table>
      <br/>
      <br/>
    <?php 
        $net_tax_total=$sales_tax_total-$pur_tax_total;
    ?>  
    <table class="table-tree">
    <thead>
     <tr class="bold">
      <td class="bold" rowspan="4" width="37%" style="text-align: center;">Tax Payable</td>
      <td class="cell-right" width="20%">Outbound Tax</td>
      <td class="cell-right" width="20%"><?php echo Yii::app()->numberFormatter->formatCurrency($sales_tax_total,""); ?></td>
<!--       <td class="bold" rowspan="3" width="40%" style="text-align: center;">Three Hundred Only</td>-->
    </tr>
    <tr class="bold">
      <td class="cell-right" width="20%">Inbound Tax</td>
      <td class="cell-right" width="20%"><?php echo Yii::app()->numberFormatter->formatCurrency($pur_tax_total,""); ?></td>
     
    </tr>
    <tr class="bold">
      <td class="bold cell-right" width="20%">Total</td>
      <td class="bold cell-right" width="20%"><?php echo Yii::app()->numberFormatter->formatCurrency($net_tax_total,""); ?></td>
      
    </tr>   
    <tr>
      <td class="bold" colspan="2" style="text-align: center;"><?php echo ucfirst($this->widget('ext.NumtoWord.NumtoWord', array('num' => floatval($net_tax_total)))->result) . ' only';?></td>
    </tr>
    </thead>
    </table>
</div>

        
                    <!--mpdf
        <htmlpagefooter name="myfooter">
            <div style="border-top: 1px dotted #000000; font-size: 12px; text-align: center; padding-top: 10px; ">
                <div style="text-align:left;width:50%;float:left">Printed on <?php
                  date_default_timezone_set("Asia/Dubai");
                 echo date('d/m/Y')." ".date("h:i:sa"); ?> by <?php $use=User::model()->findByPk(Yii::app()->user->id); echo $use->username; ?> </div>
                <div style="text-align:right;width:50%;float:left">Page {PAGENO} of {nb} </div>
            </div>
        </htmlpagefooter>
        <sethtmlpagefooter name="myfooter" page="all" value="on" />
        mpdf-->