<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<style>
  page {
        background: white;
    padding: 10px;
    display: block;
    margin: 0 auto;
    margin-bottom: 0.5cm;
    box-shadow: rgba(0, 0, 0, 0.15) 0px 2px 44px 0px;
  }

 
 .btn {
    padding: 1px 12px;
}
  .header_sec h3{
    font-weight: 600;
     font-size: 24px;
  }

  .company_name{
    font-size: 15px;
    font-weight: 600;
  }

  .date_1{
    font-size: 14px;
    margin-bottom: 25px;
  }

  .table th, .table td {
    padding: 5px !important;
  }

  .right_align{
    text-align: right !important;
  }

  .right_float{
    float: right;
  }
  .table_head{
  margin-bottom: 1px;
  } 
  .thead-light th{
    background-color: #428BCA;
    color: white;
    border-color: #357EBD;
    border-top: 1px solid #357EBD;  
  }  
  @media print {
 page[size="A4"] {  
    width: 21cm;
    height: 29.7cm; 
  }
</style>
<?php 

$v = "";
/* if($this->input->post('name')){
  $v .= "&product=".$this->input->post('product');
  } */

if ($this->input->post('start_date')) {
    $v .= "&start_date=" . $this->input->post('start_date');
}
if ($this->input->post('end_date')) {
    $v .= "&end_date=" . $this->input->post('end_date');
}

?>

<script type="text/javascript">
    $(document).ready(function () {
        $('#form').hide();
        
        $('.toggle_down').click(function () {
            $("#form").slideDown();
            return false;
        });
        $('.toggle_up').click(function () {
            $("#form").slideUp();
            return false;
        });
    });
</script>
<div class="box">
<div class="box-header">
        <h2 class="blue"><i class="fa fa-money"></i><?= lang('trialBalance')?> <?php
            if ($this->input->post('start_date')) {
                echo "From " . $this->input->post('start_date') . " to " . $this->input->post('end_date');
            }
            ?>
        </h2>

       <div class="box-icon">
            <ul class="btn-tasks">
                <li class="dropdown">
                    <a href="#" class="toggle_up tip" title="<?= lang('hide_form') ?>">
                        <i class="icon fa fa-toggle-up"></i>
                    </a>
                </li>
                <li class="dropdown">
                    <a href="#" class="toggle_down tip" title="<?= lang('show_form') ?>">
                        <i class="icon fa fa-toggle-down"></i>
                    </a>
                </li>
            </ul>
        </div> 
    </div>
<div class="box-content">
	 <div class="row">
            <div class="col-lg-12">
				<div id="form">
					<?php echo admin_form_open("reports/trialBalance"); ?>
						<div class="row">
							<div class="col-sm-4">
								<div class="form-group">
									<?= lang("start_date", "start_date"); ?>
									<?php echo form_input('start_date', (isset($_POST['start_date']) ? $_POST['start_date'] : ""), 'class="form-control datetime" id="start_date"'); ?>
								</div>
							</div>
							<div class="col-sm-4">
								<div class="form-group">
									<?= lang("end_date", "end_date"); ?>
									<?php echo form_input('end_date', (isset($_POST['end_date']) ? $_POST['end_date'] : ""), 'class="form-control datetime" id="end_date"'); ?>
								</div>
							</div>
						</div>
						<div class="form-group">
							<div class="controls"> <?php echo form_submit('submit_report', $this->lang->line("submit"), 'class="btn btn-primary"'); ?> </div>
						</div>
					<?php echo form_close(); ?>

                </div>
                <div class="clearfix"></div>
  <page size="A4" style="height: auto;">
    <div class="container">
      <div class="row">
        <div class="header_sec col-md-11">
          <h3>TRIAL BALANCE</h3>
          <span class="company_name"><?php echo $created_by->company; ?></span><br>
          <div class="date_1">
            <span>Date:</span>
            <span><?php
            if ($this->input->post('start_date')) {
                echo "From " . $this->input->post('start_date') . " to " . $this->input->post('end_date');
            }
            else{
           echo  "From " . $this->sma->hrld(date('Y-m-d 00:00:00')). " to " .$this->sma->hrld(date('Y-m-d H:i:s')) ;
            }
            ?></span>
          </div>
        </div>
        <div class="col-md-1">
          <button type="button" class="no-print btn btn-primary" onclick="window.print();">Print</button>
        </div>
        <div class="col-md-12"><span>ACCOUNTS</span><span class="right_float"><?= lang("date"); ?>: <?= $this->sma->hrld(date('Y-m-d H:i:s')); ?></span></div>
        <table class="table table_head">
          <thead class="thead-light">
            <tr>
              <th style="width: 55%;border-bottom: 1px solid #fff;"></th>
              <th style="text-align: right;border-bottom: 1px solid #fff;"><b>Debit</b></th>
              <th style="text-align: right;border-bottom: 1px solid #fff;"><b>Credit</b></th>
            </tr>
            <tr>
              <th colspan="3" style="text-align:  left;"><b>Assets</b></th>
            </tr>  
          </thead>
		  <?php //print_r($invse);
			$to_amount=$tot_amounts=$equitqq=$credit=$equitq=0;	 
		  foreach ($trial as $row2)
		  {
			$categry = $row2->category;
			$tp = $row2->type;
			$amunt = $row2->amount;			
			$condition =  $this->db->get_where('type' , array('id' =>$row2->acc_type))->row()->account_category; ?>
		 
          <tbody>
		   <?php //$condition =  $this->db->get_where('type' , array('id' =>$row2->acc_type))->row()->account_category; ?>
		 <?php if($condition == 2){ ?>
		    
		  <tr>
				  
		
            <td style="width:34%;"><b><?php echo $this->db->get_where('accounts' , array('id' =>$row2->category))->row()->Name; ?></b></td>
			<?php if ($tp == 'expense'){ 
			$to_amount += $amunt;
			?>
		  <td class="right_align"><?php echo $this->sma->formatMoney($amunt); ?></td>
			<?php }
			else{ ?>
			 <td class="right_align">0.00</td>
			<?php }
			if ($tp == 'income'){
				$tot_amounts += $amunt;
				?>
            <td class="right_align"><?php echo $this->sma->formatMoney($amunt); ?></td>
			<?php }	else{ ?>
			 <td class="right_align">0.00</td>
			<?php } ?>
		  </tr><?php } }?>
        </tbody>
      <thead class="thead-light">
          <tr>
            <th colspan="3" style="text-align:  left;">Liabilities</th>
          </tr>
        </thead>
		<?php //print_r($invse);
				 
		  foreach ($trial as $pro)
		  {
			$categry = $pro->category;
			$tp = $pro->type;
			$amunt = $pro->amount;			
			$condition =  $this->db->get_where('type' , array('id' =>$pro->acc_type))->row()->account_category; ?>
		 
          <tbody>
		   <?php //$condition =  $this->db->get_where('type' , array('id' =>$pro->acc_type))->row()->account_category; ?>
		 <?php if($condition == 3){ ?>
		    
		  <tr>
			<td style="width:34%;"><b><?php echo $this->db->get_where('accounts' , array('id' =>$pro->category))->row()->Name; ?></b></td>
			<?php if ($tp == 'expense'){ 
			$to_amount += $amunt;
			?>
		  <td class="right_align"><?php echo $this->sma->formatMoney($amunt); ?></td>
			<?php }
			else{ ?>
			 <td class="right_align">0.00</td>
			<?php }
			if ($tp == 'income'){
				$tot_amounts += $amunt;
				?>
            <td class="right_align"><?php echo $this->sma->formatMoney($amunt); ?></td>
			<?php }	else{ ?>
			 <td class="right_align">0.00</td>
			<?php } ?>
		  </tr><?php }}?>
        <!--  <tbody>
          <tr>
            <td style="width: 67%;"><b>Total Liabilities</b></td>
            <td class="right_align">00.00</td>
            <td class="right_align"><?php echo $this->sma->formatQuantity($balano); ?></td>
          </tr>
        </tbody>
        <thead class="thead-light">
          <tr>
            <th colspan="3" style="text-align:  left;">Equity</th>
          </tr>
        </thead>
        <tbody>
		 <?php //print_r($invse);
		  foreach ($trial as $rowz){
			  	$invseet = $rowz->category;
				//$a = $this->db->get_where('accounts' , array('id' =>$invseet))->row()->type;
				//$cat = $this->db->get_where('type' , array('id' =>$a))->row()->name;
				
				//print_r($cat);
				
				
		   if(($rowz->category == '7')){
			  $equit+= $rowz->amount; //print_r($tot);
		 
		  }
		  if(($rowz->category == '12')){
				   $equity+= $rowz->amount; 
		 
		  }
		  
		  }
			
			$balanos = $equit+$equity;
		  ?>
          <tr>
            <td style="width: 66%;"><b>Total Equity</b></td>
            <td class="right_align">00.00</td>
            <td class="right_align"><?php echo $this->sma->formatQuantity($balanos); ?></td>
          </tr>
        </tbody>
        <thead class="thead-light">
          <tr>
            <th  colspan="3" style="text-align:  left;"><b>Income</b></th>
          </tr>
        </thead>
        <tbody>
		 <?php //print_r($invse);
		  foreach ($trial as $rowq){
			  	$invseetq = $rowq->category;
				//$a = $this->db->get_where('accounts' , array('id' =>$invseet))->row()->type;
				//$cat = $this->db->get_where('type' , array('id' =>$a))->row()->name;
				
				//print_r($cat);
				
				
		   if(($rowq->category == '8')||($rowq->category == '34')||($rowq->category == '35')||($rowq->category == '11')||($rowq->category == '13')){
			  $equitq+= $rowq->amount; //print_r($tot);
		 
		  }
		  
		  
		  }
			
			
		  ?>
          <tr>
            <td style="width: 34%;">Total Income</td>
            <td class="right_align">00.00</td>
            <td class="right_align"><?php echo $this->sma->formatQuantity( $equitq); ?></td>
          </tr>
        </tbody>-->
        <thead class="thead-light">
          <tr>
            <th colspan="3" style="text-align:  left;"><b>Expenses</b></th>
          </tr>
        </thead>
		<?php //print_r($invse);
				 
		  foreach ($trial as $prof)
		  {
			$categry = $prof->category;
			$tp = $prof->type;
			$amunt = $prof->amount;			
			$condition =  $this->db->get_where('type' , array('id' =>$prof->acc_type))->row()->account_category; ?>
		 
          <tbody>
		   <?php //$condition =  $this->db->get_where('type' , array('id' =>$prof->acc_type))->row()->account_category; ?>
		 <?php if($condition == 5){ ?>
		   <tr>
				  
		
            <td style="width:34%;"><b><?php echo $this->db->get_where('accounts' , array('id' =>$prof->category))->row()->Name; ?></b></td>
			<?php if ($tp == 'expense'){ 
			$to_amount += $amunt;
			?>
		  <td class="right_align"><?php echo $this->sma->formatMoney($amunt); ?></td>
			<?php }
			else{ ?>
			 <td class="right_align">0.00</td>
			<?php }
			if ($tp == 'income'){
				$tot_amounts += $amunt;
				?>
            <td class="right_align"><?php echo $this->sma->formatMoney($amunt); ?></td>
			<?php }	else{ ?>
			 <td class="right_align">0.00</td>
			<?php } ?>
		  </tr><?php }}?>
		   <thead class="thead-light">
          <tr>
            <th colspan="3" style="text-align:  left;"><b>Income</b></th>
          </tr>
        </thead>
		<?php //print_r($invse);
				 
		  foreach ($trial as $prof)
		  {
			$categry = $prof->category;
			$tp = $prof->type;
			$amunt = $prof->amount;			
			$condition =  $this->db->get_where('type' , array('id' =>$prof->acc_type))->row()->account_category; ?>
		 
          <tbody>
		   <?php //$condition =  $this->db->get_where('type' , array('id' =>$prof->acc_type))->row()->account_category; ?>
		 <?php if($condition == 4){ ?>
		   <tr>
				  
		
            <td style="width:34%;"><b><?php echo $this->db->get_where('accounts' , array('id' =>$prof->category))->row()->Name; ?></b></td>
			<?php if ($tp == 'expense'){ 
			$to_amount += $amunt;
			?>
		  <td class="right_align"><?php echo $this->sma->formatMoney($amunt); ?></td>
			<?php }
			else{ ?>
			 <td class="right_align">0.00</td>
			<?php }
			if ($tp == 'income'){
				$tot_amounts += $amunt;
				?>
            <td class="right_align"><?php echo $this->sma->formatMoney($amunt); ?></td>
			<?php }	else{ ?>
			 <td class="right_align">0.00</td>
			<?php } ?>
		  </tr><?php }}?>
		   <thead class="thead-light">
          <tr>
            <th colspan="3" style="text-align:  left;"><b>Equity</b></th>
          </tr>
        </thead>
		<?php //print_r($invse);
				 
		  foreach ($trial as $prof)
		  {
			$categry = $prof->category;
			$tp = $prof->type;
			$amunt = $prof->amount;			
			$condition =  $this->db->get_where('type' , array('id' =>$prof->acc_type))->row()->account_category; ?>
		 
          <tbody>
		   <?php //$condition =  $this->db->get_where('type' , array('id' =>$prof->acc_type))->row()->account_category; ?>
		 <?php if($condition == 6){ ?>
		   <tr>
				  
		
            <td style="width:34%;"><b><?php echo $this->db->get_where('accounts' , array('id' =>$prof->category))->row()->Name; ?></b></td>
			<?php if ($tp == 'expense'){ 
			$to_amount += $amunt;
			?>
		  <td class="right_align"><?php echo $this->sma->formatMoney($amunt); ?></td>
			<?php }
			else{ ?>
			 <td class="right_align">0.00</td>
			<?php }
			if ($tp == 'income'){
				$tot_amounts += $amunt;
				?>
            <td class="right_align"><?php echo $this->sma->formatMoney($amunt); ?></td>
			<?php }	else{ ?>
			 <td class="right_align">0.00</td>
			<?php } ?>
		  </tr><?php }}?>
        <!--<tbody>
		 <?php //print_r($invse);
		  foreach ($trial as $rowqq){
			  	$invseetqq = $rowqq->category;
				//$a = $this->db->get_where('accounts' , array('id' =>$invseet))->row()->type;
				//$cat = $this->db->get_where('type' , array('id' =>$a))->row()->name;
				
				//print_r($cat);
				
				
		   if(($rowqq->category == '14')||($rowqq->category == '15')||($rowqq->category == '16')||($rowqq->category == '17')||($rowqq->category == '18')||($rowqq->category == '19')||($rowqq->category == '20')||($rowqq->category == '21')||($rowqq->category == '22')||($rowqq->category == '23')||($rowqq->category == '24')||($rowqq->category == '25')){
			  $equitqq+= $rowqq->amount; //print_r($tot);
		 
		  }
		  
		  
		  }
			
			
		  ?>
          <tr>
            <td style="width: 67%;">Total Expenses</td>
            <td class="right_align"><?php echo $this->sma->formatQuantity($equitqq); ?></td>
            <td class="right_align">00.00</td>
          </tr>
        </tbody>-->
        <!--<thead class="thead-light">
          <tr>
           <th style="width: 66%;text-align: left; background-color: white;color: #0808089e;">Profit/Loss</th>
           <th class="right_align" style=" background-color: white;color: #0808089e;"><b>00.00</b></th>
           <th class="right_align" style=" background-color: white;color: #0808089e;"><b><?php echo $this->sma->formatQuantity($profits); ?></b></th>
         </tr>
       </thead>-->
	   <?php
			
			  $value =  $tot_amounts - $to_amount;
			 $debit = $equitqq + $value ;
			 $credits = $credit + $balanos + $equitq;
			 //$to_amount = $to_amount +  $value;
		?>
       <thead class="thead-light">
        <tr>
         <th style="width: 57%;text-align: left;">Total for all accounts</th>
         <th style="text-align:right;"><b><?php echo $this->sma->formatQuantity($to_amount); ?></b></th>
         <th style="text-align:right;"><b><?php echo $this->sma->formatQuantity($tot_amounts); ?></b></th>
       </tr>
     </thead>
   </table>
 </div>
</div> 
</page>
</div>
 </div>
</div>
 </div>

  <!---details_end-->

