<?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&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;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 loccode, locationname from locations ",$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 id,client_code,c_name from clientmaster",$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']."'",$db);
}
 if($_REQUEST['party_id']!='000') 
{
$sql=DB_query("Select * from quotation where party='".$_REQUEST['party_id']."' ",$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']."'",$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&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>&amp;action=rev&amp;Id=<?php echo $myrow['id'];?>" >Revise</a></div></td>
<td><div align="center"><a href="index.php?route=quotation_list&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>&amp;action=view&amp;Id=<?php echo $myrow['id'];?>">View</a></div></td>
<td><div align="center"><a href="index.php?route=edit_quotation_list&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>&amp;action=edit&amp;Id=<?php echo $myrow['id'];?>">Edit</a></div></td>
<td><div align="center"><a href="index.php?route=quotation_list&amp;modid=<?php echo $_REQUEST['modid'];?>&amp;frmid=<?php echo $_REQUEST['frmid'];?>&amp;action=delete&amp;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'];
	
	$sql2=DB_query("Select * from quotation where id='".$_REQUEST['Id']."'",$db);
	$result1=DB_fetch_array($sql2);
	$site= $result1['site']; 
					$quotationNo=$result1['quotationNo'];  
					$quotationDate=FormatDateForSQL($result1['quotationDate']);  
					$party=$result1['party'];   
					$quotationType=$result1['quotationType'];
					$quotation_subject=$result1['quotation_subject'];
					$quotation_funnel  =$result1['quotation_funnel'];
					$quotation_stage  =$result1['quotation_stage'];
				 	$enquiryNo =$result1['enquiryNo'];
				   		
 					$source=$result1['source1'];  
					$partyContact=$result1['partyContact1'];  
					$validTill=FormatDateForSQL($result1['validTill1']);  
					$pack_forward=$result1['pack_forward'];  
					$freight=$result1['freight']; 
					$payTerms=$result1['payTerms'];  
					$salesTax=$result1['salesTax'];  
					$Excise=$result1['Excise'];  
					$insurance=$result1['insurance'];  
					$basicAmount=$result1['basicAmount'];  
					$totalDiscountedPrice=$result1['totalDiscountedPrice'];  
					$exciseDuty=$result1['exciseDuty'];  
					$exciseValue=$result1['exciseValue'];  
					$ECessValue=$result1['ECessValue'];  
					$SAHCessValue=$result1['SAHCessValue'];  
					$taxableAmount=$result1['taxableAmount'];
					$VatCst=$result1['VatCst'];  
					$VatCstValue=$result1['VatCstValue'];  
					$freightValue=$result1['freightValue'];  
					$packagingCharges=$result1['packagingCharges'];  
					$additionalCharges=$result1['additionalCharges'];  
					$roundOff=$result1['roundOff'];  
				  	$grandTotal=$result1['grandTotal'];  
					$createdBy=$_SESSION['UserID'];   
					?>
	
<h2 align="center">View Quotation</h2>	
<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"   id="site" onchange="getCode(this.value)">
    <option value="000">Select</option>
    <?php 
    $site_sql=DB_query("Select loccode, locationname from locations",$db);
    while($site_row=DB_fetch_array($site_sql))
	{?>
		<option value="<?php echo $site_row['loccode']?>"<?php echo($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 $quotationNo;?>" size="25"  style="width:98%;"/></td>
  </tr>
  <tr>
    <th scope="row">Quotation Date </th>
    <td nowrap="nowrap"><input type="text" name="quotationDate" value="<?php if(isset($quotationDate)){echo $quotationDate;} else {echo date('d/m/Y');}?>"  class="datepicker"/></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">Account Name</th>
    <td nowrap="nowrap">
	
	<select name="party" style="width:80px%;" onChange="ShowDiv(this.value,'hid_Leads','CRM_GetLeads.php')" >
      <option value="000">Select</option>
      <?php 
      $client_sql=DB_query("Select AccountsID,AccountName from accountledger where ledgertype in('leads','client')",$db);
	  while($client_row=DB_fetch_array($client_sql))
	  {?>
	  	<option value="<?php echo $client_row['AccountsID'];?>"<?php echo($party==$client_row['AccountsID']?'selected':'')?>><?php echo $client_row['AccountName'];?></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($quotationType=='M'?'selected':'')?>>Material</option>
      <option value="E"<?php echo($quotationType=='E'?'selected':'')?>>Export</option>
      <option value="R"<?php echo($quotationType=='R'?'selected':'')?>>Retail</option>
    </select></td>
    </tr>
  <tr>
    <th>Against Enquiry</th>
    <td><div id='hid_Leads'>
	<?php 
	if($_REQUEST['action']=='Edit')
		$enquery_leadid=$s->GetFieldValue('crm_leads',"leadid='".$result1['enquiryNo']."'",'leadcode');
		else
		$enquery_leadid=$enquiryNo;
	?>
	
	
	<input type="text" name="enquiryNo" style="width:150px;" value="<?php  echo $enquery_leadid;?>" /></div> </td>
    <th>Quote Stage</th>
    <td><input type="text" style="width:150px;"  name="quotation_stage" value="<?php  echo $quotation_stage;?>"/></td>
  </tr>
  
  <tr>
    <th nowrap="nowrap">Mobile No.</th>
    <td nowrap="nowrap"><input type="text" name="partyContact2" style="width: 98%" value="<?php echo $_REQUEST['partyContact'];?>" /></td>
    <th scope="row">Valid Till</th>
    <td><input name="validTill" type="text" value="<?php if(isset($validTill)){echo $validTill;} else {echo date('d/m/Y');}?>" size="12" class="datepicker"  style="width:98%;"/></td>
  </tr>
  <tr>
    <th nowrap="nowrap">Funnel</th>
    <td nowrap="nowrap"><input type="text" style="width:150px;" name="quotation_funnel" value="<?php  echo $quotation_funnel;?>" /></td>
    <th scope="row">&nbsp;</th>
    <td>&nbsp;</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 id='".$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 } ?>




	
