diff --git a/app/Config/Routes.php b/app/Config/Routes.php index fbe72b6..7d04808 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -83,6 +83,10 @@ $routes->get("delete_org/(:any)", "Business::delete_org/$1"); #Routes for Donor Routes $routes->get("Donor_list/", "Customer::index"); $routes->get("new_Donor/(:any)", "Customer::new_Donor/$1"); +$routes->get('Customer/getReceiptDetails/(:num)', 'Customer::getReceiptDetails/$1'); +// In your routes file (e.g., app/Config/Routes.php) + + $routes->post("insert_donor", "Customer::insert_donor"); $routes->get("delete_donor/(:any)", "Customer::delete_donor/$1"); @@ -115,6 +119,10 @@ $routes->post("donor_cash_delete/", "Invoice::donor_cash_delete"); $routes->get("donations_accepted/", "Invoice::donations_accepted"); $routes->post("save_donations_accepted/", "Invoice::save_donations_accepted"); $routes->get("audit_history", "Invoice::audit_history"); +$routes->get('generate-pdf/(:num)', 'Invoice::generatePdf/$1'); +// app/config/Routes.php + +$routes->get('Invoice/showInvoiceModal', 'Invoice::showInvoiceModal'); $routes->post("load_details1/", "Invoice::load_details1/"); $routes->post("load_details2/", "Invoice::load_details2/"); diff --git a/app/Controllers/Authentication.php b/app/Controllers/Authentication.php index 37ab968..b73c5a7 100644 --- a/app/Controllers/Authentication.php +++ b/app/Controllers/Authentication.php @@ -47,8 +47,8 @@ class Authentication extends BaseController $pwd_verify = password_verify((string)$password, $user['password']); if (!$pwd_verify) { - $this->logger->error('Invalid Password'); - return redirect()->back()->withInput()->with('error', 'Invalid Password.'); + $this->logger->error('Invalid Email or Password'); + return redirect()->back()->withInput()->with('error', 'Invalid Email or Password.'); } // You can implement your authentication logic here diff --git a/app/Controllers/Business.php b/app/Controllers/Business.php index a3363a4..076cd21 100644 --- a/app/Controllers/Business.php +++ b/app/Controllers/Business.php @@ -38,26 +38,34 @@ class Business extends BaseController helper('session'); $session_role = get_user_role(); $session_bid = get_business_id(); + $session_uid = get_logged_user_id(); if ($id === '0') { $data['page_name'] = 'Add Organization'; $data['loged_user'] = $session_role; $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; - + if ($session_role !== 'sadmin') { + + $donationaccepted=$model->getDonationBusinessData($id); + $data['donation']=$donationaccepted; + // dd($data['donation']);die; + } // Fetch branch details $branchData = $model->getBranchesByBusinessId($id); + $data['branches'] = $branchData; // ============================ $smodel = new SettingsModel(); @@ -76,7 +84,7 @@ class Business extends BaseController } $data['business_details']=$this->business_details(); - + $data['session_bid']=$session_bid; $this->render_page('business_form', $data); } @@ -107,8 +115,8 @@ class Business extends BaseController $session_uid = get_logged_user_id(); $session_role = get_user_role(); - $img = $this->request->getFile('bfile'); - $filePath = 'public/uploads/' . $this->request->getPost('bfile'); + $img = $this->request->getFile('slogo'); + $filePath = 'public/uploads/' . $this->request->getPost('slogo'); $fileName = $img->getName(); if ($fileName !== "") { @@ -155,6 +163,7 @@ class Business extends BaseController $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 @@ -165,8 +174,11 @@ class Business extends BaseController $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'])) { @@ -208,14 +220,14 @@ $session_uid = get_logged_user_id(); $session_role = get_user_role(); $img = $this->request->getFile('slogo'); -print_r($img); +// 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"; +// var_dump($fileName); +// echo $fileName; +// echo $fileName !== "" && $fileName !== null ? "Yes":"No"; // die(); if($fileName !== ""){ @@ -302,11 +314,22 @@ if (empty($setting_id)) { // ... existing code ... // Redirect based on user role - if ($session_role === 'sadmin') { + // ... existing code ... + +// Redirect based on user role +if ($session_role === 'sadmin') { + if (empty($business_id)) { + // Redirect to the organization list after inserting a new organization return redirect()->route('org_list'); - } else { - return redirect()->route('dashboard'); } +} else { + 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) @@ -329,4 +352,20 @@ if (empty($setting_id)) { return redirect()->route('org_list'); } + public function insertDonationBusiness($businessId) + { + $donationData = $this->db->table('donation_accepted') + ->get() + ->getResultArray(); + + if (!empty($donationData)) { + // Add business_id to each donation record + foreach ($donationData as &$donation) { + $donation['business_id'] = $businessId; + } + + // Insert data into donation_business table + $this->db->table('donation_business')->insertBatch($donationData); + } + } } diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php index c4964a2..dc77386 100644 --- a/app/Controllers/Customer.php +++ b/app/Controllers/Customer.php @@ -24,7 +24,7 @@ class Customer extends BaseController } $CustomerModel = new CustomerModel(); - $data['page_name'] = 'Donor Details'; + $data['page_name'] = 'Contributor Details'; $data['customer'] = $CustomerModel->where($where)->orderBy('donor_id', 'DESC')->findAll(); // echo '
';
@@ -44,13 +44,13 @@ class Customer extends BaseController
if ($id === '0') {
// Add Donor
- $data['page_name'] = 'Add Donor Details';
+ $data['page_name'] = 'Add Contributor Details';
$data['customer'] = [];
} else if ($id !== '0') {
// Edit Donor
- $data['page_name'] = 'Edit Donor Details';
+ $data['page_name'] = 'Edit Contributor Details';
$customerModel = new CustomerModel();
// Retrieve customer details by customer ID
@@ -129,7 +129,9 @@ class Customer extends BaseController
$data['isactive'] = ($isactive == 'on') ? 1 : 0;
}
$data['updated_by'] = $session_uid;
- $donor_id_for_addresses = $donor_id; // for Customer ADDRESS Table
+ $data['isactive'] = 1;
+ $donor_id_for_addresses = $donor_id;
+ // for Customer ADDRESS Table
if ($model->update($donor_id, $data)) {
session()->setFlashdata('success', 'Donor successfully updated');
$this->logger->info("Donor: has been updated successfully. Updated Donor ID = " . $donor_id_for_addresses);
@@ -215,7 +217,7 @@ class Customer extends BaseController
public function donor_group(){
$session_bid = get_business_id();
- $data['page_name'] = 'Donor Group Details';
+ $data['page_name'] = 'Contributor Group Details';
$model = new CustomerModel();
$data['donor_group'] = $model->getGroupDetails($session_bid);
$this->render_page('customer_group', $data);
@@ -254,10 +256,10 @@ class Customer extends BaseController
if ($id === '0') {
// Add Customer
- $data['page_name'] = 'Add Donor Group';
+ $data['page_name'] = 'Add Contributor Group';
} else if ($id !== '0') {
// Edit Customer
- $data['page_name'] = 'Edit Donor Group';
+ $data['page_name'] = 'Edit Contributor Group';
// Load your Customer Model
$model = new CustomerModel();
@@ -469,5 +471,16 @@ class Customer extends BaseController
}
return redirect()->route('donor_group');
}
+ // Example in your controller
+public function getReceiptDetails($donorId)
+{
+ $CustomerModel = new CustomerModel();
+ // Fetch receipt details from the model based on $donorId
+ $receiptDetails = $CustomerModel->getReceiptDetailsByDonorId($donorId);
+
+ // Return the details as JSON
+ return $this->response->setJSON($receiptDetails);
+}
+
}
diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php
index d6a63bb..52e8074 100644
--- a/app/Controllers/Invoice.php
+++ b/app/Controllers/Invoice.php
@@ -127,23 +127,24 @@ class Invoice extends BaseController
$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();
$count_receipt_no = (count($receipt) > 0) ? count($receipt) + $settingData[0]['start_no'] + 1 : $settingData[0]['start_no'] + 1;
- $pad = '';
- for ($i=0; $i < $settingData[0]['left_pad']; $i++) {
- $pad .= '0';
- }
- $data['count_receipt_no'] = $settingData[0]['prefix_format'].'/'.$pad.''.$count_receipt_no;
+
+ // Calculate padding based on the count of digits in count_receipt_no
+ $padding_count = max(0, $settingData[0]['left_pad'] - strlen($count_receipt_no));
+ $padding = str_repeat('0', $padding_count);
+
+ $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['causes'] = $model->getData('causes', $where);
- $data['causes'] = $bmodel->select('*')->where('business_id', (int)get_business_id() )->where('isactive',1)->get()->getResult();
+ $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);
-
+
if ($id === '0') {
$this->logger->info("Receipt: In Add Details");
$data['page_name'] = 'Add Receipt Details';
@@ -160,12 +161,10 @@ class Invoice extends BaseController
$data['receipt_details'] = $model->where(['receipt_id' => $id, 'isactive' => 1])->first();
}
}
-
- // echo '';
- // print_r($data['receipt_details']);
+
$this->render_page('invoice_form', $data);
}
-
+
public function donor_cash_success()
{
helper('session');
@@ -432,6 +431,17 @@ class Invoice extends BaseController
$this->logger->error("Receipt: Err Occur =" . $e->getMessage());
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
}
+ $success = true;
+
+ // Your existing code...
+ $invoice_id = $receipt_id; // Replace with the actual invoice_id
+
+ // Pass the invoice_id and success variable to the view
+ return $this->response->setJSON(['success' => true, 'invoice_id' => $invoice_id]);
+ // Load the view with the success variable
+ // return view('invoice_modal', ['success' => $success]);
+
+ // $this->load->view('invoice_modal', array('success' => $success));
return redirect()->route('receipt_list');
}
@@ -663,7 +673,8 @@ class Invoice extends BaseController
$options->set('isRemoteEnabled', true);
$options->set('font_subsetting', true);
$options->set('tempDir', sys_get_temp_dir());
- $options->set('defaultFont', 'Arial');
+ $options->set('defaultFont', 'DejaVuSans');
+
$options->set('chroot', base_url()."public/uploads");
$dompdf = new Dompdf($options);
@@ -708,7 +719,7 @@ class Invoice extends BaseController
// echo $downloadLink;die;
return $html;
}
- $dompdf->stream('document.pdf', ['Attachment' => 1]);
+ $dompdf->stream('Receipt.pdf', ['Attachment' => 1]);
} catch (Exception $e) {
// Handle the exception
// For example, log the error, display a user-friendly message, or return an error response
diff --git a/app/Controllers/Users.php b/app/Controllers/Users.php
index b73cd24..85e32b7 100644
--- a/app/Controllers/Users.php
+++ b/app/Controllers/Users.php
@@ -121,8 +121,9 @@ class Users extends BaseController
}
$data['details'] = $edit_user_details;
+
}
-
+ $data['session_uid']=$session_uid;
$data['session_bid'] = $session_bid;
$this->render_page($render_page_name, $data);
}
@@ -277,6 +278,7 @@ class Users extends BaseController
session()->setFlashdata('error', 'User could not be added. Please try again.');
$this->logger->error("Users: Err could not be added. Please try again.");
}
+ return redirect()->route('user_list');
} else {
@@ -288,20 +290,20 @@ class Users extends BaseController
throw new \Exception("Cant able to Update Because logged-In persons can't remove. Please Contact your Admin!....");
}
if ($UsersModel->update($user_id, $data)) {
- session()->setFlashdata('success', 'User has been updated successfully.');
- $this->logger->info("Users: has been updated successfully. Updated ID = ".$user_id);
- } else {
- session()->setFlashdata('error', 'User update failed. Please try again.');
- $this->logger->error("Users: Err Failed to update ID =".$user_id);
- }
+
+ session()->setFlashdata('success', 'User has been updated successfully.');
}
- }catch(\Exception $e) {
- $this->logger->error("Users: Err Occur =".$e->getMessage());
- session()->setFlashdata('error', 'Message: ' .$e->getMessage());
- }
- return redirect()->route('user_list');
+ }
+}catch (\Exception $e) {
+ $this->logger->error("Users: Err Occur =" . $e->getMessage());
+ session()->setFlashdata('error', 'Message: ' . $e->getMessage());
}
+ // Redirect back to the user_page function or any other appropriate page
+ return redirect()->to(base_url("user_page/{$user_id}"));
+}
+
+
## For delete the user details (Which means inactive the details)
public function delete_user($id)
{
diff --git a/app/Models/BusinessModel.php b/app/Models/BusinessModel.php
index 6efdaf6..875eb34 100644
--- a/app/Models/BusinessModel.php
+++ b/app/Models/BusinessModel.php
@@ -23,6 +23,57 @@ class BusinessModel extends Model
->getResultArray();
}
-
+public function insertDonationBusiness($businessId)
+{
+ $donationData = $this->db->table('donations_accepted')
+ ->get()
+ ->getResultArray();
+
+ if (!empty($donationData)) {
+ $insertData = [];
+ foreach ($donationData as $donation) {
+ $insertData[] = [
+ 'bussiness_id' => $businessId,
+ 'donation_id' => $donation['id'],
+ 'name' => $donation['name'],
+ 'is_active'=>1
+ // Add other columns as needed
+ ];
+ }
+
+ // Insert data into donation_business table
+ $this->db->table('donation_business')->insertBatch($insertData);
+ }
+
+}
+public function getDonationBusinessData($businessId)
+{
+ return $this->db->table('donation_business')
+ ->where('bussiness_id', $businessId)
+ ->get()
+ ->getResultArray();
+}
+public function updateDonationData($businessId, $selectedDonations)
+ {
+ // Fetch all donation data for the given businessId
+ $donationData = $this->db->table('donation_business')
+ ->where('bussiness_id', $businessId)
+ ->get()
+ ->getResultArray();
+
+ foreach ($donationData as $donation) {
+ $donationId = $donation['donation_id'];
+ $isActive = in_array($donationId, $selectedDonations) ? 1 : 0;
+
+ // Update donations_accepted table based on selected options
+ $donationUpdateData = ['is_active' => $isActive];
+ $donationWhere = ['id' => $donationId];
+
+ $this->db->table('donation_business')
+ ->where($donationWhere)
+ ->update($donationUpdateData);
+ }
+ }
+
}
?>
\ No newline at end of file
diff --git a/app/Models/CustomerModel.php b/app/Models/CustomerModel.php
index e361d5f..e982118 100644
--- a/app/Models/CustomerModel.php
+++ b/app/Models/CustomerModel.php
@@ -158,6 +158,16 @@ return $this->db->table('donor_groups as CG' )
->get()
->getResultArray();
}
+public function getReceiptDetailsByDonorId($donorId)
+{
+ return $this->db->table('receipt')
+ ->select('receipt.receipt_number, receipt.donor_id, receipt.amount, receipt.currency,receipt.receipt_date, d.first_name')
+ ->join('donor as d', 'd.donor_id = receipt.donor_id', 'left') // Adjust columns accordingly
+ ->where('receipt.donor_id', $donorId) // Specify the table alias for the column in the where clause
+ ->get()
+ ->getResult();
+}
+
}
diff --git a/app/Views/auth_login.php b/app/Views/auth_login.php
index 96e8be7..cc3e132 100644
--- a/app/Views/auth_login.php
+++ b/app/Views/auth_login.php
@@ -3,7 +3,7 @@
- BigBamboo Donation
+ BigBamboo Contribution
@@ -46,18 +46,18 @@
- Enter your email address and password.
+
+
@@ -110,7 +102,7 @@
@@ -120,15 +112,23 @@
+ });
+
-