<?php



 include('function.php');

 

 include('db_con.php');

 accounts_update($connect);

 if (isset($_SESSION['user_id'])) {



        $user_type = $_SESSION['user_type'];

        $user_id = $_SESSION['user_id'];

        $user_name = $_SESSION['user_name'];

        $branch_id = $_SESSION['branch_id'];

        $branch_name = $_SESSION['branch_name'];

        $store_id = $_SESSION['store_id'];

        $store_name = $_SESSION['store_name'];

}else{

    header('Location: login');

    die();

}

 $html = '';

 

 $count = 0;

 date_default_timezone_set('Asia/Karachi');


  $tot_balance = 0;

  $dated = date('Y-m-d h:i:s a');

  

  $sql = "SELECT IFNULL(doc_status,'ON') FROM user_rights WHERE user_id = '".$user_id."' and doc_name = 'gl_reports_trial_balance'";

            $statement = $connect->prepare($sql);

            $statement->execute(); // no need to add `$sql` here, you can take that out

            $gl_reports_trial_balance = $statement->fetchColumn();



            if($gl_reports_trial_balance=='OFF'){header('Location: dashboard');}







    





  //$statement = $connect->prepare("select d.acc_no,a.acc_name, a.acc_type,sum(d.debit) as debit,

  //  sum(d.credit)as credit from jv_detail d, jv m,accounts a 

   // where m.jv_id=d.jv_id and a.acc_no=d.acc_no and m.dated between

  //  '".$fdate."' and '".$tdate."' and d.acc_no > 1037 group by acc_no,acc_name");



$statement = $connect->prepare("select a.acc_no,a.acc_name, a.balance

  from accounts_parent a where a.status = 'Active' and acc_type = 'Asset'
  order by acc_no");





 $statement->execute();

 

 $result = $statement->fetchAll(); 

 ?>



<!DOCTYPE html>

<html>

<head>

  <title>

  Balance Sheet

  </title>

  <style>

  .rightside {text-align: right;}

  table td{





    border-bottom: 1px solid gray;



  }

  </style>

</head>

<body>
 

  <table width="100%">

  <tr>

  <td colspan="10" style="text-align:center;font-size:18px;font-weight:bold;margin:5px">Balance Sheet as on <?php echo $dated;?></td>

  </tr>

  

  

  </table>

  <table width="100%" id="table_header">


<thead>
  <tr>

  <td width="3%">#</td>

  <td width="15%">Acc No.</td>

  <td width="67%">Account Name</td>

  

  

  

  <td width="15%"></td> 

  

  

  </tr>




</thead>
  
<tbody>

<tr>

<td colspan="4" width="100%"><b>Asset</b></td>

   

    

   </tr>

<?php

foreach($result as $row)

 {



  $balance = $row["balance"];
  

  $tot_balance = $tot_balance + $balance;



  

  $count = $count+1;





     // if($count == 1){$stock = $opening + $qty_in - $qty_out; }else{$stock = $stock + $qty_in - $qty_out;}

   

 echo '

  

    

  

  



<tr>

<td width="3%">'.$count.'</td>

  

  <td width="15%">'.$row["acc_no"].'</td>

<td width="67%">'.$row["acc_name"].'</td>




   <td width="15%" class="rightside">'.number_format($balance, 2).'</td>

   

  

  

   

    

   </tr>

   





        ';



}

?>

 <tr>

<td colspan="4" width="100%"><b>Liability</b></td>

   

    

   </tr>
   <?php

$statement = $connect->prepare("select a.acc_no,a.acc_name, a.balance

  from accounts_parent a where a.status = 'Active' and acc_type = 'Liability'
  order by acc_no");





 $statement->execute();

 

 $result = $statement->fetchAll(); 

 foreach($result as $row)

 {



  $balance = $row["balance"];
  

  $tot_balance = $tot_balance + $balance;



  

  $count = $count+1;





     // if($count == 1){$stock = $opening + $qty_in - $qty_out; }else{$stock = $stock + $qty_in - $qty_out;}

   

 echo '

  

    

  

  



<tr>

<td width="3%">'.$count.'</td>

  

  <td width="15%">'.$row["acc_no"].'</td>

<td width="67%">'.$row["acc_name"].'</td>




   <td width="15%" class="rightside">'.number_format($balance, 2).'</td>

   

  

  

   

    

   </tr>

   





        ';



}
?>

 <tr>

<td colspan="4" width="100%"><b>Equity</b></td>

   

    

   </tr>
   <?php

$statement = $connect->prepare("select a.acc_no,a.acc_name, a.balance

  from accounts_parent a where a.status = 'Active' and acc_type = 'Equity'
  order by acc_no");





 $statement->execute();

 

 $result = $statement->fetchAll(); 

 foreach($result as $row)

 {



  $balance = $row["balance"];
  

  $tot_balance = $tot_balance + $balance;



  

  $count = $count+1;





     // if($count == 1){$stock = $opening + $qty_in - $qty_out; }else{$stock = $stock + $qty_in - $qty_out;}

   

 echo '

  

    

  

  



<tr>

<td width="3%">'.$count.'</td>

  

  <td width="15%">'.$row["acc_no"].'</td>

<td width="67%">'.$row["acc_name"].'</td>




   <td width="15%" class="rightside">'.number_format($balance, 2).'</td>

   

  

  

   

    

   </tr>

   





        ';



}
?>

</tbody>
 </table>







  <div id="footer">

    

  </div>

 </body>

 </html>