0){
while($set_free = mysqli_fetch_assoc($get_free)){
$get_edi = mysqli_query($conn, "SELECT
COUNT(*) = SUM(
stock_status IN ('ordered', 'added by admin')
) AS all_active
FROM tbl_dealer_ef_sub
WHERE dealer_id = '$dealer_id' AND order_id = '".$set_free['id']."' and ref_order_id is NULL;
");
$set_edi = mysqli_fetch_assoc($get_edi);
if($set_edi['all_active'] == 1){
$action_1 = 'ADD MORE';
$free_id = $set_free['id'];
break;
}
}
}
$get_main = mysqli_query($conn, "SELECT * from tbl_dealer_ef_main where dealer_id='$dealer_id' order by id desc");
while($set_main = mysqli_fetch_assoc($get_main)){
if($free_id == $set_main['id']){
$action = $action_1;
}else{
$action = "";
}
$totprice = 0;
$get_sub = mysqli_query($conn, "select sum(tot_price) as total from tbl_dealer_ef_sub where dealer_id ='$dealer_id' and order_id ='".$set_main['id']."'");
$set_sub = mysqli_fetch_assoc($get_sub);
$totprice = $set_sub['total'];
$totprice_1 = 0;
$get_sub_max = mysqli_query($conn, "select distinct ref_order_id as ref_order_id from tbl_dealer_ef_sub where dealer_id ='".$set_main['dealer_id']."' and order_id ='".$set_main['id']."' and ref_order_id is not null");
while($set_sub_max = mysqli_fetch_assoc($get_sub_max)){
$get_tot = mysqli_query($conn, "SELECT SUM(totprice) as total_price from tbl_order where orderid='".$set_sub_max['ref_order_id']."'");
$set_tot = mysqli_fetch_assoc($get_tot);
$totprice_1+=$set_tot['total_price'];
}
if($set_sub_tot['tot_price_sub'] == $totprice_1){
$amount_tat = 'SAME';
}else{
$amount_tat = $totprice_1;
}
$get_empty_sub = mysqli_query($conn, "SELECT * FROM tbl_dealer_ef_sub WHERE order_id='".$set_main['id']."'");
$check_empty_sub = mysqli_num_rows($get_empty_sub);
$get_can = mysqli_query($conn, "SELECT COUNT(DISTINCT stock_status) = 1 AND MAX(stock_status) = 'cancelled' AS all_active
FROM tbl_dealer_ef_sub
WHERE dealer_id ='$dealer_id' and order_id ='".$set_main['id']."'");
$set_can = mysqli_fetch_assoc($get_can);
$get_no = mysqli_query($conn, "SELECT COUNT(DISTINCT stock_status) = 1 AND MAX(stock_status) = 'no stock' AS all_active
FROM tbl_dealer_ef_sub
WHERE dealer_id ='$dealer_id' and order_id ='".$set_main['id']."'");
$set_no = mysqli_fetch_assoc($get_no);
$get_del = mysqli_query($conn, "SELECT order_status from tbl_dealer_ef_main where dealer_id = '$dealer_id' and id='".$set_main['id']."'");
$set_del = mysqli_fetch_assoc($get_del);
$get_deal = mysqli_query($conn, "SELECT * FROM shop_user where user_id='".$set_main['dealer_id']."'");
$set_deal = mysqli_fetch_assoc($get_deal);
$ref_no='DE'.str_pad($set_main['id'], 4, "0", STR_PAD_LEFT);
$url=''.$ref_no.'';
if($set_del['order_status'] == 1){
$data[] = array('sl_no' => ++$i,'order_no'=>$url, 'order_date' => date('d-m-y, H:i',strtotime($set_main['order_date_time'])),'dealer'=>$set_deal['name'],'contact'=>$set_deal['phone'],'tot_amount'=>$totprice, 'amount'=>'DELETED
', 'action'=>$action);
}else if($set_can['all_active'] == 1){
$data[] = array('sl_no' => ++$i,'order_no'=>$url, 'order_date' => date('d-m-y, H:i',strtotime($set_main['order_date_time'])),'dealer'=>$set_deal['name'],'contact'=>$set_deal['phone'],'tot_amount'=>$totprice,'amount'=>'CANCEL
','action'=>$action);
}else if($set_no['all_active'] == 1){
$data[] = array('sl_no' => ++$i,'order_no'=>$url, 'order_date' => date('d-m-y, H:i',strtotime($set_main['order_date_time'])),'dealer'=>$set_deal['name'],'contact'=>$set_deal['phone'],'tot_amount'=>$totprice,'amount'=>'NO STOCK
','action'=>$action);
}else if($totprice!=0 && $set_can['all_active']==0){
$data[] = array('sl_no' => ++$i,'order_no'=>$url, 'order_date' => date('d-m-y, H:i',strtotime($set_main['order_date_time'])),'dealer'=>$set_deal['name'],'contact'=>$set_deal['phone'],'tot_amount'=>$totprice,'amount'=>$amount_tat,'action'=>$action);
}
// else if($check_empty_sub==0){
// $data[] = array('sl_no' => ++$i,'order_no'=>$url, 'order_date' => date('d-m-y, H:i',strtotime($set_main['order_date_time'])),'dealer'=>$set_deal['name'],'contact'=>$set_deal['phone'],'tot_amount'=>$totprice,'amount'=>'EMPTY','action'=>$action);
// }
}
mysqli_close($conn);
if(!empty($data))
{
echo json_encode(array(
"aaData"=>$data));
}
else
{
echo json_encode(array('aaData'=>[]));
}
?>