<?php session_start();



if($_SESSION[invcox] == ""){



header("location:login.php?action=need");



}else{





include("config.php");?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml">



<head>



<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />



<title>Arnim Holidays Accounting Software</title>



<link href="style.css" rel="stylesheet" type="text/css" />

 


<SCRIPT LANGUAGE="JavaScript">







<!-- Begin



function popUp(URL) {

day = new Date();
id = day.getTime();



eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=yes,width=950,height=650,left = 100,top = 100');");



}



// End -->



</script>

<style type="text/css">

<!--

.style2 {color: #DC147B;

	font-weight: bold;

}

.style3 {color: #000000}

-->

</style>
<?php include("calendar.php"); ?>
</head>







<body>



<table width="95%" border="0" align="center" cellpadding="0" cellspacing="1" class="box-wrap">



  <tr>



    <td><?php include("top.php")?></td>



  </tr>



  <tr>



    <td>&nbsp;</td>



  </tr>



  <tr>



    <td class="center_page_white"><table width="100%" border="0" cellspacing="1" cellpadding="0">



      <tr>



        <td valign="top"><br />



          <form id="form1" name="form1" method="post" action="">



            <table width="100%" border="0" cellpadding="3" cellspacing="1"  class="round_box">



              <tr>



                <td width="16%"><strong>Restaurant Cash Book</strong></td>



                <td width="84%">&nbsp;</td>



              </tr>

<?php 

if($_POST[ds]!=""){$ds=$_POST[ds];}

if($_POST[de]!=""){$de=$_POST[de];}



if($_GET[ds]!=""){$ds=$_GET[ds];}

if($_GET[de]!=""){$de=$_GET[de];}



if($ds == ""){



//$dddez = strtotime("-60 day");

$ds=date('d-m-Y');



}

if($de == ""){$de=date("d-m-Y");}



 ?>

              <tr>



                <td>Search by date :                  </td>



                <td><table width="703" border="0" cellspacing="1" cellpadding="2">
                  <tbody>
                    <tr>
                      <td width="69">From
                        <input name="p" type="hidden" id="p" value="y" /></td>
                      <td width="233"><table width="180" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="70%"><input name="ds" type="text" id="ds" size="15"  value="<?php echo $ds;?>" required="required"/></td>
                          <td width="30%" align="center"><a title="Calendar" onclick="displayDatePicker('ds', this);" href="javascript:;"><img src="images/calendar.gif" width="20" height="20" border="0" /></a></td>
                        </tr>
                      </table></td>
                      <td width="22"><input name="p2" type="hidden" id="p2" value="y" /></td>
                      <td width="23">To</td>
                      <td width="233"><table width="180" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="70%"><input name="de" type="text" id="de" size="15"  value="<?php echo $de;?>" required="required"/></td>
                          <td width="30%" align="center"><a title="Calendar" onclick="displayDatePicker('de', this);" href="javascript:;"><img src="images/calendar.gif" width="20" height="20" border="0" /></a></td>
                        </tr>
                      </table></td>
                      <td width="92"><input type="submit" name="Submit" value="Search" /></td>
                    </tr>
                  </tbody>
                </table></td>



              </tr>

              <tr>
                
                
                
                <td>&nbsp;</td>
                
                
                
                <td>&nbsp;</td>
                
                
                
              </tr>



            </table>



            </form>



          </td>



      </tr>



      <tr>



        <td height="30">&nbsp;</td>



      </tr>

<?php  $result=mysql_query("SELECT pay_methode 
FROM (
    SELECT pay_methode
    FROM chalan 
    
    GROUP BY pay_methode

    UNION ALL
    
    SELECT pay_methode
    FROM chalan_payment 
   
    GROUP BY pay_methode

    
) AS all_methods
GROUP BY pay_methode;
");
		  $row=mysql_fetch_array($result);
		 
	 if($ds!=""){  $ds=dtformat($ds); $de=dtformat($de);  $d="and cdate<'$ds' "; }	
		
		?>

      <tr>
        <td class="round_box"><table width="100%" border="0" cellpadding="3" cellspacing="1" class="list_table">
          <tbody>
            <tr>
              <th>Pay Methode</th>
              <th>Opening</th>
              <th>Cash In</th>
              <th>Cash Out </th>
              <th>Balance</th>
            </tr>
			  <?php 

 if($row!=""){
		  do{
			  
			  

	 
	 
			  ?>
            <tr>
              <td><?php echo $row[pay_methode];?></td>
              <td><?php 
$pay_methode="and pay_methode='$row[pay_methode]' ";
$pay_methode2="and cost_type='$row[pay_methode]' ";
$opening_balance=0; 



$dresult=mysql_query("select sum(payment)as payment from chalan WHERE total_payeble!='0'  $d $pay_methode");
$drow=mysql_fetch_array($dresult);
$opening_balance=$drow[payment];
	 
 $dresult=mysql_query("select sum(payment_amount)as payment_amount from chalan_payment WHERE payment_amount!='0'  $d $pay_methode");
 $drow=mysql_fetch_array($dresult);
$opening_balance=$opening_balance+$drow[payment_amount];
	 
/* $dresult=mysql_query("select sum(amount)as amount from income WHERE amount!='0'  $d $pay_methode");
 $drow=mysql_fetch_array($dresult);
$opening_balance=$opening_balance+$drow[amount];

 
 $dresult=mysql_query("select sum(amount)as amount from cost WHERE amount!='0'  $d $pay_methode");
 $drow=mysql_fetch_array($dresult);

 
 $fresult=mysql_query("select sum(amount)as amount from transfar WHERE amount!='0'  $d $pay_methode");
 $frow=mysql_fetch_array($fresult);
$opening_balance=$opening_balance+$frow[amount];
 
 $gresult=mysql_query("select sum(amount)as amount from transfar WHERE amount!='0'  $d $pay_methode2");
 $grow=mysql_fetch_array($gresult);
$opening_balance=$opening_balance-$grow[amount];


  $gresult=mysql_query("select sum(amount)as amount from withdraw WHERE amount!='0'  $d $pay_methode2");
 $grow=mysql_fetch_array($gresult);
$opening_balance=$opening_balance-$grow[amount];


$eresult=mysql_query("select sum(salary)as salary from hr_salary_paid WHERE salary!='0'  $d $pay_methode");
 $erow=mysql_fetch_array($eresult);
			  
 
$opening_balance=($opening_balance-$drow[amount])-$erow[salary];	*/
echo number_format($opening_balance);	 
			  
$gt_oping=$gt_oping+$opening_balance;
				  ?></td>
              <td class="link"><a href="rcash_book_details_in.php?pay_methode=<?php echo $row[pay_methode];?>&date1=<?php echo $ds;?>&date2=<?php echo $de;?>" target="new"><?php 
//------------cash in -----------------
			  
$a="and cdate>='$ds' and cdate<='$de' ";
$cash_in=0;		 


$dresult=mysql_query("select sum(payment)as payment from chalan WHERE payment!='0'  $pay_methode $a ");
$drow=mysql_fetch_array($dresult);
$cash_in=$drow[payment];
	 
  
 $dresult=mysql_query("select sum(payment_amount)as payment_amount from chalan_payment WHERE payment_amount!='0'  $pay_methode $a");
 $drow=mysql_fetch_array($dresult);
$cash_in=$cash_in+$drow[payment_amount];
/*
 
 $dresult=mysql_query("select sum(amount)as amount from income WHERE amount!='0'   $pay_methode $a");
 $drow=mysql_fetch_array($dresult);
$cash_in=$cash_in+$drow[amount];

 
 $fresult=mysql_query("select sum(amount)as amount from transfar WHERE amount!='0'  $a $pay_methode");
 $frow=mysql_fetch_array($fresult);
$cash_in=$cash_in+$frow[amount];
 */

	echo number_format($cash_in);
			  
$gt_in=$gt_in+$cash_in;
				  ?></a></td>
              <td class="link"><a href="rcash_book_details_out.php?pay_methode=<?php echo $row[pay_methode];?>&amp;date1=<?php echo $ds;?>&amp;date2=<?php echo $de;?>" target="new"><?php 
/*
 $dresult=mysql_query("select sum(amount)as amount from cost WHERE amount!='0'  $a $pay_methode");
 $drow=mysql_fetch_array($dresult);


 $eresult=mysql_query("select sum(salary)as salary from hr_salary_paid WHERE salary!='0'  $a $pay_methode");
 $erow=mysql_fetch_array($eresult);
			  
  	  
			  
$cash_out=$drow[amount]+$erow[salary];
			  $gt_out=$gt_out+$cash_out;
 
 $gresult=mysql_query("select sum(amount)as amount from transfar WHERE amount!='0'  $a $pay_methode2");
 $grow=mysql_fetch_array($gresult);
$cash_out=$cash_out+$grow[amount];

 $gresult=mysql_query("select sum(amount)as amount from withdraw WHERE amount!='0'  $a $pay_methode2");
 $grow=mysql_fetch_array($gresult);
$cash_out=$cash_out+$grow[amount];
*/

echo number_format($cash_out);
				  ?></a></td>
              <td><?php 
$closing=0;
$closing=($opening_balance+$cash_in)-$cash_out;	
			  echo number_format($closing);

$gt_bala=$gt_bala+$closing;
			  
				  ?></td>
            </tr>
            
			  <?php }while($row=mysql_fetch_array($result));}?>
			  <tr>
              <td>Total </td>
              <td><?php echo number_format($gt_oping);	?></td>
              <td><?php echo number_format($gt_in);	?></td>
              <td><?php echo number_format($gt_out);	?></td>
              <td><?php echo number_format($gt_bala);	?></td>
            </tr>
          </tbody>
        </table></td>
      </tr>
  
 
		
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>



        <td class="round_box"><table width="100%" border="0" cellspacing="3" cellpadding="2">
          <tbody>
            <tr>
              <td width="50%" height="30" bgcolor="#518289" class="white_color"><strong>Cash In</strong></td>
              <td width="50%" bgcolor="#518289" class="white_color"><strong>Cash Out</strong></td>
            </tr>
            <tr>
              <td valign="top"><table width="100%" border="0" cellpadding="3" cellspacing="1" class="list_table">
                <tr>
                  <th align="center" >Sr</th>
                  <th align="center" >Date</th>
                  <th align="center" >Source</th>
                  <th align="center" >Amount</th>
                  </tr>
                <?php 



		// opening balance -------------    
$opening_balance=0;
	
 if($ds!=""){
  
	 
		 
		 
$dresult=mysql_query("select sum(payment)as payment from chalan WHERE total_payeble!='0'  $d");
$drow=mysql_fetch_array($dresult);
$opening_balance=$drow[payment];
	 
 $dresult=mysql_query("select sum(payment_amount)as payment_amount from chalan_payment WHERE payment_amount!='0'  $d");
 $drow=mysql_fetch_array($dresult);
$opening_balance=$opening_balance+$drow[payment_amount];
	 
 
	 
$opening_balance=($opening_balance-$drow[amount])-$erow[salary];	
		
 }
// opening balance -------------     

		  if($ds!=""){

		  
		  
		$d="and cdate>='$ds' and cdate<='$de' ";}else{$d="";}

		  
 


		 
		  $total=0;



		  ?>
                <tr>
                  <td colspan="3" align="right" class="link">Opening Balance </td>
                  <td align="center" class="link"><?php 

 
	echo number_format($opening_balance);

	
			?></td>
                </tr>
<?php  $dresult=mysql_query("select  id ,cdate,payment from chalan WHERE payment!='0'  $d");
          $drow=mysql_fetch_array($dresult);
	if($drow!=""){
				  do{
					  $sr=$sr+1;
				  ?>
                <tr>
                  <td width="4%" align="center" class="link"><?php echo $sr; ?></td>
                  <td width="4%" align="center" class="link norwap"><?php echo dtformat($drow[cdate]);?></td>
                  <td width="50%" align="center" class="link">Restaurant - <?php echo $drow[id];?></td>
                  <td width="25%" align="center" class="link"><?php 



			 echo number_format($drow[payment]);

$total=$total+$drow[payment];

	
	
			?></td>
                  </tr>
	<?php 
				  }while($drow=mysql_fetch_array($dresult));
	}
		  $dresult=mysql_query("select   * from chalan_payment WHERE payment_amount!='0'  $d");
          $drow=mysql_fetch_array($dresult);
	if($drow!=""){
	do{
			 $sr=$sr+1;	  ?>			  
                <tr>
                  <td width="4%" align="center" class="link"><?php echo $sr; ?></td>
                  <td width="4%" align="center" class="link norwap"><?php echo dtformat($drow[cdate]);?></td>
                  <td width="50%" align="center" class="link">Restaurant Due Payment - <?php echo $drow[bill_id];?></td>
                  <td width="25%" align="center" class="link"><?php 


echo number_format($drow[payment_amount]);

$total=$total+$drow[payment_amount];

			?></td>
                  </tr>
<?php 
	
	 }while($drow=mysql_fetch_array($dresult));
	}
	
	
/*$d="and hr_salary_paid.cdate>='$ds' and hr_salary_paid.cdate<='$de' ";
	
$dresult=mysql_query("select 
hr_employee.customer_name, hr_salary_paid.salary, hr_salary_paid.cdate 
from hr_salary_paid 
JOIN hr_employee 
    ON hr_employee.id = hr_salary_paid.employee

WHERE hr_salary_paid.salary!='0'  $d 
 
	
");
	
	 
	 
          $drow=mysql_fetch_array($dresult);
	if($drow!=""){
	do{
			 $sr=$sr+1;	  ?>			  
                <tr>
                  <td width="4%" align="center" class="link"><?php echo $sr; ?></td>
                  <td width="4%" align="center" class="link norwap"><?php echo dtformat($drow[cdate]);?></td>
                  <td width="50%" align="center" class="link">Salary Paid - <?php echo $drow[customer_name];?></td>
                  <td width="25%" align="center" class="link"><?php 


echo number_format($drow[salary]);

$total=$total+$drow[salary];

			?></td>
                  </tr>
<?php 
	
	 }while($drow=mysql_fetch_array($dresult));
	}
	*/
	
	/*	  if($ds!=""){

	 
	$d="and income.cdate>='$ds' and income.cdate<='$de' ";}else{$d="";}
 
		  $dresult=mysql_query("SELECT 
    income_type.cost, 
    income.amount,
	income.cost_type,
	income.cdate,
	income.pt
FROM income 
JOIN income_type 
    ON income.cost_type = income_type.id
WHERE income.amount != 0 
    $d
ORDER BY income_type.cost ASC");
          $drow=mysql_fetch_array($dresult);
if($drow!=""){
	do{
		$sr=$sr+1;		  ?>
				  
                <tr>
                  <td align="center"  class="link"><?php echo $sr; ?></td>
                  <td align="center"  class="link norwap"><?php echo dtformat($drow[cdate]);?></td>
                  <td align="center"  class="link"><?php echo $drow[cost];?> - <?php echo $drow[pt];?></td>
                  <td align="center"  class="link"><?php echo number_format($drow[amount]);?></td>
                </tr>
<?php 
$total=$total+$drow[amount];
		
}while($drow=mysql_fetch_array($dresult));
}*/
				  ?>
                <tr>
                  <td colspan="3" align="right"  class="link"><strong>Cash in  Total :</strong></td>
                  <td align="center"  class="link"><strong><?php echo number_format($total); ?></strong></td>
                  </tr>
                <tr>
                  <td colspan="3" align="right"  class="link">Total :</td>
                  <td align="center"  class="link"><?php $total=$total+$opening_balance; echo number_format($total); ?></td>
                </tr>
              </table></td>
              <td valign="top"><table width="100%" border="0" cellpadding="3" cellspacing="1" class="list_table">
                <tr>
                  <th width="4%" align="center" >Sr</th>
                  <th width="4%" align="center" >Date</th>
                  <th width="50%" align="center" >Source</th>
                  <th width="25%" align="center" >Amount</th>
                </tr>
                <?php 



		    



		 
	/*  if($ds!=""){

		 
		$d="and cost.cdate>='$ds' and cost.cdate<='$de' ";}else{$d="";}
 



		  $ctotal=0;


 
 $sr=0;

	
		  $dresult=mysql_query("SELECT 
    cost_type.cost, 
    cost.amount AS amount,
	cost.cdate,
	cost.pt,
	cost.cost_type
FROM cost 
JOIN cost_type 
    ON cost.cost_type = cost_type.id
WHERE cost.amount != 0 
    $d
ORDER BY cost.cost_type ASC");
          $drow=mysql_fetch_array($dresult);
if($drow!=""){
	do{
		$sr=$sr+1;		  ?>
                <tr>
                  <td align="center"  class="link"><?php echo $sr; ?></td>
                  <td align="center"  class="link norwap"><?php echo dtformat($drow[cdate]);?></td>
                  <td align="center"  class="link"><?php echo $drow[cost];?> - <?php echo $drow[pt];?></td>
                  <td align="center"  class="link"><?php echo number_format($drow[amount]);?></td>
                </tr>
                <?php 
$ctotal=$ctotal+$drow[amount];
		
}while($drow=mysql_fetch_array($dresult));
}*/
				  ?>
                <tr>
                  <td colspan="3" align="right"  class="link"><strong>Cash Out:</strong></td>
                  <td align="center"  class="link"><strong><?php echo number_format($ctotal); ?></strong></td>
                </tr>
                <tr>
                  <td colspan="3" align="right"  class="link">Cash In :</td>
                  <td align="center"  class="link"><?php echo number_format($total); ?></td>
                </tr>
                <tr>
                  <td colspan="3" align="right" bgcolor="#BBD9DC"  class="link"><strong>Current Balance :</strong></td>
                  <td align="center" bgcolor="#BBD9DC"  class="link"><strong><?php 
					  
	$profit_loss=$total-$ctotal;  echo number_format($profit_loss);
					  ?></strong></td>
                </tr>
              </table></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
           
          </tbody>
        </table></td>



      </tr>
      <tr>
        <td >&nbsp;</td>
      </tr>
      <tr>
        <td class="round_box"><table width="100%" border="0" cellpadding="3" cellspacing="1" class="list_table">
          <tbody>
            <tr>
              <th>Opening</th>
              <th>Cash In</th>
              <th>Cash Out </th>
              <th>Balance</th>
            </tr>
            <tr>
              <td><?php echo number_format($opening_balance);	?></td>
              <td><?php echo number_format($total);	?></td>
              <td><?php echo number_format($ctotal);	?></td>
              <td><?php echo number_format($profit_loss);	?></td>
            </tr>
          </tbody>
        </table></td>
      </tr>



    </table></td>



  </tr>



  <tr>



    <td><?php include("bot.php")?></td>



  </tr>



</table>



</body>



</html>



<?php }?>