diff --git a/.env b/.env index 13f6ad3..baef502 100644 --- a/.env +++ b/.env @@ -15,13 +15,13 @@ #-------------------------------------------------------------------- # CI_ENVIRONMENT = production -#CI_ENVIRONMENT = development +CI_ENVIRONMENT = development #LOCAL_FOLDER = 'donation' #-------------------------------------------------------------------- # APP #-------------------------------------------------------------------- -# app.baseURL = 'http://localhost/donation/' +app.baseURL = 'http://localhost/donation/' # app.baseURL ='https://venbainfotech.com/donr/' # app.forceGlobalSecureRequests = false @@ -63,6 +63,19 @@ # database.tests.password = root # database.tests.DBDriver = MySQLi + +database.default.hostname = localhost +database.default.database = doner_management +database.default.username = root +database.default.password = '' +database.default.DBDriver = MySQLi + +database.tests.hostname = localhost +database.tests.database = doner_management +database.tests.username = root +database.tests.password = '' +database.tests.DBDriver = MySQLi + #-------------------------------------------------------------------- # CONTENT SECURITY POLICY #-------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index b24d71e..9ce12c6 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,5 @@ Thumbs.db *.mov *.wmv +writable/session/ +writable/debugbar/ diff --git a/app/Config/Routes.php b/app/Config/Routes.php index aaa888a..579b82a 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -71,9 +71,9 @@ $routes->get("new_bussiness/(:any)", "Business::new_bussiness/$1"); $routes->post("insert_business/", "Business::insert_business"); $routes->get("delete_business/(:any)", "Business::delete_business/$1"); -# Doner Routes -$routes->get("doner_list/", "Customer::index"); -$routes->get("new_doner/(:any)", "Customer::new_doner/$1"); +# Donor Routes +$routes->get("Donor_list/", "Customer::index"); +$routes->get("new_Donor/(:any)", "Customer::new_Donor/$1"); $routes->post("insert_customer", "Customer::insert_customer"); $routes->get("delete_customer/(:any)", "Customer::delete_customer/$1"); diff --git a/app/Controllers/Authentication.php b/app/Controllers/Authentication.php index d67b116..37ab968 100644 --- a/app/Controllers/Authentication.php +++ b/app/Controllers/Authentication.php @@ -248,7 +248,9 @@ class Authentication extends BaseController $this->response->setHeader('Pragma', 'no-cache'); $this->response->setHeader('Expires', 'Fri, 01 Jan 1990 00:00:00 GMT'); $data = []; - return view('auth_logout', $data); + + return redirect()->route('login'); + // return view('auth_logout', $data); } ## Lock Screen - holded diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 527ebe3..907d415 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -78,6 +78,8 @@ abstract class BaseController extends Controller $session_uid = get_logged_user_id(); $session_uname = get_logged_name(); + + // echo $session_uname; die; $mergedData = array_merge($data, $this->authData); $mergedData['browser_title']= $mergedData['company_name'] . ' | ' . $mergedData['company_short_name'] . ' ' . $mergedData['page_name']; diff --git a/app/Controllers/Books.php b/app/Controllers/Books.php index 82d6471..e5c2fce 100644 --- a/app/Controllers/Books.php +++ b/app/Controllers/Books.php @@ -81,7 +81,7 @@ class Books extends BaseController $causes_id = $BooksModel->insert($data); - if ($BooksModel->insert($data)) { + if ($causes_id) { session()->setFlashdata('success', 'causes successfully created.'); $this->logger->info("Books: has been added successfully. Inserted ID = " . $BooksModel->insertID()); } else { diff --git a/app/Controllers/Business.php b/app/Controllers/Business.php index 0ef06c7..c7c1482 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)->findAll(); + $data['businesses'] = $BusinessModel->where($where)->where('business_id !=', 0)->findAll(); // $data['lastQuery'] = $BusinessModel->getLastQuery(); // print_r($data);die; $this->render_page('business_list', $data); @@ -33,10 +33,13 @@ class Business extends BaseController ## To Load Business Form (Add/Update) public function new_bussiness($id) - { + { + helper('session'); + $session_role = get_user_role(); if ($id === '0') { $data['page_name'] = 'Add Organization'; + $data['loged_user'] = $session_role; $data['businesses'] = []; } else if ($id !== '0') { $data['page_name'] = 'Edit Organization'; @@ -58,6 +61,7 @@ class Business extends BaseController helper('session'); $session_uid = get_logged_user_id(); $session_role = get_user_role(); + $img = $this->request->getFile('bfile'); $business_id = $this->request->getPost('business_id'); @@ -110,8 +114,13 @@ class Business extends BaseController $data['updated_by'] = $session_uid; $BusinessModel->update($business_id, $data); } - + + if (empty($business_id)) { + return redirect()->route('business_list'); + }else{ return redirect()->route('dashboard'); + } + } ## For delete the business details (Which means inactive the details) diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php index e8f6e4c..055572e 100644 --- a/app/Controllers/Customer.php +++ b/app/Controllers/Customer.php @@ -16,15 +16,15 @@ class Customer extends BaseController $session_role = get_user_role(); $session_bid = get_business_id(); if (!empty($session_role) && $session_role !== "sadmin") { - $this->logger->info("Doner: Listing In admin role . BID = ".$session_bid); + $this->logger->info("Donor: Listing In admin role . BID = ".$session_bid); $where = ['isactive' => 1, 'business_id' => (int)$session_bid]; } else { - $this->logger->info("Doner: Listing In Super-admin role ."); + $this->logger->info("Donor: Listing In Super-admin role ."); $where = ['isactive != ' => NULL]; } $CustomerModel = new CustomerModel(); - $data['page_name'] = 'Doner Details'; + $data['page_name'] = 'Donor Details'; $data['customer'] = $CustomerModel->where($where)->orderBy('doner_id', 'DESC')->findAll(); // print_r($data); die(); @@ -35,22 +35,21 @@ class Customer extends BaseController } } - ## To Load Doner Form (Add/Update) - public function new_doner($id) + ## To Load Donor Form (Add/Update) + public function new_Donor($id) { helper('session'); $session_bid = get_business_id(); if ($id === '0') { - // Add Doner - $data['page_name'] = 'Add Doner Details'; + // Add Donor + $data['page_name'] = 'Add Donor Details'; $data['customer'] = []; } else if ($id !== '0') { - // Edit Doner - $data['page_name'] = 'Edit Doner Details'; - - // Load your Customer Model + + // Edit Donor + $data['page_name'] = 'Edit Donor Details'; $customerModel = new CustomerModel(); // Retrieve customer details by customer ID @@ -74,7 +73,7 @@ class Customer extends BaseController { $requestData = $this->request->getPost(); // print_r($requestData);die; - $this->logger->info("Doner: Inserting/Updating Details"); + $this->logger->info("Donor: Inserting/Updating Details"); try { helper('session'); $session_bid = get_business_id(); @@ -90,7 +89,7 @@ class Customer extends BaseController 'email' => $this->request->getPost('cmail'), 'date_of_birth' => $dob, 'pan_no' => $this->request->getPost('pan_no'), - 'doner_type' => $this->request->getPost('donerType'), + 'doner_type' => $this->request->getPost('DonorType'), 'org_name' => $this->request->getPost('org_name') !== '' || $this->request->getPost('org_name') !== null ? $this->request->getPost('org_name') : NULL, 'address' => $this->request->getPost('address'), 'city' => $this->request->getPost('city'), @@ -110,12 +109,12 @@ class Customer extends BaseController $data['isactive'] = 1; $data['created_by'] = $session_uid; if ($model->insert($data)) { - session()->setFlashdata('success', 'Doner successfully created.'); - $this->logger->info("Doner : has been added successfully. Inserted ID = " . $model->insertID()); - $doner_id_for_addresses = $model->insertID();// for Doner ADDRESS Table + session()->setFlashdata('success', 'Donor successfully created.'); + $this->logger->info("Donor : has been added successfully. Inserted ID = " . $model->insertID()); + $doner_id_for_addresses = $model->insertID();// for Donor ADDRESS Table } else { - session()->setFlashdata('error', 'Doner could not be added. Please try again..'); - $this->logger->error("Doner: Err could not be added. Please try again."); + session()->setFlashdata('error', 'Donor could not be added. Please try again..'); + $this->logger->error("Donor: Err could not be added. Please try again."); $doner_id_for_addresses = ""; } } else { @@ -127,98 +126,31 @@ class Customer extends BaseController $data['updated_by'] = $session_uid; $doner_id_for_addresses = $doner_id; // for Customer ADDRESS Table if ($model->update($doner_id, $data)) { - session()->setFlashdata('success', 'Doner successfully updated'); - $this->logger->info("Doner: has been updated successfully. Updated Doner ID = " . $doner_id_for_addresses); + session()->setFlashdata('success', 'Donor successfully updated'); + $this->logger->info("Donor: has been updated successfully. Updated Donor ID = " . $doner_id_for_addresses); } else { - session()->setFlashdata('error', 'Doner updation failed. Please try again.'); - $this->logger->error("Doner: Err Failed to update ID =" . $doner_id_for_addresses); + session()->setFlashdata('error', 'Donor updation failed. Please try again.'); + $this->logger->error("Donor: Err Failed to update ID =" . $doner_id_for_addresses); } } // if($doner_id_for_addresses != ""){ - // $this->logger->info("Doner: i got Doner id for addresses = " . $doner_id_for_addresses); + // $this->logger->info("Donor: i got Donor id for addresses = " . $doner_id_for_addresses); // $requestData = $this->request->getPost(); // $bill_addr = $this->save_customer_addresses($doner_id_for_addresses, $requestData, 'b'); // $this->logger->info("Customer: bill addr final message = " .implode(" ",$bill_addr)); // $ship_addr = $this->save_customer_addresses($doner_id_for_addresses, $requestData, 's'); - // $this->logger->info("Doner: Ship addr final message = " . implode(" ",$ship_addr)); + // $this->logger->info("Donor: Ship addr final message = " . implode(" ",$ship_addr)); // } } catch (\Exception $e) { - $this->logger->error("Doner : Err Occur =" . $e->getMessage()); + $this->logger->error("Donor : Err Occur =" . $e->getMessage()); session()->setFlashdata('error', 'Message: ' . $e->getMessage()); } - return redirect()->route('doner_list'); + return redirect()->route('Donor_list'); } - ## For Save the customer addresses details (Using Letting Flag and Customer ID) - // public function save_customer_addresses($id, $requestData, $letteringflag) - // { - // try { - // $addressType = ($letteringflag == 'b') ? 1 : 2; - // $this->logger->info("Doner: Addresses Lettering Flag = " . $letteringflag . " Doner address type = " . $addressType); - // $getAddressdetails = $this->get_customer_address($id, $addressType); - // $CAid = $requestData[$letteringflag . 'customer_address_id']; // Available Address IDS in Form Fields. - // $session_uid = get_logged_user_id(); - // $model = new CustomerModel(); - // ## IF Any Missing value Means that values are Inactive here.... - // if(!empty($CAid)){ - // $this->logger->info("Doner: Primary Addresses ID = ".implode(",",$CAid)); - // $filteringAddressIds = []; - // for ($y = 0; $y < count($getAddressdetails); $y++) { - // $filteringAddressIds[$y] = $getAddressdetails[$y]['customer_address_id']; - // } - // if (!empty($filteringAddressIds)) { - // $A = $filteringAddressIds; - // $B = $CAid; - // $missingValues = array_diff($A, $B); - // if (!empty($missingValues)) { - // $where = ['isactive' => 1, 'doner_id' => (int)$id, 'address_type' => $addressType]; - // $model->inactiveMissingAddressDetails($where, $missingValues); - // $this->logger->info("Doner: Inactived Missing Addresses Count = " . count($missingValues)." That Primary Addresses ID = ".implode(",",$CAid)); - // } - // } - // } - - - // $baddress1 = $requestData[$letteringflag . 'address1']; - // $baddress2 = $requestData[$letteringflag . 'address2']; - // $bcountry = $requestData[$letteringflag . 'country']; - // $bcity = $requestData[$letteringflag . 'city']; - // $binputstate = $requestData[$letteringflag . 'istate']; - // $bdropdownstate = $requestData[$letteringflag . 'dstate']; - // $bzip = $requestData[$letteringflag . 'zip']; - // $count = count($CAid); - // $address_array = []; - // if ($count > 0) { - // for ($x = 0; $x < $count; $x++) { - // $address_array[$x]['first_name'] = $requestData['cfname']; - // $address_array[$x]['last_name'] = $requestData['csname']; - // // $address_array[$x]['company'] = ""; - // $address_array[$x]['email'] = $requestData['cmail']; - // $address_array[$x]['mobile_no'] = $requestData['cmobile']; - // $address_array[$x]['address_1'] = $baddress1[$x]; - // $address_array[$x]['address_2'] = $baddress2[$x]; - // $address_array[$x]['city'] = $bcity[$x]; - // $address_array[$x]['state'] = $bcountry[$x] === 'IN' ? $bdropdownstate[$x] : $binputstate[$x] ; - // $address_array[$x]['country'] = $bcountry[$x]; - // $address_array[$x]['postal_code'] = $bzip[$x]; - // $address_array[$x]['doner_id'] = $id; - // $address_array[$x]['address_type'] = $addressType; - // $address_array[$x]['created_by'] = $session_uid; - // $address_array[$x]['updated_by'] = $CAid[$x] ? $session_uid : null; - // $address_array[$x]['customer_address_id'] = $CAid[$x]; - // } - // $statement = !empty($address_array) ? $model->saveAddressDetails($address_array) : ["No data found For addresses"]; - // $this->logger->info("Doner: Address Final message = " . implode(",",$statement)); - // } - // } catch (\Exception $e) { - // $this->logger->error("Doner: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); - // $statement = ['Message: ' . $e->getMessage()]; - // } - // return $statement; - // } ## For delete the customer details (Which means inactive the details) public function delete_customer($id) @@ -228,31 +160,18 @@ class Customer extends BaseController $session_uid = get_logged_user_id(); $CustomerModel = new CustomerModel(); $where = ['doner_id' => (int)$id, 'isactive =' => 1]; + // Check if the business ID exists $existingCustomer = $CustomerModel->where($where)->find($id); if ($existingCustomer) { - $this->logger->Info("Doner: Going to Inactive ID = ".$id); + $this->logger->Info("Donor: Going to Inactive ID = ".$id); $data = ['isactive' => 0 , 'updated_by' => $session_uid]; // Delete the business record if ($CustomerModel->update($id, $data)) { - $billAddressdetails = $this->get_customer_address($id, 1); - if(!empty($billAddressdetails)){ - for ($y = 0; $y < count($billAddressdetails); $y++) { - $billAddressIds[$y] = $billAddressdetails[$y]['customer_address_id']; - } - $CustomerModel->inactiveMissingAddressDetails($where, $billAddressIds); - } - $shipAddressdetails = $this->get_customer_address($id, 2); - if(!empty($shipAddressdetails)){ - for ($z = 0; $z < count($shipAddressdetails); $z++) { - $shipAddressIds[$z] = $shipAddressdetails[$z]['customer_address_id']; - } - $CustomerModel->inactiveMissingAddressDetails($where, $shipAddressIds); - } - session()->setFlashdata('success', 'Doner successfully deleted.'); - $this->logger->info("Doner: has been Inactived successfully. Inactived ID = " . $id); + session()->setFlashdata('success', 'Donor successfully deleted.'); + $this->logger->info("Donor: has been Inactived successfully. Inactived ID = " . $id); } else { - $this->logger->error("Doner: Not able to Inactive ID =" . $id); + $this->logger->error("Donor: Not able to Inactive ID =" . $id); throw new \Exception("Data Not able to Deleted"); } } @@ -260,7 +179,7 @@ class Customer extends BaseController $this->logger->error("Customer: Err Occur = " . $e->getMessage()); session()->setFlashdata('error', 'Message: ' . $e->getMessage()); } - return redirect()->route('doner_list'); + return redirect()->route('Donor_list'); } public function get_customer_address($id,$type){ @@ -288,25 +207,27 @@ class Customer extends BaseController } public function customer_group(){ - $data['page_name'] = 'Doner Group Details'; + + $session_bid = get_business_id(); + $data['page_name'] = 'Donor Group Details'; $model = new CustomerModel(); - $data['customer_group'] = $model->getGroupDetails(); + $data['customer_group'] = $model->getGroupDetails($session_bid); $this->render_page('customer_group', $data); } + + public function view_customer_group($id){ + helper('session'); $session_bid = get_business_id(); $data['field'] = [ - ['value'=>'','fieldflag'=>1,'text'=> 'Choose the Field','disable' => false], - ['value'=>'C.type','fieldflag'=>1,'text'=> 'Type','disable' => false], - ['value'=>'CA.city','fieldflag'=>1,'text'=> 'City','disable' => false], - // ['value'=>'CA.state','fieldflag'=>1,'text'=> 'State','disable' => false], - ['value'=>'CA.postal_code','fieldflag'=>1,'text'=> 'Postal Code','disable' => false], - ['value'=>'C.mode','fieldflag'=>3,'text'=> 'Mode','disable' => false], - ['value'=>'CM.name','fieldflag'=>1,'text'=> 'Category','disable' => false], - ['value'=>'I.invoice_date','fieldflag'=>2,'text'=> 'Invoice Date','disable' => false], - ['value'=>'S.to_subscription','fieldflag'=>2,'text'=> 'Expiry Date','disable' => false]]; + ['value'=>'', 'fieldflag'=>1, 'text'=> 'Choose the Field', 'disable' => false], + ['value'=>'C.doner_type', 'fieldflag'=>1, 'text'=> 'Donor Type', 'disable' => false], + ['value'=>'C.city', 'fieldflag'=>1, 'text'=> 'City', 'disable' => false], + ['value'=>'C.postal_code', 'fieldflag'=>1, 'text'=> 'Postal Code', 'disable' => false], + ['value'=>'I.receipt_date', 'fieldflag'=>2, 'text'=> 'Receipt Date', 'disable' => false], + ]; $data['operator'] = [ '' => 'Choose the operator', @@ -324,12 +245,13 @@ class Customer extends BaseController 'is not null' => 'Is Not NULL', ]; $data['customer_group'] = []; + if ($id === '0') { // Add Customer - $data['page_name'] = 'Add Doner Group'; + $data['page_name'] = 'Add Donor Group'; } else if ($id !== '0') { // Edit Customer - $data['page_name'] = 'Edit Doner Group'; + $data['page_name'] = 'Edit Donor Group'; // Load your Customer Model $model = new CustomerModel(); @@ -348,6 +270,8 @@ class Customer extends BaseController } $this->render_page('customer_group_form', $data); } + + public function preview_customer_group($id){ try { helper('session'); @@ -357,7 +281,7 @@ class Customer extends BaseController $result = $model->where($where)->findAll(); $db = \Config\Database::connect(); $sql = (string)$result[0]['group_query']; - //print_r($sql);die; + if($sql){ $query = $db->query($sql); $results = $query->getResultArray(); @@ -371,7 +295,7 @@ class Customer extends BaseController } } catch (\Exception $e) { - $this->logger->error("Doner Group: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); + $this->logger->error("Donor Group: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); session()->setFlashdata('error', 'Message: ' . $e->getMessage()); } } @@ -384,7 +308,7 @@ class Customer extends BaseController $where = ['isactive' => 1,'group_id'=>(int)$id]; $result = $model->where($where)->findAll(); if ($result) { - $this->logger->Info("Doner Group: Going to Inactive ID = ".$id); + $this->logger->Info("Donor Group: Going to Inactive ID = ".$id); $data = ['isactive' => 0 , 'updated_by' => $session_uid,'group_id'=>(int)$id]; $statement = $model->saveGroupDetails($data);// just updating Inactive status only. if ($statement['success']) { @@ -394,34 +318,37 @@ class Customer extends BaseController session()->setFlashdata('error', $statement['error']); $this->logger->error($statement['log']); }else{ - throw new \Exception("Doner Group: Err Occur on data the Doner Group Inactive"); + throw new \Exception("Donor Group: Err Occur on data the Donor Group Inactive"); } } } catch (\Exception $e) { - $this->logger->error("Doner Group: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); + $this->logger->error("Donor Group: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); session()->setFlashdata('error', 'Message: ' . $e->getMessage()); } return redirect()->route('customer_group'); } - public function insert_customer_group(){ - + public function insert_customer_group(){ try { - $this->logger->info("Doner Group: Inserting/Updating Details"); + $this->logger->info("Donor Group: Inserting/Updating Details"); helper('session'); $session_uid = get_logged_user_id(); $request_data = $this->request->getPost(); $string_flag = $request_data['string_flag']; // $this->logger->info("Customer Group: Request data = ".json_encode($request_data)); - + + $session_bid = get_business_id(); $model = new CustomerModel(); // Array ( [groupname] => nil [column] => Array ( [0] => city [1] => state ) [operator] => Array ( [0] => not contain [1] => not equal ) [values] => Array ( [0] => 2 [1] => 3 ) ) $data = [ - 'group_name' => $request_data['groupname'], - 'column' => serialize($request_data['column']), - 'operator' => serialize($request_data['operator']), - 'value' => serialize($request_data['values']) + 'group_name' => $request_data['groupname'], + 'column' => serialize($request_data['column']), + 'operator' => serialize($request_data['operator']), + 'value' => serialize($request_data['values']), ]; + + $data['business_id'] = $session_bid; + // Initialize an empty array to store the conditions $conditions = array(); @@ -488,15 +415,15 @@ class Customer extends BaseController // Now you can use $whereCondition in your SQL query $db = \Config\Database::connect(); // $sql = "SELECT doner_id,CONCAT(first_name,'',last_name) as customer_name,email,mobile_no FROM customers WHERE ".$whereCondition; - $sql = "SELECT CA.city,CA.state,I.invoice_date,C.doner_id,CONCAT(C.first_name,'',C.last_name) as customer_name,C.email,C.mobile_no ,S.to_subscription as due_date, C.isactive ,count(I.invoice_id) as invoice_count_raised_by_customer, S.scheme_id , CM.name - FROM customers as C - LEFT JOIN invoice I on I.doner_id = C.doner_id and I.isactive = 1 - LEFT JOIN customer_addresses CA on CA.doner_id = C.doner_id and CA.address_type = 1 and CA.isactive = 1 - LEFT JOIN subscription S on S.doner_id = C.doner_id - LEFT JOIN book_categories BC on BC.book_id = S.scheme_id - LEFT JOIN category CM on CM.id = BC.category_id - WHERE C.isactive = 1 AND ".$whereCondition." GROUP BY C.doner_id"; + $sql = "SELECT C.city, C.state, I.receipt_date, C.doner_id, CONCAT(C.first_name, ' ', C.last_name) as customer_name, C.email, C.mobile_no, C.isactive, COUNT(I.receipt_id) as invoice_count_raised_by_customer FROM customers as C + LEFT JOIN receipt I ON I.doner_id = C.doner_id and I.isactive = 1 + WHERE C.isactive = 1 AND " . $whereCondition . " + GROUP BY C.doner_id"; + $this->logger->info("Customer Group: SQL = ".$sql); + + // echo "$sql"; die; + // Execute the query $query = $db->query($sql); @@ -520,7 +447,7 @@ class Customer extends BaseController session()->setFlashdata('error', $statement['error']); $this->logger->error($statement['log']); }else{ - throw new \Exception("Doner Group: Err Occur on data the Save"); + throw new \Exception("Donor Group: Err Occur on data the Save"); } }else if($string_flag == "preview"){ @@ -529,7 +456,7 @@ class Customer extends BaseController throw new \Exception("Data Not Found"); } } catch (\Exception $e) { - $this->logger->error("Doner Group: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); + $this->logger->error("Donor Group: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); session()->setFlashdata('error', 'Message: ' . $e->getMessage()); } return redirect()->route('customer_group'); diff --git a/app/Controllers/Event.php b/app/Controllers/Event.php index 7c52506..77debcc 100644 --- a/app/Controllers/Event.php +++ b/app/Controllers/Event.php @@ -64,7 +64,7 @@ class Event extends BaseController public function insert_event() { - $this->logger->info("Event: Inserting/Updating Details"); + $this->logger->info("campaign: Inserting/Updating Details"); try { helper('session'); $session_bid = get_business_id(); @@ -87,43 +87,31 @@ class Event extends BaseController if (empty($campaign_id)) { // It's an insert operation $data['created_by'] = $session_uid; - - // echo '
';
- // print_r($data);
-
- // $value = $EventModel->insert($data);
- // $builder = $EventModel;
-
- // // Get the last run query
- // $lastQuery = $builder->getLastQuery();
-
- // // Output or log the last query
- // echo $lastQuery; die;
if ($EventModel->insert($data)) {
- session()->setFlashdata('success', 'Event has been added successfully.');
- $this->logger->info("Event : has been added successfully. Inserted ID = " . $EventModel->insertID());
+ session()->setFlashdata('success', 'campaign has been added successfully.');
+ $this->logger->info("campaign : has been added successfully. Inserted ID = " . $EventModel->insertID());
} else {
- session()->setFlashdata('error', 'Event could not be added. Please try again..');
- $this->logger->error("Event: Err data could not be added. Please try again.");
+ session()->setFlashdata('error', 'campaign could not be added. Please try again..');
+ $this->logger->error("campaign: Err data could not be added. Please try again.");
}
} else {
// It's an update operation
$data['updated_by'] = $session_uid;
if ($EventModel->update($campaign_id, $data)) {
- session()->setFlashdata('success', 'Event has been updated successfully.');
- $this->logger->info("Event: has been updated successfully. Updated Event ID = " . $campaign_id);
+ session()->setFlashdata('success', 'campaign has been updated successfully.');
+ $this->logger->info("campaign: has been updated successfully. Updated campaign ID = " . $campaign_id);
} else {
- session()->setFlashdata('error', 'Event update failed. Please try again.');
- $this->logger->error("Event: Err Failed to update ID =" . $campaign_id);
+ session()->setFlashdata('error', 'campaign update failed. Please try again.');
+ $this->logger->error("campaign: Err Failed to update ID =" . $campaign_id);
}
}
} catch (\Exception $e) {
- $this->logger->error("Event: Err Occur = " . $e->getMessage() . " Line = " . $e->getLine() . " File = " . $e->getFile());
+ $this->logger->error("campaign: Err Occur = " . $e->getMessage() . " Line = " . $e->getLine() . " File = " . $e->getFile());
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
}
- return redirect()->route('campaign');
+ return redirect()->route('campaign_list');
}
public function invoice_number_format($id)
@@ -181,7 +169,7 @@ class Event extends BaseController
}
}
} catch (\Exception $e) {
- $this->logger->error("Event: Err Occur = " . $e->getMessage() . " Line = " . $e->getLine() . " File = " . $e->getFile());
+ $this->logger->error("campaign: Err Occur = " . $e->getMessage() . " Line = " . $e->getLine() . " File = " . $e->getFile());
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
}
return redirect()->to(base_url("invoice_number_format/1"));
diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php
index 313150a..2107ea2 100644
--- a/app/Controllers/Home.php
+++ b/app/Controllers/Home.php
@@ -12,13 +12,16 @@ class Home extends BaseController
helper('session');
$session_role = get_user_role();
$session_bid = get_business_id();
+
+ // echo $session_bid, $session_role; die;
$data['page_name'] = 'Dashboard';
- if (!empty($session_role) && $session_role !== "sadmin") {
- $where = ['isactive' => 1, 'business_id' => (int)$session_bid];
- } else if (!empty($session_role) && $session_role !== "admin") {
+ if (!empty($session_role) && $session_role == "sadmin") {
$where = ['isactive != ' => NULL];
- } else {
+ } else if (!empty($session_role) && $session_role == "admin") {
+ $where = ['isactive' => 1, 'business_id' => $session_bid];
+ }
+ else {
$where = [];
}
$model = new HomeModel();
@@ -26,7 +29,7 @@ class Home extends BaseController
$data['customer']['label'] = "Doners";
// echo '';
- // print_r($data); die;
+ // print_r($data['customer'] ); die;
// $data['invoice'] = $model->invoice();
// $data['active_category'] = array_filter($model->schemes(), function ($element) {
diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php
index 1f03c22..792a5fd 100644
--- a/app/Controllers/Invoice.php
+++ b/app/Controllers/Invoice.php
@@ -1,624 +1,600 @@
- (int)get_business_id()];
- $data['doners'] = $model->getData('customers', $where);
- $data['page_name'] = 'Receipt Details';
- $data['receipt'] = $model->where(["business_id"=>$session_bid])->findAll();
-
- // echo '';
- // print_r($data); die;
-
- $this->logger->info("Invoice: Listing Count ." . count($data['receipt']));
- $this->render_page('invoice_list', $data);
- } else {
- return redirect()->to('login');
- }
- }
-
- ## To Load Invoice ADD/EDIT page...
- public function new_receipt($id = '0')
- {
- helper('session');
- $model = new InvoiceModel();
- $where = ['business_id' => (int)get_business_id()];
-
- // Get customer names for the dropdown, events details, and books details
- $data['customers'] = $model->getData('customers', $where);
- $data['causes'] = $model->getData('causes', $where);
-
- if ($id === '0') {
- $this->logger->info("Receipt: In Add Details");
- $data['page_name'] = 'Add Receipt Details';
- $data['receipt_details'] = [];
- } elseif ($id !== '0') {
- $this->logger->info(" Book Invoice: In Edit Details ID = " . $id);
- $data['page_name'] = 'Edit Receipt Details';
- $data['receipt_details'] = $model->where(['receipt_id' => $id, 'isactive' => 1])->first();
- }
-
- // echo '';
- // print_r($data);die;
- $this->render_page('invoice_form', $data);
- }
-
-
- ## For Ajax Call To Fetch/Retrive All Address Details Based On Customer...
- public function load_details1()
- {
- $id = $this->request->getPost('selectedValue');
- $where = ['customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$id];
- $where['address_type'] = 1;
- $data['customer_billing'] = $this->get_customer_address($where, []);
- $select = ["customer_address_id", "CONCAT(address_1,' ',address_2) as address"];
- $where['address_type'] = 2;
- $data['customer_shipping'] = $this->get_customer_address($where, $select);
- $data['customer_membership'] = $this->get_customer_membership("membership",(int)$id);
- return $this->response->setJSON(['data' => $data]);
- }
-
- ## For Ajax Call To Fetch/Retrive Shipping Address Details Only Based On Customer...
- public function load_details2()
- {
- $customer_id = $this->request->getPost('customerValue');
- $address_id = $this->request->getPost('selectedValue');
- $where = ['customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$customer_id, 'address_type' => 2, 'customer_address_id' => (int)$address_id];
- $data['customer_shipping'] = $this->get_customer_address($where, []);
- return $this->response->setJSON(['data' => $data]);
- }
- // public function generate_serial_no(){}
-
- ## For Gethering Address Details...
- public function get_customer_address($where, $select)
- {
- $model = new CustomerModel();
- $model->setTable('customer_addresses');
- if (empty($select)) {
- $select = ["customer_addresses.customer_id","customer_addresses.customer_address_id","customer_addresses.first_name","customer_addresses.last_name ","customer_addresses.company","customer_addresses.email","customer_addresses.mobile_no","customer_addresses.address_type","customer_addresses.address_1","customer_addresses.address_2","customer_addresses.city","customer_addresses.state","customer_addresses.postal_code","customer_addresses.country","states.state_name","countries.country_name"];
- }
- $address_details = $model->select($select)->join('states', 'states.state_short_name = customer_addresses.state AND customer_addresses.country = "IN"', 'left')->join('countries', 'countries.country_short_name = customer_addresses.country', 'left')->where($where)->findAll();
- return $address_details;
- }
-
- public function get_customer_membership($category,$id){
- $model = new InvoiceModel();
- $result = $model->getMembershipListForCustomer($category,$id);
- return $result;
- }
-
- ## To insert or update the details of the invoice
- public function save_invoice()
- {
- $this->logger->info("Invoice: Insert/Update Details");
- try {
-
- ## Declarions
- helper('session');
- $model = new InvoiceModel();
-
- $receipt_date = $this->request->getVar('receipt_date');
-
- $receipt_id = (!empty($this->request->getPost('receipt_id'))) ? $this->request->getPost('receipt_id') : "";
- $customer_id = (int)$this->request->getPost('doner_id');
-
- $data = [
- 'receipt_number' => $this->request->getPost('receipt_number'),
- 'doner_id' => $customer_id,
- 'notes'=>$this->request->getPost('notes'),
- 'receipt_date' => (!empty($receipt_date)) ? date("Y-m-d", strtotime($receipt_date)) : NULL,
- 'amount' => (int)$this->request->getPost('amount'),
- 'payment_mode' => $this->request->getPost('payment_mode'),
- 'payment_ref_no' => $this->request->getPost('payment_ref_no'),
- 'causes_id' => (int)$this->request->getPost('causes_id'),
- 'business_id' => (int)get_business_id(),
- 'isactive' => 1
- ];
- ## Based on the invoice ID, we designated Insert or Update on Details...
- if (empty($receipt_id)) {
- $data['created_by'] = (int)get_logged_user_id();
- if ($model->insert($data, 'invoices')) {
- $receipt_id = $model->insertID();
- session()->setFlashdata('success', 'Receipt has been added successfully.');
- $this->logger->info("Receipt: has been added successfully. Inserted ID = " . $receipt_id);
-
- } else {
- session()->setFlashdata('error', 'Receipt could not be added. Please try again.');
- $this->logger->error("Receipt: Err Occur could not be added. Please try again.");
- }
-
- } else {
- $data['updated_by'] = (int)get_logged_user_id();
- if ($model->update($receipt_id, $data)) {
- session()->setFlashdata('success', 'Receipt has been updated successfully.');
- $this->logger->info("Receipt: has been updated successfully. Updated ID = " . $receipt_id);
- } else {
- session()->setFlashdata('error', 'Receipt update failed. Please try again.');
- $this->logger->error("Receipt: Err Failed to update ID =" . $receipt_id);
- }
- }
-
-
- } catch (\Exception $e) {
- $this->logger->error("Receipt: Err Occur =" . $e->getMessage());
- session()->setFlashdata('error', 'Message: ' . $e->getMessage());
- }
- return redirect()->route('receipt_list');
-
-
-
-
- }
-
- ## For Updating Events Details ..
- public function update_number_formatting($update_events)
- {
- // `id``event_name``business_id``updated_by``updated_on``next_id`
- $model = new InvoiceModel();
- $model->setTable('invoice_number_formatting');
- $where = ['isactive' => 1, 'id' => (int)$update_events['id'], 'business_id' => (int)$update_events['business_id'], 'next_id' => $update_events['next_id']];
- $details = $model->where($where)->findAll();
- if (empty($details)) {
- $update_where = ['id' => (int)$update_events['id'], 'business_id' => (int)$update_events['business_id']];
- $update_data = ['next_id' => $update_events['next_id'], 'updated_by' => $update_events['updated_by']];
- $model->updateData('invoice_number_formatting', $update_data, $update_where);
- }
- }
-
- ## To insert or update invoice item details based on invoice ID
- public function save_invoice_item($id, $requestData)
- {
-
- ## Get Invoice item details (to checking purpose exist or not based on invoice ID)
- $getInvoiceItemDetails = $this->get_invoice_item($id);
-
- ## Declaration
- $statement = "";
- $model = new InvoiceModel();
- $itemid = $requestData['invoice_child_id'];
-
- ## IF Any Missing value Means that values are Inactive here....
- if (!empty($itemid)) {
- $filteringInvoiceItemIds = [];
- for ($y = 0; $y < count($getInvoiceItemDetails); $y++) {
- $filteringInvoiceItemIds[$y] = $getInvoiceItemDetails[$y]['invoice_child_id'];
- }
-
- if (!empty($filteringInvoiceItemIds)) {
- $A = $filteringInvoiceItemIds;
- $B = $itemid;
- $missingValues = array_diff($A, $B);
-
- if (!empty($missingValues)) {
- $where = ['isactive' => 1, 'receipt_id' => (int)$id];
- $model->inactiveMissingInvoiceItemDetails($where, $missingValues);
- }
- }
- }
- // echo "
....................";
- $count = count($itemid);
- $invoiceitem_arr = [];
- if ($count > 0) {
- for ($x = 0; $x < $count; $x++) {
- if(!empty($requestData['item_details'][$x])){
- $invoiceitem_arr[$x]['receipt_id'] = $id;
- $invoiceitem_arr[$x]['product'] = (int)$requestData['item_details'][$x];
- $invoiceitem_arr[$x]['quantity'] = (int)$requestData['quantity'][$x];
- $invoiceitem_arr[$x]['tax'] = (int)$requestData['tax'][$x];
- $invoiceitem_arr[$x]['unit_price'] = (int)$requestData['rate'][$x];
- $invoiceitem_arr[$x]['subtotal'] = (int)$requestData['amount'][$x];
- $invoiceitem_arr[$x]['discount_amount'] = (int)$requestData['discount_amount'][$x];
- $invoiceitem_arr[$x]['discount_type'] =$requestData['discount_type'][$x];
- if (!empty($requestData['from_subscription'])) {
- $invoiceitem_arr[0]['from_subscription'] = $requestData['from_subscription'];
- }
-
- if (!empty($requestData['to_subscription'])) {
- $invoiceitem_arr[0]['to_subscription'] = $requestData['to_subscription'];
- }
- $invoiceitem_arr[$x]['created_by'] = (int)get_logged_user_id();
- $invoiceitem_arr[$x]['updated_by'] = (int)get_logged_user_id();
- $invoiceitem_arr[$x]['isactive'] = 1;
- $invoiceitem_arr[$x]['invoice_child_id'] = $itemid[$x];
- }
- }
- $statement = $model->saveInvoiceItemDetails($invoiceitem_arr);
- }
- return $statement;
- }
-
- ## To Retrive Invoice item details based on invoice ID
- public function get_invoice_item($id)
- {
- $model = new InvoiceModel();
- $model->setTable('invoiceitems');
- $where = ['isactive' => 1, 'receipt_id' => (int)$id];
- $details = $model->where($where)->findAll();
- return $details;
- }
-
- ## To Inactive Invoice details based on invoice ID Including Invoice Item Details also
- public function delete_invoice($id)
- {
- helper('session');
- $session_uid = get_logged_user_id();
- try {
- $model = new InvoiceModel();
- $where = ['isactive' => 1, 'business_id' => (int)get_business_id(), 'receipt_id' => (int)$id];
- $existed = $model->where($where)->findAll();
- $this->logger->Info("Invoice : Going to Inactive ID = " . $id);
-
- if ($existed) {
- $data['isactive'] = 0;
- $data['updated_by'] = get_logged_user_id();
-
- if ($model->update($id, $data)) {
- session()->setFlashdata('success', 'Deleted successfully.');
- $this->logger->info("Invoice: has been Inactived successfully. Inactived ID = " . $id);
- } else {
- $this->logger->error("Invoice: Not able to Inactive ID =" . $id);
- throw new \Exception("Data Not able to Deleted");
- }
- $getInvoiceItemDetails = $this->get_invoice_item($id);
- if ($getInvoiceItemDetails) {
- $update_where = ['receipt_id' => (int)$id];
- $model->updateData('invoiceitems', $data, $update_where);
- }
- } else {
- $this->logger->error("Invoice: Does Not Exist To Inactive, ID = " . $id);
- throw new \Exception("Invoice Already Deleted");
- }
- } catch (\Exception $e) {
- $this->logger->error("Invoice: Err Occur = " . $e->getMessage());
- session()->setFlashdata('error', 'Message: ' . $e->getMessage());
- }
- return redirect()->route('receipt_list');
- }
-
- ## To Approve Invoice details based on invoice ID
- public function approve_invoice($id)
- {
-
- try {
- if (!$id) {
- throw new \Exception("Invoice can't able to Approved. Because ID can't Found");
- }
- $model = new InvoiceModel();
- helper('session');
- $where = ['isactive' => 1, 'status' => 'Approved', 'receipt_id' => (int)$id];
- $details = $model->where($where)->findAll();
- if (empty($details)) { // Array Empty Means allow to Approve.
- $data = ['status' => 'Approved', 'updated_by' => get_logged_user_id()];
- if ($model->update($id, $data)) {
- $this->approve_notifications((int)$id);
- session()->setFlashdata('success', 'Invoice has been Approved Successfully.');
- $this->logger->info("Invoice: has been Approved successfully. ID = " . $id);
- } else {
- $this->logger->error("Invoice: Does Not Exist To Approved");
- throw new \Exception("Invoice can't Approved");
- }
- } else {
- $this->logger->error("Invoice: already Approved ID = " . $id);
- throw new \Exception("Invoice already Approved");
- }
- } catch (\Exception $e) {
- $this->logger->error("Invoice: Err Occur = " . $e->getMessage());
- session()->setFlashdata('error', 'Message: ' . $e->getMessage());
- }
- // Redirect back to the invoice list
- return redirect()->route('receipt_list');
- }
-
- public function approve_notifications($receipt_id)
- {
- $model = new InvoiceModel();
- $where = ['I.business_id' => (int)get_business_id(), 'I.receipt_id' => $receipt_id, 'I.isactive' => 1];
- $details = $model->getDetailForApproveNotifications($where);
- $records = [];
- $reference_number = "";
- $invoice_serial_number = "";
- $recipient_name = "";
- $approval_date = "";
- $approved_by = "";
- $recipient_email = "";
- $recipient_mobile = "";
- $subtotal = "";
- $tax = "";
- $total_amount = "";
- $payment_method = "";
- $business_name= "";
- $business_address= "";
- $business_city= "";
- $business_state= "";
- $business_postal_code= "";
- $business_email= "";
- $business_mobile_no= "";
- if (isset($details)) {
- $this->logger->info("Invoice: approve notification Request data type = ".gettype($details));
- }
- helper('notification');
- $notification = new NotificationHelper();
- foreach ($details['invoice'] as $rec) {
- $reference_number = $rec['order_number'];
- $invoice_serial_number = $rec['invoice_number'];
- $recipient_name = $rec['customer_name'];
- $approval_date = $rec['updated_on'];
- $approved_by = $rec['updated_by_name'];
- $recipient_email = $rec['customer_email'];
- $recipient_mobile = $rec['customer_mobile'];
- $subtotal = $rec['subtotal'];
- $tax = $rec['tax'];
- $total_amount = $rec['total_amount'];
- $payment_method = $rec['payment_method'];
- $business_name= $rec['business_name'];
- $business_address= $rec['business_address'];
- $business_city= $rec['business_city'];
- $business_state= $rec['business_state'];
- $business_postal_code= $rec['business_postal_code'];
- $business_email= $rec['business_email'];
- $business_mobile_no= $rec['business_mobile_no'];
- }
- $records['invoice_order_number'] = $reference_number;
- $records['invoice_serial_number'] = $invoice_serial_number;
- $records['recipient_name'] = $recipient_name;
- $records['recipient_email'] = $recipient_email ? $recipient_email : "sanjeev.p@venbainfotech.com";
- $records['subtotal'] = $subtotal;
- $records['tax'] = $tax;
- $records['total_amount'] = $total_amount;
- $records['payment_method'] = $payment_method;
- $records['favicon'] = base_url("public/uploads/default.ico");
- $records['browser_title'] = "bbb-bp | Approve Template";
- $records['page_name'] = 'Approve Template';
- // view('approve_template',$records);
- // $this->logger->info("Approve : Request data = ".json_encode($records));
- // view('approve_template',$records);
-
- $records['template_name'] = 'approve_template';
- $records['item'] = $details['item'];
- $records['subject'] = $invoice_serial_number . " - Approval Notification";
-
- $records['description'] = "VBP Approve Information
- Dear $recipient_name,
- We are pleased to inform you that your Invoice has been approved.
- Details:
- Best regards,
-';
+ // print_r($data); die;
+
+ $this->logger->info("Invoice: Listing Count ." . count($data['receipt']));
+ $this->render_page('invoice_list', $data);
+ } else {
+ return redirect()->to('login');
+ }
+ }
+
+ ## To Load Invoice ADD/EDIT page...
+ public function new_receipt($id = '0')
+ {
+ helper('session');
+ $model = new InvoiceModel();
+ $where = ['business_id' => (int)get_business_id()];
+
+ // Get customer names for the dropdown, events details, and books details
+ $data['customers'] = $model->getData('customers', $where);
+ $data['causes'] = $model->getData('causes', $where);
+ $data['invoice_number_formatting'] = $model->getData('invoice_number_formatting', $where);
+
+ if ($id === '0') {
+ $this->logger->info("Receipt: In Add Details");
+ $data['page_name'] = 'Add Receipt Details';
+ $data['receipt_details'] = [];
+ } elseif ($id !== '0') {
+ $this->logger->info(" Book Invoice: In Edit Details ID = " . $id);
+ $data['page_name'] = 'Edit Receipt Details';
+ $data['receipt_details'] = $model->where(['receipt_id' => $id, 'isactive' => 1])->first();
+ }
+
+ // echo '';
+ // print_r($data['invoice_number_formatting']);die;
+ $this->render_page('invoice_form', $data);
+ }
+
+
+ ## For Ajax Call To Fetch/Retrive All Address Details Based On Customer...
+ public function load_details1()
+ {
+ $id = $this->request->getPost('selectedValue');
+ $where = ['customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$id];
+ $where['address_type'] = 1;
+ $data['customer_billing'] = $this->get_customer_address($where, []);
+ $select = ["customer_address_id", "CONCAT(address_1,' ',address_2) as address"];
+ $where['address_type'] = 2;
+ $data['customer_shipping'] = $this->get_customer_address($where, $select);
+ $data['customer_membership'] = $this->get_customer_membership("membership",(int)$id);
+ return $this->response->setJSON(['data' => $data]);
+ }
+
+ ## For Ajax Call To Fetch/Retrive Shipping Address Details Only Based On Customer...
+ public function load_details2()
+ {
+ $customer_id = $this->request->getPost('customerValue');
+ $address_id = $this->request->getPost('selectedValue');
+ $where = ['customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$customer_id, 'address_type' => 2, 'customer_address_id' => (int)$address_id];
+ $data['customer_shipping'] = $this->get_customer_address($where, []);
+ return $this->response->setJSON(['data' => $data]);
+ }
+ // public function generate_serial_no(){}
+
+ ## For Gethering Address Details...
+ public function get_customer_address($where, $select)
+ {
+ $model = new CustomerModel();
+ $model->setTable('customer_addresses');
+ if (empty($select)) {
+ $select = ["customer_addresses.customer_id","customer_addresses.customer_address_id","customer_addresses.first_name","customer_addresses.last_name ","customer_addresses.company","customer_addresses.email","customer_addresses.mobile_no","customer_addresses.address_type","customer_addresses.address_1","customer_addresses.address_2","customer_addresses.city","customer_addresses.state","customer_addresses.postal_code","customer_addresses.country","states.state_name","countries.country_name"];
+ }
+ $address_details = $model->select($select)->join('states', 'states.state_short_name = customer_addresses.state AND customer_addresses.country = "IN"', 'left')->join('countries', 'countries.country_short_name = customer_addresses.country', 'left')->where($where)->findAll();
+ return $address_details;
+ }
+
+ public function get_customer_membership($category,$id){
+ $model = new InvoiceModel();
+ $result = $model->getMembershipListForCustomer($category,$id);
+ return $result;
+ }
+
+ ## To insert or update the details of the invoice
+ public function save_invoice()
+ {
+ $this->logger->info("Invoice: Insert/Update Details");
+ try {
+
+ ## Declarions
+ helper('session');
+ $model = new InvoiceModel();
+
+ $receipt_date = $this->request->getVar('receipt_date');
+
+ $receipt_id = (!empty($this->request->getPost('receipt_id'))) ? $this->request->getPost('receipt_id') : "";
+ $customer_id = (int)$this->request->getPost('doner_id');
+
+ $data = [
+ 'receipt_number' => $this->request->getPost('receipt_number'),
+ 'doner_id' => $customer_id,
+ 'notes'=>$this->request->getPost('notes'),
+ 'receipt_date' => (!empty($receipt_date)) ? date("Y-m-d", strtotime($receipt_date)) : NULL,
+ 'amount' => (int)$this->request->getPost('amount'),
+ 'payment_mode' => $this->request->getPost('payment_mode'),
+ 'payment_ref_no' => $this->request->getPost('payment_ref_no'),
+ 'causes_id' => (int)$this->request->getPost('causes_id'),
+ 'business_id' => (int)get_business_id(),
+ 'isactive' => 1
+ ];
+ ## Based on the invoice ID, we designated Insert or Update on Details...
+ if (empty($receipt_id)) {
+ $data['created_by'] = (int)get_logged_user_id();
+ if ($model->insert($data, 'invoices')) {
+ $receipt_id = $model->insertID();
+ session()->setFlashdata('success', 'Receipt has been added successfully.');
+ $this->logger->info("Receipt: has been added successfully. Inserted ID = " . $receipt_id);
+
+ } else {
+ session()->setFlashdata('error', 'Receipt could not be added. Please try again.');
+ $this->logger->error("Receipt: Err Occur could not be added. Please try again.");
+ }
+
+ } else {
+ $data['updated_by'] = (int)get_logged_user_id();
+ if ($model->update($receipt_id, $data)) {
+ session()->setFlashdata('success', 'Receipt has been updated successfully.');
+ $this->logger->info("Receipt: has been updated successfully. Updated ID = " . $receipt_id);
+ } else {
+ session()->setFlashdata('error', 'Receipt update failed. Please try again.');
+ $this->logger->error("Receipt: Err Failed to update ID =" . $receipt_id);
+ }
+ }
+
+ if($this->request->getPost('next_id')){
+ ## Array Formation For Events Details And Updating Events also Here..
+ $update_events = [
+ 'id' => 1,
+ 'next_id' => (int)$this->request->getPost('next_id'),
+ 'business_id' => (int)get_business_id(),
+ 'updated_by' => get_logged_user_id()
+ ];
+ $this->update_number_formatting($update_events);}
+
+
+ } catch (\Exception $e) {
+ $this->logger->error("Receipt: Err Occur =" . $e->getMessage());
+ session()->setFlashdata('error', 'Message: ' . $e->getMessage());
+ }
+ return redirect()->route('receipt_list');
+
+
+
+
+ }
+
+ ## For Updating Events Details ..
+ public function update_number_formatting($update_events)
+ {
+ // `id``event_name``business_id``updated_by``updated_on``next_id`
+ $model = new InvoiceModel();
+ $model->setTable('invoice_number_formatting');
+ $where = ['isactive' => 1, 'id' => (int)$update_events['id'], 'business_id' => (int)$update_events['business_id'], 'next_id' => $update_events['next_id']];
+ $details = $model->where($where)->findAll();
+ if (empty($details)) {
+ $update_where = ['id' => (int)$update_events['id'], 'business_id' => (int)$update_events['business_id']];
+ $update_data = ['next_id' => $update_events['next_id'], 'updated_by' => $update_events['updated_by']];
+ $model->updateData('invoice_number_formatting', $update_data, $update_where);
+ }
+ }
+
+ ## To insert or update invoice item details based on invoice ID
+ public function save_invoice_item($id, $requestData)
+ {
+
+ ## Get Invoice item details (to checking purpose exist or not based on invoice ID)
+ $getInvoiceItemDetails = $this->get_invoice_item($id);
+
+ ## Declaration
+ $statement = "";
+ $model = new InvoiceModel();
+ $itemid = $requestData['invoice_child_id'];
+
+ ## IF Any Missing value Means that values are Inactive here....
+ if (!empty($itemid)) {
+ $filteringInvoiceItemIds = [];
+ for ($y = 0; $y < count($getInvoiceItemDetails); $y++) {
+ $filteringInvoiceItemIds[$y] = $getInvoiceItemDetails[$y]['invoice_child_id'];
+ }
+
+ if (!empty($filteringInvoiceItemIds)) {
+ $A = $filteringInvoiceItemIds;
+ $B = $itemid;
+ $missingValues = array_diff($A, $B);
+
+ if (!empty($missingValues)) {
+ $where = ['isactive' => 1, 'receipt_id' => (int)$id];
+ $model->inactiveMissingInvoiceItemDetails($where, $missingValues);
+ }
+ }
+ }
+ // echo "
....................";
+ $count = count($itemid);
+ $invoiceitem_arr = [];
+ if ($count > 0) {
+ for ($x = 0; $x < $count; $x++) {
+ if(!empty($requestData['item_details'][$x])){
+ $invoiceitem_arr[$x]['receipt_id'] = $id;
+ $invoiceitem_arr[$x]['product'] = (int)$requestData['item_details'][$x];
+ $invoiceitem_arr[$x]['quantity'] = (int)$requestData['quantity'][$x];
+ $invoiceitem_arr[$x]['tax'] = (int)$requestData['tax'][$x];
+ $invoiceitem_arr[$x]['unit_price'] = (int)$requestData['rate'][$x];
+ $invoiceitem_arr[$x]['subtotal'] = (int)$requestData['amount'][$x];
+ $invoiceitem_arr[$x]['discount_amount'] = (int)$requestData['discount_amount'][$x];
+ $invoiceitem_arr[$x]['discount_type'] =$requestData['discount_type'][$x];
+ if (!empty($requestData['from_subscription'])) {
+ $invoiceitem_arr[0]['from_subscription'] = $requestData['from_subscription'];
+ }
+
+ if (!empty($requestData['to_subscription'])) {
+ $invoiceitem_arr[0]['to_subscription'] = $requestData['to_subscription'];
+ }
+ $invoiceitem_arr[$x]['created_by'] = (int)get_logged_user_id();
+ $invoiceitem_arr[$x]['updated_by'] = (int)get_logged_user_id();
+ $invoiceitem_arr[$x]['isactive'] = 1;
+ $invoiceitem_arr[$x]['invoice_child_id'] = $itemid[$x];
+ }
+ }
+ $statement = $model->saveInvoiceItemDetails($invoiceitem_arr);
+ }
+ return $statement;
+ }
+
+ ## To Retrive Invoice item details based on invoice ID
+ public function get_invoice_item($id)
+ {
+ $model = new InvoiceModel();
+ $model->setTable('invoiceitems');
+ $where = ['isactive' => 1, 'receipt_id' => (int)$id];
+ $details = $model->where($where)->findAll();
+ return $details;
+ }
+
+ ## To Inactive Invoice details based on invoice ID Including Invoice Item Details also
+ public function delete_invoice($id)
+ {
+ helper('session');
+ $session_uid = get_logged_user_id();
+ try {
+ $model = new InvoiceModel();
+ $where = ['isactive' => 1, 'business_id' => (int)get_business_id(), 'receipt_id' => (int)$id];
+ $existed = $model->where($where)->findAll();
+ $this->logger->Info("Invoice : Going to Inactive ID = " . $id);
+
+ if ($existed) {
+ $data['isactive'] = 0;
+ $data['updated_by'] = get_logged_user_id();
+
+ if ($model->update($id, $data)) {
+ session()->setFlashdata('success', 'Deleted successfully.');
+ $this->logger->info("Invoice: has been Inactived successfully. Inactived ID = " . $id);
+ } else {
+ $this->logger->error("Invoice: Not able to Inactive ID =" . $id);
+ throw new \Exception("Data Not able to Deleted");
+ }
+ $getInvoiceItemDetails = $this->get_invoice_item($id);
+ if ($getInvoiceItemDetails) {
+ $update_where = ['receipt_id' => (int)$id];
+ $model->updateData('invoiceitems', $data, $update_where);
+ }
+ } else {
+ $this->logger->error("Invoice: Does Not Exist To Inactive, ID = " . $id);
+ throw new \Exception("Invoice Already Deleted");
+ }
+ } catch (\Exception $e) {
+ $this->logger->error("Invoice: Err Occur = " . $e->getMessage());
+ session()->setFlashdata('error', 'Message: ' . $e->getMessage());
+ }
+ return redirect()->route('receipt_list');
+ }
+
+ ## To Approve Invoice details based on invoice ID
+ public function approve_invoice($id)
+ {
+
+ try {
+ if (!$id) {
+ throw new \Exception("Invoice can't able to Approved. Because ID can't Found");
+ }
+ $model = new InvoiceModel();
+ helper('session');
+ $where = ['isactive' => 1, 'status' => 'Approved', 'receipt_id' => (int)$id];
+ $details = $model->where($where)->findAll();
+ if (empty($details)) { // Array Empty Means allow to Approve.
+ $data = ['status' => 'Approved', 'updated_by' => get_logged_user_id()];
+ if ($model->update($id, $data)) {
+ $this->approve_notifications((int)$id);
+ session()->setFlashdata('success', 'Invoice has been Approved Successfully.');
+ $this->logger->info("Invoice: has been Approved successfully. ID = " . $id);
+ } else {
+ $this->logger->error("Invoice: Does Not Exist To Approved");
+ throw new \Exception("Invoice can't Approved");
+ }
+ } else {
+ $this->logger->error("Invoice: already Approved ID = " . $id);
+ throw new \Exception("Invoice already Approved");
+ }
+ } catch (\Exception $e) {
+ $this->logger->error("Invoice: Err Occur = " . $e->getMessage());
+ session()->setFlashdata('error', 'Message: ' . $e->getMessage());
+ }
+ // Redirect back to the invoice list
+ return redirect()->route('receipt_list');
+ }
+
+ public function approve_notifications($receipt_id)
+ {
+ $model = new InvoiceModel();
+ $where = ['I.business_id' => (int)get_business_id(), 'I.receipt_id' => $receipt_id, 'I.isactive' => 1];
+ $details = $model->getDetailForApproveNotifications($where);
+ $records = [];
+ $reference_number = "";
+ $invoice_serial_number = "";
+ $recipient_name = "";
+ $approval_date = "";
+ $approved_by = "";
+ $recipient_email = "";
+ $recipient_mobile = "";
+ $subtotal = "";
+ $tax = "";
+ $total_amount = "";
+ $payment_method = "";
+ $business_name= "";
+ $business_address= "";
+ $business_city= "";
+ $business_state= "";
+ $business_postal_code= "";
+ $business_email= "";
+ $business_mobile_no= "";
+ if (isset($details)) {
+ $this->logger->info("Invoice: approve notification Request data type = ".gettype($details));
+ }
+ helper('notification');
+ $notification = new NotificationHelper();
+ foreach ($details['invoice'] as $rec) {
+ $reference_number = $rec['order_number'];
+ $invoice_serial_number = $rec['invoice_number'];
+ $recipient_name = $rec['customer_name'];
+ $approval_date = $rec['updated_on'];
+ $approved_by = $rec['updated_by_name'];
+ $recipient_email = $rec['customer_email'];
+ $recipient_mobile = $rec['customer_mobile'];
+ $subtotal = $rec['subtotal'];
+ $tax = $rec['tax'];
+ $total_amount = $rec['total_amount'];
+ $payment_method = $rec['payment_method'];
+ $business_name= $rec['business_name'];
+ $business_address= $rec['business_address'];
+ $business_city= $rec['business_city'];
+ $business_state= $rec['business_state'];
+ $business_postal_code= $rec['business_postal_code'];
+ $business_email= $rec['business_email'];
+ $business_mobile_no= $rec['business_mobile_no'];
+ }
+ $records['invoice_order_number'] = $reference_number;
+ $records['invoice_serial_number'] = $invoice_serial_number;
+ $records['recipient_name'] = $recipient_name;
+ $records['recipient_email'] = $recipient_email ? $recipient_email : "sanjeev.p@venbainfotech.com";
+ $records['subtotal'] = $subtotal;
+ $records['tax'] = $tax;
+ $records['total_amount'] = $total_amount;
+ $records['payment_method'] = $payment_method;
+ $records['favicon'] = base_url("public/uploads/default.ico");
+ $records['browser_title'] = "bbb-bp | Approve Template";
+ $records['page_name'] = 'Approve Template';
+ // view('approve_template',$records);
+ // $this->logger->info("Approve : Request data = ".json_encode($records));
+ // view('approve_template',$records);
+
+ $records['template_name'] = 'approve_template';
+ $records['item'] = $details['item'];
+ $records['subject'] = $invoice_serial_number . " - Approval Notification";
+
+ $records['description'] = "VBP Approve Information
+ Dear $recipient_name,
+ We are pleased to inform you that your Invoice has been approved.
+ Details:
+ Best regards,
+';
+ // print_r($data); die;
$this->render_page('user_list', $data);
}
diff --git a/app/Models/CustomerModel.php b/app/Models/CustomerModel.php
index d7924be..4cc7809 100644
--- a/app/Models/CustomerModel.php
+++ b/app/Models/CustomerModel.php
@@ -146,13 +146,14 @@ public function saveGroupDetails($data){
return $statement;
}
-public function getGroupDetails()
+public function getGroupDetails($business_id)
{
return $this->db->table('customer_groups as CG' )
->join('users as U1', 'U1.user_id = CG.created_by', 'left')
->join('users as U2', 'U2.user_id = CG.updated_by', 'left')
->select('CG.group_id,CG.group_name,CG.created_on,CG.created_by,CG.updated_on,CG.updated_by,DATE_FORMAT(CG.created_on, "%d/%m/%Y %h:%i %p") AS formatted_created_on,concat(U1.first_name," ",U1.last_name) as created_by_name,concat(U2.first_name," ",U2.last_name) as updated_by_name,CG.isactive')
->where(['CG.group_name != ' => 'EXPIRYDATE'])
+->where('CG.business_id', $business_id)
// ->where(['CG.isactive' => 1])
->get()
->getResultArray();
diff --git a/app/Models/HomeModel.php b/app/Models/HomeModel.php
index e18b97b..6893a5f 100644
--- a/app/Models/HomeModel.php
+++ b/app/Models/HomeModel.php
@@ -5,6 +5,7 @@ class HomeModel extends Model
{
public function customers($where) {
+
$query = $this->db->table('customers');
$totalCustomers = $query->where($where)->countAll();
diff --git a/app/Views/auth_login.php b/app/Views/auth_login.php
index 9a45727..96e8be7 100644
--- a/app/Views/auth_login.php
+++ b/app/Views/auth_login.php
@@ -3,7 +3,7 @@
- BigBambooBookPublish | BBBP
+ BigBamboo Donation
@@ -46,7 +46,7 @@
- Enter your email address and password to access admin panel.
+ Enter your email address and password.