<style type="text/css">
.style20 {
	font-family: Verdana;
	font-size: 12px;
}
.style5 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
}
.style3 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
}
.style10{ border-top:solid 1px; border-top-color:#999;}
.style11{ border-bottom:dashed 1px; border-bottom-color:#333333;}
.style4 {font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
}
.style23 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-weight: bold;
}
.style27 {font-size: 12px}
.style28 {
	font-size: 16px;
	font-weight: bold;
}
.text {font-family: Verdana; font-size:13px;}
.style29 {	font-family: Verdana;
	font-size: 14px;

}
.stylebottom
{
	border-right:1px solid #999;

	
	border-bottom:1px solid #999;
}	
</style>
<div class="row-fluid">
<div class="span12">
<div class="table-responsive">
<div class="CSSTableGenerator">
<?php 
  include ("../../include/db.php");
error_reporting(0);
ob_start();
session_start();
$session_branch=$_SESSION['branch'];
$session_user_type=$_SESSION['user_type'];
  $branch_name=$_GET['branch_name'];

function get_categ_branch_id($branch_name)
{
$sql_query11="select * from branch_creation where branch_id='$branch_name' and delete_status!='1'";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $id=$rsdata11->branch_name;
 } 
	return $id;
 }

											 ?>
<table width="850px" height="30" border="0" align="center"  cellpadding="0" cellspacing="0">
<tr style="height:60">
<td width="137" height="106" align="left" style="font-size:12px; border-bottom:1px solid #999;"><img src="../../img/logo_image.png" width="126" height="130"/></td>
<td width="711" colspan="5" align="center" valign="top" style="border-bottom:1px solid #999;"><strong style="font-size: 30px; color: #06F; padding-top: 5px; width: 80px; font-family: Verdana, sans-serif">SRI AMMAN DIGITAL PRINTS</strong><br />
        <span width="80%" class="title1" style="font-size:14px;font-family:Verdana, sans-serif; font-weight:bold"><b></b> DOOR No: 1/2,1/3  KOMBAI THOTTAM MAIN ROAD,</span><br />
       <span width="80%" class="title0" style="font-size:14px;font-family:Verdana, sans-serif; font-weight:bold"><b></b>SELLANDIAMMAN THURAI ROAD,</span><br />
       <span width="80%" class="title0" style="font-size:14px;font-family:Verdana, sans-serif; font-weight:bold"><b></b>TIRUPPUR-641604 TAMILNADU STATE INDIA,</span><br/>
       <span width="80%" class="title00" style="font-size:14px;font-family:Verdana, sans-serif; font-weight:bold"><b></b>Contact Office: 0421-4355333,+91 83442-33555,+91 83442-33888,</span><br/>
       <span width="80%" class="title0" style="font-size:14px;font-family:Verdana, sans-serif; font-weight:bold"><b></b>Email Id : sriammandigitalprints@gmail.com/yahoo.com.</span><br/>
       <br/>
    <span width="80%" class="title1" style="font-size:18px;font-family:Verdana, sans-serif; font-weight:bold"><b></b>Customer Wise Report Print</span></td>  </tr>

<tr>
<td colspan="2">
<table width="100%" height="40" border="0"  cellpadding="0" cellspacing="0">
<tr>
<td width="39%" height="28" align="left" class="style4"><strong>Customer Name : </strong>
  <?php if($_GET['customer_name']==''){ echo "All";} else { echo ucfirst($_GET['customer_name']);}?>&nbsp;&nbsp;</td>
<td colspan="2" align="center" class="style4"><strong>From Date :</strong>  <?php if($_GET['from_date']==''){ echo $curdate=date('d-m-Y');} else { echo date("d-m-Y",strtotime($_GET['from_date']));}?></td>
<td align="right" scope="col" class="style4"><strong>To Date :</strong>  <?php if($_GET['to_date']==''){ echo $curdate=date('d-m-Y');} else { echo date("d-m-Y",strtotime($_GET['to_date'])); }?></td>
</tr></table>
</td></tr>
<tr>
<td colspan="2">
<table  width="100%"  cellpadding="0" cellspacing="0" style="border-top:dashed 1px" >
      <tr>
      <td width="89" height="26" align="center"  style="border-bottom:dashed 1px; font-family:Verdana, sans-serif; font-size:12px;"><strong>S.No</strong></td>
      <td width="451" align="left"  style="border-bottom:dashed 1px; font-family:Verdana, sans-serif; font-size:12px;" scope="col"><strong>&nbsp;&nbsp;Customer Name</strong><strong>&nbsp;</strong></td>
        <td width="192" scope="col" align="right" style="border-bottom:dashed 1px; font-family:Verdana, sans-serif; font-size:12px;" ><strong>&nbsp;&nbsp;opening Balance</strong>&nbsp;&nbsp;</td>
      <td align="right"  style="border-bottom:dashed 1px; font-family:Verdana, sans-serif; font-size:12px;" scope="col"><strong>&nbsp;&nbsp;Debit Amount</strong>&nbsp;&nbsp;</td>
      <td width="165"  align="right" style="border-bottom:dashed 1px; font-family:Verdana, sans-serif; font-size:12px;" scope="col" ><strong>&nbsp;Credit Amount</strong>&nbsp;&nbsp;</td>
      <td width="162"  align="right" style="border-bottom:dashed 1px; font-family:Verdana, sans-serif; font-size:12px;"   scope="col"><strong>&nbsp;Closing Balance</strong>&nbsp;&nbsp;</td>
  </tr>
  <?php
  include ("../../include/db.php");


function get_opening_amt11($jobcard_no)
{
	 $sql="select sum(net_total)  as net_total from   jobcard_main where jobcard_no='$jobcard_no' ";
	 $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                 $net_total=$rsdata['net_total'];
			}
return $net_total;
}
function get_dbt($jobcard_no)
{
$sql="select *  from  printer_production_main where job_type='sticker' and job_card_no='$jobcard_no' and billed_status='0'  union select *  from  fusing_production_main where p_id!='' and job_card_no='$jobcard_no' and billed_status='0'";	 
$rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                 $job_card_no=$rsdata['job_card_no'];
			}
			 $sql="select sum(net_total)  as net_total from   jobcard_main where jobcard_no='$job_card_no' ";
	 $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                 $net_total=$rsdata['net_total'];
			}
return $net_total;
}
function get_cdt($job_card_no)
{
	$sql="select *  from  printer_production_main where job_type='sticker'  and job_card_no='$jobcard_no' and billed_status='1'  union select *  from  fusing_production_main where p_id!='' and job_card_no='$jobcard_no' and billed_status='1'";	 
$rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                 $job_card_no=$rsdata['job_card_no'];
			}
			 $sql="select sum(net_total)  as net_total from   jobcard_main where jobcard_no='$job_card_no' ";
	 $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                 $net_total=$rsdata['net_total'];
			}
return $net_total;
	
	
}
function get_opening_amt($cust_name,$from_date,$current_date)
{
	 if($from_date!='')
	 {
  $sql="select *  from  printer_production_main where job_type='sticker' and print_date<'$from_date'  and cust_name='$cust_name'  union select *  from  fusing_production_main where p_id!='' and print_date<'$from_date' and cust_name='$cust_name' ";
	 }
	 else
	 {
		$sql="select *  from  printer_production_main where job_type='sticker' and print_date<'$current_date'  and cust_name='$cust_name'  union select *  from  fusing_production_main where p_id!='' and print_date<'$current_date' and cust_name='$cust_name' "; 
		 }
 	 $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                 $job_card_no=$rsdata['job_card_no'];
				 $debit+=get_dbt($job_card_no);
 				 $credit+=get_cdt($job_card_no);
				 $opening_amt=$credit-$debit;
			}
return $opening_amt;
}
function get_debit_amt11($job_card_no22)
{
	 $sql="select sum(net_total)  as net_total from  jobcard_main where jobcard_no='$job_card_no22' ";
	 $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                 $net_total=$rsdata['net_total'];
			}
return $net_total;
}
function get_credit_amt11($job_card_no1)
{
	  $sql="select sum(net_total)  as net_total from  jobcard_main where jobcard_no='$job_card_no1' ";
	 $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                 $net_total=$rsdata['net_total'];
			}
return $net_total;
}
function get_debit_amt($cust_name,$from_date,$to_date,$current_date)
{
	if($from_date!='')
	 {
	  $sql="select *  from  printer_production_main where job_type='sticker' and print_date>='$from_date' and print_date<='$to_date'  and cust_name='$cust_name' and 	billed_status='1'  union select *  from  fusing_production_main where p_id!='' and print_date>='$from_date' and print_date<='$to_date' and cust_name='$cust_name' and billed_status='1'";
	 }
	 else
	 {
		 $sql="select *  from  printer_production_main where job_type='sticker' and  print_date='$current_date' and cust_name='$cust_name' and 	billed_status='1'  union select *  from  fusing_production_main where p_id!='' and print_date='$current_date' and cust_name='$cust_name' and billed_status='1'"; 
	 }
	//echo $sql;
	 $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                  $job_card_no22=$rsdata['job_card_no'];
				 $debit_amt+=get_debit_amt11($job_card_no22);
			}
return $debit_amt;
}
function get_credit_amt($cust_name,$from_date,$to_date,$current_date)
{
	 if($from_date!='')
     {
	$sql="select *  from  printer_production_main where job_type='sticker' and print_date>='$from_date' and print_date<='$to_date'  and cust_name='$cust_name' and 	billed_status='0'   union select *  from  fusing_production_main where p_id!='' and print_date>='$from_date' and print_date<='$to_date' and cust_name='$cust_name' and 	billed_status='0'";
	 }
	 else
	 {
		$sql="select *  from  printer_production_main where job_type='sticker' and print_date='$current_date' and cust_name='$cust_name' and 	billed_status='0'   union select *  from  fusing_production_main where p_id!='' and print_date='$current_date' and cust_name='$cust_name' and 	billed_status='0'"; 
	}
	//echo $sql;
	 $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                  $job_card_no1=$rsdata['job_card_no'];
				  $credit_amt+=get_credit_amt11($job_card_no1);
			}
return $credit_amt;
} 


$from_date=$_GET['from_date'];
$to_date=$_GET['to_date'];
$customer_name=$_GET['customer_name'];

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

if($from_date!=""){ $from_date1= "print_date>='$from_date'"; }else{$from_date1="print_date='$current_date'"; }
if($to_date!=""){ $to_date1 = "print_date<='$to_date'";}else{$to_date1="print_date='$current_date'";}
if($job_card_no!=""){ $job_card_no1 = "job_card_no='$job_card_no'";}else{$job_card_no1="";}
if($customer_name!=""){ $customer_name1 = "cust_name='$customer_name'";}else{$customer_name1="";}

{
$all_value10 = $from_date1.",".$to_date1.",".$job_card_no1.",".$customer_name1;
}
$all_array10 = explode(',',$all_value10);
foreach($all_array10 as $value10)
{ 
if($value10!='')
{
  $get_query106 .= $value10." AND ";
}
}	  




if($from_date!='')
{
 $sql="select distinct cust_name from  printer_production_main where $get_query106 p_id!='' and job_type='sticker' union select distinct cust_name from  fusing_production_main where $get_query106 p_id!=''";
}
else
{  
 $sql="select distinct cust_name  from  printer_production_main where job_type='sticker'  union select distinct cust_name  from  fusing_production_main where p_id!=''";
}
//echo $sql;
    $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				 $s_no=$s_no+1;
				 $from=$from+1;
                 $cust_name=$rsdata['cust_name'];
				$opening_amt=get_opening_amt($cust_name,$from_date,$current_date);
				 $debit=get_debit_amt($cust_name,$from_date,$to_date,$current_date);
 				  $credit=get_credit_amt($cust_name,$from_date,$to_date,$current_date);
				  $opening_amt1=abs($opening_amt);
				if($opening_amt<=0)
				 {
					 $closing_bal=$opening_amt+($debit-$credit); 
				 }
				 if($opening_amt>0)
				 {
					$closing_bal=($credit-$debit)+$opening_amt;
				 }
				 if($opening_amt>0)
				 {
					 $get_dr='<span style="color:#336600;text-align:center;">Dr</span>';
				 }
				 if($opening_amt<=0)
				 {
					 $get_dr='<span style="color:#FF0000;text-align:center;">Cr</span>';
				 }
				  if($opening_amt<=0)
				 {
					 $closing_bal=($debit-$credit)+$opening_amt; 
				 }
				 if($opening_amt>0)
				 {
					$closing_bal=($credit-$debit)+$opening_amt;
				 }
				 if($closing_bal>0)
				 {
					 $get_cr='<span style="color:#FF0000;text-align:center;">Dr</span>';
				 }
				 if($closing_bal<=0)
				 {
					$get_cr='<span style="color:#336600;text-align:center;">Cr</span>';
				 }
				 $closing_bal1=abs($closing_bal);
 ?>
  <tr >
    <td width="89" height="26" style=" font-family:Verdana, sans-serif; font-size:12px;"   align="center" ><?php echo $from; ?></td>
    <td width="451" style=" font-family:Verdana, sans-serif; font-size:12px;"  align="left" >&nbsp;<?php echo $cust_name;?></td>
    <td align="right" style=" font-family:Verdana, sans-serif; font-size:12px;"  >&nbsp;<?php echo number_format($opening_amt1,2);?>&nbsp;</td>
    <td width="195" style=" font-family:Verdana, sans-serif; font-size:12px;"  align="right" >&nbsp;<?php echo number_format($debit,2);?>&nbsp;</td>
    <td align="right" style=" font-family:Verdana, sans-serif; font-size:12px;"  >&nbsp;<?php echo number_format($credit,2); ?>&nbsp;</td>
    <td align="right" style=" font-family:Verdana, sans-serif; font-size:12px;" >&nbsp;<?php echo number_format($closing_bal1,2);?>&nbsp;</td>
   </tr>&nbsp;
  <?php 
  
  $net_tot+=$net_total;
  } ?>

       <td height="30" colspan="15" align="right" style="border-top:dashed 1px; font-family:Verdana, sans-serif; font-size:12px;">Printed Date : <?php echo $curdate=date('d-m-Y h:m a');?>&nbsp;</p></td>
</table>
</td></tr></table>
