<?php 
$rurl="&modid=".$modid."&frmid=".$frmid;

if($_REQUEST['Id']!='' && $_REQUEST['action']=='delete')
{
$del="delete from quotation where id='".$_REQUEST['Id']."'";
$query=DB_query($del,$db);
$del1="delete from quotation_details where parentId='".$_REQUEST['Id']."'";
$query1=DB_query($del1,$db);	
$s->pageLocation("index.php?route=quotation_list&daction=Updated".$rurl);	
}


?>


<?php if($_REQUEST['action']==''){?>
<h2 align="center">Quotation List</h2>
<a href="index.php?route=quote_offer_to_customer&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>">Add New</a>
<br>
<form action="" method="Post">
<table width="50%" border="0" cellpadding="2" cellspacing="2" align="center">
<tr><td><strong>Branch Wise</strong></td><td><select name="branch_id" style="width: 100%">
	<option value="000">Select Branch</option>
    	<?php $site_sql=DB_query("Select prefix, loccode, locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
    	while($site_row=DB_fetch_array($site_sql))
		{?>
			<option value="<?php echo $site_row['loccode'];?>"<?php echo($_SESSION['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
		<?php 	
		}
    	?></select></td>
    	<td><strong>Party Wise</strong></td>
    	<td><select name="party_id" style="width: 80%">
    		<option value="000">Select Party</option>
	<?php 
	$vendor_sql=DB_query("Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site in('".$_SESSION['AssignedBranch']."') 
		and Zone in(".$_SESSION['AssignedSites'].") order by c_name",$db);
	while($vendor=DB_fetch_array($vendor_sql))
	{
	?>
      <option value="<?php echo $vendor['client_code'];?>"<?php echo ($_REQUEST['party']==$vendor['client_code']?'selected':'')?>><?php echo $vendor['c_name'];?></option>
      <?php } ?>
			</select></td>
    	<td><input type="submit" name="Search" value="Search" /></td>	
</tr></table>	
</form>
<br>
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr>
<th>Branch</th>
<th>Quotation No.</th>
<th>Quotation Date</th>
<th>Quotation Type</th>
<th>Source</th>
<th>Party</th>
<th>Follow Up</th>
<th>Revise</th>
<th>View</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<?php 
if(isset($_POST['Search']))
{
if($_REQUEST['branch_id']!='000')
{
	
	
$sql=DB_query("Select * from quotation where site='".$_REQUEST['branch_id']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
}
 if($_REQUEST['party_id']!='000') 
{
	
$sql=DB_query("Select * from quotation where party='".$_REQUEST['party_id']."'and CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);	
}
if($_REQUEST['branch_id']!='000' and $_REQUEST['party_id']!='000')
{
$sql=DB_query("Select * from quotation where party='".$_REQUEST['party_id']."' and site='".$_REQUEST['branch_id']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);	
}
$i=0;
$num=DB_num_rows($sql);

if($num>0)
{
while($myrow=DB_fetch_array($sql))
{
?>
<tr bgcolor="#FFFFFF">
<td><?php echo $myrow['site'];?></td>
<td><?php echo $myrow['quotationNo'];?></td>
<td><?php echo $myrow['quotationDate'];?></td>
<td><?php 
if($myrow['quotationType']=='M'){echo "Material";}
if($myrow['quotationType']=='E'){echo "Export";}
if($myrow['quotationType']=='R'){echo "Retail";}
?></td>
<td>
<?php 
if($myrow['source']=='CC'){echo "Cold Call";}
if($myrow['source']=='EC'){echo "Existing Customer";}
if($myrow['source']=='SG'){echo "Self Generated";}
if($myrow['source']=='EMP'){echo "Employee";}
if($myrow['source']=='PTN'){echo "Partner";}
if($myrow['source']=='DM'){echo "Direct Mail";}
if($myrow['source']=='WEB'){echo "Web Site";}
if($myrow['source']=='O'){echo "Other";}?></td>
<td><?php echo  $unitName=$s->getField('clientmaster','client_code',$myrow['party'],'c_name');
?></td>
<td><div align="center"><a href="">Follow</a></div></td>
<td><div align="center"><a href="index.php?route=quotation_revision&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=rev&Id=<?php echo $myrow['id'];?>"">Revise</a></div></td>
<td><div align="center"><a href="index.php?route=quotation_list&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=view&Id=<?php echo $myrow['id'];?>">View</a></div></td>
<td><div align="center"><a href="index.php?route=edit_quotation_list&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=edit&Id=<?php echo $myrow['id'];?>">Edit</a></div></td>
<td><div align="center"><a href="index.php?route=quotation_list&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=delete&Id=<?php echo $myrow['id'];?>">Delete</a></div></td>
</tr>
<?php $i++;} } else { ?>
	<tr bgcolor="#FFFFFF">
<td colspan="10">No Records Find</td>
</tr>
<?php } }  ?>
</table>
<?php }
if($_REQUEST['Id']!='' && $_REQUEST['action']=='view')
{
	$sql1=DB_query("Select * from quotation where id='".$_REQUEST['Id']."'",$db);
	$result1=DB_fetch_array($sql1);
	$taxamount=$result1['taxableAmount'];
	?>
	
<h2 align="center">View Quotation</h2>	

<table width="80%" cellpadding="0" cellspacing="0" border="0" bgcolor="#FFFFFF" style="border:1px solid #CCC;" align="center">
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="2" align="center">
  <tr>
    <th width="25%" nowrap="nowrap" scope="row"><strong>Branch</strong></th>
    <td width="25%" nowrap="nowrap">
    <select name="site" style="width:98%;" id="site" onchange="getCode(this.value)">
    <?php 
    $site_sql=DB_query("Select loccode, locationname from locations where loccode='".$result1['site']."'",$db);
    while($site_row=DB_fetch_array($site_sql))
	{?>
		<option value="<?php echo $site_row['loccode']?>"<?php echo($_REQUEST['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname']?></option>
	<?php 	
	}
    ?>
    </select></td>
    <th width="25%"><strong>Quotation No.</strong></th>
    <td width="25%" id="CODE"><input name="quotationNo" type="text" value="<?php echo $result1['quotationNo'];?>" size="25"  style="width:98%;"/></td>
  </tr>
  <tr>
    <th scope="row"><strong>Date </strong></th>
    <td nowrap="nowrap"><input type="text" name="quotationDate" value="<?php echo $result1['quotationDate'];?>" style="width:98%;"  readonly/></td>
    <th nowrap="nowrap">Format</th>
    <td nowrap="nowrap"><select name="format" style="width:98%;">
      <option value="Standard">Standard</option>
    </select></td>
  </tr>
  <tr>
    <th nowrap="nowrap"><strong>Party Name</strong></th>
    <td nowrap="nowrap">
    <select name="party" style="width:98%;" onchange="enquiryDetails(this.value)">
      <?php 
      $client_sql=DB_query("Select client_code,c_name from clientmaster where client_code='".$result1['party']."'",$db);
	  while($client_row=DB_fetch_array($client_sql))
	  {?>
	  	<option value="<?php echo $client_row['client_code'];?>"<?php echo($_REQUEST['party']==$client_row['client_code']?'selected':'')?>><?php echo $client_row['c_name'];?></option>
	  <?php 	
	  }
      ?>
    </select></td>
    <th scope="row"><strong>Type of Quotation</strong></th>
    <td><select name="quotationType" style="width:98%;">
      <option value="M"<?php echo($result1['quotationType']=='M'?'selected':'')?>>Material</option>
      <option value="E"<?php echo($result1['quotationType']=='E'?'selected':'')?>>Export</option>
      <option value="R"<?php echo($result1['quotationType']=='R'?'selected':'')?>>Retail</option>
    </select></td>
    </tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td colspan="4"> 
    <table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">
    <tr>
    <td colspan="2" valign="top"><div id="enquiryId">
    	<table width="100%" cellpadding="2" cellspacing="1" border="0">
        	<tr>
            <th nowrap="nowrap" width="50%"><strong>Against Enquiry</strong></th>
            <td nowrap="nowrap" width="50%">
          
            <select name="enquiryNo" style="width:98%;" onchange="showEnqDetails(this.value)">
              <?php 
             $enq_sql=DB_query("Select id,enquiryNo from enquiry where id='".$result1['enquiryNo']."'",$db);
			while($enq_row=DB_fetch_array($enq_sql))
			{?>
				<option value="<?php echo $enq_row['id'];?>"<?php echo($_REQUEST['enquiryNo']==$enq_row['id']?'selected':'')?>><?php echo $enq_row['enquiryNo'];?></option>	
			<?php 	
			}
            ?>
            </select></td>
   		 </tr>
   		 <?php 
   		 $address_sql=DB_query("Select pre_address1,pre_address2,pre_address3,pre_country,pre_state,pre_city from clientmaster where client_code='".$result1['party']."'",$db);
		 $address_result=DB_fetch_array($address_sql);
   		 
   		 $countryName=$s->getField('country_master','id',$address_result['pre_country'],'country');
		 $stateName=$s->getField('state_master','id',$address_result['pre_state'],'state');
		 $cityName=$s->getField('city_master','id',$address_result['pre_city'],'city');
   		 ?>
         <tr>
            <th scope="row" rowspan="3"><strong>Address</strong></th>
            <td><input name="partyaddress1" type="text" value="<?php echo $address_result['pre_address1'];?>" size="25"  style="width:98%;" readonly/></td>
            </tr>
            <tr>
            <td><input name="partyaddress2" type="text" value="<?php echo $address_result['pre_address2'];?>" size="25"  style="width:98%;" readonly/></td>
            </tr>
            <tr>
            <td><input name="partyaddress3" type="text" value="<?php echo $address_result['pre_address3'].",".$cityName.",".$stateName.",".$countryName;?>" size="25"  style="width:98%;" readonly/></td>
            </tr>
     </table></div>
    </td>
    <td valign="top"><div id="enqdetailsId"><table width="100%" border="0" cellspacing="1" cellpadding="1">
  <?php 
if($result1['source']=='CC'){$source="Cold Call";}
if($result1['source']=='EC'){$source="Existing Customer";}
if($result1['source']=='SG'){$source="Self Generated";}
if($result1['source']=='EMP'){$source="Employee";}
if($result1['source']=='PTN'){$source="Partner";}
if($result1['source']=='DM'){$source="Direct Mail";}
if($result1['source']=='WEB'){$source="Web Site";}
if($result1['source']=='O'){$source="Other";} ?>
      <tr>
        <th width="50%" scope="row"><strong>Source Through </strong></th>
        <td width="50%">	
        <input name="source" type="text" value="<?php echo $source;?>" size="25"  style="width:98%;"/></td>
      </tr>      
      <tr>
        <th scope="row"><strong>Contact Person</strong></th>
        <td><input type="text" name="partyContact" style="width: 98%" value="<?php echo $result1['partyContact'];?>" /></td>
      </tr>
     <?php 
     $mobile_sql=DB_query("Select phone from contact_information_master where person='".$result1['partyContact']."'",$db);
     $mobile_res=DB_fetch_array($mobile_sql)
     ?>
      <tr>
        <th scope="row"><strong>Mobile No.</strong></th>
        <td><input name="ContactMobile" type="text" value="<?php echo $mobile_res['phone'];?>" size="25" style="width:98%;" readonly/></td>
      </tr>
    </table></div>
    <table border="0" width="100%"><tr><th width="50%">Valid Till</th><td width="50%"><input name="validTill" type="text" value="<?php echo $result1['validTill'];?>" size="12"  readonly  style="width:98%;"/></td></tr></table>	
    </td>
    </tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br/>
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr>
<th>Item Code</th>
<th>Item Name</th>
<th>Unit</th>
<th>Qty</th>
<th>Price</th>
<th>Per Unit(s)</th>
<th>Value</th>
<th>Discount Type</th>
<th>Discount</th>
<th>Discounted Price</th>
<th>Date Of Requisition</th>
</tr>
<?php 
$details_sql=DB_query("Select * from quotation_details where parentId='".$_REQUEST['Id']."'",$db);
	$i=0;
	
	while($details_row=DB_fetch_array($details_sql))
	{
		
		$item_sql=DB_query("Select * from item_master where StockID='".$details_row['itemCode']."'",$db);
		$item_row=DB_fetch_array($item_sql);	
	?>
<tr bgcolor="#FFFFFF">
<td><?php echo $details_row['itemCode']?><input type="hidden" name="itemCode[<?php echo $i;?>]" value="<?php echo $details_row['itemCode']?>" id="itemCode_<?php echo $i;?>" /></td>
<td><?php echo $item_row['item_name']?></td>
<td><?php 
$unitName=$s->getField('unitsofmeasure','unitid',$item_row['unit'],'unitname');
echo $unitName?></td>
<td><?php echo $details_row['quantity']?><input type="hidden" name="quantity[<?php echo $i;?>]" value="<?php echo $details_row['quantity']?>" id="quantity_<?php echo $i;?>" /></td>
<td><?php echo $details_row['price']?><input type="hidden" name="price[<?php echo $i;?>]" value="<?php echo $details_row['price']?>" id="price_<?php echo $i;?>" /></td>
<td><?php echo $details_row['PerUnits']?><input type="hidden" name="PerUnits[<?php echo $i;?>]" id="PerUnits_<?php echo $i;?>" value="<?php echo $details_row['pricePer']?>" /></td>
<td><?php echo $details_row['totalValue']?><input type="hidden" name="totalValue[<?php echo $i;?>]" id="totalValue_<?php echo $i;?>" value="<?php echo $details_row['totalValue']?>" /></td>
<td>
<select name="discountType[<?php echo $i;?>]" id="discountType_<?php echo $i;?>" style="width: 98%">
	<option value="A"<?php echo($details_row['discountType']=='A'?'selected':'')?>>Amount</option>
	<option value="P"<?php echo($details_row['discountType']=='P'?'selected':'')?>>Percent</option>
</select>
</td>
<td><input type="text" name="discount[<?php echo $i;?>]" id="discount_<?php echo $i;?>" value="<?php echo $details_row['discount']?>" size="15" onblur="calculateDiscount(this.value,<?php echo $i;?>)" readonly /></td>
<td><input type="text" name="valueAfterDisc[<?php echo $i;?>]" id="valueAfterDisc_<?php echo $i;?>" value="<?php echo $details_row['valueAfterDisc']?>" size="15" readonly/></td>
<td><?php echo $details_row['requisitionDate']?><input type="hidden" name="requisitionDate[<?php echo $i;?>]" id="requisitionDate_<?php echo $i;?>" value="<?php echo $details_row['requisitionDate']?>" size="15" readonly/></td>
</tr>
<?php 	
} 
?>
</table><br>
<br>
<table width="45%" border="0" cellspacing="1" cellpadding="0" align="right" bgcolor="#FFFFFF" style="border:1px solid #ccc;" >
    		<tr>
    	<th style="text-align:center;" colspan="2">Amount And Taxes</th>
    </tr>
    <tr>
    	  <tr>
    	    <th width="14%">Basic Amount</th>
    	    <td width="31%"><input name="basicAmount" type="text" value="<?php echo $result1['basicAmount'];?>" size="25" style="width:98%;" onfocus="calculateBasic()" id="basicAmount" readonly /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th nowrap="nowrap">Discounted Price</th>
    	    <td><input name="totalDiscountedPrice" id="totalDiscountedPrice" type="text" value="<?php echo $result1['totalDiscountedPrice'];?>" size="25" style="width:98%;"  readonly onfocus="calculateDiscounted()" /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Excise</th>
    	    <td nowrap="nowrap">
    	    <select name="exciseDuty" style="width:98%;" onchange="claculateExcise(this.value)">
    	     <?php 
    	    $excise_sql=DB_query("Select * from excise_tax where caption like '%excise%' and form_type='Sales'",$db);
			while($excise_row=DB_fetch_array($excise_sql))
			{?>
				<option value="<?php echo $excise_row['id'];?>"><?php echo $excise_row['caption'];?></option>
			<?php 	
			}
    	    ?> 
  	      </select><div id="exciseId"><input name="exciseValue" id="exciseValue" type="text" value="<?php echo $result1['exciseValue']; ?>" size="25" style="width:98%;"  readonly="readonly"/></div>
    	   </tr>
    	     
    	     <?php 
    	     $cessSql=DB_query("Select caption from excise_tax where caption like '%cess%'",$db);
			 $k=1;
			 while($cessRow=DB_fetch_array($cessSql))
			 {
			 	$caption[$k]=$cessRow['caption']; 
				
				$rate_sql=DB_query("Select def_rate from excise_tax where caption='".$caption[$k]."'",$db);
				while($rate_row=DB_fetch_array($rate_sql))
				{
					$rate[$k]=$rate_row['def_rate'];
				}
				$k++;
			 } 
    	     ?></td>
    	     <tr>
    	    <th>E-Cess</th>
    	    <td><input name="ECessPercentage" id="ECessPercentage" type="text" value="<?php echo $rate[1];?>" size="25" style="width:20%;" readonly />
    	    	<input name="ECessValue" id="ECessValue" type="text" value="<?php echo $result1['ECessValue']; ?>" size="25" style="width:75%;" readonly onfocus="calculateECess()"/></td>
    	    </tr>
    	    <tr>
            <th nowrap="nowrap">SAH-E Cess </th>
    	    <td><input name="SAHCessPercentage" id="SAHCessPercentage" type="text" value="<?php echo $rate[2];?>" size="25" style="width:20%;" readonly/>
    	    	<input name="SAHCessValue" id="SAHCessValue" type="text" value="<?php echo $result1['SAHCessValue']; ?>" size="25" style="width:75%;" readonly onfocus="calculateSAHCess()"/></td>
  	    	</tr>    	  
    	  
      <tr>
   	<th>Taxable Amount</th>
   	<td><input name="taxableAmount" id="taxableAmount" type="text" value="<?php echo $result1['taxableAmount'];?>" size="25" style="width:98%;" onfocus="calculateTaxable()"/></td>
   </tr>	  
    	   <tr>
    	    <th>VAT/CST</th>
    	    <td nowrap="nowrap">
    	    <select name="VatCst" id="value3" style="width:98%;" onchange="calculateVATCST(this.value)">
    	     <?php 
    	    $salesSql=DB_query("Select * from sales_tax_master where salestax_id='".$result1['VatCst']."'",$db);
			while($salesRow=DB_fetch_array($salesSql))
			{?>
				<option value="<?php echo $salesRow['salestax_id'];?>"><?php echo $salesRow['tax_code'];?></option>
			<?php 	
			}
    	    ?>
  	      </select>
    	      <div id="VATId"><input name="VatCstValue" id="VatCstValue" type="text" value="<?php echo $result1['VatCstValue'];?>" size="25" style="width:98%;" readonly /></div></td>
    	    
  	    </tr>
    	  
    	  
    	  <tr>
    	    <th>Freight</th>
    	    <td><input name="freightValue" id="value2" type="text" value="<?php echo $result1['frightValue'];?>" size="25" style="width:98%;" readonly/></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Pkg Charges</th>
    	    <td><input name="packagingCharges" id="value1" type="text" value="<?php echo $result1['PackagingCharges'];?>" size="25" style="width:98%;" readonly/></td>
    	    
  	    </tr>
  	    <tr>
    	    <th>Additional Charges</th>
    	    <td><input name="additionalCharges" id="value4" type="text" value="<?php echo $result1['additionalCharges'];?>" size="25" style="width:98%;" readonly/></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Round Off</th>
    	    <td><input name="roundOff" type="text" value="<?php echo $result1['roundOff'];?>" size="25" style="width:98%;" readonly /></td>
    	    
  	    </tr>
    	  <tr>
    	    <th>Grand Total</th>
    	    <td><input name="grandTotal" id="grandTotal" type="text" value="<?php echo $result1['grandTotal'];?>" size="25" style="width:98%;" onfocus="calculateGrand()" readonly="readonly" /></td>
    	    
  	    </tr>
  	    </table>
<?php } ?>




	
