diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 373c069..f20770c 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -88,8 +88,6 @@ $routes->post("insert_contributor_group", "Customer::insert_donor_group"); $routes->get("campaign_list/", "Event::index"); $routes->get("new_campaign/(:any)", "Event::new_campaign/$1"); $routes->post("insert_event/", "Event::insert_event"); -$routes->get('invoice_number_format/(:any)', 'Event::invoice_number_format/$1'); -$routes->post("insert_invoice_number_format", "Event::insert_invoice_number_format"); #Receipt Routes (also known as Invoice) $routes->get("receipt_list/", "Invoice::index"); @@ -105,7 +103,6 @@ $routes->post("get_donor_details", "Invoice::get_donor_details"); $routes->post("save_invoice/", "Invoice::save_invoice/"); $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'); #Report Routes $routes->match(['get','post'],'/general_inv_rp','Invoice::general_inv_rp'); diff --git a/app/Controllers/Books.php b/app/Controllers/Books.php index 96d2244..4f72650 100644 --- a/app/Controllers/Books.php +++ b/app/Controllers/Books.php @@ -15,17 +15,19 @@ class Books extends BaseController $session_role = get_user_role(); $session_bid = get_business_id(); - if (!empty($session_role) && $session_role !== "sadmin") { - $where = ['causes.business_id' => $session_bid, 'causes.isactive' => 1]; - } else { - $where = ['causes.isactive !=' => NULL]; - } + + $default_financial_year_condition = [ + 'causes.created_on >= CONCAT(YEAR(NOW()) - IF(MONTH(NOW()) >= 1 AND MONTH(NOW()) <= 3, 1, 0), "-01-01")', + 'causes.created_on < CONCAT(YEAR(NOW()) + IF(MONTH(NOW()) >= 1 AND MONTH(NOW()) <= 3, 1, 0), "-01-01")' + ]; + $where = ['causes.business_id' => $session_bid]; + // $where = array_merge($where, $default_financial_year_condition); $model = new BooksModel(); $model->setTable('causes'); $data['cause_list'] = $model->getData('donations_accepted',null,null); $data['page_name'] = 'Causes List'; - $data['details'] = $model->where('causes.business_id', $session_bid)->where('causes.isactive', 1)->findAll(); + $data['details'] = $model->where($where)->where('causes.isactive', 1)->findAll(); $this->render_page('book_list', $data); } else { // Session is not active or user is not logged in diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php index cfc031d..c42d283 100644 --- a/app/Controllers/Customer.php +++ b/app/Controllers/Customer.php @@ -15,6 +15,11 @@ class Customer extends BaseController if (is_session_active()) { $session_role = get_user_role(); $session_bid = get_business_id(); + $default_financial_year_condition = [ + 'created_on >= CONCAT(YEAR(NOW()) - IF(MONTH(NOW()) >= 1 AND MONTH(NOW()) <= 3, 1, 0), "-01-01")', + 'created_on < CONCAT(YEAR(NOW()) + IF(MONTH(NOW()) >= 1 AND MONTH(NOW()) <= 3, 1, 0), "-01-01")' + ]; + if (!empty($session_role) && $session_role !== "sadmin") { $this->logger->info("Donor: Listing In admin role . BID = ".$session_bid); $where = ['isactive' => 1, 'business_id' => (int)$session_bid]; @@ -22,6 +27,7 @@ class Customer extends BaseController $this->logger->info("Donor: Listing In Super-admin role ."); $where = ['isactive != ' => NULL]; } + // $where = array_merge($where, $default_financial_year_condition); $CustomerModel = new CustomerModel(); $data['page_name'] = 'Contributor Details'; @@ -138,7 +144,7 @@ class Customer extends BaseController ]; - print_r($data); + // print_r($data); // echo $this->db->getLastQuery();die(); $donor_id = $this->request->getPost('donor_id'); // Get the business ID for update if (empty($donor_id)) { diff --git a/app/Controllers/Event.php b/app/Controllers/Event.php index 77debcc..62baf89 100644 --- a/app/Controllers/Event.php +++ b/app/Controllers/Event.php @@ -15,11 +15,17 @@ class Event extends BaseController $session_role = get_user_role(); $session_bid = get_business_id(); + $default_financial_year_condition = [ + 'campaign.created_on >= CONCAT(YEAR(NOW()) - IF(MONTH(NOW()) >= 1 AND MONTH(NOW()) <= 3, 1, 0), "-01-01")', + 'campaign.created_on < CONCAT(YEAR(NOW()) + IF(MONTH(NOW()) >= 1 AND MONTH(NOW()) <= 3, 1, 0), "-01-01")' + ]; + if (!empty($session_role) && $session_role !== "sadmin") { $where = ['campaign.business_id' => (int)$session_bid]; } else { $where = ['campaign.business_id != ' => NULL]; } + // $where = array_merge($where, $default_financial_year_condition); $EventModel = new EventModel(); $data['page_name'] = 'Campaign Details'; @@ -114,64 +120,4 @@ class Event extends BaseController return redirect()->route('campaign_list'); } - public function invoice_number_format($id) - { - helper('session'); - $session_bid = get_business_id(); - $data['page_name'] = 'Edit invoice number formatting'; - $model = new EventModel(); - $edit_campaign_details = $model->setTable('invoice_number_formatting')->where(['id' => (int)$id,'business_id'=>$session_bid])->first(); - $data['campaign'] = $edit_campaign_details; - $data['session_bid'] = $session_bid; - - $this->render_page('invoice_number_formatting', $data); - } - public function insert_invoice_number_format() - { - $this->logger->info("insert_invoice_number_format: Inserting/Updating Details"); - try { - helper('session'); - $session_bid = get_business_id(); - $session_uid = get_logged_user_id(); - $EventModel = new EventModel(); - $data = [ - 'next_id' => $this->request->getPost('nextid'), - 'left_pad' => $this->request->getPost('leftpad'), - 'id_formating' => $this->request->getPost('formating'), - 'business_id' => $this->request->getPost('business_id') - ]; - $pk_id = $this->request->getPost('id'); // Get the business ID for update - - if (empty($pk_id)) { - // It's an insert operation - $data['created_by'] = $session_uid; - // $EventModel->insert($data); - $insert_result = $EventModel->insertData('invoice_number_formatting', $data); - - if ($insert_result['info']) { - session()->setFlashdata('success', "updated Successfully"); - $this->logger->info($insert_result['info']); - } else { - session()->setFlashdata('error', $insert_result['err']); - $this->logger->error($insert_result['err']); - } - } else { - // It's an update operation - $data['updated_by'] = $session_uid; - $where = ['id' => $pk_id, 'business_id' => get_business_id()]; - $update_result = $EventModel->updateData('invoice_number_formatting', $data,$where); - if ($update_result['info']) { - session()->setFlashdata('success',"updated Successfully"); - $this->logger->info($update_result['info']); - } else { - session()->setFlashdata('error', $update_result['err']); - $this->logger->error($update_result['err']); - } - } - } catch (\Exception $e) { - $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 76c5842..ef36556 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -12,47 +12,64 @@ class Home extends BaseController helper('session'); $session_role = get_user_role(); $session_bid = get_business_id(); + $session_uid = get_logged_user_id(); // echo $session_bid, $session_role; die; $data['page_name'] = 'Dashboard'; - if (!empty($session_role) && $session_role == "sadmin") { - $where = ['isactive != ' => NULL]; - } else if (!empty($session_role) && $session_role == "admin") { - $where = ['isactive' => 1, 'business_id' => $session_bid]; - } - else { - $where = []; - } $model = new HomeModel(); - $data['customer'] = $model->customers($where); - $data['customer']['label'] = "donors"; - - // echo '
';
- // print_r($data['customer'] ); die;
+ $bwhere = ['user_id'=> $session_uid,'business_id'=> $session_bid,'isactive'=> 1];
+ $branch_id = $model->getbranchid($bwhere);
+
+ $where = ['donor.business_id' => $session_bid];
+
+ if (!empty($session_role)) {
+ switch ($session_role) {
+ case 'auditor':
+ $where['donor.created_by'] = $session_uid;
+ break;
+ case 'accounts':
+ if ($branch_id) {
+ $where['users.branch_id'] = $branch_id;
+ }
+ break;
+ case 'donor':
+ case 'volunteer':
+ if ($branch_id) {
+ $where['users.branch_id'] = $branch_id;
+ }
+ $where['donor.created_by'] = $session_uid;
+ break;
+ }
+ }
+
+ $data['donordetails'] = $model->donordetails($where);
+
+ $data['donordetails']['label'] = "donors";
- // $data['invoice'] = $model->invoice();
- // $data['active_category'] = array_filter($model->schemes(), function ($element) {
- // return $element['count'] !== '0' ;
- // });
- // $data['book_published'] = $model->book_published_list();
$this->render_page('dashboard', $data);
}
+ ## Dynamic Validation For Existing Check AJAX Call
+ # USED in 1) User Module
+ # 2) Recepit-DonorQuickAdd Module
+ # 3) Contributor(or)Donor Module
+ # 4) Buiness(Or)Organsation Module
+ ## PLEASE mention here wherever you used this.
public function check_existing()
{
$value = $this->request->getPost('value');
$table = $this->request->getPost('module');
$field = $this->request->getPost('field');
$model = new HomeModel();
- // $model->setTable('customers');
+
$model->setTable((string)$table);
$where = [$field => $value];
$check_existing = $model->where($where)->findAll();
$statement_string = ucfirst(str_replace('_', ' ', (string)$field));
- $data = ['status' => false, 'message' => '']; // Initialize the data array
+ $data = ['status' => false, 'message' => ''];
if (!empty($check_existing)) {
$data['status'] = true;
$data['message'] = $statement_string." Already existing";
diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php
index b387175..e087502 100644
--- a/app/Controllers/Invoice.php
+++ b/app/Controllers/Invoice.php
@@ -42,7 +42,12 @@ class Invoice extends BaseController
$where = ['business_id' => (int)get_business_id()];
$data['Donors'] = $model->getData('donor', $where);
$data['page_name'] = 'Receipt Details';
- $data['receipt'] = $model->where(["business_id"=>$session_bid])->findAll();
+ $default_financial_year_condition = [
+ 'created_at >= CONCAT(YEAR(NOW()) - IF(MONTH(NOW()) >= 1 AND MONTH(NOW()) <= 3, 1, 0), "-01-01")',
+ 'created_at < CONCAT(YEAR(NOW()) + IF(MONTH(NOW()) >= 1 AND MONTH(NOW()) <= 3, 1, 0), "-01-01")'
+ ];
+ // $where = array_merge($where, $default_financial_year_condition);
+ $data['receipt'] = $model->where($where)->findAll();
$data['temp_receipt_count'] = $model->where(["business_id"=>$session_bid, 'receipt_header' => 'Temporary Receipt'])->countAllResults();
foreach ($data['receipt'] as $key => $value) {
@@ -155,17 +160,7 @@ 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;
- }
+ $data['receipt_type'] = (int)$data['receipt_details']['receipt_type'];
}
$cus_where = ['business_id' => (int)get_business_id() , 'isactive' => 1, 'donor_type'=>$data['receipt_type']];
$data['typebaseddonors'] = $model->getData('donor', $cus_where);
@@ -534,28 +529,27 @@ class Invoice extends BaseController
$dompdf = new Dompdf($options);
define("DOMPDF_UNICODE_ENABLED", true);
- $user = $this->UserModel->select('first_name')->where('user_id',$data[0]->created_by)->findAll();
+ $user = $this->UserModel->select('first_name, last_name')->where('user_id',$data[0]->created_by)->findAll();
clearstatcache();
// var_dump(file_exists($logoPath));
if ($data[0]->business_logo && file_exists(ROOTPATH."public/uploads/".$data[0]->business_logo)) {
// echo "Inside: Logo exists
";
- $baseurl = base_url()."public/uploads/".$data[0]->business_logo;;
+ $baseurl = base_url()."public/uploads/".$data[0]->business_logo;
} else {
// echo "Inside: Logo does not exist
"; die;
$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' => $amount_in_words ,
'baseurl' => $baseurl,
- 'signature' => "",
- 'staff_name' => $user[0]['first_name'],
+ 'signature' => $data[0]->signature,
+ 'staff_name' => $user[0]['first_name'] . ' ' .$user[0]['last_name'],
'Notes' => $terms_data[0]['terms']
]);
// echo $html;die;
@@ -577,8 +571,11 @@ class Invoice extends BaseController
// $downloadLink = base_url() . 'pdf/' . $filename;
// echo $downloadLink;die;
return $html;
- }
- $dompdf->stream('Receipt.pdf', ['Attachment' => 1]);
+ }
+ $original_name = isset($data[0]->receipt_number) && !empty($data[0]->receipt_number) ? $data[0]->receipt_number : 'Receipt';
+ $sanitized_name = preg_replace("/[^A-Za-z0-9_\-\.]/", "_", $original_name);
+ $pdf_extension_name = $sanitized_name . '.pdf';
+ $dompdf->stream($pdf_extension_name, ['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 7c086b0..6e6d1dd 100644
--- a/app/Controllers/Users.php
+++ b/app/Controllers/Users.php
@@ -14,7 +14,10 @@ class Users extends BaseController
$session_role = get_user_role();
$session_bid = get_business_id();
-
+ $default_financial_year_condition = [
+ 'users.created_at >= CONCAT(YEAR(NOW()) - IF(MONTH(NOW()) >= 1 AND MONTH(NOW()) <= 3, 1, 0), "-01-01")',
+ 'users.created_at < CONCAT(YEAR(NOW()) + IF(MONTH(NOW()) >= 1 AND MONTH(NOW()) <= 3, 1, 0), "-01-01")'
+ ];
if (!empty($session_role) && $session_role === "sadmin") {
$this->logger->info("Users: Listing In Super-admin role .");
$where = ['users.isactive !=' => NULL];
@@ -25,6 +28,7 @@ class Users extends BaseController
$this->logger->info("Users: Listing In ".$session_role." role . BID = ".$session_bid);
$where = ['users.business_id' => (int)$session_bid, 'users.isactive' => 1];
}
+ // $where = array_merge($where, $default_financial_year_condition);
$model = new UsersModel();
$model->setTable('users');
// $user_details = $model->where($where)->orderBy('user_id', 'DESC')->findAll();
diff --git a/app/Models/CustomerModel.php b/app/Models/CustomerModel.php
index 1895f68..2f35653 100644
--- a/app/Models/CustomerModel.php
+++ b/app/Models/CustomerModel.php
@@ -16,104 +16,8 @@ class CustomerModel extends Model
{
return $this->insert($data);
}
- public function getCustomerNamesByBusiness($business_id)
- {
- $this->builder()->select('donor_id,CONCAT(first_name, " ", last_name) as full_name', false);
- $this->builder()->where('business_id ', $business_id); // Filter by business_id
- $query = $this->builder()->get(); // Use findAll() instead of get()
- return ($query->getResult());
- }
-
- // $customerNames = [];
-
- // foreach ($query->getResult() as $row) {
- // $customerNames[] = [ $row->full_name ];
- // }
- // print_r($customerNames);
- // die();
-
-
-// public function getCustomerIdByName($customerName, $businessId)
-// {
-// $customer = $this->builder()
-// ->select('donor_id')
-// ->where('CONCAT(first_name, " ", last_name)', $customerName)
-// ->where('business_id', $businessId)
-// ->get()
-// ->getRow();
-
-// if ($customer) {
-// return $customer->donor_id;
-// }
-
-// return null; // Customer not found
-// }
-
-
-
-
-
- public function insertAddress($addressData) {
- $this->db->table('customer_addresses')->insert($addressData);
- return $this->db->insertID(); // Return the last inserted ID
- }
-
- public function insertAddressBatch($addressesDataArray) {
- $this->db->table('customer_addresses')->insertBatch($addressesDataArray);
- return $this->db->insertID(); // Note: insertID() might not be applicable for batch inserts
- }
-
- public function saveAddressDetails($data){
- $i = 0;
- $statement = [];
- foreach ($data as $row) {
- $id = $row['customer_address_id'];
- if($id != ''){
- unset($row['customer_address_id']); // Remove the id from the data to avoid updating it
- unset($row['created_by']); // bcoz here data Updating here.
- $this->db->table('customer_addresses')->where('customer_address_id', $id)->update($row);// Update the row with the specified id
- $affectedRows = $this->db->affectedRows();
- $statement[$i] = "address - ".$id." ". ($affectedRows ? " Updated":" Nothing to Updated");
- }else{
- $this->db->table('customer_addresses')->insert($row);
- $insertID = $this->db->insertID();
- $statement[$i] = "address - ".$insertID." Inserted";
- }
- $i++;
- }
- return $statement;
- }
-
-
- public function inactiveMissingAddressDetails($where,$missingValues){
- $dataToUpdate = ['isactive' => 0];
- $this->db->table('customer_addresses')->where($where)->whereIn('customer_address_id',$missingValues)->update($dataToUpdate);
- }
- public function getInvoicesByCustomerId($donor_id)
-{
- return $this->db->table('invoice')
- ->select('invoice_number, subtotal, invoice_date')
- ->where('donor_id', $donor_id)
- ->get()
- ->getResult();
-}
-public function getSubscriberDataByCustomerId($customerId)
-{
- // Assuming 'subscription' is the table name where subscriber data is stored.
- $builder = $this->db->table('subscription');
- $builder->join('books', 'books.book_id = subscription.scheme_id');
-
-
- // Define the columns you want to select from the subscription table.
- $builder->select('subscription.*,books.title');
-
- // Add a where condition to filter results based on customer ID.
- $builder->where('donor_id', $customerId);
-
- // Execute the query and return the result as an array of objects.
- return $builder->get()->getResult();
-}
+
public function saveGroupDetails($data){
$id = $data['group_id'];
diff --git a/app/Models/HomeModel.php b/app/Models/HomeModel.php
index 52fad01..8be1431 100644
--- a/app/Models/HomeModel.php
+++ b/app/Models/HomeModel.php
@@ -4,94 +4,37 @@ use CodeIgniter\Model;
class HomeModel extends Model
{
- public function customers($where) {
+ public function donordetails($where) {
- $query = $this->db->table('donor');
+ $totalDonors = $this->db->table('donor')
+ ->where($where)->countAll();
- $totalCustomers = $query->where($where)->countAll();
- $activeCustomers = $query->where($where)->countAllResults();
-
- $where['DATE(created_on)'] = date('Y-m-d');
- $todayCustomers = $query->where($where)->countAllResults();
-
- if ($totalCustomers > 0) {
- $customer['percentage'] = ($activeCustomers / $totalCustomers) * 100;
+ $activeDonors = $this->db->table('donor')->select('donor.*, users.branch_id,users.business_id as users_business_id')
+ ->join('users', 'users.user_id = donor.created_by AND users.business_id = donor.business_id', 'left')
+ ->where($where)->where('donor.isactive',1)->countAllResults();
+
+ $where['DATE(donor.created_on)'] = date('Y-m-d');
+ $todayDonors = $this->db->table('donor')->select('donor.*, users.branch_id,users.business_id as users_business_id')
+ ->join('users', 'users.user_id = donor.created_by AND users.business_id = donor.business_id', 'left')
+ ->where($where)->where('donor.isactive',1)->countAllResults();
+
+ if ($totalDonors > 0) {
+ $final['percentage'] = ($activeDonors / $totalDonors) * 100;
} else {
- $customer['percentage'] = 0;
+ $final['percentage'] = 0;
}
- $customer['total'] = $totalCustomers;
- $customer['active'] = $activeCustomers;
- $customer['today'] = $todayCustomers;
- return $customer;
+ $final['total'] = $totalDonors;
+ $final['active'] = $activeDonors;
+ $final['today'] = $todayDonors;
+
+ return $final;
}
- // public function invoice() {
- // if (date('m') <= 3) {
- // $invoice['financial_year'] = (date('Y')-1) . '-' . date('Y');
- // $start_date = (date('Y')-1).'-04-01';
- // $end_date = date('Y').'-03-31';
- // } else {
- // $invoice['financial_year'] = date('Y') . '-' . (date('Y') + 1);
- // $start_date = date('Y').'-04-01';
- // $end_date = (date('Y')+1).'-03-31';
- // }
- // $date_where = ['DATE(created_on)' => date('Y-m-d'),'isactive'=>1];
- // $date_query = $this->db->table('invoice')->where($date_where)->countAllResults();
- // $month_where = ['MONTH(created_on)' => date('m'),'isactive'=>1];
- // $month_query = $this->db->table('invoice')->where($month_where)->countAllResults();
- // $fin_year_where = ['DATE(created_on) >= ' => $start_date , 'DATE(created_on) <= ' => $end_date,'isactive'=>1];
- // $fin_year_query = $this->db->table('invoice')->where($fin_year_where)->countAllResults();
- // $invoice['today'] = $date_query;
- // $invoice['month'] = $month_query;
- // $invoice['year'] = $fin_year_query;
- // return $invoice;
- // }
-
- // public function schemes(){
- // $query = $this->db->table('category AS C')
- // ->select('C.id,C.name,LEFT(C.name, 1) AS first_letter, COUNT(S.customer_id) AS count')
- // ->join('subscription AS S', 'C.id = S.scheme_id', 'left')
- // ->where(['C.isactive'=>1,'C.business_id'=>1])
- // ->groupBy('C.id, S.scheme_id');
- // $results = $query->get()->getResultArray();
- // return $results;
- // }
-
- // public function expiring_membership_list(){
- // $now = date('Y-m-d');
- // $last30days = date('Y-m-d', strtotime('+30 days'));
- // return $this->db->table('subscription as S')
- // ->join('donor as C', 'C.customer_id = S.customer_id', 'left')
- // ->join('books as BK', 'BK.book_id = S.scheme_id', 'left')
- // ->join('book_categories as BC', 'BC.book_id = S.scheme_id', 'left')
- // ->join('category as CM', 'CM.id = BC.category_id', 'left')
- // ->select('CM.name, CONCAT(C.first_name, " ", C.last_name) as customer_name, C.email as customer_email, C.mobile_no as customer_mobile, S.sub_id, S.scheme_id, S.customer_id, S.business_id, S.to_subscription, S.from_subscription, BK.title, BK.book_id,DATEDIFF(S.to_subscription, CURDATE()) as countdays,DATE_FORMAT(S.to_subscription, "%d-%m-%Y") as to_subscription_date_format')
- // ->where('S.to_subscription >=', $now)
- // ->where('S.to_subscription <=', $last30days)
- // // ->where('BC.category_id', 5)
- // ->where('LOWER(CM.name)', strtolower("Membership"))
- // ->orderBy('S.to_subscription', 'ASC')
- // ->groupBy('S.sub_id')
- // ->get()
- // ->getResultArray();
- // }
-
- // public function book_published_list(){
- // $now = date('Y-m-d');
- // $oneMonthAgo = date('Y-m-d', strtotime($now . ' -1 month'));
-
- // return $this->db->table('books as B')
- // ->select("B.book_id, B.title, B.created_on, B.publisher, B.author, B.publication_date, DATE_FORMAT(B.publication_date, '%d-%m-%Y') as publication_date_format, GROUP_CONCAT(CM.name, ',') as categories")
- // ->join('book_categories as BC', 'BC.book_id = B.book_id and BC.isactive = 1', 'left')
- // ->join('category as CM', 'BC.category_id = CM.id', 'left')
- // ->where('B.created_on >=', $oneMonthAgo)
- // ->where('B.created_on <=', $now)
- // ->where('B.isactive', 1)
- // ->orderBy('B.publication_date', 'DESC')
- // ->groupBy('B.book_id')
- // ->get()
- // ->getResultArray();
- // }
+ public function getbranchid($bwhere){
+ $query = $this->db->table('users');
+ $result = $query->select('branch_id')->where($bwhere)->get()->getRow();
+ return $result ? (int)$result->branch_id : 0;
+ }
}
diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php
index 1bb51cf..9e6d133 100644
--- a/app/Models/InvoiceModel.php
+++ b/app/Models/InvoiceModel.php
@@ -7,105 +7,14 @@ class InvoiceModel extends Model
{
protected $table = 'receipt';
protected $primaryKey = 'receipt_id';
-// protected $allowedFields = ['invoice_id','invoice_number','donor_id','invoice_date','event_id','business_id','created_on','business_id'];
-protected $allowedFields = ['receipt_id', 'receipt_number', 'donor_id','notes','amount', 'payment_mode', 'business_id', 'created_on', 'created_by', 'updated_on', 'updated_by','isactive', 'payment_ref_no', 'receipt_date','causes_id','campaign_id','receipt_header','reason','currency'];
-
-public function saveInvoiceItemDetails($data){
- $i = 0;
- $statement = [];
- foreach ($data as $row) {
- $id = isset($row['invoice_child_id']) ? $row['invoice_child_id'] : '';
- if($id != ''){
- unset($row['invoice_child_id']); // Remove the id from the data to avoid updating it
- unset($row['created_by']); // bcoz here data are Updating here.
- $this->db->table('invoiceitems')->where('invoice_child_id', $id)->update($row);// Update the row with the specified id
- $affectedRows = $this->db->affectedRows();
- $statement[$i] = "Invoice Item - ".$id." ".$affectedRows ? " Updated":" Not Updated";
- }else{
- unset($row['updated_by']); // bcoz here data are inserting here.
- $this->db->table('invoiceitems')->insert($row);
- $insertID = $this->db->insertID();
- $statement[$i] = "Invoice Item - ".$insertID." Inserted";
- }
- }
- return $statement;
-}
+protected $allowedFields = ['receipt_id', 'receipt_number', 'donor_id','notes','amount', 'payment_mode', 'business_id', 'created_on', 'created_by', 'updated_on', 'updated_by','isactive', 'payment_ref_no', 'receipt_date','causes_id','campaign_id','receipt_header','reason','currency','receipt_type'];
-public function inactiveMissingInvoiceItemDetails($where,$missingValues){
- $dataToUpdate = ['isactive' => 0];
- $this->db->table('invoiceitems')->where($where)->whereIn('invoice_child_id',$missingValues)->update($dataToUpdate);
-}
-
-public function updateData($table, $data, $where)
-{
- $this->db->table($table)->update($data, $where);
- $affected_rows = $this->db->affectedRows();
- return $affected_rows;
-}
-
- public function getSubscriptionInvoiceDetail($where)
+ public function updateData($table, $data, $where)
{
- $result = $this->getJoinedData($where);
- // print_r($result);die;
- if(!empty($result)){
- foreach ($result as $i => $item) {
- $invoiceId = $item['invoice_id'];
- $scheme_name = [];
- $from_subscription = [];
- $to_subscription = [];
- $invoiceItems = $this->getInvoiceItems($invoiceId,'');
- foreach ($invoiceItems as $j => $child) {
- if ($child->category_name == 'Membership') {
- $scheme_name[] = $child->title;
- $from_subscription[] = ($j == 0 && !empty($child->from_subscription) && $child->from_subscription !== null) ? date('d/m/Y', strtotime($child->from_subscription)) : "";
- $to_subscription[] = ($j == 0 && !empty($child->to_subscription) && $child->from_subscription !== null ) ? date('d/m/Y', strtotime($child->to_subscription)) : "";
- }
- }
- $result[$i]['scheme_name'] = !empty($scheme_name) ? implode(", ", $scheme_name) : '';
- $result[$i]['from_subscription'] = !empty($from_subscription) ? implode(" ", $from_subscription) : '';
- $result[$i]['to_subscription'] = !empty($to_subscription) ? implode(" ", $to_subscription) : '';
- $result[$i]['invoice_items_details'] = $invoiceItems;
- }
- }
- return $result;
- }
-
- public function getJoinedData($where)
- {
-
- return $this->db->table($this->table.' as I' )
-
- ->join('donor as C', 'C.donor_id = I.donor_id', 'left')
- ->join('Campaign as E', 'E.Campaign_id = I.event_id', 'left')
- ->join('business as B', 'B.business_id = I.business_id', 'left')
- ->join('users as U1', 'U1.user_id = I.created_by', 'left')
- ->join('users as U2', 'U2.user_id = I.updated_by', 'left')
- ->select('I.invoice_id, (C.first_name," ",C.last_name) as customer_name , I.business_id, I.created_on, I.created_by,concat(U1.first_name," ",U1.last_name) as created_by_name, I.updated_on, I.updated_by,concat(U2.first_name," ",U2.last_name) as updated_by_name, I.isactive,C.email as customer_email,C.mobile_no as customer_mobile')
- ->where($where)
- ->orderBy('invoice_id', 'DESC')
- ->get()
- ->getResultArray();
-
-
- // I.shipping_address_id, I.billing_address_id,
- }
-
-
- public function getDetailForApproveNotifications($where)
- {
- $result = $this->getJoinedData($where);
- if(!empty($result)){
- foreach ($result as $object) {
- $invoiceId = $object['invoice_id'];
- $items = $this->getInvoiceItems($invoiceId,'');
- }
- }else{
- $items = [];
- }
- $data['invoice'] = $result;
- $data['item'] = $items;
- return $data;
+ $this->db->table($table)->update($data, $where);
+ $affected_rows = $this->db->affectedRows();
+ return $affected_rows;
}
public function getData($table, $where = null)
@@ -117,6 +26,7 @@ public function updateData($table, $data, $where)
return $query->get()->getResult();
}
+ ## gethering Donor receipt Details for PDF.
public function getInvoiceData($id)
{
// Fetch invoice data
@@ -131,174 +41,5 @@ public function updateData($table, $data, $where)
->getResult();
}
- // // this function Also Used For Approve Notification.
- // public function getInvoiceItems($id,$stringflag)
- // {
-
- // if ($stringflag == 'groupby') {
- // $select = 'invoiceitems.*, B.*, GROUP_CONCAT(C.name SEPARATOR \',\') as name';
- // $group_by = 'invoiceitems.invoice_child_id';
- // } else {
- // $select = 'invoiceitems.*, B.*, C.name as category_name';
- // $group_by = "";
- // }
-
- // $data = $this->db->table('invoiceitems')
- // ->where(['invoice_id' => $id, 'invoiceitems.isactive' => 1])
- // ->join('causes as B', 'B.causes_id = invoiceitems.product', 'left')
- // ->select($select)
- // ->groupBy($group_by) // Fixed the variable name here
- // ->get()
- // ->getResult();
-
- // //->orderBy("book_img_id", "asc") // Order by book_img_id in ascending order
- // //->limit(1,0)
-
-
- // // print_r($this->db->getLastQuery());die;
- // // print_r($data);die("ends -- here");
- // return $data;
- // }
-
-
- // public function getMembershipListForCustomer($category, $id)
- // {
- // $data = $this->db->table('subscription as S')
- // ->join('donor as C', 'C.donor_id = S.donor_id', 'left')
- // ->join('category as CM', 'CM.id = S.scheme_id', 'left')
- // ->join('book_categories as BC', 'BC.category_id = S.scheme_id', 'left')
- // ->join('causes as BK', 'BC.causes_id = BK.causes_id', 'left')
- // ->select('S.donor_id, CONCAT(C.first_name, " ", C.last_name) as customer_name, S.sub_id, S.scheme_id, DATE_FORMAT(S.from_subscription, "%d/%m/%Y") AS formatted_from_subscription, DATE_FORMAT(S.to_subscription, "%d/%m/%Y") AS formatted_to_subscription, S.from_subscription, S.to_subscription, S.created_on, CM.name, BK.title, BK.causes_id')
- // ->where('CM.name', strtolower($category))
- // ->where('S.donor_id', $id)
- // ->groupBy('S.sub_id')
- // ->orderBy('S.created_on', 'ASC')
- // ->get()
- // ->getResultArray();
- // return $data;
- // }
-
- public function getProductImgs($productId)
- {
- $data = $this->db->table('book_images')
- ->where(['causes_id' => $productId])
- // ->join('causes as B', 'B.causes_id = invoiceitems.product', 'left')
- // ->join('book_images as BI', 'BI.causes_id = invoiceitems.product', 'left')
- ->select('book_images.*')
- //->orderBy("book_img_id", "asc") // Order by book_img_id in ascending order
- //->limit(1,0)
- ->get()
- ->getResult();
-
- // print_r($this->db->getLastQuery());
- return $data;
- }
-
- public function getCategoryBooks()
-{
- return $this->db->table('causes')
- ->join('book_categories', 'book_categories.causes_id= causes.causes_id', 'left')
- ->join('category','category.id=book_categories.category_id')
- ->where('category.name', 'membership')
- ->get()
- ->getResult();
-
-}
-public function getNonMembershipCategoryBooks()
-{
- $data = $this->db->table('causes')
- ->select('causes.*')
- ->join('book_categories', 'book_categories.causes_id= causes.causes_id', 'left')
- ->join('category','category.id=book_categories.category_id')
- ->where('category.name !=', 'membership')
- ->groupBy('causes.causes_id')
- ->get()
- ->getResult();
- return $data;
-
-}
-public function insertSubscriptionData($data)
-{
- return $this->db->table('subscription')->insert($data);
-}
-
-// ***********************REPORT**********************
-
-public function get_general_invoice_data($f_date = null, $t_date = null)
-{
- // Fetch invoice data
- $query = $this->db->table('invoice')
- ->select('invoice.*, donor.*, COUNT(invoiceitems.product) as item_count')
- ->where('invoice.isactive', 1)
- ->where('invoice.invoice_type', 1)
- ->where('invoiceitems.isactive', 1);
-
- // Add date range filter if provided
- if ($f_date !== null && $t_date !== null) {
- $query->where('invoice.invoice_date >=', $f_date)
- ->where('invoice.invoice_date <=', $t_date);
- }
-
- $result = $query->join('donor', 'donor.donor_id = invoice.donor_id', 'left')
- ->join('invoiceitems', 'invoiceitems.invoice_id = invoice.invoice_id', 'left')
- ->join('causes', 'causes.causes_id = invoiceitems.product', 'left')
- ->groupBy('invoice.invoice_id') // Assuming invoice_id is the primary key of the invoice table
- ->get()
- ->getResult();
-
- return $result;
-}
-
-
-public function get_mem_invoice_data($f_date = null, $t_date = null)
-{
- // Fetch invoice data
- $query = $this->db->table('invoice')
- ->select('invoice.*, donor.*, COUNT(invoiceitems.product) as item_count')
- ->where('invoice.isactive', 1)
- ->where('invoice.invoice_type', 2)
- ->where('invoiceitems.isactive', 1);
-
- // Add date range filter if provided
- if ($f_date !== null && $t_date !== null) {
- $query->where('invoice.invoice_date >=', $f_date)
- ->where('invoice.invoice_date <=', $t_date);
- }
-
- $result = $query->join('donor', 'donor.donor_id = invoice.donor_id', 'left')
- ->join('invoiceitems', 'invoiceitems.invoice_id = invoice.invoice_id', 'left')
- ->join('causes', 'causes.causes_id = invoiceitems.product', 'left')
- ->groupBy('invoice.invoice_id') // Assuming invoice_id is the primary key of the invoice table
- ->get()
- ->getResult();
-
- return $result;
-
-}
-
-public function itemwise_report_data($f_date = null, $t_date = null)
-{
- // Fetch invoice data
- $query = $this->db->table('invoice')
- ->select('invoice.*, causes.* , COUNT(invoiceitems.product) as item_count , sum(invoiceitems.product * invoiceitems.unit_price) as item_cost')
- ->where('invoice.isactive', 1)
- ->where('causes.isactive', 1);
-
- // Add date range filter if provided
- if ($f_date !== null && $t_date !== null) {
- $query->where('invoice.invoice_date >=', $f_date)
- ->where('invoice.invoice_date <=', $t_date);
- }
-
- $result = $query->join('invoiceitems', 'invoiceitems.invoice_id = invoice.invoice_id', 'left')
- ->join('causes', 'causes.causes_id = invoiceitems.product', 'left')
- ->groupBy('causes.causes_id')
- ->get()
- ->getResult();
-
- return $result;
-}
-
-}
-
+}
\ No newline at end of file
diff --git a/app/Views/business_form.php b/app/Views/business_form.php
index 3c9db79..b020b03 100644
--- a/app/Views/business_form.php
+++ b/app/Views/business_form.php
@@ -61,18 +61,20 @@
-
+
+
Please provide.
-
-
+
+
+
Please provide.
-
+
Please provide.
@@ -80,7 +82,8 @@
-
+
+
Please provide.
@@ -91,7 +94,7 @@
-
+
@@ -152,11 +155,13 @@
-
+
+
-
+
+
@@ -587,4 +592,47 @@
}
});
-
\ No newline at end of file
+
+
diff --git a/app/Views/customer_form.php b/app/Views/customer_form.php
index a0a6096..c662fb0 100644
--- a/app/Views/customer_form.php
+++ b/app/Views/customer_form.php
@@ -4,28 +4,14 @@
= $page_name; ?>
-
-
-
-
-
+
-
-
+
+
@@ -86,7 +71,7 @@
-
+
@@ -97,11 +82,13 @@
-
+
+
-
+
+
@@ -169,8 +156,8 @@
-
-
+
+
@@ -323,4 +310,45 @@
toggleFormElements();
});
-
+
\ No newline at end of file
diff --git a/app/Views/customer_list.php b/app/Views/customer_list.php
index 55402c8..77a053c 100644
--- a/app/Views/customer_list.php
+++ b/app/Views/customer_list.php
@@ -33,7 +33,8 @@
Name
Mobile Number
Contributor Type
- Action
+
+ Action
@@ -52,6 +53,7 @@
= 'Organization'; ?>
+
" class="edit-button">
@@ -60,6 +62,7 @@
" class="delete-button">
+
diff --git a/app/Views/dashboard.php b/app/Views/dashboard.php
index 8359d10..336f256 100644
--- a/app/Views/dashboard.php
+++ b/app/Views/dashboard.php
@@ -5,17 +5,17 @@
-
+
- = $customer['active']; ?>
- = 'Available ' . $customer['label']; ?>
+ = $donordetails['active']; ?>
+ = 'Available ' . $donordetails['label']; ?>
- = $customer['total']; ?>
- = 'Total ' . $customer['label']; ?>
+ = $donordetails['total']; ?>
+ = 'Total ' . $donordetails['label']; ?>
- = $customer['today']; ?>
- = 'New ' . $customer['label']; ?>
+ = $donordetails['today']; ?>
+ = 'New ' . $donordetails['label']; ?>
diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php
index 11dea00..130e1ec 100644
--- a/app/Views/invoice_form.php
+++ b/app/Views/invoice_form.php
@@ -7,6 +7,26 @@
color: #ff0000;
/* Change to the desired hover color */
}
+ .spinner-overlay {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ background-color: rgba(255, 255, 255, 0.7);
+ display: none;
+ }
+
+ .spinner-overlay.active {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+
+ .spinner-border {
+ z-index: 1;
+ }
+
@@ -168,6 +188,9 @@
+
@@ -185,7 +208,7 @@
@@ -202,11 +225,11 @@
type: 'POST',
url: '= base_url("save_invoice"); ?>',
data: $(this).serialize(),
+ beforeSend: function() { $('.spinner-overlay').addClass('active'); },
success: function(response) {
if (response.success) {
$('#successModal').modal('show');
$('#downloadButton').attr('href', "= base_url('generate_invoice_pdf/'); ?>" + response.invoice_id);
-
} else {
// Handle errors or display a different modal for failure
console.log(response.message);
@@ -214,9 +237,17 @@
},
error: function(error) {
console.log('AJAX Error:', error);
- }
+ },
+ complete: function() { $('.spinner-overlay').removeClass('active'); }
});
});
+ $('#closeButton').on('click', function(e) {
+ e.preventDefault();
+ var url = "";
+ $('#successModal').modal('hide');
+ $('#receiptForm')[0].reset();
+ window.location.href = url;
+ });
});
@@ -225,7 +256,7 @@
var data = ;
var alldonors = ;
var editdata = ;
- var Rt = ;
+ var Rt = "";
$(function() {
if (Rt == 'organization') {
@@ -241,7 +272,7 @@
}
$('#donor_mobile').on('change', function() {
- var type = $('.receipt_type:checked').val();
+ var Rtype = $('.receipt_type:checked').val();
if ($(this).val()) {
if ($(this).val() == '0') {
$('#standard-modal').modal('show');
@@ -259,7 +290,7 @@
// Assuming `data` is an array of objects containing donor information
for (const donor of data) {
if (selectedMobile == donor.mobile_no) {
- if (type == "organization") {
+ if (Rtype == "organization") {
options += ``;
}else{
options += ``;
@@ -273,7 +304,7 @@
}
} else {
var selectedMobile = $(this).val();
- var type = $('.receipt_type:checked').val();
+ var Rtype = $('.receipt_type:checked').val();
var options = '';
if(role != 'accounts'){
options += '';
@@ -281,7 +312,7 @@
// Assuming `data` is an array of objects containing donor information
console.log(donor);
for (const donor of data) {
- if (type == "organization") {
+ if (Rtype == "organization") {
options += ``;
}else{
options += ``;
@@ -296,13 +327,13 @@
});
$('#donor_first_name').on('change', function() {
- var type = $('.receipt_type:checked').val();
+ var Rtype = $('.receipt_type:checked').val();
if ($(this).val() == '0') {
$('#standard-modal').modal('show');
} else {
$('#standard-modal').modal('hide');
$('#donor-form-submit').prop('disabled', false);
- if (type == "organization") {
+ if (Rtype == "organization") {
var selectedID = $(this).val();
var options = '';
if(role != 'accounts'){
@@ -332,7 +363,7 @@
$('#donor-form-submit').on('click', function() {
var form = $('#donorForm');
var isValid = form[0].checkValidity();
- var type = $('.receipt_type:checked').val();
+ var Rtype = $('.receipt_type:checked').val();
if (isValid) {
// If the form is valid, disable the button to prevent multiple clicks
@@ -367,7 +398,7 @@
value: v.mobile_no,text: v.mobile_no,
selected: (v.donor_id == response['data']['donor_id']) ? true : false
}));
- var dynamic = (type == 'organization') ? v.org_name+' - '+v.pan_no : v.first_name;
+ var dynamic = (Rtype == 'organization') ? v.org_name+' - '+v.pan_no : v.first_name;
$('#donor_first_name').append($('