<?php error_reporting(0);
$PageSecurity = 3;
 	$modid=$_REQUEST['modid'];
	$frmid=$_REQUEST['frmid'];
	$rurl="&modid=".$modid."&frmid=".$frmid;
	 $cnp=$_REQUEST['cnp'];
	//echo $_SERVER['PHP_SELF'];
 include ('includes/session.inc');
 include ('includes/function_lib.php');
 global $db;
   echo '<link href="'.$rootpath. '/css/'. $_SESSION['Theme'] .'/default.css" rel="stylesheet" type="text/css" />';
   
include('includes/DefinePOClass.php');
include('includes/SQL_CommonFunctions.inc');
$sql="Select * from purchase_billbook where id='".$_REQUEST['viewId']."'";
$result=DB_query($sql,$db);
$myrow=DB_fetch_array($result);

?>

<h2 align="center"><strong>View Purchase Bill - <?php echo $myrow['bill'];?></strong></h2>
<h2 align="center"><strong>General Details</strong></h2>


<div align="center">
<table width="60%"  cellspacing="2" cellpadding="2" >
<tr>
<td><strong>Site</strong></td>
<?php 
$site_name=$s->getField('locations','loccode',$myrow['site'],'locationname');
?>
<td><input name="textfield" type="text" value="<?php echo $site_name;?>" size="30" readonly></td>
<td>
 <strong>Bill No  </strong></td>
<td><input name="textfield5" type="text" value="<?php echo $myrow['purchase_bill'];?>" size="15" readonly></td>
</tr>
<tr>
<td><strong>Date</strong></td>
<td><input name="textfield6" type="text" value="<?php echo ConvertSQLDate($myrow['bill_date']);?>" size="30" readonly></td>
<td><strong>Credit Days</strong></td>
<td><input name="textfield8" type="text" value="<?php echo $myrow['credit_days'];?>" size="15" readonly></td>
</tr>


<tr>
<td><strong>Vendor Name </strong></td>
<?php 
$vendor_name=$s->getField('suppliers','vendor_code',$myrow['vendor'],'vendor_name');
?>
<td><input name="textfield3" type="text" value="<?php echo $vendor_name;?>" size="30" readonly></td>
<td><strong>Cash/Credit</strong></td>
<td><input name="textfield7" type="text" value="<?php echo $myrow['cash_credit'];?>" size="15" readonly></td>
</tr>
<tr>
<td><strong>MRN No</strong></td>
<?php 
$mrn_code=$s->getField('addmrn','id',$myrow['mrn_no'],'MRNNo');
?>
<td><input name="textfield4" type="text" value="<?php echo $mrn_code;?>" size="30" readonly></td> 
</tr>
</table>
</div>
<?php 
?>
<fieldset><legend><h3><strong>Item Details</strong></h3></legend>
<div align="center">
<div style="overflow:auto; width:900px ; height:170px">
<table width="100%" border="0" cellspacing="1" cellpadding="2">
    <tr valign="top">
	<th ><strong>Item Code</th >
	<th ><strong>Item Name</th >
    <th ><strong>Make</th >
    <th ><strong>Color</th >
    <th ><strong>Grade</th >
    <th ><strong>Unit</th >
    <th ><strong>Quantity</th >
    <th ><strong>Rate</th >
	<th ><strong>Total Price</th >
	<th ><strong>Discount type</th >
    <th ><strong>Discount</th >
    <th ><strong>Discount Amount</th >
    <th ><strong>SubTotal</th >
	 <th><strong>SPECIAL DISCOUNT</th >	
	<th ><strong>Special Discount Amount</th >
	<th ><strong>BASIC AMOUNT</th >
	<th ><strong>Tax Type</th >
	<th ><strong>Excise</th >
	<th ><strong>E-Cess</th >
	<th ><strong>SAH-E Cess</th >
	<th ><strong>Taxable Amount </th >
	<th ><strong>VAT/CST</th >
	<th ><strong>VAT/CST Amount</th >
	<th ><strong>TOTAL AMOUNT</th >
    </tr>
   <?php 				
$vend_sql="SELECT * FROM purchase_billbook WHERE id='".$_REQUEST['viewId']."'";
$result_vend=DB_query($vend_sql,$db);
$myrowvender=DB_fetch_array($result_vend);
  
$basic_amt  =$myrowvender['basic_amount'];
//$ExcisePercentage  =$myrowvender['ExcisePercentage'];
$Excise_Duty_value  =$myrowvender['Excise_Duty'];
//$Edu_Cess_perc  =$myrowvender['Edu_Cess_perc'];
$Edu_Cess  =$myrowvender['Edu_Cess'];
//$SHE_Cess_perc  =$myrowvender['SHE_Cess_perc'];
$SHE_Cess  =$myrowvender['SHE_Cess'];
$taxable_amt  =$myrowvender['taxable_amt'];
//$taxname  =$myrowvender['taxname'];
$taxvalue  =$myrowvender['taxvalue'];
//$sur_oct_perc  =$myrowvender['sur_oct_perc'];
$sur_oct_amt  =$myrowvender['sur_oct_value'];
$totalcharge  =$myrowvender['total_charges'];
$pkg_charges  =$myrowvender['pkg_charges'];
$add_charges  =$myrowvender['add_charges'];
//$roundoff  =$myrowvender['roundOff'];
$grand_total   = $myrowvender['grand_total']; 
$totalamount  = $myrowvender['total_amt'];

$billingType= $myrowvender['billingType'];
 
$sql="SELECT * FROM purchase_bill_details WHERE purch_billbookid='".$_REQUEST['viewId']."'  ";


//echo $sql;
$result=DB_query($sql,$db);
$i=1;
$totalqty1=0;
while($myrow=DB_fetch_array($result))
{
$totalqty1=$totalqty1+$myrow['total_amount'];
$grandtotal1=$totalqty1+$pkg_charges+$add_charges+$sur_oct_amt+$totalcharge+$roundoff;
//echo "<pre>";
//print_r($myrow);

?>
	<tr bgcolor="#FFFFFF">
	
      <td ><?php echo $myrow['prod_id'];?><input type="hidden" name="item_code[<?php echo $i;?>]" id="item_code_<?php echo $i;?>" value="<?php echo $get_row['prod_id'];?>"></td>
      <td ><?php echo $myrow['prod_dec'];?><input type="hidden" name="item_name[<?php echo $i;?>]" id="item_name_<?php echo $i;?>" value="<?php echo $get_row['prod_dec'];?>"></td>
 
       <td ><?php  echo	  $myrow['make'];	  ?>
        <input type="hidden" name="make[<?php echo $i;?>]2" size="45" value="<?php echo $myrow['make'];?>" readonly /></td>
    <td ><?php 
	  $colorname=$s->getField('product_color','id',$myrow['color'],'color');
	  echo $colorname;?>
        <input type="hidden" name="color[<?php echo $i;?>]2" size="45" value="<?php echo $myrow['color'];?>" readonly /></td>
    <td ><?php 
	  $gradename=$s->getField('product_grade','id',$myrow['grade'],'grade');
	  echo $gradename;?>
        <input type="hidden" name="grade[<?php echo $i;?>]2" size="45" value="<?php echo $myrow['grade'];?>" readonly /></td>
      <td ><?php 
	  $unitname=$s->getField('unitsofmeasure','unitid',$myrow['uom'],'unitname');
	  echo $unitname;?>
        <input type="hidden" name="unit[<?php echo $i;?>]2" size="45" value="<?php echo $myrow['uom'];?>" readonly /></td>
    <?php $query_item=DB_query("select * from item_master where StockID='".$myrow['prod_id']."'", $db);
		  	$item_row=DB_fetch_array($query_item);
		   ?> 
   
    <td ><input type="hidden" name="quantity[<?php echo $i;?>]2" size="5" value="<?php echo $myrow['quantity'];?>" id="quantity[<?php echo $i;?>]" readonly />
        <?php echo $myrow['quantity'];?></td>
    <td ><?php echo $myrow['rate'];?>
        <input type="hidden" name="Rate[<?php echo $i;?>]2" id="Rate[<?php echo $i;?>]" value="<?php echo $myrow['rate'];?>" size="4" readonly/>
		<td ><?php echo $myrow['rate']*$myrow['quantity'];?>
           </td>
    <td ><?php 
	  if($myrow['discount']=='0')
	  echo "N/A";
	  else
	  echo $myrow['discount_type'];?>
        <input type="hidden" name="discount_type[<?php echo $i;?>]2" id="discount_type[<?php echo $i;?>]" value="<?php echo $myrow['discount_type'];?>" readonly/>
    </td>
    <td ><?php 	   
if($myrow['discount_type']=="PercentAmt")
{?>
        <?php echo $myrow['discount'];?>%
      <input type="hidden" name="Discount[<?php echo $i;?>]2" id="Discount[<?php echo $i;?>]" value="<?php echo $myrow['discount'];?>" onblur="DiscountAmount(this.value,<?php echo $i;?>)" size="8" readonly />
        <?php 	 }
else 
{?>
        <?php echo $myrow['discount'];?>
        <input type="hidden" name="Discount[<?php echo $i;?>]2" id="Discount[<?php echo $i;?>]" value="<?php echo $myrow['discount'];?>" onblur="DiscountAmount(this.value,<?php echo $i;?>)" size="8" readonly />
        <?php } ?></td>
    <td ><?php echo $myrow['discount_amount'];?>
        <input type="hidden" id="discount_amount[<?php echo $i;?>]" name="discount_amount[<?php echo $i;?>]2" value="<?php echo $myrow['discount_amount'];?>" readonly/></td>
         <td ><?php echo $myrow['sub_total'];?></td> 
		  <td ><?php echo $myrow['specialdiscount'];?></td> 
    <td ><?php echo $myrow['specialdiscount_amount']; ?>
        <input type="hidden" id="specialdiscount_amount[<?php echo $i;?>]" name="specialdiscount_amount[<?php echo $i;?>]2" value="<?php echo $myrow['specialdiscount_amount'];?>" size="8" readonly/></td>
     <td ><?php echo $myrow['basic_amt']; ?></td>
     <td ><?php echo $myrow['tax_type']; ?></td>
     <td ><?php echo $myrow['Excise_Duty_value']; ?></td>
     <td ><?php echo $myrow['Edu_Cess']; ?></td>
     <td ><?php echo $myrow['SHE_Cess']; ?></td>
     <td ><?php echo $myrow['taxable_amt']; ?></td>
     <td ><?php echo $s->getField('service_tax_master','id',$myrow['taxname'],'tax_code'); ?></td>
      <td ><?php echo $myrow['taxvalue']; ?></td>
    
   
    <td ><?php echo $myrow['total_amount']; ?></td>
    <?php 
	  
	    
$i++;
}?>
      <input type="hidden" name="PO_count" value="<?php echo $i;?>" />
    </tr>
  </table>

</div>

</div>	

<div align="right">

<table border="0" cellspacing="1" cellpadding="2" width="80%">
<tr>
<td valign="top">
<table width="100%" align="left">
<tr>
<th><strong>Ledger</strong></th>
<td>
<?php 
$ledger=$s->getField('purchase_billbook','id',$_REQUEST['viewId'],'ledger_list');
?>
<select name="ledger" id="ledger" style="width:220px">
<option value="000">---Select Ledger---</option>
<?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==$ledger_row['AccountsID']?'selected':'')?>><?php echo $ledger_row['AccountName'];?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<th><strong>Remarks If Any</strong></th>
<td>
<textarea name="remarks" id="remarks" rows="3" cols="25" readonly="readonly"><?php echo $myrow['remarks'];?></textarea>
</td>
</tr>
<tr>
    <th valign="top"><strong>Excise Effect</strong></th>
    <td valign="top"><select name='Excise_Effect' style="width:auto">
	<option value="0">---</option>
	<option value="RG-23A"  <?php echo ( $myrowvender['Excise_Effect']=='RG-23A')?'selected':''?>  >RG 23A &Iota; &Iota;nd</option>
		<option value="RG-23C"  <?php echo ( $myrowvender['Excise_Effect']=='RG-23C')?'selected':''?>  >RG 23C &Iota; &Iota;nd</option>
		<option value="modvat"  <?php echo ( $myrowvender['Excise_Effect']=='modvat')?'selected':''?>  >Mod Vat</option>
 	</select>&nbsp;</td>
  </tr>
  <tr>
  <th>Form Type</th>
  <td><select  name="form_type" id="form_type" style="width:100%; height:20px;">
  <option value="">Select</option>
  <?php
 $formSql=DB_query("Select * from form_type_master",$db);
while($formRow=DB_fetch_array($formSql))
{
?>
  <option value="<?php  echo $formRow['id']?>"<?php echo ($myrowvender['form_type']==$formRow['id']?'selected':'')?>><?php  echo $formRow['form_name']?></option>
  <?php }?>
</select></td>
  </tr>
</table></td>
<td align="right">
<div align="right">
<fieldset style="width:300px"><legend><strong>AMOUNT AND TAX </strong></legend>

<table width="100%" border="0" cellspacing="2" cellpadding="2" align="right" >
                <tr>
                  <th><strong>TOTAL Basic AMOUNT </strong> </th>
                  <td ><input type="text" name="basic_amount" value="<?php echo $basic_amt; ?>" id="basic_amount" readonly  style="width:100%;"/></td>
                </tr>                
                 <tr>
                  <th><strong>TOTAL EXCISE AMOUNT</strong> </th>
                  <td ><input type="text" name="exciseValue" id="exciseValue" value="<?php echo $Excise_Duty_value; ?>" style="width:100%;"  readonly="readonly" /></td>
                </tr>
                <tr>
                  <th><strong>TOTAL E-Cess AMOUNT</strong> </th>
                  <td ><input type="text" name="ECessValue" id="ECessValue" value="<?php echo $Edu_Cess;?>" style="width:100%;"  readonly="readonly" /></td>
                </tr>
                <tr>
                  <th><strong>TOTAL SAH-E Cess AMOUNT</strong> </th>
                  <td ><input type="text" name="SAHCessValue" id="SAHCessValue" value="<?php echo $SHE_Cess;?>" style="width:100%;"  readonly="readonly" /></td>
                </tr>
                 <tr>
                  <th><strong>TOTAL Taxable Amount</strong> </th>
                  <td ><input type="text" name="taxable_amt" id="taxable_amt" value="<?php echo $taxable_amt;?>" style="width:100%;"  readonly="readonly" /></td>
                </tr>
                <tr>
                  <th><strong>TOTAL VAT/CST Amount</strong> </th>
                  <td ><input type="text" name="taxvalue" id="taxvalue" value="<?php echo $taxvalue; ?>" style="width:100%;"  readonly="readonly" /></td>
                </tr>
                         
                <tr>
                  <th><strong>Surcharge Amount</strong> </th>
                  <td><input name="sur_oct_amt" type="text" id="sur_oct_amt" value="<?php echo $sur_oct_amt; ?>" style="width:100%;" /></td>
                </tr>
                <tr>
                  <th><strong>Freight</strong> </th>
                  <td><input type="text" name="TotalCharge" id="TotalCharge" value="<?php echo $totalcharge; ?>" style="width:100%;"/></td>
                </tr>
                <tr>
                  <th><strong>Pkg Charges</strong> </th>
                  <td><input name="pkg_charges" id="packagingCharges" type="text" value="<?php echo  $pkg_charges;?>" size="25" style="width:100%;" /></td>
                </tr>
                <tr>
                  <th><strong>Additional Charges</strong> </th>
                  <td><input name="add_charges" id="additionalCharges" type="text" value="<?php echo $add_charges; ?>" size="25" style="width:100%;" /></td>
                </tr>
				               <tr>
                  <th><strong>Grand Total</strong></th>
                  <td><input type="text" name="grand_total" value="<?php echo $grand_total; ?>" id="grand_total" readonly /></td>
                </tr>
              </table>	
</fieldset></div>
</strong>
</td>
</tr>
</table>
<?php 
 ?>
