<?php
include '../global-connect/global-connect.php';
include '../functions/inc.php';
$user=$_COOKIE[$info1000['software_version'].'user'];
session_start();
$eid=$info['id'];
$role=$_COOKIE[$info1000['software_version'].'role'];
$loginuser=$_COOKIE[$info1000['software_version'].'uid'];
$onrecord_id=$_COOKIE[$info1000['software_version'].'onrecord_id'];
$on_record = 1;
$current_company=$_COOKIE[$info1000['software_version'].'multi_company'];
$current_company2=$_COOKIE[$info1000['software_version'].'multi_company2'];
$current_zone=$_COOKIE[$info1000['software_version'].'current_zone'];
$current_warehouse=$_COOKIE[$info1000['software_version'].'current_warehouse'];
$current_costcenter=$_COOKIE[$info1000['software_version'].'cost_center']; 
$current_costcenter2=$_COOKIE[$info1000['software_version'].'cost_center2']; 
include('../functions/limit-multi.php');
$data87 = mysqli_query($conn,"SELECT * FROM user_access_control WHERE eid='$role'") or die(mysqli_error($conn));       
$info87 = mysqli_fetch_array( $data87 );
if($info2000['en_storespares']==1) {
  $type_component=2;
}else{
  $type_component=0;
}

if(!function_exists('bms_customer_old_receivable_amount')) {
  function bms_customer_old_receivable_amount($cid, $mode='simple') {
    global $info2000, $info4000;

    $cid = (int)$cid;
    if($cid <= 0) {
      return 0.0;
    }

    if(isset($info2000['customervendor_same']) && (int)$info2000['customervendor_same'] === 1) {
      $net = (float)customeroldreceivablemulticurrency($cid);
      return ($net > 0) ? $net : 0.0;
    }

    if($mode === 'detailed') {
      $pending_sales_sum = (float)mysqli_get_var("SELECT COALESCE(SUM(pending_amount),0) FROM sales WHERE customer_id='$cid'");
      $advance_payment_sum = (float)mysqli_get_var("SELECT COALESCE(SUM(advance_payment),0) FROM customer WHERE id='$cid'");
      $pending_debit_note_sum = (float)mysqli_get_var("SELECT COALESCE(SUM(pending_amount),0) FROM sales_debit_note WHERE cid='$cid'");
      $opening_balance = (float)mysqli_get_var("SELECT COALESCE(SUM(CASE WHEN COALESCE(ob,0)!=0 THEN oba ELSE COALESCE(ob,0) END),0) FROM customer WHERE id='$cid'");

      $payment_received_sum = 0;
      if($info4000['en_hotel']==1) {
        $payment_received_sum = (float)mysqli_get_var("SELECT COALESCE(SUM(amount),0) FROM payment_received WHERE cid='$cid'");
      }

      $tot_pending = $pending_sales_sum + $pending_debit_note_sum - $advance_payment_sum - $payment_received_sum + $opening_balance;

      $ledger_sales_sum = (float)mysqli_get_var("SELECT COALESCE(SUM(total),0) FROM sales WHERE customer_id='$cid'");
      $ledger_debit_note_sum = (float)mysqli_get_var("SELECT COALESCE(SUM(total),0) FROM sales_debit_note WHERE cid='$cid'");
      $ledger_sales_return_sum = (float)mysqli_get_var("SELECT COALESCE(SUM(total_amount),0) FROM sales_return WHERE customer_id='$cid'");
      $ledger_sales_credit_sum = (float)mysqli_get_var("SELECT COALESCE(SUM(total),0) FROM sales_credit_note WHERE cid='$cid'");
      $ledger_payment_received_sum = (float)mysqli_get_var("SELECT COALESCE(SUM(amount),0) FROM payment_received WHERE cid='$cid'");
      $ledger_cash_adjustment_sum = (float)mysqli_get_var("SELECT COALESCE(SUM(debit-credit),0) FROM cash_transaction WHERE user_id='$cid' && user_type=1 && `show`=1 && (debit!=0 || credit!=0)");
      $ledger_tot = $ledger_sales_sum + $ledger_debit_note_sum - $ledger_sales_return_sum - $ledger_sales_credit_sum - $ledger_payment_received_sum + $ledger_cash_adjustment_sum + $opening_balance;

      $tot = $tot_pending;
      if((float)$tot == 0.0 && (float)$ledger_tot != 0.0) {
        $tot = $ledger_tot;
      }
      if($tot < 0) { $tot = 0; }
      return (float)$tot;
    }

    return (float)customeroldreceivable($cid);
  }
}

if(!function_exists('bms_vendor_old_payable_amount')) {
  function bms_vendor_old_payable_amount($cid, $po_id = 0) {
    global $conn, $info2000;

    $cid = (int)$cid;
    $po_id = (int)$po_id;

    if($cid <= 0) {
      return 0.0;
    }

    if(isset($info2000['customervendor_same']) && (int)$info2000['customervendor_same'] === 1) {
      $net = (float)customeroldreceivablemulticurrency($cid);
      $tot = ($net < 0) ? ($net * -1) : 0.0;
    } else {
      $data34 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM purchasing WHERE vendor_id='$cid'") or die(mysqli_error($conn));
      $info34 = mysqli_fetch_array($data34);
      $data40 = mysqli_query($conn,"SELECT SUM(advance_payment) as sum FROM vendor WHERE id='$cid'") or die(mysqli_error($conn));
      $info40 = mysqli_fetch_array($data40);
      $data38 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM purchase_credit_note WHERE vid='$cid'") or die(mysqli_error($conn));
      $info38 = mysqli_fetch_array($data38);
      $data36 = mysqli_query($conn,"SELECT ob FROM vendor WHERE id='$cid'") or die(mysqli_error($conn));
      $info36 = mysqli_fetch_array($data36);
      $tot = $info34['sum'] + $info38['sum'] + $info36['ob'] - $info40['sum'];
    }

    if($po_id != 0 && isset($info2000['en_qandflavours']) && (int)$info2000['en_qandflavours'] === 1) {
      $total_amount = (float)mysqli_get_var("SELECT total_amount FROM po WHERE id = '$po_id' ");
      $pay_term_per = (float)mysqli_get_var("SELECT advance FROM payment_terms WHERE id IN ( SELECT payment_terms FROM po WHERE id = '$po_id' ) ");
      $tot += ($total_amount/100)*$pay_term_per;
    }

    if($tot < 0) {
      $tot = 0;
    }

    return (float)$tot;
  }
}

 if(isset($_POST['stichingprice']))
{
$ssss = $_POST['stichingprice'];
$data337 = mysqli_query($conn,"SELECT rate FROM stitching_type WHERE id='$ssss'") or die(mysqli_error($conn));       
$info337 = mysqli_fetch_array( $data337 );  
$nn = $info337['rate'];
 $advert = array(
        'ajax' => $nn,
        'advert' => 3,
     );
    echo json_encode($advert);
}
else if(isset($_POST['cnid']))
{
$cid=test_input($_POST['cnid']);
$data34 = mysqli_query($conn,"SELECT id, total FROM sales WHERE customer_id='$cid'") or die(mysqli_error($conn));      ?>
Invoice #
<select name="invoice" class="form-control">
    <?php while($info34 = mysqli_fetch_array( $data34 )){
echo "<option value='".$info34['id']."' >".$info34['id']." ( ".$info34['total']." )</option>"; 
}
?>
</select>
<br />
<?php }


else if(isset($_POST['deliverya']))
{


$deliverya=test_input($_POST['deliverya']);


 $data4 = mysqli_query($conn,"SELECT charges, delivery_time from customer_zone where id='$deliverya'") or die(mysqli_error($conn)); 

$info4 = mysqli_fetch_array( $data4 );
  
   
?>

<input name="delivery_charges" type="text" class="form-control areachange delivery_charges" id="delivery_charges"  value="<?php if($info4['charges']!='') echo $info4['charges']*-1; else echo 0;?>"  />
<input name="area_time" type="hidden" class="form-control area_time" id="area_time" value="<?php if($info4['delivery_time']!='') echo $info4['delivery_time']; else echo 0;?>"  />
<script type="text/javascript">
var cc2 = $('#delivery_charges').val();
if(cc2!='') {
    $('#delivery_charges').trigger('change');
}
</script>
<?php 
}

else if(isset($_POST['deliveryadd']))
{

$deliverya=test_input($_POST['deliveryadd']);


 $data4 = mysqli_query($conn,"SELECT charges, delivery_time from customer_zone aa, customer_address a where a.area=aa.id && a.id='$deliverya' "); 

$info4 = mysqli_fetch_array( $data4 );
  
   
?>

<input name="delivery_charges" type="text" class="form-control delivery_charges" id="delivery_charges" value="<?php if($info4['charges']!='') echo $info4['charges']*-1; else echo 0;?>"  />
<input name="area_time" type="hidden" class="form-control area_time" id="area_time" value="<?php if($info4['delivery_time']!='') echo $info4['delivery_time']; else echo 0;?>"  />

<script type="text/javascript">
var cc2 = $('#delivery_charges').val();
if(cc2!='') {
    $('#delivery_charges').trigger('change');
}
</script>
<?php 
}
else if(isset($_POST['custprd']))
{
$custn=test_input($_POST['custprd']);
$brand = mysqli_get_var("Select company_name from user where id='$custn'");
$brandid = mysqli_get_var("Select id from product_brands where name='$brand'");
if($brandid=='') {  
$sql2 = "Insert into product_brands (name) VALUES ('$brand')";
$retval = mysqli_query($conn, $sql2 ) or die(mysqli_error($conn)); 
$brandid = mysqli_get_var("Select max(id) from product_brands");
 }
?>
<span id="dis">
    <?php $data = mysqli_query($conn,"SELECT id,name,sku from inventory where inactive=0 && brand_id='$brandid' && type_id=1 order by name") or die(mysqli_error($conn)); 
 $data2 = mysqli_query($conn,"SELECT id,name from deal where inactive=0  order by name") or die(mysqli_error($conn)); 
echo "<select name='teacher_id'  tabindex='3' id='searchbox'  accesskey='s'  class='combobox form-control'   >";
echo "<option value=''>Select a ".$info1000['product_label']."</option>";
 while($info = mysqli_fetch_array( $data )) 
 { 
   echo "<option value='".$info['id']."' >".$info['sku'].' '.$info['name']."</option>";
}
 while($info2 = mysqli_fetch_array( $data2 )) 
 { 
   echo "<option value='".$info2['id']."' >".$info2['name']."</option>";
}
echo "</select>";
?>
</span>
<br />
<?php }
else if(isset($_POST['custprd5']))
{
$custn=test_input($_POST['custprd5']);
$brand = mysqli_get_var("Select company_name from user where id='$custn'");
$brandid = mysqli_get_var("Select id from product_brands where name='$brand'");
?>
<span id="dis">
    <?php $data = mysqli_query($conn,"SELECT id,name,sku from inventory where inactive=0 && brand_id='$brandid' order by name") or die(mysqli_error($conn)); 
echo "<select name='teacher_id'  tabindex='3' id='itemid'  accesskey='s'  class='combobox form-control'   >";
echo "<option value='a'>All</option>";
 while($info = mysqli_fetch_array( $data )) 
 { 
   echo "<option value='".$info['id']."' >".$info['sku'].' '.$info['name']."</option>";
}
echo "</select>";
?>
</span>
<br />
<?php }
else if(isset($_POST['newprd']))
{
$newprd=test_input($_POST['newprd']);
$custn=test_input($_POST['custn']);
$brand = mysqli_get_var("Select company_name from user where id='$custn'");
$brandid = mysqli_get_var("Select id from product_brands where name='$brand'");
if($brandid=='') {  
$sql2 = "Insert into product_brands (name) VALUES ('$brand')";
$retval = mysqli_query($conn, $sql2 ) or die(mysqli_error($conn)); 
$brandid = mysqli_get_var("Select max(id) from product_brands");
 }
$bq1 = mysqli_get_var("Select name from inventory where brand_id='$brandid' && name='$newprd'");
if($bq1=='') { 
$sql2 = "Insert into inventory (name, brand_id, type_id ) VALUES ('$newprd','$brandid','1')";
$retval = mysqli_query($conn, $sql2 ) or die(mysqli_error($conn));  } else {    }
?>
<span id="dis">
    <?php $data = mysqli_query($conn,"SELECT id,name,sku from inventory where inactive=0 && brand_id='$brandid' && type_id=1 order by name") or die(mysqli_error($conn)); 
 $data2 = mysqli_query($conn,"SELECT id,name from deal where inactive=0  order by name") or die(mysqli_error($conn)); 
echo "<select name='teacher_id'  tabindex='3' id='searchbox'  accesskey='s'  class='combobox form-control'   >";
echo "<option value=''>Select a ".$info1000['product_label']."</option>";
 while($info = mysqli_fetch_array( $data )) 
 { 
   echo "<option value='".$info['id']."' >".$info['sku'].' '.$info['name']."</option>";
}
 while($info2 = mysqli_fetch_array( $data2 )) 
 { 
   echo "<option value='".$info2['id']."' >".$info2['name']."</option>";
}
echo "</select>";
?>
</span> <?php
if($bq1=='') {  echo "<div class='alert alert-success'>New product created</div>";
} else { echo "<div class='alert alert-danger'>Product already Exist</div>";    } ?>
<br />
<?php }
else if(isset($_POST['custprd2']))
{
$custn=test_input($_POST['custprd2']);
$brand = mysqli_get_var("Select company_name from user where id='$custn'");
$brandid = mysqli_get_var("Select id from product_brands where name='$brand'");
if($brandid=='') {  
$sql2 = "Insert into product_brands (name) VALUES ('$brand')";
$retval = mysqli_query($conn, $sql2 ) or die(mysqli_error($conn)); 
$brandid = mysqli_get_var("Select max(id) from product_brands");
 }
?>
<span id="dis">
    <?php $data = mysqli_query($conn,"SELECT id,name,sku from inventory where inactive=0 && brand_id='$brandid' && type_id=2 order by name") or die(mysqli_error($conn)); 
 $data2 = mysqli_query($conn,"SELECT id,name from deal where inactive=0  order by name") or die(mysqli_error($conn)); 
echo "<select name='teacher_id'  tabindex='3' id='searchbox'  accesskey='s'  class='combobox form-control'   >";
echo "<option value=''>Select a ".$info1000['product_label']."</option>";
 while($info = mysqli_fetch_array( $data )) 
 { 
   echo "<option value='".$info['id']."' >".$info['sku'].' '.$info['name']."</option>";
}
 while($info2 = mysqli_fetch_array( $data2 )) 
 { 
   echo "<option value='".$info2['id']."' >".$info2['name']."</option>";
}
echo "</select>";
?>
</span>
<br />
<?php }
else if(isset($_POST['newprd2']))
{
$newprd=test_input($_POST['newprd2']);
$custn=test_input($_POST['custn']);
$brand = mysqli_get_var("Select company_name from user where id='$custn'");
$brandid = mysqli_get_var("Select id from product_brands where name='$brand'");
if($brandid=='') {  
$sql2 = "Insert into product_brands (name) VALUES ('$brand')";
$retval = mysqli_query($conn, $sql2 ) or die(mysqli_error($conn)); 
$brandid = mysqli_get_var("Select max(id) from product_brands");
 }
$bq1 = mysqli_get_var("Select name from inventory where brand_id='$brandid' && name='$newprd'");
if($bq1=='') { 
$sql2 = "Insert into inventory (name, brand_id, type_id ) VALUES ('$newprd','$brandid','2')";
$retval = mysqli_query($conn, $sql2 ) or die(mysqli_error($conn));  } else {    }
?>
<span id="dis">
    <?php $data = mysqli_query($conn,"SELECT id,name,sku from inventory where inactive=0 && brand_id='$brandid' && type_id=2 order by name") or die(mysqli_error($conn)); 
 $data2 = mysqli_query($conn,"SELECT id,name from deal where inactive=0  order by name") or die(mysqli_error($conn)); 
echo "<select name='teacher_id'  tabindex='3' id='searchbox'  accesskey='s'  class='combobox form-control'   >";
echo "<option value=''>Select a ".$info1000['product_label']."</option>";
 while($info = mysqli_fetch_array( $data )) 
 { 
   echo "<option value='".$info['id']."' >".$info['sku'].' '.$info['name']."</option>";
}
 while($info2 = mysqli_fetch_array( $data2 )) 
 { 
   echo "<option value='".$info2['id']."' >".$info2['name']."</option>";
}
echo "</select>";
?>
</span> <?php
if($bq1=='') {  echo "<div class='alert alert-success'>New product created</div>";
} else { echo "<div class='alert alert-danger'>Product already Exist</div>";    } ?>
<br />
<?php }
else if(isset($_POST['cid52']))
{
$cid=test_input($_POST['cid52']);
if($cid=='a')
  $id1 = "";
  else {
$iid1 = str_replace("a, "," ",$cid);    
  $id1 = " AND prd_id IN ($iid1)";
  }
?>
<label class="col-lg-12 control-label">Batch</label>
<br>
<br>
<link href="css/select2.min.css" rel="stylesheet" />
<script src="js/select2.min.js"></script>
<script type="text/javascript">
$('.reportselect').select2();
</script>
<?php }
else if(isset($_POST['cid20']))
{
$cid=test_input($_POST['cid20']);
?>
<div class="text-right"><input type="submit" name="update" value="Save" class="pay btn btn-success" /><br>
    <br>
</div>
<input type="hidden" name="geo_id" value="<?php echo $cid; ?>" />
<table id="tblExport" class="table print table-bordered table-striped table-condensed">
    <thead>
        <tr>
            <th>Town (From)</th>
            <th>Town (To)</th>
            <th>Rate (One way)</th>
            <th>Rate (Two way)</th>
            <th>Stay (Per day)</th>
            <th>Allowed KM</th>
            <th>Google KM</th>
        </tr>
    </thead>
    <?php
   $data2 = mysqli_query($conn,"SELECT t.id as tid, e.id as eid, t.name as tname, e.name as ename from town t, town e  where t.id!=e.id && e.geo_id='$cid' && t.geo_id='$cid'  order by t.id DESC ");
  $test =1;
while($info2 = mysqli_fetch_array( $data2 )) 
 {
   $is=0; 
    ?>
    <tr>
        <td><?php  $tid=$info2['tid']; echo $info2['tname'];?><input type="hidden" name="items[]"
                value="<?php echo $info2['tid'];?>" /></td>
        <td><?php  $eid=$info2['eid']; echo $info2['ename'];?><input type="hidden" name="items2[]"
                value="<?php echo $info2['eid'];?>" /></td>
        <?php
$bid=$info16['id'];
 $data15 = mysqli_query($conn,"SELECT one_way, two_way, stay_accom, total_km, google_km from town_travel where   town_id1='$tid' AND town_id2='$eid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
        <td><input type="text" name="one_way[]" class="income_count" tabindex="1"
                value="<?php echo $info15['one_way'];?>" />
        </td>
        <td><input type="text" name="two_way[]" class="income_count" tabindex="1"
                value="<?php echo $info15['two_way'];?>" />
        </td>
        <td><input type="text" name="stay_rate[]" class="income_count" tabindex="1"
                value="<?php echo $info15['stay_accom'];?>" />
        </td>
        <td><input type="text" name="total_km[]" class="income_count" tabindex="1"
                value="<?php echo $info15['total_km'];?>" />
        </td>
        <td><input type="text" name="google_km[]" class="income_count" tabindex="1"
                value="<?php echo $info15['google_km'];?>" />
        </td>
        <?php } else {  ?>
        <td><input type="text" name="one_way[]" class="income_count" tabindex="1" value="0" /></td>
        <td><input type="text" name="two_way[]" class="income_count" tabindex="1" value="0" /></td>
        <td><input type="text" name="stay_rate[]" class="income_count" tabindex="1" value="0" /></td>
        <td><input type="text" name="total_km[]" class="income_count" tabindex="1" value="0" />
        </td>
        <td><input type="text" name="google_km[]" class="income_count" tabindex="1" value="0" />
        </td>
        <?php } ?>
    </tr>
    <?php } ?>
</table>
<br>
<br>
<?php }






else if(isset($_POST['loadBatchExpiry']))
{
$BatchId=test_input($_POST['loadBatchExpiry']);
$data34 = mysqli_query($conn,"Select exp_date from inventory_batch where `id` = '$BatchId'") or die(mysqli_error($conn));    
$info34 = mysqli_fetch_array( $data34 );
echo $info34['exp_date'];
}
else if(isset($_POST['LoadExpiryHere']))
{
    $Expiry=test_input($_POST['LoadExpiryHere']);
    $pid=test_input($_POST['pid']);
    $batch_w_cost = mysqli_get_var("Select batch_code from inventory_batch where prd_id='$pid' and exp_date='$Expiry' and active=1 and type_component=0 order by id asc limit 1"); 
    if($batch_w_cost!=''){
        echo $batch_w_cost;
    }else{
        $maxbatch = mysqli_get_var("Select batch_code from inventory_batch where prd_id='$pid' order by id desc limit 1");
        // echo $maxbatch;
        preg_match('/^(.*?)(\d+)$/', $maxbatch, $matches);
        $startingPart = $matches[1]==''?'':$matches[1];
        $lastNumbers = $matches[2]==''?0:$matches[2];
        //$NewBatch = $lastNumbers+1;
        $NewBatch = str_pad($lastNumbers + 1, strlen($lastNumbers), '0', STR_PAD_LEFT);
        $NewBatch = $startingPart.$NewBatch;
        echo $NewBatch;

    }
}

else  if(isset($_POST['batch5']))
{
$cid=test_input($_POST['batch5']);
$data34 = mysqli_query($conn,"Select qty from inventory_batch where `id` = '$cid'") or die(mysqli_error($conn));    
$info34 = mysqli_fetch_array( $data34 );
echo $info34['qty'];
 }
else  if(isset($_POST['batch6']))
{
$cid=test_input($_POST['batch6']);
$data34 = mysqli_query($conn,"Select unit_cost from inventory_batch where `id` = '$cid'") or die(mysqli_error($conn));    
$info34 = mysqli_fetch_array( $data34 );
echo $info34['unit_cost'];
 }
else if(isset($_POST['ppid']))
{
$cid=test_input($_POST['ppid']);
$tot = bms_vendor_old_payable_amount($cid);
?>
Old Payable <input name="old" type="text" class="form-control" id="old" value="<?php echo $tot;?>"
    readonly="readonly" />
<br />
<?php } 
else if(isset($_POST['saleold2']))
{
$cid=test_input($_POST['saleold2']);

if($info3000['en_expense']==1) 
{ 
  $statement_id=test_input($_POST['statement_id']);
}
else
{
  $statement_id = 0; 
}

$invoiceid=test_input($_POST['invoiceid']);
$cleartype=test_input($_POST['cleartype']);
$subcust = $_POST['subcust'];
if($subcust!=0 && $subcust!='') { $filtera= "  && sub_customer='$subcust' ";  $filterb= "  && sub_cid='$subcust' ";  }
?>
<div class="bs-example">
    <div class="panel-group" id="accordion">
        <div class="card">
            <div class="card-header">
                <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseTwo" data-bs-target="#collapseTwo">Pending Invoices (Partial
                        Payment)</a>
                </h4>
            </div>
            <div id="collapseTwo" class="card-collapse collapse">
                <div class="card-body oldpaymentheight">
                    <?php 
$total_amt = $total_pending_amt = 0;
if($info3000['en_expense']==1) 
{ 
  if($statement_id == 0)
  {
    $data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount, daily_id, grn_id,sub_customer,currency_total  from sales  where ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=1 ))  && id NOT IN (select invoice_id from statement_details WHERE 1=1 && `type`=0  )  && customer_id='$cid' $filtera ") or die(mysqli_error($conn));
  }
  else {
    $data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount, daily_id, grn_id,sub_customer  from sales  where customer_id IN (select customer_id from statement WHERE id = $statement_id) && ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=1 )) && id IN (select invoice_id from statement_details WHERE sid in (select id from statement where type = 0 && sid = '$statement_id')) && customer_id='$cid' $filtera ") or die(mysqli_error($conn));
  // $data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount, daily_id, grn_id,sub_customer,currency_total  from sales  where customer_id IN (select customer_id from statement WHERE id = $statement_id) && ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=1 )) && id IN (select invoice_id from statement_details WHERE sid = $statement_id) && customer_id='$cid' $filtera ") or die(mysqli_error($conn)); 
}
}
else{
$data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount, daily_id, grn_id,sub_customer,currency_total  from sales  where ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=1 )) && customer_id='$cid' $filtera ") or die(mysqli_error($conn)); }
  $tot=0; 
echo '<table class="table table-bordered" width="80%"> 
  <tr>
  <th colspan="3">
    <label>
      <input type="checkbox" id="distribute_amount" />
      Auto Distribute Amount
    </label>
  </th>
</tr>
  <tr>
  <th>ID/Date</th>';
  if($info4000['en_tradelink']==1){
    echo '<th>Invoice #</th> <th>' . $subCustomerLabel . '</th>';
    }
  if($info1000['en_hassanali'] == 1){ echo '<th>GDN</th>'; }
  if($info2000['multi_currencys']==1) { echo ' <th>Total (Main Currency)</th>'; }else{  echo '<th>Total Amount</th>'; }
  echo '<th>Pending Amount</th>
  <th>Paid Amount</th>
  </tr>'; 
while($info9 = mysqli_fetch_array( $data9 )) 
 { ?>
                    <tr>
                        <td>
                            <?php  
      $eid =  $info9['id'];
      $link = rtrim($info1000['printview_slug'], '/')."/sales/print-si.php?sid=".$info9['id'];
      ?>
                            <a href="<?php echo $link ?>" target="blank">
                                <?php
      if($info3000['en_hassanali_document_no'] == 1){
        $fiscal_month = date('m', strtotime($info2000['fiscal_month']));
        $datetime = $info9['datetime'];
        $daily_id = $info9['daily_id'];
        $month = date('m', strtotime($datetime));
        if($month < $fiscal_month){
            $year1 = date('y', strtotime("-1 year",  strtotime($datetime)));
            $year2 = date('y', strtotime($datetime));
        }else{
            $year1 = date('y', strtotime($datetime));
            $year2 = date('y', strtotime("+1 year",  strtotime($datetime)));
        }
        echo "SI/".$year1."-".$year2."/".str_pad($daily_id, 2, '0', STR_PAD_LEFT);
      } else{
          if($info3000['en_customdailyid']==1) { echo $info9['daily_id']; } else { echo $info9['id']; }
      }  
      $old_payment = mysqli_get_var("Select SUM(amount) from payment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 1 ");
      if($old_payment=='' || $old_payment===NULL){ $old_payment = 0; }
      ?>
                                (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)
                            </a>
                        </td><?php
    if($info4000['en_tradelink']==1){
      $invoiceno = $info9['id'];
      $subcustomer =  $info9['sub_customer'];
      ?>
                        <td><?php echo  mysqli_get_var("SELECT value FROM rice_field_details WHERE stype = 3 AND sid = '$invoiceno' AND value != '' and fid ='16' limit 1");?>
                        </td>
                        <td><?php echo  mysqli_get_var("SELECT name FROM sub_customer WHERE id='$subcustomer'");?></td>
                        <?php  }?>
                        <?php 
    if($info2000['en_ricetrade_advance'] == 1){
      if($info1000['en_hassanali'] == 1){ ?>
                        <td>
                            <a href="<?php echo rtrim($info1000['printview_slug'], '/'); ?>/warehouse/print-gdn.php?sid=<?php echo $info9['grn_id']; ?>" target="blank">
                                <?php
            $fiscal_month = date('m', strtotime($info2000['fiscal_month']));
            $datetime = mysqli_get_var("SELECT datetime FROM sales_grn WHERE id = '".$info9['grn_id']."' ");
            $daily_id = mysqli_get_var("SELECT daily_id FROM sales_grn WHERE id = '".$info9['grn_id']."' ");
            $month = date('m', strtotime($datetime));
            if($month < $fiscal_month){
                $year1 = date('y', strtotime("-1 year",  strtotime($datetime)));
                $year2 = date('y', strtotime($datetime));
            }else{
                $year1 = date('y', strtotime($datetime));
                $year2 = date('y', strtotime("+1 year",  strtotime($datetime)));
            }
            echo "GDN/".$year1."-".$year2."/".str_pad($daily_id, 2, '0', STR_PAD_LEFT);
            ?>
                            </a>
                        </td>
                        <?php } else{ ?>
                        <td><a href="<?php echo rtrim($info1000['printview_slug'], '/'); ?>/warehouse/print-gdn.php?sid=<?php echo $info9['grn_id']; ?>"
                                target="blank"><?php echo $info9['grn_id']; ?></a></td>
                        <?php } ?>
                        <?php } ?>
                        <?php if($info2000['multi_currencys']==1) { ?>  <td><?php echo number_format($info9['currency_total']); $total_amt += $info9['currency_total']; $cc = $info9['currency']; echo ' '; echo $nn = mysqli_get_var("Select symbol from currency where id='$cc' "); ?></td> <?php }
                        else{ ?>
                            <td><?php echo number_format($info9['total'],$info2000['total_decimal']); $total_amt += $info9['total']; ?>
                        <?php
                        }
                        ?>

                        </td>
                        <td><?php echo number_format($info9['pending_amount'],$info2000['total_decimal']); $total_pending_amt += $info9['pending_amount']; ?>
                        </td>
                        <?php 
                          
                        $invId = $info9['id'];
                        $curr_rate = mysqli_get_var("SELECT currency_rate FROM sales WHERE id = '$invId'");
                        
                          ?>  
                        <td>
                          <input name="oinvoicerate[]" class="oinvoicerate" type="hidden" value="<?php echo $curr_rate;?>" />
                          <input name="oinvoice[]" type="hidden" value="<?php echo $info9['id'];?>" /> <input
                                name="oinvoice_qty[]" class="debit debit_row" type="number" min="0" step="0.0001"
                                <?php if($invoiceid==0) { ?> max="<?php echo $info9['pending_amount'];?>"
                                <?php } else{ ?> max="<?php echo $info9['pending_amount']+$old_payment;?>" <?php  } ?>
                                value="<?php if($old_payment!='') { echo $old_payment; } else { echo 0; } ?>"  required/>

                                <input name="oinvoicetotal[]" class="oinvoicetotal" type="hidden" />  
                              </td>
                        
                    </tr>
                    <?php } 
    if($info2000['en_ricetrade_advance'] == 1){ $colspan = 2; }  else { $colspan = 1; } 
  ?>
                    <tr>
                        <td colspan="<?php echo $colspan; ?>">Total</td>
                        <!-- <td></td> -->
                        <!-- <td></td> -->
                        <td><?php echo number_format($total_amt,$info2000['total_decimal']); ?></td>
                        <td><?php echo number_format($total_pending_amt,$info2000['total_decimal']); ?></td>
                    </tr>
                    <?php
echo ' </table>';
?>
<input type="hidden" id="grand_total" name="grand_total" />   
                </div>
            </div>
        </div>
        <div class="card">
            <div class="card-header">
                <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseThree" data-bs-target="#collapseThree">Pending
                        <?php echo $info2000['creditnote_label'];  ?> (Partial Payment)</a>
                </h4>
            </div>
            <div id="collapseThree" class="card-collapse collapse">
                <div class="card-body oldpaymentheight">
                    <?php 

// $data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount  from sales_debit_note  where ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=2 )) && cid='$cid' ") or die(mysqli_error($conn));
  
  if($info3000['en_expense']==1) 
{ 
  if($statement_id == 0)
  {
    $data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount  from sales_debit_note  where ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=2 )) && cid='$cid' ") or die(mysqli_error($conn));
  }
  else {
$data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount  from sales_debit_note  where ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=2 )) && cid='$cid' && id IN (select invoice_id from statement_details WHERE sid in (select id from statement where type = 1 && sid = '$statement_id')) ") or die(mysqli_error($conn));
    }
}
else
{
    $data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount  from sales_debit_note  where ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=2 )) && cid='$cid' ") or die(mysqli_error($conn));
}


  $tot=0; 
echo '<table class="table table-bordered" width="80%"> 
  <tr>
  <th colspan="3">
    <label>
      <input type="checkbox" id="distribute_amount2" />
      Auto Distribute Amount
    </label>
  </th>
</tr>
  <tr>
  <th>ID/Date</th>
  <th>Total Amount</th>
  <th>Pending Amount</th>
  <th>Paid Amount</th>
  </tr>'; 
while($info9 = mysqli_fetch_array( $data9 )) 
 { ?>
                    <tr>
                        <td><?php echo $eid = $info9['id']; 
    $old_payment = mysqli_get_var("Select SUM(amount) from payment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 2 ");
    if($old_payment=='' || $old_payment===NULL){ $old_payment = 0; }
    ?>
                            (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)</td>
                        <td><?php echo number_format($info9['total'],$info2000['total_decimal']); ?></td>
                        <td><?php echo number_format($info9['pending_amount'],$info2000['total_decimal']); ?></td>
                        <td><input name="onotes[]" type="hidden" value="<?php echo $info9['id'];?>" />
                            <input name="onotes_qty[]" class="debit debit_row debit_row2" type="number" min="0"
                                <?php if($invoiceid==0) { ?> max="<?php echo $info9['pending_amount'];?>"
                                <?php } else{ ?> max="<?php echo $info9['pending_amount']+$old_payment;?>" <?php  } ?>
                                value="<?php echo ($old_payment); ?>"  required/>
                        </td>
                    </tr>
                    <?php } 
echo ' </table>';
?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
 } 
 else if(isset($_POST['sales_debit_note_dist_to']))
{
 $sales_debit_note_dist_to=test_input($_POST['sales_debit_note_dist_to']);
$sales_debit_note_dist_from = test_input($_POST['sales_debit_note_dist_from']);
$cid=0;//test_input($_POST['saleold2']);
$invoiceid=test_input($_POST['invoiceid']);
$cleartype=test_input($_POST['cleartype']);
?>
<div class="bs-example">
    <div class="panel-group" id="accordion">
        <div class="card">
            <div class="card-header">
                <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseTwo" data-bs-target="#collapseTwo">Pending Invoices (Partial
                        Payment)</a>
                </h4>
            </div>
            <div id="collapseTwo" class="card-collapse collapse">
                <div class="card-body oldpaymentheight">
                    <?php 
$total_amt = $total_pending_amt = 0; 
$data9 = mysqli_query($conn,"SELECT id, datetime,total_amount, pending_amount, daily_id, grn_id  from pr_invoice  where ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=1 )) && distributor_to_id='$sales_debit_note_dist_to'   ") or die(mysqli_error($conn));
  $tot=0; 
echo '<table class="table table-bordered" width="80%"> 
  <tr>
  <th>ID/Date</th>';
  if($info1000['en_hassanali'] == 1){ echo '<th>GDN</th>'; }
  echo '<th>Total Amount</th>
  <th>Pending Amount</th>
  <th>Paid Amount</th>
  </tr>'; 
while($info9 = mysqli_fetch_array( $data9 )) 
 { ?>
                    <tr>
                        <td>
                            <?php  
      $eid =  $info9['id'];
     $link = rtrim($info1000['printview_slug'], '/') . "/distributorpurchasing/print-pi-snd.php?sid=" . $info9['id'];

      ?>
                            <a href="<?php echo $link ?>" target="blank">
                                <?php
      if($info3000['en_hassanali_document_no'] == 1){
        $fiscal_month = date('m', strtotime($info2000['fiscal_month']));
        $datetime = $info9['datetime'];
        $daily_id = $info9['daily_id'];
        $month = date('m', strtotime($datetime));
        if($month < $fiscal_month){
            $year1 = date('y', strtotime("-1 year",  strtotime($datetime)));
            $year2 = date('y', strtotime($datetime));
        }else{
            $year1 = date('y', strtotime($datetime));
            $year2 = date('y', strtotime("+1 year",  strtotime($datetime)));
        }
        echo "SI/".$year1."-".$year2."/".str_pad($daily_id, 2, '0', STR_PAD_LEFT);
      } else{
        echo $eid;
      } 
      $old_payment = mysqli_get_var("Select SUM(amount) from payment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 1 "); ?>
                                (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)
                            </a>
                        </td>
                        <?php 
    if($info2000['en_ricetrade_advance'] == 1){
      if($info1000['en_hassanali'] == 1){ ?>
                        <td>
                            <a href="<?php echo rtrim($info1000['printview_slug'], '/'); ?>/warehouse/print-gdn.php?sid=<?php echo $info9['grn_id']; ?>" target="blank">
                                <?php
            $fiscal_month = date('m', strtotime($info2000['fiscal_month']));
            $datetime = mysqli_get_var("SELECT datetime FROM sales_grn WHERE id = '".$info9['grn_id']."' ");
            $daily_id = mysqli_get_var("SELECT daily_id FROM sales_grn WHERE id = '".$info9['grn_id']."' ");
            $month = date('m', strtotime($datetime));
            if($month < $fiscal_month){
                $year1 = date('y', strtotime("-1 year",  strtotime($datetime)));
                $year2 = date('y', strtotime($datetime));
            }else{
                $year1 = date('y', strtotime($datetime));
                $year2 = date('y', strtotime("+1 year",  strtotime($datetime)));
            }
            echo "GDN/".$year1."-".$year2."/".str_pad($daily_id, 2, '0', STR_PAD_LEFT);
            ?>
                            </a>
                        </td>
                        <?php } else{ ?>
                        <td><a href="<?php echo rtrim($info1000['printview_slug'], '/'); ?>/warehouse/print-gdn.php?sid=<?php echo $info9['grn_id']; ?>"
                                target="blank"><?php echo $info9['grn_id']; ?></a></td>
                        <?php } ?>
                        <?php } ?>
                        <td><?php echo number_format($info9['total_amount'],$info2000['total_decimal']); $total_amt += $info9['total_amount']; ?>
                        </td>
                        <td><?php echo number_format($info9['pending_amount'],$info2000['total_decimal']); $total_pending_amt += $info9['pending_amount']; ?>
                        </td>
                        <td><input name="oinvoice[]" type="hidden" value="<?php echo $info9['id'];?>" /> <input
                                name="oinvoice_qty[]" class="debit debit_row" type="number" min="0" step="0.0001"
                                <?php if($invoiceid==0) { ?> max="<?php echo $info9['pending_amount'];?>"
                                <?php } else{ ?> max="<?php echo $info9['pending_amount']+$old_payment;?>" <?php  } ?>
                                value="<?php if($old_payment!='') { echo $old_payment; } else { echo 0; } ?>" required/></td>
                    </tr>
                    <?php } 
    if($info2000['en_ricetrade_advance'] == 1){ $colspan = 2; }  else { $colspan = 1; } 
  ?>
                    <tr>
                        <td colspan="<?php echo $colspan; ?>">Total</td>
                        <td><?php echo number_format($total_amt,$info2000['total_decimal']); ?></td>
                        <td><?php echo number_format($total_pending_amt,$info2000['total_decimal']); ?></td>
                    </tr>
                    <?php
echo ' </table>';
?>
                </div>
            </div>
        </div>
        <div class="card">
            <div class="card-header">
                <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseThree" data-bs-target="#collapseThree">Pending
                        <?php echo $info2000['creditnote_label'];  ?> (Partial Payment)</a>
                </h4>
            </div>
            <div id="collapseThree" class="card-collapse collapse">
                <div class="card-body oldpaymentheight">
                    <?php 
$data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount  from sales_debit_note  where ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=2 )) && distributor_to_id='$sales_debit_note_dist_to'   ") or die(mysqli_error($conn));
  $tot=0; 
echo '<table class="table table-bordered" width="80%"> 
  <tr>
  <th>ID/Date</th>
  <th>Total Amount</th>
  <th>Pending Amount</th>
  <th>Paid Amount</th>
  </tr>'; 
while($info9 = mysqli_fetch_array( $data9 )) 
 { ?>
                    <tr>
                        <td><?php echo $eid = $info9['id']; $old_payment = mysqli_get_var("Select SUM(amount) from payment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 2 ");?>
                            (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)</td>
                        <td><?php echo number_format($info9['total'],$info2000['total_decimal']); ?></td>
                        <td><?php echo number_format($info9['pending_amount'],$info2000['total_decimal']); ?></td>
                        <td><input name="onotes[]" type="hidden" value="<?php echo $info9['id'];?>" />
                            <input name="onotes_qty[]" class="debit debit_row" type="number" min="0"
                                <?php if($invoiceid==0) { ?> max="<?php echo $info9['pending_amount'];?>"
                                <?php } else{ ?> max="<?php echo $info9['pending_amount']+$old_payment;?>" <?php  } ?>
                                value="<?php echo $old_payment; ?>" />
                        </td>
                    </tr>
                    <?php } 
echo ' </table>';
?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
 } 
else if(isset($_POST['dist_saleold2']) )
{
$dist_to=test_input($_POST['dist_to_id']);
$dist_from=test_input($_POST['dist_from_id']);
$invoiceid=test_input($_POST['invoiceid']);
$cleartype=test_input($_POST['cleartype']);
?>
<div class="bs-example">
    <div class="panel-group" id="accordion">
        <div class="card">
            <div class="card-header">
                <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseTwo" data-bs-target="#collapseTwo">Pending Invoices (Partial
                        Payment)</a>
                </h4>
            </div>
            <div id="collapseTwo" class="card-collapse collapse">
                <div class="card-body oldpaymentheight">
                    <?php 
$total_amt = $total_pending_amt = 0;
$data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount, daily_id, grn_id  from sales  where ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=1 )) && distributor_to_id='$dist_to' AND  distributor_from_id='$dist_from'  ") or die(mysqli_error($conn));
  $tot=0; 
echo '<table class="table table-bordered" width="80%"> 
  <tr>
  <th>ID/Date</th>';
  if($info1000['en_hassanali'] == 1){ echo '<th>GDN</th>'; }
  echo '<th>Total Amount</th>
  <th>Pending Amount</th>
  <th>Paid Amount</th>
  </tr>'; 
while($info9 = mysqli_fetch_array( $data9 )) 
 { ?>
                    <tr>
                        <td>
                            <?php  
      $eid =  $info9['id'];
      $link = rtrim($info1000['printview_slug'], '/')."/sales/print-si.php?sid=".$info9['id'];
      ?>
                            <a href="<?php echo $link ?>" target="blank">
                                <?php
      if($info3000['en_hassanali_document_no'] == 1){
        $fiscal_month = date('m', strtotime($info2000['fiscal_month']));
        $datetime = $info9['datetime'];
        $daily_id = $info9['daily_id'];
        $month = date('m', strtotime($datetime));
        if($month < $fiscal_month){
            $year1 = date('y', strtotime("-1 year",  strtotime($datetime)));
            $year2 = date('y', strtotime($datetime));
        }else{
            $year1 = date('y', strtotime($datetime));
            $year2 = date('y', strtotime("+1 year",  strtotime($datetime)));
        }
        echo "SI/".$year1."-".$year2."/".str_pad($daily_id, 2, '0', STR_PAD_LEFT);
      } else{
        echo $eid;
      } 
      $old_payment = mysqli_get_var("Select SUM(amount) from payment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 1 "); ?>
                                (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)
                            </a>
                        </td>
                        <?php 
    if($info2000['en_ricetrade_advance'] == 1){
      if($info1000['en_hassanali'] == 1){ ?>
                        <td>
                            <a href="<?php echo rtrim($info1000['printview_slug'], '/'); ?>/warehouse/print-gdn.php?sid=<?php echo $info9['grn_id']; ?>" target="blank">
                                <?php
            $fiscal_month = date('m', strtotime($info2000['fiscal_month']));
            $datetime = mysqli_get_var("SELECT datetime FROM sales_grn WHERE id = '".$info9['grn_id']."' ");
            $daily_id = mysqli_get_var("SELECT daily_id FROM sales_grn WHERE id = '".$info9['grn_id']."' ");
            $month = date('m', strtotime($datetime));
            if($month < $fiscal_month){
                $year1 = date('y', strtotime("-1 year",  strtotime($datetime)));
                $year2 = date('y', strtotime($datetime));
            }else{
                $year1 = date('y', strtotime($datetime));
                $year2 = date('y', strtotime("+1 year",  strtotime($datetime)));
            }
            echo "GDN/".$year1."-".$year2."/".str_pad($daily_id, 2, '0', STR_PAD_LEFT);
            ?>
                            </a>
                        </td>
                        <?php } else{ ?>
                        <td><a href="<?php echo rtrim($info1000['printview_slug'], '/'); ?>/warehouse/print-gdn.php?sid=<?php echo $info9['grn_id']; ?>"
                                target="blank"><?php echo $info9['grn_id']; ?></a></td>
                        <?php } ?>
                        <?php } ?>
                        <td><?php echo number_format($info9['total'],$info2000['total_decimal']); $total_amt += $info9['total']; ?>
                        </td>
                        <td><?php echo number_format($info9['pending_amount'],$info2000['total_decimal']); $total_pending_amt += $info9['pending_amount']; ?>
                        </td>
                        <td><input name="oinvoice[]" type="hidden" value="<?php echo $info9['id'];?>" /> <input
                                name="oinvoice_qty[]" class="debit debit_row" type="number" min="0" step="0.0001"
                                <?php if($invoiceid==0) { ?> max="<?php echo $info9['pending_amount'];?>"
                                <?php } else{ ?> max="<?php echo $info9['pending_amount']+$old_payment;?>" <?php  } ?>
                                value="<?php if($old_payment!='') { echo $old_payment; } else { echo 0; } ?>" required/></td>
                    </tr>
                    <?php } 
    if($info2000['en_ricetrade_advance'] == 1){ $colspan = 2; }  else { $colspan = 1; } 
  ?>
                    <tr>
                        <td colspan="<?php echo $colspan; ?>">Total</td>
                        <td><?php echo number_format($total_amt,$info2000['total_decimal']); ?></td>
                        <td><?php echo number_format($total_pending_amt,$info2000['total_decimal']); ?></td>
                    </tr>
                    <?php
echo ' </table>';
?>
                </div>
            </div>
        </div>
        <div class="card">
            <div class="card-header">
                <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseThree" data-bs-target="#collapseThree">Pending
                        <?php echo $info2000['creditnote_label'];  ?> (Partial Payment)</a>
                </h4>
            </div>
            <div id="collapseThree" class="card-collapse collapse">
                <div class="card-body oldpaymentheight">
                    <?php 
$data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount  from sales_debit_note  where ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=2 )) && distributor_to_id='$dist_to' AND  distributor_from_id='$dist_from'  ") or die(mysqli_error($conn));
  $tot=0; 
echo '<table class="table table-bordered" width="80%"> 
  <tr>
  <th>ID/Date</th>
  <th>Total Amount</th>
  <th>Pending Amount</th>
  <th>Paid Amount</th>
  </tr>'; 
while($info9 = mysqli_fetch_array( $data9 )) 
 { ?>
                    <tr>
                        <td><?php echo $eid = $info9['id']; $old_payment = mysqli_get_var("Select SUM(amount) from payment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 2 ");?>
                            (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)</td>
                        <td><?php echo number_format($info9['total'],$info2000['total_decimal']); ?></td>
                        <td><?php echo number_format($info9['pending_amount'],$info2000['total_decimal']); ?></td>
                        <td><input name="onotes[]" type="hidden" value="<?php echo $info9['id'];?>" />
                            <input name="onotes_qty[]" class="debit debit_row" type="number" min="0"
                                <?php if($invoiceid==0) { ?> max="<?php echo $info9['pending_amount'];?>"
                                <?php } else{ ?> max="<?php echo $info9['pending_amount']+$old_payment;?>" <?php  } ?>
                                value="<?php echo $old_payment; ?>" />
                        </td>
                    </tr>
                    <?php } 
echo ' </table>';
?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
 } 
else if(isset($_POST['saleold22']))
{
$cid=test_input($_POST['saleold22']);
?>
<script type="text/javascript">
$('.submit').click(function() {
    if ((calculatedebit() == $(".aamount").val() || calculatedebit() == 0) && (calculatedebit2() == $(
            ".aamount").val() || calculatedebit2() == 0)) {} else {
        alert('Invoices partial amount or bank cheque amount should be 0 or equal to total paid amount.');
        return false;
    }
});

function calculatedebit() {
    var sum = 0;
    //iterate through each textboxes and add the values
    $(".debit").each(function() {
        //add only if the value is number
        if (!isNaN(this.value) && this.value.length != 0) {
            sum += parseFloat(this.value);
        }
    });
    //.toFixed() method will roundoff the final sum to 2 decimal places
    return sum;
}

function calculatedebit2() {
    var sum2 = 0;
    //iterate through each textboxes and add the values
    $(".bamount").each(function() {
        //add only if the value is number
        if (!isNaN(this.value) && this.value.length != 0) {
            sum2 += parseFloat(this.value);
        }
    });
    //.toFixed() method will roundoff the final sum to 2 decimal places
    return sum2;
}
</script>
<?php
 } 
else if(isset($_POST['purchaseold2']))
{
$cid=test_input($_POST['purchaseold2']);
 $invoiceid=test_input($_POST['invoiceid']);
$cleartype = $_POST['cleartype'];
$po_id = $_POST['po_id'];
$query = " AND 1=1";
if($info2000['en_ricetrade_advance'] == 1){
  $query = " AND type_component NOT IN (3, 4) ";
}
?>
<?php 
/*saqib startcode*/
if($info3000['en_noorani']==1){ ?>
<script type="text/javascript">
$('.pend_amt').on('change', function() {
    var amt = 0;
    $(".pending_amtt").each(function() {
        var va = $(this).val();
        va = va.replace(/,/g, '');
        amt += +va; //(+$(this).val()).replace(",", "");;
    });
    if (amt != 0) {
        // alert(amt);
        if ($('.aamount').val() > amt) {
            alert('Please Check Your Pending Payments is Low');
            $('.aamount').val(amt);
        }
        if ($('.aamount').val() < amt) {
            alert('Please Check Your Pending Payments is High');
            $('.aamount').val(amt);
        }
    }
});
</script>
<?php }
/*saqib endcode*/
?>
<div class="bs-example">
    <div class="panel-group" id="accordion">
        <div class="card">
            <div class="card-header">
                <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseTwo" data-bs-target="#collapseTwo">Pending Invoices (Partial
                        Payment)</a>
                </h4>
            </div>
            <div id="collapseTwo" class="card-collapse collapse">
                <div class="card-body oldpaymentheight">
                    <?php 
$data9 = mysqli_query($conn,"SELECT id, datetime,total_amount, pending_amount, grn_id, daily_id  from purchasing  where ( pending_amount!=0 || id IN (Select invoice_id from ppayment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=1 ))  && vendor_id='$cid' $query ") or die(mysqli_error($conn));
  $tot=0; 
echo '<table class="table table-bordered" width="80%"> 
  <tr>';
  if($info3000['en_meskay_bulk_payment'] == 1){
    echo '<th></th>';
  }
  echo '<th>ID/Date</th>';
  if($info2000['en_ricetrade_advance'] == 1){
      echo '<th>Arrival Slip #</th>
            <th>Bilty #</th>
            <th>Truck No</th>';
  } 
  echo '<th>Total Amount</th>
  <th>Pending Amount</th>
  <th>Paid Amount</th>
  </tr>'; 
$total1 = 0;
$total2 = 0;  
while($info9 = mysqli_fetch_array( $data9 )) 
 { ?>
                    <tr>
                        <?php if($info3000['en_meskay_bulk_payment'] == 1){ ?>
                        <td>
                            <input type="checkbox" class="payment_check" value="1">
                            <input type="hidden" class="hidden_id" value="<?php echo $info9['id']; ?>">
                            <input type="hidden" class="hidden_amt" value="<?php echo $info9['pending_amount']; ?>">
                        </td>
                        <?php } ?>
                        <td>
                            <?php
      $link = rtrim($info1000['printview_slug'], '/') . "/print-custom/print-pi.php?sid=" . $info9['id'];
        if($info2000['en_ricetrade_advance'] == 1){
            $link = "print-pi-rice.php?sid=".$info9['id'];
        }
        ?>
                            <a href="<?php echo $link ?>" target="blank">
                                <?php if($info3000['en_hassanali_document_no'] == 1){
            $fiscal_month = date('m', strtotime($info2000['fiscal_month']));
            $datetime = $info9['datetime'];
            $daily_id = $info9['daily_id'];
            $month = date('m', strtotime($datetime));
            if($month < $fiscal_month){
                $year1 = date('y', strtotime("-1 year",  strtotime($datetime)));
                $year2 = date('y', strtotime($datetime));
            }else{
                $year1 = date('y', strtotime($datetime));
                $year2 = date('y', strtotime("+1 year",  strtotime($datetime)));
            }
            echo "PI/".$year1."-".$year2."/".str_pad($daily_id, 2, '0', STR_PAD_LEFT);
        }else{?>
                                <?php if($info3000['en_customdailyid']==1) { echo $info9['daily_id']; } else { echo $info9['id']; } ?>
                                <?php } ?>
                                (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)
                            </a>
                        </td>
                        <?php
    $arrival_slip = $bilty = $truck_no = '';
    if($info2000['en_ricetrade_advance'] == 1){
        $grn_id = $info9['grn_id'];
        $arrival_slip .= mysqli_get_var("SELECT arrival_truck_id FROM purchasing_grn WHERE id = '$grn_id' ").", ";
        $datetime = mysqli_get_var("SELECT datetime FROM purchasing_grn WHERE id = '$grn_id' ");
        $bilty .= mysqli_get_var("SELECT value FROM rice_field_details WHERE stype = 5 AND fid = '2' AND sid = '$grn_id' ").", ";
        $result2 = mysqli_query($conn, "SELECT num FROM pshipping WHERE po = 1 AND sid = '$grn_id' ") or die(mysqli_error($conn));
        while($myrow2 = mysqli_fetch_array($result2)){
          $truck_no .= $myrow2['num'].", ";
        }
        $arrival_slip = rtrim($arrival_slip, ", ");
        $bilty = rtrim($bilty, ", ");
        $truck_no = rtrim($truck_no, ", ");
      ?>
                        <td><?php if($arrival_slip != 0) { echo str_pad($arrival_slip, 4, '0', STR_PAD_LEFT).date('-d-m-y ', strtotime($datetime)); }  ?>
                        </td>
                        <td><?php echo $bilty; ?></td>
                        <td><?php echo $truck_no; ?></td>
                        <?php }
    $total1 +=  $info9['total_amount'];
    $total2 +=  $info9['pending_amount'];
    $iddam = $info9['id'];
    ?>
                        <td><?php echo number_format($info9['total_amount'],$info2000['total_decimal']);?></td>
                        <td><?php echo number_format($info9['pending_amount'],$info2000['total_decimal']); $eid = $info9['id'];  $old_payment = mysqli_get_var("Select SUM(amount) from ppayment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 1 ");?>
                        </td>
                        <?php
                        $invId = $info9['id'];
                        $curr_rate = mysqli_get_var("SELECT currency_rate FROM purchasing WHERE id = '$invId'");
                        ?>
                        <td>
                          <input name="oinvoicerate[]" class="oinvoicerate" type="hidden" value="<?php echo $curr_rate;?>" />
                          <input name="oinvoicetotal[]" class="oinvoicetotal" type="hidden" />
                          <input name="oinvoice[]" type="hidden" value="<?php echo $info9['id'];?>" /> <input
                                name="oinvoice_qty[]"
                                <?php if($info3000['en_meskay_bulk_payment'] == 1){ echo "readonly"; } ?>
                                class="debit debit_row  <?php echo 'pending_amtt';?>" type="number" min="0"
                                <?php if($invoiceid==0) { ?> max="<?php echo $info9['pending_amount'];?>"
                                <?php } else{ ?> max="<?php echo $info9['pending_amount']+$old_payment;?>" <?php  } ?>
                                step="0.0001" value="<?php if($old_payment!='') { echo $old_payment; } else { echo 0; } ?>" required/>
                              </td>
                    </tr>
                    <?php }  if($info2000['en_ricetrade_advance'] == 1){
 $colspan = 4; }  else { $colspan = 1; }  
 if($info3000['en_meskay_bulk_payment'] == 1){
    $colspan = $colspan+1;
 }
 ?>
                    <tr>
                        <td colspan="<?php echo $colspan; ?>">Total</td>
                        <td><?php echo number_format($total1, 2) ?></td>
                        <td <?php echo "id='pending_tamt_$cid'";?>><?php echo number_format($total2, 2) ?></td>
                        <td></td>
                    </tr>
                    <?php echo ' </table>';
?>
<input type="hidden" id="grand_total" name="grand_total" />   
                </div>
            </div>
        </div>
        <?php if($info2000['en_ricetrade_advance'] == 1){ ?>
        <div class="card">
            <div class="card-header">
                <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseFour" data-bs-target="#collapseFour">Pending Freight Invoices
                        (Partial Payment)</a>
                </h4>
            </div>
            <div id="collapseFour" class="card-collapse collapse">
                <div class="card-body oldpaymentheight">
                    <?php 
                $data9 = mysqli_query($conn,"SELECT id, datetime,total_amount, pending_amount, grn_id, daily_id  from purchasing  where ( pending_amount!=0 || id IN (Select invoice_id from ppayment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=1 )) && vendor_id='$cid' AND type_component = 4 ") or die(mysqli_error($conn));
                $tot=0; 
                ?>
                    <table class="table table-bordered" width="80%">
                        <tr>
                            <?php
                    if($info3000['en_meskay_bulk_payment'] == 1){
                      echo '<th></th>';
                    }
                    ?>
                            <th>ID/Date</th>
                            <th>Arrival Slip #</th>
                            <th>Bilty #</th>
                            <th>Truck No</th>
                            <th>Total Amount</th>
                            <th>Pending Amount</th>
                            <th>Paid Amount</th>
                        </tr>
                        <?php 
                  $total1 = $total2 = 0;
                  while($info9 = mysqli_fetch_array( $data9 )) { ?>
                        <tr>
                            <?php if($info3000['en_meskay_bulk_payment'] == 1){ ?>
                            <td>
                                <input type="checkbox" class="payment_check" value="1">
                                <input type="hidden" class="hidden_id" value="<?php echo $info9['id']; ?>">
                                <input type="hidden" class="hidden_amt" value="<?php echo $info9['pending_amount']; ?>">
                            </td>
                            <?php } ?>
                            <?php $link = "purchase/print-pi.php?sid=".$info9['id']; ?>
                            <td>
                                <a href="<?php echo $link ?>" target="blank">
                                    <?php if($info3000['en_hassanali_document_no'] == 1){
                                $fiscal_month = date('m', strtotime($info2000['fiscal_month']));
                                $datetime = $info9['datetime'];
                                $daily_id = $info9['daily_id'];
                                $month = date('m', strtotime($datetime));
                                if($month < $fiscal_month){
                                    $year1 = date('y', strtotime("-1 year",  strtotime($datetime)));
                                    $year2 = date('y', strtotime($datetime));
                                }else{
                                    $year1 = date('y', strtotime($datetime));
                                    $year2 = date('y', strtotime("+1 year",  strtotime($datetime)));
                                }
                                echo "FI/".$year1."-".$year2."/".str_pad($daily_id, 2, '0', STR_PAD_LEFT);
                            }else{?>
                                    <?php echo $info9['id']; ?>
                                    <?php } ?>
                                    (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)
                                </a>
                            </td>
                            <?php 
                      $arrival_slip = $bilty = $truck_no = $ticket_num = '';
                      if($info2000['en_single_invoice'] == 1){ 
                        $result = mysqli_query($conn, "SELECT * FROM pi_grn_link WHERE pi_id = '".$info9['id']."' ") or die(mysqli_error($conn));
                        while($myrow = mysqli_fetch_array($result)){
                          $grn_id = mysqli_get_var("SELECT grn_reference_id FROM purchasing_grn WHERE id = '".$myrow['grn_id']."' ");
                          $arrival_slip = mysqli_get_var("SELECT arrival_truck_id FROM purchasing_grn WHERE id = '$grn_id' ");
                          $datetime = mysqli_get_var("SELECT datetime FROM purchasing_grn WHERE id = '$grn_id' ");
                          $ticket_num .= str_pad($arrival_slip, 4, '0', STR_PAD_LEFT).date('-d-m-y ', strtotime($datetime)).", ";
                          $bilty .= mysqli_get_var("SELECT value FROM rice_field_details WHERE stype = 5 AND fid = '2' AND sid = '$grn_id' ").", ";
                          $result2 = mysqli_query($conn, "SELECT num FROM pshipping WHERE po = 1 AND sid = '$grn_id' ") or die(mysqli_error($conn));
                          while($myrow2 = mysqli_fetch_array($result2)){
                            $truck_no .= $myrow2['num'].", ";
                          }
                        }
                        $arrival_slip = rtrim($arrival_slip, ", ");
                        $ticket_num = rtrim($ticket_num, ", ");
                        $bilty = rtrim($bilty, ", ");
                        $truck_no = rtrim($truck_no, ", ");
                      ?>
                            <td><?php echo $ticket_num; ?></td>
                            <td><?php echo $bilty; ?></td>
                            <td><?php echo $truck_no; ?></td>
                            <?php }else{ 
                        $grn_id = mysqli_get_var("SELECT grn_reference_id FROM purchasing_grn WHERE id = '".$info9['grn_id']."' ");
                        $arrival_slip = mysqli_get_var("SELECT arrival_truck_id FROM purchasing_grn WHERE id = '$grn_id' ");
                        $datetime = mysqli_get_var("SELECT datetime FROM purchasing_grn WHERE id = '$grn_id' ");
                        $ticket_num .= str_pad($arrival_slip, 4, '0', STR_PAD_LEFT).date('-d-m-y ', strtotime($datetime)).", ";
                        $bilty .= mysqli_get_var("SELECT value FROM rice_field_details WHERE stype = 5 AND fid = '2' AND sid = '$grn_id' ").", ";
                        $result2 = mysqli_query($conn, "SELECT num FROM pshipping WHERE po = 1 AND sid = '$grn_id' ") or die(mysqli_error($conn));
                        while($myrow2 = mysqli_fetch_array($result2)){
                          $truck_no .= $myrow2['num'].", ";
                        }
                        $ticket_num = rtrim($ticket_num, ", ");
                        $bilty = rtrim($bilty, ", ");
                        $truck_no = rtrim($truck_no, ", ");
                      ?>
                            <td><?php echo $ticket_num; ?></td>
                            <td><?php echo $bilty; ?></td>
                            <td><?php echo $truck_no; ?></td>
                            <?php } 
                      $total1 +=  $info9['total_amount'];
                      $total2 +=  $info9['pending_amount'];
                      ?>
                            <td><?php echo $info9['total_amount'];?></td>
                            <td><?php echo $info9['pending_amount']; $eid = $info9['id']; $old_payment = mysqli_get_var("Select SUM(amount) from ppayment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 1 "); ?>
                            </td>
                            <td><input name="oinvoice[]" type="hidden" value="<?php echo $info9['id'];?>" /> <input
                                    name="oinvoice_qty[]"
                                    <?php if($info3000['en_meskay_bulk_payment'] == 1){ echo "readonly"; } ?>
                                    class="debit debit_row" type="number" min="0" <?php if($invoiceid==0) { ?>
                                    max="<?php echo $info9['pending_amount'];?>" <?php } else{ ?>
                                    max="<?php echo $info9['pending_amount']+$old_payment;?>" <?php  } ?>
                                    value="<?php if($old_payment!='') { echo $old_payment; } else { echo 0; } ?>" required/></td>
                        </tr>
                        <?php } ?>
                        <tr>
                            <?php 
                      $colspan = 4;
                      if($info3000['en_meskay_bulk_payment'] == 1){ 
                        $colspan = 5;
                      } ?>
                            <td colspan="<?php echo $colspan; ?>">Total</td>
                            <td><?php echo number_format($total1, 2) ?></td>
                            <td><?php echo number_format($total2, 2) ?></td>
                            <td></td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        <div class="card">
            <div class="card-header">
                <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseFive" data-bs-target="#collapseFive">Pending Brokery Invoices
                        (Partial Payment)</a>
                </h4>
            </div>
            <div id="collapseFive" class="card-collapse collapse">
                <div class="card-body oldpaymentheight">
                    <?php 
                 $total1 = $total2 = 0;
                $data9 = mysqli_query($conn,"SELECT id, datetime,total_amount, pending_amount, grn_id, daily_id  from purchasing  where ( pending_amount!=0 || id IN (Select invoice_id from ppayment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=1 )) && vendor_id='$cid' AND type_component = 3 ") or die(mysqli_error($conn));
                $tot=0; 
                ?>
                    <table class="table table-bordered" width="80%">
                        <tr>
                            <?php
                    if($info3000['en_meskay_bulk_payment'] == 1){
                      echo '<th></th>';
                    }
                    ?>
                            <th>ID/Date</th>
                            <th>Arrival Slip #</th>
                            <th>Bilty #</th>
                            <th>Truck No</th>
                            <th>Total Amount</th>
                            <th>Pending Amount</th>
                            <th>Paid Amount</th>
                        </tr>
                        <?php 
                  while($info9 = mysqli_fetch_array( $data9 )) { ?>
                        <tr>
                            <?php if($info3000['en_meskay_bulk_payment'] == 1){ ?>
                            <td>
                                <input type="checkbox" class="payment_check" value="1">
                                <input type="hidden" class="hidden_id" value="<?php echo $info9['id']; ?>">
                                <input type="hidden" class="hidden_amt" value="<?php echo $info9['pending_amount']; ?>">
                            </td>
                            <?php } ?>
                            <?php $link = "purchase/print-pi.php?sid=".$info9['id']; ?>
                            <td>
                                <a href="<?php echo $link ?>" target="blank">
                                    <?php if($info3000['en_hassanali_document_no'] == 1){
                                $fiscal_month = date('m', strtotime($info2000['fiscal_month']));
                                $datetime = $info9['datetime'];
                                $daily_id = $info9['daily_id'];
                                $month = date('m', strtotime($datetime));
                                if($month < $fiscal_month){
                                    $year1 = date('y', strtotime("-1 year",  strtotime($datetime)));
                                    $year2 = date('y', strtotime($datetime));
                                }else{
                                    $year1 = date('y', strtotime($datetime));
                                    $year2 = date('y', strtotime("+1 year",  strtotime($datetime)));
                                }
                                echo "BI/".$year1."-".$year2."/".str_pad($daily_id, 2, '0', STR_PAD_LEFT);
                            }else{?>
                                    <?php echo $info9['id']; ?>
                                    <?php } ?>
                                    (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)
                                </a>
                            </td>
                            <?php 
                        $arrival_slip = $bilty = $truck_no = $ticket_num = '';
                        $grn_id = mysqli_get_var("SELECT grn_reference_id FROM purchasing_grn WHERE id = '".$info9['grn_id']."' ");
                        $arrival_slip = mysqli_get_var("SELECT arrival_truck_id FROM purchasing_grn WHERE id = '$grn_id' ");
                        $datetime = mysqli_get_var("SELECT datetime FROM purchasing_grn WHERE id = '$grn_id' ");
                        $ticket_num .= str_pad($arrival_slip, 4, '0', STR_PAD_LEFT).date('-d-m-y ', strtotime($datetime)).", ";
                        $bilty .= mysqli_get_var("SELECT value FROM rice_field_details WHERE stype = 5 AND fid = '2' AND sid = '$grn_id' ").", ";
                        $result2 = mysqli_query($conn, "SELECT num FROM pshipping WHERE po = 1 AND sid = '$grn_id' ") or die(mysqli_error($conn));
                        while($myrow2 = mysqli_fetch_array($result2)){
                          $truck_no .= $myrow2['num'].", ";
                        }
                        $ticket_num = rtrim($ticket_num, ", ");
                        $bilty = rtrim($bilty, ", ");
                        $truck_no = rtrim($truck_no, ", ");
                        $total1 +=  $info9['total_amount'];
                        $total2 +=  $info9['pending_amount'];
                      ?>
                            <td><?php echo $ticket_num; ?></td>
                            <td><?php echo $bilty; ?></td>
                            <td><?php echo $truck_no; ?></td>
                            <td><?php echo $info9['total_amount'];?></td>
                            <td><?php echo $info9['pending_amount']; $eid = $info9['id']; $old_payment = mysqli_get_var("Select SUM(amount) from ppayment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 1 "); ?>
                            </td>
                            <td><input name="oinvoice[]" type="hidden" value="<?php echo $info9['id'];?>" /> <input
                                    name="oinvoice_qty[]"
                                    <?php if($info3000['en_meskay_bulk_payment'] == 1){ echo "readonly"; } ?>
                                    class="debit debit_row" type="number" min="0" <?php if($invoiceid==0) { ?>
                                    max="<?php echo $info9['pending_amount'];?>" <?php } else{ ?>
                                    max="<?php echo $info9['pending_amount']+$old_payment;?>" <?php  } ?>
                                    value="<?php if($old_payment!='') { echo $old_payment; } else { echo 0; } ?>" required/></td>
                        </tr>
                        <?php } ?>
                        <tr>
                            <?php
                    $colspan = 4;
                      if($info3000['en_meskay_bulk_payment'] == 1){ 
                        $colspan = 5;
                      } ?>
                            <td colspan="<?php echo $colspan; ?>">Total</td>
                            <td><?php echo number_format($total1, 2) ?></td>
                            <td><?php echo number_format($total2, 2) ?></td>
                            <td></td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        <div class="card">
            <div class="card-header">
                <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseSix" data-bs-target="#collapseSix">PO Pending Amount</a>
                </h4>
            </div>
            <div id="collapseSix" class="card-collapse collapse">
                <div class="card-body oldpaymentheight">
                    <?php 
                $data9 = mysqli_query($conn,"SELECT id, datetime,total_amount from po  where id = '$po_id' ") or die(mysqli_error($conn));
                $tot=0; 
                ?>
                    <table class="table table-bordered" width="80%">
                        <tr>
                            <th>ID/Date</th>
                            <th>Total Amount</th>
                            <th>Pending Amount</th>
                        </tr>
                        <?php 
                  while($info9 = mysqli_fetch_array( $data9 )) { ?>
                        <tr>
                            <td><?php echo $info9['id'];?> (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)
                            </td>
                            <td><?php echo number_format($info9['total_amount']); ?></td>
                            <td>
                                <?php
                        $pending_amount =  mysqli_get_var("SELECT SUM(pending_amount) FROM purchasing WHERE type_component = 0 AND po_id = '$po_id' ");
                        echo number_format($info9['total_amount']-$pending_amount);
                        ?>
                            </td>
                        </tr>
                        <?php } ?>
                    </table>
                </div>
            </div>
        </div>
        <?php } ?>
        <div class="card">
            <div class="card-header">
                <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseThree" data-bs-target="#collapseThree">Pending
                        <?php echo $info2000['debitnote_label'];  ?> (Partial Payment)</a>
                </h4>
            </div>
            <div id="collapseThree" class="card-collapse collapse">
                <div class="card-body oldpaymentheight">
                    <?php 
$data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount  from purchase_credit_note  where ( pending_amount!=0 || id IN (Select invoice_id from ppayment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=2 )) && vid='$cid' ") or die(mysqli_error($conn));
  $tot=0; 
echo '<table class="table table-bordered" width="80%"> 
  <tr>
  <th>ID/Date</th>
  <th>Total Amount</th>
  <th>Pending Amount</th>
  <th>Paid Amount</th>
  </tr>'; 
while($info9 = mysqli_fetch_array( $data9 )) 
 { ?>
                    <tr>
                        <td><?php echo $eid = $info9['id']; $old_payment = mysqli_get_var("Select SUM(amount) from ppayment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 2 "); ?>
                            (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)</td>
                        <td><?php echo $info9['total'];?></td>
                        <td><?php echo $info9['pending_amount'];?></td>
                        <td><input name="onotes[]" type="hidden" value="<?php echo $info9['id'];?>" /> <input
                                name="onotes_qty[]" class="debit debit_row" type="number" min="0"
                                <?php if($invoiceid==0) { ?> max="<?php echo $info9['pending_amount'];?>"
                                <?php } else{ ?> max="<?php echo $info9['pending_amount']+$old_payment;?>" <?php  } ?>
                                value="<?php echo $old_payment; ?>" required/></td>
                    </tr>
                    <?php } 
echo ' </table>';
?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
 } 
else if(isset($_POST['pdist_to_id']))
{
$pdist_to_id=test_input($_POST['pdist_to_id']);
$pdist_from_id=test_input($_POST['pdist_from_id']);
// $cid=test_input($_POST['purchaseold2']);
 $invoiceid=test_input($_POST['invoiceid']);
$cleartype = $_POST['cleartype'];
$po_id = $_POST['po_id'];
$query = " AND 1=1";
?>
<div class="bs-example">
    <div class="panel-group" id="accordion">
        <div class="card">
            <div class="card-header">
                <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseTwo" data-bs-target="#collapseTwo">Pending Invoices (Partial
                        Payment)</a>
                </h4>
            </div>
            <div id="collapseTwo" class="card-collapse collapse">
                <div class="card-body oldpaymentheight">
                    <?php 
$data9 = mysqli_query($conn,"SELECT id, datetime,total_amount, pending_amount, grn_id, daily_id  from purchasing  where ( pending_amount!=0 || id IN (Select invoice_id from ppayment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=1 ))  && distributor_to_id='$pdist_to_id' && distributor_from_id='$pdist_from_id' $query ") or die(mysqli_error($conn));
  $tot=0; 
echo '<table class="table table-bordered" width="80%"> 
  <tr>';
  echo '<th>ID/Date</th>';
  echo '<th>Total Amount</th>
  <th>Pending Amount</th>
  <th>Paid Amount</th>
  </tr>'; 
$total1 = 0;
$total2 = 0;  
while($info9 = mysqli_fetch_array( $data9 )) 
 { ?>
                    <tr>
                        <td>
                            <?php
     $link = rtrim($info1000['printview_slug'], '/') . "/print-custom/print-pi.php?sid=" . $info9['id'];
        ?>
                            <a href="<?php echo $link ?>" target="blank">
                                <?php echo $info9['id']; ?>
                                (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)
                            </a>
                        </td>
                        <?php
    $arrival_slip = $bilty = $truck_no = '';
    $total1 +=  $info9['total_amount'];
    $total2 +=  $info9['pending_amount'];
    ?>
                        <td><?php echo number_format($info9['total_amount'],$info2000['total_decimal']);?></td>
                        <td><?php echo number_format($info9['pending_amount'],$info2000['total_decimal']); $eid = $info9['id'];  $old_payment = mysqli_get_var("Select SUM(amount) from ppayment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 1 ");?>
                        </td>
                        <td><input name="oinvoice[]" type="hidden" value="<?php echo $info9['id'];?>" /> <input
                                name="oinvoice_qty[]"
                                <?php if($info3000['en_meskay_bulk_payment'] == 1){ echo "readonly"; } ?>
                                class="debit debit_row" type="number" min="0" <?php if($invoiceid==0) { ?>
                                max="<?php echo $info9['pending_amount'];?>" <?php } else{ ?>
                                max="<?php echo $info9['pending_amount']+$old_payment;?>" <?php  } ?> step="0.0001"
                                value="<?php if($old_payment!='') { echo $old_payment; } else { echo 0; } ?>" /></td>
                    </tr>
                    <?php }  
  $colspan = 1;
 ?>
                    <tr>
                        <td colspan="<?php echo $colspan; ?>">Total</td>
                        <td><?php echo number_format($total1, 2) ?></td>
                        <td><?php echo number_format($total2, 2) ?></td>
                        <td></td>
                    </tr>
                    <?php echo ' </table>';
?>
                </div>
            </div>
        </div>
        <div class="card">
            <div class="card-header">
                <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseThree" data-bs-target="#collapseThree">Pending
                        <?php echo $info2000['debitnote_label'];  ?> (Partial Payment)</a>
                </h4>
            </div>
            <div id="collapseThree" class="card-collapse collapse">
                <div class="card-body oldpaymentheight">
                    <?php 
$data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount  from purchase_credit_note  where ( pending_amount!=0 || id IN (Select invoice_id from ppayment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=2 )) && distributor_to_id='$pdist_to_id' && distributor_from_id='$pdist_from_id'  ") or die(mysqli_error($conn));
  $tot=0; 
echo '<table class="table table-bordered" width="80%"> 
  <tr>
  <th>ID/Date</th>
  <th>Total Amount</th>
  <th>Pending Amount</th>
  <th>Paid Amount</th>
  </tr>'; 
while($info9 = mysqli_fetch_array( $data9 )) 
 { ?>
                    <tr>
                        <td><?php echo $eid = $info9['id']; $old_payment = mysqli_get_var("Select SUM(amount) from ppayment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 2 "); ?>
                            (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)</td>
                        <td><?php echo $info9['total'];?></td>
                        <td><?php echo $info9['pending_amount'];?></td>
                        <td><input name="onotes[]" type="hidden" value="<?php echo $info9['id'];?>" /> <input
                                name="onotes_qty[]" class="debit debit_row" type="number" min="0"
                                <?php if($invoiceid==0) { ?> max="<?php echo $info9['pending_amount'];?>"
                                <?php } else{ ?> max="<?php echo $info9['pending_amount']+$old_payment;?>" <?php  } ?>
                                value="<?php echo $old_payment; ?>" /></td>
                    </tr>
                    <?php } 
echo ' </table>';
?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
 } 
else if(isset($_POST['ppid99']))
{
$cid=test_input($_POST['ppid99']);
$po_id=test_input($_POST['po_id']);
$cledger = $cid;
 $withholding_tax = mysqli_get_var("SELECT withholding_tax FROM vendor WHERE id = '$cid' ");
$tot = bms_vendor_old_payable_amount($cid, $po_id);
?>
Old Payable
<input name="old" type="text" class="form-control" id="old" value="<?php echo number_format($tot, $info2000['total_decimal']);?>"
    readonly="readonly" />
<br />
<div>
    <table width="100%" border="0" cellspacing="0" id="tblExport" cellpadding="5" class="table-bordered table-striped">
        <tr>
            <td><b>Month</b></td>
            <td><b>Pending Payment</b></td>
        </tr>
        <?php  
     $data63 = mysqli_query($conn,"SELECT MONTHNAME(DATETIME) AS mn, YEAR(DATETIME) AS yn, SUM(s1-s2+s3+s4) AS pa
  FROM
  (
      SELECT DATETIME, pending_amount AS s1, 0 AS s2, 0 AS s3, 0 as s4 FROM purchasing where vendor_id='$cledger' 
      UNION ALL
      SELECT DATETIME, 0 AS s1, 0 AS s2, pending_amount AS s3, 0 as s4  FROM purchase_credit_note  where vid='$cledger'
      UNION ALL
      SELECT obdate as DATETIME, 0 AS s1, 0 AS s2, 0 AS s3, ob AS s4  FROM vendor 
      where id='$cledger' 
      ) AS UnionTable
  GROUP BY  YEAR(DATETIME), MONTHNAME(DATETIME) order by YEAR(DATETIME), MONTHNAME(DATETIME) DESC
  ") or die(mysqli_error($conn));
      $ta=0;
  while($info63 = mysqli_fetch_array( $data63 )) 
   { 
    ?>
        <?php if($info63['pa']!=0) { ?>
        <tr>
            <td><?php echo $info63['mn']; ?> <?php echo $info63['yn']; ?></td>
            <td><?php echo number_format($info63['pa'],$info2000['total_decimal']); $ta=$info63['pa']+$ta; ?></td>
        </tr>
        <?php } }  ?>
        <?php
        if(isset($info2000['customervendor_same']) && (int)$info2000['customervendor_same'] === 1) {
          $net_adjustment = (float)$tot - (float)$ta;
          if(abs($net_adjustment) > 0.0000001) {
            ?>
        <tr>
            <td>Net Adjustment</td>
            <td><?php echo number_format($net_adjustment,$info2000['total_decimal']); ?></td>
        </tr>
        <?php
            $ta = $ta + $net_adjustment;
          }
        }
        ?>
        <tr>
            <td><b>Total</b></td>
            <td><?php echo number_format($ta,$info2000['total_decimal']); ?></td>
        </tr>
    </table>
</div>
<?php
$result5 = mysqli_query($conn, "SELECT * FROM v_cheque_clearing WHERE vid = '$cid' AND cleared = 0 ") or die(mysqli_error($conn));
if(mysqli_num_rows($result5) > 0){
?>
<div class="col-md-8">
    <table width="100%" border="0" cellspacing="0" id="tblExport" cellpadding="5" class="table-bordered table-striped">
        <tr>
            <td><b>PDC Date</b></td>
            <td><b>Bank</b></td>
            <td><b>Cheque No</b></td>
            <td><b>Memo</b></td>
            <td><b>PDC Amount</b></td>
        </tr>
        <?php 
    $t_total_amount = 0;
    while($myrow5 = mysqli_fetch_array($result5)){
      ?>
        <tr>
            <td width="90px;"><?php echo date('d M Y', strtotime($myrow5['datetime'])); ?></td>
            <td width="170px;">
                <?php echo mysqli_get_var("SELECT name FROM accounts_type WHERE id IN (SELECT account_id FROM v_cheque_coa WHERE credit != 0 AND cheque_id = '".$myrow5['id']."') ") ?>
            </td>
            <td width="100px;"><?php echo $myrow5['checkid']; ?></td>
            <td width="170px;"><?php echo $myrow5['details']; ?></td>
            <td width="100px;">
                <?php echo number_format($myrow5['actual_amount'], 2); $t_total_amount += $myrow5['actual_amount']; ?>
            </td>
        </tr>
        <?php
    }
    ?>
        <tr>
            <td colspan="4"><b>Total</b></td>
            <td><?php echo number_format($t_total_amount,$info2000['total_decimal']); ?></td>
        </tr>
    </table>
</div>
<?php } else { ?>
<?php } ?>
<div class="clearfix"></div>
<?php if($withholding_tax!=0 && $withholding_tax!=-1) { ?>
<script type="text/javascript">
$(".whtax_percent").val(<?php echo $withholding_tax; ?>);
</script>
<?php 
}
} 
else if(isset($_POST['pp_dist_to_id']))
{
$pp_dist_to_id=test_input($_POST['pp_dist_to_id']);
$ppd_ist_from_id=test_input($_POST['ppd_ist_from_id']);
$cledger = $cid;
$data34 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM purchasing WHERE distributor_to_id='$pp_dist_to_id' &&  distributor_from_id='$ppd_ist_from_id' ") or die(mysqli_error($conn));      
$info34 = mysqli_fetch_array( $data34 );
// $data40 = mysqli_query($conn,"SELECT SUM(advance_payment) as sum FROM vendor WHERE id='$cid'") or die(mysqli_error($conn));      
// $info40 = mysqli_fetch_array( $data40 );
$data38 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM purchase_credit_note WHERE distributor_to_id='$pp_dist_to_id' &&  distributor_from_id='$ppd_ist_from_id' ") or die(mysqli_error($conn));      
$info38 = mysqli_fetch_array( $data38 );
// $data36 = mysqli_query($conn,"SELECT ob FROM vendor WHERE id='$cid'") or die(mysqli_error($conn));       
// $info36 = mysqli_fetch_array( $data36 );
$tot= $info34['sum'] + $info38['sum'] + $info36['ob']  - $info40['sum'];
?>
Old Payable
<input name="old" type="text" class="form-control" id="old" value="<?php echo number_format($tot, 2);?>"
    readonly="readonly" />
<br />
<div>
    <table width="100%" border="0" cellspacing="0" id="tblExport" cellpadding="5" class="table-bordered table-striped">
        <tr>
            <td><b>Month</b></td>
            <td><b>Pending Payment</b></td>
        </tr>
        <?php  
      //      UNION ALL
      // SELECT obdate as DATETIME, 0 AS s1, 0 AS s2, 0 AS s3, ob AS s4  FROM vendor 
      // where id='$cledger' 
     $data63 = mysqli_query($conn,"SELECT MONTHNAME(DATETIME) AS mn, YEAR(DATETIME) AS yn, SUM(s1-s2+s3+s4) AS pa
  FROM
  (
      SELECT DATETIME, pending_amount AS s1, 0 AS s2, 0 AS s3, 0 as s4 FROM purchasing where distributor_to_id='$pp_dist_to_id' &&  distributor_from_id='$ppd_ist_from_id' 
      UNION ALL
      SELECT DATETIME, 0 AS s1, 0 AS s2, pending_amount AS s3, 0 as s4  FROM purchase_credit_note  where distributor_to_id='$pp_dist_to_id' &&  distributor_from_id='$ppd_ist_from_id'
      ) AS UnionTable
  GROUP BY  YEAR(DATETIME), MONTHNAME(DATETIME) order by YEAR(DATETIME), MONTHNAME(DATETIME) DESC
  ") or die(mysqli_error($conn));
      $ta=0;
  while($info63 = mysqli_fetch_array( $data63 )) 
   { 
    ?>
        <?php if($info63['pa']!=0) { ?>
        <tr>
            <td><?php echo $info63['mn']; ?> <?php echo $info63['yn']; ?></td>
            <td><?php echo number_format($info63['pa'],$info2000['total_decimal']); $ta=$info63['pa']+$ta; ?></td>
        </tr>
        <?php } }  ?>
        <tr>
            <td><b>Total</b></td>
            <td><?php echo number_format($ta,$info2000['total_decimal']); ?></td>
        </tr>
    </table>
</div>
<?php
$result5 = mysqli_query($conn, "SELECT * FROM v_cheque_clearing WHERE vid = '$cid' AND cleared = 0 ") or die(mysqli_error($conn));
if(mysqli_num_rows($result5) > 0){
?>
<div class="col-md-8">
    <table width="100%" border="0" cellspacing="0" id="tblExport" cellpadding="5" class="table-bordered table-striped">
        <tr>
            <td><b>PDC Date</b></td>
            <td><b>Bank</b></td>
            <td><b>Cheque No</b></td>
            <td><b>Memo</b></td>
            <td><b>PDC Amount</b></td>
        </tr>
        <?php 
    $t_total_amount = 0;
    while($myrow5 = mysqli_fetch_array($result5)){
      ?>
        <tr>
            <td width="90px;"><?php echo date('d M Y', strtotime($myrow5['datetime'])); ?></td>
            <td width="170px;">
                <?php echo mysqli_get_var("SELECT name FROM accounts_type WHERE id IN (SELECT account_id FROM v_cheque_coa WHERE credit != 0 AND cheque_id = '".$myrow5['id']."') ") ?>
            </td>
            <td width="100px;"><?php echo $myrow5['checkid']; ?></td>
            <td width="170px;"><?php echo $myrow5['details']; ?></td>
            <td width="100px;">
                <?php echo number_format($myrow5['actual_amount'], 2); $t_total_amount += $myrow5['actual_amount']; ?>
            </td>
        </tr>
        <?php
    }
    ?>
        <tr>
            <td colspan="4"><b>Total</b></td>
            <td><?php echo number_format($t_total_amount,$info2000['total_decimal']); ?></td>
        </tr>
    </table>
</div>
<?php } else { ?>
<?php } ?>
<div class="clearfix"></div>
<?php } 
else if(isset($_POST['maxcid']))
{
$cid=test_input($_POST['maxcid']);
$data34 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM sales WHERE customer_id='$cid'") or die(mysqli_error($conn));       
$info34 = mysqli_fetch_array( $data34 );
$data36 = mysqli_query($conn,"SELECT ob FROM customer WHERE id='$cid'") or die(mysqli_error($conn));       
$info36 = mysqli_fetch_array( $data36 );
$tot= $info34['sum']+ $info36['ob'];
?>
Amount <input name="amount" type="number" required class="form-control" max="<?php echo $tot;?>" value="0" />
<br />
<?php }
else if(isset($_POST['custdisc']))
{
$cid=test_input($_POST['custdisc']);
$data34 = mysqli_query($conn,"SELECT invoice_discount FROM customer WHERE id='$cid'") or die(mysqli_error($conn));       
$info34 = mysqli_fetch_array( $data34 );
$tot= $info34['invoice_discount'];
if($info3000['en_elixirbeauty'])
  $tot=0;
?>
Discount (%) <input name="discount" step="0.0001" type="number" id="discount" class="form-control" tabindex="15" accesskey="d"
    value="<?php echo $tot;?>" />
<br />
<?php }
else if(isset($_POST['custmark']))
{
$cid=test_input($_POST['custmark']);
$fid = mysqli_get_var("SELECT id FROM rice_field WHERE customer = 1 AND `class` LIKE '%customermark%' LIMIT 1");
$value = '';
if($fid!='') {
    $value = mysqli_get_var("SELECT value FROM rice_field_details WHERE sid = '$cid' AND fid = '$fid' AND stype = 13 ORDER BY id DESC LIMIT 1");
    if($value=='') {
        $value = mysqli_get_var("SELECT value FROM rice_field WHERE id = '$fid'");
    }
}
if($value=='') { $value = 0; }
echo $value;
}
else if(isset($_POST['custtax']))
{
$cid=test_input($_POST['custtax']);
$sst=test_input($_POST['sst']);
$data34 = mysqli_query($conn,"Select direct_invoicetax2 from customer where `id` = '$cid'  ") or die(mysqli_error($conn));       
$info34 = mysqli_fetch_array( $data34 );
if($sst==1 && $info34['direct_invoicetax2']!='-1') {
$tot= $info34['direct_invoicetax2'];
} else {
$tot = 0;    
}
echo 'Tax Applied <input name="tax" type="text" id="tax" value="'.$tot.'" class="form-control income_count"    /><br>';   
 }
else if(isset($_POST['custdisc55']))
{
 $cid=test_input($_POST['custdisc55']);
?><br />
<br />
<table width="100%" border="1" class="bgcolor-alert" cellspacing="0" cellpadding="5">
    <tr>
        <td>Sales order (Approved)</td>
        <td><?php 
   $tot1 = mysqli_get_var("Select sum(total) from so  where approval=1 && completed=0 && customer_id='$cid' "); echo number_format($tot1); ?>
        </td>
    </tr>
    <tr>
        <td>Sale order (In approval)</td>
        <td><?php $tot2 = mysqli_get_var("Select sum(total) from so  where approval=0 && completed=0 && customer_id='$cid' "); echo number_format($tot2); ?>
        </td>
    </tr>
    <tr>
        <td>Sale orders (Total)</td>
        <td><?php  echo number_format($tot1+$tot2);  ?></td>
        </th>
    </tr>
    <tr>
        <td>Payment Available</td>
        <th><?php 
$data34 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM sales WHERE customer_id='$cid'") or die(mysqli_error($conn));       
$info34 = mysqli_fetch_array( $data34 );
$data40 = mysqli_query($conn,"SELECT SUM(advance_payment) as sum FROM customer WHERE id='$cid'") or die(mysqli_error($conn));      
$info40 = mysqli_fetch_array( $data40 );
$data38 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM sales_debit_note WHERE cid='$cid'") or die(mysqli_error($conn));      
$info38 = mysqli_fetch_array( $data38 );
$data36 = mysqli_query($conn,"SELECT ob FROM customer WHERE id='$cid'") or die(mysqli_error($conn));       
$info36 = mysqli_fetch_array( $data36 );
$tot3 = $info34['sum']+$info38['sum'] - $info40['sum'] + $info36['ob'];
echo number_format($tot3); ?> </th>
    </tr>
    <tr>
        <td>Balance Payment </td>
        <th><?php $tot4= $tot1+$tot2+$tot3; if($tot4<0) { echo number_format($tot4*-1); echo " - Advance Payment"; } else { echo number_format($tot4); } ?>
        </th>
    </tr>
</table>
<?php }
else if(isset($_POST['cid']))
{
$cid=test_input($_POST['cid']);

$credit_limit = mysqli_get_var("Select credit_amount from customer WHERE id='$cid' ");

$tot = bms_customer_old_receivable_amount($cid, 'simple');
$credit_limit2 = mysqli_get_var("Select amount from cust_ven_payment_terms WHERE pid='$cid' AND type = 1 ");
$balancelimit = $credit_limit - $tot; 
$balancelimit2 = $credit_limit2 - $tot;  
if($balancelimit<0) $balancelimit=0;
if($balancelimit2<0) $balancelimit2=0;
?>
Old Receivable<input name="old" type="text" tabindex="-1" class="form-control" id="old" value="<?php echo $tot;?>"
    readonly="readonly" />
<br />
<?php
  if($info2000['en_fixed_payment_term'] == 1){
    if($credit_limit2 !='-1' && $credit_limit2 !='0'){
      $mess = '<div class="alert alert-warning alert-border-left alert-dismissible fade show"><button type="button" class="btn btn-warning btn-xs">Note</button><br />Customer Balance: <b>'.number_format($tot).'</b> <br />Allowed Balance: <b>'.number_format($credit_limit2).'</b>  <br />Remaining Balance: <b>'.number_format($balancelimit2).'</b> <br /></div>'; 
      ?>
<script type="text/javascript">
$(".results55").html('<?php  echo $mess; ?>');
$("#total").attr({
    "max": <?php echo $balancelimit2; ?>, // substitute your own
    "min": 0 // values (or variables) here
});
</script>
<?php 
    }else{
      ?>
<script type="text/javascript">
$(".results55").html('');
</script>
<?php 
    }
  } 
  else if($info2000['lock_customercredit']==1 && $info2000['brandlimit_enable']!=1  && $credit_limit!='-1' && $credit_limit!='0') {
$mess = '<div class="alert alert-warning alert-border-left alert-dismissible fade show"><button type="button" class="btn btn-warning btn-xs">Note</button><br />Customer Balance: <b>'.number_format($tot).'</b> <br />Allowed Balance: <b>'.number_format($credit_limit).'</b>  <br />Remaining Balance: <b>'.number_format($balancelimit).'</b> <br /></div>';  
    ?>
<script type="text/javascript">
$(".results55").html('<?php  echo $mess; ?>');
$("#total").attr({
    "max": <?php echo $balancelimit; ?>, // substitute your own
    "min": 0 // values (or variables) here
});
</script>
<?php }  
 else {
     ?>
<script type="text/javascript">
$(".results55").html('');
</script>
<?php
   }  
 }
else if(isset($_POST['cid522']))
{
$cid=test_input($_POST['cid522']);
?>
<table width="100%" cellpadding="5" class="table table-striped table-hover align-middle" id="acart">
    <thead>
        <tr>
            <th>
                <div>&nbsp;</div>
            </th>
            <th width="20%">
                <div><?php echo $info1000['product_label']; ?></div>
            </th>
            <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                <div>QTA</div>
            </th>
            <th>
                <div><?php echo $info1000['multi_unit_label']; ?></div>
            </th>
            <th>
                <div>Stitch/Unit </div>
            </th>
            <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                <div><?php echo $info1000['single_unit_label']; ?></div>
            </th>
            <?php if($info1000['en_warehouse']==1) {  echo  '  <th ><div>WH </div></th> '; } ?>
            <?php if($info1000['en_inventorybatch']==1) {   echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; } ?>
            <?php if($info1000['en_embroidery']==1) { 
         echo  ' 
          <th ><div>Type </div></th>
          <th ><div>Colors </div></th>
         <th ><div>Head Working </div></th>
         <th ><div>Fusing </div></th>
          '; } ?>
            <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                <div><?php echo $info1000['packing_label']; ?></div>
            </th>
            <th>
                <div><?php echo $info1000['price_label']; ?></div>
            </th>
            <?php if($info1000['customer_discount1']==1) {  echo  '  <th ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
            <?php if($info1000['customer_discount2']==1) {  echo  '  <th ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
            <?php if($info1000['customer_discount3']==1) {  echo  '  <th ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
            <?php if($info1000['customer_scheme']==1) {  echo  '  <th ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
            <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                <div><?php echo $info1000['total_unit_label']; ?></div>
            </th>
            <?php if($info1000['customer_tax1']==1) {  echo  '  <th ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
            <?php if($info1000['customer_tax2']==1) {  echo  '  <th ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
            <?php if($info1000['customer_tax3']==1) {  echo  '  <th ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
            <th>
                <div>Total</div>
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <?php 
       $data2 = mysqli_query($conn,"SELECT i.*, e.prd_id, e.id as did,  e.type_id as ttid, e.qty as eqty, e.stitches as estitch, head_working, color, fusing, rate as rt from inventory i, embroidery_grn_details e where e.prd_id=i.id && invoice=0  && grn_id IN (Select id from embroidery_grn where customer_id='$cid')") or die(mysqli_error($conn));
  $totc=0;
  $totp=0;
  $tots=0;
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
        <?php   if(1==1) { ?>
        <tr class="carttr">
            <td></td>
            <td><input name="products[]" type="hidden" value="<?php echo $info2['prd_id'];?>" /> <input
                    name="delivery_id[]" type="hidden" value="<?php echo $info2['did'];?>" />
                <?php echo $info2['name'];?>
                <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                    <textarea name="products_description[]" class="form-control"
                        placeholder="Details.."><?php echo $info2['details2']; ?></textarea>
                </div>
            </td>
            <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                <?php echo floor($info2['qty']/$info2['dp']);?> </td>
            <td>
                <?php 
  $mpc=$info2['pqty']/$info2['dp'];
$discount=$info2['dd']/100; 
$discount2=$info2['dd2']/100; 
$discount4=$info2['dd4']/100; 
$toffer = $info2['dd3']*($info2['pqty']-$info2['scheme_qty']);
$tax= $info2['ta']/100;
$tax2= $info2['ta2']/100;
$tax3= $info2['ta3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
$discount4=1-$discount4;
$aaqty = $info2['pqty']-$info2['scheme_qty'];
 $n = $info2['pqty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2  ;
$nm = $n + $m ;
$x = ($info2['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x ;
$quant_tot=$info2['pqty']+$quant_tot;
$price=round($price,  $info1000['sproductdecimal'] );
  $totc=$totc+$mpc;?>
                <input type="text" value="<?php echo $info2['eqty']*$info2['estitch'];?>"
                    class="searchqty packing income_count totalorder" size="4" id="ctn<?php echo $info2['id'];?>"
                    tabindex="1" />
            </td>
            <td> <input type="text" value="<?php echo $info2['estitch'];?>" class="" size="4" name='stitch[]'
                    tabindex="1" />
            </td>
            <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>> <input type="text"
                    size="4" value="0" class="form-control change income_count totalorder" tabindex="1"
                    id="pcs<?php echo $info2['id'];?>" />
            </td>
            <?php if($info1000['en_warehouse']==1) { ?>
            <td><select name="products_warehouse[]" class='teacher warehouse'><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse  ") or die(mysqli_error($conn)); 
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
 if($info2['warehouse_id']==$info4['id'])
 {
   echo "<option value='".$info4['id']."' selected >".$info4['name']."</option>";
}
else {
     echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
  }
 }
?>
                </select></td>
            <?php } ?>
            <?php if($info1000['en_inventorybatch']==1) { 
  $pid =  $info2['prd_id'];
  ?>
            <td><select name="products_batch[]" class='teacher warehouse reportselect inventory3'>
                    <?php $data4 = mysqli_query($conn,"SELECT * from inventory_batch where  active=1 && prd_id='$pid'") or die(mysqli_error($conn)); 
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
$batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
 if($info2['batch_id']==$info4['id'])
 {
   echo "<option value='".$info4['id']."' selected >".$batch_code."</option>";
}
else {
     echo "<option value='".$info4['id']."' >".$batch_code."</option>";
  }
 }
?>
                </select></td>
            <?php } ?>
            <?php if($info1000['en_embroidery']==1) { ?>
            <td><select name="products_sarea[]" id="sa<?php echo $info2['id'];?>" class='teacher income_count'>
                    <?php $data4 = mysqli_query($conn,"SELECT * from stitching_area") or die(mysqli_error($conn)); 
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
 if($info2['ttid']==$info4['id'])
 {
   echo "<option value='".$info4['id']."' selected >".$info4['name']."</option>";
}
else {
     echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
  }
 }
?>
                </select></td>
            <td><input name="products_scolor[]" type="text" size="4" value="<?php echo $info2['color']; ?>" />
            </td>
            <td><select name="products_stype[]" id="sa<?php echo $info2['id'];?>" class='teacher stype income_count2'>
                    <?php $data4 = mysqli_query($conn,"SELECT * from stitching_type") or die(mysqli_error($conn)); 
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
    if($info2['head_working']==$info4['id'])
 {
   echo "<option value='".$info4['id']."' selected >".$info4['name']."</option>";
}
else {
     echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
  }
 }
?>
                </select></td>
            <td><select name="products_sfusion[]" class='teacher '>
                    <?php $data4 = mysqli_query($conn,"SELECT * from stitching_fusion") or die(mysqli_error($conn)); 
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
 if($info2['fusing']==$info4['id'])
 {
   echo "<option value='".$info4['id']."' selected >".$info4['name']."</option>";
}
else {
     echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
  }
 }
?>
                </select></td>
            <?php } ?>

            <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>> <input
                    name="products_packing[]" type="number" min="0.1" step="0.001" value="<?php echo $info2['packing'];?>" size="4"
                    class="change income_count edit-input totalorder" tabindex="1" id="p<?php echo $info2['id'];?>" />
            </td>
            <td>
                <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" value="<?php echo $info2['rt'];?>" name="
                []" size="4" class="income_count change totalorder" />
            </td>
            <?php if($info1000['customer_discount1']==1) {     ?> <td><input name="products_discount[]" size="4"
                    type="number" class="edit-input income_count totalorder" id="<?php echo "ppp".$info2['id'];?>"
                    tabindex="1" value="<?php echo $info2['dd'];?>" /></td>
            <?php } else { ?> <input name="products_discount[]" type="hidden"
                class="edit-input income_count totalorder" id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0"
                size="4" />
            <?php } if($info1000['customer_discount2']==1) {     ?> <td><input name="products_discount2[]" size="4"
                    type="text" class="edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>"
                    tabindex="1" value="<?php echo $info2['dd2'];?>" /></td>
            <?php } else { ?> <input name="products_discount2[]" type="hidden"
                class="edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0"
                size="4" />
            <?php }
  if($info1000['customer_discount4']==1) {     ?> <td><input name="products_discount4[]" size="4" type="text"
                    class="edit-input income_count totalorder" id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                    value="<?php echo $info2['dd4'];?>" /></td>
            <?php } else { ?> <input name="products_discount4[]" type="hidden"
                class="edit-input income_count totalorder" id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0"
                size="4" />
            <?php }
   if($info1000['customer_discount3']==1) {     ?> <td><input name="products_discount3[]" type="number" size="4"
                    class="edit-input income_count totalorder products_discount3" id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                    value="<?php echo $info2['dd3'];?>" step="0.000001"  /></td>
            <?php } else { ?>
            <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
            <?php } if($info1000['customer_scheme']==1) {     ?> <td><input name="products_scheme[]" type="text"
                    size="4" class="edit-input income_count totalorder" id="<?php echo "ppps".$info2['id'];?>"
                    tabindex="1" value="<?php echo $info2['scheme'];?>" /></td>
            <?php } else { ?> <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /> <?php }   ?>
            <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                <?php $totp=$totp+$info2['pqty'];?>
                <input name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                    id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info2['scheme_qty'];?>"
                    size="4" />
                <input name="products_pcs[]" type="text" class="edit-input total_pcs"
                    value="<?php echo $info2['pqty'];?>" size="4" id="<?php echo "t".$info2['id'];?>" readonly />
            </td>
            <?php if($info1000['customer_tax1']==1) {     ?> <td><input type="number" name="products_tax[]"
                    class="edit-input income_count" value="<?php echo $info2['ta'];?>" tabindex="1"
                    id="<?php echo "pppp".$info2['id'];?>" size="4" readonly /></td>
            <?php } else { ?>
            <input name="products_tax[]" type="hidden" class="edit-input income_count"
                id="<?php echo "pppp".$info2['id'];?>"
                value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                readonly="readonly" />
            <?php } if($info1000['customer_tax2']==1) {     ?> <td><input type="text" name="products_tax2[]"
                    class="edit-input income_count" value="<?php echo $info2['ta2'];?>"
                    id="<?php echo "ppptt".$info2['id'];?>" size="4" readonly /></td>
            <?php } else { ?>
            <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
            <?php } if($info1000['customer_tax3']==1) {     ?> <td><input type="text" name="products_tax3[]"
                    class="edit-input income_count" value="<?php echo $info2['ta3'];?>"
                    id="<?php echo "pppttt".$info2['id'];?>" size="4" readonly /></td>
            <?php } else { ?>
            <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
            <?php }    ?>
            <td>
                <?php $tots=$tots+$info2['prd_amount'];?>
                <input type="hidden" name="products_cogs[]" value="<?php echo $info2['cogs'];?>"
                    class="prd_cogs" /><input name="products_total[]" step="0.0001" id="newtotal<?php echo $info2['id'];?>" min="0" size="7" type="number"
                    class="tot<?php echo $info2['id'];?> ptotal sub_total income_count readonly "
                    value="<?php echo $info2['prd_amount'];?>" tabindex="-1" onkeypress="return false;" />
            </td>
            <td class="d-flex gap-2">
                <input type="button" class="rounded-1 bg-info text-white border-0 p-1 edit receipt_edit_hide5" value="Edit" />
                <input type="button" class="rounded-1 bg-success text-white border-0 p-1 save" value="Save" /> 
                <input type="button" class="rounded-1 bg-danger text-white border-0 p-1 delete receipt_delete_edit5" value="Delete" /></td>
        </tr>
        <?php 
               } 
                 } ?>
    </tbody>
    <tfoot>
    </tfoot>
</table>
<?php  include('../functions/incomecount_function.php'); ?>
<script type="text/javascript">
var $form = $('#slip'),
    $summands = $form.find('.income_count'),
    $sumDisplay = $('#income_sum');
var sum = 0;
$summands.each(function() {
    var value = Number($(this).val());
    if (!isNaN(value)) sum += value;
});
$sumDisplay.val(sum);
$(".income_count").change(function() {
    var sum = 0;
    $summands.each(function() {
        var value = Number($(this).val());
        if (!isNaN(value)) sum += value;
    });
    $sumDisplay.val(sum);
});



</script>
<script type="text/javascript">
$(document).ready(function() {
    $(document).on('change', '#service_invoice', function () {
        var cid = $("#service_invoice").val();
        $.ajax({
            type: "POST",
            url: "../ajax/serial-query.php",
            data: {
                totax: cid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                $(".invoicetax").html(html);
                $("#discount").trigger("change");
            }
        });
    });
    $('#searchbox').focus();
    $('#searchbox').change(function() {
        var empid = $("#searchbox").val();
        var cid = $(".cid").val();
        var onrecord = $("#onrecord").val();
        if (onrecord > 0) {
            onrecord = 1;
        }
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                sid23: empid,
                customerid: cid,
                st: onrecord
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                $("#psearch").html(html);
                $('#searchbox').val('');
                $('.searchqty:first').focus();
            }
        });
    });
    $('.cid').change(function() {
        var cid = $(".cid").val();
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                cid: cid
            },
            k8cache: false,
            dataType: 'html',
            success: function(html) {
                $("#oldr").html(html);
            }
        });
    });
});
$('.cid').change(function() {
    var vid = $(".cid").val();
    $.ajax({
        type: "POST",
        url: "../ajax/receipt-query.php",
        data: {
            cid5: vid
        },
        cache: false,
        dataType: 'html',
        success: function(html) {
            $("#subcustomer").html(html);
        }
    });
    $.ajax({
        type: "POST",
        url: "../ajax/receipt-query.php",
        data: {
            custdisc: vid
        },
        cache: false,
        dataType: 'html',
        success: function(html) {
            $("#customerdisc").html(html);
        }
    });
});
</script>
<script type="text/javascript">
function changealert(id) {
    $('#' + id).closest("tr").addClass('changecolor2');
}
$('#on_record').click(function() {
    if ($(this).is(':checked')) {
        window.open("new-sales-receipt-recorded.php", "_self");
    }
});
</script>
<script type="text/javascript">
$(function() {
    <?php if ($snum<=0) {?>
    $('.trdiv').hide();
    <?php } ?>
    $('#tr').change(function() {
        if ($('#tr').val() == 'y') {
            $('.trdiv').show();
        } else {
            $('.trdiv').hide();
        }
    });
});
</script>
<script type="text/javascript">
$(document).ready(function() {
    $('.save').hide();
    <?php if($info3000['en_osaka']==1){ ?>
        $('.edit-input').attr("readonly", false);
    <?php }else{ ?>
        $('.edit-input').attr("readonly", true);
    <?php } ?>
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $('.delete').on('click', function() {
        $(this).closest('tr').remove();
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass ==
                    'trade_no_impact') {} else if (specialclass != 'brokery_rs' &&
                    specialclass !=
                    'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass ==
                    'trade_no_impact') {} else if (specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        $(".total-display").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        result2 = Math.round(result2);
        $("#pending_amount").val(result2);
    });
});
$(document).ready(function() {
    $(".income_count").trigger("change");
});
</script>
<?php }
else if(isset($_POST['cid5221']))
{
$cid=test_input($_POST['cid5221']);
?>
<table width="100%" cellpadding="5" class="table table-striped table-hover align-middle" id="acart">
    <thead>
        <tr>
            <th width="5%">
                <div>S.No</div>
            </th>
            <th width="20%">
                <div><?php echo $info1000['product_label']; ?></div>
            </th>

            <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                <div>QTA</div>
            </th>
            <th>
                <div>QTY</div>
            </th>
            <th>
                <div><?php echo $info1000['price_label']; ?></div>
            </th>
            <?php if($info1000['customer_discount1']==1) {  echo  '  <th ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
            <?php if($info1000['customer_discount2']==1) {  echo  '  <th ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
            <?php if($info1000['customer_discount3']==1) {  echo  '  <th ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
            <?php if($info1000['customer_scheme']==1) {  echo  '  <th ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
            <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                <div><?php echo $info1000['total_unit_label']; ?></div>
            </th>
            <?php if($info1000['customer_tax1']==1) {  echo  '  <th ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
            <?php if($info1000['customer_tax2']==1) {  echo  '  <th ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
            <?php if($info1000['customer_tax3']==1) {  echo  '  <th ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
            <th width="80">
                <div>Total</div>
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <?php 
       $data2 = mysqli_query($conn,"SELECT i.*, e.prd_id, e.id as did,  e.type_id as ttid, e.qty as eqty, e.rate as rt, e.stitches as estitch from inventory i, knitting_grn_details e where e.prd_id=i.id && invoice=0  && grn_id IN (Select id from knitting_grn where customer_id='$cid')") or die(mysqli_error($conn));
  $totc=0;
  $totp=0;
  $tots=0;
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
        <?php   if(1==1) { ?>
        <tr class="carttr">
            <td></td>
            <td><input name="products[]" type="hidden" value="<?php echo $info2['prd_id'];?>" /> <input
                    name="delivery_id[]" type="hidden" value="<?php echo $info2['did'];?>" />
                <?php echo $info2['name'];?>
                <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                    <textarea name="products_description[]" class="form-control"
                        placeholder="Details.."><?php echo $info2['details2']; ?></textarea>
                </div>
            </td>
            <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                <?php echo floor($info2['qty']/$info2['dp']);?> </td>
            <td>
                <?php 
  $mpc=$info2['pqty']/$info2['dp'];
$discount=$info2['dd']/100; 
$discount2=$info2['dd2']/100; 
$toffer = $info2['dd3']*($info2['pqty']-$info2['scheme_qty']);
$tax= $info2['ta']/100;
$tax2= $info2['ta2']/100;
$tax3= $info2['ta3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
$discount4=1-$discount4;
$aaqty = $info2['pqty']-$info2['scheme_qty'];
 $n = $info2['pqty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2  ;
$nm = $n + $m ;
$x = ($info2['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x ;
$quant_tot=$info2['pqty']+$quant_tot;
$price=round($price,  $info1000['sproductdecimal'] );
  $totc=$totc+$mpc;?>
                <input type="text" value="<?php echo $info2['eqty'];?>"
                    class="searchqty packing income_count totalorder" size="4" id="ctn<?php echo $info2['id'];?>"
                    tabindex="1" />
            </td>
            <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>> <input type="text"
                    size="4" value="0" class="form-control change income_count totalorder" tabindex="1"
                    id="pcs<?php echo $info2['id'];?>" />
            </td>
            <?php if($info1000['en_warehouse']==1) { ?>
            <td><select name="products_warehouse[]" class='teacher warehouse'><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse  ") or die(mysqli_error($conn)); 
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
 if($info2['warehouse_id']==$info4['id'])
 {
   echo "<option value='".$info4['id']."' selected >".$info4['name']."</option>";
}
else {
     echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
  }
 }
?>
                </select></td>
            <?php } ?>
            <?php if($info1000['en_inventorybatch']==1) { 
  $pid =  $info2['prd_id'];
  ?>
            <td><select name="products_batch[]" class='teacher reportselect warehouse inventory3'>
                    <?php $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'") or die(mysqli_error($conn)); 
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
$batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
 if($info2['batch_id']==$info4['id'])
 {
   echo "<option value='".$info4['id']."' selected >".$batch_code."</option>";
}
else {
     echo "<option value='".$info4['id']."' >".$batch_code."</option>";
  }
 }
?>
                </select></td>
            <?php } ?>

            <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>> <input
                    name="products_packing[]" type="number" min="0.1" step="0.001" value="<?php echo $info2['packing'];?>" size="4"
                    class="change income_count edit-input totalorder" tabindex="1" id="p<?php echo $info2['id'];?>" />
            </td>
            <td>
                <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" min="0" value="<?php echo $info2['rt'];?>"
                    name="unitcos[]" type="number" size="4" required class="income_count change totalorder" />
            </td>
            <?php if($info1000['customer_discount1']==1) {     ?> <td><input name="products_discount[]" size="4"
                    type="number" class="edit-input income_count totalorder" id="<?php echo "ppp".$info2['id'];?>"
                    tabindex="1" value="<?php echo $info2['dd'];?>" /></td>
            <?php } else { ?> <input name="products_discount[]" type="hidden"
                class="edit-input income_count totalorder" id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0"
                size="4" />
            <?php } if($info1000['customer_discount2']==1) {     ?> <td><input name="products_discount2[]" size="4"
                    type="text" class="edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>"
                    tabindex="1" value="<?php echo $info2['dd2'];?>" /></td>
            <?php } else { ?> <input name="products_discount2[]" type="hidden"
                class="edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0"
                size="4" />
            <?php  
  }
  if($info1000['customer_discount4']==1) {     ?> <td><input name="products_discount4[]" size="4" type="text"
                    class="edit-input income_count totalorder" id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                    value="<?php echo $info2['dd4'];?>" /></td>
            <?php } else { ?> <input name="products_discount4[]" type="hidden"
                class="edit-input income_count totalorder" id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0"
                size="4" />
            <?php }
  if($info1000['customer_discount3']==1) {     ?> <td><input name="products_discount3[]" type="number" size="4"
                    class="edit-input income_count totalorder products_discount3" id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                    value="<?php echo $info2['dd3'];?>" step="0.0001" /></td>
            <?php } else { ?>
            <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
            <?php } if($info1000['customer_scheme']==1) {     ?> <td><input name="products_scheme[]" type="text"
                    size="4" class="edit-input income_count totalorder" id="<?php echo "ppps".$info2['id'];?>"
                    tabindex="1" value="<?php echo $info2['scheme'];?>" /></td>
            <?php } else { ?> <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /> <?php }   ?>
            <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                <?php $totp=$totp+$info2['pqty'];?>
                <input name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                    id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info2['scheme_qty'];?>"
                    size="4" />
                <input name="products_pcs[]" type="text" class="edit-input total_pcs"
                    value="<?php echo $info2['pqty'];?>" size="4" id="<?php echo "t".$info2['id'];?>" readonly />
            </td>
            <?php if($info1000['customer_tax1']==1) {     ?> <td><input type="number" name="products_tax[]"
                    class="edit-input income_count" value="<?php echo $info2['ta'];?>" tabindex="1"
                    id="<?php echo "pppp".$info2['id'];?>" size="4" readonly /></td>
            <?php } else { ?>
            <input name="products_tax[]" type="hidden" class="edit-input income_count"
                id="<?php echo "pppp".$info2['id'];?>"
                value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                readonly="readonly" />
            <?php } if($info1000['customer_tax2']==1) {     ?> <td><input type="text" name="products_tax2[]"
                    class="edit-input income_count" value="<?php echo $info2['ta2'];?>"
                    id="<?php echo "ppptt".$info2['id'];?>" size="4" readonly /></td>
            <?php } else { ?>
            <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
            <?php } if($info1000['customer_tax3']==1) {     ?> <td><input type="text" name="products_tax3[]"
                    class="edit-input income_count" value="<?php echo $info2['ta3'];?>"
                    id="<?php echo "pppttt".$info2['id'];?>" size="4" readonly /></td>
            <?php } else { ?>
            <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
            <?php }    ?>
            <td>
                <?php $tots=$tots+$info2['prd_amount'];?>
                <input type="hidden" name="products_cogs[]" value="<?php echo $info2['cogs'];?>"
                    class="prd_cogs" /><input name="products_total[]" step="0.0001"  id="newtotal<?php echo $info2['id'];?>" min="0" size="7" type="number"
                    class="tot<?php echo $info2['id'];?> ptotal sub_total income_count readonly "
                    value="<?php echo $info2['prd_amount'];?>" tabindex="-1" onkeypress="return false;" />
            </td>
            <td class="d-flex gap-2">
                <input type="button" class="rounded-1 bg-info text-white border-0 p-1 edit receipt_edit_hide5" value="Edit" />
                <input type="button" class="rounded-1 bg-success text-white border-0 p-1 save" value="Save" /> 
                <input type="button" class="rounded-1 bg-danger text-white border-0 p-1 delete receipt_delete_edit5" value="Delete" /></td>
        </tr>
        <?php 
               } 
                 } ?>
    </tbody>
    <tfoot>
    </tfoot>
</table>
<?php  include('../functions/incomecount_function.php'); ?>
<script type="text/javascript">
var $form = $('#slip'),
    $summands = $form.find('.income_count'),
    $sumDisplay = $('#income_sum');
var sum = 0;
$summands.each(function() {
    var value = Number($(this).val());
    if (!isNaN(value)) sum += value;
});
$sumDisplay.val(sum);
$(".income_count").change(function() {
    var sum = 0;
    $summands.each(function() {
        var value = Number($(this).val());
        if (!isNaN(value)) sum += value;
    });
    $sumDisplay.val(sum);
});


</script>
<script type="text/javascript">
$(document).ready(function() {
    $(document).on('change', '#service_invoice', function () {
        var cid = $("#service_invoice").val();
        $.ajax({
            type: "POST",
            url: "../ajax/serial-query.php",
            data: {
                totax: cid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                $(".invoicetax").html(html);
                $("#discount").trigger("change");
            }
        });
    });
    $('#searchbox').focus();
    $('#searchbox').change(function() {
        var empid = $("#searchbox").val();
        var cid = $(".cid").val();
        var onrecord = $("#onrecord").val();
        if (onrecord > 0) {
            onrecord = 1;
        }
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                sid2331: empid,
                customerid: cid,
                st: onrecord
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                $("#psearch").html(html);
                $('#searchbox').val('');
                $('.searchqty:first').focus();
            }
        });
    });
    $('.cid').change(function() {
        var cid = $(".cid").val();
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                cid: cid
            },
            k8cache: false,
            dataType: 'html',
            success: function(html) {
                $("#oldr").html(html);
            }
        });
    });
});
$('.cid').change(function() {
    var vid = $(".cid").val();
    $.ajax({
        type: "POST",
        url: "../ajax/receipt-query.php",
        data: {
            cid5: vid
        },
        cache: false,
        dataType: 'html',
        success: function(html) {
            $("#subcustomer").html(html);
        }
    });
    $.ajax({
        type: "POST",
        url: "../ajax/receipt-query.php",
        data: {
            custdisc: vid
        },
        cache: false,
        dataType: 'html',
        success: function(html) {
            $("#customerdisc").html(html);
        }
    });
});
</script>
<script type="text/javascript">
function changealert(id) {
    $('#' + id).closest("tr").addClass('changecolor2');
}
$('#on_record').click(function() {
    if ($(this).is(':checked')) {
        window.open("new-sales-receipt-recorded.php", "_self");
    }
});
</script>
<script type="text/javascript">
$(function() {
    <?php if ($snum<=0) {?>
    $('.trdiv').hide();
    <?php } ?>
    $('#tr').change(function() {
        if ($('#tr').val() == 'y') {
            $('.trdiv').show();
        } else {
            $('.trdiv').hide();
        }
    });
});
</script>
<script type="text/javascript">
$(document).ready(function() {
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $('.delete').on('click', function() {
        $(this).closest('tr').remove();
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass ==
                    'trade_no_impact') {} else if (specialclass != 'brokery_rs' &&
                    specialclass !=
                    'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass ==
                    'trade_no_impact') {} else if (specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        $(".total-display").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        result2 = Math.round(result2);
        $("#pending_amount").val(result2);
    });
});
$(document).ready(function() {
    $(".income_count").trigger("change");
});
</script>
<?php }
else if(isset($_POST['cid5222']))
{
$cid=test_input($_POST['cid5222']);
?>
<table width="100%" cellpadding="5" class="table table-striped table-hover align-middle" id="acart">
    <thead>
        <tr>
            <th width="2%">
                <div>S.No</div>
            </th>
            <th width="25%">
                <div><?php echo $info1000['product_label']; ?></div>
            </th>
            <th>
                <div>Pcs </div>
            </th>
            <th>
                <div>Unit</div>
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <?php 
       $data2 = mysqli_query($conn,"SELECT i.*, e.prd_id, e.id as did, e.qty_produced, e.qty_delivered,  e.type_id as ttid, e.color as ecolor, e.qty as eqty, e.unit_id, e.stitches as estitch from inventory i, embroidery_grn_details e where e.prd_id=i.id && e.qty>e.qty_delivered  && grn_id IN (Select id from embroidery_grn where customer_id='$cid')") or die(mysqli_error($conn));
  $totc=0;
  $totp=0;
  $tots=0;
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
        <?php   if(1==1) { ?>
        <tr class="carttr">
            <td></td>
            <td><input name="products[]" type="hidden" value="<?php echo $info2['prd_id'];?>" /> <input
                    name="delivery_id[]" type="hidden" value="<?php echo $info2['did'];?>" />
                <?php echo $info2['name']; echo " ".$info2['ecolor']." "; $ttid=$info2['ttid']; echo $bq1 = mysqli_get_var("Select name from stitching_area where id='$ttid'"); ?>
                <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                    <textarea name="products_description[]" class="form-control"
                        placeholder="Details.."><?php echo $info2['details2']; ?></textarea>
                </div>
            </td>
            <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                <?php echo floor($info2['qty']/$info2['dp']);?> </td>
            <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>> <input type="text"
                    size="4" value="0" class="form-control change income_count totalorder" tabindex="1"
                    id="pcs<?php echo $info2['id'];?>" />
            </td>
            <?php if($info1000['en_embroidery']==1) { ?>
            <td><input name="products_scolor[]" type="number" step="0.1"
                    max="<?php echo floor($info2['qty_produced']-$info2['qty_delivered']); ?>" required size="4"
                    value="0" />
            </td>
            <td><?php $ttid=$info2['unit_id']; echo $bq1 = mysqli_get_var("Select name from product_unit where id='$ttid'");   ?>
            </td>
            <?php } ?>
            <td><input type="hidden" class="edit" value="Edit" /><input type="hidden" class="save" value="Save" />
                <input type="button" class="delete receipt_delete_edit5" value="Delete" />
            </td>
        </tr>
        <?php 
               } 
                 } ?>
    </tbody>
    <tfoot>
    </tfoot>
</table>
<?php  include('../functions/incomecount_function.php'); ?>
<script type="text/javascript">
var $form = $('#slip'),
    $summands = $form.find('.income_count'),
    $sumDisplay = $('#income_sum');
var sum = 0;
$summands.each(function() {
    var value = Number($(this).val());
    if (!isNaN(value)) sum += value;
});
$sumDisplay.val(sum);
$(".income_count").change(function() {
    var sum = 0;
    $summands.each(function() {
        var value = Number($(this).val());
        if (!isNaN(value)) sum += value;
    });
    $sumDisplay.val(sum);
});


</script>
<script type="text/javascript">
$(document).ready(function() {
    $(document).on('change', '#service_invoice', function () {
        var cid = $("#service_invoice").val();
        $.ajax({
            type: "POST",
            url: "../ajax/serial-query.php",
            data: {
                totax: cid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                $(".invoicetax").html(html);
                $("#discount").trigger("change");
            }
        });
    });
    $('#searchbox').focus();
    $('#searchbox').change(function() {
        var empid = $("#searchbox").val();
        var cid = $(".cid").val();
        var onrecord = $("#onrecord").val();
        if (onrecord > 0) {
            onrecord = 1;
        }
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                sid23: empid,
                customerid: cid,
                st: onrecord
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                $("#psearch").html(html);
                $('#searchbox').val('');
                $('.searchqty:first').focus();
            }
        });
    });
    $('.cid').change(function() {
        var cid = $(".cid").val();
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                cid: cid
            },
            k8cache: false,
            dataType: 'html',
            success: function(html) {
                $("#oldr").html(html);
            }
        });
    });
});
$('.cid').change(function() {
    var vid = $(".cid").val();
    $.ajax({
        type: "POST",
        url: "../ajax/receipt-query.php",
        data: {
            cid5: vid
        },
        cache: false,
        dataType: 'html',
        success: function(html) {
            $("#subcustomer").html(html);
        }
    });
    $.ajax({
        type: "POST",
        url: "../ajax/receipt-query.php",
        data: {
            custdisc: vid
        },
        cache: false,
        dataType: 'html',
        success: function(html) {
            $("#customerdisc").html(html);
        }
    });
});
</script>
<script type="text/javascript">
function changealert(id) {
    $('#' + id).closest("tr").addClass('changecolor2');
}
$('#on_record').click(function() {
    if ($(this).is(':checked')) {
        window.open("new-sales-receipt-recorded.php", "_self");
    }
});
</script>
<script type="text/javascript">
$(function() {
    <?php if ($snum<=0) {?>
    $('.trdiv').hide();
    <?php } ?>
    $('#tr').change(function() {
        if ($('#tr').val() == 'y') {
            $('.trdiv').show();
        } else {
            $('.trdiv').hide();
        }
    });
});
</script>
<script type="text/javascript">
$(document).ready(function() {
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $('.delete').on('click', function() {
        $(this).closest('tr').remove();
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass ==
                    'trade_no_impact') {} else if (specialclass != 'brokery_rs' &&
                    specialclass !=
                    'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass ==
                    'trade_no_impact') {} else if (specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        $(".total-display").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        result2 = Math.round(result2);
        $("#pending_amount").val(result2);
    });
});
$(document).ready(function() {
    $(".income_count").trigger("change");
});
</script>
<?php }
else if(isset($_POST['cid52223']))
{
$cid=test_input($_POST['cid52223']);
?>
<table width="100%" cellpadding="5" class="table table-striped table-hover align-middle" id="acart">
    <thead>
        <tr>
            <th width="2%">
                <div>S.No</div>
            </th>
            <th width="25%">
                <div><?php echo $info1000['product_label']; ?></div>
            </th>
            <th>
                <div>Total KG </div>
            </th>
            <th>
                <div>Unit</div>
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <?php 
       $data2 = mysqli_query($conn,"SELECT i.*, e.prd_id, e.id as did, e.qty_produced, e.qty_delivered,  e.type_id as ttid, e.color as ecolor, e.qty as eqty, e.unit_id, e.stitches as estitch from inventory i, knitting_grn_details e where e.prd_id=i.id && e.qty>e.qty_delivered  && grn_id IN (Select id from knitting_grn where customer_id='$cid')") or die(mysqli_error($conn));
  $totc=0;
  $totp=0;
  $tots=0;
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
        <?php   if(1==1) { ?>
        <tr class="carttr">
            <td></td>
            <td><input name="products[]" type="hidden" value="<?php echo $info2['prd_id'];?>" /> <input
                    name="delivery_id[]" type="hidden" value="<?php echo $info2['did'];?>" />
                <?php echo $info2['name']; echo " ".$info2['ecolor']." "; $ttid=$info2['ttid']; echo $bq1 = mysqli_get_var("Select name from stitching_area where id='$ttid'"); ?>
                <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                    <textarea name="products_description[]" class="form-control"
                        placeholder="Details.."><?php echo $info2['details2']; ?></textarea>
                </div>
            </td>
            <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                <?php echo floor($info2['qty']/$info2['dp']);?> </td>
            <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>> <input type="text"
                    size="4" value="0" class="form-control change income_count totalorder" tabindex="1"
                    id="pcs<?php echo $info2['id'];?>" />
            </td>
            <?php if($info1000['en_embroidery']==1) { ?>
            <td><input name="products_scolor[]" type="number" step="0.1"
                    max="<?php echo floor($info2['qty_produced']-$info2['qty_delivered']); ?>" required size="4"
                    value="0" />
            </td>
            <td>KG </td>
            <?php } ?>
            <td><input type="hidden" class="edit" value="Edit" /><input type="hidden" class="save" value="Save" />
                <input type="button" class="delete receipt_delete_edit5" value="Delete" />
            </td>
        </tr>
        <?php 
               } 
                 } ?>
    </tbody>
    <tfoot>
    </tfoot>
</table>
<?php  include('../functions/incomecount_function.php'); ?>
<script type="text/javascript">
var $form = $('#slip'),
    $summands = $form.find('.income_count'),
    $sumDisplay = $('#income_sum');
var sum = 0;
$summands.each(function() {
    var value = Number($(this).val());
    if (!isNaN(value)) sum += value;
});
$sumDisplay.val(sum);
$(".income_count").change(function() {
    var sum = 0;
    $summands.each(function() {
        var value = Number($(this).val());
        if (!isNaN(value)) sum += value;
    });
    $sumDisplay.val(sum);
});

</script>
<script type="text/javascript">
$(document).ready(function() {
    $(document).on('change', '#service_invoice', function () {
        var cid = $("#service_invoice").val();
        $.ajax({
            type: "POST",
            url: "../ajax/serial-query.php",
            data: {
                totax: cid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                $(".invoicetax").html(html);
                $("#discount").trigger("change");
            }
        });
    });
    $('#searchbox').focus();
    $('#searchbox').change(function() {
        var empid = $("#searchbox").val();
        var cid = $(".cid").val();
        var onrecord = $("#onrecord").val();
        if (onrecord > 0) {
            onrecord = 1;
        }
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                sid23: empid,
                customerid: cid,
                st: onrecord
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                $("#psearch").html(html);
                $('#searchbox').val('');
                $('.searchqty:first').focus();
            }
        });
    });
    $('.cid').change(function() {
        var cid = $(".cid").val();
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                cid: cid
            },
            k8cache: false,
            dataType: 'html',
            success: function(html) {
                $("#oldr").html(html);
            }
        });
    });
});
$('.cid').change(function() {
    var vid = $(".cid").val();
    $.ajax({
        type: "POST",
        url: "../ajax/receipt-query.php",
        data: {
            cid5: vid
        },
        cache: false,
        dataType: 'html',
        success: function(html) {
            $("#subcustomer").html(html);
        }
    });
    $.ajax({
        type: "POST",
        url: "../ajax/receipt-query.php",
        data: {
            custdisc: vid
        },
        cache: false,
        dataType: 'html',
        success: function(html) {
            $("#customerdisc").html(html);
        }
    });
});
</script>
<script type="text/javascript">
function changealert(id) {
    $('#' + id).closest("tr").addClass('changecolor2');
}
$('#on_record').click(function() {
    if ($(this).is(':checked')) {
        window.open("new-sales-receipt-recorded.php", "_self");
    }
});
</script>
<script type="text/javascript">
$(function() {
    <?php if ($snum<=0) {?>
    $('.trdiv').hide();
    <?php } ?>
    $('#tr').change(function() {
        if ($('#tr').val() == 'y') {
            $('.trdiv').show();
        } else {
            $('.trdiv').hide();
        }
    });
});
</script>
<script type="text/javascript">
$(document).ready(function() {
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $('.delete').on('click', function() {
        $(this).closest('tr').remove();
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass ==
                    'trade_no_impact') {} else if (specialclass != 'brokery_rs' &&
                    specialclass !=
                    'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass ==
                    'trade_no_impact') {} else if (specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        $(".total-display").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        result2 = Math.round(result2);
        $("#pending_amount").val(result2);
    });
});
$(document).ready(function() {
    $(".income_count").trigger("change");
});
</script>
<?php }
else if(isset($_POST['salesblockid']))
{
$cid=test_input($_POST['salesblockid']);
$bq1 = mysqli_get_var("Select level from salesman_block_types where id='$cid'");   
$data4 = mysqli_query($conn,"SELECT s.*, t.level from salesman_block s, salesman_block_types t where s.type=t.id && `level`<'$bq1'"); 
echo "<select name='parent' id='combobox' required  class='form-control'   >
<option value='0' >No parent</option>
";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name'].' ('.$info4['level'].") </option>";
}
echo "</select>";
?>
<?php }
else if(isset($_POST['cid99']))
{
$cid=test_input($_POST['cid99']);
$no=test_input($_POST['no']);
$cledger = $cid;
 $withholding_tax = mysqli_get_var("SELECT withholding_tax FROM customer WHERE id = '$cid' ");
$tot = bms_customer_old_receivable_amount($cid, 'detailed');
?>
Old Receivable <input name="old" type="text" class="form-control" id="old"
    value="<?php echo number_format($tot,$info2000['total_decimal']);?>" readonly="readonly" />
<?php if($no != 1){ ?>
<br />
<table width="100%" border="0" cellspacing="0" id="tblExport" cellpadding="5" class="table-bordered table-striped">
    <tr>
        <td><b>Month</b></td>
        <td><b>Pending Payment</b></td>
    </tr>
    <?php  
    $hotelUnion = "";
    if($info4000['en_hotel'] == 1){
        $hotelUnion = "
            UNION ALL
            SELECT datetime, 
                   0 AS s1, 
                   (amount * -1) AS s2, 
                   0 AS s3, 
                   0 AS s4
            FROM payment_received
            WHERE cid='$cledger'
        ";
    }
   // $data63 = mysqli_query($conn,"
   //      SELECT 
   //          MONTHNAME(DATETIME) AS mn, 
   //          YEAR(DATETIME) AS yn, 
   //          SUM(s1 + s3 + s4 + s2) AS pa
   //      FROM
   //      (
   //          SELECT datetime, pending_amount AS s1, 0 AS s2, 0 AS s3, 0 AS s4 
   //          FROM sales 
   //          WHERE customer_id='$cledger'

   //          UNION ALL
   //          SELECT datetime, 0 AS s1, 0 AS s2, pending_amount AS s3, 0 AS s4  
   //          FROM sales_debit_note  
   //          WHERE cid='$cledger'

   //          UNION ALL
   //          SELECT obdate AS datetime, 0 AS s1, 0 AS s2, 0 AS s3, ob AS s4  
   //          FROM customer 
   //          WHERE id='$cledger'

   //          $hotelUnion
   //      ) AS UnionTable
   //      GROUP BY YEAR(DATETIME), MONTH(DATETIME)
   //      ORDER BY YEAR(DATETIME) DESC, MONTH(DATETIME) DESC
   //  ") or die(mysqli_error($conn));

   $data63 = mysqli_query($conn,"
    SELECT 
        MIN(MONTHNAME(DATETIME)) AS mn, 
        YEAR(DATETIME) AS yn, 
        SUM(s1 + s3 + s4 + s2) AS pa
    FROM
    (
        SELECT datetime, pending_amount AS s1, 0 AS s2, 0 AS s3, 0 AS s4 
        FROM sales 
        WHERE customer_id='$cledger'

        UNION ALL
        SELECT datetime, 0 AS s1, 0 AS s2, pending_amount AS s3, 0 AS s4  
        FROM sales_debit_note  
        WHERE cid='$cledger'

        UNION ALL
        SELECT COALESCE(obdate, '$current_time') AS datetime, 0 AS s1, 0 AS s2, 0 AS s3,
               (CASE WHEN COALESCE(ob,0)!=0 THEN ob ELSE COALESCE(ob,0) END) AS s4
        FROM customer 
        WHERE id='$cledger'

        $hotelUnion
    ) AS UnionTable
    GROUP BY YEAR(DATETIME), MONTH(DATETIME)
    ORDER BY YEAR(DATETIME) DESC, MONTH(DATETIME) DESC
") or die(mysqli_error($conn));

    $ta=0;
while($info63 = mysqli_fetch_array( $data63 )) 
 { 
  ?>
    <?php if($info63['pa']!=0) { ?>
    <tr>
        <td><?php echo $info63['mn']; ?> <?php echo $info63['yn']; ?></td>
        <td><?php if($info63['pa'] < 0){ $info63['pa'] = 0; } echo number_format($info63['pa'],$info2000['total_decimal']); $ta=$info63['pa']+$ta; ?></td>
    </tr>
    <?php } }  ?>
    <?php
    if($ta == 0 && $tot > 0){
        $opening_date = mysqli_get_var("SELECT obdate FROM customer WHERE id='$cledger'");
        if($opening_date != '' && $opening_date != NULL){
            $fallback_label = date('M Y', strtotime($opening_date));
        } else {
            $fallback_label = 'Balance Fwd';
        }
        ?>
        <tr>
            <td><?php echo $fallback_label; ?></td>
            <td><?php echo number_format($tot,$info2000['total_decimal']); ?></td>
        </tr>
        <?php
        $ta = $tot;
    }
    ?>
    <?php
    if(isset($info2000['customervendor_same']) && (int)$info2000['customervendor_same'] === 1) {
        $net_adjustment = (float)$tot - (float)$ta;
        if(abs($net_adjustment) > 0.0000001) {
            ?>
    <tr>
        <td>Net Adjustment</td>
        <td><?php echo number_format($net_adjustment,$info2000['total_decimal']); ?></td>
    </tr>
    <?php
            $ta = $ta + $net_adjustment;
        }
    }
    ?>
    <tr>
        <td><b>Total</b></td>
        <td><?php if($ta < 0){ $ta = 0; } echo number_format($ta,$info2000['total_decimal']); ?></td>
    </tr>
</table>
<?php } ?>
<?php if($withholding_tax!=0 && $withholding_tax!=-1) { ?>
<script type="text/javascript">
$(".whtax_percent").val(<?php echo $withholding_tax; ?>);
</script>
<?php 
} }
else if(isset($_POST['debit_note_dist_to']) && isset($_POST['debit_note_dist_from']))
{
  $debit_note_dist_to=test_input($_POST['debit_note_dist_to']);
  $debit_note_dist_from=test_input($_POST['debit_note_dist_from']);
  $cid=0;//test_input($_POST['cid99']);
  $no=0;//test_input($_POST['no']);
  $cledger = $cid;
  $data34 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM sales WHERE distributor_to_id='$debit_note_dist_to' && distributor_from_id ='$debit_note_dist_from' ") or die(mysqli_error($conn));       
  $info34 = mysqli_fetch_array( $data34 );
  // $data40 = mysqli_query($conn,"SELECT SUM(advance_payment) as sum FROM customer WHERE id='$cid'") or die(mysqli_error($conn));      
  // $info40 = mysqli_fetch_array( $data40 );
  $data38 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM sales_debit_note WHERE  distributor_to_id='$debit_note_dist_to' && distributor_from_id ='$debit_note_dist_from' ") or die(mysqli_error($conn));      
  $info38 = mysqli_fetch_array( $data38 );
  // $data36 = mysqli_query($conn,"SELECT ob FROM customer WHERE id='$cid'") or die(mysqli_error($conn));       
  // $info36 = mysqli_fetch_array( $data36 );
  $tot= $info34['sum']+$info38['sum'] - $info40['sum'] + $info36['ob'];
  ?>
Old Receivable <input name="old" type="text" class="form-control" id="old"
    value="<?php echo number_format($tot,$info2000['total_decimal']);?>" readonly="readonly" />
<?php if($no != 1){ ?>
<br />
<table width="100%" border="0" cellspacing="0" id="tblExport" cellpadding="5" class="table-bordered table-striped">
    <tr>
        <td><b>Month</b></td>
        <td><b>Pending Payment</b></td>
    </tr>
    <?php  
      // UNION ALL
      // SELECT obdate as DATETIME, 0 AS s1, 0 AS s2, 0 AS s3, ob AS s4  FROM customer 
      // where id='$cledger' 
     $data63 = mysqli_query($conn,"SELECT MONTHNAME(DATETIME) AS mn, YEAR(DATETIME) AS yn, SUM(s1-s2+s3+s4) AS pa
  FROM
  (
      SELECT DATETIME, pending_amount AS s1, 0 AS s2, 0 AS s3, 0 as s4 FROM sales where distributor_to_id='$debit_note_dist_to' && distributor_from_id ='$debit_note_dist_from'
      UNION ALL
      SELECT DATETIME, 0 AS s1, 0 AS s2, pending_amount AS s3, 0 as s4  FROM sales_debit_note  where distributor_to_id='$debit_note_dist_to' && distributor_from_id ='$debit_note_dist_from'
      ) AS UnionTable
  GROUP BY  YEAR(DATETIME), MONTHNAME(DATETIME) order by YEAR(DATETIME), MONTHNAME(DATETIME) DESC
  ") or die(mysqli_error($conn));
      $ta=0;
  while($info63 = mysqli_fetch_array( $data63 )) 
   { 
    ?>
    <?php if($info63['pa']!=0) { ?>
    <tr>
        <td><?php echo $info63['mn']; ?> <?php echo $info63['yn']; ?></td>
        <td><?php echo number_format($info63['pa'],$info2000['total_decimal']); $ta=$info63['pa']+$ta; ?></td>
    </tr>
    <?php } }  ?>
    <tr>
        <td><b>Total</b></td>
        <td><?php echo number_format($ta,$info2000['total_decimal']); ?></td>
    </tr>
</table>
<?php } ?>
<?php }
else if(isset($_POST['cid993']))
{
$cid=test_input($_POST['cid993']);
$cledger = $cid;
customerpaymentfifoclearsnd($cid);
$data34 = mysqli_query($conn,"SELECT SUM(total2-amount_received) as sum FROM so WHERE customer_id='$cid' AND order_delete=0 && execute_complete=1") or die(mysqli_error($conn));      
$info34 = mysqli_fetch_array( $data34 );
$data40 = mysqli_query($conn,"SELECT SUM(advance_payment) as sum FROM customer WHERE id='$cid'") or die(mysqli_error($conn));      
$info40 = mysqli_fetch_array( $data40 );
$data38 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM sales_debit_note WHERE cid='$cid'") or die(mysqli_error($conn));      
$info38 = mysqli_fetch_array( $data38 );
$data36 = mysqli_query($conn,"SELECT ob FROM customer WHERE id='$cid'") or die(mysqli_error($conn));       
$info36 = mysqli_fetch_array( $data36 );
$tot= $info34['sum']+$info38['sum'] - $info40['sum'] + $info36['ob'];
?>
Old Receivable <input name="old" type="text" class="form-control" id="old" value="<?php echo $tot;?>"
    readonly="readonly" />
<br />
<table width="100%" border="0" cellspacing="0" id="tblExport" cellpadding="5" class="table-bordered table-striped">
    <tr>
        <td><b>Month</b></td>
        <td><b>Pending Payment</b></td>
    </tr>
    <?php  
   $data63 = mysqli_query($conn,"SELECT MONTHNAME(DATETIME) AS mn, YEAR(DATETIME) AS yn, SUM(s1-s2+s3+s4) AS pa
FROM
(
    SELECT DATETIME, total-amount_received AS s1, 0 AS s2, 0 AS s3, 0 as s4 FROM so where customer_id='$cledger' AND order_delete=0 && execute_complete=1 
    UNION ALL
    SELECT DATETIME, 0 AS s1, 0 AS s2, pending_amount AS s3, 0 as s4  FROM sales_debit_note  where cid='$cledger'
    UNION ALL
    SELECT obdate as DATETIME, 0 AS s1, 0 AS s2, 0 AS s3, ob AS s4  FROM customer 
    where id='$cledger' 
    ) AS UnionTable
GROUP BY  YEAR(DATETIME), MONTHNAME(DATETIME) order by YEAR(DATETIME), MONTHNAME(DATETIME) DESC
") or die(mysqli_error($conn));
    $ta=0;
while($info63 = mysqli_fetch_array( $data63 )) 
 { 
  ?>
    <?php if($info63['pa']!=0) { ?>
    <tr>
        <td><?php echo $info63['mn']; ?> <?php echo $info63['yn']; ?></td>
        <td><?php echo number_format($info63['pa']); $ta=$info63['pa']+$ta; ?></td>
    </tr>
    <?php } }  ?>
    <tr>
        <td><b>Total</b></td>
        <td><?php echo number_format($ta); ?></td>
    </tr>
</table>
<?php }
else if(isset($_POST['cid992']))
{
$cid=test_input($_POST['cid992']);
$cledger = $cid;
$data34 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM sales WHERE customer_id='$cid'") or die(mysqli_error($conn));       
$info34 = mysqli_fetch_array( $data34 );
$data40 = mysqli_query($conn,"SELECT SUM(advance_payment) as sum FROM customer WHERE id='$cid'") or die(mysqli_error($conn));      
$info40 = mysqli_fetch_array( $data40 );
$data38 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM sales_debit_note WHERE cid='$cid'") or die(mysqli_error($conn));      
$info38 = mysqli_fetch_array( $data38 );
$data36 = mysqli_query($conn,"SELECT ob FROM customer WHERE id='$cid'") or die(mysqli_error($conn));       
$info36 = mysqli_fetch_array( $data36 );
$tot= $info34['sum']+$info38['sum'] - $info40['sum'] + $info36['ob'];
?>
Old Receivable <input name="old" type="text" class="form-control" id="old" value="<?php echo $tot;?>"
    readonly="readonly" />
<br />
<table width="100%" border="0" cellspacing="0" id="tblExport" cellpadding="5" class="table-bordered table-striped">
    <tr>
        <td><b>Month</b></td>
        <td><b>Pending Payment</b></td>
    </tr>
    <?php  
   $data63 = mysqli_query($conn,"SELECT MONTHNAME(DATETIME) AS mn, YEAR(DATETIME) AS yn, SUM(s1-s2+s3+s4) AS pa
FROM
(
    SELECT DATETIME, pending_amount AS s1, 0 AS s2, 0 AS s3, 0 as s4 FROM sales where customer_id='$cledger' 
    UNION ALL
    SELECT DATETIME, 0 AS s1, 0 AS s2, pending_amount AS s3, 0 as s4  FROM sales_debit_note  where cid='$cledger'
    UNION ALL
    SELECT obdate as DATETIME, 0 AS s1, 0 AS s2, 0 AS s3, ob AS s4  FROM customer 
    where id='$cledger' 
    ) AS UnionTable
GROUP BY  YEAR(DATETIME), MONTHNAME(DATETIME) order by YEAR(DATETIME), MONTHNAME(DATETIME) DESC
") or die(mysqli_error($conn));
    $ta=0;
while($info63 = mysqli_fetch_array( $data63 )) 
 { 
  ?>
    <?php if($info63['pa']!=0) { ?>
    <tr>
        <td><?php echo $info63['mn']; ?> <?php echo $info63['yn']; ?></td>
        <td><?php echo number_format($info63['pa']); $ta=$info63['pa']+$ta; ?></td>
    </tr>
    <?php } }  ?>
    <tr>
        <td><b>Total</b></td>
        <td><?php echo number_format($ta); ?></td>
    </tr>
</table>
<?php }
else if(isset($_POST['cid9921']))
{
$cid=test_input($_POST['cid9921']);
$cledger = $cid;
$data34 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM expense WHERE vendor='$cid'") or die(mysqli_error($conn));      
$info34 = mysqli_fetch_array( $data34 );
$data35 = mysqli_query($conn,"SELECT SUM(oba) as sum FROM expense_vendor WHERE id='$cid'") or die(mysqli_error($conn));      
$info35 = mysqli_fetch_array( $data35 );
$data40 = mysqli_query($conn,"SELECT SUM(advance_payment) as sum FROM expense_vendor WHERE id='$cid'") or die(mysqli_error($conn));      
$info40 = mysqli_fetch_array( $data40 );
$tot= $info34['sum'] + $info35['sum'] - $info40['sum'] ;
?>
Old Payable <input name="old" type="text" class="form-control" id="old" value="<?php echo $tot;?>"
    readonly="readonly" />
<br />
<table width="100%" border="0" cellspacing="0" id="tblExport" cellpadding="5" class="table-bordered table-striped">
    <tr>
        <td><b>Month</b></td>
        <td><b>Pending Payment</b></td>
    </tr>
    <?php  
   $data63 = mysqli_query($conn,"SELECT MONTHNAME(DATETIME) AS mn, YEAR(DATETIME) AS yn, SUM(s1-s2+s3+s4) AS pa
FROM
(
    SELECT DATETIME, pending_amount AS s1, 0 AS s2, 0 AS s3, 0 as s4 FROM expense where vendor='$cledger'  
    UNION ALL
    SELECT obdate as DATETIME, 0 AS s1, 0 AS s2, 0 AS s3, ob AS s4  FROM expense_vendor 
    where id='$cledger' 
    ) AS UnionTable
GROUP BY  YEAR(DATETIME), MONTHNAME(DATETIME), MONTH(DATETIME) order by YEAR(DATETIME) DESC, MONTH(DATETIME) DESC
") or die(mysqli_error($conn));
    $ta=0;
while($info63 = mysqli_fetch_array( $data63 )) 
 { 
  ?>
    <?php if($info63['pa']!=0) { ?>
    <tr>
        <td><?php echo $info63['mn']; ?> <?php echo $info63['yn']; ?></td>
        <td><?php echo number_format($info63['pa']); $ta=$info63['pa']+$ta; ?></td>
    </tr>
    <?php } }  ?>
    <tr>
        <td><b>Total</b></td>
        <td><?php echo number_format($ta); ?></td>
    </tr>
</table>
<?php }
else if(isset($_POST['cid520230131']))
{
 $cid=test_input($_POST['cid520230131']);
if($cid=='a' || $cid=='')
   $cid = "";
  else {
  $cid = str_replace("a, "," ",$cid);   
  $cid = " AND cid IN ($cid)";
  }
$data34 = mysqli_query($conn,"SELECT * FROM sub_customer WHERE 1=1  $cid order by name") or die(mysqli_error($conn));     
$num_rows = mysqli_num_rows($data34);
if($num_rows!=0) {
echo " <select name='subc' id='subc' class=' reportselect form-control'>";
echo "<option value='0' >Select a {$subCustomerLabel}</option> ";
while($info34 = mysqli_fetch_array( $data34 )){
echo "<option value='".$info34['id']."' >".$info34['name']."</option>"; 
}
echo "</select><br />";
}?>
<script>
$('.reportselect').select();
</script>
<?php
}
else if(isset($_POST['cid5']))
{
 $cid=test_input($_POST['cid5']);
$subcust = $_POST['subcust'];
$paypage = $_POST['paypage'];
$subc_multi = isset($_POST['subc_multi']) ? test_input($_POST['subc_multi']) : 0;
if($cid=='a' || $cid=='')
   $cid = "";
  else {
  $cid = str_replace("a, "," ",$cid);   
  $cid = " AND cid IN ($cid)";
  }
$quotation_id= $_POST['quotation_id'];
if($quotation_id!=""){
  $quot_sub_customer= mysqli_get_var("SELECT sub_customer from lead_quotation where lq_id='$quotation_id' ");
}
if($quot_sub_customer!="" && $quot_sub_customer!=0){
  $subcust=$quot_sub_customer;
}
//echo "SELECT * FROM sub_customer WHERE 1=1  $cid order by name";
$data34 = mysqli_query($conn,"SELECT * FROM sub_customer WHERE 1=1  $cid order by name") or die(mysqli_error($conn));     
$num_rows = mysqli_num_rows($data34);
if($num_rows!=0) {
if($subc_multi==1){
echo "{$subCustomerLabel} <select name='subc' id='subc' class='form-control reportselect' multiple='multiple'>";
echo "<option value='a' selected>All</option> ";
} else {
echo "{$subCustomerLabel} <select name='subc' id='subc' class='form-control reportselect'>";
echo "<option value='0' >Select a {$subCustomerLabel}</option> ";
}
while($info34 = mysqli_fetch_array( $data34 )){
if($subcust==$info34['id']) { $select = ' selected '; }
// echo "<option value='".$info34['id']."' $select >".$info34['branchcode']." ".$info34['name']. "</option>"; 

echo "<option value='".$info34['id']."' $select>"
    .$info34['branchcode']." ".$info34['name']." (".$info34['address'].")</option>";
}
echo "</select><br />";
}
if($num_rows!=0) { ?>
<script type="text/javascript">
<?php if($paypage==1) { ?>
$('#subc').on('change', function() {
    var cid = $(".cid").val();
    var old_si = $("#old_si").val();
    var subc = $("#subc").val();
    $.ajax({
        type: "POST",
        url: "../ajax/receipt-query.php",
        data: {
            saleold2: cid,
            invoiceid: old_si,
            cleartype: 1,
            subcust: subc
        },
        cache: false,
        dataType: 'html',
        success: function(html) {
            $("#res").html(html);
        }
    });
});
<?php } ?>
$('.reportselect').select2();
</script>
<?php
}

}


else if(isset($_POST['subc_id'])){
    $subc_id = test_input($_POST['subc_id']);

   
    $q1 = mysqli_query($conn,"SELECT cid FROM sub_customer WHERE id='$subc_id'");
    $res1 = mysqli_fetch_assoc($q1);

    if($res1 && !empty($res1['cid'])){
        $cid = $res1['cid'];

        
        $q = mysqli_query($conn,"SELECT u.company_name, u.fname, u.lname, u.id FROM user u, customer c WHERE u.id=c.id AND c.id='$cid' AND inactive=0") or die(mysqli_error($conn));

        if(mysqli_num_rows($q) > 0){
            echo "<b>Customer</b><br>";
            echo "<select name='customer_id' id='cid2' class='form-control reportselect'>";
            echo "<option value=''>Select Customer..</option>";
            while($r = mysqli_fetch_array($q)){
               
                echo "<option value='".$r['id']."' selected>".$r['company_name']." (".$r['fname']." ".$r['lname'].")</option>";
            }
            echo "</select>";
        } else {
            echo "<b>No customer found for this Sub Customer!</b>";
        }

    } else {
        echo "<b>No main customer assigned to this Sub Customer!</b>";
    }
}
else if(isset($_POST['sales_man'])){
    $salemanid= $_POST["sales_man"];
    // $sql=mysqli_query($conn, "SELECT *, u.username AS cid,e.id AS aid from employee e, user u WHERE u.id='$salemanid'");
    $sql=mysqli_query($conn, "SELECT e.*, c.emp_id as emp_id, e.id as aid from customer c, user u, employee e WHERE c.emp_id=e.id AND c.id='$salemanid'");
    $info2= mysqli_fetch_array($sql);
    // if()
    echo "<option value='".$info2["aid"]."'>".mysqli_get_var("select fname from user where id=".$info2["aid"]."")."</option>";
}
else if(isset($_POST['cid25']))
{
$cid=test_input($_POST['cid25']);
$numb = mysqli_get_var("Select count(batch_no) from production_material where batch_no='$cid'");
$numb2 = $numb+1;
echo 'Lot #
  <input name="lot"  type="text"  class="form-control" tabindex="1" value="'.$numb2.'"  /> 
<br> ';
}
else if(isset($_POST['pdemand']))
{
$reorderlevel=test_input($_POST['pdemand']);
$vendorid=test_input($_POST['vendorid']);
$itemlevel=test_input($_POST['itemlevel']);
$reorderwarehouse=test_input($_POST['reorderwarehouse']);
$reorderbrand=test_input($_POST['reorderbrand']);
$product_ctype=test_input($_POST['product_ctype']);
$reordercategory=test_input($_POST['reordercategory']);
$vendorlimit = test_input($_POST['vendorlimit']);
if($vendorlimit=='0') { 
$vendorlimit2=" && 1=1  ";  }
else {
$vendorlimit2=" && vendor_id='$vendorid'  ";  
  }
if($reorderwarehouse=='a')
{
$reorderwarehouse2=" AND 1=1    ";    }
else {
$reorderwarehouse2="  AND warehouse_id='$reorderwarehouse'   "; 
  } 
 if($product_ctype=='a')
{
$product_ctype2=" AND 1=1    ";    }
else {
$product_ctype2="  AND ctype_id='$product_ctype'   "; 
  }  
if($reorderfilter=='n')
{
$aaa=" AND qty<min_qty    ";    }
else {
$aaa="  AND qty<min_qty   "; 
  } 
if ($reorderbrand=='a')
{
$reorderbrand2=" ";
}
else
{
$reorderbrand = str_replace("a, "," ",$reorderbrand);   
$reorderbrand2=" AND brand_id IN ($reorderbrand) ";
}
if ($reordercategory=='a')
{
$reordercategory2=" ";
}
else
{
$reordercategory = str_replace("a, "," ",$reordercategory); 
$reordercategory2=" AND type_id IN ($reordercategory) ";
} 
$cwarehouse = mysqli_get_var("Select inventory_warehouse from vendor where `id` = '$vendorid'");
   ?>
<table width="100%" cellpadding="5" class="table-bordered table-striped" id="acart">
    <thead>
        <tr>
            <th width="25%"><?php echo $info1000['product_label']; ?></th>
            <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                <div>QTA</div>
            </th>
            <th>
                <div><?php echo $info1000['multi_unit_label']; ?></div>
            </th>
            <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                <div><?php echo $info1000['single_unit_label']; ?></div>
            </th>
            <?php if($info1000['en_warehouse']==1) {  echo  '  <th ><div>WH </div></th> '; } ?>
            <th <?php if($info1000['en_pos']==0) echo ' style="display:none;"';  ?>>
                <div>Stock Level</div>
            </th>
            <th <?php if($info1000['en_pos']==0) echo ' style="display:none;"';  ?>>
                <div>Sale Price</div>
            </th>
            <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                <div><?php echo $info1000['packing_label']; ?></div>
            </th>
            <th>
                <div><?php echo $info1000['price_label']; ?></div>
            </th>
            <th>Disc (%)</th>
            <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                <div><?php echo $info1000['total_unit_label']; ?></div>
            </th>
            <th contenteditable="true" width="80">Total </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <?php  $data2 = mysqli_query($conn,"SELECT * from inventory where 1=1  ".$vendorlimit2.$reorderbrand2.$reordercategory2.$product_ctype2);
  $sub_total=0;     
while($info2 = mysqli_fetch_array( $data2 )) 
 {
     $item_id = $info2['id'];
     $min_qty = $info2['min_qty'];
     $max_qty = $info2['max_qty'];
     if($info3000['warehousewise_inventorylimit']==1 && $reorderwarehouse!='a') {
    $data20 = mysqli_query($conn,"SELECT * from  item_warehouselimit WHERE item_id = '$id' && warehouse_id='$reorderwarehouse'  && component_type=0  ");
while($info20 = mysqli_fetch_array( $data20 )) 
 {
      $min_qty = $info20['minimum_qty'];
     $max_qty = $info20['maximum_qty'];
     if($min_qty=='') $min_qty=0;
      if($max_qty=='') $max_qty=0;
 }
         }
     $add = mysqli_get_var("Select SUM(qty) from warehouse_transaction where tran_type IN ( Select id from warehouse_transaction_type where `type`=1 )  && deleted=0 && type_component=0 && item_id='$item_id' $reorderwarehouse2  ");
  $less = mysqli_get_var("Select SUM(qty) from warehouse_transaction where tran_type IN ( Select id from warehouse_transaction_type where `type`=0 )  && deleted=0  && type_component=0 && item_id='$item_id' $reorderwarehouse2  ");
   $balancestock = $add-$less;
if($balancestock<$min_qty || $itemlevel==0 ) {   
if($reorderlevel==0) {  $orderqty = $min_qty - $balancestock; } else if($reorderlevel==1) {  $orderqty = $max_qty - $balancestock;  } else {  $orderqty = 0;  }
      ?>
        <tr class="carttr">
            <td><input type="hidden" name="products[]" class="products singleitem" value="<?php echo $info2['id'];?>"
                    id="<?php echo "code".$info2['id'];?>" /> <?php echo $info2['sku'].' '.$info2['name'];?>
                <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                    value="<?php echo $info2['is_taxable'];?>" />
                <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from purchasing_details sd, purchasing s  where sd.prd_id='$sid' AND s.type_component=0 AND sd.`order_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
    else if($info1000['en_lastprice']==2 ) {
        $data200 = mysqli_query($conn,"SELECT sd.* from purchasing_details sd, purchasing s  where sd.prd_id='$sid' AND s.type_component=0 AND sd.`order_id`=s.`id` AND s.vendor_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }    ?>
                <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                    <textarea name="products_description[]" class="form-control" placeholder="Details.."></textarea>
                </div>
            </td>
            <td class="triggeravailable"
                <?php if($info1000['hide_qavailable']==1 || $type_component == 3) echo ' style="display:none;"';  ?>><?php 
    /*if($info2000['qta_inpacking']==0) { $a=' SUM(qty) '; } else { $a=' SUM(qty/packing) '; } 
    $sid = $info2['id'];
    $transfer_in = mysqli_get_var("SELECT $a as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=0 $wlimit_warehouse8   ");
    $transfer_out = mysqli_get_var("SELECT $a as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=0 $wlimit_warehouse8  ");
    echo  $product_qta = $transfer_in-$transfer_out;*/
    $sp = mysqli_get_var("SELECT id FROM inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse ");
    $stocksingle = $info2['id'];
    if(1) { $a=' SUM(qty) '; } else { $a=' SUM(qty/packing) '; }
    $minus = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id && t.type=0 && w.deleted=0 &&  `item_id` = '$stocksingle' &&  `warehouse_id` = '$sp' "); 
    if($info1000['inventory_limit']==1) {
      $minus2 = mysqli_get_var("SELECT $a AS sqty FROM so_details WHERE warehouse_id='$sp' && prd_id='$stocksingle' && order_id IN (SELECT id FROM so WHERE completed=0)  "); 
    }else{
      $minus2 = 0;
    }
    $plus = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id && t.type=1 && w.deleted=0 &&  `item_id` = '$stocksingle' &&  `warehouse_id` = '$sp' "); 
    $minus3 = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id && w.deleted=0 && (w.tran_type=1 || w.tran_type=21) && verified_by=0 && t.type=1 &&  `item_id` = '$stocksingle' &&  `warehouse_id` = '$sp' ");
    $product_qta=$plus-$minus-$minus2-$minus3;
    if($info2000['qta_inpacking']==0) {
      echo number_format($product_qta, 2);
    }else{
      $packing5 = mysqli_get_var("SELECT packing FROM inventory WHERE id = '$stocksingle' ");
      echo number_format($product_qta/$packing5, 2);
    }
  ?></td>
            <td>
                <input type="text" <?php if($info2000['multiple_batch']==1) { echo "value='1'  ";  } ?> size="4" min="0"
                    class="highlight searchp <?php if($info1000['no_purchasepacking']==1) echo ' change5';  ?>  income_count  packing"
                    id="ctn<?php echo $info2['id'];?>" value="<?php echo $orderqty; ?>" tabindex="1" />
            </td>
            <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                <!--<input type="hidden" name="<?php// echo $info2['id'];?>_packing" id="p<?php// echo $info2['id'];?>" class="searchqty income_count form-control" tabindex="1"  value="<?php// echo $info2['packing'];?>"  /> -->
                <input type="text" size="4" min="1" value="0" class="searchqty change change5 income_count totalorder"
                    tabindex="1" id="pcs<?php echo $info2['id'];?>" />
            </td>
            <td <?php if($info2000['en_customfield1c']==0) echo ' style="display:none;"';  ?>><input
                    name="custom_field1[]" id="customfield<?php echo $info2['id'];?>" type="text" tabindex="1"
                    class="form-control  <?php if($info3000['ctn_customfieldrate']==0) { ?>income_count<?php } ?>  customfield1 " /> </td>
            <?php if($info1000['en_warehouse']==1) { ?>
            <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse  ") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' tabindex='1' class='teacher warehouse form-control change6'  >";
while($info4 = mysqli_fetch_array( $data4 )) 
 { 
 if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
 }
echo "</select>";
?></td>
            <?php } ?>
            <td <?php if($info1000['en_pos']==0) echo ' style="display:none;"';  ?>>
                Min Qty <b><?php echo $info2['min_qty'];?></b><br>
                Max Qty <b><?php echo $info2['max_qty'];?></b>
            </td>
            <td <?php if($info1000['en_pos']==0) echo ' style="display:none;"';  ?>>
                <input tabindex="1" name="sale_price[]" type="text" required
                    class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count  "
                    value="<?php echo $info2['mrp_price'];?>" size="4" />
            </td>
            <?php if($return==1) { if($info1000['en_inventorybatch']==1 && $grnn==1) { ?>
            <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'   && type_component=0 ") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1'  class='teacher reportselect batch7 inventory3 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
 $batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?><input type="hidden" name="batch_old[]" value="1" /></td>
            <?php } } else { ?>
            <?php if($info1000['en_inventorybatch']==1 && $grnn==1) { ?>
            <td>
                <div class="batchdiv"><input type="text" name="products_batch[]"
                        <?php  if($info2['is_batch']==0) { echo 'readonly';  }?>
                        value="<?php  if($info2['is_batch']==0) { echo 'No Batch';  }?>" tabindex="1"
                        class="change7 income_count batch7 form-control"
                        maxlength="<?php echo $info2000['max_batch_length']; ?>" required
                        id="<?php echo "batch".$info2['id'];?>" /></div> <input type="hidden" name="batch_old[]"
                    value="0" />
            </td>
            <?php } } ?>
            <?php if($info2000['multiple_batch']==1) { ?>
            <td><input type="text" name="multi_batch[]" value="-" readonly="readonly" /> </td>
            <?php } ?>
            <?php  if($info1000['en_expirydisplay']==1 && $grnn==1) {  ?>
            <td <?php if($return==1) { echo ' style=" display:none;"'; } ?>><input type="date" name="products_expiry[]"
                    <?php  if($info2['is_batch']==0) { echo 'readonly';  }?> value="" tabindex="1"
                    <?php if($return==0) { ?> required <?php } ?> class="change8 form-control expiry7"
                    id="<?php echo "expiry".$info2['id'];?>" /></td>
            <?php } ?>

            <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                <input name="products_packing[]" type="number" min="0.1" step="0.001" size="4" min="1"
                    class="edit-input change income_count totalorder" id="p<?php echo $info2['id'];?>" tabindex="1"
                    value="<?php echo $info2['packing'];?>" readonly="readonly" />
                <input name="products_packing2[]" type="hidden" class="edit-input change income_count packing2 totalorder"
                    id="pack2<?php echo $info2['id'];?>" tabindex="1" value="<?php echo $info2['packing2'];?>" />
            </td>
            <td>
                <?php
$data15 = mysqli_query($conn,"SELECT vendor_type from vendor where  id='$cid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$ttid=$info15['vendor_type'];
$ppid=$info2['id'];
 $data15 = mysqli_query($conn,"SELECT price from vendor_type_pricing where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" min="0" step="0.00001" name="unitcos[]" type="number"
                    value="<?php echo $info15['price'];?>" required
                    class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                    size="4" />
                <?php } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100; 
$discount4=$info200['discount4']/100;
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3; 
$discount4=1-$discount4; 
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info200['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;

$price= $x;
    ?>
                <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" step="0.00001" type="number"
                    value="<?php echo $price;?>" required min="0" 
                    class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                    size="4" />
                <?php }
else {  ?>
                <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" step="0.00001" type="number" required min="0" 
                    value="<?php echo $info2['unit_cost'];?>"
                    class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                    size="4" />
                <?php } ?>
                <input name="mrp_price[]" size="4" type="hidden" class="edit-input income_count totalorder"
                    id="<?php echo "mrp".$info2['id'];?>" tabindex="1"
                    value="<?php if($mpp!=''  && $mpp!='0') { echo $mpp;  } else { echo $info2['mrp_price']; } $mpp=''; ?>" />
                <input name="tax_mrp[]" size="4" type="hidden" class="edit-input income_count totalorder"
                    id="<?php echo "mrptax".$info2['id'];?>" tabindex="1" value="<?php echo $info2['tax_mrp'];?>" />
            </td>
            <td <?php  if($info2000['invoice_cartonrate']==0) { echo ' style=" display:none;"'; } ?>>
                <select name='rate_in_carton[]' class='teacher income_count case2qty'
                    id="<?php echo "ric".$info2['id'];?>">
                    <option value='0'>Default</option>
                    <?php if($info4000['en_engineering']==0){ ?>
                    <option value='1'><?php echo $info1000['packing_label']; ?></option>
                    <?php } ?>
                    <option value='2'><?php echo $info1000['multi_unit_label']; ?></option>
                    <option value='3'><?php echo $info2000['customfield1_display'];  ?></option>
                </select>
            </td>
            <td <?php  if($info2000['en_ricetrade']==0) { echo ' style=" display:none;"'; } ?>><input name="packing2[]"
                    type="number" step="0.0001" class='teacher packing2 income_count' value="<?php echo $info2['pac2']; ?>"
                    id="<?php echo "packk".$info2['id'];?>" /> </td>
            <?php if($info1000['vendor_discount1']==1) { 
 echo '<td >';
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from vb_discount where vid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from vendor_type_discount1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($num_rows!=0) {
?>
            <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>" size="4" />
            <?php }
else if($num_rows2!=0) {
?>
            <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info17['discount'];?>" size="4" />
            <?php }  else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
            <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info200['discount'];?>"
                size="4" />
            <?php }
 else {  ?>
            <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
            <?php } echo '</td>'; } else { ?>
            <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
            <?php } if($info1000['vendor_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from vendor_type_discount2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
            <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                    size="4" /></td>
            <?php }
elseif($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
            <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="<?php echo $info200['discount2'];?>"
                    size="4" /></td>
            <?php }
 else {  ?>
            <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
            <?php } } else { ?>
            <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
            <?php }
 if($info1000['vendor_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from vendor_type_discount4 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
            <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                    size="4" /></td>
            <?php }
else if($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
            <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="<?php echo $info200['discount4'];?>"
                    size="4" /></td>
            <?php }
 else {  ?>
            <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
            <?php } } else { ?>
            <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
            <?php }
  if($info1000['vendor_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from vendor_type_discount3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
            <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder"
                    id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                    size="4" step="0.0001" /></td>
            <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='') {?>
            <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder"
                    id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="<?php echo $info200['discount3'];?>"
                    size="4" step="0.0001" /></td>
            <?php }  else {  ?>
            <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder"
                    id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" step="0.0001" /></td>
            <?php } } else {?>
            <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
            <?php }
 if($info1000['vendor_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from vendor_type_scheme where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
            <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                    size="4" />
            </td>
            <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
            <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                    size="4" /></td>
            <?php } else {  ?>
            <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
            <?php } } else { ?>
            <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
            <?php } ?>
            <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                    name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                    id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                    size="4" /> <input name="products_pcs[]" type="text" size="4" min="1" class="edit-input total_pcs"
                    id="<?php echo "t".$info2['id'];?>" readonly="readonly" /></td>
            <?php if($info1000['vendor_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from vendor_type_tax1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($info2000['en_maintaxc']==1) {
?>
            <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                    id="<?php echo "pppp".$info2['id'];?>"
                    value="<?php if($st==1) {  if($cfiler==1) { echo $info2000['filer_taxc']; } else { echo $info2000['nonfiler_taxc']; }  } else { echo 0; } ?>"
                    size="4" <?php if($info4000['en_engineering']==1){} else { ?>readonly="readonly" <?php } ?> /></td>
            <?php }
else if($num_rows!=0 && (float)$info15['discount']>0) {
?>
            <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                    id="<?php echo "pppp".$info2['id'];?>"
                    value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                    size="4" <?php if($info4000['en_engineering']==0){} else { ?>readonly="readonly" <?php } ?> /></td>
            <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
            <td> <input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                    id="<?php echo "pppp".$info2['id'];?>"
                    value="<?php if($info1000['en_tax']==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                    size="4" readonly="readonly" /></td>
            <?php } else {  ?>
            <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                    id="<?php echo "pppp".$info2['id'];?>"
                    value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                    readonly="readonly" /></td>
            <?php } } else { ?>
            <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                id="<?php echo "pppp".$info2['id'];?>"
                value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                readonly="readonly" /></td>
            <?php } ?>
            <td <?php if($info2000['invoice_cartonrate']==0) { echo ' style=" display:none;" '; } ?>><input
                    name="pipe[]" type="text" class="edit-input pipehide income_count" tabindex="1"
                    id="<?php echo "pipe".$info2['id'];?>" value="<?php  echo 0; ?>" size="4" readonly="readonly" />
            </td>
            <?php  if($info1000['vendor_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from vendor_type_tax2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
            <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                    value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                    size="4" /></td>
            <?php } 
else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
            <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="<?php echo $info200['tax_applied2']; ?>"
                    size="4" /></td>
            <?php } else {  ?>
            <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
            <?php } } else { ?>
            <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
            <?php } if($info1000['vendor_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from vendor_type_tax3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
            <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                    value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                    size="4" /></td>
            <?php } else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
            <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                    value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
            <?php }  else {  ?>
            <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                    id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
            <?php } }  else { ?>
            <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
            <?php } ?>
            <td><input name="products_total[]" step="0.0001"  id="newtotal<?php echo $info2['id'];?>" type="number" size="5" min="0" 
                    class="tot<?php echo $info2['id'];?> ptotal sub_total readonly " tabindex="-1" onkeypress="return false;" /></td>
            <td class="d-flex gap-2">
                <?php if(1==1) { ?>
                    <td class="d-flex gap-2">
                <input type="button" class="rounded-1 bg-info text-white border-0 p-1 edit receipt_edit_hide5" value="Edit" />
                <input type="button" class="rounded-1 bg-success text-white border-0 p-1 save" value="Save" /> 
                    <!-- <input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                    type="button" class="save" value="Save" /> -->
                    <?php } ?><?php if(1==1) { ?>
                        <td class="d-flex gap-2">
                        <input type="button" class="rounded-1 bg-danger text-white border-0 p-1 delete receipt_delete_edit5" value="Delete" />
                            <?php } ?></td>
        </tr>
        <?php } 
             } ?>
    </tbody>
</table>
<?php  include('../functions/incomecount_function.php'); ?>

<script type="text/javascript">
$('input').keyup(function(e) {
    if (e.which == 39)
        $(this).closest('td').next().find('input').focus();
    else if (e.which == 37)
        $(this).closest('td').prev().find('input').focus();
    else if (e.which == 40)
        $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input').focus();
    else if (e.which == 38)
        $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input').focus();
});
</script>
<script type="text/javascript">
$(document).ready(function() {
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $('.delete').on('click', function() {
        $(this).closest('tr').remove();
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#paid_amount").val();
        var n6 = $("#pending_amount").val();
        var total = +n4;
        var pending = +total - n5;
        $("#total_amount").val(total);
        $("#pending_amount").val(pending);
    });
});
$(".income_count").trigger("change");
</script>
<?php
}
else if(isset($_POST['demand']))
{
$df=test_input($_POST['demand']);
$vf=test_input($_POST['vf']);
$pf=test_input($_POST['pf']);
if($vf=='a')
{
$a=" where vendor_id=vendor_id AND inactive=0 ";  }
else {
$a=" where vendor_id='$vf' AND inactive=0 ";  
  }
if($pf=='n')
{
$b=" AND qty<min_qty";    }
else {
$b=" "; 
  } 
   ?>
<div style=" width:100%; clear:both;">
    <div id="psearch" class="psearch"> </div>
    <div
        style=" width:100%; background-color:#EEE; clear:both; padding:10px; height:600px; overflow:auto; border-radius:5px;">
        <table width="100%" cellpadding="5" class="table-bordered table-striped" id="acart">
            <thead>
                <tr>
                    <th width="25%"><?php echo $info1000['material_label']; ?></th>
                    <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <div>QTA</div>
                    </th>
                    <th>
                        <div><?php echo $info1000['multi_unit_label']; ?></div>
                    </th>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['single_unit_label']; ?></div>
                    </th>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['packing_label']; ?></div>
                    </th>
                    <th>
                        <div><?php echo $info1000['price_label']; ?></div>
                    </th>
                    <th>Disc (%)</th>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                    <th contenteditable="true" width="80">Total </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php  $data2 = mysqli_query($conn,"SELECT *, min_qty-qty as rqty, max_qty-qty as xqty from inventory".$a.$b);
  $sub_total=0;     
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr>
                    <td><input type="hidden" name="products[]" value="<?php echo $info2['id'];?>" />
                        <?php echo $info2['name'];?></td>
                    <?php if($df=='x')
{
$min=$info2['xqty']/$info2['packing'];
      $min=ceil($min);
      $totp=$min*$info2['packing'];
      $tota= $totp*$info2['unit_cost'];
  }
else if($df=='n')  {
  $min=$info2['rqty']/$info2['packing'];
  $min=ceil($min);
      $totp=$min*$info2['packing'];
      $tota=$totp*$info2['unit_cost'];
  } 
else {
   $min=0;
    $totp=0;
    $tota=0;} 
?>
                    <td> <?php echo $info2['qty'];?> </td>
                    <td>
                        <input type="text" class="aaa highlight searchp income_count form-control packing"
                            id="ctn<?php echo $info2['id'];?>" value="<?php echo $min; ?>" tabindex="1" />
                    </td>
                    <td><input type="text" value="0" class="searchqty form-control change income_count totalorder"
                            tabindex="1" id="pcs<?php echo $info2['id'];?>" /></td>

                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_packing[]" type="number" min="0.1" step="0.001" id="p<?php echo $info2['id'];?>"
                            class="searchqty edit-input income_count form-control" tabindex="1"
                            value="<?php echo $info2['packing'];?>" /></td>
                    <td><input type="text" class="searchqty edit-input income_count form-control"
                            id="pp<?php echo $info2['id'];?>" value="<?php echo $info2['unit_cost'];?>" tabindex="1"
                            size="20" /></td>
                    <td><input name="products_discount[]" type="number"
                            class="form-control income_count edit-input totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" /></td>
                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_pcs[]" type="text" class="form-control edit-input total_pcs"
                            id="<?php echo "t".$info2['id'];?>" readonly="readonly" value="<?php echo $totp; ?>" /></td>
                    <?php $sub_total=$sub_total+$tota;?>
                    <td><input name="products_total[]" step="0.0001"  type="number" min="0" id="newtotal<?php echo $info2['id'];?>"  
                            class="tot<?php echo $info2['id'];?> sub_total form-control " tabindex="-1"
                            value="<?php echo $tota; ?>" /></td>
                    <td><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input type="button"
                            class="save" value="Save" /> <input type="button" class="delete receipt_delete_edit5"
                            value="Delete" /></td>
                </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <script type="text/javascript">
    $(document).ready(function() {
        $('.save').hide();
        $('.edit-input').attr("readonly", true);
        $(".edit").on('click', function() {
            $(this).closest('tr').find('.edit').hide();
            $(this).closest('tr').find('.save').show();
            $(this).closest('tr').find('.edit-input').attr("readonly", false);
        });
        $(".save").on('click', function() {
            $(this).closest('tr').find('.save').hide();
            $(this).closest('tr').find('.edit').show();
            $(this).closest('tr').find('.edit-input').attr("readonly", true);
        });
        $('.delete').on('click', function() {
            $(this).closest('tr').remove();
            //Total Quantity Sum  (Pcs)
            var sum = 0;
            $(".total_pcs").each(function() {
                sum += parseFloat($(this).val()) || 0;
            });
            $("#total_pcs").val(sum);
            //Total Quantity Sum  (Carton)
            var sum3 = 0;
            $(".packing").each(function() {
                sum3 += parseFloat($(this).val()) || 0;
            });
            $("#packing").val(sum3);
            //Total Amount Sum  (Sub Total)
            var sum2 = 0;
            $(".sub_total").each(function() {
                sum2 += parseFloat($(this).val()) || 0;
            });
            $("#sub_total").val(sum2);
            var n4 = $("#sub_total").val();
            var n5 = $("#paid_amount").val();
            var n6 = $("#pending_amount").val();
            var total = +n4;
            var pending = +total - n5;
            $("#total_amount").val(total);
            $("#pending_amount").val(pending);
        });
    });
    </script>
    <?php
}
else if(isset($_POST['pid']))
{
$sid=test_input($_POST['pid']);
$vid=test_input($_POST['vendorid']);
$po_withoutvalue_request = !empty($_POST['po_withoutvalue']) && (int)$_POST['po_withoutvalue'] === 1;
$rate=mysqli_get_var("SELECT rate from vendor_item where prd_id='$sid' AND vid='$vid' ");
$wo_po=test_input($_POST['wo_po']);
$invoice=test_input($_POST['invoice']);
$return=test_input($_POST['return']);
$lid=test_input($_POST['lid']);


if($lid!='') {
$lid=" && location_id='$lid' ";
}

$cid=test_input($_POST['vendorid']);
$grnn=test_input($_POST['grn']);
if($info1000['direct_invoicep']==1  || $info2000['batch_grnonly'] == 0) {
    $grnn=1; 
    }
$dist_id=test_input($_POST['dist_id']);
$snd_purh=test_input($_POST['snd_purh']);
 $cfiler = mysqli_get_var("Select filer from vendor where `id` = '$vid'");
$st=test_input($_POST['st']);
$type_component = $_POST['type_component'];
if($type_component == '')
  $type_component = 0;
$cwarehouse = mysqli_get_var("Select inventory_warehouse from vendor where `id` = '$vid'");
?>
 
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <?php if($wo_po==0 || $wo_po=='') { ?><th width="20%">
                        <div><?php echo $info1000['product_label']; ?></div>
                    </th>
                    <?php } else { ?>
                    <th width="20%">
                        <div>Item</div>

                    </th>
                    <th width="20%" <?php if($info4000['tollmanufacturing_purchase'] == 0) echo ' style="display:none;"';  ?>>
                        <div>Outward Item</div>
                    </th>
                    <?php } ?>
                    <th
                        <?php if($info1000['hide_qavailable']==1 || $info3000['en_aico']==1 || $type_component == 3 || ($info1000['en_export']==1 && $type_component == 10)) echo ' style="display:none;"';  ?>>
                        <div>QTA</div>
                    </th>
                    <th <?php if($info3000['en_ajk'] ==0) echo ' style="display:none;"'; ?> >
                      <div>History</div>
                    </th>
                    <th>
                        <div><?php echo $info1000['multi_unit_labela']; ?></div>
                    </th>
                    <?php  if($info2000['uom_display']==1) { ?> <th align="center"><?php echo $info2000['uom_label']; ?>
                    </th><?php } ?>
                    <?php if($info3000['en_goodluck'] == 1  && $type_component != 3){ ?> <th>Weightage</th><?php  } ?>
                    <th <?php if($info1000['no_purchasepacking']==1 || $info2000['pcs_hidec']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['single_unit_label']; ?></div>
                    </th>
                    <th <?php if(( $info2000['en_customfield1c']==0  && $type_component != 3 ) || $snd_purh==1) echo ' style="display:none;"';  ?>
                        class="recurringhide">
                        <div><?php echo $info2000['customfield1c_display'];  ?></div>
                    </th>
                    <th
                        <?php if($info4000['en_customfield2c']==0  && $type_component != 3) { echo ' style="display:none;"'; }  ?>>
                        <div><?php echo $info4000['customfield2c_label'];  ?></div>
                    </th>
                    <th
                        <?php if($info4000['en_customfield3c']==0  && $type_component != 3) { echo ' style="display:none;"'; }  ?>>
                        <div><?php echo $info4000['customfield3c_label'];  ?></div>
                    </th>
                <th <?php if($info3000['en_customfield4c']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info3000['customfield4c_label'];  ?></div></th>
                <th <?php if($info3000['en_customfield5c']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info3000['customfield5c_label'];  ?></div></th>
                 <th <?php if($info3000['en_customfield6c']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info3000['customfield6c_label'];  ?></div></th>
                 <th <?php if($info3000['en_customfield8']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info3000['customfield8_label'];  ?></div></th>
 
                    <th
                        <?php if($info3000['en_goodluck']==0 || $info2000['en_customfield1c']==0  || $type_component == 3) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info2000['customfield1c_display'];  ?></div>
                    </th>
                    <th
                        <?php if($info3000['en_goodluck']==0 || $info2000['en_customfield1c']==0 || $type_component == 3) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info2000['customfield1c_display']." Difference ";  ?></div>
                    </th>
                    <?php  if($info1000['en_warehouse']==1) {  echo  '  <th ><div>WH </div></th> '; } ?>
                    <th <?php if($info1000['en_pos']==0 || $return==1) echo ' style="display:none;"';  ?>>
                        <div>Stock Level</div>
                    </th>
                    <th <?php if($info1000['en_pos']==0  || $return==1) echo ' style="display:none;"';  ?>>
                        <div>Sale Price</div>
                    </th>
                    <th
                        <?php if($info1000['en_pos']==0  || $return==1  || $invoice==1) echo ' style="display:none;"';  ?>>
                        <div>Margin %</div>
                    </th>
                    <?php if($info1000['en_inventorybatch']==1 && $info1000['batch_with_brand']==1) {   echo  ' <th><div>Brand</div></th> '; } ?>
                    <?php if($info1000['en_inventorybatch']==1 && $grnn==1 && $info2000['batch_grnonly'] == 0) {   echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; } ?>
                    <?php if($info2000['multiple_batch']==1 ) {   echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; } ?>
                    <?php if($info1000['en_batch_expiry']==1 && $snd_purh==1) {   echo  '  <th ><div> Batch Expiry</div></th> '; } ?>
                    <?php if($info1000['en_expirydisplay']==1 && $return==0 && $grnn==1) {   echo  '  <th ><div>Expiry </div></th> '; } ?>
                    <?php if($info1000['en_expirydisplay']==1 && $return==1 && $grnn==1) {   echo  '  <th ><div>Expiry </div></th> '; } ?>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['packing_label']; ?></div>
                    </th>
                              <th <?php if($info2000['en_ricetrade']==0) echo ' style="display:none;"';  ?> ><div><?php echo $info2000['itemcustomunit_label']; ?></div></th>

                    <th>
                        <div>
                            <?php   if($info4000['en_engineering']==1){ echo 'Per Unit Rate';} else { echo $info4000['price_labelp']; }?>
                        </div>
                    </th>

<th <?php if($info4000['separate_mrpcolumnp']==0) echo ' style="display:none;"';  ?>
                        class="recurringhide">
                        <div><?php echo $info4000['mrp_label']; ?></div>
                    </th>


                    <?php if($info2000['en_sarhad']==1 || $info4000['itemmulti_unit']==1) { ?>
                    <th>
                        <div>Unit</div>
                    </th>
                    <th style="display:none;">
                        <div>Unit Rate</div>
                    </th>
                    <?php } ?>
                    <?php  if($info2000['invoice_cartonratep']==1) {  ?>
                    <th>
                        <div>Rate Apply</div>
                    </th>
                    <?php } ?>
                    <?php if($info1000['vendor_discount1']==1) {  echo  '  <th ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_discount2']==1) {  echo  '  <th ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_discount4']==1) {  echo  '  <th ><div>'.$info1000['disc3_label'].'</div></th> '; } ?>
                    <?php if($info4000['vendor_foc']==1) {  echo  '  <th ><div>'.$info4000['customerfoc_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_discount3']==1) {  echo  '  <th ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_scheme']==1) {  echo  '  <th ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                  <?php if($info4000['display_taxamount']==1){   ?>    
            <th>Exclusive of GST Amount</th>    
            <?php } ?>
                    <?php if($info1000['vendor_tax1']==1) {  echo  '  <th ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
                    <?php  if($info4000['invoice_cartonratep']==1) {  ?>
                    <th>
                        <div>Pipe Rate</div>
                    </th>
                    <?php } ?>
                    <?php if($info1000['vendor_tax2']==1) {  echo  '  <th ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_tax3']==1) {  echo  '  <th ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
                  <?php if($info4000['display_taxamount']==1){   ?>    
            <th><?php echo $info4000['taxamount_label']; ?></th>    
            <?php } ?> 
                    <th contenteditable="true" width="80"<?php if($po_withoutvalue_request) { echo ' style="display:none;"'; } ?>>Total </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
   if($type_component == 3){
    $table = "services";
    $packing2 = "1";
   }else{
    $table = "inventory";
    $packing2 = "packing2";
   }
    $data2 = mysqli_query($conn,"SELECT *, $packing2 as pac2 from $table where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr class="carttr">
                    <td><input type="hidden" name="products[]" class="products singleitem"
                            value="<?php echo $tollitem = $info2['id'];?>" id="<?php echo "code".$info2['id'];?>" />
                        <?php echo $info2['sku'].' '.$info2['name'];?>
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from purchasing_details sd, purchasing s  where sd.prd_id='$sid' AND s.type_component=0 AND sd.`order_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
    else if($info1000['en_lastprice']==2 ) {
        $data200 = mysqli_query($conn,"SELECT sd.* from purchasing_details sd, purchasing s  where sd.prd_id='$sid' AND s.type_component=0 AND sd.`order_id`=s.`id` AND s.vendor_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }    ?>
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <?php if($wo_po!=0 && $wo_po!='' && $info4000['tollmanufacturing_purchase']==1 ) { ?>
                    <td><?php 

if($info3000['tollmanufacturing_bom']==0) { 

$vv = " && id IN (Select outward_id from toll_rate where vid='$cid' && inward_id='$tollitem' && type_component=1  )  ";

} else {

$vv = " && id IN (Select prd_id from bom where vendor_id='$sp'  ) ";

}

 $data200 = mysqli_query($conn,"Select name from inventory where id IN (Select outward_id from toll_rate where vid='$cid' && inward_id='$tollitem' && type_component=0  ) ") or die(mysqli_error($conn));
         while($info200 = mysqli_fetch_array( $data200 )) { echo $info200['name']."<br><hr />";    } 

  $data200 = mysqli_query($conn,"Select name from component where 1=1 $vv   ") or die(mysqli_error($conn));
         while($info200 = mysqli_fetch_array( $data200 )) { echo $info200['name']."<br><hr />";    }    


    
     $data20 = mysqli_query($conn,"SELECT s.item_id  from bom b, bom_materialsc s where b.id=s.bom_id && b.prd_id='$tollitem'   ") or die(mysqli_error($conn));
       $count_rows20 = mysqli_num_rows($data20);  
        $data21 = mysqli_query($conn,"SELECT s.item_id  from bom b, bom_materials s where b.id=s.bom_id && b.prd_id='$tollitem'   ") or die(mysqli_error($conn));
       $count_rows21 = mysqli_num_rows($data21);  
        if($count_rows20!=0 || $count_rows21!=0) {
    echo '<br /><br /><b>Recipe:</b><br />';        
            }
while($info20 = mysqli_fetch_array( $data20 )) 
 {
    $toliid = $info20['item_id']; 
    echo   mysqli_get_var("Select name from component where id='$toliid'  ");
    echo "<br />";
 }
 while($info21 = mysqli_fetch_array( $data21 )) 
 {
    $toliid = $info21['item_id']; 
    echo   mysqli_get_var("Select name from inventory where id='$toliid'  ");
    echo "<br />";
 }
      ?></td>
                    <?php } ?>
                    <td class="triggeravailable"
                        <?php if($info1000['hide_qavailable']==1 || $info3000['en_aico']==1 || $type_component == 3 || ($info1000['en_export']==1 && $type_component == 10)) echo ' style="display:none;"';  ?>><?php 
    /*if($info2000['qta_inpacking']==0) { $a=' SUM(qty) '; } else { $a=' SUM(qty/packing) '; } 
    $sid = $info2['id'];
    $transfer_in = mysqli_get_var("SELECT $a as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=0 $wlimit_warehouse8   ");
    $transfer_out = mysqli_get_var("SELECT $a as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=0 $wlimit_warehouse8  ");
    echo  $product_qta = $transfer_in-$transfer_out;*/
    $sp = mysqli_get_var("SELECT id FROM inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse ");
    $stocksingle = $info2['id'];
    if(1) { $a=' SUM(qty) '; } else { $a=' SUM(qty/packing) '; }
    $minus = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id && t.type=0 && w.deleted=0 &&  `item_id` = '$stocksingle' &&  `warehouse_id` = '$sp' "); 
    if($info1000['inventory_limit']==1) {
      $minus2 = mysqli_get_var("SELECT $a AS sqty FROM so_details WHERE warehouse_id='$sp' && prd_id='$stocksingle' && order_id IN (SELECT id FROM so WHERE completed=0)  "); 
    }else{
      $minus2 = 0;
    }
    $plus = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id && t.type=1 && w.deleted=0 &&  `item_id` = '$stocksingle' &&  `warehouse_id` = '$sp' "); 
    $minus3 = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id && w.deleted=0 && (w.tran_type=1 || w.tran_type=21) && verified_by=0 && t.type=1 &&  `item_id` = '$stocksingle' &&  `warehouse_id` = '$sp' ");
    $product_qta=$plus-$minus-$minus2-$minus3;
    if($info2000['qta_inpacking']==0) {
      echo number_format($product_qta, 2);
    }else{
      $packing5 = mysqli_get_var("SELECT packing FROM inventory WHERE id = '$stocksingle' ");
      echo number_format($product_qta/$packing5, 2);
    }
  ?></td>

<td <?php if($info3000['en_ajk'] ==0) echo ' style="display:none;"'; ?> >
                        <div class="product_lastsalepurchase">
                          <?php
$item_id = $info2['id'];

// Last Sale Rate and Qty
$sale_sql = "
    SELECT sd.tp, sd.qty 
    FROM sales_details sd
    JOIN sales s ON sd.order_id = s.id
    WHERE sd.prd_id = '$item_id'
    ORDER BY s.id DESC
    LIMIT 1
";
$sale_result = $conn->query($sale_sql);
if ($sale_result && $sale_result->num_rows > 0) {
    $row = $sale_result->fetch_assoc();
    $sale_rate = $row['tp'];
    $sale_qty = $row['qty'];
} else {
    $sale_rate = '---';
    $sale_qty = '---';
}

// Last Purchase Rate and Qty
$purchase_sql = "
    SELECT pd.tp, pd.qty 
    FROM purchasing_details pd
    JOIN purchasing p ON pd.order_id = p.id
    WHERE pd.prd_id = '$item_id'
    ORDER BY p.id DESC
    LIMIT 1
";
$purchase_result = $conn->query($purchase_sql);
if ($purchase_result && $purchase_result->num_rows > 0) {
    $row = $purchase_result->fetch_assoc();
    $purchase_rate = $row['tp'];
    $purchase_qty = $row['qty'];
} else {
    $purchase_rate = '---';
    $purchase_qty = '---';
}

echo "<strong>Sale:</strong> $sale_rate (Qty: $sale_qty)<br>";
echo "<strong>Purchase:</strong> $purchase_rate (Qty: $purchase_qty)";
?>
                        </div>
                    </td>

                    <td>
                        <input type="number" <?php if($info2000['multiple_batch']==1) { echo "value='1'  ";  } ?> size="4" required
                            min="0" step="0.00001" 
                            class="highlight searchp <?php if($info1000['no_purchasepacking']==1) echo ' change5';  ?>  income_count  packing"
                            id="ctn<?php echo $info2['id'];?>" tabindex="1"
                            value="" tabindex="1" />

                    </td>
                    <?php  if($info2000['uom_display']==1) { ?>
                    <td>
                        <?php if($info3000['en_uom_selection'] == 1){ ?>
                        <select class="form-control reportselect" name="uom[]" required="">
                            <?php 
          $data4 = mysqli_query($conn, "SELECT * FROM product_unit") or die(mysqli_error($conn)); 
          while($info4 = mysqli_fetch_array($data4)){
            ?><option value="<?php echo $info4['id'] ?>"
                                <?php if($info2['unit'] == $info4['id']){ echo "selected"; } ?>>
                                <?php echo $info4['name']; ?></option><?php
          }
          ?>
                        </select>
                        <?php } else{ ?>
                        <input type="hidden" name="uom[]" value="<?php echo $info2['unit'];  ?>">
                        <?php echo mysqli_get_var("SELECT name FROM product_unit WHERE id = '".$info2['unit']."' "); ?>
                        <?php } ?>
                    </td>
                    <?php } else{ ?>
                    <input type="hidden" name="uom[]" value="<?php echo $info2['unit'];  ?>">
                    <?php } ?>
                    <?php if($info3000['en_goodluck'] == 1 && $type_component != 3){ ?>
                    <th>
                        <input type="hidden" class="ohc" value="<?php echo $info2['ohc']; ?>">
                        <input type="hidden" class="weightage_field" value="0">
                        <div class="weightage_div">0</div>
                    </th>
                    <?php  } ?>
                    <td <?php if($info1000['no_purchasepacking']==1 || $info2000['pcs_hidec']==1) echo ' style="display:none;"';  ?>>
                        <!--<input type="hidden" name="<?php// echo $info2['id'];?>_packing" id="p<?php// echo $info2['id'];?>" class="searchqty income_count form-control" tabindex="1"  value="<?php// echo $info2['packing'];?>"  /> -->
                        <input type="text" size="4" min="1" value="0"
                            class="searchqty change change5 income_count totalorder" tabindex="1"
                            id="pcs<?php echo $info2['id'];?>" />
                    </td>
                    <?php 
                        if($info3000['en_fastpackages']==1){
                            $value_size= $info2['size'];
                            $value_color= $info2['color'];
                        }else {
                          $value_size="";
                          $value_color= "";
                        }                    
                    ?>
                    <td <?php if(($info2000['en_customfield1c']==0  && $type_component != 3)  ) {
    echo ' style="display:none;"';
} ?> class="recurringhide">
<input 
    name="custom_field1[]" 
    <?php if ($info2000['en_benin'] == 1) { echo 'readonly'; } ?>
    id="customfield<?php echo $info2['id']; ?>" 
    <?php echo $readonly; ?> 
    type="text" 
    tabindex="1"
    class="form-control customfield1 mycf teacher<?php if ($info3000['en_hapaperhub'] == 0) { echo ' income_count'; } ?>" 
    <?php if ($info3000['en_hapaperhub'] == 1) { echo 'style="max-width: 200px !important; width: 200px !important;"'; } ?> 
    value="<?php echo $value_size; ?>" 
/>
 </td>
                    <td <?php if($info4000['en_customfield2c']==0  && $type_component != 3) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input name="custom_field2[]" type="text" tabindex="1"
                            class="form-control customfield2 income_count" id="<?php echo "customfields".$info2['id'];?>" 
                            value="<?php echo $value_color ?>" /> </td>
                    <td <?php if($info4000['en_customfield3c']==0  && $type_component != 3) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input name="custom_field3[]" type="text" tabindex="1"
                            class="form-control customfield3 income_count" id="<?php echo "customfields".$info2['id'];?>" /> </td>
                             <td <?php if($info3000['en_customfield4c']==0  && $type_component != 3) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input name="custom_field4[]" type="text" tabindex="1"
                            class="form-control customfield4 income_count" id="<?php echo "customfields".$info2['id'];?>" /> </td>
                             <td <?php if($info3000['en_customfield5c']==0  && $type_component != 3) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input name="custom_field5[]" type="text" tabindex="1"
                            class="form-control customfield5 income_count" id="<?php echo "customfields".$info2['id'];?>" /> </td>
                              <td <?php if($info3000['en_customfield6c']==0  && $type_component != 3) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input name="custom_field6[]" type="text" tabindex="1"
                            class="form-control customfield6 income_count" id="<?php echo "customfields".$info2['id'];?>" /> </td>

                            

                    <td <?php if($info2000['en_customfield1c']==0 || $info3000['en_goodluck']==0 || $type_component == 3) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input name="price_slc[]" value="" type="text"
                            id="price_slc<?php echo $info2['id'];?>" tabindex="1"
                            class="form-control price_slc income_count" /> </td>
                    <td
                        <?php if($info2000['en_customfield1c']==0 || $info3000['en_goodluck']==0 || $type_component == 3) echo ' style="display:none;"';  ?>>
                        <input name="slc_amt[]" readonly type="text" tabindex="1" id="slc_amt<?php echo $info2['id'];?>"
                            class="form-control slc_amt income_count" />
                    </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse $lid  ") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]'  tabindex='1' class=' warehouse_charges teacher warehouse change6' required  >";
if($info3000['en_osaka']==1){echo "<option value=''>Select Warehouse</option>";}
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
 if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
 }
echo "</select>";
?></td>
                    <?php } ?>
                    <td <?php if($info1000['en_pos']==0  || $return==1) echo ' style="display:none;"';  ?>>
                        Min Qty <b><?php echo $info2['min_qty'];?></b><br>
                        Max Qty <b><?php echo $info2['max_qty'];?></b>
                    </td>
                    <td <?php if($info1000['en_pos']==0   || $return==1) echo ' style="display:none;"';  ?>>
                        <input tabindex="1" name="sale_price[]" id="<?php echo "mrp_pp".$info2['id'];?>" type="text"
                            required
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count  "
                            value="<?php if($info2['mrp_price']=='') echo 0; else echo $info2['mrp_price']; ?>"
                            size="4" />
                    

                    </td>



                    <td <?php if($info1000['en_pos']==0  || $return==1 || $invoice==1) echo ' style="display:none;"';  ?>>
                        <input tabindex="1" type="text" required class="price_margin" size="4"
                            value="0" readonly="readonly" />
                    </td>
                    <?php if($return==1) { if($info1000['en_inventorybatch']==1 && $grnn==1) {   ?>
                    <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid' && type_component=0 ") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1'  class='teacher reportselect batch7 inventory3 change7 loadBatchExpiry' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
 $batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?><input type="hidden" name="batch_old[]" value="1" /></td>
                    <?php } } else {  ?>

  <?php if($info1000['en_inventorybatch']==1 && $grnn==1 && $info2000['batch_grnonly'] == 0) { ?>

    <?php if($info1000['batch_with_brand']==1){ ?>
  <td>
  <input type="text" name="batch_brand[]"
    <?php  if($info2['is_batch']==0) { echo 'readonly';  }?>
    value="" tabindex="1"
    class="change71 income_count batch71 form-control"
    id="<?php echo "batch_brand".$info2['id'];?>" />
  </td>
    <?php } ?>
    
  <td>
  <div id="increase_width" <?php if($info2['is_batch'] != 1){ echo "class='hide'"; } ?> >
         <?php if($info3000['open_batchgrn']==1) { ?>
         <input type="text" name="products_batch[]"
                        <?php  if($info2['is_batch']==0) { echo 'readonly';  }?>
                        value="<?php echo $info2['is_batch']; ?>" tabindex="1"
                        class="change7 income_count batch7 form-control"
                        maxlength="<?php echo $info2000['max_batch_length']; ?>" required
                        id="<?php echo "batch".$info2['id'];?>" /></div> <input type="hidden" name="batch_old[]"
                    value="0" />
          <?php } else { ?>  
           <select name="products_batch[]"   class='teacher warehouse inventory3'  >
             <?php $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid' AND type_component = 0") or die(mysqli_error($conn));

 while($info4 = mysqli_fetch_array( $data4 ))
 {


    $batch_code = "";
    $batch_code2 = $info4['batch_code'];

    if($batch_code2!="") { $batch_code=$batch_code2;} else {
    if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
    }


    if($info2['batch_id']==$info4['id'])
    {
     echo "<option value='".$info4['id']."' selected >".$batch_code."</option>";
    }
    else {
       echo "<option value='".$info4['id']."' >".$batch_code."</option>";
    }

 }


?>
</select><?php } ?>
        </div>     
    
  <!-- <div class="batchdiv">
  <?php  $pid =  $info2['id']; 
  
        
        if($info4000['en_allbatchdisplay']==0) { 
    $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid' && type_component=0   order by batch_code ") or die(mysqli_error($conn)); 
  } else { 
  
    $data4 = mysqli_query($conn,"SELECT batch_code, MIN(id) as id   from inventory_batch where active=1  && type_component=0 group by batch_code  order by batch_code ") or die(mysqli_error($conn)); 
  
   }
        
   $ii=0;
   // if($info2['is_batch'] != 1)
   //   $class="hide";
    
    if($info3000['datewise_batch']==1) { 
        ?>
            <input type="text" name="products_batch[]"
            value="" tabindex="1"
            class="change7 income_count batch7 form-control loadautobatch"
            maxlength="<?php echo $info2000['max_batch_length']; ?>" required
            id="" />
        <?php
    }else{
        if($info3000['en_karachicables'] == 0){
        echo "<select name='products_batch[]' id='loadBatchExpiry' tabindex='1'  class='teacher change7 reportselect $class loadBatchExpiry'    required  >";
            while($info4 = mysqli_fetch_array( $data4 )) 
            { 
            echo "<option value='".$info4['id']."' >".$info4['batch_code']."  </option>";
        }
        echo "</select>";
        }
    }

     ?>
     </div> -->
  </td>

<?php } } ?>
                    <?php if($info2000['multiple_batch']==1) { ?>
                    <td>
                        <?php if($return==1) {
       $pid =  $info2['id']; 
         $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'   && type_component=0 ") or die(mysqli_error($conn)); 
        $ii=0;
        // if($info2['is_batch'] != 1)
        //   $class="hide";
        echo "<select name='multi_batch[]' tabindex='1'  class='teacher reportselect $class'    required  >";
         while($info4 = mysqli_fetch_array( $data4 )) 
         { 
              $in = mysqli_get_var("Select SUM(qty) from warehouse_transaction w, warehouse_transaction_type t where item_id='$pid' && w.deleted=0  && w.tran_type=t.id && t.type=1 && w.batch_no='".$info4['id']."' ");
              $out = mysqli_get_var("Select SUM(qty) from warehouse_transaction w, warehouse_transaction_type t where item_id='$pid' && w.deleted=0  && w.tran_type=t.id && t.type=0 && w.batch_no='".$info4['id']."' ");
              $bbance = $in - $out;
              if($bbance==0) continue;
           echo "<option value='".$info4['id']."' >".$info4['batch_code']." (".$bbance.") </option>";
        }
        echo "</select>";
       }else { ?>
                        <input <?php if($info2['is_batch'] != 1){ echo "class='hide'"; } ?> type="text"
                            name="multi_batch[]" value="-"
                            <?php if($info1000['en_batch_expiry']==1) { echo 'required';} else {?> readonly="readonly"
                            <?php  }?> />
                        <?php }?>
                    </td>
                    <?php } ?>
                    <?php if($info1000['en_batch_expiry']==1 &&  $snd_purh==1) { ?>
                    <td><input type="date" name="multi_batch_expiry[]"
                            <?php if($info2['is_batch'] != 1){ echo "class='hide' value='".date('Y-m-d')."'"; }else{ echo "class='form-control' required";} ?>
                            id="<?php echo "expiry8".$info2['id'];?>" /> </td>
                    <?php } ?>
                    <?php  if($info1000['en_expirydisplay']==1 && $grnn==1) {  ?>
                        <?php if($info3000['datewise_batch']==1) { ?>
                            <td <?php //if($return==1) { echo ' style=" display:none;"'; } ?>><input type="date"
                                name="products_expiry[]" id="LoadExpiryHere" <?php  /*if($info2['is_batch']==0) { echo 'readonly';  }*/ ?> value=""
                                tabindex="1" <?php if($return==0) { ?> required <?php } ?>
                                class="change8 change7 form-control income_count LoadExpiryHere batch7" id="<?php echo "expiry".$info2['id'];?>" /></td>
                       <?php }else{ ?>
                            <td <?php if($return==1) { echo ' style=" display:none;"'; } ?>><input type="date"
                            name="products_expiry[]" id="LoadExpiryHere" <?php  if($info2['is_batch']==0) { echo 'readonly';  }?> value=""
                            tabindex="1" <?php if($return==0) { ?> required <?php } ?>
                            class="change8 form-control  LoadExpiryHere batch7" id="<?php echo "expiry".$info2['id'];?>" /></td>                            
                          <?php  } ?>
                    <?php } ?>

                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <input name="products_packing[]" type="number" min="0.1" step="0.001" size="4" min="1"
                            class="new_packing change income_count totalorder qtyCheck"
                            id="p<?php echo $info2['id'];?>" tabindex="1" value="<?php echo $info2['packing'];?>"
                            <?php if($info2000['en_ricetrade']==0){echo "readonly='readonly'";} ?> />
                        <input name="products_packing2[]" type="hidden"
                            class="edit-input change income_count packing2 totalorder qtyCheck" id="pack2<?php echo $info2['id'];?>"
                            tabindex="1" value="<?php echo $info2['packing2'];?>" />
                    </td>
                    <td>
                        <?php
if($info3000['en_snd_purchase']==1)
{
  $data15 = mysqli_query($conn,"SELECT distributor_vendor_type  from distributor where  id='$dist_id' ") or die(mysqli_error($conn));    
  $info15 = mysqli_fetch_array( $data15 ); 
  // echo "SELECT distributor_type  from distributor where  id='$dist_id' ";
  $ttid=$info15['distributor_vendor_type'];
}
else if($info1000['en_distributor']==1)
{
   $data15 = mysqli_query($conn,"SELECT distributor_vendor_type  from distributor where  id='$dist_id' ") or die(mysqli_error($conn));    
  $info15 = mysqli_fetch_array( $data15 );
  // echo "SELECT distributor_vendor_type  from distributor where  id='$dist_id' <br>"; 
  // echo "SELECT distributor_type  from distributor where  id='$dist_id' ";
  $ttid=$info15['distributor_vendor_type'];
}
else
{
$data15 = mysqli_query($conn,"SELECT vendor_type from vendor where  id='$cid' ") or die(mysqli_error($conn));    
$info15 = mysqli_fetch_array( $data15 ); 
$ttid=$info15['vendor_type'];
}
$ppid=$info2['id'];
// echo "SELECT price from vendor_type_pricing where pid='$ttid' AND tid='$ppid' ";
 $data15 = mysqli_query($conn,"SELECT price from vendor_type_pricing where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" min="0" name="unitcos[]" type="number" step="0.00001"
                            value="<?php echo $info15['price'];?>" required
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> <?php if($info4000['en_mdfoods']==1){echo "teacher warehouse  change6 ";} ?> new_rate  income_count chk8ange totalorder"
                            size="4" />
                        <?php } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100; 
$discount4=$info200['discount4']/100;
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3; 
$discount4=1-$discount4; 
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info200['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $info2['unit_cost'];
if($wo_po!=0 && $wo_po!='') { 
$price = mysqli_get_var("Select rate from toll_rate where vid='$cid' && inward_id='$tollitem' order by id  ");
    }
    ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" min="0" name="unitcos[]" type="number" step="0.00001"
                            value="<?php echo $price;?>" required
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  <?php if($info4000['en_mdfoods']==1){echo "teacher warehouse  change6 ";} ?> new_rate income_count chk8ange totalorder"
                            size="4" />
                        <?php }
else {  
$price = $info2['unit_cost'];
if($wo_po!=0 && $wo_po!='') { 
$rate = $price = mysqli_get_var("Select rate from toll_rate where vid='$cid' && inward_id='$tollitem' order by id  ");
    }
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" required min="0" step="0.00001"   
                            value="<?php if($info3000['en_crest']==1 || $rate=='-1' || $rate=='') { echo $price; } else {
       echo $rate; 
 }
 ?>" class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> <?php if($info4000['en_mdfoods']==1){echo "teacher warehouse  change6 ";} ?> new_rate income_count chk8ange totalorder"
                            size="4" />
                        <?php } ?>
                        <?php if($info4000['vendor_foc']!=1) { ?>
                        <input type="hidden" required step="0.0001" name="products_foc[]" value="0"  class="foc income_count"   size="4"   />
                        <?php } ?>

<input type="hidden" name="discount5[]" value="0" id="<?php echo "pppl".$info2['id'];?>"  tabindex="1"  class="edit-input income_count"   size="4"   /> 


         

  <input name="tax_mrp[]" size="4" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "mrptax".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['tax_mrp'];?>" />
                        <?php
              if($info4000['separate_mrpcolumnp']==0)
              {
              ?>
                        <input name="mrp_price[]" size="4" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "mrp".$info2['id'];?>" tabindex="1"
                            value="<?php if($mpp!='' && $mpp!=0) { echo $mpp;  } else { if($info1000['rate_incartonp']==1) { echo $info2['mrp_price']*$info2['packing']; } else { echo $info2['mrp_price']; } } $mpp=''; ?>" />
                        <?php
              }
              ?>
                        <!-- <input name="new_rate[]" size="4"   type="hidden" class="new_rate" value="<?php echo $new_rate;?>"  /> -->
                    </td>
                    <?php if($info4000['separate_mrpcolumnp']==1) { ?> <td>
                        <input name="mrp_price[]" size="4" type="number" required step='0.0001'
                            class="edit-input income_count totalorder" id="<?php echo "mrp".$info2['id'];?>"
                            tabindex="1"
                            value="<?php if($mpp!='' && $mpp!=0) { echo $mpp;  } else { if($info1000['rate_incartonp']==1) { echo $info2['mrp_price']*$info2['packing']; } else { echo $info2['mrp_price']; } } $mpp=''; ?>" />
                    </td>
                    <?php }  //closepricing ?>

                    <?php if($info2000['en_sarhad'] == 1 || $info4000['itemmulti_unit']==1){ ?>
                    <input name="prd_hidden[]" type="hidden" class="prd_hidden" value="<?php echo $info2['id'];?>" />
                    <input name="packing_hidden[]" type="hidden" class="packing_hidden"
                        value="<?php echo $info2['packing'];?>" />
                    <td>
                        <?php 
  $single_unit = mysqli_get_var("SELECT unit FROM inventory WHERE id='".$info2['id']."' ");
  $data4 = mysqli_query($conn,"SELECT * FROM product_unit WHERE id IN (SELECT unit FROM multiple_product_unit WHERE pid = '".$info2['id']."' )  ") or die(mysqli_error($conn)); 
  echo "<select name='munit[]'  required class=' munit form-control'   >";
  //echo "<option value='0' >Select Product Unit</option>";
  while($info4 = mysqli_fetch_array( $data4 )){ 
    $selected = '';
    if($single_unit == $info4['id'])
      $selected = 'selected';
    echo "<option value='".$info4['id']."' $selected >".$info4['name']."</option>";
  }
  echo "</select>";
  ?></td>
                    <td style="display:none;"><input name="con_rate[]" value="1" size="4" class="con_rate" id="" /></td>
                    <?php } ?>
                    <td <?php  if($info4000['invoice_cartonratep']==0) { echo ' style=" display:none;"'; } ?>>
                        <select name='rate_in_carton[]' class='teacher income_count case2qty'
                            id="<?php echo "ric".$info2['id'];?>">
                            <?php if($info4000['en_engineering']==0){  ?>
                            <option value='0'>Default</option>
                            <option value='1'><?php echo $info1000['packing_label']; ?></option>
                            <?php } ?>
                            <option value='2'><?php echo $info1000['multi_unit_label']; ?></option>
                            <option value='3'><?php echo $info2000['customfield1_display'];  ?></option>
                        </select>
                    </td>
                    <td <?php  if($info2000['en_ricetrade']==0) { echo ' style=" display:none;"'; } ?>><input
                            name="packing2[]" type="number" step="0.0001" class='teacher packing2 income_count'
                            value="<?php echo $info2['pac2']; ?>" id="<?php echo "packk".$info2['id'];?>" /> </td>
                    <?php if($info1000['vendor_discount1']==1) { 
 echo '<td >';
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from vb_discount where vid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from vendor_type_discount1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
// echo "SELECT discount from vendor_type_discount1 where pid='$ttid' AND tid='$ppid' ";
if($num_rows!=0) {
?>
                    <input name="products_discount[]" type="number" required step="0.0001" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                        size="4" />
                    <?php }
else if($num_rows2!=0) {
?>
                    <input name="products_discount[]" type="number" required step="0.0001" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info17['discount'];?>"
                        size="4" />
                    <?php }  else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <input name="products_discount[]" type="number" required step="0.0001" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info200['discount'];?>"
                        size="4" />
                    <?php }
 else {  ?>
                    <input name="products_discount[]" type="number" required step="0.0001" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } echo '</td>'; } else { ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['vendor_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from vendor_type_discount2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php }
elseif($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php }
 else {  ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['vendor_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from vendor_type_discount4 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php }
else if($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php }
 else {  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }

 if($info4000['vendor_foc']==1  ) { 
  $foc = mysqli_get_var("SELECT discount_percentage FROM amount_discountp where min_amount='$sid' ");
  $foc_value = mysqli_get_var("SELECT discount_value FROM amount_discountp where min_amount='$sid' ");
  if($foc=="") {  $foc=0; }
  if($foc_value=="") {  $foc_value=0; }
 ?>
                    <td>
                        <input type="number" name="products_foc[]" class="gggg form-control foc income_count" id="<?php echo "pfoc".$info2['id'];?>" required size="4" />
                        <input type="hidden" class="foc_scheme" id="<?php echo "pfoc_scheme".$info2['id'];?>" value="<?php echo $foc; ?>" />
                        <input type="hidden" class="foc_value" id="<?php echo "pfoc_value".$info2['id'];?>" value="<?php echo $foc_value; ?>" />
                    </td>
                    <?php } 

else { 
    ?>
                    <input type="hidden" name="products_foc[]" value="0" class="a3 foc income_count"
                        id="<?php echo "pfoc".$info2['id'];?>" required size="4" />
                    <?php }
  if($info1000['vendor_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from vendor_type_discount3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" step="0.0001" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='') {?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount3'];?>" size="4" step="0.0001" /></td>
                    <?php }  else {  ?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" step="0.0001" /></td>
                    <?php } } else {?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['vendor_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from vendor_type_scheme where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                            size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } ?>
                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                        <input name="products_pcs[]" type="text" size="4" min="1" class="edit-input total_pcs"
                            id="<?php echo "t".$info2['id'];?>" readonly="readonly" />
                    </td>

                    <?php if(1==1){   ?>     
     <td  <?php if($info4000['display_taxamount']==0){ echo ' style="display:none;"';    }  ?> >
   <input name="display_totaltax2[]" type="text" class="income_count display_totaltax2" id="<?php echo "ppptttt".$info2['id'];?>"    value="0" size="4" readonly/>
</td>
<?php } ?>
                    <?php if($info1000['vendor_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from vendor_type_tax1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($info2000['en_maintaxc']==1) {
?>
                    <td><input name="products_tax[]" type="number" required step="0.0001" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($st==1) {  if($cfiler==1) { echo $info2000['filer_taxc']; } else { echo $info2000['nonfiler_taxc']; }  } else { echo 0; } ?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
else if($num_rows!=0 && (float)$info15['discount']>0) {
?>
                    <td><input name="products_tax[]" type="number" required step="0.0001" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td> <input name="products_tax[]" type="number" required step="0.0001" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php } elseif($info2['direct_invoicetax']!=-1) { //direct_invoicetax ?>
                    <td> <input name="products_tax[]" type="number" required step="0.0001" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php echo $info2['direct_invoicetax']; ?>"
                            size="4" readonly="readonly" /></td>
                    <?php } else {  ?> 
                    <td><input name="products_tax[]" type="number" required step="0.0001" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } } else { ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" /></td>
                    <?php } ?>
                    <td <?php if($info4000['invoice_cartonratep']==0) { echo ' style=" display:none;" '; } ?>><input
                            name="pipe[]" type="text" class="edit-input pipehide income_count" tabindex="1"
                            id="<?php echo "pipe".$info2['id'];?>" value="<?php  echo 0; ?>" size="4"
                            readonly="readonly" /></td>
                    <?php  if($info1000['vendor_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from vendor_type_tax2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } 
else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied2']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } if($info1000['vendor_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from vendor_type_tax3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php }  else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } ?>

 <?php if(1==1){   ?>     
     <td  <?php if($info4000['display_taxamount']==0){ echo ' style="display:none;"';    }  ?> >
   <input name="display_totaltax[]" type="text" class="income_count display_totaltax" id="<?php echo "ppptt".$info2['id'];?>"    value="0" size="4" readonly/>
</td>
<?php } ?> 

                    <td<?php if($po_withoutvalue_request) { echo ' style="display:none;"'; } ?>><input name="products_total[]" id="newtotal<?php echo $info2['id'];?>" type="number" size="5" min="0" step="0.0001"  
                            class="tot<?php echo $info2['id'];?> ptotal sub_total readonly " tabindex="-1" onkeypress="return false;" /></td>
                            <!-- jhasdkfnksjdf -->
                             
                    <td class="d-flex gap-2">
                        <?php if(1==1) { ?>
                            <input type="button" class="rounded-1 bg-info text-white border-0 p-1 edit receipt_edit_hide5" value="Edit" />
                            <input type="button" class="rounded-1 bg-success text-white border-0 p-1 save" value="Save" /><?php } ?><?php if(1==1) { ?>
                            <input type="button" class="rounded-1 bg-danger text-white border-0 p-1 delete receipt_delete_edit5" value="Delete" /><?php } ?>
                            <?php if($info3000['duplicatebutton_order'] == 1) {
                                                echo '<input type="button" name="add" value="+" class="tr_clone_add12">';
                                            } ?></td>

                            
                    
                </tr>
                <?php } ?>

            </tbody>
        </table>
    </div>
    <?php if($info1000['en_recurringinvoices']==1){ ?>
    <script type="text/javascript">
    $('.recurringhide').hide();
    </script>
    <?php } ?>
    
    <script type="text/javascript">
    $(document).ready(function() {
                
            <?php if($info3000['duplicatebutton_order'] == 1) { ?>
                $(document).off('click', 'input.tr_clone_add12').on('click', 'input.tr_clone_add12', function() {
                    $('.reportselect').filter('.select2-hidden-accessible').select2('destroy');
                    console.log("Cloning row...");
                    
                    var $tr = $(this).closest('.carttr');
                    var $clone = $tr.clone();
                    
                    // Remove the clone button from the new row
                    $clone.find('input.tr_clone_add12').remove();
                    
                    // Mark as clone (optional, if you need to track cloned rows)
                    $clone.data('is-clone', true);
                    
                    $tr.after($clone);
                    $('.reportselect').select2();
                    $(".income_count:last").trigger("change");
                });
            <?php } ?>
                <?php 
  if($info1000['open_ratecolumn']==1) { ?>
                $('.change15').focusout(function() {
                            $(".change15").removeClass("change15");
                            <?php } else if($info1000['en_expirydisplay']==1 && $return=0 && $grnn==1) {  ?>
                            $('.change8').focusout(function() {
                                        $(".change8").removeClass("change8");
                                        <?php } 
    else if($info1000['en_inventorybatch']==1 && $grnn==1) {  ?>
                                        $('.change7').focusout(function() {
                                                    $(".change7").removeClass("change7");
                                                    <?php } else if($info1000['en_warehouse']==1) {  ?>
                                                    $('.change6').focusout(function() {
                                                        $(".change6").removeClass("change6");
                                                        <?php } else {  ?>
                                                        $('.change5').focusout(function() {
                                                            $(".change5").removeClass("change5");
                                                            <?php }  ?>
                                                            var $orginal = $(this).closest("tr");
                                                            var $cloned = $orginal.clone();
                                                            //get original selects into a jq object
                                                            var $originalSelects = $orginal.find(
                                                                'select');
                                                            $cloned.find('select').each(function(index,
                                                                item) {
                                                                //set new select to value of old select
                                                                $(item).val($originalSelects.eq(
                                                                    index).val());
                                                            });
                                                            //get original textareas into a jq object
                                                            var $originalTextareas = $orginal.find(
                                                                'textarea');
                                                            $cloned.find('textarea').each(function(
                                                                index, item) {
                                                                //set new textareas to value of old textareas
                                                                $(item).val($originalTextareas
                                                                    .eq(index).val());
                                                            });
                                                            $cloned.appendTo("#acart");
                                                            $('.searchqty').attr('class',
                                                                "highlight income_count ");
                                                            $("#searchbox").focus();
                                                            $("#psearch").html('');
                                                            $(".combobox").select2();
                                                        });
                                                    });
    </script>
    <script type="text/javascript">
    $(document).ready(function() {
        $('.save').hide();
        $('.edit-input').attr("readonly", true);        
        <?php if($info2000['en_ricetrade']==0){?> $('.new_packing').attr("readonly", false); <?php } ?>
        $(document).on('click', ".edit", function() {
            $(this).closest('tr').find('.edit').hide();
            $(this).closest('tr').find('.save').show();
            $(this).closest('tr').find('.edit-input').attr("readonly", false);
        });
        $(document).on('click', ".save", function() {
            $(this).closest('tr').find('.save').hide();
            $(this).closest('tr').find('.edit').show();
            $(this).closest('tr').find('.edit-input').attr("readonly", true);
        });
        $(document).on('click', ".delete", function() {
            $(this).closest('tr').remove();
            //Total Quantity Sum  (Pcs)
            var sum = 0;
            $(".total_pcs").each(function() {
                sum += parseFloat($(this).val()) || 0;
            });
            $("#total_pcs").val(sum);
            //Total Quantity Sum  (Carton)
            var sum3 = 0;
            $(".packing").each(function() {
                sum3 += parseFloat($(this).val()) || 0;
            });
            $("#packing").val(sum3);
            //Total Amount Sum  (Sub Total)
            var sum2 = 0;
            $(".sub_total").each(function() {
                sum2 += parseFloat($(this).val()) || 0;
            });
            var decimal_point = "<?php echo $info2000['total_decimal']; ?>";
            sum2 = sum2.toFixed(decimal_point);
            $("#sub_total").val(sum2);
            var n4 = $("#sub_total").val();
            var n5 = $("#paid_amount").val();
            var n6 = $("#pending_amount").val();
            var total = +n4;
            var pending = +total - n5;
            total = total.toFixed(decimal_point);
            pending = pending.toFixed(decimal_point);
            $("#total_amount").val(total);
            $("#pending_amount").val(pending);
        });
    });
    </script>
    <script type="text/javascript">
    <?php if($return==0) { ?>
    $(document).on('change focusout ', '.batch7', function() {
        var a = this.id;
        a = a.replace(/\D/g, '');
        var batch = $(this).closest(".carttr").find(".batch7").val();
        if (batch != '') {
            var prd_id = $(this).closest(".carttr").find("#code" + a).val();
            var that = $(this);
            $.ajax({
                type: "POST",
                url: "../ajax/receipt-query2.php",
                data: {
                    batch7: batch,
                    prd_id7: prd_id
                },
                cache: false,
                dataType: 'html',
                success: function(html) {
                    that.closest(".carttr").find(".expiry7").val(html);
                }
            });
        }
    });
    <?php } else { ?>
    $(document).on('change focusout ', '.batch7', function() {
        var a = this.id;
        a = a.replace(/\D/g, '');
        var batch = $(this).closest(".carttr").find(".batch7").val();
        if (batch != '') {
            var prd_id = $(this).closest(".carttr").find("#code" + a).val();
            var that = $(this);
            $.ajax({
                type: "POST",
                url: "../ajax/receipt-query2.php",
                data: {
                    batch71: batch,
                    prd_id7: prd_id
                },
                cache: false,
                dataType: 'html',
                success: function(html) {
                    that.closest(".carttr").find(".expiry7").val(html);
                }
            });
        }
    });
    <?php }  ?>



</script>    
<?php  include('customer-custom-formula.php'); ?>
<?php  include('../functions/incomecount_function.php'); ?>


    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  }
else if(isset($_POST['pidc']))
{
$sid=test_input($_POST['pidc']);
$vid=test_input($_POST['vendorid']);
$return=test_input($_POST['return']);
$cid=test_input($_POST['vendorid']);

$lid=test_input($_POST['lid']);


if($lid!='') {
$lid=" && location_id='$lid' ";
}


  $st=test_input($_POST['st']);
   $grnn=test_input($_POST['grn']);
$materialrate = mysqli_get_var("SELECT rate from vendor_material where vid='$vid' and raw_material_id='$sid'");
$cwarehouse = mysqli_get_var("Select inventory_warehouse from vendor where `id` = '$vid'");
 $cfiler = mysqli_get_var("Select filer from vendor where `id` = '$vid'");
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="25%"><?php echo $info1000['material_label']; ?></th>
                    <?php if(0==0){ ?>
                    <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <div>QTA</div>
                    </th>
                    <?php } ?>
                    <th>
                        <div><?php echo $info1000['multi_unit_labelp']; ?></div>
                    </th>
                    <?php  if($info2000['uom_display']==1) { ?> <th align="center"><?php echo $info2000['uom_label']; ?>
                    </th><?php } ?>
                    <th
                        <?php if($info1000['no_purchasepacking']==1   || $info2000['pcs_hidec']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['single_unit_label']; ?></div>
                    </th>
                    <th <?php if($info2000['en_customfield1c']==0) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info2000['customfield1c_display'];  ?></div>
                    </th>

<th <?php if($info4000['en_customfield2c']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info4000['customfield2c_label'];  ?></div></th>
  <th <?php if($info4000['en_customfield3c']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info4000['customfield3c_label'];  ?></div></th>                        
<th <?php if($info3000['en_customfield4c']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info3000['customfield4c_label'];  ?></div></th>
                <th <?php if($info3000['en_customfield5c']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info3000['customfield5c_label'];  ?></div></th>


<th <?php if($info3000['en_customfield6c']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info3000['customfield6c_label'];  ?></div></th>



                    <?php if($info1000['en_warehouse']==1) {  echo  '  <th ><div>'.$info2000['warehouse_label'].' </div></th> '; } ?>
                    <?php if($info1000['en_rawmaterialbatch']==1 && ($grnn==1 || $info2000['batch_grnonly']==0) ) {   echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; } ?>
                    <?php if($info1000['en_expirydisplayc']==1 && $return==0 && $grnn==1) {   echo  '  <th ><div>Expiry </div></th> '; } ?>
                    <th <?php if($info1000['no_purchasepacking']==1 ) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['packing_label']; ?></div>
                    </th>

                    <?php if($info3000['en_posch']==1) { ?>
                    <th>
                        <div>Last Purchase Price</div>
                    </th>
                    <?php } ?>
                    <th>
                        <div><?php echo $info1000['price_label']; ?></div>
                    </th>
<th <?php if($info4000['separate_mrpcolumn']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info4000['mrp_label']; ?></div></th> 
                    
                    <?php  if($info2000['invoice_cartonrate']==1) {  ?>
                    <th>
                        <div>Rate Apply</div>
                    </th>
                    <?php } ?>
                    <?php if($info1000['vendor_discount1']==1) {  echo  '  <th ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_discount2']==1) {  echo  '  <th ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_discount4']==1) {  echo  '  <th ><div>'.$info1000['disc3_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_discount3']==1) {  echo  '  <th ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_scheme']==1) {  echo  '  <th ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                    <?php if($info4000['display_taxamount']==1){   ?>    
            <th>Exclusive of GST Amount</th>    
            <?php } ?> 
                    <?php if($info1000['vendor_tax1']==1) {  echo  '  <th ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
                    <?php  if($info2000['invoice_cartonrate']==1) {  ?>
                    <th>
                        <div>Pipe Rate</div>
                    </th>
                    <?php } ?>
                    <?php if($info1000['vendor_tax2']==1) {  echo  '  <th ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_tax3']==1) {  echo  '  <th ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
               <?php if($info4000['display_taxamount']==1){     ?>    
            <th><?php echo $info4000['taxamount_label']; ?></th>    
            <?php } ?>

                    <th contenteditable="true" width="80">Total </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
    $data2 = mysqli_query($conn,"SELECT * from component where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr class="carttr">
                    <td><input type="hidden" name="products[]" class="singleitem" value="<?php echo $info2['id'];?>" />
                        <?php echo $info2['sku'].' '.$info2['name'];?>
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from purchasing_details sd, purchasing s  where sd.prd_id='$sid' AND s.type_component=1 AND sd.`order_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
      else if($info1000['en_lastprice']==2 ) {
       $data200 = mysqli_query($conn,"SELECT sd.* from purchasing_details sd, purchasing s  where sd.prd_id='$sid' AND s.type_component=1 AND sd.`order_id`=s.`id` AND s.vendor_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }  

      if($info3000['en_posch']==1 && !$info200) {
        $data200 = mysqli_query($conn,"SELECT sd.* from purchasing_details sd, purchasing s  where sd.prd_id='$sid' AND s.type_component=1 AND sd.`order_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
        $info200 = mysqli_fetch_array( $data200 );
      }
      $last_purchase_price = '';
      if(!empty($info200) && isset($info200['tp']) && $info200['tp'] !== '') {
        $last_purchase_price = $info200['tp'];
      } elseif(!empty($info200) && isset($info200['prd_amount'], $info200['qty']) && $info200['qty'] > 0) {
        $last_purchase_price = $info200['prd_amount'] / $info200['qty'];
      }
         ?> <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <?php if(0==0){ ?>
                    <td class="triggeravailable"
                        <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>><?php   
    $sid = $info2['id'];
    $sp = mysqli_get_var("SELECT id from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse ");
   $stocksingle = $info2['id'];
   if(1) { $a=' SUM(qty) '; } else { $a=' SUM(qty/packing) '; }
    $minus = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id && t.type=0 && w.deleted=0 AND w.type_component = 1 &&  `item_id` = '$stocksingle' &&  `warehouse_id` = '$sp' "); 
    if($info1000['inventory_limit']==1) {
      $minus2 = mysqli_get_var("SELECT $a AS sqty FROM so_details WHERE warehouse_id='$sp' && prd_id='$stocksingle' && order_id IN (SELECT id FROM so WHERE completed=0 AND type_component = 1)  "); 
    }else{
      $minus2 = 0;
    }
    $plus = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id && t.type=1 && w.deleted=0 AND w.type_component = 1 &&  `item_id` = '$stocksingle' &&  `warehouse_id` = '$sp' "); 
    $minus3 = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id AND w.type_component = 1 && w.deleted=0 && (w.tran_type=1 || w.tran_type=21) && verified_by=0 && t.type=1 &&  `item_id` = '$stocksingle' &&  `warehouse_id` = '$sp' ");
    $product_qta=$plus-$minus-$minus2-$minus3;
    if($info2000['qta_inpacking']==0) {
      echo number_format($product_qta, 2);
    }else{
      $packing5 = mysqli_get_var("SELECT packing FROM component WHERE id = '$stocksingle' ");
      echo number_format($product_qta/$packing5, 2);
    }
    /*$transfer_in = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=1 $wlimit_warehouse8   ");
    $transfer_out = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=1 $wlimit_warehouse8  ");
    echo  $product_qta = $transfer_in-$transfer_out;*/
  ?></td>
                    <?php } ?>
                    <td>
                        <input type="text"
                            class="highlight <?php if($info1000['no_purchasepacking']==1) echo ' change5';  ?>  searchp income_count packing"
                            size="4" min="1" id="ctn<?php echo $info2['id'];?>" tabindex="1" />
                    </td>
                    <?php  if($info2000['uom_display']==1) { ?>
                    <td>
                        <?php if($info3000['en_uom_selection'] == 1){ ?>
                        <select class="form-control reportselect" name="uom[]" required="">
                            <?php 
          $data4 = mysqli_query($conn, "SELECT * FROM component_unit") or die(mysqli_error($conn)); 
          while($info4 = mysqli_fetch_array($data4)){
            ?><option value="<?php echo $info4['id'] ?>"
                                <?php if($info2['unit'] == $info4['id']){ echo "selected"; } ?>>
                                <?php echo $info4['name']; ?></option><?php
          }
          ?>
                        </select>
                        <?php } else{ ?>
                        <input type="hidden" name="uom[]" value="<?php echo $info2['unit'];  ?>">
                        <?php echo mysqli_get_var("SELECT name FROM component_unit WHERE id = '".$info2['unit']."' "); ?>
                        <?php } ?>
                    </td>
                    <?php } else{ ?>
                    <input type="hidden" name="uom[]" value="<?php echo $info2['unit'];  ?>">
                    <?php } ?>
                    <td
                        <?php if($info1000['no_purchasepacking']==1   || $info2000['pcs_hidec']==1) echo ' style="display:none;"';  ?>>
                        <!--<input type="hidden" name="<?php// echo $info2['id'];?>_packing" id="p<?php// echo $info2['id'];?>" class="searchqty income_count form-control" tabindex="1"  value="<?php// echo $info2['packing'];?>"  /> -->
                        <input type="text" value="0" size="4" min="1"
                            class="searchqty change change5 income_count totalorder" tabindex="1"
                            id="pcs<?php echo $info2['id'];?>" />
                    </td>
                    <td <?php if($info2000['en_customfield1c']==0) echo ' style="display:none;"';  ?>><input
                            name="custom_field1[]" id="customfield<?php echo $info2['id'];?>" type="text" tabindex="1"
                            class="form-control  <?php if($info3000['ctn_customfieldrate']==0) { ?>income_count<?php } ?>  customfield1" /> </td>


   <td <?php if($info4000['en_customfield2c']==0) echo ' style="display:none;"';  ?> ><input  style="width:100px;"  name="custom_field2[]"     id="customfield<?php echo $info2['id'];?>" type="text" value="<?php echo $info2['custom_field2']; ?>"  tabindex="1" class="form-control  <?php if($info3000['ctn_customfieldrate']==0) { ?>income_count<?php } ?>  customfield2" /> </td>   
                                 
                               <td <?php if($info4000['en_customfield3c']==0) echo ' style="display:none;"';  ?> ><input  style="width:100px;"   name="custom_field3[]"     id="customfield<?php echo $info2['id'];?>" type="text" value="<?php echo $info2['custom_field3']; ?>"  tabindex="1" class="form-control income_count customfield3" /> </td>  
                              
                               <td <?php if($info3000['en_customfield4c']==0) echo ' style="display:none;"';  ?> ><input  style="width:100px;"  name="custom_field4[]"     id="customfieldddd<?php echo $info2['id'];?>" type="text" value="<?php echo $info2['custom_field4']; ?>"  tabindex="1" class="form-control income_count customfield4" /> </td>  
                               
                               
                                  <td <?php if($info3000['en_customfield5c']==0) echo ' style="display:none;"';  ?> ><input name="custom_field5[]"     id="customfieldccd<?php echo $info2['id'];?>" type="text" value="<?php echo $info2['custom_field5']; ?>"  tabindex="1" class="form-control income_count customfield5" /> </td>
       
       <td <?php if($info3000['en_customfield6c']==0) echo ' style="display:none;"';  ?> ><input name="custom_field6[]"     id="customfieldccdd<?php echo $info2['id'];?>" type="text" value="<?php echo $info2['custom_field6']; ?>"  tabindex="1" class="form-control income_count customfield6" /> </td>





                    <td <?php if($info1000['en_warehouse']!=1) { ?>style="display: none;" <?php } ?>><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse $lid ") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' tabindex='1' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
 if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
 }
echo "</select>";
?></td>
                    <?php if($return==1) { if($info1000['en_rawmaterialbatch']==1 && ($grnn==1  || $info2000['batch_grnonly']==0) ) { ?>
                    <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'   && type_component=0 ") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1'  class='teacher reportselect batch7 inventory3 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
 $batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?><input type="hidden" name="batch_old[]" value="1" /></td>
                    <?php } } else { ?>
                    <?php if($info1000['en_rawmaterialbatch']==1 && ($grnn==1  || $info2000['batch_grnonly']==0) ) { ?>
                    <td><?php $pid =  $info2['id']; 
 if($info4000['en_allbatchdisplay']==0) { 
    $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid' && type_component=1   order by batch_code ") or die(mysqli_error($conn)); 
  } else { 
    $data4 = mysqli_query($conn,"SELECT batch_code, MIN(id) as id   from inventory_batch where active=1  && type_component=1 group by batch_code  order by batch_code ") or die(mysqli_error($conn)); 
   }
$ii=0;
echo "<select name='products_batch[]' tabindex='1'  class='teacher reportselect batch7 inventory3 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
 $batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?><input type="hidden" name="batch_old[]" value="0" /></td>
                    <?php } } ?>
                    <?php  if($info1000['en_expirydisplayc']==1  && $grnn==1) {  ?>
                    <td <?php if($return==1) { echo ' style=" display:none;"'; } ?>><input type="date"
                            name="products_expiry[]" <?php  if($info2['is_batch']==0) { echo 'readonly';  }?> value=""
                            tabindex="1" <?php if($return==0) { ?> required <?php } ?>
                            class="change8 form-control expiry7" id="<?php echo "expiry".$info2['id'];?>" /></td>
                    <?php } ?>

                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_packing[]" type="number" min="0.1" step="0.001" size="4" min="1"
                            class="edit-input change income_count totalorder" id="p<?php echo $info2['id'];?>"
                            tabindex="1" value="<?php echo $info2['packing'];?>" readonly="readonly" />
                    </td>


                    <?php if($info3000['en_posch']==1) { ?>
                    <td>
                        <input name="purchase_price[]" type="number" min="0" step="0.0001"
                            class="edit-input purchase-price" id="<?php echo "purchase_price".$info2['id'];?>"
                            tabindex="1" value="<?php echo $last_purchase_price;?>" readonly />
                    </td>
                    <?php } ?>
                    <td>
                        <?php
$data15 = mysqli_query($conn,"SELECT vendor_type from vendor where  id='$cid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$ttid=$info15['vendor_type'];
$ppid=$info2['id'];
 $data15 = mysqli_query($conn,"SELECT price from vendor_type_pricingc where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" required min="0" 
                            value="<?php echo $info15['price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100;
$discount4=$info200['discount4']/100; 
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3;
$discount4=1-$discount4;  
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
 $m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info200['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x;
    ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" required min="0" 
                            value="<?php echo $price;?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } else {  ?>
                        <?php if($info3000['en_crest']==1 || $info4000['limitvendor_material'] == 1){ ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" min="0" name="unitcos[]" type="number" required
                            value="<?php echo $materialrate;?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } else { ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" min="0" name="unitcos[]" step="0.001" type="number" required
                            value="<?php echo $info2['unit_cost'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } } ?>
                    
                    <input type="hidden" required step="0.0001" name="products_foc[]" value="0"  class="foc income_count" id="<?php echo "pfoc".$info2['id'];?>"  size="4"   />

<input type="hidden" name="discount5[]" value="0" id="<?php echo "pppl".$info2['id'];?>"  tabindex="1"  class="edit-input income_count"   size="4"   /> 


         

  <input name="tax_mrp[]" size="4" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "mrptax".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['tax_mrp'];?>" />
                        <?php
              if($info4000['separate_mrpcolumn']==0)
              {
              ?>
                        <input name="mrp_price[]" size="4" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "mrp".$info2['id'];?>" tabindex="1"
                            value="<?php if($mpp!='' && $mpp!=0) { echo $mpp;  } else { echo $info2['mrp_price']; } $mpp=''; ?>" />
                        <?php
              }
              ?>
                        <!-- <input name="new_rate[]" size="4"   type="hidden" class="new_rate" value="<?php echo $new_rate;?>"  /> -->
                    </td>
                    <?php if($info4000['separate_mrpcolumn']==1) { ?> <td>
                        <input name="mrp_price[]" size="4" type="number" required step='0.0001'
                            class="edit-input income_count totalorder" id="<?php echo "mrp".$info2['id'];?>"
                            tabindex="1"
                            value="<?php if($mpp!='' && $mpp!=0) { echo $mpp;  } else { echo $info2['mrp_price']; } $mpp=''; ?>" />
                    </td>
                    <?php }  //closepricing ?>




                    <td <?php  if($info2000['invoice_cartonrate']==0) { echo ' style=" display:none;"'; } ?>>
                        <select name='rate_in_carton[]' class='teacher income_count case2qty'
                            id="<?php echo "ric".$info2['id'];?>">
                            <option value='0'>Default</option>
                            <?php if($info4000['en_engineering']==0){  ?>
                            <option value='1'><?php echo $info1000['packing_label']; ?></option>
                            <?php } ?>
                            <option value='2'><?php echo $info1000['multi_unit_label']; ?></option>
                            <option value='3'><?php echo $info2000['customfield1_display'];  ?></option>
                        </select>
                    </td>
                    <?php if($info1000['vendor_discount1']==1) { 
 echo '<td >';
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from vb_discount where vid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from vendor_type_discount1c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($num_rows!=0) {
?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                        size="4" />
                    <?php }
else if($num_rows2!=0) {
?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info17['discount'];?>"
                        size="4" />
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info200['discount'];?>"
                        size="4" />
                    <?php } 
 else {  ?>
                    <input name="products_discount[]" type="number" step="0.0001"  class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } echo '</td>'; } else { ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['vendor_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from vendor_type_discount2c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } 
 if($info1000['vendor_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from vendor_type_discount4c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } 
 if($info1000['vendor_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from vendor_type_discount3c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" step="0.0001" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='') {?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount3'];?>" size="4" step="0.0001" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" step="0.0001" /></td>
                    <?php } } else {?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4"  />
                    <?php }
 if($info1000['vendor_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from vendor_type_schemec where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                            size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" /> <input name="products_pcs[]" type="text" size="4" min="1"
                            class="edit-input total_pcs" id="<?php echo "t".$info2['id'];?>" readonly="readonly" />
                    </td>
                 
<?php if(1==1){   ?>     
     <td  <?php if($info4000['display_taxamount']==0){ echo ' style="display:none;"';    }  ?> >
   <input name="display_totaltax2[]" type="text" class="income_count display_totaltax2" id="<?php echo "ppptttt".$info2['id'];?>"    value="0" size="4" readonly/>
</td>
<?php } ?>

                    <?php if($info1000['vendor_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from vendor_type_tax1c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($info2['tax_applied']!=-1 && $st==1) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>" value="<?php   echo $info2['tax_applied']; ?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
else if($info2000['en_maintaxc']==1) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($st==1) {  if($cfiler==1) { echo $info2000['filer_taxc']; } else { echo $info2000['nonfiler_taxc']; }  } else { echo 0; } ?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
else if($num_rows!=0) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td> <input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) {  echo $info2['tax_applied'];; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php } } else { ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" />
                    <?php } ?>
                    <td <?php if($info2000['invoice_cartonrate']==0) { echo ' style=" display:none;" '; } ?>><input
                            name="pipe[]" type="text" class="edit-input pipehide income_count" tabindex="1"
                            id="<?php echo "pipe".$info2['id'];?>" value="<?php  echo 0; ?>" size="4"
                            readonly="readonly" /></td>
                    <?php if($info1000['vendor_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from vendor_type_tax2c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied2']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['vendor_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from vendor_type_tax3c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php }  else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>

                     <?php if(1==1){   ?>     
     <td  <?php if($info4000['display_taxamount']==0){ echo ' style="display:none;"';    }  ?> >
   <input name="display_totaltax[]" type="text" class="income_count display_totaltax" id="<?php echo "ppptt".$info2['id'];?>"    value="0" size="4" readonly/>
</td>
<?php } ?> 

                    <td><input name="products_total[]" step="0.0001"  id="newtotal<?php echo $info2['id'];?>" type="number" size="5" min="0" 
                            class="tot<?php echo $info2['id'];?> ptotal sub_total readonly " tabindex="-1" onkeypress="return false;" /></td>
                    <td class="d-flex gap-2">
                        <?php if(1==1) { ?>
                            <input type="button" class="rounded-1 bg-info text-white border-0 p-1 edit receipt_edit_hide5" value="Edit" />
                            <input type="button" class="rounded-1 bg-success text-white border-0 p-1 save" value="Save" /><?php } ?><?php if(1==1) { ?>
                            <input type="button" class="rounded-1 bg-danger text-white border-0 p-1 delete receipt_delete_edit5" value="Delete" /><?php } ?></td>

                    
                </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php 
       if($info1000['open_ratecolumn']==1) { ?>
                $('.change15').focusout(function() {
                            $(".change15").removeClass("change15");
                            <?php } 
       else if($info1000['en_rawmaterialbatch']==1 && $grnn==1) {  ?>
                            $('.change7').focusout(function() {
                                        $(".change7").removeClass("change7");
                                        <?php } else if($info1000['en_warehouse']==1) {  ?>
                                        $('.change6').focusout(function() {
                                            $(".change6").removeClass("change6");
                                            <?php } else {  ?>
                                            $('.change5').focusout(function() {
                                                $(".change5").removeClass("change5");
                                                <?php }  ?>
                                                var $orginal = $(this).closest("tr");
                                                var $cloned = $orginal.clone();
                                                //get original selects into a jq object
                                                var $originalSelects = $orginal.find('select');
                                                $cloned.find('select').each(function(index, item) {
                                                    //set new select to value of old select
                                                    $(item).val($originalSelects.eq(index)
                                                        .val());
                                                });
                                                //get original textareas into a jq object
                                                var $originalTextareas = $orginal.find('textarea');
                                                $cloned.find('textarea').each(function(index, item) {
                                                    //set new textareas to value of old textareas
                                                    $(item).val($originalTextareas.eq(index)
                                                        .val());
                                                });
                                                $cloned.appendTo("#acart");
                                                $('.searchqty').attr('class',
                                                    "highlight income_count ");
                                                $("#searchbox").focus();
                                                $("#psearch").html('');
                                            });
                                        });
    </script>
    <script type="text/javascript">
    $('.batch7').on('change focusout ', function() {
        var a = this.id;
        a = a.replace(/\D/g, '');
        var batch = $(this).closest(".carttr").find(".batch7").val();
        if (batch != '') {
            var prd_id = $(this).closest(".carttr").find("#code" + a).val();
            var that = $(this);
            $.ajax({
                type: "POST",
                url: "../ajax/receipt-query2.php",
                data: {
                    batch9: batch,
                    prd_id7: prd_id
                },
                cache: false,
                dataType: 'html',
                success: function(html) {
                    that.closest(".carttr").find(".expiry7").val(html);
                }
            });
        }
    });
    $(document).ready(function() {

    // Initial setup
    $('.save').hide();
    $('.edit-input').attr("readonly", true);

    // Edit button
    $(document).on('click', '.edit', function () {
        var tr = $(this).closest('tr');

        tr.find('.edit').hide();
        tr.find('.save').show();
        tr.find('.edit-input').attr("readonly", false);
    });

    // Save button
    $(document).on('click', '.save', function () {
        var tr = $(this).closest('tr');

        tr.find('.save').hide();
        tr.find('.edit').show();
        tr.find('.edit-input').attr("readonly", true);
    });

    // Delete button
    $(document).on('click', '.delete', function () {
        $(this).closest('tr').remove();

        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function () {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);

        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function () {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);

        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function () {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);

        var n4 = $("#sub_total").val();
        var n5 = $("#paid_amount").val();
        var total = +n4;
        var pending = total - n5;

        $("#total_amount").val(total);
        $("#pending_amount").val(pending);
    });

});

    </script>

<?php  include('../functions/incomecount_function.php'); ?>

    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  }
// for finsih good item row 
else if(isset($_POST['pidi']))
{
$sid=test_input($_POST['pidi']);
$vid=test_input($_POST['vendorid']);
$return=test_input($_POST['return']);
$cid=test_input($_POST['vendorid']);
  $st=test_input($_POST['st']);
   $grnn=test_input($_POST['grn']);
$materialrate = mysqli_get_var("SELECT rate from vendor_item where vid='$vid' and prd_id='$sid'");
$cwarehouse = mysqli_get_var("Select inventory_warehouse from vendor where `id` = '$vid'");
 $cfiler = mysqli_get_var("Select filer from vendor where `id` = '$vid'");
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="25%"><?php echo $info1000['material_label']; ?></th>
                    <?php if($info2000['en_crest']!=0){ ?>
                    <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <div>QTA</div>
                    </th>
                    <?php  } ?>
                    <th>
                        <div><?php echo $info1000['multi_unit_labelp']; ?></div>
                    </th>
                    <?php  if($info2000['uom_display']==1) { ?> <th align="center"><?php echo $info2000['uom_label']; ?>
                    </th><?php } ?>
                    <th
                        <?php if($info1000['no_purchasepacking']==1   || $info2000['pcs_hidec']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['single_unit_label']; ?></div>
                    </th>
                    <th <?php if($info2000['en_customfield1c']==0) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info2000['customfield1c_display'];  ?></div>
                    </th>
                    <?php if($info1000['en_warehouse']==1) {  echo  '  <th ><div>WH </div></th> '; } ?>
                    <?php if($info1000['en_rawmaterialbatch']==1 && $grnn==1) {   echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; } ?>
                    <?php if($info1000['en_expirydisplayc']==1 && $return==0 && $grnn==1) {   echo  '  <th ><div>Expiry </div></th> '; } ?>
                    <th <?php if($info1000['no_purchasepacking']==1 ) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['packing_label']; ?></div>
                    </th>
                    <th>
                        <div><?php echo $info1000['price_label']; ?></div>
                    </th>
                    <?php  if($info2000['invoice_cartonrate']==1) {  ?>
                    <th>
                        <div>Rate Apply</div>
                    </th>
                    <?php } ?>
                    <?php if($info1000['vendor_discount1']==1) {  echo  '  <th ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_discount2']==1) {  echo  '  <th ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_discount4']==1) {  echo  '  <th ><div>'.$info1000['disc3_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_discount3']==1) {  echo  '  <th ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_scheme']==1) {  echo  '  <th ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                    <?php if($info1000['vendor_tax1']==1) {  echo  '  <th ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
                    <?php  if($info2000['invoice_cartonrate']==1) {  ?>
                    <th>
                        <div>Pipe Rate</div>
                    </th>
                    <?php } ?>
                    <?php if($info1000['vendor_tax2']==1) {  echo  '  <th ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
                    <?php if($info1000['vendor_tax3']==1) {  echo  '  <th ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
                    <th contenteditable="true" width="80">Total </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
    $data2 = mysqli_query($conn,"SELECT * from inventory where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr class="carttr">
                    <td><input type="hidden" name="products[]" class="singleitem" value="<?php echo $info2['id'];?>" />
                        <?php echo $info2['sku'].' '.$info2['name'];?>
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from purchasing_details sd, purchasing s  where sd.prd_id='$sid' AND s.type_component=1 AND sd.`order_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
      else if($info1000['en_lastprice']==2 ) {
       $data200 = mysqli_query($conn,"SELECT sd.* from purchasing_details sd, purchasing s  where sd.prd_id='$sid' AND s.type_component=1 AND sd.`order_id`=s.`id` AND s.vendor_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }  
         ?> <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <?php if($info2000['en_crest']!=0){ ?>
                    <td class="triggeravailable"
                        <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>><?php   
    $sid = $info2['id'];
    $sp = mysqli_get_var("SELECT id from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse ");
   $stocksingle = $info2['id'];
   if(1) { $a=' SUM(qty) '; } else { $a=' SUM(qty/packing) '; }
    $minus = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id && t.type=0 && w.deleted=0 AND w.type_component = 1 &&  `item_id` = '$stocksingle' &&  `warehouse_id` = '$sp' "); 
    if($info1000['inventory_limit']==1) {
      $minus2 = mysqli_get_var("SELECT $a AS sqty FROM so_details WHERE warehouse_id='$sp' && prd_id='$stocksingle' && order_id IN (SELECT id FROM so WHERE completed=0 AND type_component = 1)  "); 
    }else{
      $minus2 = 0;
    }
    $plus = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id && t.type=1 && w.deleted=0 AND w.type_component = 1 &&  `item_id` = '$stocksingle' &&  `warehouse_id` = '$sp' "); 
    $minus3 = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id AND w.type_component = 1 && w.deleted=0 && (w.tran_type=1 || w.tran_type=21) && verified_by=0 && t.type=1 &&  `item_id` = '$stocksingle' &&  `warehouse_id` = '$sp' ");
    $product_qta=$plus-$minus-$minus2-$minus3;
    if($info2000['qta_inpacking']==0) {
      echo number_format($product_qta, 2);
    }else{
      $packing5 = mysqli_get_var("SELECT packing FROM component WHERE id = '$stocksingle' ");
      echo number_format($product_qta/$packing5, 2);
    }
    /*$transfer_in = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=1 $wlimit_warehouse8   ");
    $transfer_out = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=1 $wlimit_warehouse8  ");
    echo  $product_qta = $transfer_in-$transfer_out;*/
  ?></td>
                    <?php } ?>
                    <td>
                        <input type="text"
                            class="highlight <?php if($info1000['no_purchasepacking']==1) echo ' change5';  ?>  searchp income_count packing"
                            size="4" min="1" id="ctn<?php echo $info2['id'];?>" tabindex="1" />
                    </td>
                    <?php  if($info2000['uom_display']==1) { ?>
                    <td>
                        <?php if($info3000['en_uom_selection'] == 1){ ?>
                        <select class="form-control reportselect" name="uom[]" required="">
                            <?php 
          $data4 = mysqli_query($conn, "SELECT * FROM component_unit") or die(mysqli_error($conn)); 
          while($info4 = mysqli_fetch_array($data4)){
            ?><option value="<?php echo $info4['id'] ?>"
                                <?php if($info2['unit'] == $info4['id']){ echo "selected"; } ?>>
                                <?php echo $info4['name']; ?></option><?php
          }
          ?>
                        </select>
                        <?php } else{ ?>
                        <input type="hidden" name="uom[]" value="<?php echo $info2['unit'];  ?>">
                        <?php echo mysqli_get_var("SELECT name FROM component_unit WHERE id = '".$info2['unit']."' "); ?>
                        <?php } ?>
                    </td>
                    <?php } else{ ?>
                    <input type="hidden" name="uom[]" value="<?php echo $info2['unit'];  ?>">
                    <?php } ?>
                    <td
                        <?php if($info1000['no_purchasepacking']==1   || $info2000['pcs_hidec']==1) echo ' style="display:none;"';  ?>>
                        <!--<input type="hidden" name="<?php// echo $info2['id'];?>_packing" id="p<?php// echo $info2['id'];?>" class="searchqty income_count form-control" tabindex="1"  value="<?php// echo $info2['packing'];?>"  /> -->
                        <input type="text" value="0" size="4" min="1"
                            class="searchqty change change5 income_count totalorder" tabindex="1"
                            id="pcs<?php echo $info2['id'];?>" />
                    </td>
                    <td <?php if($info2000['en_customfield1c']==0) echo ' style="display:none;"';  ?>><input
                            name="custom_field1[]" id="customfield<?php echo $info2['id'];?>" type="text" tabindex="1"
                            class="form-control  <?php if($info3000['ctn_customfieldrate']==0) { ?>income_count<?php } ?>  customfield1" /> </td>
                    <td <?php if($info1000['en_warehouse']!=1) { ?>style="display: none;" <?php } ?>><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse  ") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' tabindex='1' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
 if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
 }
echo "</select>";
?></td>
                    <?php if($return==1) { if($info1000['en_rawmaterialbatch']==1 && $grnn==1) { ?>
                    <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'   && type_component=0 ") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1'  class='teacher reportselect batch7 inventory3 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
 $batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?><input type="hidden" name="batch_old[]" value="1" /></td>
                    <?php } } else { ?>
                    <?php if($info1000['en_rawmaterialbatch']==1 && $grnn==1) { ?>
                    <td>
                        <div class="batchdiv"><input type="text" name="products_batch[]"
                                <?php  if($info2['is_batch']==0) { echo 'readonly';  }?>
                                value="<?php  if($info2['is_batch']==0) { echo 'No Batch';  }?>" tabindex="1"
                                class="change7 income_count batch7 form-control"
                                maxlength="<?php echo $info2000['max_batch_length']; ?>" required
                                id="<?php echo "batch".$info2['id'];?>" /></div> <input type="hidden" name="batch_old[]"
                            value="0" />
                    </td>
                    <?php } } ?>
                    <?php  if($info1000['en_expirydisplayc']==1  && $grnn==1) {  ?>
                    <td <?php if($return==1) { echo ' style=" display:none;"'; } ?>><input type="date"
                            name="products_expiry[]" <?php  if($info2['is_batch']==0) { echo 'readonly';  }?> value=""
                            tabindex="1" <?php if($return==0) { ?> required <?php } ?>
                            class="change8 form-control expiry7" id="<?php echo "expiry".$info2['id'];?>" /></td>
                    <?php } ?>

                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_packing[]" type="number" min="0.1" step="0.001" size="4" min="1"
                            class="edit-input change income_count totalorder" id="p<?php echo $info2['id'];?>"
                            tabindex="1" value="<?php echo $info2['packing'];?>" readonly="readonly" />
                    </td>
                    <td>
                        <?php
$data15 = mysqli_query($conn,"SELECT vendor_type from vendor where  id='$cid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$ttid=$info15['vendor_type'];
$ppid=$info2['id'];
 $data15 = mysqli_query($conn,"SELECT price from vendor_type_pricingc where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" required min="0"
                            value="<?php echo $info15['price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100;
$discount4=$info200['discount4']/100; 
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3;
$discount4=1-$discount4;  
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
 $m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info200['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x;
    ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" required min="0" 
                            value="<?php echo $price;?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } else {  ?>
                        <?php if($info3000['en_crest']==1){ ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" required min="0" 
                            value="<?php echo $materialrate;?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } else { ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" required min="0" 
                            value="<?php echo $info2['unit_cost'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } } ?>
                    </td>
                    <td <?php  if($info2000['invoice_cartonrate']==0) { echo ' style=" display:none;"'; } ?>>
                        <select name='rate_in_carton[]' class='teacher income_count case2qty'
                            id="<?php echo "ric".$info2['id'];?>">
                            <option value='0'>Default</option>
                            <?php if($info4000['en_engineering']==0){ ?>
                            <option value='1'><?php echo $info1000['packing_label']; ?></option>
                            <?php } ?>
                            <option value='2'><?php echo $info1000['multi_unit_label']; ?></option>
                            <option value='3'><?php echo $info2000['customfield1_display'];  ?></option>
                        </select>
                    </td>
                    <?php if($info1000['vendor_discount1']==1) { 
 echo '<td >';
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from vb_discount where vid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from vendor_type_discount1c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($num_rows!=0) {
?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                        size="4" />
                    <?php }
else if($num_rows2!=0) {
?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info17['discount'];?>"
                        size="4" />
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info200['discount'];?>"
                        size="4" />
                    <?php } 
 else {  ?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } echo '</td>'; } else { ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['vendor_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from vendor_type_discount2c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } 
 if($info1000['vendor_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from vendor_type_discount4c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } 
 if($info1000['vendor_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from vendor_type_discount3c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" step="0.0001"  /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='') {?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount3'];?>" size="4" step="0.0001" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" step="0.0001" /></td>
                    <?php } } else {?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['vendor_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from vendor_type_schemec where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                            size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" /> <input name="products_pcs[]" type="text" size="4" min="1"
                            class="edit-input total_pcs" id="<?php echo "t".$info2['id'];?>" readonly="readonly" />
                    </td>
                    <?php if($info1000['vendor_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from vendor_type_tax1c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($info2['tax_applied']!=-1 && $st==1) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>" value="<?php   echo $info2['tax_applied']; ?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
else if($info2000['en_maintaxc']==1) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($st==1) {  if($cfiler==1) { echo $info2000['filer_taxc']; } else { echo $info2000['nonfiler_taxc']; }  } else { echo 0; } ?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
else if($num_rows!=0) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td> <input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) {  echo $info2['tax_applied'];; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php } } else { ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" />
                    <?php } ?>
                    <td <?php if($info2000['invoice_cartonrate']==0) { echo ' style=" display:none;" '; } ?>><input
                            name="pipe[]" type="text" class="edit-input pipehide income_count" tabindex="1"
                            id="<?php echo "pipe".$info2['id'];?>" value="<?php  echo 0; ?>" size="4"
                            readonly="readonly" /></td>
                    <?php if($info1000['vendor_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from vendor_type_tax2c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied2']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['vendor_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from vendor_type_tax3c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php }  else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td><input name="products_total[]" step="0.0001"  id="newtotal<?php echo $info2['id'];?>" type="number" size="5" min="0" 
                            class="tot<?php echo $info2['id'];?> ptotal sub_total readonly " tabindex="-1" onkeypress="return false;" /></td>
                <td class="d-flex gap-2">
                        <?php if(1==1) { ?>
                            <input type="button" class="rounded-1 bg-info text-white border-0 p-1 edit receipt_edit_hide5" value="Edit" />
                            <input type="button" class="rounded-1 bg-success text-white border-0 p-1 save" value="Save" /><?php } ?><?php if(1==1) { ?>
                            <input type="button" class="rounded-1 bg-danger text-white border-0 p-1 delete receipt_delete_edit5" value="Delete" /><?php } ?></td>

                    
                </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php 
       if($info1000['open_ratecolumn']==1) { ?>
                $('.change15').focusout(function() {
                            $(".change15").removeClass("change15");
                            <?php } 
       else if($info1000['en_rawmaterialbatch']==1 && $grnn==1) {  ?>
                            $('.change7').focusout(function() {
                                        $(".change7").removeClass("change7");
                                        <?php } else if($info1000['en_warehouse']==1) {  ?>
                                        $('.change6').focusout(function() {
                                            $(".change6").removeClass("change6");
                                            <?php } else {  ?>
                                            $('.change5').focusout(function() {
                                                $(".change5").removeClass("change5");
                                                <?php }  ?>
                                                var $orginal = $(this).closest("tr");
                                                var $cloned = $orginal.clone();
                                                //get original selects into a jq object
                                                var $originalSelects = $orginal.find('select');
                                                $cloned.find('select').each(function(index, item) {
                                                    //set new select to value of old select
                                                    $(item).val($originalSelects.eq(index)
                                                        .val());
                                                });
                                                //get original textareas into a jq object
                                                var $originalTextareas = $orginal.find('textarea');
                                                $cloned.find('textarea').each(function(index, item) {
                                                    //set new textareas to value of old textareas
                                                    $(item).val($originalTextareas.eq(index)
                                                        .val());
                                                });
                                                $cloned.appendTo("#acart");
                                                $('.searchqty').attr('class',
                                                    "highlight income_count ");
                                                $("#searchbox").focus();
                                                $("#psearch").html('');
                                            });
                                        });
    </script>
    <script type="text/javascript">
    $('.batch7').on('change focusout ', function() {
        var a = this.id;
        a = a.replace(/\D/g, '');
        var batch = $(this).closest(".carttr").find(".batch7").val();
        if (batch != '') {
            var prd_id = $(this).closest(".carttr").find("#code" + a).val();
            var that = $(this);
            $.ajax({
                type: "POST",
                url: "../ajax/receipt-query2.php",
                data: {
                    batch9: batch,
                    prd_id7: prd_id
                },
                cache: false,
                dataType: 'html',
                success: function(html) {
                    that.closest(".carttr").find(".expiry7").val(html);
                }
            });
        }
    });
    $(document).ready(function() {
        $('.save').hide();
        $('.edit-input').attr("readonly", true);
        $(".edit").on('click', function() {
            $(this).closest('tr').find('.edit').hide();
            $(this).closest('tr').find('.save').show();
            $(this).closest('tr').find('.edit-input').attr("readonly", false);
        });
        $(".save").on('click', function() {
            $(this).closest('tr').find('.save').hide();
            $(this).closest('tr').find('.edit').show();
            $(this).closest('tr').find('.edit-input').attr("readonly", true);
        });
        $(".delete").on('click', function() {
            $(this).closest('tr').remove();
            //Total Quantity Sum  (Pcs)
            var sum = 0;
            $(".total_pcs").each(function() {
                sum += parseFloat($(this).val()) || 0;
            });
            $("#total_pcs").val(sum);
            //Total Quantity Sum  (Carton)
            var sum3 = 0;
            $(".packing").each(function() {
                sum3 += parseFloat($(this).val()) || 0;
            });
            $("#packing").val(sum3);
            //Total Amount Sum  (Sub Total)
            var sum2 = 0;
            $(".sub_total").each(function() {
                sum2 += parseFloat($(this).val()) || 0;
            });
            $("#sub_total").val(sum2);
            var n4 = $("#sub_total").val();
            var n5 = $("#paid_amount").val();
            var n6 = $("#pending_amount").val();
            var total = +n4;
            var pending = +total - n5;
            $("#total_amount").val(total);
            $("#pending_amount").val(pending);
        });
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  }
  // end for finish good item
else if(isset($_POST['poid']))
{
$sid=test_input($_POST['poid']);
$vid=test_input($_POST['vendorid']);
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="20%">
                        <div><?php echo $info1000['product_label']; ?></div>
                    </th>
                    <th>
                        <div><?php echo $info1000['multi_unit_labelp']; ?></div>
                    </th>
                    <?php  if($info2000['uom_display']==1) { ?> <th align="center"><?php echo $info2000['uom_label']; ?>
                    </th><?php } ?>
                    <?php if( $info4000['itemmulti_unit']==1) { 
                    echo '<th ><div>Unit</div></th>
                    <th style="display:none;" ><div>Unit Rate</div></th>'; 
                } ?>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['single_unit_label']; ?></div>
                    </th>

                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>  ><div><?php echo $info1000['single_unit_label']; ?></div></th>
                  
                    <th <?php if($info2000['en_customfield1c']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info2000['customfield1c_display'];  ?></div></th>
                            
  <th <?php if($info4000['en_customfield2c']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info4000['customfield2c_label'];  ?></div></th>
  <th <?php if($info4000['en_customfield3c']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info4000['customfield3c_label'];  ?></div></th>                        
<th <?php if($info3000['en_customfield4c']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info3000['customfield4c_label'];  ?></div></th>
                <th <?php if($info3000['en_customfield5c']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info3000['customfield5c_label'];  ?></div></th>
                <th <?php if($info3000['en_customfield6c']==0) echo ' style="display:none;"';  ?>  class="recurringhide" ><div><?php echo $info3000['customfield6c_label'];  ?></div></th>  

                    <?php if($info1000['en_warehouse']==1) {  echo  '  <th ><div>WH </div></th> '; } ?>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['packing_label']; ?></div>
                    </th>
                    <th style="display:none;">Old Price</th>
                    <th style="display:none;">
                        <div><?php echo $info1000['price_label']; ?></div>
                    </th>
                    <?php if($info1000['customer_discount1']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount2']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount3']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_scheme']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                    <?php if($info1000['customer_tax1']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax2']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax3']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
                    <th contenteditable="true" width="80" style="display:none;">Total </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
 $data2 = mysqli_query($conn,"SELECT * from inventory where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr class="carttr">
                    <td><input type="hidden" class="products" name="products[]" value="<?php echo $info2['id'];?>" />
                        <?php echo $info2['sku'].' '.$info2['name'];?>
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."><?php echo $details2 ?></textarea>
                        </div>
                    </td>
                    <td>
                        <input type="text"
                            class="highlight <?php if($info1000['no_purchasepacking']==1) echo ' change5';  ?>  searchp income_count form-control packing"
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" />
                    </td>
                    <?php  if($info2000['uom_display']==1) { ?>
                    <td>
                        <?php if($info3000['en_uom_selection'] == 1){ ?>
                        <select class="form-control reportselect" name="uom[]" required="">
                            <?php 
          $data4 = mysqli_query($conn, "SELECT * FROM product_unit") or die(mysqli_error($conn)); 
          while($info4 = mysqli_fetch_array($data4)){
            ?><option value="<?php echo $info4['id'] ?>"
                                <?php if($info2['uom'] == $info4['id']){ echo "selected"; } ?>>
                                <?php echo $info4['name']; ?></option><?php
          }
          ?>
                        </select>
                        <?php } else{ ?>
                        <input type="hidden" name="uom[]" value="<?php echo $info2['unit'];  ?>">
                        <?php echo mysqli_get_var("SELECT name FROM product_unit WHERE id = '".$info2['unit']."' "); ?>
                        <?php } ?>
                    </td>
                    <?php } else{ ?>
                    <input type="hidden" name="uom[]" value="<?php echo $info2['unit'];  ?>">
                    <?php } ?>
                    <?php if($info4000['itemmulti_unit']==1){ ?>
                    <td>
                        <input name="prd_hidden[]" type="hidden" class="prd_hidden" value="<?php echo $sid;?>" />
                        <input name="packing_hidden[]" type="hidden" class="packing_hidden"
                            value="<?php echo $info2['packing'];?>" />
                        <?php 
            $single_unit = mysqli_get_var("SELECT unit FROM inventory WHERE id='".$sid."' ");
            $data4 = mysqli_query($conn,"SELECT * FROM product_unit WHERE id IN (SELECT unit FROM multiple_product_unit WHERE pid = '".$sid."' )  ") or die(mysqli_error($conn)); 
            echo "<select name='munit[]'  required class=' munit form-control'   >";
            //echo "<option value='0' >Select Product Unit</option>";
            while($info4 = mysqli_fetch_array( $data4 )){ 
                $selected = '';
                if($info2['dunit'] == $info4['id'])
                    $selected = 'selected';
                echo "<option value='".$info4['id']."' $selected >".$info4['name']."</option>";
            }
            echo "</select>";
            ?>
                    </td>
                    <?php } ?>

                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <!-- <input type="hidden" name="products_packing[]" id="p<?php// echo $info2['id'];?>" class="searchqty income_count form-control" tabindex="1"  value=" <?php// echo $info2['packing'];?>"  /> -->
                        <input type="text" value="0"
                            class="searchqty form-control change change5 income_count totalorder" tabindex="1"
                            id="pcs<?php echo $info2['id'];?>" />
                    </td>

                    <td <?php if(($info2000['en_customfield1c']==0  && $type_component != 3)  ) {
    echo ' style="display:none;"';
} ?> class="recurringhide">
<input 
    name="custom_field1[]" 
    <?php if ($info2000['en_benin'] == 1) { echo 'readonly'; } ?>
    id="customfield<?php echo $info2['id']; ?>" 
    <?php echo $readonly; ?> 
    type="text" 
    tabindex="1"
    class="form-control customfield1 mycf teacher<?php if ($info3000['en_hapaperhub'] == 0) { echo ' income_count'; } ?>" 
    <?php if ($info3000['en_hapaperhub'] == 1) { echo 'style="max-width: 200px !important; width: 200px !important;"'; } ?> 
    value="<?php echo $value_size; ?>" 
/>
 </td>
                    <td <?php if($info4000['en_customfield2c']==0  && $type_component != 3) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input name="custom_field2[]" type="text" tabindex="1"
                            class="form-control customfield2 income_count" id="<?php echo "customfields".$info2['id'];?>" 
                            value="<?php echo $value_color ?>" /> </td>
                    <td <?php if($info4000['en_customfield3c']==0  && $type_component != 3) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input name="custom_field3[]" type="text" tabindex="1"
                            class="form-control customfield3 income_count" id="<?php echo "customfields".$info2['id'];?>" /> </td>
                             <td <?php if($info3000['en_customfield4c']==0  && $type_component != 3) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input name="custom_field4[]" type="text" tabindex="1"
                            class="form-control customfield4 income_count" id="<?php echo "customfields".$info2['id'];?>" /> </td>
                             <td <?php if($info3000['en_customfield5c']==0  && $type_component != 3) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input name="custom_field5[]" type="text" tabindex="1"
                            class="form-control customfield5 income_count" id="<?php echo "customfields".$info2['id'];?>" /> </td>
                              <td <?php if($info3000['en_customfield6c']==0  && $type_component != 3) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input name="custom_field6[]" type="text" tabindex="1"
                            class="form-control customfield6 income_count" id="<?php echo "customfields".$info2['id'];?>" /> </td>

                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse  ") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' class='teacher warehouse change6' tabindex='1'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>

                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_packing[]" type="number" min="0.1" step="0.001"
                            class="new_packing form-control edit-input change income_count totalorder"
                            id="p<?php echo $info2['id'];?>" tabindex="1" value="<?php echo $info2['packing'];?>"
                            readonly="readonly" />
                    </td>
                    <td style="display:none;"><?php // echo $info2['unit_cost'];?></td>
                    <td style="display:none;">
                        <input id="pp<?php echo $info2['id'];?>" name="unitcos[]" 
                            value="<?php echo $info2['unit_cost'];?>" class=" <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> income_count  form-control"
                            type="hidden" />
                    </td>
                    <td style="display:none;"><?php
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from vb_discount where vid='$vid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input name="products_discount[]" type="hidden"
                            class="form-control income_count edit-input totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" />
                        <?php } else {  ?>
                        <input name="products_discount[]" type="hidden"
                            class="form-control income_count edit-input totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" />
                        <?php } ?>
                    </td>
                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_pcs[]" type="text" class="form-control edit-input total_pcs"
                            id="<?php echo "t".$info2['id'];?>" readonly="readonly" /></td>
                    <td style="display:none;"><input name="products_total[]" step="0.0001"  id="newtotal<?php echo $info2['id'];?>" type="hidden"
                            class="tot<?php echo $info2['id'];?> ptotal form-control sub_total" tabindex="-1"
                            readonly /></td>

                    <td class="d-flex gap-2">
                        <?php if(1==1) { ?>
                            <input type="button" class="rounded-1 bg-info text-white border-0 p-1 edit receipt_edit_hide5" value="Edit" />
                            <input type="button" class="rounded-1 bg-success text-white border-0 p-1 save" value="Save" /><?php } ?><?php if(1==1) { ?>
                            <input type="button" class="rounded-1 bg-danger text-white border-0 p-1 delete receipt_delete_edit5" value="Delete" /><?php } ?></td>

                    
                </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php  if($info1000['en_warehouse']==1) {  ?>
                $('.change6').focusout(function() {
                    $(".change6").removeClass("change6");
                    <?php } else {  ?>
                    $('.change5').focusout(function() {
                        $(".change5").removeClass("change5");
                        <?php }  ?>
                        var $orginal = $(this).closest("tr");
                        var $cloned = $orginal.clone();
                        //get original selects into a jq object
                        var $originalSelects = $orginal.find('select');
                        $cloned.find('select').each(function(index, item) {
                            //set new select to value of old select
                            $(item).val($originalSelects.eq(index).val());
                        });
                        //get original textareas into a jq object
                        var $originalTextareas = $orginal.find('textarea');
                        $cloned.find('textarea').each(function(index, item) {
                            //set new textareas to value of old textareas
                            $(item).val($originalTextareas.eq(index).val());
                        });
                        $cloned.appendTo("#acart");
                        $('.searchqty').attr('class', "highlight income_count form-control");
                        $("#searchbox").focus();
                        $("#psearch").html('');
                    });
                });
    </script>
    <script type="text/javascript">
    $(document).ready(function() {
        $('.save').hide();
        $('.edit-input').attr("readonly", true);
        $(".edit").on('click', function() {
            $(this).closest('tr').find('.edit').hide();
            $(this).closest('tr').find('.save').show();
            $(this).closest('tr').find('.edit-input').attr("readonly", false);
        });
        $(".save").on('click', function() {
            $(this).closest('tr').find('.save').hide();
            $(this).closest('tr').find('.edit').show();
            $(this).closest('tr').find('.edit-input').attr("readonly", true);
        });
        $(".delete").on('click', function() {
            $(this).closest('tr').remove();
            //Total Quantity Sum  (Pcs)
            var sum = 0;
            $(".total_pcs").each(function() {
                sum += parseFloat($(this).val()) || 0;
            });
            $("#total_pcs").val(sum);
            //Total Quantity Sum  (Carton)
            var sum3 = 0;
            $(".packing").each(function() {
                sum3 += parseFloat($(this).val()) || 0;
            });
            $("#packing").val(sum3);
            //Total Amount Sum  (Sub Total)
            var sum2 = 0;
            $(".sub_total").each(function() {
                sum2 += parseFloat($(this).val()) || 0;
            });
            $("#sub_total").val(sum2);
            var n4 = $("#sub_total").val();
            var n5 = $("#paid_amount").val();
            var n6 = $("#pending_amount").val();
            var n7 = $("#shipping").val();
            var n8 = $("#discount").val();
            var n10 = $("#tax").val();
            var result = +n4;
            <?php if ( $info1000['en_discount']==1) { ?>
            n8 = (+n8 * 1) / 100;
            n8 = (n8 * 1) * result;
            result = +result - n8;
            <?php } ?>
            <?php if($info2000['rice_discount']==1) { ?>
            $(".drice").each(function() {
                var damount = $(this).find('.rice_discount_value').val();
                var dless = $(this).find('.rice_type').val();
                var dpercent = $(this).find('.rice_percent').val();
                var specialclass = $(this).find('.specialclass').val();
                var specialclass2 = $(this).find('.specialclass2').val();
                var pack22 = $('#packing').val();
                var broker_id = $('#broker_id').val();
                var customfield1 = $('.customfield1').val();
                var sub_total = $('.sub_total').val();
                if (broker_id != '0') {
                    if (specialclass == 'noimpact' || specialclass ==
                        'trade_no_impact') {} else if (specialclass != 'brokery_rs' &&
                        specialclass !=
                        'brokery_percentage') {
                        if (dless == 1) {
                            if (dpercent == 1) {
                                damount = (+100 - +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result - +damount;
                            }
                        } else if (dless == 0) {
                            if (dpercent == 1) {
                                damount = (+100 + +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result + +damount;
                            }
                        }
                    }
                } else if (broker_id == '0') {
                    if (specialclass == 'noimpact' || specialclass ==
                        'trade_no_impact') {} else if (specialclass == 'brokery_rs') {
                        damount = damount * customfield1;
                        if (dless == 1) {
                            result = +result - +damount;
                        } else if (dless == 0) {
                            result = +result + +damount;
                        }
                    } else if (specialclass == 'brokery_percentage') {
                        damount = (damount / 100) * sub_total;
                        if (dless == 1) {
                            result = +result - +damount;
                        } else if (dless == 0) {
                            result = +result + +damount;
                        }
                    } else {
                        if (dless == 1) {
                            if (dpercent == 1) {
                                damount = (+100 - +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result - +damount;
                            }
                        } else if (dless == 0) {
                            if (dpercent == 1) {
                                damount = (+100 + +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result + +damount;
                            }
                        }
                    }
                }
            });
            <?php } ?>
            <?php if ($info1000['en_tax']==1) { ?>
            var percent = (result * 1) / 100;
            percent = (percent * 1) * n10;
            result = +result + +percent;
            <?php } ?>
            <?php if ($info1000['en_shipping']==1) { ?>
            var result = +result + +n7;
            <?php } ?>
            result = Math.round(result);
            var pending = +result - n5;
            $("#total_amount").val(result);
            $("#pending_amount").val(pending);
        });
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  }
else if(isset($_POST['prid']))
{
$sid=test_input($_POST['prid']);
$vid=test_input($_POST['vendorid']);
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="20%">
                        <div><?php echo $info1000['product_label']; ?></div>
                    </th>
                    <th>
                        <div><?php echo $info1000['multi_unit_labelp']; ?></div>
                    </th>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['single_unit_label']; ?></div>
                    </th>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['packing_label']; ?></div>
                    </th>
                    <th style="display:none;">Old Price</th>
                    <th style="display:none;">
                        <div><?php echo $info1000['price_label']; ?></div>
                    </th>
                    <?php if($info1000['customer_discount1']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount2']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount3']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_scheme']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                    <?php if($info1000['customer_tax1']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax2']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax3']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
                    <th contenteditable="true" width="80" style="display:none;">Total </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
 $data2 = mysqli_query($conn,"SELECT * from inventory where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr class="carttr">
                    <td><input type="hidden" name="products[]" value="<?php echo $info2['id'];?>" />
                        <?php echo $info2['sku'].' '.$info2['name'];?>
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                    </td>
                    <td>
                        <input type="text"
                            class="highlight <?php if($info1000['no_purchasepacking']==1) echo ' change5';  ?>  searchp income_count form-control packing"
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" />
                    </td>

                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <!-- <input type="hidden" name="products_packing[]" id="p<?php// echo $info2['id'];?>" class="searchqty income_count form-control" tabindex="1"  value=" <?php// echo $info2['packing'];?>"  /> -->
                        <input type="text" value="0"
                            class="searchqty form-control change change5 income_count totalorder" tabindex="1"
                            id="pcs<?php echo $info2['id'];?>" />
                    </td>

                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_packing[]" type="number" min="0.1" step="0.001"
                            class="form-control edit-input change income_count totalorder"
                            id="p<?php echo $info2['id'];?>" tabindex="1" value="<?php echo $info2['packing'];?>"
                            readonly="readonly" />
                    </td>
                    <td style="display:none;"><?php // echo $info2['unit_cost'];?></td>
                    <td style="display:none;">
                        <input id="pp<?php echo $info2['id'];?>" name="unitcos[]"
                            value="<?php echo $info2['unit_cost'];?>" class="income_count <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> form-control"
                            type="hidden" />
                    </td>
                    <td style="display:none;"><?php
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from vb_discount where vid='$vid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input name="products_discount[]" type="hidden"
                            class="form-control income_count edit-input totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" />
                        <?php } else {  ?>
                        <input name="products_discount[]" type="hidden"
                            class="form-control income_count edit-input totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" />
                        <?php } ?>
                    </td>
                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_pcs[]" type="text" class="form-control edit-input total_pcs"
                            id="<?php echo "t".$info2['id'];?>" readonly="readonly" /></td>
                    <td style="display:none;"><input name="products_total[]" id="newtotal<?php echo $info2['id'];?>" type="hidden"
                            class="tot<?php echo $info2['id'];?> ptotal form-control sub_total" tabindex="-1"
                            readonly /></td>
                    <td class="d-flex gap-2">
                        <?php if(1==1) { ?>
                            <input type="button" class="rounded-1 bg-info text-white border-0 p-1 edit receipt_edit_hide5" value="Edit" />
                            <input type="button" class="rounded-1 bg-success text-white border-0 p-1 save" value="Save" /><?php } ?><?php if(1==1) { ?>
                            <input type="button" class="rounded-1 bg-danger text-white border-0 p-1 delete receipt_delete_edit5" value="Delete" /><?php } ?></td>

                    
                </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
        $('.change5').focusout(function() {
            $(".change5").removeClass("change5");
            var $orginal = $(this).closest("tr");
            var $cloned = $orginal.clone();
            //get original selects into a jq object
            var $originalSelects = $orginal.find('select');
            $cloned.find('select').each(function(index, item) {
                //set new select to value of old select
                $(item).val($originalSelects.eq(index).val());
            });
            //get original textareas into a jq object
            var $originalTextareas = $orginal.find('textarea');
            $cloned.find('textarea').each(function(index, item) {
                //set new textareas to value of old textareas
                $(item).val($originalTextareas.eq(index).val());
            });
            $cloned.appendTo("#acart");
            $('.searchqty').attr('class', "highlight income_count form-control");
            $("#searchbox").focus();
            $("#psearch").html('');
        });
    });
    </script>
    <script type="text/javascript">
    $(document).ready(function() {
        $('.save').hide();
        $('.edit-input').attr("readonly", true);
        $(".edit").on('click', function() {
            $(this).closest('tr').find('.edit').hide();
            $(this).closest('tr').find('.save').show();
            $(this).closest('tr').find('.edit-input').attr("readonly", false);
        });
        $(".save").on('click', function() {
            $(this).closest('tr').find('.save').hide();
            $(this).closest('tr').find('.edit').show();
            $(this).closest('tr').find('.edit-input').attr("readonly", true);
        });
        $(".delete").on('click', function() {
            $(this).closest('tr').remove();
            //Total Quantity Sum  (Pcs)
            var sum = 0;
            $(".total_pcs").each(function() {
                sum += parseFloat($(this).val()) || 0;
            });
            $("#total_pcs").val(sum);
            //Total Quantity Sum  (Carton)
            var sum3 = 0;
            $(".packing").each(function() {
                sum3 += parseFloat($(this).val()) || 0;
            });
            $("#packing").val(sum3);
            //Total Amount Sum  (Sub Total)
            var sum2 = 0;
            $(".sub_total").each(function() {
                sum2 += parseFloat($(this).val()) || 0;
            });
            $("#sub_total").val(sum2);
            var n4 = $("#sub_total").val();
            var n5 = $("#paid_amount").val();
            var n6 = $("#pending_amount").val();
            var n7 = $("#shipping").val();
            var n8 = $("#discount").val();
            var n10 = $("#tax").val();
            var result = +n4;
            <?php if ( $info1000['en_discount']==1) { ?>
            n8 = (+n8 * 1) / 100;
            n8 = (n8 * 1) * result;
            result = +result - n8;
            <?php } ?>
            <?php if($info2000['rice_discount']==1) { ?>
            $(".drice").each(function() {
                var damount = $(this).find('.rice_discount_value').val();
                var dless = $(this).find('.rice_type').val();
                var dpercent = $(this).find('.rice_percent').val();
                var specialclass = $(this).find('.specialclass').val();
                var specialclass2 = $(this).find('.specialclass2').val();
                var pack22 = $('#packing').val();
                var broker_id = $('#broker_id').val();
                var customfield1 = $('.customfield1').val();
                var sub_total = $('.sub_total').val();
                if (broker_id != '0') {
                    if (specialclass == 'noimpact' || specialclass ==
                        'trade_no_impact') {} else if (specialclass != 'brokery_rs' &&
                        specialclass !=
                        'brokery_percentage') {
                        if (dless == 1) {
                            if (dpercent == 1) {
                                damount = (+100 - +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result - +damount;
                            }
                        } else if (dless == 0) {
                            if (dpercent == 1) {
                                damount = (+100 + +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result + +damount;
                            }
                        }
                    }
                } else if (broker_id == '0') {
                    if (specialclass == 'noimpact' || specialclass ==
                        'trade_no_impact') {} else if (specialclass == 'brokery_rs') {
                        damount = damount * customfield1;
                        if (dless == 1) {
                            result = +result - +damount;
                        } else if (dless == 0) {
                            result = +result + +damount;
                        }
                    } else if (specialclass == 'brokery_percentage') {
                        damount = (damount / 100) * sub_total;
                        if (dless == 1) {
                            result = +result - +damount;
                        } else if (dless == 0) {
                            result = +result + +damount;
                        }
                    } else {
                        if (dless == 1) {
                            if (dpercent == 1) {
                                damount = (+100 - +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result - +damount;
                            }
                        } else if (dless == 0) {
                            if (dpercent == 1) {
                                damount = (+100 + +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result + +damount;
                            }
                        }
                    }
                }
            });
            <?php } ?>
            <?php if ($info1000['en_tax']==1) { ?>
            var percent = (result * 1) / 100;
            percent = (percent * 1) * n10;
            result = +result + +percent;
            <?php } ?>
            <?php if ($info1000['en_shipping']==1) { ?>
            var result = +result + +n7;
            <?php } ?>
            result = Math.round(result);
            var pending = +result - n5;
            $("#total_amount").val(result);
            $("#pending_amount").val(pending);
        });
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  }
else if(isset($_POST['poidc']))
{
$sid=test_input($_POST['poidc']);
$vid=test_input($_POST['vendorid']);
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="20%">
                        <div><?php echo $info1000['material_label']; ?></div>
                    </th>
                    <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <div>QTA</div>
                    </th>
                    <th>
                        <div><?php echo $info1000['multi_unit_labelp']; ?></div>
                    </th>
                    <?php  if($info2000['uom_display']==1) { ?> <th align="center"><?php echo $info2000['uom_label']; ?>
                    </th><?php } ?>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['single_unit_label']; ?></div>
                    </th>
                    <th <?php if( $info2000['en_customfield1c']==0  && $type_component != 3 ) echo ' style="display:none;"';  ?>
                        class="recurringhide">
                        <div><?php echo $info2000['customfield1c_display'];  ?></div>
                    </th>
                    <?php if($info1000['en_warehouse']==1) {  echo  '  <th ><div>WH </div></th> '; } ?>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['packing_label']; ?></div>
                    </th>
                    <th style="display:none;">Old Price</th>
                    <th style="display:none;">
                        <div><?php echo $info1000['price_label']; ?></div>
                    </th>
                    <?php if($info1000['customer_discount1']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount2']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount3']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_scheme']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                    <?php if($info1000['customer_tax1']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax2']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax3']==1) {  echo  '  <th style="display:none;" ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
                    <th contenteditable="true" width="80" style="display:none;">Total </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
 $data2 = mysqli_query($conn,"SELECT * from component where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr class="carttr">
                    <td><input type="hidden" name="products[]" class="singleitem" value="<?php echo $info2['id'];?>" />
                        <?php echo $info2['sku'].' '.$info2['name'];?>
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <td class="triggeravailable"
                        <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>><?php 
  $sid = $info2['id'];
   $transfer_in = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=1 $wlimit_warehouse8   ");
             $transfer_out = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=1 $wlimit_warehouse8  ");
           echo  $product_qta = $transfer_in-$transfer_out;
  ?></td>
                    <td>
                        <input type="text"
                            class="highlight <?php if($info1000['no_purchasepacking']==1) echo ' change5';  ?>  searchp income_count form-control packing"
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" />
                    </td>
                    <?php  if($info2000['uom_display']==1) { ?>
                    <td>
                        <?php if($info3000['en_uom_selection'] == 1){ ?>
                        <select class="form-control reportselect" name="uom[]" required="">
                            <?php 
          $data4 = mysqli_query($conn, "SELECT * FROM component_unit") or die(mysqli_error($conn)); 
          while($info4 = mysqli_fetch_array($data4)){
            ?><option value="<?php echo $info4['id'] ?>"
                                <?php if($info2['uom'] == $info4['id']){ echo "selected"; } ?>>
                                <?php echo $info4['name']; ?></option><?php
          }
          ?>
                        </select>
                        <?php } else{ ?>
                        <input type="hidden" name="uom[]" value="<?php echo $info2['unit'];  ?>">
                        <?php echo mysqli_get_var("SELECT name FROM component_unit WHERE id = '".$info2['unit']."' "); ?>
                        <?php } ?>
                    </td>
                    <?php } else{ ?>
                    <input type="hidden" name="uom[]" value="<?php echo $info2['unit'];  ?>">
                    <?php } ?>

                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <!-- <input type="hidden" name="products_packing[]" id="p<?php// echo $info2['id'];?>" class="searchqty income_count form-control" tabindex="1"  value=" <?php// echo $info2['packing'];?>"  /> -->
                        <input type="text" value="0"
                            class="searchqty form-control change change5 income_count totalorder" tabindex="1"
                            id="pcs<?php echo $info2['id'];?>" />
                    </td>
                    <td <?php if($info2000['en_customfield1c']==0) echo ' style="display:none;"';  ?>><input
                    name="custom_field1[]" id="customfield<?php echo $info2['id'];?>" type="text" tabindex="1"
                    class="form-control customfield1" /> </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse  ") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' class='teacher warehouse change6' tabindex='1'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>

                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_packing[]" type="number" min="0.1" step="0.001"
                            class="form-control edit-input change income_count totalorder"
                            id="p<?php echo $info2['id'];?>" tabindex="1" value="<?php echo $info2['packing'];?>"
                            readonly="readonly" />
                    </td>
                    <td style="display:none;"><?php // echo $info2['unit_cost'];?></td>
                    <td style="display:none;">
                        <input id="pp<?php echo $info2['id'];?>" name="unitcos[]"
                            value="<?php echo $info2['unit_cost'];?>" class="income_count <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> form-control"
                            type="hidden" />
                    </td>
                    <td style="display:none;"><?php
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from vb_discount where vid='$vid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input name="products_discount[]" type="hidden"
                            class="form-control income_count edit-input totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" />
                        <?php } else {  ?>
                        <input name="products_discount[]" type="hidden"
                            class="form-control income_count edit-input totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" />
                        <?php } ?>
                    </td>
                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_pcs[]" type="text" class="form-control edit-input total_pcs"
                            id="<?php echo "t".$info2['id'];?>" readonly="readonly" /></td>
                    <td style="display:none;"><input name="products_total[]" id="newtotal<?php echo $info2['id'];?>" type="hidden"
                            class="tot<?php echo $info2['id'];?> ptotal form-control sub_total" tabindex="-1"
                            readonly /></td>
                    <td class="d-flex gap-2">
                        <?php if(1==1) { ?>
                            <input type="button" class="rounded-1 bg-info text-white border-0 p-1 edit receipt_edit_hide5" value="Edit" />
                            <input type="button" class="rounded-1 bg-success text-white border-0 p-1 save" value="Save" /><?php } ?><?php if(1==1) { ?>
                            <input type="button" class="rounded-1 bg-danger text-white border-0 p-1 delete receipt_delete_edit5" value="Delete" /><?php } ?></td>

                   
                </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php  if($info1000['en_warehouse']==1) {  ?>
                $('.change6').focusout(function() {
                    $(".change6").removeClass("change6");
                    <?php } else {  ?>
                    $('.change5').focusout(function() {
                        $(".change5").removeClass("change5");
                        <?php }  ?>
                        var $orginal = $(this).closest("tr");
                        var $cloned = $orginal.clone();
                        //get original selects into a jq object
                        var $originalSelects = $orginal.find('select');
                        $cloned.find('select').each(function(index, item) {
                            //set new select to value of old select
                            $(item).val($originalSelects.eq(index).val());
                        });
                        //get original textareas into a jq object
                        var $originalTextareas = $orginal.find('textarea');
                        $cloned.find('textarea').each(function(index, item) {
                            //set new textareas to value of old textareas
                            $(item).val($originalTextareas.eq(index).val());
                        });
                        $cloned.appendTo("#acart");
                        $('.searchqty').attr('class', "highlight income_count form-control");
                        $("#searchbox").focus();
                        $("#psearch").html('');
                    });
                });
    </script>
    <script type="text/javascript">
    $(document).ready(function() {
        $('.save').hide();
        $('.edit-input').attr("readonly", true);
        $(".edit").on('click', function() {
            $(this).closest('tr').find('.edit').hide();
            $(this).closest('tr').find('.save').show();
            $(this).closest('tr').find('.edit-input').attr("readonly", false);
        });
        $(".save").on('click', function() {
            $(this).closest('tr').find('.save').hide();
            $(this).closest('tr').find('.edit').show();
            $(this).closest('tr').find('.edit-input').attr("readonly", true);
        });
        $(".delete").on('click', function() {
            $(this).closest('tr').remove();
            //Total Quantity Sum  (Pcs)
            var sum = 0;
            $(".total_pcs").each(function() {
                sum += parseFloat($(this).val()) || 0;
            });
            $("#total_pcs").val(sum);
            //Total Quantity Sum  (Carton)
            var sum3 = 0;
            $(".packing").each(function() {
                sum3 += parseFloat($(this).val()) || 0;
            });
            $("#packing").val(sum3);
            //Total Amount Sum  (Sub Total)
            var sum2 = 0;
            $(".sub_total").each(function() {
                sum2 += parseFloat($(this).val()) || 0;
            });
            $("#sub_total").val(sum2);
            var n4 = $("#sub_total").val();
            var n5 = $("#paid_amount").val();
            var n6 = $("#pending_amount").val();
            var n7 = $("#shipping").val();
            var n8 = $("#discount").val();
            var n10 = $("#tax").val();
            var result = +n4;
            <?php if ( $info1000['en_discount']==1) { ?>
            n8 = (+n8 * 1) / 100;
            n8 = (n8 * 1) * result;
            result = +result - n8;
            <?php } ?>
            <?php if($info2000['rice_discount']==1) { ?>
            $(".drice").each(function() {
                var damount = $(this).find('.rice_discount_value').val();
                var dless = $(this).find('.rice_type').val();
                var dpercent = $(this).find('.rice_percent').val();
                var specialclass = $(this).find('.specialclass').val();
                var specialclass2 = $(this).find('.specialclass2').val();
                var pack22 = $('#packing').val();
                var broker_id = $('#broker_id').val();
                var customfield1 = $('.customfield1').val();
                var sub_total = $('.sub_total').val();
                if (broker_id != '0') {
                    if (specialclass == 'noimpact' || specialclass ==
                        'trade_no_impact') {} else if (specialclass != 'brokery_rs' &&
                        specialclass !=
                        'brokery_percentage') {
                        if (dless == 1) {
                            if (dpercent == 1) {
                                damount = (+100 - +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result - +damount;
                            }
                        } else if (dless == 0) {
                            if (dpercent == 1) {
                                damount = (+100 + +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result + +damount;
                            }
                        }
                    }
                } else if (broker_id == '0') {
                    if (specialclass == 'noimpact' || specialclass ==
                        'trade_no_impact') {} else if (specialclass == 'brokery_rs') {
                        damount = damount * customfield1;
                        if (dless == 1) {
                            result = +result - +damount;
                        } else if (dless == 0) {
                            result = +result + +damount;
                        }
                    } else if (specialclass == 'brokery_percentage') {
                        damount = (damount / 100) * sub_total;
                        if (dless == 1) {
                            result = +result - +damount;
                        } else if (dless == 0) {
                            result = +result + +damount;
                        }
                    } else {
                        if (dless == 1) {
                            if (dpercent == 1) {
                                damount = (+100 - +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result - +damount;
                            }
                        } else if (dless == 0) {
                            if (dpercent == 1) {
                                damount = (+100 + +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result + +damount;
                            }
                        }
                    }
                }
            });
            <?php } ?>
            <?php if ($info1000['en_tax']==1) { ?>
            var percent = (result * 1) / 100;
            percent = (percent * 1) * n10;
            result = +result + +percent;
            <?php } ?>
            <?php if ($info1000['en_shipping']==1) { ?>
            var result = +result + +n7;
            <?php } ?>
            result = Math.round(result);
            var pending = +result - n5;
            $("#total_amount").val(result);
            $("#pending_amount").val(pending);
        });
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  }
else if(isset($_POST['sid']))
{
$sid=test_input($_POST['sid']);
$cid=test_input($_POST['customerid']);
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="20%">
                        <div><?php echo $info1000['product_label']; ?></div>
                    </th>
                    <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <div>QTA</div>
                    </th>
                    <th>
                        <div><?php echo $info1000['multi_unit_labelp']; ?></div>
                    </th>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['single_unit_label']; ?></div>
                    </th>
                    <?php if($info1000['en_warehouse']==1) {  echo  '  <th ><div>WH </div></th> '; } ?>
                    <?php if($info1000['en_inventorybatch']==1) {   echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; } ?>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['packing_label']; ?></div>
                    </th>
                    <th>
                        <div><?php echo $info1000['price_label']; ?></div>
                    </th>
                    <?php if($info1000['customer_discount1']==1) {  echo  '  <th ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount2']==1) {  echo  '  <th ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount3']==1) {  echo  '  <th ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_scheme']==1) {  echo  '  <th ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
                    <th <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                    <?php if($info1000['customer_tax1']==1) {  echo  '  <th ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax2']==1) {  echo  '  <th ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax3']==1) {  echo  '  <th ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
                    <th contenteditable="true" width="80">Total </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
   ?>
                <?php  if($info1000['en_singleproducts']==1) { 
       $data2 = mysqli_query($conn,"SELECT * from inventory where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr class="carttr">
                    <td>
                        <input type="hidden" name="products[]" class="singleitem" value="<?php echo $info2['id'];?>" />
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                    </td>
                    <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>><?php 
         $sid = $info2['id'];
   $transfer_in = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=0 $wlimit_warehouse8   ");
             $transfer_out = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=0 $wlimit_warehouse8  ");
           echo  $product_qta = $transfer_in-$transfer_out;
         ?></td>
                    <td>
                        <input type="number"
                            class="searchqty <?php if($info1000['no_purchasepacking']==1) echo ' change5';  ?> packing income_count totalorder form-control"
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" value="0" required/>
                    </td>
                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>>
                        <input type="text" value="0" class="form-control change income_count totalorder" tabindex="1"
                            id="pcs<?php echo $info2['id'];?>" />
                    </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse  ") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>

                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            type="text" name="products_packing[]" value="<?php echo $info2['packing'];?>"
                            class="edit-input form-control income_count" id="p<?php echo $info2['id'];?>" /></td>
                    <td>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['sale_price'];?>"
                            class="form-control income_count change totalorder" size="20" />
                    </td>
                    <td>
                        <?php
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from cb_discount where cid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input name="products_discount[]" type="number"
                            class="form-control income_count edit-input totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" />
                        <?php } else {  ?>
                        <input name="products_discount[]" type="number"
                            class="form-control income_count edit-input totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" />
                        <?php } ?>
                    </td>
                    <td <?php if($info1000['no_purchasepacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_pcs[]" type="text" class="form-control edit-input total_pcs"
                            id="<?php echo "t".$info2['id'];?>" readonly="readonly" /></td>
                    <td><input type="number" name="products_tax[]" class="form-control edit-input income_count"
                            value="<?php echo $info1000['tax_percent'];?>" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>" readonly="readonly" /></td>
                    <td><input type="hidden" name="products_cogs[]" value="<?php echo $info2['unit_cost'];?>" /><input
                            name="products_total[]" step="0.0001"  id="newtotal<?php echo $info2['id'];?>" type="number" min="0" 
                            class=" tot<?php echo $info2['id'];?> ptotal sub_total income_count form-control readonly "
                            tabindex="-1" onkeypress="return false;" /> </td>
                    <td><input type="button" class="delete receipt_delete_edit5" value="Delete" /></td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
        $('.searchqty').change(function() {
            var $orginal = $(this).closest("tr");
            var $cloned = $orginal.clone();
            //get original selects into a jq object
            var $originalSelects = $orginal.find('select');
            $cloned.find('select').each(function(index, item) {
                //set new select to value of old select
                $(item).val($originalSelects.eq(index).val());
            });
            //get original textareas into a jq object
            var $originalTextareas = $orginal.find('textarea');
            $cloned.find('textarea').each(function(index, item) {
                //set new textareas to value of old textareas
                $(item).val($originalTextareas.eq(index).val());
            });
            $cloned.appendTo("#acart");
            $('.searchqty').attr('class', "highlight income_count packing form-control");
            $("#searchbox").focus();
            $("#psearch").html('');
            var n10 = $("#totpc").val();
            n10 = parseInt(n10) + parseInt(1);
            $("#totpc").val(n10);
        });
    });
    </script>
    <script type="text/javascript">
    $(document).ready(function() {
        $('.delete').on('click', function() {
            $(this).closest('tr').remove();
            //Total Quantity Sum  (Pcs)
            var sum = 0;
            $(".total_pcs").each(function() {
                sum += parseFloat($(this).val()) || 0;
            });
            $("#total_pcs").val(sum);
            //Total Quantity Sum  (Carton)
            var sum3 = 0;
            $(".packing").each(function() {
                sum3 += parseFloat($(this).val()) || 0;
            });
            $("#packing").val(sum3);
            //Total Amount Sum  (Sub Total)
            var sum2 = 0;
            $(".sub_total").each(function() {
                sum2 += parseFloat($(this).val()) || 0;
            });
            $("#sub_total").val(sum2);
            var n4 = $("#sub_total").val();
            var n5 = $("#shipping").val();
            var n6 = $("#discount").val();
            var n7 = $("#tax").val();
            var result = +n4;
            <?php if ( $info1000['en_discount']==1) { ?>
            n6 = (+n6 * 1) / 100;
            n6 = (n6 * 1) * result;
            result = +result - n6;
            <?php } ?>
            <?php if($info2000['rice_discount']==1) { ?>
            $(".drice").each(function() {
                var damount = $(this).find('.rice_discount_value').val();
                var dless = $(this).find('.rice_type').val();
                var dpercent = $(this).find('.rice_percent').val();
                var specialclass = $(this).find('.specialclass').val();
                var specialclass2 = $(this).find('.specialclass2').val();
                var pack22 = $('#packing').val();
                var broker_id = $('#broker_id').val();
                var customfield1 = $('.customfield1').val();
                var sub_total = $('.sub_total').val();
                if (broker_id != '0') {
                    if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') { } else if (specialclass != 'brokery_rs' &&
                        specialclass !=
                        'brokery_percentage') {
                        if (dless == 1) {
                            if (dpercent == 1) {
                                damount = (+100 - +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result - +damount;
                            }
                        } else if (dless == 0) {
                            if (dpercent == 1) {
                                damount = (+100 + +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result + +damount;
                            }
                        }
                    }
                } else if (broker_id == '0') {
                    if (specialclass == 'noimpact' || specialclass ==
                        'trade_no_impact') {} else if (specialclass == 'brokery_rs') {
                        damount = damount * customfield1;
                        if (dless == 1) {
                            result = +result - +damount;
                        } else if (dless == 0) {
                            result = +result + +damount;
                        }
                    } else if (specialclass == 'brokery_percentage') {
                        damount = (damount / 100) * sub_total;
                        if (dless == 1) {
                            result = +result - +damount;
                        } else if (dless == 0) {
                            result = +result + +damount;
                        }
                    } else {
                        if (dless == 1) {
                            if (dpercent == 1) {
                                damount = (+100 - +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result - +damount;
                            }
                        } else if (dless == 0) {
                            if (dpercent == 1) {
                                damount = (+100 + +damount) / 100;
                                result = +result * damount;
                            } else {
                                result = +result + +damount;
                            }
                        }
                    }
                }
            });
            <?php } ?>
            <?php if ($info1000['en_tax']==1) { ?>
            var percent = (result * 1) / 100;
            percent = (percent * 1) * n7;
            result = +result + +percent;
            <?php } ?>
            <?php if ($info1000['en_shipping']==1) { ?>
            var result = +result + +n5;
            <?php } ?>
            result = Math.round(result);
            $("#total").val(result);
            var n7 = $("#total").val();
            var n8 = $("#amount_received").val();
            var result2 = +n7 - n8;
            $("#pending_amount").val(result2);
            var n10 = $("#totpc").val();
            n10 = parseInt(n10) - parseInt(1);
            $("#totpc").val(n10);
        });
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script>
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  }
/////
else if(isset($_POST['sid2']))
{
$sid = isset($_POST['sid2']) ? (int)$_POST['sid2'] : 0;
if($sid <= 0) { exit; }
$cid = isset($_POST['customerid']) ? (int)$_POST['customerid'] : 0;
$subc_id = isset($_POST['subc']) ? (int)$_POST['subc'] : 0;
$paymentterm = isset($_POST['paymentterm']) ? (int)$_POST['paymentterm'] : 0;
$st=test_input($_POST['st']);
$gdn=test_input($_POST['gdn']);
$uom_hide =  test_input($_POST['uom_hide']);
$dist_id = isset($_POST['dist_id']) ? (int)$_POST['dist_id'] : 0;
$dist_id2 = isset($_POST['dist_id2']) ? (int)$_POST['dist_id2'] : 0;

// Hamza
$pricing_type = test_input($_POST['pricing_type']);
//Hamza end 
$search_batch = test_input($_POST['search3']);
$currency_rate_f = test_input($_POST['currency_rate']);
$currencymargin = test_input($_POST['currencymargin']);
$return_form = test_input($_POST['return_form']);

$lid=test_input($_POST['lid']);


if($lid!='') {
$lid=" && location_id='$lid' ";
}


$search3_raw = isset($_POST['search3']) ? trim((string)$_POST['search3']) : '';
$search3_sql = mysqli_real_escape_string($conn, $search3_raw);
$search3 = mysqli_get_var("Select id from inventory_batch where `prd_id` = '$sid' && batch_code='$search3_sql' ");

$wid =  test_input($_POST['wid']);
$subc =  test_input($_POST['subc']);
if($info4000['en_razi']==1){
$itemtax = mysqli_get_var("Select tax_applied from inventory where `id` = '$sid'");
if($itemtax==""){
  $itemtax=0;
}
}
else{
   $itemtax=0; 
}

$idirect_invoicetax3 = -1;
if($info3000['direct_iteminvoicetax3']==1){
$idirect_invoicetax3 = mysqli_get_var("Select direct_invoicetax3 from inventory where `id` = '$sid'");
}
$subcustomerdiscount=mysqli_get_var("select discount from sub_customer where id='$subc'");
if($subcustomerdiscount==="" || $subcustomerdiscount===null){
  $subcustomerdiscount=0;
}
$type_component =  test_input($_POST['type_component']);
$cdirect_invoicetax2 = mysqli_get_var("select direct_invoicetax2 from customer where id='$cid'");
$cdirect_invoicetax3 = mysqli_get_var("select direct_invoicetax3 from customer where id='$cid'");
$csaletax_no = mysqli_get_var("select saletax_no from customer where id='$cid'");
if($gdn=='') $gdn=0;
if($dist_id=='') $dist_id=0;
if($dist_id2=='') $dist_id2=0;
$query22="SELECT * FROM direct_pricing WHERE 1=1 AND active=1 AND ((customer_type LIKE '%$cid%') || (customer_type='0')) && ((payment_term LIKE '%$sid%') || (payment_term='0'))   order by id DESC";
$result22=mysqli_query($conn,$query22);
$data22=mysqli_fetch_array($result22);
$price_type= $data22['price_type'];
$price_range= $data22['price_range'];
$trade_price= $data22['trade_price'];
$price= $data22['price'];
$from_date= $data22['from_date'];
$to_date= $data22['to_date'];
if($dist_id=='') $dist_id=0;
if($dist_id2=='') $dist_id2=0;
$allowfoc = mysqli_get_var("SELECT allow_foc from customer where id='$cid' ");
$add_customer_discount4= mysqli_get_var("SELECT discount FROM customer_item where prd_id='$sid' and cid='$cid'");
$query60 = "SELECT discount1_reserve,discount2_reserve,discount3_reserve,discount4_reserve FROM customer WHERE id='$cid'";
$result60 = mysqli_query($conn,$query60);
$customer_discount_array= mysqli_fetch_array($result60);
 $discount1_reserve=$customer_discount_array['discount1_reserve']; 
 $discount2_reserve=$customer_discount_array['discount2_reserve']; 
 $discount3_reserve=$customer_discount_array['discount3_reserve']; 
 $discount4_reserve=$customer_discount_array['discount4_reserve']; 
 ?>
    <input type="hidden" name="discount1_reserve" value="<?php echo $discount1_reserve; ?>">
    <input type="hidden" name="discount2_reserve" value="<?php echo $discount2_reserve; ?>">
    <input type="hidden" name="discount3_reserve" value="<?php echo $discount3_reserve;  ?>">
    <input type="hidden" name="discount4_reserve" value="<?php echo $discount4_reserve; ?>">
    <?php 
/*------start multipricing------------- */
$date =      date('Y-m-d');
  if($info4000['en_payment_mode_pricing']==1){ 
     // $customer_type=1;
    // echo "SELECT amount from cust_ven_payment_terms where pid='$cid' AND term_id='$paymentterm'";
    // echo "------".$sid;
   $customer_type = (int)mysqli_get_var("SELECT amount from cust_ven_payment_terms where pid='$cid' AND term_id='$paymentterm'");
  } else{
$customer_type = (int)mysqli_get_var("SELECT customer_type FROM `customer` where id = '$cid'");
$customer_filer = (int)mysqli_get_var("SELECT filer FROM `customer` where id = '$cid'");
$cid = ($cid=='a') ? 0 : (int)$cid;
if($cid=='') $cid=0;

if(1==1) {
$multiprice1000 = mysqli_query($conn,"SELECT * FROM `multi_pricing` 
where (find_in_set($sid,prd_id) <> 0 || prd_id = 0) and  
(find_in_set($dist_id2,distributor_id) <> 0  || distributor_id =0)
 and (find_in_set($cid,customer_id) <> 0   || customer_id=0)  
and (find_in_set($customer_type,customer_type) <> 0 || customer_type=0) and `status` = 1 and 
(starting_date <= '$date'||starting_date ='') and (ending_date >= '$date' || ending_date='') and
1=1  order by id desc limit 1") or die(mysqli_error($conn));       
$infomultiprice1000 = mysqli_fetch_array( $multiprice1000 );
$userdefault_price = $infomultiprice1000['use_defaultprice'];
$tax1filer_value = $infomultiprice1000['tax1filer_value'];
$tax2filer_value = $infomultiprice1000['tax2filer_value'];
$tax3filer_value = $infomultiprice1000['tax3filer_value'];

}

  }
if($gdn=='') $gdn = 0;
if (!isset($_SESSION['shopping_cart']) || !is_array($_SESSION['shopping_cart'])) {
    $_SESSION['shopping_cart'] = [];
}
// var_dump($_SESSION["shopping_cart"]);
if ($info2000['noduplicate_item'] == 1  && !empty($_SESSION['shopping_cart']) && in_array($sid, $_SESSION['shopping_cart'], true && $info2000['noduplicate_item']==1) )
           {  
     ?>
    <script type="text/javascript">
    alert('This item is already added');
    </script>
    <?php   }
  else {
     $_SESSION['shopping_cart'][] = $sid;
$cwarehouse = mysqli_get_var("Select inventory_warehouse from customer where `id` = '$cid'");
$cfiler = mysqli_get_var("Select filer from customer where `id` = '$cid'");
?>

<style>
input#newtotal9 {
    width: 100px;
}

input#pppp9 {
    width: 100px;
}
</style>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <?php if($info3000['en_hapaperhub'] == 1){ ?><th></th><?php } ?>
                    <th width="2%">S.No</th>
                    <th width="20%">
                        <div><?php echo $info1000['product_label']; ?></div>
                    </th>
                        <?php if ($info3000['en_sstrader'] == 1) { ?>
                    <th>Ctn Barcode</th>
                    <?php } ?>
                    <?php if ($info3000['en_osaka_tape'] == 1 || $info3000['en_osaka'] == 1) { ?>
                     <th width="5%"><div>Brand</div></th>
                    <?php } ?>
                    <th <?php if($info2000['en_brandsmoq']==0) echo ' style="display:none;"';  ?>>
                        <div>Store QTY</div>
                    </th>
                    <th <?php if($info2000['en_brandsmoq']==0) echo ' style="display:none;"';  ?>>
                        <div>MOQ</div>
                    </th>
                    <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <div>QTA</div>
                    </th>
                    <th <?php if($info3000['en_ajk'] ==0) echo ' style="display:none;"'; ?> >
                      <div>History</div>
                    </th>
                    <th>
                        <div><?php echo $info1000['multi_unit_label']; ?></div>
                    </th>
                    <th
                        <?php if($info1000['no_salespacking']==1   || $info2000['pcs_hide']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['single_unit_label']; ?></div>
                    </th>
                    <?php  if($info2000['uom_display']==1 && $uom_hide != 1) { ?> <th align="center">
                        <?php echo $info2000['uom_label']; ?></th><?php } ?>
                    <th <?php if($info2000['en_customfield1']==0  || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide">
                        <div><?php echo $info2000['customfield1_display'];  ?></div>
                    </th>
                    <th <?php if($info4000['en_customfield2']==0  || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide printinghide">
                        <div><?php echo $info4000['customfield2_label'];  ?></div>
                    </th>
                    <th <?php if($info4000['en_customfield3']==0 || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide printinghide">
                        <div><?php echo $info4000['customfield3_label'];  ?></div>
                    </th>
                    <th <?php if($info4000['en_customfield4']==0  || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide">
                        <div><?php echo $info4000['customfield4_label'];  ?></div>
                    </th>
                    <th <?php if($info4000['en_customfield5']==0  || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide">
                        <div><?php echo $info4000['customfield5_label'];  ?></div>
                    </th>
                    <th <?php if($info4000['en_customfield6']==0  || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide">
                        <div><?php echo $info4000['customfield6_label'];  ?></div>
                    </th>
                    <th <?php if($info4000['en_customfield7']==0  || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide">
                        <div><?php echo $info4000['customfield7_label'];  ?></div>
                    </th>
                    <th <?php if($info4000['en_customfield8']==0  || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide">
                        <div><?php echo $info4000['customfield8_label'];  ?></div>
                    </th>
                    <?php if($info4000['en_engineering']==1){ 
        echo " <th >Per KG Rate</th>"; }?>
                    
                    <?php if($info1000['en_warehouse']==1) {  echo  '  <th ><div>'.$info2000['warehouse_label'].'</div></th> '; } ?>

                    <?php if($info3000['datewise_batch']==1) { ?>   
                        <?php if($info1000['en_inventorybatch']==1  && $info2000['batch_grnonly']==0 && 1==2 ) { echo  '  <th ><div>'.$info1000['batch_label'].'</div></th> '; } ?>
                        <?php if($info1000['en_expirydisplay']==1 && 1==2) {   echo  '  <th ><div>Expiry </div></th> '; } ?>       
                    <?php } ?>

                    <?php if($info3000['en_item_area_shipping'] == 1){ ?>
                    <th>Area</th>
                    <th>Charges</th>
                    <?php } ?>
                    <?php if($info4000['batchselection_order']==1) { 
               echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; 

               if($info1000['batch_with_brand']==1){
                    echo  '  <th ><div>Brand</div></th> '; 
                }
        
    if($info4000['en_inventorybatch2']==1) {  echo  '  <th ><div>'.$info4000['batch_label2'].' </div></th> ';  }           
                } ?>
                    <?php if($info2000['multiple_batch']==1 && $st!=1) {   echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; } ?>
                    
                    <?php if($info1000['en_embroidery']==1) 
                    { 
                       echo  ' 
                        <th ><div>Type </div></th>
                        <th ><div>Colors </div></th>
                       <th ><div>Head Working </div></th>
                       <th ><div>Fusing </div></th>
                        '; } ?>

                    <!-- Basit  -->
                    <!-- Added 3 Custom Fields Headers -->
                    <?php
                    if ($info4000['customfield_itemwise'] == 1)
                    {
                    ?>
                      <th>
                        <div><?php echo $info4000['customfielditem_label1']; ?></div>
                      </th>

                      <th>
                        <div><?php echo $info4000['customfielditem_label2']; ?></div>
                      </th>

                      <th>
                        <div><?php echo $info4000['customfielditem_label3']; ?></div>
                      </th>
                    <?php 
                    } 
                    ?>
                    <!--  -->


                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['packing_label']; ?></div>
                    </th>
                    <th <?php if($gdn==1 || $info3000['en_osaka']==1 && 1==2) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['price_label']; ?></div>
                    </th>
                    <th <?php if($info4000['separate_mrpcolumn']==0) echo ' style="display:none;"';  ?> class="">
                        <div><?php echo $info4000['mrp_label']; ?></div>
                    </th>
                    <?php if($info2000['en_sarhad']==1 || $info4000['itemmulti_unit']==1) { ?>
                    <th>
                        <div>Unit</div>
                    </th>
                    <th style="display:none;">
                        <div>Unit Rate</div>
                    </th>
                    <?php } ?>
                    <th <?php   if($info2000['en_sarhad']==0 || $gdn==0) {  echo ' style="display:none;"'; }  ?>>
                        <div><?php echo $info2000['itemcustomunit_label']; ?></div>
                    </th>
                    <th <?php if($info4000['en_tradelink']==0) echo ' style="display:none;"';  ?> class="recurringhide">
                        <div>Total Clicks</div>
                    </th>
                    <th <?php if($info2000['en_ricetrade']==0) echo ' style="display:none;"';  ?> class="recurringhide">
                        <div><?php echo $info2000['itemcustomunit_label']; ?></div>
                    </th>
                    <th <?php if($info4000['en_tradelink']==0) echo ' style="display:none;"';  ?> class="recurringhide">
                        <div>Additional Print Charges</div>
                    </th>
                    <?php  if($info2000['invoice_cartonrate']==1) {  ?>
                    <th>
                        <div>Rate Apply</div>
                    </th>
                    <?php } ?>
                    <?php if($info1000['customer_discount1']==1 && $gdn==0) {  echo  '  <th ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount2']==1 && $gdn==0) {  echo  '  <th ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount4']==1 && $gdn==0) {  echo  '  <th ><div>'.$info1000['disc4_label'].'</div></th> '; } ?>
                    <?php 
                     if( $info2000['customer_foc']==1 && $gdn==0) {
                      echo  '  <th ><div>'.$info4000['customerfoc_label'].'</div></th> '; 
                    } 
                    ?>
                    <?php if($info1000['customer_discount3']==1 && $gdn==0) {  echo  '  <th ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
                    <?php if($info2000['en_discount5']==1) {  echo  '  <th ><div>Disc (Rs.)</div></th> '; } ?>
                    <?php if($info1000['customer_scheme']==1) {  echo  '  <th ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
                    <?php if($info3000['customer_scheme_value']==1) {  echo  '  <th ><div>'.$info3000['scheme_value_label'].'</div></th> '; } ?>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>

                    <?php if($info4000['display_taxamount']==1){   ?>    
            <th>Exclusive of GST Amount</th>    
            <?php } ?> 
                    <?php if($info1000['customer_tax1']==1 && $gdn==0) {  echo  '  <th ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
                    <?php  if($info2000['invoice_cartonrate']==1) {  ?>
                    <th class="pipehide">
                        <div>Pipe Rate</div>
                    </th>
                    <?php } ?>
                    <?php if($info1000['customer_tax2']==1 && $gdn==0) {  echo  '  <th ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax3']==1 && $gdn==0) {  echo  '  <th ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
                    <?php if($info4000['display_taxamount']==1){  ?>
                    <th><?php echo $info4000['taxamount_label']; ?></th>
                    <?php } ?>
                    <!-- <th class="<?php $info2000['en_freshmate'] == 1 ? '' : 'hidden'?>">Expiry Date</th> -->
                    <!-- <th class="<?php $info2000['en_freshmate'] == 1 ? '' : 'hidden'?>">Reason</th> -->
                    <th contenteditable="true" width="80" <?php if($gdn==1) { ?> style="display:none;" <?php }  ?>>Total
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php  if($info1000['en_singleproducts']==1) { 
      //  echo "SELECT *, packing2 as pac2 from inventory where id='$sid'";
       $data2 = mysqli_query($conn,"SELECT *, packing2 as pac2 from inventory where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { 
$applyfrom = $from_date;
$applytill = $to_date;
// echo "---------".$applyfrom;
// echo "---------".$applytill;
$today = date('Y-m-d');
if($applyfrom <= $today && $applytill>=$today) {
   //   echo "yes";
     // avaiable on this date range 
if($price_range=="higher"){
 if($price_type=="amount"){
     if($custom_price!='0.00' || $custom_price!=''){
        $finalprice=$custom_price;
     }else{
           $finalprice=  $info2['sale_price'];
     }
   // $finalprice=  $info2['sale_price'] + $price;
  }
  else{
    $addamount = $info2['sale_price'] * $price/100;
    $finalprice=  $info2['sale_price'] + $addamount; 
  }
}
else if($price_range=="lower"){
   if($price_type=="amount"){
   if($custom_price!='0.00' || $custom_price!=''){
        $finalprice=$custom_price; 
     }else{
           $finalprice=  $info2['sale_price'];
     }
    // $finalprice=  $info2['sale_price'] - $price;
  }
  else{
    $addamount = $info2['sale_price'] * $price/100;
    $finalprice=  $info2['sale_price'] - $addamount; 
  }
}
// for fix amounr
else if($price_range=="fixed"){
    $finalprice=  $price;
}
// end
else{
$finalprice=$price;
}
if($finalprice=='' || $finalprice<0){
  $finalprice = $info2['sale_price'];
}
}else{
   $finalprice = $info2['sale_price'];
}
  if($info4000['en_engineering']==1){
    $readonly = 'readonly';
 }
 ?>
                <tr class="carttr">
                    <?php if($info3000['en_hapaperhub']==1) { ?>
                    <td><input type="button" name="add" value="+" class="tr_clone_add btn btn-primary"></td> 
                    <?php } ?>

                    <td><input type="text" class="sno form-control" />
                        <input type="hidden" class="productWeight" id="productWeight<?php echo $info2['id']; ?>" value="<?php echo $info2['weight']; ?>" />
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php 

 $direct_invoicetaxtype = mysqli_get_var("Select direct_invoicetaxtype from customer where id='$cid'");

if($direct_invoicetaxtype==2) { echo 2; } else { echo $info2['is_taxable']; } ?>" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
       else if($info1000['en_lastprice']==2 ) {
       $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id` AND s.customer_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      } 
         ?>
                    </td>
                    <td>
                    <input type="hidden" id="brandidd<?php echo $info2['id'];?>"
                value="<?php echo $info2['brand_id'];?>" />
                        <input type="hidden" class="singleitem products" name="products[]"
                            value="<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>  
                           <?php    if($info3000['en_subcustomer_pricing']==1){ ?>
                        Sale Price:<?php echo $info2['sale_price'];?>  
                        <?php } ?>
                        
                        <?php if($info3000['en_alphatea']!=1){
                        echo $info2['barcode'];
                        }?>
                      
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]"
    placeholder="Details..."
    style="
        width:100%;
        padding:6px 8px;
        box-sizing:border-box;
        overflow:hidden;
        line-height:1.4;
        min-height:30px;
    "
    oninput="this.style.height='auto';this.style.height=this.scrollHeight+'px';"
><?php 
if($info3000['itemname_description'] == 1){
    echo trim($info2['sku'].' '.$info2['name'].' '.$info2['barcode']);
}
?></textarea>
<br>
<span>
<?php
$itemid = $info2['id'];

$result = mysqli_query($conn,"
    SELECT DISTINCT s.id 
    FROM so s
    INNER JOIN so_details sd ON sd.order_id = s.id
    WHERE s.completed = 0
      AND s.customer_id = '$cid'  
      AND sd.prd_id = '$itemid'
    ORDER BY s.id DESC
") or die(mysqli_error($conn));

if(mysqli_num_rows($result) == 0)
{
    echo 'N/A';
}
else
{
    $links = [];

    while($row = mysqli_fetch_assoc($result))
    {
        $sid = $row['id'];
        $links[] = '<a href="../sales/print-so.php?sid='.$sid.'" target="_blank">'.$sid.'</a>';
    }

    echo 'SO #: '.implode(', ', $links);
}
?>
</span>
<br>
<span>
    <?php
    if($return_form==1)
    {
        $itemid = $info2['id'];
        $last_salerate = mysqli_get_var("Select tp from sales_details where prd_id = '$itemid' && order_id in (select id from sales where customer_id = '$cid') order by id desc limit 1 ");
        if($last_salerate == ''){ $last_salerate = 0; }

        if($last_salerate == 0)
        { 
            echo "Last Sale Rate: N/A"; 
        }
        else
        {
            echo "Last Sale Rate: ".$last_salerate;
        }
    }
    ?>
</span>
                        </div>

                    </td>


<?php if ($info3000['en_sstrader'] == 1) { ?>
                    <td>
                       <h5><?php echo $info2['details'];?></h5>
                    </td>

                    <?php } ?>
                     <?php if ($info3000['en_osaka_tape'] == 1 || $info3000['en_osaka'] == 1) { ?>
                        <td>
                            <div> <?php $brand_idss = $info2['brand_id']; echo mysqli_get_var("select name from product_brands where id = '$brand_idss' "); ?></div>
                        </td>
                    <?php } ?>
                    <td <?php if($info2000['en_brandsmoq']==0) echo ' style="display:none;"';  ?>>
                        <div class="triggeravailable9"></div>
                    </td>
                    <td <?php if($info2000['en_brandsmoq']==0) echo ' style="display:none;"';  ?>>
                        <div class="triggeravailable5"></div>
                    </td>
                    <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <div class="triggeravailable" <?php if($info1000['hide_qavailable']==1 || $type_component == 3 || ($info1000['en_export']==1 && $type_component == 10)) echo ' style="display:none;"';  ?> >
                            <?php 
                                /*if($info2000['qta_inpacking']==0) { $a=' SUM(qty) '; } else { $a=' SUM(qty/packing) '; } 
                                $sid = $info2['id'];
                                $transfer_in = mysqli_get_var("SELECT $a as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=0 $wlimit_warehouse8   ");
                                $transfer_out = mysqli_get_var("SELECT $a as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=0 $wlimit_warehouse8  ");
                                echo  $product_qta = $transfer_in-$transfer_out;*/
                                if($info1000['salesman_mode']==1){
                                    $Warehouse_id_label = 'distributor_id';
                                    $sp = $dist_id2;
                                }else{
                                    $sp = mysqli_get_var("SELECT id FROM inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse ");
                                    $Warehouse_id_label = 'warehouse_id';
                                }
                                $stocksingle = $info2['id'];
                                if(1) { $a=' SUM(qty) '; } else { $a=' SUM(qty/packing) '; }
                                $minus = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id && t.type=0 && w.deleted=0 &&  `item_id` = '$stocksingle' &&  $Warehouse_id_label = '$sp' "); 
                                if($info1000['inventory_limit']==1) {
                                $minus2 = mysqli_get_var("SELECT $a AS sqty FROM so_details WHERE $Warehouse_id_label='$sp' && prd_id='$stocksingle' && order_id IN (SELECT id FROM so WHERE completed=0)  "); 
                                }else{
                                $minus2 = 0;
                                }
                                $plus = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id && t.type=1 && w.deleted=0 &&  `item_id` = '$stocksingle' &&  $Warehouse_id_label = '$sp' "); 
                                $minus3 = mysqli_get_var("SELECT $a AS sqty FROM warehouse_transaction w, warehouse_transaction_type t WHERE w.tran_type=t.id && w.deleted=0 && (w.tran_type=1 || w.tran_type=21) && verified_by=0 && t.type=1 &&  `item_id` = '$stocksingle' &&  `warehouse_id` = '$sp' ");
                                $product_qta=$plus-$minus-$minus2-$minus3;
                                if($info2000['qta_inpacking']==0) {
                                echo number_format($product_qta, 2);
                                }else{
                                $packing5 = mysqli_get_var("SELECT packing FROM inventory WHERE id = '$stocksingle' ");
                                echo number_format($product_qta/$packing5, 2);
                                }
                            ?>                        
                        </div>
                        <!-- here it is -->
                        <a class="btn btn-info view_stock" name="<?php echo $info2['id']; ?>" data-bs-toggle="modal"
                            href="#info" data-bs-target="#info">
                            <i class="fa fa-info-circle" aria-hidden="true"> </i>
                        </a>
                    </td>
                    <td <?php if($info3000['en_ajk'] ==0) echo ' style="display:none;"'; ?> >
                        <div class="product_lastsalepurchase">
                          <?php
$item_id = $info2['id'];

// Last Sale Rate and Qty
$sale_sql = "
    SELECT sd.tp, sd.qty 
    FROM sales_details sd
    JOIN sales s ON sd.order_id = s.id
    WHERE sd.prd_id = '$item_id'
    ORDER BY s.id DESC
    LIMIT 1
";
$sale_result = $conn->query($sale_sql);
if ($sale_result && $sale_result->num_rows > 0) {
    $row = $sale_result->fetch_assoc();
    $sale_rate = $row['tp'];
    $sale_qty = $row['qty'];
} else {
    $sale_rate = '---';
    $sale_qty = '---';
}

// Last Purchase Rate and Qty
$purchase_sql = "
    SELECT pd.tp, pd.qty 
    FROM purchasing_details pd
    JOIN purchasing p ON pd.order_id = p.id
    WHERE pd.prd_id = '$item_id'
    ORDER BY p.id DESC
    LIMIT 1
";
$purchase_result = $conn->query($purchase_sql);
if ($purchase_result && $purchase_result->num_rows > 0) {
    $row = $purchase_result->fetch_assoc();
    $purchase_rate = $row['tp'];
    $purchase_qty = $row['qty'];
} else {
    $purchase_rate = '---';
    $purchase_qty = '---';
}

echo "<strong>Sale:</strong> $sale_rate (Qty: $sale_qty)<br>";
echo "<strong>Purchase:</strong> $purchase_rate (Qty: $purchase_qty)";
?>
                        </div>
                    </td>
                    <td>
                        <input type="hidden" id="u<?php echo $info2['id'];?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <!-- here we need to remove ctn from id in crest auto parts -->
                        <input style="width:100px;" type="number" required step="0.0001" name="stitch_pcs[]"
                            <?php if($info2000['multiple_batch']==1) { echo "value='1'  ";  } ?>
                            class="form-control searchqty ctn qty_weight<?php if($info1000['no_salespacking']==1){ if($info3000['en_hapaperhub']==1) { echo ' change55';} else {echo ' change5';}} ?>  <?php if($info4000['en_mbl']==1) { echo ' change6 '; }  ?>  <?php if($info3000['en_osaka']==1){echo "edit-input";} ?> income_count qtychange22 packing "
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" size="7" min="0"
                            value="" />
                    </td>
                  <td
                        <?php if($info1000['no_salespacking']==1   || $info2000['pcs_hide']==1) echo ' style="display:none;"';  ?>>
                        <input type="number" class="form-control change5  change income_count totalorder custompcs <?php if($info3000['en_osaka']==1){echo "edit-input";} ?>"
                            id="pcs<?php echo $info2['id'];?>" tabindex="1" value="0" size="4" required />
                    </td>
                    <?php  if($info2000['uom_display']==1 && $uom_hide != 1) { ?>
                    <td>
                        <?php if($info3000['en_uom_selection'] == 1){ ?>
                        <select class="form-control reportselect" name="uom[]" required="">
                            <?php 
          $data4 = mysqli_query($conn, "SELECT * FROM product_unit") or die(mysqli_error($conn)); 
          while($info4 = mysqli_fetch_array($data4)){
            ?><option value="<?php echo $info4['id'] ?>"
                                <?php if($info2['unit'] == $info4['id']){ echo "selected"; } ?>>
                                <?php echo $info4['name']; ?></option><?php
          }
          ?>
                        </select>
                        <?php } else{ ?>
                        <input type="hidden" name="uom[]" value="<?php echo $info2['unit'];  ?>">
                        <?php echo mysqli_get_var("SELECT name FROM product_unit WHERE id = '".$info2['unit']."' "); ?>
                        <?php } ?>
                    </td>
                    <?php } else{ ?>
                    <input type="hidden" name="uom[]" value="<?php echo $info2['unit'];  ?>">
                    <?php } ?>
                    <?php 
    if($info4000['en_sarwana']==1) 
    {
      $value= $info2['color'];
      $value_color= "";
    }
    else if($info3000['en_fastpackages']==1){
        $value= $info2['size'];
        $value_color= $info2['color'];
    }
    else if($info3000['en_seatex']==1){
        $value = mysqli_get_var("select value from rice_field_details where sid = '$sid' && fid = 1 && stype = 10 ");
    }
    else {
      $value="";
      $value_color= "";
    }
    ?>
                    <td <?php if($info2000['en_customfield1']==0  || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input class="form-control" style="width:100px;" type="text" value="<?php echo $value;?>"
                            name="custom_field1[]"  id="customfield<?php echo $info2['id'];?>"
                            <?php if($info1000['en_recurringinvoices']==1){ echo "type='text' ";}else {echo "type='text'";}?>
                            tabindex="1" class="form-control teacher income_count customfield1 cf_class" value="<?php if($info3000['direct_grossdiscount']==1) { echo  mysqli_get_var("Select discount1 from direct_pricing where customer_type='$cid' && type='$sid' "); } ?>" /> </td>
                    <td <?php if($info4000['en_customfield2']==0  || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide printinghide"><input class="form-control" style="width:100px;" name="custom_field2[]" <?php echo $readonly;?>
                            id="customfield<?php echo $info2['id'];?>" type="text" tabindex="1" value="<?php echo $value_color; ?>"
                            class="form-control income_count customfield2 cf_class" /> </td>
                     <td <?php if($info4000['en_customfield3']==0 || $type_component==10) echo ' style="display:none;"'; ?>
    class="recurringhide printinghide">
    
    <?php if($info3000['en_sofasticatedfabrics'] == 1) { ?>
        <select class="form-control" style="width:100px;" name="custom_field3[]" <?php echo $readonly;?>
            id="customfield<?php echo $info2['id'];?>"
            tabindex="1"
            class="form-control income_count customfield3 cf_class">
            <option value="None">None</option>
            <option value="D-Disc">D-Disc</option>
            <option value="Yard Disc">Yard Disc</option>
            <option value="Meter-Disc">Meter-Disc</option>
            <option value="Pcs-Disc">Pcs-Disc</option>
        </select>
    <?php } else { ?>
        <input class="form-control" style="width:100px;" name="custom_field3[]" <?php echo $readonly;?>
            id="customfield<?php echo $info2['id'];?>"
            type="text"
            tabindex="1"
            class="form-control income_count customfield3 cf_class" />
    <?php } ?>
</td>
                    <td <?php if($info4000['en_customfield4']==0  || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide">
                        <?php
if($info3000['en_hafeeznsons']==1){
    $data4 = mysqli_query($conn,"SELECT *, v.id AS cid from vendor v, user u WHERE u.id=v.id $vv AND u.inactive=0  $vlimit_user $vlimit_zone   order by u.company_name") or die(mysqli_error($conn)); 
    echo "<select name='custom_field4[]' id='customfieldddd'.".$info2['id']."'   required  class=' form-control'   >";
    echo "<option value=''>Select a ".$info3000['distributer_vendor_label']."...</option>";
     while($info4 = mysqli_fetch_array( $data4 )) 
     { 
     if($info4['cid']==$vendorid) { echo "<option value='".$info4['cid']."' selected='selected' >".$info4['company_name'].' ( '.$info4['fname']." ".$info4['lname']." )</option>"; } else { echo "<option value='".$info4['cid']."' >".$info4['company_name'].' ( '.$info4['fname']." ".$info4['lname']." )</option>"; }
    }
    echo "</select>";
} else { 
?>
                        <input class="form-control" style="width:100px;" name="custom_field4[]" <?php echo $readonly;?>
                            id="customfieldddd<?php echo $info2['id'];?>" type="text" tabindex="1"
                            class="form-control income_count cf_class customfield4" />
                        <?php } ?>
                    </td>

<?php if($info3000['en_hafeeznsons'] == 1){   
$cf_width = mysqli_get_var("Select width from inventory where id = '$sid' ");
$cf_size = mysqli_get_var("Select size from inventory where id = '$sid' ");
} 
$hscode_value = mysqli_get_var("Select hs_code from inventory where id = '$sid' ");
?>

                    <td <?php if($info4000['en_customfield5']==0  || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input class="form-control income_count cf_width <?php if($info3000['en_eFBRinvoicing'] == 1){ echo 'hscode_class'; } ?> " name="custom_field5[]" <?php echo $readonly;?>
                            id="customfieldx<?php echo $info2['id'];?>" type="text" tabindex="1"
                              value="<?php if($info3000['en_eFBRinvoicing'] == 1){ echo $hscode_value; } else{ echo $cf_width; } ?>" readonly /> </td>

                     <td <?php if($info4000['en_customfield6']==0  || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input class="form-control" name="custom_field6[]" <?php echo $readonly;?>
                            id="customfieldx<?php echo $info2['id'];?>" type="text" tabindex="1"
                            class="form-control income_count cf_size cf_class" /> </td>
                            
                      <td <?php if($info4000['en_customfield7']==0  || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide"><input class="form-control" name="custom_field7[]" <?php echo $readonly;?>
                            id="customfieldx<?php echo $info2['id'];?>" type="text" tabindex="1"
                            class="form-control income_count customfield7 cf_class" /> </td>

                                             <td <?php if($info4000['en_customfield8']==0  || $type_component==10) echo ' style="display:none;"';  ?>
                        class="recurringhide">
                        <?php
if($info3000['en_hafeeznsons']==1){
    $data4 = mysqli_query($conn,"SELECT id, name from product_brands WHERE 1=1 ") or die(mysqli_error($conn)); 
    echo "<select name='custom_field8[]' id='customfieldddd'.".$info2['id']."'   required  class=' form-control'   >";
    echo "<option value=''>Select a Brand</option>";
     while($info4 = mysqli_fetch_array( $data4 )) 
     { 
      echo "<option value='".$info4['id']."' >".$info4['name']."</option>"; 
    }
    echo "</select>";
} else { 
?>
                        <input style="width:100px;" name="custom_field8[]" <?php echo $readonly;?>
                            id="customfieldddd<?php echo $info2['id'];?>" type="text" tabindex="1"
                            class="form-control income_count cf_class customfield8" />
                        <?php } ?>
                    </td> 

                       <?php if($info3000['en_hafeeznsons'] == 1){ ?>     

                       <input type="hidden" name="consumption[]" id="consumption<?php echo $info2['id']; ?>" class="consumption" />

                       <input type="hidden" name="total_consumption[]" id="total_consumption<?php echo $info2['id']; ?>" class="total_consumption" />       

                       <?php } ?>   

                    <?php  if($info4000['en_engineering']==1){
      ?>
                    <td class="pkg"><input readonly name="custom_field2[]" <?php echo $readonly;?> style="width:50px;"
                            id="customfieldd<?php echo $info2['id'];?>" type="number" step="0.0001" tabindex="1"
                            class="form-control pkg<?php echo $info2['id'];?> form-control income_count" size="2" / /></td>
                    <?php
        } ?>

                    <?php if($info1000['en_warehouse']==1) 
                    { 
                        // if($info4000['warehousefilter_invoice']==1){
                        //     $Only_warehouse = " AND id = '$wid' ";
                        // }else{
                        //     $Only_warehouse = " ";
                        // }
                    ?>
                    
                    <td><?php   $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse $lid ") or die(mysqli_error($conn)); 
                    echo "<select name='products_warehouse[]'  tabindex='1' class='form-control warehouse_charges teacher warehouse change6 qtychange22' required  >";
                    if($info3000['en_osaka']==1){echo "<option value=''>Select Warehouse</option>";}
                    while($info4 = mysqli_fetch_array( $data4 )) 
                    { 
                      if($info4['id']==$cwarehouse)
                      {
                        echo "<option value='".$info4['id']."' selected='sel
                        ected' >".$info4['name']."</option>"; 
                      }
                      else 
                      { 
                        echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
                      }
                    }
                    echo "</select>";
                    ?></td>
                    <?php } ?>

                        <?php if($info1000['en_inventorybatch']==1 && $info2000['batch_grnonly']==0 && 1==2) { //Batch not display
                            if($info3000['en_karachicables'] == 0){
                        ?>
                        <td  style="display:none"><div class="batchdiv">
                        <?php  $pid =  $info2['id']; 
                        if($info4000['en_allbatchdisplay']==0) { 
                        $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid' && type_component=0   order by batch_code ") or die(mysqli_error($conn)); 
                        } else { 
                        $data4 = mysqli_query($conn,"SELECT batch_code, MIN(id) as id   from inventory_batch where active=1  && type_component=0 group by batch_code  order by batch_code ") or die(mysqli_error($conn)); 
                        }
                        $ii=0;
                        // if($info2['is_batch'] != 1)
                        //   $class="hide";
                        echo "<select name='products_batch[]' id='loadBatchExpiry' tabindex='1' class='form-control teacher change7 reportselect $class loadBatchExpiry' required  >";
                        echo "<option value='0' selected >Select batch</option>";
                        while($info4 = mysqli_fetch_array( $data4 )) 
                        {

                            echo "<option value='".$info4['id']."' >".$info4['batch_code']."  </option>";
                        }
                        echo "</select>";
                        ?>
                        </div>
                        </td>
                        <?php } }?>
                        <?php if($info3000['datewise_batch']==1) { ?>   
                            <?php  if($info1000['en_expirydisplay']==1 && 1==2) {  //Batch not display
                        ?>
                        <td <?php //if($return==1) { echo ' style=" display:none;"'; } ?>><input class="form-control" type="date"
                        name="products_expiry[]" id="LoadExpiryHere" <?php  if($info2['is_batch']==0) { echo 'readonly';  }?> value=""
                        tabindex="1" <?php if($return==0) { ?> required <?php } ?>
                        class="change8 form-control LoadExpiryHere" readonly="readonly" id="<?php echo "expiry".$info2['id'];?>" /></td>
                        <?php //expiry7 class is removed from here 
                        } ?>

                    <?php } ?>


                    <?php if($info3000['en_item_area_shipping'] == 1){ 
    $customer_area = 0;
    ?>
                    <td>
                        <?php   
      //AND id IN (SELECT route FROM customer WHERE id = '$cid' )
      $data4 = mysqli_query($conn,"SELECT * FROM dsr_area where 1=1    ") or die(mysqli_error($conn)); 
          $cust_ship = mysqli_get_var("SELECT route FROM customer WHERE id = '$cid' ") ;
      echo "<select name='item_area[]' tabindex='1' class='form-control item_area' required  >";
      while($info4 = mysqli_fetch_array( $data4 )) {
        $selected='';
        if($cust_ship)
        {
          if($info4['id']==$cust_ship)
            $selected=' selected';
          echo "<option value='".$info4['id']."'  ".$selected.">".$info4['area_name']."</option>";
        }
      } 
      ?>
                    </td>
                    <?php
    $value = mysqli_get_var("SELECT day2 FROM salesman_area WHERE uid = '".$info2['id']."' AND aid = '".$cust_ship."'  ") 
    ?>
                    <td><input type="number" required step="0.0001" name="item_charges[]"
                            class="form-control item_charges" value="<?php echo $value; ?>"></td>
                    <?php } ?>



<?php if($info4000['batchselection_order']==1) { 
    if($return_form==1){
?>
<td>
  <div <?php if($info2['is_batch'] != 1){ echo "class='hide'"; } ?> >
         <?php if($info3000['open_batchgrn']==1) { ?>
         <input type="text" name="products_batch[]"
                        <?php  if($info2['is_batch']==0) { echo 'readonly';  }?>
                        value="<?php echo ($info2['is_batch'] == 0) ? 'No Batch' : date('Y-m-d'); ?>" tabindex="1"
                        class="qtyCheck change7 income_count batch7 form-control"
                        maxlength="<?php echo $info2000['max_batch_length']; ?>" required
                        id="<?php echo "batch".$info2['id'];?>" /></div> <input type="hidden" name="batch_old[]"
                    value="0" />
          <?php } else { ?>  
           <select name="products_batch[]"   class='teacher warehouse inventory3'  >
             <?php $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid' AND type_component = 0") or die(mysqli_error($conn));

            while($info4 = mysqli_fetch_array( $data4 ))
            {


                $batch_code = "";
                $batch_code2 = $info4['batch_code'];

                if($batch_code2!="") { $batch_code=$batch_code2;} else {
                if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
                }


                if($info2['batch_id']==$info4['id'])
                {
                echo "<option value='".$info4['id']."' selected >".$batch_code."</option>";
                }
                else {
                echo "<option value='".$info4['id']."' >".$batch_code."</option>";
                }

            }


            ?>
            </select>
        <?php } ?>
</div>   
</td>  
<?php
    }else{
    ?>
<td class="LoadBatchWarehouseWise"><?php 
$pid =  $info2['id']; 
if($info2['is_batch'] != 1) {
    echo "<input type='hidden' name='products_batch[]' value='0' />";
    echo "<span class='text-muted'>No Batch</span>";
} else {
  if($info4000['en_allbatchdisplay']==0) {
    if($info1000['batch_with_brand']==1){
        // $batch_name = mysqli_get_var('select name from product_brands where id = '.$info4['brand_id']);
        $data4 = mysqli_query($conn,"SELECT batch_code, MIN(id) as id, SUM(qty) as qty from inventory_batch where active=1 && prd_id='$pid'  && type_component=0 group by batch_code  order by batch_code ") or die(mysqli_error($conn)); 
    }else{
        $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid' && type_component=0   order by batch_code ") or die(mysqli_error($conn)); 
    }     
  } else { 
    
    $data4 = mysqli_query($conn,"SELECT batch_code, MIN(id) as id, SUM(qty) as qty from inventory_batch where active=1  && type_component=0 group by batch_code  order by batch_code ") or die(mysqli_error($conn)); 
   }


$ii=0;
$options_html = '';
$batch_options = array();
while($info4 = mysqli_fetch_array( $data4 )) 
{ 
    $batch_w_id = $info4['id'];
    
    if($ii==0) 
    { 
        $maxx = $info4['qty']; $unitc = $info4['unit_cost']; 
    }
  
    $ii=5;
    $batch_code = "";
    $batch_code2 = $info4['batch_code'];
  
    if($batch_code2!="") 
    { 
        $batch_code=$batch_code2;
    } 
    else 
    {
        if($info1000['month_code']==1) 
        {  
            $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  
        } 
        else 
        {   
            $batch_code= $info4['id']; 
        }
    }
 
    $selected = ' ';
    if($search_batch!==0){
        if($search_batch===$info4['batch_code']) { $selected = ' selected'; }
    }else{
        if($search3==$info4['id']) { $selected = ' selected'; }
    }

    $batch_qty = isset($info4['qty']) ? floatval($info4['qty']) : 0;
    if (!isset($warehouse_for_batch)) {
        $warehouse_for_batch = isset($sp) && $sp != '' ? $sp : (isset($cwarehouse) && $cwarehouse != '' ? $cwarehouse : $current_warehouse);
        if ($warehouse_for_batch == '') {
            $warehouse_for_batch = 0;
        }
    }

    $batch_qty = 0;
    if ($info4000['en_allbatchdisplay']==1 || $info1000['batch_with_brand']==1) {
        $batch_code_lookup = $info4['batch_code'];
        if ($batch_code_lookup != '') {
            $batch_ids = mysqli_query($conn,"SELECT id FROM inventory_batch WHERE prd_id='$pid' AND batch_code='$batch_code_lookup' AND type_component=0") or die(mysqli_error($conn));
            while($bid = mysqli_fetch_array($batch_ids)) {
                $batch_qty += get_available_quantity($pid, $warehouse_for_batch, 0, 0, $bid['id']);
            }
        } else {
            $batch_qty = get_available_quantity($pid, $warehouse_for_batch, 0, 0, $info4['id']);
        }
    } else {
        $batch_qty = get_available_quantity($pid, $warehouse_for_batch, 0, 0, $info4['id']);
    }

    $batch_options[] = array('id' => $info4['id'], 'code' => $info4['batch_code'], 'qty' => $batch_qty);
    $options_html .= "<option value='".$info4['id']."' ".$selected." >".$info4['batch_code']."</option>";
}

    $smart_last_batch_number = mysqli_get_var("SELECT MAX(CAST(batch_code AS UNSIGNED)) FROM inventory_batch WHERE prd_id='$pid' AND type_component=0 AND batch_code REGEXP '^[0-9]+$'");
    if($smart_last_batch_number=='') { $smart_last_batch_number = 0; }

if($gdn==1 && $info3000['en_smartbatch']==1 && ($info4000['grn_single_batch_qty']==1 || $info3000['open_batchgrn']==1)) {
    $batch_json = htmlspecialchars(json_encode($batch_options), ENT_QUOTES);
    ?>
    <button type="button" class="btn btn-default btn-sm smartbatch-open"
      data-item="<?php echo htmlspecialchars($info2['name']); ?>"
      data-lastbatch="<?php echo (int)$smart_last_batch_number; ?>">+</button>
    <span class="smartbatch-view text-muted" style="display:none;"></span>
    <input type="hidden" name="smartbatch_data[]" class="smartbatch-data" value="" />
    <input type="hidden" name="products_batch[]" class="batch" value="0" />
    <input type="hidden" class="smartbatch-options" value="<?php echo $batch_json; ?>" />
    <?php
} else {
    echo "<select name='products_batch[]' tabindex='1' class='abcd teacher reportselect inventory3 change7 qtychange22 batch ' required  >";
    echo $options_html;
    echo "</select>";
}
}
?></td>
<?php
    }//End Batch

    if($info1000['batch_with_brand']==1){
        if($return_form==1){
            ?>
                <td>
                <input type="text" name="products_batch_brand[]"
                    <?php  if($info2['is_batch']==0) { echo 'readonly';  }?>
                    value="" tabindex="1"
                    class="change71 income_count batch71 form-control"
                    id="<?php echo "products_batch_brand".$info2['id'];?>" />
                </td>
            <?php
        }else{
            ?>
                <td class="LoadBrandBatchWise"></td>
            <?php
        }
    }
?>



                    <?php if($info4000['en_inventorybatch2']==1) { ?><td><?php 
if($info2['is_batch'] != 1) {
    echo "<input type='hidden' name='products_batch2[]' value='0' />";
    echo "<span class='text-muted'>No Batch</span>";
} else {
 $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch2 where active=1  && type_component=0") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch2[]' tabindex='1' class='teacher reportselect inventory32 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
 $batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
}
?></td> <?php } ?>
                    <?php } ?>


                    <?php if($info2000['multiple_batch']==1 && $st!=1) { ?>
                    <td><input class="form-control" type="text" name="multi_batch[]" value="-" readonly="readonly" /> </td>
                    <?php } ?>
                    <?php if($info1000['en_embroidery']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from stitching_area") or die(mysqli_error($conn)); 
echo "<select name='products_sarea[]' id=sa".$info2['id']."  class='teacher income_count'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><input class="form-control" name="products_scolor[]" type="text" value="1" size="4" /> </td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from stitching_type") or die(mysqli_error($conn)); 
echo "<select name='products_stype[]' id=st".$info2['id']." class='teacher income_count stype'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from stitching_fusion") or die(mysqli_error($conn)); 
echo "<select name='products_sfusion[]' id=sf".$info2['id']." class='teacher income_count change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <?php } ?>


                    <!-- Basit -->
                    <!-- Three Dropdown Fields -->
<?php 
if($info4000['customfield_itemwise'] == 1) { 
?>
    <?php 
    $data4 = mysqli_query($conn, "SELECT `COL 16`, `COL 17`, `COL 18` FROM `table 811` WHERE `COL 15` = 1") or die(mysqli_error($conn)); 
    
    $info4 = mysqli_fetch_array($data4);
    
    // Removing '|' separator and creating arrays
    $col16_values = explode('|', $info4['COL 16']);
    $col17_values = explode('|', $info4['COL 17']);
    $col18_values = explode('|', $info4['COL 18']);
    ?>
    <!-- First Dropdown for COL 16 -->
    <td>
    <?php
    echo "<select name='col16[]' class='teacher col16 change6 form-control'>";
    foreach($col16_values as $value) {
        echo "<option value='".trim($value)."'>".trim($value)."</option>";
    }
    echo "</select>";?>
    </td>
    <td>
    <?php
    // Second Dropdown for COL 17
    echo "<select name='col17[]' class='teacher col17 change6 form-control'>";
    foreach($col17_values as $value) {
        echo "<option value='".trim($value)."'>".trim($value)."</option>";
    }
    echo "</select>";
    ?>
    </td>
    <td>
    <?php  
    // Third Dropdown for COL 18
    echo "<select name='col18[]' class='teacher col18 change6 form-control'>";
    foreach($col18_values as $value) {
        echo "<option value='".trim($value)."'>".trim($value)."</option>";
    }
    echo "</select>";
    ?>
  </td>
<?php 
} 
?>
       
<!--  -->


                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <input name="products_packing[]" type="number" min="0.1" step="0.001"
                            class="form-control new_packing change income_count totalorder readonly"
                            id="p<?php echo $info2['id'];?>" tabindex="1" value="<?php echo $info2['packing'];?>"
                            size="4" />
                        <input name="products_packing2[]" type="hidden" class="form-control edit-input change packing2 income_count"
                            id="pack2<?php echo $info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['packing2'];?>" />
                    </td>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>>
                        <?php
  // if($info)       
  if($info3000['en_snd_purchase']==1)
  {
   //echo " SELECT distributor_type from distributor where  id='$dist_id'";
    $data15 = mysqli_query($conn,"SELECT distributor_type from distributor where  id='$dist_id' ") or die(mysqli_error($conn));
    $info15 = mysqli_fetch_array( $data15 ); 
     $ttid=$info15['distributor_type'];
  }
  else
  {
   // echo "SELECT customer_type, customer_type2 from customer where  id='$cid'";
    $data15 = mysqli_query($conn,"SELECT customer_type, customer_type2 from customer where  id='$cid' ") or die(mysqli_error($conn));
    $info15 = mysqli_fetch_array( $data15 ); 
     $ttid=$info15['customer_type'];
   $ttid2=$info15['customer_type2'];

   // for sub customers
   $data15 = mysqli_query($conn,"SELECT customer_type from sub_customer where  id='$subc_id' ") or die(mysqli_error($conn));
    $info15 = mysqli_fetch_array( $data15 ); 
    $subc_customertype=$info15['customer_type'];
  }
  $ppid=$info2['id'];
  $ctp_pid = $ttid;
  if($subc_id != 0 && $info3000['en_subcustomer_pricing'] == 1 && $subc_customertype!='')
  {
      $ctp_pid = $subc_customertype;
  }
  $data_ctp = mysqli_query($conn,"SELECT foc, disc_type, disc_amount, disc_percentage, trade_offer, advance_tax, further_tax FROM customer_type_pricing where pid='$ctp_pid' AND tid='$ppid' && company_id = '$current_company' order by id desc limit 1") or die(mysqli_error($conn));
  $info_ctp = mysqli_fetch_array($data_ctp);
  $num_rows_ctp = mysqli_num_rows($data_ctp);
  $ctp_foc = ($num_rows_ctp!=0 && $info_ctp['foc']!=='') ? $info_ctp['foc'] : 0;
  $ctp_disc_type = ($num_rows_ctp!=0 && $info_ctp['disc_type']!=='') ? (int)$info_ctp['disc_type'] : 0;
  $ctp_disc_amount = ($num_rows_ctp!=0 && $info_ctp['disc_amount']!=='') ? $info_ctp['disc_amount'] : 0;
  $ctp_disc_percentage = ($num_rows_ctp!=0 && $info_ctp['disc_percentage']!=='') ? $info_ctp['disc_percentage'] : 0;
  $ctp_trade_offer = ($num_rows_ctp!=0 && $info_ctp['trade_offer']!=='') ? $info_ctp['trade_offer'] : 0;
  $ctp_advance_tax = ($num_rows_ctp!=0 && $info_ctp['advance_tax']!=='') ? $info_ctp['advance_tax'] : 0;
  $ctp_further_tax = ($num_rows_ctp!=0 && $info_ctp['further_tax']!=='') ? $info_ctp['further_tax'] : 0;
//multipricingratecheck
if($userdefault_price=='0'){
   $sale_multiprice = $infomultiprice1000['sale_price'];
  ?>
                        <input <?php echo $readonly;?> id="<?php echo "pp".$info2['id'];?>" tabindex="1"
                            name="unitcos[]" step="0.0001" type="number" required
                            value="<?php echo  $infomultiprice1000['sale_price'];?>"
                            class="form-control edit-input <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> new_rate income_count chk8ange totalorder"
                            size="4" min="0" />
                        <?php
}else{
 $data15 = mysqli_query($conn,"SELECT price, mrp_price from customer_type_pricing where pid='$ttid' AND tid='$ppid' && company_id = '$current_company' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input id="<?php echo "pp".$info2['id'];?>" <?php echo $readonly;?> tabindex="1"
                            name="unitcos[]" min="0" step="0.0001" type="number" required
                            value="<?php echo $info15['price']; $mpp = $info15['mrp_price']; ?>"
                            class="form-control edit-input <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> income_count chk8ange totalorder"
                            size="4" />
                        <?php } else if($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {

if($subc_id != 0 && $info3000['en_subcustomer_pricing'] == 1)
{
    $data15 = mysqli_query($conn,"SELECT price, mrp_price from customer_type_pricing where pid='$subc_customertype' AND tid='$ppid' && company_id = '$current_company' ") or die(mysqli_error($conn));
    $info15 = mysqli_fetch_array( $data15 ); 
    $num_rows = mysqli_num_rows($data15);
    // echo "Price: ".$info15['price'];
    // echo "Subc: ".$subc_id;
    ?>
    <input id="<?php echo "pp".$info2['id'];?>" <?php echo $readonly;?> tabindex="1"
    name="unitcos[]" min="0" step="0.0001" type="number" required
    value="<?php echo $info15['price']; $mpp = $info15['mrp_price']; ?>"
    class="form-control aaaaaa edit-input <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> income_count chk8ange totalorder"
    size="4" /> <?php
}

else
{


  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100; 
$discount4=$info200['discount4']/100; 
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
$discount4=1-$discount4;  
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info200['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x;
//rate
    ?>
<!-- Sohail -->
<?php

// Basit
if($info3000['en_buraqcorp']==1)
{
    $c_pid = $info2['id'];
    $calculated_mrp_price = itemcost($c_pid, 0, 1, 0, '', resolve_itemcost_date(), '');

    if($currency_rate_f == '' || $currency_rate_f == 0){
        $currency_rate_f = 1;
    }
    if($currencymargin=='' || $currencymargin==0){
        $currencymargin = 0;
    }
    
    $calculated_unit_cos = ($calculated_mrp_price / $currency_rate_f) * (1 + ($currencymargin/100));
    $calculated_unit_cos = round($calculated_unit_cos, 2);
    $calculated_mrp_price = round($calculated_mrp_price, 2);
}
else
{
    $calculated_unit_cos = $price;
    $calculated_mrp_price = $info2['mrp_price'];
}

// if($info3000['en_buraqcorp']==1){
    
//     $c_pid = $info2['id'];
//     $calculated_mrp_price = itemcost($c_pid, 0, 1, 0, '', resolve_itemcost_date(), '');

//     $calculated_unit_cos = $calculated_mrp_price;
//     $calculated_unit_cos_f = $calculated_unit_cos/$currency_rate_f;

//     if($currencymargin=='' || $currencymargin==0){
//         $currencymargin = 1;
//     }
//     $calculated_unit_cos = $calculated_unit_cos_f*($currencymargin/100);
//     $calculated_unit_cos = $calculated_unit_cos+$calculated_unit_cos_f;

//     $calculated_unit_cos = round($calculated_unit_cos,2);
//     $calculated_mrp_price = round($calculated_mrp_price,2);
//     // $calculated_mrp_price = $calculated_unit_cos_f;
//     // echo "PRD_id".$c_pid;
// }else{
//     $calculated_unit_cos = $price;
//     $calculated_mrp_price = $info2['mrp_price'];
// }
?>

                        <input <?php echo $readonly;?> id="<?php echo "pp".$info2['id'];?>" tabindex="1"
                            name="unitcos[]" min="0" step="0.0001" type="number" required value="<?php echo $calculated_unit_cos;?>"
                            class=" form-control <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } }
else if($info4000['en_direct_customer_pricing_discount']==1){ ?>
                        <input <?php echo $readonly;?> id="<?php echo "pp".$info2['id'];?>" tabindex="1"
                            name="unitcos[]" min="0" step="0.0001" type="number" required value="<?php echo  $finalprice; ?>"
                            class="form-control  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> new_rate income_count chk8ange totalorder"
                            size="4" />
                        <?php }
 else {
// here we go
  ?>
                        <?php
 if($info4000['export_costing']==1){
   $sql299= "SELECT fob_currency from export_costing_details d where export_costing_id IN(SELECT id from export_costing e where  e.warehouse='$wid' and e.customer='$cid' ) && item_id='$ppid' order by id desc limit 1";        
   $res299=mysqli_query($conn,$sql299);
   $info299=mysqli_fetch_array($res299);
   $saleprice= $info299['fob_currency'];
     $currency_rate =mysqli_get_var("select currency_rate from export_costing e where  e.customer='$cid' and e.warehouse='$wid'  order by date DESC limit 1 ");
    $currency =mysqli_get_var("select currency from export_costing e where  e.customer='$cid' and e.warehouse='$wid'  order by date DESC limit 1 "); 
 ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" step="0.00001" min="0" 
                            type="number" required value="<?php echo $saleprice; ?>"
                            class=" form-control <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> new_rate income_count chk8ange totalorder"
                            size="4" />
                        <script type="text/javascript">
                        $("#currency").val(<?php echo $currency; ?>);
                        $(".currency_rate").val(<?php echo $currency_rate; ?>);
                        </script>
                        <?php }else{
                             // Hamza
                            if($pricing_type){
                               if ($pricing_type == '1') { 
                                    $type = 'type_1';
                                } elseif ($pricing_type == '2') { 
                                    $type = 'type_2';
                                } elseif ($pricing_type == '3') { 
                                    $type = 'type_3';
                                } elseif ($pricing_type == '4') { 
                                    $type = 'type_4';
                                }
                                $sid=test_input($_POST['sid2']);
                                $price_value = mysqli_get_var("SELECT $type FROM customer_product Where customer_id = $cid AND item_id = $sid");
                            }
                            // Hamza end
?>                      

<!-- Sohail -->
<?php
if($info3000['en_buraqcorp']==1){
    
    $c_pid = $info2['id'];
    $calculated_mrp_price = itemcost($c_pid, 0, 1, 0, '', resolve_itemcost_date(), '');

    $calculated_unit_cos = $calculated_mrp_price;
    $calculated_unit_cos_f = $calculated_unit_cos/$currency_rate_f;

    if($currencymargin=='' || $currencymargin==0){
        $currencymargin = 1;
    }
    $calculated_unit_cos = $calculated_unit_cos_f*($currencymargin/100);
    $calculated_unit_cos = $calculated_unit_cos+$calculated_unit_cos_f;

    $calculated_unit_cos = round($calculated_unit_cos,2);
    $calculated_mrp_price = round($calculated_mrp_price,2);
    // $calculated_mrp_price = $calculated_unit_cos_f;
    // echo "PRD_id".$c_pid;
}else{
    $calculated_unit_cos = $info2['sale_price'];
    $calculated_mrp_price = $info2['mrp_price'];
}
?>
<input <?php echo $readonly;?> id="<?php echo "pp".$info2['id'];?>" tabindex="1"
                            name="unitcos[]" min="0" type="number" step="0.00001" required
                            value="<?php echo ($pricing_type ? $price_value : $calculated_unit_cos); ?>"
                            class="form-control  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> new_rate income_count chk8ange totalorder"
                            size="4" />
                        <?php }  
}
 ?>
                        <?php
     if($info4000['separate_mrpcolumn']==0 && 1==2)
     {
          ?>
                        <input name="mrp_price[]" size="4" type="hidden" class="form-control edit-input income_count totalorder"
                            id="<?php echo "mrp".$info2['id'];?>" tabindex="1"
                            value="<?php if($mpp!='' && $mpp!=0) { echo $mpp;  } else { echo $info2['mrp_price']; } $mpp=''; ?>" />
                        <?php
     }
  }
     ?>
                        <?php 
$direct_invoicediscount = mysqli_get_var("Select direct_invoicediscount from customer where id='$cid'");
 $direct_invoicetaxtype = mysqli_get_var("Select direct_invoicetaxtype from customer where id='$cid'");
 ?>
                        <input name="tax_mrp[]" size="4" type="hidden" class="form-control edit-input income_count totalorder"
                            id="<?php echo "mrptax".$info2['id'];?>" tabindex="1"
                            value="<?php if($direct_invoicetaxtype==0) { echo $info2['tax_mrp']; } else if($direct_invoicetaxtype==1) { echo 0;    } else { echo 1; } ?>" />
                    </td>
                    <?php if($info4000['separate_mrpcolumn']==1) { 

if($userdefault_price=='0'){
   $mrp_multiprice = $infomultiprice1000['mrp_price'];

  
  ?>
                       
                            <td>
                        <input name="mrp_price[]" size="4" type="number" required step="0.0001"
                            class="form-control edit-input income_count totalorder" id="<?php echo "mrp".$info2['id'];?>"
                            tabindex="1"
                            value="<?php if($mrp_multiprice!='' && $mrp_multiprice!=0) { echo $mrp_multiprice;  } else { echo $info2['mrp_price']; } $mpp=''; ?>" />
                    </td>
                        <?php
}else{  ?> 
<?php
if($info3000['en_buraqcorp']==1){
    
    $c_pid = $info2['id'];
    $calculated_mrp_price = itemcost($c_pid, 0, 1, 0, '', resolve_itemcost_date(), '');

    $calculated_unit_cos = $calculated_mrp_price;
    $calculated_unit_cos_f = $calculated_unit_cos/$currency_rate_f;

    if($currencymargin=='' || $currencymargin==0){
        $currencymargin = 1;
    }
    $calculated_unit_cos = $calculated_unit_cos_f*($currencymargin/100);
    $calculated_unit_cos = $calculated_unit_cos+$calculated_unit_cos_f;

    $calculated_unit_cos = round($calculated_unit_cos,2);
    $calculated_mrp_price = round($calculated_mrp_price,2);
    // $calculated_mrp_price = $calculated_unit_cos_f;
    // echo "PRD_id".$c_pid;
}else{
    $calculated_unit_cos = $info2['sale_price'];
    $calculated_mrp_price = $info2['mrp_price'];
}
?>
                    <td>
                        <input name="mrp_price[]" size="4" type="number" required step="0.0001"
                            class="form-control edit-input income_count totalorder" id="<?php echo "mrp".$info2['id'];?>"
                            tabindex="1"
                            value="<?php if($mpp!='' && $mpp!=0) { echo $mpp;  } else { echo $calculated_mrp_price; } $mpp=''; ?>" />
                    </td>
                    <?php }
}else{
    ?>
    <td style="display:none">
    <input name="mrp_price[]" size="4" type="hidden" class="form-control edit-input income_count totalorder"
        id="<?php echo "mrp".$info2['id'];?>" tabindex="1"
        value="<?php if($mpp!='' && $mpp!=0) { echo $mpp;  } else { echo $info2['mrp_price']; } $mpp=''; ?>" />
    </td>
    <?php
}//closepricing
             ?>
                    <?php if($info2000['en_sarhad'] == 1 || $info4000['itemmulti_unit']==1){ ?>
                    <input name="prd_hidden[]" type="hidden" class="prd_hidden" value="<?php echo $info2['id'];?>" />
                    <input name="packing_hidden[]" type="hidden" class="packing_hidden"
                        value="<?php echo $info2['packing'];?>" />
                    <td>
                        <?php 
   $idmain = $info2['id'];
  $single_unit = mysqli_get_var("SELECT unit FROM inventory WHERE id='".$info2['id']."' ");
  $data4 = mysqli_query($conn,"SELECT * FROM product_unit WHERE id IN (SELECT unit FROM multiple_product_unit WHERE pid = '".$info2['id']."' )  ") or die(mysqli_error($conn)); 
  echo "<select name='munit[]'  id='mnunit$idmain' required class=' munit form-control'   >";
  //echo "<option value='0' >Select Product Unit</option>";
  while($info4 = mysqli_fetch_array( $data4 )){ 
    $selected = '';
    if($single_unit == $info4['id'])
      $selected = 'selected';
    echo "<option value='".$info4['id']."' $selected >".$info4['name']."</option>";
  }
  echo "</select>";
  ?></td>
                    <td style="display:none;"><input  name="con_rate[]" value="1" size="4" class="con_rate form-control" id="" /></td>
                    <?php } ?>
                    <td <?php  if($info4000['en_tradelink']==0) { echo ' style=" display:none;"'; } ?>
                        class="recurringhide"><input  style="width:100px;" name="stich_area[]" type="number"
                            class='form-control  teacher income_count' value="<?php echo $info2['stich_area']; ?>"
                            step="0.0001" id="<?php echo "cusarea".$info2['id'];?>" /> </td>
                    <td <?php  if($info4000['en_tradelink']==0) { echo ' style=" display:none;"'; } ?>
                        class="recurringhide"><input style="width:100px;" name="app_tp[]" type="number"
                            class='form-control  teacher income_count' value="<?php echo $info2['app_tp']; ?>"
                            step="0.0001" id="<?php echo "cuspackk".$info2['id'];?>" /> </td>
                    <td <?php  if($info4000['en_tradelink']==0) { echo ' style=" display:none;"'; } ?>
                        class="recurringhide"><input name="stich_type[]" type="number"
                            class='form-control  teacher income_count' value="<?php echo $info2['stich_type']; ?>"
                            step="0.0001" id="<?php echo "cusstich".$info2['id'];?>" /> </td>
                    <td
                        <?php  if($info2000['en_ricetrade']==0) { echo ' style=" display:none;"'; } ?>>
                        <input name="packing2[]" type="number" step="0.0001" class=' form-control teacher  packing_22  packing2 income_count'
                            value="<?php echo $info2['pac2']; ?>" id="<?php echo "packk".$info2['id'];?>" />
                    </td>
                    <td <?php  if($info2000['invoice_cartonrate']==0) { echo ' style=" display:none;"'; } ?>>
                        <select name='rate_in_carton[]' class='form-control teacher income_count case2qty'
                            id="<?php echo "ric".$info2['id'];?>">
                            <option value='0'>Default</option>
                            <?php if($info4000['en_engineering']==0){ ?>
                            <option value='1'><?php echo $info1000['packing_label']; ?></option>
                            <?php } ?>
                            <option value='2'><?php echo $info1000['multi_unit_label']; ?></option>
                            <option value='3'><?php echo $info2000['customfield1_display'];  ?></option>
                        </select>
                    </td>
                    <?php
/***----start saqib---------*/
 if($info1000['salesman_mode']==1){
  if($info1000['customer_discount1']==1){
if($num_rows_ctp!=0 && $ctp_disc_type==2){
  $infomultiprice1000['disc1_value'] = $ctp_disc_percentage;
}
   if($infomultiprice1000['disc1_value']>0){ 
    ?>
                    <td>
                        <input name="products_discount[]" type="number" step="0.0001" class=" edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id']?>" tabindex="1"
                            value="<?php  echo $infomultiprice1000['disc1_value']; ?>" size="4" />
                    </td>
                    <?php  }else{ ?>
                    <td>
                        <input name="products_discount[]" type="number" step="0.0001" class=" edit-input income_count totalorder "
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $direct_invoicediscount; ?>" size="4" />
                    </td>
                    <?php
}
}else{
?>
                    <input name="products_discount[]" type="hidden" step="0.0001" class=" edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $subcustomerdiscount; ?>" size="4" />
                    <?php
}
//closedist1_sales
if($info1000['customer_discount2']==1){
  if($infomultiprice1000['disc2_value']>0){ 
   ?>
                    <td>
                        <input name="products_discount2[]" type="number" required step="0.0001"
                            class="form-control edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>"
                            tabindex="1" value="<?php  echo $infomultiprice1000['disc2_value']; ?>" size="4" />
                    </td>
                    <?php  }else{ ?>
                    <td><input name="products_discount2[]" type="number" required step="0.0001"
                            class="form-control edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>"
                            tabindex="1" value="0" size="4" min="0" />
                    </td>
                    <?php
}
}else{ ?>
                    <input name="products_discount2[]" type="hidden" class="form-control edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php
}//closedist2_sales
 if($info1000['customer_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount4 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows_ctp!=0){
  $num_rows = 1;
  $info15['discount'] = $ctp_trade_offer;
}
if($num_rows!=0) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount4[]"
                            type="text" class="form-control edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount4[]"
                            type="text" class="form-control edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount4[]"
                            type="text" class="form-control edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount4[]" type="hidden" class="form-control edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }//closedist4
 if($info2000['customer_foc']==1  ) { 
    $sid = $info2['id'];
   // echo "SELECT discount_percentage FROM amount_discount where min_amount='$sid' ";
  $foc = mysqli_get_var("SELECT discount_percentage FROM amount_discount where min_amount='$sid' ");
  $foc_value = mysqli_get_var("SELECT discount_value FROM amount_discount where min_amount='$sid' ");
  if($foc=="") {  $foc=0; }
  if($foc_value=="") {  $foc_value=0; }
  if($num_rows_ctp!=0){
    $foc = $ctp_foc;
  }
 ?>
                    <td>
                        <input type="number" name="products_foc[]" value="<?php echo $foc; ?>" class="agggg form-control foc "
                            id="<?php echo "pfoc".$info2['id'];?>" required size="4" />
                        <input type="hidden" class="foc_scheme" id="<?php echo "pfoc_scheme".$info2['id'];?>" value="<?php echo $foc; ?>" />
                        <input type="hidden" class="foc_value" id="<?php echo "pfoc_value".$info2['id'];?>" value="<?php echo $foc_value; ?>" />
                    </td>
                    <?php }
else { 
    ?>
                    <input type="hidden" name="products_foc[]" value="0" class="form-control foc income_count"
                        id="<?php echo "pfoc".$info2['id'];?>" required size="4" />
                    <?php }
if($info1000['customer_discount3']==1){
  $inv_tradeoffer = (float)$info2['tradeoffer'];
  if($inv_tradeoffer>0){
   ?>
                    <td>
                        <input name="products_discount3[]" type="number" class="form-control edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $inv_tradeoffer; ?>" step="0.0001" size="4"  />
                    </td>
                    <?php
  }
  else if($num_rows_ctp!=0 && (float)$ctp_trade_offer>0){ 
   ?>
                    <td>
                        <input name="products_discount3[]" type="number" class="form-control edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo is_numeric($ctp_trade_offer) ? $ctp_trade_offer : 0; ?>" step="0.0001" size="4"  />
                    </td>
                    <?php
  }
  else{
  if($infomultiprice1000['trade_offer']>0){ 
   ?>
                    <td>
                        <input name="products_discount3[]" type="number" class="form-control edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo is_numeric($infomultiprice1000['trade_offer']) ? $infomultiprice1000['trade_offer'] : 0; ?>" step="0.0001" size="4"  />
                    </td>
                    <?php  }else{ 
                      
                      $c_dis = mysqli_get_var("SELECT discount from customer_item where prd_id='$sid' AND cid='$cid' ");  
                      if($c_dis === false || $c_dis === "" || $c_dis === null || !is_numeric($c_dis) || (float)$c_dis<=0)
                      {
                        $c_dis = $info2['tradeoffer'];
                      }
                      if($c_dis === false || $c_dis === "" || $c_dis === null || !is_numeric($c_dis))
                      {
                        $c_dis=0;
                      }

                      ?>
                    <td>
                        <input name="products_discount3[]" required min="0" type="number" class="form-control edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="<?php echo is_numeric($c_dis) ? $c_dis : 0; ?>" step="0.0001" size="4" />
                    </td>
                    <?php
}
}
}
else{ ?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" step="0.0001" size="4" />
                    <?php
}//closedist3_sales
if($info2000['en_discount5']==1) { ?>
                    <td><input type="text" name="discount5[]" class="form-control edit-input income_count"
                            id="<?php echo "pppl".$info2['id'];?>" tabindex="1" value="<?php  echo $infomultiprice1000['disc3_value']; ?>" required size="4" /> </td>
                    <?php }
if($info1000['customer_scheme']==1) { 
  if($infomultiprice1000['scheme']>0){ 
   ?>
                    <td>
                        <input name="products_scheme[]" type="text"
                            class="form-control edit-input income_count totalorder scheme_o remaingcal"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1"
                            value="<?php  echo $infomultiprice1000['scheme']; ?>" size="4" />
                    </td>
                    <?php  }else{ ?>
                    <td><input name="products_scheme[]" type="text"
                            class="form-control edit-input income_count totalorder scheme_o remaingcal"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php
}
}
else{ ?>
                    <input name="products_scheme[]" type="hidden"
                        class="form-control edit-input income_count totalorder scheme_o remaingcal"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php
 }
 //closescheme_sales
  if($info3000['customer_scheme_value']==1) { 
  if($infomultiprice1000['scheme_value_amount']>0){ 
   ?>
                    <td>
                        <input name="products_scheme_value[]" type="text"
                            class=" edit-input income_count  scheme_v remaingcal"
                            id="<?php echo "sv".$info2['id'];?>" tabindex="1"
                            value="<?php  echo $infomultiprice1000['scheme_value_amount']; ?>" size="4" />
                    </td>
                    <?php  }else{ ?>
                    <td><input name="products_scheme_value[]" type="text"
                            class=" edit-input income_count  scheme_v remaingcal"
                            id="<?php echo "sv".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php
}
}
else{ ?>
                    <input name="products_scheme_value[]" type="hidden"
                        class=" edit-input income_count  scheme_v remaingcal"
                        id="<?php echo "sv".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php
 }
 
?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <input name="products_scheme_qty[]" type="hidden"
                            class="form-control edit-input income_count totalorder scheme_valcal"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="" size="4" />
                        <input name="products_pcs[]" type="number" step="0.0001"
                            <?php 
                                if($info1000['inventory_limit']==1 && ($info1000['gdninventory_limit']==1 || $gdn==1)) {
                                    if($info1000['en_inventorybatch']==1) { echo 'max="'.$maxx.'"'; } 
                                    else{ 
                                        if($info1000['salesman_mode']==1) { echo 'max="'.$product_qta.'"'; } 
                                        else { echo 'max="'.$info2['qty'].'"'; } 
                                    }
                                } 
                            ?>
                            class="form-control total_pcs" id="<?php echo "t".$info2['id'];?>" min="0" size="4" />
                    </td>
  
  <?php if(1==1){   ?>     
     <td  <?php if($info4000['display_taxamount']==0){ echo ' style="display:none;"';    }  ?> >
 <input name="display_totaltax2[]" type="text" class="form-control income_count display_totaltax2" id="<?php echo "ppptttt".$info2['id'];?>"    value="0" size="4" readonly/>
</td>
<?php } ?>              
 
                    <?php  /*closeschemeqty_sales */   ?>
                    <?php if($info1000['customer_tax1']==1) { 
$tax1_value = $infomultiprice1000['tax1_value'];
$tax1_value1 = ($customer_filer=='1')?$tax1filer_value:$tax1_value;
  if($infomultiprice1000['tax1_value']>0){ 
   ?>
                    <td>
                        <input name="products_tax[]" type="number" required step="0.0001"
                            class="form-control edit-input income_count" id="<?php echo "pppp".$info2['id'];?>" tabindex="1"
                            value="<?php  echo $tax1_value1; ?>" size="4" readonly="readonly" />
                    </td>
                    <?php  }else{ ?>

                    <?php if($info2['direct_invoicetax']!=-1 ) { ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>>
                        <input name="products_tax[]" type="number" required step="0.0001"
                            class="edit-input income_count" tabindex="1" id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php   echo $info2['direct_invoicetax']; ?>" size="4" readonly="readonly" />
                    </td>
                    <?php } else {?>
                    <td>
                        <input name="products_tax[]" type="number" required step="0.0001"
                            class="form-control edit-input income_count" id="<?php echo "pppp".$info2['id'];?>" tabindex="1"
                            value="0" size="4" readonly="readonly" />
                    </td>
                    <?php }
}
}else{ ?>
                    <input name="products_tax[]" type="hidden" required step="0.0001" class="form-control edit-input income_count"
                        id="<?php echo "pppp".$info2['id'];?>" tabindex="1" value="0" size="4" readonly="readonly" />
                    <?php
   }
/*closetax1_sales */   ?>
                    <?php if($info1000['customer_tax2']==1) { 
$tax2_value = $infomultiprice1000['tax2_value'];
if($num_rows_ctp!=0){
  $infomultiprice1000['tax2_value'] = $ctp_advance_tax;
  $tax2_value = $infomultiprice1000['tax2_value'];
}
if($num_rows_ctp!=0){
  $tax2_value2 = $tax2_value;
} else {
  $tax2_value2 = ($customer_filer=='1')?$tax2filer_value:$tax2_value;
}
if($infomultiprice1000['tax2_value']>0){ 
 ?>
                    <td>
                        <input name="products_tax2[]" type="number" step="0.0001" required
                            class="form-control edit-input income_count" id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php  echo $tax2_value2; ?>" size="4" readonly="readonly" />
                    </td>
                    <?php  }else{ ?>
                    <?php if($cdirect_invoicetax2!=-1 ) { ?>
                    <td>
                        <input name="products_tax2[]" type="number" step="0.0001" required
                            class="form-control edit-input income_count" id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php  echo $cdirect_invoicetax2; ?>" size="4" readonly="readonly" />
                    </td>
                    <?php } else {?>
                    <td>
                        <input name="products_tax2[]" type="number" step="0.0001" required
                            class="form-control edit-input income_count" id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php  echo '0'; ?>" size="4" readonly="readonly" />
                    </td>
                    <?php }
}
}else{ ?>
                    <input name="products_tax2[]" type="hidden" class="form-control edit-input income_count"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="<?php  echo '0'; ?>" size="4"
                        readonly="readonly" />
                    <?php
     }
/*closetax2_sales */   ?>
                    <?php if($info1000['customer_tax3']==1) { 
$tax3_value = $infomultiprice1000['tax3_value'];
if($num_rows_ctp!=0){
  $infomultiprice1000['tax3_value'] = $ctp_further_tax;
  $tax3_value = $infomultiprice1000['tax3_value'];
}
if($num_rows_ctp!=0){
  $tax3_value3 = $tax3_value;
} else {
  $tax3_value3 =($customer_filer=='1')?$tax3filer_value:$tax3_value;
}
if($infomultiprice1000['tax3_value']>0){ 
 ?>
                    <td>
                        <input name="products_tax3[]" type="text" class="form-control edit-input income_count"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="<?php  echo $tax3_value3; ?>"
                            size="4" readonly="readonly" />
                    </td>
                    <?php  }else{ ?>
                    <?php if($idirect_invoicetax3!=-1 ) { ?>
                    <td>
                        <input name="products_tax3[]" type="text" class="form-control edit-input income_count"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="<?php  echo $idirect_invoicetax3; ?>"
                            size="4" readonly="readonly" />
                    </td>
                    <?php } else if($cdirect_invoicetax3!=-1 ) { ?>
                    <td>
                        <input name="products_tax3[]" type="text" class="form-control edit-input income_count"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="<?php  echo $cdirect_invoicetax3; ?>"
                            size="4" readonly="readonly" />
                    </td>
                    <?php } else if($info3000['en_strn_base_tax3']==1 && !$csaletax_no){?>
                    <td>
                        <input name="products_tax3[]" type="text" class="form-control edit-input income_count"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="<?php  echo $info3000['strn_base_tax3_value']; ?>"
                            size="4" readonly="readonly" />
                    </td>
                    <?php } else {?>
                    <td>
                        <input name="products_tax3[]" type="text" class="form-control edit-input income_count"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="<?php  echo '0'; ?>" size="4"
                            readonly="readonly" />
                    </td>
                    <?php }
}
}else{ ?>
                    <input name="products_tax3[]" type="hidden" class="form-control edit-input income_count"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="<?php  echo '0'; ?>" size="4"
                        readonly="readonly" />
                    <?php
       }
/*closetax3_sales */   ?>
                    <?php
}//close salesmode
else{
///here need to put foc
 ?>
                    <?php if($info1000['customer_discount1']==1) { 
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from cb_discount where cid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
//echo "SELECT discount from customer_type_discount1 where pid='$ttid' AND tid='$ppid'";
$data17 = mysqli_query($conn,"SELECT discount from customer_type_discount1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($num_rows_ctp!=0 && $ctp_disc_type==2){
  $discount1_reserve = '';
  $direct_invoicediscount = -1;
  $info2['direct_invoicediscount1'] = -1;
  $num_rows = 1;
  $num_rows2 = 0;
  $info15['discount'] = $ctp_disc_percentage;
}
//   Sohail Customer Discount check - 3rd time
if($discount1_reserve!='' && $discount1_reserve!=0){
    //$discount1_reserve;
  //$info17['discount'];
  $customer_discount1_reserve=$info17['discount']-$discount1_reserve;
  if($customer_discount1_reserve<0)  {   $customer_discount1_reserve=0; }
   ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount[]"
                            type="number" step="0.0001" class="form-control edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $customer_discount1_reserve;?>" size="4" /></td>
                    <?php }
else if($info2['direct_invoicediscount1']!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount[]"
                            type="number" step="0.0001" class="form-control edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['direct_invoicediscount1'];?>" size="4" /></td>
                    <?php 
}
else if($info3000['en_elixirbeauty']) {
     $bid=$info2['brand_id'];
    $binv_discount = mysqli_get_var("Select binv_discount from customer_brandlimit WHERE customer_id='$cid' && brand_id='$bid' "); 
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount[]"
                            type="number" step="0.0001" class="form-control edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $binv_discount;?>"
                            size="4" /></td>
                    <?php 
}
else if($direct_invoicediscount!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount[]"
                            type="number" step="0.0001" class="form-control edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $direct_invoicediscount;?>" size="4" /></td>
                    <?php 
}
else if($num_rows!=0 && $info15['discount']!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount[]"
                            type="number" step="0.0001" class="form-control edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                            size="4" /></td>
                    <?php }
else if($num_rows2!=0) {
?>
                      <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount[]"
                            type="number" step="0.0001" class=" edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $subcustomerdiscount; ?>" size="4" /></td>
                    <?php } 
                   
 else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount[]"
                            type="number" step="0.0001" class="form-control edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount[]"
                            type="number" step="0.0001" class="form-control edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } 
 }
 else {
if($subcustomerdiscount!="" && $subcustomerdiscount!=0){
  $subcustomerdiscount=$subcustomerdiscount;
}
else{
$subcustomerdiscount=0;
}
  ?>
                    <input name="products_discount[]" type="hidden" class="form-control edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" step="0.0001" tabindex="1" value="<?php echo $subcustomerdiscount; ?>"
                        size="4" />
                    <?php }  //closedist1


 if($info1000['customer_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);

$direct_invoiceadditionaldiscount = mysqli_get_var("Select direct_invoiceadditionaldiscount from customer where id='$cid'");
$direct_invoiceextradiscount = mysqli_get_var("Select direct_invoiceextradiscount from customer where id='$cid'");

if($direct_invoiceadditionaldiscount!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount2[]"
                            type="number" required step="0.0001" class="form-control edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $direct_invoiceadditionaldiscount;?>" size="4" /></td>
                    <?php 
}

else if($info4000['alternate_customertype']==1 )  {
   $disc22 = mysqli_get_var("SELECT discount from customer_type_discount2 where pid='$ttid2' AND tid='$ppid' "); 
   if($disc22=='' || $disc22=='-1' ) $disc22=0;
  ?>
                    <td><input name="products_discount2[]" type="number" required step="0.0001"
                            class="form-control edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>"
                            tabindex="1" value="<?php echo $disc22;?>" size="4" /></td>
                    <?php }
 else if($discount2_reserve!=''){
  $customer_discount2_reserve=$info17['discount']-$discount2_reserve;
  if($customer_discount2_reserve<0)  {   $customer_discount2_reserve=0; }
   ?>
                    <td><input name="products_discount2[]" type="number" required step="0.0001"
                            class="form-control edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>"
                            tabindex="1" value="<?php echo $customer_discount2_reserve;?>" size="4" /></td>
                    <?php }
else if($info2['direct_invoicediscount2']!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount2[]"
                            type="number" required step="0.0001" class="form-control edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['direct_invoicediscount2'];?>" size="4" /></td>
                    <?php 
}
 else  if($num_rows!=0 && $info15['discount']!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount2[]"
                            type="number" required step="0.0001" class="form-controledit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php }  else if($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount2[]"
                            type="number" required step="0.0001" class="form-controledit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount2[]"
                            type="number" required step="0.0001" class="form-controledit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount2[]" type="hidden" class="form-controledit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }//closedist2
 if($info1000['customer_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount4 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows_ctp!=0){
  $discount4_reserve = '';
  $add_customer_discount4 = '';
  $num_rows = 1;
  $info15['discount'] = $ctp_trade_offer;
}
if($discount4_reserve!='') {
    $discount4reserver=$info15['discount']-$discount4_reserve;
      if($discount4reserver<0){
        $discount4reserver=0;
      }
?>
                    <td <?php 
if($gdn==1) echo ' style="display:none;"';  ?>>
                        <input name="products_discount4[]" type="text" class="form-controledit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $discount4reserver; ?>" size="4" />
                    </td>
                    <?php } 
/////////if  available add to customer discount 4
else if($add_customer_discount4!=""){
?>
                    <td> <?php if($gdn==1) echo ' style="display:none;"';  ?>
                        <input name="products_discount4[]" type="text" class="form-controledit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $add_customer_discount4 ;?>" size="4" />
                    </td>
                    <?php 
}
///
else if($num_rows!=0 && $info15['discount']!=-1) {
?>
                    <td <?php 
if($gdn==1) echo ' style="display:none;"';  ?>>
                        <input name="products_discount4[]" type="text" class="form-control edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" />
                    </td>
                    <?php } 
else if($info2['direct_invoicediscount4']!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>>
                        <input name="products_discount4[]" type="text" class="form-control edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['direct_invoicediscount4'];?>" size="4" />
                    </td>
                    <?php 
} else if($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount4[]"
                            type="text" class="form-control edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>>
                        <!-- //ye chalra hai  -->
                        <input name="products_discount4[]" type="text" class="form-control edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    </td>
                    <?php } } 
 else { 
  ?>
                    <input name="products_discount4[]" type="hidden" class="form-control edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }//closedist4
 if($info2000['customer_foc']==1  ) { 
   // echo "SELECT foc FROM customer_type_foc where tid='$customer_type' and product_id='$sid'";
  if($num_rows_ctp!=0){
    $foc = $ctp_foc;
    $foc_value = 0;
  } else {
    $foc = mysqli_get_var("SELECT discount_percentage FROM amount_discount where min_amount='$sid' ");
    $foc_value = mysqli_get_var("SELECT discount_value FROM amount_discount where min_amount='$sid' ");
    if($foc=="") {  $foc=0; }
    if($foc_value=="") {  $foc_value=0; }
  }
 ?>
                    <td>
                        <input type="number" name="products_foc[]" value="<?php echo $foc; ?>" class="bgggg form-control foc income_count"
                            id="<?php echo "pfoc".$info2['id'];?>" required size="4" />
                        <input type="hidden" class="foc_scheme" id="<?php echo "pfoc_scheme".$info2['id'];?>" value="<?php echo $foc; ?>" />
                        <input type="hidden" class="foc_value" id="<?php echo "pfoc_value".$info2['id'];?>" value="<?php echo $foc_value; ?>" />
                    </td>
                    <?php } 
else { 
    ?>
                    <input type="hidden" name="products_foc[]" value="0" class="foc income_count"
                        id="<?php echo "pfoc".$info2['id'];?>" required size="4" />
                    <input type="hidden" class="foc_scheme" id="<?php echo "pfoc_scheme".$info2['id'];?>" value="0" />
                    <input type="hidden" class="foc_value" id="<?php echo "pfoc_value".$info2['id'];?>" value="0" />
                    <?php }
if($info1000['customer_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows_ctp!=0 && (float)$ctp_trade_offer>0){
  $add_customer_discount4 = "";
  $discount3_reserve = "";
  $num_rows = 1;
  $info15['discount'] = $ctp_trade_offer;
}
$inv_tradeoffer = (float)$info2['tradeoffer'];

if($inv_tradeoffer>0) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount3[]" required
                    type="number" step="0.0001" class="form-control edit-input income_count totalorder"
                    id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                    value="<?php echo is_numeric($inv_tradeoffer) ? $inv_tradeoffer : 0; ?>" size="4" /></td>
                    <?php 
}

else if($direct_invoiceextradiscount!=-1 && (float)$direct_invoiceextradiscount!=0) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount3[]" required
                    type="number" step="0.0001" class="form-control edit-input income_count totalorder"
                    id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                    value="<?php echo is_numeric($direct_invoiceextradiscount) ? $direct_invoiceextradiscount : 0; ?>" size="4" /></td>
                    <?php 
}

else if($add_customer_discount4!="" && (float)$add_customer_discount4>0){ 
$info200['discount3']=$add_customer_discount4;
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount3[]" required
                            type="number" step="0.0001" class="form-control edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo is_numeric($info200['discount3']) ? $info200['discount3'] : 0; ?>" size="4"  /></td>
                    <?php }
else if($num_rows!=0 && (float)$info15['discount']>0) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount3[]" required
                            type="number" step="0.0001" class="form-control edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo is_numeric($info15['discount']) ? $info15['discount'] : 0; ?>" size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='' && (float)$info200['discount3']>0) {?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount3[]" required
                            type="number" step="0.0001" class="form-control edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo is_numeric($info200['discount3']) ? $info200['discount3'] : 0; ?>" size="4" /></td>
                    <?php }
else if($discount3_reserve!=''){ 
   $customerdiscount3 = $info15['discount']-$discount3_reserve;
   if($customerdiscount3<0) { $customerdiscount3=0; } 
     ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount3[]" required
                            type="number" step="0.0001" class="form-control edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo is_numeric($customerdiscount3) ? $customerdiscount3 : 0; ?>" size="4" /></td>
                    <?php } 
else if($num_rows!=0 && (float)$info15['discount']>0) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount3[]" required
                            type="number" step="0.0001" class="form-control edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo is_numeric($info15['discount']) ? $info15['discount'] : 0; ?>" size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='' && (float)$info200['discount3']>0) {?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount3[]" required
                            type="number" step="0.0001" class="form-control edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo is_numeric($info200['discount3']) ? $info200['discount3'] : 0; ?>" size="4" /></td>
                    <?php } else if((float)$info2['tradeoffer']>0) {  ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>>
                        <input name="products_discount3[]" required type="number" step="0.0001"
                            class="form-control edit-input income_count totalorder products_discount3" id="<?php echo "pppm".$info2['id'];?>"
                            tabindex="1" value="<?php echo is_numeric($info2['tradeoffer']) ? $info2['tradeoffer'] : 0; ?>" size="4" />
                    </td>
                    <?php } else {  ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>>
                        <input name="products_discount3[]" required type="number" step="0.0001"
                            class="form-control edit-input income_count totalorder products_discount3" id="<?php echo "pppm".$info2['id'];?>"
                            tabindex="1" value="0" size="4" />
                    </td>
                    <?php } } 
else {?>
                    <input name="products_discount3[]" type="hidden" class="form-control edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }//closedist3
if($info2000['en_discount5']==1) { ?>
                    <td><input type="text" name="discount5[]" class="form-control edit-input income_count"
                            id="<?php echo "pppl".$info2['id'];?>" tabindex="1" value="0" required size="4" /> </td>
                    <?php } //closedist5
 if($info1000['customer_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme, scheme_val, scheme_prd from customer_type_scheme where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="text" class="form-control edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                        <input name="products_scheme_val[]" type="text" class="form-control edit-input income_count totalorder"
                            id="<?php echo "pppsv".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['scheme_val'];?>" size="4" />
                        <?php 
echo "<select name='products_scheme_prd[]'   class='combobox form-control'   >";
echo "<option value='0'>Same Product</option>";
    $data556 = mysqli_query($conn,"SELECT id,name, sku from inventory where inactive=0  order by name") or die(mysqli_error($conn));
 while($info556 = mysqli_fetch_array( $data556 )) 
 { 
 if($info15['scheme_prd']==$info556['id']) {
  echo "<option value='".$info556['id']."' selected >".$info556['sku'].' '.$info556['name']."</option>";
   }
   else {
   echo "<option value='".$info556['id']."' >".$info556['sku'].' '.$info556['name']."</option>";
}
 }
echo "</select>"; ?>
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                            size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
//closescheme
?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                        <input name="products_pcs[]" type="number" step="0.0001"
                            <?php if($info1000['inventory_limit']==1 && ($info1000['gdninventory_limit']==0 || $gdn==1)) { if($info1000['en_inventorybatch']==1) { echo 'max="'.$maxx.'"'; } else { echo 'max="'.$info2['qty'].'"'; } } ?>
                            class="form-control qty total_pcs" id="<?php echo "t".$info2['id'];?>" min="0" size="4" readonly required/>
                    </td>

  <?php if(1==1){   ?>     
     <td  <?php if($info4000['display_taxamount']==0){ echo ' style="display:none;"';    }  ?> >
 <input name="display_totaltax2[]" type="text" class="income_count display_totaltax2" id="<?php echo "ppptttt".$info2['id'];?>"    value="0" size="4" readonly/>
</td>
<?php } ?>
                  
                    <?php if($info1000['customer_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
 if($info2000['en_maintax']==1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>>
                        <?php 
    $sub_customer_tax=mysqli_get_var("SELECT tax from sub_customer where id='$subc'");
    // if($sub_customer_tax!="" && $sub_customer_tax!=0) {  echo $sub_customer_tax; }
    ?>
                        <!-- here we are -->
                        <input name="products_tax[]" type="number" required step="0.0001"
                            class="form-control edit-input income_count subcustomertax" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>" value="<?php 
   if($st==1) {
     if($sub_customer_tax!="" && $sub_customer_tax!=0) { 
      echo $sub_customer_tax;
     }
     else {
     if($cfiler==1) {
      echo $info2000['filer_tax'];
       } else {
        echo $info2000['nonfiler_tax']; 
      } 
    }
     } 
     else 
     { echo 0;
    } 
      ?>" size="4" readonly="readonly" />
                    </td>
                    <?php }
else if($num_rows!=0 && $info15['tax']!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>>  <input name="products_tax[]" type="number"
                            required step="0.0001" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
else if($info2['direct_invoicetax']!=-1 && $st==1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>>
                        <input name="products_tax[]" type="number" required step="0.0001"
                            class="edit-input income_count" tabindex="1" id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php   echo $info2['direct_invoicetax']; ?>" size="4" readonly="readonly" />
                    </td>
                    <?php }
 elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>>
                        <input name="products_tax[]" type="number" required step="0.0001"
                            class="edit-input income_count" tabindex="1" id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" readonly="readonly" />
                    </td>
                    <?php }
  else {  ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>>
                        <input name="products_tax[]" type="number" required step="0.0001"
                            class="edit-input income_count" tabindex="1" id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo $itemtax; }?>"
                            size="4" readonly="readonly" />
                    </td>
                    <?php } } 
 else {      //----sid2 --->
  ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" />
                    <?php }   ?>
                    <td <?php if($info2000['invoice_cartonrate']==0) { echo ' style=" display:none;" '; } ?>
                        class="pipehide"><input name="pipe[]" type="text" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pipe".$info2['id'];?>" value="<?php  echo 0; ?>" size="4"
                            readonly="readonly" /></td>
                    <?php 
//closetax2
  if($info1000['customer_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows_ctp!=0){
  $cdirect_invoicetax2 = -1;
  $num_rows = 1;
  $info15['tax'] = $ctp_advance_tax;
}
if($cdirect_invoicetax2!=-1) { ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_tax2[]" type="number"
                            step="0.0001" required class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="<?php 
 if($st==1) {   echo $cdirect_invoicetax2;   } else { echo 0; } 
//echo $cdirect_invoicetax2;
?>" size="4" /></td>
                    <?php }
else  if($num_rows!=0 && $info15['tax']!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_tax2[]" type="number"
                            step="0.0001" requierd class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php if($num_rows_ctp!=0) { echo $info15['tax']; } else if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } 
else if($info2['direct_invoicetax2']!=-1 && $st==1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_tax2[]" type="number"
                            step="0.0001" required class="edit-input income_count totalorder" tabindex="1"
                            id="<?php echo "ppptt".$info2['id'];?>"
                            value="<?php   echo $info2['direct_invoicetax2']; ?>" size="4"
                            <?php if($info4000['en_engineering']==1){} else { ?>readonly="readonly" <?php } ?> /></td>
                    <?php }
else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_tax2[]" type="number"
                            step="0.0001" required class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied2']; ?>" size="4"
                            <?php if($info4000['en_engineering']==1){} else { ?>readonly="readonly" <?php } ?> /></td>
                    <?php }
else {  ?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_tax2[]" type="number"
                            step="0.0001" required class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="<?php if($cfiler==1) { echo 0; } else { echo $info2000['nonfiler_tax']; } ?>" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }  
 if($info1000['customer_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows_ctp!=0){
  $num_rows = 1;
  $info15['tax'] = $ctp_further_tax;
}
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($num_rows_ctp!=0) { echo $info15['tax']; } else if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php }  
else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }    else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } 
 ?>
                    <?php }//close main
        ?>
                    <!-- <td class="<?php echo ($info2000['en_freshmate'] == 1 )? '': 'hidden'?>"><input type="date" name="expiry_date[]" value="<?=$info2['expiry_date'];?>" <?php echo ($info2000['en_freshmate'] == 1 )? 'required':''?>/></td> -->
                    <!-- <td class="<?php ($info2000['en_freshmate'] == 1) ? '': 'hidden'?>" >
 <?php
    $data16 = mysqli_query($conn,"SELECT * FROM return_reason ORDER BY name") or die(mysqli_error($conn));
    $required = ($info2000['en_freshmate'] == 1) ? 'required':'';
    echo "<select name='reason[]' ".$required." > 
    <option value='' selected >Select Reason..</option> ";
    while($info16 = mysqli_fetch_array( $data16 )){
        echo "<option value='".$info16['id']."' >".$info16['name']."</option>";
    }
    echo "</select>";
?>
</td> -->
                    <?php if(1==1){   ?>     
     <td  <?php if($info4000['display_taxamount']==0){ echo ' style="display:none;"';    }  ?> >
                        <input name="display_totaltax[]" type="text" class="income_count display_totaltax"
                            id="<?php echo "ppptt".$info2['id'];?>" value="0" size="4" readonly />
                    </td>
                    <?php } ?>
                    <td <?php if($gdn==1) { echo  'style="display:none"'; } ?>><input type="hidden"
                            name="products_cogs[]" value="<?php
      if($info1000['en_inventorybatch']==1) { echo $unitc; } else {  echo $info2['unit_cost']; } ?>"
                            class="prd_cogs" />
                        <input name="products_total[]" step="0.0001"  type="number" min="0" id="newtotal<?php echo $info2['id'];?>"  
                            class="form-control tot<?php echo $info2['id'];?> ptotal sub_total income_count readonly " tabindex="-1" size="5" 
                            onkeypress="return false;" />
                    </td>

                    <td>
                    <div class="d-flex gap-2">
                    <?php if($info4000['en_engineering']==0){

              if(1==1) { ?>
              <input type="button" class="rounded-1 bg-info text-white border-0 p-1 edit receipt_edit_hide5" value="Edit" />
              <input type="button" class="rounded-1 bg-success text-white border-0 p-1 save" value="Save" /><?php }}
              ?><?php if($uom_hide != 1) { ?><input type="button" class="rounded-1 bg-danger text-white border-0 p-1 delete receipt_delete_edit5"
                            value="Delete" /> <?php } ?>
                    </div>
                    <br>        
                    </td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <?php if($info1000['en_recurringinvoices']==1){ ?>
    <script type="text/javascript">
    $('.recurringhide').hide();
    </script>
    <?php } ?>
    <script type="text/javascript">
    $(document).ready(function() {
                $(document).on('change', '.ctn', function() {
                    var ctn = $(this).val();
                    var packing = $(this).closest("tr").find(".new_packing").val();
                    var aqty = ctn * packing;
                    $(this).closest("tr").find(".qty").val(aqty);
                });
                $(document).on('change', '.qty', function() {
                    var ctn = $(this).val();
                    var packing = $(this).closest("tr").find(".ctn").val();
                    var aqty = ctn / packing;
                    // Limit aqty to 3 decimal places
                    aqty = parseFloat(aqty.toFixed(5));
                    $(this).closest("tr").find(".new_packing").val(aqty);
                    $(this).closest("tr").find(".income_count:first").trigger("change");
                });
               
                <?php if($info1000['open_ratecolumn']==1 && $gdn==0) { ?>
                $('.change15').focusout(function() {
                            $(".change15").removeClass("change15");
                            <?php } else if($info1000['en_inventorybatch']==1 && $gdn==1) {  ?>
                            $('.change7').focusout(function() {
                                        $(".change7").removeClass("change7");
                                        <?php } else if($info1000['en_warehouse']==1 ) {  ?>
                                        $('.change6').focusout(function() {
                                            $(".change6").removeClass("change6");
                                            <?php } else {  ?>
                                            $('.change5').focusout(function() {
                                                $(".change5").removeClass("change5");
                                                <?php }  ?>
                                                var $orginal = $(this).closest("tr");
                                                var $cloned = $orginal.clone();
                                                //get original selects into a jq object
                                                var $originalSelects = $orginal.find('select');
                                                $cloned.find('select').each(function(index, item) {
                                                    //set new select to value of old select
                                                    $(item).val($originalSelects.eq(index)
                                                        .val());
                                                });
                                                //get original textareas into a jq object
                                                var $originalTextareas = $orginal.find('textarea');
                                                $cloned.find('textarea').each(function(index, item) {
                                                    //set new textareas to value of old textareas
                                                    $(item).val($originalTextareas.eq(index)
                                                        .val());
                                                });
                                                var $orginal = $(this).closest("tr");


                                                var currentProductId = $orginal.find('.singleitem').val();   // hidden input `products[]` ka value

                                                <?php
                                                if ($info2000['noduplicate_item'] == 1){ ?>
                                                    var noduplicate_item = 1;
                                                <?php } else { ?>
                                                    var noduplicate_item = 0;
                                                <?php } ?>


                                                var isDuplicate = false;
                                                
                                                if(noduplicate_item == 1)
                                                {
                                                    $('#acart .singleitem').each(function () {
                                                        if ($(this).val() == currentProductId) {
                                                            isDuplicate = true;
                                                            return false; // break loop
                                                        }
                                                    });

                                                    if (isDuplicate) {
                                                        alert('The product has already inserted into the cart.');


                                                        $orginal.find('.income_count').val('');
                                                        $("#psearch").html('');
                                                        $("#searchbox").focus();

                                                        return; 
                                                    }
                                                }

                                                $cloned.appendTo("#acart");
                                                <?php if($info3000['en_osaka']==1){ ?>
                                                    $('.edit-input').attr("readonly", true);
                                                    setTimeout(() => {
                                                        $(".warehouse_charges").removeClass("reportselect").css("display","none");                                                        
                                                    }, 200);
                                                <?php }?>
                                                $(".combobox").select2();
                                                <?php if($info4000['en_mbl']==1) { ?>
                                                $(".packing").trigger("change");
                                                <?php } ?>
                                                //});
                                                <?php if($info3000['en_hapaperhub']==1) { ?>
                                                var a=this.id;
                                                a = a.replace(/\D/g, '');
                                                $('.change5').attr('class',
                                                    " change income_count totalorder");
                                                    $('.change55').attr('class',
                                                    " qty_weight change income_count totalorder");
                                                <?php }else{ ?>
                                                     $('.change5').attr('class',
                                                    " change income_count totalorder");
                                                    <?php } ?>
                                                <?php if($info2000['search_multibarcode']==0) { ?>
                                                $("#searchbox").focus();
                                                <?php } else { ?>
                                                $(".baccodesearch").focus();
                                                <?php } ?>
                                                $("#psearch").html('');
                                                var n10 = $("#totpc").val();
                                                n10 = parseInt(n10) + parseInt(1);
                                                $("#totpc").val(n10);
                                                var n11 = $("#totpc").val();
                                                $(".sno:last").val(n11);
                                                if (n11 > <?php echo $info2000['form_maxitem']; ?>) {
                                                    alert(
                                                        'You have crossed <?php echo $info2000['form_maxitem']; ?> items limit. '
                                                    );
                                                }
                                            });
                                        });
                                        
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);

    // $(".edit").on('click', function() {
    $(document).on('click', '.edit', function() {
        /*$(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);*/
        var prd_id = $(this).closest('.carttr').find('.products').val();
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
        <?php if($info3000['en_goodluck']==1) { ?> $('#pp' + prd_id).attr("readonly", true);
        <?php  } ?>
    });
    <?php  if($info1000['en_inventorybatch']==1) { ?>
    $(".inventory3").on('change', function() {
        var vid = $(this).val();
        var self = $(this);

    <?php if($info1000['batch_with_brand']!=0) { ?>
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch5: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                var tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.total_pcs').attr("max", tt);
            }
        });
    <?php } ?>

        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch6: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.prd_cogs').attr("value", tt);
            }
        });

        if(1==2){
            $.ajax({
                type: "POST",
                url: "../ajax/receipt-query4.php",
                data: {
                    batch61: vid
                },
                cache: false,
                dataType: 'html',
                success: function(html) {
                    self.closest('tr').find('.customfield1').attr("value", html);
                }
            });
            $.ajax({
                type: "POST",
                url: "../ajax/receipt-query4.php",
                data: {
                    batch62: vid
                },
                cache: false,
                dataType: 'html',
                success: function(html) {
                    self.closest('tr').find('.customfield2').attr("value", html);
                }
            });
            $.ajax({
                type: "POST",
                url: "../ajax/receipt-query4.php",
                data: {
                    batch63: vid
                },
                cache: false,
                dataType: 'html',
                success: function(html) {
                    self.closest('tr').find('.customfield3').attr("value", html);
                }
            });
        }
    });
    $(".inventory3").trigger("change");
    <?php } ?>
    // $(".save").on('click', function() {
    $(document).on('click', '.save', function() {
        /*$(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true); */
        $('.save').hide();
        $('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    // $(".delete").on('click', function() {
    $(document).on('click', '.delete', function() {
        var shoppingcart = $(this).closest('tr').find('.singleitem').val();
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query2.php",
            data: {
                cartclear: shoppingcart
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                $(".shopping_cart").html(html);
            }
        });
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        var sum30 = 0;
        $(".foc").each(function() {
            sum30 += parseFloat($(this).val()) || 0;
        });
        var sum30c = sum3 + sum30;
        $("#packing").val(sum30c);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        var decimal_point = "<?php echo $info2000['total_decimal']; ?>";
        sum2 = sum2.toFixed(decimal_point);
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (specialclass == 'noimpact' || specialclass == 'trade_no_impact' || specialclass ==
                'freight_class') {} else if (specialclass != 'brokery_rs' && specialclass !=
                'brokery_percentage') {
                if (dless == 1) {
                    if (dpercent == 1) {
                        damount = (+100 - +damount) / 100;
                        result = +result * damount;
                    } else {
                        result = +result - +damount;
                    }
                } else {
                    if (dpercent == 1) {
                        damount = (+100 + +damount) / 100;
                        result = +result * damount;
                    } else {
                        result = +result + +damount;
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        var decimal_point = "<?php echo $info2000['total_decimal']; ?>";
        result = result.toFixed(decimal_point);
        //result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        result2 = result2.toFixed(decimal_point);
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>
    <!--saqibeditjquery-->
    <script type="text/javascript">
    <?php if ($info1000['display_previous_discount']==1) { ?>
    // 
    $('.qtychange').on('change focusout ', function() {
        var qty = $(this).closest(".qtychange").val();
        var customerid = $("#cid2").val();
        var prdid = $(this).closest('.carttr').find('#product_id').val();
        var munit = $(this).closest('.carttr').find('.munit').val();
        $.ajax({
            type: "POST",
            url: "../ajax/lastdisocuntajax.php",
            data: {
                sid9922: prdid,
                customerid: customerid,
                qty: qty,
                munit: munit
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                $("#pppm" + prdid).val(html);
                $(".totalorder").trigger("change");
            }
        });
    });
    <?php } ?>
    <?php if($info4000['en_engineering']==1){
?>
    $(".teacher").trigger("change");
    $('.teacher').on('change', function() {
        var a = this.id;
        a = a.replace(/\D/g, '');
        var dd = $(this).find(":selected").val();
        if (dd == '0') {
            //perkg
            $('.pkg' + a).attr('readonly', true);
            //kg
            $('#customfield' + a).attr('readonly', true);
            //list rate
            $('#pp' + a).attr('readonly', true);
            //list weight
            $('#p' + a).attr('readonly', true);
            //piperate
            $('#pipe' + a).attr('readonly', true);
            //pc
            $('#' + a).attr('readonly', false);
            //rate%
            $('#pppp' + a).attr('readonly', false);
            $('#customfield' + a).val(0);
            $('#customfieldd' + a).val(0);
            var qty = $(this).closest(".carttr").find("#" + a).val();
            var w_list = $(this).closest(".carttr").find("#p" + a).val();
            var scheme = $(this).closest(".carttr").find("#ppps" + a).val();
            var totkg = (qty * w_list);
            $('#t' + a).val(totkg);
        } else if (dd == '1') {
            //perkg
            //perkg
            $('.pkg' + a).attr('readonly', true);
            $('.teacher').hide();
            $('#customfield' + a).val(0);
            $('#customfieldd' + a).val(0);
        } else if (dd == '2') {
            //perkg
            //perkg
            $('.pkg' + a).attr('readonly', true);
            //kg
            $('#customfield' + a).attr('readonly', true);
            //list rate
            $('#pp' + a).attr('readonly', true);
            //list weight
            $('#p' + a).attr('readonly', true);
            //rate%
            $('#pppp' + a).attr('readonly', true);
            //pc
            $('#' + a).attr('readonly', false);
            //piperate
            $('#pipe' + a).attr('readonly', false);
            $('#pppp' + a).val(0);
            $('#customfield' + a).val(0);
            $('#customfieldd' + a).val(0);
            var qty = $(this).closest(".carttr").find("#" + a).val();
            var w_list = $(this).closest(".carttr").find("#p" + a).val();
            var scheme = $(this).closest(".carttr").find("#ppps" + a).val();
            var totkg = (qty * w_list);
            $('#t' + a).val(totkg);
        } else if (dd == '3') {
            //perkg
            //perkg
            $('.pkg' + a).attr('readonly', false); //kg
            $('#customfield' + a).attr('readonly', false);
            //list rate
            $('#pp' + a).attr('readonly', true);
            //list weight
            $('#p' + a).attr('readonly', true);
            //rate%
            $('#pppp' + a).attr('readonly', true);
            //pc
            $('#' + a).attr('readonly', false);
            //piperate
            $('#pipe' + a).attr('readonly', true);
            $('#pppp' + a).val(0);
            var customm = $(this).closest(".carttr").find("#customfield" + a).val();
            $('#t' + a).val(customm);
        }
    });
    <?php   } ?>
    <?php   if($info4000['en_engineering']==1 ){        ?>
    $(".case2qty").on('change  ', function() {
        var a = this.id;
        a = a.replace(/\D/g, '');
        var dd = $(this).closest(".carttr").find("#ric" + a).find(":selected").val();
        if (dd == '2') {
            var piperate = $('#pipe' + a).val();
            if (piperate == 0) {
                var listrate = $('#pp' + a).val();
                $('#pipe' + a).val(listrate);
            }
        } else if (dd == '3') {
            var total = $('#ptotal' + a).val();
            var pcss = $('#ctn' + a).val();
            var piperate = pcss / total;
            $('#pipe' + a).val(piperate);
        }
    });
    <?php  } ?>
    <?php if($info4000['en_tradelink']==1) { ?>
    $('.customfield3').attr('readonly', true);
    $('.tcharges_type').on('change ', function() {
        $(".totalorder").trigger("change");
    });
    <?php  } ?>

    // Basit
    <?php if($info3000['en_highway']==1){ ?>
    $(document).on('change', '.warehouse_charges', function () {

        $(".searchqty").focus();
        var wid = $(this).val(); 
        if (wid) {
            $.ajax({
                type: "POST",
                url: "../ajax/receipt-query5.php",
                data: { warehouse_charges: wid },
                cache: false,
                dataType: 'html',
                success: function (html) {
                    $("#wresult").html(html);
                },
                error: function () {
                    alert("Failed to fetch data. Please try again.");
                }
            });
        } else {
            alert("Please select a valid warehouse.");
        }
    });
  <?php } ?>




  </script>

<?php  include('../functions/incomecount_function.php'); ?>

<script type="text/javascript">

    
    $(".totalorder,  .rice_discount_value, .change, #sub_total, #shipping, #discount").change(function() {
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (specialclass == 'noimpact' || specialclass == 'trade_no_impact' || specialclass ==
                'freight_class') {} else if (specialclass != 'brokery_rs' && specialclass !=
                'brokery_percentage') {
                if (dless == 1) {
                    if (dpercent == 1) {
                        damount = (+100 - +damount) / 100;
                        result = +result * damount;
                    } else {
                        result = +result - +damount;
                    }
                } else {
                    if (dpercent == 1) {
                        damount = (+100 + +damount) / 100;
                        result = +result * damount;
                    } else {
                        result = +result + +damount;
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        var decimal_point = "<?php echo $info2000['total_decimal']; ?>";
        result = result.toFixed(decimal_point);
        //result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        result2 = result2.toFixed(decimal_point);
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
    });
    $("#amount_received").change(function() {
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        result2 = result2.toFixed(decimal_point);
        $("#pending_amount").val(result2);
    });
    </script>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    <?php   if($info4000['en_engineering']==1  ){
      ?>
    saqib();

    function saqib() {
        $(".case2qty").each(function() {
            // Test if the div element is empty
            var dd = $(this).find(":selected").val();
            var a = this.id;
            a = a.replace(/\D/g, '');
            if (dd == '0') {
                //perkg
                $('.pkg' + a).attr('readonly', true);
                //kg
                $('#customfield' + a).attr('readonly', true);
                //list rate
                $('#pp' + a).attr('readonly', true);
                //list weight
                $('#p' + a).attr('readonly', true);
                //piperate
                $('#pipe' + a).attr('readonly', true);
                //pc
                $('#' + a).attr('readonly', false);
                //rate%
                $('#pppp' + a).attr('readonly', false);
                $('#customfield' + a).val(0);
                $('#customfieldd' + a).val(0);
                var qty = $(this).closest(".carttr").find("#" + a).val();
                var w_list = $(this).closest(".carttr").find("#p" + a).val();
                var scheme = $(this).closest(".carttr").find("#ppps" + a).val();
                var totkg = (qty * w_list);
                $('#t' + a).val(totkg);
            } else if (dd == '1') {
                //perkg
                //perkg
                $('.pkg' + a).attr('readonly', true);
                $('.teacher').hide();
                $('#customfield' + a).val(0);
                $('#customfieldd' + a).val(0);
                //$('#t'+ a).val(0);
            } else if (dd == '2') {
                //perkg
                //perkg
                $('.pkg' + a).attr('readonly', true);
                //kg
                $('#customfield' + a).attr('readonly', true);
                //list rate
                $('#pp' + a).attr('readonly', true);
                //list weight
                $('#p' + a).attr('readonly', true);
                //rate%
                $('#pppp' + a).attr('readonly', true);
                //pc
                $('#' + a).attr('readonly', false);
                //piperate
                $('#pipe' + a).attr('readonly', false);
                $('#pppp' + a).val(0);
                $('#customfield' + a).val(0);
                $('#customfieldd' + a).val(0);
                var qty = $(this).closest(".carttr").find("#" + a).val();
                var w_list = $(this).closest(".carttr").find("#p" + a).val();
                var scheme = $(this).closest(".carttr").find("#ppps" + a).val();
                var totkg = (qty * w_list);
                $('#t' + a).val(totkg);
            } else if (dd == '3') {
                //perkg
                //perkg
                $('.pkg' + a).attr('readonly', false); //kg
                $('#customfield' + a).attr('readonly', false);
                //list rate
                $('#pp' + a).attr('readonly', true);
                //list weight
                $('#p' + a).attr('readonly', true);
                //rate%
                $('#pppp' + a).attr('readonly', true);
                //pc
                $('#' + a).attr('readonly', false);
                //piperate
                $('#pipe' + a).attr('readonly', true);
                $('#pppp' + a).val(0);
                var customm = $(this).closest(".carttr").find("#customfield" + a).val();
                $('#t' + a).val(customm);
            }
        });
    }
    <?php }?>
    <?php if($info4000['en_mbl']==1) { ?>
    $('.cf_class').prop('readonly', true);
    $('.packing').on('change focusout ', function() {
        var qty = $(this).val();
        var prdid = $(this).closest('.carttr').find('.singleitem').val();
        var containersize = $('.containersize').val();
        if (containersize == '20 Ft. ' || containersize == '') {
            containersize = 1050;
        } else {
            containersize = 2100;
        }
        var that = $(this);
        $.ajax({
            type: "POST",
            url: "../ajax/lastdisocuntajax.php",
            data: {
                mbl9922: prdid,
                qty: qty
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                that.closest(".carttr").find(".customfield1").val(html);
                that.closest(".carttr").find(".customfield2").val(containersize);
                var csp = ((html / containersize) * 100).toFixed(2);
                that.closest(".carttr").find(".customfield3").val(csp);
            }
        });
        $.ajax({
            type: "POST",
            url: "../ajax/lastdisocuntajax.php",
            data: {
                mbl9921: prdid,
                qty: qty
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                that.closest(".carttr").find(".customfield5").val(html);
                var aw = (qty * html) / 100;
                that.closest(".carttr").find(".customfield4").val(aw);
            }
        });
    });
    <?php } ?>
    <?php  if($info4000['en_engineering'] == 0){ ?>
    $('.pipehide').hide();
    $('.case2qty option[value="0"]').remove();
    $('.case2qty option[value="3"]').remove();
    <?php } ?>
    </script>
    <?php
  }//end sid2
/////


}
 else if(isset($_POST['sid23']))
{
$sid=test_input($_POST['sid23']);
$cid=test_input($_POST['customerid']);
$st=test_input($_POST['st']);
$cwarehouse = mysqli_get_var("Select inventory_warehouse from customer where `id` = '$cid'");
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="2%">S.No</th>
                    <th width="20%">
                        <div><?php echo $info1000['product_label']; ?></div>
                    </th>

                    

                    <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <div>QTA</div>
                    </th>
                    <th>
                        <div><?php echo $info1000['multi_unit_label']; ?></div>
                    </th>
                    <th>
                        <div>Stitch/Unit </div>
                    </th>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['single_unit_label']; ?></div>
                    </th>
                    <?php if($info1000['en_warehouse']==1) {  echo  '  <th ><div>WH </div></th> '; } ?>
                    <?php if($info1000['en_inventorybatch']==1) {   echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; } ?>
                    <?php if($info1000['en_embroidery']==1) { 
         echo  ' 
          <th ><div>Type </div></th>
          <th ><div>Colors </div></th>
         <th ><div>Head Working </div></th>
         <th ><div>Fusing </div></th>
          '; } ?>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['packing_label']; ?></div>
                    </th>
                    <th>
                        <div><?php echo $info1000['price_label']; ?></div>
                    </th>
                    <?php if($info1000['customer_discount1']==1) {  echo  '  <th ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount2']==1) {  echo  '  <th ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount3']==1) {  echo  '  <th ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_scheme']==1) {  echo  '  <th ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                    <?php if($info1000['customer_tax1']==1) {  echo  '  <th ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax2']==1) {  echo  '  <th ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax3']==1) {  echo  '  <th ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
                    <th contenteditable="true" width="80">Total </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
   if($info1000['en_deals']==1) { 
    $data2 = mysqli_query($conn,"SELECT * from deal where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr>
                    <td class="sno"></td>
                    <td><input type="hidden" name="deal[]" value="d<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <?php 
   $did=$info2['id'];
   $data15 = mysqli_query($conn,"SELECT *, i.qty/d.qty AS aqty, d.qty AS dqty from inventory i, deal_details d where d.did='$did' AND d.pid=i.id") or die(mysqli_error($conn));
  $taqty=10000; 
while($info15 = mysqli_fetch_array( $data15 )) 
 { 
 if($info15['aqty']<=$taqty)
 {
 $taqty=$info15['aqty'];
 }
 else {
 $info15['aqty']=ceil($taqty);
 }
 $staqty=$info15['aqty'];
 echo $info15['dqty']." Pcs - ".$info15['name']."<br>";
 }
 ?>
                    </td>
                    <td><?php  if($staqty<$taqty)
        {
        echo ceil($staqty);
        }
        else  {
          $staqty=$taqty;
           echo ceil($staqty);
        }
        ?></td>
                    <td>
                        <input name="d<?php echo $info2['id'];?>" type="text" min="1"
                            class="searchqty income_count form-control" id="d<?php echo $info2['id'];?>"
                            tabindex="1" />
                    </td>
                    <td><input type="text" class="form-control income_count" /> </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse  ") or die(mysqli_error($conn)); 
echo "<select name='".$info2['id']."_warehouse' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <?php echo $info2['packing'];?></td>
                    <td>
                        <input id="<?php echo "nm".$info2['id'];?>" value="<?php echo $info2['sale_price'];?>"
                            class="income_count" onchange="changealert(this.id)" size="20" />
                    </td>
                    <td><input type="text" class="form-control income_count" value="0" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>" /></td>
                    <td><input type="text" class="form-control income_count" /></td>
                    <td><input type="text" class="form-control income_count" value="0" /></td>
                    <td><input type="hidden" name="d<?php echo $info2['id']."_cogs";?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input name="d<?php echo $info2['id']."_total";?>" type="text"
                            class="d<?php echo $info2['id'];?> ptotal form-control" tabindex="-1" readonly />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
                <?php  if($info1000['en_singleproducts']==1) { 
       $data2 = mysqli_query($conn,"SELECT * from inventory i where id='$sid' ") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { 
 ?>
                <tr class="carttr">
                    <td><input type="text" class="sno form-control" />
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
      else if($info1000['en_lastprice']==2 ) {
   $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id` AND s.customer_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }  ?>
                    </td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $info2['id'];?>" />
                        <input name="delivery_id[]" type="hidden" value="0" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>><?php 
         $sid = $info2['id'];
   $transfer_in = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=0 $wlimit_warehouse8   ");
             $transfer_out = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=0 $wlimit_warehouse8  ");
           echo  $product_qta = $transfer_in-$transfer_out;
         ?></td>
                    <td>
                        <input type="hidden" id="u<?php echo $info2['id'];?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input type="text" name="stitch_pcs"
                            class="searchqty <?php if($info1000['no_salespacking']==1) echo ' change5';  ?> packing income_count totalorder "
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" size="7" />
                    </td>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <input type="text" class="change5 change income_count totalorder"
                            id="pcs<?php echo $info2['id'];?>" tabindex="1" value="0" size="4" />
                    </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse  ") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' tabindex='1' class='teacher warehouse change6' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
 if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <?php } ?>
                    <?php if($info1000['en_inventorybatch']==1) { ?>
                    <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'  && type_component=0") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1' class='teacher reportselect inventory3 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
 $batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td><input name="stitch[]" type="text" value="1" size="4" /> </td>
                    <?php if($info1000['en_embroidery']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from stitching_area") or die(mysqli_error($conn)); 
echo "<select name='products_sarea[]' id=sa".$info2['id']."  class='teacher income_count'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><input name="products_scolor[]" type="text" value="1" size="4" /> </td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from stitching_type") or die(mysqli_error($conn)); 
echo "<select name='products_stype[]' id=st".$info2['id']." class='teacher income_count stype'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from stitching_fusion") or die(mysqli_error($conn)); 
echo "<select name='products_sfusion[]' id=sf".$info2['id']." class='teacher income_count change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <?php } ?>

                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_packing[]" type="number" min="0.1" step="0.001" class="edit-input change income_count totalorder"
                            id="p<?php echo $info2['id'];?>" tabindex="1" value="<?php echo $info2['packing'];?>"
                            size="4" />
                    </td>
                    <td>
                        <?php
$data15 = mysqli_query($conn,"SELECT customer_type from customer where  id='$cid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$ttid=$info15['customer_type'];
$ppid=$info2['id'];
 $data15 = mysqli_query($conn,"SELECT price from customer_type_pricing where pid='$ttid' AND tid='$ppid' && company_id = '$current_company' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            required value="<?php echo $info15['price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100; 
$discount4=$info200['discount4']/100;
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3; 
$discount4=1-$discount4; 
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info2000['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x;
    ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" required min="0" 
                            value="0.7"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } else {  ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" required min="0" 
                            value="0.7"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php }  ?>
                    </td>
                    <?php if($info1000['customer_discount1']==1) { 
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from cb_discount where cid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from customer_type_discount1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($num_rows!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                            size="4" /></td>
                    <?php }
else if($num_rows2!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info17['discount'];?>"
                            size="4" /></td>
                    <?php }
 else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } 
 } else { ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount4 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
  if($info1000['customer_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount3[]" required type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" step="0.0001" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='' && (float)$info200['discount3']>0) {?>
                    <td><input name="products_discount3[]" required type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount3'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount3[]" required type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
else {?>
                    <input name="products_discount3[]" type="hidden"  class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from customer_type_scheme where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                            size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                        <input name="products_pcs[]" type="text"
                            <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { echo 'max="'.$maxx.'"'; } else { echo 'max="'.$info2['qty'].'"'; } } ?>
                            class="total_pcs" id="<?php echo "t".$info2['id'];?>" min="0" size="4" />
                    </td>
                    <?php if($info1000['customer_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info15['tax']; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td> <input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
  else {  ?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo 0; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" />
                    <?php } if($info1000['customer_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } 
else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied2']; ?>" size="4" /></td>
                    <?php }
else {  ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }  if($info1000['customer_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php }  
else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }    else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td><input type="hidden" name="products_cogs[]" value="<?php
      if($info1000['en_inventorybatch']==1) { echo $unitc; } else {  echo $info2['unit_cost']; } ?>"
                            class="prd_cogs" />
                        <input name="products_total[]" step="0.0001"  id="newtotal<?php echo $info2['id'];?>" type="number" min="0" 
                            class="form-control tot<?php echo $info2['id'];?> ptotal sub_total income_count readonly " tabindex="-1" size="5"
                            onkeypress="return false;" />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php if($info1000['open_ratecolumn']==1) { ?>
                $('.change15').focusout(function() {
                            $(".change15").removeClass("change15");
                            <?php } else if($info1000['en_inventorybatch']==1) {  ?>
                            $('.change7').focusout(function() {
                                        $(".change7").removeClass("change7");
                                        <?php } else if($info1000['en_warehouse']==1) {  ?>
                                        $('.change6').focusout(function() {
                                            $(".change6").removeClass("change6");
                                            <?php } else {  ?>
                                            $('.change5').focusout(function() {
                                                $(".change5").removeClass("change5");
                                                <?php }  ?>
                                                var $orginal = $(this).closest("tr");
                                                var $cloned = $orginal.clone();
                                                //get original selects into a jq object
                                                var $originalSelects = $orginal.find('select');
                                                $cloned.find('select').each(function(index, item) {
                                                    //set new select to value of old select
                                                    $(item).val($originalSelects.eq(index)
                                                        .val());
                                                });
                                                //get original textareas into a jq object
                                                var $originalTextareas = $orginal.find('textarea');
                                                $cloned.find('textarea').each(function(index, item) {
                                                    //set new textareas to value of old textareas
                                                    $(item).val($originalTextareas.eq(index)
                                                        .val());
                                                });
                                                $cloned.appendTo("#acart");
                                                //});
                                                $('.change5').attr('class',
                                                    " change income_count totalorder packing");
                                                $("#searchbox").focus();
                                                $("#psearch").html('');
                                                var n10 = $("#totpc").val();
                                                n10 = parseInt(n10) + parseInt(1);
                                                $("#totpc").val(n10);
                                                var n11 = $("#totpc").val();
                                                $(".sno:last").val(n11);
                                            });
                                        });
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { 
?>
    $(".inventory3").on('change', function() {
        var vid = $(this).val();
        var self = $(this);
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch5: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                var tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.total_pcs').attr("max", tt);
            }
        });
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch6: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.prd_cogs').attr("value", tt);
            }
        });
    });
    <?php }} ?>
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $(".delete").on('click', function() {
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact' || specialclass ==
                    'freight_class') {} else if (specialclass != 'brokery_rs' && specialclass !=
                    'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact' || specialclass ==
                    'freight_class') {} else if (specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  } 
 else if(isset($_POST['sid2331']))
{
$sid=test_input($_POST['sid2331']);
$cid=test_input($_POST['customerid']);
$st=test_input($_POST['st']);
$cwarehouse = mysqli_get_var("Select inventory_warehouse from customer where `id` = '$cid'");
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="5%">
                        <div>S.No</div>
                    </th>
                    <th width="20%">
                        <div><?php echo $info1000['product_label']; ?></div>
                    </th>

                    <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <div>QTA</div>
                    </th>
                    <th>
                        <div>Carton</div>
                    </th>
                    <th>
                        <div>KG/Ctn</div>
                    </th>
                    <th>
                        <div>Formula</div>
                    </th>
                    <th>
                        <div>Brand</div>
                    </th>
                    <th>
                        <div>Type</div>
                    </th>
                    <th>
                        <div>Cons. Rate</div>
                    </th>
                    <th>
                        <div>Rate</div>
                    </th>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                    <th width="80">
                        <div>Total</div>
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
   if($info1000['en_deals']==1) { 
    $data2 = mysqli_query($conn,"SELECT * from deal where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr>
                    <td class="sno"></td>
                    <td><input type="hidden" name="deal[]" value="d<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <?php 
   $did=$info2['id'];
   $data15 = mysqli_query($conn,"SELECT *, i.qty/d.qty AS aqty, d.qty AS dqty from inventory i, deal_details d where d.did='$did' AND d.pid=i.id") or die(mysqli_error($conn));
  $taqty=10000; 
while($info15 = mysqli_fetch_array( $data15 )) 
 { 
 if($info15['aqty']<=$taqty)
 {
 $taqty=$info15['aqty'];
 }
 else {
 $info15['aqty']=ceil($taqty);
 }
 $staqty=$info15['aqty'];
 echo $info15['dqty']." Pcs - ".$info15['name']."<br>";
 }
 ?>
                    </td>
                    <td><?php  if($staqty<$taqty)
        {
        echo ceil($staqty);
        }
        else  {
          $staqty=$taqty;
           echo ceil($staqty);
        }
        ?></td>
                    <td>
                        <input name="d<?php echo $info2['id'];?>" type="text" min="1"
                            class="searchqty income_count form-control" id="d<?php echo $info2['id'];?>"
                            tabindex="1" />
                    </td>
                    <td><input type="text" class="form-control income_count" /> </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse  ") or die(mysqli_error($conn)); 
echo "<select name='".$info2['id']."_warehouse' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <?php echo $info2['packing'];?></td>
                    <td>
                        <input id="<?php echo "nm".$info2['id'];?>" value="<?php echo $info2['sale_price'];?>"
                            class="income_count" onchange="changealert(this.id)" size="20" />
                    </td>
                    <td><input type="text" class="form-control income_count" value="0" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>" /></td>
                    <td><input type="text" class="form-control income_count" /></td>
                    <td><input type="text" class="form-control income_count" value="0" /></td>
                    <td><input type="hidden" name="d<?php echo $info2['id']."_cogs";?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input name="d<?php echo $info2['id']."_total";?>" type="text"
                            class="d<?php echo $info2['id'];?> ptotal form-control" tabindex="-1" readonly />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
                <?php  if($info1000['en_singleproducts']==1) { 
       $data2 = mysqli_query($conn,"SELECT * from inventory i where id='$sid' ") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { 
 ?>
                <tr class="carttr">
                    <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                        value="<?php echo $info2['is_taxable'];?>" />
                    <td><input type="text" class="sno form-control" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
else if($info1000['en_lastprice']==2 ) {
      $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id` AND s.customer_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }       
         ?></td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $info2['id'];?>" />
                        <input name="delivery_id[]" type="hidden" value="0" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>><?php 
         $sid = $info2['id'];
   $transfer_in = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=0 $wlimit_warehouse8   ");
             $transfer_out = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=0 $wlimit_warehouse8  ");
           echo  $product_qta = $transfer_in-$transfer_out;
         ?></td>
                    <td>
                        <input type="hidden" id="u<?php echo $info2['id'];?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input type="text" name="stitch_pcs"
                            class="searchqty <?php if($info1000['no_salespacking']==1) echo ' ';  ?> packing income_count totalorder "
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" size="7" />
                    </td>
                    
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_packing[]" type="number" min="0.1" step="0.001" class="kgcloud change income_count totalorder"
                            id="p<?php echo $info2['id'];?>" tabindex="1" value="<?php echo $info2['packing'];?>"
                            size="4" />
                    </td>
                    <td>
                        <select name="even[]" class="seven" tabindex="1">
                            <option value="1">Even</option>
                            <option value="0">Odd</option>
                        </select>
                    </td>
                    <td <?php  echo ' style="display:none;"';  ?>>
                        <input type="text" class="change5 change income_count totalorder"
                            id="pcs<?php echo $info2['id'];?>" tabindex="1" value="0" size="4" />
                    </td>
                    <?php if($info1000['en_inventorybatch']==1) { ?>
                    <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'  && type_component=0") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1' class='teacher reportselect inventory3 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
$batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from product_brands") or die(mysqli_error($conn)); 
echo "<select name='products_brand[]' class='teacher  '   tabindex='1'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from product_type") or die(mysqli_error($conn)); 
echo "<select name='products_type[]' class='teacher  '   tabindex='1'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><input name="consumption_rate[]" type="text" class="income_count totalorder"
                            id="prate<?php echo $info2['id'];?>" tabindex="1" value="0" size="4" />
                    <td>
                        <?php
$data15 = mysqli_query($conn,"SELECT customer_type from customer where  id='$cid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$ttid=$info15['customer_type'];
$ppid=$info2['id'];
 $data15 = mysqli_query($conn,"SELECT price from customer_type_pricing where pid='$ttid' AND tid='$ppid' && company_id = '$current_company' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" required min="0" 
                            value="<?php echo $info15['price'];?>"
                            class="change5 change6 income_count chk8ange totalorder" size="4" />
                        <?php } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100; 
$discount4=$info200['discount4']/100;
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3; 
$discount4=1-$discount4; 
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info2000['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x;
    ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" value="0" min="0" 
                            class="change5 change6 income_count chk8ange totalorder" size="4"  required/>
                        <?php } else {  ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" value="0" min="0" 
                            class="change5 change6 income_count chk8ange totalorder" size="4"  required/>

                        <?php }  ?>
                    </td>
                    <?php if($info1000['customer_discount1']==1) { 
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from cb_discount where cid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from customer_type_discount1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($num_rows!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                            size="4" /></td>
                    <?php }
else if($num_rows2!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info17['discount'];?>"
                            size="4" /></td>
                    <?php }
 else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } 
 } else { ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount4 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
  if($info1000['customer_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount3[]" required type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='') {?>
                    <td><input name="products_discount3[]" required type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount3'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount3[]" required type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
else {?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from customer_type_scheme where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                            size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                        <input name="products_pcs[]" type="text"
                            <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { echo 'max="'.$maxx.'"'; } else { echo 'max="'.$info2['qty'].'"'; } } ?>
                            class="total_pcs" id="<?php echo "t".$info2['id'];?>" min="0" size="4" />
                    </td>
                    <?php if($info1000['customer_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info15['tax']; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td> <input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
  else {  ?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo 0; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" />
                    <?php } if($info1000['customer_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } 
else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied2']; ?>" size="4" /></td>
                    <?php }
else {  ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }  if($info1000['customer_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php }  
else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }    else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td><input type="hidden" name="products_cogs[]" value="<?php
      if($info1000['en_inventorybatch']==1) { echo $unitc; } else {  echo $info2['unit_cost']; } ?>"
                            class="prd_cogs" />
                        <input name="products_total[]" step="0.0001"  id="newtotal<?php echo $info2['id'];?>" type="number" min="0" 
                            class="form-control tot<?php echo $info2['id'];?> ptotal sub_total income_count readonly " tabindex="-1" size="5"
                            onkeypress="return false;" />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php if($info1000['en_inventorybatch']==1) {  ?>
                $('.change7').focusout(function() {
                            $(".change7").removeClass("change7");
                            <?php } else if($info1000['en_warehouse']==1) {  ?>
                            $('.change6').focusout(function() {
                                $(".change6").removeClass("change6");
                                <?php } else {  ?>
                                $('.change5').focusout(function() {
                                    $(".change5").removeClass("change5");
                                    <?php }  ?>
                                    var $orginal = $(this).closest("tr");
                                    var $cloned = $orginal.clone();
                                    //get original selects into a jq object
                                    var $originalSelects = $orginal.find('select');
                                    $cloned.find('select').each(function(index, item) {
                                        //set new select to value of old select
                                        $(item).val($originalSelects.eq(index).val());
                                    });
                                    //get original textareas into a jq object
                                    var $originalTextareas = $orginal.find('textarea');
                                    $cloned.find('textarea').each(function(index, item) {
                                        //set new textareas to value of old textareas
                                        $(item).val($originalTextareas.eq(index).val());
                                    });
                                    $cloned.appendTo("#acart");
                                    //});
                                    $('.change5').attr('class',
                                        " change income_count totalorder packing ");
                                    $("#searchbox").focus();
                                    $("#psearch").html('');
                                    var n10 = $("#totpc").val();
                                    n10 = parseInt(n10) + parseInt(1);
                                    $("#totpc").val(n10);
                                    var n11 = $("#totpc").val();
                                    $(".sno:last").val(n11);
                                });
                            });
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { 
?>
    $(".inventory3").on('change', function() {
        var vid = $(this).val();
        var self = $(this);
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch5: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                var tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.total_pcs').attr("max", tt);
            }
        });
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch6: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.prd_cogs').attr("value", tt);
            }
        });
    });
    <?php }} ?>
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $(".delete").on('click', function() {
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass != 'brokery_rs' && specialclass != 'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('.seven').on('change', function() {
        var ftype = $(this).val();
        if (ftype == 0) {
            $(this).closest('.carttr').find('.kgcloud').prop("readOnly", true);
            $(this).closest('.carttr').find(".kgcloud").val(0);
            $(this).closest('.carttr').find('.income_count:first').trigger('change');
        } else {
            $(this).closest('.carttr').find(".kgcloud").prop("readOnly", false);
            $(this).closest('.carttr').find('.income_count:first').trigger('change');
        }
    });
     </script>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  } 
 else if(isset($_POST['sid2334']))
{
$sid=test_input($_POST['sid2334']);
$cid=test_input($_POST['customerid']);
$st=test_input($_POST['st']);
$cwarehouse = mysqli_get_var("Select inventory_warehouse from customer where `id` = '$cid'");
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="5%">
                        <div>S.No</div>
                    </th>
                    <th width="20%">
                        <div><?php echo $info1000['product_label']; ?></div>
                    </th>
                    <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <div>QTA</div>
                    </th>
                    <th>
                        <div>Qty</div>
                    </th>
                    <th>
                        <div>Brand</div>
                    </th>
                    <th>
                        <div>Type</div>
                    </th>
                    <th>
                        <div>Cons. Rate</div>
                    </th>
                    <th>
                        <div>Rate</div>
                    </th>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                    <th width="80">
                        <div>Total</div>
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php  if($info1000['en_singleproducts']==1) { 
         $data2 = mysqli_query($conn,"SELECT c.id as id, combination_id, other_material, sub_quality, brand_id, type_id,  SUM(qty_total) as qty_total FROM production_weaving_details d, weaving_combination c WHERE c.id=d.`combination_id` && d.`invoice`=0  GROUP BY combination_id, sub_quality ") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { 
 $bid = $info2['brand_id'];
 $tid = $info2['type_id'];
 $cid = $info2['sub_quality'];
 $qtyid = $info2['qty_total'];
 ?>
                <tr class="carttr">
                    <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                        value="<?php echo $info2['is_taxable'];?>" />
                    <td><input type="text" class="sno form-control" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
else if($info1000['en_lastprice']==2 ) {
      $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id` AND s.customer_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }       
         ?></td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $info2['id'];?>" />
                        <input name="delivery_id[]" type="hidden" value="0" />
                        <h5><?php echo $cwarehouse = mysqli_get_var("Select name from component where `id` = '$cid'"); ?>
                        </h5>
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <td <?php  echo ' style="display:none;"';  ?>><?php echo $info2['qty'];?></td>
                    <td>
                        <input type="hidden" id="u<?php echo $info2['id'];?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input name="stitch_pcs" type="text"
                            class="searchqty <?php if($info1000['no_salespacking']==1) echo ' ';  ?> packing income_count qtychange totalorder "
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" value="<?php echo $qtyid; ?>" size="4" />
                    </td>
                    
                    <td <?php  echo ' style="display:none;"';  ?>><input name="products_packing[]" type="number" min="0.1" step="0.001"
                            class="change income_count totalorder" id="p<?php echo $info2['id'];?>" tabindex="1"
                            value="1" size="4" />
                    </td>
                    <td <?php  echo ' style="display:none;"';  ?>>
                        <select name="even[]" tabindex="1">
                            <option value="1">Even</option>
                            <option value="0">Odd</option>
                        </select>
                    </td>
                    <td <?php  echo ' style="display:none;"';  ?>>
                        <input type="text" class="change5 change income_count totalorder"
                            id="pcs<?php echo $info2['id'];?>" tabindex="1" value="0" size="4" />
                    </td>
                    <?php if($info1000['en_inventorybatch']==1) { ?>
                    <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'  && type_component=0") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1' class='teacher reportselect inventory3 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
$batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from product_brands") or die(mysqli_error($conn)); 
echo "<select name='products_brand[]' class='teacher  '   tabindex='1'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from product_type") or die(mysqli_error($conn)); 
echo "<select name='products_type[]' class='teacher  '   tabindex='1'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><input name="consumption_rate[]" type="text" class="income_count totalorder"
                            id="prate<?php echo $info2['id'];?>" tabindex="1" value="0" size="4" />
                    <td>
                        <?php
$data15 = mysqli_query($conn,"SELECT customer_type from customer where  id='$cid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$ttid=$info15['customer_type'];
$ppid=$info2['id'];
 $data15 = mysqli_query($conn,"SELECT price from customer_type_pricing where pid='$ttid' AND tid='$ppid' && company_id = '$current_company' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $info15['price'];?>"
                            class="change5 change6 income_count chk8ange totalorder" size="4" />
                        <?php } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100; 
$discount4=$info200['discount4']/100;
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3; 
$discount4=1-$discount4; 
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info200['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x;
    ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" value="0" min="0" 

                            class="change5 change6 income_count chk8ange totalorder" size="4"  required/>
                        <?php } else {  ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" min="0" name="unitcos[]" type="number" value="0"
                            class="change5 change6 income_count chk8ange totalorder" size="4"  required/>
                        <?php }  ?>
                    </td>
                    <?php if($info1000['customer_discount1']==1) { 
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from cb_discount where cid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from customer_type_discount1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($num_rows!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                            size="4" /></td>
                    <?php }
else if($num_rows2!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info17['discount'];?>"
                            size="4" /></td>
                    <?php }
 else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } 
 } else { ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount4 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
  if($info1000['customer_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" step="0.0001" size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='') {?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount3'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
else {?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from customer_type_scheme where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                            size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                        <input name="products_pcs[]" type="text"
                            <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { echo 'max="'.$maxx.'"'; } else { echo 'max="'.$info2['qty'].'"'; } } ?>
                            class="total_pcs" id="<?php echo "t".$info2['id'];?>" min="0" size="4" />
                    </td>
                    <?php if($info1000['customer_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info15['tax']; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td> <input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
  else {  ?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo 0; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" />
                    <?php } if($info1000['customer_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } 
else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied2']; ?>" size="4" /></td>
                    <?php }
else {  ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }  if($info1000['customer_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php }  
else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }    else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td><input type="hidden" name="products_cogs[]" value="<?php
      if($info1000['en_inventorybatch']==1) { echo $unitc; } else {  echo $info2['unit_cost']; } ?>"
                            class="prd_cogs" />
                        <input name="products_total[]" step="0.0001"  id="newtotal<?php echo $info2['id'];?>" type="number" min="0" 
                            class="form-control tot<?php echo $info2['id'];?> ptotal sub_total income_count readonly " tabindex="-1" size="5"
                            onkeypress="return false;" />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php if($info1000['en_inventorybatch']==1) {  ?>
                $('.change7').focusout(function() {
                            $(".change7").removeClass("change7");
                            <?php } else if($info1000['en_warehouse']==1) {  ?>
                            $('.change6').focusout(function() {
                                $(".change6").removeClass("change6");
                                <?php } else {  ?>
                                $('.change5').focusout(function() {
                                    $(".change5").removeClass("change5");
                                    <?php }  ?>
                                    var $orginal = $(this).closest("tr");
                                    var $cloned = $orginal.clone();
                                    //get original selects into a jq object
                                    var $originalSelects = $orginal.find('select');
                                    $cloned.find('select').each(function(index, item) {
                                        //set new select to value of old select
                                        $(item).val($originalSelects.eq(index).val());
                                    });
                                    //get original textareas into a jq object
                                    var $originalTextareas = $orginal.find('textarea');
                                    $cloned.find('textarea').each(function(index, item) {
                                        //set new textareas to value of old textareas
                                        $(item).val($originalTextareas.eq(index).val());
                                    });
                                    $cloned.appendTo("#acart");
                                    //});
                                    $('.change5').attr('class',
                                        " change income_count totalorder packing");
                                    $("#searchbox").focus();
                                    $("#psearch").html('');
                                    var n10 = $("#totpc").val();
                                    n10 = parseInt(n10) + parseInt(1);
                                    $("#totpc").val(n10);
                                    var n11 = $("#totpc").val();
                                    $(".sno:last").val(n11);
                                });
                            });
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { 
?>
    $(".inventory3").on('change', function() {
        var vid = $(this).val();
        var self = $(this);
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch5: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                var tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.total_pcs').attr("max", tt);
            }
        });
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch6: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.prd_cogs').attr("value", tt);
            }
        });
    });
    <?php }} ?>
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $(".delete").on('click', function() {
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass != 'brokery_rs' && specialclass != 'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  } 
 else if(isset($_POST['sid2324']))
{
$sub_quality=test_input($_POST['sid2324']);
$customerid=test_input($_POST['customerid']);
$main_quality=test_input($_POST['main_quality']);
$start_date=test_input($_POST['start_date']);
$end_date=test_input($_POST['end_date']);
$combination=test_input($_POST['combination']);
$warehouse=test_input($_POST['warehouse']);
if($sub_quality=='')
   $sub_quality2 = "";
  else {
$sub_quality = str_replace("a, "," ",$sub_quality);   
  $sub_quality2 = "  AND d.combination_id IN ( Select id from weaving_combination where sub_quality=$sub_quality) ";
  }
if($warehouse=='')
   $warehouse2 = "";
  else {
$warehouse = str_replace("a, "," ",$warehouse);   
  $warehouse2 = " AND d.combination_id IN ( Select id from weaving_combination where warehouse_id=$warehouse) ";
  }
if($combination=='')
   $combination2 = "";
  else {
$combination = str_replace("a, "," ",$combination);   
  $combination2 = " AND d.combination_id='$combination' ";
  }
if($customerid=='')
   $customerid2 = "";
  else {
$customerid = str_replace("a, "," ",$customerid);   
  $customerid2 = " AND d.combination_id IN ( Select id from weaving_combination where customer_id=$customerid) ";
  }
if($main_quality=='')
   $main_quality2 = "";
  else {
$main_quality = str_replace("a, "," ",$main_quality);   
  $main_quality2 = "  AND d.combination_id IN ( Select id from weaving_combination where other_material=$main_quality) ";
  }
if($start_date=='')
   $start_date2 = "";
  else {
  $d= $start_date;
$start_date2= " AND d.datetime >= '{$d}%'";
  }
  if($end_date=='')
   $end_date2 = "";
  else {
  $d2=  $end_date;
$end_date2= " AND d.datetime <= '{$d2}%'";
  }
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th>
                        <div>S.No</div>
                    </th>
                    <th>Date</th>
                    <th>
                        <div>Qty</div>
                    </th>
                </tr>
            </thead>
            <tbody>
                <?php  if($info1000['en_singleproducts']==1) { 
    $sno=0;  
    $tqty = 0;
 $data2 = mysqli_query($conn,"SELECT DATE(datetime) as ddt,   SUM(d.qty_total-d.delivery) as qty_total FROM production_weaving_details d WHERE  (d.qty_total-d.delivery)>0 $sub_quality2 $main_quality2 $combination2 $warehouse2 $customerid2 $start_date2 $end_date2 group by DATE(datetime)  ") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { 
 $sno++;
 $bid = $info2['did'];
 $tid = $info2['type_id'];
 $combination_id = $info2['combination_id'];
  $datetime = $info2['ddt'];
 $qtyid = $info2['qty_total'];
 $tqty = $tqty + $info2['qty_total'];
 ?>
                <tr class="carttr">
                    <td><?php echo $sno; ?></td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $info2['id'];?>" />
                        <input name="delivery_id[]" type="hidden" value="0" />
                        <h5><?php echo date('d M Y', strtotime($datetime)); ?></h5>
                    </td>
                    <td>
                        <input type="hidden" id="u<?php echo $info2['id'];?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input name="stitch_pcs" type="text"
                            class="searchqty <?php if($info1000['no_salespacking']==1) echo ' ';  ?> packing income_count totalorder qtychange "
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" value="<?php echo $qtyid; ?>" size="4"
                            readonly="readonly" />
                    </td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <input type="hidden" id="tserial" value="<?php echo $sno; ?>" />
    <input type="hidden" id="tqty" value="<?php echo $tqty; ?>" />
    <script type="text/javascript">
    $(document).ready(function() {
                var tserial = $('#tserial').val();
                var tqty = $('#tqty').val();
                $('#tserials2').val(tserial);
                $('#tqty2').val(tqty);
                <?php if($info1000['en_inventorybatch']==1) {  ?>
                $('.change7').focusout(function() {
                            $(".change7").removeClass("change7");
                            <?php } else if($info1000['en_warehouse']==1) {  ?>
                            $('.change6').focusout(function() {
                                $(".change6").removeClass("change6");
                                <?php } else {  ?>
                                $('.change5').focusout(function() {
                                    $(".change5").removeClass("change5");
                                    <?php }  ?>
                                    var $orginal = $(this).closest("tr");
                                    var $cloned = $orginal.clone();
                                    //get original selects into a jq object
                                    var $originalSelects = $orginal.find('select');
                                    $cloned.find('select').each(function(index, item) {
                                        //set new select to value of old select
                                        $(item).val($originalSelects.eq(index).val());
                                    });
                                    //get original textareas into a jq object
                                    var $originalTextareas = $orginal.find('textarea');
                                    $cloned.find('textarea').each(function(index, item) {
                                        //set new textareas to value of old textareas
                                        $(item).val($originalTextareas.eq(index).val());
                                    });
                                    $cloned.appendTo("#acart");
                                    //});
                                    $('.change5').attr('class',
                                        " change income_count totalorder packing");
                                    $("#searchbox").focus();
                                    $("#psearch").html('');
                                    var n10 = $("#totpc").val();
                                    n10 = parseInt(n10) + parseInt(1);
                                    $("#totpc").val(n10);
                                    var n11 = $("#totpc").val();
                                    $(".sno:last").val(n11);
                                });
                            });
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { 
?>
    $(".inventory3").on('change', function() {
        var vid = $(this).val();
        var self = $(this);
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch5: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                var tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.total_pcs').attr("max", tt);
            }
        });
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch6: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.prd_cogs').attr("value", tt);
            }
        });
    });
    <?php }} ?>
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $(".delete").on('click', function() {
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass != 'brokery_rs' && specialclass != 'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  } 
 else if(isset($_POST['sid23241']))
{
$sub_quality=test_input($_POST['sid23241']);
$customerid=test_input($_POST['customerid']);
$main_quality=test_input($_POST['main_quality']);
$start_date=test_input($_POST['start_date']);
$end_date=test_input($_POST['end_date']);
$warehouse=test_input($_POST['warehouse']);
if($sub_quality=='')
   $sub_quality2 = "";
  else {
$sub_quality = str_replace("a, "," ",$sub_quality);   
  $sub_quality2 = "  AND d.combination_id IN ( Select id from weaving_combination where sub_quality=$sub_quality) ";
  }
if($customerid=='')
   $customerid2 = "";
  else {
$customerid = str_replace("a, "," ",$customerid);   
  $customerid2 = " AND d.combination_id IN ( Select id from weaving_combination where customer_id=$customerid) ";
  }
if($main_quality=='')
   $main_quality2 = "";
  else {
$main_quality = str_replace("a, "," ",$main_quality);   
  $main_quality2 = "  AND d.combination_id IN ( Select id from weaving_combination where other_material=$main_quality) ";
  }
if($warehouse=='')
   $warehouse2 = "";
  else {
$warehouse = str_replace("a, "," ",$warehouse);   
  $warehouse2 = "  AND d.combination_id IN ( Select id from weaving_combination where warehouse_id=$warehouse) ";
  } 
if($start_date=='')
   $start_date2 = "";
  else {
  $d= $start_date;
$start_date2= " AND d.datetime >= '{$d}%'";
  }
  if($end_date=='')
   $end_date2 = "";
  else {
  $d2=  $end_date;
$end_date2= " AND d.datetime <= '{$d2}%'";
  }
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th>
                        <div>S.No</div>
                    </th>
                    <th>Date</th>
                    <th>
                        <div>Qty</div>
                    </th>
                </tr>
            </thead>
            <tbody>
                <?php  if($info1000['en_singleproducts']==1) { 
    $sno=0;  
    $tqty = 0;
 $data2 = mysqli_query($conn,"SELECT DATE(datetime) as ddt, SUM(d.qty_total-d.invoice) as qty_total FROM production_weaving_details d WHERE  (d.qty_total-d.invoice)>0 $sub_quality2  $main_quality2 $customerid2 $start_date2 $end_date2 $warehouse2 group by DATE(datetime)  ") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { 
 $sno++;
 $bid = $info2['did'];
 $tid = $info2['type_id'];
 $combination_id = $info2['combination_id'];
  $datetime = $info2['ddt'];
 $qtyid = $info2['qty_total'];
 $tqty = $tqty + $info2['qty_total'];
 ?>
                <tr class="carttr">
                    <td><?php echo $sno; ?></td>
                    <td>
                        <h5><?php echo date('d M Y', strtotime($datetime)); ?></h5>
                    </td>
                    <td>
                        <input type="hidden" id="u<?php echo $info2['id'];?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input type="text"
                            class="searchqty <?php if($info1000['no_salespacking']==1) echo ' ';  ?> packing income_count totalorder "
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" value="<?php echo $qtyid; ?>" size="4"
                            readonly="readonly" min="1" />
                    </td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <input type="hidden" id="tserial" value="<?php echo $sno; ?>" />
    <input type="hidden" id="tqty" value="<?php echo $tqty; ?>" />
    <script type="text/javascript">
    $(document).ready(function() {
                var tserial = $('#tserial').val();
                var tqty = $('#tqty').val();
                $('#tserials2').val(tserial);
                $('#tqty2').val(tqty);
                <?php if($info1000['en_inventorybatch']==1) {  ?>
                $('.change7').focusout(function() {
                            $(".change7").removeClass("change7");
                            <?php } else if($info1000['en_warehouse']==1) {  ?>
                            $('.change6').focusout(function() {
                                $(".change6").removeClass("change6");
                                <?php } else {  ?>
                                $('.change5').focusout(function() {
                                    $(".change5").removeClass("change5");
                                    <?php }  ?>
                                    var $orginal = $(this).closest("tr");
                                    var $cloned = $orginal.clone();
                                    //get original selects into a jq object
                                    var $originalSelects = $orginal.find('select');
                                    $cloned.find('select').each(function(index, item) {
                                        //set new select to value of old select
                                        $(item).val($originalSelects.eq(index).val());
                                    });
                                    //get original textareas into a jq object
                                    var $originalTextareas = $orginal.find('textarea');
                                    $cloned.find('textarea').each(function(index, item) {
                                        //set new textareas to value of old textareas
                                        $(item).val($originalTextareas.eq(index).val());
                                    });
                                    $cloned.appendTo("#acart");
                                    //});
                                    $('.change5').attr('class',
                                        " change income_count totalorder packing");
                                    $("#searchbox").focus();
                                    $("#psearch").html('');
                                    var n10 = $("#totpc").val();
                                    n10 = parseInt(n10) + parseInt(1);
                                    $("#totpc").val(n10);
                                    var n11 = $("#totpc").val();
                                    $(".sno:last").val(n11);
                                });
                            });
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { 
?>
    $(".inventory3").on('change', function() {
        var vid = $(this).val();
        var self = $(this);
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch5: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                var tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.total_pcs').attr("max", tt);
            }
        });
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch6: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.prd_cogs').attr("value", tt);
            }
        });
    });
    <?php }} ?>
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $(".delete").on('click', function() {
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass != 'brokery_rs' && specialclass != 'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  } 
 else if(isset($_POST['sid2325']))
{
$sub_quality=test_input($_POST['sid2325']);
$customerid=test_input($_POST['customerid']);
$main_quality=test_input($_POST['main_quality']);
$start_date=test_input($_POST['start_date']);
$end_date=test_input($_POST['end_date']);
$combination=test_input($_POST['combination']);
$warehouse=test_input($_POST['warehouse']);
if($sub_quality=='')
   $sub_quality2 = "";
  else {
$sub_quality = str_replace("a, "," ",$sub_quality);   
  $sub_quality2 = "  AND d.combination_id IN ( Select id from weaving_combination where sub_quality=$sub_quality) ";
  }
if($customerid=='')
   $customerid2 = "";
  else {
$customerid = str_replace("a, "," ",$customerid);   
  $customerid2 = " AND d.combination_id IN ( Select id from weaving_combination where customer_id=$customerid) ";
  }
if($warehouse=='')
   $warehouse2 = "";
  else {
$warehouse = str_replace("a, "," ",$warehouse);   
  $warehouse2 = " AND d.combination_id IN ( Select id from weaving_combination where warehouse_id=$warehouse) ";
  }
if($combination=='')
   $combination2 = "";
  else {
$combination = str_replace("a, "," ",$combination);   
  $combination2 = " AND d.combination_id='$combination' ";
  }
if($main_quality=='')
   $main_quality2 = "";
  else {
$main_quality = str_replace("a, "," ",$main_quality);   
  $main_quality2 = "  AND d.combination_id IN ( Select id from weaving_combination where other_material=$main_quality) ";
  }
if($start_date=='')
   $start_date2 = "";
  else {
  $d= $start_date;
$start_date2= " AND d.datetime >= '{$d}%'";
  }
  if($end_date=='')
   $end_date2 = "";
  else {
  $d2=  $end_date;
$end_date2= " AND d.datetime <= '{$d2}%'";
  }
?>
    <div class="table-responsive table-card mt-4">
        <table width="100%" class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr class="test">
                    <th width="5%">
                        <div>S.No</div>
                    </th>
                    <th width="10%">Combination</th>
                    <th width="10%">
                        <div>Total Qty</div>
                    </th>
                    <th width="60%">
                        <div>Serials</div>
                    </th>
                </tr>
            </thead>
            <tbody>
                <?php  if($info1000['en_singleproducts']==1) { 
    $sno=0;  
    $tqty = 0;
 $data2 = mysqli_query($conn,"SELECT combination_id as ddt,   SUM(d.qty_total-d.delivery) as qty_total FROM production_weaving_details d WHERE (d.`qty_total`-d.`delivery`)>0 $sub_quality2 $main_quality2 $customerid2 $combination2 $warehouse2 $start_date2 $end_date2 group by combination_id  ") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { 
 $sno++;
 $bid = $info2['did'];
 $tid = $info2['qty_total'];
 $combination_id = $info2['ddt'];
 $cwarehouse = mysqli_get_var("Select name from weaving_combination where `id` = '$combination_id'");
 ?>
                <tr class="carttr">
                    <td><?php echo $sno; ?></td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $combination_id; ?>" />
                        <h5><?php echo $cwarehouse; ?></h5>
                    </td>
                    <td>
                        <input name="stitch_pcs" type="text"
                            class="searchqty <?php if($info1000['no_salespacking']==1) echo ' ';  ?> packing income_count qtychange totalorder "
                            id="<?php echo $combination_id;?>" tabindex="1" value="<?php echo $tid; ?>" size="4"
                            readonly="readonly" />
                    </td>
                    <td>
                        <div class="serials_div"><input name="<?php echo $combination_id; ?>_single[]" type="text"
                                class="issues_single" value="0" size="5" maxlength="5" /></div>
                    </td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <?php
  } 
 else if(isset($_POST['sid23258']))
{
$sub_quality=test_input($_POST['sid23258']);
$customerid=test_input($_POST['customerid']);
$main_quality=test_input($_POST['main_quality']);
$type=test_input($_POST['type2']);
$brand=test_input($_POST['brand2']);
$start_date=test_input($_POST['start_date']);
$end_date=test_input($_POST['end_date']);
if($sub_quality=='') {
   $sub_quality2 = "";
   $warehouse4="";
    }
  else {
$sub_quality = str_replace("a, "," ",$sub_quality);   
  $sub_quality2 = "  AND d.production_id IN ( Select id from production_weaving where location_id=$sub_quality) ";
  $warehouse4 = " && w.warehouse_id='$sub_quality' ";
  }
if($customerid=='') {
   $customerid2 = ""; 
   $customer4 = "";
   }
  else {
$customerid = str_replace("a, "," ",$customerid);   
  $customerid2 = " AND d.combination_id IN ( Select id from weaving_combination where customer_id=$customerid) ";
    $customer4 = " && w.customer_id='$customerid' ";
  }
if($main_quality=='') {
   $main_quality2 = "";
   $quality4 = "";
    }
  else {
$main_quality = str_replace("a, "," ",$main_quality);   
  $main_quality2 = "  AND d.combination_id IN ( Select id from weaving_combination where other_material=$main_quality) ";
    $quality4 = " && w.item_id='$main_quality' ";
  }
if($brand=='') {
   $brand2 = "";
     $brand4 = "";
    }
  else {
$brand = str_replace("a, "," ",$brand);   
  $brand2 = "  AND d.combination_id IN ( Select id from weaving_combination where brand_id=$brand) ";
      $brand4 = " && w.brand_id='$brand' ";
  }
if($type=='') {
   $type2 = "";
    $type4 = "";
    }
  else {
$type = str_replace("a, "," ",$type);   
  $type2 = "  AND d.combination_id IN ( Select id from weaving_combination where type_id=$type) ";
        $type4 = " && w.type_id='$type' ";
  }
if($start_date=='')
{
   $start_date2 = "";
   $start4 = " && 1=4 ";
}
else {
  $d= $start_date;
$start_date2= " AND d.datetime >= '{$d}%'";
$start4= " AND w.datetime >= '{$d}%'";
$start5= " AND w.datetime < '{$d}%'";
  }
  if($end_date=='')
{
   $end_date2 = "";
   $end4 = " && 1=2";
} else {
  $d2=  $end_date;
$end_date2= " AND d.datetime <= '{$d2}%'";
$end4 = " AND w.datetime <= '{$d2}%'";
}
?>
    <div class="table-responsive table-card mt-4">
        <table width="100%" class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr class="test">
                    <th>
                        <div>S.No</div>
                    </th>
                    <th>
                        <div>Combination</div>
                    </th>
                    <th>
                        <div>Sub Quality</div>
                    </th>
                    <th>
                        <div>Pick</div>
                    </th>
                    <th>
                        <div>Width</div>
                    </th>
                    <th>
                        <div>Total Production</div>
                    </th>
                    <th>
                        <div>Total Pick</div>
                    </th>
                    <th>
                        <div>Total Consumption</div>
                    </th>
                    <th>
                        <div>Total Consumption (Pounds)</div>
                    </th>
                    <th>
                        <div>Total Consumption (KG)</div>
                    </th>
                </tr>
            </thead>
            <tbody>
                <?php 
    $sno=0;  
    $tqty = 0;
 $data2 = mysqli_query($conn,"SELECT combination_id as ddt,   SUM(qty_total) as qty_total FROM production_weaving_details d WHERE  d.`consumption`=0 $sub_quality2 $main_quality2 $customerid2 $type2 $brand2 $start_date2 $end_date2 group by combination_id  ") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { 
 $sno++;
 $bid = $info2['did'];
 $tid = $info2['qty_total'];
 $combination_id = $info2['ddt'];
 $cwarehouse = mysqli_get_var("Select name from weaving_combination where `id` = '$combination_id'");
 $cpick = mysqli_get_var("Select pick from weaving_combination where `id` = '$combination_id'");
   $cwidth = mysqli_get_var("Select width from weaving_combination where `id` = '$combination_id'");
   $csub_quality = mysqli_get_var("Select name from component where id IN (Select sub_quality from weaving_combination where `id` = '$combination_id' )");
 ?>
                <tr class="carttr">
                    <td><?php echo $sno; ?></td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $combination_id; ?>" />
                        <h5><?php echo $cwarehouse; ?></h5>
                    </td>
                    <td><?php echo $csub_quality;  ?></td>
                    <td>
                        <input name="pick[]" type="text" class="form-control pick" value="<?php echo $cpick; ?>"
                            readonly="readonly" />
                    </td>
                    <td>
                        <input name="width[]" type="text" class="form-control width" value="<?php echo $cwidth; ?>"
                            readonly="readonly" />
                    </td>
                    <td>
                        <input name="stitch_pcs[]" type="text"
                            class="form-control packing income_count total_production"
                            id="ctn<?php echo $combination_id;?>" tabindex="1" value="<?php echo $tid; ?>" size="4"
                            readonly="readonly" min="0" />
                    </td>
                    <td>
                        <input name="total_pick[]" type="text" class="form-control total_pick"
                            value="<?php echo $cpick*$cwidth*$tid;  ?>" readonly="readonly" />
                    </td>
                    <td>
                        <input type="text" name="total_consumption[]" required class="form-control total_consumption" />
                    </td>
                    <td>
                        <input type="text" name="total_pounds[]" required class="form-control total_pounds" />
                    </td>
                    <td>
                        <input type="text" name="total_fakeconsumption[]" required
                            class="form-control total_fakeconsumption" />
                    </td>
                </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
    <?php if($sno==0) { ?><div style="display:none;"> <input name="new" type="text" required="required" /></div>
    <?php } ?>
    <?php
  $obplus = mysqli_get_var("SELECT SUM(qty) FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.tran_type=tt.id $warehouse4 $customer4 $quality4 $start5 $brand4 $type4  && w.deleted=0  && w.warehouse_id!=0 && w.warehouse_id!=0 && tt.type=1 && w.process=1 ");
  $obminus = mysqli_get_var("SELECT SUM(qty) FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.tran_type=tt.id $warehouse4 $customer4 $quality4 $start5 $brand4 $type4  && w.deleted=0  && w.warehouse_id!=0 && w.warehouse_id!=0 && tt.type=0 && w.process=1 ");
   $oin = mysqli_get_var("SELECT SUM(qty) FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.tran_type=tt.id $warehouse4  $customer4 $quality4 $start4 $end4 $brand4 $type4 && w.deleted=0  && w.warehouse_id!=0 && tt.id=1 && tt.type=1 && w.process=1 ");
  $oout = mysqli_get_var("SELECT SUM(qty) FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.tran_type=tt.id $warehouse4  $customer4 $quality4 $start4 $end4 $brand4 $type4 && w.deleted=0  && w.warehouse_id!=0 && tt.id=2 && tt.type=0 && w.process=1 ");  
  $oreceiving = mysqli_get_var("SELECT SUM(qty) FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.tran_type=tt.id $warehouse4 $customer4 $quality4 $start4 $brand4 $type4 $end4 && w.deleted=0  && w.warehouse_id!=0 && tt.id=26 && tt.type=1 && w.process=1 ");
  $odelivery = mysqli_get_var("SELECT SUM(qty) FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.tran_type=tt.id $warehouse4 $customer4 $quality4 $start4 $end4 $brand4 $type4 && w.deleted=0  && w.warehouse_id!=0 && tt.id=27 && tt.type=0 && w.process=1 ");
  $oproduction = mysqli_get_var("SELECT SUM(qty) FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.tran_type=tt.id $warehouse4 $customer4 $quality4 $start4 $end4 $brand4 $type4 && w.deleted=0  && w.warehouse_id!=0 && tt.id=25 && tt.type=0 && w.process=1 ");
  if($obplus=='') $obplus=0;
  if($obminus=='') $obminus=0;
  if($oin=='') $oin=0;
  if($oout=='') $oout=0;
  if($oreceiving=='') $oreceiving=0;
  if($odelivery=='') $odelivery=0;
  if($oproduction=='') $oproduction=0;
  $oba = $obplus-$obminus;
?>
    <script>
    $("#coba").val(<?php echo $oba; ?>);
    $("#creceived").val(<?php echo $oreceiving; ?>);
    $("#cin").val(<?php echo $oin; ?>);
    $("#cout").val(<?php echo $oout; ?>);
    $("#cdelivery").val(<?php echo $odelivery; ?>);
    $("#aproduction").val(<?php echo $oproduction; ?>);
    // $("#physical_stock").trigger('change');
    $('#physical_stock').on('change', function() {
        var oba = $("#coba").val();
        var oreceiving = $("#creceived").val();
        var oin = $("#cin").val();
        var oout = $("#cout").val();
        var odelivery = $("#cdelivery").val();
        var oproduction = $("#aproduction").val();
        var physical_stock = $("#physical_stock").val();
        var old = parseFloat(oba) + parseFloat(oreceiving) + parseFloat(oin) - parseFloat(oout) - parseFloat(
            odelivery);
        var bb = parseFloat(old) - parseFloat(physical_stock) + parseFloat(oproduction);
        $("#cproduction").val(bb);
        var productionpounds = bb * 2.2046;
        $('.total_pick').each(function() {
            var pick = $(this).val();
            var bb = $("#cproduction").val();
            var pounds = bb * 2.2046;
            var sum = 0;
            $('.total_pick').each(function() {
                sum += parseFloat(this.value);
            });
            pounds = pounds / sum;
            var production = $(this).closest(".carttr").find(".total_production").val();
            var consumed = (pounds * pick * 1000) / (production);
            var kg5 = (consumed / 1000) / 2.2046 * production;
            var pounds5 = (consumed / 1000) / production;
            $(this).closest(".carttr").find(".total_consumption").val(consumed);
            $(this).closest(".carttr").find(".total_pounds").val(pounds5);
            $(this).closest(".carttr").find(".total_fakeconsumption").val(kg5);
        });
    });
    $('#customer_consumption').on('change', function() {
        var oba = $("#coba").val();
        var oreceiving = $("#creceived").val();
        var oin = $("#cin").val();
        var oout = $("#cout").val();
        var odelivery = $("#cdelivery").val();
        var oproduction = $("#aproduction").val();
        var physical_stock = $("#physical_stock").val();
        var customer_consumption = $("#customer_consumption").val();
        var old = parseFloat(oba) + parseFloat(oreceiving) + parseFloat(oin) - parseFloat(oout) - parseFloat(
            odelivery);
        var bb = parseFloat(old) - parseFloat(physical_stock) + parseFloat(oproduction);
        $("#cproduction").val(bb);
        $('.total_pick').each(function() {
            var pick = $(this).val();
            var bb = $("#cproduction").val();
            var pounds = bb * 2.2046;
            var width = $(this).closest(".carttr").find(".width").val();
            var customer_consumption = $("#customer_consumption").val();
            var sum = customer_consumption / width;
            sum = sum / pick;
            pounds = pounds / sum;
            var production = $(this).closest(".carttr").find(".total_production").val();
            var consumed = (pounds * pick) / (production * 1000);
            $(this).closest(".carttr").find(".total_pounds").val(consumed);
            $(this).closest(".carttr").find(".total_fakeconsumption").val(consumed);
        });
    });
    </script>
    <?php   } 
 else if(isset($_POST['sid232581']))
{
$sub_quality=test_input($_POST['sid232581']);
$customerid=test_input($_POST['customerid']);
$main_quality=test_input($_POST['main_quality']);
$start_date=test_input($_POST['start_date']);
$end_date=test_input($_POST['end_date']);
if($sub_quality=='') {
   $sub_quality2 = "";
   $warehouse4="";
    }
  else {
$sub_quality = str_replace("a, "," ",$sub_quality);   
  $sub_quality2 = "  AND d.production_id IN ( Select id from production_weaving where location_id=$sub_quality) ";
  $warehouse4 = " && w.warehouse_id='$sub_quality' ";
  }
if($customerid=='') {
   $customerid2 = ""; 
   $customer4 = "";
   }
  else {
$customerid = str_replace("a, "," ",$customerid);   
  $customerid2 = " AND d.combination_id IN ( Select id from weaving_combination where customer_id=$customerid) ";
    $customer4 = " && w.customer_id='$customerid' ";
  }
if($main_quality=='') {
   $main_quality2 = "";
   $quality4 = "";
    }
  else {
$main_quality = str_replace("a, "," ",$main_quality);   
  $main_quality2 = "  AND d.combination_id IN ( Select id from weaving_combination where other_material=$main_quality) ";
    $quality4 = " && w.item_id='$main_quality' ";
  }
if($start_date=='')
{
   $start_date2 = "";
   $start4 = " && 1=4";
}
else {
  $d= $start_date;
$start_date2= " AND d.datetime >= '{$d}%'";
$start4= " AND w.datetime >= '{$d}%'";
$start5= " AND w.datetime < '{$d}%'";
  }
  if($end_date=='')
{
   $end_date2 = "";
   $end4 = " && 1=2";
} else {
  $d2=  $end_date;
$end_date2= " AND d.datetime <= '{$d2}%'";
$end4 = " AND w.datetime <= '{$d2}%'";
  }
?>
    <div class="table-responsive table-card mt-4">
        <table width="100%" class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr class="test">
                    <th>
                        <div>S.No</div>
                    </th>
                    <th>
                        <div>Combination</div>
                    </th>
                    <th>
                        <div>Sub Quality</div>
                    </th>
                    <th>
                        <div>Pick</div>
                    </th>
                    <th>
                        <div>Width</div>
                    </th>
                    <th>
                        <div>Total Production</div>
                    </th>
                    <th>
                        <div>Total Pick</div>
                    </th>
                    <th>
                        <div>Total Consumption</div>
                    </th>
                    <th>
                        <div>Total Consumption (Pounds)</div>
                    </th>
                    <th>
                        <div>Total Consumption (KG)</div>
                    </th>
                </tr>
            </thead>
            <tbody>
                <?php  
    $sno=0;  
    $tqty = 0;
 $data2 = mysqli_query($conn,"SELECT combination_id as ddt,   SUM(qty_total) as qty_total FROM production_weaving_details d WHERE  d.`consumption_customer`=0 $sub_quality2 $main_quality2 $customerid2 $start_date2 $end_date2 group by combination_id  ") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { 
 $sno++;
 $bid = $info2['did'];
 $tid = $info2['qty_total'];
 $combination_id = $info2['ddt'];
 $cwarehouse = mysqli_get_var("Select name from weaving_combination where `id` = '$combination_id'");
 $cpick = mysqli_get_var("Select pick from weaving_combination where `id` = '$combination_id'");
   $cwidth = mysqli_get_var("Select width from weaving_combination where `id` = '$combination_id'");
   $csub_quality = mysqli_get_var("Select name from component where id IN (Select sub_quality from weaving_combination where `id` = '$combination_id' )");
 ?>
                <tr class="carttr">
                    <td><?php echo $sno; ?>
                        <input type="hidden" name="products[]2" value="<?php echo $combination_id; ?>" />
                    </td>
                    <td>
                        <h5><?php echo $cwarehouse; ?></h5>
                    </td>
                    <td><?php echo $csub_quality; ?></td>
                    <td>
                        <input name="pick[]" type="text" class="form-control pick" value="<?php echo $cpick; ?>"
                            readonly="readonly" />
                    </td>
                    <td>
                        <input name="width[]" type="text" class="form-control width" value="<?php echo $cwidth; ?>"
                            readonly="readonly" />
                    </td>
                    <td>
                        <input name="stitch_pcs[]" type="text"
                            class="form-control packing income_count total_production"
                            id="ctn<?php echo $combination_id;?>" tabindex="1" value="<?php echo $tid; ?>" size="4"
                            readonly="readonly" min="0" />
                    </td>
                    <td>
                        <input name="total_pick[]" type="text" class="form-control total_pick"
                            value="<?php echo $cpick*$cwidth*$tid;  ?>" readonly="readonly" />
                    </td>
                    <td>
                        <input type="text" name="total_consumption[]" required class="form-control total_consumption" />
                    </td>
                    <td>
                        <input type="text" name="total_pounds[]" required class="form-control total_pounds" />
                    </td>
                    <td>
                        <input type="text" name="total_fakeconsumption[]" required
                            class="form-control total_fakeconsumption" />
                    </td>
                </tr>
                <?php  } ?>
            </tbody>
        </table>
    </div>
    <?php if($sno==0) { ?><div style="display:none;"> <input name="new" type="text" required="required" /></div>
    <?php } ?>
    <?php
 $obplus = mysqli_get_var("SELECT SUM(qty) FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.tran_type=tt.id $warehouse4 $customer4 $quality4 $start5  && w.deleted=0  && w.warehouse_id!=0 && tt.type=1 && w.process=1 ");
 $obminus = mysqli_get_var("SELECT SUM(qty) FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.tran_type=tt.id $warehouse4 $customer4 $quality4 $start5  && tt.type=0 && (tt.id!=25 || (w.deleted=1 && w.process=2)) ");
 $oin = mysqli_get_var("SELECT SUM(qty) FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.tran_type=tt.id $warehouse4  $quality4 $start4 $end4 && w.deleted=0  && w.warehouse_id!=0 && tt.id=1 && tt.type=1 && w.process=1 ");
   $oout = mysqli_get_var("SELECT SUM(qty) FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.tran_type=tt.id $warehouse4  $quality4 $start4 $end4 && w.deleted=0  && w.warehouse_id!=0 && tt.id=2 && tt.type=0 && w.process=1 ");  
  $oreceiving = mysqli_get_var("SELECT SUM(qty) FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.tran_type=tt.id $warehouse4 $customer4 $quality4 $start4 $end4 && w.deleted=0  && w.warehouse_id!=0 && tt.id=26 && tt.type=1 && w.process=1 ");
  $oproduction = mysqli_get_var("SELECT SUM(qty) FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.tran_type=tt.id $warehouse4 $customer4 $quality4 $start4 $end4 && w.deleted=1 && tt.id=25 && tt.type=0 && w.process=2 "); 
   $odelivery = mysqli_get_var("SELECT SUM(qty) FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.tran_type=tt.id $warehouse4 $customer4 $quality4 $start4 $end4 && w.deleted=0  && w.warehouse_id!=0 && tt.id=27 && tt.type=0 && w.process=1 ");
  $oba = $obplus-$obminus;
if($obplus=='') $obplus=0;
  if($obminus=='') $obminus=0;
  if($oin=='') $oin=0;
  if($oout=='') $oout=0;
  if($oreceiving=='') $oreceiving=0;
  if($odelivery=='') $odelivery=0;
  if($oproduction=='') $oproduction=0;
$physical_stock = $oba - $oout - $odelivery - $oproduction + $oin + $oreceiving;
?>
    <script>
    $("#coba").val(<?php echo $oba; ?>);
    $("#creceived").val(<?php echo $oreceiving; ?>);
    $("#cin").val(<?php echo $oin; ?>);
    $("#cout").val(<?php echo $oout; ?>);
    $("#cdelivery").val(<?php echo $odelivery; ?>);
    $("#aproduction").val(<?php echo $oproduction; ?>);
    $("#physical_stock").val(<?php echo $physical_stock; ?>);
    $('.total_consumption').on('change', function() {
        var oba = $("#coba").val();
        var oreceiving = $("#creceived").val();
        var oin = $("#cin").val();
        var oout = $("#cout").val();
        var odelivery = $("#cdelivery").val();
        var oproduction = $("#aproduction").val();
        var physical_stock = $("#physical_stock").val();
        var old = parseFloat(oba) + parseFloat(oreceiving) + parseFloat(oin) - parseFloat(oout) - parseFloat(
            odelivery);
        var bb = parseFloat(old) - parseFloat(physical_stock) + parseFloat(oproduction);
        var total_consumption = $(this).val();
        var pick = $(this).closest(".carttr").find(".pick").val();
        var width = $(this).closest(".carttr").find(".width").val();
        var that = $(this);
        var fake_consumption = (total_consumption / pick) / width;
        $('.total_pick').each(function() {
            var npick = $(this).closest(".carttr").find(".pick").val();
            var nwidth = $(this).closest(".carttr").find(".width").val();
            var nproduction = $(this).closest(".carttr").find(".total_production").val();
            var nconsumed = fake_consumption * nwidth * npick;
            var pounds5 = (nconsumed / 1000) / nproduction;
            var kg5 = (nconsumed / 1000) / 2.2046 * nproduction;
            $(this).closest(".carttr").find(".total_pounds").val(pounds5.toFixed(3));
            $(this).closest(".carttr").find(".total_consumption").val(nconsumed.toFixed(3));
            $(this).closest(".carttr").find(".total_pounds").val(pounds5.toFixed(3));
            $(this).closest(".carttr").find(".total_fakeconsumption").val(kg5.toFixed(3));
        });
        var sum5 = bb;
        $(".total_fakeconsumption").each(function() {
            sum5 += +$(this).val();
        });
        $("#cproduction").val(sum5);
    });
    </script>
    <?php   } 
 else if(isset($_POST['sid23251']))
{
$sub_quality=test_input($_POST['sid23251']);
$customerid=test_input($_POST['customerid']);
$main_quality=test_input($_POST['main_quality']);
$start_date=test_input($_POST['start_date']);
$end_date=test_input($_POST['end_date']);
$warehouse=test_input($_POST['warehouse']);
if($sub_quality=='')
   $sub_quality2 = "";
  else {
$sub_quality = str_replace("a, "," ",$sub_quality);   
  $sub_quality2 = "  AND d.combination_id IN ( Select id from weaving_combination where sub_quality=$sub_quality) ";
  }
if($warehouse=='')
   $warehouse2 = "";
  else {
$warehouse = str_replace("a, "," ",$warehouse);   
  $warehouse2 = "  AND d.combination_id IN ( Select id from weaving_combination where warehouse_id=$warehouse) ";
  } 
if($customerid=='')
   $customerid2 = "";
  else {
$customerid = str_replace("a, "," ",$customerid);   
  $customerid2 = " AND d.combination_id IN ( Select id from weaving_combination where customer_id=$customerid) ";
  }
if($main_quality=='')
   $main_quality2 = "";
  else {
$main_quality = str_replace("a, "," ",$main_quality);   
  $main_quality2 = "  AND d.combination_id IN ( Select id from weaving_combination where other_material=$main_quality) ";
  }
if($start_date=='')
   $start_date2 = "";
  else {
  $d= $start_date;
$start_date2= " AND d.datetime >= '{$d}%'";
  }
  if($end_date=='')
   $end_date2 = "";
  else {
  $d2=  $end_date;
$end_date2= " AND d.datetime <= '{$d2}%'";
  }
?>
    <div class="table-responsive table-card mt-4">
        <table width="100%" class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr class="test">
                    <th>
                        <div>S.No</div>
                    </th>
                    <th>
                        <div>Combination</div>
                    </th>
                    <th>
                        <div>Qty</div>
                    </th>
                    <th>
                        <div>Rate</div>
                    </th>
                    <th>
                        <div>Total</div>
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php  if($info1000['en_singleproducts']==1) { 
    $sno=0;  
    $tqty = 0;
 $data2 = mysqli_query($conn,"SELECT combination_id as ddt,   SUM(qty_total-invoice) as qty_total FROM production_weaving_details d WHERE  (qty_total-d.`invoice`)>0 $sub_quality2 $main_quality2 $customerid2 $start_date2 $warehouse2 $end_date2 group by combination_id  ") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { 
 $sno++;
 $bid = $info2['did'];
 $tid = $info2['qty_total'];
 $combination_id = $info2['ddt'];
 $cwarehouse = mysqli_get_var("Select name from weaving_combination where `id` = '$combination_id'");
 ?>
                <tr class="carttr">
                    <td><?php echo $sno; ?></td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $combination_id; ?>" />
                        <h5><?php echo $cwarehouse; ?></h5>
                    </td>
                    <td>
                        <input name="stitch_pcs[]" type="text"
                            class="searchqty income_count singleqty <?php if($info1000['no_salespacking']==1) echo ' ';  ?> packing income_count totalorder "
                            id="ctn<?php echo $combination_id;?>" tabindex="1" value="<?php echo $tid; ?>" size="4" min="0" />
                    </td>
                    <td>
                        <div class="serials_div"><input name="qty_single[]" type="text"
                                class="issues_single income_count" tabindex="1" value="0" size="5" maxlength="5" />
                        </div>
                    </td>
                    <td><input name="sub_total[]" tabindex="1" type="text" class="sub_total income_count" value="0"
                            size="5" maxlength="5" /></td>
                    <td>
                        <input type="button" class="newrow1 btn btn-success" value="-" />
                    </td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <script>
    $('.income_count').on('change', function() {
        var qty = $(this).closest(".carttr").find(".singleqty").val();
        var rate = $(this).closest(".carttr").find(".issues_single").val();
        var totsub = qty * rate;
        $(this).closest(".carttr").find(".sub_total").val(totsub);
        var sum = 0;
        $('.sub_total').each(function() {
            sum += parseFloat($(this).val()); // Or this.innerHTML, this.innerText
        });
        $("#total").val(sum);
        $("#sub_total").val(sum);
        $("#pending_amount").val(sum);
    });
    </script>
    <?php
  } 
 else if(isset($_POST['grn2']))
{
$sid=test_input($_POST['grn2']);
$cid=test_input($_POST['customerid']);
$st=test_input($_POST['st']);
$cwarehouse = mysqli_get_var("Select inventory_warehouse from customer where `id` = '$cid'");
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="2%">S.No</th>
                    <th width="25%">
                        <div><?php echo $info1000['product_label']; ?></div>
                    </th>
                    <th>
                        <div>Type</div>
                    </th>
                    <th>
                        <div>Qty</div>
                    </th>
                    <th>
                        <div>Stitch/Unit</div>
                    </th>
                    <th>
                        <div>Unit</div>
                    </th>
                    <th>
                        <div>Color</div>
                    </th>
                    <th>
                        <div>Head Working</div>
                    </th>
                    <th>
                        <div>Fusing</div>
                    </th>
                    <th>
                        <div>Rate</div>
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
   if($info1000['en_deals']==1) { 
    $data2 = mysqli_query($conn,"SELECT * from deal where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr>
                    <td class="sno"></td>
                    <td><input type="hidden" name="deal[]" value="d<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <?php 
   $did=$info2['id'];
   $data15 = mysqli_query($conn,"SELECT *, i.qty/d.qty AS aqty, d.qty AS dqty from inventory i, deal_details d where d.did='$did' AND d.pid=i.id") or die(mysqli_error($conn));
  $taqty=10000; 
while($info15 = mysqli_fetch_array( $data15 )) 
 { 
 if($info15['aqty']<=$taqty)
 {
 $taqty=$info15['aqty'];
 }
 else {
 $info15['aqty']=ceil($taqty);
 }
 $staqty=$info15['aqty'];
 echo $info15['dqty']." Pcs - ".$info15['name']."<br>";
 }
 ?>
                    </td>
                    <td><?php  if($staqty<$taqty)
        {
        echo ceil($staqty);
        }
        else  {
          $staqty=$taqty;
           echo ceil($staqty);
        }
        ?></td>
                    <td>
                        <input name="d<?php echo $info2['id'];?>" type="text" min="1"
                            class="searchqty income_count form-control" id="d<?php echo $info2['id'];?>"
                            tabindex="1" />
                    </td>
                    <td><input type="text" class="form-control income_count" /> </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='".$info2['id']."_warehouse' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <?php echo $info2['packing'];?></td>
                    <td>
                        <input id="<?php echo "nm".$info2['id'];?>" value="<?php echo $info2['sale_price'];?>"
                            class="income_count" onchange="changealert(this.id)" size="20" />
                    </td>
                    <td><input type="text" class="form-control income_count" value="0" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>" /></td>
                    <td><input type="text" class="form-control income_count" /></td>
                    <td><input type="text" class="form-control income_count" value="0" /></td>
                    <td><input type="hidden" name="d<?php echo $info2['id']."_cogs";?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input name="d<?php echo $info2['id']."_total";?>" type="text"
                            class="d<?php echo $info2['id'];?> ptotal form-control" tabindex="-1" readonly />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
                <?php  if($info1000['en_singleproducts']==1) { 
       $data2 = mysqli_query($conn,"SELECT * from inventory where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { 
 $taxtype = $info2['is_taxable'];
 ?>
                <tr class="carttr">
                    <td><input type="text" class="sno form-control" />
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
    else if($info1000['en_lastprice']==2 ) {
      $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id` AND s.customer_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }    ?>
                    </td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from stitching_area") or die(mysqli_error($conn)); 
echo "<select name='products_sarea[]' id=sa".$info2['id']." tabindex='1'  class='searchqty teacher income_count'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>><?php 
         $sid = $info2['id'];
   $transfer_in = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=0 $wlimit_warehouse8   ");
             $transfer_out = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=0 $wlimit_warehouse8  ");
           echo  $product_qta = $transfer_in-$transfer_out;
         ?></td>
                    <td>
                        <input type="hidden" id="u<?php echo $info2['id'];?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input type="text" name="stitch_pcs[]" class="packing income_count totalorder"
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" size="7" min="0" />
                    </td>
                    <td>
                        <input type="text" name="stitch_qty[]" class="change income_count totalorder"
                            id="pcs<?php echo $info2['id'];?>" tabindex="1" value="0" size="4" />
                    </td>
                    <?php if($info1000['en_inventorybatch']==1) { ?>
                    <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'  && type_component=0") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1' class='teacher reportselect inventory3 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
$batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>
                    <?php if($info1000['en_embroidery']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from product_unit order by id") or die(mysqli_error($conn)); 
echo "<select name='products_unit[]' id=st".$info2['id']." class='teacher income_count '  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><input name="products_scolor[]" type="text" value="" tabindex="1" size="4" /> </td>
                    <td><select name="products_stype[]" id="sa<?php echo $info2['id'];?>" tabindex="1" required
                            class='teacher stype income_count2'>
                            <option value="">Select Head Type</option>
                            <?php $data4 = mysqli_query($conn,"SELECT * from stitching_type") or die(mysqli_error($conn)); 
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
     echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
 }
?>
                        </select></td>
                    <td><select name="products_sfusion[]" tabindex="1" class='teacher '>
                            <?php $data4 = mysqli_query($conn,"SELECT * from stitching_fusion") or die(mysqli_error($conn)); 
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
 if($info2['stich_fusion']==$info4['id'])
 {
   echo "<option value='".$info4['id']."' selected >".$info4['name']."</option>";
}
else {
     echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
  }
 }
?>
                        </select></td>



                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>> <input
                            name="products_packing[]" type="number" min="0.1" step="0.001" value="<?php echo $info2['packing'];?>" size="4"
                            class="change income_count edit-input totalorder" tabindex="1"
                            id="p<?php echo $info2['id'];?>" /></td>
                    <td>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" value="<?php echo $price;?>"
                            name="unitcos[]" type="number" size="4" min="0" 
                            class="change5 change6 income_count change totalorder" />
                    </td>
                    <?php } ?>
                    <td <?php  echo ' style="display:none;"';  ?>><input name="products_packing[]" type="number" min="0.1" step="0.001"
                            class="edit-input change income_count totalorder" id="p<?php echo $info2['id'];?>"
                            tabindex="1" value="<?php echo $info2['packing'];?>" size="4" />
                    </td>
                    <td style="display:none;">
                        <?php
$data15 = mysqli_query($conn,"SELECT customer_type from customer where  id='$cid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$ttid=$info15['customer_type'];
$ppid=$info2['id'];
 $data15 = mysqli_query($conn,"SELECT price from customer_type_pricing where pid='$ttid' AND tid='$ppid' && company_id = '$current_company' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="rate5[]"
                            value="<?php echo $info15['price'];?>" class="edit-input income_count chk8ange totalorder"
                            size="4" />
                        <?php } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100; 
$discount4=$info200['discount4']/100;
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3;
$discount4=1-$discount4;  
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info200['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x;
    ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="rate5[]"
                            value="<?php echo $price;?>" class="edit-input income_count chk8ange totalorder"
                            size="4" />
                        <?php } else {  ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="rate5[]"
                            value="<?php echo $info2['sale_price'];?>"
                            class="edit-input income_count chk8ange totalorder" size="4" />
                        <?php }  ?>
                    </td>
                    <?php if($info1000['customer_discount1']==1) { 
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from cb_discount where cid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from customer_type_discount1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($num_rows!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                            size="4" /></td>
                    <?php }
else if($num_rows2!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info17['discount'];?>"
                            size="4" /></td>
                    <?php }
 else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } 
 } else { ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount4 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
  if($info1000['customer_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='') {?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount3'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
else {?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from customer_type_scheme where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                            size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                        <input name="products_pcs[]" type="text"
                            <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { echo 'max="'.$maxx.'"'; } else { echo 'max="'.$info2['qty'].'"'; } } ?>
                            class="total_pcs" id="<?php echo "t".$info2['id'];?>" min="0" size="4" />
                    </td>
                    <?php if($info1000['customer_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info15['tax']; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td> <input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
  else {  ?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo 0; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" />
                    <?php } if($info1000['customer_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } 
else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied2']; ?>" size="4" /></td>
                    <?php }
else {  ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }  if($info1000['customer_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php }  
else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }    else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td style="display:none;"><input type="hidden" name="products_cogs[]" value="<?php
      if($info1000['en_inventorybatch']==1) { echo $unitc; } else {  echo $info2['unit_cost']; } ?>"
                            class="prd_cogs" />
                        <input name="products_total[]" step="0.0001"  id="newtotal<?php echo $info2['id'];?>" type="number" min="0" 
                            class="form-control tot<?php echo $info2['id'];?> ptotal sub_total income_count readonly " tabindex="-1" size="5"
                            onkeypress="return false;" />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php if($info1000['en_inventorybatch']==1) {  ?>
                $('.change7').focusout(function() {
                            $(".change7").removeClass("change7");
                            <?php } else if($info1000['en_warehouse']==1) {  ?>
                            $('.change6').focusout(function() {
                                $(".change6").removeClass("change6");
                                <?php } else {  ?>
                                $('.change5').focusout(function() {
                                    $(".change5").removeClass("change5");
                                    <?php }  ?>
                                    var $orginal = $(this).closest("tr");
                                    var $cloned = $orginal.clone();
                                    //get original selects into a jq object
                                    var $originalSelects = $orginal.find('select');
                                    $cloned.find('select').each(function(index, item) {
                                        //set new select to value of old select
                                        $(item).val($originalSelects.eq(index).val());
                                    });
                                    //get original textareas into a jq object
                                    var $originalTextareas = $orginal.find('textarea');
                                    $cloned.find('textarea').each(function(index, item) {
                                        //set new textareas to value of old textareas
                                        $(item).val($originalTextareas.eq(index).val());
                                    });
                                    $cloned.appendTo("#acart");
                                    //});
                                    $('.change5').attr('class',
                                        " change income_count totalorder packing");
                                    $("#searchbox").focus();
                                    $("#psearch").html('');
                                    var n10 = $("#totpc").val();
                                    n10 = parseInt(n10) + parseInt(1);
                                    $("#totpc").val(n10);
                                    var n11 = $("#totpc").val();
                                    $(".sno:last").val(n11);
                                });
                            });
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { 
?>
    $(".inventory3").on('change', function() {
        var vid = $(this).val();
        var self = $(this);
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch5: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                var tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.total_pcs').attr("max", tt);
            }
        });
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch6: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.prd_cogs').attr("value", tt);
            }
        });
    });
    <?php }} ?>
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $(".delete").on('click', function() {
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass != 'brokery_rs' && specialclass != 'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  } 
 else if(isset($_POST['grn22']))
{
$sid=test_input($_POST['grn22']);
$cid=test_input($_POST['customerid']);
$st=test_input($_POST['st']);
$cwarehouse = mysqli_get_var("Select inventory_warehouse from customer where `id` = '$cid'");
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="2%">S.No</th>
                    <th width="25%">
                        <div><?php echo $info1000['product_label']; ?></div>
                    </th>
                    <th>
                        <div>Carton</div>
                    </th>
                    <th>
                        <div>Total QTY</div>
                    </th>
                    <th>
                        <div></div>
                    </th>
                    <th>
                        <div>Rate</div>
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
   if($info1000['en_deals']==1) { 
    $data2 = mysqli_query($conn,"SELECT * from deal where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr>
                    <td class="sno"></td>
                    <td><input type="hidden" name="deal[]" value="d<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <?php 
   $did=$info2['id'];
   $data15 = mysqli_query($conn,"SELECT *, i.qty/d.qty AS aqty, d.qty AS dqty from inventory i, deal_details d where d.did='$did' AND d.pid=i.id") or die(mysqli_error($conn));
  $taqty=10000; 
while($info15 = mysqli_fetch_array( $data15 )) 
 { 
 if($info15['aqty']<=$taqty)
 {
 $taqty=$info15['aqty'];
 }
 else {
 $info15['aqty']=ceil($taqty);
 }
 $staqty=$info15['aqty'];
 echo $info15['dqty']." Pcs - ".$info15['name']."<br>";
 }
 ?>
                    </td>
                    <td><?php  if($staqty<$taqty)
        {
        echo ceil($staqty);
        }
        else  {
          $staqty=$taqty;
           echo ceil($staqty);
        }
        ?></td>
                    <td>
                        <input name="d<?php echo $info2['id'];?>" type="text" min="1"
                            class="searchqty income_count form-control" id="d<?php echo $info2['id'];?>"
                            tabindex="1" />
                    </td>
                    <td><input type="text" class="form-control income_count" /> </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='".$info2['id']."_warehouse' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <?php echo $info2['packing'];?></td>
                    <td>
                        <input id="<?php echo "nm".$info2['id'];?>" value="<?php echo $info2['sale_price'];?>"
                            class="income_count" onchange="changealert(this.id)" size="20" />
                    </td>
                    <td><input type="text" class="form-control income_count" value="0" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>" /></td>
                    <td><input type="text" class="form-control income_count" /></td>
                    <td><input type="text" class="form-control income_count" value="0" /></td>
                    <td><input type="hidden" name="d<?php echo $info2['id']."_cogs";?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input name="d<?php echo $info2['id']."_total";?>" type="text"
                            class="d<?php echo $info2['id'];?> ptotal form-control" tabindex="-1" readonly />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
                <?php  if($info1000['en_singleproducts']==1) { 
       $data2 = mysqli_query($conn,"SELECT * from inventory where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr class="carttr">
                    <td><input type="text" class="sno form-control" />
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
    else if($info1000['en_lastprice']==2 ) {
     $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id` AND s.customer_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }   
         ?>
                    </td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>><?php 
         $sid = $info2['id'];
   $transfer_in = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=0 $wlimit_warehouse8   ");
             $transfer_out = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=0 $wlimit_warehouse8  ");
           echo  $product_qta = $transfer_in-$transfer_out;
         ?></td>
                    <td><input name="carton[]" type="number" class="searchqty income_count totalorder" tabindex="1"
                            value="0" size="4" /></td>
                    <td>
                        <input type="hidden" id="u<?php echo $info2['id'];?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input type="text" name="stitch_pcs[]" class="packing income_count totalorder"
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" size="7" min="0" />
                    </td>
                    <?php if($info1000['en_inventorybatch']==1) { ?>
                    <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'  && type_component=0") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1' class='teacher reportselect inventory3 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
 $batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td>KG</td>
                    <td <?php  echo ' style="display:none;"';  ?>><input name="products_packing[]" type="number" min="0.1" step="0.001"
                            class="edit-input change income_count totalorder" id="p<?php echo $info2['id'];?>"
                            tabindex="1" value="<?php echo $info2['packing'];?>" size="4" />
                    </td>
                    <td style="display:none;">
                        <?php
$data15 = mysqli_query($conn,"SELECT customer_type from customer where  id='$cid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$ttid=$info15['customer_type'];
$ppid=$info2['id'];
 $data15 = mysqli_query($conn,"SELECT price from customer_type_pricing where pid='$ttid' AND tid='$ppid' && company_id = '$current_company' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $info15['price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100; 
$discount4=$info200['discount4']/100;
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3;  
$discount4=1-$discount4;
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info200['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x;
    ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $price;?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } else {  ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $info2['sale_price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php }  ?>
                    </td>
                    <?php if($info1000['customer_discount1']==1) { 
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from cb_discount where cid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from customer_type_discount1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($num_rows!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                            size="4" /></td>
                    <?php }
else if($num_rows2!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info17['discount'];?>"
                            size="4" /></td>
                    <?php }
 else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } 
 } else { ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount4 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
  if($info1000['customer_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" step="0.0001" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='') {?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount3'];?>" size="4" step="0.0001" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" step="0.0001" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
else {?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" step="0.0001" size="4" />
                    <?php }
 if($info1000['customer_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from customer_type_scheme where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                            size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                        <input name="products_pcs[]" type="text"
                            <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { echo 'max="'.$maxx.'"'; } else { echo 'max="'.$info2['qty'].'"'; } } ?>
                            class="total_pcs" id="<?php echo "t".$info2['id'];?>" min="0" size="4" />
                    </td>
                    <?php if($info1000['customer_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info15['tax']; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td> <input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
  else {  ?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo 0; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" />
                    <?php } if($info1000['customer_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } 
else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied2']; ?>" size="4" /></td>
                    <?php }
else {  ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }  if($info1000['customer_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php }  
else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }    else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td><input name="rate2[]" type="text" class="change5 change6 income_count totalorder" tabindex="1"
                            value="0" size="4" /></td>
                    <td style="display:none;"><input type="hidden" name="products_cogs[]" value="<?php
      if($info1000['en_inventorybatch']==1) { echo $unitc; } else {  echo $info2['unit_cost']; } ?>"
                            class="prd_cogs" />
                        <input name="products_total[]" step="0.0001"  id="newtotal<?php echo $info2['id'];?>" type="number" min="0" 
                            class=" form-control tot<?php echo $info2['id'];?> ptotal sub_total income_count readonly " tabindex="-1" size="5"
                            onkeypress="return false;" />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php if($info1000['open_ratecolumn']==1) { ?>
                $('.change15').focusout(function() {
                            $(".change15").removeClass("change15");
                            <?php }  else if($info1000['en_inventorybatch']==1) {  ?>
                            $('.change7').focusout(function() {
                                        $(".change7").removeClass("change7");
                                        <?php } else if($info1000['en_warehouse']==1) {  ?>
                                        $('.change6').focusout(function() {
                                            $(".change6").removeClass("change6");
                                            <?php } else {  ?>
                                            $('.change5').focusout(function() {
                                                $(".change5").removeClass("change5");
                                                <?php }  ?>
                                                var $orginal = $(this).closest("tr");
                                                var $cloned = $orginal.clone();
                                                //get original selects into a jq object
                                                var $originalSelects = $orginal.find('select');
                                                $cloned.find('select').each(function(index, item) {
                                                    //set new select to value of old select
                                                    $(item).val($originalSelects.eq(index)
                                                        .val());
                                                });
                                                //get original textareas into a jq object
                                                var $originalTextareas = $orginal.find('textarea');
                                                $cloned.find('textarea').each(function(index, item) {
                                                    //set new textareas to value of old textareas
                                                    $(item).val($originalTextareas.eq(index)
                                                        .val());
                                                });
                                                $cloned.appendTo("#acart");
                                                //});
                                                $('.change5').attr('class',
                                                    " change income_count totalorder packing");
                                                $("#searchbox").focus();
                                                $("#psearch").html('');
                                                var n10 = $("#totpc").val();
                                                n10 = parseInt(n10) + parseInt(1);
                                                $("#totpc").val(n10);
                                                var n11 = $("#totpc").val();
                                                $(".sno:last").val(n11);
                                            });
                                        });
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { 
?>
    $(".inventory3").on('change', function() {
        var vid = $(this).val();
        var self = $(this);
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch5: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                var tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.total_pcs').attr("max", tt);
            }
        });
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch6: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.prd_cogs').attr("value", tt);
            }
        });
    });
    <?php }} ?>
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $(".delete").on('click', function() {
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass != 'brokery_rs' && specialclass != 'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  } 
 else if(isset($_POST['grn225']))
{
$sid=test_input($_POST['grn225']);
$cid=test_input($_POST['customerid']);
$st=test_input($_POST['st']);
$cwarehouse = mysqli_get_var("Select inventory_warehouse from customer where `id` = '$cid'");
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="2%">
                        <div>S.No</div>
                    </th>
                    <th width="25%">
                        <div><?php echo $info1000['product_label']; ?></div>
                    </th>
                    <th>
                        <div>Carton</div>
                    </th>
                    <th>
                        <div>KG/Ctn</div>
                    </th>
                    <th>
                        <div>Lot #</div>
                    </th>
                    <th>
                        <div>Brand</div>
                    </th>
                    <th>
                        <div>Type</div>
                    </th>
                    <th>
                        <div>Formula</div>
                    </th>
                    <th>
                        <div>WH</div>
                    </th>
                    <th>
                        <div>Total QTY</div>
                    </th>
                    <th>
                        <div>&nbsp;</div>
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
   if($info1000['en_deals']==1) { 
    $data2 = mysqli_query($conn,"SELECT * from deal where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr>
                    <td class="sno"></td>
                    <td><input type="hidden" name="deal[]" value="d<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <?php 
   $did=$info2['id'];
   $data15 = mysqli_query($conn,"SELECT *, i.qty/d.qty AS aqty, d.qty AS dqty from inventory i, deal_details d where d.did='$did' AND d.pid=i.id") or die(mysqli_error($conn));
  $taqty=10000; 
while($info15 = mysqli_fetch_array( $data15 )) 
 { 
 if($info15['aqty']<=$taqty)
 {
 $taqty=$info15['aqty'];
 }
 else {
 $info15['aqty']=ceil($taqty);
 }
 $staqty=$info15['aqty'];
 echo $info15['dqty']." Pcs - ".$info15['name']."<br>";
 }
 ?>
                    </td>
                    <td><?php  if($staqty<$taqty)
        {
        echo ceil($staqty);
        }
        else  {
          $staqty=$taqty;
           echo ceil($staqty);
        }
        ?></td>
                    <td>
                        <input name="d<?php echo $info2['id'];?>" type="text" min="1"
                            class="searchqty income_count form-control" id="d<?php echo $info2['id'];?>"
                            tabindex="1" />
                    </td>
                    <td><input type="text" class="form-control income_count" /> </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='".$info2['id']."_warehouse' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <?php echo $info2['packing'];?></td>
                    <td>
                        <input id="<?php echo "nm".$info2['id'];?>" value="<?php echo $info2['sale_price'];?>"
                            class="income_count" onchange="changealert(this.id)" size="20" />
                    </td>
                    <td><input type="text" class="form-control income_count" value="0" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>" /></td>
                    <td><input type="text" class="form-control income_count" /></td>
                    <td><input type="text" class="form-control income_count" value="0" /></td>
                    <td><input type="hidden" name="d<?php echo $info2['id']."_cogs";?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input name="d<?php echo $info2['id']."_total";?>" type="text"
                            class="d<?php echo $info2['id'];?> ptotal form-control" tabindex="-1" readonly />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
                <?php  if($info1000['en_singleproducts']==1) { 
       $data2 = mysqli_query($conn,"SELECT * from inventory where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr class="carttr">
                    <td><input type="text" class="sno form-control" />
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
    else if($info1000['en_lastprice']==2 ) {
     $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id` AND s.customer_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }   
         ?>
                    </td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>><?php 
         $sid = $info2['id'];
   $transfer_in = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=0 $wlimit_warehouse8   ");
             $transfer_out = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=0 $wlimit_warehouse8  ");
           echo  $product_qta = $transfer_in-$transfer_out;
         ?></td>
                    <td><input name="carton[]" type="number" class="searchqty income_count totalorder"
                            id="<?php echo $info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <td>
                        <input type="hidden" id="u<?php echo $info2['id'];?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input type="text" name="stitch_pcs[]" class="kgcloud packing income_count totalorder"
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" size="7" min="0" />
                    </td>
                    <td><input type="text" required tabindex="1" name="lotno[]" size="4" /></td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from product_brands") or die(mysqli_error($conn)); 
echo "<select name='products_brand[]' class='teacher  '   tabindex='1'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from product_type") or die(mysqli_error($conn)); 
echo "<select name='products_type[]' class='teacher  '   tabindex='1'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td>
                        <select name="even[]" class="seven" tabindex="1">
                            <option value="1">Even</option>
                            <option value="0">Odd</option>
                        </select>
                    </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' tabindex='1' class='teacher warehouse '  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
  if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <?php } ?>
                    <?php if($info1000['en_inventorybatch']==1) { ?>
                    <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'  && type_component=0") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1' class='teacher reportselect inventory3 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
 $batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>

                    <td <?php  echo ' style="display:none;"';  ?>><input name="products_packing[]" type="number" min="0.1" step="0.001"
                            class="edit-input change income_count totalorder" id="p<?php echo $info2['id'];?>"
                            tabindex="1" value="<?php echo $info2['packing'];?>" size="4" />
                    </td>
                    <td style="display:none;">
                        <?php
$data15 = mysqli_query($conn,"SELECT customer_type from customer where  id='$cid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$ttid=$info15['customer_type'];
$ppid=$info2['id'];
 $data15 = mysqli_query($conn,"SELECT price from customer_type_pricing where pid='$ttid' AND tid='$ppid' && company_id = '$current_company' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $info15['price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100;
$discount4=$info200['discount4']/100; 
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3; 
$discount4=1-$discount4; 
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info200['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x;
    ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $price;?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } else {  ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $info2['sale_price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php }  ?>
                    </td>
                    <?php if($info1000['customer_discount1']==1) { 
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from cb_discount where cid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from customer_type_discount1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($num_rows!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                            size="4" /></td>
                    <?php }
else if($num_rows2!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info17['discount'];?>"
                            size="4" /></td>
                    <?php }
 else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } 
 } else { ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount4 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
  if($info1000['customer_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='') {?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount3'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }   
else {?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from customer_type_scheme where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                            size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td><input name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                        <input name="products_pcs[]" type="text"
                            <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { echo 'max="'.$maxx.'"'; } else { echo 'max="'.$info2['qty'].'"'; } } ?>
                            class="change5 change6" tabindex="1" id="<?php echo "t".$info2['id'];?>" min="0"
                            size="4" />
                    </td>
                    <?php if($info1000['customer_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info15['tax']; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td> <input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
  else {  ?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo 0; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" />
                    <?php } if($info1000['customer_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } 
else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied2']; ?>" size="4" /></td>
                    <?php }
else {  ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }  if($info1000['customer_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php }  
else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }    else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td style="display:none;"><input name="production[]" type="text"
                            class="change5 change6 totalorder" tabindex="1" value="0" size="4"
                            id="<?php echo "production".$info2['id']; ?>" /></td>
                    <td>KG</td>
                    <td style="display:none;"><input type="hidden" name="products_cogs[]" value="<?php
      if($info1000['en_inventorybatch']==1) { echo $unitc; } else {  echo $info2['unit_cost']; } ?>"
                            class="prd_cogs" />
                        <input name="products_total[]" step="0.0001"  id="newtotal<?php echo $info2['id'];?>" type="text" min="0" 
                            class="form-control tot<?php echo $info2['id'];?> ptotal sub_total income_count readonly " tabindex="-1" size="5"
                            onkeypress="return false;" />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php if($info1000['open_ratecolumn']==1) { ?>
                $('.change15').focusout(function() {
                            $(".change15").removeClass("change15");
                            <?php }  else if($info1000['en_inventorybatch']==1) {  ?>
                            $('.change7').focusout(function() {
                                        $(".change7").removeClass("change7");
                                        <?php } else if($info1000['en_warehouse']==1) {  ?>
                                        $('.change6').focusout(function() {
                                            $(".change6").removeClass("change6");
                                            <?php } else {  ?>
                                            $('.change5').focusout(function() {
                                                $(".change5").removeClass("change5");
                                                <?php }  ?>
                                                var $orginal = $(this).closest("tr");
                                                var $cloned = $orginal.clone();
                                                //get original selects into a jq object
                                                var $originalSelects = $orginal.find('select');
                                                $cloned.find('select').each(function(index, item) {
                                                    //set new select to value of old select
                                                    $(item).val($originalSelects.eq(index)
                                                        .val());
                                                });
                                                //get original textareas into a jq object
                                                var $originalTextareas = $orginal.find('textarea');
                                                $cloned.find('textarea').each(function(index, item) {
                                                    //set new textareas to value of old textareas
                                                    $(item).val($originalTextareas.eq(index)
                                                        .val());
                                                });
                                                $cloned.appendTo("#acart");
                                                //});
                                                $('.change5').attr('class',
                                                    " change income_count totalorder packing");
                                                $("#searchbox").focus();
                                                $("#psearch").html('');
                                                var n10 = $("#totpc").val();
                                                n10 = parseInt(n10) + parseInt(1);
                                                $("#totpc").val(n10);
                                                var n11 = $("#totpc").val();
                                                $(".sno:last").val(n11);
                                            });
                                        });
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { 
?>
    $(".inventory3").on('change', function() {
        var vid = $(this).val();
        var self = $(this);
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch5: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                var tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.total_pcs').attr("max", tt);
            }
        });
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch6: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.prd_cogs').attr("value", tt);
            }
        });
    });
    <?php }} ?>
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $(".delete").on('click', function() {
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass != 'brokery_rs' && specialclass != 'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('.seven').on('change', function() {
        var ftype = $(this).val();
        if (ftype == 0) {
            $(this).closest('.carttr').find('.kgcloud').prop("readOnly", true);
            $(this).closest('.carttr').find(".kgcloud").val(0);
            $(this).closest('.carttr').find('.income_count:first').trigger('change');
        } else {
            $(this).closest('.carttr').find(".kgcloud").prop("readOnly", false);
            $(this).closest('.carttr').find('.income_count:first').trigger('change');
        }
    });
    </script>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  } 
 else if(isset($_POST['grn226']))
{
$sid=test_input($_POST['grn226']);
$cid=test_input($_POST['customerid']);
$st=test_input($_POST['st']);
$cwarehouse = mysqli_get_var("Select inventory_warehouse from customer where `id` = '$cid'");
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="2%">
                        <div>S.No</div>
                    </th>
                    <th width="25%">
                        <div><?php echo $info1000['product_label']; ?></div>
                    </th>
                    <th>
                        <div>Carton</div>
                    </th>
                    <th>
                        <div>KG/Ctn</div>
                    </th>
                    <th>
                        <div>Lot #</div>
                    </th>
                    <th>
                        <div>Brand</div>
                    </th>
                    <th>
                        <div>Type</div>
                    </th>
                    <th>
                        <div>Formula</div>
                    </th>
                    <th>
                        <div>WH</div>
                    </th>
                    <th>
                        <div>Total QTY</div>
                    </th>
                    <th>
                        <div>&nbsp;</div>
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
   if($info1000['en_deals']==1) { 
    $data2 = mysqli_query($conn,"SELECT * from deal where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr>
                    <td class="sno"></td>
                    <td><input type="hidden" name="deal[]" value="d<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <?php 
   $did=$info2['id'];
   $data15 = mysqli_query($conn,"SELECT *, i.qty/d.qty AS aqty, d.qty AS dqty from inventory i, deal_details d where d.did='$did' AND d.pid=i.id") or die(mysqli_error($conn));
  $taqty=10000; 
while($info15 = mysqli_fetch_array( $data15 )) 
 { 
 if($info15['aqty']<=$taqty)
 {
 $taqty=$info15['aqty'];
 }
 else {
 $info15['aqty']=ceil($taqty);
 }
 $staqty=$info15['aqty'];
 echo $info15['dqty']." Pcs - ".$info15['name']."<br>";
 }
 ?>
                    </td>
                    <td><?php  if($staqty<$taqty)
        {
        echo ceil($staqty);
        }
        else  {
          $staqty=$taqty;
           echo ceil($staqty);
        }
        ?></td>
                    <td>
                        <input name="d<?php echo $info2['id'];?>" type="text" min="1"
                            class="searchqty income_count form-control" id="d<?php echo $info2['id'];?>"
                            tabindex="1" />
                    </td>
                    <td><input type="text" class="form-control income_count" /> </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='".$info2['id']."_warehouse' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <?php echo $info2['packing'];?></td>
                    <td>
                        <input id="<?php echo "nm".$info2['id'];?>" value="<?php echo $info2['sale_price'];?>"
                            class="income_count" onchange="changealert(this.id)" size="20" />
                    </td>
                    <td><input type="text" class="form-control income_count" value="0" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>" /></td>
                    <td><input type="text" class="form-control income_count" /></td>
                    <td><input type="text" class="form-control income_count" value="0" /></td>
                    <td><input type="hidden" name="d<?php echo $info2['id']."_cogs";?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input name="d<?php echo $info2['id']."_total";?>" type="text"
                            class="d<?php echo $info2['id'];?> ptotal form-control" tabindex="-1" readonly />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
                <?php  if($info1000['en_singleproducts']==1) { 
       $data2 = mysqli_query($conn,"SELECT * from inventory where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr class="carttr">
                    <td><input type="text" class="sno form-control" />
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
    else if($info1000['en_lastprice']==2 ) {
     $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=0 AND sd.`order_id`=s.`id` AND s.customer_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }   
         ?>
                    </td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>><?php 
         $sid = $info2['id'];
   $transfer_in = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=0 $wlimit_warehouse8   ");
             $transfer_out = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=0 $wlimit_warehouse8  ");
           echo  $product_qta = $transfer_in-$transfer_out;
         ?></td>
                    <td><input name="carton[]" type="number" class="searchqty income_count totalorder"
                            id="<?php echo $info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <td>
                        <input type="hidden" id="u<?php echo $info2['id'];?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input type="text" name="stitch_pcs[]" class="kgcloud packing income_count totalorder"
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" size="7" min="0" />
                    </td>
                    <td><input type="text" class="income_count" tabindex="1" name="lotno[]" size="4" /></td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from product_brands") or die(mysqli_error($conn)); 
echo "<select name='products_brand[]' class='teacher '  tabindex='1'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from product_type") or die(mysqli_error($conn)); 
echo "<select name='products_type[]' class='teacher '  tabindex='1'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td>
                        <select name="even[]" class="seven" tabindex="1">
                            <option value="1">Even</option>
                            <option value="0">Odd</option>
                        </select>
                    </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' tabindex='1' class='teacher warehouse '  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
  if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <?php } ?>
                    <?php if($info1000['en_inventorybatch']==1) { ?>
                    <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'  && type_component=0") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1' class='teacher reportselect inventory3 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
 $batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>

                    <td <?php  echo ' style="display:none;"';  ?>><input name="products_packing[]" type="number" min="0.1" step="0.001"
                            class="edit-input change income_count totalorder" id="p<?php echo $info2['id'];?>"
                            tabindex="1" value="<?php echo $info2['packing'];?>" size="4" />
                    </td>
                    <td style="display:none;">
                        <?php
$data15 = mysqli_query($conn,"SELECT customer_type from customer where  id='$cid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$ttid=$info15['customer_type'];
$ppid=$info2['id'];
 $data15 = mysqli_query($conn,"SELECT price from customer_type_pricing where pid='$ttid' AND tid='$ppid' && company_id = '$current_company' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $info15['price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100;
$discount4=$info200['discount4']/100; 
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3; 
$discount4=1-$discount4; 
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info200['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x;
    ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $price;?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } else {  ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $info2['sale_price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php }  ?>
                    </td>
                    <?php if($info1000['customer_discount1']==1) { 
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from cb_discount where cid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from customer_type_discount1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($num_rows!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                            size="4" /></td>
                    <?php }
else if($num_rows2!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info17['discount'];?>"
                            size="4" /></td>
                    <?php }
 else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } 
 } else { ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount4 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
  if($info1000['customer_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='') {?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount3'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } 
else {?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from customer_type_scheme where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                            size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td><input name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                        <input name="products_pcs[]" type="text"
                            <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { echo 'max="'.$maxx.'"'; } else { echo 'max="'.$info2['qty'].'"'; } } ?>
                            class="change5 change6" tabindex="1" id="<?php echo "t".$info2['id'];?>" min="0"
                            size="4" />
                    </td>
                    <?php if($info1000['customer_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info15['tax']; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td> <input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
  else {  ?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo 0; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } } 
 else { ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" />
                    <?php } if($info1000['customer_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } 
else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied2']; ?>" size="4" /></td>
                    <?php }
else {  ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }  if($info1000['customer_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php }  
else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }    else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td style="display:none;"><input name="production[]" type="text"
                            class="change5 change6 totalorder" tabindex="1" value="0" size="4"
                            id="<?php echo "production".$info2['id']; ?>" /></td>
                    <td>KG</td>
                    <td style="display:none;"><input type="hidden" name="products_cogs[]" value="<?php
      if($info1000['en_inventorybatch']==1) { echo $unitc; } else {  echo $info2['unit_cost']; } ?>"
                            class="prd_cogs" />
                        <input name="products_total[]" step="0.0001"  type="text" min="0" id="newtotal<?php echo $info2['id'];?>"  
                            class="form-control tot<?php echo $info2['id'];?> ptotal sub_total income_count readonly " tabindex="-1" size="5"
                            onkeypress="return false;" />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php if($info1000['open_ratecolumn']==1) { ?>
                $('.change15').focusout(function() {
                            $(".change15").removeClass("change15");
                            <?php }  else if($info1000['en_inventorybatch']==1) {  ?>
                            $('.change7').focusout(function() {
                                        $(".change7").removeClass("change7");
                                        <?php } else if($info1000['en_warehouse']==1) {  ?>
                                        $('.change6').focusout(function() {
                                            $(".change6").removeClass("change6");
                                            <?php } else {  ?>
                                            $('.change5').focusout(function() {
                                                $(".change5").removeClass("change5");
                                                <?php }  ?>
                                                var $orginal = $(this).closest("tr");
                                                var $cloned = $orginal.clone();
                                                //get original selects into a jq object
                                                var $originalSelects = $orginal.find('select');
                                                $cloned.find('select').each(function(index, item) {
                                                    //set new select to value of old select
                                                    $(item).val($originalSelects.eq(index)
                                                        .val());
                                                });
                                                //get original textareas into a jq object
                                                var $originalTextareas = $orginal.find('textarea');
                                                $cloned.find('textarea').each(function(index, item) {
                                                    //set new textareas to value of old textareas
                                                    $(item).val($originalTextareas.eq(index)
                                                        .val());
                                                });
                                                $cloned.appendTo("#acart");
                                                //});
                                                $('.change5').attr('class',
                                                    " change income_count totalorder packing");
                                                $("#searchbox").focus();
                                                $("#psearch").html('');
                                                var n10 = $("#totpc").val();
                                                n10 = parseInt(n10) + parseInt(1);
                                                $("#totpc").val(n10);
                                                var n11 = $("#totpc").val();
                                                $(".sno:last").val(n11);
                                            });
                                        });
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { 
?>
    $(".inventory3").on('change', function() {
        var vid = $(this).val();
        var self = $(this);
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch5: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                var tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.total_pcs').attr("max", tt);
            }
        });
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch6: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.prd_cogs').attr("value", tt);
            }
        });
    });
    <?php }} ?>
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $(".delete").on('click', function() {
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass != 'brokery_rs' && specialclass != 'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('.seven').on('change', function() {
        var ftype = $(this).val();
        if (ftype == 0) {
            $(this).closest('.carttr').find('.kgcloud').prop("readOnly", true);
            $(this).closest('.carttr').find(".kgcloud").val(0);
            $(this).closest('.carttr').find('.income_count:first').trigger('change');
        } else {
            $(this).closest('.carttr').find(".kgcloud").prop("readOnly", false);
            $(this).closest('.carttr').find('.income_count:first').trigger('change');
        }
    });
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  } 
 else if(isset($_POST['sid2c']))
{
$sid=test_input($_POST['sid2c']);
$cid=test_input($_POST['customerid']);
$st=test_input($_POST['st']);
$gdn=test_input($_POST['gdn']);
if($gdn=='') $gdn = 0;
$cwarehouse = mysqli_get_var("Select inventory_warehouse from customer where `id` = '$cid'");
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="2%">S.No</th>
                    <th width="25%"><?php echo $info1000['material_label']; ?></th>
                    <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <div>QTA</div>
                    </th>
                    <th>
                        <div><?php echo $info1000['multi_unit_label']; ?></div>
                    </th>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['single_unit_label']; ?></div>
                    </th>
                    <?php if($info1000['en_warehouse']==1) {  echo  '  <th ><div>WH </div></th> '; } ?>
                    <?php if($info1000['en_rawmaterialbatch']==1  && $gdn==1) {   echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; } ?>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['packing_label']; ?></div>
                    </th>
                    <th>
                        <div><?php echo $info1000['price_label']; ?></div>
                    </th>
                  
                    <th <?php if($info4000['separate_mrpcolumn']==0) echo ' style="display:none;"';  ?>
                        class="recurringhide">
                        <div><?php echo $info4000['mrp_label']; ?></div>
                    </th>

                    <?php if($info1000['customer_discount1']==1) {  echo  '  <th ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount2']==1) {  echo  '  <th ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount4']==1) {  echo  '  <th ><div>'.$info1000['disc4_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount3']==1) {  echo  '  <th ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_scheme']==1) {  echo  '  <th ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                    <th <?php if(1==1) echo ' style="display:none;"';  ?> ><div><?php echo $info1000['total_unit_label']; ?></div></th>
       <?php if($info4000['display_taxamount']==1){   ?>    
            <th>Exclusive of GST Amount</th>    
            <?php } ?> 


                    <?php if($info1000['customer_tax1']==1) {  echo  '  <th ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax2']==1) {  echo  '  <th ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax3']==1) {  echo  '  <th ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
                  <?php if($info4000['display_taxamount']==1){     ?>    
            <th><?php echo $info4000['taxamount_label']; ?></th>    
            <?php } ?>

                    <th contenteditable="true" width="80">Total </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php  if($info1000['en_singleproducts']==1) { 
       $data2 = mysqli_query($conn,"SELECT * from component where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr class="carttr">
                    <td><input type="text" class="sno form-control" />
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=1 AND sd.`order_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
    else if($info1000['en_lastprice']==2 ) {
       $data200 = mysqli_query($conn,"SELECT sd.* from sales_details sd, sales s  where sd.prd_id='$sid' AND type_component=1 AND sd.`order_id`=s.`id` AND s.customer_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }   
         ?>
                    </td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>><?php 
         $sid = $info2['id'];
   $transfer_in = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=0 $wlimit_warehouse8   ");
             $transfer_out = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=0 $wlimit_warehouse8  ");
           echo  $product_qta = $transfer_in-$transfer_out;
         ?></td>
                    <td>
                        <input type="hidden" id="u<?php echo $info2['id'];?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input type="number"
                            class="searchqty <?php if($info1000['no_salespacking']==1) echo ' change5';  ?> packing income_count totalorder "
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" size="7" min="1" value="0" required/>

                    </td>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <input type="text" value="0" class="change5 change income_count totalorder" tabindex="1"
                            id="pcs<?php echo $info2['id'];?>" size="4" min="1" />
                    </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' tabindex='1' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
  if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <?php } ?>
                    <?php if($info1000['en_rawmaterialbatch']==1  && $gdn==1) { ?>
                    <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid' && type_component=1") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1' class='teacher reportselect inventory3 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
 $batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>

                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input type="text"
                            name="products_packing[]" value="<?php echo $info2['packing'];?>"
                            class="edit-input change income_count totalorder" tabindex="1"
                            id="p<?php echo $info2['id'];?>" size="4" min="1" />
                    </td>
                    <td>
                        <?php
$data15 = mysqli_query($conn,"SELECT customer_type from customer where  id='$cid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$ttid=$info15['customer_type'];
$ppid=$info2['id'];
 $data15 = mysqli_query($conn,"SELECT price from customer_type_pricingc where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $info15['price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100; 
$discount4=$info200['discount4']/100;
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3;
$discount4=1-$discount4;  
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info200['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x;
    ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $price;?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php }
else {  ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $info2['sale_price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } ?>
                    

                          <input type="hidden" required step="0.0001" name="products_foc[]" value="0"  class="foc income_count" id="<?php echo "pfoc".$info2['id'];?>"  size="4"   />
<input name="packing2[]" type="hidden" step="0.0001" class='teacher packing2 income_count' value="1" id="<?php echo "packk".$info2['id'];?>" />

<input type="hidden" name="discount5[]" value="0" id="<?php echo "pppl".$info2['id'];?>"  tabindex="1"  class="edit-input income_count"   size="4"   /> 




  <input name="tax_mrp[]" size="4" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "mrptax".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['tax_mrp'];?>" />
                        <?php
              if($info4000['separate_mrpcolumn']==0)
              {
              ?>
                        <input name="mrp_price[]" size="4" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "mrp".$info2['id'];?>" tabindex="1"
                            value="<?php if($mpp!='' && $mpp!=0) { echo $mpp;  } else { echo $info2['mrp_price']; } $mpp=''; ?>" />
                        <?php
              }
              ?>
                        <!-- <input name="new_rate[]" size="4"   type="hidden" class="new_rate" value="<?php echo $new_rate;?>"  /> -->
                    </td>
                    <?php if($info4000['separate_mrpcolumn']==1) { ?> <td>
                        <input name="mrp_price[]" size="4" type="number" required step='0.0001'
                            class="edit-input income_count totalorder" id="<?php echo "mrp".$info2['id'];?>"
                            tabindex="1"
                            value="<?php if($mpp!='' && $mpp!=0) { echo $mpp;  } else { echo $info2['mrp_price']; } $mpp=''; ?>" />
                    </td>
                    <?php } //closepricing ?>

                    <?php if($info1000['customer_discount1']==1) { 
 echo '<td >';
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from cb_discount where cid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from customer_type_discount1c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($num_rows!=0) {
?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                        size="4" />
                    <?php }
else if($num_rows2!=0) {
?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info17['discount'];?>"
                        size="4" />
                    <?php }  else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info200['discount'];?>"
                        size="4" />
                    <?php }
 else {  ?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } echo '</td>'; } else { ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount2c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php }  else {  ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount4c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php }  else {  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
  if($info1000['customer_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount3c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='') {?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount3'];?>" size="4" /></td>
                    <?php }   else {  ?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else {?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from customer_type_schemec where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                            size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                        <input name="products_pcs[]" type="text"
                            <?php if($info1000['inventory_limit']==1) { echo 'max="'.$info2['qty'].'"'; } ?> size="4"
                            min="1" class="total_pcs" id="<?php echo "t".$info2['id'];?>" />
                    </td>

 <?php if(1==1){   ?>     
     <td  <?php if($info4000['display_taxamount']==0){ echo ' style="display:none;"';    }  ?> >
   <input name="display_totaltax2[]" type="text" class="income_count display_totaltax2" id="<?php echo "ppptttt".$info2['id'];?>"    value="0" size="4" readonly/>
</td>
<?php } ?>

                    <?php if($info1000['customer_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax1c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td> <input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } } else { ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" />
                    <?php } if($info1000['customer_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax2c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied2']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax3c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <?php if(1==1){   ?>     
     <td  <?php if($info4000['display_taxamount']==0){ echo ' style="display:none;"';    }  ?> >
   <input name="display_totaltax[]" type="text" class="income_count display_totaltax" id="<?php echo "ppptt".$info2['id'];?>"    value="0" size="4" readonly/>
</td>
<?php } ?> 
           
                    <td><input type="hidden" name="products_cogs[]" value="<?php echo $info2['unit_cost'];?>" /><input
                            name="products_total[]" step="0.0001"  id="newtotal<?php echo $info2['id'];?>" type="number" min="0" 
                            class="form-control tot<?php echo $info2['id'];?> ptotal sub_total income_count readonly " size="5" tabindex="-1"
                            onkeypress="return false;" /> </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /><?php } ?></td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php if($info1000['en_rawmaterialbatch']==1 && $gdn==1) {  ?>
                $('.change7').focusout(function() {
                            $(".change7").removeClass("change7");
                            <?php } else if($info1000['en_warehouse']==1) {  ?>
                            $('.change6').focusout(function() {
                                $(".change6").removeClass("change6");
                                <?php } else {  ?>
                                $('.change5').focusout(function() {
                                    $(".change5").removeClass("change5");
                                    <?php }  ?>
                                    var $orginal = $(this).closest("tr");
                                    var $cloned = $orginal.clone();
                                    //get original selects into a jq object
                                    var $originalSelects = $orginal.find('select');
                                    $cloned.find('select').each(function(index, item) {
                                        //set new select to value of old select
                                        $(item).val($originalSelects.eq(index).val());
                                    });
                                    //get original textareas into a jq object
                                    var $originalTextareas = $orginal.find('textarea');
                                    $cloned.find('textarea').each(function(index, item) {
                                        //set new textareas to value of old textareas
                                        $(item).val($originalTextareas.eq(index).val());
                                    });
                                    $cloned.appendTo("#acart");
                                    $('.change5').attr('class',
                                        "change5 change income_count totalorder");
                                    $("#searchbox").focus();
                                    $("#psearch").html('');
                                    var n10 = $("#totpc").val();
                                    n10 = parseInt(n10) + parseInt(1);
                                    $("#totpc").val(n10);
                                    var n11 = $("#totpc").val();
                                    $(".sno:last").val(n11);
                                });
                            });
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $(".delete").on('click', function() {
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (specialclass == 'noimpact' || specialclass == 'trade_no_impact' || specialclass ==
                'freight_class') {} else if (specialclass != 'brokery_rs' && specialclass !=
                'brokery_percentage') {
                if (dless == 1) {
                    if (dpercent == 1) {
                        damount = (+100 - +damount) / 100;
                        result = +result * damount;
                    } else {
                        result = +result - +damount;
                    }
                } else {
                    if (dpercent == 1) {
                        damount = (+100 + +damount) / 100;
                        result = +result * damount;
                    } else {
                        result = +result + +damount;
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>

<?php  include('../functions/incomecount_function.php'); ?>


<script type="text/javascript">

    $(".totalorder,  .rice_discount_value, .change, #sub_total, #shipping, #discount").on("change", function() {
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass != 'brokery_rs' && specialclass != 'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
    });
    $("#amount_received").change(function() {
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        $("#pending_amount").val(result2);
    });
    </script>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  } 
  else if(isset($_POST['sid99']))
{
$sid=test_input($_POST['sid99']);
$cid=test_input($_POST['qtid2']);
?>
    <?php $p1 = mysqli_get_var("Select count(id) from item_compo where `inv_id` = '$sid'");
 if($p1>0) { ?>
    <div class="table-responsive table-card mt-4">
        <h2>Packing Material</h2>
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="5%">
                        <div>S.No</div>
                    </th>
                    <th>
                        <div>Lot No</div>
                    </th>
                    <th width="25%">
                        <div>Name of Ingredients</div>
                    </th>
                    <th>
                        <div>Standard Quantity</div>
                    </th>
                    <th>
                        <div>Unit</div>
                    </th>
                    <th>
                        <div>Quantity Issued </div>
                    </th>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <th>Warehouse</th>
                    <?php } ?>
                    <th>
                        <div>Weight By</div>
                    </th>
                    <th>
                        <div>Checked By</div>
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php  
       $data2 = mysqli_query($conn,"SELECT it.*, c.id as cid, c.name, c.unit_cost  ,c.unit as unit2 from item_compo it, component c where it.comp_id=c.id  && it.type=1 &&  it.inv_id='$sid'") or die(mysqli_error($conn));
    $i = 1;
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr>
                    <td><?php echo $i; $i++; ?></td>
                    <td></td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $info2['cid'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                    </td>
                    <td><?php echo $cid*$info2['qty'];?> </td>
                    <td><?php $unit = $info2['unit2']; echo $color = mysqli_get_var("Select name from component_unit where `id` = '$unit'"); ?>
                    </td>
                    <td>
                        <input type="hidden" value="<?php echo $info2['unit_cost'];?>" name='unit_cost[]' /> <input
                            type="hidden" value="<?php echo $cid*$info2['qty'];?>" name='standard_qty[]' />
                        <input type="number" min="1"
                            class="searchqty <?php if($info1000['no_purchasepacking']==1) echo ' change5';  ?> packing totalorder form-control"
                            id="ctn<?php echo $info2['id'];?>" value="<?php echo $cid*$info2['qty'];?>" name='a_qty[]'
                            required tabindex="1" />
                    </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td>
                    </td>
                    <td></td>
                    <td></td>
                </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
    <?php } ?>
    <?php $p1 = mysqli_get_var("Select count(id) from item_compo where `inv_id` = '$sid'");
 if($p1>0) { ?>
    <div class="table-responsive table-card mt-4">
        <h2>Raw Material</h2>
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="5%">
                        <div>S.No</div>
                    </th>
                    <th>
                        <div>Lot No</div>
                    </th>
                    <th width="25%">
                        <div>Name of Ingredients</div>
                    </th>
                    <th>
                        <div>Standard Quantity</div>
                    </th>
                    <th>
                        <div>Unit</div>
                    </th>
                    <th>
                        <div>Quantity Issued </div>
                    </th>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <th>Warehouse</th>
                    <?php } ?>
                    <th>
                        <div>Weight By</div>
                    </th>
                    <th>
                        <div>Checked By</div>
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php  
       $data2 = mysqli_query($conn,"SELECT it.*, c.id as cid, c.name,c.unit_cost  , c.unit as unit2 from item_compo it, component c where it.comp_id=c.id  && it.type=2 &&  it.inv_id='$sid'") or die(mysqli_error($conn));
    $i = 1;
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr>
                    <td><?php echo $i; $i++; ?></td>
                    <td></td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $info2['cid'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                    </td>
                    <td><?php echo $cid*$info2['qty'];?> </td>
                    <td><?php $unit = $info2['unit2']; echo $color = mysqli_get_var("Select name from component_unit where `id` = '$unit'"); ?>
                    </td>
                    <td>
                        <input type="hidden" value="<?php echo $info2['unit_cost'];?>" name='unit_cost[]' /> <input
                            type="hidden" value="<?php echo $cid*$info2['qty'];?>" name='standard_qty[]' />
                        <input type="number" min="1"
                            class="searchqty <?php if($info1000['no_purchasepacking']==1) echo ' change5';  ?> packing totalorder form-control"
                            id="ctn<?php echo $info2['id'];?>" value="<?php echo $cid*$info2['qty'];?>" name='a_qty[]'
                            required tabindex="1" />
                    </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td>
                    </td>
                    <td></td>
                    <td></td>
                </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
    <?php } ?>
    <?php $p1 = mysqli_get_var("Select count(id) from item_compo where `inv_id` = '$sid'");
 if($p1>0) { ?>
    <div class="table-responsive table-card mt-4">
        <h2>Coating Material</h2>
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="5%">
                        <div>S.No</div>
                    </th>
                    <th>
                        <div>Lot No</div>
                    </th>
                    <th width="25%">
                        <div>Name of Ingredients</div>
                    </th>
                    <th>
                        <div>Standard Quantity</div>
                    </th>
                    <th>
                        <div>Unit</div>
                    </th>
                    <th>
                        <div>Quantity Issued </div>
                    </th>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <th>Warehouse</th>
                    <?php } ?>
                    <th>
                        <div>Weight By</div>
                    </th>
                    <th>
                        <div>Checked By</div>
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php  
       $data2 = mysqli_query($conn,"SELECT it.*, c.id as cid, c.name,c.unit_cost  , c.unit as unit2 from item_compo it, component c where it.comp_id=c.id  && it.type=3 &&  it.inv_id='$sid'") or die(mysqli_error($conn));
    $i = 1;
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr>
                    <td><?php echo $i; $i++; ?></td>
                    <td></td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $info2['cid'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                    </td>
                    <td><?php echo $cid*$info2['qty'];?> </td>
                    <td><?php $unit = $info2['unit2']; echo $color = mysqli_get_var("Select name from component_unit where `id` = '$unit'"); ?>
                    </td>
                    <td>
                        <input type="hidden" value="<?php echo $info2['unit_cost'];?>" name='unit_cost[]' /> <input
                            type="hidden" value="<?php echo $cid*$info2['qty'];?>" name='standard_qty[]' />
                        <input type="number" min="1"
                            class="searchqty <?php if($info1000['no_purchasepacking']==1) echo ' change5';  ?> packing totalorder form-control"
                            id="ctn<?php echo $info2['id'];?>" name='a_qty[]' value="<?php echo $cid*$info2['qty'];?>"
                            required tabindex="1" />
                    </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td>
                    </td>
                    <td></td>
                    <td></td>
                </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
    <?php } ?>
    <?php $p1 = mysqli_get_var("Select count(id) from item_compo where `inv_id` = '$sid'");
 if($p1>0) { ?>
    <div class="table-responsive table-card mt-4">
        <h2>Marketing Material</h2>
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="5%">
                        <div>S.No</div>
                    </th>
                    <th>
                        <div>Lot No</div>
                    </th>
                    <th width="25%">
                        <div>Name of Ingredients</div>
                    </th>
                    <th>
                        <div>Standard Quantity</div>
                    </th>
                    <th>
                        <div>Unit</div>
                    </th>
                    <th>
                        <div>Quantity Issued </div>
                    </th>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <th>Warehouse</th>
                    <?php } ?>
                    <th>
                        <div>Weight By</div>
                    </th>
                    <th>
                        <div>Checked By</div>
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php  
       $data2 = mysqli_query($conn,"SELECT it.*, c.id as cid, c.name, c.unit_cost  , c.unit as unit2 from item_compo it, component c where it.comp_id=c.id  && it.type=4 &&  it.inv_id='$sid'") or die(mysqli_error($conn));
    $i = 1;
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr>
                    <td><?php echo $i; $i++; ?></td>
                    <td></td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $info2['cid'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                    </td>
                    <td><?php echo $cid*$info2['qty'];?> </td>
                    <td><?php $unit = $info2['unit2']; echo $color = mysqli_get_var("Select name from component_unit where `id` = '$unit'"); ?>
                    </td>
                    <td>
                        <input type="hidden" value="<?php echo $info2['unit_cost'];?>" name='unit_cost[]' /> <input
                            type="hidden" value="<?php echo $cid*$info2['qty'];?>" name='standard_qty[]' />
                        <input type="number" step="0.0001" required min="1"
                            class="searchqty <?php if($info1000['no_purchasepacking']==1) echo ' change5';  ?> packing totalorder form-control"
                            id="ctn<?php echo $info2['id'];?>" value="<?php echo $cid*$info2['qty'];?>" name='a_qty[]'
                            tabindex="1" />
                    </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td>
                    </td>
                    <td></td>
                    <td></td>
                </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
    <?php } ?>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php if($info1000['en_inventorybatch']==1) {  ?>
                $('.change7').focusout(function() {
                            $(".change7").removeClass("change7");
                            <?php } else if($info1000['en_warehouse']==1) {  ?>
                            $('.change6').focusout(function() {
                                $(".change6").removeClass("change6");
                                <?php } else {  ?>
                                $('.change5').focusout(function() {
                                    $(".change5").removeClass("change5");
                                    <?php }  ?>
                                    $(this).closest("tbody").clone().appendTo("#acart");
                                    $('.change5').attr('class',
                                        "form-control change income_count totalorder");
                                    $("#searchbox").focus();
                                    $("#psearch").html('');
                                    var n10 = $("#totpc").val();
                                    n10 = parseInt(n10) + parseInt(1);
                                    $("#totpc").val(n10);
                                    var n11 = $("#totpc").val();
                                    $(".sno:last").val(n11);
                                });
                            });
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $(".delete").on('click', function() {
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass != 'brokery_rs' && specialclass != 'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  } 
   else if(isset($_POST['sid5']))
{
  //huugu
    $sid=test_input($_POST['sid5']);
    $cid=test_input($_POST['customerid']);
    $st=test_input($_POST['st']);
    $inv_no=test_input($_POST['inv_no']);
     $order_id=test_input($_POST['order_id']);
    $dist_id2 = test_input($_POST['dist_id2']);
 $gdn=test_input($_POST['gdn']);
  $dist_id=test_input($_POST['dist_id']);
  if($gdn=='') $gdn=0;
  if($dist_id=='') $dist_id=0;
if($dist_id2=='') $dist_id2=0;
/*------start multipricing------------- */
$date =      date('Y-m-d');
$customer_type = mysqli_get_var("SELECT customer_type FROM `customer` where id = '$cid'");
$customer_type = ($customer_type=='')?'""':$customer_type;
$customer_filer = mysqli_get_var("SELECT filer FROM `customer` where id = '$cid'");
$customer_filer = ($customer_filer=='')?'0':$customer_filer;
$cid = ($cid=='a')?'0':$cid;
if($cid=='') $cid=0;
$multiprice1000 = mysqli_query($conn,"SELECT * FROM `multi_pricing` 
where (find_in_set($sid,prd_id) <> 0 || prd_id = 0) and  
(find_in_set($dist_id2,distributor_id) <> 0  || distributor_id =0)
 and (find_in_set($cid,customer_id) <> 0   || customer_id=0)  
and (find_in_set($customer_type,customer_type) <> 0 || customer_type=0) and `status` = 1 and 
(starting_date <= '$date'||starting_date ='') and (ending_date >= '$date' || ending_date='') and
1=1  order by id desc limit 1") or die(mysqli_error($conn));             
$infomultiprice1000 = mysqli_fetch_array( $multiprice1000 );
$userdefault_price = $infomultiprice1000['use_defaultprice'];
$tax1filer_value = $infomultiprice1000['tax1filer_value'];
$tax2filer_value = $infomultiprice1000['tax2filer_value'];
$tax3filer_value = $infomultiprice1000['tax3filer_value'];
if($gdn=='') $gdn = 0;
if(in_array($sid, $_SESSION["shopping_cart"]) && $info2000['noduplicate_item']==1) 
           {  
     ?>
    <script type="text/javascript">
    alert('This item is already added');
    </script>
    <?php   }
  else {
     $_SESSION['shopping_cart'][] = $sid;
$cwarehouse = mysqli_get_var("Select inventory_warehouse from customer where `id` = '$cid'");
$cfiler = mysqli_get_var("Select filer from customer where `id` = '$cid'");
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="2%"></th>
                    <th width="20%">
                        <div><?php echo $info1000['product_label']; ?></div>
                    </th>
                    <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <div>QTA</div>
                    </th>
                    <th>
                        <div><?php echo $info1000['multi_unit_label']; ?></div>
                    </th>
                    <th
                        <?php if($info1000['no_salespacking']==1   || $info2000['pcs_hide']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['single_unit_label']; ?></div>
                    </th>
                    <th <?php if($info2000['en_customfield1']==0) echo 'style="display:none"';  ?>>
                        <div><?php echo $info2000['customfield1_display'];  ?></div>
                    </th>
                    <?php if($info1000['en_warehouse']==1) {  echo  '  <th ><div>WH </div></th> '; } ?>
                    <?php if($info3000['datewise_batch']==1) { ?>   
                        <?php if($info1000['en_inventorybatch']==1  && $info2000['batch_grnonly']==0 && 1==2 ) { echo  '  <th ><div>'.$info1000['batch_label'].'</div></th> '; } ?>
                        <?php if($info1000['en_expirydisplay']==1 && 1==2) {   echo  '  <th ><div>Expiry </div></th> '; } ?>       
                    <?php } ?>
                    <?php if($info1000['en_inventorybatch']==1  && $gdn==1) {   echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; } ?>
                    <?php if($info2000['multiple_batch']==1) {   echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; } ?>
                    <?php if($info1000['en_embroidery']==1) { 
         echo  ' 
          <th ><div>Type </div></th>
          <th ><div>Colors </div></th>
         <th ><div>Head Working </div></th>
         <th ><div>Fusing </div></th>
          '; } ?>


                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['packing_label']; ?></div>
                    </th>
                    <th>
                        <div><?php echo $info1000['price_label']; ?></div>
                    </th>
                    <th <?php if($info4000['separate_mrpcolumn']==0) echo ' style="display:none;"';  ?>
                        class="recurringhide">
                        <div><?php echo $info4000['mrp_label']; ?></div>
                    </th>
                    <?php if($info2000['en_sarhad']==1 || $info4000['itemmulti_unit']==1) { ?>
                    <th>
                        <div>Unit</div>
                    </th>
                    <th style="display:none;">
                        <div>Unit Rate</div>
                    </th>
                    <?php } ?>
                    <?php  if($info2000['invoice_cartonrate']==1) {  ?>
                    <th>
                        <div>Rate Apply</div>
                    </th>
                    <?php } ?>
                    <?php if($info1000['customer_discount1']==1) {  echo  '  <th ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount2']==1) {  echo  '  <th ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount4']==1) {  echo  '  <th ><div>'.$info1000['disc4_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount3']==1) {  echo  '  <th ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
                    <?php if($info2000['customer_foc']==1) {  echo  '  <th ><div>'.$info4000['customerfoc_label'].'</div></th> '; } ?>
                    <?php if($info2000['en_discount5']==1) {  echo  '  <th ><div>Disc (Rs.)</div></th> '; } ?>
                    <?php if($info1000['customer_scheme']==1) {  echo  '  <th ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
                    <?php if($info3000['customer_scheme_value']==1) {  echo  '  <th ><div>'.$info3000['scheme_value_label'].'</div></th> '; } ?>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                    <?php if($info1000['customer_tax1']==1) {  echo  '  <th ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
                    <?php  if($info2000['invoice_cartonrate']==1) {  ?>
                    <th>
                        <div>Pipe Rate</div>
                    </th>
                    <?php } ?>
                    <?php if($info1000['customer_tax2']==1) {  echo  '  <th ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax3']==1) {  echo  '  <th ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
                    <th class="<?php echo ($info2000['en_freshmate'] == 1) ? '' : 'hidden'?>">Expiry Date</th>
                    <th class="<?php echo ($info2000['en_freshmate'] == 1) ? '' : 'hidden'?>">Reason</th>
                    <th contenteditable="true" width="80">Total </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php  if($info1000['en_singleproducts']==1) { 
//echo "SELECT * FROM `sales_details` s where order_id IN (select id from sales d where d.id=s.order_id AND d.customer_id='$cid' AND s.prd_id='$sid') ORDER BY s.id DESC LIMIT 1";
//echo "SELECT * FROM `sales_details` s where order_id IN (select id from sales d where d.id=s.order_id AND d.customer_id='$cid' AND s.prd_id='$sid'";
 $data2 = mysqli_query($conn,"SELECT * FROM `sales_details` s where order_id IN (select id from sales d where d.id=s.order_id AND d.customer_id='$cid' AND s.prd_id='$sid') ORDER BY s.id DESC LIMIT 1") or die(mysqli_error($conn));
 $lastinv=mysqli_fetch_array($data2);
 $num_rows25 = mysqli_num_rows($data2);
// echo "<pre>";
//  print_r($result2);
// echo "<pre>";
// echo "SELECT *, packing2 as pac2 from inventory where id='$sid'";
 $data2 = mysqli_query($conn,"SELECT *, packing2 as pac2 from inventory where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 {
      if($order_id!=0 && $order_id!='') {
   $data15 = mysqli_query($conn,"SELECT * from so_details where  order_id='$order_id' && prd_id='$sid' ") or die(mysqli_error($conn));
    // echo "SELECT distributor_type from distributor where  id='$dist_id' ";
    $info15 = mysqli_fetch_array( $data15 ); 
     $odiscount2=$info15['discount2'];
      $odiscount3=$info15['discount3'];
       $oscheme=$info15['scheme'];
        $oscheme_formula=$info15['scheme_formula'];
    $oscheme_prd=$info15['scheme_prd'];
     $otp=$info15['tp'];
      $obatch_id=$info15['batch_id'];
 }
      ?>
                <tr class="carttr">
                    <td><input type="text" class="sno form-control" />
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from sales_return_details sd, sales_return s  where sd.prd_id='$sid' AND s.type_component=0 AND sd.`return_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
  else if($info1000['en_lastprice']==2 ) {
     $data200 = mysqli_query($conn,"SELECT sd.* from sales_return_details sd, sales_return s  where sd.prd_id='$sid' AND s.type_component=0 AND sd.`return_id`=s.`id` AND s.customer_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }      ?>
                    </td>
                    <td>
                        <input type="hidden" name="products[]" class="singleitem" value="<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <?php
                  $sid = $info2['id'];
                  $warehouse_id = mysqli_get_var("SELECT id FROM inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse");
                  $product_qta = get_available_quantity($sid, $warehouse_id);
                  echo number_format($product_qta);
                  ?>
                    </td>
                    <td>
                        <input type="hidden" id="u<?php echo $info2['id'];?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <?php  if($info4000['return_invoice_ref']==1){ 
    $qty = mysqli_get_var("SELECT qty from sales_details where order_id in($inv_no) && prd_id =$sid");
    ?>
                        <input type="number" required step="0.0001" value="<?php echo  $qty; ?>"
                            class="searchqty <?php if($info1000['no_salespacking']==1) echo ' change5';  ?> packing income_count totalorder "
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" size="7" min="1" />
                        <?php  }else{ ?>
                        <input type="number" Required step="0.0001"
                            <?php if($info2000['multiple_batch']==1) { echo "value='1'  ";  } ?>
                            class="searchqty <?php if($info1000['no_salespacking']==1) echo ' change5';  ?> packing income_count totalorder "
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" size="7" min="1"
                            value="<?php echo ($info2000['multiple_batch']); ?>" />

                        <?php } ?>
                    </td>


                    <td
                        <?php if($info1000['no_salespacking']==1   || $info2000['pcs_hide']==1) echo ' style="display:none;"';  ?>>
                        <input type="text" value="0" class="change5 change income_count totalorder" tabindex="1"
                            id="pcs<?php echo $info2['id'];?>" size="4" min="1" />
                    </td>
                    <?php 
              if($info4000['en_sarwana']==1) 
              {
                $value= $info2['color'];
              }
              else
              {
                $value="";
              }
    ?>
                    <td
                        <?php if($info2000['en_customfield1']==0  || $type_component==10) echo ' style="display:none;"';  ?>>
                        <input style="width:100px;" type="text" value="<?php echo $value;?>" name="custom_field1[]"
                            <?php echo $readonly;?> id="customfield<?php echo $info2['id'];?>"
                            <?php if($info1000['en_recurringinvoices']==1){ echo "type='text' ";}else {echo "type='text'";}?>
                            tabindex="1" class="form-control teacher income_count customfield1 cf_class" />
                    </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' tabindex='1'  class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
echo "</select>";
?></td>


                    <?php } ?>



                    <?php if($info1000['en_inventorybatch']==1  ) { ?>
                    <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where (active=1 && prd_id='$sid') || id='$obatch_id' ") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1'  class='teacher reportselect inventory3 change7 loadBatchExpiry' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
 $batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?></td>
                    <?php } else if($info2000['multiple_batch']==1) { ?>
                    <td>
                        <?php if($st==1) {
       $pid =  $info2['id']; 
       $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'   && type_component=0 ") or die(mysqli_error($conn));
       $ii=0;
        // if($info2['is_batch'] != 1)
        //   $class="hide";
        echo "<select name='multi_batch[]' tabindex='1'  class='teacher reportselect $class'    required  >";
         while($info4 = mysqli_fetch_array( $data4 )) 
         { 
              // $in = mysqli_get_var("Select SUM(qty) from warehouse_transaction w, warehouse_transaction_type t where item_id='$pid' && w.deleted=0  && w.tran_type=t.id && t.type=1 && w.batch_no='".$info4['id']."' ");
              $out = mysqli_get_var("Select SUM(qty) from warehouse_transaction w, warehouse_transaction_type t where item_id='$pid' && w.deleted=0  && w.tran_type=3 && t.type=0 && w.batch_no='".$info4['id']."' ");
              $bbance =$out; // $in - 
              if($bbance==0) continue;
           echo "<option value='".$info4['id']."' >".$info4['batch_code']." (".$bbance.") </option>";
        }
        echo "</select>";
       }else { ?>
                        <input type="number" name="multi_batch[]" value="-" readonly="readonly" />
                        <?php } ?>
                    </td>
                    <?php } ?>

                    <?php  if($info1000['en_expirydisplay']==1) {  ?>
                        <td <?php //if($return==1) { echo ' style=" display:none;"'; } ?>><input type="date"
                                name="products_expiry[]" id="LoadExpiryHere" <?php  if($info2['is_batch']==0) { echo 'readonly';  }?> value=""
                                tabindex="1" <?php if($return==0) { ?> required <?php } ?>
                                class="change8 form-control LoadExpiryHere" readonly="readonly" id="<?php echo "expiry".$info2['id'];?>" /></td>
                        <?php //expiry7 class is removed from here 
                        } ?>

                    <?php if($info1000['en_embroidery']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from stitching_area") or die(mysqli_error($conn)); 
echo "<select name='products_sarea[]' class='teacher change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><input type="number" name="products_scolor[]" class="form-control" /> </td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from stitching_type") or die(mysqli_error($conn)); 
echo "<select name='products_stype[]' class='teacher change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from stitching_fusion") or die(mysqli_error($conn)); 
echo "<select name='products_sfusion[]' class='teacher  change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <?php } ?>

                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input type="text"
                            name="products_packing[]" size="4" value="<?php echo $info2['packing'];?>"
                            class="new_packing edit-input change income_count totalorder" tabindex="1"
                            id="p<?php echo $info2['id'];?>" />
                    </td>
                    <td>
                        <?php
      if($info3000['en_snd_purchase']==1)
  {
    $data15 = mysqli_query($conn,"SELECT distributor_type from distributor where  id='$dist_id' ") or die(mysqli_error($conn));
    // echo "SELECT distributor_type from distributor where  id='$dist_id' ";
    $info15 = mysqli_fetch_array( $data15 ); 
     $ttid=$info15['distributor_type'];
  }
  else
  {
      $data15 = mysqli_query($conn,"SELECT customer_type, customer_type2 from customer where  id='$cid' ") or die(mysqli_error($conn));   
      $info15 = mysqli_fetch_array( $data15 ); 
      $ttid=$info15['customer_type'];
      $ttid2=$info15['customer_type2'];
  }
  $ppid=$info2['id'];
$new_rate = 0;
//multipricingratecheck
if($userdefault_price=='0'){
  $sale_multiprice = $infomultiprice1000['sale_price'];
 ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            step="0.0001" required value="<?php echo  $infomultiprice1000['sale_price'];?>"
                            class=" edit-input <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> new_rate income_count chk8ange totalorder"
                            size="4" />
                        <?php
}else{
 $data15 = mysqli_query($conn,"SELECT price, mrp_price from customer_type_pricing where pid='$ttid' AND tid='$ppid' && company_id = '$current_company' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($info4000['loadsalesvalue_return']==1 && $num_rows25!=0) {
      $rate = $lastinv['tp'];
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" step="0.0001" required min="0" 
                            type="number" value="<?php echo $rate; $mpp = $info15['mrp_price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  new_rate income_count chk8ange totalorder"
                            size="4" />
                        <?php
}
else if($num_rows!=0 && (float)$info15['discount']>0) {
  $new_rate = $info15['price'];
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" type="number" step="0.0001" min="0" 
                            name="unitcos[]"
                            value="<?php if($otp!='') { echo $otp; } else { echo $info15['price']; } $mpp = $info15['mrp_price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  new_rate income_count chk8ange totalorder"
                            size="4" />
                        <?php } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100; 
$discount4=$info200['discount4']/100;
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3;  
$discount4=1-$discount4;
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info200['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x;
$new_rate = $price;
    ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            step="0.0001" value="<?php echo $price;?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php }
else if ($info4000['return_invoice_ref']==1){ 
$price = mysqli_get_var("SELECT tp from sales_details where order_id in($inv_no) && prd_id =$sid");
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            step="0.0001" value="<?php echo $price;?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> new_rate income_count chk8ange totalorder"
                            size="4" />
                        <?php
}
else {  
$new_rate = $info2['sale_price'];
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            step="0.0001" value="<?php echo $info2['sale_price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> new_rate income_count chk8ange totalorder"
                            size="4" />
                        <?php }
?>
                        <input name="tax_mrp[]" size="4" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "mrptax".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['tax_mrp'];?>" />
                        <?php }
              if($info4000['separate_mrpcolumn']==0)
              {
              ?>
                        <input name="mrp_price[]" size="4" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "mrp".$info2['id'];?>" tabindex="1"
                            value="<?php if($mpp!='' && $mpp!=0) { echo $mpp;  } else { echo $info2['mrp_price']; } $mpp=''; ?>" />
                        <?php
              }
              ?>
                        <!-- <input name="new_rate[]" size="4"   type="hidden" class="new_rate" value="<?php echo $new_rate;?>"  /> -->
                    </td>
                    <?php if($info4000['separate_mrpcolumn']==1) { ?> <td>
                        <input name="mrp_price[]" size="4" type="number" required step='0.0001'
                            class="edit-input income_count totalorder" id="<?php echo "mrp".$info2['id'];?>"
                            tabindex="1"
                            value="<?php if($mpp!='' && $mpp!=0) { echo $mpp;  } else { echo $info2['mrp_price']; } $mpp=''; ?>" />
                    </td>
                    <?php } //closepricing ?>
                    <?php if($info2000['en_sarhad'] == 1 || $info4000['itemmulti_unit']==1){ ?>
                    <input name="prd_hidden[]" type="hidden" class="prd_hidden" value="<?php echo $info2['id'];?>" />
                    <input name="packing_hidden[]" type="hidden" class="packing_hidden"
                        value="<?php echo $info2['packing'];?>" />
                    <td>
                        <?php 
              $single_unit = mysqli_get_var("SELECT unit FROM inventory WHERE id='".$info2['id']."' ");
              $data4 = mysqli_query($conn,"SELECT * FROM product_unit WHERE id IN (SELECT unit FROM multiple_product_unit WHERE pid = '".$info2['id']."' ) OR product_unit.`id` = '".$single_unit."' ") or die(mysqli_error($conn)); 
              echo "<select name='munit[]'  required class=' munit form-control'   >";
              //echo "<option value='0' >Select Product Unit</option>";
              while($info4 = mysqli_fetch_array( $data4 )){ 
                $selected = '';
                if($single_unit == $info4['id'])
                  $selected = 'selected';
                echo "<option value='".$info4['id']."' $selected >".$info4['name']."</option>";
              }
              echo "</select>";
              ?></td>
                    <td style="display:none;"><input name="con_rate[]" value="1" size="4" class="con_rate" id="" /></td>
                    <?php } ?>
                    <td <?php  if($info2000['en_ricetrade']==0) { echo ' style=" display:none;"'; } ?>><input
                            name="packing2[]" type="number" step="0.0001" class='teacher packing2 income_count'
                            value="<?php echo $info2['pac2']; ?>" id="<?php echo "packk".$info2['id'];?>" /> </td>
                    <td <?php  if($info2000['invoice_cartonrate']==0) { echo ' style=" display:none;"'; } ?>>
                        <select name='rate_in_carton[]' class='teacher income_count case2qty'
                            id="<?php echo "ric".$info2['id'];?>">
                            <option value='0'>Default</option>
                            <?php if($info4000['en_engineering']==0){ ?>
                            <option value='1'><?php echo $info1000['packing_label']; ?></option>
                            <?php } ?>
                            <option value='2'><?php echo $info1000['multi_unit_label']; ?></option>
                            <option value='3'><?php echo $info2000['customfield1_display'];  ?></option>
                        </select>
                    </td>
                    <?php
                        /***----start saqib---------*/
                        if($info1000['salesman_mode']==1){
                          if($info1000['customer_discount1']==1){
                           if($infomultiprice1000['disc1_value']>0){ 
                            ?>
                    <td>
                        <input name="products_discount[]" type="number" step="0.0001"
                            class="edit-input income_count totalorder" id="<?php echo "ppp".$info2['id']?>"
                            tabindex="1" value="<?php  echo $infomultiprice1000['disc1_value']; ?>" size="4" />
                    </td>
                    <?php  }
                        else{ ?>
                    <td>
                        <input name="products_discount[]" type="number" step="0.0001"
                            class="edit-input income_count totalorder" id="<?php echo "ppp".$info2['id'];?>"
                            tabindex="1" value="0" size="4" />
                    </td>
                    <?php
                        }
                        }
                        else if ($info4000['return_invoice_ref']==1){ 
                          $disc1 = mysqli_get_var("SELECT discount from sales_details where order_id in($inv_no) && prd_id =$sid");
                          ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $disc1; ?>" size="4" />
                    <?php  }
                        else{
                        ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php
                        }
                        //closedist1_sales
                        if($info1000['customer_discount2']==1){
                          if($infomultiprice1000['disc2_value']>0){ 
                           ?>
                    <td>
                        <input name="products_discount2[]" type="number" required step="0.0001"
                            class="edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>"
                            tabindex="1" value="<?php  echo $infomultiprice1000['disc2_value']; ?>" size="4" />
                    </td>
                    <?php  }else{ ?>
                    <td>
                        <input name="products_discount2[]" type="number" required step="0.0001"
                            class="edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>"
                            tabindex="1" value="0" size="4" />
                    </td>
                    <?php
                        }
                        }
                        else if ($info4000['return_invoice_ref']==1){ 
                          $disc1 = mysqli_get_var("SELECT discount2 from sales_details where order_id in($inv_no) && prd_id =$sid");
                          ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $disc1; ?>" size="4" />
                    <?php  }
                        else{ ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                        value="<?php if($odiscount2!='') { echo $odiscount2; } else { echo 0; } ?>" size="4" />
                    <?php
                        }//closedist2_sales
                        if($info1000['customer_discount3']==1){
                          if($infomultiprice1000['trade_offer']>0){ 
                           ?>
                    <td>
                        <input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php  echo $infomultiprice1000['trade_offer']; ?>" size="4" />
                    </td>
                    <?php  }else{ ?>
                    <td>
                        <input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    </td>
                    <?php
                        }
                        }
                        else if ($info4000['return_invoice_ref']==1){ 
                          $disc1 = mysqli_get_var("SELECT discount3 from sales_details where order_id in($inv_no) && prd_id =$sid");
                          ?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="<?php echo $disc1; ?>" size="4" />
                    <?php  }
                        else{ ?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                        value="<?php if($odiscount3!='') { echo $odiscount3; } else { echo 0; } ?>" size="4" />
                    <?php
                        }//closedist3_sales
                        if($info1000['customer_scheme']==1) { 
                          if($infomultiprice1000['scheme']>0){ 
                           ?>
                    <td>
                        <input name="products_scheme[]" type="number" step="0.0001" required
                            class="edit-input income_count totalorder scheme_o" id="<?php echo "ppps".$info2['id'];?>"
                            tabindex="1" value="<?php  echo $infomultiprice1000['scheme']; ?>" size="4" />
                    </td>
                    <?php  }else{ ?>
                    <td><input name="products_scheme[]" type="number" step="0.0001" required
                            class="edit-input income_count totalorder scheme_o" id="<?php echo "ppps".$info2['id'];?>"
                            tabindex="1" value="<?php if($oscheme!='') { echo $oscheme; } else { echo 0; } ?>"
                            size="4" /></td>
                    <?php
                        }
                        }
                        else{ ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder scheme_o"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1"
                        value="<?php if($oscheme!='') { echo $oscheme; } else { echo 0; } ?>" size="4" />
                    <?php
                         }
                         //closescheme_sales
                         if($info3000['customer_scheme_value']==1) { 
                            if($infomultiprice1000['scheme_value_amount']>0){ 
                            ?>
                                                <td>
                                                    <input name="products_scheme_value[]" type="text"
                                                        class=" edit-input income_count  scheme_v remaingcal"
                                                        id="<?php echo "sv".$info2['id'];?>" tabindex="1"
                                                        value="<?php  echo $infomultiprice1000['scheme_value_amount']; ?>" size="4" />
                                                </td>
                                                <?php  }else{ ?>
                                                <td><input name="products_scheme_value[]" type="text"
                                                        class=" edit-input income_count  scheme_v remaingcal"
                                                        id="<?php echo "sv".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                                                <?php
                            }
                            }
                            else{ ?>
                                                <input name="products_scheme_value[]" type="hidden"
                                                    class=" edit-input income_count  scheme_v remaingcal"
                                                    id="<?php echo "sv".$info2['id'];?>" tabindex="1" value="0" size="4" />
                                                <?php
                            }
                        ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <input name="products_scheme_qty[]" type="hidden"
                            class="edit-input income_count totalorder scheme_valcal"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1"
                            value="<?php if($oscheme_formula!='') { echo $oscheme_formula; } else {  echo $info15['scheme']; } ?>"
                            size="4" />
                        <input name="products_pcs[]" type="number" step="0.0001"
                            <?php if($info1000['inventory_limit']==1 && ($info1000['gdninventory_limit']==0 || $gdn==1)) { if($info1000['en_inventorybatch']==1) { echo 'max="'.$maxx.'"'; } else { echo 'max="'.$info2['qty'].'"'; } } ?>
                            class="total_pcs" id="<?php echo "t".$info2['id'];?>" min="0" size="4" />
                    </td>
                    <?php  /*closeschemeqty_sales */   ?>
                    <?php if($info1000['customer_tax1']==1) { 
                        $tax1_value = $infomultiprice1000['tax1_value'];
                        $tax1_value1 = ($customer_filer=='1')?$tax1filer_value:$tax1_value;
                          if($infomultiprice1000['tax1_value']>0){ 
                           ?>
                    <td>
                        <input name="products_tax[]" type="number" class="edit-input income_count"
                            id="<?php echo "pppp".$info2['id'];?>" tabindex="1" value="<?php  echo $tax1_value1; ?>"
                            size="4" readonly="readonly" />
                    </td>
                    <?php  }else{ ?>
                    <td>
                        <input name="products_tax[]" type="number" class="edit-input income_count"
                            id="<?php echo "pppp".$info2['id'];?>" tabindex="1" value="0" size="4"
                            readonly="readonly" />
                    </td>
                    <?php
                        }}else{ ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count"
                        id="<?php echo "pppp".$info2['id'];?>" tabindex="1" value="0" size="4" readonly="readonly" />
                    <?php
                           }
                        /*closetax1_sales */   ?>
                    <?php if($info1000['customer_tax2']==1) { 
                        $tax2_value = $infomultiprice1000['tax2_value'];
                        $tax2_value2 = ((isset($num_rows_ctp) && $num_rows_ctp!=0) ? $tax2_value : (($customer_filer=='1')?$tax2filer_value:$tax2_value));
                        if($infomultiprice1000['tax2_value']>0){ 
                         ?>
                    <td>
                        <input name="products_tax2[]" type="number" required step="0.0001"
                            class="edit-input income_count" id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php  echo $tax2_value2; ?>" size="4" readonly="readonly" />
                    </td>
                    <?php  }else{ ?>
                    <td>
                        <input name="products_tax2[]" type="number" required step="0.0001"
                            class="edit-input income_count" id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php  echo '0'; ?>" size="4" readonly="readonly" />
                    </td>
                    <?php
                        }
                        }else{ ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="<?php  echo '0'; ?>" size="4"
                        readonly="readonly" />
                    <?php
                             }
                        /*closetax2_sales */   ?>
                    <?php if($info1000['customer_tax3']==1) { 
                        $tax3_value = $infomultiprice1000['tax3_value'];
                        $tax3_value3 = ((isset($num_rows_ctp) && $num_rows_ctp!=0) ? $tax3_value : (($customer_filer=='1')?$tax3filer_value:$tax3_value));
                        if($infomultiprice1000['tax3_value']>0){ 
                         ?>
                    <td>
                        <input name="products_tax3[]" type="text" class="edit-input income_count"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="<?php  echo $tax3_value3; ?>"
                            size="4" readonly="readonly" />
                    </td>
                    <?php  }else{ ?>
                    <td>
                        <input name="products_tax3[]" type="text" class="edit-input income_count"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="<?php  echo '0'; ?>" size="4"
                            readonly="readonly" />
                    </td>
                    <?php
                        }
                        }else{ ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="<?php  echo '0'; ?>" size="4"
                        readonly="readonly" />
                    <?php
                               }
                        /*closetax3_sales */   ?>
                    <?php
                        }//close salesmode
else{  ?>
                    <?php if($info1000['customer_discount1']==1) { 
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from cb_discount where cid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from customer_type_discount1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($info3000['en_elixirbeauty']) {
    $bid=$info2['brand_id'];
    $binv_discount = mysqli_get_var("Select binv_discount from customer_brandlimit WHERE customer_id='$cid' && brand_id='$bid' "); 
?>
                    <td> <input name="products_discount[]" type="number" step="0.0001"
                            class="edit-input income_count totalorder" id="<?php echo "ppp".$info2['id'];?>"
                            tabindex="1" value="<?php echo $binv_discount;?>" size="4" /> </td>
                    <?php 
}
else if($num_rows!=0 && $info15['discount']!=-1) {
?>
                    <td><input name="products_discount[]" type="number" step="0.0001"
                            class="edit-input income_count totalorder" id="<?php echo "ppp".$info2['id'];?>"
                            tabindex="1" value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php }
else if($info2['direct_invoicediscount1']!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount[]"
                            type="number" step="0.0001" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['direct_invoicediscount1'];?>" size="4" /></td>
                    <?php 
}
else if($num_rows2!=0) {
?>
                    <td><input name="products_discount[]" type="number" step="0.0001"
                            class="edit-input income_count totalorder" id="<?php echo "ppp".$info2['id'];?>"
                            tabindex="1" value="<?php echo $info17['discount'];?>" size="4" /></td>
                    <?php }
 else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <td>
                        <input name="products_discount[]" type="number" step="0.0001"
                            class="edit-input income_count totalorder" id="<?php echo "ppp".$info2['id'];?>"
                            tabindex="1" value="<?php echo $info200['discount'];?>" size="4" />
                    </td>
                    <!-- add discount 1  here  -->
                    <?php } 
else if($info4000['loadsalesvalue_return']==1 && $num_rows25!=0) {
      $discount = $lastinv['discount'];
  ?>
                    <td>
                        <input name="products_discount[]" type="number" step="0.0001"
                            class="edit-input income_count totalorder" id="<?php echo "ppp".$info2['id'];?>"
                            tabindex="1" value="<?php echo $discount; ?>" size="4" />
                    </td>
                    <?php   
 }
 else {  ?>
                    <td><input name="products_discount[]" type="number" step="0.0001"
                            class="edit-input income_count totalorder" id="<?php echo "ppp".$info2['id'];?>"
                            tabindex="1" value="0" size="4" /></td>
                    <?php }  } else { ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$disc22 = $info15['discount'];
if($info4000['alternate_customertype']==1 )     {
     $disc22 = mysqli_get_var("SELECT discount from customer_type_discount2 where pid='$ttid2' AND tid='$ppid' "); 
     if($disc22=='' || $disc22=='-1' ) $disc22=0;
    ?>
                    <td><input name="products_discount2[]" type="number" step="0.0001" required
                            class="edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>"
                            tabindex="1" value="<?php echo $disc22;?>" size="4" /></td>
                    <?php   }
 else  if($num_rows!=0 && $info15['discount']!=-1) {
?>
                    <td><input name="products_discount2[]" type="number" step="0.0001" required
                            class="edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>"
                            tabindex="1" value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } 
else if($info2['direct_invoicediscount2']!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount2[]"
                            type="number" step="0.0001" required class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['direct_invoicediscount2'];?>" size="4" /></td>
                    <?php 
}
 else if($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount2[]" type="number" step="0.0001" required
                            class="edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>"
                            tabindex="1" value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php } 
else if($info4000['loadsalesvalue_return']==1 && $num_rows25!=0) {
      $discount2 = $lastinv['discount2'];
  ?>
                    <td><input name="products_discount2[]" type="number" step="0.0001" required
                            class="edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>"
                            tabindex="1" value="<?php echo $discount2; ?>" size="4" /></td>
                    <?php   
 }
 else {  ?>
                    <td><input name="products_discount2[]" type="number" step="0.0001" required
                            class="edit-input income_count totalorder" id="<?php echo "pppn".$info2['id'];?>"
                            tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } 
 if($info1000['customer_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount4 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
  if($num_rows!=0 && $info15['discount']!=-1) {
?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } if($info2['direct_invoicediscount4']!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount4[]"
                            type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['direct_invoicediscount4'];?>" size="4" /></td>
                    <?php 
} elseif($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php } 
else if($info4000['loadsalesvalue_return']==1 && $num_rows25!=0) {
      $discount3 = $lastinv['discount3'];
  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="<?php echo $discount3;?>"
                            size="4" /></td>
                    <?php   
 }
 else {  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info2000['customer_foc']==1) { 
  if ($info4000['return_invoice_ref']==1){ 
$foc = mysqli_get_var("SELECT foc from sales_details where order_id in($inv_no) && prd_id =$sid");
?>
                    <td><input type="text" name="products_foc[]" value="<?php echo $foc; ?>" class="foc income_count"
                            id="<?php echo "pfoc".$info2['id'];?>" required size="4" /> </td>
                    <?php } else { ?>
                    <td><input type="number" step="0.0001" name="products_foc[]" value="0" class="foc income_count"
                            id="<?php echo "pfoc".$info2['id'];?>" required size="4" /> </td>
                    <?php } }
 else { 
    ?>
                    <input type="hidden" name="products_foc[]" value="0" class="foc income_count"
                        id="<?php echo "pfoc".$info2['id'];?>" required size="4" />
                    <?php }
  if($info1000['customer_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='') {?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount3'];?>" size="4" /></td>
                    <?php } 
else if($info4000['loadsalesvalue_return']==1 && $num_rows25!=0) {
      $discount3 = $lastinv['discount4'];
  ?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="<?php echo $discount3 ;?>"
                            size="4" /></td>
                    <?php   
 }
else {  ?>
                    <td><input name="products_discount3[]" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" step="0.0001" /></td>
                    <?php } } else {?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" step="0.0001" size="4" />
                    <?php }
if($info2000['en_discount5']==1) { ?>
                    <td><input type="text" name="discount5[]" class="edit-input income_count"
                            id="<?php echo "pppl".$info2['id'];?>" tabindex="1" value="0" required size="4" /> </td>
                    <?php } 
 if($info1000['customer_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from customer_type_scheme where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="number" step="0.0001" required
                            class="edit-input income_count totalorder" id="<?php echo "ppps".$info2['id'];?>"
                            tabindex="1" value="<?php echo $info15['scheme'];?>" size="4" />
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="number" step="0.0001" required
                            class="edit-input income_count totalorder" id="<?php echo "ppps".$info2['id'];?>"
                            tabindex="1" value="<?php echo $info200['scheme'];?>" size="4" /></td>
                    <?php }  else {  ?>
                    <td><input name="products_scheme[]" type="number" step="0.0001" required
                            class="edit-input income_count totalorder" id="<?php echo "ppps".$info2['id'];?>"
                            tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                        <input name="products_pcs[]" type="text" class="total_pcs"
                            id="<?php echo "t".$info2['id'];?>" min="0" size="4" />
                    </td>
                    <?php if($info1000['customer_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
 if($info4000['loadsalesvalue_return']==1 && $num_rows25!=0) {
     $tax_applied = $lastinv['tax_applied'];
?>
                    <td><input name="products_tax[]" type="number" required step="0.0001"
                            class="edit-input income_count" tabindex="1" id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $tax_applied; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php }  
else if($info2000['en_maintax']==1) {
?>
                    <td><input name="products_tax[]" type="number" required step="0.0001"
                            class="edit-input income_count" tabindex="1" id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($st==1) {  if($cfiler==1) { echo $info2000['filer_tax']; } else { echo $info2000['nonfiler_tax']; }  } else { echo 0; } ?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
else if($num_rows!=0) {
?>
                    <td><input name="products_tax[]" type="number" required step="0.0001"
                            class="edit-input income_count" tabindex="1" id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" <?php if($info4000['en_engineering']==1){} else { ?>readonly="readonly"
                            <?php } ?> /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td> <input name="products_tax[]" type="number" required step="0.0001"
                            class="edit-input income_count" tabindex="1" id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" <?php if($info4000['en_engineering']==1){} else { ?>readonly="readonly"
                            <?php } ?> /></td>
                    <?php }
  else {  ?>
                    <td><input name="products_tax[]" type="number" required step="0.0001"
                            class="edit-input income_count" tabindex="1" id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                            <?php if($info4000['en_engineering']==1){} else { ?>readonly="readonly" <?php } ?> /></td>
                    <?php } } else { ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" />
                    <?php } ?>
                    <td <?php if($info2000['invoice_cartonrate']==0) { echo ' style=" display:none;" '; } ?>><input
                            name="pipe[]" type="text" class="edit-input pipehide income_count" tabindex="1"
                            id="<?php echo "pipe".$info2['id'];?>" value="<?php  echo 0; ?>" size="4"
                            <?php if($info4000['en_engineering']==1){} else { ?>readonly="readonly" <?php } ?> /></td>
                    <?php if($info1000['customer_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax2[]" type="number" required step="0.0001"
                            class="edit-input income_count totalorder" id="<?php echo "ppptt".$info2['id'];?>"
                            tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td><input name="products_tax2[]" type="number" required step="0.0001"
                            class="edit-input income_count totalorder" id="<?php echo "ppptt".$info2['id'];?>"
                            tabindex="1" value="<?php echo $info200['tax_applied2']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax2[]" type="number" required step="0.0001"
                            class="edit-input income_count totalorder" id="<?php echo "ppptt".$info2['id'];?>"
                            tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } 
else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <?php }//close main
          ?>
                    <td class="<?php echo ($info2000['en_freshmate)'] == 1)? '': 'hidden'?>"><input type="date"
                            name="expiry_date[]" value="<?php $info2['expiry_date'];?>"
                            <?php echo ($info2000['en_freshmate'] == 1) ? 'required':''?> /></td>
                    <td class="<?php echo ($info2000['en_freshmate'] == 1 )? '': 'hidden'?>">
                        <?php
    $data16 = mysqli_query($conn,"SELECT * FROM return_reason ORDER BY name") or die(mysqli_error($conn));
    $required = ($info2000['en_freshmate'] == 1) ? 'required':'';
    echo "<select name='reason[]' ".$required." > 
    <option value='' selected >Select Reason..</option> ";
    while($info16 = mysqli_fetch_array( $data16 )){
        echo "<option value='".$info16['id']."' >".$info16['name']."</option>";
    }
    echo "</select>";
?>
                    </td>
                    <td><input type="hidden" name="products_cogs[]" value="<?php
      if($info1000['en_inventorybatch']==1) { echo $unitc; } else {  echo $info2['unit_cost']; } ?>"
                            class="prd_cogs" />
                        <input name="products_total[]" step="0.0001"  type="number" id="newtotal<?php echo $info2['id'];?>"  
                            class="form-control tot<?php echo $info2['id'];?> ptotal sub_total income_count readonly " size="5" min="0"
                            tabindex="-1" onkeypress="return false;" />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php if($info1000['open_ratecolumn']==1 && $gdn==0) { ?>
                $('.change15').focusout(function() {
                            $(".change15").removeClass("change15");
                            <?php }  else if($info1000['en_inventorybatch']==1 && $gdn==1) {  ?>
                            $('.change7').focusout(function() {
                                        $(".change7").removeClass("change7");
                                        <?php } else if($info1000['en_warehouse']==1) {  ?>
                                        $('.change6').focusout(function() {
                                            $(".change6").removeClass("change6");
                                            <?php } else {  ?>
                                            $('.change5').focusout(function() {
                                                $(".change5").removeClass("change5");
                                                <?php }  ?>
                                                var $orginal = $(this).closest("tr");
                                                var $cloned = $orginal.clone();
                                                //get original selects into a jq object
                                                var $originalSelects = $orginal.find('select');
                                                $cloned.find('select').each(function(index, item) {
                                                    //set new select to value of old select
                                                    $(item).val($originalSelects.eq(index)
                                                        .val());
                                                });
                                                //get original textareas into a jq object
                                                var $originalTextareas = $orginal.find('textarea');
                                                $cloned.find('textarea').each(function(index, item) {
                                                    //set new textareas to value of old textareas
                                                    $(item).val($originalTextareas.eq(index)
                                                        .val());
                                                });
                                                $cloned.appendTo("#acart");
                                                $('.change5').attr('class',
                                                    " change income_count totalorder packing");
                                                <?php if($info2000['search_multibarcode']==0) { ?>
                                                $("#searchbox").focus();
                                                <?php } else { ?>
                                                $(".baccodesearch").focus();
                                                <?php } ?>
                                                $("#psearch").html('');
                                                var n10 = $("#totpc").val();
                                                n10 = parseInt(n10) + parseInt(1);
                                                $("#totpc").val(n10);
                                                var n11 = $("#totpc").val();
                                                $(".sno:last").val(n11);
                                            });
                                        });
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { 
?>
    $(".inventory3").on('change', function() {
        var vid = $(this).val();
        var self = $(this);
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch6: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.prd_cogs').attr("value", tt);
            }
        });
    });
    <?php }} ?>
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $(".delete").on('click', function() {
        var shoppingcart = $(this).closest('tr').find('.singleitem').val();
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query2.php",
            data: {
                cartclear: shoppingcart
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                $(".shopping_cart").html(html);
            }
        });
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        var sum30 = 0;
        $(".foc").each(function() {
            sum30 += parseFloat($(this).val()) || 0;
        });
        var sum30c = sum3 + sum30;
        $("#packing").val(sum30c);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        var decimal_point = "<?php echo $info2000['total_decimal']; ?>";
        sum2 = sum2.toFixed(decimal_point);
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass != 'brokery_rs' && specialclass != 'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        var decimal_point = "<?php echo $info2000['total_decimal']; ?>";
        result = result.toFixed(decimal_point);
        //result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        result2 = result2.toFixed(decimal_point);
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  } 
       }
   else if(isset($_POST['sid555']))
{
    $sid=test_input($_POST['sid555']);
    $cid=test_input($_POST['customerid']);
    $st=test_input($_POST['st']);
    $dist_id2 = test_input($_POST['dist_id2']);
 $gdn=test_input($_POST['gdn']);
  $dist_id=test_input($_POST['dist_id']);
  if($dist_id=='') $dist_id=0;
if($dist_id2=='') $dist_id2=0;
/*------start multipricing------------- */
$date =      date('Y-m-d');
$customer_type = mysqli_get_var("SELECT customer_type FROM `customer` where id = '$cid'");
$customer_type = ($customer_type=='')?'""':$customer_type;
$customer_filer = mysqli_get_var("SELECT filer FROM `customer` where id = '$cid'");
$customer_filer = ($customer_filer=='')?'0':$customer_filer;
$cid = ($cid=='a')?'0':$cid;
if($cid=='') $cid=0;
$multiprice1000 = mysqli_query($conn,"SELECT * FROM `multi_pricing` 
where (find_in_set($sid,prd_id) <> 0 || prd_id = 0) and  
(find_in_set($dist_id2,distributor_id) <> 0  || distributor_id =0)
 and (find_in_set($cid,customer_id) <> 0   || customer_id=0)  
and (find_in_set($customer_type,customer_type) <> 0 || customer_type=0) and `status` = 1 and 
(starting_date <= '$date'||starting_date ='') and (ending_date >= '$date' || ending_date='') and
1=1  order by id desc limit 1") or die(mysqli_error($conn));       
$infomultiprice1000 = mysqli_fetch_array( $multiprice1000 );
$userdefault_price = $infomultiprice1000['use_defaultprice'];
$tax1filer_value = $infomultiprice1000['tax1filer_value'];
$tax2filer_value = $infomultiprice1000['tax2filer_value'];
$tax3filer_value = $infomultiprice1000['tax3filer_value'];
if($gdn=='') $gdn = 0;
if(in_array($sid, $_SESSION["shopping_cart"]) && $info2000['noduplicate_item']==1) 
           {  
     ?>
    <script type="text/javascript">
    alert('This item is already added');
    </script>
    <?php   }
  else {
     $_SESSION['shopping_cart'][] = $sid;
$cwarehouse = mysqli_get_var("Select inventory_warehouse from customer where `id` = '$cid'");
$cfiler = mysqli_get_var("Select filer from customer where `id` = '$cid'");
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="2%">S.No</th>
                    <th width="20%">
                        <div><?php echo $info1000['product_label']; ?></div>
                    </th>
                    <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <div>QTA</div>
                    </th>
                    <th>
                        <div><?php echo $info1000['multi_unit_label']; ?></div>
                    </th>
                    <th
                        <?php if($info1000['no_salespacking']==1   || $info2000['pcs_hide']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['single_unit_label']; ?></div>
                    </th>
                    <th <?php if($info2000['en_customfield1']==0) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info2000['customfield1_display'];  ?></div>
                    </th>
                    <?php if($info1000['en_warehouse']==1) {  echo  '  <th ><div>WH </div></th> '; } ?>
                    <?php if($info1000['en_inventorybatch']==1  && $gdn==1) {   echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; } ?>
                    <?php if($info2000['multiple_batch']==1) {   echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; } ?>
                    <?php if($info1000['en_embroidery']==1) { 
         echo  ' 
          <th ><div>Type </div></th>
          <th ><div>Colors </div></th>
         <th ><div>Head Working </div></th>
         <th ><div>Fusing </div></th>
          '; } ?>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['packing_label']; ?></div>
                    </th>
                    <th>
                        <div><?php echo $info1000['price_label']; ?></div>
                    </th>
                    <?php if($info2000['en_sarhad']==1 || $info4000['itemmulti_unit']==1) { ?>
                    <th>
                        <div>Unit</div>
                    </th>
                    <th style="display:none;">
                        <div>Unit Rate</div>
                    </th>
                    <?php } ?>
                    <?php  if($info2000['invoice_cartonrate']==1) {  ?>
                    <th>
                        <div>Rate Apply</div>
                    </th>
                    <?php } ?>
                    <?php if($info1000['customer_discount1']==1) {  echo  '  <th ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount2']==1) {  echo  '  <th ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount4']==1) {  echo  '  <th ><div>'.$info1000['disc4_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount3']==1) {  echo  '  <th ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
                    <?php if($info2000['customer_foc']==1) {  echo  '  <th ><div>'.$info4000['customerfoc_label'].'</div></th> '; } ?>
                    <?php if($info2000['en_discount5']==1) {  echo  '  <th ><div>Disc (Rs.)</div></th> '; } ?>
                    <?php if($info1000['customer_scheme']==1) {  echo  '  <th ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                    <?php if($info1000['customer_tax1']==1) {  echo  '  <th ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
                    <?php  if($info2000['invoice_cartonrate']==1) {  ?>
                    <th>
                        <div>Pipe Rate</div>
                    </th>
                    <?php } ?>
                    <?php if($info1000['customer_tax2']==1) {  echo  '  <th ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax3']==1) {  echo  '  <th ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
                    <th class="<?php echo ($info2000['en_freshmate'] == 1)? '' : 'hidden'?>">Expiry Date</th>
                    <th class="<?php echo ($info2000['en_freshmate'] == 1)? '' : 'hidden'?>">Reason</th>
                    <th contenteditable="true" width="80">Total </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
   if($info1000['en_deals']==1) { 
    //echo "SELECT * from sales where id='$sid'";
   // echo "SELECT * FROM `sales_details` s where order_id IN (select id from sales d where d.id=s.order_id AND d.customer_id='$cid' AND prd.id='$sid' order by d.id desc limit 1";
    $data2 = mysqli_query($conn,"SELECT * FROM `sales_details` s where order_id IN (select id from sales d where d.id=s.order_id AND d.customer_id='$cid' AND s.prd_id='$sid' order by d.id DESC)") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr>
                    <td class="sno"></td>
                    <td><input type="hidden" name="deal[]" value="d<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <?php 
   $did=$info2['id'];
   $data15 = mysqli_query($conn,"SELECT *, i.qty/d.qty AS aqty, d.qty AS dqty from inventory i, deal_details d where d.did='$did' AND d.pid=i.id") or die(mysqli_error($conn));
  $taqty=10000; 
while($info15 = mysqli_fetch_array( $data15 )) 
 { 
 if($info15['aqty']<=$taqty)
 {
 $taqty=$info15['aqty'];
 }
 else {
 $info15['aqty']=ceil($taqty);
 }
 $staqty=$info15['aqty'];
 echo $info15['dqty']." Pcs - ".$info15['name']."<br>";
 }
 ?>
                    </td>
                    <td><?php  if($staqty<$taqty)
        {
        echo ceil($staqty);
        }
        else  {
          $staqty=$taqty;
           echo ceil($staqty);
        }
        ?></td>
                    <td>
                        <input name="d<?php echo $info2['id'];?>" type="text" min="1"
                            class="searchqty income_count form-control" id="d<?php echo $info2['id'];?>"
                            tabindex="1" />
                    </td>
                    <td><input type="text" class="form-control income_count" /> </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='".$info2['id']."_warehouse' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td><?php echo $info2['packing'];?></td>
                    <td>
                        <input id="<?php echo "nm".$info2['id'];?>" value="<?php echo $info2['sale_price'];?>"
                            class="income_count" onchange="changealert(this.id)" size="20" />
                    </td>
                    <td><input type="text" class="form-control income_count" value="0" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>" /></td>
                    <td><input type="text" class="form-control income_count" /></td>
                    <td><input type="text" class="form-control income_count" value="0" /></td>
                    <td><input type="hidden" name="d<?php echo $info2['id']."_cogs";?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input name="d<?php echo $info2['id']."_total";?>" type="text"
                            class="d<?php echo $info2['id'];?> ptotal form-control" tabindex="-1" readonly />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
                <?php  if($info1000['en_singleproducts']==1) { 
       $data2 = mysqli_query($conn,"SELECT *, packing2 as pac2 from inventory where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr class="carttr">
                    <td><input type="text" class="sno form-control" />
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from sales_return_details sd, sales_return s  where sd.prd_id='$sid' AND s.type_component=0 AND sd.`return_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
  else if($info1000['en_lastprice']==2 ) {
     $data200 = mysqli_query($conn,"SELECT sd.* from sales_return_details sd, sales_return s  where sd.prd_id='$sid' AND s.type_component=0 AND sd.`return_id`=s.`id` AND s.customer_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }      ?>
                    </td>
                    <td>
                        <input type="hidden" name="products[]" class="singleitem" value="<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <?php
                  $sid = $info2['id'];
                  $warehouse_id = mysqli_get_var("SELECT id FROM inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse");
                  $product_qta = get_available_quantity($sid, $warehouse_id);
                  echo number_format($product_qta);
                  ?>
                    </td>
                    <td>
                        <input type="hidden" id="u<?php echo $info2['id'];?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input type="number" step="0.0001"
                            <?php if($info2000['multiple_batch']==1) { echo "value='1'  ";  } ?>
                            class="searchqty <?php if($info1000['no_salespacking']==1) echo ' change5';  ?> packing income_count totalorder "
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" size="7" min="1" required
                            value="<?php echo ($info2000['multiple_batch']); ?>" />

                    </td>
                    <td
                        <?php if($info1000['no_salespacking']==1   || $info2000['pcs_hide']==1) echo ' style="display:none;"';  ?>>
                        <input type="text" value="0" class="change5 change income_count totalorder" tabindex="1"
                            id="pcs<?php echo $info2['id'];?>" size="4" min="1" />
                    </td>
                    <td <?php if($info2000['en_customfield1']==0) echo ' style="display:none;"';  ?>><input
                            name="custom_field1[]" id="customfield<?php echo $info2['id'];?>" type="text" tabindex="1"
                            class="form-control  <?php if($info3000['ctn_customfieldrate']==0) { ?>income_count<?php } ?>  customfield1" /> </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' tabindex='1'  class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>
                    <?php if($info1000['en_inventorybatch']==1  && $gdn==1) { ?>
                    <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1'  class='teacher reportselect inventory3 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
 $batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>
                    <?php if($info2000['multiple_batch']==1) { ?>
                    <td>
                        <?php if($st==1) {
       $pid =  $info2['id']; 
       $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'   && type_component=0 ") or die(mysqli_error($conn));
       $ii=0;
        // if($info2['is_batch'] != 1)
        //   $class="hide";
        echo "<select name='multi_batch[]' tabindex='1'  class='teacher reportselect $class'    required  >";
         while($info4 = mysqli_fetch_array( $data4 )) 
         { 
              // $in = mysqli_get_var("Select SUM(qty) from warehouse_transaction w, warehouse_transaction_type t where item_id='$pid' && w.deleted=0  && w.tran_type=t.id && t.type=1 && w.batch_no='".$info4['id']."' ");
              $out = mysqli_get_var("Select SUM(qty) from warehouse_transaction w, warehouse_transaction_type t where item_id='$pid' && w.deleted=0  && w.tran_type=3 && t.type=0 && w.batch_no='".$info4['id']."' ");
              $bbance =$out; // $in - 
              if($bbance==0) continue;
           echo "<option value='".$info4['id']."' >".$info4['batch_code']." (".$bbance.") </option>";
        }
        echo "</select>";
       }else { ?>
                        <input type="text" name="multi_batch[]" value="-" readonly="readonly" />
                        <?php } ?>
                    </td>
                    <?php } ?>
                    <?php if($info1000['en_embroidery']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from stitching_area") or die(mysqli_error($conn)); 
echo "<select name='products_sarea[]' class='teacher change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><input type="text" name="products_scolor[]" class="form-control" /> </td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from stitching_type") or die(mysqli_error($conn)); 
echo "<select name='products_stype[]' class='teacher change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from stitching_fusion") or die(mysqli_error($conn)); 
echo "<select name='products_sfusion[]' class='teacher  change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($info4['id']==$cwarehouse)
{
   echo "<option value='".$info4['id']."' selected='selected' >".$info4['name']."</option>"; 
}
else { 
echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
}
echo "</select>";
?></td>
                    <?php } ?>

                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input type="text"
                            name="products_packing[]" size="4" value="<?php echo $info2['packing'];?>"
                            class="new_packing edit-input change income_count totalorder" tabindex="1"
                            id="p<?php echo $info2['id'];?>" />
                    </td>
                    <td>
                        <?php
      if($info3000['en_snd_purchase']==1)
  {
    $data15 = mysqli_query($conn,"SELECT distributor_type from distributor where  id='$dist_id' ") or die(mysqli_error($conn));
    // echo "SELECT distributor_type from distributor where  id='$dist_id' ";
    $info15 = mysqli_fetch_array( $data15 ); 
     $ttid=$info15['distributor_type'];
  }
  else
  {
      $data15 = mysqli_query($conn,"SELECT customer_type, customer_type2 from customer where  id='$cid' ") or die(mysqli_error($conn));   
      $info15 = mysqli_fetch_array( $data15 ); 
      $ttid=$info15['customer_type'];
    $ttid2=$info15['customer_type2'];
  }
  $ppid=$info2['id'];
$new_rate = 0;
//multipricingratecheck
if($userdefault_price=='0'){
  $sale_multiprice = $infomultiprice1000['sale_price'];
 ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" required min="0" 
                            value="<?php echo  $infomultiprice1000['sale_price'];?>"
                            class=" edit-input <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> new_rate income_count chk8ange totalorder"
                            size="4" />
                        <?php
}else{
 $data15 = mysqli_query($conn,"SELECT price, mrp_price, foc from customer_type_pricing where pid='$ttid' AND tid='$ppid' && company_id = '$current_company' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
  $new_rate = $info15['price'];
  $P_foc = $info15['foc'];
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $info15['price']; $mpp = $info15['mrp_price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  new_rate income_count chk8ange totalorder"
                            size="4" />
                        <?php  } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100; 
$discount4=$info200['discount4']/100;
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3;  
$discount4=1-$discount4;
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info200['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x;
$new_rate = $price;
    ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $price;?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } else {  
$new_rate = $info2['sale_price'];
?>
                        <!-- here is the rate of previous sale order -->
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $info2['tp'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?> new_rate income_count chk8ange totalorder"
                            size="4" />
                        <?php }
?>
                        <input name="mrp_price[]" size="4" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "mrp".$info2['id'];?>" tabindex="1"
                            value="<?php if($mpp!='') { echo $mpp;  } else { echo $info2['mrp_price']; } $mpp=''; ?>" />
                        <input name="tax_mrp[]" size="4" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "mrptax".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['tax_mrp'];?>" />
                        <!-- <input name="new_rate[]" size="4"   type="hidden" class="new_rate" value="<?php echo $new_rate;?>"  /> -->
                    </td>
                    <?php }//closepricing ?>
                    <?php if($info2000['en_sarhad'] == 1 || $info4000['itemmulti_unit']==1){ ?>
                    <input name="prd_hidden[]" type="hidden" class="prd_hidden" value="<?php echo $info2['id'];?>" />
                    <input name="packing_hidden[]" type="hidden" class="packing_hidden"
                        value="<?php echo $info2['packing'];?>" />
                    <td>
                        <?php 
              $single_unit = mysqli_get_var("SELECT unit FROM inventory WHERE id='".$info2['id']."' ");
              $data4 = mysqli_query($conn,"SELECT * FROM product_unit WHERE id IN (SELECT unit FROM multiple_product_unit WHERE pid = '".$info2['id']."' ) OR product_unit.`id` = '".$single_unit."' ") or die(mysqli_error($conn)); 
              echo "<select name='munit[]'  required class=' munit form-control'   >";
              //echo "<option value='0' >Select Product Unit</option>";
              while($info4 = mysqli_fetch_array( $data4 )){ 
                $selected = '';
                if($single_unit == $info4['id'])
                  $selected = 'selected';
                echo "<option value='".$info4['id']."' $selected >".$info4['name']."</option>";
              }
              echo "</select>";
              ?></td>
                    <td style="display:none;"><input name="con_rate[]" value="1" size="4" class="con_rate" id="" /></td>
                    <?php } ?>
                    <td <?php  if($info2000['en_ricetrade']==0) { echo ' style=" display:none;"'; } ?>><input
                            name="packing2[]" type="number" step="0.0001" class='teacher packing2 income_count'
                            value="<?php echo $info2['pac2']; ?>" id="<?php echo "packk".$info2['id'];?>" /> </td>
                    <td <?php  if($info2000['invoice_cartonrate']==0) { echo ' style=" display:none;"'; } ?>>
                        <select name='rate_in_carton[]' class='teacher income_count case2qty'
                            id="<?php echo "ric".$info2['id'];?>">
                            <option value='0'>Default</option>
                            <?php if($info4000['en_engineering']==0){ ?>
                            <option value='1'><?php echo $info1000['packing_label']; ?></option>
                            <?php } ?>
                            <option value='2'><?php echo $info1000['multi_unit_label']; ?></option>
                            <option value='3'><?php echo $info2000['customfield1_display'];  ?></option>
                        </select>
                    </td>
                    <?php
                        /***----start saqib---------*/
                        if($info1000['salesman_mode']==1){
                          if($info1000['customer_discount1']==1){
                           if($infomultiprice1000['disc1_value']>0){ 
                            ?>
                    <td>
                        <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id']?>" tabindex="1"
                            value="<?php  echo $infomultiprice1000['disc1_value']; ?>" size="4" />
                    </td>
                    <?php  }else{ ?>
                    <td>
                        <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    </td>
                    <?php
                        }
                        }else{
                        ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php
                        }
                        //closedist1_sales
                        if($info1000['customer_discount2']==1){
                          if($infomultiprice1000['disc2_value']>0){ 
                           ?>
                    <td>
                        <input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php  echo $infomultiprice1000['disc2_value']; ?>" size="4" />
                    </td>
                    <?php  }else{ ?>
                    <td>
                        <input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    </td>
                    <?php
                        }
                        }else{ ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php
                        }//closedist2_sales
                        if($info1000['customer_discount3']==1){
                          if($infomultiprice1000['disc3_value']>0){ 
                           ?>
                    <td>
                        <input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php  echo $infomultiprice1000['disc3_value']; ?>" size="4" />
                    </td>
                    <?php  }else{ ?>
                    <td>
                        <input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    </td>
                    <?php
                        }
                        }
                        else{ ?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php
                        }//closedist3_sales
                        if($info1000['customer_scheme']==1) { 
                          if($infomultiprice1000['scheme']>0){ 
                           ?>
                    <td>
                        <input name="products_scheme[]" type="text" class="edit-input income_count totalorder scheme_o"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1"
                            value="<?php  echo $infomultiprice1000['scheme']; ?>" size="4" />
                    </td>
                    <?php  }else{ ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder scheme_o"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php
                        }
                        }
                        else{ ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder scheme_o"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php
                         }
                         //closescheme_sales
                        ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <input name="products_scheme_qty[]" type="hidden"
                            class="edit-input income_count totalorder scheme_valcal"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="" size="4" />
                        <input name="products_pcs[]" type="number" step="0.0001"
                            <?php if($info1000['inventory_limit']==1 && ($info1000['gdninventory_limit']==0 || $gdn==1)) { if($info1000['en_inventorybatch']==1) { echo 'max="'.$maxx.'"'; } else { echo 'max="'.$info2['qty'].'"'; } } ?>
                            class="total_pcs" id="<?php echo "t".$info2['id'];?>" min="0" size="4" />
                    </td>
                    <?php  /*closeschemeqty_sales */   ?>
                    <?php if($info1000['customer_tax1']==1) { 
                        $tax1_value = $infomultiprice1000['tax1_value'];
                        $tax1_value1 = ($customer_filer=='1')?$tax1filer_value:$tax1_value;
                          if($infomultiprice1000['tax1_value']>0){ 
                           ?>
                    <td>
                        <input name="products_tax[]" type="number" class="edit-input income_count"
                            id="<?php echo "pppp".$info2['id'];?>" tabindex="1" value="<?php  echo $tax1_value1; ?>"
                            size="4" readonly="readonly" />
                    </td>
                    <?php  }else{ ?>
                    <td>
                        <input name="products_tax[]" type="number" class="edit-input income_count"
                            id="<?php echo "pppp".$info2['id'];?>" tabindex="1" value="0" size="4"
                            readonly="readonly" />
                    </td>
                    <?php
                        }}else{ ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count"
                        id="<?php echo "pppp".$info2['id'];?>" tabindex="1" value="0" size="4" readonly="readonly" />
                    <?php
                           }
                        /*closetax1_sales */   ?>
                    <?php if($info1000['customer_tax2']==1) { 
                        $tax2_value = $infomultiprice1000['tax2_value'];
                        $tax2_value2 = ((isset($num_rows_ctp) && $num_rows_ctp!=0) ? $tax2_value : (($customer_filer=='1')?$tax2filer_value:$tax2_value));
                        if($infomultiprice1000['tax2_value']>0){ 
                         ?>
                    <td>
                        <input name="products_tax2[]" type="text" class="edit-input income_count"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="<?php  echo $tax2_value2; ?>"
                            size="4" readonly="readonly" />
                    </td>
                    <?php  }else{ ?>
                    <td>
                        <input name="products_tax2[]" type="text" class="edit-input income_count"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="<?php  echo '0'; ?>" size="4"
                            readonly="readonly" />
                    </td>
                    <?php
                        }
                        }else{ ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="<?php  echo '0'; ?>" size="4"
                        readonly="readonly" />
                    <?php
                             }
                        /*closetax2_sales */   ?>
                    <?php if($info1000['customer_tax3']==1) { 
                        $tax3_value = $infomultiprice1000['tax3_value'];
                        $tax3_value3 = ((isset($num_rows_ctp) && $num_rows_ctp!=0) ? $tax3_value : (($customer_filer=='1')?$tax3filer_value:$tax3_value));
                        if($infomultiprice1000['tax3_value']>0){ 
                         ?>
                    <td>
                        <input name="products_tax3[]" type="text" class="edit-input income_count"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="<?php  echo $tax3_value3; ?>"
                            size="4" readonly="readonly" />
                    </td>
                    <?php  }else{ ?>
                    <td>
                        <input name="products_tax3[]" type="text" class="edit-input income_count"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="<?php  echo '0'; ?>" size="4"
                            readonly="readonly" />
                    </td>
                    <?php
                        }
                        }else{ ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="<?php  echo '0'; ?>" size="4"
                        readonly="readonly" />
                    <?php
                               }
                        /*closetax3_sales */   ?>
                    <?php
                        }//close salesmode
else{  ?>
                    <?php if($info1000['customer_discount1']==1) { 
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from cb_discount where cid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from customer_type_discount1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($info3000['en_elixirbeauty']) {
    $bid=$info2['brand_id'];
    $binv_discount = mysqli_get_var("Select binv_discount from customer_brandlimit WHERE customer_id='$cid' && brand_id='$bid' "); 
?>
                    <td> <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $binv_discount;?>"
                            size="4" /> </td>
                    <?php 
}
else if($num_rows!=0 && $info15['discount']!=-1) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                            size="4" /></td>
                    <?php }
else if($info2['direct_invoicediscount1']!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount[]"
                            type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['direct_invoicediscount1'];?>" size="4" /></td>
                    <?php 
}
else if($num_rows2!=0) {
?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info17['discount'];?>"
                            size="4" /></td>
                    <?php }
 else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <td>
                        <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount'];?>" size="4" />
                    </td>
                    <?php } else {  ?>
                    <td><input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                            id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php }  } else { ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$disc22 = $info15['discount'];
if($info4000['alternate_customertype']==1 )   {
   $disc22 = mysqli_get_var("SELECT discount from customer_type_discount2 where pid='$ttid2' AND tid='$ppid' "); 
   if($disc22=='' || $disc22=='-1' ) $disc22=0;
  ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="<?php echo $disc22;?>"
                            size="4" /></td>
                    <?php }
 else  if($num_rows!=0 && $info15['discount']!=-1) {
?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } 
else if($info2['direct_invoicediscount2']!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount2[]"
                            type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['direct_invoicediscount2'];?>" size="4" /></td>
                    <?php 
}
 else if($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } 
 if($info1000['customer_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount4 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
  if($num_rows!=0 && $info15['discount']!=-1) {
?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } if($info2['direct_invoicediscount4']!=-1) {
?>
                    <td <?php if($gdn==1) echo ' style="display:none;"';  ?>><input name="products_discount4[]"
                            type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['direct_invoicediscount4'];?>" size="4" /></td>
                    <?php 
} elseif($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }

    $foc_scheme_edit = mysqli_get_var("SELECT discount_percentage FROM amount_discount WHERE min_amount='".$info2['id']."'");
    $foc_value_edit = mysqli_get_var("SELECT discount_value FROM amount_discount WHERE min_amount='".$info2['id']."'");
    if($foc_scheme_edit=="") { $foc_scheme_edit = 0; }
    if($foc_value_edit=="") { $foc_value_edit = 0; }

                    if($P_foc!=0 && $P_foc!='') { ?>
                        <td>
                        <input type="number" name="products_foc[]" value="<?php echo $P_foc ?>"  class="foc income_count" id="<?php echo "pfoc".$info2['id'];?>"  required size="4"   />
                        <input type="hidden" class="foc_scheme" id="<?php echo "pfoc_scheme".$info2['id'];?>" value="<?php echo $foc_scheme_edit; ?>" />
                        <input type="hidden" class="foc_value" id="<?php echo "pfoc_value".$info2['id'];?>" value="<?php echo $foc_value_edit; ?>" />
                        </td>
                    <?php }else if($info2000['customer_foc']==1) { ?>
                    <td><input type="text" name="products_foc[]" value="0" class="foc income_count"
                            id="<?php echo "pfoc".$info2['id'];?>" required size="4" />
                        <input type="hidden" class="foc_scheme" id="<?php echo "pfoc_scheme".$info2['id'];?>" value="<?php echo $foc_scheme_edit; ?>" />
                        <input type="hidden" class="foc_value" id="<?php echo "pfoc_value".$info2['id'];?>" value="<?php echo $foc_value_edit; ?>" />
                        </td>
                    <?php } else { 
                    ?>
                    <input type="hidden" name="products_foc[]" value="0" class="foc income_count"
                        id="<?php echo "pfoc".$info2['id'];?>" required size="4" />
                    <input type="hidden" class="foc_scheme" id="<?php echo "pfoc_scheme".$info2['id'];?>" value="<?php echo $foc_scheme_edit; ?>" />
                    <input type="hidden" class="foc_value" id="<?php echo "pfoc_value".$info2['id'];?>" value="<?php echo $foc_value_edit; ?>" />
                    <?php }
  if($info1000['customer_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='') {?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount3'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount3[]" step="0.0001" type="number" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else {?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
if($info2000['en_discount5']==1) { ?>
                    <td><input type="text" name="discount5[]" class="edit-input income_count"
                            id="<?php echo "pppl".$info2['id'];?>" tabindex="1" value="0" required size="4" /> </td>
                    <?php } 
 if($info1000['customer_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from customer_type_scheme where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                            size="4" /></td>
                    <?php }  else {  ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                        <input name="products_pcs[]" type="text" class="total_pcs"
                            id="<?php echo "t".$info2['id'];?>" min="0" size="4" />
                    </td>
                    <?php if($info1000['customer_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax1 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($info2000['en_maintax']==1) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($st==1) {  if($cfiler==1) { echo $info2000['filer_tax']; } else { echo $info2000['nonfiler_tax']; }  } else { echo 0; } ?>"
                            size="4" readonly="readonly" /></td>
                    <?php }
else if($num_rows!=0) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td> <input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } } else { ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" />
                    <?php } ?>
                    <td <?php if($info2000['invoice_cartonrate']==0) { echo ' style=" display:none;" '; } ?>><input
                            name="pipe[]" type="text" class="edit-input pipehide income_count" tabindex="1"
                            id="<?php echo "pipe".$info2['id'];?>" value="<?php  echo 0; ?>" size="4"
                            readonly="readonly" /></td>
                    <?php if($info1000['customer_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax2 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied2']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax3 where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } 
else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <?php }//close main
          ?>
                    (
                    <td class="<?php echo ( $info2000['en_freshmate'] == 1) ? '': 'hidden'?>"><input type="date"
                            name="expiry_date[]" value="<?php $info2['expiry_date'];?>"
                            <?php echo ($info2000['en_freshmate'] == 1) ? 'required':''?> /></td>
                    <td class="<?php echo  ($info2000['en_freshmate'] == 1) ? '': 'hidden'?>">
                        <?php
    $data16 = mysqli_query($conn,"SELECT * FROM return_reason ORDER BY name") or die(mysqli_error($conn));
    $required = ($info2000['en_freshmate'] == 1) ? 'required':'';
    echo "<select name='reason[]' ".$required." > 
    <option value='' selected >Select Reason..</option> ";
    while($info16 = mysqli_fetch_array( $data16 )){
        echo "<option value='".$info16['id']."' >".$info16['name']."</option>";
    }
    echo "</select>";
?>
                    </td>
                    <td><input type="hidden" name="products_cogs[]" value="<?php
      if($info1000['en_inventorybatch']==1) { echo $unitc; } else {  echo $info2['unit_cost']; } ?>"
                            class="prd_cogs" />
                        <input name="products_total[]" step="0.0001"  type="number" id="newtotal<?php echo $info2['id'];?>" 
                            class="form-control tot<?php echo $info2['id'];?> ptotal sub_total income_count readonly " size="5" min="0"
                            tabindex="-1" onkeypress="return false;" />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php if($info1000['open_ratecolumn']==1 && $gdn==0) { ?>
                $('.change15').focusout(function() {
                            $(".change15").removeClass("change15");
                            <?php }  else if($info1000['en_inventorybatch']==1 && $gdn==1) {  ?>
                            $('.change7').focusout(function() {
                                        $(".change7").removeClass("change7");
                                        <?php } else if($info1000['en_warehouse']==1) {  ?>
                                        $('.change6').focusout(function() {
                                            $(".change6").removeClass("change6");
                                            <?php } else {  ?>
                                            $('.change5').focusout(function() {
                                                $(".change5").removeClass("change5");
                                                <?php }  ?>
                                                var $orginal = $(this).closest("tr");
                                                var $cloned = $orginal.clone();
                                                //get original selects into a jq object
                                                var $originalSelects = $orginal.find('select');
                                                $cloned.find('select').each(function(index, item) {
                                                    //set new select to value of old select
                                                    $(item).val($originalSelects.eq(index)
                                                        .val());
                                                });
                                                //get original textareas into a jq object
                                                var $originalTextareas = $orginal.find('textarea');
                                                $cloned.find('textarea').each(function(index, item) {
                                                    //set new textareas to value of old textareas
                                                    $(item).val($originalTextareas.eq(index)
                                                        .val());
                                                });
                                                $cloned.appendTo("#acart");
                                                $('.change5').attr('class',
                                                    " change income_count totalorder packing");
                                                $("#searchbox").focus();
                                                $("#psearch").html('');
                                                var n10 = $("#totpc").val();
                                                n10 = parseInt(n10) + parseInt(1);
                                                $("#totpc").val(n10);
                                                var n11 = $("#totpc").val();
                                                $(".sno:last").val(n11);
                                            });
                                        });
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    <?php if($info1000['inventory_limit']==1) { if($info1000['en_inventorybatch']==1) { 
?>
    $(".inventory3").on('change', function() {
        var vid = $(this).val();
        var self = $(this);
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query.php",
            data: {
                batch6: vid
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                tt = html.replace(/\s/g, "");
                $(self).closest('tr').find('.prd_cogs').attr("value", tt);
            }
        });
    });
    <?php }} ?>
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $(".delete").on('click', function() {
        var shoppingcart = $(this).closest('tr').find('.singleitem').val();
        $.ajax({
            type: "POST",
            url: "../ajax/receipt-query2.php",
            data: {
                cartclear: shoppingcart
            },
            cache: false,
            dataType: 'html',
            success: function(html) {
                $(".shopping_cart").html(html);
            }
        });
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        var sum30 = 0;
        $(".foc").each(function() {
            sum30 += parseFloat($(this).val()) || 0;
        });
        var sum30c = sum3 + sum30;
        $("#packing").val(sum30c);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        var decimal_point = "<?php echo $info2000['total_decimal']; ?>";
        sum2 = sum2.toFixed(decimal_point);
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass != 'brokery_rs' && specialclass != 'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        var decimal_point = "<?php echo $info2000['total_decimal']; ?>";
        result = result.toFixed(decimal_point);
        //result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        result2 = result2.toFixed(decimal_point);
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  } 
       }
else if(isset($_POST['sid5c']))
{
$sid=test_input($_POST['sid5c']);
$cid=test_input($_POST['customerid']);
$st=test_input($_POST['st']);
$gdn=test_input($_POST['gdn']);
if($gdn=='') $gdn = 0;
?>
    <div class="table-responsive table-card mt-4">
        <table class="table table-striped table-hover align-middle dt-responsive nowrap display w-100" id="dynamic-table">
            <thead>
                <tr>
                    <th width="2%">S.No </th>
                    <th width="25%"><?php echo $info1000['material_label']; ?></th>
                    <th <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>>
                        <div>QTA</div>
                    </th>
                    <th>
                        <div><?php echo $info1000['multi_unit_label']; ?></div>
                    </th>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['single_unit_label']; ?></div>
                    </th>
                    <?php if($info1000['en_warehouse']==1) {  echo  '  <th ><div>WH </div></th> '; } ?>
                    <?php if($info1000['en_rawmaterialbatch']==1  && $gdn==1) {   echo  '  <th ><div>'.$info1000['batch_label'].' </div></th> '; } ?>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['packing_label']; ?></div>
                    </th>
                    <th>
                        <div><?php echo $info1000['price_label']; ?></div>
                    </th>
                   <th <?php if($info4000['separate_mrpcolumn']==0) echo ' style="display:none;"';  ?>
                        class="recurringhide">
                        <div><?php echo $info4000['mrp_label']; ?></div>
                    </th> 
                    <?php if($info1000['customer_discount1']==1) {  echo  '  <th ><div>'.$info1000['disc1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount2']==1) {  echo  '  <th ><div>'.$info1000['disc2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount4']==1) {  echo  '  <th ><div>'.$info1000['disc4_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_discount3']==1) {  echo  '  <th ><div>'.$info1000['toffer_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_scheme']==1) {  echo  '  <th ><div>'.$info1000['scheme_label'].'</div></th> '; } ?>
                    <th <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <div><?php echo $info1000['total_unit_label']; ?></div>
                    </th>
                    <th <?php if(1==1) echo ' style="display:none;"';  ?> ><div><?php echo $info1000['total_unit_label']; ?></div></th>
       <?php if($info4000['display_taxamount']==1){   ?>    
            <th>Exclusive of GST Amount</th>    
            <?php } ?> 
                    <?php if($info1000['customer_tax1']==1) {  echo  '  <th ><div>'.$info1000['tax1_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax2']==1) {  echo  '  <th ><div>'.$info1000['tax2_label'].'</div></th> '; } ?>
                    <?php if($info1000['customer_tax3']==1) {  echo  '  <th ><div>'.$info1000['tax3_label'].'</div></th> '; } ?>
                    <?php if($info4000['display_taxamount']==1){     ?>    
            <th><?php echo $info4000['taxamount_label']; ?></th>    
            <?php } ?>
                    <th contenteditable="true" width="80">Total </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
   if($info1000['en_deals']==1) { 
    $data2 = mysqli_query($conn,"SELECT * from deal where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr>
                    <td class="sno"></td>
                    <td><input type="hidden" name="deal[]" value="d<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <?php 
   $did=$info2['id'];
   $data15 = mysqli_query($conn,"SELECT *, i.qty/d.qty AS aqty, d.qty AS dqty from component i, deal_details d where d.did='$did' AND d.pid=i.id") or die(mysqli_error($conn));
  $taqty=10000; 
while($info15 = mysqli_fetch_array( $data15 )) 
 { 
 if($info15['aqty']<=$taqty)
 {
 $taqty=$info15['aqty'];
 }
 else {
 $info15['aqty']=ceil($taqty);
 }
 $staqty=$info15['aqty'];
 echo $info15['dqty']." Pcs - ".$info15['name']."<br>";
 }
 ?>
                    </td>
                    <td><?php  if($staqty<$taqty)
        {
        echo ceil($staqty);
        }
        else  {
          $staqty=$taqty;
           echo ceil($staqty);
        }
        ?></td>
                    <td>
                        <input name="d<?php echo $info2['id'];?>" type="text" min="1"
                            class="searchqty income_count form-control" id="d<?php echo $info2['id'];?>"
                            tabindex="1" />
                    </td>
                    <td><input type="text" class="form-control income_count" /> </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='".$info2['id']."_warehouse' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>
                    <td><?php echo $info2['packing'];?></td>
                    <td>
                        <input id="<?php echo "nm".$info2['id'];?>" value="<?php echo $info2['sale_price'];?>"
                            class="income_count" onchange="changealert(this.id)" size="20" />
                    </td>
                    <td><input type="text" class="form-control income_count" value="0" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>" /></td>
                    <td><input type="text" class="form-control income_count" /></td>
                    <td><input type="text" class="form-control income_count" value="0" /></td>
                    <td><input type="hidden" name="d<?php echo $info2['id']."_cogs";?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input name="d<?php echo $info2['id']."_total";?>" type="text"
                            class="d<?php echo $info2['id'];?> ptotal form-control" tabindex="-1" readonly />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /> <?php } ?></td>
                </tr>
                <?php } } ?>
                <?php  if($info1000['en_singleproducts']==1) { 
       $data2 = mysqli_query($conn,"SELECT * from component where id='$sid'") or die(mysqli_error($conn));
while($info2 = mysqli_fetch_array( $data2 )) 
 { ?>
                <tr class="carttr">
                    <td><input type="text" class="sno form-control" />
                        <input type="hidden" id="<?php echo "pptax".$info2['id'];?>" name="taxtype[]"
                            value="<?php echo $info2['is_taxable'];?>" />
                        <?php if($info1000['en_lastprice']==1) {
         $data200 = mysqli_query($conn,"SELECT sd.* from sales_return_details sd, sales_return s  where sd.prd_id='$sid' AND s.type_component=1 AND sd.`return_id`=s.`id`  order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
        }
  else if($info1000['en_lastprice']==2 ) {
     $data200 = mysqli_query($conn,"SELECT sd.* from sales_return_details sd, sales_return s  where sd.prd_id='$sid' AND s.type_component=1 AND sd.`return_id`=s.`id` AND s.customer_id='$cid' order by sd.id DESC Limit 1 ") or die(mysqli_error($conn));
         $info200 = mysqli_fetch_array( $data200 ); 
      }      ?>
                    </td>
                    <td>
                        <input type="hidden" name="products[]" value="<?php echo $info2['id'];?>" />
                        <h5><?php echo $info2['sku'].' '.$info2['name'];?></h5>
                        <div <?php if($info1000['item_description']==0) echo ' style="display:none;"';   ?>>
                            <textarea name="products_description[]" class="form-control"
                                placeholder="Details.."></textarea>
                        </div>
                    </td>
                    <td <?php if($info1000['hide_qavailable']==1) echo ' style="display:none;"';  ?>><?php 
         $sid = $info2['id'];
   $transfer_in = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='1'  && w.type_component=1 $wlimit_warehouse8   ");
             $transfer_out = mysqli_get_var("SELECT SUM(w.qty) as sum FROM warehouse_transaction w, warehouse_transaction_type tt WHERE w.item_id='$sid' && w.tran_type=tt.id && tt.type='0'   && w.type_component=1 $wlimit_warehouse8  ");
           echo  $product_qta = $transfer_in-$transfer_out;
         ?></td>
                    <td>
                        <input type="hidden" id="u<?php echo $info2['id'];?>"
                            value="<?php echo $info2['unit_cost'];?>" />
                        <input type="number" step="0.0001" size="4" min="1"
                            class="searchqty <?php if($info1000['no_salespacking']==1) echo ' change5';  ?> packing income_count totalorder "
                            id="ctn<?php echo $info2['id'];?>" tabindex="1" value="0" required/>
                    </td>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>>
                        <input type="text" size="4" min="1" value="0" class="change5 change income_count totalorder"
                            tabindex="1" id="pcs<?php echo $info2['id'];?>" />
                    </td>
                    <?php if($info1000['en_warehouse']==1) { ?>
                    <td><?php $data4 = mysqli_query($conn,"SELECT * from inventory_warehouse where 1=1 $wlimit_warehouse $climit_warehouse") or die(mysqli_error($conn)); 
echo "<select name='products_warehouse[]' tabindex='1' class='teacher warehouse change6'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>
                    <?php if($info1000['en_rawmaterialbatch']==1  && $gdn==1) { ?>
                    <td><?php $pid =  $info2['id']; $data4 = mysqli_query($conn,"SELECT * from inventory_batch where active=1 && prd_id='$pid'  && type_component=1") or die(mysqli_error($conn)); 
$ii=0;
echo "<select name='products_batch[]' tabindex='1' class='teacher reportselect inventory3 change7' required  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
if($ii==0) { $maxx = $info4['qty']; $unitc = $info4['unit_cost']; }
 $ii=5;
 $batch_code = "";
$batch_code2 = $info4['batch_code'];
if($batch_code2!="") { $batch_code=$batch_code2;} else {
if($info1000['month_code']==1) {  $batch_code= $batch_code.$info1000['invoicecode'];  $batch_code= $batch_code.str_pad($info4['month_id'], 4, '0', STR_PAD_LEFT);  $batch_code= $batch_code.date('-m-y ', strtotime($info4['production_date']));  } else {   $batch_code= $info4['id']; }
}
echo "<option value='".$info4['id']."' >".$info4['batch_code']."</option>";
}
echo "</select>";
?></td>
                    <?php } ?>

                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input type="text"
                            name="products_packing[]" size="4" value="<?php echo $info2['packing'];?>"
                            class="change income_count edit-input totalorder" tabindex="1"
                            id="p<?php echo $info2['id'];?>" />
                    </td>
                    <td>
                        <?php
$data15 = mysqli_query($conn,"SELECT customer_type from customer where  id='$cid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$ttid=$info15['customer_type'];
$ppid=$info2['id'];
 $data15 = mysqli_query($conn,"SELECT price from customer_type_pricingc where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $info15['price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } elseif($info1000['en_lastprice']!=0 && $info200['prd_amount']!='') {
  $discount=$info200['discount']/100; 
$discount2=$info200['discount2']/100; 
$discount4=$info200['discount4']/100;
// $discount3=$info2['dd3']/100; 
$toffer = $info200['discount3']*($info200['qty']-$info200['scheme_qty']);
$tax= $info200['tax_applied']/100;
$tax2= $info200['tax_applied2']/100;
$tax3= $info200['tax_applied3']/100;
$discount=1-$discount;  
$discount2=1-$discount2;  
//$discount3=1-$discount3; 
$discount4=1-$discount4; 
$aaqty = $info200['qty']-$info200['scheme_qty'];
 $sb = $info200['prd_amount'];
 $n = $info200['qty'] * ($tax + $tax2 + $tax3);
$m = $aaqty * $discount * $discount2 * $discount4;
$nm = $n + $m ;
$x = ($info200['prd_amount'] +($toffer*$discount*$discount2*$discount4)  ) / $nm;
$price= $x;
    ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $price;?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php }  else {  ?>
                        <input id="<?php echo "pp".$info2['id'];?>" tabindex="1" name="unitcos[]" type="number" min="0" 
                            value="<?php echo $info2['sale_price'];?>"
                            class="  <?php if($info1000['open_ratecolumn']==1) { echo 'change15';  } else { echo 'edit-input'; } ?>  income_count chk8ange totalorder"
                            size="4" />
                        <?php } ?>
                          

  <input name="tax_mrp[]" size="4" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "mrptax".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info2['tax_mrp'];?>" />
                        <?php
              if($info4000['separate_mrpcolumn']==0)
              {
              ?>
                        <input name="mrp_price[]" size="4" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "mrp".$info2['id'];?>" tabindex="1"
                            value="<?php if($mpp!='' && $mpp!=0) { echo $mpp;  } else { echo $info2['mrp_price']; } $mpp=''; ?>" />
                        <?php
              }
              ?>
                        <!-- <input name="new_rate[]" size="4"   type="hidden" class="new_rate" value="<?php echo $new_rate;?>"  /> -->
                    </td>
                    <?php if($info4000['separate_mrpcolumn']==1) { ?> <td>
                        <input name="mrp_price[]" size="4" type="number" required step='0.0001'
                            class="edit-input income_count totalorder" id="<?php echo "mrp".$info2['id'];?>"
                            tabindex="1"
                            value="<?php if($mpp!='' && $mpp!=0) { echo $mpp;  } else { echo $info2['mrp_price']; } $mpp=''; ?>" />
                    </td>
                    <?php }  //closepricing ?>
                    <?php if($info1000['customer_discount1']==1) { 
 echo '<td >';
$bid=$info2['brand_id'];
 $data15 = mysqli_query($conn,"SELECT discount from cb_discount where cid='$cid' AND bid='$bid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
$data17 = mysqli_query($conn,"SELECT discount from customer_type_discount1c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info17 = mysqli_fetch_array( $data17 ); 
$num_rows2 = mysqli_num_rows($data17);
if($num_rows!=0) {
?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info15['discount'];?>"
                        size="4" />
                    <?php }
else if($num_rows2!=0) {
?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info17['discount'];?>"
                        size="4" />
                    <?php }
 else if($info1000['en_lastprice']==1 && $info2000['discount']!='') { ?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="<?php echo $info200['discount'];?>"
                        size="4" />
                    <?php }
 else {  ?>
                    <input name="products_discount[]" type="number" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } echo '</td>'; } else { ?>
                    <input name="products_discount[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppp".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_discount2']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount2c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount2']!='') { ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount2'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_discount2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppn".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_discount4']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount4c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['discount4']!='') { ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount4'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount4[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_discount4[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppx".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
  if($info1000['customer_discount3']==1) { 
$data15 = mysqli_query($conn,"SELECT discount from customer_type_discount3c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info15['discount'];?>" size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['discount3']!='') {?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['discount3'];?>" size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_discount3[]" type="number" step="0.0001" class="edit-input income_count totalorder products_discount3"
                            id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else {?>
                    <input name="products_discount3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppm".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php }
 if($info1000['customer_scheme']==1) { 
$data15 = mysqli_query($conn,"SELECT scheme from customer_type_schemec where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                    </td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['scheme']!='') { ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="<?php echo $info200['scheme'];?>"
                            size="4" /></td>
                    <?php } else {  ?>
                    <td><input name="products_scheme[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_scheme[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppps".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                    <td <?php if($info1000['no_salespacking']==1) echo ' style="display:none;"';  ?>><input
                            name="products_scheme_qty[]" type="hidden" class="edit-input income_count totalorder"
                            id="<?php echo "pppss".$info2['id'];?>" tabindex="1" value="<?php echo $info15['scheme'];?>"
                            size="4" />
                        <input name="products_pcs[]" type="text" class="total_pcs" id="<?php echo "t".$info2['id'];?>"
                            min="0" size="4" />
                    </td>

<?php if(1==1){   ?>     
     <td  <?php if($info4000['display_taxamount']==0){ echo ' style="display:none;"';    }  ?> >
   <input name="display_totaltax2[]" type="text" class="income_count display_totaltax2" id="<?php echo "ppptttt".$info2['id'];?>"    value="0" size="4" readonly/>
</td>
<?php } ?>


                    <?php if($info1000['customer_tax1']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax1c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php } elseif($info1000['en_lastprice']==1 && $info2000['tax_applied']!='') { ?>
                    <td> <input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1) { echo $info2000['tax_applied']; } else { echo 0;}?>"
                            size="4" readonly="readonly" /></td>
                    <?php } else {  ?>
                    <td><input name="products_tax[]" type="number" class="edit-input income_count" tabindex="1"
                            id="<?php echo "pppp".$info2['id'];?>"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                            readonly="readonly" /></td>
                    <?php } } else { ?>
                    <input name="products_tax[]" type="hidden" class="edit-input income_count" tabindex="1"
                        id="<?php echo "pppp".$info2['id'];?>"
                        value="<?php if($info1000['en_tax']==1 && $st==1) { echo 0; } else { echo 0;}?>" size="4"
                        readonly="readonly" />
                    <?php } if($info1000['customer_tax2']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax2c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['tax_applied2']!='') { ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied2']; ?>" size="4" /></td>
                    <?php }
 else {  ?>
                    <td><input name="products_tax2[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } } else { ?>
                    <input name="products_tax2[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "ppptt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } if($info1000['customer_tax3']==1) { 
$data15 = mysqli_query($conn,"SELECT tax from customer_type_tax3c where pid='$ttid' AND tid='$ppid' ") or die(mysqli_error($conn));
$info15 = mysqli_fetch_array( $data15 ); 
$num_rows = mysqli_num_rows($data15);
if($num_rows!=0) {
?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php if($info1000['en_tax']==1 && $st==1) { echo $info15['tax']; } else { echo 0;}?>"
                            size="4" /></td>
                    <?php } else if($info1000['en_lastprice']==1 && $info2000['tax_applied3']!='') { ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1"
                            value="<?php echo $info200['tax_applied3']; ?>" size="4" /></td>
                    <?php }  else {  ?>
                    <td><input name="products_tax3[]" type="text" class="edit-input income_count totalorder"
                            id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" /></td>
                    <?php } }  else { ?>
                    <input name="products_tax3[]" type="hidden" class="edit-input income_count totalorder"
                        id="<?php echo "pppttt".$info2['id'];?>" tabindex="1" value="0" size="4" />
                    <?php } ?>
                 <?php if(1==1){   ?>     
     <td  <?php if($info4000['display_taxamount']==0){ echo ' style="display:none;"';    }  ?> >
   <input name="display_totaltax[]" type="text" class="income_count display_totaltax" id="<?php echo "ppptt".$info2['id'];?>"    value="0" size="4" readonly/>
</td>
<?php } ?>   
                    <td><input type="hidden" name="products_cogs[]" value="<?php echo $info2['unit_cost'];?>" />
                        <input name="products_total[]" id="newtotal<?php echo $info2['id'];?>" size="5" min="0" type="number" step="0.0001"
                            class="form-control tot<?php echo $info2['id'];?> ptotal sub_total income_count readonly " tabindex="-1"
                            onkeypress="return false;" />
                    </td>
                    <td><?php if(1==1) { ?><input type="button" class="edit receipt_edit_hide5" value="Edit" /><input
                            type="button" class="save" value="Save" /><?php } ?><?php if(1==1) { ?><input type="button"
                            class="delete receipt_delete_edit5" value="Delete" /><?php } ?></td>
                </tr>
                <?php } } ?>
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
                <?php if($info1000['open_ratecolumn']==1  && $gdn==0) { ?>
                $('.change15').focusout(function() {
                            $(".change15").removeClass("change15");
                            <?php } else if($info1000['en_rawmaterialbatch']==1 && $gdn==1) {  ?>
                            $('.change7').focusout(function() {
                                        $(".change7").removeClass("change7");
                                        <?php } else if($info1000['en_warehouse']==1) {  ?>
                                        $('.change6').focusout(function() {
                                            $(".change6").removeClass("change6");
                                            <?php } else {  ?>
                                            $('.change5').focusout(function() {
                                                $(".change5").removeClass("change5");
                                                <?php }  ?>
                                                var $orginal = $(this).closest("tr");
                                                var $cloned = $orginal.clone();
                                                //get original selects into a jq object
                                                var $originalSelects = $orginal.find('select');
                                                $cloned.find('select').each(function(index, item) {
                                                    //set new select to value of old select
                                                    $(item).val($originalSelects.eq(index)
                                                        .val());
                                                });
                                                //get original textareas into a jq object
                                                var $originalTextareas = $orginal.find('textarea');
                                                $cloned.find('textarea').each(function(index, item) {
                                                    //set new textareas to value of old textareas
                                                    $(item).val($originalTextareas.eq(index)
                                                        .val());
                                                });
                                                $cloned.appendTo("#acart");
                                                $('.change5').attr('class',
                                                    " change income_count totalorder packing");
                                                $("#searchbox").focus();
                                                $("#psearch").html('');
                                                var n10 = $("#totpc").val();
                                                n10 = parseInt(n10) + parseInt(1);
                                                $("#totpc").val(n10);
                                                var n11 = $("#totpc").val();
                                                $(".sno:last").val(n11);
                                            });
                                        });
    </script>
    <script type="text/javascript">
    $('.save').hide();
    $('.edit-input').attr("readonly", true);
    $(".edit").on('click', function() {
        $(this).closest('tr').find('.edit').hide();
        $(this).closest('tr').find('.save').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", false);
    });
    $(".save").on('click', function() {
        $(this).closest('tr').find('.save').hide();
        $(this).closest('tr').find('.edit').show();
        $(this).closest('tr').find('.edit-input').attr("readonly", true);
    });
    $(".delete").on('click', function() {
        $(this).closest('tr').remove();
        $("input[class='sno']").each(function(ind) {
            $(this).val(ind + 1);
        });
        //Total Quantity Sum  (Pcs)
        var sum = 0;
        $(".total_pcs").each(function() {
            sum += parseFloat($(this).val()) || 0;
        });
        $("#total_pcs").val(sum);
        //Total Quantity Sum  (Carton)
        var sum3 = 0;
        $(".packing").each(function() {
            sum3 += parseFloat($(this).val()) || 0;
        });
        $("#packing").val(sum3);
        //Total Amount Sum  (Sub Total)
        var sum2 = 0;
        $(".sub_total").each(function() {
            sum2 += parseFloat($(this).val()) || 0;
        });
        $("#sub_total").val(sum2);
        var n4 = $("#sub_total").val();
        var n5 = $("#shipping").val();
        var n6 = $("#discount").val();
        var n7 = $("#tax").val();
        var result = +n4;
        <?php if ( $info1000['en_discount']==1) { ?>
        n6 = (+n6 * 1) / 100;
        n6 = (n6 * 1) * result;
        result = +result - n6;
        <?php } ?>
        <?php if($info2000['rice_discount']==1) { ?>
        $(".drice").each(function() {
            var damount = $(this).find('.rice_discount_value').val();
            var dless = $(this).find('.rice_type').val();
            var dpercent = $(this).find('.rice_percent').val();
            var specialclass = $(this).find('.specialclass').val();
            var specialclass2 = $(this).find('.specialclass2').val();
            var pack22 = $('#packing').val();
            var broker_id = $('#broker_id').val();
            var customfield1 = $('.customfield1').val();
            var sub_total = $('.sub_total').val();
            if (broker_id != '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass != 'brokery_rs' && specialclass != 'brokery_percentage') {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            } else if (broker_id == '0') {
                if (specialclass == 'noimpact' || specialclass == 'trade_no_impact') {} else if (
                    specialclass == 'brokery_rs') {
                    damount = damount * customfield1;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else if (specialclass == 'brokery_percentage') {
                    damount = (damount / 100) * sub_total;
                    if (dless == 1) {
                        result = +result - +damount;
                    } else if (dless == 0) {
                        result = +result + +damount;
                    }
                } else {
                    if (dless == 1) {
                        if (dpercent == 1) {
                            damount = (+100 - +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result - +damount;
                        }
                    } else if (dless == 0) {
                        if (dpercent == 1) {
                            damount = (+100 + +damount) / 100;
                            result = +result * damount;
                        } else {
                            result = +result + +damount;
                        }
                    }
                }
            }
        });
        <?php } ?>
        <?php if ($info1000['en_tax']==1) { ?>
        var percent = (result * 1) / 100;
        percent = (percent * 1) * n7;
        result = +result + +percent;
        <?php } ?>
        <?php if ($info1000['en_shipping']==1) { ?>
        var result = +result + +n5;
        <?php } ?>
        result = Math.round(result);
        $("#total").val(result);
        var n7 = $("#total").val();
        var n8 = $("#amount_received").val();
        var result2 = +n7 - n8;
        $("#pending_amount").val(result2);
        $(".total-display").val(n7);
        var n10 = $("#totpc").val();
        n10 = parseInt(n10) - parseInt(1);
        $("#totpc").val(n10);
        var n13 = 0;
        /* $(".sno").each(function(){
    n13 += + parseInt(n13) + parseInt(1);
    $(".sno").val(n13);
    });
  */
    });
    </script>
    <?php  include('../functions/incomecount_function.php'); ?>
    <script type="text/javascript">
    $('input').keyup(function(e) {
        if (e.which == 39)
            $(this).closest('td').next().find('input').focus();
        else if (e.which == 37)
            $(this).closest('td').prev().find('input').focus();
        else if (e.which == 40)
            $(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
        else if (e.which == 38)
            $(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input')
            .focus();
    });
    </script>
    <?php
  } 
else if(isset($_POST['get_conversion_rate'])){
  $unit = $_POST['get_conversion_rate'];
  $prd_id = $_POST['prd_id'];
  $b = mysqli_get_var("SELECT rate FROM multiple_product_unit WHERE unit='$unit' && pid='$prd_id' ");
  if($b=='') $b = mysqli_get_var("SELECT packing FROM inventory WHERE id='$prd_id' "); 
  $array['a'] = $b;
  echo json_encode($array);
  exit;
}
else if(isset($_POST['get_conversion_rate2'])){
  $unit = $_POST['get_conversion_rate2'];
  $prd_id = $_POST['prd_id'];
  $b = mysqli_get_var("SELECT rate FROM multiple_product_unitc WHERE unit='$unit' && pid='$prd_id' ");
  if($b=='') $b = mysqli_get_var("SELECT packing FROM component WHERE id='$prd_id' "); 
  $array['a'] = $b;
  echo json_encode($array);
  exit;
}
else if(isset($_POST['inner122']))
{
$inner122=test_input($_POST['inner122']);
$oldc=test_input($_POST['old']);
$tabaar = "0";
if($inner122==1)
{
$coll = "overall_look"; 
$tabaar = "0";
}
else if($inner122==2)
{
$coll = "broken_b2";  
$tabaar = "broken";
  }
else if($inner122==3)
{
$coll = "broken_b2";  
$tabaar = "broken";
  }
else if($inner122==4)
{
$coll = "broken_b3";
$tabaar = "0";
  } 
else if($inner122==5)
{
$coll = "damage"; 
$tabaar = "damage";
  }
else if($inner122==6)
{
$coll = "damage2";  
$tabaar = "damage";
  }
else if($inner122==7)
{
$coll = "arv_moisture"; 
$tabaar = "moisture";
  }
else if($inner122==8)
{
$coll = "arv_moisture"; 
$tabaar = "moisture";
  } 
else if($inner122==9)
{
$coll = "chalky"; 
$tabaar = "0";  
}
else if($inner122==10)
{
$coll = "chobba"; 
$tabaar = "0";
}
  else if($inner122==11)
{
$coll = "under_milled"; 
$tabaar = "milled";
}
  else if($inner122==12)
{
$coll = "shaded"; 
$tabaar = "0";
}
  else if($inner122==13)
{
$coll = "ponia";  
$tabaar = "0";  }
else if($inner122==14)
{
$coll = "shrivelled_grain"; 
$tabaar = "0";  }
else if($inner122==114)
{
$coll = "short_grain";  
$tabaar = "0";  }
  else if($inner122==15)
{
$coll = "mixing"; 
$tabaar = "0";  }
  else if($inner122==16)
{
$coll = "white_rice"; 
$tabaar = "0";  }
  else if($inner122==17)
{
$coll = "polish"; 
$tabaar = 0;  }
  else if($inner122==18)
{
$coll = "paddy";
$tabaar = "paddy";  
  }
  else if($inner122==19)
{
$coll = "stone";  
$tabaar = "0";  }   
  else if($inner122==20)
{
$coll = "pink_grain"; 
$tabaar = "0";  }   
else {
$coll = "short_grain";  
$tabaar = "0"; }  
$lessbroken = mysqli_get_var("Select custom_field1 from inventory where id IN (Select commodity  from truck_received where `id` = '$oldc' ) ");
$lesschalky = mysqli_get_var("Select custom_field2 from inventory where id IN ( Select commodity  from truck_received where `id` = '$oldc' ) ");
$broken5 = mysqli_get_var("Select broken_val from truck_received where `id` = '$oldc'");
$moisture5 = mysqli_get_var("Select moisture_val from truck_received where `id` = '$oldc'");
$paddy5 = mysqli_get_var("Select paddy_val from truck_received where `id` = '$oldc'");
$damage5 = mysqli_get_var("Select damage_val from truck_received where `id` = '$oldc'");
$milled5 = mysqli_get_var("Select milled_val from truck_received where `id` = '$oldc'");
$show_broken5 = mysqli_get_var("Select show_broken from truck_received where `id` = '$oldc'");
$show_moisture5 = mysqli_get_var("Select show_moisture from truck_received where `id` = '$oldc'");
$show_paddy5 = mysqli_get_var("Select show_paddy from truck_received where `id` = '$oldc'");
$show_damage5 = mysqli_get_var("Select show_damage from truck_received where `id` = '$oldc'");
$show_milled5 = mysqli_get_var("Select show_milled from truck_received where `id` = '$oldc'");
$criteria = mysqli_get_var("SELECT $coll FROM analysis_criteria WHERE `truck_id` = '$oldc' && qc=1 ORDER BY id DESC LIMIT 1 ");
$greater =  mysqli_get_var("Select greater from quality_criteria where `id` = '$inner122'"); 
if ($tabaar=="0") { }
else if($tabaar=="broken") { if($show_broken5==1) {$criteria=1000; } else { if($criteria<$broken5){ $criteria=$broken5; } } }
else if($tabaar=="moisture") { if($show_moisture5==1) {$criteria=1000; } else { if($criteria<$moisture5){ $criteria=$moisture5; } } }
else if($tabaar=="damage") { if($show_damage5==1) {$criteria=1000; } else { if($criteria<$damage5){ $criteria=$damage5; } } }
else if($tabaar=="paddy") { if($show_damage5==1) {$criteria=1000; } else { if($criteria<$paddy5){ $criteria=$paddy5; } } }
else if($tabaar=="milled") { if($show_milled5==1) {$criteria=1000; } else { if($criteria<$milled5){ $criteria=$milled5; } } }
if($tabaar=="broken") { $criteria = $criteria - $lessbroken; }
$returnValue['criteria'] = $criteria;
$returnValue['greater'] = $greater;
$returnValue['class'] = $inner122;
$returnValue['abc'] = "SELECT $coll FROM analysis_criteria WHERE `truck_id` = '$oldc' && qc=1 ORDER BY id DESC LIMIT 1 ";
echo json_encode($returnValue);
}
else if(isset($_POST['inner122x']))
{
$inner122=test_input($_POST['inner122x']);
$oldc=test_input($_POST['old']);
$tabaar = "0";
if($inner122==1)
{
$coll = "moisture"; 
$tabaar = "0";
}
else if($inner122==2)
{
$coll = "broken"; 
$tabaar = "0";
  }
else if($inner122==3)
{
$coll = "cv"; 
$tabaar = "0";
  }
else if($inner122==4)
{
$coll = "superior_varieties";
$tabaar = "0";
  } 
else if($inner122==5)
{
$coll = "interior_varieties"; 
$tabaar = "0";
  }
else if($inner122==6)
{
$coll = "red_rice"; 
$tabaar = "0";
  }
else if($inner122==7)
{
$coll = "green_paddy";  
$tabaar = "0";
  }
else if($inner122==8)
{
$coll = "shrivelled"; 
$tabaar = "0";
  } 
else if($inner122==9)
{
$coll = "damage"; 
$tabaar = "0";  
}
else if($inner122==10)
{
$coll = "empty_shell_trash_dust"; 
$tabaar = "0";
}
  else 
{
$coll = "cracks"; 
$tabaar = "0";
}
$broken5 = mysqli_get_var("Select broken_val from truck_received where `id` = '$oldc'");
$moisture5 = mysqli_get_var("Select moisture_val from truck_received where `id` = '$oldc'");
$paddy5 = mysqli_get_var("Select paddy_val from truck_received where `id` = '$oldc'");
$damage5 = mysqli_get_var("Select damage_val from truck_received where `id` = '$oldc'");
$milled5 = mysqli_get_var("Select milled_val from truck_received where `id` = '$oldc'");
$show_broken5 = mysqli_get_var("Select show_broken from truck_received where `id` = '$oldc'");
$show_moisture5 = mysqli_get_var("Select show_moisture from truck_received where `id` = '$oldc'");
$show_paddy5 = mysqli_get_var("Select show_paddy from truck_received where `id` = '$oldc'");
$show_damage5 = mysqli_get_var("Select show_damage from truck_received where `id` = '$oldc'");
$show_milled5 = mysqli_get_var("Select show_milled from truck_received where `id` = '$oldc'");
$criteria = mysqli_get_var("Select $coll from analysis_criteria_paddy where `truck_id` = '$oldc' && qc=1");
$greater =  mysqli_get_var("Select greater from quality_criteria_paddy where `id` = '$inner122'"); 
if ($tabaar=="0") { }
else if($tabaar=="broken") { if($show_broken5==1) {$criteria=1000; } else { if($criteria<$broken5){ $criteria=$broken5; } } }
else if($tabaar=="moisture") { if($show_moisture5==1) {$criteria=1000; } else { if($criteria<$moisture5){ $criteria=$moisture5; } } }
else if($tabaar=="damage") { if($show_damage5==1) {$criteria=1000; } else { if($criteria<$damage5){ $criteria=$damage5; } } }
else if($tabaar=="paddy") { if($show_damage5==1) {$criteria=1000; } else { if($criteria<$paddy5){ $criteria=$paddy5; } } }
else if($tabaar=="milled") { if($show_milled5==1) {$criteria=1000; } else { if($criteria<$milled5){ $criteria=$milled5; } } }
$returnValue['criteria'] = $criteria;
$returnValue['greater'] = $greater;
$returnValue['class'] = $inner122;
echo json_encode($returnValue);
}
else if(isset($_POST['inner122z']))
{
$inner122=test_input($_POST['inner122z']);
$oldc=test_input($_POST['old']);
$tabaar = "0";
if($inner122==1)
{
$coll = "moisture"; 
$tabaar = "0";
  }
else if($inner122==2)
{
$coll = "black";
$tabaar = "0";
  } 
else if($inner122==3)
{
$coll = "water_damage"; 
$tabaar = "0";
  }
else if($inner122==6)
{
$coll = "dead"; 
$tabaar = "0";
  }
else if($inner122==4)
{
$coll = "total_dark_appearance";  
$tabaar = "0";
  }
else if($inner122==5)
{
$coll = "small";  
$tabaar = "0";
  } 
else if($inner122==7)
{
$coll = "green";  
$tabaar = "0";  
}
else if($inner122==8)
{
$coll = "hollow"; 
$tabaar = "0";
}
  else if($inner122==9)
{
$coll = "broken"; 
$tabaar = "0";
}
  else if($inner122==10)
{
$coll = "total_fluctutaion";  
$tabaar = "0";
}
  else if($inner122==12)
{
$coll = "stone";  
$tabaar = "0";  }
else if($inner122==11)
{
$coll = "ponia";  
$tabaar = "0";  }
else if($inner122==13)
{
$coll = "dust_Sand";  
$tabaar = "0";  }
  else if($inner122==14)
{
$coll = "fiber_dandi";  
$tabaar = "0";  }
  else if($inner122==15)
{
$coll = "total_wastage";  
$tabaar = "0";  }
  else if($inner122==16)
{
$coll = "odor"; 
$tabaar = 0;  }
  else if($inner122==17)
{
$coll = "polish";
$tabaar = "0";  
  }
  else if($inner122==18)
{
$coll = "old_fresh_mix";  
$tabaar = "0";  }   
else {
$coll = "color";  
$tabaar = "0"; }  
$broken5 = mysqli_get_var("Select broken_val from truck_received where `id` = '$oldc'");
$moisture5 = mysqli_get_var("Select moisture_val from truck_received where `id` = '$oldc'");
$paddy5 = mysqli_get_var("Select paddy_val from truck_received where `id` = '$oldc'");
$damage5 = mysqli_get_var("Select damage_val from truck_received where `id` = '$oldc'");
$milled5 = mysqli_get_var("Select milled_val from truck_received where `id` = '$oldc'");
$show_broken5 = mysqli_get_var("Select show_broken from truck_received where `id` = '$oldc'");
$show_moisture5 = mysqli_get_var("Select show_moisture from truck_received where `id` = '$oldc'");
$show_paddy5 = mysqli_get_var("Select show_paddy from truck_received where `id` = '$oldc'");
$show_damage5 = mysqli_get_var("Select show_damage from truck_received where `id` = '$oldc'");
$show_milled5 = mysqli_get_var("Select show_milled from truck_received where `id` = '$oldc'");
$criteria = mysqli_get_var("Select $coll from analysis_criteria_guar where `truck_id` = '$oldc' && qc=1");
$greater =  mysqli_get_var("Select greater from quality_criteria_guar where `id` = '$inner122'"); 
if ($tabaar=="0") { }
else if($tabaar=="broken") { if($show_broken5==1) {$criteria=1000; } else { if($criteria<$broken5){ $criteria=$broken5; } } }
else if($tabaar=="moisture") { if($show_moisture5==1) {$criteria=1000; } else { if($criteria<$moisture5){ $criteria=$moisture5; } } }
else if($tabaar=="damage") { if($show_damage5==1) {$criteria=1000; } else { if($criteria<$damage5){ $criteria=$damage5; } } }
else if($tabaar=="paddy") { if($show_damage5==1) {$criteria=1000; } else { if($criteria<$paddy5){ $criteria=$paddy5; } } }
else if($tabaar=="milled") { if($show_milled5==1) {$criteria=1000; } else { if($criteria<$milled5){ $criteria=$milled5; } } }
$returnValue['criteria'] = $criteria;
$returnValue['greater'] = $greater;
$returnValue['class'] = $inner122;
echo json_encode($returnValue);
}
else if(isset($_POST['dist_to']))
{
$dist_to=test_input($_POST['dist_to']);
$dist_from=0;
$no=test_input($_POST['no']);
$cledger = $cid;
$data34 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM pr_invoice WHERE distributor_to_id='$dist_to'  ") or die(mysqli_error($conn));       
$info34 = mysqli_fetch_array( $data34 );
// $data40 = mysqli_query($conn,"SELECT SUM(advance_payment) as sum FROM customer WHERE id='$cid'") or die(mysqli_error($conn));      
// $info40 = mysqli_fetch_array( $data40 );
$data38 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM sales_debit_note WHERE cid='$cid'") or die(mysqli_error($conn));      
$info38 = mysqli_fetch_array( $data38 );
$tot= $info34['sum']+$info38['sum'] - $info40['sum'] + $info36['ob'];
?>
    Old Receivable <input name="old" type="text" class="form-control" id="old"
        value="<?php echo number_format($tot,$info2000['total_decimal']);?>" readonly="readonly" />
    <?php if($no != 1){ ?>
    <br />
    <table width="100%" border="0" cellspacing="0" id="tblExport" cellpadding="5" class="table-bordered table-striped">
        <tr>
            <td><b>Month</b></td>
            <td><b>Pending Payment</b></td>
        </tr>
        <?php  
    //  UNION ALL
    // SELECT obdate as DATETIME, 0 AS s1, 0 AS s2, 0 AS s3, ob AS s4  FROM customer 
    // where id='$cledger' 
   $data63 = mysqli_query($conn,"SELECT MONTHNAME(DATETIME) AS mn, YEAR(DATETIME) AS yn, SUM(s1-s2+s3+s4) AS pa
FROM
(
    SELECT DATETIME, pending_amount AS s1, 0 AS s2, 0 AS s3, 0 as s4 FROM pr_invoice
     where distributor_to_id='$dist_to' 
    UNION ALL
    SELECT DATETIME, 0 AS s1, 0 AS s2, pending_amount AS s3, 0 as s4  FROM sales_debit_note  where distributor_to_id='$dist_to' 
    ) AS UnionTable
GROUP BY  YEAR(DATETIME), MONTHNAME(DATETIME) order by YEAR(DATETIME), MONTHNAME(DATETIME) DESC
") or die(mysqli_error($conn));
    $ta=0;
while($info63 = mysqli_fetch_array( $data63 )) 
 { 
  ?>
        <?php if($info63['pa']!=0) { ?>
        <tr>
            <td><?php echo $info63['mn']; ?> <?php echo $info63['yn']; ?></td>
            <td><?php echo number_format($info63['pa'],$info2000['total_decimal']); $ta=$info63['pa']+$ta; ?></td>
        </tr>
        <?php } }  ?>
        <tr>
            <td><b>Total</b></td>
            <td><?php echo number_format($ta,$info2000['total_decimal']); ?></td>
        </tr>
    </table>
    <?php } ?>
    <?php }
else if(isset($_POST['dist_to_payment_old']) && isset($_POST['dist_from_payment_old']))
{
$dist_to = test_input($_POST['dist_to_payment_old']);
$dist_form = test_input($_POST['dist_from_payment_old']);
$cid=test_input($_POST['saleold2']);
$invoiceid=test_input($_POST['invoiceid']);
$cleartype=test_input($_POST['cleartype']);
?>
    <div class="bs-example">
        <div class="panel-group" id="accordion">
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseTwo" data-bs-target="#collapseTwo">Pending Invoices (Partial
                            Payment)</a>
                    </h4>
                </div>
                <div id="collapseTwo" class="card-collapse collapse">
                    <div class="card-body oldpaymentheight">
                        <?php 
$total_amt = $total_pending_amt = 0;
$data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount, daily_id, grn_id  from sales  where ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=1 )) && distributor_to_id='$dist_to' &&  distributor_from_id='$dist_form' ") or die(mysqli_error($conn));
  $tot=0; 
echo '<table class="table table-bordered" width="80%"> 
  <tr>
  <th>ID/Date</th>';
  if($info1000['en_hassanali'] == 1){ echo '<th>GDN</th>'; }
  echo '<th>Total Amount</th>
  <th>Pending Amount</th>
  <th>Paid Amount</th>
  </tr>'; 
while($info9 = mysqli_fetch_array( $data9 )) 
 { ?>
                        <tr>
                            <td>
                                <?php  
      $eid =  $info9['id'];
      $link = rtrim($info1000['printview_slug'], '/')."/sales/print-si.php?sid=".$info9['id'];
      ?>
                                <a href="<?php echo $link ?>" target="blank">
                                    <?php
      if($info3000['en_hassanali_document_no'] == 1){
        $fiscal_month = date('m', strtotime($info2000['fiscal_month']));
        $datetime = $info9['datetime'];
        $daily_id = $info9['daily_id'];
        $month = date('m', strtotime($datetime));
        if($month < $fiscal_month){
            $year1 = date('y', strtotime("-1 year",  strtotime($datetime)));
            $year2 = date('y', strtotime($datetime));
        }else{
            $year1 = date('y', strtotime($datetime));
            $year2 = date('y', strtotime("+1 year",  strtotime($datetime)));
        }
        echo "SI/".$year1."-".$year2."/".str_pad($daily_id, 2, '0', STR_PAD_LEFT);
      } else{
        echo $eid;
      } 
      $old_payment = mysqli_get_var("Select SUM(amount) from payment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 1 "); ?>
                                    (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)
                                </a>
                            </td>
                            <?php 
    if($info2000['en_ricetrade_advance'] == 1){
      if($info1000['en_hassanali'] == 1){ ?>
                            <td>
                                <a href="<?php echo rtrim(['printview_slug'], '/'); ?>/warehouse/print-gdn.php?sid=<?php echo $info9['grn_id']; ?>" target="blank">
                                    <?php
            $fiscal_month = date('m', strtotime($info2000['fiscal_month']));
            $datetime = mysqli_get_var("SELECT datetime FROM sales_grn WHERE id = '".$info9['grn_id']."' ");
            $daily_id = mysqli_get_var("SELECT daily_id FROM sales_grn WHERE id = '".$info9['grn_id']."' ");
            $month = date('m', strtotime($datetime));
            if($month < $fiscal_month){
                $year1 = date('y', strtotime("-1 year",  strtotime($datetime)));
                $year2 = date('y', strtotime($datetime));
            }else{
                $year1 = date('y', strtotime($datetime));
                $year2 = date('y', strtotime("+1 year",  strtotime($datetime)));
            }
            echo "GDN/".$year1."-".$year2."/".str_pad($daily_id, 2, '0', STR_PAD_LEFT);
            ?>
                                </a>
                            </td>
                            <?php } else{ ?>
                            <td><a href="<?php echo rtrim($info1000['printview_slug'], '/'); ?>/warehouse/print-gdn.php?sid=<?php echo $info9['grn_id']; ?>"
                                    target="blank"><?php echo $info9['grn_id']; ?></a></td>
                            <?php } ?>
                            <?php } ?>
                            <td><?php echo number_format($info9['total'],$info2000['total_decimal']); $total_amt += $info9['total']; ?>
                            </td>
                            <td><?php echo number_format($info9['pending_amount'],$info2000['total_decimal']); $total_pending_amt += $info9['pending_amount']; ?>
                            </td>
                            <td><input name="oinvoice[]" type="hidden" value="<?php echo $info9['id'];?>" /> <input
                                    name="oinvoice_qty[]" class="debit debit_row" type="number" min="0" step="0.0001"
                                    <?php if($invoiceid==0) { ?> max="<?php echo $info9['pending_amount'];?>"
                                    <?php } else{ ?> max="<?php echo $info9['pending_amount']+$old_payment;?>"
                                    <?php  } ?> value="<?php if($old_payment!='') { echo $old_payment; } else { echo 0; } ?>" required/></td>
                        </tr>
                        <?php } 
    if($info2000['en_ricetrade_advance'] == 1){ $colspan = 2; }  else { $colspan = 1; } 
  ?>
                        <tr>
                            <td colspan="<?php echo $colspan; ?>">Total</td>
                            <td><?php echo number_format($total_amt,$info2000['total_decimal']); ?></td>
                            <td><?php echo number_format($total_pending_amt,$info2000['total_decimal']); ?></td>
                        </tr>
                        <?php
echo ' </table>';
?>
                    </div>
                </div>
            </div>
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseThree" data-bs-target="#collapseThree">Pending
                            <?php echo $info2000['creditnote_label'];  ?> (Partial Payment)</a>
                    </h4>
                </div>
                <div id="collapseThree" class="card-collapse collapse">
                    <div class="card-body oldpaymentheight">
                        <?php 
$data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount  from sales_debit_note  where ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=2 )) && distributor_to_id='$dist_to' &&  distributor_from_id='$dist_form' ") or die(mysqli_error($conn));
  $tot=0; 
echo '<table class="table table-bordered" width="80%"> 
  <tr>
  <th>ID/Date</th>
  <th>Total Amount</th>
  <th>Pending Amount</th>
  <th>Paid Amount</th>
  </tr>'; 
while($info9 = mysqli_fetch_array( $data9 )) 
 { ?>
                        <tr>
                            <td><?php echo $eid = $info9['id']; $old_payment = mysqli_get_var("Select SUM(amount) from payment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 2 ");?>
                                (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)</td>
                            <td><?php echo number_format($info9['total'],$info2000['total_decimal']); ?></td>
                            <td><?php echo number_format($info9['pending_amount'],$info2000['total_decimal']); ?></td>
                            <td><input name="onotes[]" type="hidden" value="<?php echo $info9['id'];?>" />
                                <input name="onotes_qty[]" class="debit debit_row" type="number" min="0"
                                    max="<?php if($invoiceid==0) { echo $info9['pending_amount'];  } else{  echo $info9['pending_amount']+$old_payment;  } ?>"
                                    value="<?php echo $old_payment; ?>" />
                            </td>
                        </tr>
                        <?php } 
echo ' </table>';
?>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php
 } 
 else if(isset($_POST['credit_note_dist_to']))
{
$credit_note_dist_to=test_input($_POST['credit_note_dist_to']);
$credit_note_dist_from=test_input($_POST['credit_note_dist_from']);
$cid=0;//test_input($_POST['purchaseold2']);
 $invoiceid=test_input($_POST['invoiceid']);
$cleartype = $_POST['cleartype'];
$po_id = $_POST['po_id'];
$query = " AND 1=1";
if($info2000['en_ricetrade_advance'] == 1){
  $query = " AND type_component NOT IN (3, 4) ";
}
?>
    <div class="bs-example">
        <div class="panel-group" id="accordion">
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseTwo" data-bs-target="#collapseTwo">Pending Invoices (Partial
                            Payment)</a>
                    </h4>
                </div>
                <div id="collapseTwo" class="card-collapse collapse">
                    <div class="card-body oldpaymentheight">
                        <?php 
$data9 = mysqli_query($conn,"SELECT id, datetime,total_amount, pending_amount, grn_id, daily_id  from pr_invoice  where ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=1 ))  && distributor_to_id='$credit_note_dist_to'  $query ") or die(mysqli_error($conn));
  $tot=0; 
echo '<table class="table table-bordered" width="80%"> 
  <tr>';
  if($info3000['en_meskay_bulk_payment'] == 1){
    echo '<th></th>';
  }
  echo '<th>ID/Date</th>';
  if($info2000['en_ricetrade_advance'] == 1){
      echo '<th>Arrival Slip #</th>
            <th>Bilty #</th>
            <th>Truck No</th>';
  } 
  echo '<th>Total Amount</th>
  <th>Pending Amount</th>
  <th>Paid Amount</th>
  </tr>'; 
$total1 = 0;
$total2 = 0;  
while($info9 = mysqli_fetch_array( $data9 )) 
 { ?>
                        <tr>
                            <?php if($info3000['en_meskay_bulk_payment'] == 1){ ?>
                            <td>
                                <input type="checkbox" class="payment_check" value="1">
                                <input type="hidden" class="hidden_id" value="<?php echo $info9['id']; ?>">
                                <input type="hidden" class="hidden_amt" value="<?php echo $info9['pending_amount']; ?>">
                            </td>
                            <?php } ?>
                            <td>
                                <?php
      $link = rtrim($info1000['printview_slug'], '/') . "/print-custom/print-pi.php?sid=" . $info9['id'];
        if($info2000['en_ricetrade_advance'] == 1){
            $link = "print-pi-rice.php?sid=".$info9['id'];
        }
        ?>
                                <a href="<?php echo $link ?>" target="blank">
                                    <?php if($info3000['en_hassanali_document_no'] == 1){
            $fiscal_month = date('m', strtotime($info2000['fiscal_month']));
            $datetime = $info9['datetime'];
            $daily_id = $info9['daily_id'];
            $month = date('m', strtotime($datetime));
            if($month < $fiscal_month){
                $year1 = date('y', strtotime("-1 year",  strtotime($datetime)));
                $year2 = date('y', strtotime($datetime));
            }else{
                $year1 = date('y', strtotime($datetime));
                $year2 = date('y', strtotime("+1 year",  strtotime($datetime)));
            }
            echo "PI/".$year1."-".$year2."/".str_pad($daily_id, 2, '0', STR_PAD_LEFT);
        }else{?>
                                    <?php echo $info9['id']; ?>
                                    <?php } ?>
                                    (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)
                                </a>
                            </td>
                            <?php
    $arrival_slip = $bilty = $truck_no = '';
    if($info2000['en_ricetrade_advance'] == 1){
        $grn_id = $info9['grn_id'];
        $arrival_slip .= mysqli_get_var("SELECT arrival_truck_id FROM purchasing_grn WHERE id = '$grn_id' ").", ";
        $datetime = mysqli_get_var("SELECT datetime FROM purchasing_grn WHERE id = '$grn_id' ");
        $bilty .= mysqli_get_var("SELECT value FROM rice_field_details WHERE stype = 5 AND fid = '2' AND sid = '$grn_id' ").", ";
        $result2 = mysqli_query($conn, "SELECT num FROM pshipping WHERE po = 1 AND sid = '$grn_id' ") or die(mysqli_error($conn));
        while($myrow2 = mysqli_fetch_array($result2)){
          $truck_no .= $myrow2['num'].", ";
        }
        $arrival_slip = rtrim($arrival_slip, ", ");
        $bilty = rtrim($bilty, ", ");
        $truck_no = rtrim($truck_no, ", ");
      ?>
                            <td><?php if($arrival_slip != 0) { echo str_pad($arrival_slip, 4, '0', STR_PAD_LEFT).date('-d-m-y ', strtotime($datetime)); }  ?>
                            </td>
                            <td><?php echo $bilty; ?></td>
                            <td><?php echo $truck_no; ?></td>
                            <?php }
    $total1 +=  $info9['total_amount'];
    $total2 +=  $info9['pending_amount'];
    ?>
                            <td><?php echo number_format($info9['total_amount'],$info2000['total_decimal']);?></td>
                            <td><?php echo number_format($info9['pending_amount'],$info2000['total_decimal']); $eid = $info9['id'];  $old_payment = mysqli_get_var("Select SUM(amount) from ppayment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 1 ");?>
                            </td>
                            <td><input name="oinvoice[]" type="hidden" value="<?php echo $info9['id'];?>" /> <input
                                    name="oinvoice_qty[]"
                                    <?php if($info3000['en_meskay_bulk_payment'] == 1){ echo "readonly"; } ?>
                                    class="debit debit_row" type="number" min="0"
                                    max="<?php if($invoiceid==0) {  echo $info9['pending_amount'];  } else{  echo $info9['pending_amount']+$old_payment;  } ?>"
                                    step="0.0001" value="<?php if($old_payment!='') { echo $old_payment; } else { echo 0; } ?>" required/></td>
                        </tr>
                        <?php }  if($info2000['en_ricetrade_advance'] == 1){
 $colspan = 4; }  else { $colspan = 1; }  
 if($info3000['en_meskay_bulk_payment'] == 1){
    $colspan = $colspan+1;
 }
 ?>
                        <tr>
                            <td colspan="<?php echo $colspan; ?>">Total</td>
                            <td><?php echo number_format($total1, 2) ?></td>
                            <td><?php echo number_format($total2, 2) ?></td>
                            <td></td>
                        </tr>
                        <?php echo ' </table>';
?>
                    </div>
                </div>
            </div>
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title panel-title2">
                    <a data-bs-toggle="collapse" data-bs-parent="#accordion" href="#collapseThree" data-bs-target="#collapseThree">Pending
                            <?php echo $info2000['debitnote_label'];  ?> (Partial Payment)</a>
                    </h4>
                </div>
                <div id="collapseThree" class="card-collapse collapse">
                    <div class="card-body oldpaymentheight">
                        <?php 
$data9 = mysqli_query($conn,"SELECT id, datetime,total, pending_amount  from sales_credit_note  where ( pending_amount!=0 || id IN (Select invoice_id from payment_record where payment_id='$invoiceid' && clear_type='$cleartype' && invoice_type=2 )) && distributor_to_id='$credit_note_dist_to'  ") or die(mysqli_error($conn));
  $tot=0; 
echo '<table class="table table-bordered" width="80%"> 
  <tr>
  <th>ID/Date</th>
  <th>Total Amount</th>
  <th>Pending Amount</th>
  <th>Paid Amount</th>
  </tr>'; 
while($info9 = mysqli_fetch_array( $data9 )) 
 { ?>
                        <tr>
                            <td><?php echo $eid = $info9['id']; $old_payment = mysqli_get_var("Select SUM(amount) from payment_record where invoice_id='$eid' && payment_id='$invoiceid' && clear_type='$cleartype' AND invoice_type = 2 "); ?>
                                (<?php echo date('d-M-Y ', strtotime($info9['datetime']));?>)</td>
                            <td><?php echo $info9['total'];?></td>
                            <td><?php echo $info9['pending_amount'];?></td>
                            <td><input name="onotes[]" type="hidden" value="<?php echo $info9['id'];?>" /> <input
                                    name="onotes_qty[]" class="debit debit_row" type="number" min="0"
                                    max="<?php if($invoiceid==0) {  echo $info9['pending_amount']; } else{  echo $info9['pending_amount']+$old_payment;   } ?>"
                                    value="<?php echo $old_payment; ?>" /></td>
                        </tr>
                        <?php } 
echo ' </table>';
?>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php
 } 
 else if(isset($_POST['sales_credit_note_dist_to']))
{
$sales_credit_note_dist_to=test_input($_POST['sales_credit_note_dist_to']);
$sales_credit_note_dist_from=test_input($_POST['sales_credit_note_dist_from']);
$cid=0;//test_input($_POST['ppid']);
$data34 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM purchasing WHERE distributor_to_id='$sales_credit_note_dist_to' && distributor_from_id='$sales_credit_note_dist_from'  ") or die(mysqli_error($conn));      
$info34 = mysqli_fetch_array( $data34 );
// $data40 = mysqli_query($conn,"SELECT SUM(advance_payment) as sum FROM vendor WHERE id='$cid'") or die(mysqli_error($conn));      
// $info40 = mysqli_fetch_array( $data40 );
$data38 = mysqli_query($conn,"SELECT SUM(pending_amount) as sum FROM purchase_credit_note WHERE distributor_to_id='$sales_credit_note_dist_to' && distributor_from_id='$sales_credit_note_dist_from' ") or die(mysqli_error($conn));      
$info38 = mysqli_fetch_array( $data38 );
// $data36 = mysqli_query($conn,"SELECT ob FROM vendor WHERE id='$cid'") or die(mysqli_error($conn));       
// $info36 = mysqli_fetch_array( $data36 );
$tot= $info34['sum'] + $info38['sum'] + $info36['ob']  - $info40['sum'];
?>
    Old Payable <input name="old" type="text" class="form-control" id="old" value="<?php echo $tot;?>"
        readonly="readonly" />
    <br />
    <?php }
else if(isset($_POST['remove_so_line'])){
     $order_id=$_POST['remove_so_line'];
     $prd_id=$_POST['prd_id'];
     $sql = "Delete from so_details where order_id='$order_id' AND prd_id='$prd_id'";
     // echo $sql;
     $retval = mysqli_query($conn, $sql ) or die(mysqli_error($conn));
   # code...
    exit();
 }
 else if(isset($_POST['search_table'])){
     $table_id=$_POST['search_table'];
    $so_row = mysqli_get_var("SELECT * FROM so WHERE customer_id = '$table_id'"); 
    if($so_row)
      echo json_encode($so_row['id']);
    else
    {
      $date=date("Y-m-d H:i:s");
          $sql2 = "Insert into `so` (emp_id,customer_id,datetime)
      VALUES ('$loginuser','$table_id','$date')" ;
        $retval2 = mysqli_query($conn, $sql2 ) or die(mysqli_error($conn));
        $data10 = mysqli_query($conn,"SELECT MAX(id) AS id FROM so") or die(mysqli_error($conn));
        $info10 = mysqli_fetch_array( $data10 );
        $so_id =$info10['id'];
        echo json_encode($so_id) ;
    }
   # code...
    exit();
 } 
 else if(isset($_POST['search_table_details'])){
       $order_id=$_POST['search_table_details'];
       $html="";
        $data2 = mysqli_query($conn,"SELECT * FROM so_details WHERE order_id = '$order_id'") or die(mysqli_error($conn));
        $total=0;
        $data_array=array();
        while($info = mysqli_fetch_array( $data2 )) {
         $data10 = mysqli_query($conn , "SELECT name FROM inventory WHERE id = '".$info['prd_id']."' "); 
         $info10 = mysqli_fetch_array( $data10 );
         $html.='<tr> <td><input name="product_id[]" type="hidden"  value="'.$info['prd_id'].'"  /> <input name="deal[]" type="hidden"  value="' .$info['is_deal']. '" /><input name="packing[]" type="hidden"  value="'.$info['packing']. '" /><span class="sname">'.$info10['name'].'</span> <input class="desc" id="desc' .$info['prd_id']. '"  name="detail[]" type="text" value="" onchange="myFunction(this.id, this.value)" /></td><td class="text-right"><input class="form-control input-sm rserial" name="serial[]" type="hidden"  value=""><span class="text-right singleprice" ><input class="form-control single_price" name="single_price[]" readonly onchange="ptotal(this.id);" id="pp' .$info['prd_id']. '" type="number" min="' .$info['tp']. '"  value="' .$info['tp']. '" /> </span></td><td><input class="form-control qty" onchange="ptotal(this.id);" id="' .$info['prd_id']. '" name="quantity[]" type="text" value="' .$info['qty']. '" /></td><td class="text-right"><span class="text-right ssubtotal" ><input class="form-control sub_total" name="sub_total[]" id="t' .$info['prd_id']. '" type="text" value="'.$info['prd_amount']. '" readonly /></span></td><td class="text-center"><a href="#" class="removerow"><i class="fa fa-times tip pointer posdel""></i></a></td></tr>';
         $total+=$info['prd_amount'];
         $tax_perc=$info['tax_applied'];
          $disc=$info['discount'];
         // if($info['prd_amount'])
         // $perc
        }
        if($disc>0)
        {
          $disc_amt=(($total/100)*$disc);
          $total-=$disc_amt;
        }
        if($tax_perc>0)
        {
          $tax=(($total/100)*$tax_perc);
          $total+=$tax;
        }
        // if($disc>0)
        //   $total-=$disc;
        $data_array['details']=$html;
        $data_array['total']=round($total);
           $data_array['tax']=round($tax);
              $data_array['disc']=round($disc_amt);
        echo json_encode($data_array) ;
   # code...
    exit();
 } 
  else if(isset($_POST['add_so_line'])){
     $order_id=$_POST['add_so_line'];
     $prd_id=$_POST['prd_id'];
     $price=$_POST['price'];
     $packing=$_POST['packing'];
     $so_qty=$_POST['so_qty'];
     $deal=$_POST['deal'];
     $disc=$_POST['disc'];
     $tax=$_POST['tax'];
    $so_row = mysqli_get_var("SELECT * FROM so_details WHERE order_id = '$order_id' AND prd_id='$prd_id'"); 
    if($so_row)
     {
        // return     $so_row['id'];
        $sql2 = " UPDATE so_details SET qty='$so_qty' , prd_amount=tp*qty  WHERE order_id='$order_id' AND prd_id='$prd_id' " ;
        $retval2 = mysqli_query($conn, $sql2 ) or die(mysqli_error($conn));
     }
    else
    {
      $date=date("Y-m-d H:i:s");
      $sql2 = "Insert into so_details
      (order_id,prd_id,prd_amount,tp,packing,qty,is_deal,discount,tax_applied)
      VALUES ('$order_id','$prd_id','$price','$price','$packing','$so_qty','$deal','$disc','$tax')";
    echo    $sql2;
      $retval2 = mysqli_query($conn, $sql2 ) or die(mysqli_error($conn));
    }
    exit();
   # code...
 } 
else if((isset($_POST['sub_distid']))){
    if($info1000['salesman_mode']==1) {
$sub_dist = $_POST['sub_distid'];
$sub_distributor_id = $_POST['old_subdistributor'];
    $data4 = mysqli_query($conn,"SELECT * from sub_customer where cid IN ( Select id from distributor where inactive=0 and id = '$sub_dist')  order by id DESC Limit 300 ".$lim) or die(mysqli_error($conn));
$chk = mysqli_num_rows($data4);
if($chk>0){
    echo 'Sub Distributor<br>';
 // $data4 = mysqli_query($conn,"SELECT * from distributor where inactive=0") or die(mysqli_error($conn)); 
echo "<select name='sub_distributor_id'  id='myitem2' class=' sub_distributor_id teacher form-control reportselect'   >";
// echo "<option  value='0'   >Select ".$info1000['distributor_label']." </option>";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
  if ($sub_distributor_id==$info4['id']) 
  echo "<option selected='selected' value='".$info4['id']."' >".$info4['name']."</option>";
    else 
    echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}
echo "</select>";
?>
    <script>
    function alphabetizeList() {
        var sel = $('#myitem2');
        var selected = sel.val(); // cache selected value, before reordering
        var opts_list = sel.find('option');
        opts_list.sort(function(a, b) {
            return $(a).text() > $(b).text() ? 1 : -1;
        });
        sel.html('').append(opts_list);
        sel.val(selected); // set cached selected value
    }
    $('.reportselect').select2();
    alphabetizeList('.reportselect');
    </script>
    <?php
}}}

else if(isset($_POST['custsearch3']))
{


$custsearch=test_input($_POST['custsearch3']);

$data4 = mysqli_query($conn,"SELECT c.id as cid FROM customer c, contact t  WHERE t.cid=c.id && t.no LIKE '%$custsearch%' &&  c.id!=1 && c.id NOT IN (SELECT cid FROM table_customer) GROUP BY c.id"); 

$count =  mysqli_num_rows($data4);

?>
<div style="display:none"><input type="checkbox" id="req3" checked="checked" /></div>
<div class="aa" >

<select name="address" class="form-control req31" id="address"  required>
<?php 
while($info4 = mysqli_fetch_array( $data4 )) 
 { 
 $cid = $info4['cid'];
 
 $data6 = mysqli_query($conn,"SELECT id , address FROM customer_address  WHERE   cid='$cid' ") or die(mysqli_error($conn)); 
 while($info6 = mysqli_fetch_array( $data6 )) 
 {
      echo "<option value='".$info6['id']."' >".$info6['address']."</option>"; 
 }
  
}
?>
</select>   
</div>
<div class="aa nnn" style="display:none;" >
<input type="text" name="address1" placeholder="Enter Address" class="form-control req32" /><br />
<select name="customarea" class="form-control areachange" id="customarea" >
<option value="">Select Area</option>
<?php $data4 =  mysqli_query($conn,"SELECT * from customer_zone"); 

while($info4 = mysqli_fetch_array( $data4 )) 
 { 

      echo "<option value='".$info4['id']."'  >".$info4['name']." </option>";
}
?>
</select><br />
  <input name='address_type' type="hidden" value="0" /> 
<?php $data4 = mysqli_query($conn,"SELECT * from customer_group"); 

echo "<select name='customer_group' id='title'  class='teacher form-control'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}

echo "</select>";

?><br />

</div>

<?php if($count==0) {?>
<script type="text/javascript">
$(document).ready(function(){
 $(".aa").toggle(); 
document.getElementById("req3").checked = false;
$(".req32").prop('required',true);
$(".req31").prop('required',false);
 
});

</script>
<?php } else { ?>

<?php }


} 

else if(isset($_POST['custsearch2']))
{


$custsearch=test_input($_POST['custsearch2']);


$data4 = mysqli_query($conn,"SELECT c.id as cid FROM customer c, contact t  WHERE t.cid=c.id && t.no LIKE '%$custsearch%'   $rms_limit   && c.id IN (SELECT id FROM `user` u where u.inactive=0   $climit_user $climit_zone  ) GROUP BY c.id"); 

$count = mysqli_num_rows($data4);

?>
<div style="display:none"><input type="checkbox" id="req2" checked="checked" /></div>
<div class="co" >
<select name="contact" class="form-control req21" id="contact" required >
<?php 
while($info4 = mysqli_fetch_array( $data4 )) 
 { 
 $cid = $info4['cid'];
 
 $data6 = mysqli_query($conn,"SELECT id , no FROM contact  WHERE   cid='$cid' ") or die(mysqli_error($conn)); 
 while($info6 = mysqli_fetch_array( $data6 )) 
 {
      echo "<option value='".$info6['id']."' >".$info6['no']."</option>"; 
 }
  
}
?>
</select>   
</div>
<div class="co" style="display:none;" >
<input type="text" name="contact1" placeholder="Enter Contact #" class="form-control req22" id="contact1" />

<input name='contact_type' type="hidden" value="0" />
</div>
<?php if($count==0) {?>
<script type="text/javascript">
$(document).ready(function(){

  $(".co").toggle();
  
    document.getElementById("req2").checked = false;

$(".req22").prop('required',true);
$(".req21").prop('required',false);
  
  var sear = document.getElementById('cust-search').value;
    var contact2 = document.getElementById('contact1').value;

    if(contact2=='')
{   
     $("#contact1").val(sear);
}
else {
         $("#contact1").val('');
    }
    
    

    
});
</script>

<?php } } 

else if(isset($_POST['custsearch']))
{


$custsearch=test_input($_POST['custsearch']);

$data4 = mysqli_query($conn,"SELECT c.* FROM user c, contact t  WHERE t.cid=c.id && t.no LIKE '%$custsearch%'  GROUP BY c.id"); 

$count =  mysqli_num_rows($data4);
?>
<div style="display:none"><input type="checkbox" id="req1" checked="checked"  /></div>
<div class="cc" >
<select name="customer" class="form-control req11" id="customer" required >
<?php 
while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['company_name']."</option>";
}
?>
</select>   
</div>
<div class="cc" style="display:none;" >
<input type="text" name="fname" id="fname" placeholder="First Name" class="form-control req12" />
<br />
<input type="text" name="lname" placeholder="Last Name" class="form-control" />
</div>
<?php if($count==0) {?>
<script type="text/javascript">
$(document).ready(function(){
$(".cc").toggle();
  
   document.getElementById("req1").checked = false;

$(".req12").prop('required',true);
$(".req11").prop('required',false);
    
    document.getElementById("fname").focus();


    
});
</script>
<?php } 

 } 


else if(isset($_POST['custcon']))
{

$custcon=test_input($_POST['custcon']);
?>
<div class="co"  >
<select name="contact" class="form-control" id="contact" >
<?php $data4 = mysqli_query($conn,"SELECT t.* FROM customer c, contact t  WHERE t.cid=c.id && c.id = '$custcon'  GROUP BY t.id"); 

while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['no']."</option>";
}
?>
</select>   

</div>
<div class="co" style="display:none;" >
<input type="text" name="contact1" id="contact1" placeholder="Enter Contact #" class="form-control" /><br />
 <input name='contact_type' type="hidden" value="0" />
</div>

<?php } 


else if(isset($_POST['custadd']))
{

$custcon=test_input($_POST['custadd']);
?>
<div class="aa"  >

<select name="address" class="form-control areachange" id="address" >

<?php $data4 = mysqli_query($conn,"SELECT t.* FROM customer c,address t  WHERE t.cid=c.id && c.id = '$custcon' &&  c.id!=1 && c.id NOT IN (SELECT cid FROM table_customer) GROUP BY t.id"); 

while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['address'].$info4['area']."</option>";
}
?>
</select>   
</div>
<div class="aa" style="display:none;" >
<input type="text" name="address1" placeholder="Enter Address" class="form-control" /><br />
<select name="customarea" class="form-control areachange" id="customarea" >
<option value="">Select Area</option>
<?php $data4 = mysqli_query($conn,"SELECT * from customer_zone"); 

while($info4 = mysqli_fetch_array( $data4 )) 
 { 

      echo "<option value='".$info4['id']."'  >".$info4['name']." </option>";
}
?>
</select><br />
  <input name='address_type' type="hidden" value="0" /> 
<?php $data4 = mysqli_query($conn,"SELECT * from customer_group"); 

echo "<select name='customer_group' id='title'  class='teacher form-control'  >";
 while($info4 = mysqli_fetch_array( $data4 )) 
 { 
   echo "<option value='".$info4['id']."' >".$info4['name']."</option>";
}

echo "</select>";

?></div>


<?php } 
else { echo "Nothing recieved";}
if($info4000[ 'round_qty']==1) { ?>
<script type="text/javascript" >

$(document).ready(function() {    
    $('input.total_pcs').attr('step', '1');
    $('input.maxqty').attr('step', '1');
});

  </script>
<?php } 
 if($info3000['en_buraqcorp']==1){ ?>
<script type="text/javascript" >
$(document).ready(function() {    
    $(".customfield4:first").attr('type', 'date');
    $(".cf_width:first").attr('type', 'date');

    // Purchase Side
    $(".customfield1:first").attr('type', 'date');
    $(".customfield2:first").attr('type', 'date');
});
</script>
<?php } ?>
