<?
function transc($date1,$date2){
    $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");

	 $j=mysqli_query($dbc,("select  amount,type,receipt,time,cod from x_report  where date between '$date1' and '$date2'
 and type='PAYBILL' and refe='SALES' and amount!='0'
 "));

	 
	?><br />
	<tr><td  width="100" style="font-size: 40px"><center><b>MPESA PAYBILL</td></td></tr>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="100" style="font-size: 22px"><b>Receipt NO</b></td><td width="100" style="font-size: 22px"><b>Amount </b></td><td width="100" style="font-size: 22px"><b>Code</b></td>
<td width="100" style="font-size: 22px"><b>Time </b></td>
 </tr><?
  while($row=mysqli_fetch_array($j)){
 echo '<tr>

  <td width="100" style="font-size: 22px">'.($row['receipt']).'</td>
 <td width="100" style="font-size: 22px">'.($row['amount']).'</td>
  <td width="100" style="font-size: 22px">'.($row['cod']).'</td>
<td width="100" style="font-size: 22px">'.($row['time']).'</td>
</tr>';
$amount+=($row['amount']);


 }
 echo '<tr>

  <td colspan="0" width="100" style="font-size: 22px"><center><b>TOTAL </td>
   <td width="100" style="font-size: 22px"><b>'.round($amount).'</td>

 </table><br /><br />'; 
   $jw=mysqli_query($dbc,("select  amount,type,receipt,time from x_report  where date between '$date1' and '$date2'
 and type='CASH' and refe='SALES' and amount!='0'
 "));
 	?><br /><?
 	$jj=mysqli_query($dbc,("select  amount,type,receipt,time from x_report  where date between '$date1' and '$date2'
 and type='BANK' and refe='SALES' and amount!='0'
 "));

	 
	?><br />
	<tr><td  width="100" style="font-size: 40px"><center><b>BANK</td></td></tr>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="100" style="font-size: 22px"><b>Receipt NO</b></td><td width="100" style="font-size: 22px"><b>Amount </b></td>
<td width="100" style="font-size: 22px"><b>Time </b></td>
 </tr><?
  while($row=mysqli_fetch_array($jj)){
 echo '<tr>

  <td width="100" style="font-size: 22px">'.($row['receipt']).'</td>
 <td width="100" style="font-size: 22px">'.($row['amount']).'</td>
<td width="100" style="font-size: 22px">'.($row['time']).'</td>
</tr>';
$amoun+=($row['amount']);


 }
 echo '<tr>

  <td colspan="0" width="100" style="font-size: 22px"><center><b>TOTAL </td>
   <td width="100" style="font-size: 22px"><b>'.round($amoun).'</td>

 </table><br /><br />'; 
   $jw=mysqli_query($dbc,("select  amount,type,receipt,time from x_report  where date between '$date1' and '$date2'
 and type='CASH' and refe='SALES' and amount!='0'
 "));
 	?><br />
	<tr><td  width="100" style="font-size: 40px"><center><b>CASH</td></td></tr>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="100" style="font-size: 22px"><b>Receipt NO</b></td><td width="100" style="font-size: 22px"><b>Amount </b></td>
<td width="100" style="font-size: 22px"><b>Time </b></td>
 </tr><?
  while($row=mysqli_fetch_array($jw)){
 echo '<tr>

  <td width="100" style="font-size: 22px">'.($row['receipt']).'</td>
 <td width="100" style="font-size: 22px">'.($row['amount']).'</td>
<td width="100" style="font-size: 22px">'.($row['time']).'</td>
</tr>';
$amon+=($row['amount']);


 }
 echo '<tr>

  <td colspan="0" width="100" style="font-size: 22px"><center><b>TOTAL </td>
   <td width="100" style="font-size: 22px"><b>'.round($amon).'</td>

 </table><br /><br />'; 
 mysqli_close($dbc);
 }
function trans(){
   $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");

	 $j=mysqli_query($dbc,("select  amount,type,receipt,time,cod from x_report  WHERE DAY( date ) = DAY(CURRENT_DATE )
AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())
 and type='PAYBILL' and refe='SALES' and amount!='0'
 "));

	 
	?><br />
	<tr><td  width="100" style="font-size: 40px"><center><b>MPESA PAYBILL</td></td></tr>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="100" style="font-size: 22px"><b>Receipt NO</b></td><td width="100" style="font-size: 22px"><b>Amount </b></td><td width="100" style="font-size: 22px"><b>Code</b></td>
<td width="100" style="font-size: 22px"><b>Time </b></td>
 </tr><?
  while($row=mysqli_fetch_array($j)){
 echo '<tr>

  <td width="100" style="font-size: 22px">'.($row['receipt']).'</td>
 <td width="100" style="font-size: 22px">'.($row['amount']).'</td>
  <td width="100" style="font-size: 22px">'.($row['cod']).'</td>
<td width="100" style="font-size: 22px">'.($row['time']).'</td>
</tr>';
$amount+=($row['amount']);


 }
 echo '<tr>

  <td colspan="0" width="100" style="font-size: 22px"><center><b>TOTAL </td>
   <td width="100" style="font-size: 22px"><b>'.round($amount).'</td>

 </table><br /><br />'; 
   $jw=mysqli_query($dbc,("select  amount,type,receipt,time from x_report  WHERE DAY( date ) = DAY(CURRENT_DATE )
AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())
 and type='CASH' and refe='SALES' and amount!='0'
 "));
 	?><br /><?
 	$jj=mysqli_query($dbc,("select  amount,type,receipt,time from x_report  WHERE DAY( date ) = DAY(CURRENT_DATE )
AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())
 and type='BANK' and refe='SALES' and amount!='0'
 "));

	 
	?><br />
	<tr><td  width="100" style="font-size: 40px"><center><b>BANK</td></td></tr>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="100" style="font-size: 22px"><b>Receipt NO</b></td><td width="100" style="font-size: 22px"><b>Amount </b></td>
<td width="100" style="font-size: 22px"><b>Time </b></td>
 </tr><?
  while($row=mysqli_fetch_array($jj)){
 echo '<tr>

  <td width="100" style="font-size: 22px">'.($row['receipt']).'</td>
 <td width="100" style="font-size: 22px">'.($row['amount']).'</td>
<td width="100" style="font-size: 22px">'.($row['time']).'</td>
</tr>';
$amoun+=($row['amount']);


 }
 echo '<tr>

  <td colspan="0" width="100" style="font-size: 22px"><center><b>TOTAL </td>
   <td width="100" style="font-size: 22px"><b>'.round($amoun).'</td>

 </table><br /><br />'; 
   $jw=mysqli_query($dbc,("select  amount,type,receipt,time from x_report  WHERE DAY( date ) = DAY(CURRENT_DATE )
AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())
 and type='CASH' and refe='SALES' and amount!='0'
 "));
 	?><br />
	<tr><td  width="100" style="font-size: 40px"><center><b>CASH</td></td></tr>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="100" style="font-size: 22px"><b>Receipt NO</b></td><td width="100" style="font-size: 22px"><b>Amount </b></td>
<td width="100" style="font-size: 22px"><b>Time </b></td>
 </tr><?
  while($row=mysqli_fetch_array($jw)){
 echo '<tr>

  <td width="100" style="font-size: 22px">'.($row['receipt']).'</td>
 <td width="100" style="font-size: 22px">'.($row['amount']).'</td>
<td width="100" style="font-size: 22px">'.($row['time']).'</td>
</tr>';
$amon+=($row['amount']);


 }
 echo '<tr>

  <td colspan="0" width="100" style="font-size: 22px"><center><b>TOTAL </td>
   <td width="100" style="font-size: 22px"><b>'.round($amon).'</td>

 </table><br /><br />'; 
 mysqli_close($dbc);
 }
function modales($mod,$date1,$date2){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT *,sum(qty)as q,(sum(total_p))as
 total FROM sales where date between '$date1' and '$date2' and tpe='$mod'
and status='ACTIVE' group by sale_id order by number desc"));

 ?>
<br /> <div align="center"><b> Product Sales Between <?echo $date1;?> And <?echo $date2?></b>&nbsp; <b>For &nbsp;<? echo strtoupper($mod);?>&nbsp; Mode</b></div><table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td> <td><b>RECEIPT</b></td><td><b>PRODUCT</b></td><td><b>QTY</b></td><td><b>PRICE</td><td><b>TOTAL</td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['date'].'</td><td>'.$row['number'].'</td><td>'.$row['p_name'].'</td><td>'.$row['q'].'</td><td>'.number_format($row['price']).'</td>
 <td>'.number_format($row['total']).'</td></tr>';
 $total+=$row['total'];
 
 }
 echo '<tr><td colspan="4"><center>TOTAL</td><td></td><td><b>'.round($total).'</td></tr>';
  echo '</table>';
  mysqli_close($dbc);
 }
 function usales($id,$date1,$date2,$mod){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT *,sum(qty)as q,(sum(total_p))as
 total FROM sales where date between '$date1' and '$date2' and user='$id' and tpe='$mod'
and status='ACTIVE' group by sale_id order by number desc"));

 ?>
<br /> <div align="center"><b> Product Sales Between <?echo $date1;?> And <?echo $date2?></b>&nbsp; <b>For &nbsp;<? echo strtoupper($id);?></b><b>&nbsp;In &nbsp;<? echo strtoupper($mod);?>&nbsp; Mode</b></div><table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td> <td><b>RECEIPT</b></td><td><b>PRODUCT</b></td><td><b>QTY</b></td><td><b>PRICE</td><td><b>TOTAL</td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['date'].'</td><td>'.$row['number'].'</td><td>'.$row['p_name'].'</td><td>'.$row['q'].'</td><td>'.number_format($row['price']).'</td>
 <td>'.number_format($row['total']).'</td></tr>';
 $total+=$row['total'];
 
 }
 echo '<tr><td colspan="4"><center>TOTAL</td><td></td><td><b>'.round($total).'</td></tr>';
  echo '</table>';
  mysqli_close($dbc);
 }
 function ussales($id,$date1,$date2){
	         				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT *,sum(qty)as q,(sum(total_p))as
 total FROM sales where date between '$date1' and '$date2' and user='$id'
and status='ACTIVE' group by sale_id order by number desc"));

 ?>
<br /> <div align="center"><b> Product Sales Between <?echo $date1;?> And <?echo $date2?></b>&nbsp; <b>For &nbsp;<? echo strtoupper($id);?></b></div><table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td> <td><b>RECEIPT</b></td><td><b>PRODUCT</b></td><td><b>QTY</b></td><td><b>PRICE</td><td><b>TOTAL</td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['date'].'</td><td>'.$row['number'].'</td><td>'.$row['p_name'].'</td><td>'.$row['q'].'</td><td>'.number_format($row['price']).'</td>
 <td>'.number_format($row['total']).'</td></tr>';
 $total+=$row['total'];
 
 }
 echo '<tr><td colspan="4"><center>TOTAL</td><td></td><td><b>'.round($total).'</td></tr>';
  echo '</table>';
  mysqli_close($dbc);
 }
function AgeingCustomers(){
       				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("select name,
 sum(debit)-sum(ledgers.credit) as curr,
sum(if(YEAR(date) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)
AND MONTH(date) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH),abs(debit),0))
-sum(if(YEAR(date) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)
AND MONTH(date) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH),abs(ledgers.credit),0)) as thirty,
sum(if(YEAR(date) = YEAR(CURRENT_DATE - INTERVAL 2 MONTH)
AND MONTH(date) = MONTH(CURRENT_DATE - INTERVAL 2 MONTH),abs(debit),0))
-sum(if(YEAR(date) = YEAR(CURRENT_DATE - INTERVAL 2 MONTH)
AND MONTH(date) = MONTH(CURRENT_DATE - INTERVAL 2 MONTH),abs(ledgers.credit),0)) as sixty,
sum(if(YEAR(date) = YEAR(CURRENT_DATE - INTERVAL 3 MONTH)
AND MONTH(date) = MONTH(CURRENT_DATE - INTERVAL 3 MONTH),abs(debit),0))
-sum(if(YEAR(date) = YEAR(CURRENT_DATE - INTERVAL 3 MONTH)
AND MONTH(date) = MONTH(CURRENT_DATE - INTERVAL 3 MONTH),abs(ledgers.credit),0)) as ninety,
sum(if(YEAR(date) = YEAR(CURRENT_DATE - INTERVAL 100 MONTH)
AND MONTH(date) = MONTH(CURRENT_DATE - INTERVAL 100 MONTH),abs(debit),0))
-sum(if(YEAR(date) = YEAR(CURRENT_DATE - INTERVAL 100 MONTH)
AND MONTH(date) = MONTH(CURRENT_DATE - INTERVAL 100 MONTH),abs(ledgers.credit),0)) as onet
  from ledgers inner join accounts on accounts.id=ledgers.account_id
where  accounts.stat='CUSTOMER' and accounts.status='ACTIVE'
group by ledgers.account_id having curr>0
order by curr desc"));?>
          
<style>

table {
    border-collapse:separate;
    border:solid black 1px;
    border-radius:12px;
    -moz-border-radius:6px;
}

td, th {
   border-left:solid black 1px ;
    border-right:solid black 1px;
}

th {
    
    border-top: none;
}

td:first-child {
     border-left: none;
}</style>


	<style>
td { font-family:Bell Gothic ,Verdana,Arial;
font-size: 12px;
}
</style>
  	<style>
th { font-family:Bell Gothic ,Verdana,Arial;
font-size: 16px; }
</style>
<table class="blue" border="1" style="background-color:#ffffff"
       rules="NONE" frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial"> 
 <tr><td  colspan="6"><b><center><U>CUSTOMERS AGEING ANALYSIS</td></tr>
 <TR><TD>NAME</TD><TD>CURRENT</TD><TD>30 DAYS</TD><TD>60 DAYS</TD><TD>90 DAYS</TD><TD>120 DAYS</TD><td>> 120 DAYS</td><?
 while($row=mysqli_fetch_array($r)){
	 $cur+=$row['curr'];
	 $thirty+=$row['thirty'];
	 $sixty+=$row['sixty'];$ninety+=$row['ninety'];$one+=$row['onet'];
 echo '<tr><td>'.($row['name']).'</td><td>'.number_format($row['curr']).'</td><td>'.number_format($row['thirty']).'</td>
<td>'.number_format($row['sixty']).'</td><td>'.number_format($row['ninety']).'</td><td>'.number_format($row['onet']).'</td></tr>';
 }
  echo '<tr><td><b>TOTAL</td><td><b>'.number_format($cur).'</td><td><b>'.number_format($thirty).'</td>
<td><b>'.number_format($sixty).'</td><td><b>'.number_format($ninety).'</td><td><b>'.number_format($one).'</td></tr>';
 echo '</table>';
}
function ViewCS(){
     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select phone,account_id,name,address from accounts
inner join  group_accounts on group_accounts.account_id=accounts.id
where group_id='4'
and name<>'STOCK' and status='NOT ACTIVE'"));
  echo '
     
<table border="1" width="500" cellspacing="0" class="tables"> 
                                                        <thead>
                                                            <tr>
															<th><left>Activate Account</th> 
															<th><left>Account Name</th> 
                                                              <th><left>Phone</th> 
															    
																<th><left>Address</th> 
                                                                	
																	
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr><td><a  rel="facebox" href=active_c.php?id=' . $row["account_id"] .'>Activate Account</a></td><td>' . (($row['name'])) . '</td>
	<td>' . (($row['phone'])) . '</td>
	
	<td>' . (($row['address'])) . '</td>

	</tr>';
}
							echo "</table>";
}
 function cuuy($date1){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
	$r=mysqli_query($dbc,("SELECT *,qty as  q,total_p as 
 total FROM sales WHERE  date  ='$date1'
and status='ACTIVE' group by sale_id order by number desc"));

 ?><?echo'<div align="center" width="420" style="font-size: 40px"><b>Transactions Summary For The Date ' . $date1.'</b></div>';?><table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td>Number</td><td>Item</td><td>Qty</td><td>Price</td><td>User</td><td>Total</td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td width="420" style="font-size: 16px"><b>'.$row['number'].'</td><td width="420" style="font-size: 16px"><b>'.$row['p_name'].'</td><td width="420" style="font-size: 16px"><b>'.$row['q'].'</td><td width="420" style="font-size: 16px"><b>'.number_format($row['price']).'</td>';
echo' <td width="420" style="font-size: 16px"><b>'.$row['user'].'</td>';
 echo'<td width="420" style="font-size: 16px"><b>'.number_format($row['total']).'</td>';
 
 echo'</tr>';
 $total+=$row['total'];
 //$prof+=$row['prof'];
 }
 
 echo '<tr><td  width="420" style="font-size: 16px" colspan="5"><center><b>SALES</td><td width="420" style="font-size: 16px"><b>'.number_format($total).'</td></tr>';
  echo '</table>';
	 $j=mysqli_query($dbc,("select sum(amount)as amount,type from x_report where  date ='$date1'
 and type!='CREDIT NOT SALES' and refe='SALES'
 group by type order by amount desc"));
 $gh=mysqli_query($dbc,("select date from x_report where date='$date1'"));
 $gj=mysqli_fetch_array($gh);
  $da=$gj['date'];
	 
	?><br />
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="420" style="font-size: 16px"><b>Sale Type</b></td><td width="420" style="font-size: 22px"><b>Amount </b></td>
 </tr><?
  while($row=mysqli_fetch_array($j)){
 echo '<tr>

  <td width="420" style="font-size: 40px">'.$row['type'].'</td>
 <td width="420" style="font-size: 40px">'.number_format($row['amount']).'</td>

</tr>';
$amount+=($row['amount']);


 }
 echo '<tr>

  <td colspan="0" width="420" style="font-size: 40px"><center><b>TOTAL </td>
   <td width="420" style="font-size: 40px"><b>'.number_format($amount).'</td>

 </table><br><br>'; 
  
 $ji=mysqli_query($dbc,("select amnt from cashier where date='$date1'
"));
   $irr=mysqli_fetch_array($ji);
     $amnt=$irr['amnt'];
  
 $js=mysqli_query($dbc,("select name,amnt from expens inner join accounts on accounts.id=expens.ex_id where date='$date1'
"));
 $gh=mysqli_query($dbc,("select date from x_report where date='$date1' select sum(amnt)as tota from expens where DAY(date)= DAY(CURRENT_DATE )AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
 $gj=mysqli_fetch_array($gh);
  $da=$gj['date'];
	 
	?><br />
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="420" style="font-size: 16px"><b>Expense</b></td><td width="420" style="font-size: 22px"><b>Amount </b></td>
 </tr><?
  while($row=mysqli_fetch_array($js)){
 echo '<tr>

  <td width="420" style="font-size: 40px">'.$row['name'].'</td>
 <td width="420" style="font-size: 40px">'.number_format($row['amnt']).'</td>

</tr>';
$amout+=($row['amnt']);


 }
 
 echo '<tr>

  <td colspan="0" width="420" style="font-size: 40px"><center><b>TOTAL EXPENSES</td>
   <td width="420" style="font-size: 40px"><b>'.number_format($amout).'</td>

 </table><br><br>';
 
 $gp=mysqli_query($dbc,("select amnt,date from z_report where date='$date1'
"));
 //$gb=mysqli_fetch_array($gp);
 // $dy=$gb['amnt'];
	 
	?><br />
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="420" style="font-size: 16px"><b>Date</b></td><td width="420" style="font-size: 22px"><b>Cash Drawer Amount</b></td>
 </tr><?
  while($row=mysqli_fetch_array($gp)){
 echo '<tr>

  <td width="420" style="font-size: 40px">'.$row['date'].'</td>
 <td width="420" style="font-size: 40px">'.number_format($row['amnt']).'</td>

</tr>';
//$amout+=($row['tota']);


 }
 echo'</table><br /><br />';
 
  $ry=mysqli_query($dbc,("select sum(amount)as tot from x_report where type='CASH' AND date='$date1'
"));
 $py=mysqli_query($dbc,("select sum(amnt)as tota from expens where date='$date1'
"));
$bb=mysqli_query($dbc,("select amnt,date from z_report where date='$date1'
"));
$gbk=mysqli_fetch_array($bb);
  $dll=$gbk['amnt'];
 $go=mysqli_fetch_array($ry);
  $da=$go['tot'];
  $vr=$da+$dll;
  $kj=mysqli_fetch_array($py);
  $dy=$kj['tota'];
  $li=$da-$dy;
  $fj=$li-$dll;
  $mj=$li+$dll;
 echo '<p style="font-size: 40px">TOTAL CASH, LESS  EXPENSES: &nbsp;&nbsp;'.$mj.'</P>';
// echo '<p style="font-size: 40px">CASH AMOUNT VARIATION:&nbsp;&nbsp;'.$fj.'</P>';
 
 mysqli_close($dbc);
 }
 function  ViewStatutory(){
            				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from accounts
inner join  group_accounts on group_accounts.account_id=accounts.id
where group_id='11'
"));
  echo '
     
<table border="1" width="1000" cellspacing="0" > 
                                                        <thead>
                                                            <tr>
															<th><left>Delete Account</th> 
															<th><left>Account Name</th> 
                                                              <th><left>Account Code</th> 
															
                                                                    
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr><td><a rel="facebox" href=delete_a.php?id=' . $row["account_id"] .'>Delete Account</a></td><td>' . (($row['name'])) . '</td>
	<td>' . (($row['code'])) . '</td>
	</tr>';
}
							echo "</table>";
}
 function ViewCapital(){
         				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from accounts
inner join  group_accounts on group_accounts.account_id=accounts.id
where group_id='5'
"));
  echo '
     
<table border="1" width="1000" cellspacing="0" > 
                                                        <thead>
                                                            <tr>
															<th><left>De-Activate Ledger</th> 
															<th><left>Activate Ledger</th> 
															<th><left>Account Name</th> 
                                                              <th><left>Status</th> 
															
                                                                    
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr><td><a rel="facebox" href=deactivate.php?id=' . $row["account_id"] .'>De-Activate Ledger</a></td>
	<td><a rel="facebox" href=reactivate.php?id=' . $row["account_id"] .'>Activate Ledger</a></td><td>' . (($row['name'])) . '</td>
	<td>' . (($row['status'])) . '</td>
	</tr>';
}
							echo "</table>";
}
function ViewCategory(){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from categories
"));
  echo '
     
<table border="1" width="500" cellspacing="0" class="tables"> 
                                                        <thead>
                                                            <tr>
															<th><left>Edit </th> 
															<th><left>Category Name</th> 
             
			   
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr><td><a  rel="facebox" href=edit_cat.php?id=' . $row["id"] .'>Edit Category</a></td><td>' . (($row['name'])) . '</td>

	</tr>';
}
							echo "</table>";
							mysqli_close($dbc);
}
 function transs($date1,$date2){
$js=mysqli_query($dbc,("SELECT * ,sum(qty)as qty,sum(tot)as total from trans where 
date between '$date1' and '$date2'

group by p_name order by qty desc"));?>
<br />
<div align="center" style="font-size: 16px"><b>Transfer Report For Date Between <?echo $date1;?> And <?echo $date2?></b></div><br />
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="420" style="font-size: 16px"><b>Name</b></td><td width="420" style="font-size: 22px"><b>Qty </b></td><td width="420" style="font-size: 22px"><b>Dest</b></td><td width="420" style="font-size: 22px"><b>Value</b></td><td width="420" style="font-size: 22px"><b>Date </b></td>
 </tr><?

  while($row=mysqli_fetch_array($js)){
 echo '<tr>

  <td width="420" style="font-size: 40px">'.$row['p_name'].'</td>
  <td width="420" style="font-size: 40px">'.$row['qty'].'</td> <td width="420" style="font-size: 40px">'.$row['dest'].'</td>
 <td width="420" style="font-size: 40px">'.number_format($row['price']).'</td>
<td width="420" style="font-size: 40px">'.$row['date'].'</td>
</tr>';
$amout+=($row['price']); 
 }
 echo '<tr>

  <td colspan="2" width="420" style="font-size: 40px"><center><b>TOTAL VALUE</td>
   <td width="420" style="font-size: 40px"><b>'.number_format($amout).'</td>

 </table><br><br>'; 
 }
function expes($date1,$date2){
        				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$js=mysqli_query($dbc,("select name,amnt,date,descr,
exp_id from expens inner join  accounts on accounts.id=expens.ex_id where date between '$date1' and '$date2'"));?>
<br />
<div align="center" style="font-size: 16px"><b>Expense Report For Date Between <?echo $date1;?> And <?echo $date2?></b></div><br />
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="420" style="font-size: 16px"><b>Expense</b></td><td width="420" style="font-size: 16px"><b>Description</b></td><td width="420" style="font-size: 16px"><b>Amount </b></td><td width="420" style="font-size: 16px">
    <b>Date </b></td>
 </tr><?

  while($row=mysqli_fetch_array($js)){
 echo '<tr>

  <td width="420" style="font-size: 16px">'.$row['name'].'</td>
    <td width="420" style="font-size: 16px">'.$row['descr'].'</td>
 <td width="420" style="font-size: 16px">'.number_format($row['amnt']).'</td>
<td width="420" style="font-size: 16px">'.$row['date'].'</td>

</tr>';
$amout+=($row['amnt']); 
 }
 echo '<tr>

  <td colspan="2" width="420" style="font-size: 16px"><center><b>TOTAL EXPENSES</td>
   <td width="420" style="font-size: 16px"><b>'.number_format($amout).'</td>

 </table><br><br>'; 
 }
function cuu(){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
	$r=mysqli_query($dbc,("SELECT *,qty as  q,total_p as 
 total FROM sales WHERE DAY( date ) = DAY(CURRENT_DATE )
AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())
and status='ACTIVE' group by sale_id order by number asc"));

 ?><?echo'<div align="center" width="420" style="font-size: 40px"><b>Transactions Summary For The Date ' . date("Y/m/d").'</b></div>';?><table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td width="420" style="font-size: 16px"><b>'.$row['number'].'</td><td width="420" style="font-size: 16px"><b>'.$row['p_name'].'</td><td width="420" style="font-size: 16px"><b>'.$row['q'].'</td><td width="420" style="font-size: 16px"><b>'.number_format($row['price']).'</td>
 <td width="420" style="font-size: 16px"><b>'.$row['user'].'</td>
 <td width="420" style="font-size: 16px"><b>'.number_format($row['total']).'</td>';
 
echo' </tr>';
 $total+=$row['total'];
 //$prof+=$row['prof'];
 }
 
 echo '<tr><td colspan="5" width="420" style="font-size: 16px"><center><b>TOTAL</td><td width="420" style="font-size: 16px"><b>'.number_format($total).'</td></tr>';
  echo '</table>';
	 $j=mysqli_query($dbc,("select sum(amount)as amount,type from x_report where DAY( date ) = DAY(CURRENT_DATE )
AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW()) and refe='SALES'
 group by type order by amount desc"));
 $gh=mysqli_query($dbc,("select date from x_report where DAY(date)= DAY(CURRENT_DATE )"));
 $gj=mysqli_fetch_array($gh);
  $da=$gj['date'];
	 
	?><br />
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="420" style="font-size: 16px"><b>Payment Type</b></td><td width="420" style="font-size: 22px"><b>Amount </b></td>
 </tr><?
  while($row=mysqli_fetch_array($j)){
 echo '<tr>

  <td width="420" style="font-size: 40px">'.$row['type'].'</td>
 <td width="420" style="font-size: 40px">'.number_format($row['amount']).'</td>

</tr>';
$amount+=($row['amount']);


 }
 echo '<tr>

  <td colspan="0" width="420" style="font-size: 40px"><center><b>TOTAL </td>
   <td width="420" style="font-size: 40px"><b>'.number_format($amount).'</td>

 </table><br><br>'; 
   $j=mysqli_query($dbc,("select sum(amount)as amunt,type from x_report where DAY( date ) = DAY(CURRENT_DATE )
AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW()) and type!='CREDIT NOT SALES' and refe='DEBT PAYMENT'
 group by type order by amount desc"));
 $gh=mysqli_query($dbc,("select date from x_report where DAY(date)= DAY(CURRENT_DATE )"));
 $gj=mysqli_fetch_array($gh);
  $da=$gj['date'];
	 
	?><br />
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="420" style="font-size: 16px"><b>Debt Collections</b></td><td width="420" style="font-size: 22px"><b>Amount </b></td>
 </tr><?
  while($row=mysqli_fetch_array($j)){
 echo '<tr>

  <td width="420" style="font-size: 40px">'.$row['type'].'</td>
 <td width="420" style="font-size: 40px">'.number_format($row['amunt']).'</td>

</tr>';
$amunt+=($row['amunt']);


 }
 echo '<tr>

  <td colspan="0" width="420" style="font-size: 40px"><center><b>TOTAL </td>
   <td width="420" style="font-size: 40px"><b>'.number_format($amunt).'</td>

 </table><br><br>'; 
  $ng=mysqli_query($dbc,("select concat_ws(' ', first,last) as name,lab_id,date, amnt from adv inner join labor using(lab_id) WHERE DAY( date ) = DAY(CURRENT_DATE )
AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())
 

"));
?>
 <br />
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="420" style="font-size: 16px"><b>Salary Advance</b></td><td width="420" style="font-size: 22px"><b>Amount </b></td>
 </tr><?
  while($row=mysqli_fetch_array($ng)){
 echo '<tr>

  <td width="420" style="font-size: 40px">'.$row['name'].'</td>
 <td width="420" style="font-size: 40px">'.number_format($row['amnt']).'</td>

</tr>';
$amn+=($row['amnt']);


 }
 echo '<tr>

  <td colspan="0" width="420" style="font-size: 40px"><center><b>TOTAL </td>
   <td width="420" style="font-size: 40px"><b>'.number_format($amn).'</td>

 </table><br><br>'; 
 $ji=mysqli_query($dbc,("select amnt from cashier where DAY(date)= DAY(CURRENT_DATE )AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
   $irr=mysqli_fetch_array($ji);
     $amnt=$irr['amnt'];
  
 $js=mysqli_query($dbc,("select name,amnt from expens inner join  accounts on accounts.id=expens.ex_id  where DAY(date)= DAY(CURRENT_DATE )AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
 $gh=mysqli_query($dbc,("select date from x_report where DAY(date)= DAY(CURRENT_DATE )select sum(amnt)as tota from expens where DAY(date)= DAY(CURRENT_DATE )AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
 $gj=mysqli_fetch_array($gh);
  $da=$gj['date'];
	 
	?><br />
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="420" style="font-size: 16px"><b>Expense</b></td><td width="420" style="font-size: 22px"><b>Amount </b></td>
 </tr><?
  while($row=mysqli_fetch_array($js)){
 echo '<tr>

  <td width="420" style="font-size: 40px">'.$row['name'].'</td>
 <td width="420" style="font-size: 40px">'.number_format($row['amnt']).'</td>

</tr>';
$amout+=($row['amnt']);


 }
 echo '<tr>

  <td colspan="0" width="420" style="font-size: 40px"><center><b>TOTAL EXPENSES</td>
   <td width="420" style="font-size: 40px"><b>'.number_format($amout).'</td>

 </table><br><br>';
 

 $gp=mysqli_query($dbc,("select amnt,date from cashier where DAY(date)= DAY(CURRENT_DATE )and MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
 //$gb=mysqli_fetch_array($gp);
 // $dy=$gb['amnt'];
	 
	?><br />
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="420" style="font-size: 16px"><b>Date</b></td><td width="420" style="font-size: 22px"><b>Opening Amount</b></td>
 </tr><?
  while($row=mysqli_fetch_array($gp)){
 echo '<tr>

  <td width="420" style="font-size: 40px">'.$row['date'].'</td>
 <td width="420" style="font-size: 40px">'.number_format($row['amnt']).'</td>

</tr>';
//$amout+=($row['tota']);


 }
 echo'</table><br /><br />';
 
  $ry=mysqli_query($dbc,("select sum(amount)as tot from x_report where type='CASH' AND DAY(date)= DAY(CURRENT_DATE )AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
 $py=mysqli_query($dbc,("select sum(amnt)as tota from expens where DAY(date)= DAY(CURRENT_DATE )AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
$bb=mysqli_query($dbc,("select amnt,date from cashier where DAY(date)= DAY(CURRENT_DATE )and MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
$ngg=mysqli_query($dbc,("select sum (amnt) as ads from adv  WHERE DAY( date ) = DAY(CURRENT_DATE )
AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())
 

"));
$gbk=mysqli_fetch_array($bb);
  $dll=$gbk['amnt'];
 $go=mysqli_fetch_array($ry);
  $da=$go['tot'];
  $vr=$da+$dll;
  $kj=mysqli_fetch_array($py);
  $dy=$kj['tota'];
  $my=mysqli_fetch_array($ngg);
     $mw=$my['ads'];
  $li=$vr-$dy;
  $mj=$li+$dll;
  $ki=$li-$mw;
 echo '<p style="font-size: 40px">TOTAL CASH, LESS  EXPENSES: &nbsp;&nbsp;'.$ki.'</P>';
 mysqli_close($dbc);
 }
 function cuuu(){
	    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
	$r=mysqli_query($dbc,("SELECT *,qty as  q,total_p as 
 total FROM sales WHERE DAY( date ) = DAY(CURRENT_DATE )
AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())
and status='ACTIVE' group by sale_id order by number desc"));

 ?><?echo'<div align="center" width="420" style="font-size: 40px"><b>Transactions Summary For The Date ' . date("Y/m/d").'</b></div>';?><table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><?
 while($row=mysqli_fetch_array($r)){
 //echo '<tr><td width="420" style="font-size: 16px"><b>'.$row['number'].'</td><td width="420" style="font-size: 16px"><b>'.$row['p_name'].'</td><td width="420" style="font-size: 16px"><b>'.$row['q'].'</td><td width="420" style="font-size: 16px"><b>'.number_format($row['price']).'</td>';
//echo' <td width="420" style="font-size: 16px"><b>'.$row['user'].'</td>';
// echo'<td width="420" style="font-size: 16px"><b>'.number_format($row['total']).'</td>';
 
 echo'</tr>';
 $total+=$row['total'];
 //$prof+=$row['prof'];
 }
 
 echo '<tr><td  width="420" style="font-size: 16px"><center><b>SALES</td><td width="420" style="font-size: 16px"><b>'.number_format($total).'</td></tr>';
  echo '</table>';
	 $j=mysqli_query($dbc,("select sum(amount)as amount,type from x_report where DAY( date ) = DAY(CURRENT_DATE )
AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW()) and type!='CREDIT NOT SALES' and refe='SALES'
 group by type order by amount desc"));
 $gh=mysqli_query($dbc,("select date from x_report where DAY(date)= DAY(CURRENT_DATE )"));
 $gj=mysqli_fetch_array($gh);
  $da=$gj['date'];
	 
	?><br />
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="420" style="font-size: 16px"><b>Sale Type</b></td><td width="420" style="font-size: 22px"><b>Amount </b></td>
 </tr><?
  while($row=mysqli_fetch_array($j)){
 echo '<tr>

  <td width="420" style="font-size: 40px">'.$row['type'].'</td>
 <td width="420" style="font-size: 40px">'.number_format($row['amount']).'</td>

</tr>';
$amount+=($row['amount']);


 }
 echo '<tr>

  <td colspan="0" width="420" style="font-size: 40px"><center><b>TOTAL </td>
   <td width="420" style="font-size: 40px"><b>'.number_format($amount).'</td>

 </table><br><br>'; 
  $j=mysqli_query($dbc,("select sum(amount)as amont,type from x_report where DAY( date ) = DAY(CURRENT_DATE )
AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW()) and type!='CREDIT NOT SALES' and refe='DEBT PAYMENT'
 group by type order by amount desc"));
 $gh=mysqli_query($dbc,("select date from x_report where DAY(date)= DAY(CURRENT_DATE )"));
 $gj=mysqli_fetch_array($gh);
  $da=$gj['date'];
	 
	?><br />
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="420" style="font-size: 16px"><b> Debt Collections</b></td><td width="420" style="font-size: 22px"><b>Amount </b></td>
 </tr><?
  while($row=mysqli_fetch_array($j)){
 echo '<tr>

  <td width="420" style="font-size: 40px">'.$row['type'].'</td>
 <td width="420" style="font-size: 40px">'.number_format($row['amont']).'</td>

</tr>';
$amont+=($row['amont']);


 }
 echo '<tr>

  <td colspan="0" width="420" style="font-size: 40px"><center><b>TOTAL </td>
   <td width="420" style="font-size: 40px"><b>'.number_format($amont).'</td>

 </table><br><br>'; 
 $ji=mysqli_query($dbc,("select amnt from cashier where DAY(date)= DAY(CURRENT_DATE )AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
   $irr=mysqli_fetch_array($ji);
     $amnt=$irr['amnt'];
  
 $js=mysqli_query($dbc,("select name,amnt from expens inner join  accounts on accounts.id=expens.ex_id  where DAY(date)= DAY(CURRENT_DATE )AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
 $gh=mysqli_query($dbc,("select date from x_report where DAY(date)= DAY(CURRENT_DATE ) AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
 $gj=mysqli_fetch_array($gh);
  $da=$gj['date'];
	 
	?><br />
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="420" style="font-size: 16px"><b>Expense</b></td><td width="420" style="font-size: 22px"><b>Amount </b></td>
 </tr><?
  while($row=mysqli_fetch_array($js)){
 echo '<tr>

  <td width="420" style="font-size: 40px">'.$row['name'].'</td>
 <td width="420" style="font-size: 40px">'.number_format($row['amnt']).'</td>

</tr>';
$amout+=($row['amnt']);


 }
 
 echo '<tr>

  <td colspan="0" width="420" style="font-size: 40px"><center><b>TOTAL EXPENSES</td>
   <td width="420" style="font-size: 40px"><b>'.number_format($amout).'</td>

 </table><br><br>';
 
 $gp=mysqli_query($dbc,("select amnt,date from z_report where DAY(date)= DAY(CURRENT_DATE )and MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
 //$gb=mysqli_fetch_array($gp);
 // $dy=$gb['amnt'];
	 
	?><br />
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial;font-size: 25px">
<tr><td width="420" style="font-size: 16px"><b>Date</b></td><td width="420" style="font-size: 22px"><b>Cash Drawer Amount</b></td>
 </tr><?
  while($row=mysqli_fetch_array($gp)){
 echo '<tr>

  <td width="420" style="font-size: 40px">'.$row['date'].'</td>
 <td width="420" style="font-size: 40px">'.number_format($row['amnt']).'</td>

</tr>';
//$amout+=($row['tota']);


 }
 echo'</table><br /><br />';
 
  $ry=mysqli_query($dbc,("select sum(amount)as tot from x_report where type='CASH' AND DAY(date)= DAY(CURRENT_DATE )AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
 $py=mysqli_query($dbc,("select sum(amnt)as tota from expens where DAY(date)= DAY(CURRENT_DATE )AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
$bb=mysqli_query($dbc,("select amnt,date from z_report where DAY(date)= DAY(CURRENT_DATE )and MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())"));
$gbk=mysqli_fetch_array($bb);
  $dll=$gbk['amnt'];
 $go=mysqli_fetch_array($ry);
  $da=$go['tot'];
  $vr=$da+$dll;
  $kj=mysqli_fetch_array($py);
  $dy=$kj['tota'];
  $li=$da-$dy;
  $fj=$li-$dll;
  $mj=$li+$dll;
 echo '<p style="font-size: 40px">TOTAL CASH, LESS  EXPENSES: &nbsp;&nbsp;'.$mj.'</P>';
 echo '<p style="font-size: 40px">CASH AMOUNT VARIATION:&nbsp;&nbsp;'.$fj.'</P>';
 
 mysqli_close($dbc);
 }
function ViewC(){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from accounts
inner join  group_accounts on group_accounts.account_id=accounts.id
where group_id='4' and status='ACTIVE'
and name<>'STOCK'"));
  echo '
     
<table border="1" width="500" cellspacing="0" class="tables"> 
                                                        <thead>
                                                            <tr>
															<th><left>Edit Account</th> 
															<th><left>Account Name</th> 
                                                              <th><left>Phone</th> 
																<th><left>Address</th> 
                                                                	<th><left>Credit Limit</th>
                                                                		<th><left>Deactivate Account</th> 
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr><td><a  rel="facebox" href=edit_c.php?id=' . $row["account_id"] .'>Edit Account</a></td><td>' . (($row['name'])) . '</td>
	<td>' . (($row['phone'])) . '</td>
	<td>' . (($row['address'])) . '</td>
	<td>' .(($row['descc'])) . '</td>
	
	<td><a  rel="facebox" href=delete_c.php?id=' . $row["account_id"] .'>Deactivate Account</a></td></tr>';
}
							echo "</table>";
							mysqli_close($dbc);
}
function Viewg(){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from gmem where status='ACTIVE'
"));
  echo '
     
<table border="1" width="500" cellspacing="0" class="tables"> 
                                                        <thead>
                                                            <tr>
															<th><left>Edit Account</th> 
															<th><left>First Name</th> 
																<th><left>Last Name</th> 
                                                              <th><left>Phone</th> 
																<th><left>County</th> 
																 	<th><left>Fee</th>
                                                                	<th><left>Join Date</th>
                                                                	 	<th><left>Renewal Date</th>
                                                                		<th><left>Deactivate Account</th> 
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr><td><a  rel="facebox" href=edit_c.php?id=' . $row["gid"] .'>Edit Account</a></td><td>' . (($row['firstn'])) . '</td><td>' . (($row['lastn'])) . '</td>
	<td>' . (($row['phone'])) . '</td>
	<td>' . (($row['county'])) . '</td>
	<td>' .(($row['fee'])) . '</td>
		<td>' .(($row['reg'])) . '</td>
			<td>' .(($row['ren'])) . '</td>
	<td><a  rel="facebox" href=delete_c.php?id=' . $row["gid"] .'>Deactivate Account</a></td></tr>';
}
							echo "</table>";
							mysqli_close($dbc);
}
function Viewco(){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from cmem where status='ACTIVE'
"));
  echo '
     
<table border="1" width="500" cellspacing="0" class="tables"> 
                                                        <thead>
                                                            <tr>
															<th><left>Edit Account</th> 
															<th><left>Name</th> 
																<th><left>Adrress</th> 
                                                              <th><left>Phone</th> 
																<th><left>Email</th> 
																 	<th><left>Fee</th>
                                                                	<th><left>Join Date</th>
                                                                	 	<th><left>Renewal Date</th>
                                                                		<th><left>Deactivate Account</th> 
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr><td><a  rel="facebox" href=edit_co.php?id=' . $row["gid"] .'>Edit Account</a></td><td>' . (($row['name'])) . '</td><td>' . (($row['phy'])) . '</td>
	<td>' . (($row['phone'])) . '</td>
	<td>' . (($row['email'])) . '</td>
	<td>' .(($row['fee'])) . '</td>
		<td>' .(($row['reg'])) . '</td>
			<td>' .(($row['ren'])) . '</td>
	<td><a  rel="facebox" href=delete_co.php?id=' . $row["gid"] .'>Deactivate Account</a></td></tr>';
}
							echo "</table>";
							mysqli_close($dbc);
}
function ViewCurrent(){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from accounts
inner join  group_accounts on group_accounts.account_id=accounts.id
where group_id='4' OR group_id='13'
"));
  echo '
     
<table border="1" width="1000" cellspacing="0" > 
                                                        <thead>
                                                            <tr>
															<th><left>De-Activate Ledger</th> 
															<th><left>Activate Ledger</th> 
															<th><left>Account Name</th> 
                                                              <th><left>Status</th> 
															
                                                                    
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr><td><a rel="facebox" href=deactivate.php?id=' . $row["account_id"] .'>De-Activate Ledger</a></td>
	<td><a rel="facebox" href=reactivate.php?id=' . $row["account_id"] .'>Activate Ledger</a></td><td>' . (($row['name'])) . '</td>
	<td>' . (($row['status'])) . '</td>
	</tr>';
}
							echo "</table>";
							mysqli_close($dbc);
}
function ledgerViewC($id,$date1,$date2){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $group=GetGroup($id);
 if($group==2){
$r=mysqli_query($dbc,("select *,sum(credit)as 
credit,sum(debit) as debit,concat(receipt,' ',invoice) as receip from ledgers where account_id='$id' and date between '$date1' and '$date2' group by sub order by date"));
}else{
$r=mysqli_query($dbc,("select *,sum(credit)as 
credit,sum(debit) as debit,concat(invoice,' ',receipt) as receip from ledgers where account_id='$id' and date between '$date1' and '$date2' group by sub order by date"));}

?>          
                
               <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">    
                
                <tr><td style="font-size: 16px" ><center></td></tr>
                 <tr><td style="font-size: 16px" ><center>P.O BOX ,NAIROBI TEL: </center></td></tr></table>

  <div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";><?echo Legers($id);?> Ledger Report For Date Between <?echo $date1;?> To <?echo $date2;?> </h2></div>

<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
 <tr><td><b>DATE</b></td> <td><b>SUB ACCOUNT</b></td> <td><b>ACCOUNT</b></td><td><b>NO</b></td><td><b>DESCRIPTION</b></td><td><b>DEBIT</b></td><td><b>CREDIT:</b></td></tr>
 <?while ($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['date'].'</td><td>'.SubName($row['sub']).'</td><td>'.Acc($row['froms']).'</td><td>'.Nosee($row['receip']).'</td><td>'.$row['description'].'</td><td>'.Nosee(number_format($row['debit'])).'</td><td>'.Nosee(number_format($row['credit'])).'</td></tr>';
 $debit+=$row['debit'];
 $credit+=$row['credit'];
 }
 echo '<tr><td colspan="5"><center>SUB TOTAL</td><td><center>'.number_format($debit).'</td><td><center>'.number_format($credit).'</td></tr>';
 $group=GetGroup($id);
 if($group==4||$group==1||$group==7||$group==6||$group==9||$group==10){
 $t=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit from ledgers where account_id='$id' and date between '$date1' and '$date2' "));
 $row=mysqli_fetch_array($t);
 $debit=$row['debit'];
 echo '<tr><td colspan="5"><b>Balance</td><td><b>'.number_format($debit).'</td></tr>';
 }
 if($group==3||$group==2||$group==5){
  $t=mysqli_query($dbc,("select sum(credit)-sum(debit)as debit from ledgers where account_id='$id' and date between '$date1' and '$date2' "));
 $row=mysqli_fetch_array($t);
 $debit=$row['debit'];
 echo '<tr><td colspan="5"><center><b>Balance</td><td colspan="2"><b><center>'.number_format($debit).'</td></tr>';
 }
 ?> 
 

 </table><br>
 <?
 mysqli_close($dbc);
 }
function Viewincome(){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from accounts
inner join  group_accounts on group_accounts.account_id=accounts.id
where group_id='3'
"));
  echo '
     
<table border="1" width="1000" cellspacing="0" > 
                                                        <thead>
                                                            <tr>
															<th><left>De-Activate Ledger</th> 
															<th><left>Activate Ledger</th> 
															<th><left>Account Name</th> 
                                                              <th><left>Status</th> 
															
                                                                    
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr><td><a rel="facebox" href=deactivate.php?id=' . $row["account_id"] .'>De-Activate Ledger</a></td>
	<td><a rel="facebox" href=reactivate.php?id=' . $row["account_id"] .'>Activate Ledger</a></td><td>' . (($row['name'])) . '</td>
	<td>' . (($row['status'])) . '</td>
	</tr>';
}
							echo "</table>";
							mysqli_close($dbc);
}
function ViewExpense(){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from accounts
inner join  group_accounts on group_accounts.account_id=accounts.id
where group_id='1'
"));
  echo '
     
<table border="1" width="1000" cellspacing="0" > 
                                                        <thead>
                                                            <tr>
															<th><left>De-Activate Ledger</th> 
															<th><left>Account Name</th> 
                                                              <th><left>Status</th> 
															
                                                                    
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr><td><a rel="facebox" href=deactivate.php?id=' . $row["account_id"] .'>De-Activate Ledger</a></td>
	<td><a rel="facebox" href=reactivate.php?id=' . $row["account_id"] .'>Activate Ledger</a></td><td>' . (($row['name'])) . '</td>
	<td>' . (($row['status'])) . '</td>
	</tr>';
}
							echo "</table>";
							mysqli_close($dbc);
}

function ViewMonetary(){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from accounts
inner join  group_accounts on group_accounts.account_id=accounts.id
where group_id='10'
"));
  echo '
     
<table border="1" width="1000" cellspacing="0" > 
                                                        <thead>
                                                            <tr>
															<th><left>De-Activate Ledger</th> 
															<th><left>Activate Ledger</th> 
															<th><left>Account Name</th> 
                                                              <th><left>Account Code</th> 
															
                                                                    
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr><td><a rel="facebox" href=deactivate.php?id=' . $row["account_id"] .'>De-Activate Ledger</a></td>
	<td><a rel="facebox" href=reactivate.php?id=' . $row["account_id"] .'>Activate Ledger</a></td><td>' . (($row['name'])) . '</td>
	<td>' . (($row['status'])) . '</td>
	</tr>';
}
							echo "</table>";
							mysqli_close($dbc);
}

function ViewLiability(){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from accounts
inner join  group_accounts on group_accounts.account_id=accounts.id
where group_id='2'
"));
  echo '
     
<table border="1" width="1000" cellspacing="0"> 
                                                        <thead>
                                                            <tr>
															<th><left>De-Activate Ledger</th> 
															<th><left>Activate Ledger</th> 
															<th><left>Account Name</th> 
                                                              <th><left>Status</th> 
															
                                                                    
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr><td><a rel="facebox" href=deactivate.php?id=' . $row["account_id"] .'>De-Activate Ledger</a></td>
	<td><a rel="facebox" href=reactivate.php?id=' . $row["account_id"] .'>Activate Ledger</a></td><td>' . (($row['name'])) . '</td>
	<td>' . (($row['status'])) . '</td>
	</tr>';
}
							echo "</table>";
							mysqli_close($dbc);
}


 function ledgerView($id,$date1,$date2){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $group=GetGroup($id);
if($group==2){
$r=mysqli_query($dbc,("select *,sum(credit)as 
credit,sum(debit) as debit,qty,price,dat,concat(receipt,' ',invoice) as receip from ledgers where account_id='$id'
 and date between '$date1' and '$date2' group by id order by dat ASC"));
}else{
$r=mysqli_query($dbc,("select *,sum(credit)as 
credit,sum(debit) as debit,dat,qty,price,concat(invoice,' ',receipt) as receip from ledgers where account_id='$id'
 and date between '$date1' and '$date2' group by id order by dat ASC"));}
 $opening=LedgerBalance($id,$date1);
?>          
         <a href="javascript:void(printDiv('printMe'));"><input type="image" width="30" height="21" value=<img src="print.png"/></a></div><center>
<div id="printMe"> 
 <table class="blue" border="1" style="background-color:#ffffff"; rules="NONE"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial";>
 <tr> <td>
  <strong><img border="0" src="G.PNG" width="1020" height="121"></td></tr></table> 
               <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="1050" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">    
                  

  <div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";><?echo Legers($id);?> Ledger Report For Date Between <?echo $date1;?> To <?echo $date2;?> </h2></div>

<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="1050" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial"> <tr><td  colspan="8"><b><center>LEDGER OPENING BALANCE</td><td ><b><?echo number_format($opening);?></b></td></tr>
 
 <tr><td><b>DATE</b></td>  <td><b>ACCOUNT</b></td><td><b>NO</b></td><td><b>DESCRIPTION</b></td><b><td>QTY</td><b><td>PRICE</td><td><b>DEBIT</b></td><td><b>CREDIT</b></td></td><td><b>BALANCE</b></td></tr>

 <?
 

 $group=GetGroup($id);
 while ($row=mysqli_fetch_array($r)){
   if($group==4||$group==10){
 $opening=$opening+$row['debit']-$row['credit'];
 $closing=$opening;
 }
  if($group==3||$group==2||$group==5||$group==14){
 $opening=$opening+$row['credit']-$row['debit'];
  $closing=$opening;
 }
 echo '<tr><td>'.$row['date'].'</td><td>'.Acc($row['froms']).'</td>
 <td>'.Nosee($row['receip']).'</td><td>'.$row['description'].'</td><td>'.$row['qty'].'</td><td>'.$row['price'].'</td><td>'.Nosee(number_format($row['debit'])).'</td>
 <td>'.Nosee(number_format($row['credit'])).'</td> <td><b>'.(number_format($opening)).'</td></tr>';

 $debit+=$row['debit'];
 $credit+=$row['credit'];
 }



 ?> 
 

 </table><br>
 <?mysqli_close($dbc);}
 function SubledgerView($id,$date1,$date2,$sub){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from ledgers where account_id='$id' and sub='$sub' and date between '$date1' and '$date2' group by session order by date"));

?>          
                
               <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">    
                
                <tr><td style="font-size: 16px" ><center></td></tr>
                 <tr><td style="font-size: 16px" ><center>P.O BOX ,NAIROBI TEL: </center></td></tr></table>

  <div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";><?echo SubName($sub);?> Sub Ledger Report For Date Between <?echo $date1;?> To <?echo $date2;?> </h2></div>

<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
 <tr><td><b>DATE</b></td> <td><b>ACCOUNT</b></td><td><b>NO</b></td><td><b>DESCRIPTION</b></td><td><b>DEBIT</b></td><td><b>CREDIT:</b></td></tr>
 <?while ($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['date'].'</td><td>'.Acc($row['froms']).'</td><td>'.Nosee($row['receipt']).'</td><td>'.$row['description'].'</td><td>'.Nosee(number_format($row['debit'])).'</td><td>'.(number_format($row['credit'])).'</td></tr>';
 $debit+=$row['debit'];
 $credit+=$row['credit'];
 }
 echo '<tr><td colspan="5"><center>SUB TOTAL</td><td><center>'.number_format($debit).'</td><td><center>'.number_format($credit).'</td></tr>';
 $group=GetGroup($id);
 if($group==4||$group==1||$group==7||$group==6||$group==9||$group==10){
 $t=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit from ledgers where account_id='$id' and sub='$sub' and date between '$date1' and '$date2' "));
 $row=mysqli_fetch_array($t);
 $debit=$row['debit'];
 echo '<tr><td colspan="5"><center><b>Balance</td><td colspan="2"><center><b>'.number_format($debit).'</td></tr>';
 }
 if($group==3||$group==2||$group==5){
  $t=mysqli_query($dbc,("select sum(credit)-sum(debit)as debit from ledgers where  account_id='$id' and sub='$sub' and date between '$date1' and '$date2' "));
 $row=mysqli_fetch_array($t);
 $debit=$row['debit'];
 echo '<tr><td colspan="5"><center><b>Balance</td><td colspan="2"><center><b>'.number_format($debit).'</td></tr>';
 }
 ?> 
 

 </table><br>
 <?mysqli_close($dbc);}
 function GeneralLedger($date1,$date2){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
	 $group=GetGroup($id); 
$r=mysqli_query($dbc,("select * from accounts
inner join group_accounts on group_accounts.account_id=accounts.id
where group_id='1'"));
while($ex=mysqli_fetch_array($r)){
$id=$ex['account_id'];
 $opening=LedgerBalance1($id,$date1,$dat);
?>
<div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";><?echo Legers($id);?> Ledger  </h2></div>

<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td> <td><b>ACCOUNT</b></td><td><b>NO</b></td><td><b>DESCRIPTION</b></td><td><b>DEBIT</b></td><td><b>CREDIT:</b></td><td><b>Closing</b></td></tr>
<?
$group=GetGroup($id);
$ro=mysqli_query($dbc,("select * from ledgers where account_id='$id' and date between '$date1' and '$date2' order by date"));
$d=0;
$c=0;
while($row=mysqli_fetch_array($ro)){
if($group==3||$group==2||$group==5||$group==14){
 $opening=$opening+$row['credit']-$row['debit'];
  $closing=$opening;
 }
echo '<tr><td>'.$row['date'].'</td><td>'.Acc($row['froms']).'</td><td>'.($row['receipt']).'</td><td>'.$row['description'].'</td><td>'.Nosee(number_format($row['debit'])).'</td><td>'.(number_format($row['credit'])).'</td><td>'.(number_format($opening)).'</td></tr>';
 $d+=$row['debit'];
 $c+=$row['credit'];
 }
 echo '<tr><td colspan="4"><center>SUB TOTAL</td><td><center>'.number_format($d).'</td><td><center>'.number_format($c).'</td></tr>';
 $group=GetGroup($id);

 $t=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit from ledgers where account_id='$id' and date between '$date1' and '$date2' "));
 $row=mysqli_fetch_array($t);
 $expe=$row['debit'];
 echo '<tr><td colspan="4"><b>Balance</td><td><b>'.number_format($expe).'</td></tr></table><br>';
 

}
$r=mysqli_query($dbc,("select * from accounts
inner join group_accounts on group_accounts.account_id=accounts.id
where group_id='2'"));
while($ex=mysqli_fetch_array($r)){
$id=$ex['account_id'];

?>
<br><br>
<div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";><?echo Legers($id);?> Ledger  </h2></div>

<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td> <td><b>ACCOUNT</b></td><td><b>NO</b></td><td><b>DESCRIPTION</b></td><td><b>DEBIT</b></td><td><b>CREDIT:</b></td></tr>
<?
$ro=mysqli_query($dbc,("select * from ledgers where account_id='$id' and date between '$date1' and '$date2' order by date"));
$dei=0;
$cr=0;
while($row=mysqli_fetch_array($ro)){

echo '<tr><td>'.$row['date'].'</td><td>'.Acc($row['froms']).'</td><td>'.($row['receipt']).'</td><td>'.$row['description'].'</td><td>'.Nosee(number_format($row['debit'])).'</td><td>'.(number_format($row['credit'])).'</td></tr>';
 $dei+=$row['debit'];
 $cr+=$row['credit'];
 }
 echo '<tr><td colspan="4"><center>SUB TOTAL</td><td><center>'.number_format($dei).'</td><td><center>'.number_format($cr).'</td></tr>';
 $group=GetGroup($id);

  $t=mysqli_query($dbc,("select sum(credit)-sum(debit)as debit from ledgers where account_id='$id' and date between '$date1' and '$date2' "));
 $row=mysqli_fetch_array($t);
 $liab=$row['debit'];
 echo '<tr><td colspan="4"><center><b>Balance</td><td><b>'.number_format($liab).'</td></tr></table><br>';
 
}
$r=mysqli_query($dbc,("select * from accounts
inner join group_accounts on group_accounts.account_id=accounts.id
where group_id='3'"));
while($ex=mysqli_fetch_array($r)){
$id=$ex['account_id'];

?>
<br><br>
<div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";><?echo Legers($id);?> Ledger  </h2></div>

<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td> <td><b>ACCOUNT</b></td><td><b>NO</b></td><td><b>DESCRIPTION</b></td><td><b>DEBIT</b></td><td><b>CREDIT:</b></td></tr>
<?
$ro=mysqli_query($dbc,("select * from ledgers where account_id='$id' and date between '$date1' and '$date2' order by date"));
$deb=0;
$cre=0;
while($row=mysqli_fetch_array($ro)){

echo '<tr><td>'.$row['date'].'</td><td>'.Acc($row['froms']).'</td><td>'.($row['receipt']).'</td><td>'.$row['description'].'</td><td>'.Nosee(number_format($row['debit'])).'</td><td>'.(number_format($row['credit'])).'</td></tr>';
 $deb+=$row['debit'];
 $cre+=$row['credit'];
 }
 echo '<tr><td colspan="4"><center>SUB TOTAL</td><td><center>'.number_format($deb).'</td><td><center>'.number_format($cre).'</td></tr>';
 $group=GetGroup($id);

 
  $t=mysqli_query($dbc,("select sum(credit)-sum(debit)as debit from ledgers where account_id='$id' and date between '$date1' and '$date2' "));
 $row=mysqli_fetch_array($t);
 $inc=$row['debit'];
 echo '<tr><td colspan="4"><center><b>Balance</td><td><b>'.number_format($inc).'</td></tr></table><br>';
 
}
$r=mysqli_query($dbc,("select * from accounts
inner join group_accounts on group_accounts.account_id=accounts.id
where group_id='4'"));
while($ex=mysqli_fetch_array($r)){
$id=$ex['account_id'];

?>
<br><br>
<div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";><?echo Legers($id);?> Ledger  </h2></div>

<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td> <td><b>ACCOUNT</b></td><td><b>NO</b></td><td><b>DESCRIPTION</b></td><td><b>DEBIT</b></td><td><b>CREDIT:</b></td></tr>
<?

$ro=mysqli_query($dbc,("select * from ledgers where account_id='$id' and date between '$date1' and '$date2' order by date"));
$debi=0;
$cred=0;
while($row=mysqli_fetch_array($ro)){

echo '<tr><td>'.$row['date'].'</td><td>'.Acc($row['froms']).'</td><td>'.($row['receipt']).'</td><td>'.$row['description'].'</td><td>'.Nosee(number_format($row['debit'])).'</td><td>'.(number_format($row['credit'])).'</td></tr>';
 $debi+=$row['debit'];
 $cred+=$row['credit'];
 }
 echo '<tr><td colspan="4"><center>SUB TOTAL</td><td><center>'.number_format($debi).'</td><td><center>'.number_format($cred).'</td></tr>';
 $group=GetGroup($id);

 $t=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit from ledgers where account_id='$id' and date between '$date1' and '$date2' "));
 $row=mysqli_fetch_array($t);
 $cur=$row['debit'];
 echo '<tr><td colspan="4"><b>Balance</td><td><b>'.number_format($cur).'</td></tr></table><br>';

}
$r=mysqli_query($dbc,("select * from accounts
inner join group_accounts on group_accounts.account_id=accounts.id
where group_id='10'"));
while($ex=mysqli_fetch_array($r)){
$id=$ex['account_id'];

?>
<br><br>
<div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";><?echo Legers($id);?> Ledger  </h2></div>

<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td> <td><b>ACCOUNT</b></td><td><b>NO</b></td><td><b>DESCRIPTION</b></td><td><b>DEBIT</b></td><td><b>CREDIT:</b></td></tr>
<?

$ro=mysqli_query($dbc,("select * from ledgers where account_id='$id' and date between '$date1' and '$date2' order by date"));
$debi=0;
$cred=0;
while($row=mysqli_fetch_array($ro)){

echo '<tr><td>'.$row['date'].'</td><td>'.Acc($row['froms']).'</td><td>'.($row['receipt']).'</td><td>'.$row['description'].'</td><td>'.Nosee(number_format($row['debit'])).'</td><td>'.(number_format($row['credit'])).'</td></tr>';
 $debi+=$row['debit'];
 $cred+=$row['credit'];
 }
 echo '<tr><td colspan="4"><center>SUB TOTAL</td><td><center>'.number_format($debi).'</td><td><center>'.number_format($cred).'</td></tr>';
 $group=GetGroup($id);

 $t=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit from ledgers where account_id='$id' and date between '$date1' and '$date2' "));
 $row=mysqli_fetch_array($t);
 $cur=$row['debit'];
 echo '<tr><td colspan="4"><b>Balance</td><td><b>'.number_format($cur).'</td></tr></table><br>';

}
$r=mysqli_query($dbc,("select * from accounts
inner join group_accounts on group_accounts.account_id=accounts.id
where group_id='5'"));
while($ex=mysqli_fetch_array($r)){
$id=$ex['account_id'];

?>
<br><br>
<div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";><?echo Legers($id);?> Ledger  </h2></div>

<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td> <td><b>ACCOUNT</b></td><td><b>NO</b></td><td><b>DESCRIPTION</b></td><td><b>DEBIT</b></td><td><b>CREDIT:</b></td></tr>
<?
$ro=mysqli_query($dbc,("select * from ledgers where account_id='$id' and date between '$date1' and '$date2' order by date"));
$debit=0;
$cred=0;
while($row=mysqli_fetch_array($ro)){

echo '<tr><td>'.$row['date'].'</td><td>'.Acc($row['froms']).'</td><td>'.($row['receipt']).'</td><td>'.$row['description'].'</td><td>'.Nosee(number_format($row['debit'])).'</td><td>'.(number_format($row['credit'])).'</td></tr>';
 $debit+=$row['debit'];
 $credi+=$row['credit'];
 }
 echo '<tr><td colspan="4"><center>SUB TOTAL</td><td><center>'.number_format($debit).'</td><td><center>'.number_format($credi).'</td></tr>';
 $group=GetGroup($id);
 
  $t=mysqli_query($dbc,("select sum(credit)-sum(debit)as debit from ledgers where account_id='$id' and date between '$date1' and '$date2' "));
 $row=mysqli_fetch_array($t);
 $cap=$row['debit'];
 echo '<tr><td colspan="4"><center><b>Balance</td><td><b>'.number_format($cap).'</td></tr></table><br>';
 
}
$r=mysqli_query($dbc,("select * from accounts
inner join group_accounts on group_accounts.account_id=accounts.id
where group_id='7'"));
while($ex=mysqli_fetch_array($r)){
$id=$ex['account_id'];

?>
<br><br>
<div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";><?echo Legers($id);?> Ledger  </h2></div>

<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td> <td><b>ACCOUNT</b></td><td><b>NO</b></td><td><b>DESCRIPTION</b></td><td><b>DEBIT</b></td><td><b>CREDIT:</b></td></tr>
<?
$ro=mysqli_query($dbc,("select * from ledgers where account_id='$id' and date between '$date1' and '$date2' order by date"));
$debitt=0;
$credit=0;
while($row=mysqli_fetch_array($ro)){

echo '<tr><td>'.$row['date'].'</td><td>'.Acc($row['froms']).'</td><td>'.($row['receipt']).'</td><td>'.$row['description'].'</td><td>'.Nosee(number_format($row['debit'])).'</td><td>'.(number_format($row['credit'])).'</td></tr>';
 $debitt+=$row['debit'];
 $credit+=$row['credit'];
 }
 echo '<tr><td colspan="4"><center>SUB TOTAL</td><td><center>'.number_format($debitt).'</td><td><center>'.number_format($credit).'</td></tr>';
 $group=GetGroup($id);

 $t=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit from ledgers where account_id='$id' and date between '$date1' and '$date2' "));
 $row=mysqli_fetch_array($t);
 $dire=$row['debit'];
 echo '<tr><td colspan="4"><b>Balance</td><td><b>'.number_format($dire).'</td></tr></table><br>';
 

}

$r=mysqli_query($dbc,("select * from accounts
inner join group_accounts on group_accounts.account_id=accounts.id
where group_id='8'"));
while($ex=mysqli_fetch_array($r)){
$id=$ex['account_id'];

?>
<br><br>
<div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";><?echo Legers($id);?> Ledger  </h2></div>

<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td> <td><b>ACCOUNT</b></td><td><b>NO</b></td><td><b>DESCRIPTION</b></td><td><b>DEBIT</b></td><td><b>CREDIT:</b></td></tr>
<?
$debittt=0;
$creditt=0;
$ro=mysqli_query($dbc,("select * from ledgers where account_id='$id' and date between '$date1' and '$date2' order by date"));
while($row=mysqli_fetch_array($ro)){

echo '<tr><td>'.$row['date'].'</td><td>'.Acc($row['froms']).'</td><td>'.($row['receipt']).'</td><td>'.$row['description'].'</td><td>'.Nosee(number_format($row['debit'])).'</td><td>'.(number_format($row['credit'])).'</td></tr>';
 $debittt+=$row['debit'];
 $creditt+=$row['credit'];
 }
 echo '<tr><td colspan="4"><center>SUB TOTAL</td><td><center>'.number_format($debittt).'</td><td><center>'.number_format($creditt).'</td></tr>';
 $group=GetGroup($id);

 $t=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit from ledgers where account_id='$id' and date between '$date1' and '$date2' "));
 $row=mysqli_fetch_array($t);
 $liab=$row['debit'];
 echo '<tr><td colspan="4"><b>Balance</td><td><b>'.number_format($liab).'</td></tr></table><br>';
 

}
mysqli_close($dbc);
}
function Profit($date1,$date2){
     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");?> 
 
           <table class="blue" border="1" style="background-color:#ffffff"; rules="NONE"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial";>
 <tr> <td>
  <strong><img border="0" src="logo.jpg" height="300px;" width="90%"></td></tr></table> 
                
               <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">    
                
                <tr><td style="font-size: 16px" ><center></td></tr>
                 <tr><td style="font-size: 16px" ><center>P.O BOX ,NAIROBI TEL: </center></td></tr></table>

  
  <div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";>Profit Statement For Date Between <?echo $date1;?> To <?echo $date2;?> </h4></div>

<table class="blue" border="1" style="background-color:#ffffff"
       rules="NONE" frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial"><?

  echo '<tr><td><b>INCOME</td> <td></td></tr>';
 $h=mysqli_query($dbc,("select  sum(credit)as credit,ledgers.account_id as account_id from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='3'

and ledgers.date between '$date1' and '$date2'
and description<>'P & L'
group by ledgers.account_id
having credit>0
"));

while($row=mysqli_fetch_array($h)){
echo '<tr><td>'.Legers($row['account_id']).'</td> <td>'.number_format($row['credit']).'</td></tr>';
$income+=$row['credit'];
 }
 


  echo '<tr><td><b>TOTAL INCOME</td> <td><u><b>'.number_format($income).'</td></tr>';
 echo '<tr><td colspan="2"><b>DIRECT COST</td> </tr>';
  $c=mysqli_query($dbc,("select  sum(debit)as credit,ledgers.account_id as account_id   from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='7'
and description<>'P & L'
and ledgers.date between '$date1' and '$date2'
group by ledgers.account_id
having credit>0
"));
while($row=mysqli_fetch_array($c)){
echo '<tr><td>'.Legers($row['account_id'],$row['department']).'</td> <td>'.number_format($row['credit']).'</td></tr>';
$cost+=$row['credit'];
 }
 echo '<tr><td><b>TOTAL COST</td> <td><u><b>'.number_format($cost).'</td></tr>';
 echo '<tr><td><b>GROSS PROFIT</td> <td><b><u>'.number_format($income-$cost).'</td></tr>';
  echo '<tr><td colspan="2"><b>EXPENSES</td> </tr>';
  $co=mysqli_query($dbc,("select  sum(debit)-sum(credit)as credit,ledgers.account_id as account_id   from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='1' 
and description<>'P & L'
and ledgers.date between '$date1' and '$date2'

group by ledgers.account_id
having credit>0

"));
while($row=mysqli_fetch_array($co)){
echo '<tr><td>'.Legers($row['account_id'],$row['department']).'</td> <td>'.number_format($row['credit']).'</td></tr>';
$expenses+=$row['credit'];
 }

  echo '<tr><td><b>TOTAL EXPENSES</td> <td><u><b>'.number_format($expenses+$dep).'</td></tr>';
  echo '<tr><td><b>PROFIT FOR PERIOD</td> <td><u><b><u>'.number_format(($income-$cost)-($expenses+$dep)).'</td></tr></table><br>';
  mysqli_close($dbc);
 }
 
function Viewfinancial(){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from financial_year order by id
"));
  echo '
     
<table border="1" width="500" cellspacing="0" class="tables"> 
                                                        <thead>
                                                            <tr>
															<th><left>Close Year</th> 
															<th><left>Re-Open Year</th> 
															<th><left>Start Date</th> 
															<th><left>End Date</th> 
                                                              <th><left>Status</th> 
															
                                                                    
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr><td><a rel="facebox" href=close.php?id=' . $row["id"] .'>Close Year</a></td>
	<td><a rel="facebox" href=open.php?id=' . $row["id"] .'>Re-Open Year</a></td>
	<td>' . (($row['start'])) . '</td>
		<td>' . (($row['end'])) . '</td>
	<td>' . (($row['status'])) . '</td>
	</tr>';
}
							echo "</table>";
							mysqli_close($dbc);
}
function ViewUserActivities($date1,$date2){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from user_trail
inner join users on users.user_id=user_trail.user
where user_trail.date between '$date1' and '$date2'
order by date,time
"));
  echo '<div align="center">ALL USERS AUDIT TRAIL </div>
     
<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
                                                            <tr>
															<th><left>Date</th> 
															<th><left>Time</th> 
															<th><left>Activity</th> 
															<th><left>User</th> 
                                                          
															
                                                                    
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr>
	
	<td>' . (($row['date'])) . '</td>
		<td>' . (($row['time'])) . '</td>
	<td>' . (($row['action'])) . '</td>
	<td>' . (($row['user_name'])) . '</td>
	</tr>';
}
							echo "</table>";
							mysqli_close($dbc);
}

 function TodaySales(){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT *,qty as  q,total_p as 
 total FROM sales WHERE DAY( date ) = DAY(CURRENT_DATE )
AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())
and status='ACTIVE' group by sale_id order by number asc"));

 ?><table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td><td><b>TYPE</b> <td><b>RECEIPT</b></td><td><b>PRODUCT</b></td><td><b>QTY</b></td><td><b>PRICE</td><td><b>TOTAL</td><td><b>PROFIT</b></td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['date'].'</td><td>'.$row['type'].'</td><td>'.$row['number'].'</td><td>'.$row['p_name'].'</td><td>'.$row['q'].'</td><td>'.number_format($row['price']).'</td>
 <td>'.number_format($row['total']).'</td>
 <td>'.number_format($row['prof']).'</td>
 </tr>';
 @$total+=$row['total'];
 @$prof+=$row['prof'];
 }
 
 echo '<tr><td colspan="6"><center>TOTAL</td><td>'.number_format($total).'</td><td>'.number_format($prof).'</td></tr>';
  echo '</table>';
 mysqli_close($dbc);
 }
 function bals(){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("select name,sum(debit)-sum(ledgers.credit)as balance from ledgers
inner join accounts on accounts.id=ledgers.account_id
where  accounts.stat='CUSTOMER' and accounts.status='ACTIVE'
group by ledgers.account_id having balance>0
order by balance desc"));

 ?>    
         <a href="javascript:void(printDiv('printMe'));"><input type="image" width="30" height="21" value=<img src="print.png"/></a></div><center>
<div id="printMe">    

           <table class="blue" border="1" style="background-color:#ffffff"; rules="NONE"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial";>
 <tr> <td>
  <strong><img border="0" src="G.PNG" width="1040" height="121"></td></tr></table> 
               <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="1050" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">    
                
                   <tr><td colspan="2"><h3><b><center></center></b></h3></td></tr>
				   <? echo '<tr><td colspan="2"><center><b>OutStanding Balances As At Date:&nbsp;' . (date("Y/m/d")) . '</center></td></tr>';?>
                 <tr><td colspan="2"><center></center></td></tr>
				
								
										
<tr><td><b>NAME</b></td><td><b>DEBT</b></td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['name'].'</td><td>'.$row['balance'].'</td>
 
 </tr>';
 @$total+=$row['balance'];
 @$prof+=$row['prof'];
 }
 
 echo '<tr><td colspan="1"><center>TOTAL</td><td>'.round($total).'</td></tr>';
  echo '</table>';
 mysqli_close($dbc);
 }
 function YesterdaySales(){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT *,sum(qty)as q,round(sum(total_p))as
 total FROM sales WHERE DAY( date ) = DAY(CURRENT_DATE-1 )
AND MONTH(date)=MONTH(NOW())
AND YEAR(date)=YEAR(NOW())
and status='ACTIVE' group by sale_id order by number asc"));
?>
 <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td><td><b>TYPE</b></td> <td><b>RECEIPT</b></td><td><b>PRODUCT</b></td><td><b>QTY</b></td><td><b>PRICE</td><td><b>TOTAL</td><td><b>PROFIT</b></td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['date'].'</td><td>'.$row['type'].'</td><td>'.$row['number'].'</td><td>'.$row['p_name'].'</td><td>'.$row['q'].'</td><td>'.number_format($row['price']).'</td>
 <td>'.number_format($row['total']).'</td>
  <td>'.number_format($row['prof']).'</td>
 </tr>';
@$total+=$row['total'];
 @$prof+=$row['prof'];
 }
 echo '<tr><td colspan="6"><center>TOTAL</td><td>'.number_format($total).'</td><td>'.number_format($prof).'</td></tr>';
  echo '</table>';
 mysqli_close($dbc);
 }
 function SalesDates($date1,$date2){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT *,sum(qty)as q,(sum(total_p))as
 total FROM sales where date between '$date1' and '$date2'
and status='ACTIVE' group by sale_id order by number desc"));
$gh=mysqli_query($dbc,("SELECT sum (prof)as
 fin FROM sales WHERE DAY( date ) = DAY(CURRENT_DATE-1 )"));
  $th=mysqli_fetch_array($gh);
 $fin=$th['fin'];
 ?>
 <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td> <td><b>RECEIPT</b></td><td><b>PRODUCT</b></td><td><b>QTY</b></td><td><b>PRICE</td><td><b>TOTAL</td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['date'].'</td><td>'.$row['number'].'</td><td>'.$row['p_name'].'</td><td>'.$row['q'].'</td><td>'.number_format($row['price']).'</td>
 <td>'.number_format($row['total']).'</td></tr>';
 $total+=$row['total'];
 
 }
 echo '<tr><td colspan="5"><center>TOTAL</td><td>'.number_format($total).'</td><td>'.number_format($fin).'</td></tr>';
  echo '</table>';
  mysqli_close($dbc);
 }
  function ProductProperties(){
	      				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT * from products order by p_name"));
 ?><div align="center"><h3>Product Properties</h3></div>
 <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>PRODUCT NAME</b></td> <td><b>CATEGORY</b></td><td><b>QTY LEFT</b></td><td><b>BUYING </b></td><td><b>SELLING </b></td><td><b>MARGIN</b></td></tr><?
 $t=0;
 while($row=mysqli_fetch_array($r)){
 $t++;
 if($t==42){
 echo '<tr><td><b>PRODUCT NAME</b></td> <td><b>CATEGORY</b></td><td><b>QTY LEFT</b></td><td><b>BUYING </b></td><td><b>SELLING </b></td><td><b>MARGIN</b></td></tr>';
 $t=0;
 }
 echo '<tr><td>'.$row['p_name'].'</td><td>'.$row['category'].'</td><td>'.$row['left_p'].'</td><td>'.$row['buying'].'</td><td>'.number_format($row['price']).'</td><td>'.number_format(($row['price'])-($row['buying'])).'</td>
</tr>';
 $total+=$row['total'];
 
 }

  echo '</table>';
  mysqli_close($dbc);
 }
  function Props(){
	      				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT * from products where category!='CONDOMS' order by category asc"));
 ?><div align="center"><h2>PRODUCTS PRICE LIST</h3></div>
 <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
  <tr><td colspan="4"><h2><b><center><strong></center></b></h3></td></tr>
                 								 <tr><td colspan="4"><center><H2><strong></center></td></tr>
				 <tr><td colspan="4"><center><H2><strong></center></td></tr>

<tr><td colspan="4"><center><H2><strong></center></td></tr>								 
<tr><td><b>PRODUCT NAME</b></td> <td><b>CATEGORY</b></td><td><b>WHOLESALE</b></td><td><b>RETAIL</b></td></tr><?
 $t=0;
 while($row=mysqli_fetch_array($r)){
 $t++;
 if($t==42){
 echo '<tr><td><b>PRODUCT NAME</b></td> <td><b>CATEGORY</b></td><td><b>WHOLESALE</b></td><td><b>RETAIL</b></td></tr>';
 $t=0;
 }
 echo '<tr><td>'.$row['p_name'].'</td><td>'.$row['category'].'</td><td>'.$row['minimum'].'</td><td>'.$row['price'].'</td>
</tr>';
 $total+=$row['total'];
 
 }

  echo '</table>';
  mysqli_close($dbc);
 }
 function propp(){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
	 $hy=mysqli_query($dbc,("select * from products where  category!='CONDOMS' order by p_name asc"));?>
	 <div align="center"><h2>RECONCILLIATION SHEET</h2></div>
 <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
  <tr><td colspan="4"><h2><b><center><strong></center></b></h3></td></tr>
	 <tr><td colspan="4"><center><H2><strong></center></td></tr>								 
<tr><td><b>PRODUCT NAME</b></td> <td><b>ISSUED</b></td><td><b>SOLD</b></td><td><b>RETURNED</b></td></tr><?
while($row=mysqli_fetch_array($hy)){
	
	 echo '<tr><td>'.$row['p_name'].'</td><td></td><td></td><td></td></tr>';
	
}
	 echo '</table>'; 
	 mysqli_close($dbc);
 }
 function proppp(){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
	 $hy=mysqli_query($dbc,("select * from products where  category!='CONDOMS' order by p_name asc"));?>
	 <div align="center"><h2>PRODUCTS PRICE LIST</h3></div>
 <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
  <tr><td colspan="5"><h2><b><center><strong></center></b></h3></td></tr>
	 <tr><td colspan="5"><center><H2><strong></center></td></tr>								 
<tr><td><b>PRODUCT NAME</b></td> <td><b>BUYING</b></td><td><b>DISTRIBUTOR</b></td><td><b>WHOLESALE</b></td><td><b>RETAIL</b></td></tr><?
while($row=mysqli_fetch_array($hy)){
	
	 echo '<tr><td>'.$row['p_name'].'</td><td>'.$row['buying'].'</td><td>'.$row['distro'].'</td><td>'.$row['minimum'].'</td><td>'.$row['price'].'</td></tr>';
	
}
	 echo '</table>'; 
	 mysqli_close($dbc);
 }
 function StockQty(){
 require_once('print.php');
     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT  * FROM products
ORDER BY left_p ASC "));
 ?>
 <a href="javascript:void(processPrint());"><input type="image" value=<img src="print.png"/></a>
<div id="printMe"><div align="center">STOCK REPORT BY QTY</div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>PRODUCT</b></td> <td><b>QTY LEFT</b></td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['p_name'].'</td><td>'.number_format($row['left_p']).'</td>
</tr>';
 }
 echo '</table></div>';
 mysqli_close($dbc);
 }
 
 function ProductPropertiess(){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT * from products where price<>0 order by p_name"));
 ?><div align="center"><h3>Product Properties</h3></div>
 <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>PRODUCT NAME</b></td> <td><b>SELLING </b></td></tr><?
 $t=0;
 while($row=mysqli_fetch_array($r)){
 $t++;
 if($t==42){
 echo '<tr><td><b>PRODUCT NAME</b></td><td><b>SELLING </b></td></tr>';
 $t=0;
 }
 echo '<tr><td>'.$row['p_name'].'</td><td>'.number_format($row['price']).'</td>
</tr>';
 
 
 }

  echo '</table>';
  mysqli_close($dbc);
 }
 function PurchasesReports($date1,$date2){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT *,sum(total_p)as d FROM stocking where 
 p_date BETWEEN '$date1' AND '$date2'
 group by t_code order by supplier

"));
mysqli_close($dbc);
 }
 function BestMargins($date1,$date2){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT p_name, avg(price)as selling,avg(p_price)as buying,avg(price)-avg(p_price)as margin,
 ((avg(price)-avg(p_price))/avg(p_price))*100 as perc
 from sales where date between '$date1' and '$date2'
 and p_price>0
 
 group by p_name order by perc desc"));
 ?><div align="center">PRODUCTS MARGIN REPORT FOR DATE BETWEEN <?echo $date1;?> AND <?echo $date2;?></div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>PRODUCT</b></td> <td><b>AVG BUYING</b></td><td><b>AVG SELLING</b></td><td><b>MARGIN</b></td><td><b>PERCENTAGE</b></td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['p_name'].'</td><td>'.number_format($row['buying']).'</td><td>'.number_format($row['selling']).'</td>
 <td>'.number_format($row['margin']).'</td>
  <td>'.number_format($row['perc'],2).'</td></tr>';
 $buying+=$row['buying'];
  $selling+=$row['selling'];
   $margin+=$row['margin'];
 }
  echo '<tr><td ><center>TOTAL</td><td>'.number_format($buying).'</td>
  <td>'.number_format($selling).'</td><td>'.number_format($marging).'</td></tr>';
   echo '</table>';
 mysqli_close($dbc);
 }
 function Popular($date1,$date2){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT p_name,sum(qty)as q,sum(total_p)as p FROM sales
WHERE date between '$date1' and '$date2'
GROUP BY p_name ORDER BY q DESC limit 20 "));
?><div align="center">POPULAR PRODUCTS</div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>PRODUCT</b></td> <td><b>QTY SOLD</b></td><td><b>TOTAL VALUE</b></td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['p_name'].'</td><td>'.number_format($row['q']).'</td><td>'.number_format($row['p']).'</td>
</tr>';



 }

 
echo '</table>';
  mysqli_close($dbc);
 }
 
 function ViewUsers(){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$rO=mysqli_query($dbc,("select *,user_name as user,department.name as department from users
inner join department on department.id=users.department
"));
?>
<table class="blue" border="1" style="background-color:#ffffff"; rules="NONE"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">

 <tr><td><b>
Full Name</td><td>
Department</td></tr>
<?
while ($row=mysqli_fetch_array($rO)){
 echo '<tr>
 <td>'.($row['user']).'</td><td>'.($row['department']).'</td>

</tr>';
 }
 echo '</table>';
 mysqli_close($dbc);
}
 
 function BestCatP($date1,$date2,$id){
      				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
     $vg=mysqli_query($dbc,("select name from categories where id='$id'"));
        $ve=mysqli_fetch_array($vg);
          $bn=$ve['name'];
$r=mysqli_query($dbc,("SELECT sales.p_name as p_name,sum(qty) as qty, sum(total_p)as total_p

 from sales 
 inner join products on products.p_name=sales.p_name
 where date between '$date1' and '$date2'
 and p_price>0
 and sales.category='$bn'
 
 group by p_name order by qty desc"));
 ?><div align="center"><?echo $bn;?> CATEGORY REPORT BASED ON QTY SOLD
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>PRODUCT</b></td> <td><b>QTY SOLD</b></td><td><b>TOTAL VALUE</b></td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['p_name'].'</td>
<td>'.round($row['qty']).'</td><td>'.round($row['total_p']).'</td>
</tr>';
 }
 echo '</table>';
 }
 function Bestprod($date1,$date2,$id){
      				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
     $vg=mysqli_query($dbc,("select p_name from products  where product_id='$id'"));
        $ve=mysqli_fetch_array($vg);
          $bn=$ve['p_name'];
$r=mysqli_query($dbc,("SELECT *
 from sales  where date between '$date1' and '$date2'
 and sales.p_name='$bn'"));
 ?><div align="center"><?echo $bn;?>  REPORT 
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>PRODUCT</b></td> <td><b>QTY SOLD</b></td>  <td><b>DATE</b></td><td><b>TOTAL VALUE</b></td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['p_name'].'</td>
<td>'.round($row['qty']).'</td><td>'.($row['date']).'</td><td>'.round($row['total_p']).'</td>
</tr>';
 }
 echo '</table>';
 }
 
 function StockByValuation(){
  require_once('print.php');
     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT  *,buying*left_p as value FROM products
where left_p>0
ORDER BY left_p ASC "));
 ?> 			
	
	
</form></div></center><div align="center">STOCK REPORT BY VALUATION</div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>PRODUCT</b></td> <td><b>QTY LEFT</b></td><td><b>QTY VALUE</b></td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['p_name'].'</td><td>'.number_format($row['left_p']).'</td><td>'.number_format($row['value']).'</td>
</tr>';
$value+=$row['value'];
 }
  echo '<tr><td colspan="2"><center>TOTAL</td><td>'.number_format($value).'</td></tr></table></div>';
  mysqli_close($dbc);
 }
 function Rejects($date1,$date2){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT * FROM return_in where 
 date BETWEEN '$date1' AND '$date2'
 group by id desc

"));
?>
<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td><td><b>PRODUCT</b></td> <td><b>QTY</b></td><td><b>AMOUNT</b></td><td><b>RECEIPT</b></td><td><b>CREDIT NOTE</b></td></tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.$row['date'].'</td><td>'.$row['p_name'].'</td><td>'.number_format($row['qty']).'</td><td>'.number_format($row['total_p']).'</td>
 <td>'.$row['receipt'].'</td><td>'.$row['credit'].'</td>
</tr>';
$value+=$row['value'];
 }
  //echo '<tr><td colspan="2"><center>TOTAL</td><td>'.number_format($value).'</td></tr>';

 echo '</table>';
 mysqli_close($dbc);
}
function Audit($id){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from audit where product='$id' group by audit_id order by date "));?>
<div align="center">PRODUCT AUDIT REPORTS</div>
<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>DATE</b></td><td><b>CLOSING STOCK</b></td> <td><b>QTY</b></td><td><b>VALUE</b></td><td><b>REASON</b></td><td><b>Invoice/Receipt</b></td></tr><?
while($row = mysqli_fetch_array($r))
{
  echo '<tr>';
    echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="center">'.$row['date'].'</div></td>';
	 echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="center">'.$row['stock'].'</div></td>';
    echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="center">'.$row['qty'].'</div></td>';
	  echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="center">'.$row['value'].'</div></td>';
	  	  echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="center">'.$row['reason'].'</div></td>';
		  	  echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="center">'.$row['number'].'</div></td>';

	  echo '</tr>';
 }
 mysqli_close($dbc);
}
function ViewAssets(){
        				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select *,debit-(datediff(NOW(),date)/365)*(dep/100*debit) as current from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='6'"));

?>
<table class="blue" border="1" style="background-color:#ffffff"; rules="NONE"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial";>
 <tr> <td>
  <strong><img border="0" src="logo.JPG" width="930" height="121"></td></tr></table>
  <div align="center"><h2 style="font-family:Bell Gothic,Verdana,Arial";>Fixed Assets</h2></div>

<table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
 <tr> <td><b>Name</b></td><td><b>Sub Name</b></td><td><b>Purchase Date:</b></td><td><b>Purchase Price:</b></td><td><b>Depreciation Rate:</b></td><td><b>Current Value:</b></td></tr>
 <?while ($row=mysqli_fetch_array($r)){
 echo '<tr><td>'.Legers($row['account_id']).'</td><td>'.SubName($row['sub']).'</td><td>'.$row['date'].'</td><td>'.number_format($row['debit']).'</td><td>'.$row['dep'].'</td><td>'.number_format($row['current']).'</td></tr>';
 
 }?> 
 

 </table><br>
 <?}
function ViewSuppliers(){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from accounts
inner join  group_accounts on group_accounts.account_id=accounts.id
where group_id='2'"));
  echo '
     
<table border="1" width="500" cellspacing="0" class="tables"> 
                                                        <thead>
                                                            <tr>
															<th><left>Edit Account</th> 
															<th><left>Account Name</th> 
                                                              <th><left>Phone</th> 
																<th><left>Address</th> 
                                                                    
                                                            </tr>

                                                        </thead>';

														while($row=mysqli_fetch_array($r)){

    echo'<tr><td><a href=edit.php?id=' . $row["id"] .'>Edit Account</a></td><td>' . (($row['name'])) . '</td>
	<td>' . (($row['phone'])) . '</td>
	<td>' . (($row['address'])) . '</td></tr>';
}
							echo "</table>";
							mysqli_close($dbc);
}

function PriceChanges($date1,$date2){

}
function ReorderLevels(){
}

  function ReorderLevel(){
	      				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("SELECT * from products where left_p<=reorder
"));
 ?><div align="center"><b>These Products Have Reached Their Re-Ordr Level Limits</b></div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>Product</b></td><td><b>Re-Order Limit</b></td><td><b>Current Stock</b></td>
 </tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>

  <td>'.$row['p_name'].'</td>
 <td>'.$row['reorder'].'</td><td>'.$row['left_p'].'</td> 

</tr>';
 }
 echo '</table>';
 mysqli_close($dbc);
 }
   function ReorderLevell(){
	       				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("SELECT *,(left_p-reorder)as r from products 
having r=10
"));
 ?><div align="center"><b>These Products Have Ten Products To Re-Order Level Limits</b></div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>Product</b></td><td><b>Re-Order Limit</b></td><td><b>Current Stock</b></td>
 </tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>

  <td>'.$row['p_name'].'</td>
 <td>'.$row['reorder'].'</td><td>'.$row['left_p'].'</td> 

</tr>';
 }
 echo '</table>';
 mysqli_close($dbc);
 }
 function NotMax($date1,$date2){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("SELECT * from sales where date between '$date1' and '$date2'
and price<current
"));
 ?><div align="center"><b>Products Sold Below Recommended Prices Between <?echo $date1;?> And <?echo $date2;?></b></div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>Product</b></td><td><b>Qty Sold</b></td><td><b>Selling Price</b></td><td><b>Recommended Price</b></td><td><b>Discount Total</b></td>
 </tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>

  <td>'.$row['p_name'].'</td>
 <td>'.$row['qty'].'</td><td>'.number_format($row['price']).'</td> <td>'.number_format($row['current']).'</td>
 <td>'.number_format(($row['current']-$row['price'])*$row['qty']).'</td>  

</tr>';
$totald+=(($row['current']-$row['price'])*$row['qty']);
 }
 echo '<tr>

  <td colspan="4"><center><b>TOTAL DISCOUNT</td>
 <td><b>'.number_format($totald).'</td>
 </table>';
 mysqli_close($dbc);
 }
 function BalanceS($date){
 //$r=mysql_query("select * from financial_year where status='ACTIVE' order by id desc limit 1");
 //$row
 	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 ?>     <table class="blue" border="1" style="background-color:#ffffff"; rules="NONE"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial";>
 <tr> <td>
  <strong><img border="0" src="logo.jpg" width="930" height="121"></td></tr></table> 
               <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">    
                
               
  
  <div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";>Balance Sheet Statement As Of Date  <?echo $date;?> </h4></div>

<table class="blue" border="1" style="background-color:#ffffff"
       rules="NONE" frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial"><?
   $he=mysqli_query($dbc,("select  sum(credit)-SUM(debit)as credit,ledgers.account_id as account_id  from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='3'
and date<='$date' 

group by ledgers.account_id
"));

while($row=mysqli_fetch_array($he)){

$incom+=$row['credit'];
 }
   $ce=mysqli_query($dbc,("select  sum(debit)-sum(credit)as credit,ledgers.account_id as account_id   from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='7'
and date<='$date' 

group by ledgers.account_id

"));
while($row=mysqli_fetch_array($ce)){

$cost+=$row['credit'];
 }
   $c=mysqli_query($dbc,("select  sum(debit)-sum(credit)as credit,ledgers.account_id as account_id   from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id ='1'
and date<='$date' 

group by ledgers.account_id
having credit>0
"));
while($row=mysqli_fetch_array($c)){

$expenses+=$row['credit'];
 }
    $ce=mysqli_query($dbc,("select  sum(credit)-sum(debit)as credit,ledgers.account_id as account_id   from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id ='14'

and date<='$date' 
group by ledgers.account_id

"));
while($row=mysqli_fetch_array($ce)){

 $equity+=$row['credit'];
 }
   $over=mysqli_query($dbc,("select  sum(debit)-sum(credit)as credit,ledgers.account_id as account_id   from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='2'
and date<='$date' 

group by ledgers.account_id
having credit>0

"));
while($row=mysqli_fetch_array($over)){

$pexpenses+=$row['credit'];
 }
 $retained=$equity+($incom-($cost+$expenses));

  echo '<tr><td><b>CAPITAL EMPLOYED</td> <td></td></tr>';
 $h=mysqli_query($dbc,("select  sum(credit)-sum(debit) as credit,ledgers.account_id as account_id  from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='5'
and date<='$date' 

group by ledgers.account_id
"));

while($row=mysqli_fetch_array($h)){
echo '<tr><td>'.Legers($row['account_id']).'</td> <td>'.number_format($row['credit']).'</td></tr>';
$income+=$row['credit'];
 }


 echo '<tr><td>RETAINED EARNINGS</td> <td><u><b>'.number_format($retained-$dep).'</td></tr>';


  echo '<tr><td><b>TOTAL SHAREHOLDERS FUND</td> <td><u><b>'.number_format($income+$retained-$dep).'</td></tr>';
 echo '<tr><td colspan="2"><b>LONG TERM LIABLITIES</td> </tr>';
  $c=mysqli_query($dbc,("select  sum(credit)-sum(debit)as credit,ledgers.account_id as account_id   from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='8'
and date<='$date' 
group by ledgers.account_id
"));
while($row=mysqli_fetch_array($c)){
echo '<tr><td>'.Legers($row['account_id']).'</td> <td>'.number_format($row['credit']).'</td></tr>';
$coste+=$row['credit'];
 }
 echo '<tr><td><b></td> <td><u><b>'.number_format($coste).'</td></tr>';
 echo '<tr><td><b></td> <td><b><u>'.number_format($income+$coste+$retained-$dep).'</td></tr>';
  echo '<tr><td colspan="2"><b>REPRESENTED BY</td> </tr>';
  echo '<tr><td colspan="2"><b>NON CURRENT ASSETS</td> </tr>';
  $c=mysqli_query($dbc,("select *,SUM(debit)-sum(credit) as credit from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
inner join accounts on accounts.id=ledgers.account_id
where group_id='6'
and date<='$date' 
group by ledgers.account_id
"));
while($row=mysqli_fetch_array($c)){
echo '<tr><td>'.Legers($row['account_id']).'</td> <td>'.number_format($row['credit']).'</td></tr>';
$fixedd+=$row['credit'];
 }
  echo '<tr><td><b></td> <td><u><b>'.number_format($fixedd).'</td></tr>';
    echo '<tr><td colspan="2"><b>CURRENT ASSETS</td> </tr>';
  $c=mysqli_query($dbc,("select  sum(debit)-sum(credit)as credit,ledgers.account_id as account_id   from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='4' 
and date<='$date' 

group by ledgers.account_id

"));
while($row=mysqli_fetch_array($c)){if($row['credit']!=0.00){
echo '<tr><td>'.Legers($row['account_id']).'</td> <td>'.number_format($row['credit']).'</td></tr>';}
$current+=$row['credit'];
 }
   $c=mysqli_query($dbc,("select  sum(debit)-sum(credit)as credit,ledgers.account_id as account_id   from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='10' 
and date<='$date' 

group by ledgers.account_id

"));
while($row=mysqli_fetch_array($c)){
echo '<tr><td>'.Legers($row['account_id']).'</td> <td>'.number_format($row['credit']).'</td></tr>';
$currentt+=$row['credit'];
 }
 $current=$current+$currentt;//$pexpenses;
echo '<tr><td colspan="2"><b>PRE-PAID EXPENSES</td> </tr>';
 $c=mysqli_query($dbc,("select  sum(credit)-sum(debit)as credit,ledgers.account_id as account_id   from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='1' 
and date<='$date' 

group by ledgers.account_id
having credit>0

"));
while($row=mysqli_fetch_array($c)){
if($row['credit']!=0.00){
echo '<tr><td>'.Legers($row['account_id']).'</td> <td>'.number_format($row['credit']).'</td></tr>';}
$currenttp+=$row['credit'];
 }
 echo '<tr><td colspan="2"><b>TRADE DEBTORS</td> </tr>';
 $c=mysqli_query($dbc,("select  sum(debit)-sum(credit)as credit,ledgers.account_id as account_id   from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='2' 
and ledgers.account_id<>'11'
and date<='$date' 

group by ledgers.account_id
having credit>0

"));
while($row=mysqli_fetch_array($c)){
if($row['credit']!=0.00){
echo '<tr><td>'.Legers($row['account_id']).'</td> <td>'.number_format($row['credit']).'</td></tr>';}
$currenttpp+=$row['credit'];
 }

 $current=$current+$currenttp+$currenttpp;
  echo '<tr><td><b></td> <td><u><b>'.number_format($current).'</td></tr>';
  echo '<tr><td colspan="2"><b>CURRENT LIABILITIES</td> </tr>';
  $c=mysqli_query($dbc,("select  sum(credit)-sum(debit)as credit,ledgers.account_id as account_id   from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='2'
and date<='$date' 
group by ledgers.account_id


"));
while($row=mysqli_fetch_array($c)){
if($row['credit']<0){
$cu=$row['credit']*-1;
}
else{
$cu=$row['credit'];
}if($cu!=0.00){
echo '<tr><td>'.Legers($row['account_id']).'</td> <td>'.number_format($cu).'</td></tr>';}
if($row['credit']<0){
$ty=$row['credit']*-1;
$currentl+=$ty;
}else{
$currentl+=$row['credit'];
}
 }
    echo '<tr><td colspan="2"><b>STATUTORY DEDUCTIONS</td> </tr>';
  $c=mysqli_query($dbc,("select  sum(credit)-sum(debit)as credit,ledgers.account_id as account_id   from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='12'
and date<='$date' 
group by ledgers.account_id


"));
while($row=mysqli_fetch_array($c)){
echo '<tr><td>'.Legers($row['account_id']).'</td> <td>'.number_format($row['credit']).'</td></tr>';
$currentll1+=$row['credit'];
 }
   echo '<tr><td colspan="2"><b>UNPAID SALARIES</td> </tr>';
  $c=mysqli_query($dbc,("select  sum(credit)-sum(debit)as credit,ledgers.account_id as account_id   from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
where group_id='11'
and date<='$date' 
group by ledgers.account_id


"));
while($row=mysqli_fetch_array($c)){
echo '<tr><td>'.Legers($row['account_id']).'</td> <td>'.number_format($row['credit']).'</td></tr>';
$currentll+=$row['credit'];
 }
$currentl0=$currentl+$currentll+$currentll1;
  echo '<tr><td><b></td> <td><u><b>'.number_format($currentl).'</td></tr>';
  echo '<tr><td><b> NET CURRENT ASSETS</td> <td><u><b>'.number_format($current-$currentl0).'</td></tr>';
  echo '<tr><td></td> <td><u><b><u>'.number_format($fixedd+($current-$currentl0)+$currenttpp).'</td></tr></table><br>';
  mysqli_close($dbc);
 }
  
  function Physical($date1,$date2,$session){
  if($date1!=''&&$date2!=''){
	      				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("SELECT *,stock_balances.system-manual as diff,stock_balances.system as system from stock_balances 
inner join products on products.product_id=stock_balances.product_id
where date between '$date1' and '$date2'
group by id
 order by diff
"));
}

  if($session!=''){
$r=mysqli_query($dbc,("SELECT *,stock_balances.system-manual as diff,stock_balances.system as system from stock_balances 
inner join products on products.product_id=stock_balances.product_id  where session='$session'
group by id
 order by diff

"));
}
 ?><div align="center"><b>Products Physical & System Stock Analysis</b></div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>Product</b></td><td><b>System Qty </b></td><td><b>Manual Qty</b></td><td><b>Variation</b></td>
 </tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>

  <td>'.$row['p_name'].'</td>
 <td>'.number_format($row['system']).'</td><td>'.number_format($row['manual']).'</td> <td>'.number_format($row['diff']).'</td>
 

</tr>';
$totald+=($row['diff']);
$manual+=($row['manual']);
$system+=($row['system']);
 }
 echo '<tr>

  <td colspan="0"><center><b>TOTAL VARIATIONS</td>
   <td><b>'.number_format($system).'</td>
    <td><b>'.number_format($manual).'</td>
 <td><b>'.number_format($totald).'</td>
 </table>';
 mysqli_close($dbc);
 }
 
 
 function PhysicalD($date1,$date2){
  if($date1!=''&&$date2!=''){
$r=mysqli_query("SELECT *,sum(stock_balances.system)-sum(manual) as diff,sum(stock_balances.system) as system,sum(manual)as manual from stock_balances 
inner join products on products.product_id=stock_balances.product_id
where date between '$date1' and '$date2'
group by products.product_id
 order by diff
 limit 0,20
");
}

;

 ?><div align="center"><b>Top Twenty Products With Most Stock Discrepancies</b></div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>Product</b></td><td><b>System Qty </b></td><td><b>Manual Qty</b></td><td><b>Variation</b></td>
 </tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>

  <td>'.$row['p_name'].'</td>
 <td>'.number_format($row['system']).'</td><td>'.number_format($row['manual']).'</td> <td>'.number_format($row['diff']).'</td>
 

</tr>';
$totald+=($row['diff']);
$manual+=($row['manual']);
$system+=($row['system']);
 }
 echo '<tr>

  <td colspan="0"><center><b>TOTAL VARIATIONS</td>
   <td><b>'.number_format($system).'</td>
    <td><b>'.number_format($manual).'</td>
 <td><b>'.number_format($totald).'</td>
 </table>';
 
 }
   function SaleInvoice($date1,$date2){
  if($date1!=''&&$date2!=''){
	      				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("SELECT * from sales

 where date between '$date1' and '$date2'

 and type='INVOICE'
 
group by sale_id order by number
"));
}

;

 ?><div align="center"><b>Detailed  Product  Credit Sales Between <?echo $date1;?> And <?echo $date2?></b></div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>Product</b></td><td><b>Qty </b></td><td><b>Price</b></td><td><b>Total</b></td><td><b>Delivery No</b></td><td><b>Time</b></td><td><b>User</b></td><td><b>Customer</b></td>
 </tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>

  <td>'.$row['p_name'].'</td>
 <td>'.($row['qty']).'</td><td>'.number_format($row['price']).'</td><td>'.number_format($row['total_p']).'</td> <td>'.($row['number']).'</td>
  <td>'.($row['time']).'</td>
   <td>'.($row['user']).'</td>
   <td>'.Mode($row['account_id']).'</td>
 

</tr>';
$totald+=($row['total_p']);
$totalq+=($row['qty']);

 }
 echo '<tr>

  <td colspan="0"><center><b>TOTAL </td>
   <td><b>'.number_format($totalq).'</td>
    <td><b></td>
 <td><b>'.number_format($totald).'</td>
 </table>';
 mysqli_close($dbc);
 }
  function SalesD($date1,$date2){
	      				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
  if($date1!=''&&$date2!=''){
$r=mysqli_query($dbc,("SELECT * from sales where date between '$date1' and '$date2'
 and type='RECEIPT'
group by sale_id order by number
"));
$th=mysqli_query($dbc,("SELECT sum(prof)as fin from sales where date between '$date1' and '$date2'
 and type='RECEIPT'"));
 $jk=mysqli_fetch_array($th);
 $fin=$jk['fin'];

}

;

 ?><div align="center"><b>Detailed Product Sales Between <?echo $date1;?> And <?echo $date2?></b></div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>Product</b></td><td><b>Qty </b></td><td><b>Price</b></td><td><b>Total</b></td><td><b>Profit</b></td><td><b>Receipt</b></td><td><b>Time</b></td><td><b>User</b></td>
 </tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>

  <td>'.$row['p_name'].'</td>
 <td>'.($row['qty']).'</td><td>'.number_format($row['price']).'</td><td>'.number_format($row['total_p']).'</td><td>'.$row['prof'].'</td> <td>'.($row['number']).'</td>
  <td>'.($row['time']).'</td>
   <td>'.($row['user']).'</td>
 

</tr>';
$totald+=($row['total_p']);
$totalq+=($row['qty']);

 }
 echo '<tr>

  <td colspan="0"><center><b>TOTAL </td>
   <td><b>'.number_format($totalq).'</td>
    <td><b></td>
 <td><b>'.number_format($totald).'</td><td><b>'.number_format($fin).'</td>
 </table>';
 mysqli_close($dbc);
 }
 function Salesloc($date1,$date2,$address){
	      				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
  if($date1!=''&&$date2!=''){
$r=mysqli_query($dbc,("SELECT * from sales where date between '$date1' and '$date2'
 and address='$address'
group by sale_id order by number
"));
$th=mysqli_query($dbc,("SELECT sum(prof)as fin from sales where date between '$date1' and '$date2'
 and type='RECEIPT'"));
 $jk=mysqli_fetch_array($th);
 $fin=$jk['fin'];

}

;

 ?><div align="center"><b>Product Sales Between <?echo $date1;?> And <?echo $date2?> in <?echo $address;?></b></div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>Product</b></td><td><b>Qty </b></td><td><b>Price</b></td><td><b>Total</b></td><td><b>Profit</b></td><td><b>Receipt</b></td><td><b>Time</b></td><td><b>User</b></td>
 </tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>

  <td>'.$row['p_name'].'</td>
 <td>'.($row['qty']).'</td><td>'.number_format($row['price']).'</td><td>'.number_format($row['total_p']).'</td><td>'.$row['prof'].'</td> <td>'.($row['number']).'</td>
  <td>'.($row['time']).'</td>
   <td>'.($row['user']).'</td>
 

</tr>';
$totald+=($row['total_p']);
$totalq+=($row['qty']);

 }
 echo '<tr>

  <td colspan="0"><center><b>TOTAL </td>
   <td><b>'.number_format($totalq).'</td>
    <td><b></td>
 <td><b>'.number_format($totald).'</td><td><b>'.number_format($fin).'</td>
 </table>';
 mysqli_close($dbc);
 }
  function Salesz($date1,$date2,$to,$fro){
	      				
  if($date1!=''&&$date2!=''){
         if($fro=='store'){
        $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
        $gt='HOME STORE'; 
    }
      

$r=mysqli_query($dbc,("SELECT * ,sum(qty)as qty,sum(tot)as total from trans where 
date between '$date1' and '$date2' and tot='$to'

group by p_name order by qty desc
"));

}

;

 ?><div align="center"><b>Delivery Report From <? echo $gt;?> &nbsp; To &nbsp;<? echo strtoupper($to); ?> &nbsp;  Between <?echo $date1;?> And <?echo $date2?></b></div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>Product</b></td><td><b>Qty </b></td><td><b>Date</b></td><td><b>Dest</b></td><td><b>Delivery Number</b></td><td><b>User</b></td>
 </tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>

  <td>'.$row['p_name'].'</td>
 <td>'.($row['qty']).'</td><td>'.($row['date']).'</td><td>'.($row['tot']).'</td><td>'.($row['cod']).'</td>
  
   <td>'.($row['user']).'</td>
 

</tr>';
$totald+=($row['total_p']);
$totalq+=($row['qty']);
$tot+=($row['total']);
 }
 echo '<tr>

  <td colspan="0"><center><b>TOTAL </td>
   <td><b>'.number_format($totalq).'</td>
    
 </table>';
 mysqli_close($dbc);
 }
 function cumulative($date1,$date2){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
  if($date1!=''&&$date2!=''){
$r=mysqli_query($dbc,("SELECT * ,sum(qty)as qty,sum(total_p)as total from sales where 
date between '$date1' and '$date2'

group by p_name order by qty desc
"));
}

;

 ?><div align="center"><b>Detailed Product Sales Between <?echo $date1;?> And <?echo $date2?></b></div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>Product</b></td><td><b>Qty </b></td><td><b>Total</b></td>
 </tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>

  <td>'.$row['p_name'].'</td>
 <td>'.($row['qty']).'</td><td>'.number_format($row['total']).'</td>

</tr>';
$totald+=($row['total']);
$totalq+=($row['qty']);

 }

 echo '<tr>

  <td colspan="0"><center><b>TOTAL </td>
   <td><b>'.number_format($totalq).'</td>
    
 <td><b>'.number_format($totald).'</td>
 </table>';
 mysqli_close($dbc);
 }
 function MoreB(){
     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("SELECT p_name,session, number,qty,type,price,p_price,date, (
qty * price
) - ( p_price * qty ) AS mar
FROM sales
HAVING mar <0
ORDER BY `sales`.`date` DESC
"));


;

 ?><div align="center"><b>Sold Products With Huge Buying Prices Than Selling Prices</b></div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="900" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>Date</b></td><td><b>Product</b></td><td><b>Buying </b></td><td><b>Selling</b></td><td><b>Qty </b></td><td><b>Receipt</b></td><td><b>Type</b></td><td><b>Customer</b></td>
 </tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>
  <td>'.$row['date'].'</td>
  <td>'.$row['p_name'].'</td>

  <td>'.number_format($row['p_price']).'</td>
   <td>'.number_format($row['price']).'</td>
    <td>'.($row['qty']).'</td><td>'.number_format($row['number']).'</td>
   <td>'.$row['type'].'</td>
    <td>'.GetCustomer($row['session']).'</td>

</tr>';


 }

 echo '
 </table>';
 mysqli_close($dbc);
 }
 function SalesR($date1,$date2){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
  if($date1!=''&&$date2!=''){
$r=mysqli_query($dbc,("SELECT number,sum(qty)as qty,sum(total_p)as total_p,time,user,session,type 
from sales where date between '$date1' and '$date2'

group by number,type order by number
"));
}

;

 ?><div align="center"><b>Detailed Product Sales Between <?echo $date1;?> And <?echo $date2?></b></div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
<tr><td><b>Preview</b></td><td><b>Type</b></td><td><b>Receipt/ Invoice</b></td><td><b>Total Qty </b></td><td><b>Amount</b></td><td><b>Time</b></td><td><b>User</b></td>
 </tr><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr> <td style="border-color:#000000; border-style:solid; border-width:1px;">
  <div align="left"><a rel="facebox" href="prev.
php?id=' . $row['session'] . '">Preview Transaction</a></div>
<td>'.$row['type'].'</td>
  <td>'.$row['number'].'</td> 
<td>'.number_format($row['qty']).'</td><td>'.number_format($row['total_p']).'</td> 
  <td>'.($row['time']).'</td>
   <td>'.($row['user']).'</td>
 

</tr>';
$totald+=($row['total_p']);
$totalq+=($row['qty']);

 }
 echo '<tr>

  <td colspan="2"><center><b>TOTAL </td>
   <td><b>'.number_format($totalq).'</td>
 
 <td><b>'.number_format($totald).'</td>
 </table>';
 mysqli_close($dbc);
 }
 function supplierAllInvoices(){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("select * from accounts
 inner join group_accounts on group_accounts.account_id=accounts.id
 where group_id='2'"));
 
 
 
 ?>
 
 

<body>
		<link rel="stylesheet" href="auto.css" />
	<div id="tablewrapper">
		<div id="tableheader">
        	<div class="search">
                <select id="columns" onchange="sorter.search('query')"></select>
                <input type="text" id="query" onkeyup="sorter.search('query')" />
            </div>
            <span class="details">
				<div>Records <span id="startrecord"></span>-<span id="endrecord"></span> of <span id="totalrecords"></span></div>
        		<div><a href="javascript:sorter.reset()">reset</a></div>
        	</span>
        </div><div align="center"><h2>Supplier Invoices</div>
		  <form method="post" action="generate_sheet.php">
        <table cellpadding="0" cellspacing="0" border="0" id="table" class="tinytable">
            <thead>
               <tr>
                    
          
			  <th><h3>Get Invoices</th>
			  <th><h3>Supplier</th>
			  	
			 
                   
                
                </tr>
            </thead>
            <tbody><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>';
  echo '<td style="border-color:#000000; border-style:solid; border-width:1px;">
  <div align="left"><a  href="supplier.
php?id=' . $row['account_id'] . '">VIEW INVOICES</a></div></td>';

    echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['name'].'</div></td>';

   

	
	  echo '</tr>';
 }?>
  </tbody>
   </table>
        <div id="tablefooter">
          <div id="tablenav">
            	<div>
                    <img src="images/first.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1,true)" />
                    <img src="images/previous.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1)" />
                    <img src="images/next.gif" width="16" height="16" alt="First Page" onclick="sorter.move(1)" />
                    <img src="images/last.gif" width="16" height="16" alt="Last Page" onclick="sorter.move(1,true)" />
                </div>
                <div>
                	<select id="pagedropdown"></select>
				</div>
                <div>
                	<a href="javascript:sorter.showall()">view all</a>
                </div>
            </div>
			<div id="tablelocation">
            	<div>
                    <select onchange="sorter.size(this.value)">
                    <option value="50" selected="selected">50</option>
					<option value="5" >5</option>
                        <option value="10" >10</option>
                        <option value="20">20</option>
                        <option value="50">50</option>
                        <option value="100">100</option>
						<option value="100">500</option>
						<option value="100">1000</option>
                    </select>
                    <span>Entries Per Page</span>
                </div>
                <div class="page">Page <span id="currentpage"></span> of <span id="totalpages"></span></div>
            </div>
        </div>
    </div>


	<script type="text/javascript" src="script.js"></script>
	<script type="text/javascript">
	var sorter = new TINY.table.sorter('sorter','table',{
		headclass:'head',
		ascclass:'asc',
		descclass:'desc',
		evenclass:'evenrow',
		oddclass:'oddrow',
		evenselclass:'evenselected',
		oddselclass:'oddselected',
		paginate:true,
		size:100,
		colddid:'columns',
		currentid:'currentpage',
		totalid:'totalpages',
		startingrecid:'startrecord',
		endingrecid:'endrecord',
		totalrecid:'totalrecords',
		hoverid:'selectedrow',
		pageddid:'pagedropdown',
		navid:'tablenav',
		sortcolumn:1,
		sortdir:1,
		sum:[8],
		avg:[6,7,8,9],
		columns:[{index:7, format:'%', decimals:1},{index:8, format:'$', decimals:0}],
		init:true
	})
  </script>
</body>
 
 <?

 
 
 
 mysqli_close($dbc);
 }
 function TrialBalance($date){
     	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$assets=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit,ledgers.account_id as id from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='4' 
and date<='$date' group by id
 having debit>0
"));
$bassets=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit,ledgers.account_id as id from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='4' 
and date<='$date'  group by id
 having debit<0
"));
$equity=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit,ledgers.account_id as id from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='14' 
and date<='$date'  group by id
 having debit>0
"));
$equityy=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit,ledgers.account_id as id from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='14' 
and date<='$date'  group by id
 having debit<0
"));


 $asssets=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit,ledgers.account_id as id from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='10' 
and date<='$date'  group by id
 having debit>0"));
  $basssets=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit,ledgers.account_id as id from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='10'
and date<='$date'  group by id
 having debit<0"));
 $expenses=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit,ledgers.account_id as id  from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='1' 
and date<='$date'  group by id having debit>0"));
  $expensespo=mysqli_query($dbc,("select sum(credit)-sum(debit)as debit,ledgers.account_id as id  from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='1' 
and date<='$date'  group by id having debit>0"));
 $fixed=mysqli_query($dbc,("select *,sum(debit)-sum(credit) as debit,accounts.id as id from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
inner join accounts on accounts.id=ledgers.account_id
where group_id='6'
and date<='$date' 
GROUP BY ledgers.account_id"));

  $cost=mysqli_query($dbc,("select sum(debit)-sum(credit)as debit,ledgers.account_id as id  from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='7'
and date<='$date'  group by id"));
   $income=mysqli_query($dbc,("select sum(credit)-sum(debit)as debit,ledgers.account_id as id  from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='3'
and date<='$date'  group by id"));
    $liab=mysqli_query($dbc,("select sum(credit)-sum(debit)as debit,ledgers.account_id as id  from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='2' 
and date<='$date'  group by id
 having debit>0
 "));
   $bliab=mysqli_query($dbc,("select sum(credit)-sum(debit)as debit,ledgers.account_id as id  from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='2'
and date<='$date'  group by id
 having debit<0
 "));
   $liabb=mysqli_query($dbc,("select sum(credit)-sum(debit)as debit,ledgers.account_id as id  from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where  group_id='11'
and date<='$date'  group by id
 having debit>0"));
  $bliabb=mysqli_query($dbc,("select sum(credit)-sum(debit)as debit,ledgers.account_id as id  from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where  group_id='11'
and date<='$date'  group by id
 having debit<0"));
   $liabbb=mysqli_query($dbc,("select sum(credit)-sum(debit)as debit,ledgers.account_id as id  from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='12' 
and date<='$date'  group by id
 having debit>0"));
    $bliabbb=mysqli_query($dbc,("select sum(credit)-sum(debit)as debit,ledgers.account_id as id  from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='12'
and date<='$date'  group by id
 having debit<0"));
 
    $capital=mysqli_query($dbc,("select sum(credit)-sum(debit)as debit,ledgers.account_id as id  from ledgers
inner join group_accounts on group_accounts.account_id=ledgers.account_id
 where group_id='5'
and date<='$date'  group by id"));

?>
     <table class="blue" border="1" style="background-color:#ffffff"; rules="NONE"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial";>
 <tr> <td>
  <strong><img border="0" src="logo.jpg" width="930" height="121"></td></tr></table>       
                
               <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">    
                
               
  <div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";>Trial Balance As Of Date  <?echo $date;?> </h2></div>

<table class="blue" border="1" style="background-color:#ffffff" rules="NONE"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
 <tr><td><b>ACCOUNT</b></td> <td><b>DEBIT</b></td><td><b>CREDIT</b></td></tr>
 <?
  echo '<tr><td colspan="2"><left><b><u>OWNERS EQUITY</td></tr>';
 while ($row=mysqli_fetch_array($equity)){
 if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td>'.(number_format($row['debit'])).'</td><td></td></tr>';}
 $tequity+=$row['debit'];

 }
  while ($row=mysqli_fetch_array($equityy)){
 if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td></td><td>'.(number_format($row['debit']*-1)).'</td></tr>';}
 $btequity+=$row['debit']*-1;

 }
 echo '<tr><td colspan="2"><left><b><u>CURRENT ASSETS</td></tr>';
 while ($row=mysqli_fetch_array($assets)){
 if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td>'.(number_format($row['debit'])).'</td><td></td></tr>';}
 $tassets+=$row['debit'];

 }
  while ($row=mysqli_fetch_array($bassets)){
 if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td></td><td>'.(number_format($row['debit']*-1)).'</td></tr>';}
 $btassets+=$row['debit'];

 }
 while ($row=mysqli_fetch_array($asssets)){if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td>'.(number_format($row['debit'])).'</td><td></td></tr>';}
 $ttassets+=$row['debit'];

 }
  while ($row=mysqli_fetch_array($basssets)){if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td></td><td>'.(number_format($row['debit']*-1)).'</td></tr>';}
 $bttassets+=$row['debit'];

 }
  echo '<tr><td colspan="2"><left><b><u>FIXED ASSETS</td></tr>';
 while ($row=mysqli_fetch_array($fixed)){if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td>'.(number_format($row['debit'])).'</td><td></td></tr>';}
 $tfixed+=$row['debit'];

 }
  echo '<tr><td colspan="2"><left><b><u>EXPENSES</td></tr>';
  while ($row=mysqli_fetch_array($expenses)){if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td>'.(number_format($row['debit'])).'</td><td></td></tr>';}
 $texpenses+=$row['debit'];

 }
   while ($row=mysqli_fetch_array($expensespo)){if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td></td><td>'.(number_format($row['debit'])).'</td><td></td></tr>';}
 $texpenseso+=$row['debit'];

 }
  
  while ($row=mysqli_fetch_array($cost)){if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td>'.(number_format($row['debit'])).'</td><td></td></tr>';}
 $tcost+=$row['debit'];

 }
  echo '<tr><td colspan="2"><left><b><u>INCOME</td></tr>';
 while ($row=mysqli_fetch_array($income)){if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td></td><td>'.(number_format($row['debit'])).'</td></tr>';}
 $tincome+=$row['debit'];

 }
  echo '<tr><td colspan="2"><left><b><u>LIABILITY</td></tr>';
 while ($row=mysqli_fetch_array($liab)){if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td></td><td>'.(number_format($row['debit'])).'</td></tr>';}
 $tliab+=$row['debit'];

 }
  while ($row=mysqli_fetch_array($bliab)){if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td>'.(number_format($row['debit']*-1)).'</td><td></td></tr>';}
 $btliab+=$row['debit'];

 }
  while ($row=mysqli_fetch_array($liabb)){if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td></td><td>'.(number_format($row['debit'])).'</td></tr>';}
 $tliabb+=$row['debit'];

 }
  while ($row=mysqli_fetch_array($bliabb)){if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td>'.(number_format($row['debit']*-1)).'</td><td></td></tr>';}
 $btliabb+=$row['debit'];

 }
  while ($row=mysqli_fetch_array($liabbb)){if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td></td><td>'.(number_format($row['debit'])).'</td></tr>';}
 $tliabbb+=$row['debit'];

 }
 
   while ($row=mysqli_fetch_array($bliabbb)){if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td>'.(number_format($row['debit']*-1)).'</td><td></td></tr>';}
 $btliabbb+=$row['debit'];

 }
  echo '<tr><td colspan="2"><left><b><u>CAPITAL</td></tr>';
 while ($row=mysqli_fetch_array($capital)){if($row['debit']!=0.00){
 echo '<tr><td>'.Legers($row['id']).'</td><td></td><td>'.(number_format($row['debit'])).'</td></tr>';}
 $tcapital+=$row['debit'];

 }
 $btliabbb=$btliabbb*-1;
 $btliabb=$btliabb*-1;
 $btliab=$btliab*-1;
  $totaldebit=$texpenses+ $tfixed+$tcost+ $ttassets+ $tassets+$dep+$btliabbb+$btliabb+$btliab+$tequity;
  $bttassets=$bttassets*-1;
  $btassets=$btassets*-1;
  $totalcredit=$tcapital+$tliab+$tincome+$tliabb+$tliabbb+$bttassets+$btassets+$btequity+$texpenseso;
  echo '<tr><td><b><center><u>TOTAL</td><td><b><u><center>'.number_format($totaldebit).'</td><td><b><u><center>'.number_format($totalcredit).'</td></tr></table>';
  mysqli_close($dbc);
}
 function DebtorAllInvoices(){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("select * from accounts
 inner join group_accounts on group_accounts.account_id=accounts.id
 where group_id='4'"));
 
 
 
 ?>
 
 

<body>
		<link rel="stylesheet" href="auto.css" />
	<div id="tablewrapper">
		<div id="tableheader">
        	<div class="search">
                <select id="columns" onchange="sorter.search('query')"></select>
                <input type="text" id="query" onkeyup="sorter.search('query')" />
            </div>
            <span class="details">
				<div>Records <span id="startrecord"></span>-<span id="endrecord"></span> of <span id="totalrecords"></span></div>
        		<div><a href="javascript:sorter.reset()">reset</a></div>
        	</span>
        </div><div align="center"><h2>Debtor Invoices</div>
		  <form method="post" action="generate_sheet.php">
        <table cellpadding="0" cellspacing="0" border="0" id="table" class="tinytable">
            <thead>
               <tr>
                    
          
			  <th><h3>Get Invoices</th>
			  <th><h3>Customer</th>
			  	
			 
                   
                
                </tr>
            </thead>
            <tbody><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>';
  echo '<td style="border-color:#000000; border-style:solid; border-width:1px;">
  <div align="left"><a  href="debtor.
php?id=' . $row['account_id'] . '">VIEW INVOICES</a></div></td>';

    echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['name'].'</div></td>';

   

	
	  echo '</tr>';
 }?>
  </tbody>
   </table>
        <div id="tablefooter">
          <div id="tablenav">
            	<div>
                    <img src="images/first.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1,true)" />
                    <img src="images/previous.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1)" />
                    <img src="images/next.gif" width="16" height="16" alt="First Page" onclick="sorter.move(1)" />
                    <img src="images/last.gif" width="16" height="16" alt="Last Page" onclick="sorter.move(1,true)" />
                </div>
                <div>
                	<select id="pagedropdown"></select>
				</div>
                <div>
                	<a href="javascript:sorter.showall()">view all</a>
                </div>
            </div>
			<div id="tablelocation">
            	<div>
                    <select onchange="sorter.size(this.value)">
                    <option value="50" selected="selected">50</option>
					<option value="5" >5</option>
                        <option value="10" >10</option>
                        <option value="20">20</option>
                        <option value="50">50</option>
                        <option value="100">100</option>
						<option value="100">500</option>
						<option value="100">1000</option>
                    </select>
                    <span>Entries Per Page</span>
                </div>
                <div class="page">Page <span id="currentpage"></span> of <span id="totalpages"></span></div>
            </div>
        </div>
    </div>


	<script type="text/javascript" src="script.js"></script>
	<script type="text/javascript">
	var sorter = new TINY.table.sorter('sorter','table',{
		headclass:'head',
		ascclass:'asc',
		descclass:'desc',
		evenclass:'evenrow',
		oddclass:'oddrow',
		evenselclass:'evenselected',
		oddselclass:'oddselected',
		paginate:true,
		size:100,
		colddid:'columns',
		currentid:'currentpage',
		totalid:'totalpages',
		startingrecid:'startrecord',
		endingrecid:'endrecord',
		totalrecid:'totalrecords',
		hoverid:'selectedrow',
		pageddid:'pagedropdown',
		navid:'tablenav',
		sortcolumn:1,
		sortdir:1,
		sum:[8],
		avg:[6,7,8,9],
		columns:[{index:7, format:'%', decimals:1},{index:8, format:'$', decimals:0}],
		init:true
	})
  </script>
</body>
 
 <?
 mysqli_close($dbc);
 }
  function supplierAllInvoicesI($id){
	      				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("select *from stocking where supplier='$id'
GROUP BY t_code

"));
 
 
 
 ?>
 
 

<body>
		<link rel="stylesheet" href="auto.css" />
	<div id="tablewrapper">
		<div id="tableheader">
        	<div class="search">
                <select id="columns" onchange="sorter.search('query')"></select>
                <input type="text" id="query" onkeyup="sorter.search('query')" />
            </div>
            <span class="details">
				<div>Records <span id="startrecord"></span>-<span id="endrecord"></span> of <span id="totalrecords"></span></div>
        		<div><a href="javascript:sorter.reset()">reset</a></div>
        	</span>
        </div><div align="center"><h2>Supplier Invoices Issued By <?echo Mode($id);?></div>
		  <form method="post" action="generate_sheet.php">
        <table cellpadding="0" cellspacing="0" border="0" id="table" class="tinytable">
            <thead>
               <tr>
                    
          
			  <th><h3>Get Details</th>
			   <th><h3>Invoice Date</th>
			  	
			  <th><h3>Invoice No</th>
			  
			  	
			  	
			 
                   
                
                </tr>
            </thead>
            <tbody><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>';
  echo '<td style="border-color:#000000; border-style:solid; border-width:1px;">
  <div align="left"><a  rel="facebox" href="preview.
php?id=' . $row['supplier'] . ' & idd=' . $row['t_code'] . '">VIEW DETAILS</a></div></td>';

    echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['p_date'].'</div></td>';
 echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['t_code'].'</div></td>';
  //echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.number_format($row['creditt']).'</div></td>';
   

	
	  echo '</tr>';
 }?>
  </tbody>
   </table>
        <div id="tablefooter">
          <div id="tablenav">
            	<div>
                    <img src="images/first.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1,true)" />
                    <img src="images/previous.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1)" />
                    <img src="images/next.gif" width="16" height="16" alt="First Page" onclick="sorter.move(1)" />
                    <img src="images/last.gif" width="16" height="16" alt="Last Page" onclick="sorter.move(1,true)" />
                </div>
                <div>
                	<select id="pagedropdown"></select>
				</div>
                <div>
                	<a href="javascript:sorter.showall()">view all</a>
                </div>
            </div>
			<div id="tablelocation">
            	<div>
                    <select onchange="sorter.size(this.value)">
                    <option value="50" selected="selected">50</option>
					<option value="5" >5</option>
                        <option value="10" >10</option>
                        <option value="20">20</option>
                        <option value="50">50</option>
                        <option value="100">100</option>
						<option value="100">500</option>
						<option value="100">1000</option>
                    </select>
                    <span>Entries Per Page</span>
                </div>
                <div class="page">Page <span id="currentpage"></span> of <span id="totalpages"></span></div>
            </div>
        </div>
    </div>


	<script type="text/javascript" src="script.js"></script>
	<script type="text/javascript">
	var sorter = new TINY.table.sorter('sorter','table',{
		headclass:'head',
		ascclass:'asc',
		descclass:'desc',
		evenclass:'evenrow',
		oddclass:'oddrow',
		evenselclass:'evenselected',
		oddselclass:'oddselected',
		paginate:true,
		size:100,
		colddid:'columns',
		currentid:'currentpage',
		totalid:'totalpages',
		startingrecid:'startrecord',
		endingrecid:'endrecord',
		totalrecid:'totalrecords',
		hoverid:'selectedrow',
		pageddid:'pagedropdown',
		navid:'tablenav',
		sortcolumn:1,
		sortdir:1,
		sum:[8],
		avg:[6,7,8,9],
		columns:[{index:7, format:'%', decimals:1},{index:8, format:'$', decimals:0}],
		init:true
	})
  </script>
</body>
 
 <?

 
 
 mysqli_close($dbc);
 
 }
 function DebtorAllInvoicesI($id){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("select *, SUM(debit)AS creditt from ledgers

 where account_id='$id'
 
 GROUP BY INVOICE
 having creditt>0
"));
 
 
 
 ?>
 
 

<body>
		<link rel="stylesheet" href="auto.css" />
	<div id="tablewrapper">
		<div id="tableheader">
        	<div class="search">
                <select id="columns" onchange="sorter.search('query')"></select>
                <input type="text" id="query" onkeyup="sorter.search('query')" />
            </div>
            <span class="details">
				<div>Records <span id="startrecord"></span>-<span id="endrecord"></span> of <span id="totalrecords"></span></div>
        		<div><a href="javascript:sorter.reset()">reset</a></div>
        	</span>
        </div><div align="center"><h2>Debtor Invoices Issued To <?echo Mode($id);?></div>
		  <form method="post" action="generate_sheet.php">
        <table cellpadding="0" cellspacing="0" border="0" id="table" class="tinytable">
            <thead>
               <tr>
                    
          
			  <th><h3>Get Details</th>
			   <th><h3>Invoice Date</th>
			  	
			  <th><h3>Invoice No</th>
			   <th><h3>Invoice Amount</th>
			  	
			  	
			 
                   
                
                </tr>
            </thead>
            <tbody><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>';
  echo '<td style="border-color:#000000; border-style:solid; border-width:1px;">
  <div align="left"><a  rel="facebox" href="preview_c.
php?id=' . $row['account_id'] . ' & idd=' . $row['invoice'] . '">VIEW DETAILS</a></div></td>';

    echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['date'].'</div></td>';
 echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['invoice'].'</div></td>';
  echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.number_format($row['creditt']).'</div></td>';
   

	
	  echo '</tr>';
 }?>
  </tbody>
   </table>
        <div id="tablefooter">
          <div id="tablenav">
            	<div>
                    <img src="images/first.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1,true)" />
                    <img src="images/previous.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1)" />
                    <img src="images/next.gif" width="16" height="16" alt="First Page" onclick="sorter.move(1)" />
                    <img src="images/last.gif" width="16" height="16" alt="Last Page" onclick="sorter.move(1,true)" />
                </div>
                <div>
                	<select id="pagedropdown"></select>
				</div>
                <div>
                	<a href="javascript:sorter.showall()">view all</a>
                </div>
            </div>
			<div id="tablelocation">
            	<div>
                    <select onchange="sorter.size(this.value)">
                    <option value="50" selected="selected">50</option>
					<option value="5" >5</option>
                        <option value="10" >10</option>
                        <option value="20">20</option>
                        <option value="50">50</option>
                        <option value="100">100</option>
						<option value="100">500</option>
						<option value="100">1000</option>
                    </select>
                    <span>Entries Per Page</span>
                </div>
                <div class="page">Page <span id="currentpage"></span> of <span id="totalpages"></span></div>
            </div>
        </div>
    </div>


	<script type="text/javascript" src="script.js"></script>
	<script type="text/javascript">
	var sorter = new TINY.table.sorter('sorter','table',{
		headclass:'head',
		ascclass:'asc',
		descclass:'desc',
		evenclass:'evenrow',
		oddclass:'oddrow',
		evenselclass:'evenselected',
		oddselclass:'oddselected',
		paginate:true,
		size:100,
		colddid:'columns',
		currentid:'currentpage',
		totalid:'totalpages',
		startingrecid:'startrecord',
		endingrecid:'endrecord',
		totalrecid:'totalrecords',
		hoverid:'selectedrow',
		pageddid:'pagedropdown',
		navid:'tablenav',
		sortcolumn:1,
		sortdir:1,
		sum:[8],
		avg:[6,7,8,9],
		columns:[{index:7, format:'%', decimals:1},{index:8, format:'$', decimals:0}],
		init:true
	})
  </script>
</body>
 
 <?

 
 
 
 
 

 mysqli_close($dbc);
 
 
 
 }
 function CancelTransactions($date,$amount){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from ledgers
inner join accounts on accounts.id=ledgers.account_id where date='$date' and debit='$amount' group by ledgers.id order by name"));
?><div align="center" style="font-family:Bell Gothic,Verdana,Arial"><h3><u>Delete Or Amend Transactions</div><table class="blue" border="1" style="background-color:#ffffff"; rules="NONE"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="1" style="font-family:Bell Gothic,Verdana,Arial";>
  <tr><td><b>Delete Transactions</b></td><td><b>DATE</b></td><td><b>ACCOUNT DEBITED</b></td> <td><b>ACCOUNT CREDITED</b></td><td><b>DESCRIPTION</b></td><td><b>AMOUNT</b></td></tr>
 <?
while ($row=mysqli_fetch_array($r)){
 echo '<tr>
 <td >
  <div align="left"><a  rel="facebox" href="delete_t.
php?id=' . $row['session'] . '&date='.$row['date'].'&amount='.$row['debit'].'">Delete Transactions </a></div></td><td>'.($row['date']).'</td>
<td>'.($row['name']).'</td><td>'.Legers($row['froms']).'</td><td>'.(($row['description'])).'</td><td>'.(number_format($row['debit'])).'</td></tr>';
 

 }
 echo '</table>';
mysqli_close($dbc);
}
 function AllUsers(){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("select *,department.name as d from users
 inner join department on department.id=users.department
 group by user_id
"));
 
 
 
 ?>
 
 

<body>
		<link rel="stylesheet" href="tables.css" />
	<div id="tablewrapper">
		<div id="tableheader">
        	<div class="search">
                <select id="columns" onchange="sorter.search('query')"></select>
                <input type="text" id="query" onkeyup="sorter.search('query')" />
            </div>
            <span class="details">
				<div>Records <span id="startrecord"></span>-<span id="endrecord"></span> of <span id="totalrecords"></span></div>
        		<div><a href="javascript:sorter.reset()">reset</a></div>
        	</span>
        </div><div align="center"><h2>User Accounts Administration</h2></div>
		  <form method="post" action="generate_sheet.php">
        <table cellpadding="0" cellspacing="0" border="0" id="table" class="tinytable">
            <thead>
               <tr>
                    
          
			 
			  	 
			  <th><h3>Delete Account</th>
			   
			  <th><h3>Creation Date</th>
			  <th><h3>User</th>
			   <th><h3>Full Names</th>
			  	   <th><h3>Phone</th>
				     <th><h3>Department</th>
					   <th><h3>Status</th>
			  	
			 
                   
                
                </tr>
            </thead>
            <tbody><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>';
 
 echo '<td style="border-color:#000000; border-style:solid; border-width:1px;">
  <div align="left"><a  rel="facebox" href="delete_a.
php?id=' . $row['user_id'] . ' ">Delete Account</a></div></td>';

  echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['date_created'].'</div></td>';
   echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['user_name'].'</div></td>';
 echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['name'].'</div></td>';
  
	 echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['phone'].'</div></td>';

 echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['d'].'</div></td>';
    echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['status'].'</div></td>';

	
	  echo '</tr>';
 }?>
  </tbody>
   </table>
        <div id="tablefooter">
          <div id="tablenav">
            	<div>
                    <img src="images/first.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1,true)" />
                    <img src="images/previous.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1)" />
                    <img src="images/next.gif" width="16" height="16" alt="First Page" onclick="sorter.move(1)" />
                    <img src="images/last.gif" width="16" height="16" alt="Last Page" onclick="sorter.move(1,true)" />
                </div>
                <div>
                	<select id="pagedropdown"></select>
				</div>
                <div>
                	<a href="javascript:sorter.showall()">view all</a>
                </div>
            </div>
			<div id="tablelocation">
            	<div>
                    <select onchange="sorter.size(this.value)">
                    <option value="50" selected="selected">50</option>
					<option value="5" >5</option>
                        <option value="10" >10</option>
                        <option value="20">20</option>
                        <option value="50">50</option>
                        <option value="100">100</option>
						<option value="100">500</option>
						<option value="100">1000</option>
                    </select>
                    <span>Entries Per Page</span>
                </div>
                <div class="page">Page <span id="currentpage"></span> of <span id="totalpages"></span></div>
            </div>
        </div>
    </div>


	<script type="text/javascript" src="script.js"></script>
	<script type="text/javascript">
	var sorter = new TINY.table.sorter('sorter','table',{
		headclass:'head',
		ascclass:'asc',
		descclass:'desc',
		evenclass:'evenrow',
		oddclass:'oddrow',
		evenselclass:'evenselected',
		oddselclass:'oddselected',
		paginate:true,
		size:100,
		colddid:'columns',
		currentid:'currentpage',
		totalid:'totalpages',
		startingrecid:'startrecord',
		endingrecid:'endrecord',
		totalrecid:'totalrecords',
		hoverid:'selectedrow',
		pageddid:'pagedropdown',
		navid:'tablenav',
		sortcolumn:1,
		sortdir:1,
		sum:[8],
		avg:[6,7,8,9],
		columns:[{index:7, format:'%', decimals:1},{index:8, format:'$', decimals:0}],
		init:true
	})
  </script>
</body>
 
 <?

 
 
 
 mysqli_close($dbc);
 }
  function AllNhif(){
	      				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT *
FROM nhif
"));
 
 
 
 ?>
 
 

<body>
		<link rel="stylesheet" href="tables.css" />
	<div id="tablewrapper">
		<div id="tableheader">
        	<div class="search">
                <select id="columns" onchange="sorter.search('query')"></select>
                <input type="text" id="query" onkeyup="sorter.search('query')" />
            </div>
            <span class="details">
				<div>Records <span id="startrecord"></span>-<span id="endrecord"></span> of <span id="totalrecords"></span></div>
        		<div><a href="javascript:sorter.reset()">reset</a></div>
        	</span>
        </div><div align="center"><h2>Nhif Administration</h2></div>
		  <form method="post" action="generate_sheet.php">
        <table cellpadding="0" cellspacing="0" border="0" id="table" class="tinytable">
            <thead>
               <tr>
                    
          
		
			  	 
			  <th><h3>Edit</th>
			    <th><h3>Minimum Bracket</th>
			  <th><h3>Maximum Bracket</th>
			  <th><h3>Rate</th>
			  
			  	
			 
                   
                
                </tr>
            </thead>
            <tbody><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>';
 

 echo '<td style="border-color:#000000; border-style:solid; border-width:1px;">
  <div align="left"><a  href="edit_nhif.
php?id=' . $row['rate_id'] . '">Edit Bracket</a></div></td>';
  echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.number_format($row['mini']).'</div></td>';
   echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.number_format($row['maxi']).'</div></td>';
 echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['rate'].'</div></td>';
  
	;

	
	  echo '</tr>';
 }?>
  </tbody>
   </table>
        <div id="tablefooter">
          <div id="tablenav">
            	<div>
                    <img src="images/first.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1,true)" />
                    <img src="images/previous.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1)" />
                    <img src="images/next.gif" width="16" height="16" alt="First Page" onclick="sorter.move(1)" />
                    <img src="images/last.gif" width="16" height="16" alt="Last Page" onclick="sorter.move(1,true)" />
                </div>
                <div>
                	<select id="pagedropdown"></select>
				</div>
                <div>
                	<a href="javascript:sorter.showall()">view all</a>
                </div>
            </div>
			<div id="tablelocation">
            	<div>
                    <select onchange="sorter.size(this.value)">
                    <option value="50" selected="selected">50</option>
					<option value="5" >5</option>
                        <option value="10" >10</option>
                        <option value="20">20</option>
                        <option value="50">50</option>
                        <option value="100">100</option>
						<option value="100">500</option>
						<option value="100">1000</option>
                    </select>
                    <span>Entries Per Page</span>
                </div>
                <div class="page">Page <span id="currentpage"></span> of <span id="totalpages"></span></div>
            </div>
        </div>
    </div>


	<script type="text/javascript" src="script.js"></script>
	<script type="text/javascript">
	var sorter = new TINY.table.sorter('sorter','table',{
		headclass:'head',
		ascclass:'asc',
		descclass:'desc',
		evenclass:'evenrow',
		oddclass:'oddrow',
		evenselclass:'evenselected',
		oddselclass:'oddselected',
		paginate:true,
		size:100,
		colddid:'columns',
		currentid:'currentpage',
		totalid:'totalpages',
		startingrecid:'startrecord',
		endingrecid:'endrecord',
		totalrecid:'totalrecords',
		hoverid:'selectedrow',
		pageddid:'pagedropdown',
		navid:'tablenav',
		sortcolumn:1,
		sortdir:1,
		sum:[8],
		avg:[6,7,8,9],
		columns:[{index:7, format:'%', decimals:1},{index:8, format:'$', decimals:0}],
		init:true
	})
  </script>
</body>
 
 <?

 
 
 
 mysqli_close($dbc);
 }
 function AllPaye(){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("SELECT *
FROM `tax`
"));
 
 
 
 ?>
 
 

<body>
		<link rel="stylesheet" href="tables.css" />
	<div id="tablewrapper">
		<div id="tableheader">
        	<div class="search">
                <select id="columns" onchange="sorter.search('query')"></select>
                <input type="text" id="query" onkeyup="sorter.search('query')" />
            </div>
            <span class="details">
				<div>Records <span id="startrecord"></span>-<span id="endrecord"></span> of <span id="totalrecords"></span></div>
        		<div><a href="javascript:sorter.reset()">reset</a></div>
        	</span>
        </div><div align="center"><h2>Paye Administration</h2></div>
		  <form method="post" action="generate_sheet.php">
        <table cellpadding="0" cellspacing="0" border="0" id="table" class="tinytable">
            <thead>
               <tr>
                    
          
		
			  	 
			  <th><h3>Edit</th>
			    <th><h3>Minimum Bracket</th>
			  <th><h3>Maximum Bracket</th>
			  <th><h3>Rate</th>
			  
			  	
			 
                   
                
                </tr>
            </thead>
            <tbody><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>';
 

 echo '<td style="border-color:#000000; border-style:solid; border-width:1px;">
  <div align="left"><a  href="edit_paye.
php?id=' . $row['tax_id'] . '">Edit Bracket</a></div></td>';
  echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.number_format($row['mini']).'</div></td>';
   echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.number_format($row['maxi']).'</div></td>';
 echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['rate'].'</div></td>';
  
	;

	
	  echo '</tr>';
 }?>
  </tbody>
   </table>
        <div id="tablefooter">
          <div id="tablenav">
            	<div>
                    <img src="images/first.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1,true)" />
                    <img src="images/previous.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1)" />
                    <img src="images/next.gif" width="16" height="16" alt="First Page" onclick="sorter.move(1)" />
                    <img src="images/last.gif" width="16" height="16" alt="Last Page" onclick="sorter.move(1,true)" />
                </div>
                <div>
                	<select id="pagedropdown"></select>
				</div>
                <div>
                	<a href="javascript:sorter.showall()">view all</a>
                </div>
            </div>
			<div id="tablelocation">
            	<div>
                    <select onchange="sorter.size(this.value)">
                    <option value="50" selected="selected">50</option>
					<option value="5" >5</option>
                        <option value="10" >10</option>
                        <option value="20">20</option>
                        <option value="50">50</option>
                        <option value="100">100</option>
						<option value="100">500</option>
						<option value="100">1000</option>
                    </select>
                    <span>Entries Per Page</span>
                </div>
                <div class="page">Page <span id="currentpage"></span> of <span id="totalpages"></span></div>
            </div>
        </div>
    </div>


	<script type="text/javascript" src="script.js"></script>
	<script type="text/javascript">
	var sorter = new TINY.table.sorter('sorter','table',{
		headclass:'head',
		ascclass:'asc',
		descclass:'desc',
		evenclass:'evenrow',
		oddclass:'oddrow',
		evenselclass:'evenselected',
		oddselclass:'oddselected',
		paginate:true,
		size:100,
		colddid:'columns',
		currentid:'currentpage',
		totalid:'totalpages',
		startingrecid:'startrecord',
		endingrecid:'endrecord',
		totalrecid:'totalrecords',
		hoverid:'selectedrow',
		pageddid:'pagedropdown',
		navid:'tablenav',
		sortcolumn:1,
		sortdir:1,
		sum:[8],
		avg:[6,7,8,9],
		columns:[{index:7, format:'%', decimals:1},{index:8, format:'$', decimals:0}],
		init:true
	})
  </script>
</body>
 
 <?

 
 
 mysqli_close($dbc);
 
 }
 function UserA($id,$name){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 $r=mysqli_query($dbc,("select * from user_trail where user='$id'
"));
 
 
 
 ?>
 
 

<body>
		<link rel="stylesheet" href="tables.css" />
	<div id="tablewrapper">
		<div id="tableheader">
        	<div class="search">
                <select id="columns" onchange="sorter.search('query')"></select>
                <input type="text" id="query" onkeyup="sorter.search('query')" />
            </div>
            <span class="details">
				<div>Records <span id="startrecord"></span>-<span id="endrecord"></span> of <span id="totalrecords"></span></div>
        		<div><a href="javascript:sorter.reset()">reset</a></div>
        	</span>
        </div><a href="javascript:void(processPrint());"><input type="image" value=<img src="print.png"/></a>
<div id="printMe"><div align="center"><h2>User Account Activity For <?echo $name;?></h2></div>
		  <form method="post" action="generate_sheet.php">
        <table cellpadding="0" cellspacing="0" border="0" id="table" class="tinytable">
            <thead>
               <tr>
                    
          
			  <th><h3>Date</th>
			   <th><h3>Time</th>
			  	 
			  <th><h3>Account Activity</th>
			    
			  	
			 
                   
                
                </tr>
            </thead>
            <tbody><?
 while($row=mysqli_fetch_array($r)){
 echo '<tr>';

  echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['date'].'</div></td>';
   echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['time'].'</div></td>';
 echo '<td style="border-color:#000000; border-style:solid; border-width:1px;"><div align="left">'.$row['action'].'</div></td>';
  


	
	  echo '</tr></div>';
 }?>
  </tbody>
   </table>
        <div id="tablefooter">
          <div id="tablenav">
            	<div>
                    <img src="images/first.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1,true)" />
                    <img src="images/previous.gif" width="16" height="16" alt="First Page" onclick="sorter.move(-1)" />
                    <img src="images/next.gif" width="16" height="16" alt="First Page" onclick="sorter.move(1)" />
                    <img src="images/last.gif" width="16" height="16" alt="Last Page" onclick="sorter.move(1,true)" />
                </div>
                <div>
                	<select id="pagedropdown"></select>
				</div>
                <div>
                	<a href="javascript:sorter.showall()">view all</a>
                </div>
            </div>
			<div id="tablelocation">
            	<div>
                    <select onchange="sorter.size(this.value)">
                    <option value="50" selected="selected">50</option>
					<option value="5" >5</option>
                        <option value="10" >10</option>
                        <option value="20">20</option>
                        <option value="50">50</option>
                        <option value="100">100</option>
						<option value="100">500</option>
						<option value="100">1000</option>
                    </select>
                    <span>Entries Per Page</span>
                </div>
                <div class="page">Page <span id="currentpage"></span> of <span id="totalpages"></span></div>
            </div>
        </div>
    </div>


	<script type="text/javascript" src="script.js"></script>
	<script type="text/javascript">
	var sorter = new TINY.table.sorter('sorter','table',{
		headclass:'head',
		ascclass:'asc',
		descclass:'desc',
		evenclass:'evenrow',
		oddclass:'oddrow',
		evenselclass:'evenselected',
		oddselclass:'oddselected',
		paginate:true,
		size:100,
		colddid:'columns',
		currentid:'currentpage',
		totalid:'totalpages',
		startingrecid:'startrecord',
		endingrecid:'endrecord',
		totalrecid:'totalrecords',
		hoverid:'selectedrow',
		pageddid:'pagedropdown',
		navid:'tablenav',
		sortcolumn:1,
		sortdir:1,
		sum:[8],
		avg:[6,7,8,9],
		columns:[{index:7, format:'%', decimals:1},{index:8, format:'$', decimals:0}],
		init:true
	})
  </script>
</body>
 
 <?

 
 mysqli_close($dbc);
 
 
 }
 function movement($date1,$date2,$data){
	     				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
 ?>
 <div align="center"><b> Products Movement Analysis For Dates Between <?echo $date1;?> And <?echo $date2?></b></div>
  <table class="blue" border="1" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
       <tr>
                    
          
			  <th><h3>Product</th>
			  <th><h3>Barcode</th>
			  	<th><h3>System Code</th> 
				  	 
              <th><h3>Current Stock</th>
			   
              <th><h3>Qty Bought</th>
			 <th><h3>Qty Sold</th>
                   
                
                </tr>
 
 <?
 $N = count($data);

  if($date1!=''&&$date2!=''){
for($i=0; $i < $N; $i++){

$Sql=mysqli_query($dbc,("select sum(qty)as s  from sales where p_name='$data[$i]' and date between '$date1' and '$date2'"));

$row=mysqli_fetch_array($Sql);
 $sold=$row['s'];
$sql=mysqli_query($dbc,("select sum(qty)as s  from stocking where p_name='$data[$i]' and p_date between '$date1' and '$date2'"));

$row=mysqli_fetch_array($Sql);
$bot=$row['s'];
$sql=mysqli_query($dbc,("select * from products where p_name='$data[$i]'"));

$row=mysqli_fetch_array($sql);

echo '<tr><td>'.$row['p_name'].'</td><td>'.$row['code'].'</td><td>'.$row['system'].'</td><td>'.$row['left_p'].'</td><td>
'.number_format($bot).'</td><td>'.number_format($sold).'</td></tr>';

}
}
mysqli_close($dbc);
}

function GraphSales(){
$mask="graphs/*.png";
array_map("unlink",glob($mask));
$plot = new PHPlot();
$r=mysqli_query("select sum(IF(month(date)=1,ABS(total_p),0)) as jan,
sum(IF(month(date)=2,ABS(total_p),0)) as feb,
sum(IF(month(date)=3,ABS(total_p),0)) as mar,
sum(IF(month(date)=4,ABS(total_p),0)) as apr,
sum(IF(month(date)=5,ABS(total_p),0)) as may,
sum(IF(month(date)=6,ABS(total_p),0)) as jun,
sum(IF(month(date)=7,ABS(total_p),0)) as jul,
sum(IF(month(date)=8,ABS(total_p),0)) as aug,
sum(IF(month(date)=9,ABS(total_p),0)) as sep,
sum(IF(month(date)=10,ABS(total_P),0)) as oct,
sum(IF(month(date)=11,ABS(total_p),0)) as nov,
sum(IF(month(date)=12,ABS(total_p),0)) as deci
from sales where year(date)=year(NOW())

");
$row=mysqli_fetch_array($r);
$data = array(array('JAN',$row['jan']), array('FEB',$row['feb']),array('MAR',$row['mar']),array('APR',$row['apr']),array('MAY',$row['may']),
array('JUN',$row['jun']),array('JUL',$row['jul']),
array('AUG',$row['aug']),array('SEP',$row['sep']),array('OCT',$row['oct']),
array('NOV',$row['nov']),array('DEC',$row['deci']));
$plot=new PHPlot(900,400);
$plot->SetImageBorderType('plain');
$plot->SetPlotType('bars');
$plot->SetTitle('SALES GRAPH');
$plot->SetDataType('text-data');
$plot->SetDataValues($data);
$plot->SetYTitle('TOTAL SALES IN KSHS');

$plot->SetFont('y_label','5','72');
$plot->SetFont('x_label','5','72');
$plot->SetFont('y_title','5','72');
$plot->SetFont('x_title','5','72');
//$plot->SetPlotAreaWorld(null, 0, null, 100000);

$plot->SetIsInline(True);
$plot->SetOutputFile("graphs/sales.png");
$plot->DrawGraph();





}

function InvoiceGeneration($no){
    				  $dbc=mysqli_connect("localhost","dhdogzbe_rots","@@67YHeqSUYz4@YIKU@@Lo@@@","dhdogzbe_store");
$r=mysqli_query($dbc,("select * from sales where type='INVOICE' and number='$no'"));
$l=mysqli_query($dbc,("select * from ledgers
inner join accounts on accounts.id=ledgers.account_id where invoice='$no' and debit>0 and description='SALES VIA INVOICE'"));
$row=mysqli_fetch_array($l);

?>



				
         <table class="blue" border="0" style="background-color:#ffffff"; rules="NONE"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial";>
 <tr> <td>
  <strong><img border="0" src="logo.jpg" width="930" height="121"></td></tr></table> 
               <table class="blue" border="0" style="background-color:#ffffff"
        frame="BOX" width="980" align="center" 
 cellpadding="5" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">    
                
               
                 <tr><td style="font-size: 16px" ><center>P.O BOX 71305-00622,NAIROBI TEL: 0723 224 270</center></td></tr></table>
  
  <div align="center"><h4 style="font-family:Bell Gothic,Verdana,Arial";><u>INVOICE NO <?echo $no;?></u></h4></div>

<table class="blue" border="0" style="background-color:#ffffff"
       rules="NONE" frame="BOX" width="980" align="center" 
 cellpadding="12" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
 <tr><td style="font-family:Bell Gothic ,Verdana,Arial;font-size: 16px">Client Name <b><?echo $row['name'];?></td><td style="font-family:Bell Gothic ,Verdana,Arial;font-size: 16px"></td></tr> 
  <tr><td style="font-family:Bell Gothic ,Verdana,Arial;font-size: 16px">Delivery Date <b><?echo $row['date'];?></td><td style="font-family:Bell Gothic ,Verdana,Arial;font-size: 16px"></td></tr>
 <tr><td style="font-family:Bell Gothic ,Verdana,Arial;font-size: 16px"> Payment Date <b><?echo $row['mat_date'];?></td><td style="font-family:Bell Gothic ,Verdana,Arial;font-size: 16px"></td></tr>
 </table>
 <table class="blue" border="3" style="background-color:#ffffff"
       rules="NONE" frame="BOX" width="980" align="center" 
 cellpadding="12" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial"><th style="font-size: 18px"><u><left>INVOICE DETAILS</th>
 
 <tr><td style="font-size: 18px"><u>Product Name</td><td style="font-size: 18px"><u>Qty</td> <td style="font-size: 18px"><u>Price</td><td style="font-size: 18px"><u>Sub Total</td></tr> 
  <?while($row=mysqli_fetch_array($r)){
   echo '<tr><td style="font-size: 16px">'.$row['p_name'].'</td><td style="font-size: 16px">'.($row['qty']).'</td>
 <td style="font-size: 16px">'.($row['price']).'</td><td style="font-size: 16px"><b>'.number_format($row['total_p'],2).'</td></tr>';
 $total+=$row['total_p'];
 $qty+=$row['qty'];
  
  } echo '<tr><td cospan="3" style="font-size: 18px"><center><b>TOTAL (Vat Inclusive)</td><td style="font-size: 18px"><b><u>'.number_format($total,2).' </td></tr>';?>
 </table>
 <table class="blue" border="0" style="background-color:#ffffff"
       rules="NONE" frame="BOX" width="980" align="center" 
 cellpadding="20" cellspacing="0" style="font-family:Bell Gothic,Verdana,Arial">
 <tr><td style="font-family:Bell Gothic ,Verdana,Arial;font-size: 16px">Stamp</td></tr>
  <tr><td></td><td style="font-family:Bell Gothic ,Verdana,Arial;font-size: 16px"><div align="right">Accountant's Signature.................................................</td></tr>
</table>
 <div align="center" style="font-family:Bell Gothic ,Verdana;">ACCOUNT IS DUE ON DEMAND</i></div><br>
   <div align="center" style="font-family:Bell Gothic ,Verdana;"><i>"Finish your house in style"</i></div>
   
   <?
   mysqli_close($dbc);
   }

 
 