Add Product Module and Major issues fixes : ps
This commit is contained in:
parent
2d1b057501
commit
687fc818e8
@ -48,15 +48,11 @@ class Books extends BaseController
|
||||
$data['details'] = [];
|
||||
} elseif ($id !== '0') {
|
||||
$data['page_name'] = 'Edit Book';
|
||||
|
||||
$imageData = $model->getBooksAndImagesByBookId($id);
|
||||
|
||||
$data['details'] = $imageData[0];
|
||||
|
||||
}
|
||||
|
||||
$data['categories'] = $categories; // Pass the categories to the view
|
||||
|
||||
$this->render_page('book_form', $data);
|
||||
}
|
||||
|
||||
@ -108,36 +104,94 @@ class Books extends BaseController
|
||||
$this->logger->info("Books Category : has been added successfully. Inserted ID = " . $book_categories_id);
|
||||
}else{
|
||||
$existingRecordId = $existingRecord->id;
|
||||
$BooksModel->db->table('book_categories')->where('id', $existingRecordId)->update(['isactive' => 1]);
|
||||
$BooksModel->db->table('book_categories')->where('id', $existingRecordId)->update(['isactive' => 0,'updated_by'=>(int)$session_uid]);
|
||||
$book_categories_affectedRows = $BooksModel->db->affectedRows();
|
||||
$this->logger->info("Books Category : has been updated successfully. Updated Book Category ID = " . $existingRecordId." Aff ".$book_categories_affectedRows);
|
||||
}
|
||||
}
|
||||
|
||||
##book image section.
|
||||
if (!empty($_FILES['img_name']['name'])) {
|
||||
// A new image has been uploaded
|
||||
|
||||
// First, delete the previous image file if it exists
|
||||
if (!empty($imageData) && file_exists(WRITEPATH . 'public/uploads/' . $imageData[0]->img_name)) {
|
||||
unlink(WRITEPATH . 'public/uploads/' . $imageData[0]->img_name);
|
||||
}
|
||||
|
||||
|
||||
$imageData = [
|
||||
'book_id' => $book_id, // Assuming $last_inserted_id contains the ID of the inserted scheme
|
||||
'img_name' => $_FILES['img_name']['name'],
|
||||
'is_cover' => 1, // Set this based on your requirements
|
||||
'type' => $_FILES['img_name']['type']
|
||||
## CI validation rule for img_name
|
||||
$validationRule = [
|
||||
'img_name' => [
|
||||
'label' => 'Image File',
|
||||
'rules' => 'uploaded[img_name]|is_image[img_name]|mime_in[img_name,image/jpg,image/jpeg,image/gif,image/png,image/webp]'
|
||||
]
|
||||
];
|
||||
|
||||
// Move the uploaded image to a desired location
|
||||
$imagePath = 'public/uploads/' . $_FILES['img_name']['name'];
|
||||
move_uploaded_file($_FILES['img_name']['tmp_name'], $imagePath);
|
||||
|
||||
// Update image data in the 'book_images' table
|
||||
$BooksModel->insertImage($imageData);
|
||||
}
|
||||
|
||||
$img_details = $this->request->getFile('img_name'); // Here I Have Image details ;
|
||||
$final_img_name = NULL;//Just flag
|
||||
$existing_img_name = $this->request->getPost('existing_img_name'); // HiddenField for if have any pic name means;
|
||||
$img_path = 'public/uploads/';
|
||||
|
||||
##Step 1 : image details available
|
||||
if($img_details){
|
||||
$this->logger->info("Books: image details avaiable");
|
||||
##Step 2 : i have image details .<br/>
|
||||
if ($img_details->isValid()) {
|
||||
##Step 3 : image Name.$new_img_name."<br/>";
|
||||
$new_img_name = $img_details->getName(); // before movement name
|
||||
$this->logger->info("Books: Image Name B4 Upload".$new_img_name);
|
||||
##Step 4 : Validation Rule Apply here.if not throw the error"<br/>";
|
||||
if (!$this->validate($validationRule)) {
|
||||
if($new_img_name !== ''){
|
||||
|
||||
$error = $this->validator->getErrors();
|
||||
// echo "Error : ".(string)$error."<br/>";
|
||||
$this->logger->error("Books: Err on image upload".$error['img_name']);
|
||||
throw new \Exception((string)$error['img_name']);
|
||||
}
|
||||
}
|
||||
##Step 5 : Check Existing and New Image Name Same Or not same no use to move on target folder
|
||||
if($new_img_name !== $existing_img_name){
|
||||
$existing_images_record = $BooksModel->db->table('book_images')
|
||||
->where(['book_id'=>$book_id,'isactive'=>1,'type'=>1])
|
||||
->get()->getRow();
|
||||
$existing_image_id = $existing_images_record->book_img_id;
|
||||
$this->logger->info("Books: Image Name are Differ".$new_img_name." & ".$existing_img_name);
|
||||
## Step 6 : Different Image Name means removed on target folder using Unlink;
|
||||
if ($existing_image_id && $existing_img_name && is_file($img_path.$existing_img_name)) {
|
||||
$BooksModel->db->table('book_images')->where(['book_img_id'=>$existing_image_id,"book_id"=>$book_id])->update(['isactive' => 0,"updated_by"=>(int)$session_uid]);
|
||||
$book_images_affectedRows = $BooksModel->db->affectedRows();
|
||||
$this->logger->info("Books: Image has been updated successfully. Updated Book Image ID = " . $existing_image_id." Aff ".$book_images_affectedRows);
|
||||
$this->logger->info("Books: already Image Available on target Folder Path : ".$img_path.$existing_img_name." So, Deleted.");
|
||||
unlink($img_path.$existing_img_name);
|
||||
}else{
|
||||
if(!$existing_image_id) $this->logger->info("Books: already Image Available but existing image id not availble in our DB So Unable to deactive");
|
||||
if(!$existing_img_name) $this->logger->info("Books: already Image Available but existing image name not founded So Unable to deactive");
|
||||
if(!is_file($img_path.$existing_img_name)) $this->logger->info("Books: Image on target Folder Path : ".$img_path.$existing_img_name." So Unable to deactive");
|
||||
}
|
||||
## Step 7 : Moved to target;
|
||||
$img_details->move($img_path, $new_img_name);
|
||||
$final_img_name = $img_details->getName(); // after movement name
|
||||
$image_data = [
|
||||
'book_id' => $book_id,
|
||||
'img_name' => $new_img_name,
|
||||
'is_cover' => 1, // cover images means 1
|
||||
'type' => 1, // manual uploaded means 1
|
||||
];
|
||||
|
||||
// Update image data in the 'book_images' table
|
||||
$BooksModel->insertImage($image_data);
|
||||
|
||||
$this->logger->info("Books: Image Name After Upload".$final_img_name);
|
||||
}else{
|
||||
$final_img_name = $existing_img_name;
|
||||
$this->logger->info("Books: Image Name are same".$new_img_name." & ".$existing_img_name." Can't Upload");
|
||||
}
|
||||
}
|
||||
else{
|
||||
## Step 8 : Not a Vaild Image File so replace Existing file name;
|
||||
$final_img_name = $existing_img_name;
|
||||
$this->logger->info("Books: Not a Vaild Image File Nothing To Update/Upload");
|
||||
// throw new \Exception("Not a Vaild Image File");
|
||||
}
|
||||
}
|
||||
else{
|
||||
## Step 9 : Testing Purpose File Details Not Available. so i can't move it.;
|
||||
$this->logger->info("Books: Testing Purpose Image Details Not Available. so i can't move it.");
|
||||
$final_img_name = $existing_img_name;
|
||||
//throw new \Exception("Testing Purpose File Details Not Available so i can't move it if you have existing filee means save it or your choice");
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Book: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine());
|
||||
|
||||
@ -107,7 +107,7 @@ class Event extends BaseController
|
||||
helper('session');
|
||||
helper('financial_year_helper');
|
||||
$session_bid = get_business_id();
|
||||
$data['page_name'] = 'Edit invoice number formatting';
|
||||
$data['page_name'] = 'Edit Invoice number formatting';
|
||||
$model = new EventModel();
|
||||
$edit_event_details = $model->setTable('invoice_number_formatting')->where(['id' => (int)$id,'business_id'=>$session_bid])->first();
|
||||
$data['event'] = $edit_event_details;
|
||||
|
||||
@ -30,7 +30,7 @@ class BooksModel extends Model
|
||||
public function getnonMembershiplist($business_id)
|
||||
{
|
||||
$builder = $this->builder();
|
||||
$builder->select('books.book_id, books.wp_api_product_id, books.title, books.price, books.duration, books.isactive, books.publisher, books.genre, books.language, books.publication_date, GROUP_CONCAT(category.name SEPARATOR \',\') as name');
|
||||
$builder->select('books.book_id, books.wp_api_product_id, books.title, books.price, books.duration, books.isactive, books.publisher, books.genre, books.language, books.publication_date, GROUP_CONCAT(category.name SEPARATOR \',\') as name,category.id as category_id');
|
||||
$builder->join('book_categories', 'book_categories.book_id = books.book_id and book_categories.isactive = 1', 'left');
|
||||
$builder->join('category', 'category.id = book_categories.category_id', 'left');
|
||||
$builder->where('books.business_id', $business_id);
|
||||
@ -52,6 +52,7 @@ class BooksModel extends Model
|
||||
'language'=>$row->language,
|
||||
'publication_date'=>$row->publication_date,
|
||||
'name'=>$row->name,
|
||||
'category_id' => $row->category_id,
|
||||
'wp_api_product_id'=>$row->wp_api_product_id
|
||||
];
|
||||
}
|
||||
@ -72,8 +73,7 @@ public function insertBooksCategory($book_id, $category_id)
|
||||
public function getCategories()
|
||||
{
|
||||
// Use the Query Builder to retrieve categories from the 'categories' table
|
||||
$categories = $this->db->table('category')->get()->getResultArray();
|
||||
|
||||
$categories = $this->db->table('category')->groupBy('category.name')->get()->getResultArray();
|
||||
return $categories;
|
||||
}
|
||||
public function getBooksAndImagesByBookId($id)
|
||||
|
||||
@ -115,7 +115,7 @@ public function getSubscriberDataByCustomerId($customerId)
|
||||
$builder->groupBy('subscription.sub_id');
|
||||
// Execute the query and return the result as an array of objects.
|
||||
return $builder->get()->getResult();
|
||||
print_r($this->db->getLastQuery());die;
|
||||
// print_r($this->db->getLastQuery());die;
|
||||
}
|
||||
|
||||
public function saveGroupDetails($data){
|
||||
|
||||
@ -102,7 +102,7 @@ public function getSchemeNames()
|
||||
}
|
||||
|
||||
return $schemes;
|
||||
print_r($schemes);die();
|
||||
// print_r($schemes);die();
|
||||
}
|
||||
|
||||
public function getSchemeNameById($schemeId)
|
||||
|
||||
@ -97,28 +97,34 @@
|
||||
<label for="category_id" class="col-form-label">Category</label>
|
||||
<select class="form-control" id="category_id" name="category_id">
|
||||
<option>Select the Category of the Book</option>
|
||||
<?php foreach ($categories as $category) : ?>
|
||||
|
||||
<option value="<?= $category['id'] ?>">
|
||||
<?= $category['name'] ?>
|
||||
<?php foreach ($categories as $category) { ?>
|
||||
<option value="<?php echo $category['id']; ?>" <?php if (isset($details['category_id']) && ($details['category_id'] === $category['id'])) echo "selected"; ?>>
|
||||
<?php echo $category['name']; ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group col-md-4">
|
||||
<label for="img_name" class="col-form-label">Picture</label>
|
||||
<input type="file" name="img_name" accept="image/*" />
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<?php if (isset($details) && !empty($details)) : ?>
|
||||
<img id="imagePreview" src="<?= base_url('public/uploads/' . $details['img_name']) ?>" alt="Image Preview" style="max-width: 200px; display: block" />
|
||||
<?php else : ?>
|
||||
<img id="imagePreview" src="" alt="Image Preview" style="max-width: 200px; display: none" />
|
||||
<?php endif; ?>
|
||||
<div class="form-row">
|
||||
<?php if (!empty($details['img_name'])) { ?>
|
||||
<div class="form-group col-md-4 mt-3">
|
||||
<div class="media">
|
||||
<img src="<?= base_url('public/uploads/' . $details['img_name']) ?>" alt="Image Cover" height="50" class="preview-image d-flex align-self-start rounded mr-2">
|
||||
<div class="media-body">
|
||||
<h5 class="mt-0">Existing Image</h5>
|
||||
<p class="mb-1"><?= $details['img_name']; ?></p>
|
||||
<input type="hidden" id="existing_img_name_name" name="existing_img_name_name" placeholder="hidden Field for Image Cover name" readonly value="<?= $details['img_name']; ?>" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="img_name" class="col-form-label">Image</label>
|
||||
<input type="file" name="img_name" value="<?= isset($details['img_name']) ? $details['img_name'] : '' ?>" accept="image/*" onchange="validateFile(this)" />
|
||||
<div id="error_message" style="color: red;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" id="book_id" name="book_id" placeholder="hidden for book id" value="<?= isset($details['book_id']) ? $details['book_id'] : '' ?>" />
|
||||
@ -139,7 +145,7 @@
|
||||
</button>
|
||||
<a href="<?= base_url() . "book_list"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div> <!-- end card-body-->
|
||||
</div> <!-- end card-->
|
||||
@ -203,4 +209,21 @@
|
||||
|
||||
// Set the min and max date attributes
|
||||
DateInput.setAttribute("max", maxDate);
|
||||
</script>
|
||||
<script>
|
||||
function validateFile(input) {
|
||||
const file = input.files[0];
|
||||
const errorMessage = document.getElementById("error_message");
|
||||
|
||||
if (file) {
|
||||
if (file.type.startsWith("image/")) {
|
||||
// It's an image file, no error
|
||||
errorMessage.textContent = "";
|
||||
} else {
|
||||
// Invalid file type
|
||||
errorMessage.textContent = "Invalid file type. Please select an image.";
|
||||
input.value = ""; // Clear the input field
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -23,7 +23,7 @@
|
||||
}
|
||||
} ?>
|
||||
<label for="customerName">Customer Name</label>
|
||||
<input type="hidden" name="customer_name" value="<?= $details['business_id']; ?>" />
|
||||
<input type="hidden" name="customer_name" value="<?= $invoice_details['customer_id']; ?>" />
|
||||
<input type="text" class="form-control" value="<?= $displayvalue ?>" readonly/>
|
||||
<?php } else { ?>
|
||||
<label for="customerName">Customer Name<span class="text-danger"> *</span></label>
|
||||
@ -348,7 +348,7 @@
|
||||
<div class="input-group-prepend">
|
||||
<div class="input-group-text">+91</div>
|
||||
</div>
|
||||
<input type="text" class="form-control" id="cus_mobile_no" placeholder="Mobile Number (Enter only numbers)" required maxlength="10" onkeypress="return restriction(event)" onchange="checkExisting(this.value,'mobile_no','cus_mobile_no')" />
|
||||
<input type="text" class="form-control" id="cus_mobile_no" placeholder="Mobile Number (Enter only numbers)" maxlength="10" onkeypress="return restriction(event)" onchange="checkExisting(this.value,'mobile_no','cus_mobile_no')" />
|
||||
<div class="invalid-feedback"> Please provide. </div>
|
||||
</div>
|
||||
<span id="mobileValidationMessage"></span>
|
||||
@ -596,8 +596,9 @@
|
||||
var iid_arr = <?php echo json_encode($invoice_item_details); ?>;
|
||||
var custid = "<?= isset($invoice_details['customer_id']) ? $invoice_details['customer_id'] : ""; ?>";
|
||||
var inv_number = "<?= isset($invoice_details['invoice_number']) ? $invoice_details['invoice_number'] : ""; ?>";
|
||||
var ship_addrid = "";
|
||||
if (custid != '') {
|
||||
var ship_addrid = "<?= isset($invoice_details['shipping_address_id']) ? $invoice_details['shipping_address_id'] : ""; ?>";
|
||||
ship_addrid = "<?= isset($invoice_details['shipping_address_id']) ? $invoice_details['shipping_address_id'] : ""; ?>";
|
||||
var bill_addrid = "<?= isset($invoice_details['billing_address_id']) ? $invoice_details['billing_address_id'] : ""; ?>";
|
||||
var cust_ship_arr = <?= isset($customer_shipping_arr) ? json_encode($customer_shipping_arr) : "[]"; ?>;
|
||||
if (cust_ship_arr.length > 0) {
|
||||
@ -666,6 +667,13 @@
|
||||
return serial_number;
|
||||
}
|
||||
|
||||
|
||||
if (custid != '' && (ship_addrid == undefined || ship_addrid == null || ship_addrid == '0' || ship_addrid == '')) {
|
||||
|
||||
$("#storeShippingAddress").prop("readonly", false);
|
||||
console.log('ship addrid is undefined, null, 0, or empty');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Billing ajax call
|
||||
|
||||
@ -1,175 +1,165 @@
|
||||
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="page-title-box page-title-box-alt">
|
||||
<h4 class="page-title"><?= $page_name ?></h4>
|
||||
<h4 class="page-title"><?= $page_name ?></h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="offset-md-3 col-md-5">
|
||||
<div class="offset-md-3 col-md-5">
|
||||
<form action="<?php echo base_url('general_inv_rp'); ?>" method="post">
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="col-md-7">
|
||||
<input class="form-control input-daterange-datepicker" type="text" name="date" value="<?php if(isset($selected_data)) { echo $selected_data; } ?>"/>
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<button type="submit" class="btn btn-primary">Generate Report</button>
|
||||
<div class="row">
|
||||
<div class="col-md-7">
|
||||
<input class="form-control input-daterange-datepicker" type="text" name="date" value="<?php if (isset($selected_data)) { echo $selected_data; } ?>" />
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<button type="submit" class="btn btn-primary">Generate Report</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
||||
<div class="table-responsive">
|
||||
<table id="datatable-buttons" class="table table-striped dt-responsive nowrap w-100">
|
||||
<thead>
|
||||
<tr>
|
||||
<th hidden>id</th>
|
||||
<th>Invoice No</th>
|
||||
<th>Invoice Date</th>
|
||||
<th>Customer Name</th>
|
||||
<th>GST</th>
|
||||
<th>Discount</th>
|
||||
<th>Count</th>
|
||||
<th>OT Charges</th>
|
||||
<th>Total</th>
|
||||
<th>Status</th>
|
||||
<th>Payment</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table id="datatable-buttons" class="table table-striped nowrap w-100">
|
||||
<thead>
|
||||
<tr>
|
||||
<th hidden>id</th>
|
||||
<th>Invoice No</th>
|
||||
<th>Invoice Date</th>
|
||||
<th>Customer Name</th>
|
||||
<th>GST</th>
|
||||
<th>Discount</th>
|
||||
<th>Count</th>
|
||||
<th>OT Charges</th>
|
||||
<th>Total</th>
|
||||
<th>Status</th>
|
||||
<th>Payment</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
|
||||
<tbody>
|
||||
<?php foreach ($report_data as $row)
|
||||
{ ?>
|
||||
<tr>
|
||||
<td hidden><?php echo $row->invoice_id;?></td>
|
||||
<td><?php echo $row->invoice_number;?></td>
|
||||
<td><?php echo $row->formatted_invoice_date;?></td>
|
||||
<td><?php echo $row->first_name." ".$row->last_name;?></td>
|
||||
<td><?php echo $row->tax . '%'; ?></td>
|
||||
<td><?php echo '₹' . number_format($row->discount, 2, '.', ','); ?></td>
|
||||
<td><?php echo $row->item_count;?></td>
|
||||
<td><?php echo '₹' . number_format($row->shipping_charge, 2, '.', ','); ?></td>
|
||||
<td><?php echo '₹' . number_format($row->total_amount, 2, '.', ','); ?></td>
|
||||
<td><?php echo $row->status;?></td>
|
||||
<td><?php echo $row->payment_method;?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
<tbody>
|
||||
<?php foreach ($report_data as $row) { ?>
|
||||
<tr>
|
||||
<td hidden><?php echo $row->invoice_id; ?></td>
|
||||
<td><?php echo $row->invoice_number; ?></td>
|
||||
<td><?php echo $row->formatted_invoice_date; ?></td>
|
||||
<td><?php echo $row->first_name . " " . $row->last_name; ?></td>
|
||||
<td><?php echo $row->tax . '%'; ?></td>
|
||||
<td><?php echo '₹' . number_format($row->discount, 2, '.', ','); ?></td>
|
||||
<td><?php echo $row->item_count; ?></td>
|
||||
<td><?php echo '₹' . number_format($row->shipping_charge, 2, '.', ','); ?></td>
|
||||
<td><?php echo '₹' . number_format($row->total_amount, 2, '.', ','); ?></td>
|
||||
<td><?php echo $row->status; ?></td>
|
||||
<td><?php echo $row->payment_method; ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
</div> <!-- end card body-->
|
||||
</div> <!-- end card -->
|
||||
</div><!-- end col-->
|
||||
</table>
|
||||
</div>
|
||||
</div> <!-- end card body-->
|
||||
</div> <!-- end card -->
|
||||
</div><!-- end col-->
|
||||
</div>
|
||||
<!-- end row-->
|
||||
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function() {
|
||||
|
||||
var table = $('#datatable-buttons').DataTable({
|
||||
"order": [[0, 'desc']],
|
||||
"dom": 'Bfrtip',
|
||||
buttons: [
|
||||
{
|
||||
extend: 'print',
|
||||
text: 'Print',
|
||||
title: 'General Invoice Report',
|
||||
customize: function(win) {
|
||||
// Exclude the first and last columns
|
||||
$(win.document.body).find('table').find('th:first-child, td:first-child').remove();
|
||||
var table = $('#datatable-buttons').DataTable({
|
||||
"order": [
|
||||
[0, 'desc']
|
||||
],
|
||||
"dom": 'Bfrtip',
|
||||
buttons: [{
|
||||
extend: 'print',
|
||||
text: 'Print',
|
||||
title: 'General Invoice Report',
|
||||
customize: function(win) {
|
||||
// Exclude the first and last columns
|
||||
$(win.document.body).find('table').find('th:first-child, td:first-child').remove();
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'csv',
|
||||
text: 'CSV',
|
||||
title: 'General Invoice Report',
|
||||
exportOptions: {
|
||||
columns: ':not(:first-child)'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'csv',
|
||||
text: 'CSV',
|
||||
title: 'General Invoice Report',
|
||||
exportOptions: {
|
||||
columns: ':not(:first-child)'
|
||||
}
|
||||
}
|
||||
],
|
||||
columnDefs: [
|
||||
{ type: 'date', targets: [1,2,3,4,5,6,7,8,9], orderable: false } // Specify the column index for date sorting and disable sorting
|
||||
]
|
||||
});
|
||||
],
|
||||
columnDefs: [{
|
||||
type: 'date',
|
||||
targets: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
orderable: false
|
||||
} // Specify the column index for date sorting and disable sorting
|
||||
]
|
||||
});
|
||||
|
||||
// Add date range filter and dropdowns
|
||||
$('#datatable-buttons thead tr').clone(true).appendTo('#datatable-buttons thead');
|
||||
$('#datatable-buttons thead tr:eq(1) th').each(function (i) {
|
||||
var title = $(this).text();
|
||||
// Add date range filter and dropdowns
|
||||
$('#datatable-buttons thead tr').clone(true).appendTo('#datatable-buttons thead');
|
||||
$('#datatable-buttons thead tr:eq(1) th').each(function(i) {
|
||||
var title = $(this).text();
|
||||
// For non-"Invoice Date" columns, add a dropdown
|
||||
var uniqueValues = table.column(i).data().unique().sort();
|
||||
var select = $('<select class="form-control form-control-sm"><option value="">Search ' + title + '</option></select>')
|
||||
.appendTo($(this).empty())
|
||||
.on('change', function () {
|
||||
.on('change', function() {
|
||||
var val = $.fn.dataTable.util.escapeRegex($(this).val());
|
||||
table.column(i)
|
||||
.search(val ? '^' + val + '$' : '', true, false)
|
||||
.draw();
|
||||
});
|
||||
|
||||
uniqueValues.each(function (d, j) {
|
||||
uniqueValues.each(function(d, j) {
|
||||
select.append('<option value="' + d + '">' + d + '</option>');
|
||||
});
|
||||
|
||||
$('input', this).on('keyup change', function () {
|
||||
if (table.column(i).search() !== this.value) {
|
||||
table
|
||||
.column(i)
|
||||
.search(this.value)
|
||||
.draw();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Add date range filter for "Invoice Date" column
|
||||
var dateRangeFilter = $('<input type="text" class="form-control form-control-sm" placeholder="Select date range"/>')
|
||||
.appendTo('#datatable-buttons thead tr:eq(2) th:eq(2)')
|
||||
.daterangepicker({
|
||||
autoUpdateInput: false,
|
||||
locale: {
|
||||
format: 'DD/MM/YYYY',
|
||||
cancelLabel: 'Clear'
|
||||
}
|
||||
})
|
||||
.on('click', function (e) {
|
||||
// Prevent sorting when clicking on the date range filter input
|
||||
e.stopPropagation();
|
||||
$('input', this).on('keyup change', function() {
|
||||
if (table.column(i).search() !== this.value) {
|
||||
table
|
||||
.column(i)
|
||||
.search(this.value)
|
||||
.draw();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Add date range filter for "Invoice Date" column
|
||||
var dateRangeFilter = $('<input type="text" class="form-control form-control-sm" placeholder="Select date range"/>')
|
||||
.appendTo('#datatable-buttons thead tr:eq(2) th:eq(2)')
|
||||
.daterangepicker({
|
||||
autoUpdateInput: false,
|
||||
locale: {
|
||||
format: 'DD/MM/YYYY',
|
||||
cancelLabel: 'Clear'
|
||||
}
|
||||
})
|
||||
.on('click', function(e) {
|
||||
// Prevent sorting when clicking on the date range filter input
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
dateRangeFilter.on('apply.daterangepicker', function(ev, picker) {
|
||||
table.column(2)
|
||||
.search(picker.startDate.format('YYYY-MM-DD') + ' to ' + picker.endDate.format('YYYY-MM-DD'))
|
||||
.draw();
|
||||
});
|
||||
|
||||
dateRangeFilter.on('cancel.daterangepicker', function() {
|
||||
dateRangeFilter.val('');
|
||||
table.column(2).search('').draw();
|
||||
});
|
||||
|
||||
dateRangeFilter.on('apply.daterangepicker', function (ev, picker) {
|
||||
table.column(2)
|
||||
.search(picker.startDate.format('YYYY-MM-DD') + ' to ' + picker.endDate.format('YYYY-MM-DD'))
|
||||
.draw();
|
||||
});
|
||||
|
||||
dateRangeFilter.on('cancel.daterangepicker', function () {
|
||||
dateRangeFilter.val('');
|
||||
table.column(2).search('').draw();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
@ -35,7 +35,7 @@
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table id="datatable-buttons" class="table table-striped dt-responsive nowrap w-100">
|
||||
<table id="datatable-buttons" class="table table-striped nowrap w-100">
|
||||
<thead class="custom-thead">
|
||||
<tr>
|
||||
<th>Product Name</th>
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table id="datatable-buttons" class="table table-striped dt-responsive nowrap w-100">
|
||||
<table id="datatable-buttons" class="table table-striped nowrap w-100">
|
||||
<thead>
|
||||
<tr>
|
||||
<th hidden>id</th>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user