ok
Direktori : /home2/selectio/public_html/obnovit-tracking/android-api/old/ |
Current File : /home2/selectio/public_html/obnovit-tracking/android-api/old/shipments.php |
<?php include_once('config/config.php'); include_once('config/custom-functions.php'); include 'config/send-sms.php'; $fn = new custom_functions(); /* ------------------------------------------- APIs for Speedlink Services App ------------------------------------------- 1. add-shipments 2. get-shipments 3. update-shipments 4. delete-shipments ------------------------------------------- */ /*get_shipments accesskey:lalitha type:shipments branch_id:10 {optional} limit:10 {optional} offset:0 {optional} sort:id {optional} order:ASC/DESC {optional} search:value {optional} */ if ((isset($_POST['type'])) && ($_POST['type'] == 'get_shipments')){ $where = ''; $offset = (isset($_POST['offset']) && !empty(trim($_POST['offset'])) && is_numeric($_POST['offset'])) ? trim($fn->xss_clean($_POST['offset'])) : 0; $limit = (isset($_POST['limit']) && !empty(trim($_POST['limit'])) && is_numeric($_POST['limit'])) ? trim($fn->xss_clean($_POST['limit'])) : 10; $sort = (isset($_POST['sort']) && !empty(trim($_POST['sort']))) ? trim($fn->xss_clean($_POST['sort'])) : 'id'; $order = (isset($_POST['order']) && !empty(trim($_POST['order']))) ? trim($fn->xss_clean($_POST['order'])) : 'DESC'; if (isset($_POST['search']) && !empty($_POST['search'])) { $search = $fn->xss_clean($_POST['search']); $where .= " and pickup_entry.awb_no like '%" . $search . "%' OR pickup_entry.ref_no like '%" . $search . "%'"; } $statement = $pdo->prepare("SELECT COUNT(pickup_entry.id) as total FROM pickup_entry INNER JOIN tbl_user INNER JOIN tbl_customer INNER JOIN material_desc on pickup_entry.client_id=tbl_user.id AND pickup_entry.content_desc=material_desc.id AND pickup_entry.customer_id=tbl_customer.cust_id where pickup_entry.id!=0 " . $where); $statement->execute(); $res = $statement->fetchAll(PDO::FETCH_ASSOC); if (!empty($res)) { foreach ($res as $row) $total = $row['total']; $statement = $pdo->prepare("SELECT pickup_entry.*,tbl_user.full_name as client_name,tbl_customer.cust_code as cust_code,material_desc.full_desc as content,tbl_customer.cust_name as cust_name,(select branch_name from tbl_branch WHERE id=pickup_entry.orgin_branch_id) as orgin,(select branch_name from tbl_branch WHERE id=pickup_entry.destination_branch_id) as destinations FROM pickup_entry INNER JOIN tbl_user INNER JOIN tbl_customer INNER JOIN material_desc on pickup_entry.client_id=tbl_user.id AND pickup_entry.content_desc=material_desc.id AND pickup_entry.customer_id=tbl_customer.cust_id where pickup_entry.id!=0 " . $where . " ORDER BY `" . $sort . "` " . $order . " LIMIT " . $offset . ", " . $limit); $statement->execute(); $res = $statement->fetchAll(PDO::FETCH_ASSOC); $rows = array(); $tempRow = array(); foreach ($res as $row) { $rows[] = $row; } $response['error'] = false; $response['message'] = "Shipments fatched successfully."; $response['total'] = $total; $response['data'] = $rows; } else { $response['error'] = true; $response['message'] = "Something went wrong, please try again leter."; } print_r(json_encode($response)); } /*scan shipment using barcode*/ if ((isset($_POST['type'])) && ($_POST['type'] == 'shipment_scan')){ $where = ''; $scan_number = (isset($_POST['id']) && !empty(trim($_POST['id']))) ? trim($fn->xss_clean($_POST['id'])) : ''; $status = (isset($_POST['status']) && !empty(trim($_POST['status']))) ? trim($fn->xss_clean($_POST['status'])) : '0'; $where .= " and pickup_entry.ref_no='" . $scan_number . "'"; $statement = $pdo->prepare("SELECT pickup_entry.*,tbl_user.full_name as client_name,tbl_customer.cust_code as cust_code,material_desc.full_desc as content,tbl_customer.cust_name as cust_name,(select branch_name from tbl_branch WHERE id=pickup_entry.orgin_branch_id) as orgin,(select branch_name from tbl_branch WHERE id=pickup_entry.destination_branch_id) as destinations FROM pickup_entry INNER JOIN tbl_user INNER JOIN tbl_customer INNER JOIN material_desc on pickup_entry.client_id=tbl_user.id AND pickup_entry.content_desc=material_desc.id AND pickup_entry.customer_id=tbl_customer.cust_id where pickup_entry.id!=0 " . $where); $statement->execute(); $res = $statement->fetchAll(PDO::FETCH_ASSOC); if (!empty($res)) { $rows = array(); $tempRow = array(); foreach ($res as $row) { if($row['status_code']<$status ){ $rows[] = $row; $response['error'] = false; $response['message'] = "Shipments Scaning Data fatched successfully."; $response['data'] = $rows; } else{ $response['error'] = true; $response['message'] = "Shipment Status is '".$row['status']."' Can't Add Shipment..."; } } } else{ $response['error'] = true; $response['message'] = "Something went wrong, please try again leter."; } print_r(json_encode($response)); } /*scan shipment update status*/ if ((isset($_POST['type'])) && ($_POST['type'] == 'update_shipment_status')){ $id = (isset($_POST['id']) && !empty(trim($_POST['id']))) ? trim($fn->xss_clean($_POST['id'])) : '0'; $shipment_id = (isset($_POST['shipment_id']) && !empty(trim($_POST['shipment_id']))) ? trim($fn->xss_clean($_POST['shipment_id'])) : ''; $status = (isset($_POST['status']) && !empty(trim($_POST['status']))) ? trim($fn->xss_clean($_POST['status'])) : '0'; $branch_id = (isset($_POST['branch_id']) && !empty(trim($_POST['branch_id']))) ? trim($fn->xss_clean($_POST['branch_id'])) : '0'; $location = (isset($_POST['location']) && !empty(trim($_POST['location']))) ? trim($fn->xss_clean($_POST['location'])) : '0'; $sh_id=array(); $sh_id=explode(",",$shipment_id); //split ("\,", $s_id); switch($status){ case 2: { $status_name="Picked"; break; } case 4: { $status_name="Intransit"; break; } case 5: { $status_name="Received at Destination"; break; } case 6: { $status_name="Out for Delivery"; break; } case 7: { $status_name="Delivery"; break; } case 8: { $status_name="Un-Delivery"; break; } case 9: { $status_name="Return to Origin"; break; } default: { $status_name="---"; break; } } $pic_desc='Shipment has been '; $c_at ="2021-09-18"; $msg=""; foreach ($sh_id as $ship_id){ $msg.=$ship_id; $d=$ship_id; $statement = $pdo->prepare("UPDATE pickup_entry SET status_code=?, status=? WHERE id=?"); $statement->execute(array($status,$status_name,$ship_id)); $statement1 = $pdo->prepare("INSERT INTO tbl_tracking (pickup_entry_id,user_id,location,status,description,remark) VALUES (3,$id,'$location','$status_name','$pic_desc',' ')"); $result2=$statement1->execute(); } $msg.="shipment Status Updated Sucessfully..."; $response['error'] = false; $response['message'] = $msg; print_r(json_encode($response)); } /*get booked shipment list*/ if ((isset($_POST['type'])) && ($_POST['type'] == 'get_booked_shipments')){ $where = ''; $offset = (isset($_POST['offset']) && !empty(trim($_POST['offset'])) && is_numeric($_POST['offset'])) ? trim($fn->xss_clean($_POST['offset'])) : 0; $limit = (isset($_POST['limit']) && !empty(trim($_POST['limit'])) && is_numeric($_POST['limit'])) ? trim($fn->xss_clean($_POST['limit'])) : 500; $sort = (isset($_POST['sort']) && !empty(trim($_POST['sort']))) ? trim($fn->xss_clean($_POST['sort'])) : 'id'; $order = (isset($_POST['order']) && !empty(trim($_POST['order']))) ? trim($fn->xss_clean($_POST['order'])) : 'DESC'; /*if (isset($_POST['search']) && !empty($_POST['search'])) { $search = $fn->xss_clean($_POST['search']); $where .= " and pickup_entry.awb_no like '%" . $search . "%' OR pickup_entry.ref_no like '%" . $search . "%'"; }*/ $statement = $pdo->prepare("SELECT pickup_entry.*,tbl_user.full_name as client_name,tbl_customer.cust_code as cust_code,material_desc.full_desc as content,tbl_customer.cust_name as cust_name,(select branch_name from tbl_branch WHERE id=pickup_entry.orgin_branch_id) as orgin,(select branch_name from tbl_branch WHERE id=pickup_entry.destination_branch_id) as destinations,(select count(id) from tbl_no_of_box where pickup_entry_id=pickup_entry.id and status=pickup_entry.status_code) as current_status_pics_count,(select count(id) from tbl_no_of_box where pickup_entry_id=pickup_entry.id and status=1) as booked_count FROM pickup_entry INNER JOIN tbl_user INNER JOIN tbl_customer INNER JOIN material_desc on pickup_entry.client_id=tbl_user.id AND pickup_entry.content_desc=material_desc.id AND pickup_entry.customer_id=tbl_customer.cust_id where pickup_entry.id!=0 " . $where); $statement->execute(); $res = $statement->fetchAll(PDO::FETCH_ASSOC); $ii=0; if (!empty($res)) { foreach ($res as $row) $statement = $pdo->prepare("SELECT pickup_entry.*,tbl_user.full_name as client_name,tbl_customer.cust_code as cust_code,material_desc.full_desc as content,tbl_customer.cust_name as cust_name,(select branch_name from tbl_branch WHERE id=pickup_entry.orgin_branch_id) as orgin,(select branch_name from tbl_branch WHERE id=pickup_entry.destination_branch_id) as destinations,(select count(id) from tbl_no_of_box where pickup_entry_id=pickup_entry.id and status=pickup_entry.status_code) as current_status_pics_count,(select count(id) from tbl_no_of_box where pickup_entry_id=pickup_entry.id and status=1) as booked_count FROM pickup_entry INNER JOIN tbl_user INNER JOIN tbl_customer INNER JOIN material_desc on pickup_entry.client_id=tbl_user.id AND pickup_entry.content_desc=material_desc.id AND pickup_entry.customer_id=tbl_customer.cust_id where pickup_entry.id!=0 " . $where . " ORDER BY `" . $sort . "` " . $order . " LIMIT " . $offset . ", " . $limit); $statement->execute(); $res = $statement->fetchAll(PDO::FETCH_ASSOC); $rows = array(); $tempRow = array(); foreach ($res as $row) { if($row['booked_count']!=0){ $rows[] = $row; $ii++;} } $total=$ii; $response['error'] = false; $response['message'] = "Shipments fatched successfully."; $response['total'] = $total; $response['data'] = $rows; } else { $response['error'] = true; $response['message'] = "Something went wrong, please try again leter."; } print_r(json_encode($response)); } /*get booked shipment Box's list*/ if ((isset($_POST['type'])) && ($_POST['type'] == 'get_booked_shipments_boxs')){ $ids = (isset($_POST['ids']) && !empty(trim($_POST['ids'])) ) ? trim($fn->xss_clean($_POST['ids'])) : 0; $k=0; $statement = $pdo->prepare("SELECT tbl_no_of_box.*,pickup_entry.awb_no FROM `tbl_no_of_box` inner join pickup_entry on tbl_no_of_box.pickup_entry_id=pickup_entry.id WHERE tbl_no_of_box.pickup_entry_id in ($ids) and tbl_no_of_box.status=1 order by tbl_no_of_box.id"); $statement->execute(); $res = $statement->fetchAll(PDO::FETCH_ASSOC); if (!empty($res)) { $rows = array(); $tempRow = array(); foreach ($res as $row) { $rows[] = $row; $k++; } $total=$k; $response['error'] = false; $response['message'] = "Shipments fatched successfully."; $response['total'] = $total; $response['data'] = $rows; } else{ $response['error'] = true; $response['message'] = "Something went wrong, please try again leter."; } print_r(json_encode($response)); } /*update shipment box as picked*/ if(isset($_POST['type']) && $_POST['type']=="update_shipment_box_status_as_picked"){ $clientId=1; $clientLocation="Bangalore"; $s_id=$_POST['shp_id']; $sh_id=array(); $sh_id=explode(",",$s_id); //split ("\,", $s_id); /* $s_stat_id = $_POST['stat']; $s_stat_name = $_POST['stat_name']; $pic_desc= $_POST['status_notes']; $c_at = $_POST['status_date'];*/ $s_stat_id = 2; $s_stat_name = "Picked"; $pic_desc= "Box Successfully Picked"; $c_at = date("Y-m-d"); foreach ($sh_id as $ship_id){ $pickup_entry_id=0;$status_code=0; $statement = $pdo->prepare("SELECT tbl_no_of_box.*,pickup_entry.status_code FROM `tbl_no_of_box` INNER JOIN pickup_entry on tbl_no_of_box.pickup_entry_id=pickup_entry.id WHERE tbl_no_of_box.id=$ship_id"); $statement->execute(); $results = $statement->fetchAll(PDO::FETCH_ASSOC); foreach ($results as $fetch) { $pickup_entry_id = $fetch['pickup_entry_id']; $status_code=$fetch['status_code']; } if($status_code!=$s_stat_id && $s_stat_id!=10){ $statement = $pdo->prepare("UPDATE pickup_entry SET status_code=?, status=? WHERE id=?"); $statement->execute(array($s_stat_id,$s_stat_name,$pickup_entry_id)); /*Tracking Module Start*/ $statement = $pdo->prepare("INSERT INTO tbl_tracking (pickup_entry_id,user_id,location,status,description,remark,created_at) VALUES (?,?,?,?,?,?,?)"); $result2=$statement->execute(array($pickup_entry_id,$clientId,$clientLocation,$s_stat_name,$pic_desc,'Material Safe...',$c_at)); } $statement = $pdo->prepare("UPDATE tbl_no_of_box SET status=?, notes=? WHERE id=?"); $statement->execute(array($s_stat_id,$pic_desc,$ship_id)); $statement = $pdo->prepare("SELECT * FROM `tbl_no_of_box` WHERE pickup_entry_id=$pickup_entry_id GROUP by status"); $statement->execute(); $total_box_status = $statement->rowCount(); $ship_status=1;//1-cmple 0-partial if($total_box_status>1){ $ship_status=0; } $statement = $pdo->prepare("UPDATE pickup_entry SET ship_status=? WHERE id=?"); $statement->execute(array($ship_status,$pickup_entry_id)); } $response['error'] = false; $response['message'] = "Successfully Picked Shipment Box's."; print_r(json_encode($response)); } ?>