$product="active";
$caller1="open";
$india_stock="active";
include '../../include/conf.php';
require_once '../template/superadmin/action_connection.php' ;
include("../settings/adminsession.php");
session_start();
$id = $_GET['id'];
?>
alert("some error, contact admin");';
}
}
?>
if($flag=="success")
{
?>
Success! Data Updated Sucessfully.
}
?>
if($flag=="failure")
{
?>
Danger! Data Not Updated
}
$get_stock = mysqli_query($conn, "select * from tbl_india_update_stock where id='$id'");
$set_stock = mysqli_fetch_array($get_stock, MYSQLI_ASSOC);
$get_prod = mysqli_query($conn, "select * from shop_product where product_id='$set_stock[product_id]'");
$set_prod = mysqli_fetch_array($get_prod, MYSQLI_ASSOC);
//code for instock
$start_date = date('Y-m-d');
$date = new DateTime($start_date);
$yesterday= $date->modify("-1 days")->format('Y-m-d');
$arr = array();
$arr_1 = array();
$arr_2 = array();
$get_orid = mysqli_query($conn,"Select * from tbl_confirmorder WHERE DATE_FORMAT(order_date_time, '%Y-%m-%d') = '$start_date' AND refid NOT LIKE '%SYP%' and company_name not like 'Siddhayoga Pharma' and orderstatus not like '90'");
while($set_orid = mysqli_fetch_array($get_orid, MYSQLI_ASSOC))
{
$pattern1 = "/CO/i";
$pattern2 = "/Siddhayoga/i";
$pattern3 = "/Cash/i";
$pattern4 = "/HC/i";
$pattern5 = "/Energy/i";
array_push($arr, $set_orid['orderid']);
}
ksort($arr);
foreach($arr as $arrays){
$check_sy = mysqli_query($conn, "select * from tbl_confirmorder where refid like '%HC%' and company_name='Energy Foods' and userid='7444' and orderid='$arrays'");
$check_syp = mysqli_num_rows($check_sy);
if($check_syp == 0){
array_push($arr_2, $arrays);
}
}
foreach($arr_2 as $arr_zee){
$check_yv = mysqli_query($conn, "select * from tbl_order where orderid='$arr_zee'");
$yv_count = mysqli_num_rows($check_yv);
$check_yvs = mysqli_query($conn, "SELECT * FROM tbl_order td INNER JOIN shop_product sp on td.productid = sp.product_id WHERE td.orderid='$arr_zee' and sp.cloud_url<>'' ORDER BY td.ordid desc;");
$yvs_count = mysqli_num_rows($check_yvs);
if($yv_count != $yvs_count){
array_push($arr_1, $arr_zee);
}
}
ksort($arr_1);
$check_stock = mysqli_query($conn, "SELECT m1.*
FROM tbl_india_update_stock m1 LEFT JOIN tbl_india_update_stock m2
ON (m1.product_id = m2.product_id AND m1.id < m2.id) INNER JOIN shop_product sp ON sp.product_id = m1.product_id
WHERE m2.id IS NULL AND sp.can_add_stock = 'yes';");
while($row1 = mysqli_fetch_array($check_stock, MYSQLI_ASSOC)) {
$opening_balance='';
$sale_qty = 0;
$get_refund_count = 0;
$balance = 0;
$pending = 0;
$packing = 0;
$new = 0;
$get_prod = mysqli_query($conn, "SELECT * from shop_product where product_id='$set_stock[product_id]'");
$get_product = mysqli_fetch_array($get_prod, MYSQLI_ASSOC);
$get_comp = mysqli_query($conn, "select `name` from tbl_company where id='".$get_product['vstatus']."'");
$set_comp = mysqli_fetch_array($get_comp, MYSQLI_ASSOC);
foreach($arr_1 as $arrays){
$get_sale = mysqli_query($conn, "SELECT qty+freeqty as qtys FROM tbl_order WHERE orderid ='$arrays' AND productid = '$set_stock[product_id]'");
$check_rows_2 = mysqli_num_rows($get_sale);
if($check_rows_2 > 0){
$get_sales = mysqli_fetch_array($get_sale, MYSQLI_ASSOC);
$sale_qty = $sale_qty + $get_sales['qtys'];
}
}
$select = "select new_stock, product_id,from_name from tbl_india_update_stock where stock_date='$start_date' and product_id = '$set_stock[product_id]' group by product_id";
$get_sto = mysqli_query($conn, $select);
$check_sto = mysqli_num_rows($get_sto);
if($check_sto > 0){
$set_sto = mysqli_fetch_array($get_sto);
$new_stock = $set_sto['new_stock'];
}else{
$new_stock = 0;
}
foreach($arr_1 as $arrays){
$get_refu = mysqli_query($conn, "SELECT ts.qty + ts.freeqty as qtys FROM tbl_confirmorder tb inner join tbl_order ts on tb.orid = ts.orderid where tb.orderstatus = 4 AND ts.productid='$set_stock[product_id]' and ts.orderid = '$arrays' and DATE(tb.refund_time) = '$start_date'");
$check_rows_2 = mysqli_num_rows($get_refu);
if($check_rows_2 > 0){
$get_refund = mysqli_fetch_array($get_refu, MYSQLI_ASSOC);
$get_refund_count = $get_refund_count + $get_refund['qtys'];
}
}
$get_prod = mysqli_query($conn, "SELECT * from shop_product where product_id='$set_stock[product_id]'");
$get_product = mysqli_fetch_array($get_prod, MYSQLI_ASSOC);
//opening balance
$open_bal = mysqli_query($conn, "select * from tbl_cron_stock_report where product_id ='$set_stock[product_id]' and snap_date='$yesterday'");
$set_bal = mysqli_fetch_array($open_bal, MYSQLI_ASSOC);
$opening_balance = $set_bal['balance'];
//echo $get_product['name'].' '.$get_product['product_url'].' '.$opening_balance.' '.$sale_qty.' '.$new_stock.' '.$get_refund_count.'';
$balance = $opening_balance - $sale_qty + $new_stock + $get_refund_count;
$get_packing = mysqli_query($conn, "SELECT sum(tb.qty + tb.freeqty) AS fqty FROM tbl_confirmorder tc INNER JOIN tbl_order tb ON tc.orderid = tb.orderid WHERE tc.orderstatus = 5 AND tc.varstatus!='Cash' and tc.company_name='Energy Foods' and tc.userid!=7444 and tb.productid='$set_stock[product_id]'");
$pack_rows = mysqli_num_rows($get_packing);
if($pack_rows > 0){
$set_packing = mysqli_fetch_array($get_packing, MYSQLI_ASSOC);
$packing = $set_packing['fqty'];
}else{
$packing = 0;
}
$get_new = mysqli_query($conn, "SELECT sum(tb.qty + tb.freeqty) AS fqty FROM tbl_confirmorder tc INNER JOIN tbl_order tb ON tc.orderid = tb.orderid WHERE tc.orderstatus = 0 AND tc.varstatus!='Cash' and tc.company_name='Energy Foods' and tc.userid!=7444 and tb.productid='$set_stock[product_id]'");
$new_rows = mysqli_num_rows($get_new);
if($new_rows > 0){
$set_new = mysqli_fetch_array($get_new, MYSQLI_ASSOC);
$new = $set_new['fqty'];
}else{
$new = 0;
}
$pending = $packing + $new;
if(!isset($pending)){
$pending = 0;
}
$instock = $balance + $pending;
}
?>