<link rel="stylesheet" href="css/font.css" type="text/css" />
<script>
function jobcard_report_print(url)
{
onmouseover43= window.open(url,'onmouseover43','height=580,width=1100,scrollbars=yes,left=50,top=50,toolbar=no,location=no,directories=no,status=no,menubar=no');
}
</script>
<?php error_reporting(0);
/*********************************Get Found Result And Pagination********************************************************/
include("../../include/db.php");
function get_customer($customer_name)
{
        $sql="select * from  customer_entry where  customer_name='$customer_name' ";
        $rs=mysql_query($sql);
	    $s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
                 $id=$rsdata['id'];
	        }
return $id;
}
$show = 10;
$num_links = 9;
$from = $_GET['from'];
if (empty($from))
	 {
		$from = "0";
	 } 
else 
	{
	    $html_query = $html_query. "&from=$from";
	}
$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($customer_name!=""){ $customer_name1 = "cust_name='$customer_name'";}else{$customer_name1="";}
{
$all_value10 = $from_date1.",".$to_date1.",".$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!=''";
}
$html_query = "main_fram.php?file=sales_report";
$result=mysql_query($sql);
$num_results=mysql_num_rows($result);
if ($num_results == 0) 
{
 $confirmation = "No Records!";
} 
elseif ($num_results == 1) 
{
$confirmation = "Found 1 Record.";
} 
else 
{
$confirmation = "Found $num_results Records.";
} 
$job_card_no=$_GET['job_card_no'];
$customer_name=$_GET['customer_name'];
$from_date=$_GET['from_date'];
$to_date=$_GET['to_date'];
?>
<style type="text/css">
<!--
.style1 {font-size: 16px}
-->
</style>
<table width="100%">
<tr>
<td width="1%" height="38">&nbsp;</td>
<td width="7%" class="style15">&nbsp;</td> 
<td width="13%" align="center">&nbsp;</td>
<td width="1%">&nbsp;</td>
<td width="6%" class="style15">&nbsp;</td>
<td width="14%" align="center"  class="style15">&nbsp;</td>
<td width="2%">&nbsp;</td>
<td width="11%" class="style15">&nbsp;</td>
<td width="24%" align="left" >&nbsp;</td>
<td width="8%" align="center">&nbsp;</td>
<td width="2%"></td>
<td width="7%" align="center"><a href="javascript:jobcard_report_print('report/customer_wise_report/customer_wise_print.php?from_date=<?php echo $_GET['from_date'];?>&to_date=<?php echo $_GET['to_date'];?>&customer_name=<?php echo $_GET['customer_name'];?>');" style="text-decoration:none;"><img src="img/PrinterBlack.png" width="35" height="30" title="Print" value="Print"/></a></td>
  </tr>
</table>
<div class="container">
<div class="row-fluid">
<div class="span12">
<div class="table-responsive">
<div class="CSSTableGenerator">  
<table border="0" width="97%"  align="center" cellpadding="0" cellspacing="0" style="border:1px solid #ddd" >
<thead>
<tr>
    <th  height="23"  align="center" style="border:1px solid #ddd" >S.No</th>
    <th  align="left" style="border:1px solid #ddd" >Customer Name</th>
    <th  align="right" style="border:1px solid #ddd" >opening Balance</th>
    <th  align="right" style="border:1px solid #ddd" >Debit Amount</th>
    <th  align="right" style="border:1px solid #ddd" >Credit Amount</th>
        <th  align="right" style="border:1px solid #ddd" >Closing Balance</th>

    </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($customer_name!=""){ $customer_name1 = "cust_name='$customer_name'";}else{$customer_name1="";}
$all_value102 = $from_date1.",".$to_date1.",".$customer_name1;
$all_array102 = explode(',',$all_value102);
foreach($all_array102 as $value102)
{ 
if($value102!='')
{
  $get_query103.= $value102." AND ";
}
}	 
if($from_date!='')
{
 $sql="select distinct cust_name from  printer_production_main where $get_query103 p_id!='' and job_type='sticker' union select distinct cust_name from  fusing_production_main where $get_query103 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="67"  align="center" style="border:1px solid #ddd">&nbsp;<?php echo $from; ?></td>
    <td width="254" align="left" style="border:1px solid #ddd" >&nbsp;<a href="#" onClick="javascript:jobcard_report_print('report/customer_wise_report/individual_customer_details.php?cust_name=<?php echo $cust_name;?>&fdate=<?php echo $from_date;?>&tdate=<?php echo $to_date;?>&opening_balance=<?php echo $opening_amt;?>')"><?php echo $cust_name;?></a></td>
    <td width="272" align="right" style="border:1px solid #ddd" >&nbsp;<?php echo number_format($opening_amt1,2).$get_dr;?>&nbsp;</td>
    <td width="189" align="right" style="border:1px solid #ddd" >&nbsp;<?php echo number_format($debit,2);?>&nbsp;</td>
    <td width="231" align="right" style="border:1px solid #ddd" ><?php echo number_format($credit,2);?>&nbsp;</td>
    <td width="203" align="right" style="border:1px solid #ddd" ><?php echo number_format($closing_bal1,2).$get_cr;?>&nbsp;</td>
    </tr>
  <?php } ?>
  </thead>
</table>
</div>
</div>
</div>
</div>

