From d6b2908dd33d77a6f0c75d6f67c971331e70cd49 Mon Sep 17 00:00:00 2001 From: heama Date: Tue, 3 Oct 2023 12:12:18 +0530 Subject: [PATCH] corrections in customer,user,invoice --- app/Controllers/Customer.php | 18 ++++- app/Controllers/Invoice.php | 71 ++++++++++------- app/Models/CustomerModel.php | 9 ++- app/Models/InvoiceModel.php | 1 + app/Models/SubscriptionModel.php | 9 ++- app/Views/customer_form.php | 132 +++++++++++++++++++++++++++---- app/Views/invoice_form.php | 52 +++++++++--- app/Views/template/header.php | 66 ++++++++-------- app/Views/user_form.php | 67 ++++++++++++---- 9 files changed, 322 insertions(+), 103 deletions(-) diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php index a2931183..0b76818c 100644 --- a/app/Controllers/Customer.php +++ b/app/Controllers/Customer.php @@ -3,6 +3,7 @@ namespace App\Controllers; use App\Models\CustomerModel; +use App\Models\SubscriptionModel; class Customer extends BaseController { @@ -38,22 +39,35 @@ class Customer extends BaseController helper('session'); $session_bid = get_business_id(); if ($id === '0') { + // Add Customer $data['page_name'] = 'Add Customer'; $data['customer'] = []; $data['customer_billing'] = []; $data['customer_shipping'] = []; + $data['subscriptionData'] = []; + $data['invoices'] = []; } else if ($id !== '0') { + // Edit Customer $data['page_name'] = 'Edit Customer'; + $subscriptionModel = new SubscriptionModel(); + $subscriptionData = $subscriptionModel->getSubscriptionsByCustomerId($id); $model = new CustomerModel(); $model->setTable('customers'); $edit_user_details = $model->where(['customer_id' => $id])->first(); $data['customer'] = $edit_user_details; - $data['customer_billing'] = $this->get_customer_address($id,1); - $data['customer_shipping'] = $this->get_customer_address($id,2); + $data['customer_billing'] = $this->get_customer_address($id, 1); + $data['customer_shipping'] = $this->get_customer_address($id, 2); + $data['subscriptionData'] = $subscriptionData; + + // Fetch invoice data for the customer + $CustomerModel = new CustomerModel(); + $invoices = $CustomerModel->getInvoicesByCustomerId($id); + $data['invoices'] = $invoices; } $data['session_bid'] = $session_bid; $this->render_page('customer_form', $data); } + ## For inserting/updating details of customer public function insert_customer() diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index 6fe26b8a..bb60f0e8 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -232,26 +232,26 @@ class Invoice extends BaseController } } // echo "
...................."; - $count = count($itemid); - $invoiceitem_arr = []; - if($count > 0){ - for ($x = 0; $x < $count; $x++) { - $invoiceitem_arr[$x]['invoice_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]; - $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); + $count = count($itemid); + $invoiceitem_arr = []; + if ($count > 0) { + for ($x = 0; $x < $count; $x++) { + $invoiceitem_arr[$x]['invoice_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]; + $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]; } - return $statement; + $statement = $model->saveInvoiceItemDetails($invoiceitem_arr); + } + return $statement; } ## To Retrive Invoice item details based on invoice ID @@ -275,17 +275,30 @@ class Invoice extends BaseController $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(); - $model->update($id, $data); - $getInvoiceItemDetails = $this->get_invoice_item($id); - if ($getInvoiceItemDetails) { - $update_where = ['invoice_id' => (int)$id]; - $model->updateData('invoiceitems', $data, $update_where); - } - } + 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 = ['invoice_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('invoice_list'); } diff --git a/app/Models/CustomerModel.php b/app/Models/CustomerModel.php index 8fa07ee0..b3ee3a4a 100644 --- a/app/Models/CustomerModel.php +++ b/app/Models/CustomerModel.php @@ -90,6 +90,13 @@ class CustomerModel extends Model $dataToUpdate = ['isactive' => 0]; $this->db->table('customer_addresses')->where($where)->whereIn('customer_address_id',$missingValues)->update($dataToUpdate); } - + public function getInvoicesByCustomerId($customer_id) +{ + return $this->db->table('invoice') + ->select('invoice_number, subtotal, invoice_date') + ->where('customer_id', $customer_id) + ->get() + ->getResult(); +} } ?> \ No newline at end of file diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index eed5dc03..017b9a30 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -116,6 +116,7 @@ public function updateData($table, $data, $where) ->get() ->getResult(); } + } diff --git a/app/Models/SubscriptionModel.php b/app/Models/SubscriptionModel.php index 4ab630fe..5992885e 100644 --- a/app/Models/SubscriptionModel.php +++ b/app/Models/SubscriptionModel.php @@ -147,7 +147,14 @@ public function getAllCustomerDetailsBySchemeName($schemeName) return $customerDetails; } - + public function getSubscriptionsByCustomerId($customerId) + { + $builder = $this->db->table('subscription'); + $builder->select('schemes.scheme_name,from_subscription,to_subscription'); + $builder->join('schemes', 'schemes.scheme_id = subscription.scheme_id'); + // Query to retrieve subscription records for a specific customer + return $builder->get()->getResultArray(); + } } diff --git a/app/Views/customer_form.php b/app/Views/customer_form.php index 7955c90d..3508f406 100644 --- a/app/Views/customer_form.php +++ b/app/Views/customer_form.php @@ -4,9 +4,34 @@

-
+ + + +
+ +
+ +
+ +
@@ -68,17 +95,19 @@
- +
Please provide.
- -
Please provide.
+ +
Please provide.
+
" class="btn btn-secondary waves-effect">Cancel
+ + + + + + + + +
-
-
+ +
+ + + + + + + + + + + + + + + + + + +
Subscription NameDurationAmount
+ +

No subscriptions found for this customer.

+ +
+
+ + + + + + + + + + + + + + + + + + + +
Invoice NumberInvoice DateSubtotal
invoice_number ?>invoice_date ?>subtotal ?>
+ +

No subscriptions found for this customer.

+ +
+
+ + + + + \ No newline at end of file diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index a3c4ae6c..0e5cde4a 100644 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -1,3 +1,13 @@ + + + + + +
@@ -9,7 +19,7 @@
- +
+
Please select customer.
-
+
Please select shipping address.
@@ -95,7 +108,7 @@ Rate Tax Amount - Discount + Discount Actions @@ -104,7 +117,7 @@ - @@ -205,6 +218,11 @@ readonly value="">
+
+ + +
+
@@ -223,7 +241,7 @@
- +
@@ -347,13 +365,13 @@ function calculateInvoice(inputElement) { if (discountType === '₹') { // Calculate discount based on ₹ var discountedAmount = amount - discountAmount; - row.querySelector('#amount').value = discountedAmount.toFixed(2); // Format to two decimal places + row.querySelector('#amount').value = amount.toFixed(2); } else if (discountType === '%') { // Calculate discount based on % var discountPercentage = discountAmount; var discountValue = (amount * discountPercentage) / 100; var discountedAmount = amount - discountValue; - row.querySelector('#amount').value = discountedAmount.toFixed(2); + row.querySelector('#amount').value = amount.toFixed(2); } else { // Invalid discount type row.querySelector('#amount').value = amount.toFixed(2); // No discount applied @@ -393,7 +411,15 @@ function calculateOverallTotals() { } }); - // Update the overall amount, tax, and discount in the calculation card + // Get the shipping charges value, tax, and discount values + var shippingCharges = parseFloat(document.getElementById('shippingCharges').value) || 0; + var tax = parseFloat($("#invoicetax").val()) || 0; + var discount = parseFloat($("#discount").val()) || 0; + + // Calculate the total using the formula: subtotal - tax + shipping - discount + var total = overallAmount - overallTax + shippingCharges - overallDiscount; + + // Update the subtotal, tax, shipping charges, discount, and total in the calculation card var subtotalElement = overallAmount.toFixed(2); $("#subtotal").val(subtotalElement); @@ -403,9 +429,11 @@ function calculateOverallTotals() { var discountElement = overallDiscount.toFixed(2); $("#discount").val(discountElement); - // Calculate the grand total using the overall amount, tax, and discount - calculateGrandTotal(overallAmount, overallTax, overallDiscount); + var totalElement = total.toFixed(2); + $("#grandtotal").val(totalElement); } + + // Define a function to calculate the grand total // Define a function to calculate the grand total function calculateGrandTotal() { @@ -698,3 +726,5 @@ $(document).ready(function() { document.getElementById('status').value = 'Approved'; }); + + diff --git a/app/Views/template/header.php b/app/Views/template/header.php index df679a7b..b8be13f2 100644 --- a/app/Views/template/header.php +++ b/app/Views/template/header.php @@ -116,18 +116,43 @@ Dashboard +
  • + "> + + Invoices + +
  • +
  • + "> + + Customer + +
  • +
  • + "> + + Subscription + +
  • +
  • + "> + + Scheme + +
  • +
  • + "> + + Products + +
  • "> Users
  • -
  • - "> - - Books - -
  • +
  • "> @@ -142,12 +167,7 @@ Business
  • -
  • - "> - - Customer - -
  • +
  • "> @@ -155,29 +175,13 @@ Campaign
  • -
  • - "> - - Invoices - -
  • - + -
  • - "> - - Scheme - -
  • -
  • - "> - - Subscription - -
  • + +
  • "> diff --git a/app/Views/user_form.php b/app/Views/user_form.php index 90802542..7b687106 100644 --- a/app/Views/user_form.php +++ b/app/Views/user_form.php @@ -38,10 +38,10 @@
  • - - - -
    + + +
    +
    @@ -51,16 +51,29 @@
    -
    - - + + +
    + + +
    + +
    + + +
    -
    - - - -
    -
    + + +
    @@ -135,4 +148,30 @@
    - \ No newline at end of file + +