Merge branch 'uat' of bitbucket.org:venbainformationtechnology/vb_book into uat

This commit is contained in:
VE10-Sanjeev 2023-10-20 13:15:55 +05:30
commit 12f278c7ee
5 changed files with 910 additions and 716 deletions

View File

@ -144,6 +144,8 @@ class Invoice extends BaseController
$duedate = $this->request->getVar('due_date'); $duedate = $this->request->getVar('due_date');
$invdate = $this->request->getVar('invoice_date'); $invdate = $this->request->getVar('invoice_date');
$invoice_status = $this->request->getPost('status'); $invoice_status = $this->request->getPost('status');
// echo 'Hi';
// echo($this->request->getPost('invoice_number'));die();
$invoice_id = (!empty($this->request->getPost('invoice_id'))) ? $this->request->getPost('invoice_id') : ""; $invoice_id = (!empty($this->request->getPost('invoice_id'))) ? $this->request->getPost('invoice_id') : "";
$customer_id = (int)$this->request->getPost('customer_name'); $customer_id = (int)$this->request->getPost('customer_name');
$invoiceType = $this->request->getPost('invoice_type'); $invoiceType = $this->request->getPost('invoice_type');
@ -164,12 +166,13 @@ class Invoice extends BaseController
'discount' => (int)$this->request->getPost('discount'), 'discount' => (int)$this->request->getPost('discount'),
'total_amount' => (int)$this->request->getPost('grand_total'), 'total_amount' => (int)$this->request->getPost('grand_total'),
'shipping_charge' => (int)$this->request->getPost('shippingCharges'), 'shipping_charge' => (int)$this->request->getPost('shippingCharges'),
'shipping_label' =>$this->request->getPost('shippingChargesLabel'),
'order_number' => $this->request->getPost('order_number'), 'order_number' => $this->request->getPost('order_number'),
'payment_method' => 'Cash on Delivery', // "Credit Card," "Cash on Delivery," "PayPal","PayTm","Gpay" 'payment_method' =>$this->request->getPost('payment_method'), // "Credit Card," "Cash on Delivery," "PayPal","PayTm","Gpay"
'payment_status' => 'Pending', //"Paid," "Pending," "Failed," "Refunded," "Canceled," "Authorized," and "Completed." 'payment_status' => 'Pending', //"Paid," "Pending," "Failed," "Refunded," "Canceled," "Authorized," and "Completed."
'event_id' => (int)$this->request->getPost('event_id'), 'event_id' => (int)$this->request->getPost('event_id'),
'business_id' => (int)get_business_id(), 'business_id' => (int)get_business_id(),
'status' => $this->request->getPost('status'), 'status' => $this->request->getPost('saveas'),
'isactive' => 1 'isactive' => 1
]; ];
## Based on the invoice ID, we designated Insert or Update on Details... ## Based on the invoice ID, we designated Insert or Update on Details...
@ -522,7 +525,16 @@ class Invoice extends BaseController
$data = $model->getInvoiceData($id); $data = $model->getInvoiceData($id);
$invoiceItems = $model->getInvoiceItems($id); $invoiceItems = $model->getInvoiceItems($id);
$invoiceTerms= $model->getInvoiceData($id); $invoiceTerms= $model->getInvoiceData($id);
// print_r($invoiceTerms);die()
foreach($invoiceItems as $index => $singleItem)
{
$productImgs= $model->getProductImgs($singleItem->product);
$invoiceItems[$index]->imgs = $productImgs;
}
// print_r($invoiceItems);die();
$invoice_type = $data[0]->invoice_type; $invoice_type = $data[0]->invoice_type;
// print_r($invoiceItems);die(); // print_r($invoiceItems);die();

View File

@ -8,7 +8,7 @@ class InvoiceModel extends Model
protected $table = 'invoice'; protected $table = 'invoice';
protected $primaryKey = 'invoice_id'; protected $primaryKey = 'invoice_id';
// protected $allowedFields = ['invoice_id','invoice_number','customer_id','invoice_date','event_id','business_id','created_on','business_id']; // protected $allowedFields = ['invoice_id','invoice_number','customer_id','invoice_date','event_id','business_id','created_on','business_id'];
protected $allowedFields = ['invoice_id', 'invoice_number', 'customer_id','notes', 'invoice_date', 'due_date', 'subtotal', 'tax', 'discount', 'shipping_charge','total_amount', 'payment_status', 'order_number','invoice_type', 'payment_method', 'event_id', 'business_id', 'shipping_address_id', 'billing_address_id', 'created_on', 'created_by', 'updated_on', 'updated_by','category','isactive','billing_address','shipping_address','status']; protected $allowedFields = ['invoice_id', 'invoice_number', 'customer_id','notes', 'invoice_date', 'due_date', 'subtotal', 'tax', 'discount', 'shipping_charge','shipping_label','total_amount', 'payment_status', 'order_number','invoice_type', 'payment_method', 'event_id', 'business_id', 'shipping_address_id', 'billing_address_id', 'created_on', 'created_by', 'updated_on', 'updated_by','category','isactive','billing_address','shipping_address','status'];
public function saveInvoiceItemDetails($data){ public function saveInvoiceItemDetails($data){
$i = 0; $i = 0;
@ -125,15 +125,39 @@ public function updateData($table, $data, $where)
} }
// this function Also Used For Approve Notification. // this function Also Used For Approve Notification.
public function getInvoiceItems($id) public function getInvoiceItems($id)
{ {
return $this->db->table('invoiceitems') $data = $this->db->table('invoiceitems')
->where(['invoice_id' => $id, 'invoiceitems.isactive' => 1]) ->where(['invoice_id' => $id, 'invoiceitems.isactive' => 1])
->join('books as B', 'B.book_id = invoiceitems.product', 'left') ->join('books as B', 'B.book_id = invoiceitems.product', 'left')
->select('invoiceitems.*,B.title') // ->join('book_images as BI', 'BI.book_id = invoiceitems.product', 'left')
->select('invoiceitems.*,B.*')
//->orderBy("book_img_id", "asc") // Order by book_img_id in ascending order
//->limit(1,0)
->get() ->get()
->getResult(); ->getResult();
// print_r($this->db->getLastQuery());
return $data;
} }
public function getProductImgs($productId)
{
$data = $this->db->table('book_images')
->where(['book_id' => $productId])
// ->join('books as B', 'B.book_id = invoiceitems.product', 'left')
// ->join('book_images as BI', 'BI.book_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() public function getCategoryBooks()
{ {
return $this->db->table('books') return $this->db->table('books')

View File

@ -1,12 +1,15 @@
<html> <html>
<head> <head>
<style> <style>
.discount-header { .discount-header {
text-align: center; /* Add this to center-align the content */ text-align: center;
/* Add this to center-align the content */
} }
</style> </style>
</head> </head>
<body> <body>
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
@ -32,11 +35,11 @@
<div class="invalid-feedback"> Please select customer. </div> <div class="invalid-feedback"> Please select customer. </div>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="loadShippingDropdown">Shipping Address</label> <label for="loadShippingDropdown">Shipping Address</label>
<select class="form-control" id="loadShippingDropdown" name="shipping_address_id"required> <select class="form-control" id="loadShippingDropdown" name="shipping_address_id">
<option value="">Select an address</option> <option value="">Select an address</option>
</select> </select>
</div> </div>
<div class="invalid-feedback"> Please select shipping address. </div>
</div> </div>
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-6"> <div class="form-group col-md-6">
@ -45,12 +48,14 @@
<input type="hidden" id="hiddenBillingAddressId" name="billing_address_id" <input type="hidden" id="hiddenBillingAddressId" name="billing_address_id"
placeholder="hidden for billing address id" placeholder="hidden for billing address id"
value="<?= isset($invoice_details['billing_address_id']) ? $invoice_details['billing_address_id'] : '' ?>" /> value="<?= isset($invoice_details['billing_address_id']) ? $invoice_details['billing_address_id'] : '' ?>" />
<textarea class="form-control" id="storeBillingAddress" name="billing_address" rows="4" <textarea class="form-control" id="storeBillingAddress" name="billing_address"
rows="4"
readonly><?= isset($invoice_details['billing_address']) ? $invoice_details['billing_address'] : '' ?></textarea> readonly><?= isset($invoice_details['billing_address']) ? $invoice_details['billing_address'] : '' ?></textarea>
</div> </div>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="storeShippingAddress">Shipping Address</label> <label for="storeShippingAddress">Shipping Address</label>
<textarea class="form-control" id="storeShippingAddress" name="shipping_address" rows="4" <textarea class="form-control" id="storeShippingAddress" name="shipping_address"
rows="4"
readonly><?= isset($invoice_details['shipping_address']) ? $invoice_details['shipping_address'] : '' ?></textarea> readonly><?= isset($invoice_details['shipping_address']) ? $invoice_details['shipping_address'] : '' ?></textarea>
</div> </div>
</div> </div>
@ -101,12 +106,15 @@
<?php if ($invoice_type === '1'): ?> <?php if ($invoice_type === '1'): ?>
<label for="fromsubcription">From Subcription</label> <label for="fromsubcription">From Subcription</label>
<input type="date" class="form-control" id="fromsubcription" name="from_subscription" value="<?= isset($invoice_item_details[0]['from_subscription']) ? $invoice_item_details[0]['from_subscription'] : '' ?>"> <input type="date" class="form-control" id="fromsubcription"
name="from_subscription"
value="<?= isset($invoice_item_details[0]['from_subscription']) ? $invoice_item_details[0]['from_subscription'] : '' ?>">
</div> </div>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="tosubcription">To Subcription</label> <label for="tosubcription">To Subcription</label>
<input type="date" class="form-control" id="to_subcription" name="to_subscription"value="<?= isset($invoice_item_details[0]['to_subscription']) ? $invoice_item_details[0]['to_subscription'] : '' ?>"> <input type="date" class="form-control" id="to_subcription" name="to_subscription"
value="<?= isset($invoice_item_details[0]['to_subscription']) ? $invoice_item_details[0]['to_subscription'] : '' ?>">
<?php endif; ?> <?php endif; ?>
</div> </div>
</div> </div>
@ -142,30 +150,43 @@
<?php endforeach; ?> <?php endforeach; ?>
</select></td> </select></td>
<td style="width:10%;"><input type="number" class="form-control" <td style="width:10%;"><input type="number" class="form-control"
id="quantity" name="quantity[]" oninput="calculateInvoice(this)" value="<?= isset($ii_details['product']) ? $ii_details['quantity'] : '' ?>" /> id="quantity" name="quantity[]" oninput="calculateInvoice(this)"
value="<?= isset($ii_details['product']) ? $ii_details['quantity'] : '' ?>" />
</td> </td>
<td style="width:10%;"><input type="text" class="form-control" id="rate" <td style="width:10%;"><input type="text" class="form-control" id="rate"
name="rate[]" oninput="calculateInvoice(this)" value="<?= isset($ii_details['unit_price']) ? $ii_details['unit_price'] : '' ?>" /></td> name="rate[]" oninput="calculateInvoice(this)"
value="<?= isset($ii_details['unit_price']) ? $ii_details['unit_price'] : '' ?>" />
</td>
<td style="width:5%;"><input type="text" class="form-control item-tax" <td style="width:5%;"><input type="text" class="form-control item-tax"
id="tax" name="tax[]" value="<?= isset($ii_details['tax']) ? $ii_details['tax'] : '' ?>" /></td> id="tax" name="tax[]"
<td style="width:12%;"><input type="text" class="form-control item-amount" value="<?= isset($ii_details['tax']) ? $ii_details['tax'] : '' ?>" />
id="amount" name="amount[]" value="<?= isset($ii_details['subtotal']) ? $ii_details['subtotal'] : '' ?>" /></td> </td>
<td style="width:12%;"><input type="text" <td style="width:12%;"><input type="text"
class="form-control item-discount-amount" name="discount_amount[]" class="form-control item-amount" id="amount" name="amount[]"
oninput="calculateInvoice(this)" value="<?= isset($ii_details['discount_amount']) ? $ii_details['discount_amount'] : '' ?>" /> value="<?= isset($ii_details['subtotal']) ? $ii_details['subtotal'] : '' ?>" />
</td>
<td style="width:12%;"><input type="text"
class="form-control item-discount-amount"
name="discount_amount[]" oninput="calculateInvoice(this)"
value="<?= isset($ii_details['discount_amount']) ? $ii_details['discount_amount'] : '' ?>" />
</td> </td>
<td style="width:10%;"> <td style="width:10%;">
<select class="form-control item-discount-type" name="discount_type[]" <select class="form-control item-discount-type"
oninput="calculateInvoice(this)"> name="discount_type[]" oninput="calculateInvoice(this)">
<option value="" <?php if (isset($ii_details['discount_type']) && $ii_details['discount_type'] === '₹') echo "selected"; ?>>₹</option> <option value=""
<option value="%" <?php if (isset($ii_details['discount_type']) && $ii_details['discount_type'] === '%') echo "selected"; ?>>%</option> <?php if (isset($ii_details['discount_type']) && $ii_details['discount_type'] === '₹') echo "selected"; ?>>
</option>
<option value="%"
<?php if (isset($ii_details['discount_type']) && $ii_details['discount_type'] === '%') echo "selected"; ?>>
%</option>
</select> </select>
</td> </td>
<td><input type="hidden" class="form-control" id="hiddenInvoiceChildId" <td><input type="hidden" class="form-control" id="hiddenInvoiceChildId"
name="invoice_child_id[]" value="" name="invoice_child_id[]" value=""
placeholder="hidden for invoice child/item id" value="<?= isset($ii_details['invoice_child_id']) ? $ii_details['invoice_child_id'] : '' ?>" /> placeholder="hidden for invoice child/item id"
value="<?= isset($ii_details['invoice_child_id']) ? $ii_details['invoice_child_id'] : '' ?>" />
<center><i class="fa fa-trash remove-item "></i></center> <center><i class="fa fa-trash remove-item "></i></center>
</td> </td>
</tr> </tr>
@ -176,26 +197,29 @@
name="item_details[]" onchange="displayBookTag(this)"> name="item_details[]" onchange="displayBookTag(this)">
<option value="">Select a book</option> <option value="">Select a book</option>
<?php foreach ($books as $book) : ?> <?php foreach ($books as $book) : ?>
<option value="<?= $book->book_id ?>"><?= $book->title ?></option> <option value="<?= $book->book_id ?>"><?= $book->title ?>
</option>
<?php endforeach; ?> <?php endforeach; ?>
</select></td> </select></td>
<td style="width:10%;"><input type="number" class="form-control" <td style="width:10%;"><input type="number" class="form-control"
id="quantity" name="quantity[]" oninput="calculateInvoice(this)" /> id="quantity" name="quantity[]"
oninput="calculateInvoice(this)" />
</td> </td>
<td style="width:10%;"><input type="text" class="form-control" id="rate" <td style="width:10%;"><input type="text" class="form-control" id="rate"
name="rate[]" oninput="calculateInvoice(this)" /></td> name="rate[]" oninput="calculateInvoice(this)" /></td>
<td style="width:5%;"><input type="text" class="form-control item-tax" <td style="width:5%;"><input type="text" class="form-control item-tax"
id="tax" name="tax[]" /></td> id="tax" name="tax[]" /></td>
<td style="width:12%;"><input type="text" class="form-control item-amount" <td style="width:12%;"><input type="text"
id="amount" name="amount[]" /></td> class="form-control item-amount" id="amount" name="amount[]" />
</td>
<td class="discount-cell" 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[]" class="form-control item-discount-amount"
oninput="calculateInvoice(this)" /> name="discount_amount[]" oninput="calculateInvoice(this)" />
</td> </td>
<td style="width:10%;"> <td style="width:10%;">
<select class="form-control item-discount-type" name="discount_type[]" <select class="form-control item-discount-type"
oninput="calculateInvoice(this)"> name="discount_type[]" oninput="calculateInvoice(this)">
<option value=""></option> <option value=""></option>
<option value="%">%</option> <option value="%">%</option>
</select> </select>
@ -228,7 +252,8 @@
<h4>Calculation</h4> <h4>Calculation</h4>
<div class="form-group"> <div class="form-group">
<label for="subtotal">Subtotal</label> <label for="subtotal">Subtotal</label>
<input type="text" class="form-control" id="subtotal" name="sub_total" readonly <input type="text" class="form-control" id="subtotal" name="sub_total"
readonly
value="<?= isset($invoice_details['subtotal']) ? $invoice_details['subtotal'] : '' ?>"> value="<?= isset($invoice_details['subtotal']) ? $invoice_details['subtotal'] : '' ?>">
</div> </div>
<div class="form-group"> <div class="form-group">
@ -237,12 +262,36 @@
readonly readonly
value="<?= isset($invoice_details['tax']) ? $invoice_details['tax'] : '' ?>"> value="<?= isset($invoice_details['tax']) ? $invoice_details['tax'] : '' ?>">
</div> </div>
<?php
// Check if it's a subscription invoice
$isSubscriptionInvoice = ($page_name === 'Add Subscription Invoice Details' || $page_name === 'Edit Subscription Invoice Details');
// Conditionally set the "hidden" attribute for the fields
$balanceHidden = $isSubscriptionInvoice ? 'hidden' : '';
$paidAmountHidden = $isSubscriptionInvoice ? 'hidden' : '';
$shippingChargesHidden = $isSubscriptionInvoice ? 'hidden' : '';
$balanceStyle = $isSubscriptionInvoice ? 'display: none;' : '';
$paidAmountStyle = $isSubscriptionInvoice ? 'display: none;' : '';
$shippingChargesStyle = $isSubscriptionInvoice ? 'display: none;' : '';
?>
<div class="form-group"> <div class="form-group">
<label for="shippingCharges">Shipping Charges:</label> <span style="<?= $shippingChargesStyle ?>">
<input type="number" class="form-control" id="shippingCharges" name="shippingCharges" oninput="calculateOverallTotals()">
<input type="text" class="form-control" id="shippingChargesLabel"
name="shippingChargesLabel" placeholder="Shipping Charges Label"
value="Shipping Charge" oninput="calculateOverallTotals()"
<?= $shippingChargesHidden ?>>
</span>
<span style="<?= $shippingChargesStyle ?>">
<input type="text" class="form-control" id="shippingCharges"
name="shippingCharges" placeholder="Shipping Charges"
oninput="calculateOverallTotals()" <?= $shippingChargesHidden ?>>
</span>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="discount">Discount</label> <label for="discount">Discount</label>
<input type="number" class="form-control" id="discount" name="discount" <input type="number" class="form-control" id="discount" name="discount"
@ -255,6 +304,22 @@
readonly readonly
value="<?= isset($invoice_details['total_amount']) ? $invoice_details['total_amount'] : '' ?>"> value="<?= isset($invoice_details['total_amount']) ? $invoice_details['total_amount'] : '' ?>">
</div> </div>
<div class="form-group">
<label for="balanceAmount" style="<?= $balanceStyle ?>">Balance
Amount:</label>
<input type="number" class="form-control" id="balanceAmount"
name="balanceAmount"
value="<?= (isset($invoice_details['status']) && $invoice_details['status'] === 'Draft') ? (isset($invoice_details['total_amount']) ? $invoice_details['total_amount'] : '') : '0' ?>"
oninput="calculateOverallTotals()" <?= $balanceHidden ?>>
</div>
<div class="form-group">
<label for="paidAmount" style="<?= $paidAmountStyle ?>">Paid Amount:</label>
<input type="number" class="form-control" id="paidAmount" name="paidAmount"
value="<?= (isset($invoice_details['status']) && $invoice_details['status'] === 'Approved') ? (isset($invoice_details['total_amount']) ? $invoice_details['total_amount'] : '') : '0' ?>"
oninput="calculateOverallTotals()" <?= $paidAmountHidden ?>>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -267,27 +332,65 @@
</div> </div>
</div> </div>
</div> </div>
<div class="modal fade" id="paymentModal" tabindex="-1" role="dialog"
aria-labelledby="paymentModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="paymentModalLabel">Select Mode of Payment</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<!-- Add your mode of payment options here -->
<select class="form-control" id="paymentMode" name="payment_method">
<option value="credit">Credit Card</option>
<option value="debit">Debit Card</option>
<option value="cash">Cash</option>
<option value="upi">UPI</option>
<option value="banktransfer">Bank Transfer</option>
<!-- Add more options as needed -->
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary"
data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="saveas" value="Approved"
id="saveapproved">Save as Approved</button>
</div>
</div>
</div>
</div>
<input type="hidden" id="status" name="status"
value="<?= isset($invoice_details['status']) ? $invoice_details['status'] : '' ?>">
<input type="hidden" id="hiddenInvoiceId" name="invoice_id" placeholder="hidden for invoice id" <input type="hidden" id="hiddenInvoiceId" name="invoice_id" placeholder="hidden for invoice id"
value="<?= isset($invoice_details['invoice_id']) ? $invoice_details['invoice_id'] : '' ?>" /> value="<?= isset($invoice_details['invoice_id']) ? $invoice_details['invoice_id'] : '' ?>" />
<div class="form-group text-right m-b-0"> <div class="form-group text-right m-b-0">
<?php if (!isset($invoice_details['status']) || $invoice_details['status'] !== 'Approved'): ?> <?php if (!isset($invoice_details['status']) || $invoice_details['status'] !== 'Approved'): ?>
<!-- Show the "Save as Draft" button only if the status is not "Approved" --> <!-- Show the "Save as Draft" button only if the status is not "Approved" -->
<button type="submit" class="btn btn-primary waves-effect mr-1" name="save_as_draft" id="saveDraftButton">Save as Draft</button> <button type="submit" class="btn btn-primary waves-effect mr-1" name="saveas" value="Draft"
id="saveDraftButton">Save as Draft</button>
<?php endif; ?> <?php endif; ?>
<?php if (!isset($invoice_details['status']) || $invoice_details['status'] !== 'Approved'): ?> <?php if (!isset($invoice_details['status']) || $invoice_details['status'] !== 'Approved'): ?>
<!-- Show the "Save as Approved" button only if the status is not "Approved" --> <!-- Show the "Save as Approved" button only if the status is not "Approved" -->
<button type="submit" class="btn btn-primary waves-effect mr-1" name="save_as_approved" id="saveApprovedButton">Save as Approved</button> <button type="button" class="btn btn-primary waves-effect mr-1" name="saveas"
value="Approved" id="saveApprovedButton">Save as Approved</button>
<?php endif; ?> <?php endif; ?>
<input type="hidden" name="invoice_type" value="<?php echo ($page_name === 'Add Subscription Invoice Details' || $page_name === 'Edit Subscription Invoice Details') ? '1' : '2'; ?>"> <input type="hidden" name="invoice_type"
<input type="hidden" id="status" name="status" value="<?= isset($invoice_details['status']) ? $invoice_details['status'] : '' ?>"> value="<?php echo ($page_name === 'Add Subscription Invoice Details' || $page_name === 'Edit Subscription Invoice Details') ? '1' : '2'; ?>">
<input type="hidden" id="status" name="status"
value="<?= isset($invoice_details['status']) ? $invoice_details['status'] : '' ?>">
</div> </div>
</div> </div>
</form> </form>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<script> <script>
document.getElementById("addItem").addEventListener("click", function() { document.getElementById("addItem").addEventListener("click", function() {
var bookArray = <?php echo json_encode($books); ?>; var bookArray = <?php echo json_encode($books); ?>;
@ -326,13 +429,18 @@ document.getElementById("addItem").addEventListener("click", function() {
}); });
cell1.appendChild(select); cell1.appendChild(select);
// cell1.innerHTML = '<input type="text" class="form-control" name="item_details[]">'; // cell1.innerHTML = '<input type="text" class="form-control" name="item_details[]">';
cell2.innerHTML = '<input type="number" class="form-control" id="quantity" name="quantity[]" oninput="calculateInvoice(this)">'; cell2.innerHTML =
cell3.innerHTML = '<input type="text" class="form-control" id="rate" name="rate[]" oninput="calculateInvoice(this)">'; '<input type="number" class="form-control" id="quantity" name="quantity[]" oninput="calculateInvoice(this)">';
cell3.innerHTML =
'<input type="text" class="form-control" id="rate" name="rate[]" oninput="calculateInvoice(this)">';
cell4.innerHTML = '<input type="text" class="form-control item-tax" id="tax" name="tax[]">'; cell4.innerHTML = '<input type="text" class="form-control item-tax" id="tax" name="tax[]">';
cell5.innerHTML = '<input type="text" class="form-control item-amount" id="amount" name="amount[]">'; cell5.innerHTML = '<input type="text" class="form-control item-amount" id="amount" name="amount[]">';
cell6.innerHTML = '<input type="text" class="form-control item-discount-amount" name="discount_amount[]">'; cell6.innerHTML =
cell7.innerHTML = '<select class="form-control item-discount-type" name="discount_type[]" oninput="calculateInvoice(this)"><option value="₹">₹</option><option value="%">%</option></select>'; '<input type="text" class="form-control item-discount-amount" name="discount_amount[]">';
cell8.innerHTML = '<input type="hidden" class="form-control" id="hiddenInvoiceChildId" placeholder="hidden for invoice child/item id" name="invoice_child_id[]" value=""><center><i class="fa fa-trash remove-item "></center>'; cell7.innerHTML =
'<select class="form-control item-discount-type" name="discount_type[]" oninput="calculateInvoice(this)"><option value="₹">₹</option><option value="%">%</option></select>';
cell8.innerHTML =
'<input type="hidden" class="form-control" id="hiddenInvoiceChildId" placeholder="hidden for invoice child/item id" name="invoice_child_id[]" value=""><center><i class="fa fa-trash remove-item "></center>';
// Attach the calculateInvoice function to new input fields' change events // Attach the calculateInvoice function to new input fields' change events
// cell1.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice); // cell1.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice);
@ -452,8 +560,20 @@ function calculateOverallTotals() {
var totalElement = total.toFixed(2); var totalElement = total.toFixed(2);
$("#grandtotal").val(totalElement); $("#grandtotal").val(totalElement);
var status = document.getElementById('status').value;
// $("#balanceAmount").val(totalElement);
if (status == 'Draft') {
$("#balanceAmount").val(totalElement);
$("#paidAmount").val('0');
} else if (status == 'Approved') {
$("#balanceAmount").val('0');
$("#paidAmount").val(totalElement);
} }
}
// Define a function to calculate the grand total // Define a function to calculate the grand total
// Define a function to calculate the grand total // Define a function to calculate the grand total
@ -465,7 +585,8 @@ function calculateGrandTotal() {
rows.forEach(function(row) { rows.forEach(function(row) {
var item = { var item = {
subtotal: parseFloat(row.querySelector("#amount").value) || 0, subtotal: parseFloat(row.querySelector("#amount").value) || 0,
discount_amount: parseFloat(row.querySelector('input[name="discount_amount[]"]').value) || 0, discount_amount: parseFloat(row.querySelector('input[name="discount_amount[]"]').value) ||
0,
discount_type: row.querySelector('select[name="discount_type[]"]').value discount_type: row.querySelector('select[name="discount_type[]"]').value
}; };
invoiceItems.push(item); // Add the item to the array invoiceItems.push(item); // Add the item to the array
@ -584,7 +705,8 @@ document.querySelector("#itemTable tbody").addEventListener("click", function(ev
$(document).ready(function() { $(document).ready(function() {
var iid_arr = <?php echo json_encode($invoice_item_details); ?>; var iid_arr = <?php echo json_encode($invoice_item_details); ?>;
var cust_id = "<?= isset($invoice_details['customer_id']) ? $invoice_details['customer_id'] : ""; ?>"; var cust_id = "<?= isset($invoice_details['customer_id']) ? $invoice_details['customer_id'] : ""; ?>";
var ship_addr = "<?= isset($invoice_details['shipping_address']) ? $invoice_details['shipping_address'] : ""; ?>"; var ship_addr =
"<?= isset($invoice_details['shipping_address']) ? $invoice_details['shipping_address'] : ""; ?>";
var ship_addr_id = var ship_addr_id =
"<?= isset($invoice_details['shipping_address_id']) ? $invoice_details['shipping_address_id'] : ""; ?>"; "<?= isset($invoice_details['shipping_address_id']) ? $invoice_details['shipping_address_id'] : ""; ?>";
var bill_addr = var bill_addr =
@ -644,7 +766,9 @@ $(document).ready(function() {
customer_billing = ""; customer_billing = "";
if (cb.length > 0) { if (cb.length > 0) {
$.each(cb, function(k, v) { $.each(cb, function(k, v) {
customer_billing = v.address_1 + " " + v.address_2 + ",\n" + v.city + ",\n" + v.state + " - "+v.postal_code+",\n"+ v.country +"." customer_billing = v.address_1 + " " + v.address_2 + ",\n" + v
.city + ",\n" + v.state + " - " + v.postal_code + ",\n" + v
.country + "."
customer_billing_id = v.customer_address_id customer_billing_id = v.customer_address_id
}); });
} }
@ -675,7 +799,8 @@ $(document).ready(function() {
$('#loadShippingDropdown').append($('<option>', { $('#loadShippingDropdown').append($('<option>', {
value: v.customer_address_id, value: v.customer_address_id,
text: v.address, text: v.address,
selected: (v.customer_address_id == ship_addr_id) ? selected: (v.customer_address_id ==
ship_addr_id) ?
true : false true : false
})); }));
@ -702,7 +827,9 @@ $(document).ready(function() {
customer_shipping = ""; customer_shipping = "";
if (cs.length > 0) { if (cs.length > 0) {
$.each(cs, function(k, v) { $.each(cs, function(k, v) {
customer_shipping = v.address_1 + " " + v.address_2 + ",\n" + v.city + ",\n" + v.state + " - "+v.postal_code+",\n"+ v.country +"." customer_shipping = v.address_1 + " " + v.address_2 + ",\n" + v
.city + ",\n" + v.state + " - " + v.postal_code + ",\n" + v
.country + "."
}); });
} }
// console.log(customer_shipping); // console.log(customer_shipping);
@ -735,13 +862,8 @@ $(document).ready(function() {
}); });
</script> </script>
<script> <script>
document.getElementById('saveDraftButton').addEventListener('click', function () { document.getElementById('saveapproved').addEventListener('click', function() {
// Set the status field to 'Draft' before submitting // Set the status field to 'Draft' before submitting
document.getElementById('status').value = 'Draft';
});
document.getElementById('saveApprovedButton').addEventListener('click', function () {
// Set the status field to 'Approved' before submitting
document.getElementById('status').value = 'Approved'; document.getElementById('status').value = 'Approved';
}); });
</script> </script>
@ -752,12 +874,13 @@ const invoiceDateInput = document.getElementById("invoiceDate");
// Get the current date // Get the current date
const currentDate = new Date(); const currentDate = new Date();
// Set the minimum date attribute to today's date (YYYY-MM-DD format) // Calculate the min and max date strings
const minDate = currentDate.toISOString().split("T")[0]; const minDate = "YYYY-MM-DD"; // Replace with your desired minimum date
const maxDate = currentDate.toISOString().split("T")[0]; // Today's date in YYYY-MM-DD format
// Set the min and max date attributes
invoiceDateInput.setAttribute("min", minDate); invoiceDateInput.setAttribute("min", minDate);
invoiceDateInput.setAttribute("max", maxDate);
// Optional: Set the default value to today's date
</script> </script>
<script> <script>
@ -776,6 +899,34 @@ invoiceDateInput.setAttribute("min", minDate);
}); });
</script> </script>
<script>
// When the "Save as Approved" button is clicked
document.getElementById('saveApprovedButton').addEventListener('click', function() {
// Show the payment modal
$('#paymentModal').modal('show');
// When the "Confirm Payment" button in the modal is clicked
// Get the selected mode of payment
var selectedPaymentMode = document.getElementById('paymentMode').value;
// You can now use the selected payment mode as needed
console.log('Selected Payment Mode: ' + selectedPaymentMode);
// Close the modal
$('#paymentModal').modal('hide');
});
</script>
<script>
document.getElementById('saveapproved').addEventListener('click', function() {
// Get the balance amount
var balanceAmount = parseFloat(document.getElementById('balanceAmount').value) || 0;
// Replicate the balance amount value to the paid amount
document.getElementById('paidAmount').value = balanceAmount;
});
</script>
</body> </body>
</html> </html>

View File

@ -5,10 +5,10 @@
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<div class="float-right"> <div class="float-right">
<a href="#" id="addNewButton" class="btn btn-primary"><i class="fe-file-text"></i> Add New </a> <a href="new_book_invoice/0" class="btn btn-primary"><i class="ri-currency-line"></i> Add New </a>
<!-- HTML for the "Add New" button --> <!-- HTML for the "Add New" button -->
<div id="standard-modal" > <!-- <div id="standard-modal" >
<div id="invoiceTypeModal" class="modal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"> <div id="invoiceTypeModal" class="modal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm"> <div class="modal-dialog modal-sm">
@ -28,11 +28,9 @@
<div class="modal-footer"> <div class="modal-footer">
<button id="confirmInvoiceType">Continue</button> <button id="confirmInvoiceType">Continue</button>
</div> </div>
</div><!-- /.modal-content --> </div>< /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
</div> </div>
<br> <br>
<h4 class="header-title mb-3"><?= $page_name; ?></h4> <h4 class="header-title mb-3"><?= $page_name; ?></h4>

View File

@ -237,6 +237,7 @@ if (count($invoiceDateParts) === 3) {
<table class="invoice-related-table"> <table class="invoice-related-table">
<thead> <thead>
<tr> <tr>
<th>Image</th>
<th>Item Name</th> <th>Item Name</th>
<th>Qty</th> <th>Qty</th>
<th>Rate</th> <th>Rate</th>
@ -248,6 +249,14 @@ if (count($invoiceDateParts) === 3) {
<tbody> <tbody>
<?php foreach ($invoiceItems as $item) : ?> <?php foreach ($invoiceItems as $item) : ?>
<tr> <tr>
<td>
<?php if (!empty($item->imgs[0]->wp_img_url)) : ?>
<img src="<?= $item->imgs[0]->wp_img_url?>" alt="Product Image"style="max-width: 50px; max-height: 30px;">
<?php else : ?>
<img src="<?= base_url('public/uploads/' . $item->imgs[0]->img_name) ?>" alt="Fallback Image"style="max-width: 50px; max-height: 30px;">
<?php endif; ?>
</td>
<td><?= $item->title ?></td> <td><?= $item->title ?></td>
<td><?= $item->quantity ?></td> <td><?= $item->quantity ?></td>
<td><?= number_format($item->unit_price, 2, '.', ',') ?></td> <td><?= number_format($item->unit_price, 2, '.', ',') ?></td>
@ -276,7 +285,7 @@ if (count($invoiceDateParts) === 3) {
<td colspan="5" align="right">Discount : &nbsp;&nbsp;<?= number_format($value->discount, 2, '.', ',') ?></td> <td colspan="5" align="right">Discount : &nbsp;&nbsp;<?= number_format($value->discount, 2, '.', ',') ?></td>
</tr> </tr>
<tr> <tr>
<td colspan="5" align="right">Shipping : &nbsp;&nbsp;<?= number_format($value->shipping_charge, 2, '.', ',') ?></td> <td colspan="5" align="right"><?= $value->shipping_label?> : &nbsp;&nbsp;₹<?= number_format($value->shipping_charge, 2, '.', ',') ?></td>
</tr> </tr>
<tr> <tr>
<td colspan="5" align="right">Total : &nbsp;&nbsp;<?= number_format($value->subtotal, 2, '.', ',') ?></td> <td colspan="5" align="right">Total : &nbsp;&nbsp;<?= number_format($value->subtotal, 2, '.', ',') ?></td>