File manager - Edit - /home/autoph/public_html/data03252025consolidation/src/Controllers/Customer_update.php
Back
<?php namespace App\Controllers; use App\Core\Controller; use App\Core\Database; // use App\Core\Sms; // use App\Utilities\Session; // use App\Utilities\Uuid; use App\Utilities\Utility; // use App\Controllers\Customer; // include_once("Customer.php"); // include_once("../../api/controllers/customer.php"); // token =b0JCRy9CcUZEOFhrV1ErSE9CTW5IVmR2YkZZNDJaeS8xSU9jNkJjczJMWT0= // Utility::str_encrypt('28D4DE7C6AFD6'); // Utility::str_decrypt('b0JCRy9CcUZEOFhrV1ErSE9CTW5IVmR2YkZZNDJaeS8xSU9jNkJjczJMWT0='); define('API_TOKEN', 'b0JCRy9CcUZEOFhrV1ErSE9CTW5IVmR2YkZZNDJaeS8xSU9jNkJjczJMWT0='); // Check if token is provided and valid if (!isset($_REQUEST['token']) || $_REQUEST['token'] !== API_TOKEN) { http_response_code(401); // Unauthorized echo json_encode(array("error" => "Unauthorized")); exit; } class Customer_update extends Controller { private $customer; public function test() { echo Utility::str_encrypt('autohubgroupAppDev0406224'); } function __construct() { // $this->lto = new \App\Models\Lto; // include_once(__DIR__ . '/Customer.php'); // $this->customer = new Customer; // $this->dealer = new \App\Models\Dealer; } public function cu_profile() { $customer_id = isset($_REQUEST['customer_id']) ? $_REQUEST['customer_id'] : '-1'; // $customer_profile = $this->customer->read_customer_profile_display($customer_id, $granted_company_ids, Database::connectDB()); // var_dump($customer_profile); $query_customer_info = "SELECT DATE_FORMAT(ci.date_modified, '%M %d, %Y - %h:%i:%s %p') AS date_modified, em.first_name AS emfname, em.middle_name AS emmname, em.last_name AS emlname, ci.id, ci.corporation_id,snob.name as profession ,sr.name as religion, ci.corporation_name,ci.first_name, ci.middle_name, ci.last_name, g.gender_name, DATE_FORMAT(ci.date_created, '%M %d, %Y') AS date_created, cc.email_1, cc.email_2, cc.email_3, cc.mobile_phone_1, cc.mobile_phone_2,cc.mobile_phone_3, cc.residential_phone, cc.fax_phone, cc.business_phone, cc.landline, sx.suffix_name AS suffix, ac.nationality, ci.no_of_children, ci.occupation, ams.name AS marital_status, DATE_FORMAT(ci.date_of_birth, '%M %d, %Y') AS birthdate,ci.contact_person, ci.time_created, cc.address_1, cc.address_2, acity1.citymunDesc AS address_1_city, sc.code AS source_company, sd.code AS source_dealer, sdms.name AS source_dms, acity2.citymunDesc AS address_2_city, cc.address_1_postal, cc.address_2_postal, ci.photo, ci.spouse_name, DATE_FORMAT(ci.date_uploaded, '%M %d, %Y - %h:%i:%s %p') AS date_uploaded, e.first_name AS efname, e.middle_name AS emname, e.last_name AS elname, TIMESTAMPDIFF(YEAR,ci.date_of_birth, CURDATE()) as age_number , ci.type, cc.viber, cc.facebook, cc.instagram, cc.whatsapp, cc.telegram, cc.website,snb.name as nature_of_business, ( IF( ci.category_id <> 0,ccat.name, IF( COUNT(se.id) > 0 && COUNT(s.id) < 1, 'SVO', IF( COUNT(se.id) < 1 && COUNT(s.id) > 0, 'SAO', IF( COUNT(v.id) = 1 && COUNT(se.id) > 0 && COUNT(s.id) > 0, 'LYL', IF( COUNT(v.id) > 1 && COUNT(v.id) < 4, 'SLY', IF( COUNT(v.id) > 3, 'VIP','None'/*VVIP*/ ) ) ) ) ) ) ) as customer_category, IF( (SELECT DATEDIFF(NOW(),se.start_date_of_service) <= 365) || (SELECT DATEDIFF(NOW(),s.activity_date) <= 365) , '1','2' ) as isActive, smoc.name as mode_of_contact, sct.name as customer_type, ci.aha_status FROM inactive_customer ci LEFT OUTER JOIN customer_category ccat ON ci.category_id = ccat.id LEFT OUTER JOIN source_profession snob ON ci.profession_id=snob.id LEFT OUTER JOIN source_nature_of_business snb ON ci.nature_of_business_id=snb.id LEFT OUTER JOIN source_religion sr ON ci.religion_id = sr.id LEFT OUTER JOIN all_gender g ON ci.gender_id=g.id LEFT OUTER JOIN customer_contact cc ON ci.id=cc.customer_id LEFT OUTER JOIN all_suffix sx ON ci.suffix_id=sx.id LEFT OUTER JOIN all_countries ac ON ci.nationality_id=ac.num_code LEFT OUTER JOIN all_marital_status ams ON ci.marital_status_id=ams.id LEFT OUTER JOIN employee e ON ci.upload_by=e.id LEFT OUTER JOIN employee em ON ci.modified_by=em.id LEFT OUTER JOIN customer_dms cd ON ci.id=cd.customer_record_id LEFT OUTER JOIN source_company_dealer scd ON cd.company_dealer_id=scd.id LEFT OUTER JOIN source_company sc ON scd.company_id=sc.id LEFT OUTER JOIN source_dms sdms ON sc.dms_id=sdms.id LEFT OUTER JOIN source_dealer sd ON scd.dealer_id=sd.id LEFT OUTER JOIN all_city acity1 ON cc.address_1_city=acity1.id LEFT OUTER JOIN all_city acity2 ON cc.address_2_city=acity2.id LEFT OUTER JOIN source_customer_type sct ON ci.type=sct.id LEFT OUTER JOIN vehicle v ON ci.id = v.customer_record_id LEFT OUTER JOIN sales s ON v.id = s.vehicle_id LEFT OUTER JOIN service se ON v.id = se.vehicle_id LEFT OUTER JOIN source_mode_of_contact smoc ON cc.mode_of_contact_id = smoc.id WHERE ci.id='$customer_id' ORDER BY ci.id ASC LIMIT 1"; //echo $query_customer_info; return; $involvements = "SELECT sd.name AS dms, sc.code AS company, sdr.code AS dealer FROM `customer_dms` cd LEFT OUTER JOIN source_company_dealer scd ON cd.company_dealer_id = scd.id LEFT OUTER JOIN source_company sc ON sc.id = scd.company_id LEFT OUTER JOIN source_dms sd ON sc.`dms_id` = sd.id LEFT OUTER JOIN source_dealer sdr ON sdr.id = scd.dealer_id WHERE `customer_record_id` IN ('$customer_id')";//" AND sc.id IN (" . $granted_company_ids . ") "; // echo $query_customer_info; // return; $customer_info = Database::return_result($query_customer_info); $suffix = ""; $in = Database::return_result($involvements); //echo $involvements; return; $dms = array(); $company = array(); $dealer = array(); foreach ($in as $data1) { $dms = array_merge($dms, array($data1['dms'])); $company = array_merge($company, array($data1['company'])); $dealer = array_merge($dealer, array($data1['dealer'])); } $dms_new = array_unique($dms); $company_new = array_unique($company); $dealer_new = array_unique($dealer); $list_dms = implode(', ', $dms_new); $list_company = implode(', ', $company_new); $list_dealer = implode(', ', $dealer_new); foreach ($customer_info as $data) { if (intval($data['corporation_id']) <= 0) { $customer_corporation_name = ''; } else { $customer_corporation_name = Database::connectDB()->select("SELECT corporation_name FROM customer WHERE id = '" . $data['corporation_id'] . "' AND status = 1"); } if ($data['suffix'] == "None") { $suffix = ""; } else { $suffix = " " . $data['suffix']; } $get_image_query = "SELECT vi.name FROM vehicle v INNER JOIN vehicle_images vi ON v.id = vi.vehicle_id INNER JOIN source_company_dealer scd ON v.company_dealer_id = scd.id WHERE 1 AND v.customer_record_id ='" . $data['id'] . "' AND scd.company_id IN (" . $granted_company_ids . ") AND vi.name <> 'default.png' AND vi.status <> 0 AND v.status <> 0 ORDER BY v.id DESC LIMIT 1"; // echo $get_image_query; $get_image_name = Database::select2($get_image_query); if ($get_image_name <> '') { $data['photo'] = $get_image_name; } $arr['photo'] = $data['photo']; if (intval($data['type']) === 1) { $arr['main_corporation_name'] = ''; $arr['full_name'] = $data['first_name'] . " " . $data['middle_name'] . " " . $data['last_name'] . " " . $suffix; $arr['main_first_name'] = $data['first_name']; $arr['main_middle_name'] = $data['middle_name']; $arr['main_last_name'] = $data['last_name']; $arr['suffix'] = $suffix; } else { $arr['main_corporation_name'] = $data['corporation_name']; $arr['full_name'] = ''; $arr['main_first_name'] = ''; $arr['main_middle_name'] = ''; $arr['main_last_name'] = ''; $arr['suffix'] = ''; } $arr['customer_record_id'] = $data['id']; $arr['main_email'] = $data['email_1']; $arr['main_customer_email_2'] = $data['email_2'] .(strlen($data['email_3'])>0 ? ', '.$data['email_3'] : ''); // $arr['main_customer_email_3'] = $data['email_3']; $arr['information_religion'] = $data['religion']; $arr['main_customer_mobile'] = $data['mobile_phone_1']; $arr['main_customer_landline'] = $data['landline']; $arr['main_customer_mobile_2'] = $data['mobile_phone_2'].(strlen($data['mobile_phone_3'])>0 ? ', '.$data['mobile_phone_3'] : ''); // $arr['main_customer_mobile_3'] = $data['mobile_phone_3']; $arr['main_customer_home_mobile'] = $data['residential_phone']; $arr['fax_phone'] = $data['fax_phone']; $arr['main_customer_business_mobile'] = $data['business_phone']; $arr['information_gender'] = $data['gender_name']; $arr['information_date_created'] = $data['date_created']; // $arr['information_dob'] = $data['birthdate']; // $arr['information_nationality'] = $data['nationality']; $arr['no_of_children'] = $data['no_of_children']; $arr['information_age'] = $data['age_number']; $arr['information_position'] = $data['occupation']; $arr['information_marital_status'] = $data['marital_status']; $arr['information_spouse'] = $data['spouse_name']; $arr['contact_person'] = $data['contact_person']; $arr['time_created'] = $data['time_created']; $arr['information_source_company'] = $data['source_company']; $arr['information_source_dealer'] = $data['source_dealer']; $arr['information_source_dms'] = $data['source_dms']; $arr['main_address_1'] = $data['address_1']; $arr['main_address_2'] = $data['address_2']; $arr['main_city_1'] = $data['address_1_city']; $arr['main_city_2'] = $data['address_2_city']; $arr['main_postal_1'] = $data['address_1_postal']; $arr['main_postal_2'] = $data['address_2_postal']; $arr['main_customer_address_1'] = $arr['main_address_1'] . ' ' . $arr['main_city_1'] . ' ' . $arr['main_postal_1']; $arr['main_customer_address_2'] = $arr['main_address_2'] . ' ' . $arr['main_city_2'] . ' ' . $arr['main_postal_2']; $arr['information_uploaded_by'] = $data['efname'] . " " . $data['elname']; $arr['information_date_uploaded'] = $data['date_uploaded']; $arr['information_modified_by'] = $data['emfname'] . " " . $data['emlname']; $arr['information_date_modified'] = $data['date_modified']; $arr['customer_type'] = (intval($data['type']) === 1) ? 'Individual' : 'Corporation'; $arr['main_customer_type'] = $data['customer_type']; $arr['customer_type_id'] = $data['type']; $arr['main_category'] = $data['customer_category']; $arr['main_customer_status'] = (intval($data['isActive']) == 1 ? 'Active' : 'Inactive'); $arr['main_customer_aha_status'] = (intval($data['aha_status']) == 1 ? 'Registered' : 'Not Registered'); $arr['main_customer_moc'] = $data['mode_of_contact']; $arr['main_facebook'] = $data['facebook']; $arr['main_instagram'] = $data['instagram']; $arr['main_viber'] = $data['viber']; $arr['main_telegram'] = $data['telegram']; $arr['main_whatsapp'] = $data['whatsapp']; $arr['main_website_link'] = $data['website']; $arr['information_business_company_name'] = $customer_corporation_name; $arr['information_profession'] = $data['profession']; $arr['information_nature_of_work_business'] = $data['nature_of_business']; } $get_image_query = "SELECT si.name FROM sales s INNER JOIN vehicle_images si ON s.id = si.sales_id INNER JOIN vehicle v ON s.vehicle_id = v.id INNER JOIN source_company_dealer scd ON s.company_dealer_id = scd.id WHERE 1 AND v.customer_record_id ='$customer_id' AND si.name <> 'default.png' AND vi.status <> 0 ORDER BY s.date_uploaded DESC LIMIT 1"; // echo $get_image_query; $get_image_name = Database::select2($get_image_query); if ($get_image_name <> '') { $arr['photo'] = $get_image_name; } $arr['information_dms_list'] = $list_dms; $arr['information_company_list'] = $list_company; $arr['information_dealer_list'] = $list_dealer; return response()->json($arr); } function isNotEmpty($data) { return preg_match('/\S/', $data); } public function index(){ $user_dealer_id = $_REQUEST['dealer_id']; $user_employee_id = $_REQUEST['employee_id']; $search = $_REQUEST['search']; $type = (isset($_REQUEST['type']) && $_REQUEST['type'] != '0') ? " AND t1.type = '".$_REQUEST['type']."' " : "" ; if($this->isNotEmpty($search)){ $filter_email = " OR cc.email_1 = '".$search."' "; }else{ $filter_email = ""; } $type =($this->isNotEmpty($search) ? " AND t1.type ='".$search."' " :''); $gender=''; // $dms=''; $age=''; $complete_data=''; $incomplete_data=''; $mobile_phone_1=''; $address_1=''; $date_of_birth=''; $company=''; $my_record =''; $group_by=''; $customer_actions = "" ; if(isset($_REQUEST['customer_actions']) && $_REQUEST['customer_actions'] != '0'){ switch($_REQUEST['customer_actions']){ case "all": $customer_actions = ""; break; case "new": $customer_actions = " AND t1.date_uploaded > DATE_SUB(NOW(), INTERVAL 1 WEEK) "; break; case "updated": $customer_actions = " AND t1.date_modified > DATE_SUB(NOW(), INTERVAL 1 WEEK) "; break; case "added": $customer_actions = " AND t1.date_uploaded > DATE_SUB(NOW(), INTERVAL 1 DAY) "; break; } } // $my_record =($this->isNotEmpty($search) ? " AND t1.type ='".$search."' " :'') $group_by =''; $offset_limit ='';//" LIMIT 100" $query = " SELECT DISTINCT %s FROM inactive_customer t1 /*INNER JOIN cu_assign ON t1.id =cu_assign.customer_id INNER JOIN cu_dealer_users_assign cdua ON t1.id = cdua.customer_id */ RIGHT JOIN cu_dealer_users_assign cdua ON t1.id = cdua.customer_id INNER JOIN customer_contact cc ON t1.id = cc.customer_id INNER JOIN customer_dms cd ON t1.id = cd.customer_record_id INNER JOIN source_company_dealer scd ON cd.company_dealer_id = scd.id INNER JOIN source_company sc ON scd.company_id = sc.id INNER JOIN source_dms sd ON sc.dms_id = sd.id LEFT OUTER JOIN all_suffix ass ON t1.suffix_id = ass.id LEFT OUTER JOIN vehicle v ON t1.id = v.customer_record_id LEFT OUTER JOIN sales s ON v.id = s.vehicle_id LEFT OUTER JOIN service se ON v.id = se.vehicle_id WHERE cdua.user_id='$user_employee_id' AND cdua.dealer_id ='$user_dealer_id' AND cdua.is_removed=0 AND ( (CONCAT('', CONCAT( t1.corporation_name, ' ', t1.first_name, ' ', t1.last_name , ' ', t1.first_name, ' ', t1.middle_name, ' ', t1.last_name ),' ', CONCAT('0',SUBSTRING(cc.mobile_phone_1, 4) ), ' ', cc.mobile_phone_1,' ',cd.customer_dms_id) LIKE '%%%s%%' /* 1 search */ ) %s /* email */ %s /* 3 gender */ ) %s /* 2 type */ ORDER BY t1.id DESC "; // } $fields = " t1.id, t1.photo, IF(t1.type = 1, concat(t1.first_name,' ',t1.middle_name,' ',t1.last_name) ,t1.corporation_name ) as name, t1.gender_id, (SELECT gender_name FROM all_gender WHERE id=t1.gender_id) as gender_name, t1.date_of_birth, t1.date_uploaded, t1.date_created, TIMESTAMPDIFF(YEAR,t1.date_of_birth, CURDATE()) as age_number, cc.mobile_phone_1, cc.landline, cc.email_1, cc.address_1, CASE WHEN t1.type =1 THEN 'Corporation' WHEN t1.type =2 THEN 'Individual' END as type, t1.date_modified, t1.is_active, (SELECT DATEDIFF(NOW(),t1.date_modified)) as last_date_modified"; $count = " 1 "; $final_query = sprintf( $query, $fields, $search, $filter_email, $gender, $type, );//." $offset_limit"; $exec_query = Database::connect()->runBaseQuery($final_query);//Database::connect()->query($final_query); // echo $final_query;exit; // http_response_code(200); return response()->json($exec_query); } public function setStatus(){ $customer_id = $_REQUEST['customer_id']; $set_active_status = $_REQUEST['status']; // echo $customer_id.' '.$set_active_status;exit; $new_status = ($set_active_status == 1 ? 'Active' : 'Inactive'); $query_old = "SELECT is_active,first_name,middle_name,last_name FROM inactive_customer WHERE id=".$customer_id; $result = Database::connectDB()->query($query_old); // var_dump($result->num_rows); $full_name =''; if($result->num_rows == 1) { foreach($result as $row) { $is_active_status = $row['is_active']; $old_status = ($row['is_active'] == 0 ? 'Inactive' : 'Active'); $full_name = $row['first_name'].(strlen($row['middle_name'])>0 ? ' '.$row['middle_name'].' ' :' ').$row['last_name']; } unset($row); $log_set_active_customer = ($is_active_status == $set_active_status) ? '' : "[Customer status: " . $old_status . " to " . $new_status."]\n"; $log_desc = "Update customer: [ID:" . $customer_id . ", " . $full_name . "]".$log_set_active_customer."\n"; $id = $_SESSION['user']['id']; $code ='update_customer'; // echo $full_name;exit; try{ // ); Database::connectDB()->begin_transaction(); $update = Database::connectDB()->query("UPDATE inactive_customer SET is_active =".$set_active_status." WHERE id=".$customer_id); if(Database::connectDB()->query("INSERT INTO `all_activity_log`(`description`,`owner_id`,`target_id`,`code`) VALUES ('$log_desc',NULLIF('$id',''),'$customer_id','$code')") && $update){ Database::connectDB()->commit(); http_response_code(201); return response()->json(['msg'=>'Record successfully updated.','status'=>201]); // echo '{"msg" :"Record successfully updated.","status":1}'; }else{ // http_response_code(304); Database::connectDB()->rollback(); return response()->json(['msg'=>'Unable to create logs','status'=>304]); // echo '{"msg" :"Unable to create logs ","status":0}';exit; } }catch (\Throwable $e) { Database::connectDB()->rollback(); // http_response_code(304); return response()->json(['msg'=>'Unable to create logs'. $e ,'status'=>304]); // '{"msg" :"Unable to create logs "'.$e.',"status":0}';exit; } } } public function update() { if(isset($_REQUEST['customer_id']) && strlen($_REQUEST['customer_id'])>0) { $customer_id = $_REQUEST['customer_id']; $find_query = $this->read_customer_info_and_contact($customer_id); // var_dump($find_query);exit; // $find_query = $this->read_customer_profile_edit($customer_id); // $customer_info = json_decode($find_query,true); $customer_info =$find_query; // var_dump($customer_info);exit; $old_info_array=[]; $now = date('Y-m-d h:i:s'); if($customer_info->num_rows ===1) // if(is_array($customer_info) && count($customer_info)===1) { foreach ($customer_info as $old_info) { $old_info_array = $old_info; }unset($old_info); // echo'<pre>';print_r($old_info_array);echo'</pre>';exit; //customer info in customer and incative customer table $corporation_name = (isset($_REQUEST['corporation_name']) ? $_REQUEST['corporation_name'] : $old_info_array['corporation_name']); $first_name = (isset($_REQUEST['first_name']) ? $_REQUEST['first_name'] : $old_info_array['first_name']); $middle_name = (isset($_REQUEST['middle_name']) ? $_REQUEST['middle_name'] : $old_info_array['middle_name']); $last_name = (isset($_REQUEST['last_name']) ? $_REQUEST['last_name'] : $old_info_array['last_name']); $suffix_id = (isset($_REQUEST['suffix_id']) ? $_REQUEST['suffix_id'] : $old_info_array['suffix_id']); $gender_id = (isset($_REQUEST['gender_id']) ? $_REQUEST['gender_id'] : $old_info_array['gender_id']); $nationality_id = (isset($_REQUEST['nationality_id']) ? $_REQUEST['nationality_id'] : $old_info_array['nationality_id'] ); $date_of_birth = $_REQUEST['date_of_birth']; $marital_status_id = (isset($_REQUEST['marital_status_id']) ? $_REQUEST['marital_status_id'] : $old_info_array['marital_status_id']); $source_id = (isset($_REQUEST['source_id']) ? $_REQUEST['source_id'] : $old_info_array['source_id']); $mode_of_contact_id = (isset($_REQUEST['mode_of_contact_id']) ? $_REQUEST['mode_of_contact_id'] : $old_info_array['mode_of_contact_id']); $spouse_name = (isset($_REQUEST['spouse_name']) ? $_REQUEST['spouse_name'] : $old_info_array['spouse_name']); $no_of_children = (isset($_REQUEST['no_of_children']) ? $_REQUEST['no_of_children'] : $old_info_array['no_of_children']); $occupation = (isset($_REQUEST['occupation']) ? $_REQUEST['occupation'] : $old_info_array['occupation']); $contact_person = (isset($_REQUEST['contact_person']) ? $_REQUEST['contact_person'] : $old_info_array['contact_person']); $modified_by = (isset($_REQUEST['modified_by']) ? $_REQUEST['modified_by'] : $old_info_array['modified_by']); //employee id in employee id autoph_db $date_modified = $now; $customer_type = (isset($_REQUEST['type']) ? $_REQUEST['type'] : $old_info_array['type']); $category_id = (isset($_REQUEST['category_id']) ? $_REQUEST['category_id'] : $old_info_array['category_id']); $religion_id = (isset($_REQUEST['religion_id']) ? $_REQUEST['religion_id'] : $old_info_array['religion_id']); $corporation_id = (isset($_REQUEST['corporation_id']) ? $_REQUEST['corporation_id'] : $old_info_array['corporation_id']); $profession_id = (isset($_REQUEST['profession_id']) ? $_REQUEST['profession_id'] : $old_info_array['profession_id']); $nature_of_business_id = (isset($_REQUEST['nature_of_business_id']) ? $_REQUEST['nature_of_business_id'] : $old_info_array['nature_of_business_id']); $aha_status = (isset($_REQUEST['aha_status']) && $_REQUEST['aha_status']!=NULL && strlen($_REQUEST['aha_status'])>0 ? $_REQUEST['aha_status'] : $old_info_array['aha_status']); $status= (isset($_REQUEST['status']) ? $_REQUEST['status'] : $old_info_array['status']); //customer contact info $address_1 = (isset($_REQUEST['address_1']) ? $_REQUEST['address_1'] : $old_info_array['address_1']); $address_2 = (isset($_REQUEST['address_2']) ? $_REQUEST['address_2'] : $old_info_array['address_2']); $address_1_city= (isset($_REQUEST['address_1_city']) ? $_REQUEST['address_1_city'] : $old_info_array['address_1_city']); $address_2_city= (isset($_REQUEST['address_2_city']) ? $_REQUEST['address_2_city'] : $old_info_array['address_2_city']); $address_1_postal =(isset($_REQUEST['address_1_postal']) ? $_REQUEST['address_1_postal'] : $old_info_array['address_1_postal']) ; $address_2_postal = (isset($_REQUEST['address_2_postal']) ? $_REQUEST['address_2_postal'] : $old_info_array['address_2_postal']); $email_1 = (isset($_REQUEST['email_1']) ? $_REQUEST['email_1'] : $old_info_array['email_1']); $email_2 = (isset($_REQUEST['email_2']) ? $_REQUEST['email_2'] : $old_info_array['email_2']); $email_3 = (isset($_REQUEST['email_3']) ? $_REQUEST['email_3'] : $old_info_array['email_3']); $viber = (isset($_REQUEST['viber']) ? $_REQUEST['viber'] : $old_info_array['viber']); $facebook = (isset($_REQUEST['facebook']) ? $_REQUEST['facebook'] : $old_info_array['facebook']); $instagram = (isset($_REQUEST['instagram']) ? $_REQUEST['instagram'] : $old_info_array['instagram']); $telegram = (isset($_REQUEST['telegram']) ? $_REQUEST['telegram'] : $old_info_array['telegram']); $whatsapp = (isset($_REQUEST['whatsapp']) ? $_REQUEST['whatsapp'] : $old_info_array['whatsapp']); // $other_social = (isset($_REQUEST['other_social']) ? $_REQUEST['other_social'] : $old_info_array['other_social']); $business_phone = (isset($_REQUEST['business_phone']) ? $_REQUEST['business_phone'] : $old_info_array['business_phone']); $website = (isset($_REQUEST['website']) ? $_REQUEST['website'] : $old_info_array['website']); // $mobile_phone_1 = (isset($_REQUEST['mobile_phone_1']) ? $_REQUEST['mobile_phone_1'] : $old_info_array['mobile_phone_1']); $mobile_phone_2 =(isset($_REQUEST['mobile_phone_2']) && !empty($_REQUEST['mobile_phone_2']) ? $this->transform_mobile($_REQUEST['mobile_phone_2']) : $old_info_array['mobile_phone_2']); $mobile_phone_3 = (isset($_REQUEST['mobile_phone_3']) && !empty($_REQUEST['mobile_phone_2']) ? $this->transform_mobile($_REQUEST['mobile_phone_3']) : $old_info_array['mobile_phone_3']); $landline = (isset($_REQUEST['landline']) ? $_REQUEST['landline'] : $old_info_array['landline']); $residential_phone = (isset($_REQUEST['residential_phone']) ? $_REQUEST['residential_phone'] : $old_info_array['residential_phone']); // if(strlen($mobile_phone_2) ==11 && substr($mobile_phone_2, 0,1) ==0) // { // $ten_digits = substr($mobile_phone_2, 1,10); // $transform_zero = str_replace("0","+63",substr($mobile_phone_2, 0,1)); // $mobile_phone_2 = $transform_zero.$ten_digits; // } ///Customer interest //category id - customer_interest table //customer_interest_content sub table //customer_interest_list - main table $query_interest = "select id,interest_id from customer_interest_list where customer_id=".$customer_id; $categoryID =null; $customer_interest_list_id = null; $n=Database::connectDB()->query($query_interest); if($n->num_rows > 0) { foreach($n as $introw){ $customer_interest_list_id = $introw['id']; $interest_content = Database::connectDB()->query("SELECT id,interest_id,name FROM customer_interest_content WHERE id =".$introw['interest_id']); foreach($interest_content as $content) { $category_id = $content['interest_id']; $cu_interest = Database::connectDB()->query("SELECT id,name FROM customer_interest WHERE id=".$category_id); if($cu_interest->num_rows ===1) { foreach($cu_interest as $category) { $categoryID = $category['id']; } } } } } //CONTACT PERSON //customer_contact_person - main table $query_contact_info = "UPDATE `customer_contact` SET `customer_id`='$customer_id', `address_1`='$address_1', `address_2`='$address_2', `address_1_state`='$address_1_state', `address_2_state`='$address_2_state', `address_1_city`='$address_1_city', `address_2_city`='$address_2_city', `address_1_postal`='$address_1_postal', `address_2_postal`='$address_2_postal', -- `email_1`='$email_1', `email_2`='$email_2', `email_3`='$email_3', `viber`='$viber', `facebook`='$facebook', `instagram`='$instagram', `telegram`='$telegram', `whatsapp`='$whatsapp', -- `other_social`='$other_social', `website`='$website', `business_phone`='$business_phone', -- `fax_phone`='$fax_phone', -- `mobile_phone_1`='$mobile_phone_1', `mobile_phone_2`='$mobile_phone_2', `mobile_phone_3`='$mobile_phone_3', `landline`= '$landline', `residential_phone`='$residential_phone', `date_modified`='$now', `mode_of_contact_id`='$mode_of_contact_id' -- `status`='$status' WHERE `customer_id` = '$customer_id' "; $query_main = "UPDATE `customer` SET `corporation_name`='$corporation_name', `salutation_id`='$salutation_id', `first_name`='$first_name', `middle_name`='$middle_name', `last_name`='$last_name', `suffix_id`='$suffix_id', `gender_id`='$gender_id', `nationality_id`='$nationality_id', `date_of_birth`='$date_of_birth', `marital_status_id`='$marital_status_id', -- `source_id`='$source_id', `mode_of_contact_id`='$mode_of_contact_id', `spouse_name`='$spouse_name', `no_of_children`='', `occupation`='$occupation', `contact_person`='', `modified_by`='$modified_by', `date_modified`= '$now', `type`='$customer_type', `category_id`='$category_id', `religion_id`='$religion_id', `corporation_id`='$corporation_id', `profession_id`='$profession_id', `nature_of_business_id`='$nature_of_business_id', `aha_status` = '$aha_status', `status`='$status' WHERE id = '$customer_id' "; //CUSTOMER UPDATE- INACTIVE TABLE $query_cu = "UPDATE `inactive_customer` SET `id`='$customer_id', `corporation_name`='$corporation_name', `salutation_id`='$salutation_id', `first_name`='$first_name', `middle_name`='$middle_name', `last_name`='$last_name', `suffix_id`='$suffix_id', `gender_id`='$gender_id', `nationality_id`='$nationality_id', `date_of_birth`='$date_of_birth', `marital_status_id`='$marital_status_id', -- `source_id`='$source_id', `mode_of_contact_id`='$mode_of_contact_id', `spouse_name`='$spouse_name', `no_of_children`='', `occupation`='$occupation', `contact_person`='', `modified_by`='$modified_by', `date_modified`= NOW(), `type`='$customer_type', `category_id`='$category_id', `religion_id`='$religion_id', `corporation_id`='$corporation_id', `profession_id`='$profession_id', `nature_of_business_id`='$nature_of_business_id', `aha_status` = '$aha_status', `status`='$status' WHERE id = '$customer_id' "; // var_dump($mobile_phone_1); // $mobile_phone_1 = (($this->isNotEmpty($mobile_phone_1)) ? '+63'.$mobile_phone_1 : ''); // var_dump($mobile_phone_1); $mobile_phone_2 = (($this->isNotEmpty($mobile_phone_2)) ? '+63'.$mobile_phone_2 : ''); $mobile_phone_3 = (($this->isNotEmpty($mobile_phone_3)) ? '+63'.$mobile_phone_3 : ''); $mobile_info_array = [ $old_info_array['$mobile_phone_1'],$old_info_array['mobile_phone_2'], $old_info_array['$mobile_phone_3']]; $new_mobile_info_array[] =[$mobile_phone_1,$mobile_phone_2,$mobile_phone_3]; // echo'<pre>';print_r($new_mobile_info_array);echo'<pre>';return; if ($customer_type == 1) { // $old_info_array['mobile_phone_1'] <> $mobile_phone_1 // if(strlen($mobile_phone_1)>0) // { // if($old_info_array['mobile_phone_1'] <> $mobile_phone_1) // { // if ($this->read_customer_mobile_if_exist($mobile_phone_1) > 0) { // return response()->json(['msg'=>'Mobile already registered.' ,'status'=>304]); // } // } // } if(strlen($mobile_phone_2)>0) { if($old_info_array['mobile_phone_2'] <> $mobile_phone_2) { if ($this->read_customer_mobile_if_exist( $mobile_phone_2) > 0) { return response()->json(['msg'=>'Mobile already registered.' ,'status'=>304]); } } } if(strlen($mobile_phone_3)>0) { if($old_info_array['mobile_phone_3'] <> $mobile_phone_3) { if ($this->read_customer_mobile_if_exist($mobile_phone_3) > 0) { return response()->json(['msg'=>'Mobile already registered.' ,'status'=>304]); } } } // if (!in_array($mobile_phone_1,$mobile_info_array) && !in_array($mobile_phone_2,$mobile_info_array) && !in_array($mobile_phone_3,$mobile_info_array)) { // $i=0; // foreach($new_mobile_info_array as $mobile) // { // if ($this->read_customer_mobile_if_exist($new_customer_number) > 0) { // return response()->json(['msg'=>'Mobile already registered.' ,'status'=>304]); // } // } // } if ($this->isNotEmpty($email_1)) { if (strtolower($old_info_array['email_1']) <> strtolower($email_1)) { if ($this->read_customer_email_if_exist($email_1) > 0) { return response()->json(['msg'=>'Email already registered.' ,'status'=>304]); } } } if ($this->isNotEmpty($email_3)) { if (strtolower($old_info_array['email_3']) <> strtolower($email_1)) { if ($this->read_customer_email_if_exist($email_3) > 0) { return response()->json(['msg'=>'Email already registered.' ,'status'=>304]); } } } if ($this->isNotEmpty($email2)) { if (strtolower($old_info_array['email_2']) <> strtolower($email_1)) { if ($this->read_customer_email_if_exist($email_2) > 0) { return response()->json(['msg'=>'Email already registered.' ,'status'=>304]); } } } } if ($customer_type == 1) { $old_name = $old_info_array['first_name'] . ' ' . $old_info_array['middle_name'] . ' ' . $old_info_array['last_name']; $new_name = $first_name . ' ' . $middle_name. ' ' . $last_name; } else if ($customer_type == 2) { $old_name = $old_info_array['corporation_name']; $new_name = $corporation_name; } // echo'<pre>';print_r($old_info_array['first_name']);echo'</pre>'; // var_dump($old_name);var_dump($new_name);exit; $log_desc = "Update customer: "; //modify $log_customer_id ="[ID:" . $customer_id . ", " . $new_name . "]\n"; $log_name = ($old_name == $new_name) ? '' : "[Name: " . $old_name . " to " . $new_name . "]\n"; // $log_mobile = ($old_info_array["mobile_phone_1"] == $mobile_phone_1) ? '' : "[Mobile: " . $old_info_array["mobile_phone_1"] . " to " . $mobile_phone_1 . "]\n"; $log_mobile2 = ($old_info_array['mobile_phone_2'] == $mobile_phone_2 ? '' : '[Other Mobile 1 :'. $old_info_array['mobile_phone_2'].' to '.$mobile_phone_2.']\n'); $log_mobile3 =($old_info_array['mobile_phone_3'] == $mobile_phone_3 ? '' : '[Other Mobile 2 :'. $old_info_array['mobile_phone_3'].' to '.$mobile_phone_3.']\n'); $log_email = ($old_info_array["email_1"] == $email_1) ? '' : "[Email: " . $old_info_array["email_1"] . " to " . $email_1."]\n"; $log_email2 =(strlen($email_2) >0 ? ($old_info_array["email_2"] == $email_2) ? '' : "[Email: " . $old_info_array["email_2"] . " to " . $email_2 . "]\n" :''); $log_email3 =(strlen($email_3) > 0 ? ($old_info_array["email_3"] == $email_3) ? '' : "[Email: " . $old_info_array["email_3"] . " to " . $email_3 . "]\n" : ''); $log_address = ($old_info_array["address_1"] == $address_1) ? '' : "[Address: " . $old_info_array["address_1"] . " to " . $address_1. "]\n"; $log_address2 = ($old_info_array["address_2"] == $address_2) ? '' : "[Other address: " . $old_info_array["address_2"] . " to " . $address_2 . "]\n"; $log_bday = ($old_info_array["date_of_birth"] == date('Y-m-d',strtotime($date_of_birth))) ? '' : "[Birthday: " . $old_info_array["date_of_birth"] . " to " . date('Y-m-d',strtotime($date_of_birth)) . "]\n"; $log_gender = ($old_info_array["gender_id"] == $gender_id) ? '' : "[Gender: " . ($old_info_array["gender_id"]==1 ? 'Male' : 'Female') . " to " . ($gender_id==1 ? 'Male' : 'Female') . "]\n"; $query_log=''; if( strlen($log_name)>0 || strlen($log_mobile)>0 || strlen($log_mobile2)>0 || strlen($log_mobile3)>0 || strlen($log_email)>0 || strlen($log_email2)>0 || strlen($log_email3)>0 || strlen($log_address)>0 || strlen($log_address2)>0 || strlen($log_bday)>0 || strlen($log_gender)>0 ){ //create logs // $employee_id = $_SESSION['user']['id']; $employee_id = 1; $log_description = $log_desc. $log_name. $log_gender. $log_bday. $log_mobile. $log_mobile2. $log_mobile3. $log_email. $log_email2. $log_email3. $log_address. $log_address2; // $create_log =$this->createLog($employee_id,$log_description,$customer_id,'update_customer','api-customer-update'); $query_log ="INSERT INTO `all_activity_log`(`description`,`owner_id`,`target_id`,`code`) VALUES ('$log_description',NULLIF('$employee_id',''),'$customer_id','api-customer-update')"; } // echo $query_log;exit; try{ $this->dbTransaction($query_main,'customer'); $this->dbTransaction($query_cu,'inactive_customer'); $this->dbTransaction($query_contact_info,'customer_contact'); $this->dbTransaction($query_log,'all_activity_log'); // Database::connectDB()->begin_transaction(); // if( Database::connectDB()->query($query_main) && Database::connectDB()->query($query_cu) && Database::connectDB()->query($query_contact_info) && $create_log) // { Database::connectDB()->commit(); return response()->json(['msg'=>'Record successfully updated.' ,'status'=>201]); // } // else // { // Database::connectDB()->rollback(); // return response()->json(['msg'=>'Unable to update record. Please contact system administrator' ,'status'=>304]); // } } catch (\Throwable $e) { Database::connectDB()->rollback(); return response()->json(['msg'=>'Unable to update record. Please contacty system administrator' ,'status'=>304]); } } else { return response()->json(['msg' => 'No data found.','status'=>204]); } } else { // http_response_code(204); return response()->json(['msg' => 'No data found.','status'=>204]); } } private function read_customer_info_and_contact($id) { $customer_info =Database::connectDB()->query("SELECT * FROM `customer` c INNER JOIN customer_contact cc ON c.`id` = cc.customer_id WHERE 1 AND c.id = $id LIMIT 1"); return $customer_info; } private function read_customer_mobile_if_exist($mobile) { $query = "SELECT 1 FROM `customer_contact` cc INNER JOIN customer c ON cc.customer_id = c.id WHERE 1 AND `mobile_phone_1` = '$mobile' OR `mobile_phone_2` = '$mobile' OR `mobile_phone_3` = '$mobile' AND c.type = 1 AND c.status = 1"; return Database::connectDB()->query($query)->num_rows; } private function read_customer_email_if_exist($email) { $query = "SELECT 1 FROM `customer_contact` cc INNER JOIN customer c ON cc.customer_id = c.id WHERE 1 AND cc.`email_1` = '$email' AND c.type = 1 AND c.status = 1"; return Database::connectDB()->query($query)->num_rows; } private function createLog($id,$description,$target_id,$code,$db){ Database::connectDB()->query("INSERT INTO `all_activity_log`(`description`,`owner_id`,`target_id`,`code`) VALUES ('$description',NULLIF('$id',''),'$target_id','$code')"); } private function dbTransaction($query,$table) { if(strlen($query)>0) { if(Database::connectDB()->query($query)) { Database::connectDB()->commit(); } else { return response()->json(['msg'=>'Unable to update record. Please contact system administrator' ,'source table'=>$table,'status'=>304]); Database::connectDB()->rollback(); } } } private function compareValues($value1, $value2) { // Convert both values to strings for comparison $stringValue1 = strval($value1); $stringValue2 = strval($value2); // Compare the string representations of the values if ($stringValue1 === $stringValue2) { return false; // Values are equal } else { return tue; } } private function read_customer_profile_edit($id) { $query_info= Database::connectDB()->query("SELECT c.*,snob.name as nature_of_business_name,sp.name as profession_name FROM `customer` c LEFT OUTER JOIN source_nature_of_business snob ON c.nature_of_business_id = snob.id LEFT OUTER JOIN source_profession sp ON c.profession_id = sp.id WHERE c.`id` = '$id' "); // return $query_info;// json_encode($query); $data=[]; if($query_info->num_rows ===1) { foreach($query_info as $row) { $data[] = $row; } } return json_encode($data); } // private function transform_mobile($mobile_number) // { // // if(strlen($mobile_number) ==11 && substr($mobile_number, 0,1) ==0) // { // $ten_digits = substr($mobile_number, 1,10); // $transform_zero = str_replace("0","+63",substr($mobile_number, 0,1)); // $mobile_number = $transform_zero.$ten_digits; // return $mobile_number; // else // { // return response()->json(['msg'=>'Invalid mobile number.' ,'status'=>304]); // } // } //api collection dropdow public function customer_interest_list(){ $cu_interest = Database::connectDB()->query("SELECT id,name FROM customer_interest WHERE status =1"); $interest_category=[]; foreach($cu_interest as $row) { $interest_category[] = $row; } return response()->json($interest_category); } public function customer_interest_content(){ $cu_interest = Database::connectDB()->query("SELECT id,name FROM customer_interest_content WHERE status =1"); $interest_subcategory=[]; foreach($cu_interest as $row) { $interest_subcategory[] = $row; } return response()->json($interest_subcategory); } public function all_city(){ $all_city = Database::connectDB()->query("SELECT id,citymunDesc FROM all_city WHERE status =1"); $all_citys=[]; foreach($all_city as $row) { $all_citys[] = $row; } return response()->json($all_citys); } public function all_suffix(){ $all_suffix = Database::connectDB()->query("SELECT id,suffix_name FROM all_suffix WHERE 1"); $all_suffixs=[]; foreach($all_suffix as $row) { $all_suffixs[] = $row; } return response()->json($all_suffixs); } public function all_gender(){ $all_suffix = Database::connectDB()->query("SELECT id,gender_name FROM all_gender WHERE 1"); $all_suffixs=[]; foreach($all_suffix as $row) { $all_suffixs[] = $row; } return response()->json($all_suffixs); } public function all_marital_status(){ $all_marital = Database::connectDB()->query("SELECT id,name FROM all_marital_status WHERE 1"); $all_marital_status=[]; foreach($all_marital as $row) { $all_marital_status[] = $row; } return response()->json( $all_marital_status); } public function source_mode_contact(){ $moc = Database::connectDB()->query("SELECT id,name FROM source_mode_of_contact WHERE status =1"); $mocs=[]; foreach($moc as $row) { $mocs[] = $row; } return response()->json($mocs); } public function source_customer_type(){ $ctype = Database::connectDB()->query("SELECT id,name FROM source_customer_type WHERE 1"); $types=[]; foreach($ctype as $row) { $types[] = $row; } return response()->json($types); } public function customer_category(){ $cu_category = Database::connectDB()->query("SELECT id,name FROM customer_category WHERE status =1"); $customer_categories=[]; foreach($cu_category as $row) { $customer_categories[] = $row; } return response()->json($customer_categories); } public function source_religion(){ $religion = Database::connectDB()->query("SELECT id,name FROM source_religion WHERE status =1"); $religions=[]; foreach($religion as $row) { $religions[] = $row; } return response()->json($religions); } public function source_profession(){ $profession = Database::connectDB()->query("SELECT id,name FROM source_profession WHERE status =1"); $professions=[]; foreach($profession as $row) { $professions[] = $row; } return response()->json($professions); } public function source_nature_business(){ $nature_business = Database::connectDB()->query("SELECT id,name FROM source_nature_of_business WHERE status =1"); $nature_businesses=[]; foreach($nature_business as $row) { $nature_businesses[] = $row; } return response()->json($nature_businesses); } public function cu_affiliation_category(){ $affilications_category = Database::connectDB()->query("SELECT id,name FROM customer_affiliations_category WHERE status =1"); $category_affilications=[]; foreach( $affilications_category as $row) { $category_affilications[] = $row; } return response()->json($category_affilications); } public function cu_affiliation_content(){ $affilications_content = Database::connectDB()->query("SELECT id,name FROM customer_affiliations_content WHERE status =1"); $content_affilications=[]; foreach($affilications_content as $row) { $content_affilications[] = $row; } return response()->json($content_affilications); } public function corporation_name(){ $corporation = Database::connectDB()->query("SELECT id,corporation_name FROM customer WHERE corporation_name !=''"); $corporation_name=[]; foreach($corporation as $row) { $corporation_name[] = $row; } return response()->json( $corporation_name); } }
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings