diff --git a/.gitignore b/.gitignore
index 20d1c153..bdae25d5 100755
--- a/.gitignore
+++ b/.gitignore
@@ -87,7 +87,7 @@ writable/**/*.sqlite
php_errors.log
public/uploads/*
-# !public/uploads/index.html
+!public/uploads/index.html
#-------------------------
# Composer
diff --git a/Untitled-1.json b/Untitled-1.json
deleted file mode 100644
index 65229e19..00000000
--- a/Untitled-1.json
+++ /dev/null
@@ -1 +0,0 @@
- "friendsofphp/php-cs-fixer": "3.13.0",
\ No newline at end of file
diff --git a/app/Config/Constants.php b/app/Config/Constants.php
index d3df0db2..c95970b7 100644
--- a/app/Config/Constants.php
+++ b/app/Config/Constants.php
@@ -97,7 +97,26 @@ define('EVENT_PRIORITY_HIGH', 10);
* Constants For Api Integration.
*/
// define('VB_APIURL', 'https://vbp.venbait.in/wp-json/wc/v3/');
-// define('VB_BOOKS', VB_APIURL.'products');
-// define('VB_CUSTOMERS', VB_APIURL.'customers');
+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', '650be030cedb3');
+define('WAAI_INSTANCE', '650C383B67BC7');
+define('SEND_WAAI_URL', 'https://waai.in/api/send');
diff --git a/app/Config/Email.php b/app/Config/Email.php
index 3875d5f1..5cb4e15a 100644
--- a/app/Config/Email.php
+++ b/app/Config/Email.php
@@ -28,24 +28,22 @@ class Email extends BaseConfig
/**
* SMTP Server Address
*/
- public string $SMTPHost = 'bh-in-11.webhostbox.net';
+ public string $SMTPHost = 'smtp.sendgrid.net';
/**
* SMTP Username
*/
- public string $SMTPUser = 'devbook@mprkv.co.in';
- //public string $SMTPUser = 'venbalap08@gmail.com';
+ public string $SMTPUser = 'apikey';
/**
* SMTP Password
*/
- public string $SMTPPass = 'DevBook@2023';
- //public string $SMTPPass = 'sganobynfyouaxgs';
+ public string $SMTPPass = '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';
/**
* SMTP Port
*/
- public int $SMTPPort = 465;
+ public int $SMTPPort = 587;
/**
* SMTP Timeout (in seconds)
@@ -60,7 +58,7 @@ class Email extends BaseConfig
/**
* SMTP Encryption. Either tls or ssl
*/
- public string $SMTPCrypto = 'ssl';
+ public string $SMTPCrypto = 'tls';
/**
* Enable word-wrap
diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 9266f649..e59b1127 100644
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -109,17 +109,20 @@ $routes->get('print_address/(:num)', 'Invoice::print_address/$1');
-
-
-
+# Notifications Routes
+$routes->get('send_whatsapp_message/', 'Notifications::send_whatsapp_message');
+$routes->post('whatsapp_custom_notifications/', 'Notifications::whatsapp_custom_notifications');
+$routes->match(['post', 'get'], 'mail_custom_notifications', 'Notifications::mail_custom_notifications');
# Api integration Routes
-$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');
-});
+$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');
+// });
/*
* --------------------------------------------------------------------
diff --git a/app/Controllers/ApiIntegration.php b/app/Controllers/ApiIntegration.php
index 15df8767..36d6e33a 100644
--- a/app/Controllers/ApiIntegration.php
+++ b/app/Controllers/ApiIntegration.php
@@ -11,94 +11,179 @@ class ApiIntegration extends ResourceController
{
use ResponseTrait;
- public function book_api_integration()
- {
- $request = \Config\Services::request();
- $message = "";
+ public function api_integration($api_request_text) {
+ $this->logger->info("Api Integration : Request Text = ".$api_request_text);
try {
- switch ($this->request) {
- case $this->request->is('put'):
+ $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 {
- // $url = http://localhost/vb_book/api/products?id=795;
- $records = (array)$this->request->getVar();
- $id = $this->request->getVar('id');
- if ($records['id'] == $id) {
- $response = $this->save_book_details($records, $id);
- } else {
- $response = ['status' => 404, 'message' => "ID Mismatched"];
+ 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) {
- return $this->fail('PUT request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
+ $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 $this->request->is('post'):
+ case 'delete':
try {
- // $url = http://localhost/vb_book/api/products;
- $records = (array)$this->request->getVar();
- $wordpress_book_id = $records['id'];
- $response = $this->save_book_details($records, $wordpress_book_id);
- } catch (\Exception $e) {
- return $this->fail('POST request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
- }
- break;
- case $request->is('get'):
- try {
- // $url = http://localhost/vb_book/api/products?id=795;
- // $url = http://localhost/vb_book/api/products;
- $id = $this->request->getVar('id');
- if ($id) {
- $where = ['wp_api_product_id' => (int)$id, 'isactive' => 1];
- } else {
- $where = ['isactive' => 1];
- }
+ $basic_message = "";
+ $records = (array)$row_data;
+ $wordpress_refer_id = $records['id'];
$api_model = new ApiIntegrationModel();
- $book_details = $api_model->setTable('books')->where($where);
- $response = ['status' => 200, 'message' => "Book Details", "data" => $book_details];
- } catch (\Exception $e) {
- return $this->fail('GET request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
- }
- break;
- case $request->is('delete'):
- try {
- // $url = http://localhost/vb_book/api/products?id=795;
- $id = $this->request->getVar('id');
- $api_model = new ApiIntegrationModel();
- $where = ['isactive' => 1, 'wp_api_product_id' => (int)$id];
- $existing_book_data = $api_model->getData('books', $where);
- if ((int)count($existing_book_data) > 0) {
- $book_id = (int)$existing_book_data[0]->book_id;
+ $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;
- $update_where = ['isactive' => 1, 'book_id' => $book_id];
- $api_model->updateData('books', $inactive_data, $update_where);
- $getExistingBookImageDetails = $api_model->getData('book_images', $update_where);
- if ($getExistingBookImageDetails) {
- // $update_where = ['book_id' => $book_id];
- $api_model->updateData('book_images', $inactive_data, $update_where);
+ $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";
}
- $response = ['status' => 200, 'message' => "Book Details and Book Images Details Are Inactived"];
+ $this->logger->info("Api CallMethods : ".$basic_message);
+ $response = ['status' => 200, 'message' => $basic_message];
} catch (\Exception $e) {
- // Handle DELETE-specific exception
- return $this->fail('DELETE request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
+ $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 $this->respond($response);
+ return $response;
} catch (\Exception $e) {
// Handle the exception, you can log it or return an error response
- return $this->fail('An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
- // return $this->fail($e->getMessage());
+ $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();
- $message = "";
+ $extensive_correspondence = "";
+ $basic_message = "";
$book_id = "";
if (count($records) > 0 && !empty($wordpress_book_id)) {
$where = ['wp_api_product_id' => $wordpress_book_id, 'isactive' => 1];
@@ -108,11 +193,12 @@ class ApiIntegration extends ResourceController
$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 = '';
$language = '';
$attributes = $records['attributes'];
+
if (count($attributes) > 0) {
foreach ($attributes as $att) {
if (isset($att->name) && $att->name == "Publisher") {
@@ -139,24 +225,31 @@ class ApiIntegration extends ResourceController
$book_data['business_id'] = 1;
$images = $records['images'];
- $i = 0;
+
if ((int)$countAll == 0) {
$insert_result = $api_model->insertData('books', $book_data);
$last_insert_book_id = $insert_result['info'];
- $message .= $insert_result['info'] ? "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_where = ['book_id' => $book_id, 'isactive' => 1, 'wp_api_product_id' => $wordpress_book_id];
$update_result = $api_model->updateData('books', $book_data, $book_where);
- $message .= $update_result['info'] ? "Book id : " . $last_insert_book_id . " ( " . $update_result['info'] . ")"
+ $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']):"";
}
- $book_image_data = [];
-
+ $this->logger->info("Api SaveBookDetails : Book images count : " .count($images));
if (count($images) > 0 && $last_insert_book_id != "") {
- $message .= " Its have " . count($images) . " Images ,";
+ $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;
@@ -174,11 +267,14 @@ class ApiIntegration extends ResourceController
}
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;
@@ -195,7 +291,9 @@ class ApiIntegration extends ResourceController
$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'
@@ -214,106 +312,30 @@ class ApiIntegration extends ResourceController
$book_image_data[$i]['isactive'] = 1;
$book_image_data[$i]['wp_api_img_id'] = $img->id;
$book_image_data[$i]['book_img_id'] = $bookImgId;
+ $this->logger->info("Api SaveBookDetails : Image Data = $i ");
$i++;
} // image loop closed
- $message .= (!empty($book_image_data) ? $api_model->insertAndUpdateChildDetails($book_image_data, 'book_images', 'book_img_id') : []);
+ $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
- $response = ['status' => 200, 'message' => $message];
+ else{
+ $this->logger->error("Api SaveBookDetails : Err = Image Data Not Found");
+ }
+ $response = ['status' => 200, 'message' => $basic_message ,'indetails' => $extensive_correspondence];
} //if cond. closed
else {
- $response = ['status' => 204, 'message' => 'Data No Found'];
+ $this->logger->error("Api SaveBookDetails : Err = Data Not Found");
+ $response = ['status' => 204, 'message' => 'Data Not Found'];
}
return $response;
}
- public function customer_api_integration()
- {
- $request = \Config\Services::request();
- $message = "";
- try {
- switch ($this->request) {
- case $this->request->is('put'):
- try {
- // $url = http://localhost/vb_book/api/customers?id=795;
- $records = (array)$this->request->getVar();
- $id = $this->request->getVar('id');
- if ($records['id'] == $id) {
- $response = $this->save_customer_details($records, $id);
- } else {
- $response = ['status' => 404, 'message' => "ID Mismatched"];
- }
- } catch (\Exception $e) {
- return $this->fail('PUT request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
- }
- break;
- case $this->request->is('post'):
- try {
- // $url = http://localhost/vb_book/api/customers;
- $records = (array)$this->request->getVar();
- $wordpress_customer_id = $records['id'];
- $response = $this->save_customer_details($records, $wordpress_customer_id);
- } catch (\Exception $e) {
- return $this->fail('POST request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
- }
- break;
- case $request->is('get'):
- try {
- // $url = http://localhost/vb_book/api/customers?id=795;
- // $url = http://localhost/vb_book/api/customers;
- $id = $this->request->getVar('id');
- if ($id) {
- $where = ['wp_api_customer_id' => (int)$id, 'isactive' => 1];
- } else {
- $where = ['isactive' => 1];
- }
- $api_model = new ApiIntegrationModel();
- $customer_details = $api_model->setTable('customers')->where($where);
- $response = ['status' => 200, 'message' => "Customer Details", "data" => $customer_details];
- } catch (\Exception $e) {
- return $this->fail('GET request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
- }
- break;
- case $request->is('delete'):
- try {
- // $url = http://localhost/vb_book/api/customers?id=795;
- $id = $this->request->getVar('id');
- $api_model = new ApiIntegrationModel();
- $where = ['isactive' => 1, 'wp_api_customer_id' => (int)$id];
- $existing_customer_data = $api_model->getData('customers', $where);
- if ((int)count($existing_customer_data) > 0) {
- $customer_id = (int)$existing_customer_data[0]->customer_id;
- $inactive_data['isactive'] = 0;
- $update_where = ['isactive' => 1, 'customer_id' => $customer_id];
- $api_model->updateData('customers', $inactive_data, $update_where);
- $getExistingCustomerImageDetails = $api_model->getData('customer_addresses', $update_where);
- if ($getExistingCustomerImageDetails) {
-
- $api_model->updateData('customer_addresses', $inactive_data, $update_where);
- }
- }
- $response = ['status' => 200, 'message' => "customer Details and Customer Addresses Details Are Inactived"];
- } catch (\Exception $e) {
- // Handle DELETE-specific exception
- return $this->fail('DELETE request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
- }
- break;
- default:
- throw new \Exception('Unsupported HTTP method');
- // return $this->fail('Unsupported HTTP method');
- }
- return $this->respond($response);
- } catch (\Exception $e) {
- // Handle the exception, you can log it or return an error response
- return $this->fail('An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
- // return $this->fail($e->getMessage());
- }
- }
-
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();
- $message = "";
+ $extensive_correspondence = "";
+ $basic_message = "";
$customer_id = "";
if (count($records) > 0 && !empty($wordpress_customer_id)) {
$where = ['wp_api_customer_id' => $wordpress_customer_id, 'isactive' => 1];
@@ -322,7 +344,9 @@ class ApiIntegration extends ResourceController
$customer_id = $customer_details['customer_id'];
$where['customer_id'] = $customer_details['customer_id'];
}
+
$countAll = $api_model->countAll('customers', $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'];
@@ -339,27 +363,36 @@ class ApiIntegration extends ResourceController
if ((int)$countAll == 0) {
$insert_result = $api_model->insertData('customers', $customer_data);
$last_insert_customer_id = $insert_result['info'];
- $message .= $insert_result['info'] ? "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 {
$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('customers', $customer_data, $customer_where);
- $message .= $update_result['info'] ? "Customer id : " . $last_insert_customer_id . " ( " . $update_result['info'] . ")"
+ $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 != "") {
- $message .= " Its have " . count($billing) . " Billing address ,";
-
+ $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;
@@ -377,11 +410,14 @@ class ApiIntegration extends ResourceController
}
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;
@@ -398,7 +434,7 @@ class ApiIntegration extends ResourceController
$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 != '') {
@@ -424,17 +460,21 @@ class ApiIntegration extends ResourceController
$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;
";
}
}
- $message .= (!empty($customer_billing_address_data) ? $api_model->insertAndUpdateChildDetails($customer_billing_address_data, 'customer_addresses', 'customer_address_id') : []);
+ $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 != "") {
- $message .= " Its have " . count($shipping) . " Shipping address ,";
+ $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;
@@ -452,6 +492,8 @@ class ApiIntegration extends ResourceController
}
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
@@ -461,6 +503,7 @@ class ApiIntegration extends ResourceController
$inactive_whereIn[0] = 'address_1';
$inactive_whereIn[1] = $missingShippingValues;
$api_model->inactiveMissingDetails('customer_addresses', $inactive_where, $inactive_whereIn);
+ $this->logger->info("Api SaveCustomerDetails : Missing Shipping " .implode(",",$missingShippingValues)." Are inactived");
}
}
}
@@ -473,6 +516,7 @@ class ApiIntegration extends ResourceController
$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;
@@ -499,108 +543,34 @@ class ApiIntegration extends ResourceController
$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
";
}
}
- $message .= (!empty($customer_shipping_address_data) ? $api_model->insertAndUpdateChildDetails($customer_shipping_address_data, 'customer_addresses', 'customer_address_id') : []);
+ $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' => $message];
+ $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 sales_api_integration()
- {
- $request = \Config\Services::request();
- $message = "";
- try {
- switch ($this->request) {
- case $this->request->is('put'):
- try {
- // $url = http://localhost/vb_book/api/orders?id=795;
- $records = (array)$this->request->getVar();
- $id = $this->request->getVar('id');
- if ($records['id'] == $id) {
- $response = $this->save_sales_details($records, $id);
- } else {
- $response = ['status' => 404, 'message' => "ID Mismatched"];
- }
- } catch (\Exception $e) {
- return $this->fail('PUT request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
- }
- break;
- case $this->request->is('post'):
- try {
- // $url = http://localhost/vb_book/api/orders;
- $records = (array)$this->request->getVar();
- $wordpress_order_id = $records['id'];
- $response = $this->save_sales_details($records, $wordpress_order_id);
- } catch (\Exception $e) {
- return $this->fail('POST request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
- }
- break;
- case $request->is('get'):
- try {
- // $url = http://localhost/vb_book/api/orders?id=795;
- // $url = http://localhost/vb_book/api/orders;
- $id = $this->request->getVar('id');
- if ($id) {
- $where = ['wp_api_order_id' => (int)$id, 'isactive' => 1];
- } else {
- $where = ['isactive' => 1];
- }
- $api_model = new ApiIntegrationModel();
- $invoice_details = $api_model->setTable('invoice')->where($where);
- $response = ['status' => 200, 'message' => "Invoice Details", "data" => $invoice_details];
- } catch (\Exception $e) {
- return $this->fail('GET request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
- }
- break;
- case $request->is('delete'):
- try {
- // $url = http://localhost/vb_book/api/orders?id=795;
- $id = $this->request->getVar('id');
- $api_model = new ApiIntegrationModel();
- $where = ['isactive' => 1, 'wp_api_order_id' => (int)$id];
- $existing_invoice_data = $api_model->getData('invoice', $where);
- if ((int)count($existing_invoice_data) > 0) {
- $invoice_id = (int)$existing_invoice_data[0]->invoice_id;
- $inactive_data['isactive'] = 0;
- $update_where = ['isactive' => 1, 'invoice_id' => $invoice_id];
- $api_model->updateData('invoice', $inactive_data, $update_where);
- $getExistingInvoiceItemsDetails = $api_model->getData('invoiceitems', $update_where);
- if ($getExistingInvoiceItemsDetails) {
- $api_model->updateData('invoiceitems', $inactive_data, $update_where);
- }
- }
- $response = ['status' => 200, 'message' => "Invoice Details and Invoice Items Details Are Inactived"];
- } catch (\Exception $e) {
- // Handle DELETE-specific exception
- return $this->fail('DELETE request failed, An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
- }
- break;
- default:
- throw new \Exception('Unsupported HTTP method');
- // return $this->fail('Unsupported HTTP method');
- }
- return $this->respond($response);
- } catch (\Exception $e) {
- // Handle the exception, you can log it or return an error response
- return $this->fail('An error occurred on line ' . $e->getline() . ': ' . $e->getMessage());
- // return $this->fail($e->getMessage());
- }
- }
-
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();
- $message = "";
+ $extensive_correspondence = "";
$invoice_id = "";
if (count($records) > 0 && !empty($wordpress_order_id)) {
$where = ['wp_api_order_id' => $wordpress_order_id, 'isactive' => 1];
@@ -610,6 +580,7 @@ class ApiIntegration extends ResourceController
$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 = "";$shipping_addr = "";
$lineitems_array = [];
$billing_array = []; $shipping_array = [];
@@ -669,22 +640,31 @@ class ApiIntegration extends ResourceController
if ((int)$countAll == 0) {
$insert_result = $api_model->insertData('invoice', $invoice_data);
$last_insert_invoice_id = $insert_result['info'];
- $message .= $insert_result['info'] ? "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];
$update_result = $api_model->updateData('invoice', $invoice_data, $customer_where);
- $message .= $update_result['info'] ? "Invoice id : " . $last_insert_invoice_id . " ( " . $update_result['info'] . ")"
+ $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 = [];
$shipping_line_item_data = [];
$i = 0;$j=0;
+ $this->logger->info("Api SaveSalesDetails : Invoice items count : " .count($lineitems_array));
if (count($lineitems_array) > 0 && $last_insert_invoice_id != "") {
- $message .= " Its have " . count($lineitems_array) . " LineItems ,";
- $where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1];
+ $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;
@@ -701,11 +681,14 @@ class ApiIntegration extends ResourceController
}
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;
@@ -714,7 +697,7 @@ class ApiIntegration extends ResourceController
}
}
- $where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1];
+ $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;
@@ -722,6 +705,7 @@ class ApiIntegration extends ResourceController
$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;
@@ -747,17 +731,24 @@ class ApiIntegration extends ResourceController
$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;
+ $this->logger->info("Api SaveSalesDetails : Invoiceitem Data inx = $i ");
$i++;
} // line item loop closed
- $message .= (!empty($line_item_data) ? $api_model->insertAndUpdateChildDetails($line_item_data, 'invoiceitems', 'invoice_child_id') : []);
-
+ $extensive_correspondence .= (!empty($line_item_data) ? $api_model->insertAndUpdateChildDetails($line_item_data, 'invoiceitems', 'invoice_child_id') : "");
+ $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 != "") {
- $message .= " Its have " . count($shipping_lineitems_array) . " shipping details ,";
- $where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1];
- $existing_shipping_invoiceitem = $api_model->getData('invoiceitems', $where);
+ $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 = [];
@@ -773,11 +764,15 @@ class ApiIntegration extends ResourceController
}
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;
@@ -786,7 +781,7 @@ class ApiIntegration extends ResourceController
}
}
- $where = ['invoice_id' => (int)$last_insert_invoice_id, 'isactive' => 1];
+ $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;
@@ -794,6 +789,7 @@ class ApiIntegration extends ResourceController
$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;
@@ -819,17 +815,23 @@ class ApiIntegration extends ResourceController
$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
- $message .= (!empty($shipping_line_item_data) ? $api_model->insertAndUpdateChildDetails($shipping_line_item_data, 'invoiceitems', 'invoice_child_id') : []);
+ $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);
}
- $response = ['status' => 200, 'message' => $message];
+ 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;
}
-
-}
+
+}
\ No newline at end of file
diff --git a/app/Controllers/Authentication.php b/app/Controllers/Authentication.php
index 8085d39a..d67b1165 100755
--- a/app/Controllers/Authentication.php
+++ b/app/Controllers/Authentication.php
@@ -36,7 +36,7 @@ class Authentication extends BaseController
$username = $this->request->getPost('username');
$password = $this->request->getPost('password');
- $user = $auth_model->where('email', $username)->first();
+ $user = $auth_model->where(['email'=>$username,'isactive'=>1])->first();
// $this->logger->info("Authenticate: Function Called.");
if (is_null($user)) {
@@ -84,7 +84,7 @@ class Authentication extends BaseController
public function auth_confirm_mail()
{
// Get the email address from the request
- $email = $this->request->getGet('email');
+ $mail_id = $this->request->getGet('email');
$url_domain = base_url();
// Validate the email address
@@ -99,43 +99,32 @@ class Authentication extends BaseController
// Check if the email exists in the database
$auth_model = new AuthenticationModel();
- // $user = $auth_model->where('email', $email)->first();
- $where = ['email' => $email, 'isactive' => 1];
+ // $user = $auth_model->where('email', $mail_id)->first();
+ $where = ['email' => $mail_id, 'isactive' => 1];
$user = $auth_model->where($where)->first();
if (!$user) {
$this->logger->error('There is no user enteries against given mail');
return redirect()->back()->withInput()->with('error', 'There is no user enteries against given mail');
} else {
- $data['email'] = $email;
+ $data['mail_id'] = $mail_id;
// Generate a unique token for password reset
$token = bin2hex(random_bytes(32));
- $content = "Click the link below to reset your password : " . $url_domain . "reset_password?email=" . $email . "&token=" . $token;
- // $email = \Config\Services::email();
- // $email->setTo('sanjeev.p@venbainfotech.com');
- // $email->setFrom('venbalap08@gmail.com', 'BB-VBP');
- // $email->setSubject('BB-VBP Password Reset');
- // $email->setMessage($content);
+ $content = "Click the link below to reset your password : " . $url_domain . "auth_reset_password?email=" . $mail_id . "&token=" . $token;
+ $email = \Config\Services::email();
+ // $recipient = 'venbalap08@gmail.com';
+ $recipient = $mail_id;
-
-
- // $email->setTo('venbalap08@gmail.com');
- // $email->setFrom('venbalap08@gmail.com');
- // $email->setSubject('Password Reset Testing');
- // $email->setMessage('ZXER');
-
-
- // if ($email->send()) {
- // // Email sent successfully
- // return view('auth_confirm_mail', $data);
- // } else {
- // $this->logger->error('Email Not Sended,Try Again');
- // return redirect()->back()->withInput()->with('error', 'Email Not Sended,Try Again');
- // }
+ // Compose the email
+ $email->setTo($recipient);
+ $email->setFrom('no-reply@tripapprovaltool.com', 'BB-VBP');
+ $email->setSubject('Email Notification');
+ // $email->setMessage('This is a notification email from CodeIgniter.');
+ $email->setMessage($content);
$update_token['reset_link'] = $token;
$auth_model->update($user['user_id'], $update_token);
- $data['link'] = $url_domain . "auth_reset_password?email=" . $email . "&token=" . $token;
+ $data['link'] = $url_domain . "auth_reset_password?email=" . $mail_id . "&token=" . $token;
// Retrieve flashed session data
$successMessage = session()->getFlashdata('success');
$validationErrors = session()->getFlashdata('error');
@@ -144,7 +133,14 @@ class Authentication extends BaseController
// Here, we'll use the default View class for demonstration purposes
$data['successMessage'] = $successMessage;
$data['validationErrors'] = $validationErrors;
- return view('auth_confirm_mail', $data);
+ // return view('auth_confirm_mail', $data);
+ if ($email->send()) {
+ // Email sent successfully
+ return view('auth_confirm_mail', $data);
+ } else {
+ $this->logger->error('Email Not Sended,Try Again');
+ return redirect()->back()->withInput()->with('error', 'Email Not Sended,Try Again');
+ }
}
}
@@ -264,12 +260,15 @@ class Authentication extends BaseController
$session_uid = get_logged_user_id();
$session_uname = get_logged_name();
$auth_model = new AuthenticationModel();
-
+
+
$details = $auth_model->getheringDetailsForHeader($session_uid);
$data['loggedin_person'] = $session_uname;
$data['loggedin_person_role'] = $details[0]['role'];
- $data['favicon'] = $details[0]['favicon'];
- $data['profile_picture'] = $details[0]['profile_picture'];
+ $data['favicon'] = !empty($details[0]['favicon']) && file_exists(FCPATH."public/uploads/".$details[0]['favicon']) ? base_url("public/uploads/".$details[0]['favicon']) : base_url("public/uploads/default.ico");
+ $data['profile_picture'] = !empty($details[0]['profile_picture']) && file_exists(FCPATH."public/uploads/".$details[0]['profile_picture']) ? base_url("public/uploads/" . $details[0]['profile_picture']) : base_url("public/assets/images/users/avatar-9.jpg");
+ $data['company_logo_small'] = !empty($details[0]['company_logo_small']) && file_exists(FCPATH."public/uploads/".$details[0]['company_logo_small']) ? base_url("public/uploads/" . $details[0]['company_logo_small']) : base_url("public/uploads/default_logo.png");
+ $data['company_logo_large'] = !empty($details[0]['company_logo_large']) && file_exists(FCPATH."public/uploads/".$details[0]['company_logo_large']) ? base_url("public/uploads/" . $details[0]['company_logo_large']) : base_url("public/uploads/default.png");
$successMessage = session()->getFlashdata('success');
$validationErrors = session()->getFlashdata('error');
// Load and display the form view with the above data
diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php
index 812be8b8..b3960e33 100644
--- a/app/Controllers/BaseController.php
+++ b/app/Controllers/BaseController.php
@@ -74,8 +74,10 @@ abstract class BaseController extends Controller
$data['loggedin_person'] = $session_uname;
$data['loggedin_person_id'] = $session_uid;
$data['loggedin_person_role'] = $details[0]['role'];
- $data['favicon'] = $details[0]['favicon'];
- $data['profile_picture'] = $details[0]['profile_picture'];
+ $data['favicon'] = !empty($details[0]['favicon']) && file_exists(FCPATH."public/uploads/".$details[0]['favicon']) ? base_url("public/uploads/".$details[0]['favicon']) : base_url("public/uploads/default.ico");
+ $data['profile_picture'] = !empty($details[0]['profile_picture']) && file_exists(FCPATH."public/uploads/".$details[0]['profile_picture']) ? base_url("public/uploads/" . $details[0]['profile_picture']) : base_url("public/assets/images/users/avatar-9.jpg");
+ $data['company_logo_small'] = !empty($details[0]['company_logo_small']) && file_exists(FCPATH."public/uploads/".$details[0]['company_logo_small']) ? base_url("public/uploads/" . $details[0]['company_logo_small']) : base_url("public/uploads/default_logo.png");
+ $data['company_logo_large'] = !empty($details[0]['company_logo_large']) && file_exists(FCPATH."public/uploads/".$details[0]['company_logo_large']) ? base_url("public/uploads/" . $details[0]['company_logo_large']) : base_url("public/uploads/default.png");
$data['browser_title'] = $data['company_name'] . ' | ' . $data['company_short_name'] . ' ' . $data['page_name'];
$data['heading'] = $data['page_name'] == "Dashboard" ? 'Welcome to ' . $data['company_name'] : "";
echo view('template/header.php', $data);
diff --git a/app/Controllers/Business.php b/app/Controllers/Business.php
index d254fa19..8df4e8db 100644
--- a/app/Controllers/Business.php
+++ b/app/Controllers/Business.php
@@ -12,9 +12,19 @@ class Business extends BaseController
{
helper('session');
if (is_session_active()) {
+ $session_role = get_user_role();
+ if (!empty($session_role) && $session_role !== "sadmin") {
+ $this->logger->info("Buiness: Listing In admin role .");
+ $where = ['business_id' => (int)get_business_id(), 'isactive' => 1];
+ } else {
+ $this->logger->info("Buiness: Listing In Super-admin role .");
+ $where = ['isactive !=' => NULL];
+ }
$BusinessModel = new BusinessModel();
$data['page_name'] = 'Buiness Listing';
- $data['businesses'] = $BusinessModel->where(['isactive' => 1])->findAll();
+ $data['businesses'] = $BusinessModel->where($where)->findAll();
+ // $data['lastQuery'] = $BusinessModel->getLastQuery();
+ // print_r($data);die;
$this->render_page('business_list', $data);
} else {
return redirect()->to('login');
@@ -43,7 +53,7 @@ class Business extends BaseController
{
helper('session');
$session_uid = get_logged_user_id();
-
+ $session_role = get_user_role();
$validationRule = [
'user' => [
'label' => 'Image File',
@@ -103,8 +113,9 @@ class Business extends BaseController
$BusinessModel->insert($data);
} else {
// It's an update operation
+ if($session_role === 'sadmin'){
$isactive = $this->request->getPost('bcheckbox');
- $data['isactive'] = ($isactive == 'on') ? 1 : 0;
+ $data['isactive'] = ($isactive == 'on') ? 1 : 0; }
$data['updated_by'] = $session_uid;
$BusinessModel->update($business_id, $data);
}
diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php
index fd494bd5..a2931183 100644
--- a/app/Controllers/Customer.php
+++ b/app/Controllers/Customer.php
@@ -191,104 +191,4 @@ class Customer extends BaseController
$address_details = $model->where($where)->findAll();
return $address_details;
}
- ## ApiIntegration For Customer.
- public function apiintegration()
- {
- helper('apiIntegration');
- helper('session');
- $session_bid = get_business_id();
- $session_uid = get_logged_user_id();
- $response = perform_http_request('GET', VB_CUSTOMERS);
- $message = "";
- if (count($response['response']) > 0) {
- //$message = "Reponse Count : ".count($response['response'])."
";
- echo "Note : This For CrossCheck Purpose 1ly
";
- echo "Total Customer API Reponse Count : " . count($response['response']) . "
";
- $CustomerModel = new CustomerModel();
- $x=0;
- foreach ($response['response'] as $row) {
- $insertion_data['first_name'] = $row->first_name;
- $insertion_data['last_name'] = $row->last_name;
- $insertion_data['type'] = $row->role;
- $insertion_data['email'] = $row->email;
- // $insertion_data['profile_picture'] = $row->avatar_url;
- $insertion_data['mode'] = 'online';
- $insertion_data['created_by'] = $session_uid;
- $insertion_data['business_id'] = $session_bid;
- $billing = $row->billing;
- $shipping = $row->shipping;
- $CustomerModel->insert($insertion_data);
- $lastInsertId = $CustomerModel->insertID();
- $insertion_baddress_data = [];$insertion_saddress_data = [];
- $i = 0; $j = 0;
-
- if(isset($billing) && gettype($billing) === 'object') {$billing = [$billing];}
- if(isset($shipping) && gettype($shipping) === 'object') {$shipping = [$shipping];}
- echo "Customer ID : ".$lastInsertId." have Billing address = ".count($billing)." and Shipping address = ".count($shipping)."
";
- if (count($billing) > 0) {
- foreach ($billing as $bill) {
- if ($bill->first_name !== '') {
- $insertion_baddress_data[$i]['first_name'] = $bill->first_name;
- $insertion_baddress_data[$i]['last_name'] = $bill->last_name;
- $insertion_baddress_data[$i]['company'] = $bill->company;
- $insertion_baddress_data[$i]['address_1'] = $bill->address_1;
- $insertion_baddress_data[$i]['address_2'] = $bill->address_2;
- $insertion_baddress_data[$i]['city'] = $bill->city;
- $insertion_baddress_data[$i]['state'] = $bill->state;
- $insertion_baddress_data[$i]['country'] = $bill->country;
- $insertion_baddress_data[$i]['postal_code'] = $bill->postcode;
- $insertion_baddress_data[$i]['customer_id'] = $lastInsertId;
- $insertion_baddress_data[$i]['address_type'] = 1;
- $insertion_baddress_data[$i]['created_by'] = $session_uid;
- $insertion_baddress_data[$i]['email'] = isset($bill->email) ? $bill->email : '';
- $insertion_baddress_data[$i]['mobile_no'] = isset($bill->phone) ? $bill->phone : '';
- $i++;
- echo " Billing address has a value and Inserted ".$i."
";
- }else{
- echo " Keys are available but Billing address has no value;
";
- }
- }
- (!empty($insertion_baddress_data) ? $CustomerModel->insertAddressBatch($insertion_baddress_data) : "");
- }
- if (count($shipping) > 0) {
- foreach ($shipping as $ship) {
- if ($ship->first_name !== '') {
- $insertion_saddress_data[$j]['first_name'] = $ship->first_name;
- $insertion_saddress_data[$j]['last_name'] = $ship->last_name;
- $insertion_saddress_data[$j]['company'] = $ship->company;
- $insertion_saddress_data[$j]['address_1'] = $ship->address_1;
- $insertion_saddress_data[$j]['address_2'] = $ship->address_2;
- $insertion_saddress_data[$j]['city'] = $ship->city;
- $insertion_saddress_data[$j]['state'] = $ship->state;
- $insertion_saddress_data[$j]['country'] = $ship->country;
- $insertion_saddress_data[$j]['postal_code'] = $ship->postcode;
- $insertion_saddress_data[$j]['email'] = isset($ship->email)?$ship->email:"";
- $insertion_saddress_data[$j]['mobile_no'] = isset($ship->phone)?$ship->phone:"";
- $insertion_saddress_data[$j]['customer_id'] = $lastInsertId;
- $insertion_saddress_data[$j]['address_type'] = 2;
- $insertion_saddress_data[$j]['created_by'] = $session_uid;
- $j++;
- echo " Shipping address has a value and Inserted ".$j."
";
- }
- else{
- echo " Keys are available but Shipping address has no value
";
- }
- }
- (!empty($insertion_saddress_data) ? $CustomerModel->insertAddressBatch($insertion_saddress_data) : "");
- }
- } //reponse foreach closed
- } //reponse count if closed
- if (!empty($response['error'])) {
- echo $response['error'];
- echo $response['error_msg'];
- $message .= $response['error'] . $response['error_msg'];
- echo "Error :".$response['error'] . $response['error_msg'];
- }else{
- echo "Done";
- }
- $go_to_list_page = base_url()."customer_list";
- echo "
BigBambooBookPublish
-BigBambooBookPublish
BigBambooBookPublish
-BigBambooBookPublish
Enter your password to access the = $loggedin_person_role; ?>
BigBambooBookPublish
-BigBambooBookPublish
Enter your email address and password to access admin panel.
diff --git a/app/Views/auth_logout.php b/app/Views/auth_logout.php index 0b3c1d0a..2b709b8a 100755 --- a/app/Views/auth_logout.php +++ b/app/Views/auth_logout.php @@ -8,7 +8,7 @@ - "> + "> " rel="stylesheet" type="text/css" id="bs-default-stylesheet" /> @@ -36,16 +36,14 @@BigBambooBookPublish
-BigBambooBookPublish
= date('Y') ?> © = $company_name; ?>.
- +