ok
Direktori : /home2/selectio/public_html/obnovit-tracking/android-api/old/ |
Current File : /home2/selectio/public_html/obnovit-tracking/android-api/old/customer.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-customer 2. get-customers 3. update-customer 4. delete-customer ------------------------------------------- */ /*add-customer*/ /*if ((isset($_POST['type'])) && ($_POST['type'] == 'add_customer')){ try{ $branch_id = (isset($_POST['branch_id'])) ? $fn->xss_clean($_POST['branch_id']) : "0"; $customer_name = (isset($_POST['customer_name'])) ? $fn->xss_clean($_POST['customer_name']) : ""; $father_husband_name = (isset($_POST['father_husband_name'])) ? $fn->xss_clean($_POST['father_husband_name']) : ""; $dob = (isset($_POST['dob'])) ? $fn->xss_clean($_POST['dob']) : ""; $gender = (isset($_POST['gender'])) ? $fn->xss_clean($_POST['gender']) : ""; $mobile = (isset($_POST['mobile'])) ? $fn->xss_clean($_POST['mobile']) : ""; $email = (isset($_POST['email'])) ? $fn->xss_clean($_POST['email']) : ""; $address = (isset($_POST['address'])) ? $fn->xss_clean($_POST['address']) : ""; $nominee_address = (isset($_POST['nominee_address'])) ? $fn->xss_clean($_POST['nominee_address']) : ""; $id_proof_type = (isset($_POST['id_proof_type'])) ? $fn->xss_clean($_POST['id_proof_type']) : ""; $id_proof_number = (isset($_POST['id_proof_number'])) ? $fn->xss_clean($_POST['id_proof_number']) : ""; $dob = date("Y-m-d", strtotime($dob)); $statement = $pdo->prepare("SELECT max(id) FROM customer_details"); $statement->execute(); $results = $statement->fetchAll(PDO::FETCH_ASSOC); foreach($results as $row){ $last_id=$row["max(id)"]; } $curr_id=$last_id+1; $str=sprintf("%03d",$curr_id); $str1="SLJ"; $user_id=$str1.$str; $statement = $pdo->prepare("INSERT INTO `customer_details`(`user_id`, `customer_name`, `fathers_name`, `dob`, `gender`, `mobile_number`, `email_id`, `proof_type`, `proof_number`, `proof_image`, `customer_address`, `nominee_address`, `emp_id`, `e_id`, `branch_id`, `delete_status`) VALUES ('$user_id','$customer_name','$father_husband_name','$dob','$gender','$mobile','$email','$id_proof_type','$id_proof_number','','$address','$nominee_address','$emp_id','$id','$branch_id','1')"); $result=$statement->execute(); if($result){ $response["error"] = false; $response["message"] = "customer added successfully!"; } else { $response["error"] = true; $response["message"] = "This mobile $mobile is already registered. Please try another mobile number!"; } print_r(json_encode($response)); } catch(exception $e) { $response["error"] = true; $response["message"] = $e; print_r(json_encode($response)); } }*/ /*get_customers accesskey:lalitha type:get_customers 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_customers')){ $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'])) : 'cust_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 tc.cust_code like '%" . $search . "%' OR tc.cust_name like '%" . $search . "%'"; } $statement = $pdo->prepare("SELECT COUNT(tc.cust_id) as total FROM `tbl_customer` tc INNER JOIN tbl_user tu on tc.client_id=tu.id INNER JOIN tbl_branch tb on tu.branch_id=tb.id where tc.cust_type='regular' " . $where); $statement->execute(); $res = $statement->fetchAll(PDO::FETCH_ASSOC); if (!empty($res)) { foreach ($res as $row) $total = $row['total']; $statement = $pdo->prepare("SELECT tc.*,tu.full_name as client_name,tb.branch_name FROM `tbl_customer` tc INNER JOIN tbl_user tu on tc.client_id=tu.id INNER JOIN tbl_branch tb on tu.branch_id=tb.id where tc.cust_type='regular' " . $where . " ORDER BY `" . $sort . "` " . $order . " LIMIT " . $offset . ", " . $limit); $statement->execute(); $res = $statement->fetchAll(PDO::FETCH_ASSOC); $rows = array(); $tempRow = array(); foreach ($res as $row) { $tempRow['cust_id'] = $row['cust_id']; $tempRow['branch_name'] = $row['branch_name']; $tempRow['client_name'] = $row['client_name']; $tempRow['cust_name'] = $row['cust_name']; $tempRow['cust_code'] = $row['cust_code']; $tempRow['cust_city'] = $row['cust_city']; $tempRow['cust_zip'] = $row['cust_zip']; $tempRow['cust_phone'] = substr($row['cust_phone'],0,10); $tempRow['cust_address'] = $row['cust_address']; $tempRow['destination_city'] = $row['destination_city']; $rows[] = $tempRow; } $response['error'] = false; $response['message'] = "Customers 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)); } /*if ((isset($_POST['type'])) && ($_POST['type'] == 'search_customers')){ $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 .= " Where `user_id` like '%" . $search . "%' OR `customer_name` like '%" . $search . "%' "; } $statement = $pdo->prepare("SELECT COUNT(id) as total FROM `customer_details` " . $where); $statement->execute(); $res = $statement->fetchAll(PDO::FETCH_ASSOC); if (!empty($res)) { foreach ($res as $row) $total = $row['total']; $statement = $pdo->prepare("SELECT cd.*,bd.name as branch_name from customer_details cd INNER JOIN branch_details bd on cd.branch_id=bd.id " . $where . " ORDER BY `" . $sort . "` " . $order . " LIMIT " . $offset . ", " . $limit); $statement->execute(); $res = $statement->fetchAll(PDO::FETCH_ASSOC); $rows = array(); $tempRow = array(); foreach ($res as $row) { $tempRow['id'] = $row['id']; $tempRow['user_id'] = $row['user_id']; $tempRow['customer_name'] = $row['customer_name']; $tempRow['mobile_number'] = $row['mobile_number']; $tempRow['dob'] = $row['dob']; $tempRow['customer_address'] = $row['customer_address']; $tempRow['branch_name'] = $row['branch_name']; $rows[] = $tempRow; } $response['error'] = false; $response['message'] = "Customers 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)); }*/ ?>