<style type="text/css">
@media print {
    @page {
    margin-top: 1.3cm;
    margin-bottom: 3cm;
  }
  *{
    box-sizing: border-box;
  }
  .table-tree{
    width:100%;
    text-align:left;
    padding-left:10px !important;
    font-size: 11px;
    border-collapse: collapse;
    border-spacing: 0;
  }
  .table-tree th{
    padding-top:5px;
    padding-bottom:5px;
    border-top:1px solid #000;
    border-bottom:1px solid #000;
  }
  .table-tree th, td{
    border-left: 0;
    border-right: 0;
    margin: 0;
    padding: 3px 5px;
  }
  .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;
  }
  .tittle h6{
    border-bottom:2px solid #000;
    width: 80px;
    max-width: 330px;
    font-size: 16px;
    margin: 10px auto;
  }
  .date{
    width: 100%;
    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: 3px double #000 !important;
  }
  .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;
  }
  .f-l{
    float: left;
  }
  .div-ct{
    width: 500px !important;
    text-align: center !important;
    margin: 0 auto !important;
  }
}
</style>
<!-- <title>VAT Summary</title> -->
<div id="finance-account-trialbal">
    <div class="container">
            <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">
                                <div class="date">
                            <div class="span5">
                                <b>Date From</b>
                            : <?php echo date("d/m/Y", strtotime($date_from)); ?></div><br>
                            <div class="span5">
                                <b>Date To</b>
                           : <?php echo date("d/m/Y", strtotime($date_to)); ?> </div><br>
                        </div>
                </div>

        </div>
        </div>
  <table class="table-tree">
    <thead>
    <tr>
      <th class="cell-left">Date</th>
      <th class="cell-left">Transaction No</th>
      <th class="cell-left">Customer/vendor</th>
      <th class="cell-right">Inbound VAT</th>
      <th class="cell-right">Outbound VAT</th>
    </tr>
    </thead>
    <?php 
    $total_invoice_value_sale= $total_vat_purchase = 0;
    $query ="SELECT SUM(I.total_tax_amount) AS tax_amount,I.id AS Invoice_id,C.customer_name AS cus_name,I.invoice_date as inv_date FROM crm_invoice I LEFT JOIN crm_customer C ON I.company_id = C.id WHERE I.total_tax_amount > 0 AND I.invoice_date BETWEEN '".$date_from."' AND '".$date_to."' GROUP BY I.id"; 
    $allVAT 	= Yii::app()->db->createCommand($query)->queryAll();
    foreach ($allVAT as $each){ ?>
       <tr>
          <?php $total_vat_sale += $each['tax_amount']; ?>
          <td class=""><?php echo date('d/m/Y',strtotime($each['inv_date'])); ?></td>
          <td class=""><?php echo  'SI '.$each['Invoice_id']; ?></td>
          <td class=""><?php echo  $each['cus_name']; ?></td>
          <td class="cell-right">0.00</td>          
          <td class="cell-right">+<?php echo Yii::app()->numberFormatter->formatCurrency($each['tax_amount'],""); ?></td>
        </tr>
       <?php } ?>
    <?php $query ="SELECT SUM(CN.total_tax_amount) AS tax_amount,CN.id AS cr_id,C.customer_name AS cus_name,CN.credit_date as cr_date FROM crm_creditnote CN LEFT JOIN crm_customer C ON CN.company_id = C.id WHERE CN.total_tax_amount > 0 AND CN.credit_date BETWEEN '".$date_from."' AND '".$date_to."' GROUP BY CN.id"; 
    $allVAT 	= Yii::app()->db->createCommand($query)->queryAll();
    foreach ($allVAT as $each){ ?>
       <tr>
          <?php $total_vat_sale -= $each['tax_amount']; ?>
          <td class=""><?php echo date('d/m/Y',strtotime($each['cr_date'])); ?></td>
          <td class=""><?php echo  'CN '.$each['cr_id']; ?></td>
          <td class=""><?php echo  $each['cus_name']; ?></td>
          <td class="cell-right">0.00</td>          
          <td class="cell-right">-<?php echo Yii::app()->numberFormatter->formatCurrency($each['tax_amount'],""); ?></td>
        </tr>
       <?php } ?>
       <?php $query ="SELECT SUM(PI.total_tax_amount) AS tax_amount,PI.id AS purchase_id,V.vendor_name AS vendor_name,PI.invoice_date as inv_date FROM crm_purchasinginvoice PI LEFT JOIN crm_vendor V ON PI.vendor_id = V.id WHERE PI.total_tax_amount > 0 AND PI.invoice_date BETWEEN '".$date_from."' AND '".$date_to."' GROUP BY PI.id"; 
    $allVAT 	= Yii::app()->db->createCommand($query)->queryAll();
    foreach ($allVAT as $each){ ?>
       <tr>
          <?php $total_vat_purchase += $each['tax_amount']; ?>
          <td class=""><?php echo date('d/m/Y',strtotime($each['inv_date'])); ?></td>
          <td class=""><?php echo  'PI '.$each['purchase_id']; ?></td>
          <td class=""><?php echo  $each['vendor_name']; ?></td>
          <td class="cell-right">+<?php echo Yii::app()->numberFormatter->formatCurrency($each['tax_amount'],""); ?></td>
          <td class="cell-right">0.00</td>    
        </tr>
       <?php } ?>
       <?php $query ="SELECT SUM(DN.total_tax_amount) AS tax_amount,DN.id AS debitnote_id,V.vendor_name AS vendor_name,DN.debited_date as debit_date FROM crm_purchasing_debit_note DN LEFT JOIN crm_vendor V ON DN.vendor_id = V.id WHERE DN.total_tax_amount > 0 AND DN.debited_date BETWEEN '".$date_from."' AND '".$date_to."' GROUP BY DN.id"; 
    $allVAT 	= Yii::app()->db->createCommand($query)->queryAll();
    foreach ($allVAT as $each){ ?>
       <tr>
          <?php $total_vat_purchase -= $each['tax_amount']; ?>
          <td class=""><?php echo date('d/m/Y',strtotime($each['debit_date'])); ?></td>
          <td class=""><?php echo  'DN '.$each['debitnote_id']; ?></td>
          <td class=""><?php echo  $each['vendor_name']; ?></td>
          <td class="cell-right">-<?php echo Yii::app()->numberFormatter->formatCurrency($each['tax_amount'],""); ?></td>
          <td class="cell-right">0.00</td>    
        </tr>
       <?php } ?>
      <tr>  
        <td class="cell-right br-top" colspan="3"><b>Total</b></td> 
        <td class="cell-right br-top"><b><?php echo Yii::app()->numberFormatter->formatCurrency($total_vat_purchase,""); ?></b></td>
        <td class="cell-right br-top"><b><?php echo Yii::app()->numberFormatter->formatCurrency($total_vat_sale,""); ?></b></td>
      </tr>
  </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"); ?> </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-->