corrections in customer,user,invoice

This commit is contained in:
heama 2023-10-03 12:12:18 +05:30
parent 3c42c1c089
commit d6b2908dd3
9 changed files with 322 additions and 103 deletions

View File

@ -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()

View File

@ -232,26 +232,26 @@ class Invoice extends BaseController
}
}
// echo "<br/>....................";
$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');
}

View File

@ -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();
}
}
?>

View File

@ -116,6 +116,7 @@ public function updateData($table, $data, $where)
->get()
->getResult();
}
}

View File

@ -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();
}
}

View File

@ -4,9 +4,34 @@
<div class="card-body">
<h4 class="header-title"><?= $page_name; ?></h4>
<p class="sub-header"> </p>
<form class="needs-validation" novalidate method="POST" enctype="multipart/form-data"
action="<?php echo base_url(); ?>insert_customer">
<ul class="nav nav-tabs" id="customerTabs" role="tablist">
<li class="nav-item">
<a class="nav-link" id="customerDetails-tab" data-toggle="tab" href="#customerDetails"
role="tab" aria-controls="customerDetails" aria-selected="true">Customer Details</a>
</li>
<?php if ($page_name === 'Edit Customer'): ?>
<li class="nav-item">
<a class="nav-link active" id="subscriptionDetails-tab" data-toggle="tab"
href="#subscriptionDetails" role="tab" aria-controls="subscriptionDetails"
aria-selected="false">Subscription Details</a>
</li>
<li class="nav-item">
<a class="nav-link" id="invoiceDetails-tab" data-toggle="tab" href="#invoiceDetails"
role="tab" aria-controls="invoiceDetails" aria-selected="false">Invoice Details</a>
</li>
<?php endif; ?>
</ul>
<div class="tab-content">
<!-- Customer Details Tab -->
<div class="tab-pane fade show active" id="customerDetails" role="tabpanel" aria-labelledby="customerDetails-tab">
<!-- Customer details form fields -->
<form class="needs-validation" novalidate method="POST" enctype="multipart/form-data"
action="<?php echo base_url(); ?>insert_customer">
<div class="form-group">
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="cfname" class="col-form-label">First Name<span
@ -58,9 +83,11 @@
</div>
<div class="form-group col-md-4">
<label for="gen" class="col-form-label">Gender<span class="text-danger">*</span></label>
<input type="rad" class="form-control" name="gen"
value="<?= isset($customer['gender']) ? $customer['gender'] : '' ?>"
placeholder="Gender" required />
<select class="form-control" name="gen" required>
<option> Select the Gender</option>
<option value="male" <?= isset($customer['gender']) && $customer['gender'] == 'male' ? 'selected' : '' ?>>Male</option>
<option value="female" <?= isset($customer['gender']) && $customer['gender'] == 'female' ? 'selected' : '' ?>>Female</option>
</select>
<div class="invalid-feedback"> Please provide. </div>
</div>
</div>
@ -68,17 +95,19 @@
<div class="form-row">
<div class="form-group col-md-6">
<label for="ctype" class="col-form-label">Type<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="ctype"
value="<?= isset($customer['type']) ? $customer['type'] : '' ?>"
placeholder="Customer/Subscriebr" required />
<select class="form-control" name="ctype" required>
<option value="customer" <?= isset($customer['type']) && $customer['type'] == 'customer' ? 'selected' : '' ?>>Customer</option>
<option value="subscriber" <?= isset($customer['type']) && $customer['type'] == 'subscriber' ? 'selected' : '' ?>>Subscriber</option>
</select>
<div class="invalid-feedback"> Please provide. </div>
</div>
<div class="form-group col-md-6">
<label for="cmode" class="col-form-label">Mode<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="cmode"
value="<?= isset($customer['mode']) ? $customer['mode'] : '' ?>"
placeholder="Mode (Online/Offline)" required />
<div class="invalid-feedback"> Please provide. </div>
<select class="form-control" name="cmode" required>
<option value="online" <?= isset($customer['mode']) && $customer['mode'] == 'online' ? 'selected' : '' ?>>Online</option>
<option value="offline" <?= isset($customer['mode']) && $customer['mode'] == 'offline' ? 'selected' : '' ?>>Offline</option>
</select>
<div class="invalid-feedback"> Please provide. </div>
</div>
</div>
<input type="hidden" id="customer_id" name="customer_id" placeholder="hidden for customer id"
@ -240,6 +269,7 @@
</div>
</div>
<div class="form-row">
<div class="form-group col-md-3">
<input type="hidden" id="scustomer_address_id" name="scustomer_address_id[]"
@ -273,10 +303,72 @@
<a href="<?= base_url() . "customer_list"; ?>"
class="btn btn-secondary waves-effect">Cancel</a>
</div>
<!-- Display Subscription Details -->
<!-- Add subscription details content here -->
<!-- You can fetch and display subscription details here -->
</form>
</div> <!-- end card-body-->
</div> <!-- end card-->
</div> <!-- end col-->
<div class="tab-pane fade show active" id="subscriptionDetails" role="tabpanel" aria-labelledby="subscriptionDetails-tab">
<?php if (!empty($subscriptionData)): ?>
<table class="table table-bordered">
<thead>
<tr>
<th>Subscription Name</th>
<th>Duration</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<?php foreach ($subscriptionData as $subscription): ?>
<tr>
<td><?= $subscription['scheme_name']; ?></td>
<td><?= $subscription['from_subscription']; ?></td>
<td><?= $subscription['to_subscription']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else : ?>
<p>No subscriptions found for this customer.</p>
<?php endif; ?>
</div>
<div class="tab-pane fade" id="invoiceDetails" role="tabpanel" aria-labelledby="invoiceDetails-tab">
<?php if (!empty($invoices)): ?>
<table class="table table-bordered">
<thead>
<tr>
<th>Invoice Number</th>
<th>Invoice Date</th>
<th>Subtotal</th>
</tr>
</thead>
<tbody>
<?php foreach ($invoices as $value): ?>
<tr>
<td><?= $value->invoice_number ?></td>
<td><?= $value->invoice_date ?></td>
<td><?= $value->subtotal ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else : ?>
<p>No subscriptions found for this customer.</p>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$("#copyToBillingCheckbox").on("change", function() {
@ -389,5 +481,17 @@
}
});
</script>
<script>
$(document).ready(function() {
// Show the Subscription Details tab by default
$('#subscriptionDetails-tab').tab('show');
// Handle tab switching
$('#customerTabs a').on('click', function (e) {
e.preventDefault();
$(this).tab('show');
});
});
</script>

View File

@ -1,3 +1,13 @@
<html>
<head>
<style>
.discount-header {
text-align: center; /* Add this to center-align the content */
}
</style>
</head>
<body>
<div class="row">
<div class="col-lg-12">
<div class="card">
@ -9,7 +19,7 @@
<div class="form-row">
<div class="form-group col-md-6">
<label for="customerName">Customer Name</label>
<select class="form-control" id="customerName" name="customer_name">
<select class="form-control" id="customerName" name="customer_name"required>
<option value="">Select a customer</option>
<?php foreach ($customers as $customer) : ?>
<option value="<?= $customer->customer_id ?>"
@ -17,13 +27,16 @@
<?= $customer->first_name.' '.$customer->last_name; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="invalid-feedback"> Please select customer. </div>
<div class="form-group col-md-6">
<label for="loadShippingDropdown">Shipping Address</label>
<select class="form-control" id="loadShippingDropdown" name="shipping_address_id">
<select class="form-control" id="loadShippingDropdown" name="shipping_address_id"required>
<option value="">Select an address</option>
</select>
</div>
<div class="invalid-feedback"> Please select shipping address. </div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
@ -95,7 +108,7 @@
<th>Rate</th>
<th>Tax</th>
<th>Amount </th>
<th colspan="2">Discount</th>
<th class="discount-header" colspan="2">Discount</th>
<th>Actions</th>
</tr>
</thead>
@ -104,7 +117,7 @@
<?php if(!empty($invoice_item_details)){ foreach ($invoice_item_details as $ii_details): ?>
<tr>
<td><select class="form-control" id="book" name="item_details[]"
onchange="displayBookTag(this)">
onchange="displayBookTag(this)"required>
<option value="">Select a book</option>
<?php foreach ($books as $book) : ?>
<option value="<?= $book->book_id ?>"
@ -159,7 +172,7 @@
id="tax" name="tax[]" /></td>
<td style="width:12%;"><input type="text" class="form-control item-amount"
id="amount" name="amount[]" /></td>
<td style="width:12%;"><input type="text"
<td class="discount-cell" style="width:12%;"><input type="text"
class="form-control item-discount-amount" name="discount_amount[]"
oninput="calculateInvoice(this)" />
@ -205,6 +218,11 @@
readonly
value="<?= isset($invoice_details['tax']) ? $invoice_details['tax'] : '' ?>">
</div>
<div class="form-group">
<label for="shippingCharges">Shipping Charges:</label>
<input type="number" class="form-control" id="shippingCharges" name="shippingCharges" oninput="calculateOverallTotals()">
</div>
<div class="form-group">
<label for="discount">Discount</label>
@ -223,7 +241,7 @@
</div>
<div class="form-row">
<div class="form-group text-left col-md-12 ">
<label for="terms">Terms & Conditions</label>
<label for="terms">Notes</label>
<textarea class="form-control" id="terms" name="terms"></textarea>
</div>
</div>
@ -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';
});
</script>
</body>
</html>

View File

@ -116,18 +116,43 @@
<span> Dashboard </span>
</a>
</li>
<li>
<a href="<?= base_url()."invoice_list"; ?>">
<i class="fe-file-text"></i>
<span> Invoices </span>
</a>
</li>
<li>
<a href="<?= base_url()."customer_list"; ?>">
<i class="ri-map-pin-user-fill"></i>
<span> Customer </span>
</a>
</li>
<li>
<a href="<?= base_url()."subscribers_list"; ?>">
<i class="ri-shield-user-line"></i>
<span>Subscription </span>
</a>
</li>
<li>
<a href="<?= base_url()."scheme_list"; ?>">
<i class="ri-currency-line"></i>
<span> Scheme </span>
</a>
</li>
<li>
<a href="<?= base_url()."book_list"; ?>">
<i class=" ri-book-open-line"></i>
<span> Products </span>
</a>
</li>
<li>
<a href="<?= base_url()."user_list"; ?>">
<i class="ri-user-line"></i>
<span> Users </span>
</a>
</li>
<li>
<a href="<?= base_url()."book_list"; ?>">
<i class=" ri-book-open-line"></i>
<span> Books </span>
</a>
</li>
<?php if($loggedin_person_role === 'sadmin'){ ?>
<li>
<a href="<?= base_url()."sitesetting_list"; ?>">
@ -142,12 +167,7 @@
<span> Business </span>
</a>
</li>
<li>
<a href="<?= base_url()."customer_list"; ?>">
<i class="ri-map-pin-user-fill"></i>
<span> Customer </span>
</a>
</li>
<li>
<a href="<?= base_url()."event_list"; ?>">
@ -155,29 +175,13 @@
<span> Campaign </span>
</a>
</li>
<li>
<a href="<?= base_url()."invoice_list"; ?>">
<i class="fe-file-text"></i>
<span> Invoices </span>
</a>
</li>
<li>
<a href="<?= base_url()."scheme_list"; ?>">
<i class="ri-currency-line"></i>
<span> Scheme </span>
</a>
</li>
<li>
<a href="<?= base_url()."subscribers_list"; ?>">
<i class="ri-shield-user-line"></i>
<span>Subscription </span>
</a>
</li>
<li>
<a href="<?= base_url()."mail_custom_notifications"; ?>">

View File

@ -38,10 +38,10 @@
<input data-parsley-type="alphanum" type="text" class="form-control" id="last_name" name="last_name" placeholder="Last Name" value="<?= isset($details['last_name']) ? $details['last_name'] : '' ?>" required />
</div>
<div class="form-group col-md-4">
<label for="date_of_birth" class="col-form-label">Date Of Birth<span class="text-danger"></span></label>
<input type="date" class="form-control" id="date_of_birth" name="date_of_birth" placeholder="Date Of birth (format : DD/MM/YYYY)" data-toggle="input-mask" data-mask-format="00/00/0000" value="<?= isset($details['date_of_birth']) ? $details['date_of_birth'] : '' ?>" />
</div>
<label for="date_of_birth" class="col-form-label">Date Of Birth<span class="text-danger">*</span></label>
<input type="date" class="form-control" id="date_of_birth" name="date_of_birth" placeholder="Date Of birth (format : DD/MM/YYYY)" data-toggle="input-mask" data-mask-format="00/00/0000" required />
</div>
</div>
<div class="form-row">
@ -51,16 +51,29 @@
</div>
<div class="form-group col-md-4">
<label for="gender" class="col-form-label">Gender</label>
<input type="text" class="form-control" id="gender" name="gender" placeholder="Gender" value="<?= isset($details['gender']) ? $details['gender'] : '' ?>" />
<!-- ... (other form elements) ... -->
<div class="form-group col-md-4">
<label for="gender" class="col-form-label">Gender<span class="text-danger">*</span></label>
<select id="gender" name="gender" class="form-control" required>
<option value="">Select Gender</option>
<option value="male" <?= isset($details['gender']) && $details['gender'] === 'male' ? 'selected' : '' ?>>Male</option>
<option value="female" <?= isset($details['gender']) && $details['gender'] === 'female' ? 'selected' : '' ?>>Female</option>
</select>
</div>
<div class="form-group col-md-4">
<label for="role" class="col-form-label">Role<span class="text-danger">*</span></label>
<select id="role" name="role" class="form-control" required>
<option value="">Select Role</option>
<option value="admin" <?= isset($details['role']) && $details['role'] === 'admin' ? 'selected' : '' ?>>Admin</option>
<option value="manager" <?= isset($details['role']) && $details['role'] === 'manager' ? 'selected' : '' ?>>Manager</option>
</select>
</div>
</div>
<div class="form-group col-md-4">
<label for="role" class="col-form-label">Role<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="role" name="role" placeholder="Role" required value="<?= isset($details['role']) ? $details['role'] : '' ?>" autofocus />
</div>
</div>
<!-- ... (rest of the form) ... -->
<div class="form-row">
<div class="form-group col-md-4">
<label for="address" class="col-form-label">Address<span class="text-danger">*</span></label>
@ -135,4 +148,30 @@
</div> <!-- end card-body-->
</div> <!-- end card-->
</div> <!-- end col-->
</div><!-- end row -->
</div><!-- end row -->
<script>
// Get the current date in "yyyy-mm-dd" format
function getCurrentDate() {
const today = new Date();
const year = today.getFullYear();
let month = today.getMonth() + 1;
let day = today.getDate();
// Add leading zeros if month or day is less than 10
if (month < 10) {
month = '0' + month;
}
if (day < 10) {
day = '0' + day;
}
return `${year}-${month}-${day}`;
}
// Set the max attribute of the date input field to the current date
document.getElementById('date_of_birth').setAttribute('max', getCurrentDate());
// Set the min attribute of the date input field to "1965-01-01"
document.getElementById('date_of_birth').setAttribute('min', '1965-01-01');
</script>