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'];
}
$stock_transfer_date = $_REQUEST['stock_transfer_date'];
$posd_id = $_REQUEST['pos'];
//$item_name = $_REQUEST['item_name'];
//$brand_name = $_REQUEST['brand_name'];
//$dimension = $_REQUEST['dimension'];
$quantity = $_REQUEST['quantity'];
$stock_transfer_nosk = $_REQUEST['stocktransfer_no'];
//$purchase_item_id = $_REQUEST['purchase_item_id'];
$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 = date("Y-m-d");
$active = 'yes';
$userId = $_SESSION['USER_ID'];
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)
VALUES ('$newInsert','$purchase_item_id','$quantity')");
}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)
VALUES ('$newInsert','$purchase_item_id','$quantity')");
}
}
if($newInsert2 == TRUE){
echo '{"status": "1",
"message":" Insert successfully"
}';
}else{
echo '{"status": "0",
"message":"Unccessful"
}';
}
$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);
?>