diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 18c725a..08ab34b 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -49,7 +49,7 @@ $routes->get('dashboard/', 'Home::index'); # Users Routes $routes->get("user_list/", "Users::index"); -$routes->get("user_page/(:any)", "Users::user_page/$1"); +$routes->get("user_page/(:any)/(:any)", "Users::user_page/$1/$2"); $routes->post("insert_users", "Users::insert_users"); $routes->get("delete_user/(:any)", "Users::delete_user/$1"); $routes->get("activateUser/(:any)", "Users::activateUser/$1"); @@ -70,7 +70,7 @@ $routes->get("delete_sitesetting/(:any)", "Books::delete_sitesetting/$1"); # App Site-Setting Routes(SuperAdmin) // $routes->get("appsetting/", "AppSettings::index"); -$routes->get("appsetting_page/(:any)", "AppSettings::appsetting_page/$1"); +$routes->get("appsetting_page", "AppSettings::appsetting_page"); $routes->post("appsetting_synchronization", "AppSettings::appsetting_synchronization"); // $routes->get("delete_sitesetting/(:any)", "Books::delete_sitesetting/$1"); @@ -88,14 +88,15 @@ $routes->get('Customer/getReceiptDetails/(:num)', 'Customer::getReceiptDetails/$ $routes->post("insert_donor", "Customer::insert_donor"); +$routes->post("insert_ajaxdonor", "Customer::insert_ajaxdonor"); $routes->get("delete_donor/(:any)", "Customer::delete_donor/$1"); -#Routes for donor group -$routes->get('donor_group/', 'Customer::donor_group'); -$routes->get('view_donor_group/(:any)', 'Customer::view_donor_group/$1'); -$routes->get('preview_donor_group/(:any)', 'Customer::preview_donor_group/$1'); -$routes->get('delete_donor_group/(:any)', 'Customer::delete_donor_group/$1'); -$routes->post("insert_donor_group", "Customer::insert_donor_group"); +#Routes for donor group (renamed as contributor group : 20/03/2024) +$routes->get('contributor_group/', 'Customer::donor_group'); +$routes->get('view_contributor_group/(:any)', 'Customer::view_donor_group/$1'); +$routes->get('preview_contributor_group/(:any)', 'Customer::preview_donor_group/$1'); +$routes->get('delete_contributor_group/(:any)', 'Customer::delete_donor_group/$1'); +$routes->post("insert_contributor_group", "Customer::insert_donor_group"); @@ -124,10 +125,8 @@ $routes->get('generate-pdf/(:num)', 'Invoice::generatePdf/$1'); $routes->get('Invoice/showInvoiceModal', 'Invoice::showInvoiceModal'); -$routes->post("load_details1/", "Invoice::load_details1/"); -$routes->post("load_details2/", "Invoice::load_details2/"); +$routes->post("get_donor_details", "Invoice::get_donor_details"); $routes->post("save_invoice/", "Invoice::save_invoice/"); -$routes->get("delete_invoice/(:any)", "Invoice::delete_invoice/$1"); $routes->add('approve_invoice/(:num)', 'Invoice::approve_invoice/$1'); $routes->get('generate_invoice_pdf/(:num)', 'Invoice::generate_invoice_pdf/$1'); $routes->get('print_address/(:num)', 'Invoice::print_address/$1'); diff --git a/app/Controllers/Business.php b/app/Controllers/Business.php index 13e3e1c..9083c10 100644 --- a/app/Controllers/Business.php +++ b/app/Controllers/Business.php @@ -3,7 +3,6 @@ namespace App\Controllers; use App\Models\BusinessModel; -use App\Models\SettingsModel; class Business extends BaseController { @@ -32,7 +31,7 @@ class Business extends BaseController } } - ## To Load Business Form (Add/Update) + ## For Organization Form (Add/Update) public function new_org($id) { helper('session'); @@ -46,44 +45,29 @@ class Business extends BaseController $data['businesses'] = []; $data['branches'] = []; $data['donation']=[]; - // ----------- - $data['details'] = []; } else if ($id !== '0') { $data['page_name'] = 'Edit Organization'; $data['loged_user'] = $session_role; $model = new BusinessModel(); $model->setTable('business'); - // Fetch business details - $edit_user_details = $model->where(['business_id ' => $id])->first(); - $data['businesses'] = $edit_user_details; + ## Fetch business details (particular business) + $edit_business_details = $model->where(['business_id ' => $id , 'isactive' => 1])->first(); + $data['businesses'] = $edit_business_details; + + ## Fetch branch details + $branch_details = $model->getBranchesByBusinessId($id); + $data['branches'] = $branch_details; + + ## Fetch donation details if ($session_role !== 'sadmin') { - - $donationaccepted=$model->getDonationBusinessData($id); - $data['donation']=$donationaccepted; - // dd($data['donation']);die; + $donation_accepted=$model->getDonationBusinessData($id); + $data['donation']=$donation_accepted; } - // Fetch branch details - $branchData = $model->getBranchesByBusinessId($id); - - $data['branches'] = $branchData; - // ============================ - $smodel = new SettingsModel(); - $smodel->setTable('settings'); - if($session_role === 'sadmin'){ - - $details = $smodel->where(['setting_id' => $id, 'isactive' => 1])->first(); - } - else{ - $details = $smodel->where(['business_id' => $session_bid, 'isactive' => 1])->first(); - // print_r($session_bid);die; - } - // echo json_decode($details);die; - $data['details'] = $details; - // echo json_encode($data);die; - + } - $data['business_details']=$this->business_details(); + + $data['master_business_details']=$this->business_details(); $data['session_bid']=$session_bid; $this->render_page('business_form', $data); } @@ -109,233 +93,182 @@ class Business extends BaseController ## For inserting/updating details of business - public function insert_org() -{ - helper('session'); - $session_uid = get_logged_user_id(); - $session_role = get_user_role(); + public function insert_org() + { + helper('session'); + $session_uid = get_logged_user_id(); + $session_role = get_user_role(); - $img = $this->request->getFile('slogo'); - $filePath = 'public/uploads/' . $this->request->getPost('slogo'); - $fileName = $img->getName(); - - if ($fileName !== "") { - if ($img->isValid() && !$img->hasMoved()) { - $img->move(ROOTPATH . 'public/uploads', $fileName); + ## logo + $img = $this->request->getFile('business_logo'); + $filePath = 'public/uploads/' . $this->request->getPost('business_logo'); + $fileName = $img->getName(); + if ($fileName !== "") { + if ($img->isValid() && !$img->hasMoved()) { + $img->move(ROOTPATH . 'public/uploads', $fileName); + } } - } - $sign = $this->request->getFile('signature'); - $signFileName = $sign->getName(); - - if ($signFileName !== "") { - if ($sign->isValid() && !$sign->hasMoved()) { - $sign->move(ROOTPATH . 'public/uploads', $signFileName); + ## favicon + $favicon = $this->request->getFile('favicon'); + $faviconFileName = $favicon->getName(); + if ($faviconFileName !== "") { + if ($favicon->isValid() && !$favicon->hasMoved()) { + $favicon->move(ROOTPATH . 'public/uploads', $faviconFileName); + } } - } - $BusinessModel = new BusinessModel(); - $data = [ - 'title' => $this->request->getPost('bname'), - 'email' => $this->request->getPost('bmail'), - 'mobile_no' => $this->request->getPost('bmobile'), - 'address' => $this->request->getPost('baddress'), - 'city' => $this->request->getPost('bcity'), - 'state' => $this->request->getPost('bstate'), - 'postal_code' => $this->request->getPost('bzip'), - 'pan_no' => $this->request->getPost('pan_no'), - 'org_reg_no' => $this->request->getPost('org_reg_no'), - 'terms' => $this->request->getPost('bterms'), - '80G' => $this->request->getPost('80G'), - ]; + ## signature + $sign = $this->request->getFile('signature'); + $signFileName = $sign->getName(); + if ($signFileName !== "") { + if ($sign->isValid() && !$sign->hasMoved()) { + $sign->move(ROOTPATH . 'public/uploads', $signFileName); + } + } - if ($fileName !== "") { - $data['business_logo'] = $fileName; - } - if ($signFileName !== "") { - $data['signature'] = $signFileName; - } - - $business_id = $this->request->getPost('business_id'); // Get the business ID for update - - if (empty($business_id)) { - // It's an insert operation - $data['isactive'] = 1; - $data['created_by'] = $session_uid; - $businessId = $BusinessModel->insert($data); - $BusinessModel->insertDonationBusiness($businessId); - // $this->insert_branch($businessId); - } else { - // It's an update operation - if ($session_role === 'sadmin') { - - $data['isactive'] = 1; - - $data['updated_by'] = $session_uid; - $BusinessModel->update($business_id, $data); - $businessId = $business_id; - $selectedDonations = $this->request->getPost('name'); - $BusinessModel->updateDonationData($businessId, $selectedDonations); - - } -} - - // ... existing code ... - - if (!empty($_POST['branchname'])) { - $branchNames = $_POST['branchname']; - $branchMobile = $_POST['mobile_no']; - $branchMail = $_POST['email']; - $branchAddress = $_POST['branchaddress']; - $branchIds = isset($_POST['id']) ? $_POST['id'] : []; - - foreach ($branchNames as $key => $branchName) { - $branchId = isset($branchIds[$key]) ? $branchIds[$key] : null; - - $branchData = [ - 'business_id' => $businessId, - 'branch_name' => $branchName, - 'mobile_no' => $branchMobile[$key], - 'email' => $branchMail[$key], - 'address' => $branchAddress[$key], + ## Business Data + $BusinessModel = new BusinessModel(); + $data = [ + 'title' => $this->request->getPost('bname'), + 'email' => $this->request->getPost('bmail'), + 'mobile_no' => $this->request->getPost('bmobile'), + 'address' => $this->request->getPost('baddress'), + 'city' => $this->request->getPost('bcity'), + 'state' => $this->request->getPost('bstate'), + 'postal_code' => $this->request->getPost('bzip'), + 'pan_no' => $this->request->getPost('pan_no'), + 'org_reg_no' => $this->request->getPost('org_reg_no'), + 'terms' => $this->request->getPost('bterms'), + '80G' => $this->request->getPost('80G'), + 'site_name' => $this->request->getPost('site_name'), + 'site_title' => $this->request->getPost('site_title'), + 'admin_email' => $this->request->getPost('admin_email'), + 'site_mobile'=> $this->request->getPost('site_mobile'), + 'copyright'=> $this->request->getPost('copyright'), + 'currency'=> $this->request->getPost('currency'), + 'country'=> $this->request->getPost('country'), + 'start_no'=> $this->request->getPost('start_no'), + 'left_pad'=> $this->request->getPost('left_pad'), + 'prefix_format'=> $this->request->getPost('prefix_format'), ]; - if (!empty($branchId)) { - // Update the existing branch - $db = \Config\Database::connect(); - $db->table('business_branches') - ->where('id', $branchId) - ->update($branchData); + if ($fileName !== "") { + $data['business_logo'] = $fileName; + } + if ($faviconFileName !== "") { + $data['favicon'] = $faviconFileName; + } + if ($signFileName !== "") { + $data['signature'] = $signFileName; + } + + $business_id = $this->request->getPost('business_id'); // Get the business ID for update + + if (empty($business_id)) { + // It's an insert operation + $data['created_by'] = $session_uid; + $businessId = $BusinessModel->insert($data); } else { - // Insert new branch - $db = \Config\Database::connect(); - $db->table('business_branches')->insert($branchData); + // It's an update operation + $businessId = $business_id; + $data['updated_by'] = $session_uid; + $BusinessModel->update($business_id, $data); + } + + ## Donation Business Data (Note: not a super-admin means) + if ($session_role !== 'sadmin') { + if (empty($business_id)) { + $BusinessModel->insertDonationBusiness($businessId); + }else{ + $selectedDonations = $this->request->getPost('name'); + $BusinessModel->updateDonationData($businessId, $selectedDonations); + } + } + + ## Buiness Branch Data + if(!empty($_POST['branch_name'])){ + $requestData = $this->request->getPost(); + $bb_result = $this->save_business_branch($requestData, $businessId); + $this->logger->info("business branch: final message = " .implode(" ",$bb_result)); + } + + if ($session_role === 'sadmin') { + session()->setFlashdata('success', 'organization details has been updated successfully.'); + return redirect()->route('org_list'); + }else{ + session()->setFlashdata('success', 'organization details has been updated successfully.'); + return redirect()->to(base_url("new_org/{$business_id}")); } } -} -//SITE SETTINGS -helper('session'); -$session_bid = get_business_id(); -$session_uid = get_logged_user_id(); -$session_role = get_user_role(); + public function save_business_branch($requestData, $bid) + { + try { + + $getBuinessBranchdetails = $this->get_business_branch($bid); + + + $BBprimaryid = $requestData['id'] ; // Available Buiness Branch Primary IDS in Form Fields. + -$img = $this->request->getFile('slogo'); -// print_r($img); -$business_id = $this->request->getPost('business_id'); -$app_setting_id = $this->request->getPost('app_setting_id'); -$filePath = 'public/uploads/' . $this->request->getPost('slogo'); -$fileName = $img->getName(); -// var_dump($fileName); -// echo $fileName; -// echo $fileName !== "" && $fileName !== null ? "Yes":"No"; -// die(); + $model = new BusinessModel(); -if($fileName !== ""){ + ## IF Any Missing value Means that values are Inactive here.... + if(!empty($BBprimaryid)){ + $this->logger->info("BuinessBranch: Primary ID = ".implode(",",$BBprimaryid)); + $filteringIds = []; + for ($y = 0; $y < count($getBuinessBranchdetails); $y++) { + $filteringIds[$y] = $getBuinessBranchdetails[$y]['id']; + } - if ($img->isValid() && !$img->hasMoved()) { + + if (!empty($filteringIds)) { + $A = $filteringIds; + $B = $BBprimaryid; + $missingValues = array_diff($A, $B); + if (!empty($missingValues)) { + $where = ['isactive' => 1, 'business_id'=>$bid]; + $model->inactiveMissingBuinessBranchDetails($where, $missingValues); + echo + $this->logger->info("BuinessBranch: Inactived Missing Count = " . count($missingValues)." That Primary ID = ".implode(",",$BBprimaryid)); + } + } + } - $img->move(ROOTPATH . 'public/uploads', $fileName); + + $count = count($BBprimaryid); + + $branchData = []; + if ($count > 0) { + for ($x = 0; $x < $count; $x++) { + $branchData[$x]['id'] = $requestData['id'][$x]; + $branchData[$x]['branch_name'] = $requestData['branch_name'][$x]; + $branchData[$x]['business_id'] = $bid; + $branchData[$x]['email'] = $requestData['email'][$x]; + $branchData[$x]['mobile_no'] = $requestData['mobile_no'][$x]; + $branchData[$x]['address'] = $requestData['branchaddress'][$x]; + } + + $statement = !empty($branchData) ? $model->saveBuinessBranchDetails($branchData) : ["No data found For buisness branch"]; + $this->logger->info("BuinessBranch: Final message = " . implode(",",$statement)); + } + } catch (\Exception $e) { + $this->logger->error("BuinessBranch: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); + $statement = ['Message: ' . $e->getMessage()]; + } + return $statement; } - -} - -$favicon = $this->request->getFile('favicon'); -$faviconName = $favicon->getName(); - - if($faviconName !== ""){ - - if ($favicon->isValid() && !$favicon->hasMoved()) { - - $favicon->move(ROOTPATH . 'public/uploads', $faviconName); + public function get_business_branch($bid){ + $model = new BusinessModel(); + $model->setTable('business_branches'); + $where = ['business_id'=> (int)$bid , 'isactive' => 1]; + $details = $model->where($where)->findAll(); + return $details; } -} -$SettingsModel = new SettingsModel(); -$data = [ - - 'site_name' => $this->request->getPost('site_name'), - 'site_title' => $this->request->getPost('site_title'), - 'terms_service' => $this->request->getPost('terms_service'), - 'footer_about' => $this->request->getPost('footer_about'), - 'admin_email' => $this->request->getPost('admin_email'), - 'mobile'=> $this->request->getPost('mobile'), - 'copyright'=> $this->request->getPost('copyright'), - 'pagination_limit'=> $this->request->getPost('pagination_limit'), - 'site_info'=> $this->request->getPost('site_info'), - 'about_info'=> $this->request->getPost('about_info'), - 'mail_protocol'=> $this->request->getPost('mail_protocol'), - 'mail_title'=> $this->request->getPost('mail_title'), - 'mail_host'=> $this->request->getPost('mail_host'), - 'mail_port'=> $this->request->getPost('mail_port'), - 'mail_encryption'=> $this->request->getPost('mail_encryption'), - 'mail_username'=> $this->request->getPost('mail_username'), - 'mail_password'=> $this->request->getPost('mail_password'), - 'currency'=> $this->request->getPost('currency'), - 'country'=> $this->request->getPost('country'), - 'business_id'=> $this->request->getPost('business_id'), - 'start_no'=> $this->request->getPost('start_no'), - 'left_pad'=> $this->request->getPost('left_pad'), - 'prefix_format'=> $this->request->getPost('prefix_format'), -]; - -if($fileName !== "" && $fileName !== null) -{ - $data['logo'] = $fileName; -} - -if($faviconName !== "" && $faviconName !== null) -{ - $data['favicon'] = $faviconName; -} - -// echo '
';
-// print_r($data); die;
-
-$setting_id = $this->request->getPost('setting_id'); // Get the business ID for update
-
-if (empty($setting_id)) {
- // It's an insert operation
- $data['isactive'] = 1;
- $data['created_by'] = $session_uid;
-
- $SettingsModel->insert($data);
- // print_r($data);die;
-} else {
- // It's an update operation
- $isactive = $this->request->getPost('isactive');
- $data['isactive'] = ($isactive == 'on') ? 1 : 0;
- $data['updated_by'] = $session_uid;
- $SettingsModel->update($setting_id, $data);
-}
-
-
-// ... exis
- // ... existing code ...
-
- // Redirect based on user role
- // ... existing code ...
-
-// Redirect based on user role
-if ($session_role === 'sadmin') {
- return redirect()->route('org_list');
- }
-
-
-// Redirect based on user role
-if ($session_role !== 'sadmin') {
-
- session()->setFlashdata('success', 'User has been updated successfully.');
- // Assuming 'index' is the route name for your index page
- return redirect()->to(base_url("new_org/{$business_id}"));
-
-
-}
-
-}
-
- ## For delete the business details (Which means inactive the details)
+ ## For delete the business details (Which means inactive the details)
public function delete_org($id)
{
helper('session');
@@ -357,7 +290,8 @@ if ($session_role !== 'sadmin') {
}
public function insertDonationBusiness($businessId)
{
- $donationData = $this->db->table('donation_accepted')
+ $db = \Config\Database::connect();
+ $donationData = $db->table('donation_accepted')
->get()
->getResultArray();
@@ -368,7 +302,7 @@ if ($session_role !== 'sadmin') {
}
// Insert data into donation_business table
- $this->db->table('donation_business')->insertBatch($donationData);
+ $db->table('donation_business')->insertBatch($donationData);
}
}
}
diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php
index dc4b17b..cfc031d 100644
--- a/app/Controllers/Customer.php
+++ b/app/Controllers/Customer.php
@@ -69,7 +69,40 @@ class Customer extends BaseController
}
- ## For inserting/updating details of customer
+
+ public function insert_ajaxdonor(){
+
+ helper('session');
+ $model = new CustomerModel();
+
+ $session_uid = get_logged_user_id();
+ $session_bid = get_business_id();
+
+ $pan = ($this->request->getPost('pan_no') == '') ? $this->request->getPost('o_pan_no') : $this->request->getPost('pan_no');
+
+ $data = [
+ 'first_name' => $this->request->getPost('cfname'),
+ 'mobile_no' => $this->request->getPost('mobile'),
+ 'email' => $this->request->getPost('cmail'),
+ 'pan_no' => $pan,
+ 'donor_type' => $this->request->getPost('DonorType'),
+ 'org_name' => $this->request->getPost('org_name') !== '' || $this->request->getPost('org_name') !== null ? $this->request->getPost('org_name') : NULL,
+ 'org_reg_details'=> $this->request->getPost('org_reg_Details'),
+ 'business_id' => $session_bid,
+ 'isactive' => 1,
+ 'created_by' => $session_uid
+ ];
+
+ if ($model->insert($data)) {
+ $results = ['status' => true, 'message' => 'added successfully','donor_id' => $model->insertID()];
+ }else {
+ $results = ['status' => false, 'message' => 'could not be added','donor_id' => ''];
+ }
+
+ $donor_where = ['business_id' => (int)get_business_id() , 'isactive' => 1, 'donor_type'=>$this->request->getPost('DonorType')];
+ $results['donor'] = $model->getData('donor', $donor_where);
+ return $this->response->setJSON(['data' => $results]);
+ }
public function insert_donor()
{
$requestData = $this->request->getPost();
diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php
index 52e8074..164b65d 100644
--- a/app/Controllers/Invoice.php
+++ b/app/Controllers/Invoice.php
@@ -20,13 +20,15 @@ use Dompdf\Options;
class Invoice extends BaseController
{
+ protected $AuditHistoryModel;
+ protected $UserModel;
+ protected $BusinessModel;
+
public function __construct()
{
-
$this->AuditHistoryModel = new AuditHistoryModel();
$this->UserModel = new UsersModel();
- $this->Business_Model = new BusinessModel();
-
+ $this->BusinessModel = new BusinessModel();
}
## For Invoice Listing..
@@ -48,11 +50,6 @@ class Invoice extends BaseController
$data['receipt'][$key]['created_name'] = $this->UserModel->where('user_id', $value['created_by'])->get()->getRow()->first_name;
}
- // echo json_encode($data['receipt']);die;
-
- // echo '';
- // print_r($data); die;
-
$this->logger->info("Invoice: Listing Count ." . count($data['receipt']));
$this->render_page('invoice_list', $data);
} else {
@@ -116,20 +113,19 @@ class Invoice extends BaseController
}
}
- ## To Load Invoice ADD/EDIT page...
+ ## To Save/Update the Recepit Details
public function new_receipt($id = '0')
{
helper('session');
$model = new InvoiceModel();
$bmodel = new BooksModel();
- $setting_model = new SettingsModel();
+
$where = ['business_id' => (int)get_business_id() ];
- $cus_where = ['business_id' => (int)get_business_id() , 'isactive' => 1];
$rec_where = ['business_id' => (int)get_business_id(), 'YEAR(created_on)' => date('Y')];
$receipt = $model->getData('receipt', $rec_where);
// receipt number
- $settingData = $setting_model->select('*')->where($where)->findAll();
+ $settingData = $this->BusinessModel->select('*')->where($where)->findAll();
$count_receipt_no = (count($receipt) > 0) ? count($receipt) + $settingData[0]['start_no'] + 1 : $settingData[0]['start_no'] + 1;
// Calculate padding based on the count of digits in count_receipt_no
@@ -139,12 +135,12 @@ class Invoice extends BaseController
$data['count_receipt_no'] = $settingData[0]['prefix_format'] . $padding . $count_receipt_no;
// Get customer names for the dropdown, events details, and books details
- $data['currency'] = $setting_model->select('currency')->where($where)->findAll();
- $data['customers'] = $model->getData('donor', $cus_where);
+ $data['currency'] = $this->BusinessModel->select('currency')->where($where)->findAll();
+
$data['causes'] = $bmodel->select('*')->where('business_id', (int)get_business_id())->where('isactive',1)->get()->getResult();
$data['campaign'] = $model->getData('campaign', $where);
$data['invoice_number_formatting'] = $model->getData('settings', $where);
-
+ $data['receipt_type'] = "option1";
if ($id === '0') {
$this->logger->info("Receipt: In Add Details");
$data['page_name'] = 'Add Receipt Details';
@@ -160,8 +156,22 @@ class Invoice extends BaseController
{
$data['receipt_details'] = $model->where(['receipt_id' => $id, 'isactive' => 1])->first();
}
+ $get_receipt_type_where = [
+ 'business_id' => (int)get_business_id(),
+ 'isactive' => 1,
+ 'donor_id' => $data['receipt_details']['donor_id']
+ ];
+
+ $get_receipt_type = $model->getData('donor', $get_receipt_type_where);
+ if (!empty($get_receipt_type)) {
+ $firstItem = reset($get_receipt_type);
+ $data['receipt_type'] = $firstItem->donor_type;
+ }
}
-
+ $cus_where = ['business_id' => (int)get_business_id() , 'isactive' => 1, 'donor_type'=>$data['receipt_type']];
+ $data['typebaseddonors'] = $model->getData('donor', $cus_where);
+ $data['alldonors'] = $model->getData('donor', ['business_id' => (int)get_business_id() , 'isactive' => 1]);
+
$this->render_page('invoice_form', $data);
}
@@ -234,50 +244,6 @@ class Invoice extends BaseController
return redirect()->route('receipt_list');
}
-
- ## 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()
{
@@ -290,11 +256,12 @@ class Invoice extends BaseController
$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('donor_id');
+ $donor_id = (int)$this->request->getPost('donor_id');
$data = [
+ 'receipt_type' => $this->request->getPost('receipt_type'),
'receipt_number' => $this->request->getPost('receipt_number'),
- 'donor_id' => $customer_id,
+ 'donor_id' => $donor_id,
'campaign_id' => (int)$this->request->getPost('campaign_id'),
'notes'=>$this->request->getPost('notes'),
'receipt_date' => (!empty($receipt_date)) ? date("Y-m-d", strtotime($receipt_date)) : NULL,
@@ -395,8 +362,8 @@ class Invoice extends BaseController
$donormodel = new CustomerModel();
$template_data = $notificationModel->select('*')->where('template_id',7)->findAll();
$cause = $bmodel->select('name')->where('causes_id',(int)$this->request->getPost('causes_id'))->findAll();
- $d_name = $donormodel->select('first_name')->where('donor_id',$customer_id)->findAll();
- $business = $this->Business_Model->select('*')->where('business_id',(int)get_business_id())->findAll();
+ $d_name = $donormodel->select('first_name')->where('donor_id',$donor_id)->findAll();
+ $business = $this->BusinessModel->select('*')->where('business_id',(int)get_business_id())->findAll();
$donor_name = $d_name[0]['first_name'];
$currency_amount = $this->request->getPost('amount');
@@ -450,7 +417,6 @@ class Invoice extends BaseController
{
helper('session');
$model = new InvoiceModel();
- $usermodel = new UsersModel();
$where = ['business_id' => (int)get_business_id()];
$data = $model->getData('audit_history', $where);
// echo $data[0]->current_data;die;
@@ -466,7 +432,7 @@ class Invoice extends BaseController
foreach ($arr1[0] as $key => $value) {
$con = $key != 'created_on' && $key != 'created_by' && $key != 'updated_on' && $key != 'updated_by';
if ($audit_data->is_edit == 1 && $arr2[0][$key] !== $value) {
- $user = $usermodel->select('first_name,last_name')->where('user_id',$audit_data->updated_by)->findAll();
+ $user = $this->UserModel->select('first_name,last_name')->where('user_id',$audit_data->updated_by)->findAll();
if($con){
$temp_diff[] = (object) [
'id' => $audit_data->id,
@@ -482,7 +448,7 @@ class Invoice extends BaseController
}
else if($con && $audit_data->is_add == 1){
// echo $key;die;
- $user = $usermodel->select('first_name,last_name')->where('user_id',$audit_data->created_by)->findAll();
+ $user = $this->UserModel->select('first_name,last_name')->where('user_id',$audit_data->created_by)->findAll();
$temp_diff[] = (object) [
'id' => $audit_data->id,
'key' => '-',
@@ -497,7 +463,7 @@ class Invoice extends BaseController
}
else if($con && $audit_data->is_delete == 1){
// echo $key;die;
- $user = $usermodel->select('first_name,last_name')->where('user_id',$audit_data->updated_by)->findAll();
+ $user = $this->UserModel->select('first_name,last_name')->where('user_id',$audit_data->updated_by)->findAll();
$temp_diff[] = (object) [
'id' => $audit_data->id,
'key' => '-',
@@ -539,132 +505,21 @@ class Invoice extends BaseController
}
}
- ## 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');
- }
-
-
+
public function generate_invoice_pdf($id, $dest = null)
{
try {
// Fetch the receipt data based on $receipt_id
$model = new InvoiceModel();
- $usermodel = new UsersModel();
$setting_model = new SettingsModel();
- $business_model = new BusinessModel();
+
$where = ['business_id' => (int)get_business_id()];
$currency_data = $setting_model->select('currency')->where($where)->findAll();
- $terms_data = $business_model->select('terms,signature')->where($where)->findAll();
+ $terms_data = $this->BusinessModel->select('terms,signature')->where($where)->findAll();
$data = $model->getInvoiceData($id);
// Check if data is empty
if (!$data || !$currency_data) {
- throw new Exception('Data not found or empty');
+ throw new \Exception('Data not found or empty');
}
$options = new Options();
@@ -680,7 +535,7 @@ class Invoice extends BaseController
$dompdf = new Dompdf($options);
define("DOMPDF_UNICODE_ENABLED", true);
- $user = $usermodel->select('first_name')->where('user_id',$data[0]->created_by)->findAll();
+ $user = $this->UserModel->select('first_name')->where('user_id',$data[0]->created_by)->findAll();
$logoPath = base_url()."public/uploads/".$data[0]->business_logo;
if ($data[0]->business_logo && file_exists($logoPath)) {
@@ -689,11 +544,13 @@ class Invoice extends BaseController
// Logo does not exist, handle this case accordingly
$baseurl = base_url()."public/uploads/default.png";
}
+ $digits = strlen((string)$data[0]->amount);
+ $amount_in_words = $digits <= 9 ? $this->convertNumberToWords($data[0]->amount) : $data[0]->amount;
$html = view('invoice_pdf_template', [
'data' => $data[0],
'currency' => $data[0]->currency,
- 'currency_in_words' => $this->convertNumberToWords($data[0]->amount) ,
+ 'currency_in_words' => $amount_in_words ,
'baseurl' => $baseurl,
'signature' => $terms_data[0]['signature'],
'staff_name' => $user[0]['first_name'],
@@ -720,7 +577,7 @@ class Invoice extends BaseController
return $html;
}
$dompdf->stream('Receipt.pdf', ['Attachment' => 1]);
- } catch (Exception $e) {
+ } catch (\Exception $e) {
// Handle the exception
// For example, log the error, display a user-friendly message, or return an error response
echo 'Error: ' . $e->getMessage();
@@ -763,14 +620,28 @@ class Invoice extends BaseController
if ($number == 0) {
return $words[0];
}
-
+
$num = (int)$number;
$result = '';
+
+ // Handle numbers greater than 10 million (crores)
+ if ($num >= 10000000) {
+ $crores = floor($num / 10000000);
+ $result .= $this->convertNumberToWords($crores) . ' Crore ';
+ $num %= 10000000;
+ }
+
+ // Handle numbers between 1 million and 9 million (lakhs)
+ if ($num >= 100000) {
+ $lakhs = floor($num / 100000);
+ $result .= $this->convertNumberToWords($lakhs) . ' Lakh ';
+ $num %= 100000;
+ }
- // Handle numbers greater than 1000
+ // Handle numbers between 1000 and 99999
if ($num >= 1000) {
$thousands = floor($num / 1000);
- $result .= $words[$thousands] . ' Thousand ';
+ $result .= $this->convertNumberToWords($thousands) . ' Thousand ';
$num %= 1000;
}
@@ -796,196 +667,18 @@ class Invoice extends BaseController
return $result;
}
-
+ ## For Ajax Call To Retrive Donor Details Based On Donor type...
+ public function get_donor_details()
+ {
+ helper('session');
+ $model = new InvoiceModel();
+ $value = $this->request->getPost('donor_type');
+ //For Donor Name And Donor Mobile Number Dropdown..
+ $where = ['business_id' => (int)get_business_id() , 'donor_type'=>$value, 'isactive' => 1];
+ $data['donor_details'] = $model->getData('donor', $where);
+ return $this->response->setJSON(['data' => $data]);
+ }
- // 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,
- //