diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 907f2ea6..e13f4e23 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -63,7 +63,7 @@ $routes->get("delete_books/(:any)", "Books::delete_books/$1"); $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"); +$routes->get("delete_sitesetting/(:any)", "Settings::delete_sitesetting/$1"); # Business Routes $routes->get("business_list/", "Business::index"); @@ -76,6 +76,7 @@ $routes->get("customer_list/", "Customer::index"); $routes->get("new_customer/(:any)", "Customer::new_customer/$1"); $routes->post("insert_customer", "Customer::insert_customer"); $routes->get("delete_customer/(:any)", "Customer::delete_customer/$1"); +$routes->post("save_invoice_customer", "Customer::save_invoice_customer"); # Routes for Customer group $routes->get('customer_group/', 'Customer::customer_group'); diff --git a/app/Controllers/Business.php b/app/Controllers/Business.php index 620bb55b..c8238b5b 100644 --- a/app/Controllers/Business.php +++ b/app/Controllers/Business.php @@ -124,7 +124,6 @@ class Business extends BaseController //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"); } - $BusinessModel = new BusinessModel(); $data = [ 'title' => $this->request->getPost('bname'), @@ -134,6 +133,7 @@ class Business extends BaseController 'city' => $this->request->getPost('bcity'), 'state' => $this->request->getPost('bstate'), 'postal_code' => $this->request->getPost('bzip'), + 'country' => $this->request->getPost('bcountry'), 'terms'=>$this->request->getPost('bterms'), 'business_logo' => $final_img_name ]; @@ -143,14 +143,30 @@ class Business extends BaseController // It's an insert operation $data['isactive'] = 1; $data['created_by'] = $session_uid; - $BusinessModel->insert($data); + if ($BusinessModel->insert($data)) { + $business_id = $BusinessModel->insertID(); + session()->setFlashdata('success', 'business successfully created.'); + $this->logger->info("businesss: has been added successfully. Inserted ID = " . $business_id); + } else { + session()->setFlashdata('error', 'business could not be created. Please try again..'); + $this->logger->error("business: Err could not be added. Please try again."); + } + } else { // It's an update operation if($session_role === 'sadmin'){ $isactive = $this->request->getPost('bcheckbox'); $data['isactive'] = ($isactive == 'on') ? 1 : 0; } $data['updated_by'] = $session_uid; - $BusinessModel->update($business_id, $data); + if ($BusinessModel->update($business_id, $data)) { + $business_affectedRows = $BusinessModel->db->affectedRows(); + session()->setFlashdata('success', 'business successfully updated.'); + $this->logger->info("Business: has been updated successfully. Updated Business ID = " . $business_id . " Aff ".$business_affectedRows); + } else { + session()->setFlashdata('error', 'business updation failed. Please try again.'); + $this->logger->error("Business: Err Failed to update ID =" . $business_id); + } + } return redirect()->route('business_list'); @@ -161,20 +177,31 @@ class Business extends BaseController { helper('session'); $session_uid = get_logged_user_id(); - $BusinessModel = new BusinessModel(); + try { + + $BusinessModel = new BusinessModel(); + $existed = $BusinessModel->find($id); + $this->logger->Info("Business : Going to Inactive ID = " . $id); - // Check if the business ID exists - $existingBusiness = $BusinessModel->find($id); - if (!$existingBusiness) { - return redirect()->route('business_list'); + if ($existed) { + $data['isactive'] = 0; + $data['updated_by'] = get_logged_user_id(); + + if ($BusinessModel->update($id, $data)) { + session()->setFlashdata('success', 'Deleted successfully.'); + $this->logger->info("Business: has been Inactived successfully. Inactived ID = " . $id); + } else { + $this->logger->error("Business: Not able to Inactive ID =" . $id); + throw new \Exception("Data Not able to Deleted"); + } + } else { + $this->logger->error("Business: Does Not Exist To Inactive, ID = " . $id); + throw new \Exception("Business Already Deleted"); + } + } catch (\Exception $e) { + $this->logger->error("Business: Err Occur = " . $e->getMessage()); + session()->setFlashdata('error', 'Message: ' . $e->getMessage()); } - - // Delete the business record - $data['isactive'] = 0; - $data['updated_by'] = $session_uid; - $BusinessModel->update($id, $data); - //$BusinessModel->delete($id); - return redirect()->route('business_list'); } } diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php index 43f4f5f2..cfdacc90 100644 --- a/app/Controllers/Customer.php +++ b/app/Controllers/Customer.php @@ -545,5 +545,41 @@ class Customer extends BaseController } return redirect()->route('customer_group'); } + + ## For Ajax Call To Save Invoice Customer... + public function save_invoice_customer() + { + helper('session'); + $session_bid = get_business_id(); + $session_uid = get_logged_user_id(); + $model = new CustomerModel(); + + $data = [ + 'first_name' => $this->request->getPost('cus_first_name'), + 'last_name' => $this->request->getPost('cus_last_name'), + 'mobile_no' => $this->request->getPost('cus_mobile_no'), + 'email' => $this->request->getPost('cus_email'), + 'date_of_birth' => NULL, + 'type' => "customer", + 'mode' => "Offline", + 'business_id' => $session_bid, + 'isactive' => 1, + 'created_by' => $session_uid + ]; + + if ($model->insert($data)) { + $this->logger->info("Invoice Customer : has been added successfully. Inserted ID = " . $model->insertID()); + $results = ['status' => true, 'message' => 'customer has been added successfully','cus_id' => $model->insertID()]; + }else { + $this->logger->error("Invoice Customer: Err could not be added. Please try again."); + $results = ['status' => false, 'message' => 'customer could not be added']; + } + + //get all customerss + $CustomerModel = new CustomerModel(); + $where = ['isactive' => 1, 'business_id' => (int)$session_bid]; + $results['customers'] = $CustomerModel->where($where)->orderBy('customer_id', 'DESC')->findAll(); + return $this->response->setJSON(['data' => $results]); + } } diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index 4b9c4a1b..22e462af 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -76,6 +76,8 @@ class Invoice extends BaseController public function new_subscription_invoice($id = '0') { helper('session'); + helper('financial_year_helper'); + $data['financial_year'] = get_financial_year(); $model = new InvoiceModel(); $where = ['business_id' => (int)get_business_id()]; @@ -193,6 +195,7 @@ class Invoice extends BaseController 'order_number' => $this->request->getPost('order_number'), 'payment_method' => $invoice_status !== 'Draft' ? $this->request->getPost('payment_method') : NULL, // "Credit Card," "Cash on Delivery," "PayPal","PayTm","Gpay" 'payment_status' => 'Pending', //"Paid," "Pending," "Failed," "Refunded," "Canceled," "Authorized," and "Completed." + 'payment_note'=> $this->request->getPost('payment_note'), 'event_id' => (int)$this->request->getPost('event_id'), 'business_id' => (int)get_business_id(), 'status' => $invoice_status, diff --git a/app/Controllers/Settings.php b/app/Controllers/Settings.php index f040b9f6..6d288c38 100755 --- a/app/Controllers/Settings.php +++ b/app/Controllers/Settings.php @@ -12,14 +12,15 @@ class Settings extends BaseController $session_role = get_user_role(); $session_bid = get_business_id(); - $where = ['settings.isactive' => 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(); + if (!empty($session_role) && $session_role !== "sadmin") { + $where = ['settings.business_id !='=> '1', 'settings.isactive' => 1]; + $sitesetting_details = $model->where($where)->orderBy('setting_id', 'DESC')->findAll(); + }else{ + $where = ['settings.business_id !='=> '1']; + $sitesetting_details = $model->where($where)->orderBy('setting_id', 'DESC')->findAll(); + } $data['page_name'] = 'Site Settings Details'; $data['details'] = $sitesetting_details; $data['session_role'] = $session_role; @@ -63,23 +64,23 @@ class Settings extends BaseController $session_bid = get_business_id(); $session_uid = get_logged_user_id(); - // $validationRule = [ - // 'favicon' => [ - // 'label' => 'Favicon', - // 'rules' => [ - // 'uploaded[favicon]', - // 'is_image[favicon]', - // 'mime_in[favicon,image/ico,image/x-icon]', - // ], - // ], - // ]; + // $validationRule = [ + // 'favicon' => [ + // 'label' => 'Favicon', + // 'rules' => [ + // 'uploaded[favicon]', + // 'is_image[favicon]', + // 'mime_in[favicon,image/ico,image/x-icon]', + // ], + // ], + // ]; - // if (!$this->validate($validationRule)) { - // // Validation failed, return to the form with errors - // $data['validation_errors'] = $this->validator->getErrors(); - // $this->render_page('setting_form', $data); - // return; - // } + // if (!$this->validate($validationRule)) { + // // Validation failed, return to the form with errors + // $data['validation_errors'] = $this->validator->getErrors(); + // $this->render_page('setting_form', $data); + // return; + // } $setting_id = $this->request->getPost('setting_id'); $business_id = $this->request->getPost('business_id'); @@ -172,15 +173,60 @@ class Settings extends BaseController // It's an insert operation $data['isactive'] = 1; $data['created_by'] = $session_uid; - - $SettingsModel->insert($data); + if ($SettingsModel->insert($data)) { + $setting_id = $SettingsModel->insertID(); + session()->setFlashdata('success', 'Site Settings has been added successfully.'); + $this->logger->info("Site Settings : has been added successfully. Inserted ID = " . $setting_id); + // If it's a subscription invoice, also store data in the 'subscription' table + } else { + session()->setFlashdata('error', 'Site Settings could not be added. Please try again.'); + $this->logger->error("Site Settings : Err Occur could not be added. Please try again."); + } // 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 ($SettingsModel->update($setting_id, $data)) { + $business_affectedRows = $SettingsModel->db->affectedRows(); + session()->setFlashdata('success', 'Site Settings successfully updated.'); + $this->logger->info("Site Settings: has been updated successfully. Updated Site Settings ID = " . $business_id . " Aff ".$business_affectedRows); + } else { + session()->setFlashdata('error', 'Site Settings updation failed. Please try again.'); + $this->logger->error("Site Settings: Err Failed to update ID =" . $business_id); + } + } + return redirect()->route('sitesetting_list'); + } + + public function delete_sitesetting($id) + { + helper('session'); + $session_uid = get_logged_user_id(); + try { + $SettingsModel = new SettingsModel(); + $existed = $SettingsModel->find($id); + $this->logger->Info("SiteSetting : Going to Inactive ID = " . $id); + + if ($existed) { + $data['isactive'] = 0; + $data['updated_by'] = get_logged_user_id(); + + if ($SettingsModel->update($id, $data)) { + session()->setFlashdata('success', 'Deleted successfully.'); + $this->logger->info("SiteSetting: has been Inactived successfully. Inactived ID = " . $id); + } else { + $this->logger->error("SiteSetting: Not able to Inactive ID =" . $id); + throw new \Exception("Data Not able to Deleted"); + } + } else { + $this->logger->error("SiteSetting: Does Not Exist To Inactive, ID = " . $id); + throw new \Exception("SiteSetting Already Deleted"); + } + } catch (\Exception $e) { + $this->logger->error("SiteSetting: Err Occur = " . $e->getMessage()); + session()->setFlashdata('error', 'Message: ' . $e->getMessage()); } return redirect()->route('sitesetting_list'); } diff --git a/app/Models/BusinessModel.php b/app/Models/BusinessModel.php index 5b61c1cc..635296ad 100644 --- a/app/Models/BusinessModel.php +++ b/app/Models/BusinessModel.php @@ -9,7 +9,7 @@ class BusinessModel extends Model { protected $table = 'business'; protected $primaryKey = 'business_id'; - protected $allowedFields = ['business_id','title','email','mobile_no','terms','address','city','state','postal_code' ,'business_logo','isactive']; + protected $allowedFields = ['business_id','title','email','mobile_no','terms','address','city','state','postal_code','country','business_logo','isactive']; public function insertBusiness($data) { diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index 702707e2..4aa9346d 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -8,7 +8,7 @@ class InvoiceModel extends Model protected $table = 'invoice'; protected $primaryKey = 'invoice_id'; // protected $allowedFields = ['invoice_id','invoice_number','customer_id','invoice_date','event_id','business_id','created_on','business_id']; -protected $allowedFields = ['invoice_id', 'invoice_number', 'customer_id','notes', 'invoice_date', 'due_date', 'subtotal', 'tax', 'discount', 'shipping_charge','shipping_label','total_amount', 'payment_status', 'order_number','invoice_type', 'payment_method', 'event_id', 'business_id', 'shipping_address_id', 'billing_address_id', 'created_on', 'created_by', 'updated_on', 'updated_by','category','isactive','billing_address','shipping_address','status']; +protected $allowedFields = ['invoice_id', 'invoice_number', 'customer_id','notes', 'invoice_date', 'due_date', 'subtotal', 'tax', 'discount', 'shipping_charge','shipping_label','total_amount', 'payment_status', 'order_number','invoice_type', 'payment_method', 'event_id', 'business_id', 'shipping_address_id', 'billing_address_id', 'created_on', 'created_by', 'updated_on', 'updated_by','category','isactive','billing_address','shipping_address','status','payment_note']; public function saveInvoiceItemDetails($data){ $i = 0; diff --git a/app/Views/business_form.php b/app/Views/business_form.php index 04cf292f..fb9ca211 100644 --- a/app/Views/business_form.php +++ b/app/Views/business_form.php @@ -60,12 +60,12 @@
| - + + + " class="delete-button" title="Click to Delete Site Setting"> + | -