<title>INDIVIDUAL CUSTOMER REPORT</title>
 <style type="text/css">
<!--
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-weight: bold;
	font-size: 12px;
}
.style2 {font-family: Verdana, Arial, Helvetica, sans-serif}
.style5 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
}
.style13 {font-size: 12px}
.style14 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
.style16 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12; }
-->
 </style>
 <table width="850px" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="591" height="18" colspan="5"  align="center" ><span class="style1">INDIVIDUAL CUSTOMER REPORT LIST</span></td>
  </tr>
     <?php  
include("../../include/db.php"); 
error_reporting(0); 
$from_date	=	$_GET['fdate'];
$to_date	  =	$_GET['tdate'];
$cust_name	  =	$_GET['cust_name'];
$opening_balance	  =	$_GET['opening_balance'];

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

 if(($opening_balance<=0))
				 {
					 $get_dr='<span style="color:#336600;text-align:center;">Cr</span>';
				 }
				 if(($opening_balance>0))
				 {
					 $get_dr='<span style="color:#FF0000;text-align:center;">Dr</span>';
				 }
?> 
<tr>
<td width="640" height="24" align="left" class=" style2 style13"><strong>Customer Name :</strong><?php echo ucfirst($_GET['cust_name']);?></td>
<td colspan="3" align="right" class=" style2 style13"><strong>Op.Balance :</strong><b><?php echo number_format(abs($opening_balance),2);?>&nbsp;<?php echo $get_dr?></b></td>
</tr>

<tr>
    <td height="25" colspan="5" align="right">
    
    <table width="100%" height="74" border="0" align="center" cellpadding="0" cellspacing="0"  >
      <tr>
        <td width="13%" height="21" align="center" style="border-bottom:dashed 1px; border-top:dashed 1px;"><span class="style5">&nbsp;Date</span></td>
        <td width="45%" height="21" style="border-bottom:dashed 1px; border-top:dashed 1px;"><span class="style5">&nbsp;Transactions with Details</span></td>
        <td width="21%" align="right" style="border-bottom:dashed 1px; border-top:dashed 1px;"><span class="style5">Dr &nbsp;</span></td>
        <td width="21%" align="right" style="border-bottom:dashed 1px; border-top:dashed 1px;"><span class="style5">Cr &nbsp;</span></td>
        </tr>
     <?php 
	 
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($job_card_no,$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 job_card_no='$job_card_no' and 	billed_status='1'  union select *  from  fusing_production_main where p_id!='' and print_date>='$from_date' and print_date<='$to_date' and job_card_no='$job_card_no' and billed_status='1'";
	 }
	 else
	 {
		 $sql="select *  from  printer_production_main where job_type='sticker' and  print_date='$current_date' and job_card_no='$job_card_no' and 	billed_status='1'  union select *  from  fusing_production_main where p_id!='' and print_date='$current_date' and job_card_no='$job_card_no' 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($job_card_no,$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 job_card_no='$job_card_no' and 	billed_status='0'   union select *  from  fusing_production_main where p_id!='' and print_date>='$from_date' and print_date<='$to_date' and job_card_no='$job_card_no' and 	billed_status='0'";
	 }
	 else
	 {
		$sql="select *  from  printer_production_main where job_type='sticker' and print_date='$current_date' and job_card_no='$job_card_no' and 	billed_status='0'   union select *  from  fusing_production_main where p_id!='' and print_date='$current_date' and job_card_no='$job_card_no' 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;
} 

if(($from_date!='')&&($to_date!=''))
{
$supplier_sql ="select * from  printer_production_main where $get_query106 p_id!='' and job_type='sticker' and cust_name='$cust_name' and print_date>='$from_date' and print_date<='$to_date'  union select * from  fusing_production_main where $get_query106 p_id!='' and cust_name='$cust_name' and print_date>='$from_date' and print_date<='$to_date'";
}
else
{
$supplier_sql ="select  * from  printer_production_main where job_type='sticker' and cust_name='$cust_name' and print_date='$current_date'   union select  *  from  fusing_production_main where p_id!='' and cust_name='$cust_name' and print_date='$current_date'";
}
//echo $supplier_sql;
     $supplier_rs = mysql_query($supplier_sql);
     $supplier_rscount=mysql_num_rows($supplier_rs);
	  while($supplier_rsdata=mysql_fetch_object($supplier_rs))
	  {
		  $print_date  = $supplier_rsdata->print_date;
		  $job_card_no = $supplier_rsdata->job_card_no;
		  $debit       =get_debit_amt($job_card_no,$from_date,$to_date,$current_date);
		  $credit       =get_credit_amt($job_card_no,$from_date,$to_date,$current_date);

		 
?>
      <tr>
      <td height="24" align="center"><span class="style13" style="font-family: Verdana, Arial, Helvetica, sans-serif;"><?php echo date('d-m-Y',strtotime($print_date));?></span></td>
      <td><span class="style13" style="font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;</span> <span class="style14"><?php echo $job_card_no;?></span></td>
      <td align="right"><span class="style13" style="font-family: Verdana, Arial, Helvetica, sans-serif;"><?php echo number_format($debit,2);?> &nbsp;</span></td>
      <td align="right"><span class="style14"><?php echo number_format($credit,2);?> &nbsp;&nbsp;</span></td>
      </tr>
 <?php 
$debit1+=$debit;
$credit1+=$credit;
 }	          
 
 				if($opening_balance<=0)
				 {
					 $closing_balance=$opening_balance+($debit1-$credit1); 
				 }
				 if($opening_balance>0)
				 {
					$closing_balance=($credit1-$debit1)+$opening_balance;
				 }
				 if($closing_balance>0)
				 {
					 $get_cr='<span style="color:#FF0000;text-align:center;">Dr</span>';
				 }
				 if($closing_balance<=0)
				 {
					$get_cr='<span style="color:#336600;text-align:center;">Cr</span>';
				 }
?><?php if($supplier_rscount!='') { ?>
      <tr>
        <td align="right" ></td>
        <td align="right" ><span class="style5 style2 style13">Total : </span></td>
        <td align="right" style="border-bottom:dashed 1px; border-top:dashed 1px;"><span class="style2 style13"><?php echo number_format(abs($debit1),2); ?>&nbsp;&nbsp;</span></td>
        <td align="right" style="border-bottom:dashed 1px; border-top:dashed 1px;"><span class="style2 style13"><?php echo number_format(abs($credit1),2); ?>&nbsp;&nbsp;</span><span class="style14">&nbsp;</span></td>
      </tr><?php } else {?> <tr>
        <td align="right" ></td>
        <td align="right" ><span class="style5 style2 style13"> <?php  echo "No Transaction Details"; ?></span></td>
        <td align="right" style="border-bottom:dashed 1px; border-top:dashed 1px;"><span class="style2 style13">&nbsp;&nbsp;</span></td>
        <td align="right" style="border-bottom:dashed 1px; border-top:dashed 1px;"><span class="style2 style13">&nbsp;&nbsp;</span><span class="style14">&nbsp;</span></td>
      </tr><?php }?>
      <tr>
      <td align="right" ></td>
      <td align="right" ><span class="style5">Closing Balance :</span></td>
         <td align="right" style="border-bottom:dashed 1px;"><span class="style14">
          <?php
		  if($closing_balance>0)
		  { 
		  echo number_format(abs($closing_balance),2);?>           
          &nbsp;<?php echo $get_cr;
		  }?> &nbsp; </span></td>
               <td align="right"  style="border-bottom:dashed 1px;">
                 <span class="style16">
          <?php 
		   if($closing_balance<=0)
		  {  
		  echo number_format(abs($closing_balance),2);?>
          &nbsp;<?php echo $get_cr;
		  }?> &nbsp;</span></td>
      </tr>
    </table>
    </td></tr></table>