Add Product Module and Major issues fixes : ps

This commit is contained in:
VE10-Sanjeev 2024-01-03 11:27:48 +05:30
parent 2d1b057501
commit 687fc818e8
10 changed files with 265 additions and 190 deletions

View File

@ -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,35 +104,93 @@ 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);
$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($imageData);
$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) {

View File

@ -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;

View File

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

View File

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

View File

@ -102,7 +102,7 @@ public function getSchemeNames()
}
return $schemes;
print_r($schemes);die();
// print_r($schemes);die();
}
public function getSchemeNameById($schemeId)

View File

@ -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 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">
<?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; ?>
<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'] : '' ?>" />
@ -204,3 +210,20 @@
// 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>

View File

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

View File

@ -1,4 +1,3 @@
<!-- start page title -->
<div class="row">
<div class="col-md-4">
@ -23,16 +22,12 @@
</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">
<table id="datatable-buttons" class="table table-striped nowrap w-100">
<thead>
<tr>
<th hidden>id</th>
@ -51,8 +46,7 @@
<tbody>
<?php foreach ($report_data as $row)
{ ?>
<?php foreach ($report_data as $row) { ?>
<tr>
<td hidden><?php echo $row->invoice_id; ?></td>
<td><?php echo $row->invoice_number; ?></td>
@ -82,10 +76,11 @@
$(document).ready(function() {
var table = $('#datatable-buttons').DataTable({
"order": [[0, 'desc']],
"order": [
[0, 'desc']
],
"dom": 'Bfrtip',
buttons: [
{
buttons: [{
extend: 'print',
text: 'Print',
title: 'General Invoice Report',
@ -103,8 +98,11 @@ $(document).ready(function() {
}
}
],
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
]
});
@ -164,12 +162,4 @@ $(document).ready(function() {
});
});
</script>

View File

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

View File

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