<?php 
$PageSecurity = 1;
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');


 if($_REQUEST['q']!=''){
$prefix_sql=DB_query("Select prefix from locations where loccode='".$_REQUEST['q']."' ",$db);
$prefix_row=DB_fetch_array($prefix_sql);
$branchPrefix=$prefix_row['prefix'];

$orderNo_sql="Select id,orderNo from salesorder where branch='".$_REQUEST['q']."' order by id desc limit 1";
$orderResult=DB_query($orderNo_sql,$db);


if(DB_num_rows($orderResult)>0)
{
	$orderNo_row=DB_fetch_array($orderResult);	
 	$OrderNo=$orderNo_row['orderNo'];
	$OrderNo_brk1=substr($OrderNo,0,7);
	$OrderNo_brk2=substr($OrderNo,-4);
	$next=$OrderNo_brk2+1;
	$string=$OrderNo_brk1.str_pad($next,4,"0",STR_PAD_LEFT);
}
else
{
	$string=$branchPrefix."/SO-0001";
}
?>
<input type="text" name="orderNo" id="orderNo" value="<?php echo $string;?>" size="6"  style="width:206px;">
<?php } 
if($_REQUEST['client']!='')
{?>
	<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">
    <tr>
        <td nowrap="nowrap" colspan="2" width="50%" valign="top">
        <div id="enquiryId" style="width:100%; margin:0 auto;">
            <table width="100%" cellpadding="2" cellspacing="1" border="0">
                <tr>
                  <th width="21%" align="left" nowrap="nowrap"><strong>Against Quotation</strong></th>
                  <td nowrap="nowrap" width="28%">
                    <select name="enquiryNo" style="width:100%;">
                      <option value="0">Select</option>
                      <?php 
                 $enq_sql=DB_query("Select id,quotationNo from quotation where party='".$_REQUEST['client']."' and site='".$_REQUEST['branch']."' and status='0'",$db);
                while($enq_row=DB_fetch_array($enq_sql))
                {?>
                      <option value="<?php echo $enq_row['id'];?>"><?php echo $enq_row['quotationNo'];?></option>	
                      <?php 	
                }
                ?>
                      </select></td>
                <?php 
                $client_sql=DB_query("Select pre_address1,pre_address2,pre_address3,pre_country,pre_state,pre_city from clientmaster where client_code='".$_REQUEST['client']."'",$db);
				$client_row=DB_fetch_array($client_sql,$db);
                ?>
                       <th width="24%" rowspan="3" align="left" nowrap="nowrap"><strong>Address</strong></th>
                       <td width="27%"><input name="partyaddress1" type="text" value="<?php echo $client_row['pre_address1'];?>" size="25"  style="width:100%;"/></td>
                  </tr>
                <tr>
                  <th align="left">Valid Till</th>
                  <td><input name="validTill" type="text" value="<?php if(isset($_REQUEST['validTill'])){echo $_REQUEST['validTill'];} else {echo date('d/m/Y');}?>" size="12" class="datepicker"  style="width:100%;"/></td>
                  <td><input name="partyaddress2" type="text" value="<?php echo $client_row['pre_address2'];?>" size="25"  style="width:100%;"/></td>
                  </tr>
             <tr>
               <th width="21%" align="left" nowrap="nowrap"><strong>Send to PPC</strong></th>
               <td nowrap="nowrap" width="28%">
                 <select name="enquiryNo" style="width:100%;" onchange="showEnqDetails(this.value)">
                   <option value="Yes">Yes</option>
                   <option value="No">No</option>
                   </select></td>
               <td><input name="partyaddress3" type="text" value="<?php echo $client_row['pre_address3'];?>" size="25"  style="width:100%;"/></td>
                  </tr>
         </table>
         </div>
        </td>
        </tr>
    </table>
<?php 
}
if($_REQUEST['Directclient']!='')
{	
	?>
	<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">
    <tr>
        <td nowrap="nowrap" colspan="2" width="50%" valign="top">
        <div id="enquiryId" style="width:100%; margin:0 auto;">
            <table width="100%" cellpadding="2" cellspacing="1" border="0">
                <tr>
                  <th align="left">Valid Till</th>
                  <td><input name="validTill" type="text" value="<?php if(isset($_REQUEST['validTill'])){echo $_REQUEST['validTill'];} else {echo date('d/m/Y');}?>" size="12" class="datepicker"  style="width:100%;"/></td>
                <?php 
                $client_sql=DB_query("Select pre_address1,pre_address2,pre_address3,pre_country,pre_state,pre_city from clientmaster where client_code='".$_REQUEST['Directclient']."'",$db);
				$client_row=DB_fetch_array($client_sql,$db);
                ?>
                       <th width="24%" rowspan="3" align="left" nowrap="nowrap"><strong>Address</strong></th>
                       <td width="27%"><input name="partyaddress1" type="text" value="<?php echo $client_row['pre_address1'];?>" size="25"  style="width:100%;"/></td>
                  </tr>
                <tr>
                   <th width="21%" align="left" nowrap="nowrap"><strong>Send to PPC</strong></th>
               <td nowrap="nowrap" width="28%">
                 <select name="enquiryNo" style="width:100%;" onchange="showEnqDetails(this.value)">
                   <option value="Yes">Yes</option>
                   <option value="No">No</option>
                   </select></td>
                  <td><input name="partyaddress2" type="text" value="<?php echo $client_row['pre_address2'];?>" size="25"  style="width:100%;"/></td>
                  </tr>
             <tr>
               <td width="21%" align="left" nowrap="nowrap"><strong>&nbsp;</strong></td>
               <td nowrap="nowrap" width="28%">&nbsp;
                 </td>
               <td><input name="partyaddress3" type="text" value="<?php echo $client_row['pre_address3'];?>" size="25"  style="width:100%;"/></td>
                  </tr>
         </table>
         </div>
        </td>
        </tr>
    </table><?php 
}
?>