<?php
$PageSecurity = 11;
include "includes/function_lib.php";
include "includes/session.inc";
$data1 = "";
$data2 = "";
$data3 = "";
$data4 = "";
$data5 = "";
$vendorType = $s->getField("suppliers", "id", $_REQUEST["VID"], "vendor_type");
if ($vendorType == "Domestic") {
    $data0 = '<select name="purch_ord_type" id="purch_ord_type">
       <option value="DO">Domestic Order</option></select>';
} else {
    $data0 = '<select name="purch_ord_type" id="purch_ord_type">
       <option value="IO">Import Order</option></select>';
}
$sqlConPerSon = DB_query("select * from contact_information_master where master_code='" . $_REQUEST["VID"] . "' and master_prefix='S' ORDER BY person", $db);
$data4 .= "<select name='contact_person' id='contact_person' onchange='GetMobileNo(this.value)'>";
//$data4.="<option value=''>Select</option>";
while ($ConPerDetails = DB_fetch_array($sqlConPerSon)) {
    $data4 .= "<option value='" . $ConPerDetails["id"] . "'>" . $ConPerDetails["person"] . "</option>";
}
$data4 .= "</select>";
// $sqlConPerSon=DB_fetch_array(DB_query("select phone from contact_information_master where master_code='".$_REQUEST['VID']."' and master_prefix='S' ORDER BY person LIMIT 0,1",$db));
// $data5=$sqlConPerSon['phone'];
$resultPhone = DB_query("SELECT phone FROM contact_information_master WHERE master_code='" . $_REQUEST["VID"] . "' AND master_prefix='S'  ORDER BY person LIMIT 1", $db);

$sqlConPerSon = DB_fetch_array($resultPhone);
$data5 = $sqlConPerSon["phone"];
$SQLVend = DB_query(
    "select * from suppliers where id='" . $_REQUEST["VID"] . "'",
    $db
);
$VindoeDetails = DB_fetch_array($SQLVend);

if ($vendorType == "Domestic") {
    $data3 .= "Delivery";
} else {
    $data3 .= "Shipping";
}

if ($vendorType == "Domestic") {
    $data1 .=
        "<table width='100%' cellpadding='2' cellspacing='0' border='0' id='tableDataProduction' class='thborder'>";
    $data1 .= "<tr>";
    $data1 .= '<th width="1%">S.No.</th>';
    $data1 .= "<th width='1%'></th>";
    $data1 .= '<th width="10%">Item Code</th>';
    $data1 .= '<th width="10%">Item Name</th>';
    $data1 .= '<th width="5%">Brand</th>';
    $data1 .= '<th width="5%">Pack Qty</th>';
    $data1 .= '<th width="4%">UOM</th>';
    $data1 .= '<th width="4%">Qty.</th>';
    $data1 .= '<th width="5%">Purchase Rate</th>';
    $data1 .= '<th width="5%">MRP</th>';
    $data1 .= '<th width="5%">Free Qty</th>';
    $data1 .= '<th width="5%">Total Price</th>';
    $data1 .=
        '<th width="8%" colspan="2" class="text-center">Discount</th>';
    //$data1.='<th width="5%">Discount Amount</th>';
    $data1 .= '<th width="5%">Basic Amount</th>';
    // $data1.='<th width="4%">Pkg Charges</th>';
    // $data1.='<th width="4%">Excise flag</th>';
    // $data1.='<th width="4%">Excise</th>';
    // $data1.='<th width="4%">Excise Value</th>';
    // $data1.='<th width="4%">E-Cess</th>';
    // $data1.='<th width="4%">E-Cess Value</th>';
    // $data1.='<th width="4%">SAH-E Cess</th>';
    // $data1.='<th width="4%">SAH-E Cess Value</th>';
    // $data1.='<th width="5%">Excise Amt.</th>';
    $data1 .= '<th width="4%">Freight and P&S</th>';
    //$data1.='<th width="4%">Input Vat/Cst</th>';
    $data1 .= '<th width="6%">GST</th>';
    $data1 .= '<th width="4%">Value</th>';
    // $data1.='<th width="1"></th>';
    // $data1.='<th width="4%">Surcharge %</th>';
    // $data1.='<th width="4%">Surcharge Amt</th>';
    $data1 .= '<th width="4%">Total Amt.</th>';
    $data1 .= "</tr>";

    $data1 .= "<tbody id='dataTable'>";
    $data1 .= "<tr>";
    $data1 .= "<td id='first_row'><input type='checkbox'  /></td>";
    $data1 .= "<td><input type='hidden'  name='mst_itemid[]' id='itemid_1'  /></td>";
    $data1 .= "<td width='10%'><input  type='text'   id='itemcode_1'  readonly='' /></td>";
    $data1 .= "<td width='10%'><input  type='text'  id='itemname_1'  readonly='' /></td>";
    $data1 .= "<td  width='5%'><input type='text'  id='brand_1'  readonly='' /></td>";
    $data1 .= "<td width='5%'><input  type='text'   name='equivalentqty[]' id='equivalentqty_1'  readonly='' /></td>";
    $data1 .= "<td width='4%'><input  type='text'  id='itemunit_1'  readonly='' /></td>";
    $data1 .= "<td width='4%'><input   onkeyup='' autocomplete='off' type='text' name='Quantity[]' id='qty_1' onkeypress='return isNumberKey(event)'  class='get_tot' /></td>";
    $data1 .= "<td width='5%'><input  autocomplete='off' onkeyup='calcTotAmtInt(this.value,this.id);' onkeypress='return isNumberKey(event)' type='text' name='Rate[]' id='rate_1' class='' /></td>";
    $data1 .= "<td width='5%'><input  autocomplete='off' onkeypress='return isNumberKey(event)' type='text' name='Mrp[]' id='mrp_1' class='' /></td>";
    $data1 .= "<td width='5%'><input  type='text' name='freeqty[]' id='freeqty_1'   /></td>";
    $data1 .= "<td width='5%'><input  type='text' name='totalPrice[]' id='price_1' readonly='true' class='tot_price'/></td>";
    $data1 .= "<td width='4.5%'><select   name='DiscountType[]' id='PerAmo_1' class='item_PerAmo' onchange='DiscountAmounts(this.value,this.id)' >";
    $data1 .= "<option value='Amount'>Amt</option>";
    $data1 .= "<option value='PercentAmt'>%</option>";
    $data1 .= "</select></td>";
    $data1 .= "<td width='3.5%'><input  type='text'  onkeyup='DiscountAmountsInt(this.value,this.id)' autocomplete='off' name='Discount[]' onkeypress='return isNumberKey(event)' id='Discount_1' class='discount_item'  /></td>";
    /*$data1.="<td><input type='text' name='discounted_amount[]'  id='discounted_amount_1'   class='discounted_item_price'  readonly/></td>";*/
    $data1 .= "<td width='5%'><input  type='text' id='basic_1' name='basic_Amt[]' class='basic'  readonly   value='0' class='total_item_amount'/></td>";
    //$data1.="<td><input type='text' id='pkgamt_1' name='pkg_Amt[]'   onkeyup='pkgamt(this.id)'   value='0' class='pkgamt'/></td>";
    //  $data1.="<td><select name='Excise_type[]'  id='hidBillingType_1'
    // 		           onchange='checkExcisable(this.value,this.id)'><option value=''>Select</option>
    // 				  <option value='NonExcisable'>NonExcisable</option>
    // 				  <option value='Excisable'>Excisable</option>
    // 				  <option value='IncludeTax'>IncludeTax</option>
    // 				  </select></td>";
    // 		 $data1.="<td><select name='Excise_Duty[]' id='exciseDuty_1' onfocus='checkexiseflag(this.id)'
    //                            onchange='claculateExcise(this.id,this.value)'>
    //                          <option value=''>Select</option>";
    //   $excise_sql=DB_query("select * from excise_tax where ledgertype like'%excisetax%' and form_type='Purchase' group by caption",$db);
    //   while($excise_row=DB_fetch_array($excise_sql))
    //   {
    //   $g='';
    //   if($Excise_Duty==$excise_row['id'])
    //   {$g='selected';}
    //     $data1.="<option value='".$excise_row['id']."'>".$excise_row['caption']."</option>";
    //   }
    //      $data1.="</select></td>";
    // $data1.="<td><input name='exciseValue[]' readonly class='excise' id='exciseValue_1' value='' type='text'  /></td>";
    $cessLedgerSql1 = DB_query("Select * from excise_tax where ledgertype like '%cess%' group by caption", $db);
    $cessLedgerSql2 = DB_query("Select * from excise_tax where ledgertype like'%scess%' group by caption ", $db);
    //   $data1.="<td><select name='Cess_ID[]' id='cessID1_1' onfocus='checkexiseflag(this.id)' onchange='calEcessonchange(this.id,this.value)' >";
    //   $data1.="<option value=''>Select</option>";
    //   $cessLedger1=DB_fetch_array($cessLedgerSql1);
    //   if(DB_num_rows($cessLedgerSql1)>0)
    //   $data1.="<option value=".$cessLedger1['id'].">".$cessLedger1['caption']."</option>";
    //   else
    //   //$data1.="<option value=''></option>";
    //   $data1.="</select></td>";
    //$data1.="<td><input name='ECessValue[]' class='ecess' readonly id='ECessValue_1' type='text'  readonly /></td>";
    //   $data1.="<td><select name='SHECess_ID[]' id='cessID2_1'  onfocus='checkexiseflag(this.id)' onchange='calSHEcessonchange(this.id,this.value)'>";
    //   $data1.="<option value=''>Select</option>";
    //   $cessLedger2=DB_fetch_array($cessLedgerSql2);
    //   if(DB_num_rows($cessLedgerSql2)>0)
    //   $data1.="<option value=".$cessLedger2['id'].">".$cessLedger2['caption']."</option>";
    //   else
    //    //$data1.="<option value=''></option>";
    //    $data1.="</select></td>";
    //$data1.="<td><input name='SAHCessValue[]' class='shecess' id='SAHCessValue_1' type='text'  readonly /></td>";
    //   $data1.="<td><input type='text' name='taxable_amt[]' id='taxableAmt_1'  onfocus='calculateTaxable(this.id)'
    //    readonly/></td>";
    $data1 .= "<td width='4%'><input  type='text' name='freightItem[]' class='freight' id='freightItem_1'  
   	   onkeyup='tax_rate2(this.value,this.id)' /></td>";
    //$data1.="<td><input type='hidden' name='' id='vatdes_1'  readonly > </td>";
    //$data1.="<td><input type='text' name='' id='vatPer_1'  readonly > </td>";
    $data1 .= "<td width='6%'><select  name='inputVat[]' id='inputVat_1' onfocus='checkexiseflag(this.id)' onchange='tax_rate3(this.value,this.id)'>
   	  	<option>Select GST</option>
   	  	</select>
   	  </td>";
    //$data1.="<td><input type='hidden' name='inputVat[]' id='inputVat_1'></td>";
    $data1 .= "<td width='4%'><input  type='text' name='taxvalue1[]' class='vat' id='taxvalue_1'  value='' readonly='true'/></td>";
    //$data1.="<td><input type='hidden' name='surchargeper[]'  id='surchargeper_1'  value='' readonly='true'/></td>";
    // $data1.="<td><input type='text' name='' id='surchargeperDisp_1'></td>";
    //$data1.="<td><input type='text' name='surchargeamt[]' class='surcharge' id='surchargeamt_1'  value='' readonly='true'/></td>";
    $data1 .= "<td width='4%'><input  type='text' id='TotalSpecial_1' onfocus='cal_grandtotal(this.id)' name='TotalAmount[]'  readonly class='TotalSpecial' value='0'/></td>";
    $data1 .= "</tr>";
    $data1 .= "</tbody>";
    $data1 .= "</table>";

    $data2 .= "<table width='100%' border='0' cellspacing='0' cellpadding='3'>
                   <tr class='row1'>
   	                  <td width='36%' align='right'>Total Amount</td>
   	                  <td><input type='text' name='basic_amt' readonly id='total_item_amount'  value='' /></td>
                  	</tr>   
                   <!--<tr class='row1'>
   			        <td align='right'>Pkg Charges</td>
   			        <td> <input name='pkg_charges' readonly id='pkg_charges1' type='text' value=''   /></td>
   	         	</tr>       
           <tr class='row1'>
           <td align='right'>Excise Duty</td>
           <td><input type='text' name='excise_amt' id='excise_duty_val' value=''   readonly='true'/></td>
            </tr>
           <tr class='row1'>
            <td align='right'>Ecess</td>
            <td><input type='text' name='ecess_amt' id='ecess_val'  value=''  readonly='true'/></td>
            </tr>
            <tr class='row1'>
            <td align='right'>SHEcess</td>
             <td><input type='text' name='shecess_amt' id='shecess_val'   readonly='true'/></td>
             </tr> -->
             <tr class='row1'>
           <td align='right'>Freight And P&amp;S</td>
           <td><input type='text' name='Freight' id='TotalCharge'  value=''  readonly='true'/></td>
           </tr>
           <tr class='row1'>
           <td align='right'>GST</td>
           <td><div id='taxval'><input type='text' name='vat_amt' id='taxvalue'    readonly='true'/></div></td>
           </tr>
           <!--<tr class='row1'>
           <td align='right'>Surcharge</td>
           <td><input type='text' name='surcharge_amt' id='sur_oct_amt'    readonly='true'/></td>
           </tr>-->
           <tr class='row1'>
           <td align='right'>Insurance </td>
           <td><input name='insr_amt' id='insurance' type='text'   onkeyup='cal_total_grand()' /></td>
         	</tr>
          <tr class='row1'>
          <td align='right'>Miscellaneous</td>
          <td><input type='text'  name='other_amt' id='miscellaneous'  onkeyup='cal_total_grand()'/></td>
          </tr>	             
        	<tr class='row1'>
   			<td align='right'>Round Off</td>
   		    <td><input type='text' name='pluMin' readonly id='pluMin' style='width:23%;' /> <input type='text' name='roundVal' readonly  id='roundVal' style='width:74%;' />
   		    </td>
   		</tr>
   		<tr class='row1'>
   			<td align='right'>Grand Total</td>
   		    <td><input type='text' name='GrandTotal' readonly id='GrandTotal' value=''/></td>
   		</tr>
   		</table>";

    $data6 .= '<table width="100%" border="0" cellspacing="0" cellpadding="3" align="left" >
   	<tr class="row1"><td align="right" width="13%">Remarks</td><td><textarea name="remarks"></textarea></td></tr>
   			<tr class="row1">
   				<td style="text-align:center;" colspan="2">Terms And Conditions</td>
   			</tr>';
    //$data2= "SELECT * FROM terms_condition where parant_id=0 and frm_id='".$_REQUEST['frmid']."' and CompanyId='".$_SESSION['ACGCompanyId']."'";
    $i = 0;
    $SQLTerms = DB_query("SELECT * FROM terms_condition where parant_id=0 and frm_id='" . $_REQUEST["frmid"] . "' and CompanyId='" . $_SESSION["ACGCompanyId"] . "'", $db);
    while ($TermsAndCond = DB_fetch_array($SQLTerms)) {
        $data6 .= '<tr class="row1"><td align="right">' . $TermsAndCond["terms_conditions"] . '<input type="hidden" name="terms[]" id="terms" value="' . $TermsAndCond["id"] . '" /><td><td><select name="Terms_Condition[]" id="Terms_Condition" style="width:100%"><option value="">Select</option>';
        $SQLCond = DB_query("SELECT * FROM terms_condition where parant_id='" . $TermsAndCond["id"] . "' and frm_id='" . $_REQUEST["frmid"] . "' and CompanyId='" . $_SESSION["ACGCompanyId"] . "'", $db);
        while ($GetCond = DB_fetch_array($SQLCond)) {
            $data6 .= '<option value="' . $GetCond["id"] . '">' . $GetCond["terms_conditions"] . "</option>";
        }
        $data6 .= "</select></td> </tr>";
        $i++;
    }
    $data6 .= "</table>";
}

//**********************************************************************************************************************

if ($vendorType == "International") {
    $data1 .= "<table width='100%' cellpadding='3' cellspacing='0' border='0' class='thborder'>";
    $data1 .= "<tr>";

    $data1 .= '<th width="1%">S. No.</th>';
    $data1 .= '<th width="0.1%"></th>';
    $data1 .= '<th width="10%">Item Code</th>';
    $data1 .= "<th width:'10%'>Item Name</th>";
    $data1 .= '<th width="4%">UOM</th>';
    $data1 .= '<th width="0.1%" colspan="2"><!--Specification--></th>';
    $data1 .= '<th width="4%">Qty.</th>';
    $data1 .= '<th width="6%">Quoted Rate </th>';
    $data1 .= '<th width="6%">Amount</th>';
    $data1 .= '<th width="8%" colspan="2" class="text-center">Discount</th>';
    $data1 .= '<th width="4%">Basuc Amount</th>';
    $data1 .= '<th width="4%">Discounted Amount</th>';
    $data1 .= '<th width="5%">Currency </th>';
    $data1 .= '<th width="10%">Remarks</th>';
    $data1 .= "</tr>";
    $data1 .= "<tbody id='dataTable'>";
    $data1 .= "<tr>";
    $data1 .= "<td><input type='checkbox'  /></td>";
    $data1 .= "<td width='0.1%'><input type='hidden' name='mst_itemid[]' id='itemid_1' /></td>";
    $data1 .= "<td width='10%'><input type='text'  id='itemcode_1'  readonly='' /></td>";
    $data1 .= "<td width='10%'><input type='text' id='itemname_1'  readonly='' /></td>";
    $data1 .= "<td width='4%'><input type='text' name='itemunit[]' id='itemunit_1'  readonly='' /></td>";
    $data1 .= "<td width='0.1%'><!--<select  name='itemgrade[]' id=''><option value='' >select</option>";
    $grade_sql = DB_query("SELECT * FROM product_grade ", $db);
    while ($grade_res = DB_fetch_assoc($grade_sql)) {
        $data1 .= "<option value='" . $grade_res["id"] . "'>" . $grade_res["grade"] . "</option>";
    }
    $data1 .= "<select/>--></td>";
    $data1 .= "<td width='0.1%'><!--<select  name='itemsize[]' id=''><option value='' >select</option>";
    $size_sql = DB_query("SELECT * FROM size_master WHERE CompanyId='" . $_SESSION["ACGCompanyId"] . "'", $db);
    while ($size_res = DB_fetch_assoc($size_sql)) {
        $data1 .= "<option value='" . $size_res["id"] . "'>" . $size_res["size"] . "</option>";
    }
    $data1 .= "<select/>--></td>";
    $data1 .= "<td width='4%'><input type='text' autocomplete='off' onkeyup='calculateFull_import(this);' name='Quantity[]' onkeypress='return isNumberKey(event)' id='Quantity_1' /></td>";
    $data1 .= "<td width='6%'><input type='text' autocomplete='off' name='Rate[]' onkeypress='return isNumberKey(event)' id='Rate_1' onkeyup='calculateFull_import(this);' /></td>";
    $data1 .= "<td width='6%'><input type='text' name='totalPrice[]' id='totalValue_1' readonly='true'/></td>";
    $data1 .= "<td width='4.5%'><select  name='DiscountType[]' id='PerAmo_1'  onchange='calculateFull_import(this);' >";
    $data1 .= "<option value='Amount'>Amt</option>";
    $data1 .= "<option value='PercentAmt'>%</option>";
    $data1 .= "</select></td>";
    $data1 .= "<td width='3.5%'><input type='text'  autocomplete='off' name='Discount[]' id='Discount_1' onkeypress='return isNumberKey(event)' onkeyup='calculateFull_import(this);' /></td>";
    $data1 .= "<td width='4%'><input type='text'  id='TotalSpecial_1' class='total_item_amount' name='basic_Amt[]' readonly /></td>";
    $data1 .= "<td width='4%'><input type='text' name='discounted_amount[]' id='discounted_amount_1'    readonly/></td>";
    $data1 .= "<td width='5%'><select name='currency[]' ><option value='0'>Select</option>";
    $sql_currency = DB_query("select * from currency_master where CompanyId='" . $_SESSION["ACGCompanyId"] . "'", $db);
    while ($row_currency = DB_fetch_array($sql_currency)) {
        $data1 .= "<option value='" . $row_currency["id"] . "'>" . $row_currency["abbreviation"] . "</option>";
    }
    $data1 .= "</select></td>";
    $data1 .= "<td width='10%'><input type='text'  id='remarks' class='total_item_amount' name='item_remarks[]'  /></td>";
    $data1 .= "</tr>";
    $data1 .= "</tbody>";
    $data1 .= "</table>";
    $data2 .= "<table width='100%' border='0' cellspacing='0' cellpadding='3'>";
    $data2 .= "<tr class='row1'>";
    $data2 .= "<td align='right'>Basic Amount</td>";
    $data2 .= "<td><input name='basic_amt' id='total_item_amount'  readonly></td>";
    $data2 .= "</tr>";
    $data2 .= "<tr class='row1'>";
    $data2 .= "<td align='right'>Discount</td>";
    $data2 .= "<td><input type='text' name='' placeholder='Percent' id='discount_percent' onkeypress='return isNumberKey(event)' onkeyup='cal_po_charges_import(this)'  >
   	<input type='text' name='discount_amt' onkeypress='return isNumberKey(event)' id='discount_amt' placeholder='Amount' onkeyup='cal_po_charges_import(this)'   ></td>";
    $data2 .= "</tr>";
    $data2 .= "<table width='100%' border='0' cellspacing='0' cellpadding='3'>";
    $data2 .= "<tr class='row1'>";
    $data2 .= "<td align='right'>Discounted Amount</td>";
    $data2 .=
        "<td><input name='discounted_amt' id='discnted_amt'  readonly > <input name='total_po_amt' id='total_po_amt' type='text'  readonly /> </td>";
    $data2 .= "</tr>";

    $data2 .= '<tr class="row1">';
    $data2 .= '<td align="right">Round Off</td>';
    $data2 .=
        '<td><input type="text" name="pluMin" readonly id="pluMin" style="width:50px;" />';
    $data2 .=
        '<input type="text" name="roundVal" readonly  id="roundVal" style="width:100px;"/>';
    $data2 .= "</td>";
    $data2 .= "</tr>";

    $data2 .= '<tr class="row1">';
    $data2 .= '<td align="right">Grand Total</td>';
    $data2 .=
        '<td><input type="text" name="GrandTotal" readonly id="GrandTotal"  style="width:150px;" />';
    $data2 .= '<input type="hidden"  id="orig_grand_tot" />';
    $data2 .= "</td>";
    $data2 .= "</tr>";

    $data2 .= "</table>";
    $data6 .= '<table width="100%" border="0" cellspacing="0" cellpadding="3" style="valign:top" align="left">
   		<tr class="row1" ><td width="13%" align="right">Remarks</td><td><textarea name="remarks"></textarea></td></tr>
   			<tr class="row1">
   				<td style="text-align:center;" colspan="2">Terms And Conditions</td>
   			</tr>';
    //$data2= "SELECT * FROM terms_condition where parant_id=0 and frm_id='".$_REQUEST['frmid']."' and CompanyId='".$_SESSION['ACGCompanyId']."'";
    $i = 0;
    $SQLTerms = DB_query("SELECT * FROM terms_condition where parant_id=0 and frm_id='" . $_REQUEST["frmid"] . "' and CompanyId='" . $_SESSION["ACGCompanyId"] . "'", $db);
    while ($TermsAndCond = DB_fetch_array($SQLTerms)) {
        $data6 .= '<tr class="row1"><td>' . $TermsAndCond["terms_conditions"] . '<input type="hidden" name="terms[]" id="terms" value="' . $TermsAndCond["id"] . '" /></td><td><select name="Terms_Condition[]" id="Terms_Condition" style="width:100%">
   						<option value="">Select</option>';
        $SQLCond = DB_query("SELECT * FROM terms_condition where parant_id='" . $TermsAndCond["id"] . "' and frm_id='" . $_REQUEST["frmid"] . "' and CompanyId='" . $_SESSION["ACGCompanyId"] . "'", $db);
        while ($GetCond = DB_fetch_array($SQLCond)) {
            $data6 .= '<option value="' . $GetCond["id"] . '">' . $GetCond["terms_conditions"] . "</option>";
        }
        $data6 .= "</select></td> </tr>";
        $i++;
    }
    $data6 .= "</table>";
}
echo $data = $data0 . "__" . $data1 . "__" . $data2 . "__" . $data3 . "__" . $data4 . "__" . $data5 . "__" . $data6;
