From af64355a8843708928cc351382246d37e4d25137 Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Fri, 29 Mar 2024 19:23:14 +0530 Subject: [PATCH] Discussion 25th march Done : ps --- app/Config/Constants.php | 31 +- app/Config/Routes.php | 63 +- app/Controllers/Address.php | 54 - app/Controllers/ApiIntegration.php | 1209 ----------------- app/Controllers/AppSettings.php | 151 -- app/Controllers/Authentication.php | 61 + app/Controllers/Books.php | 17 +- app/Controllers/Business.php | 18 +- app/Controllers/Home.php | 19 + app/Controllers/Invoice.php | 20 +- app/Controllers/Settings.php | 213 --- app/Controllers/Subscription.php | 217 --- app/Controllers/Users.php | 191 +-- app/Helpers/apiIntegration_helper.php | 68 - app/Models/ApiIntegrationModel.php | 113 -- app/Models/AppSettingModel.php | 22 - app/Models/InvoiceModel.php | 2 +- app/Models/SettingsModel.php | 22 - app/Views/address_list.php | 66 - app/Views/app_setting_form.php | 248 ---- app/Views/book_form.php | 2 +- app/Views/book_list.php | 2 +- app/Views/business_form.php | 80 +- app/Views/business_list.php | 2 +- app/Views/customer_form.php | 6 +- app/Views/customer_list.php | 6 +- app/Views/dashboard.php | 20 +- app/Views/invoice_form.php | 177 ++- app/Views/invoice_pdf_template.php | 8 +- app/Views/setting_form.php | 2 +- app/Views/template/footer.php | 672 +-------- app/Views/template/header.php | 2 +- app/Views/template/topbar.php | 117 +- app/Views/user_form.php | 230 ++-- app/Views/user_list.php | 48 +- .../07156b4680962b650af1c6927c7019d5.jpg | Bin 11487 -> 0 bytes .../07156b4680962b650af1c6927c7019d5_1.jpg | Bin 11487 -> 0 bytes .../07156b4680962b650af1c6927c7019d5_4.jpg | Bin 11487 -> 0 bytes .../07156b4680962b650af1c6927c7019d5_5.jpg | Bin 11487 -> 0 bytes public/uploads/1.png | Bin 5198 -> 0 bytes public/uploads/1_1.png | Bin 5198 -> 0 bytes public/uploads/600px-Instagram_icon.png | Bin 171855 -> 0 bytes public/uploads/600px-Instagram_icon_1.png | Bin 171855 -> 0 bytes public/uploads/600px-Instagram_icon_2.png | Bin 171855 -> 0 bytes public/uploads/600px-Instagram_icon_3.png | Bin 171855 -> 0 bytes public/uploads/600px-Instagram_icon_4.png | Bin 171855 -> 0 bytes public/uploads/600px-Instagram_icon_5.png | Bin 171855 -> 0 bytes public/uploads/600px-Instagram_icon_6.png | Bin 171855 -> 0 bytes public/uploads/600px-Instagram_icon_7.png | Bin 171855 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6.jpg | Bin 20144 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6_1.jpg | Bin 20144 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6_10.jpg | Bin 20144 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6_11.jpg | Bin 20144 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6_12.jpg | Bin 20144 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6_13.jpg | Bin 20144 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6_14.jpg | Bin 20144 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6_2.jpg | Bin 20144 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6_3.jpg | Bin 20144 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6_4.jpg | Bin 20144 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6_5.jpg | Bin 20144 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6_6.jpg | Bin 20144 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6_7.jpg | Bin 20144 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6_8.jpg | Bin 20144 -> 0 bytes .../8831c6628b6a3fb79db75b39d8ef98d6_9.jpg | Bin 20144 -> 0 bytes public/uploads/favicon.ico | Bin 5430 -> 0 bytes public/uploads/favicon_1.ico | Bin 5430 -> 0 bytes 66 files changed, 614 insertions(+), 3565 deletions(-) delete mode 100644 app/Controllers/Address.php delete mode 100644 app/Controllers/ApiIntegration.php delete mode 100644 app/Controllers/AppSettings.php delete mode 100644 app/Controllers/Settings.php delete mode 100644 app/Controllers/Subscription.php delete mode 100644 app/Helpers/apiIntegration_helper.php delete mode 100644 app/Models/ApiIntegrationModel.php delete mode 100644 app/Models/AppSettingModel.php delete mode 100644 app/Models/SettingsModel.php delete mode 100644 app/Views/address_list.php delete mode 100644 app/Views/app_setting_form.php delete mode 100644 public/uploads/07156b4680962b650af1c6927c7019d5.jpg delete mode 100644 public/uploads/07156b4680962b650af1c6927c7019d5_1.jpg delete mode 100644 public/uploads/07156b4680962b650af1c6927c7019d5_4.jpg delete mode 100644 public/uploads/07156b4680962b650af1c6927c7019d5_5.jpg delete mode 100644 public/uploads/1.png delete mode 100644 public/uploads/1_1.png delete mode 100644 public/uploads/600px-Instagram_icon.png delete mode 100644 public/uploads/600px-Instagram_icon_1.png delete mode 100644 public/uploads/600px-Instagram_icon_2.png delete mode 100644 public/uploads/600px-Instagram_icon_3.png delete mode 100644 public/uploads/600px-Instagram_icon_4.png delete mode 100644 public/uploads/600px-Instagram_icon_5.png delete mode 100644 public/uploads/600px-Instagram_icon_6.png delete mode 100644 public/uploads/600px-Instagram_icon_7.png delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6.jpg delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6_1.jpg delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6_10.jpg delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6_11.jpg delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6_12.jpg delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6_13.jpg delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6_14.jpg delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6_2.jpg delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6_3.jpg delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6_4.jpg delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6_5.jpg delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6_6.jpg delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6_7.jpg delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6_8.jpg delete mode 100644 public/uploads/8831c6628b6a3fb79db75b39d8ef98d6_9.jpg delete mode 100644 public/uploads/favicon.ico delete mode 100644 public/uploads/favicon_1.ico diff --git a/app/Config/Constants.php b/app/Config/Constants.php index 970e679..5c01703 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -94,37 +94,8 @@ define('EVENT_PRIORITY_NORMAL', 100); define('EVENT_PRIORITY_HIGH', 10); /** - * Constants For Api Integration. + * Constants For BBD */ -// define('VB_APIURL', 'https://vbp.venbait.in/wp-json/wc/v3/'); -define('product','books'); -define('product_column', ["book_id","wp_api_product_id"]); - -define('product_child','book_images'); -define('product_child_column', ["book_id","wp_api_img_id","book_img_id"]); - -define('customer','customers'); -define('customer_column', ["customer_id","wp_api_customer_id"]); - -define('customer_child','customer_addresses'); -define('customer_child_column', ["customer_id","","customer_address_id"]); - -define('order','invoice'); -define('order_column', ["invoice_id","wp_api_order_id","invoice_child_id"]); - -define('order_child','invoiceitems'); -define('order_child_column', ["invoice_id","wp_api_line_items_id","customer_id"]); - -// define('WAAI_TOKEN', '652548474f4e4'); -// define('WAAI_INSTANCE', '65254894E4A88'); - -// UAT - for testing Purpose.. -// define('WAAI_TOKEN', '65685e954bcf6'); -// define('WAAI_INSTANCE', '656863C54F90C'); - -// LIVE - Vel given.30th Nov. -// define('WAAI_TOKEN', '6568739969f28'); -// define('WAAI_INSTANCE', '656876690A9FD'); define('SEND_WAAI_URL', 'https://waai.in/api/send'); define('SEND_WAAI_GROUP_URL', 'https://waai.in/api/send_group'); diff --git a/app/Config/Routes.php b/app/Config/Routes.php index bbd0300..373c069 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -29,6 +29,7 @@ $routes->set404Override(); // We get a performance increase by specifying the default // route since we don't have to scan directories. +// In your routes file (e.g., app/Config/Routes.php) # Authentication Routes $routes->get('/', 'Authentication::index'); @@ -41,78 +42,56 @@ $routes->post('auth_reset_password_save/', 'Authentication::auth_reset_password_ $routes->get('lockscreen/', 'Authentication::lockscreen'); $routes->get('lock/', 'Authentication::lock'); $routes->post('unlock/', 'Authentication::unlock'); - - +$routes->post('confirm_password/', 'Authentication::confirm_password'); +$routes->post('change_password', 'Authentication::change_password'); # Dashboard Routes $routes->get('dashboard/', 'Home::index'); +$routes->post("check_existing/", "Home::check_existing/"); # Users Routes $routes->get("user_list/", "Users::index"); $routes->get("user_page/(:any)/(:any)", "Users::user_page/$1/$2"); $routes->post("insert_users", "Users::insert_users"); $routes->get("delete_user/(:any)", "Users::delete_user/$1"); -$routes->get("activateUser/(:any)", "Users::activateUser/$1"); +$routes->get("activate_user/(:any)", "Users::activate_user/$1"); $routes->get('users/get_branches/(:num)', 'Users::get_branches/$1'); - # Causes Routes $routes->get("causes_list/", "Books::index"); $routes->get("add_causes/(:any)", "Books::add_causes/$1"); -$routes->post("insert_books", "Books::insert_books"); -$routes->get("delete_books/(:any)", "Books::delete_books/$1"); +$routes->post("insert_causes", "Books::insert_causes"); +$routes->get("delete_causes/(:any)", "Books::delete_causes/$1"); -# Site-Setting Routes -$routes->get("sitesetting_list/", "Settings::index"); -$routes->get("sitesetting_page/(:any)", "Settings::sitesetting_page/$1"); -$routes->post("sitesetting_synchronization", "Settings::sitesetting_synchronization"); -$routes->get("delete_sitesetting/(:any)", "Books::delete_sitesetting/$1"); - -# App Site-Setting Routes(SuperAdmin) -// $routes->get("appsetting/", "AppSettings::index"); -$routes->get("appsetting_page", "AppSettings::appsetting_page"); -$routes->post("appsetting_synchronization", "AppSettings::appsetting_synchronization"); -// $routes->get("delete_sitesetting/(:any)", "Books::delete_sitesetting/$1"); - -#Routes for Organization Routes +#Organization Routes (also known as business) $routes->get("org_list/", "Business::index"); $routes->get("new_org/(:any)", "Business::new_org/$1"); $routes->post("insert_org/", "Business::insert_org"); $routes->get("delete_org/(:any)", "Business::delete_org/$1"); -#Routes for Donor Routes +#Donor Routes (also known as contributor,customer) $routes->get("Contributor_list/", "Customer::index"); $routes->get("new_Donor/(:any)", "Customer::new_Donor/$1"); $routes->get('Customer/getReceiptDetails/(:num)', 'Customer::getReceiptDetails/$1'); -// In your routes file (e.g., app/Config/Routes.php) - - $routes->post("insert_donor", "Customer::insert_donor"); $routes->post("insert_ajaxdonor", "Customer::insert_ajaxdonor"); $routes->get("delete_donor/(:any)", "Customer::delete_donor/$1"); -#Routes for donor group (renamed as contributor group : 20/03/2024) +#Donor group Routes (renamed as contributor group : 20/03/2024) $routes->get('contributor_group/', 'Customer::donor_group'); $routes->get('view_contributor_group/(:any)', 'Customer::view_donor_group/$1'); $routes->get('preview_contributor_group/(:any)', 'Customer::preview_donor_group/$1'); $routes->get('delete_contributor_group/(:any)', 'Customer::delete_donor_group/$1'); $routes->post("insert_contributor_group", "Customer::insert_donor_group"); - - -#adres priknt -$routes->get('addressprint/', 'Address::index'); -$routes->post('address/generatePdf', 'Address::generatePdf'); - -#Routes for campaign +#Campaign Routes (also known as Event) $routes->get("campaign_list/", "Event::index"); $routes->get("new_campaign/(:any)", "Event::new_campaign/$1"); $routes->post("insert_event/", "Event::insert_event"); - $routes->get('invoice_number_format/(:any)', 'Event::invoice_number_format/$1'); $routes->post("insert_invoice_number_format", "Event::insert_invoice_number_format"); -#Routes for Receipt Routes +#Receipt Routes (also known as Invoice) $routes->get("receipt_list/", "Invoice::index"); $routes->get("new_receipt/(:any)", "Invoice::new_receipt/$1"); $routes->post("donor_cash_success/", "Invoice::donor_cash_success"); @@ -121,17 +100,14 @@ $routes->get("donations_accepted/", "Invoice::donations_accepted"); $routes->post("save_donations_accepted/", "Invoice::save_donations_accepted"); $routes->get("audit_history", "Invoice::audit_history"); $routes->get('generate-pdf/(:num)', 'Invoice::generatePdf/$1'); -// app/config/Routes.php - $routes->get('Invoice/showInvoiceModal', 'Invoice::showInvoiceModal'); - $routes->post("get_donor_details", "Invoice::get_donor_details"); $routes->post("save_invoice/", "Invoice::save_invoice/"); $routes->add('approve_invoice/(:num)', 'Invoice::approve_invoice/$1'); $routes->get('generate_invoice_pdf/(:num)', 'Invoice::generate_invoice_pdf/$1'); $routes->get('print_address/(:num)', 'Invoice::print_address/$1'); -$routes->get('print_address/(:num)', 'Invoice::print_address/$1'); +#Report Routes $routes->match(['get','post'],'/general_inv_rp','Invoice::general_inv_rp'); $routes->match(['get','post'],'/mem_inv_rp','Invoice::general_membership_inv_rp'); $routes->match(['get','post'],'/itemwise_report','Invoice::itemwise_report'); @@ -139,7 +115,6 @@ $routes->match(['get','post'],'/itemwise_report','Invoice::itemwise_report'); # Notifications Routes // $routes->get('controller/SubExpdetail/(:num)', 'YourController::SubExpdetail/$1'); - $routes->cli("getExpCustomerDetail/(:num)",'Notifications::getExpCustomerDetail/$1'); $routes->get('send_whatsapp_message/', 'Notifications::send_whatsapp_message'); $routes->post('whatsapp_custom_notifications/', 'Notifications::whatsapp_custom_notifications'); @@ -151,24 +126,12 @@ $routes->get('template_creation/', 'Notifications::template_creation'); $routes->get('template_creation_form/(:any)', 'Notifications::template_creation_form/$1'); $routes->get('template_creation_delete/(:any)', 'Notifications::template_creation_delete/$1'); $routes->post("template_creation_insert", "Notifications::template_creation_insert"); - $routes->get('campaign_creation/', 'Notifications::campaign_creation'); $routes->get('campaign_creation_form/(:any)', 'Notifications::campaign_creation_form/$1'); $routes->get('campaign_creation_delete/(:any)', 'Notifications::campaign_creation_delete/$1'); $routes->post("campaign_creation_insert", "Notifications::campaign_creation_insert"); - -# Api integration Routes -$routes->post('api/(:any)', 'ApiIntegration::api_integration/$1'); - -// $routes->group("api", function ($routes) { -// // $routes->post("create_products/", "ApiIntegration::save_book_details"); -// // $routes->match(['put', 'post', 'get', 'delete'], 'products', 'ApiIntegration::book_api_integration'); -// // $routes->match(['put', 'post', 'get', 'delete'], 'customers', 'ApiIntegration::customer_api_integration'); -// // $routes->match(['put', 'post', 'get', 'delete'], 'orders', 'ApiIntegration::sales_api_integration'); -// }); - /* * -------------------------------------------------------------------- * Additional Routing diff --git a/app/Controllers/Address.php b/app/Controllers/Address.php deleted file mode 100644 index 40e2e11..0000000 --- a/app/Controllers/Address.php +++ /dev/null @@ -1,54 +0,0 @@ -findAll(); - return view('address_list', $data); - } -} - - - -// public function generatePdf() -// { -// $customerModel = new CustomerModel(); - -// $customer_id = $this->request->getPost('customer_id'); -// $customerData = $customerModel->find($customer_id); - -// if ($customerData) { - -// $options->set('isHtml5ParserEnabled', true); -// $options->set('isPhpEnabled', true); -// $dompdf = new Dompdf($options); - - -// $html = view('address_list', ['customerData' => $customerData]); - - -// $dompdf->loadHtml($html); - - -// $dompdf->setPaper('A4', 'portrait'); - -// $dompdf->render(); - - -// $dompdf->stream('customer_information.pdf', ['Attachment' => 0]); -// } else { - -// return redirect()->to('index'); -// } -// } -// } diff --git a/app/Controllers/ApiIntegration.php b/app/Controllers/ApiIntegration.php deleted file mode 100644 index c5ac467..0000000 --- a/app/Controllers/ApiIntegration.php +++ /dev/null @@ -1,1209 +0,0 @@ -global_variable_business_id = 1; - $this->global_variable_role = "Online"; - $api_model = new ApiIntegrationModel(); - $table = 'users'; - $where = ['role'=>$this->global_variable_role,'business_id'=>(int)$this->global_variable_business_id]; - $existing_data = $api_model->getData($table, $where); - $this->global_variable_user_id = isset($existing_data[0]->user_id) ? (int)$existing_data[0]->user_id : NULL; - $this->global_variable_user_name = isset($existing_data[0]->user_id) ? $existing_data[0]->first_name." ".$existing_data[0]->last_name : NULL; - } - - public function api_integration($api_request_text) { - $this->logger->info("Api Integration : UID = ".$this->global_variable_user_id." * ".$this->global_variable_user_name); - $this->logger->info("Api Integration : Request Text = ".$api_request_text); - try { - $request_data = $this->request->getVar(); - $this->logger->info("Api Integration : Request data type = ".gettype($request_data)); - if(isset($request_data) && gettype($request_data) === 'object') {$request_data = [$request_data]; $this->logger->info("Api Integration : Request data type = ".gettype($request_data));} - - if(count($request_data)>0){ - $this->logger->info("Api Integration : Request data count = ".count($request_data)); - $this->logger->info("Api Integration : Request data = ".json_encode($request_data)); - $i = 0; - $final_response = []; - foreach($request_data as $row_data) - { - $get_response[$i] = $this->call_methods((array)$row_data, $api_request_text); - $final_response[$i] = isset($get_response[$i]['message'])?$get_response[$i]['message']:$get_response[$i]; - $i++; - } - // return $this->respond(['status' => 200, 'message' => $final_response,'references'=>$get_response]); - return $this->respond(['status' => 200, 'message' => $final_response]); - }else{ - $this->logger->error('Api Integration : Err = Request data Not Found.'); - throw new \Exception('Api Request data Not Found.'); - } - - } catch (\Exception $e) { - // $this->logger->error("Api Integration : ".str_replace("_", " ",ucwords($api_request_text))." {exception}", ['exception' => $e]); - $this->logger->error("Api Integration : ".str_replace("_", " ",ucwords($api_request_text))." Exception Message: " . $e->getMessage() . "
File: " . $e->getFile() . "
Line: " . $e->getLine() . "
"); - return $this->fail('request failed, An error occurred on line ' . $e->getline() . ' : ' . $e->getMessage()); - } - - } - - public function call_methods($row_data, $api_request_text) - { - - $parts = explode('_', $api_request_text); - $method = $parts[0]; - $table = constant($parts[1]); - $table_column = constant($parts[1].'_column'); - $table_child = constant($parts[1].'_child'); - // $table_child_column = constant($table.'_child_column'); - $this->logger->info("Api CallMethods : method name = ".$method.", table = ".$table.", table child = ".$table_child); - $this->logger->info("Api CallMethods : table = ".$table ." and its column => " .implode(",",$table_column)); - - try { - switch ($method) { - case "create": - case "update": - try { - switch ($table) { - case "books": - try { - $records = (array)$row_data; - $this->logger->info("Api CallMethods : method name = ".$method.", data type =".gettype($records)); - if (isset($records['id']) && !empty($records['id'])) { - $wordpress_book_id = $records['id']; - $this->logger->info("Api CallMethods : method name = ".$method.", row data count = ".count($records).", wordpress Product Ref ID = ".$wordpress_book_id); - $response = $this->save_book_details($records, $wordpress_book_id); - $this->logger->info("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." response = ".$response['status']); - } else { - throw new \Exception('The "id" field is not set or empty.'); - } - } catch (\Exception $e) { - // $this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." {exception} ", ['exception' => $e]); - $this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." Exception Message: " . $e->getMessage() . "
File: " . $e->getFile() . "
Line: " . $e->getLine() . "
"); - return $this->fail('request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage()); - } - break; - case "customers": - try { - $records = (array)$row_data; - $this->logger->info("Api CallMethods : method name = ".$method.", data type =".gettype($records)); - if (isset($records['id']) && !empty($records['id'])) { - $wordpress_customer_id = $records['id']; - $this->logger->info("Api CallMethods : method name = ".$method.", row data count = ".count($records).", wordpress Customer Ref ID = ".$wordpress_customer_id); - $response = $this->save_customer_details($records, $wordpress_customer_id); - $this->logger->info("Api CallMethods : response = ".$response['status']); - } else { - throw new \Exception('The "id" field is not set or empty.'); - } - - } catch (\Exception $e) { - // $this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." {exception}", ['exception' => $e]); - $this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." Exception Message: " . $e->getMessage() . "
File: " . $e->getFile() . "
Line: " . $e->getLine() . "
"); - return $this->fail('request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage()); - } - break; - case "invoice": - try { - $records = (array)$row_data; - $this->logger->info("Api CallMethods : method name = ".$method.", data type =".gettype($records)); - if (isset($records['id']) && !empty($records['id'])) { - $wordpress_order_id = $records['id']; - $this->logger->info("Api CallMethods : method name = ".$method.", row data count = ".count($records).", wordpress Order Ref ID = ".$wordpress_order_id); - $response = $this->save_sales_details($records, $wordpress_order_id); - $this->logger->info("Api CallMethods : response = ".$response['status']); - } else { - throw new \Exception('The "id" field is not set or empty.'); - } - } catch (\Exception $e) { - // $this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." {exception}", ['exception' => $e]); - $this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." Exception Message: " . $e->getMessage() . "
File: " . $e->getFile() . "
Line: " . $e->getLine() . "
"); - return $this->fail('request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage()); - } - break; - default: - $this->logger->error('Api CallMethods : Err = Invaild Api Route.'); - throw new \Exception('Api Route Not Available'); - } - } catch (\Exception $e) { - $exception_ends_with = $e->getline() ? 'on line ' . $e->getline() . ': ' . $e->getMessage() : $e->getMessage(); - return $this->fail(ucwords($method).' request failed, An error occurred ' .$exception_ends_with); - // $this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." {exception}", ['exception' => $e]); - $this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." Exception Message: " . $e->getMessage() . "
File: " . $e->getFile() . "
Line: " . $e->getLine() . "
"); - } - break; - case 'delete': - try { - $basic_message = ""; - $records = (array)$row_data; - $wordpress_refer_id = $records['id']; - $api_model = new ApiIntegrationModel(); - $where = ['isactive' => 1, $table_column[1] => (int)$wordpress_refer_id]; - $existing_data = $api_model->getData($table, $where); - $this->logger->info("Api CallMethods : method name = ".$method.", row data count = ".count($records).", ".$table_column[1]." Ref ID = ".$wordpress_refer_id); - if ((int)count($existing_data) > 0) { - if(isset($existing_data[0]) && gettype($existing_data[0]) === 'object') {$existing_data[0] = (array)$existing_data[0]; $this->logger->info("Api Integration : delete ".$table." array data type = ".gettype($existing_data[0]));} - $primary_key_id = (int)$existing_data[0][$table_column[0]]; - $this->logger->info("Api CallMethods : ".$table." its PrimaryKey ID = ".$primary_key_id); - $inactive_data['isactive'] = 0; - $inactive_data['updated_by'] = $this->global_variable_user_id; - $update_where = ['isactive' => 1, $table_column[0] => $primary_key_id]; - $api_model->updateData($table, $inactive_data, $update_where); - $get_existing_child_details = $api_model->getData($table_child, $update_where); - $this->logger->info("Api CallMethods : ".$table." Child Details Count = ".count($get_existing_child_details)); - if ($get_existing_child_details) { - $api_model->updateData($table_child, $inactive_data, $update_where); - } - $basic_message = ucwords($table)." Details (ID = ".$primary_key_id.") and ".ucwords($table)." Child Details Are Deleted"; - }else{ - $basic_message = ucwords($table)." has No Details"; - } - $this->logger->info("Api CallMethods : ".$basic_message); - $response = ['status' => 200, 'message' => $basic_message]; - } catch (\Exception $e) { - $exception_ends_with = $e->getline() ? 'on line ' . $e->getline() . ': ' . $e->getMessage() : $e->getMessage(); - // $this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." {exception}", ['exception' => $e]); - $this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." Exception Message: " . $e->getMessage() . "
File: " . $e->getFile() . "
Line: " . $e->getLine() . "
"); - return $this->fail('DELETE request failed, An error occurred' . $exception_ends_with); - } - break; - - default: - throw new \Exception('Unsupported HTTP method'); - $this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." Unsupported HTTP method"); - // return $this->fail('Unsupported HTTP method'); - } - return $response; - } catch (\Exception $e) { - // Handle the exception, you can log it or return an error response - $exception_ends_with = $e->getline() ? 'on line ' . $e->getline() . ': ' . $e->getMessage() : $e->getMessage(); - // $this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text))." {exception}", ['exception' => $e]); - $this->logger->error("Api CallMethods : ".str_replace("_", " ",ucwords($api_request_text)).$exception_ends_with); - return $this->fail('An error occurred ' . $exception_ends_with); - } - } - - public function save_book_details($records, $wordpress_book_id) - { - $this->logger->info("Api SaveBookDetails : records count = ".count($records).", wordpress Product Ref ID = ".$wordpress_book_id); - $api_model = new ApiIntegrationModel(); - $extensive_correspondence = ""; - $basic_message = ""; - $book_id = ""; - if (count($records) > 0 && !empty($wordpress_book_id)) { - /** Draft status means entry must but inactive. publish means active that's why comment here - * $where = ['wp_api_product_id' => $wordpress_book_id, 'isactive' => $isactive_for_where]; - **/ - $where = ['wp_api_product_id' => $wordpress_book_id]; - $book_details = $api_model->setTable('books')->where($where)->first(); - if (isset($book_details['book_id']) && $book_details['book_id'] != "") { - $book_id = $book_details['book_id']; - $where['book_id'] = $book_details['book_id']; - } // update means bookid where condition added : else no where condition added. - - $countAll = $api_model->countAll('books', $where); - - $this->logger->info(($countAll) ? "Api SaveBookDetails : in wordpress product ref ID = ".$wordpress_book_id." is available on Book table and its PrimaryKey = ".$book_id : "Api SaveBookDetails : in wordpress product ref ID = ".$wordpress_book_id." Not available on Book table"); - $publisher = NULL; - $language = NULL; - $page_count = NULL; - $genre = NULL; - $author = NULL; - $category = NULL; // Book - $attributes = $records['attributes']; - $categories = $records['categories']; - // if (count($categories) > 0) { - // $categoryNames = []; - // foreach ($categories as $category) { - // if (isset($category->name) && $category->name != "") { - // if($category->name !== "Membership"){ - // $category = 1;$categoryNames[] = $category->name; } - // else{ $category = 2; } - // } - // } - // if (!empty($categoryNames)) { - // $genre = implode(", ", $categoryNames); - // } - // } - if (count($attributes) > 0) { - foreach ($attributes as $att) { - if (isset($att->name) && $att->name == "Publisher") { - $publisher = implode(", ", $att->options); - } - if (isset($att->name) && $att->name == "Book Author") { - $author = implode(", ", $att->options); - } - if (isset($att->name) && $att->name == "Book Language") { - $language = implode(", ", $att->options); - } - if (isset($att->name) && $att->name == "Page Count") { - $page_count = implode(", ", $att->options); - } - } - } - - - $book_data['wp_api_product_id'] = $wordpress_book_id; - $book_data['title'] = isset($records['name']) ? $records['name'] : NULL; - $book_data['publication_date'] = isset($records['date_created']) ? $records['date_created'] : NULL; - $book_data['publisher'] = $publisher; - $book_data['author'] = $author; - $book_data['genre'] = $genre; - $book_data['language'] = $language; - $book_data['description'] = isset($records['description']) ? $records['description'] : NULL; - $book_data['short_description'] = isset($records['short_description']) ? $records['short_description'] : NULL; - $book_data['page_count'] = $page_count; - $book_data['category'] = $category; - // $book_data['price'] = (isset($records['sale_price']) && $records['sale_price'] != '') ? $records['sale_price'] : ((isset($records['regular_price']) && $records['regular_price'] != '') ? $records['regular_price'] : NULL); - $book_data['price'] = (isset($records['sale_price']) && $records['sale_price'] != '') ? $records['sale_price'] : ((isset($records['regular_price']) && $records['regular_price'] != '') ? $records['regular_price'] : ((isset($records['price']) && $records['price'] != '') ? $records['price'] : NULL)); - $book_data['sku'] = isset($records['sku']) ? $records['sku'] : NULL; - $book_data['isactive'] = (isset($records['status']) && strtolower($records['status']) === "publish") ? 1 : 0; - $book_data['business_id'] = $this->global_variable_business_id; - $images = $records['images']; - if ((int)$countAll == 0) { - $book_data['created_by'] = $this->global_variable_user_id; - $insert_result = $api_model->insertData('books', $book_data); - $last_insert_book_id = $insert_result['info']; - $extensive_correspondence .= $insert_result['info'] ? "Book id : " . $insert_result['info'] - : "Err :" . $insert_result['err']; - $basic_message .= $insert_result['info'] ? " Book id : " . $insert_result['info'] : "Book details Not Inserted"; - $insert_result['info'] ? $this->logger->info("Api SaveBookDetails : Book id = ".$insert_result['info']):""; - $insert_result['err'] ? $this->logger->error("Api SaveBookDetails : Err = ".$insert_result['err']):""; - } else { - $last_insert_book_id = $book_id; - $book_data['updated_by'] = $this->global_variable_user_id; - /** Draft status means entry must but inactive. publish means active that's why comment here - * $book_where = ['book_id' => $book_id, 'isactive' => 1, 'wp_api_product_id' => $wordpress_book_id]; - **/ - $book_where = ['book_id' => $book_id, 'wp_api_product_id' => $wordpress_book_id]; - $update_result = $api_model->updateData('books', $book_data, $book_where); - $extensive_correspondence .= $update_result['info'] ? "Book id : " . $last_insert_book_id . " ( " . $update_result['info'] . ")" - : " ( Err :" . $update_result['err'] . ")"; - $basic_message .= "Book id : " . $last_insert_book_id; - $update_result['info'] ? $this->logger->info("Api SaveBookDetails : Book id : " . $last_insert_book_id . " ( " . $update_result['info'] . ")"):""; - $update_result['err'] ? $this->logger->error("Api SaveBookDetails : Err = ".$update_result['err']):""; - } - - $this->logger->info("Api SaveBookDetails : Book images count : " .count($images)); - if (count($images) > 0 && $last_insert_book_id != "") { - $extensive_correspondence .= " Its have " . count($images) . " Images ,"; - $basic_message .= " Its have " . count($images) . " Images"; - $this->logger->info("Api SaveBookDetails : ".$extensive_correspondence); - $where = ['book_id' => (int)$last_insert_book_id, 'isactive' => 1]; - $existing_images = $api_model->getData('book_images', $where); - $request_images = (array)$images; - - $filteringExistingImagesWpApiId = []; - $filteringRequestedImagesWpApiId = []; - $commonElements = []; - if (!empty($existing_images)) { - - for ($z = 0; $z < count($request_images); $z++) { - $filteringRequestedImagesWpApiId[$z] = $request_images[$z]->id; - } - for ($y = 0; $y < count($existing_images); $y++) { - $filteringExistingImagesWpApiId[$y] = $existing_images[$y]->wp_api_img_id; - } - - if (!empty($filteringExistingImagesWpApiId)) { - $this->logger->info("Api SaveBookDetails : Incoming Images Wp Id " .implode(",",$filteringRequestedImagesWpApiId)); - $this->logger->info("Api SaveBookDetails : Existing Images Wp Id " .implode(",",$filteringExistingImagesWpApiId)); - $A = $filteringExistingImagesWpApiId; - $B = $filteringRequestedImagesWpApiId; - $missingValues = array_diff($A, $B); //Find difference element in Existing Images only - $commonElements = array_intersect($A, $B); - if (!empty($missingValues)) { - $this->logger->info("Api SaveBookDetails : Missing Images Wp Id " .implode(",",$missingValues)." Are inactived"); - $inactive_where = ['isactive' => 1, 'book_id' => (int)$last_insert_book_id]; - $inactive_whereIn[0] = 'wp_api_img_id'; - $inactive_whereIn[1] = $missingValues; - $data_to_batch_update = ['isactive' => 0,'updated_by'=>$this->global_variable_user_id]; - $api_model->inactiveMissingDetails('book_images',$data_to_batch_update, $inactive_where, $inactive_whereIn); - } - } - } - - $where = ['book_id' => (int)$last_insert_book_id, 'isactive' => 1]; - if (!empty($commonElements)) { - $whereIn[0] = 'wp_api_img_id'; - $whereIn[1] = $commonElements; - } else { - $whereIn = null; - } - $lastestActiveBookImageData = $api_model->getData('book_images', $where, $whereIn); - $this->logger->info("Api SaveBookDetails : lastest Active Book Image Data Count " .count($lastestActiveBookImageData)); - $book_image_data = []; - $i = 0; - foreach ($images as $img) { - $bookImgId = null; - // Iterate through the array and find the 'book_img_id' based on 'wp_api_img_id' - if (!empty($lastestActiveBookImageData)) { - foreach ($lastestActiveBookImageData as $item) { - if ($item->wp_api_img_id == $img->id) { - $bookImgId = $item->book_img_id; - break; // Found the match, no need to continue looping - } - } - } - $book_image_data[$i]['img_name'] =isset($img->name) && !empty($img->name) ? $img->name : NULL; - $book_image_data[$i]['wp_img_url'] = isset($img->src) && !empty($img->src) ? $img->src : NULL; - $book_image_data[$i]['is_cover'] = (!empty($bookImgId) && $i == 0) ? 1 : 0 ; - $book_image_data[$i]['type'] = 2; - $book_image_data[$i]['book_id'] = $last_insert_book_id; - $book_image_data[$i]['isactive'] = 1; - $book_image_data[$i]['wp_api_img_id'] = isset($img->id) && !empty($img->id) ? $img->id : NULL; - $book_image_data[$i]['book_img_id'] = $bookImgId; - $i++; - $this->logger->info("Api SaveBookDetails : Image Data = $i Request data = ".json_encode($book_image_data)); - } // image loop closed - $extensive_correspondence .= (!empty($book_image_data) ? $api_model->insertAndUpdateChildDetails($book_image_data, 'book_images', 'book_img_id') : ""); - $this->logger->info("Api SaveBookDetails : ".$extensive_correspondence); - } //image count closed - else{ - $this->logger->error("Api SaveBookDetails : Err = Image Data Not Found"); - } - if (count($categories) > 0 && $last_insert_book_id != "") { - $this->save_categories_master_details($categories); - $extensive_correspondence .= " Its have " . count($categories) . " Categories"; - $basic_message .= " And Its have " . count($categories) . " Categories"; - $this->logger->info("Api SaveBookDetails : ".$extensive_correspondence); - $master_categories = $api_model->getData('category', ['isactive' => 1]); - $this->logger->info("Api SaveBookDetails : total master categories count = ".count($master_categories)); - $where = ['book_id' => (int)$last_insert_book_id, 'isactive' => 1 ]; - $existing_categories = $api_model->getData('book_categories', $where); - $this->logger->info("Api SaveBookDetails : existing categories count = ".count($existing_categories)); - $request_categories = (array)$categories; - $filtering_existing_categories_wpApiId = []; - $filtering_requested_categories_wpApiId = []; - $missing_category_values = []; - $common_category_element = []; - - if (!empty($existing_categories)) { - - for ($z = 0; $z < count($request_categories); $z++) { - $filtering_requested_categories_wpApiId[$z] = $request_categories[$z]->id; - } - for ($y = 0; $y < count($master_categories); $y++) { - $filtering_existing_categories_wpApiId[$y] = $master_categories[$y]->wp_api_category_id; - } - $filtering_existing_categories_wpApiId = array_diff($filtering_existing_categories_wpApiId, array("")); - if (!empty($filtering_requested_categories_wpApiId)) { - $this->logger->info("Api SaveBookDetails : Incoming Categories Wp Id " .implode(",",$filtering_requested_categories_wpApiId)); - $this->logger->info("Api SaveBookDetails : Existing Categories Wp Id " .implode(",",$filtering_existing_categories_wpApiId)); - - $A = $filtering_existing_categories_wpApiId; - $B = $filtering_requested_categories_wpApiId; - $missing_category_values = array_diff($A, $B); //Find difference element in Existing Images only - $common_category_element = array_intersect($A, $B); - $this->logger->info("Api SaveBookDetails : Missing Categories Wp Id " .implode(",",$missing_category_values)." Are inactived"); - if (!empty($missing_category_values)) { - $this->logger->info("Api SaveBookDetails : Missing Categories Wp Id " .implode(",",$missing_category_values)." Are inactived"); - $where1 = ['isactive' => 1]; - $whereIn1[0] = 'wp_api_category_id'; - $whereIn1[1] = array_filter($missing_category_values); - $get_master_category_id_to_inactive = $api_model->getData('category', $where1, $whereIn1); - for ($x = 0; $x < count($get_master_category_id_to_inactive); $x++) { - $book_categories_to_inactive[$x] = $get_master_category_id_to_inactive[$x]->id; - } - $this->logger->info("Api SaveBookDetails : Missing Categories Wp Id " .implode(",",$missing_category_values)." catgory pkid => ".implode(",",$book_categories_to_inactive). "Are inactived"); - $where2 = ['isactive' => 1]; - $whereIn2[0] = 'category_id'; - $whereIn2[1] = $book_categories_to_inactive; - $data_to_batch_update2 = ['isactive' => 0,'updated_by'=>$this->global_variable_user_id]; - $api_model->inactiveMissingDetails('book_categories',$data_to_batch_update2, $where2, $whereIn2); - //echo $api_model->getlastQuery(); - } - } // loop closed - } - - $where = ['isactive' => 1]; - if (!empty($common_category_element)) { - $whereIn[0] = 'wp_api_category_id'; - $whereIn[1] = $common_category_element; - } else { - $whereIn = null; - } - $get_master_category_based_WPid = $api_model->getData('category', $where, $whereIn); - $this->logger->info("Api SaveBookDetails : Common Categories Wp Id " .implode(",",$common_category_element)." Are already inserted data"); - $this->logger->info("Api SaveBookDetails : available category data count = " .count($request_categories)); - $book_categories_data = []; - $j = 0; - foreach ($categories as $cate) { - $categories_id = null; - $book_category_primarykey = null; - // Iterate through the array and find the 'book_img_id' based on 'wp_api_img_id' - if (!empty($get_master_category_based_WPid)) { - foreach ($get_master_category_based_WPid as $master) { - if ($master->wp_api_category_id == $cate->id) { - $categories_id = $master->id; - $exist_categories = $api_model->getData('book_categories', ['isactive'=>1,'category_id'=>$categories_id,'book_id' => (int)$last_insert_book_id]); - $book_category_primarykey = isset($exist_categories) && !empty($exist_categories) ? $exist_categories[0]->id : NULL; - $this->logger->info("Api SaveBookDetails : Master Category ID = " .$categories_id." => WP CategoryID = ".$master->wp_api_category_id); - break; // Found the match, no need to continue looping - } - } - } - $book_categories_data[$j]['id'] = $book_category_primarykey; - $book_categories_data[$j]['category_id'] = (int)$categories_id; - $book_categories_data[$j]['book_id'] = $last_insert_book_id; - $j++; - } // loop closed - $extensive_correspondence .= (!empty($book_categories_data) ? $api_model->insertAndUpdateChildDetails($book_categories_data, 'book_categories', 'id') : ""); - $this->logger->info("Api SaveBookDetails : ".$extensive_correspondence); - } //category count closed - else{ - $this->logger->error("Api SaveBookDetails : Err = Category Data Not Found"); - } - $response = ['status' => 200, 'message' => $basic_message ,'indetails' => $extensive_correspondence]; - } //if cond. closed - else { - $this->logger->error("Api SaveBookDetails : Err = Data Not Found"); - $response = ['status' => 204, 'message' => 'Data Not Found']; - } - return $response; - } - - public function save_customer_details($records, $wordpress_customer_id) - { - $this->logger->info("Api SaveCustomerDetails : records count = ".count($records).", wordpress Customer Ref ID = ".$wordpress_customer_id); - $api_model = new ApiIntegrationModel(); - $extensive_correspondence = ""; - $basic_message = ""; - $customer_id = ""; - if (count($records) > 0 && !empty($wordpress_customer_id)) { - $where = ['wp_api_customer_id' => $wordpress_customer_id, 'isactive' => 1]; - $customer_details = $api_model->setTable('donor')->where($where)->first(); - if (isset($customer_details['customer_id']) && $customer_details['customer_id'] != "") { - $customer_id = $customer_details['customer_id']; - $where['customer_id'] = $customer_details['customer_id']; - } - - $countAll = $api_model->countAll('donor', $where); - $this->logger->info(($countAll) ? "Api SaveCustomerDetails : in wordpress customer ref ID = ".$wordpress_customer_id." is available on customer table and its PrimaryKey = ".$customer_id : "Api SaveBookDetails : in wordpress Customer ref ID = ".$wordpress_customer_id." Not available on Customer table"); - - $customer_data['first_name'] = $records['first_name']; - $customer_data['last_name'] = $records['last_name']; - $customer_data['type'] = $records['role']; - $customer_data['email'] = $records['email']; - $customer_data['profile_picture'] = $records['avatar_url']; - $customer_data['wp_api_customer_id'] = $wordpress_customer_id; - $customer_data['mode'] = $this->global_variable_role; - $customer_data['business_id'] = $this->global_variable_business_id; - $billing = $records['billing']; - - $shipping = $records['shipping']; - - if ((int)$countAll == 0) { - $customer_data['created_by'] = $this->global_variable_user_id; - $insert_result = $api_model->insertData('donor', $customer_data); - $last_insert_customer_id = $insert_result['info']; - $extensive_correspondence .= $insert_result['info'] ? "Customer id : " . $insert_result['info'] - : "Err :" . $insert_result['err']; - $basic_message .= $insert_result['info'] ? " Customer id : " . $insert_result['info'] : "Customer details Not Inserted"; - $insert_result['info'] ? $this->logger->info("Api SaveCustomerDetails : Customer id = ".$insert_result['info']):""; - $insert_result['err'] ? $this->logger->error("Api SaveCustomerDetails : Err = ".$insert_result['err']):""; - } else { - $customer_data['updated_by'] = $this->global_variable_user_id; - $last_insert_customer_id = $customer_id; - $customer_where = ['customer_id' => $customer_id, 'isactive' => 1, 'wp_api_customer_id' => $wordpress_customer_id]; - $update_result = $api_model->updateData('donor', $customer_data, $customer_where); - $extensive_correspondence .= $update_result['info'] ? "Customer id : " . $last_insert_customer_id . " ( " . $update_result['info'] . ")" - : " ( Err :" . $update_result['err'] . ")"; - $basic_message .= "Customer id : " . $last_insert_customer_id; - $update_result['info'] ? $this->logger->info("Api SaveCustomerDetails : Customer id : " . $last_insert_customer_id . " ( " . $update_result['info'] . ")"):""; - $update_result['err'] ? $this->logger->error("Api SaveCustomerDetails : Err = ".$update_result['err']):""; - } - - $i = 0; $customer_billing_address_data = []; - $j = 0; $customer_shipping_address_data = []; - - if(isset($billing) && gettype($billing) === 'object') {$billing = [$billing];} - if(isset($shipping) && gettype($shipping) === 'object') {$shipping = [$shipping];} - $this->logger->info("Api SaveCustomerDetails : billing count : " .count($billing)); - $this->logger->info("Api SaveCustomerDetails : shipping count : " .count($shipping)); - // echo "Customer ID : ".$last_insert_customer_id." have Billing address = ".count($billing)." and Shipping address = ".count($shipping)."
"; - - if (count($billing) > 0 && $last_insert_customer_id != "") { - - $extensive_correspondence .= " Its have " . count($billing) . " Billing address ,"; - $basic_message .= " Its have " . count($billing) . " Billing address ,"; - $this->logger->info("Api SaveCustomerDetails : ".$extensive_correspondence); - $where = ['customer_id' => (int)$last_insert_customer_id, 'isactive' => 1, 'address_type'=>1]; - $existing_billing = $api_model->getData('customer_addresses', $where); - $request_billing = (array)$billing; - - $filteringExistingBillingAddress = []; - $filteringRequestedBillingAddress = []; - $commonBillingElements = []; - if (!empty($existing_billing)) { - - for ($z = 0; $z < count($request_billing); $z++) { - $filteringRequestedBillingAddress[$z] = $request_billing[$z]->address_1; - } - for ($y = 0; $y < count($existing_billing); $y++) { - $filteringExistingBillingAddress[$y] = $existing_billing[$y]->address_1; - } - - if (!empty($filteringExistingBillingAddress)) { - $this->logger->info("Api SaveCustomerDetails : Incoming billing " .implode(",",$filteringExistingBillingAddress)); - $this->logger->info("Api SaveCustomerDetails : Existing billing " .implode(",",$filteringRequestedBillingAddress)); - $A = $filteringExistingBillingAddress; - $B = $filteringRequestedBillingAddress; - $missingBillingValues = array_diff($A, $B); //Find difference element in Existing Images only - $commonBillingElements = array_intersect($A, $B); - if (!empty($missingBillingValues)) { - $this->logger->info("Api SaveCustomerDetails : Missing billing " .implode(",",$missingBillingValues)." Are inactived"); - $inactive_where = ['isactive' => 1, 'customer_id' => (int)$last_insert_customer_id,'address_type'=>1]; - $inactive_whereIn[0] = 'address_1'; - $inactive_whereIn[1] = $missingBillingValues; - $data_to_batch_update = ['isactive' => 0,'updated_by'=>$this->global_variable_user_id]; - $api_model->inactiveMissingDetails('customer_addresses',$data_to_batch_update, $inactive_where, $inactive_whereIn); - } - } - } - - $where = ['customer_id' => (int)$last_insert_customer_id, 'isactive' => 1,'address_type'=>1]; - if (!empty($commonBillingElements)) { - $whereIn[0] = 'address_1'; - $whereIn[1] = $commonBillingElements; - } else { - $whereIn = null; - } - $lastestActiveBillingAdressData = $api_model->getData('customer_addresses', $where, $whereIn); - $this->logger->info("Api SaveCustomerDetails : lastest Active billing Data Count " .count($lastestActiveBillingAdressData)); - foreach ($billing as $bill) { - $billingAddressId = null; - if ($bill->first_name !== '') { - if (!empty($lastestActiveBillingAdressData)) { - foreach ($lastestActiveBillingAdressData as $item) { - if ($item->address_1 == $bill->address_1) { - $billingAddressId = $item->customer_address_id; - break; // Found the match, no need to continue looping - } - } - } - $customer_billing_address_data[$i]['first_name'] = $bill->first_name; - $customer_billing_address_data[$i]['last_name'] = $bill->last_name; - $customer_billing_address_data[$i]['company'] = $bill->company; - $customer_billing_address_data[$i]['address_1'] = $bill->address_1; - $customer_billing_address_data[$i]['address_2'] = $bill->address_2; - $customer_billing_address_data[$i]['city'] = $bill->city; - $customer_billing_address_data[$i]['state'] = $bill->state; - $customer_billing_address_data[$i]['country'] = $bill->country; - $customer_billing_address_data[$i]['postal_code'] = $bill->postcode; - $customer_billing_address_data[$i]['customer_id'] = $last_insert_customer_id; - $customer_billing_address_data[$i]['address_type'] = 1; - $customer_billing_address_data[$i]['email'] = isset($bill->email) ? $bill->email : ''; - $customer_billing_address_data[$i]['mobile_no'] = isset($bill->phone) ? $bill->phone : ''; - $customer_billing_address_data[$i]['customer_address_id'] = $billingAddressId; - $this->logger->info("Api SaveCustomerDetails : Billing address has a value and Inserted "); - $i++; - // echo "       Billing address has a value and Inserted ".$i."
"; - }else{ - $this->logger->info("Api SaveCustomerDetails : Billing address has no value "); - // echo "       Keys are available but Billing address has no value;
"; - } - } - $extensive_correspondence .= (!empty($customer_billing_address_data) ? $api_model->insertAndUpdateChildDetails($customer_billing_address_data, 'customer_addresses', 'customer_address_id') : ""); - $this->logger->info("Api SaveCustomerDetails : ".$extensive_correspondence); - - } - if (count($shipping) > 0 && $last_insert_customer_id != "") { - $extensive_correspondence .= " Its have " . count($shipping) . " Shipping address ,"; - $basic_message .= " Its have " . count($shipping) . " Shipping address ."; - $where = ['customer_id' => (int)$last_insert_customer_id, 'isactive' => 1, 'address_type'=>2]; - $existing_shipping = $api_model->getData('customer_addresses', $where); - $request_shipping = (array)$shipping; - - $filteringExistingShippingAddress = []; - $filteringRequestedShippingAddress = []; - $commonShippingElements = []; - if (!empty($existing_shipping)) { - - for ($z = 0; $z < count($request_shipping); $z++) { - $filteringRequestedShippingAddress[$z] = $request_shipping[$z]->address_1; - } - for ($y = 0; $y < count($existing_shipping); $y++) { - $filteringExistingShippingAddress[$y] = $existing_shipping[$y]->address_1; - } - - if (!empty($filteringExistingShippingAddress)) { - $this->logger->info("Api SaveCustomerDetails : Incoming shipping " .implode(",",$filteringExistingShippingAddress)); - $this->logger->info("Api SaveCustomerDetails : Existing shipping " .implode(",",$filteringExistingShippingAddress)); - $A = $filteringExistingShippingAddress; - $B = $filteringRequestedShippingAddress; - $missingShippingValues = array_diff($A, $B); //Find difference element in Existing Images only - $commonShippingElements = array_intersect($A, $B); - if (!empty($missingShippingValues)) { - $inactive_where = ['isactive' => 1, 'customer_id' => (int)$last_insert_customer_id, 'address_type'=>2]; - $inactive_whereIn[0] = 'address_1'; - $inactive_whereIn[1] = $missingShippingValues; - $data_to_batch_update = ['isactive' => 0,'updated_by'=>$this->global_variable_user_id]; - $api_model->inactiveMissingDetails('customer_addresses',$data_to_batch_update, $inactive_where, $inactive_whereIn); - $this->logger->info("Api SaveCustomerDetails : Missing Shipping " .implode(",",$missingShippingValues)." Are inactived"); - } - } - } - - $where = ['customer_id' => (int)$last_insert_customer_id, 'isactive' => 1 ,'address_type'=>2]; - if (!empty($commonShippingElements)) { - $whereIn[0] = 'address_1'; - $whereIn[1] = $commonShippingElements; - } else { - $whereIn = null; - } - $lastestActiveShippingAdressData = $api_model->getData('customer_addresses', $where, $whereIn); - $this->logger->info("Api SaveCustomerDetails : lastest Active Shipping Data Count " .count($lastestActiveShippingAdressData)); - - foreach ($shipping as $ship) { - $shippingAddressId = null; - if ($ship->first_name !== '') { - if (!empty($lastestActiveShippingAdressData)) { - foreach ($lastestActiveShippingAdressData as $item) { - if ($item->address_1 == $ship->address_1) { - $shippingAddressId = $item->customer_address_id; - break; // Found the match, no need to continue looping - } - } - } - $customer_shipping_address_data[$j]['first_name'] = $ship->first_name; - $customer_shipping_address_data[$j]['last_name'] = $ship->last_name; - $customer_shipping_address_data[$j]['company'] = $ship->company; - $customer_shipping_address_data[$j]['address_1'] = $ship->address_1; - $customer_shipping_address_data[$j]['address_2'] = $ship->address_2; - $customer_shipping_address_data[$j]['city'] = $ship->city; - $customer_shipping_address_data[$j]['state'] = $ship->state; - $customer_shipping_address_data[$j]['country'] = $ship->country; - $customer_shipping_address_data[$j]['postal_code'] = $ship->postcode; - $customer_shipping_address_data[$j]['email'] = isset($ship->email)?$ship->email:""; - $customer_shipping_address_data[$j]['mobile_no'] = isset($ship->phone)?$ship->phone:""; - $customer_shipping_address_data[$j]['customer_id'] = $last_insert_customer_id; - $customer_shipping_address_data[$j]['address_type'] = 2; - $customer_shipping_address_data[$j]['customer_address_id'] = $shippingAddressId; - $this->logger->info("Api SaveCustomerDetails : Shipping address has a value and Inserted "); - $j++; - // echo "        Shipping address has a value and Inserted ".$j."
"; - } - else{ - $this->logger->info("Api SaveCustomerDetails : Shipping address has no value "); - // echo "        Keys are available but Shipping address has no value
"; - } - } - $extensive_correspondence .= (!empty($customer_shipping_address_data) ? $api_model->insertAndUpdateChildDetails($customer_shipping_address_data, 'customer_addresses', 'customer_address_id') : ""); - $this->logger->info("Api SaveCustomerDetails : ".$extensive_correspondence); - }else{ - $this->logger->error("Api SaveCustomerDetails : Err = Address Data Not Found"); - } - $response = ['status' => 200, 'message' => $basic_message ,'indetails' => $extensive_correspondence]; - } //if cond. closed - else { - $this->logger->error("Api SaveCustomerDetails : Err = Data Not Found"); - $response = ['status' => 204, 'message' => 'Data No Found']; - } - return $response; - } - - public function save_sales_details($records, $wordpress_order_id){ - $this->logger->info("Api SaveSalesDetails : records count = ".count($records).", wordpress Order Ref ID = ".$wordpress_order_id); - $basic_message=""; - $api_model = new ApiIntegrationModel(); - $extensive_correspondence = ""; - $invoice_id = ""; - if (count($records) > 0 && !empty($wordpress_order_id)) { - $where = ['wp_api_order_id' => $wordpress_order_id, 'isactive' => 1]; - $invoice_details = $api_model->setTable('invoice')->where($where)->first(); - if (isset($invoice_details['invoice_id']) && $invoice_details['invoice_id'] != "") { - $invoice_id = $invoice_details['invoice_id']; - $where['invoice_id'] = (int)$invoice_id; - } - $countAll = $api_model->countAll('invoice', $where); - $this->logger->info(($countAll) ? "Api SaveSalesDetails : in wordpress product ref ID = ".$wordpress_order_id." is available on Invoice table and its PrimaryKey = ".$invoice_id : "Api SaveSalesDetails : in wordpress order ref ID = ".$wordpress_order_id." Not available on Invoice table"); - $billing_addr = NULL;$shipping_addr = NULL; - $lineitems_array = []; - $billing_array = []; $shipping_array = []; - $lineitems_subtotal = 0; $lineitems_tax = 0; - $lineitems_discount = 0; $lineitems_total=0; - - // $line_items = ; - - if(isset($records['billing']) && gettype($records['billing']) === 'object') {$billing_array = [$records['billing']];} - if(isset($records['shipping']) && gettype($records['shipping']) === 'object') {$shipping_array = [$records['shipping']];} - $where = ['wp_api_customer_id' => (int)$records['customer_id'], 'isactive' => 1]; - $local_customer = $api_model->getData('donor', $where); - $local_customer_id = !empty($local_customer) ? $local_customer[0]->customer_id : NULL; - $this->logger->info((!empty($local_customer)) ? "Api SaveSalesDetails : in wordpress customer ref ID = ".$records['customer_id']." is available on Customer table and its PrimaryKey = ".$local_customer_id."(local customer id)" : "Api SaveSalesDetails : in wordpress customer ref ID = ".$records['customer_id']." Not available on Customer table"); - - if (count($billing_array) > 0) { - // foreach ($billing_array as $bill) { - // if($bill->first_name != ""){ - // $billing_addr = $bill->address_1 . " " . $bill->address_2 . ",\n" . $bill->city . ",\n" . $bill->state . " - " . $bill->postal_code . ",\n" . $bill->country . "."; - // } - // } - $result_billing_addr = $this->save_invoice_address_in_customer_address($billing_array,1,(int)$local_customer_id); - $billing_addr_id = $result_billing_addr['addr_id']; - $billing_addr = $result_billing_addr['addr']; - } - if (count($shipping_array) > 0) { - // foreach ($shipping_array as $ship) { - // if($ship->first_name != ""){ - // $shipping_addr = $ship->address_1 . " " . $ship->address_2 . ",\n" . $ship->city . ",\n" . $ship->state . " - " . $ship->postal_code . ",\n" . $ship->country . "."; - // } - // } - $result_shipping_addr = $this->save_invoice_address_in_customer_address($shipping_array,2,(int)$local_customer_id); - $shipping_addr_id = $result_shipping_addr['addr_id']; - $shipping_addr = $result_shipping_addr['addr']; - } - - if (count($records['line_items']) > 0) { - // echo count($records['line_items']);die; - $lineitems_array = $records['line_items']; - foreach ($lineitems_array as $item) { - $lineitems_subtotal += (float)$item->subtotal; - $lineitems_tax += (float)$item->total_tax; - } - $lineitems_total += ((float)$lineitems_subtotal + (float)$lineitems_tax) - (float)$lineitems_discount; - } - $method_title = ''; - $method_total = NULL; - if (count($records['shipping_lines']) > 0) { - $shipping_lines_array = $records['shipping_lines']; - foreach ($shipping_lines_array as $sl) { - $method_title = $sl->method_title; - $method_total = ((float)$sl->total)+((float)$sl->total_tax); - } - } - - $subtotal = (float)$lineitems_subtotal + (float)$records['shipping_total']; - $tax = $lineitems_tax + (float)$records['shipping_tax']; - $total = ($lineitems_total)+(float)$records['shipping_total'] + (float)$records['shipping_tax']; - - - $invoice_data['invoice_id']=$invoice_id; - $invoice_data['invoice_number']=$records['number']; - $invoice_data['customer_id']=$local_customer_id; - $invoice_data['wp_api_order_id']=$records['id']; - $invoice_data['invoice_date']=date("Y-m-d", strtotime($records['date_created'])); - $invoice_data['due_date']=NULL; - $invoice_data['subtotal']=(int)$subtotal; - $invoice_data['tax']=(int)$tax; - $invoice_data['discount']=(int)$lineitems_discount; - $invoice_data['total_amount']= $records['total']; - $invoice_data['payment_status']=$records['status']; - $invoice_data['order_number']=$records['order_key']; - $invoice_data['payment_method']=$records['payment_method_title']; - $invoice_data['status']='Approved'; - $invoice_data['event_id']=NULL; - $invoice_data['business_id']=$this->global_variable_business_id; - $invoice_data['shipping_address']=$shipping_addr; - $invoice_data['shipping_address_id']=$shipping_addr_id; - $invoice_data['billing_address']=$billing_addr; - $invoice_data['billing_address_id'] =$billing_addr_id; - $invoice_data['shipping_label'] = !empty($method_title)?$method_title:NULL; - $invoice_data['shipping_charge'] = isset($records['shipping_total'])?$records['shipping_total']: (!empty($method_total)?$method_total:NULL); - $invoice_data['notes'] = isset($records['customer_note'])?$records['customer_note']:NULL; - $invoice_data['invoice_type'] = 1; - if ((int)$countAll == 0) { - $invoice_data['created_by'] = $this->global_variable_user_id; - $insert_result = $api_model->insertData('invoice', $invoice_data); - $last_insert_invoice_id = $insert_result['info']; - $extensive_correspondence .= $insert_result['info'] ? "Invoice id : " . $insert_result['info'] - : "Err :" . $insert_result['err']; - $basic_message .= $insert_result['info'] ? " Invoice id : " . $insert_result['info'] : "Invoice details Not Inserted"; - $insert_result['info'] ? $this->logger->info("Api SaveSalesDetails : Invoice id = ".$insert_result['info']):""; - $insert_result['err'] ? $this->logger->error("Api SaveSalesDetails : Err = ".$insert_result['err']):""; - } else { - $last_insert_invoice_id = $invoice_id; - $customer_where = ['invoice_id' => $invoice_id, 'isactive' => 1, 'wp_api_order_id' => $wordpress_order_id]; - $invoice_data['updated_by'] = $this->global_variable_user_id; - $update_result = $api_model->updateData('invoice', $invoice_data, $customer_where); - $extensive_correspondence .= $update_result['info'] ? "Invoice id : " . $last_insert_invoice_id . " ( " . $update_result['info'] . ")" - : " ( Err :" . $update_result['err'] . ")"; - $basic_message .= "Invoice id : " . $last_insert_invoice_id; - $update_result['info'] ? $this->logger->info("Api SaveSalesDetails : Invoice id : " . $last_insert_invoice_id . " ( " . $update_result['info'] . ")"):""; - $update_result['err'] ? $this->logger->error("Api SaveSalesDetails : Err = ".$update_result['err']):""; - } - - $line_item_data = []; - $subscription_data = []; - //$shipping_line_item_data = []; - $h=0;$i = 0;//$j=0; - $this->logger->info("Api SaveSalesDetails : Invoice items count : " .count($lineitems_array)); - if (count($lineitems_array) > 0 && $last_insert_invoice_id != "") { - $extensive_correspondence .= " Its have " . count($lineitems_array) . " LineItems ,"; - $basic_message .= " Its have " . count($lineitems_array) . " LineItems"; - $this->logger->info("Api SaveSalesDetails : ".$extensive_correspondence); - - $where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1, 'quantity != '=>0]; - $existing_invoiceitem = $api_model->getData('invoiceitems', $where); - $request_invoiceitem = (array)$lineitems_array; - - $filteringExistingInvoiceItemWpApiId = []; - $filteringRequestedInvoiceItemWpApiId = []; - $filteringRequestedSKUWpId = []; - $commonElements = []; - if (!empty($existing_invoiceitem)) { - - for ($z = 0; $z < count($request_invoiceitem); $z++) { - $filteringRequestedInvoiceItemWpApiId[$z] = $request_invoiceitem[$z]->id; - } - for ($y = 0; $y < count($existing_invoiceitem); $y++) { - $filteringExistingInvoiceItemWpApiId[$y] = $existing_invoiceitem[$y]->wp_api_line_items_id; - } - - if (!empty($filteringExistingInvoiceItemWpApiId)) { - $this->logger->info("Api SaveSalesDetails : Incoming InvoiceItem Wp Id " .implode(",",$filteringRequestedInvoiceItemWpApiId)); - $this->logger->info("Api SaveSalesDetails : Existing InvoiceItem Wp Id " .implode(",",$filteringExistingInvoiceItemWpApiId)); - $A = $filteringExistingInvoiceItemWpApiId; - $B = $filteringRequestedInvoiceItemWpApiId; - $missingValues = array_diff($A, $B); //Find difference element in Existing Images only - $commonElements = array_intersect($A, $B); - if (!empty($missingValues)) { - $this->logger->info("Api SaveSalesDetails : Missing InvoiceItem Wp Id " .implode(",",$missingValues)." Are inactived"); - $inactive_where = ['isactive' => 1, 'invoice_id' => (int)$last_insert_invoice_id]; - $inactive_whereIn[0] = 'wp_api_line_items_id'; - $inactive_whereIn[1] = $missingValues; - $data_to_batch_update = ['isactive' => 0,'updated_by'=>$this->global_variable_user_id]; - $api_model->inactiveMissingDetails('invoiceitems',$data_to_batch_update, $inactive_where, $inactive_whereIn); - } - } - } - - $where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1, 'quantity != '=>0]; - if (!empty($commonElements)) { - $whereIn[0] = 'wp_api_line_items_id'; - $whereIn[1] = $commonElements; - } else { - $whereIn = null; - } - $lastestActiveInvoiceitemsData = $api_model->getData('invoiceitems', $where, $whereIn); - $this->logger->info("Api SaveSalesDetails : lastest Active Invoice Items Data Count " .count($lastestActiveInvoiceitemsData)); - - foreach ($lineitems_array as $ii) { - $invoiceItemsId = null; - $skuId = null; - - // Iterate through the array and find the 'book_img_id' based on 'wp_api_img_id' - if (!empty($lastestActiveInvoiceitemsData)) { - foreach ($lastestActiveInvoiceitemsData as $item) { - if ($item->wp_api_line_items_id == $ii->id) { - $invoiceItemsId = $item->invoice_child_id; - break; // Found the match, no need to continue looping - } - } - } - - $where = ['wp_api_product_id' => (int)$ii->product_id]; - $get_book_data_based_on_wp_product_id = $api_model->getData('books', $where); - $skuId = (string)$ii->sku; - - // $get_book_category = $api_model->getData('book_categories', ['book_id' => (int)$ii->product_id,'isactive'=>1]); - $get_book_category = $api_model->getBookCategories($ii->product_id); - // $result_book_category = array_filter($get_book_category, function ($element) { - // return $element['category_name'] === 'Membership' && $element['sku'] === $skuId; - // }); - $result_book_category = array_filter($get_book_category, function ($element) use ($skuId) { - return $element['category_name'] === 'Membership' && $element['sku'] === $skuId; - }); - $fromDate = NULL; - $toDate = NULL; - for ($x = 0; $x < count($result_book_category); $x++) { - $duration = $result_book_category[$x]['duration'] * 12; - $fromDateTimestamp = strtotime($records['date_created']); - $toDateTimestamp = strtotime("+$duration months", $fromDateTimestamp); - $fromDate = date("Y-m-d", strtotime($records['date_created'])); - $toDate = date("Y-m-d", $toDateTimestamp); - // $scheme_id = $result_book_category[$x]['category_id']; b4 - $scheme_id = $result_book_category[$x]['book_id']; - $dataToCheck = ['scheme_id'=>$scheme_id,'customer_id' => $local_customer_id,'invoice_id' => $invoice_id ]; - $existing_subscription = $api_model->getData('subscription', $dataToCheck); - if (count($existing_subscription) > 0) { - $this->logger->info("Api SaveSalesDetails : Subscription ".count($existing_subscription)." data already exists = ".json_encode($dataToCheck)); - } else { - $subscription_data[$x]['scheme_id'] = $result_book_category[$x]['category_id']; - $subscription_data[$x]['customer_id'] = $local_customer_id; - $subscription_data[$x]['invoice_id'] = $invoice_id; - $subscription_data[$x]['from_subscription'] = $fromDate; - $subscription_data[$x]['to_subscription'] = $toDate; - $subscription_data[$x]['mode'] = $result_book_category[$x]['category_name']; - $subscription_data[$x]['business_id']=$this->global_variable_business_id; - $this->logger->info("Api SaveSalesDetails : Subscription Data inx = $x Request data = ".json_encode($subscription_data)); - } - } - // echo $fromDate; - // echo $toDate; - // print_r($subscription_data);die; - // print_r($get_book_category); - // print_r($result_book_category); - // print_r($subscription_data); - // die; - // $skuId = $ii->sku; - // $this->logger->info("Api SaveSalesDetails : Lineitem SKU ID = " .$skuId); - - // $where = ['online_sku' => $skuId, 'isactive' => 1]; - // $existing_schemes = $api_model->getData('schemes', $where); - - // if(!empty($skuId) && !empty($existing_schemes)){ - // $duration = $existing_schemes[0]->duration; - // $fromDateTimestamp = strtotime($records['date_created']); - // $toDateTimestamp = strtotime("+$duration months", $fromDateTimestamp); - // $fromDate = date("Y-m-d", strtotime($records['date_created'])); - // $toDate = date("Y-m-d", $toDateTimestamp); - // $subscription_data[$h]['scheme_id'] = $existing_schemes[0]->scheme_id; - // $subscription_data[$h]['customer_id'] = $records['customer_id']; - // $subscription_data[$h]['invoice_id'] = $invoice_id; - // $subscription_data[$h]['from_subscription'] = $fromDate; - // $subscription_data[$h]['to_subscription'] = $toDate; - // $subscription_data[$h]['mode'] = "From WordPress Data"; - // $h++; - // $this->logger->info("Api SaveSalesDetails : Subscription Data inx = $h Request data = ".json_encode($subscription_data)); - // }else{ sku - $line_item_data[$i]['product'] = (!empty($get_book_data_based_on_wp_product_id) ? $get_book_data_based_on_wp_product_id[0]->book_id : NULL); - $line_item_data[$i]['quantity'] =(float)$ii->quantity; - $line_item_data[$i]['unit_price'] =(float)$ii->price; - $line_item_data[$i]['tax'] =(float)$ii->total_tax; - $line_item_data[$i]['subtotal'] =(int)$ii->total; - $line_item_data[$i]['invoice_child_id'] = $invoiceItemsId; - $line_item_data[$i]['wp_api_line_items_id'] = $ii->id; - $line_item_data[$i]['invoice_id'] = $last_insert_invoice_id; - $line_item_data[$i]['from_subscription'] = $fromDate; - $line_item_data[$i]['to_subscription'] = $toDate; - $i++; - $this->logger->info("Api SaveSalesDetails : Invoiceitem Data inx = $i Request data = ".json_encode($line_item_data)); - // } - } // line item loop closed - $extensive_correspondence .= (!empty($line_item_data) ? $api_model->insertAndUpdateChildDetails($line_item_data, 'invoiceitems', 'invoice_child_id') : ""); - $extensive_correspondence .= (!empty($subscription_data) ? $api_model->insertAndUpdateChildDetails($subscription_data, 'subscription', 'sub_id') : ""); - - $invoice_type_data[0]['invoice_type'] = count($result_book_category)>0 ? 2 : 1; - $invoice_type_data[0]['invoice_id'] = $last_insert_invoice_id; - (!empty($invoice_type_data) ? $api_model->insertAndUpdateChildDetails($invoice_type_data, 'invoice', 'invoice_id') : ""); - $this->logger->info("Api SaveSalesDetails : ".$extensive_correspondence); - $this->logger->info("Api SaveSalesDetails : ".$extensive_correspondence); - - } - else{ - $this->logger->error("Api SaveSalesDetails : Err = Invoice items Data Not Found"); - } - // $shipping_lineitems_array = $records['shipping_lines']; - // $this->logger->info("Api SaveSalesDetails : Shipping Invoice items count : " .count($shipping_lineitems_array)); - // if (count($shipping_lineitems_array) > 0 && $last_insert_invoice_id != "") { - // $extensive_correspondence .= " Its have " . count($shipping_lineitems_array) . " shipping details ,"; - // $basic_message .= " and Its have " . count($shipping_lineitems_array) . " shipping details"; - // $this->logger->info("Api SaveSalesDetails : ".$extensive_correspondence); - // $shipping_where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1,'quantity'=>0]; - // $existing_shipping_invoiceitem = $api_model->getData('invoiceitems', $shipping_where); - // $request_shipping_invoiceitem = (array)$shipping_lineitems_array; - - // $filteringExistingShippingInvoiceItemWpApiId = []; - // $filteringRequestedShippingInvoiceItemWpApiId = []; - // $commonShippingElements = []; - // if (!empty($existing_shipping_invoiceitem)) { - - // for ($z = 0; $z < count($request_shipping_invoiceitem); $z++) { - // $filteringRequestedShippingInvoiceItemWpApiId[$z] = $request_shipping_invoiceitem[$z]->id; - // } - // for ($y = 0; $y < count($existing_shipping_invoiceitem); $y++) { - // $filteringExistingShippingInvoiceItemWpApiId[$y] = $existing_shipping_invoiceitem[$y]->wp_api_line_items_id; - // } - - // if (!empty($filteringExistingShippingInvoiceItemWpApiId)) { - // $this->logger->info("Api SaveSalesDetails : Incoming InvoiceItem (Shipping) Wp Id " .implode(",",$filteringRequestedShippingInvoiceItemWpApiId)); - // $this->logger->info("Api SaveSalesDetails : Existing InvoiceItem (Shipping) Wp Id " .implode(",",$filteringExistingShippingInvoiceItemWpApiId)); - // $A = $filteringExistingShippingInvoiceItemWpApiId; - // $B = $filteringRequestedShippingInvoiceItemWpApiId; - - // $missingShippingValues = array_diff($A, $B); //Find difference element in Existing Images only - // $commonShippingElements = array_intersect($A, $B); - // if (!empty($missingShippingValues)) { - // $this->logger->info("Api SaveSalesDetails : Missing InvoiceItem (shipping) Wp Id " .implode(",",$missingShippingValues)." Are inactived"); - // $inactive_where = ['isactive' => 1, 'invoice_id' => (int)$last_insert_invoice_id]; - // $inactive_whereIn[0] = 'wp_api_line_items_id'; - // $inactive_whereIn[1] = $missingShippingValues; - // $api_model->inactiveMissingDetails('invoiceitems', $inactive_where, $inactive_whereIn); - // } - // } - // } - - // $where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1,'quantity'=>0]; - // if (!empty($commonShippingElements)) { - // $whereIn[0] = 'wp_api_line_items_id'; - // $whereIn[1] = $commonShippingElements; - // } else { - // $whereIn = null; - // } - // $lastestActiveShippingInvoiceitemsData = $api_model->getData('invoiceitems', $where, $whereIn); - // $this->logger->info("Api SaveSalesDetails : lastest Active Invoice Item (shipping) Data Count " .count($lastestActiveShippingInvoiceitemsData)); - - // foreach ($shipping_lineitems_array as $sii) { - // $shippingInvoiceItemsId = null; - - // // Iterate through the array and find the 'book_img_id' based on 'wp_api_img_id' - // if (!empty($lastestActiveShippingInvoiceitemsData)) { - // foreach ($lastestActiveShippingInvoiceitemsData as $item) { - // if ($item->wp_api_line_items_id == $sii->id) { - // $shippingInvoiceItemsId = $item->invoice_child_id; - // break; // Found the match, no need to continue looping - // } - // } - // } - - // $where = ['title' => (int)$sii->method_title]; - // $get_book_data_based_on_title = $api_model->getData('books', $where); - - // $shipping_line_item_data[$j]['product'] = (!empty($get_book_data_based_on_title) ? $get_book_data_based_on_title[0]->book_id : NULL); - // $shipping_line_item_data[$j]['quantity'] = 0; - // $shipping_line_item_data[$j]['unit_price'] =0; - // $shipping_line_item_data[$j]['tax'] =(float)$sii->total_tax; - // $shipping_line_item_data[$j]['subtotal'] =(float)$sii->total; - // $shipping_line_item_data[$j]['invoice_child_id'] = $shippingInvoiceItemsId; - // $shipping_line_item_data[$j]['wp_api_line_items_id'] = $sii->id; - // $shipping_line_item_data[$j]['invoice_id'] = $last_insert_invoice_id; - // $this->logger->info("Api SaveSalesDetails : Invoiceitem Data For Shipping inx = $j "); - // $j++; - // } // line item loop closed - // $extensive_correspondence .= (!empty($shipping_line_item_data) ? $api_model->insertAndUpdateChildDetails($shipping_line_item_data, 'invoiceitems', 'invoice_child_id') : ""); - // $this->logger->info("Api SaveSalesDetails : ".$extensive_correspondence); - // } - // else{ - // $this->logger->error("Api SaveSalesDetails : Err = Invoice items (Shipping) Data Not Found"); - // } - $response = ['status' => 200, 'message' => $basic_message ,'indetails' => $extensive_correspondence]; - } - else { - $this->logger->error("Api SaveSalesDetails : Err = Data Not Found"); - $response = ['status' => 204, 'message' => 'Data No Found']; - } - return $response; - } - - public function save_categories_master_details($records) - { - $api_model = new ApiIntegrationModel(); - if (count($records) > 0) { - $this->logger->info("Api SaveCategoriesMasterDetails : Master Categories Count = " . count($records)); - $where = ['isactive' => 1]; - $where_in = null; - $existing_master_categories = $api_model->getData('category', $where); - $request_master_categories = (array)$records; - $common_master_categories = []; - $filter_existing_master_categories_WPID = []; - $filter_request_master_categories_WPID = []; - if (!empty($request_master_categories)) { - for ($z = 0; $z < count($request_master_categories); $z++) { - $filter_request_master_categories_WPID[$z] = $request_master_categories[$z]->id; - } - $this->logger->info("Api SaveCategoriesMasterDetails : Incoming Categories Wp Id " . implode(",", $filter_request_master_categories_WPID)); - } - if (!empty($existing_master_categories)) { - for ($y = 0; $y < count($existing_master_categories); $y++) { - $filter_existing_master_categories_WPID[$y] = $existing_master_categories[$y]->wp_api_category_id; - } - $this->logger->info("Api SaveCategoriesMasterDetails : Existing Categories Wp Id " . implode(",", $filter_existing_master_categories_WPID)); - } - if (!empty($filter_existing_master_categories_WPID)) { - $common_master_categories = array_intersect($filter_existing_master_categories_WPID, $filter_request_master_categories_WPID); - if (!empty($common_master_categories)) { - $where_in[0] = 'wp_api_category_id'; - $where_in[1] = $common_master_categories; - } - } - $lastestActiveMasterCategoriesData = $api_model->getData('category', $where, $where_in); - $this->logger->info("Api SaveCategoriesMasterDetails : lastest Active Book Categories Data Count " . count($lastestActiveMasterCategoriesData)); - $book_category_data = []; - $a = 0; - foreach ($request_master_categories as $r) { - $masterCategoryId = null; - if (!empty($lastestActiveMasterCategoriesData)) { - foreach ($lastestActiveMasterCategoriesData as $l) { - if ($l->wp_api_category_id == $r->id) { - $masterCategoryId = $l->id; //local category id from Master Table - break; // Found the match, no need to continue looping - } - } - } - $book_category_data[$a]['id'] = $masterCategoryId; - $book_category_data[$a]['name'] = $r->name; - $book_category_data[$a]['wp_api_category_id'] = $r->id; - $book_category_data[$a]['business_id'] = $this->global_variable_business_id; - $book_category_data[$a]['parent_wp_api_category_id'] = NULL; - $a++; - $this->logger->info("Api SaveCategoriesMasterDetails : Categories Data = $a Request data to save on master category = " . json_encode($book_category_data)); - } // loop closed - $message = (!empty($book_category_data) ? $api_model->insertAndUpdateChildDetails($book_category_data, 'category', 'id') : "Info : New Categories Not Avaialble to Save"); - $this->logger->info("Api SaveCategoriesMasterDetails : " . $message); - } // count closed - else { - $this->logger->error("Api SaveCategoriesMasterDetails : Err = Categories Data Not Found"); - } - } - - public function save_invoice_address_in_customer_address($request_addr_array,$flag,$customer_id){ - $this->logger->info("Api saveInvoiceAddressInCustomerAddress = ".json_encode($request_addr_array)); - $this->logger->info("Api saveInvoiceAddressInCustomerAddress Flag = ".$flag." Customer Id = ".$customer_id); - $api_model = new ApiIntegrationModel(); - $where = ['customer_id' =>$customer_id,'address_type'=>(int)$flag, - 'first_name'=>$request_addr_array[0]->first_name,'last_name'=>$request_addr_array[0]->last_name, - 'address_1'=>$request_addr_array[0]->address_1,'address_2'=>$request_addr_array[0]->address_2, - 'city'=>$request_addr_array[0]->city,'postal_code'=>$request_addr_array[0]->postcode]; - $existing_addr = $api_model->getData('customer_addresses', $where); - $this->logger->info("Api saveInvoiceAddressInCustomerAddress Count = ".count($existing_addr)); - $final_array['addr_id'] = NULL; - $final_array['addr'] = NULL; - - $addr_data = []; - - if (!empty($existing_addr)) { - $final_array['addr_id'] = isset($existing_addr) && !empty($existing_addr) ? $existing_addr[0]->customer_address_id : NULL; - $this->logger->info("Api saveInvoiceAddressInCustomerAddress Ex Addr id = ".$final_array['addr_id']); - if($existing_addr[0]->first_name != ""){ - $final_array['addr'] = $existing_addr[0]->address_1 . " " . $existing_addr[0]->address_2 . ",\n" . $existing_addr[0]->city . ",\n" . $existing_addr[0]->state . " - " . $existing_addr[0]->postal_code . ",\n" . $existing_addr[0]->country . "."; - } - $this->logger->info("Api saveInvoiceAddressInCustomerAddress Ex Addr = ".$final_array['addr']); - } - if (empty($existing_addr)) { - foreach ($request_addr_array as $addr) { - if($addr->first_name != ""){ - $addr_data['first_name'] = $addr->first_name; - $addr_data['last_name'] = $addr->last_name; - $addr_data['company'] = $addr->company; - $addr_data['address_1'] = $addr->address_1; - $addr_data['address_2'] = $addr->address_2; - $addr_data['city'] = $addr->city; - $addr_data['state'] = $addr->state; - $addr_data['country'] = $addr->country; - $addr_data['postal_code'] = $addr->postcode; - $addr_data['email'] = isset($addr->email)? $addr->email:""; - $addr_data['mobile_no'] = isset($addr->phone)?$addr->phone:""; - $addr_data['customer_id'] = $customer_id; - $addr_data['address_type'] = $flag; - $addr_data['customer_address_id'] = NULL; - $addr_data['created_by'] = $this->global_variable_user_id; - $final_array['addr'] = $addr->address_1 . " " . $addr->address_2 . ",\n" . $addr->city . ",\n" . $addr->state . " - " . $addr->postcode . ",\n" . $addr->country . "."; - } - } - $this->logger->info("Api saveInvoiceAddressInCustomerAddress New Addr = ".$final_array['addr']); - if(!empty($addr_data)){ - - $insert_result = $api_model->insertData('customer_addresses',$addr_data); - $final_array['addr_id'] = $insert_result['info']; - $this->logger->info("Api saveInvoiceAddressInCustomerAddress New Addr id = ".$final_array['addr_id']); - } - - } - return $final_array; - } -} \ No newline at end of file diff --git a/app/Controllers/AppSettings.php b/app/Controllers/AppSettings.php deleted file mode 100644 index 3f15946..0000000 --- a/app/Controllers/AppSettings.php +++ /dev/null @@ -1,151 +0,0 @@ - 1]; - if (!empty($session_role) && $session_role !== "sadmin") { - $where = ['app_settings.business_id' => $session_bid, 'app_settings.isactive' => 1]; - } - - $model = new AppSettingModel(); - $model->setTable('app_settings'); - $sitesetting_details = $model->where($where)->orderBy('app_setting_id', 'DESC')->findAll(); - $data['page_name'] = 'App Settings Details'; - $data['details'] = $sitesetting_details; - $data['session_role'] = $session_role; - $this->render_page('app_setting_list', $data); - } - - ## To Load Settings Add/Update page - public function appsetting_page($id) - { - if ($id === '0') { - $data['page_name'] = 'Add Site Settings'; - $data['details'] = []; - } else if ($id !== '0') { - $data['page_name'] = 'Edit App Settings'; - $model = new AppSettingModel(); - $model->setTable('app_settings'); - $details = $model->where(['app_setting_id' => $id, 'isactive' => 1])->first(); - $data['details'] = $details; - - } - $data['business_details']=$this->business_details(); - $this->render_page('app_setting_form', $data); - } - public function business_details() - { - $model = new BusinessModel(); - $model->setTable('business'); - $business_details = $model->where('business_id', 0)->orderBy('business_id', 'DESC')->findAll(); - return $business_details; - } - - - ## To Save/Update Setting Data on DB. - public function appsetting_synchronization() - { - helper('session'); - $session_bid = get_business_id(); - $session_uid = get_logged_user_id(); - - - - $img = $this->request->getFile('slogo'); - $business_id = $this->request->getPost('business_id'); - $app_setting_id = $this->request->getPost('app_setting_id'); - $filePath = 'public/uploads/' . $this->request->getPost('slogo'); - $fileName = $img->getName(); - - if($fileName !== ""){ - - if ($img->isValid() && !$img->hasMoved()) { - - $img->move(ROOTPATH . 'public/uploads', $fileName); - } - - } - - - $favicon = $this->request->getFile('favicon'); - $faviconName = $favicon->getName(); - - if($faviconName !== ""){ - - if ($favicon->isValid() && !$favicon->hasMoved()) { - - $favicon->move(ROOTPATH . 'public/uploads', $faviconName); - } - } - - - $AppSettingModel = new AppSettingModel(); - $data = [ - - 'site_name' => $this->request->getPost('site_name'), - 'site_title' => $this->request->getPost('site_title'), - 'terms_service' => $this->request->getPost('terms_service'), - 'footer_about' => $this->request->getPost('footer_about'), - 'admin_email' => $this->request->getPost('admin_email'), - 'mobile'=> $this->request->getPost('mobile'), - 'copyright'=> $this->request->getPost('copyright'), - 'pagination_limit'=> $this->request->getPost('pagination_limit'), - 'site_info'=> $this->request->getPost('site_info'), - 'about_info'=> $this->request->getPost('about_info'), - 'mail_protocol'=> $this->request->getPost('mail_protocol'), - 'mail_title'=> $this->request->getPost('mail_title'), - 'mail_host'=> $this->request->getPost('mail_host'), - 'mail_port'=> $this->request->getPost('mail_port'), - 'mail_encryption'=> $this->request->getPost('mail_encryption'), - 'mail_username'=> $this->request->getPost('mail_username'), - 'mail_password'=> $this->request->getPost('mail_password'), - 'currency'=> $this->request->getPost('currency'), - 'country'=> $this->request->getPost('country'), - 'business_id'=> $this->request->getPost('business_id'), - - ]; - - if($fileName !== "") - { - $data['logo'] = $fileName; - } - - if($faviconName !== "") - { - $data['favicon'] = $faviconName; - } - - - $app_setting_id = $this->request->getPost('app_setting_id'); // Get the business ID for update - - - if (empty($app_setting_id)) { - // It's an insert operation - $data['isactive'] = 1; - $data['created_by'] = $session_uid; - - $AppSettingModel->insert($data); - // print_r($data);die; - } else { - // It's an update operation - $isactive = $this->request->getPost('isactive'); - $data['isactive'] = ($isactive == 'on') ? 1 : 0; - $data['updated_by'] = $session_uid; - $AppSettingModel->update($app_setting_id, $data); - } - return redirect()->route('dashboard'); - } -} - - - diff --git a/app/Controllers/Authentication.php b/app/Controllers/Authentication.php index 49a32b4..d4a98b2 100644 --- a/app/Controllers/Authentication.php +++ b/app/Controllers/Authentication.php @@ -338,4 +338,65 @@ class Authentication extends BaseController $pwd_verify = password_verify((string)$password, $user['password']); return $pwd_verify ; } + + #change password + public function change_password() + { + helper('session'); + $session_uid = get_logged_user_id(); + if (is_session_active()) { + $requested = $this->request->getPost(); + // $mail_id = $requested['user_mail']; + $old_pwd = $requested['user_old_password']; + $new_pwd = $requested['user_new_password']; + $conf_pwd = $requested['user_confirm_password']; + $auth_model = new AuthenticationModel(); + $user = $auth_model->where('user_id', $session_uid)->first(); + $pwd_verify = password_verify((string)$old_pwd, $user['password']); + + if($pwd_verify){ + + if ($old_pwd === $new_pwd) { + $response['status'] = false; + $response['message'] = "New password should not be the same as the old password."; + $this->logger->error($response['message']); + return $this->response->setJSON(['data' => $response]); + } + if ($new_pwd !== $conf_pwd) { + $response['status'] = false; + $response['message'] = "New password and confirm password do not match."; + $this->logger->error($response['message']); + return $this->response->setJSON(['data' => $response]); + } + $hash_password = password_hash($new_pwd, PASSWORD_DEFAULT); + + $user_details = $auth_model->where(['user_id'=> $session_uid, 'isactive' => 1])->first(); + // print_r($user_details);die; + if ($user_details) { + $update_user_details = ['user_id', $session_uid, 'password' => $hash_password]; + $auth_model->update($user_details['user_id'], $update_user_details); + $response['status'] = true; + $response['message'] = "Password Updated.."; + $this->logger->error($response['message']); + }else{ + $response['status'] = false; + $response['message'] = "Can't able to change"; + $this->logger->error($response['message']); + } + } else { + $response['status'] = false; + $response['message'] = "Old Password Wrong"; + $this->logger->error($response['message']); + + + } + }else { + $response['status'] = false; + $response['message'] = "Something Went Wrong"; + $this->logger->error($response['message']); + + + } + return $this->response->setJSON(['data' => $response]); + } } \ No newline at end of file diff --git a/app/Controllers/Books.php b/app/Controllers/Books.php index 4d5d0b1..96d2244 100644 --- a/app/Controllers/Books.php +++ b/app/Controllers/Books.php @@ -7,7 +7,7 @@ use App\Models\BooksModel; class Books extends BaseController { - ## For Book Listing + ## For Causes Listing public function index() { helper('session'); @@ -26,16 +26,14 @@ class Books extends BaseController $data['cause_list'] = $model->getData('donations_accepted',null,null); $data['page_name'] = 'Causes List'; $data['details'] = $model->where('causes.business_id', $session_bid)->where('causes.isactive', 1)->findAll(); - // echo '
';
-            // print_r($data); die;
             $this->render_page('book_list', $data);
         } else {
             // Session is not active or user is not logged in
             return redirect()->to('login');
         }
     }
-
-    ## To Load Book Form (Add/Update)
+    
+    ## To Load Causes Form (Add/Update)
     public function add_causes($id)
     {
         helper('session');
@@ -60,8 +58,8 @@ class Books extends BaseController
         $this->render_page('book_form', $data);
     }
     
-    ## For inserting/updating details of book
-    public function insert_books()
+    ## For inserting/updating details of Cause
+    public function insert_causes()
     {
      try{
         helper('session');
@@ -121,8 +119,8 @@ class Books extends BaseController
         return redirect()->route('causes_list');
     }
 
-    ## For delete the book details (Which means inactive the details)
-    public function delete_books($id)
+    ## For delete the causes details (Which means inactive the details)
+    public function delete_causes($id)
     {
         try {
             helper('session');
@@ -146,5 +144,4 @@ class Books extends BaseController
         return redirect()->route('causes_list');
     }
 
-
 }
diff --git a/app/Controllers/Business.php b/app/Controllers/Business.php
index 0c52e5d..1c6d92a 100644
--- a/app/Controllers/Business.php
+++ b/app/Controllers/Business.php
@@ -22,7 +22,7 @@ class Business extends BaseController
             }
             $BusinessModel = new BusinessModel();
             $data['page_name'] = 'Organization Details';
-            $data['businesses'] = $BusinessModel->where($where)->where('business_id !=', 0)->where('isactive', 1)->findAll();
+            $data['organzations'] = $BusinessModel->where($where)->where('business_id !=', 0)->where('isactive', 1)->findAll();
             // $data['lastQuery'] = $BusinessModel->getLastQuery();
             // print_r($data);die;
             $this->render_page('business_list', $data);
@@ -42,7 +42,7 @@ class Business extends BaseController
         if ($id === '0') {
             $data['page_name'] = 'Add Organization';
             $data['loged_user'] = $session_role;
-            $data['businesses'] = [];
+            $data['organzations'] = [];
             $data['branches'] = [];
             $data['donation']=[];
         } else if ($id !== '0') {
@@ -52,8 +52,8 @@ class Business extends BaseController
             $model->setTable('business');
     
             ## Fetch business details (particular business)
-            $edit_business_details = $model->where(['business_id ' => $id , 'isactive' => 1])->first();
-            $data['businesses'] = $edit_business_details;
+            $edit_organzation_details = $model->where(['business_id ' => $id , 'isactive' => 1])->first();
+            $data['organzations'] = $edit_organzation_details;
 
             ## Fetch branch details
             $branch_details = $model->getBranchesByBusinessId($id);
@@ -67,12 +67,12 @@ class Business extends BaseController
             
         }
         
-        $data['master_business_details']=$this->business_details();
+        $data['master_organzation_details']=$this->organzation_details();
         $data['session_bid']=$session_bid;
         $this->render_page('business_form', $data);
     }
 
-    public function business_details()
+    public function organzation_details()
     {
         helper('session');
         $session_role = get_user_role();
@@ -82,13 +82,13 @@ class Business extends BaseController
         $model->setTable('business');
         if($session_role === 'sadmin'){
 
-            $business_details = $model->where('business_id !=', 0)->orderBy('business_id', 'DESC')->findAll();
+            $organzation_details = $model->where('business_id !=', 0)->orderBy('business_id', 'DESC')->findAll();
         }
         else{
-            $business_details = $model->where('business_id', $session_bid)->findAll();
+            $organzation_details = $model->where('business_id', $session_bid)->findAll();
 
         }
-        return $business_details;
+        return $organzation_details;
     }
     
 
diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php
index d70f608..76c5842 100644
--- a/app/Controllers/Home.php
+++ b/app/Controllers/Home.php
@@ -40,4 +40,23 @@ class Home extends BaseController
             
     }
 
+    public function check_existing()
+    {
+        $value = $this->request->getPost('value');
+        $table = $this->request->getPost('module');
+        $field = $this->request->getPost('field');
+        $model = new HomeModel();
+        // $model->setTable('customers');
+        $model->setTable((string)$table);
+        $where = [$field => $value];
+        $check_existing = $model->where($where)->findAll();
+        
+        $statement_string = ucfirst(str_replace('_', ' ', (string)$field));
+        $data = ['status' => false, 'message' => '']; // Initialize the data array
+        if (!empty($check_existing)) {
+            $data['status'] = true;
+            $data['message'] = $statement_string." Already existing";
+        }
+        return $this->response->setJSON(['data' => $data]);
+    }
 }
diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php
index 58c8f70..b387175 100644
--- a/app/Controllers/Invoice.php
+++ b/app/Controllers/Invoice.php
@@ -125,7 +125,7 @@ class Invoice extends BaseController
     
         // receipt number
         $settingData =  $this->BusinessModel->select('*')->where($where)->findAll();
-        $count_receipt_no = (count($receipt) > 0) ? count($receipt) + $settingData[0]['start_no'] + 1 : $settingData[0]['start_no'] + 1;
+        $count_receipt_no = (count($receipt) > 0) ? count($receipt) + $settingData[0]['start_no'] : $settingData[0]['start_no'];
         
         // Calculate padding based on the count of digits in count_receipt_no
         $padding_count = max(0, $settingData[0]['left_pad'] - strlen($count_receipt_no));
@@ -139,7 +139,7 @@ class Invoice extends BaseController
         $data['causes']  = $bmodel->select('*')->where('business_id', (int)get_business_id())->where('isactive',1)->get()->getResult();
         $data['campaign']    = $model->getData('campaign', $where);
         $data['invoice_number_formatting'] = $model->getData('business', $where);
-        $data['receipt_type'] = "option1";
+        $data['receipt_type'] = "individual";
         if ($id === '0') {
             $this->logger->info("Receipt: In Add Details");
             $data['page_name']       = 'Add Receipt Details';
@@ -515,6 +515,7 @@ class Invoice extends BaseController
             $currency_data = $model->setTable('business')->select('currency')->where($where)->findAll();
             $terms_data =  $this->BusinessModel->select('terms,signature')->where($where)->findAll();
             $data = $model->getInvoiceData($id);
+            // print_r($data);die;
             // Check if data is empty
             if (!$data || !$currency_data) {
                 throw new \Exception('Data not found or empty');
@@ -533,13 +534,16 @@ class Invoice extends BaseController
             $dompdf = new Dompdf($options);
     
             define("DOMPDF_UNICODE_ENABLED", true);
-            $user = $this->UserModel->select('first_name')->where('user_id',$data[0]->created_by)->findAll();
-            $logoPath = base_url()."public/uploads/".$data[0]->business_logo;
+            $user = $this->UserModel->select('first_name')->where('user_id',$data[0]->created_by)->findAll();            
+            
+            clearstatcache();
 
-            if ($data[0]->business_logo && file_exists($logoPath)) {
-                $baseurl = $logoPath;
+            // var_dump(file_exists($logoPath));
+            if ($data[0]->business_logo && file_exists(ROOTPATH."public/uploads/".$data[0]->business_logo)) {
+                // echo "Inside: Logo exists
"; + $baseurl = base_url()."public/uploads/".$data[0]->business_logo;; } else { - // Logo does not exist, handle this case accordingly + // echo "Inside: Logo does not exist
"; die; $baseurl = base_url()."public/uploads/default.png"; } $digits = strlen((string)$data[0]->amount); @@ -550,7 +554,7 @@ class Invoice extends BaseController 'currency' => $data[0]->currency, 'currency_in_words' => $amount_in_words , 'baseurl' => $baseurl, - 'signature' => $terms_data[0]['signature'], + 'signature' => "", 'staff_name' => $user[0]['first_name'], 'Notes' => $terms_data[0]['terms'] ]); diff --git a/app/Controllers/Settings.php b/app/Controllers/Settings.php deleted file mode 100644 index 42d6899..0000000 --- a/app/Controllers/Settings.php +++ /dev/null @@ -1,213 +0,0 @@ - 1]; - if (!empty($session_role) && $session_role !== "sadmin") { - $where = ['settings.business_id' => $session_bid, 'settings.isactive' => 1]; - } - - $model = new SettingsModel(); - $model->setTable('settings'); - $sitesetting_details = $model->where($where)->orderBy('setting_id', 'DESC')->findAll(); - $data['page_name'] = 'Org Settings Details'; - $data['details'] = $sitesetting_details; - $data['session_role'] = $session_role; - $this->render_page('setting_list', $data); - } - - ## To Load Settings Add/Update page - public function sitesetting_page($id) - { - helper('session'); - $session_role = get_user_role(); - $session_bid = get_business_id(); - - if ($id === '0') { - $data['page_name'] = 'Add Org Settings'; - $data['details'] = []; - } else if ($id !== '0') { - $data['page_name'] = 'Edit Org Settings'; - - $model = new SettingsModel(); - $model->setTable('settings'); - if($session_role === 'sadmin'){ - - $details = $model->where(['setting_id' => $id, 'isactive' => 1])->first(); - } - else{ - $details = $model->where(['business_id' => $session_bid, 'isactive' => 1])->first(); - - } - $data['details'] = $details; - - } - - - $data['business_details']=$this->business_details(); - - // echo '
';
-        // print_r($data); die;
-        $this->render_page('setting_form', $data);
-    }
-    public function business_details()
-    {
-        helper('session');
-        $session_role = get_user_role();
-        $session_bid = get_business_id();
-
-        $model = new BusinessModel();
-        $model->setTable('business');
-        if($session_role === 'sadmin'){
-
-            $business_details = $model->where('business_id !=', 0)->orderBy('business_id', 'DESC')->findAll();
-        }
-        else{
-            $business_details = $model->where('business_id', $session_bid)->findAll();
-
-        }
-        return $business_details;
-    }
-
-
-    ## To Save/Update Setting Data on DB.
-    public function sitesetting_synchronization()
-    {
-        helper('session');
-        $session_bid = get_business_id();
-        $session_uid = get_logged_user_id();
-        $session_role = get_user_role();
-    
-        $img = $this->request->getFile('slogo');
-        print_r($img);
-        $business_id = $this->request->getPost('business_id');
-        $app_setting_id = $this->request->getPost('app_setting_id'); 
-        $filePath = 'public/uploads/' . $this->request->getPost('slogo');
-        $fileName   =   $img->getName();
-        var_dump($fileName);
-        echo $fileName;
-        echo $fileName !== "" && $fileName !== null ? "Yes":"No";
-        // die();
-
-        if($fileName !== ""){
-
-            if ($img->isValid() && !$img->hasMoved()) {
-
-                $img->move(ROOTPATH . 'public/uploads', $fileName);   
-            }
-            
-        }
-        
-
-        $favicon = $this->request->getFile('favicon');
-        $faviconName = $favicon->getName();
-
-            if($faviconName !== ""){
-
-            if ($favicon->isValid() && !$favicon->hasMoved()) {
-
-                $favicon->move(ROOTPATH . 'public/uploads', $faviconName);
-            }
-        }
-
-        $SettingsModel = new SettingsModel();
-        $data = [
-           
-            'site_name' => $this->request->getPost('site_name'),
-            'site_title' => $this->request->getPost('site_title'),
-            'terms_service' => $this->request->getPost('terms_service'),
-            'footer_about' => $this->request->getPost('footer_about'),
-            'admin_email' => $this->request->getPost('admin_email'),
-            'mobile'=> $this->request->getPost('mobile'),
-            'copyright'=> $this->request->getPost('copyright'),
-            'pagination_limit'=> $this->request->getPost('pagination_limit'),
-            'site_info'=> $this->request->getPost('site_info'),
-            'about_info'=> $this->request->getPost('about_info'),
-            'mail_protocol'=> $this->request->getPost('mail_protocol'),
-            'mail_title'=> $this->request->getPost('mail_title'),
-            'mail_host'=> $this->request->getPost('mail_host'),
-            'mail_port'=> $this->request->getPost('mail_port'),
-            'mail_encryption'=> $this->request->getPost('mail_encryption'),
-            'mail_username'=> $this->request->getPost('mail_username'),
-            'mail_password'=> $this->request->getPost('mail_password'),
-            'currency'=> $this->request->getPost('currency'),
-            'country'=> $this->request->getPost('country'),
-            'business_id'=> $this->request->getPost('business_id'),
-            'start_no'=> $this->request->getPost('start_no'),
-            'left_pad'=> $this->request->getPost('left_pad'),
-            'prefix_format'=> $this->request->getPost('prefix_format'),
-        ];
-
-        if($fileName !== "" && $fileName !== null)
-        {
-            $data['logo'] = $fileName;
-        }
-
-        if($faviconName !== "" && $faviconName !== null)
-        {
-            $data['favicon'] = $faviconName;
-        }
-
-        // echo '
';
-        // print_r($data); die;
-
-        $setting_id = $this->request->getPost('setting_id'); // Get the business ID for update
-        
-        if (empty($setting_id)) {
-            // It's an insert operation
-            $data['isactive'] = 1;
-            $data['created_by'] = $session_uid;
-          
-            $SettingsModel->insert($data);
-            // print_r($data);die;
-        } else {
-            // It's an update operation
-            $isactive = $this->request->getPost('isactive');
-            $data['isactive'] = ($isactive == 'on') ? 1 : 0;
-            $data['updated_by'] = $session_uid;
-            $SettingsModel->update($setting_id, $data);
-        }
-
-        if($session_role === 'sadmin'){
-
-            return redirect()->route('sitesetting_list');
-        }
-        else{
-            return redirect()->route('dashboard');
-        }
-    }
-}
-
-        
-//         $model = new SettingsModel();
-//         $model->setTable('settings');
-//         if ($this->request->is('post')) {
-//             $requestData = $this->request->getVar();
-//         }
-//         $requestData['business_id'] = $session_bid;
-//         if ($requestData['setting_id']) {
-//             #edit
-//             $requestData['updated_by'] = $session_uid;
-//             $requestData['isactive'] = isset($requestData['isactive']) && $requestData['isactive'] == 'on' ? 1 : 0;
-//             $model->saveData($requestData, $requestData['setting_id']);
-//             $alert_message = "Site Settings details successfully updated.";
-//         } else {
-//             #add
-//             $requestData['created_by'] = $session_uid;
-//             $requestData['isactive'] = 1;
-//             $model->saveData($requestData, null);
-//             $alert_message = "Site Settings details successfully created.";
-//         }
-//         return redirect()->route('sitesetting_list');
-//     }
-// }
diff --git a/app/Controllers/Subscription.php b/app/Controllers/Subscription.php
deleted file mode 100644
index d77b3ab..0000000
--- a/app/Controllers/Subscription.php
+++ /dev/null
@@ -1,217 +0,0 @@
-logger->info("Invoice: Listing In Admin BID = " . $session_bid);
-                $where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1];
-            } else {
-                $this->logger->info("Invoice: Listing In the Super-Admin ");
-                $where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL];
-            }
-              
-                $model = new InvoiceModel();
-                $data['page_name'] = 'Subscription Invoice Details';
-                $data['invoice'] = $model->getSubscriptionInvoiceDetail($where);
-              
-                $this->logger->info("Invoice: Listing Count ." . count($data['invoice']));
-              
-        
-       // $data['subscriber'] = $SubscriptionModel->where($where)->findAll();;
-       
-        
-        $SubscriptionModel = new SubscriptionModel();
-        $swhere = ['subscription.business_id' => (int)$session_bid];
-        $data['subscriber'] = $SubscriptionModel->getAllSubscribersWithNames($swhere);
-        $this->render_page('subscribers_list', $data);
-    }else { 
-        return redirect()->to('login');
-    }
-}
- public function new_subscription() {
-         
-    helper('session');
-    helper('session');
-    $session_bid = get_business_id();
-    $data['page_name'] = 'Subscription Details';
-    $customerModel = new CustomerModel();
-    $schemeModel = new SchemeModel();
-
-    $business_id = get_business_id();
-
-    // Get scheme names and durations from the SchemeModel
-    $data['customers'] = $customerModel->getCustomerNamesByBusiness($business_id);
-    $data['scheme_names'] = $schemeModel->getSchemeNamesAndDurationsByBusiness($business_id);
-    
-    //print_r($data);die();
-    $this->render_page('subscription_form', $data);
-}
-
-// Subscription Controller (Subscription.php)
-public function add_subscription() {
-    helper('session');
-        $session_bid = get_business_id();
-        $session_uid = get_logged_user_id();
-        
-    $SubscriptionModel = new SubscriptionModel();
-    $data = [
-        'scheme_id' =>$this->request->getPost('scheme'),
-        'customer_id' =>$this->request->getPost('customer'),
-        'from_subscription' => $this->request->getPost('from_date'),
-        'to_subscription' => $this->request->getPost('to_date'),
-        // 'type' => "subscribed customer",
-        'type' => "customer",
-        'mode' => $this->request->getPost('mode'),
-        'business_id'=>$session_bid 
-    ];
-    
-    $SubscriptionModel->insert($data);
-
-    // $data['subscriber'] = $subscriberModel->getAllSubscribersWithNames(); 
-    // print_r($data);die();
-    return redirect()->to('subscribers_list')->with('data', $data);
-}
-    
-// Subscription.php (Controller)
-
-// public function download_details()
-// {
-//     $selectedScheme = $this->request->getPost('selected_scheme');
-
-//     // Call the model method to get customer details for the selected scheme
-//     $subscriptionModel = new SubscriptionModel();
-//     $business = $subscriptionModel->getCustomerAddressesBySchemeName($selectedScheme);
-
-//     $shippingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($selectedScheme, 2);
-//     $customerName = $subscriptionModel->getCustomerNameBySchemeName($selectedScheme);
-
-//     // Create an HTML content string using the view file (similar to print_addresses.php)
-//     if ($customerName !== 'Customer not found') {
-//         $html = view('print_addresses_form', ['customerName' => $customerName, 'shippingInfo' => $shippingInfo, 'business' => $business]);
-
-//         // Generate a PDF from the HTML content
-//         $pdf = new Mpdf();
-
-//         $pdf->WriteHTML($html);
-
-//         // Set the PDF filename
-//         $filename = 'CustomerDetails_' . date('YmdHis') . '.pdf';
-
-//         // Output the PDF for download
-//         $pdf->Output($filename, 'D');
-//     } else {
-//         // Handle the case where the customer is not found
-//         echo 'Customer not found';
-//     }
-// }
-
-public function download_details()
-{
-    $selectedSchemes = $this->request->getPost('selected_schemes');
-    $action = $this->request->getPost('action');
-    // Initialize an empty PDF with custom paper size (4x6 inches)
-    $config = [
-        'mode' => 'utf-8',
-        'format' => [101.6, 152.4],
-        'default_font_size' => 12,
-        'default_font' => 'Arial',
-        'margin_left' => 0,
-        'margin_right' => 0,
-        'margin_top' => 0,
-        'margin_bottom' => 0,
-        'margin_header' => 0,
-        'margin_footer' => 0,
-        'orientation' => 'P', // Portrait
-    ];
-
-    $configA4 = [
-        'mode' => 'utf-8',
-        'format' => [101.6 * 2, 152.4 * 4], // 2x4 inches for each label
-        'default_font_size' => 12,
-        'default_font' => 'Arial',
-        'margin_left' => 0,
-        'margin_right' => 0,
-        'margin_top' => 0,
-        'margin_bottom' => 0,
-        'margin_header' => 0,
-        'margin_footer' => 0,
-        'orientation' => 'P', // Portrait
-    ];
-
-  
-    if($action == 1) $pdf = new Mpdf($config);
-    else $pdf = new Mpdf();
-    $customerDetails = [];
-    // Iterate through selected schemes
-    if (!empty($selectedSchemes)) {
-    foreach ($selectedSchemes as $selectedScheme) {
-        // Call the model method to get customer details for each selected scheme
-        $subscriptionModel = new SubscriptionModel();
-        $details = $subscriptionModel->getAllCustomerDetailsBySchemeName($selectedScheme);
-        $customerDetails = array_merge($customerDetails, $details);
-    }
-   
-        if (!empty($customerDetails)) {
-            $html = view('print_addresses_form', ['customerDetails' => $customerDetails , 'action' => $action , 'pdf' => $pdf]);
-            // Add the current scheme's details to the PDF
-            // echo $html;die;
-            // $pdf->AddPage();
-            $pdf->WriteHTML($html);
-            // Set the PDF filename
-            $filename = 'CustomerDetails_' . date('YmdHis') . '.pdf';
-
-            // Output the PDF for download
-            $pdf->Output($filename, 'D');
-            $this->logger->info("Print Addresses (Scheme) : Downloaded = ".$filename);
-        } else {
-            echo "";
-            $this->logger->info("Print Addresses (Scheme) : Details Not Available ");
-        }
-    } else {
-        echo "";
-        $this->logger->info("Print Addresses (Scheme) : Schemes Not Choosen ");
-    }
-    
-}
-
-
-
-
-}
-// public function generate_pdf()
-// {
-//     $schemeName = $this->request->getGet('scheme_name');
-
-//     // Call the model method to get the customer's name and address (billing or shipping)
-//     $subscriptionModel = new SubscriptionModel();
-
-//     // For billing address
-//     $billingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName, 1);
-
-//     // For shipping address
-//     $shippingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName, 2);
-//     print_r($billingInfo);
-//     print_r($shippingInfo);
-
-
-//     // Handle the PDF generation using $billingInfo['customer_name'], $billingInfo['address'] (for billing address)
-//     // and $shippingInfo['customer_name'], $shippingInfo['address'] (for shipping address)
-// }
-
-
diff --git a/app/Controllers/Users.php b/app/Controllers/Users.php
index 964488a..7c086b0 100644
--- a/app/Controllers/Users.php
+++ b/app/Controllers/Users.php
@@ -4,7 +4,6 @@ namespace App\Controllers;
 
 use App\Models\UsersModel;
 use App\Models\BusinessModel;
-use CodeIgniter\Files\File;
 
 class Users extends BaseController
 {
@@ -15,20 +14,23 @@ class Users extends BaseController
         
         $session_role = get_user_role();
         $session_bid = get_business_id();
-        $session_role = get_user_role();
-
-        if (!empty($session_role) && $session_role !== "sadmin") {
-            $this->logger->info("Users: Listing In admin role . BID = ".$session_bid);
-            $where = ['users.business_id' => (int)$session_bid, 'users.isactive' => 1];
-        } else {
+        
+        if (!empty($session_role) && $session_role === "sadmin") {
             $this->logger->info("Users: Listing In Super-admin role .");
             $where = ['users.isactive !=' => NULL];
+        }else if (!empty($session_role) && $session_role === "admin") {
+            $this->logger->info("Users: Listing In admin role . BID = ".$session_bid);
+            $where = ['users.business_id' => (int)$session_bid];
+        } else {
+            $this->logger->info("Users: Listing In ".$session_role." role . BID = ".$session_bid);
+            $where = ['users.business_id' => (int)$session_bid, 'users.isactive' => 1];
         }
         $model = new UsersModel();
         $model->setTable('users');
         // $user_details = $model->where($where)->orderBy('user_id', 'DESC')->findAll();
-        $user_details = $model->select('users.*, business.title as org_name')
+        $user_details = $model->select('users.*, business.title as org_name,business_branches.branch_name')
             ->join('business', 'business.business_id = users.business_id')
+            ->join('business_branches', 'business_branches.id = users.branch_id','left')
             ->where($where)->orderBy('user_id', 'DESC')->findAll();
 
         $this->logger->info("Users: Listing Count .".count($user_details));
@@ -36,8 +38,6 @@ class Users extends BaseController
         $data['loged_user']    =  $session_role;
         $data['details'] = $user_details;
 
-        // echo '
';
-        // print_r($data); die;
         $this->render_page('user_list', $data);
     }
 
@@ -49,7 +49,7 @@ class Users extends BaseController
         $session_role = get_user_role();
         $session_bid = get_business_id();
         $session_uid = get_logged_user_id();
-        $data['business_details'] = $this->business_details();
+        $data['organzation_details'] = $this->organzation_details();
         $data['dummy_flag'] = $flag; // for redirect purpose.
         if ($id === '0') {
             $this->logger->info("Users: In Add page");
@@ -57,7 +57,7 @@ class Users extends BaseController
             $render_page_name = 'user_form';
             $data['details'] = [];
             $data['branches'] = $this->getOrganizationBranches($session_bid);
-            // print_r($data);
+
         } else {
             $this->logger->info("Users: In Edit page");
             $model = new UsersModel();
@@ -72,7 +72,6 @@ class Users extends BaseController
                         $data['page_name'] = 'Edit User';
                         // Fetch organization branches for the selected organization
                         $data['branches'] = $this->getOrganizationBranches($edit_user_details['business_id']);
-                    //    print_r($data);die;
                         break;
     
                     case "admin":
@@ -81,7 +80,6 @@ class Users extends BaseController
                         $render_page_name = 'user_form';
                         $data['page_name'] = 'Edit User';
                         $data['branches'] = $this->getOrganizationBranches($edit_user_details['business_id']);
-                        // print_r($branches);die;
                          break;
     
                     case "volunteer":
@@ -90,9 +88,7 @@ class Users extends BaseController
                         if ($session_uid === $id && $session_role === "volunteer") {
                             $data['page_name'] = 'Edit User';
                             $data['branches'] = $this->getOrganizationBranches($edit_user_details['business_id']);
-                        
                             $render_page_name = 'user_form';
-
                         } else {
                             $data['page_name'] = 'Page Not Found';
                             $render_page_name = 'pages_404';
@@ -129,7 +125,7 @@ class Users extends BaseController
         $this->render_page($render_page_name, $data);
     }
     
-    // Add the getOrganizationBranches method
+    ## Add the getOrganizationBranches method
     public function getOrganizationBranches($businessId)
     {
         $db = db_connect();
@@ -140,13 +136,12 @@ class Users extends BaseController
         return $branches;
     }
     
-    
     ## For SuperAdmin Role business Dropdown displayed on Userpage.otherwise Hidden fields
-    public function business_details()
+    public function organzation_details()
     {
         $model = new BusinessModel();
         $model->setTable('business');
-        $business_details = $model->orderBy('business_id', 'DESC')->findAll();
+        $organzation_details = $model->orderBy('business_id', 'DESC')->findAll();
     
         // Fetch branches for all organizations
         $branchModel = new BusinessModel();
@@ -154,29 +149,21 @@ class Users extends BaseController
         $branches = $branchModel->findAll();
     
         // Add branches to each business
-        foreach ($business_details as &$business) {
+        foreach ($organzation_details as &$business) {
             $business['branches'] = array_filter($branches, function ($branch) use ($business) {
                 return $branch['business_id'] == $business['business_id'];
             });
         }
     
-        return $business_details;
+        return $organzation_details;
     }
     
-
     ## For inserting/updating details of user
     public function insert_users()
     {
      $this->logger->info("Users: Inserting/Updating Details");
       try {
-        ## CI validation rule for profile_picture 
-        $validationRule = [
-            'profile_picture' => [
-                'label' => 'Image File',
-                'rules' => 'uploaded[profile_picture]|is_image[profile_picture]|mime_in[profile_picture,image/jpg,image/jpeg,image/gif,image/png,image/webp]'
-            ]
-        ];
-
+        
         ## Declarions
         helper('session');
         $UsersModel = new UsersModel();
@@ -184,83 +171,20 @@ class Users extends BaseController
         $session_bid = get_business_id();
         $user_id = $this->request->getPost('user_id');
         $business_id = $this->request->getPost('business_id')?$this->request->getPost('business_id'):$session_bid;
-        $img_details = $this->request->getFile('profile_picture'); // Here I Have Image details ;
-        $final_img_name = NULL;//Just flag
-        $existing_img_name = $this->request->getPost('existing_profile_picture_name'); // HiddenField for if have any pic name means;
-        $img_path = 'public/uploads/';
         
-        ##Step 1 : image details available
-        if($img_details){
-            $this->logger->info("Users: image details avaiable");
-            ##Step 2 : i have image details .
- if ($img_details->isValid()) { - ##Step 3 : image Name.$new_img_name."
"; - $new_img_name = $img_details->getName(); // before movement name - $this->logger->info("Users: Image Name B4 Upload".$new_img_name); - ##Step 4 : Validation Rule Apply here.if not throw the error"
"; - if (!$this->validate($validationRule)) { - if($new_img_name !== ''){ - - $error = $this->validator->getErrors(); - // echo "Error : ".(string)$error."
"; - $this->logger->error("Users: Err on image upload".$error['profile_picture']); - throw new \Exception((string)$error['profile_picture']); - } - } - ##Step 5 : Check Existing and New Image Name Same Or not same no use to move on target folder - if($new_img_name !== $existing_img_name){ - $this->logger->info("Users: Image Name are Differ".$new_img_name." & ".$existing_img_name); - ## Step 6 : Different Image Name means removed on target folder using Unlink; - if ($existing_img_name && is_file($img_path.$existing_img_name)) { - $this->logger->info("Users: already Image Available on target Folder Path : ".$img_path.$existing_img_name." So, Deleted."); - // echo "Deleted_file : ".(string)$img_path.$existing_img_name."
"; - unlink($img_path.$existing_img_name); - } - ## Step 7 : Moved to target; - $img_details->move($img_path, $new_img_name); - $final_img_name = $img_details->getName(); // after movement name - $this->logger->info("Users: Image Name After Upload".$final_img_name); - }else{ - $final_img_name = $existing_img_name; - $this->logger->info("Users: Image Name are same".$new_img_name." & ".$existing_img_name." Can't Upload"); - } - } - else{ - ## Step 8 : Not a Vaild Image File so replace Existing file name; - $final_img_name = $existing_img_name; - $this->logger->info("Users: Not a Vaild Image File Nothing To Update/Upload"); - // throw new \Exception("Not a Vaild Image File"); - } - } - else{ - ## Step 9 : Testing Purpose File Details Not Available. so i can't move it.; - $this->logger->info("Users: Testing Purpose Image Details Not Available. so i can't move it."); - $final_img_name = $existing_img_name; - //throw new \Exception("Testing Purpose File Details Not Available so i can't move it if you have existing filee means save it or your choice"); - } - // $branch_id = $this->request->getPost('branch_id'); - // $business_id = $this->request->getPost('business_id'); $data = [ - - - 'profile_picture' => $final_img_name, 'city' => $this->request->getPost('city'), 'state' => $this->request->getPost('state'), 'email' => $this->request->getPost('email'), 'postal_code' => $this->request->getPost('postal_code'), - 'country' => $this->request->getPost('country'), 'role' => $this->request->getPost('role'), 'first_name' => $this->request->getPost('first_name'), - 'last_name' => $this->request->getPost('last_name'), 'mobile_no' => $this->request->getPost('mobile_no'), - 'date_of_birth' => NULL, 'address' => $this->request->getPost('address'), - 'gender' => $this->request->getPost('gender'), 'business_id' => $business_id, 'branch_id' => $this->request->getPost('branch_id') ?? $this->request->getPost('branch'), - ]; - // print_r($data);die; + if (empty($user_id)) { // It's an insert operation @@ -290,51 +214,44 @@ class Users extends BaseController if($session_uid == $user_id && $data['isactive'] == 0){ throw new \Exception("Cant able to Update Because logged-In persons can't remove. Please Contact your Admin!...."); } - if ($UsersModel->update($user_id, $data)) { - - session()->setFlashdata('success', 'User has been updated successfully.'); - } - } -}catch (\Exception $e) { + if ($UsersModel->update($user_id, $data)) { + session()->setFlashdata('success', 'User has been updated successfully.'); + } + } + }catch (\Exception $e) { $this->logger->error("Users: Err Occur =" . $e->getMessage()); session()->setFlashdata('error', 'Message: ' . $e->getMessage()); - } + } - // Redirect back to the user_page function or any other appropriate page - if($this->request->getPost('dummy_flag') == 1){ - return redirect()->to(base_url("user_page/{$user_id}/1")); - }else{ - return redirect()->route('user_list'); + // Redirect back to the user_page function or any other appropriate page + if($this->request->getPost('dummy_flag') == 1){ + return redirect()->to(base_url("user_page/{$user_id}/1")); + }else{ + return redirect()->route('user_list'); + } } -} - ## For delete the user details (Which means inactive the details) public function delete_user($id) { helper('session'); $session_uid = get_logged_user_id(); try { - if($id == $session_uid){ - throw new \Exception("Your Logged-In, Can't able delete"); - } + // if($id == $session_uid){ + // throw new \Exception("Your Not Logged-In, Can't able delete"); + // } $model = new UsersModel(); $where = ['users.user_id' => $id, 'users.isactive =' => 1]; $existingUser = $model->where($where)->find($id); $this->logger->Info("Users: Going to Inactive ID = ".$id); - // print_r($existingUser);die; + if ($existingUser) { $data['isactive'] = 0; $data['updated_by'] = $session_uid; - if(!empty($existingUser['profile_picture']) && file_exists(FCPATH."public/uploads/".$existingUser['profile_picture'])){ - unlink('public/uploads/'.$existingUser['profile_picture']); - $data['profile_picture'] = NULL; - } - - + if ($model->update($id, $data)) { - session()->setFlashdata('success', 'User Deactivated successfully.'); $this->logger->info("Users: has been Inactived successfully. Inactived ID = ".$id); + return $this->response->setJSON(['status' => true, 'message' => "User Deactivated successfully."]); } else { $this->logger->error("Users: Not able to Inactive ID =".$id); throw new \Exception("Data Not able to Deleted"); @@ -344,20 +261,20 @@ class Users extends BaseController $this->logger->error("Users: Does Not Exist To Inactive, ID = ".$id); throw new \Exception("User Already Deleted"); } - }catch(\Exception $e) { + } catch(\Exception $e) { $this->logger->error("Users: Err Occur = ".$e->getMessage()); - session()->setFlashdata('error', 'Message: ' .$e->getMessage()); + return $this->response->setJSON(['status' => false, 'message' => $e->getMessage()]); } - return redirect()->route('user_list'); } - public function activateUser($user_id){ + ## For delete user make as active user + public function activate_user($user_id){ helper('session'); $session_uid = get_logged_user_id(); try { - if($user_id == $session_uid){ - throw new \Exception("Your Logged-In, Can't able delete"); - } + // if($user_id == $session_uid){ + // throw new \Exception("Your Logged-In, Can't able delete"); + // } $model = new UsersModel(); $where = ['users.user_id' => $user_id, 'users.isactive =' => 0]; $existingUser = $model->where($where)->find($user_id); @@ -386,16 +303,16 @@ class Users extends BaseController return redirect()->route('user_list'); } - // Add a method to fetch organization branches based on the selected organization -public function get_branches($business_id) -{ - $model = new BusinessModel(); - $model->setTable('business_branches'); + + ## Add a method to fetch organization branches based on the selected organization + public function get_branches($business_id) + { + $model = new BusinessModel(); + $model->setTable('business_branches'); - $branches = $model->where('business_id', $business_id)->findAll(); + $branches = $model->where('business_id', $business_id)->findAll(); - return json_encode($branches); -} + return json_encode($branches); + } - -} +} \ No newline at end of file diff --git a/app/Helpers/apiIntegration_helper.php b/app/Helpers/apiIntegration_helper.php deleted file mode 100644 index d8196e1..0000000 --- a/app/Helpers/apiIntegration_helper.php +++ /dev/null @@ -1,68 +0,0 @@ - Curl Errno returned $curl_errno
"; - } - else{ $error = "Curl Errno returned $curl_errno
"; } - $error_msg = curl_error($curl); - }else{ - $error = ""; - $error_msg = ""; - } - curl_close($curl); - $response = (array) json_decode($result); - }catch (Exception $e) { - $error = "Exception Errno returned".$e->getCode()."
"; - $error_msg = $e->getMessage(); - $response = array(); - - } - $final = array( "response"=>$response,"error"=>$error,"error_msg"=>$error_msg); - return $final; -} -?> \ No newline at end of file diff --git a/app/Models/ApiIntegrationModel.php b/app/Models/ApiIntegrationModel.php deleted file mode 100644 index 1312a41..0000000 --- a/app/Models/ApiIntegrationModel.php +++ /dev/null @@ -1,113 +0,0 @@ -table = $tableName; - return $this; - } - - public function insertData($table, $data) - { - try { - $this->db->table($table)->insert($data); - $last_insert_id = $this->db->insertID(); - return ["info"=>$last_insert_id,"err"=>""]; - } catch (\CodeIgniter\Database\Exceptions\DatabaseException $e) { - return ["info"=>"","err"=>'Database operation failed: ' . $e->getMessage()]; - } catch (\Exception $e) { - return ["info"=>"","err"=>'An error occurred: ' . $e->getMessage()]; - } - } - - public function updateData($table, $data, $where) - { - try { - $this->db->table($table)->update($data, $where); - $affected_rows = $this->db->affectedRows(); - return ["info"=>$affected_rows." Affected","err"=>""]; - } catch (\CodeIgniter\Database\Exceptions\DatabaseException $e) { - return ["info"=>"","err"=>'Database operation failed: ' . $e->getMessage()]; - } catch (\Exception $e) { - return ["info"=>"","err"=>'Database operation failed: ' . $e->getMessage()]; - } - } - - public function countAll($table, $where = null) - { - $query = $this->db->table($table); - if ($where) { - $query->where($where); - } - return $query->countAllResults(); - } - - - public function getData($table, $where = null,$whereIn = null) - { - $query = $this->db->table($table); - if ($where) { - $query->where($where); - } - if($whereIn){ - // $query->whereIn($column_name,$missingValues) - $query->whereIn($whereIn[0],$whereIn[1]); - } - return $query->get()->getResult(); - } - - public function insertAndUpdateChildDetails($data,$table_name,$column_name){ - $i = 1; - $text = ' Child-table Name = '.str_replace("_", " ",ucwords($table_name)) .', Column = '.str_replace("_", " ",ucwords($column_name)) .'. '; - foreach ($data as $row) { - $id = isset($row[$column_name]) ? $row[$column_name] : ""; - if($id != ''){ - unset($row[$column_name]); // Remove the primary Id from the data to avoid updating it. - $where = [$column_name=>$id,'isactive'=>1]; - $child_affected_rows = $this->updateData($table_name, $row, $where); - $text .= $child_affected_rows["info"] ? $i.') Id = '.$id.', '.$child_affected_rows["info"].'. ' - : $i.') Id = '.$id.', Err = '.$child_affected_rows["err"].'. '; - }else{ - $child_insert_id = $this->insertData($table_name, $row); - $text .= $child_insert_id["info"] ? $i.') Inserted ID = '.$child_insert_id["info"].'. ' - : $i.') Err = '.$child_insert_id["err"].'. ' ; - } - $i++; - } - return $text; - } - - // public function inactiveMissingDetails($table_name,$where,$whereIn){ - // $dataToUpdate = ['isactive' => 0]; - // $this->db->table($table_name)->where($where)->whereIn($whereIn[0],$whereIn[1])->update($dataToUpdate); - // } - public function inactiveMissingDetails($table_name,$dataToUpdate,$where = null,$whereIn = null) - { - $this->db->table($table_name); - $query = $this->db->table($table_name); - if ($where) { - $query->where($where); - } - if ($whereIn) { - $query->whereIn($whereIn[0], $whereIn[1]); - } - $query->update($dataToUpdate); - } - - public function getBookCategories($product_id){ - return $this->db->table('book_categories as BC') - ->join('category as C', 'C.id = BC.category_id', 'left') - ->join('books as B', 'B.book_id = BC.book_id', 'left') - ->select('BC.id,BC.book_id,BC.category_id,C.wp_api_category_id,C.name as category_name,B.title as book_name,B.sku,B.duration') - ->where(['BC.isactive'=>1,'B.wp_api_product_id'=>$product_id]) - ->get() - ->getResultArray(); - } - -} diff --git a/app/Models/AppSettingModel.php b/app/Models/AppSettingModel.php deleted file mode 100644 index 16aaa62..0000000 --- a/app/Models/AppSettingModel.php +++ /dev/null @@ -1,22 +0,0 @@ -insert($data); - } else { - // Update existing record - return $this->update($id, $data); - } - } - -} - diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index 8f7976e..1bb51cf 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -125,7 +125,7 @@ public function updateData($table, $data, $where) ->join('donor as C','C.donor_id= receipt.donor_id','left') ->join('causes as D','D.causes_id= receipt.causes_id','left') ->join('business as B','B.business_id = receipt.business_id','left') - ->select('receipt.*,concat(C.first_name," ",C.last_name) as customer_name,C.address, C.postal_code,C.city, C.state,C.mobile_no as customer_mobile, C.pan_no as cust_pan_no, D.name as cause_name') + ->select('receipt.*,CONCAT(C.first_name, IFNULL(CONCAT(" ", C.last_name), "")) as customer_name,C.address, C.postal_code,C.city, C.state,C.mobile_no as customer_mobile, C.pan_no as cust_pan_no, D.name as cause_name,C.org_name as cust_org_name') ->select('B.title ,B.business_logo,B.terms,B.address as org_address ,B.city as org_city,B.state as org_state,B.postal_code as org_zip,B.email as org_email,B.mobile_no as org_mobile, B.pan_no as org_pan, B.org_reg_no, B.signature') ->get() ->getResult(); diff --git a/app/Models/SettingsModel.php b/app/Models/SettingsModel.php deleted file mode 100644 index e29bc6e..0000000 --- a/app/Models/SettingsModel.php +++ /dev/null @@ -1,22 +0,0 @@ -insert($data); - } else { - // Update existing record - return $this->update($id, $data); - } - } - -} - diff --git a/app/Views/address_list.php b/app/Views/address_list.php deleted file mode 100644 index 09e6087..0000000 --- a/app/Views/address_list.php +++ /dev/null @@ -1,66 +0,0 @@ - -" rel="stylesheet" type="text/css" /> - - - " rel="stylesheet" type="text/css" /> - " rel="stylesheet" type="text/css" /> - " rel="stylesheet" type="text/css" /> - " rel="stylesheet" type="text/css" /> - - - - " rel="stylesheet" type="text/css" id="bs-default-stylesheet" /> - " rel="stylesheet" type="text/css" id="app-default-stylesheet" /> - - " rel="stylesheet" type="text/css" id="bs-dark-stylesheet" /> - " rel="stylesheet" type="text/css" id="app-dark-stylesheet" /> - - - " rel="stylesheet" type="text/css" /> - - - - - - -
- - -
- - - - - -
-
-
-
-
- -
-
-

-
- - - - - - - - - - - - - - - -
NameAuthorCategoryLanguageYear Of ReleasePrice of the BookDescriptionStatusAction
-
-
-
-
-
- \ No newline at end of file diff --git a/app/Views/app_setting_form.php b/app/Views/app_setting_form.php deleted file mode 100644 index 6d7e4e3..0000000 --- a/app/Views/app_setting_form.php +++ /dev/null @@ -1,248 +0,0 @@ - - - - - - - - -
-
-
-
-

-

- - getFlashdata('success')): ?> -
getFlashdata('success') ?>
- -
"> -
- -
-
- - -
-
- -
-
- - -
-
- - -
-
- - - -
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
- -
- - Logo -
- -
- - -
- -
- - Icon -
- -
-
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
- - -
-
-
-
- - -
- -
- - -
-
- - -
-
- - - -
- > - -
-
- -
- - - -
-
-
-
-
-
-
- - \ No newline at end of file diff --git a/app/Views/book_form.php b/app/Views/book_form.php index 5ad1a62..4f474a0 100644 --- a/app/Views/book_form.php +++ b/app/Views/book_form.php @@ -30,7 +30,7 @@
getFlashdata('success') ?>
"> + action="">
diff --git a/app/Views/book_list.php b/app/Views/book_list.php index 408de53..c21ea92 100644 --- a/app/Views/book_list.php +++ b/app/Views/book_list.php @@ -69,7 +69,7 @@ - " class="delete-button"> + " class="delete-button"> diff --git a/app/Views/business_form.php b/app/Views/business_form.php index 0557984..3c9db79 100644 --- a/app/Views/business_form.php +++ b/app/Views/business_form.php @@ -56,60 +56,60 @@
- +
Please provide.
- +
Please provide.
- +
Please provide.
- +
Please provide.
- +
Please provide.
- +
Please provide.
- +
- +
- +
Please provide.
- +
Please provide.
- +
Please provide.
@@ -130,7 +130,7 @@ - + @@ -141,32 +141,32 @@
- + Auto-Text Copied from Buiness title field (First time only)
- +
- +
- +
- +
- +
@@ -174,7 +174,7 @@
- +
@@ -270,26 +270,26 @@
- +

- +
- - Logo + + Logo
- +

- +
- - Icon + + Icon
@@ -299,19 +299,19 @@
- +

- +
- - Signature + + Signature
- +

@@ -325,20 +325,20 @@
- +
- +
- +
- +
@@ -353,9 +353,9 @@ - +
@@ -363,8 +363,8 @@
- + diff --git a/app/Views/customer_form.php b/app/Views/customer_form.php index 0dfb4e9..a0a6096 100644 --- a/app/Views/customer_form.php +++ b/app/Views/customer_form.php @@ -35,8 +35,8 @@
Please provide.
@@ -250,7 +250,7 @@ let DonorType = $('#DonorType').val(); // Organization type selected - if (DonorType === 'option2') { + if (DonorType === 'organization') { $('#org_name').show(); $('#org_reg').show(); $('.contactPerson').show(); diff --git a/app/Views/customer_list.php b/app/Views/customer_list.php index 946b1c5..55402c8 100644 --- a/app/Views/customer_list.php +++ b/app/Views/customer_list.php @@ -39,16 +39,16 @@ - + - + - + diff --git a/app/Views/dashboard.php b/app/Views/dashboard.php index 6b49d94..8359d10 100644 --- a/app/Views/dashboard.php +++ b/app/Views/dashboard.php @@ -1,4 +1,5 @@ -
+ +
@@ -9,19 +10,16 @@

+
+

+

+
+

+

- -
-

-

-
-
-

-

-
- + \ No newline at end of file diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index 4884238..11dea00 100644 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -19,25 +19,17 @@

- " class="main-form" id="myForm"> + " class="main-form" id="recepitForm">
     - onchange="get_donor_details(this.value);"> + onchange="get_donor_details(this.value);"> Individual   - onchange="get_donor_details(this.value);"> + onchange="get_donor_details(this.value);"> Organization -
@@ -58,13 +50,16 @@
- +
@@ -104,7 +99,7 @@
- +
@@ -152,8 +147,8 @@
- - + +
@@ -200,7 +195,7 @@ © ".$company_name.""; ?> + var appStartedYear = "2024"; + var currentYear = new Date().getFullYear(); + if (appStartedYear == currentYear) { + document.write(appStartedYear); + } else { + document.write(appStartedYear + " - " + currentYear); + } + + © @@ -359,363 +66,6 @@ - -
- - - -
-
- Theme Settings -
- -
- - -
Color Scheme
-
- - -
- -
- - -
- - -
Width
-
- - -
-
- - -
- - -
Topbar
- -
- - -
- -
- - -
- - -
Menus Positon (Leftsidebar and Topbar)
- -
- - -
- -
- - -
- - -
Left Sidebar Color
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- - -
Left Sidebar Size
- -
- - -
- -
- - -
- -
- - -
- - -
Sidebar User Info
- -
- - -
- - - - -
- -
-
- @@ -786,6 +136,10 @@ + + + + diff --git a/app/Views/template/header.php b/app/Views/template/header.php index 20e9a0f..108cf8c 100644 --- a/app/Views/template/header.php +++ b/app/Views/template/header.php @@ -13,7 +13,7 @@ " rel="stylesheet" type="text/css" /> " rel="stylesheet" type="text/css" /> - + " rel="stylesheet" type="text/css" /> " rel="stylesheet" type="text/css" /> diff --git a/app/Views/template/topbar.php b/app/Views/template/topbar.php index 3f9c307..8cbcdd1 100644 --- a/app/Views/template/topbar.php +++ b/app/Views/template/topbar.php @@ -81,13 +81,11 @@ - - + " class="dropdown-item notify-item"> Lock Screen @@ -161,7 +159,114 @@ + + @@ -189,48 +164,7 @@ } }); - + function checkExisting(inputvalue,fieldname,elementid){ + spanid = elementid == 'email' ? "emailValidationMessage" : "mobileValidationMessage"; + var validationMessage = document.getElementById(spanid); + $.ajax({ + type: "POST", + url: "", + data: { + value: inputvalue, + module: 'users', + field: fieldname + }, + success: function(response) { + if (response['data']['status']) { + validationMessage.textContent = response['data']['message']; + validationMessage.style.color = "red"; + document.getElementById(elementid).value = ""; + } else { + validationMessage.textContent = ""; + } + }, + error: function() { + alert("Error occur."); + } + }); + } -