FIX_Validation implemented In forms
This commit is contained in:
parent
f0415c7359
commit
99cb6327a6
@ -62,6 +62,17 @@ class Event extends BaseController
|
||||
public function insert_event()
|
||||
{
|
||||
$this->logger->info("Event: Inserting/Updating Details");
|
||||
$validationRules = [
|
||||
'ename' => 'required'
|
||||
];
|
||||
|
||||
if (!$this->validate($validationRules)) {
|
||||
$validation = \Config\Services::validation();
|
||||
$errorMessage = $validation->getErrors();
|
||||
$firstError = reset($errorMessage);
|
||||
return redirect()->back()->with('error', $firstError)->withInput();
|
||||
}
|
||||
|
||||
try {
|
||||
helper('session');
|
||||
$session_bid = get_business_id();
|
||||
|
||||
@ -20,16 +20,16 @@ class Subscription extends BaseController
|
||||
|
||||
if (!empty($session_role) && $session_role !== "sadmin") {
|
||||
$this->logger->info("Invoice: Listing In Admin BID = " . $session_bid);
|
||||
$where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1,'I.invoice_type'=>2];
|
||||
$where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1,'I.invoice_type'=>2,'S.invoice_id !='=>"",'S.sub_id !='=>""];
|
||||
} else {
|
||||
$this->logger->info("Invoice: Listing In the Super-Admin ");
|
||||
$where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL,'I.invoice_type'=>2];
|
||||
$where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL,'I.invoice_type'=>2,'S.invoice_id !='=>"",'S.sub_id !='=>""];
|
||||
}
|
||||
|
||||
$model = new InvoiceModel();
|
||||
$data['page_name'] = 'Subscription Invoice Details';
|
||||
$data['invoice'] = $model->getSubscriptionInvoiceDetail($where);
|
||||
|
||||
|
||||
$this->logger->info("Invoice: Listing Count ." . count($data['invoice']));
|
||||
$data['active_schemes'] = $model->getActiveSchemes();
|
||||
|
||||
@ -70,6 +70,22 @@ public function add_subscription() {
|
||||
$session_bid = get_business_id();
|
||||
$session_uid = get_logged_user_id();
|
||||
|
||||
$validationRules = [
|
||||
'customer_name' => 'required',
|
||||
'from_subscription' => 'required',
|
||||
'to_subscription' => 'required',
|
||||
'shipping_address_id' => 'required',
|
||||
'invoice_date' => 'required|valid_date',
|
||||
'scheme' => 'required'
|
||||
];
|
||||
|
||||
if (!$this->validate($validationRules)) {
|
||||
$validation = \Config\Services::validation();
|
||||
$errorMessage = $validation->getErrors();
|
||||
$firstError = reset($errorMessage);
|
||||
return redirect()->back()->with('error', $firstError)->withInput();
|
||||
}
|
||||
|
||||
$SubscriptionModel = new SubscriptionModel();
|
||||
$data = [
|
||||
'scheme_id' =>$this->request->getPost('scheme'),
|
||||
|
||||
@ -104,7 +104,7 @@ class HomeModel extends Model
|
||||
$query = $this->db->table('subscription AS S')
|
||||
->select('S.business_id, BK.title as name, BK.short_code, BK.book_id as id, S.scheme_id, LEFT(BK.title, 1) AS first_letter, COUNT(S.customer_id) AS count, BI.wp_img_url')
|
||||
->select('COUNT(S.customer_id) AS overall, COUNT(IF(S.isactive = 1, S.customer_id, NULL)) AS activeoverall, COUNT(IF(S.is_renew = 0 AND S.isactive = 1, S.customer_id, NULL)) AS nonrenewal, COUNT(IF(S.is_renew = 1 AND S.isactive = 1, S.customer_id, NULL)) AS renewal, SUM(CASE WHEN S.created_on >= NOW() - INTERVAL 30 DAY THEN 1 ELSE 0 END) AS new_subscribers')
|
||||
->select('COUNT(IF(S.status = 1, S.customer_id, NULL)) AS active,COUNT(IF(S.status = 0, S.customer_id, NULL)) AS expired,COUNT(IF(S.is_renew > 0 AND S.status = 1, S.customer_id, NULL)) AS renew')
|
||||
->select('COUNT(IF(S.status = 1, S.customer_id, NULL)) AS active,COUNT(IF(S.is_renew = 0 AND S.status = 0, S.customer_id, NULL)) AS expired,COUNT(IF(S.is_renew > 0 AND S.status = 1, S.customer_id, NULL)) AS renew')
|
||||
->join('customers AS C', 'C.customer_id = S.customer_id AND C.isactive = 1', 'left')
|
||||
->join('books AS BK', 'BK.book_id = S.scheme_id', 'left')
|
||||
->join('book_categories AS BC', 'BC.book_id = S.scheme_id AND BC.isactive = 1', 'left')
|
||||
|
||||
@ -248,9 +248,9 @@ public function getQueryforSubscriptionDetailsBySchemeName($flag,$condition, $va
|
||||
$builder->orderBy('s.to_subscription', 'asc');
|
||||
$query = $builder->get();
|
||||
$result = $query->getResultArray();
|
||||
$lastQuery = $this->db->getLastQuery();
|
||||
$finalQueryString = $lastQuery->getQuery();
|
||||
|
||||
$lastQuery = $this->db->getLastQuery();
|
||||
$finalQueryString = $lastQuery->getQuery();
|
||||
// echo $finalQueryString;die;
|
||||
return $result;
|
||||
}
|
||||
public function getSubscriptionDetailsBySchemeName($selectedScheme, $downloadType){
|
||||
|
||||
@ -21,6 +21,24 @@
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="header-title"><?= $page_name; ?></h4>
|
||||
<?php if (session()->getFlashdata('success') || session()->getFlashdata('error')) : ?>
|
||||
<?php if (session()->getFlashdata('success')) : ?>
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
<?= session('success') ?>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (session()->getFlashdata('error')) : ?>
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<?= session('error') ?>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<p class="sub-header"> </p>
|
||||
<?php if (session()->getFlashdata('success')) : ?>
|
||||
<div class="alert alert-success"><?= session()->getFlashdata('success') ?></div>
|
||||
@ -34,40 +52,40 @@
|
||||
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="author" class="col-form-label">Author<span class="text-danger"> *</span></label>
|
||||
<input type="text" class="form-control" id="author" name="author" value="<?= isset($details['author']) ? $details['author'] : '' ?>" placeholder="Author" required />
|
||||
<label for="author" class="col-form-label">Author </label>
|
||||
<input type="text" class="form-control" id="author" name="author" value="<?= isset($details['author']) ? $details['author'] : '' ?>" placeholder="Author" />
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
|
||||
<div class="form-group col-md-6">
|
||||
<label for="publisher" class="col-form-label">Publisher Name<span class="text-danger"> *</span></label>
|
||||
<input type="text" class="form-control" id="publisher" name="publisher" placeholder="Publisher Name" value="<?= isset($details['publisher']) ? $details['publisher'] : '' ?>" required />
|
||||
<label for="publisher" class="col-form-label">Publisher Name</label>
|
||||
<input type="text" class="form-control" id="publisher" name="publisher" placeholder="Publisher Name" value="<?= isset($details['publisher']) ? $details['publisher'] : '' ?>" />
|
||||
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="publication_date" class="col-form-label">Publication Date<span class="text-danger"> *</span></label>
|
||||
<input type="date" class="form-control" id="publication_date" name="publication_date" value="<?= isset($details['publication_date']) ? $details['publication_date'] : '' ?>" max="<?= date('Y-m-d'); ?>" required placeholder="Publication Date">
|
||||
<label for="publication_date" class="col-form-label">Publication Date</label>
|
||||
<input type="date" class="form-control" id="publication_date" name="publication_date" value="<?= isset($details['publication_date']) ? $details['publication_date'] : '' ?>" max="<?= date('Y-m-d'); ?>" placeholder="Publication Date">
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="publishers_code" class="col-form-label">Publisher Code</label>
|
||||
<input type="text" class="form-control" id="publishers_code" name="publishers_code" placeholder="Publisher Code" value="<?= isset($details['publishers_code']) ? $details['publishers_code'] : '' ?>" />
|
||||
<label for="publishers_code" class="col-form-label">Publisher Code <span class="text-danger"> *</span></label>
|
||||
<input type="text" class="form-control" id="publishers_code" name="publishers_code" placeholder="Publisher Code" value="<?= isset($details['publishers_code']) ? $details['publishers_code'] : '' ?>" required />
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="isbn_code" class="col-form-label">ISBN Code<span class="text-danger"> *</span></label>
|
||||
<input type="text" class="form-control" id="isbn_code" name="isbn_code" value="<?= isset($details['isbn_code']) ? $details['isbn_code'] : '' ?>" placeholder="ISBN Code" required />
|
||||
<label for="isbn_code" class="col-form-label">ISBN Code</label>
|
||||
<input type="text" class="form-control" id="isbn_code" name="isbn_code" value="<?= isset($details['isbn_code']) ? $details['isbn_code'] : '' ?>" placeholder="ISBN Code" />
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="language" class="col-form-label">Language<span class="text-danger"></span></label>
|
||||
<label for="language" class="col-form-label">Language</label>
|
||||
<input type="text" class="form-control" id="language" name="language" placeholder="Language" value="<?= isset($details['language']) ? $details['language'] : '' ?>" />
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
@ -84,13 +102,13 @@
|
||||
<div class="form-row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="description" class="col-form-label">Description<span class="text-danger"></span></label>
|
||||
<label for="description" class="col-form-label">Description</label>
|
||||
<textarea class="form-control" id="description" name="description" placeholder="Description" rows="6"><?= isset($details['description']) ? $details['description'] : '' ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="tax" class="col-form-label">TAX<span class="text-danger"></span></label>
|
||||
<label for="tax" class="col-form-label">TAX</label>
|
||||
<input type="text" class="form-control" id="tax" name="tax" placeholder="TAX" value="<?= isset($details['tax']) ? $details['tax'] : '' ?>" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@ -186,16 +204,14 @@
|
||||
document.getElementById('myForm').addEventListener('submit', function(event) {
|
||||
var form = event.target;
|
||||
|
||||
// Check if form is valid
|
||||
if (!form.checkValidity()) {
|
||||
form.reportValidity(); // Display validation error messages
|
||||
event.preventDefault(); // Prevent form submission if it's not valid
|
||||
$('#submitBtn').prop('disabled', false); // Re-enable the button
|
||||
|
||||
// Display custom alert message
|
||||
event.preventDefault();
|
||||
form.reportValidity();
|
||||
$('#submitBtn').prop('disabled', false);
|
||||
|
||||
alert('Please fill out all required fields correctly.');
|
||||
} else {
|
||||
$('#submitBtn').prop('disabled', true); // Disable the button to prevent duplicate submissions
|
||||
$('#submitBtn').prop('disabled', true);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -7,6 +7,24 @@
|
||||
);
|
||||
?>
|
||||
<h4 class="header-title"><?= $page_name === 'Edit Customer Details' ? htmlspecialchars($fullName)." - Customer Details" : $page_name; ?></h4>
|
||||
<?php if (session()->getFlashdata('success') || session()->getFlashdata('error')) : ?>
|
||||
<?php if (session()->getFlashdata('success')) : ?>
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
<?= session('success') ?>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (session()->getFlashdata('error')) : ?>
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<?= session('error') ?>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($page_name === 'Edit Customer Details') : ?>
|
||||
<ul class="nav nav-tabs" id="customerTabs" role="tablist">
|
||||
|
||||
@ -3,15 +3,34 @@
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="header-title"><?= $page_name; ?></h4>
|
||||
<?php if (session()->getFlashdata('success') || session()->getFlashdata('error')) : ?>
|
||||
<?php if (session()->getFlashdata('success')) : ?>
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
<?= session('success') ?>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (session()->getFlashdata('error')) : ?>
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<?= session('error') ?>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<p class="sub-header"> </p>
|
||||
<form class="needs-validation" novalidate method="POST" enctype="multipart/form-data" action="<?= base_url() . "insert_event"; ?>" id="myForm">
|
||||
<!-- <form class="needs-validation" novalidate method="POST" enctype="multipart/form-data" action="<?= base_url() . "insert_event"; ?>" id="myForm"> -->
|
||||
<form class="parsley-examples" method="POST" enctype="multipart/form-data" action="<?= base_url() . "insert_event"; ?>" id="myForm">
|
||||
<div class="form-group">
|
||||
<div class="form-row">
|
||||
|
||||
<div class="form-group col-md-12">
|
||||
<label for="ename" class="col-form-label">Events Name<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="ename" value="<?= isset($event['event_name']) ? $event['event_name'] : '' ?>" placeholder="Event Name" required />
|
||||
<div class="invalid-feedback"> Please provide. </div>
|
||||
<!-- <div class="invalid-feedback"> Please provide. </div> -->
|
||||
</div>
|
||||
<!-- <div class="form-group col-md-6">
|
||||
<label for="formating" class="col-form-label">Identifier formatting<span class="text-danger">*</span></label>
|
||||
|
||||
@ -105,6 +105,18 @@ input[type=number] {
|
||||
top: 70px !important;
|
||||
z-index: 0;
|
||||
}
|
||||
#fromsubcription~.parsley-errors-list{
|
||||
position: absolute;
|
||||
top:35px;
|
||||
}
|
||||
#tosubcription~.parsley-errors-list{
|
||||
position: absolute;
|
||||
top:35px;
|
||||
}
|
||||
/* .book-select~.parsley-errors-list{
|
||||
position: absolute;
|
||||
top:35px;
|
||||
} */
|
||||
|
||||
</style>
|
||||
<?php $flag_name = $invoice_type === '1' ? " Books" : " Scheme";
|
||||
@ -134,11 +146,28 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<h4 class="header-title"><center><?= $page_name; ?></center></h4>
|
||||
|
||||
<?php if (session()->getFlashdata('success') || session()->getFlashdata('error')) : ?>
|
||||
<?php if (session()->getFlashdata('success')) : ?>
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
<?= session('success') ?>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (session()->getFlashdata('error')) : ?>
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<?= session('error') ?>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<br>
|
||||
<form method="POST" enctype="multipart/form-data" action="<?= base_url() . "save_invoice"; ?>" id="myForm">
|
||||
<form class="parsley-examples" method="POST" enctype="multipart/form-data" action="<?= base_url() . "save_invoice"; ?>" id="myForm">
|
||||
<!-- class="parsley-examples" -->
|
||||
|
||||
<div class="form-group">
|
||||
@ -179,7 +208,6 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
|
||||
<input type="hidden" class="form-control" id="hidden_last_name" value="<?= $last_name ?>" readonly />
|
||||
<input type="hidden" class="form-control" id="hidden_first_name" value="<?= $first_name ?>" readonly />
|
||||
|
||||
<div class="invalid-feedback"> Please select customer. </div>
|
||||
<div class="subscribedetails" style="display: none">
|
||||
<!-- <div id="schemeName"></div> -->
|
||||
</div>
|
||||
@ -194,7 +222,7 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-row" style="margin-top: 19px;">
|
||||
<div class="form-group col-md-5">
|
||||
<label for="storeBillingAddress"> Billing Address  ( <input type="checkbox" id="editAddressesCheckbox" /> Do you want to change addresses?)</label>
|
||||
<input type="hidden" id="hiddenBillingAddressId" name="billing_address_id" placeholder="hidden for billing address id" value="<?= isset($invoice_details['billing_address_id']) ? $invoice_details['billing_address_id'] : '' ?>" />
|
||||
@ -236,13 +264,8 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
|
||||
</div>
|
||||
</div><!-- input-group -->
|
||||
|
||||
<!-- <input type="date" class="form-control" id="invoiceDate" name="invoice_date" value="<?= isset($invoice_details['invoice_date']) ? $invoice_details['invoice_date'] : '' ?>" max="<?= date('d/m/Y'); ?>" required> -->
|
||||
</div>
|
||||
|
||||
<!-- <div class="form-group col-md-4">
|
||||
<label for="invoiceDate">Invoice Date<span class="text-danger"> *</span></label>
|
||||
<input type="date" class="form-control" id="invoiceDate" name="invoice_date" value="<?= isset($invoice_details['invoice_date']) ? $invoice_details['invoice_date'] : '' ?>" max="<?= date('Y-m-d'); ?>" required>
|
||||
</div> -->
|
||||
<?php if ($invoice_type === '2') : ?>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="fromsubcription">From Subscription<span class="text-danger"> *</span></label>
|
||||
@ -661,7 +684,7 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
|
||||
</div>
|
||||
<input type="hidden" id="status" name="status" value="<?= isset($invoice_details['status']) ? $invoice_details['status'] : 'Draft' ?>">
|
||||
<input type="hidden" id="hiddenInvoiceId" name="invoice_id" placeholder="hidden for invoice id" value="<?= isset($invoice_details['invoice_id']) ? $invoice_details['invoice_id'] : '' ?>" />
|
||||
<input type="hidden" name="invoice_type" value="<?php echo ($page_name === 'Add Subscription Invoice Details' || $page_name === 'Edit Subscription Invoice Details') ? '2' : '1'; ?>">
|
||||
<input type="hidden" id="invoice_type" name="invoice_type" value="<?php echo ($page_name === 'Add Subscription Invoice Details' || $page_name === 'Edit Subscription Invoice Details') ? '2' : '1'; ?>">
|
||||
|
||||
<div class="form-group m-b-0">
|
||||
<button type="submit" class="btn btn-white waves-effect waves-light" name="saveas" value="Draft" id="saveDraftButton">Save as Draft</button>
|
||||
@ -732,7 +755,7 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form id="addBookForm">
|
||||
<form class="needs-validation" novalidate id="addBookForm">
|
||||
<div class="modal-body">
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
@ -747,8 +770,8 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="publication_date" class="col-form-label">Publication Date<span class="text-danger"> *</span></label>
|
||||
<input type="date" class="form-control" id="publication_date" name="publication_date" value="<?= isset($details['publication_date']) ? $details['publication_date'] : '' ?>" max="<?= date('Y-m-d'); ?>" required placeholder="Publication Date">
|
||||
<label for="publication_date" class="col-form-label">Publication Date</label>
|
||||
<input type="date" class="form-control" id="publication_date" name="publication_date" value="<?= isset($details['publication_date']) ? $details['publication_date'] : '' ?>" max="<?= date('Y-m-d'); ?>" placeholder="Publication Date">
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="isbn_code" class="col-form-label">ISBN Code</label>
|
||||
@ -1614,22 +1637,6 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
// Get the Invoice Date input element by its ID
|
||||
const invoiceDateInput = document.getElementById("invoiceDate");
|
||||
|
||||
// Get the current date
|
||||
const currentDate = new Date();
|
||||
|
||||
// Calculate the min and max date strings
|
||||
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("max", maxDate);
|
||||
|
||||
// const fromsubcriptionDateInput = document.getElementById("fromsubcription");
|
||||
// fromsubcriptionDateInput.setAttribute("max", maxDate);
|
||||
|
||||
document.getElementById("fromsubcription").onchange = function() {
|
||||
const toDateInput = document.getElementById('tosubcription');
|
||||
@ -1975,60 +1982,84 @@ function saveInvoiceCustomer() {
|
||||
// JavaScript code to handle form submission and AJAX request
|
||||
$(document).ready(function() {
|
||||
$('#addBookForm').submit(function(e) {
|
||||
e.preventDefault(); // Prevent default form submission
|
||||
|
||||
var Quickadd_bookName = $("#bookName").val();
|
||||
var Quickadd_bookPrice = $("#bookPrice").val();
|
||||
var Quickadd_publishersCode = $("#publishers_code").val();
|
||||
var isValid = true;
|
||||
var errorMessage = '';
|
||||
if (Quickadd_bookName === '') {
|
||||
errorMessage += 'Book name is required.\n';
|
||||
isValid = false;
|
||||
}
|
||||
if (Quickadd_bookPrice === '') {
|
||||
errorMessage += 'Book Price is required.\n';
|
||||
isValid = false;
|
||||
}
|
||||
if (Quickadd_publishersCode === '') {
|
||||
errorMessage += 'Book Publishers Code is required.\n';
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
// Serialize form data
|
||||
var formData = $(this).serialize();
|
||||
if (!isValid) {
|
||||
alert(errorMessage);
|
||||
}else{
|
||||
|
||||
// Send AJAX request to save the book
|
||||
$.ajax({
|
||||
url: '<?php echo base_url("saveBook"); ?>', // URL to your controller function
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
console.log("Response:", response); // Log the response object
|
||||
e.preventDefault(); // Prevent default form submission
|
||||
|
||||
if (response.success) {
|
||||
// Book saved successfully
|
||||
alert(response.message);
|
||||
$('#addBookModal').modal('hide');
|
||||
$('#addBookForm')[0].reset();
|
||||
// Append the new book to the bookData array
|
||||
var newBook = {
|
||||
book_id: response.book_id,
|
||||
title: response.title,
|
||||
price: response.price,
|
||||
tax: response.tax
|
||||
// Add other properties as needed
|
||||
};
|
||||
bookData.push(newBook);
|
||||
// Serialize form data
|
||||
var formData = $(this).serialize();
|
||||
|
||||
console.log("Updated bookData:", bookData); // Log the updated bookData array
|
||||
// Send AJAX request to save the book
|
||||
$.ajax({
|
||||
url: '<?php echo base_url("saveBook"); ?>', // URL to your controller function
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
console.log("Response:", response); // Log the response object
|
||||
|
||||
if (response.success) {
|
||||
// Book saved successfully
|
||||
alert(response.message);
|
||||
$('#addBookModal').modal('hide');
|
||||
$('#addBookForm')[0].reset();
|
||||
// Append the new book to the bookData array
|
||||
var newBook = {
|
||||
book_id: response.book_id,
|
||||
title: response.title,
|
||||
price: response.price,
|
||||
tax: response.tax
|
||||
// Add other properties as needed
|
||||
};
|
||||
bookData.push(newBook);
|
||||
|
||||
console.log("Updated bookData:", bookData); // Log the updated bookData array
|
||||
|
||||
// Retrieve the index from localStorage
|
||||
var addBookIndex = localStorage.getItem('add_book_index');
|
||||
|
||||
// Reload only the dropdown at the specified index
|
||||
var dropdown = $('#itemTable tbody tr:eq(' + addBookIndex + ')').find('.book-select');
|
||||
dropdown.empty(); // Clear existing options
|
||||
// Add default and new book options
|
||||
dropdown.append('<option value="">Select a <?= $flag_name ?></option><option value="add_new_book">+ Add New Book</option>');
|
||||
bookData.forEach(function(book) {
|
||||
dropdown.append('<option value="' + book.book_id + '">' + book.title + '</option>');
|
||||
});
|
||||
dropdown.select2(); // Reinitialize select2
|
||||
|
||||
// Select the newly added book in the dropdown
|
||||
dropdown.val(response.book_id).trigger('change');
|
||||
} else {
|
||||
// Failed to save book
|
||||
alert(response.message);
|
||||
}
|
||||
},
|
||||
|
||||
// Retrieve the index from localStorage
|
||||
var addBookIndex = localStorage.getItem('add_book_index');
|
||||
|
||||
// Reload only the dropdown at the specified index
|
||||
var dropdown = $('#itemTable tbody tr:eq(' + addBookIndex + ')').find('.book-select');
|
||||
dropdown.empty(); // Clear existing options
|
||||
// Add default and new book options
|
||||
dropdown.append('<option value="">Select a <?= $flag_name ?></option><option value="add_new_book">+ Add New Book</option>');
|
||||
bookData.forEach(function(book) {
|
||||
dropdown.append('<option value="' + book.book_id + '">' + book.title + '</option>');
|
||||
});
|
||||
dropdown.select2(); // Reinitialize select2
|
||||
|
||||
// Select the newly added book in the dropdown
|
||||
dropdown.val(response.book_id).trigger('change');
|
||||
} else {
|
||||
// Failed to save book
|
||||
alert(response.message);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -3,6 +3,24 @@
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="header-title"><?= $page_name; ?></h4>
|
||||
<?php if (session()->getFlashdata('success') || session()->getFlashdata('error')) : ?>
|
||||
<?php if (session()->getFlashdata('success')) : ?>
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
<?= session('success') ?>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (session()->getFlashdata('error')) : ?>
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<?= session('error') ?>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<!-- <?php if (session()->getFlashdata('success')) : ?>
|
||||
<div class="alert alert-success"><?= session()->getFlashdata('success') ?></div>
|
||||
<?php endif; ?> -->
|
||||
|
||||
Loading…
Reference in New Issue
Block a user