<link rel="stylesheet" href="css/new_mxerp.css">
<?php ob_start();
$PageSecurity = 2;
include('includes/SQL_CommonFunctions.inc');
include('includes/DefinePOClass.php');
$title = _('Job Work Bill Book List');
$PageName ='Job Work Bill Book List';
if($_REQUEST['id']!='' && $_REQUEST['act']=='delete')
{
	$delete1=DB_query("Delete from job_billbook where id='".$_REQUEST['id']."'",$db);
	$delete2=DB_query("Delete from job_billbook_details where masterId='".$_REQUEST['id']."'",$db);
	prnMsg( _('Record Deleted Successfully'),'success');
echo "<script>location.href='index.php?route=JobWorkBillBookList&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_REQUEST['id']!='' && $_REQUEST['act']=='View')
{
 $jobwork_sql="select * from job_billbook where id='".$_REQUEST['id']."' and CompanyId='".$_SESSION['ACGCompanyId']."'";
 $jobwork_res=DB_query($jobwork_sql,$db);
 $jobwork_row=DB_fetch_array($jobwork_res);
	?>
<div class="body_contain">
<div class="tab_div">

	
	<h1>View Job Work Bill Book</h1>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata1">Branch</td>
    <td style="width:250px;"><?php echo $jobwork_row['site'] ?></td>
    <td rowspan="4" colspan="2" >
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
	<tr>
	<td class="tabledata1">Party Challan No. </td>
	<td>
	<div style="overflow:auto; height:100px; width:auto; border: ridge;" >
	
	<input type="checkbox" name="partyChallanNo[<?php echo $i;?>]" id="partyChallanNo_<?php echo $i;?>" value="<?php echo $myrow['id']?>" <?php echo $c;?>/><?php echo $myrow['partyChallanNo'];?>&nbsp;&nbsp;<?php echo $jobwork_row['partyChallanNo'] ?>
	</div>
	</td>
	</tr>
	</table>
	</td>
  </tr>
  <tr><td class="tabledata1">Godown</td>
    <td><?php echo $jobwork_row['store'] ?></td></tr>
  <tr>
    <td class="tabledata1">Vendor</td>
    <td><?php echo $jobwork_row['vendor'] ?></td>
  </tr>
  <tr>
    <td class="tabledata1">Bill Book No. </td>
    <td><input name="billPrefix" type="text" id="billPrefix" value="<?php echo $_REQUEST['billPrefix'];?>" size="6" > 
    - 
	  <input name="billDigit" type="text" id="billDigit" value="<?php echo $_REQUEST['billDigit'];?>" size="5" ></td></tr>
  <tr>
    <td class="tabledata1">Date</td><td><?php  echo $jobwork_row['billDate'];  ?></td>
   </tr>
</table>




<?php 
if(isset($_REQUEST['partyChallanNo']) && $_REQUEST['Proceed']!='')
{$challanIds=implode(",",$_REQUEST['partyChallanNo']); }?>
<input type="hidden" name="partyChallanNo" value="<?php echo $challanIds;?>">
<?php if($_REQUEST['Proceed']!=''){$height="250px";}else{$height="150px";}; ?>
<div style="overflow:auto; width:810px; height:auto<?php //echo $height;?>;"> 
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
<tr>
<td class="tabledata">Item Code </td>
<td class="tabledata">Item Name </td>
<td class="tabledata">Make</td>
<td class="tabledata">Color</td>
<td class="tabledata">Grade</td>
<td class="tabledata">Size</td>
<td class="tabledata">Gsm</td>
<td class="tabledata">Uom</td>
<td class="tabledata">Received Quantity</td>
<td class="tabledata">Rate</td>
<td class="tabledata">Total Amount </td>
<td class="tabledata">Item Description </td>
<td class="tabledata">Item No. </td>
<td class="tabledata">Flexo/Offset</td>
<td class="tabledata">Serial No. </td>
<td class="tabledata">Original/Local</td>
<td class="tabledata">Type </td>
<td class="tabledata">Shade</td>
<td class="tabledata">Running Meter/Roll </td>
<td class="tabledata">Volume</td>
<td class="tabledata">Teeth</td>
<td class="tabledata">Bcm</td>
<td class="tabledata">Ups</td>
<td class="tabledata">Quality</td>
</tr>
<?php 
if($_REQUEST['Proceed']!='')
{
	$getJobItems="select itemCode from job_return_details where masterId in(".$challanIds.") group by itemCode";
	$getJobResult=DB_query($getJobItems,$db);
	$j=0;
	while($details_row2=DB_fetch_array($getJobResult))
	{
		//echo "select sum(receivedQty),rate from job_return_details where itemCode='".$details_row2['itemCode']."' and masterId in(".$challanIds.") ";
		
		$getReceivedQty=DB_query("select sum(receivedQty),rate from job_return_details where itemCode='".$details_row2['itemCode']."' and masterId in(".$challanIds.") ",$db);
		$receiveResult=DB_fetch_array($getReceivedQty);
		$_REQUEST['receivedQty'][$j]=$receiveResult['sum(receivedQty)'];
		$_REQUEST['rate'][$j]=$receiveResult['rate'];
		
		$item_sql="Select * from item_master where StockID ='".$details_row2['itemCode']."'";
		$item_result=DB_query($item_sql,$db);
		$item_row=DB_fetch_array($item_result);
?>
<tr bgcolor="#c1c1c1">
<td><?php echo $details_row2['itemCode'];?><input type="hidden" name="itemCode[<?php echo $j;?>]" value="<?php echo $details_row2['itemCode'];?>"></td>
<td><?php echo $item_row['item_name'];?></td>
<td><?php 
$makename=$s->getField('product_manufacture','id',$details_row2['make'],'manufacturer');
echo $makename;?><input type="hidden" name="make[<?php echo $j;?>]" id="make_<?php echo $j;?>" value="<?php echo $details_row2['make'];?>" /></td>
<td><?php 
$colorname=$s->getField('product_color','id',$details_row2['color'],'color');
echo $colorname;?><input type="hidden" name="color[<?php echo $j;?>]" id="color_<?php echo $j;?>" value="<?php echo $details_row2['color'];?>" /></td>
<td><?php 
$gradername=$s->getField('product_grade','id',$details_row2['grade'],'grade');
echo $gradername;?><input type="hidden" name="grade[<?php echo $j;?>]" id="grade_<?php echo $j;?>" value="<?php echo $details_row2['grade'];?>" /></td>
<td><?php 
$sizename=$s->getField('size_master','id',$details_row2['size'],'name');
echo $sizename;?><input type="hidden" name="size[<?php echo $j;?>]" id="size_<?php echo $j;?>" value="<?php echo $details_row2['size'];?>" /></td>
<td><?php 
$gsmname=$s->getField('gsm','id',$details_row2['gsm'],'gsm');
echo $gsmname;?><input type="hidden" name="gsm[<?php echo $j;?>]" id="gsm_<?php echo $j;?>" value="<?php echo $details_row2['gsm'];?>" /></td>
<td><?php 
$unitname=$s->getField('unitsofmeasure','unitid',$item_row['unit'],'unitname');
echo $unitname;?></td>
<td><input type="text" name="receivedQty[<?php echo $j;?>]" id="receivedQty_<?php echo $j;?>" value="<?php echo $_REQUEST['receivedQty'][$j];?>" size="15" ></td>
<td><input type="text" name="rate[<?php echo $j;?>]" id="rate_<?php echo $j;?>" value="<?php echo $_REQUEST['rate'][$j];?>" size="15" readonly="true"></td>
<td><input type="text" name="totalAmount[<?php echo $j;?>]" id="totalAmount_<?php echo $j;?>" value="<?php echo $_REQUEST['totalAmount'][$j];?>" size="15" onfocus="calculateTotalAmt(<?php echo $j;?>)" readonly="true"></td>
<td><?php echo $item_row['item_desc'];?></td>
<td><?php echo $item_row['item_no'];?></td>   
<td><?php echo $item_row['flexo_offset'];?></td>
<td><?php echo $item_row['serial_no'];?></td>
<td><?php echo $item_row['orig_local'];?></td>
<td><?php echo $item_row['type_name'];?></td>
<td><?php echo $item_row['shade'];?></td>
<td><?php echo $item_row['running_roll'];?></td>
<td><?php echo $item_row['volume'];?></td>
<td><?php echo $item_row['teeth'];?></td>
<td><?php echo $item_row['bcm'];?></td>
<td><?php echo $item_row['ups'];?></td>
<td><?php echo $item_row['quality'];?></td>
</tr>
<?php $j++;}}

?>
<input type="hidden" name="countItems" id="countItems" value="<?php echo $j;?>" />
</table>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="50%" valign="top"><table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
      <tr>
        <td class="tabledata" scope="row">Remarks</td>
        <td><textarea name="remarks" style="width:100%" ></textarea></td>
      </tr>
      <tr>
        <td class="tabledata" scope="row">Ledger</td>
        <td>
		<select name="ledger" id="ledger" style="width:100%">
		<?php 
		$ledger_sql=DB_query("Select AccountsID,AccountName from accountledger",$db);
		while($ledger_row=DB_fetch_array($ledger_sql))
		{
		?>
		<option value="<?php echo $ledger_row['AccountsID']; ?>"><?php echo $ledger_row['AccountName']; ?></option>
		<?php } ?>
		</select>
		</td>
      </tr>
    </table></td>
    <td width="27%" valign="top">
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata">Basic Amount </td>
    <td><input type="text" name="basicAmount" id="basicAmount" value="<?php echo $_REQUEST['basicAmount'];?>" onfocus="calculateBasic()" /></td>
  </tr>
  <tr>
    <td class="tabledata">BILL TYPE </td>
    <td><input type="radio" name="billType" value="Service" id="billType" onclick="returnType(this.value)" />
    Service 
    <input type="radio" name="billType" value="JW" id="billType" onclick="returnType(this.value)"/>
     Job Work </td>
  </tr>
  <tr>
    <td class="tabledata">SERVICE TAX </td>
    <td><input type="text" id="STaxPerc" name="STaxPerc" value="<?php echo $_REQUEST['STaxPerc'];?>" size="3" /><input name="STaxValue" type="text" id="STaxValue" value="<?php echo $_REQUEST['STaxValue'];?>" size="14" onfocus="calculateServiceTax()"/></td>
  </tr>
  <tr>
    <td class="tabledata">S. EDU TAX </td>
    <td><input name="SEduPerc" type="text" id="SEduPerc" value="<?php echo $_REQUEST['SEduPerc'];?>" size="3" /><input name="SEduValue" type="text" id="SEduValue" value="<?php echo $_REQUEST['SEduValue'];?>" size="14" onfocus="calculateSEdu()" /></td>
  </tr>
  <tr>
    <td class="tabledata">S. SHE TAX </td>
    <td><input name="SShePerc" type="text" id="SShePerc" value="<?php echo $_REQUEST['SShePerc'];?>" size="3" /><input name="SSheValue" type="text" id="SSheValue" value="<?php echo $_REQUEST['SSheValue'];?>" size="14" onfocus="calculateSShe()" /></td>
  </tr>
  <tr>
    <td class="tabledata">TDS</td>
    <td><input name="TDSPerc" type="text" id="TDSPerc" value="<?php echo $_REQUEST['TDSPerc'];?>" size="3" /><input name="TDSValue" type="text" id="TDSValue" value="<?php echo $_REQUEST['TDSValue'];?>" size="14" onfocus="calculateTDS()" /></td>
  </tr>
  <tr>
    <td class="tabledata">FREIGHT</td>
    <td><input type="text" name="freight" id="freight" value="<?php echo $_REQUEST['freight'];?>" /></td>
  </tr>
  <tr>
    <td class="tabledata">GRAND TOTAL </td>
    <td><input type="text" name="grandTotal" id="grandTotal" value="<?php echo $_REQUEST['grandTotal'];?>" onfocus="calculateGrandTotal()" /></td>
  </tr>
</table>
	</td>
  </tr>
</table>
	
</div></div>
	
	<?php
}

if($_REQUEST['act']=='')
{
?>

<div class="body_contain">
<div class="tab_div">
<h1>Job Work Bill Book</h1>
<?php if($_SESSION['frmAdd']=='1'){?>
<a href="index.php?route=JobWorkBillBook&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>">ADD NEW BILL BOOK</a>
<?php } ?>

<table width="99%" border="1" align="center" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px; margin-bottom:5px;">
  <tr>
  	<td class="tabledata2"><strong>Branch</strong></td>
    <td class="tabledata2"><strong>Bill No.</strong></td>
    <td class="tabledata2"><strong>Bill Date</strong></td>
    <td class="tabledata2"><strong>Vendor</strong></td>
    <td class="tabledata2"><strong>Vendor Challan(s)</strong></td>
    <td class="tabledata2"><strong>Bill Type</strong></td>
    <td class="tabledata2"><strong>View</strong></td>
    <td class="tabledata2"><strong>Edit</strong></td>
    <td class="tabledata2"><strong>Delete</strong></td>
  </tr>
  <?php 
 
  $sql=DB_query("Select * from job_billbook  where CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
  $i=0;
  while($myrow=DB_fetch_array($sql))
  {
  ?>
<tr bgcolor="#dedede">
	<td><?php echo $myrow['site'];?></td>
    <td><?php echo $myrow['billNo'];?></td>
    <td><?php echo ConvertSQLDate($myrow['billDate']);?></td>
    <td><?php echo $s->getField('suppliers','id',$myrow['vendor'],'vendor_name');?></td>
    <td><?php 
	$tt=explode(",",$myrow['partyChallanNo']);
	for($j=0;$j<count($tt);$j++)
	{
		$returnSlip=DB_query("Select partyChallanNo from job_work_return where id='".$tt[$j]."'",$db);
		$returnRow=DB_fetch_array($returnSlip);
		echo $returnRow['partyChallanNo']."<br>";
	}
	
	
	?></td>
    <td><?php echo $myrow['billType'];?></td>
    <td>
	<?php if($_SESSION['frmView']=='1'){?>
	<a href="index.php?route=JobWorkBillBookList&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $myrow['id'];?>&act=View">View</a>
	<?php }else{echo "No Permission";} ?>
	
	</td>
    <td>
	<?php if($_SESSION['frmEdit']=='1'){?>
	<a href="">Edit</a>
	<?php }else{echo "No Permission";} ?>
	</td>
    <td>
	<?php if($_SESSION['frmDelete']=='1'){?>
	<a href="index.php?route=JobWorkBillBookList&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $myrow['id']?>&act=delete" onclick="return confirm('This record will be deleted. Are you sure?')">Delete</a>
	<?php }else{echo "No Permission";} ?>
	</td>
  </tr>
  <?php } ?>
</table>
</div></div>

<?php }?>

