Event And Invoice default Event : ps

This commit is contained in:
VE10-Sanjeev 2023-12-28 18:37:18 +05:30
parent 732a76631c
commit 8ac851b81a
12 changed files with 203 additions and 90 deletions

View File

@ -105,6 +105,7 @@ $routes->post('address/generatePdf', 'Address::generatePdf');
$routes->get("event_list/", "Event::index"); $routes->get("event_list/", "Event::index");
$routes->get("new_event/(:any)", "Event::new_event/$1"); $routes->get("new_event/(:any)", "Event::new_event/$1");
$routes->post("insert_event/", "Event::insert_event"); $routes->post("insert_event/", "Event::insert_event");
$routes->post("change_default_event/", "Event::change_default_event");
$routes->get('invoice_number_format/(:any)', 'Event::invoice_number_format/$1'); $routes->get('invoice_number_format/(:any)', 'Event::invoice_number_format/$1');
$routes->post("insert_invoice_number_format", "Event::insert_invoice_number_format"); $routes->post("insert_invoice_number_format", "Event::insert_invoice_number_format");

View File

@ -105,12 +105,14 @@ class Event extends BaseController
public function invoice_number_format($id) public function invoice_number_format($id)
{ {
helper('session'); helper('session');
helper('financial_year_helper');
$session_bid = get_business_id(); $session_bid = get_business_id();
$data['page_name'] = 'Edit invoice number formatting'; $data['page_name'] = 'Edit invoice number formatting';
$model = new EventModel(); $model = new EventModel();
$edit_event_details = $model->setTable('invoice_number_formatting')->where(['id' => (int)$id,'business_id'=>$session_bid])->first(); $edit_event_details = $model->setTable('invoice_number_formatting')->where(['id' => (int)$id,'business_id'=>$session_bid])->first();
$data['event'] = $edit_event_details; $data['event'] = $edit_event_details;
$data['session_bid'] = $session_bid; $data['session_bid'] = $session_bid;
$data['financial_year'] = get_financial_year();
$this->render_page('invoice_number_formatting', $data); $this->render_page('invoice_number_formatting', $data);
} }
@ -162,4 +164,38 @@ class Event extends BaseController
} }
return redirect()->to(base_url("invoice_number_format/1")); return redirect()->to(base_url("invoice_number_format/1"));
} }
public function change_default_event() {
helper('session');
$session_bid = get_business_id();
$session_uid = get_logged_user_id();
$response = "";
$EventModel = new EventModel();
$where = ['events.business_id' => (int)$session_bid, 'events.isactive' => 1, 'events.is_the_default' => 1];
$events = $EventModel->where($where)->orderBy('event_id', 'DESC')->findAll(); // Retrieve the events
if (count($events) > 0) {
$dataToUpdate = ['is_the_default' => 0];
$eventIds = array_column($events, 'event_id');
// $EventModel->whereIn('event_id', $eventIds)->set($dataToUpdate)->update();
$affectedRows = $EventModel->whereIn('event_id', $eventIds)->set($dataToUpdate)->update();
$this->logger->info("Changed To Default as 0 - Event ID are " . implode(", ", $eventIds) . ". Affected Rows: " . $affectedRows);
}
$data['is_the_default'] = $this->request->getPost('is_the_default');
$data['updated_by'] = $session_uid;
$where = ['events.business_id' => (int)$session_bid, 'events.isactive' => 1, 'events.event_id' => $this->request->getPost('event_id')];
$update_result = $EventModel->updateData('events', $data, $where);
if ($update_result['info']) {
$response = "Event set as Default";
$this->logger->info($update_result['info']);
} else {
$response = $update_result['err'];
$this->logger->error($update_result['err']);
}
return $this->response->setJSON(['response' => $response]);
}
} }

View File

@ -41,12 +41,15 @@ class Invoice extends BaseController
public function new_book_invoice($id = '0') public function new_book_invoice($id = '0')
{ {
helper('session'); helper('session');
helper('financial_year_helper');
$model = new InvoiceModel(); $model = new InvoiceModel();
$where = ['business_id' => (int)get_business_id()]; $where = ['business_id' => (int)get_business_id()];
// Get customer names for the dropdown, events details, and books details // Get customer names for the dropdown, events details, and books details
$data['customers'] = $model->getData('customers', $where); $data['customers'] = $model->getData('customers', $where);
$data['events'] = $model->getData('events', $where); $data['events'] = $model->getData('events', $where);
$data['financial_year'] = get_financial_year();
$data['invoice_number_formatting'] = $model->getData('invoice_number_formatting', $where); $data['invoice_number_formatting'] = $model->getData('invoice_number_formatting', $where);
$data['books'] = $model->getCategoryBooks(1); // Invocie type = 2 (invoice) $data['books'] = $model->getCategoryBooks(1); // Invocie type = 2 (invoice)
@ -158,6 +161,8 @@ class Invoice extends BaseController
## Declarions ## Declarions
helper('session'); helper('session');
helper('financial_year_helper');
$model = new InvoiceModel(); $model = new InvoiceModel();
$duedate = $this->request->getVar('due_date'); $duedate = $this->request->getVar('due_date');
$invdate = $this->request->getVar('invoice_date'); $invdate = $this->request->getVar('invoice_date');
@ -225,6 +230,7 @@ class Invoice extends BaseController
## Array Formation For Invoice Numbering Format Details.. ## Array Formation For Invoice Numbering Format Details..
$update_invoice_numbering = [ $update_invoice_numbering = [
'id' => 1, 'id' => 1,
'id_formating' => get_financial_year(),
'next_id' => (int)$this->request->getPost('next_id'), 'next_id' => (int)$this->request->getPost('next_id'),
'business_id' => (int)get_business_id(), 'business_id' => (int)get_business_id(),
'updated_by' => get_logged_user_id() 'updated_by' => get_logged_user_id()

View File

@ -0,0 +1,24 @@
<?php
if (!function_exists('get_financial_year')) {
function get_financial_year($date = null)
{
// If no date is provided, use the current date
$date = $date ?: date('Y-m-d');
// Extract the year from the date
$year = date('Y', strtotime($date));
// Determine the financial year based on your business logic
// Adjust this logic according to your organization's financial year cycle
if (date('n', strtotime($date)) < 4) {
// If the month is before April, use the previous year
$financialYear = ($year - 1) . '-' . $year;
} else {
// If the month is April or later, use the current year
$financialYear = $year . '-' . ($year + 1);
}
return $financialYear;
}
}

View File

@ -9,7 +9,7 @@ class EventModel extends Model
{ {
protected $table = 'events'; protected $table = 'events';
protected $primaryKey = 'event_id'; protected $primaryKey = 'event_id';
protected $allowedFields = ['event_id','event_name','created_by','created_on','updated_on' ,'updated_by','business_id']; protected $allowedFields = ['event_id','event_name','created_by','created_on','updated_on' ,'updated_by','business_id','is_the_default'];
public function getEventnamesByBusiness($business_id) public function getEventnamesByBusiness($business_id)
{ {
@ -50,5 +50,6 @@ class EventModel extends Model
} }
} }
} }
?> ?>

View File

@ -26,7 +26,7 @@ class HomeModel extends Model
} }
public function invoice_dtls() { public function invoice_dtls() {
if (date('m') <= 3) { if ((int)date('m') <= 3) {
$invoice['financial_year'] = (date('Y')-1) . '-' . date('Y'); $invoice['financial_year'] = (date('Y')-1) . '-' . date('Y');
$start_date = (date('Y')-1).'-04-01'; $start_date = (date('Y')-1).'-04-01';
$end_date = date('Y').'-03-31'; $end_date = date('Y').'-03-31';
@ -94,7 +94,7 @@ class HomeModel extends Model
public function book_published_dtls(){ public function book_published_dtls(){
if (date('m') <= 3) { if ((int)date('m') <= 3) {
$start_date = (date('Y')-1).'-04-01'; $start_date = (date('Y')-1).'-04-01';
$end_date = date('Y').'-03-31'; $end_date = date('Y').'-03-31';
} else { } else {

View File

@ -5,7 +5,7 @@ class SettingsModel extends Model
{ {
protected $table = 'settings'; protected $table = 'settings';
protected $primaryKey = 'setting_id'; protected $primaryKey = 'setting_id';
protected $allowedFields = ['setting_id','site_name','site_title','favicon','logo','terms_service','footer_about','admin_email','mobile','copyright','pagination_limit','site_info','about_info','mail_protocol','mail_title','mail_host','mail_port','mail_encryption','mail_username','mail_password','currency','country','isactive','business_id']; protected $allowedFields = ['business_id','setting_id','site_name','site_color','site_short_name','site_email','mobile','country','favicon','site_info','logo','terms_service','footer_about','about_info','copyright','pagination_limit','mail_protocol','mail_title','mail_host','mail_port','mail_encryption','mail_username','mail_password','currency','created_on','created_by','updated_on','updated_by','isactive'];
public function saveData($data, $id = null) public function saveData($data, $id = null)
{ {

View File

@ -30,58 +30,70 @@
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="title" class="col-form-label">Book Name<span class="text-danger"> *</span></label> <label for="title" class="col-form-label">Book Name<span class="text-danger"> *</span></label>
<input type="text" class="form-control" id="title" name="title" value="<?= isset($details['title']) ? $details['title'] : '' ?>" placeholder="Name of the book" required /> <input type="text" class="form-control" id="title" name="title" value="<?= isset($details['title']) ? $details['title'] : '' ?>" placeholder="Book Name" required />
<div class="invalid-feedback"> Please provide. </div> <div class="invalid-feedback"> Please provide. </div>
</div> </div>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="author" class="col-form-label">Book Author<span class="text-danger">*</span></label> <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="Name of the book author" required /> <input type="text" class="form-control" id="author" name="author" value="<?= isset($details['author']) ? $details['author'] : '' ?>" placeholder="Author" required />
<div class="invalid-feedback"> Please provide. </div> <div class="invalid-feedback"> Please provide. </div>
</div> </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">
<label for="publisher" class="col-form-label">Book Publisher Name<span class="text-danger">*</span></label> <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="Book Publisher" value="<?= isset($details['publisher']) ? $details['publisher'] : '' ?>" required /> <input type="text" class="form-control" id="publisher" name="publisher" placeholder="Publisher Name" value="<?= isset($details['publisher']) ? $details['publisher'] : '' ?>" required />
<div class="invalid-feedback"> Please provide. </div> <div class="invalid-feedback"> Please provide. </div>
</div> </div>
<div class="form-group col-md-6">
<label for="publishers_code" class="col-form-label">Book Publishers Code</label>
<input type="text" class="form-control" id="publishers_code" name="publishers_code" placeholder="Book Publishers code" value="<?= isset($details['publishers_code']) ? $details['publishers_code'] : '' ?>" />
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="publication_date" class="col-form-label">Publication Date<span class="text-danger"> *</span></label> <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"> <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">
<div class="invalid-feedback"> Please provide. </div> <div class="invalid-feedback"> Please provide. </div>
</div> </div>
<div class="form-group col-md-6">
<label for="price" class="col-form-label">Book Price<span class="text-danger">*</span></label>
<input type="number" class="form-control" id="price" name="price" placeholder="Book Price" required value="<?= isset($details['price']) ? $details['price'] : '' ?>" />
<div class="invalid-feedback"> Please provide. </div>
</div>
</div> </div>
<div class="form-row"> <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'] : '' ?>" />
</div>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="isbn_code" class="col-form-label">ISBN Code<span class="text-danger"> *</span></label> <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 /> <input type="text" class="form-control" id="isbn_code" name="isbn_code" value="<?= isset($details['isbn_code']) ? $details['isbn_code'] : '' ?>" placeholder="ISBN Code" required />
<div class="invalid-feedback"> Please provide. </div> <div class="invalid-feedback"> Please provide. </div>
</div> </div>
<div class="form-group col-md-6">
<label for="page_count" class="col-form-label">Page Count<span class="text-danger"></span></label>
<input type="number" class="form-control" id="page_count" name="page_count" placeholder="Page Count" value="<?= isset($details['page_count']) ? $details['page_count'] : '' ?>" />
</div>
</div> </div>
<div class="form-row"> <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>
<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">
<label for="page_count" class="col-form-label">Page Count<span class="text-danger"></span></label>
<input type="number" class="form-control" id="page_count" name="page_count" placeholder="Page Count" value="<?= isset($details['page_count']) ? $details['page_count'] : '' ?>" />
</div>
<div class="form-group col-md-4">
<label for="price" class="col-form-label">Price<span class="text-danger"> *</span></label>
<input type="number" class="form-control" id="price" name="price" placeholder="Price" required value="<?= isset($details['price']) ? $details['price'] : '' ?>" />
<div class="invalid-feedback"> Please provide. </div>
</div>
</div>
<div class="form-group col-md-6"> <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>
<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>
<input type="text" class="form-control" id="tax" name="tax" placeholder="TAX" value="<?= isset($details['tax']) ? $details['tax'] : '' ?>" />
</div>
<div class="form-group">
<label for="category_id" class="col-form-label">Category</label> <label for="category_id" class="col-form-label">Category</label>
<select class="form-control" id="category_id" name="category_id"> <select class="form-control" id="category_id" name="category_id">
<option>Select the Category of the Book</option> <option>Select the Category of the Book</option>
@ -92,27 +104,11 @@
</option> </option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div>
</div>
</div> </div>
<div class="form-group col-md-6">
<label for="language" class="col-form-label">Language<span class="text-danger"></span></label>
<input type="text" class="form-control" id="language" name="language" placeholder="Language" value="<?= isset($details['language']) ? $details['language'] : '' ?>" />
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="tax" class="col-form-label">TAX<span class="text-danger"></span></label>
<input type="text" class="form-control" id="tax" name="tax" placeholder="Tax" value="<?= isset($details['tax']) ? $details['tax'] : '' ?>" />
</div>
<div class="form-group col-md-6">
<label for="description" class="col-form-label">Description<span class="text-danger"></span></label>
<textarea class="form-control" id="description" name="description" placeholder="Description" rows="5"><?= isset($details['description']) ? $details['description'] : '' ?></textarea>
</div>
</div>
<div class="form-group col-md-4"> <div class="form-group col-md-4">
<label for="img_name" class="col-form-label">Picture</label> <label for="img_name" class="col-form-label">Picture</label>
<input type="file" name="img_name" accept="image/*" /> <input type="file" name="img_name" accept="image/*" />

View File

@ -42,7 +42,11 @@
<td hidden><?= $value['event_id']; ?></td> <td hidden><?= $value['event_id']; ?></td>
<td><?= $value['event_name']; ?></td> <td><?= $value['event_name']; ?></td>
<td> <td>
<div class="custom-control custom-switch">
<input type="radio" class="custom-control-input" name="is_the_default" value="<?= $value['event_id'] ?>" id="<?= $value['event_id'] ?>" <?= $value['is_the_default'] ? "checked" : ""; ?> >
<label class="custom-control-label" for="<?= $value['event_id']; ?>"></label>
<a href="<?= "new_event/" . $value['event_id']; ?>" class="edit-button"><i class="ri-pencil-line"></i></a> <a href="<?= "new_event/" . $value['event_id']; ?>" class="edit-button"><i class="ri-pencil-line"></i></a>
</div>
</td> </td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
@ -60,6 +64,40 @@
}); });
}); });
$("input[type=radio][name=is_the_default]").change(function(event) {
var id = $(this).val();
var confirmed = window.confirm("Are you sure, you want to set the event as the default event?");
if (confirmed) {
$.ajax({
type: "POST",
url: "<?= base_url() . 'change_default_event' ?>",
data: {
event_id: id,
is_the_default: 1
},
success: function(response) {
alert(response.response);
$(this).prop('checked', true);
console.error(response);
},
error: function(error) {
alert(error.response);
console.error(error);
// $(this).prop('checked', false);
refreshPage();
}
});
} else {
alert("Action canceled");
console.log("Action canceled");
refreshPage();
// console.log(event);
// console.log(id);$event->event_id
// $(this).prop('checked', false);
}
});
</script> </script>

View File

@ -60,7 +60,7 @@
<option value="">Select an Events</option> <option value="">Select an Events</option>
<?php foreach ($events as $event) : ?> <?php foreach ($events as $event) : ?>
<!-- <option value="<?= $event->event_id ?>"><?= $event->event_name ?></option> --> <!-- <option value="<?= $event->event_id ?>"><?= $event->event_name ?></option> -->
<option value="<?= $event->event_id ?>" <?php if (isset($invoice_details['event_id']) && ($invoice_details['event_id'] === $event->event_id)) echo "selected"; ?>> <option value="<?= $event->event_id ?>" <?php if ((int)$event->is_the_default === 1 || isset($invoice_details['event_id']) && (($invoice_details['event_id'] === $event->event_id))) echo "selected"; ?>>
<?= $event->event_name ?></option> <?= $event->event_name ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
@ -582,8 +582,8 @@
var next_id_string = filtered_data[0].next_id; var next_id_string = filtered_data[0].next_id;
var left_pad_string = filtered_data[0].left_pad; var left_pad_string = filtered_data[0].left_pad;
var prefix_string = String(filtered_data[0].id_formating); // var prefix_string = String(filtered_data[0].id_formating); // don't remove
var prefix_string = <?= json_encode($financial_year); ?>;
var left_pad_numberic = parseInt(left_pad_string); var left_pad_numberic = parseInt(left_pad_string);
var next_id_numberic = parseInt(next_id_string); var next_id_numberic = parseInt(next_id_string);

View File

@ -26,9 +26,10 @@
<div class="form-group"> <div class="form-group">
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-12"> <div class="form-group col-md-12">
<label for="formating" class="col-form-label">Identifier formatting<span class="text-danger">*</span></label> <!-- <label for="formating" class="col-form-label">Identifier formatting<span class="text-danger">*</span></label>
<input type="text" class="form-control" name="formating" value="<?= isset($event['id_formating']) ? $event['id_formating'] : '' ?>" placeholder="INV{{-0-}}" required /> <input type="text" class="form-control" name="formating" value="<?= isset($event['id_formating']) ? $event['id_formating'] : '' ?>" placeholder="INV{{-0-}}" required />
<div class="invalid-feedback"> Please provide. </div> <div class="invalid-feedback"> Please provide. </div> -->
<input type="text" class="form-control" name="formating" value="<?= $financial_year; ?>" readonly />
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">

View File

@ -29,19 +29,29 @@
<div class="form-group"> <div class="form-group">
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-12"> <div class="form-group col-md-12">
<label for="business_id" class="col-form-label">Business<span <?php if (isset($details['business_id']) && $details['business_id'] != "" ) {
class="text-danger">*</span></label> $displayvalue = "";
foreach ($business_details as $value) {
if ($details['business_id'] === $value['business_id']) {
$displayvalue = $value['title'];
}
} ?>
<label for="business_id" class="col-form-label">Business</label>
<input type="hidden" name="business_id" value="<?= $details['business_id']; ?>" />
<input type="text" class="form-control" value="<?= $displayvalue ?>" readonly/>
<?php } else { ?>
<label for="business_id" class="col-form-label">Business<span class="text-danger">*</span></label>
<select id="business_id" name="business_id" class="form-control" data-toggle="select2" onchange="fetch_details(this.value);"> <select id="business_id" name="business_id" class="form-control" data-toggle="select2" onchange="fetch_details(this.value);">
<option value=null>Choose your Business</option> <option value=null>Choose your Business</option>
<?php foreach ($business_details as $value) { <?php foreach ($business_details as $value) {
$disabled = ($value['setting_id'] != "") ? 'disabled' : '' ; if($value['setting_id'] == ""){ ?>
?> <option value="<?php echo $value['business_id']; ?>" >
<option value="<?php echo $value['business_id']; ?>" <?php echo $value['title']; ?>
<?php if (isset($details['business_id']) && ($details['business_id'] === $value['business_id'])) echo "selected"; ?> <?= $disabled ?> >
<?php echo $value['title'].($value['setting_id'] != "" ? " (Disabled) " : ""); ?>
</option> </option>
<?php } ?> <?php } } ?>
</select> </select>
<?php } ?>
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">