<style type="text/css">
.header{
	font-family: Cambria, "Hoefler Text", "Liberation Serif", Times, "Times New Roman", serif;
	font-size: 55px;
	color: #06F;
}
.headersub{line-height:25px;color:#333333;}
.padleft{padding-left:15px;}
.title00{
	color: #000033;
	font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
	font-size: 17px;
}
.style34{font-size: 15px; font-style: normal; font-weight: bold;}
.title0{color:#000033;font-family:Calibri;font-size:16px;}
.title1{color: #000033;font-family:Calibri;font-size: 17px;}
.title20{font-style:normal;color:#000033;padding-left:5px}
.title2a{
	font-style: normal;
	color: #000033;
	padding-left: 5px;
	font-size: 17px;
}

.title2{font-style:normal;color:#000033;font-weight:bold;padding-left:5px}
.title3{text-align:top;font-size:1px;font-family:Verdana, Arial, Helvetica, sans-serif;}
.title4{font-style:normal;color:#000033;padding-left:15px;font-size:15px;font-family:Verdana, Arial, Helvetica, sans-serif;}
.title5{font-style:normal;color:#000033;font-weight:bold;padding-right:15px;font-size:15px;text-align:center;font-family:Verdana, Arial, Helvetica, sans-serif;}
.title6{font-style:normal;color:#000033;padding-left:15px;font-size:15px;line-height:18px;font-family:Verdana, Arial, Helvetica, sans-serif;}
.title7{font-style:normal;color:#000033;padding-left:15px;font-size:15px;font-family:Verdana, Arial, Helvetica, sans-serif;font-weight:bold;}
.style1{ border-top:solid 1px; border-color:#000000; }
.style2 {border-left:solid 1px;  border-color:#000000;}
.style3 {border-bottom:solid 1px;  border-color:#000000;}
.style31 {border-bottom:solid 1px #999999 ;}
.style32 {border-right:solid 1px #999999 ;}
.style33 {border-left:solid 1px #999999 ;}
.style4 {border-right:solid 1px;  border-color:#000000;}
.stylelg {border-left:solid 1px;  border-color:#D3D3D3;}
.styleg {border-left:solid 1px;  border-color:#808080;}

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

function convert_number($number) 
{ 
    if (($number < 0) || ($number >99999999)) 
    { 
    throw new Exception("Number is out of range");
    } 
    $Gn = floor($number / 10000000);  /* Crores (giga) */ 
    $number -= $Gn * 1000000; 
	$ln = floor($number / 100000);   /* laksh (giga1) */ 
    $number -= $ln * 100000; 
    $kn = floor($number / 1000);     /* Thousands (kilo) */ 
    $number -= $kn * 1000; 
    $Hn = floor($number / 100);      /* Hundreds (hecto) */ 
    $number -= $Hn * 100; 
    $Dn = floor($number / 10);       /* Tens (deca) */ 
    $n = $number % 10;               /* Ones */ 

    $res = ""; 

    if ($Gn) 
    { 
        $res .= convert_number($Gn) . " Crores"; 
    } 
  if ($ln) 
    { 
        $res .= (empty($res) ? "" : " ") . 
            convert_number($ln) . " Lakhs"; 
    } 
    if ($kn) 
    { 
        $res .= (empty($res) ? "" : " ") . 
            convert_number($kn) . " Thousand"; 
    } 

    if ($Hn) 
    { 
        $res .= (empty($res) ? "" : " ") . 
            convert_number($Hn) . " Hundred"; 
    } 

    $ones = array("", "One", "Two", "Three", "Four", "Five", "Six", 
        "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", 
        "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", 
        "Nineteen"); 
    $tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", 
        "Seventy", "Eighty", "Ninety"); 

    if ($Dn || $n) 
    { 
        if (!empty($res)) 
        { 
            $res .= " and "; 
        } 

        if ($Dn < 2) 
        { 
            $res .= $ones[$Dn * 10 + $n]; 
        } 
        else 
        { 
            $res .= $tens[$Dn]; 

            if ($n) 
            { 
                $res .= " " . $ones[$n]; 
            } 
        } 
    } 


    if (empty($res)) 
    { 
        $res = "zero"; 
    } 

    return $res; 
	
} 


 
 
 
 function get_estimate_type11($jobcard_no1)
  {
	  $sql_user="select billing_type as billing_type,remarks as remarks,description as description from fusing_production_main where job_card_no='$jobcard_no1' and billing_type!=''  union select billing_type as billing_type,remarks as remarks,description as description from printer_production_main where job_card_no='$jobcard_no1' and billing_type!=''";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$billing_type=$rsdata_user->billing_type;
	$remarks=$rsdata_user->remarks;
	$description=$rsdata_user->description;
	}
	return array($billing_type,$remarks,$description);
 } 
 
 
 function get_invoice_no($jobcard_no1)
  {
	$sql_user="select invoice_no as invoice_no from fusing_production_main where job_card_no='$jobcard_no1' and invoice_no!='' union select invoice_no as invoice_no from printer_production_main where job_card_no='$jobcard_no1' and invoice_no!=''";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$invoice_no=$rsdata_user->invoice_no;
	}
	return $invoice_no;
 } 
  
 function get_created_dates($jobcard_no1)
  {
	$sql_user="select bill_date as bill_date from fusing_production_main where job_card_no='$jobcard_no1' and invoice_no!='' union select bill_date as bill_date from printer_production_main where job_card_no='$jobcard_no1' and invoice_no!=''";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$bill_date=$rsdata_user->bill_date;
	}
	return $bill_date;
 } 
 
    $job_card_no=$_GET['job_card_no'];
	$invoice_no=$_GET['invoice_no'];	
    $sql="select * from jobcard_main where jobcard_no='$job_card_no' ";
	$rs=mysql_query($sql);
	$sno=0;
	$from=0;
   		while($rsdata=mysql_fetch_array($rs))		
		{
   				$sno=$sno+1;
				$from=$from+1;
           	    $jobcard_no1=$rsdata['jobcard_no'];
			    $createdate=$rsdata['createdate'];
			    $print_date=$rsdata['print_date'];
	   		    $job_created=$rsdata['job_created'];
			    $cust_name=$rsdata['cust_name'];
	   		    $cust_po=$rsdata['cust_po'];
	   			$style_no=$rsdata['style_no'];
	   			$style_name=$rsdata['style_name'];
				$combo=$rsdata['combo'];
	   			$printed_qty=$rsdata['printed_qty'];
				$billed_status=$rsdata['billed_status'];
		    	$job_type=$rsdata['job_type'];
				$amount=$rsdata['amount'];
				$cust_po_no=$rsdata['cust_po_no'];
				$qty =$rsdata['qty'];
				$jobcard_values=$rsdata['jobcard_values'];
			    list($estimate_type,$remark,$desc) = get_estimate_type11($jobcard_no1);
				$invoice_no = get_invoice_no($jobcard_no1);
				$dates=get_created_dates($jobcard_no1);
				}
  
     $sql="select * from party_creation where party_name='$cust_name' and delete_status!='1'  and `party_type`='Customer'  order by party_name ASC ";
	 $rs1=mysql_query($sql);
   		while($rsdata=mysql_fetch_array($rs1))		
		{
           	    $party_no=$rsdata['party_no'];
			    $party_name1=$rsdata['party_name'];
			    $mobile_no=$rsdata['mobile_no'];
	   		    $phone_no=$rsdata['phone_no'];
			    $address=$rsdata['address'];
	   		    $city=$rsdata['city'];
	   			$cst_no=$rsdata['cst_no'];
	   			$tin_no=$rsdata['tin_no'];
}
?><table width="850" align="center" border="0" cellspacing="0" cellpadding="0" class="style1 style2  style4">
  <tr>
    <td colspan="3"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="23" colspan="3"><span class="title1"><b>&nbsp;&nbsp;To,</b></span></td>
        <td width="38%" align="right" valign="bottom" class="style2">&nbsp;</td>
      </tr>
      <tr>
        <td height="23" colspan="3" valign="top" ><span class="title1"><b>&nbsp;&nbsp;M/s :</b>&nbsp;<span style="color:#06F; font-weight:bold;"><?php  echo $party_name1; ?></span>
        </span></td>
        <td  align="left" valign="bottom" class="title0 style2"><b> &nbsp;Re Production Mistake No</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp; &nbsp;<?php echo $invoice_no; ?></td>
      </tr>
      <tr>
        <td height="22" colspan="3" valign="top" class="padleft"><span class="title1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <?php  echo $address; ?>
        </span></td>
        <td  align="left" valign="bottom" class="title0 style2"><b>&nbsp;Re Production Mistake Date</b>&nbsp;&nbsp;:&nbsp;          <?php  echo date("d-m-Y",strtotime($dates)); ?></td>
        </tr>
      <tr>
        <td height="22" colspan="2" valign="top" class="padleft" ><span class=" title1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <?php  echo $city; ?>
        </span></td>
        <td width="45%" height="22" align="left" valign="top" class=" title1"></td>
        <td  align="left" valign="bottom" class="title0 style2"><b>&nbsp;Jobcard No</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;:&nbsp;<?php 

	$sql_user="select * from fusing_jobcard_sub where invoice_no='$invoice_no' and billing_type='$_GET[billing_type]' and acc_year='$_GET[acc_year]'";
	$rs_user=mysql_query($sql_user);
	$rscount_fuse=mysql_num_rows($rs_user);
	if($rscount_fuse!=0)
	{
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
  echo $jobcard_no=$rsdata_user->jobcard_no.",";
	}
	}
	else
	{
		echo $_GET['job_card_no'];
	}
 ?></td>
        </tr>
    
    </table></td>
  </tr>
  <tr height="" class="style32">
    <td height="" colspan="5" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
      	<td height="35" align="left" bgcolor="#CCCCCC" class="style1 style3 style32  title0" style="text-align: center"><b>&nbsp;Joncard No</b></td>
        <td height="35" align="left" bgcolor="#CCCCCC" class="style1 style3  title0" style="text-align: center"><b>&nbsp;DESCRIPTION OF PRINT</b></td>
        <td align="right" bgcolor="#CCCCCC" class="style1 style3 style2 title0 style4" style="text-align: center"><span style="font-family: Calibri; text-align: center;"><b>QTY</b></span><b>&nbsp;</b></td>
        <td align="right" bgcolor="#CCCCCC" class="style1 style3  title0 style4" style="text-align: center"><b><span style="text-align: center"></span>RATE&nbsp;</b></td>
        <td align="right" bgcolor="#CCCCCC" class="style1 style3  title0" style="text-align: center"><b>AMOUNT&nbsp;</b></td>
      </tr>
      <?php $job_card_no=$_GET['job_card_no'];
	  
	  function get_dc_no($jobcard_no)
  {
	$sql_user="select * from delivery_challan_main where job_no='$jobcard_no' ";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$delivery_no=$rsdata_user->delivery_no;
	}
	return $delivery_no;
 } 
 
 
       function get_freight_charges($jobcard_no)
  {
   $sql="select frieght_charges as frieght from printer_production_main where job_card_no='$jobcard_no' union select frieght_charges as frieght from fusing_production_main where job_card_no='$jobcard_no'";
 $rs1=mysql_query($sql);
 while($rsdata=mysql_fetch_array($rs1))		
		{
		$frieght_charges=$rsdata['frieght'];
		}
 return $frieght_charges;
 } 
 $frieght_charges=get_freight_charges($job_card_no);
 
 
 
 $sql_fusing_sub="select * from fusing_jobcard_sub where invoice_no='$invoice_no' and billing_type='$_GET[billing_type]' and acc_year='$_GET[acc_year]' ";
  $rs_fusing_sub=mysql_query($sql_fusing_sub);
   $count_fusing=mysql_num_rows($rs_fusing_sub);
 if($count_fusing!=0)
 {
  while($rsdata_fusing_sub=mysql_fetch_array($rs_fusing_sub))
  {
	   $jobcard_no=$rsdata_fusing_sub['jobcard_no'];
   $sql="select * from jobcard_sublist where jobcard_no='$jobcard_no'";
   $sno=0;
	  $rs=mysql_query($sql);
	  $rscount=mysql_num_rows($rs);
	  $count_sub+=$rscount;
   		while($rsdata=mysql_fetch_array($rs))		
		{
	    $sno=$sno+1;
		$conformed_amt=$rsdata['conformed_amt'];
		$jobcard_no=$rsdata['jobcard_no'];
	    $qty =$rsdata['qty'];
		$dc_nos=get_dc_no($jobcard_no);
		$jobcard_values=$rsdata['jobcard_values'];
		$particulars=$rsdata['particulars'];
?>
        <tr height="10px">
        <td class="style31 style32 title0" width="74" align="left"><?php echo $jobcard_no; ?>&nbsp;</td>
        <td class="style31  title0" width="7000" align="left">&nbsp;<?php echo $particulars; ?> <?php echo "- Sublimation Printing Charges"; ?></td>
        <td class="style31 style32 title0 style33" width="500" align="right"><span><?php echo $qty; ?>&nbsp;</span></td>
        <td class="style31 style32 title0" width="64" align="right"><span ><?php echo number_format($conformed_amt,2); ?>&nbsp;</span></td>
        <td class="style31 title0" width="74" align="right"><?php echo number_format($jobcard_values,2); ?>&nbsp;</td>
      </tr>
      <?php 
	  $total+=$jobcard_values;
	  $qtys+=$qty;
	  

	  } }
}
else {
	 $sql="select * from jobcard_sublist where jobcard_no='$_GET[job_card_no]'";
   $sno=0;
	  $rs=mysql_query($sql);
	  $rscount=mysql_num_rows($rs);
	  $count_sub+=$rscount;
   		while($rsdata=mysql_fetch_array($rs))		
		{
	    $sno=$sno+1;
		$conformed_amt=$rsdata['conformed_amt'];
		$jobcard_no=$rsdata['jobcard_no'];
	    $qty =$rsdata['qty'];
		$dc_nos=get_dc_no($jobcard_no);
		$jobcard_values=$rsdata['jobcard_values'];
		$particulars=$rsdata['particulars'];
?>
        <tr height="10px">
        	<td class="style31 style32 title0" width="74" align="left"><?php echo $jobcard_no; ?>&nbsp;</td>
        <td class="style31  title0" width="7000" align="left">&nbsp;<?php echo $particulars; ?> <?php echo "- Sublimation Printing Charges"; ?></td>
        <td class="style31 style32 title0 style33" width="500" align="right"><span><?php echo $qty; ?>&nbsp;</span></td>
        <td class="style31 style32 title0" width="64" align="right"><span ><?php echo number_format($conformed_amt,2); ?>&nbsp;</span></td>
        <td class="style31 title0" width="74" align="right"><?php echo number_format($jobcard_values,2); ?>&nbsp;</td>
      </tr>
      <?php 
	  $total+=$jobcard_values;
	  $qtys+=$qty;
	  }
}
  if($count_sub=='30')
			{
				$height='140px';
			}
	   if($count_sub=='29')
			{
				$height='160px';
			}
	   if($count_sub=='28')
			{
				$height='180px';
			}
	    if($count_sub=='27')
			{
				$height='200px';
			}
			  if($count_sub=='26')
			{
				$height='220px';
			}
	   if($count_sub=='25')
			{
				$height='200px';
			}
	   if($count_sub=='24')
			{
				$height='220px';
			}
	  if($count_sub=='23')
			{
				$height='240px';
			}
	  
	  if($count_sub=='22')
			{
				$height='260px';
			}
	   if($count_sub=='21')
			{
				$height='280px';
			}
	   if($count_sub=='20')
			{
				$height='300px';
			}
	  if($count_sub=='19')
			{
				$height='320px';
			}
			if($count_sub=='18')
			{
				$height='340px';
			}
			if($count_sub=='17')
			{
				$height='360px';
			}
	  
	   if($count_sub=='16')
			{
				$height='380px';
			}
				if($count_sub=='15')
			{
				$height='400px';
			} if($count_sub=='14')
			{
				$height='420px';
			}
				if($count_sub=='13')
			{
				$height='440px';
			}
	   if($count_sub=='12')
			{
				$height='460px';
			}
				if($count_sub=='11')
			{
				$height='480px';
			}
	  	    if($count_sub=='10')
			{
				$height='500px';
			}
				if($count_sub=='9')
			{
				$height='520px';
			}
			if($count_sub=='8')
			{
				$height='560px';
			}
			if($count_sub=='7')
			{
			$height='580px';
			}	
			if($count_sub=='6')
			{
				$height='600px';
			}	
			if($count_sub=='5')
			{
				$height='620px';
			}	
			if($count_sub=='4')
			{
				$height='640px';
			}	
			if($count_sub=='3')
			{
			$height='660px';
			}	
			if($count_sub=='2')
			{
			$height='680px';
			}	
			if($count_sub=='1')
			{
			$height='700px';
			}
		   ?>
             <?php if($frieght_charges!='')
			  {
		      ?>

              <tr height="10px">
              <td class="style31   title0 style32" width="625" align="left">&nbsp;Freight Charges</td>
              <td class="style31  title0 style32" width="64" align="right"><span>&nbsp;</span></td>
              <td class="style31  title0 style32" width="64" align="right"><span style="color:black;">&nbsp;</span></td>
              <td class="style31  title0 " width="74" align="right" style="color:black"><?php echo number_format($frieght_charges,2); ?>&nbsp;</td>
              </tr> 
		<?php } ?>
              <tr height="<?php echo $height; ?>">
              <td class="title0 style32" width="625" align="left">&nbsp;</td>

              <td class="title0 style32" width="100" align="right"><span>&nbsp;</span></td>
              <td class="title0 style32" width="64" align="right"><span style="color:black;">&nbsp;</span></td>
              <td class="title0 style32" width="64" align="right"><span style="color:black;">&nbsp;</span></td>
              <td class="title0 " width="74" align="right" style="color:black">&nbsp;</td>
        </tr>   
      <tr>
      	
        <td width="625" align="left" valign="bottom" class=" title2a title0">&nbsp;&nbsp;<?php echo $remark; ?><br/>
          &nbsp;&nbsp;<?php echo $desc; ?><br/>
          STYLE No&nbsp;&nbsp;:&nbsp;&nbsp;<?php echo $style_no; ?><br/>
          COMBO&nbsp;&nbsp;:</b>&nbsp;&nbsp;<?php echo $combo; ?><br/>
          DESIGN NAME&nbsp;&nbsp;:&nbsp;&nbsp;<?php echo $style_name; ?> <br/>
          PARTY DC No&nbsp;&nbsp;:&nbsp;&nbsp;<?php 
		  
		  function get_inward_dc_no($jobcard_nos)
  {

    $sql_user1="select customer_dc_no from inward_sub_list where jobcard_no='$jobcard_nos' ";
 	$rs_user11=mysql_query($sql_user1);
	while($rsdata_user11=mysql_fetch_object($rs_user11))
	{ 
	 $customer_dc_no=$rsdata_user11->customer_dc_no.",";
	}
return $customer_dc_no;
} 
			
	$sql_user="select * from fusing_jobcard_sub where invoice_no='$invoice_no' and billing_type='$_GET[billing_type]' ";
	$rs_user=mysql_query($sql_user);
	$rscount_fuse=mysql_num_rows($rs_user);
	if($rscount_fuse!=0)
	{
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
    $jobcard_nos=$rsdata_user->jobcard_no;
echo	$inward_dc_no = get_inward_dc_no($jobcard_nos);
	}
	
	}
	else
	{
	$jobcard_no=$_GET['job_card_no'];
echo $inward_dc_no = get_inward_dc_no($jobcard_no);		
	} ?> <br/>
          </span></td>
        <td width="64" align="left" valign="bottom" class="style32 title2 title0 style33">&nbsp;</td>
         <td width="100" align="left" valign="bottom" class="style32 title2 title0">&nbsp;</td> 
         <td width="100" align="left" valign="bottom" class="style32 title2 title0">&nbsp;</td> 
        <td width="74" align="left" valign="bottom" class="title2 title0">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="4" class="style2 style3"></td>
        <td width="1" class=" "></td>
      </tr>
      <tr height="40px">
      	<td align="right" class="style3 style4 title4" style=" font-size: 14px; font-weight: bold;">&nbsp;&nbsp;</td>
        <td height="43"  class="title0 style3 " style="color:black;font-size:16px;"> &nbsp;&nbsp;&nbsp;<?php echo convert_number(($total+$frieght_charges));?>&nbsp; <span>Rupees Only</span></td>
        <td align="right" class="style3 style4 title4" style=" font-size: 14px; font-weight: bold;"><?php echo $qtys; ?>&nbsp;&nbsp;</td>
        <td align="center" class="style3 style4"><span class="title0" style="text-align:right"><b>TOTAL</b></span></td>
        <td align="right" class="style3 style1"><span class="title4" style="padding-left: 40px; font-size: 14px; font-weight: bold;"><?php $a=round($total+$frieght_charges);
		echo number_format($a,2); ?></span>&nbsp;&nbsp;</td>
        </tr>
<!-- </table></td></tr>
-->      
    </table></td>
  </tr>
  <tr>
    <td width="299" height="116" class="style3" valign="bottom"><span class="title0" style="text-align:inherit"><b>&nbsp;Received by</b></span></td>
    <td width="265" colspan="0"  class=" style3 style2" valign="bottom" align="center"><span class="title0"><b>Prepared by</b></span></td>
    <td width="284" colspan="0" align="center" class="style2 style3 title0" style="padding-top:30px" ><p style="font-size: 14px;"></p>
     <p><br/><br/><br/>
    <span class="title0" style="line-height:25px;text-align:cenetr;" >Authorized Signatory</span></p></td>
  </tr>
</table>