<?php defined('BASEPATH') OR exit('No direct script access allowed'); 
//print_r($invs);die();
ini_set('display_errors', 1);
error_reporting(E_ALL);
//print_r($paisa); die();
?>
<style>
  body{
    margin: 0;
    padding: 0;
  }
  page {
    background: white;
    padding: 10px;
    display: block;
    margin: 0 auto;
    margin-bottom: 0.5cm;
    box-shadow: rgba(0, 0, 0, 0.22) 0px 2px 44px 0px;
  }
  .container{
    width: auto;
  }
  a:hover,a:focus{
    text-decoration: none;
    outline: none;
  }
  .right_float {
    float: right;
  }
  .table {
    width: 100%;
    max-width: 100%;
    margin-bottom: 0px;
  }
  .header_sec .page_head{
    font-weight: 600;
    font-size: 24px;
  }
  .company_name {
    font-size: 15px;
    font-weight: 600;
  }
  .date_1 {
    font-size: 14px;
    margin-bottom: 20px;
  }
  .date_2{
    margin-bottom: 10px;
  }
  .value{
    position: absolute;
    right: 70px;
  }
  div.tab {
    overflow: hidden;
  }
  div.tab button {
    background-color: inherit;
    float: left;
    outline: none;
    cursor: pointer;
    padding:5px 10px;
    transition: 0.3s;
    font-size: 17px;
    border: 2px solid #428bca;
    margin-right: 5px;
    margin: 5px;
  }
  div.tab button:hover {
    background-color: #428bca;
    color: #fff;
  }
  div.tab button.active {
    background-color: #428bca;
    color: #fff;
  }
  .tabcontent {
    display: none;
    padding: 6px 12px;
    border-top: none;
  }
  .button {
    position: relative;
    background-color: #000000;
    border: none;
    font-size: 28px;
    color: #FFFFFF;
    padding: 20px;
    width: 200px;
    text-align: center;
    -webkit-transition-duration: 0.4s; 
    transition-duration: 0.4s;
    text-decoration: none;
    overflow: hidden;
    cursor: pointer;
  }
  .button:after {
    content: "";
    background: #90EE90;
    display: block;
    position: absolute;
    padding-top: 300%;
    padding-left: 350%;
    margin-left: -20px!important;
    margin-top: -120%;
    opacity: 0;
    transition: all 0.8s
  }
  .button:active:after {
    padding: 0;
    margin: 0;
    opacity: 1;
    transition: 0s
  }
  .thead-light th{
    background: #428BCA;
    color: #fff;
    font-size: 14px !important;
  }
  .text-right{
    text-align: right !important;
  }  
  @media print {
    .no-print
    {
      display: none !important;
    }
  }
</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('Balance'); ?> <?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 class="box-icon">
            <ul class="btn-tasks">
                <li class="dropdown">
                    <a href="#" id="xls" class="tip" title="<?= lang('download_xls') ?>">
                        <i class="icon fa fa-file-excel-o"></i>
                    </a>
                </li>
                <li class="dropdown">
                    <a href="#" id="image" class="tip" title="<?= lang('save_image') ?>">
                        <i class="icon fa fa-file-picture-o"></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/Balance"); ?>
					<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">
			<div class="container">
				<div class="header_sec col-md-12">
					<div class="col-md-6">
						<span class="page_head">BALANCE SHEET</span>
					</div>
					<div class="col-md-6 text-right">
						<button type="button" class="no-print btn btn-primary" onclick="window.print();">Print</button>
					</div>
					<span class="col-md-12 company_name"><?php echo $created_by->company; ?></span>
					<div class="col-md-12 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 class="col-md-12 date_2">
						<span><b>ACCOUNTS</b></span>
						<span class="right_float"><?= lang("date"); ?>: <?= $this->sma->hrld(date('Y-m-d H:i:s')); ?></span>
					</div>
				</div>
				<div class="col-md-12">
					<div class="tab">
						<button class="tablinks no-print" onclick="Tools(event, 'Summary')">Summary</button>
						<button class="tablinks no-print" onclick="Tools(event, 'Detail')">Detail Report</button>
					</div>
					<div id="Summary" class="tabcontent">
					<table class="table">
						<thead class="thead-light">
							<tr>
								<th colspan="2"><b>Assets</b></th>
							</tr>
						</thead>
						<tbody>
						<?php 
								$amounted = $amountse = $amountede = $amountsee = $val= $vale = $value = $o_c_a = $ot_cu_as = $oth_cur_ass = $othe_curr_asse = $other_curre_asset = $other_curren_asset = $other_current_asset = $others_current_asset = $others_currents_asset = $others_currents_assets = $thers_currents_assets =  $thers_urrents_assets = $other_current_assets = $l_t_a = $lo_te_as = $lon_ter_ass = $long_term_asse = $long_term_asset = $long_term_assets = $long_terms_assets = $longs_terms_assets = $ongs_erms_ssets = $longs_erms_ssets = $bal = $balan = 0;
								foreach ($sheet as $row2)
								{
									if((($row2->account) == '5')&&(($row2->type) == 'income'))
									{
										$amounted+= $row2->amount;  
									}
									if((($row2->account) == '4')&&(($row2->type) == 'income'))
									{
										$amountse+= $row2->amount;  
									}
									if((($row2->account) == '5')&&(($row2->type) == 'expense'))
									{
										$amountede+= $row2->amount;  
									}
									if((($row2->account) == '4')&&(($row2->type) == 'expense'))
									{
										$amountsee+= $row2->amount;  
									}
									$val =  $amounted + $amountse;
									$vale = $amountede + $amountsee;
									$value =$val - $vale; 
									if(($row2->acc_type =='7')&&($row2->type =='income'))
									{
										$o_c_a+= $row2->amount;
									}
									if(($row2->acc_type =='7')&&($row2->type =='expense'))
									{
										$ot_cu_as+= $row2->amount;
									}
									$oth_cur_ass = $ot_cu_as - $o_c_a; 
									if(($row2->acc_type =='8')&&($row2->type =='income'))
									{
										$othe_curr_asse+= $row2->amount;
									}
									if(($row2->acc_type =='8')&&($row2->type =='expense'))
									{
										$other_curre_asset+= $row2->amount;
									}
									$other_curren_asset =  $other_curre_asset - $othe_curr_asse ;
									if(($row2->acc_type =='11')&&($row2->type =='income'))
									{
										$other_current_asset+= $row2->amount;
									}
									if(($row2->acc_type =='11')&&($row2->type =='expense'))
									{
										$others_current_asset+= $row2->amount;
									}
									$others_currents_asset =  $others_current_asset - $other_current_asset ;
									if(($row2->acc_type =='12')&&($row2->type =='income'))
									{
										$others_currents_assets+= $row2->amount;
									}
									if(($row2->acc_type =='12')&&($row2->type =='expense'))
									{
										$thers_currents_assets+= $row2->amount;
									}
									$thers_urrents_assets =  $thers_currents_assets - $others_currents_assets ;
									$other_current_assets = $oth_cur_ass + $other_curren_asset + $others_currents_asset + $thers_urrents_assets;
									if(($row2->acc_type =='9')&&($row2->type =='income'))
									{
										$l_t_a+= $row2->amount;
									}					
									if(($row2->acc_type =='9')&&($row2->type =='expense'))
									{
										$lo_te_as+= $row2->amount;
									}
									$lon_ter_ass =    $lo_te_as - $l_t_a  ; 
									if(($row2->acc_type =='10')&&($row2->type =='income'))
									{
										$long_term_asse+= $row2->amount;
									}
									if(($row2->acc_type =='10')&&($row2->type =='expense'))
									{
										$long_term_asset+= $row2->amount;
									}
									$long_term_assets =    $long_term_asset - $long_term_asse  ; 
									if(($row2->acc_type =='13')&&($row2->type =='income'))
									{
										$long_terms_assets+= $row2->amount;
									}
									if(($row2->acc_type =='13')&&($row2->type =='expense'))
									{
										$longs_terms_assets+= $row2->amount;
									}
									$ongs_erms_ssets =    $longs_terms_assets - $long_terms_assets ;
									$longs_erms_ssets = $lon_ter_ass + $long_term_assets  + $ongs_erms_ssets;
								}
								$bal = $other_current_assets + $longs_erms_ssets;
								$balan = $value + $bal;
						?>
						<tr>
							<td>Total Cash and Bank</td>
							<?php if($value)
							{?>
								<td class="text-right"><?= $value;?></td>
							<?php 
							} 
							else
							{?>
								<td class="text-right">0.00</td>
							<?php 
							} ?>
						</tr>
						<tr>
							<td>Total Other Current Assets</td>
							<?php if($other_current_assets)
									{?>
										<td class="text-right"><?= $other_current_assets;?></td>
							<?php 
									} 
									else
									{?>
										<td class="text-right">0.00</td>
							<?php 
									} ?>
						</tr>
						<tr>
							<td>Total Long-term Assets</td>
							<?php if($longs_erms_ssets)
									{?>
										<td class="text-right"><?= $longs_erms_ssets;?></td>
							<?php 
									} 
									else
									{?>
										<td class="text-right">0.00</td>
							<?php 
									} ?>
						</tr>
			
						<tr class="net_value">
							<td><b>Total Assets</b></td>
							<?php if($balan)
							{?>
								<td class="text-right"><?= $balan;?></td>
							<?php 
							} 
							else
							{?>
								<td class="text-right">0.00</td>
							<?php 
							} ?>
						</tr>
						</tbody>
					</table>
					<table class="table">
						<thead class="thead-light">
						<tr>
							<th colspan="2"><b>Liabilities</b></th>
						</tr>
						</thead>
						<tbody>
						<?php
							$c_l = $cu_li = $cur_lia = $curr_liab = $curre_liabi = $curren_liabil = $current_liabili = $current_liabilit = $current_liability = $currents_liability = $current_liabiliti = $current_liabilities = $urrent_iabilities = $rrent_abilities = $current_abilities = $t_l_l = $to_lo_li = $tot_lon_lia = $total_long_liabilities = $liabl= $incos = $incose=0;
							foreach ($sheet as $row)
							{
								if(($row->acc_type =='16')&&($row->type =='income'))
								{
									$c_l+= $row->amount;
								}
								if(($row->acc_type =='16')&&($row->type =='expense'))
								{
									$cu_li+= $row->amount;
								}
								$cur_lia = $c_l - $cu_li ;
								if(($row->acc_type =='20')&&($row->type =='income'))
								{
									$curr_liab+= $row->amount;
								}
								if(($row->acc_type =='20')&&($row->type =='expense'))
								{
									$curre_liabi+= $row->amount;
								}
								$curren_liabil =  $curr_liab - $curre_liabi ;
								if(($row->acc_type =='21')&&($row->type =='income'))
								{
									$current_liabili+= $row->amount;
								}
								if(($row->acc_type =='21')&&($row->type =='expense'))
								{
									$current_liabilit+= $row->amount;
								}
								$current_liability =  $current_liabili -  $current_liabilit ;
								if(($row->acc_type =='22')&&($row->type =='income'))
								{
									$currents_liability+= $row->amount;
								}
								if(($row->acc_type =='22')&&($row->type =='expense'))
								{
									$current_liabiliti+= $row->amount;
								}
								$current_liabilities =  $currents_liability -  $current_liabiliti ;

					
					if(($row->acc_type =='23')&&($row->type =='income'))
					{
						$urrent_iabilities+= $row->amount;
					}
					if(($row->acc_type =='23')&&($row->type =='expense'))
					{
						$rrent_abilities+= $row->amount;
					}
					$current_abilities =  $urrent_iabilities -   $rrent_abilities ; 
					$total_current_liabilities =  $cur_lia + $curren_liabil + $current_liability  + $current_liabilities + $current_abilities ;

					
					if(($row->acc_type =='24')&&($row->type =='income'))
					{
						$t_l_l+= $row->amount;
					}
					if(($row->acc_type =='24')&&($row->type =='expense'))
					{
						$to_lo_li+= $row->amount;
					}
					$tot_lon_lia = $t_l_l - $to_lo_li ; 
				}
			
				$total_long_liabilities = $total_current_liabilities  +  $tot_lon_lia;
			?>
			<tr>
				<td>Total Current Liabilities</td>
				<?php if($total_current_liabilities)
				{?>
					<td class="text-right"><?=$total_current_liabilities;?></td>
				<?php 
				} 
				else
				{?>
					<td class="text-right">0.00</td>
				<?php 
				} ?>
            </tr>
			<tr>
				<td>Total Long-term Liabilities</td>
				<?php if( $tot_lon_lia)
				{?>
					<td class="text-right"><?=  $tot_lon_lia;?></td>
				<?php 
				} 
				else
				{?>
				<td class="text-right">0.00</td>
				<?php 
				} ?>
            </tr>
            <tr>
				<td>Other</td>
				<?php 
				if($liabl)
				{?>
					<td class="text-right"><?=  $liabl;?></td>
				<?php 
				} 
				else
				{?>
					<td class="text-right">0.00</td>
				<?php 
				} ?>
            </tr>
            <tr class="net_value">
				<td><b>Total Liabilities</b></td>
				<?php if( $total_long_liabilities)
				{?>
					<td class="text-right"><?=  $total_long_liabilities;?></td>
				<?php 
				} 
				else
				{?>
					<td class="text-right">0.00</td>
				<?php 
				} ?>
            </tr>
        </tbody>
    </table>
    <table class="table">
        <thead class="thead-light">
            <tr>
				<th colspan="2"><b>Equity</b></th>
            </tr>
        </thead>
        <tbody>
            <?php
				$equit = $equity = $balanos = $tot_eq =0;
				foreach ($sheet as $rowz)
				{
					if(($rowz->acc_type == '17'))
					{
						$equit+= $rowz->amount; 
					}
					if(($rowz->acc_type == '29'))
					{
						$equity+= $rowz->amount; 
		 
					}
		  
				}
				$balanos = $equit+$equity;
			?>
            <tr>
				<td>Total Other Equity</td>
				<?php if( $equit)
				{?>
					<td class="text-right"><?=  $equit;?></td>
				<?php 
				} 
				else
				{?>
					<td class="text-right">0.00</td>
				<?php 
				} ?>
            </tr>
			<?php 
				$p_type = $p_typs = $purchase_sold = $operating = $p_inc = $p_incos = $p_incose = $p_expect_inco =$p_incoss = $p_incosee = $p_expects_incos = $p_incoos = $p_incoose = $p_expecto_incoo = $p_inco = $gross_profit = $percentage = $percent = $cross_profit = $cros_percentage = $cros_percent = $profit_loss = 0;
				foreach ($sheet as $pro)
				{ 
					if($pro->type =='income')
					{
						$p_type+= $pro->amount;
					}
					if($pro->type =='expense')
					{
						$p_typs+= $pro->amount;
					}
					if($pro->acc_type =='31')
					{
						$purchase_sold+= $pro->amount;
					}
					if(($pro->acc_type =='30')||($pro->acc_type =='32')|| ($pro->acc_type =='33')||($pro->acc_type =='34') || ($pro->acc_type =='35'))
					{
						$operating+= $pro->amount;
					}
				
					if(($pro->acc_type =='18')|| ($pro->acc_type =='26')||($pro->acc_type =='27') || ($pro->acc_type =='28')||($pro->acc_type =='32'))
					{
						$p_inc+= $pro->amount;
					}
					if(($pro->acc_type =='7')&&($pro->type =='income'))
					{
						$p_incos+= $pro->amount;
					}
					if(($pro->acc_type =='7')&&($pro->type =='expense'))
					{
						$p_incose+= $pro->amount;
					}
					$p_expect_inco = $incos -  $incose ;
			
			
					if(($pro->acc_type =='25')&&($pro->type =='income'))
					{
						$p_incoss+= $pro->amount;
					}
					if(($pro->acc_type =='25')&&($pro->type =='expense'))
					{
						$p_incosee+= $pro->amount;
					}
					$p_expects_incos = $p_incoss -  $p_incosee ;
					
					
					if(($pro->acc_type =='22')&&($pro->type =='income'))
					{
						$p_incoos+= $pro->amount;
					}
					if(($pro->acc_type =='22')&&($pro->type =='expense'))
					{
						$p_incoose+= $pro->amount;
					}
					$p_expecto_incoo = $p_incoos -  $p_incoose ;
					$p_inco = $p_inc +   $p_expect_inco +  $p_expects_incos + $p_incoose; 
			  
				}
			?>
			<?php 
					$gross_profit =  $p_inco - $purchase_sold;
					if($p_inco)
					{
						$percentage = $gross_profit / $p_inco ;
					}
					else
					{
						$percentage = 0;
					}				  
					$percent=  $percentage * 100;
			?>
			<?php 
					$cross_profit = $gross_profit - $operating;
					if($p_inco)
					{
						$cros_percentage = $cross_profit /  $p_inco;
					}
					else
					{
						$cros_percentage = 0;
					}
					$cros_percent = $cros_percentage * 100;
					$profit_loss = $equity +  $cross_profit;
			?>
			
            <tr>
				<td>Total Retained Earnings</td>
				<?php if($profit_loss)
				{?>
					<td class="text-right"><?=$profit_loss;?></td>
				<?php 
				} 
				else
				{?>
					<td class="text-right">0.00</td>
				<?php 
				} ?>
            </tr>
			<tr class="net_value">
				<td><b>Total Equity</b></td>
				<?php 
					$tot_eq = $balanos + $profit_loss;
					if($tot_eq)
					{?>
						<td class="text-right"><?=$tot_eq;?></td>
					<?php 
					} 
					else
					{?>
						<td class="text-right">0.00</td>
					<?php 
					} ?>
            </tr>
        </tbody>
    </table>
</div>
<div id="Detail" class="tabcontent">
    <table class="table">
        <thead class="thead-light">
			<tr>
				<th colspan="2"><b>Assets</b></th>
			</tr>
        </thead>
		<?php //print_r($sheet);
			$amountedf = $amountsef = $amountedef = $amountseef = $valf = $valef = $vals = $vales = $valuef = $o_c_af = $ot_cu_asf = $oth_cur_assf = $othe_curr_assef = $other_curre_assetf = $other_curren_assetf = $other_current_assetf = $others_current_assetf = $others_currents_assetf = $others_currents_assetsf = $thers_currents_assetsf = $thers_urrents_assetsf = $other_current_assetsf = $l_t_af = $lo_te_asf = $lon_ter_assf = $long_term_assef = $long_term_assetf = $long_term_assetsf = $long_terms_assetsf = $longs_terms_assetsf = $ongs_erms_ssetsf = $longs_erms_ssetsf = $tot_asst = 0;
			foreach ($sheet as $rowf)
			{
				if((($rowf->account) == '5')&&(($rowf->type) == 'income'))
				{
					$amountedf+= $rowf->amount;  //print_r( $amountedf);
				}
				if((($rowf->account) == '4')&&(($rowf->type) == 'income'))
				{
					$amountsef+= $rowf->amount;  
				}
				if((($rowf->account) == '5')&&(($rowf->type) == 'expense'))
				{
					$amountedef+= $rowf->amount;  //print_r( $amountede);
				}
				if((($rowf->account) == '4')&&(($rowf->type) == 'expense'))
				{
					$amountseef+= $rowf->amount;  
				}
				$valf =  $amountedf -  $amountedef;
				$valef = $amountsef -  $amountseef;
				$vals =  $amountedf + $amountsef;
				$vales = $amountedef + $amountseef;
				$valuef =$vals - $vales; 
			   
			}
		?>
        <tbody>
			<tr>
                <th colspan="2" class="light_clr"><b>Cash and Bank</b></th>
            </tr>
			<tr>
				<td>Cash on Bank</td>
				<?php if($valf)
				{?>
					<td class="text-right"><?=$valf;?></td>
				<?php 
				} 
				else
				{?>
					<td class="text-right">0.00</td>
				<?php 
				} ?>
               
            </tr>
			<tr>
				<td>Cash on Hand</td>
				<?php if($valef)
				{?>
					<td class="text-right"><?=$valef;?></td>
				<?php 
				} 
				else
				{?>
					<td class="text-right">0.00</td>
				<?php 
				} ?>
               
            </tr>
            <tr>
				<td>Total Cash and Bank</td>
				<?php 
					if($valuef)
					{?>
						<td class="text-right"><?=$valuef;?></td>
						<?php 
					} 
					else
					{?>
						<td class="text-right">0.00</td>
						<?php 
					} 
				?>
            </tr>
			<tr>
				<th colspan="2" class="light_clr"><b>Other Current Assets</b></th>
				<?php
					foreach ($sheet as $rowo)
					{
						if(($rowo->acc_type =='7')&&($rowo->type =='income'))
						{
							$o_c_af+= $rowo->amount;
						}
						if(($rowo->acc_type =='7')&&($rowo->type =='expense'))
						{
							$ot_cu_asf+= $rowo->amount;
						}
						$oth_cur_assf = $ot_cu_asf - $o_c_af;
				?>
				<?php 
					if(($rowo->acc_type =='7')&&($rowo->type =='income'))
					{ 
				?>
				<tr>
						<td>
							<?php 
								echo $this->db->get_where('accounts',array('type' =>'7'))->row()->Name;
							?>
						</td>
					
						<?php 
							if($o_c_af)
							{
						?>			<td class="text-right"><?=$o_c_af;?></td>
						<?php 
							} 
							else
							{
						?>		<td class="text-right">0.00</td>
						<?php 
							} 
						?>
				</tr>
				<?php 
					}
					if(($rowo->acc_type =='7')&&($rowo->type =='expense'))
					{
				?>
				<tr>
					<td>
						<?php 
							echo $this->db->get_Where('accounts',array('type' =>'7'))->row()->Name;
						?>
					</td>
					
					<?php 
					if($ot_cu_asf)
					{
					?>	<td class="text-right"><?=$ot_cu_asf;?></td>
					<?php 
					} 
					else
					{
					?>
						<td class="text-right">0.00</td>
					<?php 
					} 
					?>
				</tr>
					<?php 
					}
				} 
				?>
	<?php
		foreach ($sheet as $rowt)
		{
			if(($rowt->acc_type =='8')&&($rowt->type =='income'))
			{
				$othe_curr_assef+= $rowt->amount;
				//print_r( $invent);
			}
			if(($rowt->acc_type =='8')&&($rowt->type =='expense'))
			{
				$other_curre_assetf+= $rowt->amount;
				//print_r( $inventy);
			}
			$other_curren_assetf =  $other_curre_assetf - $othe_curr_assef ;

?>
<?php 
			if(($rowt->acc_type =='8')&&($rowt->type =='income'))
			{ 
?>
				<tr>
					<td><?php echo $this->db->get_where('accounts',array('type' =>'8'))->row()->Name;?></td>
					<td class="text-right"><?=$othe_curr_assef;?></td>
				</tr>
<?php 
			}
			if(($rowt->acc_type =='8')&&($rowt->type =='expense'))
			{
?>
				<tr>
					<td><?php echo $this->db->get_Where('accounts',array('type' =>'8'))->row()->Name;?></td>
					<td class="text-right"><?=$other_curre_assetf;?></td>
				</tr>
<?php 
			}
		} 
?>
<?php
		foreach ($sheet as $rowtw)
		{
			if(($rowtw->acc_type =='11')&&($rowtw->type =='income'))
			{
				$other_current_assetf+= $rowtw->amount;
				//print_r( $invent);
			}
			if(($rowtw->acc_type =='11')&&($rowtw->type =='expense'))
			{
				$others_current_assetf+= $rowtw->amount;
			}
			$others_currents_assetf =  $others_current_assetf - $other_current_assetf ;


?>
<?php 
			if(($rowtw->acc_type =='11')&&($rowtw->type =='income'))
			{ 
?>
				<tr>
					<td><?php echo $this->db->get_where('accounts',array('type' =>'11'))->row()->Name;?></td>
					<td class="text-right"><?=$other_current_assetf;?></td>
				</tr>
<?php 
			}
			if(($rowtw->acc_type =='11')&&($rowtw->type =='expense'))
			{
?>
				<tr>
					<td><?php echo $this->db->get_Where('accounts',array('type' =>'11'))->row()->Name;?></td>
					<td class="text-right"><?=$others_current_assetf;?></td>
				</tr>
<?php 
			}
		} 
?>
<?php
		foreach ($sheet as $rowtwo)
		{
			if(($rowtwo->acc_type =='12')&&($rowtwo->type =='income'))
			{
				$others_currents_assetsf+= $rowtwo->amount;
				//print_r( $invent);
			}
			if(($rowtwo->acc_type =='12')&&($rowtwo->type =='expense'))
			{
				$thers_currents_assetsf+= $rowtwo->amount;
			}
			$thers_urrents_assetsf =  $thers_currents_assetsf - $others_currents_assetsf ;
			

?>
<?php 
			if(($rowtwo->acc_type =='12')&&($rowtwo->type =='income'))
			{ 
?>
				<tr>
					<td><?php echo $this->db->get_where('accounts',array('type' =>'12'))->row()->Name;?></td>
					<td class="text-right"><?=$other_current_assetf;?></td>
				</tr>
<?php 
			}
			if(($rowtwo->acc_type =='12')&&($rowtwo->type =='expense'))
			{
?>
				<tr>
					<td><?php echo $this->db->get_where('accounts',array('type' =>'12'))->row()->Name;?></td>
					<td class="text-right"><?=$others_current_assetf;?></td>
				</tr>
<?php 
			}
		} 

$other_current_assetsf = $oth_cur_assf + $other_curren_assetf + $others_currents_assetf + $thers_urrents_assetsf;
?>
			</tr>
			<tr>
                <td>Total Other Current Assets</td>
                <td class="text-right"><?=$other_current_assetsf;?></td>
              </tr>
			  <tr>
                <th colspan="2" class="light_clr"><b>Long-term Assets</b></th>
                </tr>
				<?php
		foreach ($sheet as $rowon)
		{
			if(($rowon->acc_type =='9')&&($rowon->type =='income'))
			{
				$l_t_af+= $rowon->amount;
			}
			if(($rowon->acc_type =='9')&&($rowon->type =='expense'))
			{
				$lo_te_asf+= $rowon->amount;
			}
			$lon_ter_assf =    $lo_te_asf - $l_t_af  ; //print_r( $propl);

?>
<?php 
			if(($rowon->acc_type =='9')&&($rowon->type =='income'))
			{ 
?>
				<tr>
					<td><?php echo $this->db->get_where('accounts',array('type' =>'9'))->row()->Name;?></td>
					<td class="text-right"><?=$l_t_af;?></td>
				</tr>
<?php 
			}
			if(($rowon->acc_type =='9')&&($rowon->type =='expense'))
			{
?>
				<tr>
					<td><?php echo $this->db->get_Where('accounts',array('type' =>'9'))->row()->Name;?></td>
					<td class="text-right"><?=$lo_te_asf;?></td>
				</tr>
<?php 
			}
		} 
?>
<?php
		foreach ($sheet as $rowth)
		{
			
			if(($rowth->acc_type =='10')&&($rowth->type =='income'))
			{
				$long_term_assef+= $rowth->amount;
				// print_r( $invent);
			}
			if(($rowth->acc_type =='10')&&($rowth->type =='expense'))
			{
				$long_term_assetf+= $rowth->amount;
			}
			$long_term_assetsf =    $long_term_assetf - $long_term_assef  ; 
			

?>
<?php 
			if(($rowth->acc_type =='10')&&($rowth->type =='income'))
			{ 
?>
				<tr>
					<td><?php echo $this->db->get_where('accounts',array('type' =>'10'))->row()->Name;?></td>
					<td class="text-right"><?=$long_term_assef;?></td>
				</tr>
<?php 
			}
			if(($rowth->acc_type =='10')&&($rowth->type =='expense'))
			{
?>
				<tr>
					<td><?php echo $this->db->get_Where('accounts',array('type' =>'10'))->row()->Name;?></td>
					<td class="text-right"><?=$long_term_assetf;?></td>
				</tr>
<?php 
			}
		} 
?>
<?php
		foreach ($sheet as $rowth)
		{
			
			if(($row2->acc_type =='13')&&($row2->type =='income'))
			{
				$long_terms_assetsf+= $row2->amount;
				//print_r( $invent);
			}
			if(($row2->acc_type =='13')&&($row2->type =='expense'))
			{
				$longs_terms_assetsf+= $row2->amount;
			}
			$ongs_erms_ssetsf =    $longs_terms_assetsf - $long_terms_assetsf ;

?>
<?php 
			if(($rowth->acc_type =='13')&&($rowth->type =='income'))
			{ 
?>
				<tr>
					<td><?php echo $this->db->get_where('accounts',array('type' =>'13'))->row()->Name;?></td>
					<td class="text-right"><?=$long_terms_assetsf;?></td>
				</tr>
<?php 
			}
			if(($rowth->acc_type =='13')&&($rowth->type =='expense'))
			{
?>
				<tr>
					<td><?php echo $this->db->get_Where('accounts',array('type' =>'13'))->row()->Name;?></td>
					<td class="text-right"><?=$longs_terms_assetsf;?></td>
				</tr>
<?php 
			}
		}
$longs_erms_ssetsf = $lon_ter_assf + $long_term_assetsf  + $ongs_erms_ssetsf;		
?>
              <tr>
			 <td>Total Long-term Assets</td>
                <td class="text-right"><?=$longs_erms_ssetsf?></td>
              </tr>
			  <?php $tot_asst = $valuef + $other_current_assetsf + $longs_erms_ssetsf;?>
              <tr class="net_value">
                <td><b>Total Assets</b></td>
                <?php if($tot_asst)
				{?>
					<td class="text-right"><?=$tot_asst;?></td>
				<?php 
				} 
				else
				{?>
					<td class="text-right">0.00</td>
				<?php 
				} ?>
              </tr>
            </tbody>
    </table>
    <table class="table">
        <thead class="thead-light">
            <tr>
				<th colspan="2"><b>Liabilities</b></th>
            </tr>
        </thead>
        <tbody>
			<?php
			$c_lf = $cu_lif = $cur_liaf = $curr_liabf = $curre_liabif = $curren_liabilf = $current_liabilif = $current_liabilitf = $current_liabilityf = $currents_liabilityf = $current_liabilitif = $current_liabilitiesf = $urrent_iabilitiesf = $rrent_abilitiesf = $current_abilitiesf = $total_current_liabilitiesf = $t_l_lf = $to_lo_lif = $tot_lon_liaf  = $total_long_liabilitiesf = 0; 
			foreach ($sheet as $rowos)
			{
				if(($rowos->acc_type =='16')&&($rowos->type =='income'))
				{
					$c_lf+= $rowos->amount;
				}
				if(($rowos->acc_type =='16')&&($rowos->type =='expense'))
				{
					$cu_lif+= $rowos->amount;
				}
				$cur_liaf = $c_lf - $cu_lif ;
				?>
				<?php 
				if(($rowos->acc_type =='16')&&($rowos->type =='income'))
				{ 
				?>
					<tr>
						<td><?php echo $this->db->get_where('accounts',array('type' =>'16'))->row()->Name;?></td>
						<td class="text-right"><?=$c_lf;?></td>
					</tr>
				<?php 
				}
				if(($rowos->acc_type =='16')&&($rowos->type =='expense'))
				{
				?>
					<tr>
						<td><?php echo $this->db->get_Where('accounts',array('type' =>'16'))->row()->Name;?></td>
						<td class="text-right"><?=$cu_lif;?></td>
					</tr>
				<?php 
				}
		
			} 
			?>
			<?php
			foreach ($sheet as $rowost)
			{
				if(($rowost->acc_type =='20')&&($rowost->type =='income'))
				{
					$curr_liabf+= $rowost->amount;
				}
				if(($rowost->acc_type =='20')&&($rowost->type =='expense'))
				{
					$curre_liabif+= $rowost->amount;
				}
				$curren_liabilf =  $curr_liabf - $curre_liabif ;

				?>
				<?php 
				if(($rowost->acc_type =='20')&&($rowost->type =='income'))
				{ 
				?>
					<tr>
						<td><?php echo $this->db->get_where('accounts',array('type' =>'20'))->row()->Name;?></td>
						<td class="text-right"><?=$curr_liabf;?></td>
					</tr>
				<?php 
				}
				if(($rowost->acc_type =='20')&&($rowost->type =='expense'))
				{
				?>
					<tr>
						<td><?php echo $this->db->get_Where('accounts',array('type' =>'20'))->row()->Name;?></td>
						<td class="text-right"><?=$curre_liabif;?></td>
					</tr>
				<?php 
				}
			} 
			?>

			<?php
			foreach ($sheet as $rowost)
			{
				if(($row->acc_type =='21')&&($row->type =='income'))
				{
					$current_liabilif+= $row->amount;
				}
				if(($row->acc_type =='21')&&($row->type =='expense'))
				{
					$current_liabilitf+= $row->amount;
				}
				$current_liabilityf =  $current_liabilif -  $current_liabilitf ;

				?>
				<?php 
				if(($rowost->acc_type =='21')&&($rowost->type =='income'))
				{ 
				?>
					<tr>
						<td><?php echo $this->db->get_where('accounts',array('type' =>'21'))->row()->Name;?></td>
						<td class="text-right"><?=$current_liabilif;?></td>
					</tr>
				<?php 
				}
				if(($rowost->acc_type =='21')&&($rowost->type =='expense'))
				{
				?>
					<tr>
						<td><?php echo $this->db->get_Where('accounts',array('type' =>'21'))->row()->Name;?></td>
						<td class="text-right"><?=$current_liabilitf;?></td>
					</tr>
				<?php 
				}
			} 
			?>

			<?php
			foreach ($sheet as $rowoster)
			{
				if(($rowoster->acc_type =='22')&&($rowoster->type =='income'))
				{
					$currents_liabilityf+= $rowoster->amount;
				}
				if(($rowoster->acc_type =='22')&&($rowoster->type =='expense'))
				{
					$current_liabilitif+= $rowoster->amount;
				}
				$current_liabilitiesf =  $currents_liabilityf -  $current_liabilitif ;
		
				?>
				<?php 
				if(($rowoster->acc_type =='22')&&($rowoster->type =='income'))
				{ 
				?>
					<tr>
						<td><?php echo $this->db->get_where('accounts',array('type' =>'22'))->row()->Name;?></td>
						<td class="text-right"><?=$currents_liabilityf;?></td>
					</tr>
				<?php 
				}
				if(($rowoster->acc_type =='22')&&($rowoster->type =='expense'))
				{
				?>
					<tr>
						<td><?php echo $this->db->get_Where('accounts',array('type' =>'22'))->row()->Name;?></td>
						<td class="text-right"><?=$current_liabilitif;?></td>
					</tr>
				<?php 
				}
			} 
		?>

		<?php
			foreach ($sheet as $rowosti)
			{
				if(($rowosti->acc_type =='23')&&($rowosti->type =='income'))
				{
					$urrent_iabilitiesf+= $rowosti->amount;
				}
				if(($rowosti->acc_type =='23')&&($rowosti->type =='expense'))
				{
					$rrent_abilitiesf+= $rowosti->amount;
				}
				$current_abilitiesf =  $urrent_iabilitiesf -   $rrent_abilitiesf ; 


		?>
		<?php 
				if(($rowosti->acc_type =='23')&&($rowosti->type =='income'))
				{ 
		?>
					<tr>
						<td><?php echo $this->db->get_where('accounts',array('type' =>'23'))->row()->Name;?></td>
						<td class="text-right"><?=$urrent_iabilitiesf;?></td>
					</tr>
		<?php 
				}
				if(($rowosti->acc_type =='23')&&($rowosti->type =='expense'))
				{
		?>
					<tr>
						<td><?php echo $this->db->get_Where('accounts',array('type' =>'23'))->row()->Name;?></td>
						<td class="text-right"><?=$rrent_abilitiesf;?></td>
					</tr>
		<?php 
				}
			} 
			$total_current_liabilitiesf =  $cur_liaf + $curren_liabilf + $current_liabilityf  + $current_liabilitiesf + $current_abilitiesf ;

		?>

			<tr>
				<th colspan="2" class="light_clr"><b>Current Liabilities</b></th>
            </tr>
            <tr>
				<td>Total Current Liabilities</td>
				<td class="text-right"><?=$total_current_liabilitiesf;?></td>
            </tr>
			<tr>
				<th colspan="2" class="light_clr"><b>Long-term Liabilities</b></th>
            </tr>
			<?php
			foreach ($sheet as $rowosx)
			{
				if(($rowosx->acc_type =='24')&&($rowosx->type =='income'))
				{
					$t_l_lf+= $rowosx->amount;
					//print_r( $invent);
				}
				if(($rowosx->acc_type =='24')&&($rowosx->type =='expense'))
				{
					$to_lo_lif+= $rowosx->amount;
				}
				$tot_lon_liaf = $t_l_lf - $to_lo_lif ; 
	
				?>
		<?php 
				if(($rowosx->acc_type =='24')&&($rowosx->type =='income'))
				{ 
		?>
					<tr>
						<td><?php echo $this->db->get_where('accounts',array('type' =>'24'))->row()->Name;?></td>
						<td class="text-right"><?=$t_l_lf;?></td>
					</tr>
		<?php 
				}
				if(($rowosx->acc_type =='24')&&($rowosx->type =='expense'))
				{
		?>
					<tr>
						<td><?php echo $this->db->get_Where('accounts',array('type' =>'24'))->row()->Name;?></td>
						<td class="text-right"><?=$to_lo_lif;?></td>
					</tr>
		<?php 
				}
		
			}
			$total_long_liabilitiesf = $total_current_liabilitiesf  +  $tot_lon_liaf;
		?>
            <tr>
				<td>Total Long-term Liabilities</td>
				<td class="text-right"><?=$tot_lon_liaf;?></td>
            </tr>
            <tr>
				<td>Other</td>
				<td class="text-right">0.00</td>
            </tr>
            <tr class="net_value">
				<td><b>Total Liabilities</b></td>
				<td class="text-right"><?=$total_long_liabilitiesf;?></td>
            </tr>
        </tbody>
    </table>
    <table class="table">
        <thead class="thead-light">
            <tr>
				<th><b>Equity</b></th>
				<th class="text-right">0.00</th>
            </tr>
        </thead>
        <tbody>
        <?php //print_r($sheet);
			$equit =$equity = $balanos = 0;
			foreach ($sheet as $rowz)
			{
				if(($rowz->acc_type == '17'))
				{
					$equit+= $rowz->amount; //print_r($equit);
				}
				if(($rowz->acc_type == '29'))
				{
					$equity+= $rowz->amount; 
				}
		  
			}
			$balanos = $equit+$equity;
		?>
        <tr>
            <td>Total Other Equity</td>
				<?php if($equit)
				{?>
					<td class="text-right"><?=  $equit;?></td>
				<?php 
				} 
				else
				{?>
					<td class="text-right">0.00</td>
				<?php 
				} ?>
        </tr>
		<?php 
		$p_type_a = $p_typs_a = $purchase_sold_a = $operating_a = $p_inc_a = $p_incos_a = $p_incose_a = $p_expect_inco_a =$p_incoss_a = $p_incosee_a = $p_expects_incos_a = $p_incoos_a = $p_incoose_a = $p_expecto_incoo_a = $p_inco_a = $gross_profit_a = $percentage_a = $percent_a = $cross_profit_a = $cros_percentage_a = $cros_percent_a = $profit_loss_a = 0;	
		foreach ($sheet as $pro)
		{ 
			if($pro->type =='income')
			{
				$p_type_a+= $pro->amount;
			}
			if($pro->type =='expense')
			{
			   $p_typs_a+= $pro->amount;
			   //print_r($p_typs);
			}
			if($pro->acc_type =='31')
			{
			    $purchase_sold_a+= $pro->amount;
				//print_r( $invent);
			}
			if(($pro->acc_type =='30')||($pro->acc_type =='32')|| ($pro->acc_type =='33')||($pro->acc_type =='34') || ($pro->acc_type =='35'))
			{
			    $operating_a+= $pro->amount;
				//print_r( $invent);
			}
			//print_r($cat);
			if(($pro->acc_type =='18')|| ($pro->acc_type =='26')||($pro->acc_type =='27') || ($pro->acc_type =='28')||($pro->acc_type =='32'))
			{
				$p_inc_a+= $pro->amount;
				//print_r($p_inc);
			}
			if(($pro->acc_type =='7')&&($pro->type =='income'))
			{
			   $p_incos_a+= $pro->amount;
			}
			if(($pro->acc_type =='7')&&($pro->type =='expense'))
			{
				$p_incose_a+= $pro->amount;
			}
			$p_expect_inco_a = $incos -  $incose ;
			
			if(($pro->acc_type =='25')&&($pro->type =='income'))
			{
				$p_incoss_a+= $pro->amount;
			}
			if(($pro->acc_type =='25')&&($pro->type =='expense'))
			{
			   $p_incosee_a+= $pro->amount;
			}
			   $p_expects_incos_a = $p_incoss -  $p_incosee ;
			   
			if(($pro->acc_type =='22')&&($pro->type =='income'))
			{
			   $p_incoos_a+= $pro->amount;
			}
			if(($pro->acc_type =='22')&&($pro->type =='expense'))
			{
				$p_incoose_a+= $pro->amount;
			}
			 $p_expecto_incoo_a = $p_incoos -  $p_incoose ;
			 
			
			$p_inco_a = $p_inc_a +   $p_expect_inco_a +  $p_expects_incos_a + $p_incoose_a; 
			  
		}
		//print_r($p_inc);
		?>
		<?php 
			$gross_profit_a =  $p_inco_a - $purchase_sold_a;
			if($p_inco_a)
			{
				$percentage_a = $gross_profit_a / $p_inco_a ;
			}
			else
			{
				$percentage_a = 0;
			}				  
			$percent_a=  $percentage_a * 100;
		?>
		<?php 
			$cross_profit_a = $gross_profit_a - $operating_a;
			if($p_inco_a)
			{
				$cros_percentage_a = $cross_profit_a /  $p_inco_a;
			}
			else
			{
				$cros_percentage_a = 0;
			}
			$cros_percent_a = $cros_percentage_a * 100;
			$profit_loss_a = $equity +  $cross_profit_a;
		?>
		<tr>
            <td>Total Retained Earnings</td>
				<?php if($profit_loss_a)
				{?>
					<td class="text-right"><?=$profit_loss_a;?></td>
				<?php 
				} 
				else
				{?>
					<td class="text-right">0.00</td>
				<?php 
				} ?>
        </tr>
		<tr class="net_value">
            <td><b>Total Equity</b></td>
            <?php 
			$tot_eq_a = $balanos + $profit_loss_a;
			if($tot_eq_a)
			{?>
				<td class="text-right"><?=$tot_eq_a;?></td>
			<?php 
			} 
			else
			{?>
				<td class="text-right">0.00</td>
			<?php 
			} ?>
        </tr>
        </tbody>
    </table>
</div>
</div>
</div>
</page>
</div>
</div>
</div>
</div>
<!--<script type="text/javascript" src="<?= $assets ?>js/html2canvas.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#pdf').click(function (event) {
            event.preventDefault();
            window.location.href = "<?=admin_url('reports/getSalesReport/pdf/?v=1'.$v)?>";
            return false;
        });
        $('#xls').click(function (event) {
            event.preventDefault();
            window.location.href = "<?=admin_url('reports/getSalesReport/0/xls/?v=1'.$v)?>";
            return false;
        });
        $('#image').click(function (event) {
            event.preventDefault();
            html2canvas($('.box'), {
                onrendered: function (canvas) {
                    openImg(canvas.toDataURL());
                }
            });
            return false;
        });
    });
</script>-->

<script>
  function Tools(evt, cityName) {
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
      tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
      tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById(cityName).style.display = "block";
    evt.currentTarget.className += " active";
  }
</script>