<head>
	<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
<style type="text/css">
@media print {
  @page {
    margin-top: 1.6cm;
    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;
    border: 1px solid rgb(31, 103, 178);
  }
  .table-tree th{
    background: rgb(31, 103, 178);
    color: #fff;
    padding-top:5px;
    padding-bottom:5px;
    border: 1px solid rgb(31, 103, 178);
  }
  .table-tree th, td{
    margin: 0;
    padding: 3px 5px;
    border: 1px solid rgb(31, 103, 178);
  }
  .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: 180px;
    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;
  }
  .date1{
    font-size: 11px;
    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: 1px solid rgb(31, 103, 178);
  }
  .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%;
    float: right;
  }
  .col-4{
    width: 33%;
    float:left;
  }
  .col-5{
    width: 40%;
    float:left;
  }
  .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;
  }
  .f-l{
    float: left;
  }
  .div-ct{
    width: 500px !important;
    text-align: center !important;
    margin: 0 auto !important;
  }
}

}
.left-col {
    float: left;
    width:40%;
}
.center-col {
    float: left;
    width: 5%;
}
.right-col {
    float: right;
    width: 40%;
    
}

</style>
  <?php  $company= Subledger::model()->findByPk($subledger); 
  $acc= FinAccounts::model()->findByPk($account);
  Yii::app()->db->createCommand("TRUNCATE TABLE ageing")->execute();
$SQL11="INSERT INTO ageing (SELECT A.id,A.subledger,A.date,A.voucher_no,A.debit,A.credit,(A.debit-sum(B.debit_allocate_amount)) as db,(A.credit-sum(B.credit_allocate_amount)) as cr FROM `crm_fin_general_ledger` A left join crm_fin_voucher_allocation B ON A.id=B.invoice_id where A.account_id=$account AND A.subledger=$subledger AND A.isAllocated='Y' AND (A.date between '2014-01-01' AND '$date_from') AND (B.allocate_date between '2014-01-01' AND '$date_from') group by B.invoice_id) UNION (SELECT A.id,A.subledger,A.date,A.voucher_no,A.debit,A.credit,(A.debit) as db,(A.credit) as cr FROM `crm_fin_general_ledger` A left join crm_fin_voucher_allocation B ON A.id=B.invoice_id where A.account_id=$account AND A.subledger=$subledger AND A.isAllocated='Y' AND (A.date between '2014-01-01' AND '$date_from') AND (B.allocate_date NOT between '2014-01-01' AND '$date_from') group by A.id) UNION (SELECT id,subledger,date,voucher_no,debit,credit,debit as db,credit as cr from crm_fin_general_ledger  where account_id=$account AND subledger=$subledger AND allocation_amount =0 AND isAllocated='Y' AND (date between '2014-01-01' AND '$date_from')) order by date ASC";
Yii::app()->db->createCommand($SQL11)->execute();
$SQL1="select sum(db)-sum(cr) as amt from ageing"; 
$arr_sum_amount1  = Yii::app()->db->createCommand($SQL1)->queryScalar();
    $acc= FinAccounts::model()->findByPk($account);
    $opening_bal='0.00';
    $type='';
    $open=FinOpeningBalance::model()->find(array('condition'=>'mainacc='.$account.' AND account_id='.$subledger));
    $open_bal=$open->statement_op;
    if($open->type==1)
    {
     $type='Dr';   
     $open_bal1=$open_bal;
    }
 else {
     $type='Cr';
     $open_bal1=-$open_bal;
    }
   $opening=$open_bal1;
    if($opening>0)
    {
    $type='Dr';      
    }
    else if($opening<0) {
    $type='Cr';   
    }
 else {
    $type='';    
    }
  ?>
</head>
<body>
 <div class="container">
<div class="heading">
<table style="border: 0; width: 100%;">
    <tr style="border: 0">
        <td style="border: 0; width: 80%;"><h1><?php echo Yii::app()->user->master_company_name;?></h1></td>

        <td style="border: 0;float: right; padding-left: 14rem;"><?php echo CHtml::image(Yii::app()->baseUrl . '/images/logo/'.Yii::app()->user->pdf_company_logo,'',array('class'=>'heading-img')); ?></td>
    </tr>
</table>
      </div>      <br>

        <div class="tittle"><h6>Statement of Account</h6></div>
  <div class="f-l date1 col-4"><!-- <div class="span1"><b>Account </b></div> <div class="span3"><b>: <?php echo $acc->id.' '.$acc->description; ?></b> <br></div>
    <div class="span1"><b>Subledger A/C </b></div> <div class="span3"><b>: <?php echo $company->id.' '.$company->description; ?></b><br></div>
    <div class="span1"></div> <div class="span3"><br></div> -->
      <table class="table-tree">
        <tr>
          <td>Account</td>
          <td><?php echo $acc->id.' '.$acc->description; ?></td>
        </tr>
        <tr>
          <td>Subledger A/C </td>
          <td><?php echo $company->id.' '.$company->description; ?></td>
        </tr>
      </table>
    </div>
    <div class="f-l date1 col-5"></div>
  <div class="f-l date1 col-3">

          <table class="table-tree">
        <tr>
          <td>Date From</td>
          <td><?php echo date_format(date_create($date_from), 'd-m-Y');?></td>
        </tr>
        <tr>
          <td>Date To </td>
          <td><?php echo date_format(date_create($date_to),'d-m-Y'); ?></td>
        </tr>
        <tr>
          <td>Opening Bal.</td>
          <td><?php echo abs($opening).$type; ?></td>
        </tr>
      </table>

  </div>
  <div class="clear"></div>
  <table class="table-tree">
    <thead>
    <tr>
      <th class="cell-left">Date</th>
      <th class="cell-left">Voc ref</th>
      <th class="cell-left">Chq. No</th>
      <th class="cell-left">Narration</th>
      <th class="cell-right">Debit</th>
      <th class="cell-right">Credit</th>
      <th class="cell-right">Balance</th>
    </tr>
  </thead>
    <?php
    $SQL="CREATE OR REPLACE VIEW ss1 AS ("
            . "SELECT A.id,A.item_description,A.narration,A.chk_no,A.date,A.voucher_no,A.debit,A.credit,(A.debit) as db,(A.credit) as cr FROM `crm_fin_general_ledger` A where A.account_id=$account AND A.subledger=$subledger AND A.isAllocated='Y' AND (A.date between '$date_from' AND '$date_to')) UNION (SELECT A.id,A.item_description,A.narration,A.chk_no,A.date,A.voucher_no,A.debit,A.credit,(A.debit) as db,(A.credit) as cr FROM `crm_fin_general_ledger` A where A.account_id=$account  AND A.subledger=$subledger AND A.isAllocated='Y' AND (A.date between '$date_from' AND '$date_to') group by A.id) UNION (SELECT id,item_description,narration,chk_no,date,voucher_no,debit,credit,debit as db,credit as cr from crm_fin_general_ledger  where account_id=$account AND subledger=$subledger AND isAllocated='Y' AND (date between '$date_from' AND '$date_to')) order by date ASC";
      Yii::app()->db->createCommand($SQL)->execute();
    $arr_sum_amount  = Yii::app()->db->createCommand("select * from ss1 group by id order by date")->queryAll();
      $totaldebit=0.00;
    $totalcredit=0.00;
    $totalbal=$opening;
    foreach ($arr_sum_amount as $eachaccounts){

      if(($eachaccounts['db']!=0) || ($eachaccounts['cr']!=0)) {
      ?>
      <tr>
        <td class="cell-"><?php
        $date = date("d/m/Y", strtotime($eachaccounts['date']));
        echo $date; ?></td>
        <td class=""><?php echo  $eachaccounts['voucher_no']; ?></td>
        <td class=""><?php if($eachaccounts['chk_no']!='XXX') { echo  $eachaccounts['chk_no']; } ?></td>
        <td class=""><?php if($eachaccounts['item_description']=='') { echo $eachaccounts['narration']; } else { echo $eachaccounts['item_description']; } ?></td>
        <td class="cell-right"><?php
        echo Yii::app()->numberFormatter->formatCurrency($eachaccounts['db'],"");
        ?></td>
        <td  class="cell-right"><?php
        echo Yii::app()->numberFormatter->formatCurrency($eachaccounts['cr'],"");
        ?></td>
        <td  class="cell-right"><?php
        $totalbal+=($eachaccounts['db'])-($eachaccounts['cr']);
            if($totalbal>0)
            {
            $val='Dr';
            }
            else {
            $val='Cr';    
            }
            $totaldebit+=$eachaccounts['db'];
            $totalcredit+=$eachaccounts['cr'];
            echo Yii::app()->numberFormatter->formatCurrency(abs($totalbal),"").' '.$val;
        ?></td>
      </tr>
      <?php }
    }
    
      ?>
      <tr><td colspan="7">&nbsp;</td></tr>
      <tr>  <td class="cell-right" colspan="3"></td> <td class="cell-right"><b>Total</b></td><td class="cell-right br-top"><b><?php  echo Yii::app()->numberFormatter->formatCurrency($totaldebit,""); ?></b></td>
        <td class="cell-right br-top"><b><?php echo Yii::app()->numberFormatter->formatCurrency($totalcredit,"");?></b></td><td class="cell-right br-top"><b><?php echo Yii::app()->numberFormatter->formatCurrency(abs($totalbal),"").' '.$val;?></b></td>
      </tr>
    </table>

       <!--mpdf
    <htmlpagefooter name="myfooter" class="newfoot">

            <!-- <div style="text-align:center;width:100%;font-size:10px;"><?= Yii::app()->user->footer_autogenerated; ?>
        <?php
                  date_default_timezone_set("Asia/Dubai");
                 echo date('d/m/Y')." ".date("h:i:sa"); ?>
    </div> -->

    
        <div style="border-top: 1px dotted #000000; font-size: 12px; text-align: center; padding-top: 10px; background-color: #d7faeb;">
            <div style="text-align:center;width:100%">
                <b><?= Yii::app()->user->footer_line_1 ?></b><br>
                <?= Yii::app()->user->footer_line_2 ?>
            </div>
            <div style="text-align:center;width:100%">Page {PAGENO} of {nb} </div>
        </div>
    </htmlpagefooter>
        <sethtmlpagefooter name="myfooter" page="all" value="on" />
        mpdf-->


</body>