CasperSecurity
<?php
session_start();
include '../../../web/connection/connection.php';
include '../../../web/connection/con.php';
include '../../../web/connection/functions/encryption.php';
$barcodee = $_POST['barcode'];
$exp = explode('_',$barcodee);
$barcode = $exp[0];
$exp2 = $exp[1];
$exp3 = $exp[2];
$exp4 = $exp[3];
$db_handle = new DBController();
$selpurchase = $db_handle->runQuery("SELECT * FROM (purchase
INNER JOIN purchase_item ON purchase.purchase_id = purchase_item.purchase_id)
WHERE purchase_item.bar_code = '$barcode' AND purchase_item.batch_no = '$exp2' AND purchase_item.mrp = '$exp3'");
foreach($selpurchase as $purchasedata){
$purchase_item_id = $purchasedata['purchase_item_id'];
$adjust_quantity = $purchasedata['adjust_quantity'];
$purchase_rate = $purchasedata['rate'];
$discountrate = $purchasedata['discount_rate'];
}
$stock_transfer_date = $_REQUEST['stock_transfer_date'];
$posd_id = $_REQUEST['pos'];
$quantity = $_REQUEST['quantity'];
$totalweight = $_REQUEST['totalweight'];
$stock_transfer_nosk = $_REQUEST['stocktransfer_no']; //not required
$totalqy = -($adjust_quantity - $quantity);
if(!empty($stock_transfer_nosk)){
$stock_transfer_no = $stock_transfer_nosk;
}else{
$selectst ="SELECT * FROM stock_transfer ORDER BY stock_transfer_id DESC";
$queryst=mysqli_query($con,$selectst);
$resultst=mysqli_fetch_assoc($queryst);
$stock_transfer_id = $resultst['stock_transfer_id']+1;
$zero = 0;
$qut = 'STA';
$year = date("Y");
$stock_transfer_noyy = $qut.'-'.$year.'-'.$zero.''.$zero.''.$zero.''.$zero.''.$stock_transfer_id;
if(($stock_transfer_id >= '10') && ($stock_transfer_id < '100')){
$stock_transfer_no = $qut.'-'.$year.'-'.$zero.''.$zero.''.$zero.''.$stock_transfer_id;
}elseif(($stock_transfer_id >= '100')&&($stock_transfer_id < '1000')){
$stock_transfer_no = $qut.'-'.$year.'-'.$zero.''.$zero.''.$stock_transfer_id;
}elseif($stock_transfer_id >= '1000'){
$stock_transfer_no = $stock_transfer_id;
}else{
$stock_transfer_no = $stock_transfer_noyy;
}
}
date_default_timezone_set('Asia/Kolkata');
$date = date("Y-m-d H:i:s");
$active = 'yes';
$userId = $_SESSION['USER_ID'];
if($purchasedata['discount_rate']){
$discount_rate = $purchasedata['discount_rate'];
}else{
$discount_rate = 0.00;
}
$base_amount = $quantity * $purchase_rate;
$discount_amount = ($base_amount * ($discount_rate/100));
$purchase_amount = $base_amount - $discount_amount;
$Pur_Amount = number_format($purchase_amount,2);
$loose_rate = $purchase_amount/$totalweight;
$Loose_Rate = number_format($loose_rate,2);
if(!empty($stock_transfer_date)){
$db_handle = new DBController();
$newUpdate = $db_handle->runMyUpdate("UPDATE purchase_item SET adjust_quantity = -'$totalqy' WHERE purchase_item_id = '$purchase_item_id'");
$st_nomrow = $db_handle-> numRows("SELECT * FROM stock_transfer WHERE stock_transfer_no = '$stock_transfer_no'");
if($st_nomrow == 0){
$db_handle = new DBController();
$newInsert = $db_handle->tableinsert("INSERT INTO stock_transfer(stock_transfer_no,stock_transfer_date,pos_id,created_on,created_by,is_active)
VALUES ('$stock_transfer_no','$stock_transfer_date','$posd_id','$date','$userId','$active')");
$db_handle = new DBController();
$newInsert2 = $db_handle->tableinsert("INSERT INTO stock_transfer_item(stock_transfer_id,purchase_item_id,item_quantity,purchase_amount,totalpacket_weight,loose_rate)
VALUES ('$newInsert','$purchase_item_id','$quantity','$purchase_amount','$totalweight','$loose_rate')");
}else{
$db_handle = new DBController();
$stocktransfer = $db_handle-> runQuery("SELECT * FROM stock_transfer WHERE stock_transfer_no = '$stock_transfer_no' ORDER BY stock_transfer_id DESC LIMIT 1");
$db_handle = new DBController();
foreach( $stocktransfer as $stocktransferd){
$newInsert = $stocktransferd['stock_transfer_id'];
}
$db_handle = new DBController();
$newInsert2 = $db_handle->tableinsert("INSERT INTO stock_transfer_item(stock_transfer_id,purchase_item_id,item_quantity,purchase_amount,totalpacket_weight,loose_rate)
VALUES ('$newInsert','$purchase_item_id','$quantity','$purchase_amount','$totalweight','$loose_rate')");
}
}
if($newInsert2 == TRUE){
$_SESSION['ERROR_MSG'] = "Instered Successfully";
$_SESSION['MSG_ALRT'] = "TRUE";
header('location:../../../web/home/modules/stock/stock_transfer/stock_transfer_grid.php');
}else{
$_SESSION['ERROR_MSG'] = "Sorry! Try Again";
$_SESSION['MSG_ALRT'] = "TRUE";
header('location:../../../web/home/modules/stock/stock_transfer/stock_transfer_grid.php');
}
$stocktransfer_ide =amebi_crypt($newInsert,e);
$stocktranfenos =amebi_crypt($stock_transfer_no,e);
$stocktransfer_date = amebi_crypt($stock_transfer_date,e);
$posd_idqe = amebi_crypt($posd_id,e);
header('location:../../../web/home/modules/stock/stock_transfer/stock_transfer_grid.php?stocktransferid='.$stocktransfer_ide.'&stocktransferdate='.$stocktransfer_date.'&posidd='.$posd_idqe.'&stocktransferno='.$stocktranfenos);
//header('location:../../../web/home/modules/stock/stock_transfer/stock_transfer_grid.php?stocktransferid='.$stocktransfer_ide.'&stocktransferdate='.$stocktransfer_date.'&posidd='.$posd_idqe.'&stocktransferno='.$stocktranfenos);
?>