diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php index f9d702f..1614604 100644 --- a/app/Controllers/Jobcard.php +++ b/app/Controllers/Jobcard.php @@ -406,7 +406,7 @@ class Jobcard extends BaseController $product['product_id'] = $pt->p_id; $product['qty'] = $pt->qty; $product['tax'] = $pt->tax; - $product['amount'] = $pt->amount; + $product['amount'] = $pt->amount / $pt->qty; if(empty($pt->id)) { $JobcardProductModel->insert($product); $job_card_product_id = $JobcardProductModel->getInsertID(); diff --git a/app/Controllers/Products.php b/app/Controllers/Products.php index 5c4c50b..6542ca5 100644 --- a/app/Controllers/Products.php +++ b/app/Controllers/Products.php @@ -36,7 +36,7 @@ class Products extends BaseController return view('product_list',$data); } else { $ProductModel = new ProductModel(); - $products = $ProductModel->where('branch_id',$this->session->get('logged_user_branch_id'))->orderBy('product_name')->findAll(); + $products = $ProductModel->get_products($this->session->get('logged_user_branch_id')); $data['products']=$products; // echo "
";
// print_r($products);die;
diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php
index c6bb107..361c204 100644
--- a/app/Controllers/Sales.php
+++ b/app/Controllers/Sales.php
@@ -353,7 +353,7 @@ public function delete_sales_product()
// return view('invoice_pdf_template', ['sales' => $data,'items'=>$items, 'business' => $business , 'vehicle' => $vehicle,'bike_model'=>$bike_model,'bike_make'=>$bike_make]);
// Generate the PDF content (HTML) with data
$html = view('invoice_pdf_template', ['sales' => $data,'company_address'=>$company_address,'items'=>$items, 'business' => $business , 'vehicle' => $vehicle,'bike_model'=>$bike_model,'bike_make'=>$bike_make]);
-
+ // echo $html;die;
// Load HTML into the mPDF instance
$mpdf->WriteHTML($html);
diff --git a/app/Models/ProductModel.php b/app/Models/ProductModel.php
index e4474d0..f51707b 100644
--- a/app/Models/ProductModel.php
+++ b/app/Models/ProductModel.php
@@ -33,6 +33,7 @@ class ProductModel extends Model
$this->select('products.*, manufacturer.manufacturer_name');
$this->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id');
$this->where('products.branch_id', $branch_id);
+ $this->orderBy('products.product_name');
return $this->findAll();
}
diff --git a/app/Views/invoice_pdf_template.php b/app/Views/invoice_pdf_template.php
index 98bd871..0110958 100644
--- a/app/Views/invoice_pdf_template.php
+++ b/app/Views/invoice_pdf_template.php
@@ -161,7 +161,7 @@
= $item->product_name ?>
= $item->qty ?>
-
+ nos
= $item->tax ?>%
@@ -174,22 +174,22 @@
Total Taxable Value
-
+ = $sales[0]->tax ?>
CGST
-
+ = $sales[0]->tax / 2 ?>
SGST
-
+ = $sales[0]->tax / 2 ?>
Total
-
+ = $sales[0]->total ?>
Amount Chargeable (in words)
diff --git a/app/Views/job_card_form.php b/app/Views/job_card_form.php
index 4e7bae7..3c989f0 100644
--- a/app/Views/job_card_form.php
+++ b/app/Views/job_card_form.php
@@ -85,6 +85,7 @@
+
@@ -130,9 +131,10 @@
Item Details
- Qty
Rate
- Tax
+
+ Qty
+ Tax (%)
Amount
Action
@@ -311,22 +313,22 @@ $(document).ready(async function() {
// console.log(servicearray);
var newRow = `
- ';
@@ -336,7 +338,7 @@ $(document).ready(async function() {
initializeSelect2();
/** APPEND CHILD PRODUCT */
await edit_product_data(value.product);
- editlabourcost(value.labour_cost);
+ editlabourcost(value,'service_lb');
}
}
@@ -346,19 +348,20 @@ $(document).ready(async function() {
for (const value of edit_complaint_data) {
complaint = ;
// console.log(productarray);
- var newRow = ' ';
+ var newRow = ' ';
for (var i = 0; i < complaint.length; i++)
{
var complaints = complaint[i];
+ if(value.complaint_id == complaints.complaint_id)
newRow += '';
}
newRow += ' ' +
- ' ' +
- ' ' +
- ' ' +
- ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
''+
' '+
''+
@@ -377,7 +380,7 @@ $(document).ready(async function() {
initializeSelect2();
/** APPEND CHILD PRODUCT */
await edit_product_data(value.product);
- editlabourcost(value.labour_cost)
+ editlabourcost(value,'complaint_lb')
}
}
@@ -386,10 +389,10 @@ $(document).ready(async function() {
if(edit_ccomplaint_data.length > 0) {
for (const value of edit_ccomplaint_data) {
var newRow = ' ' +
- ' ' +
- ' ' +
- ' ' +
- ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
''+
' '+
''+
@@ -408,21 +411,21 @@ $(document).ready(async function() {
initializeSelect2();
/** APPEND CHILD PRODUCT */
await edit_product_data(value.product);
- editlabourcost(value.labour_cost)
+ editlabourcost(value,'custom_complaint_lb')
}
}
- function editlabourcost(data) {
- var newRow = ' ' +
- ' ' +
- ' ' +
- ' ' +
- ' ' +
+ function editlabourcost(data,cls) {
+ total_wih_tax = parseInt(data.labour_cost) + (parseInt(data.labour_cost) * (data.tax / 100));
+ var newRow = ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
' ' +
' ' +
' ';
-
$('#productItemTable tbody').append(newRow);
// $(newRow).insertAfter(tr);
initializeSelect2();
@@ -431,16 +434,17 @@ $(document).ready(async function() {
function edit_product_data(products) {
for (const product of products) {
- var newRow = `
+ total_wih_tax = parseInt(product.amount) + (parseInt(product.amount) * (product.tax / 100));
+ var newRow = `
`;
newRow += '';
newRow += ' ' +
- ' ' +
' ' +
+ ' ' +
' ' +
- ' ' +
+ ' ' +
' ' +
' ' +
' ';
@@ -568,9 +572,9 @@ $(document).ready(async function() {
tableRows.forEach(function(row) {
var firstTd = row.querySelector("td:nth-child(1)");
var secondTd = row.querySelector("td:nth-child(2)");
- var thirdTd = row.querySelector("td:nth-child(3)");
+ var thirdTd = row.querySelector("td:nth-child(4)");
var fifthTd = row.querySelector("td:nth-child(5)");
- var sixthTd = row.querySelector("td:nth-child(6)");
+ var sixthTd = row.querySelector("td:nth-child(3)");
var eigthTd = row.querySelector("td:nth-child(8)");
// Check if the second element contains a element
@@ -707,13 +711,14 @@ $(document).ready(async function() {
// Access unit price from product and set it as rate
var unitPrice = parseInt(service_data.price); // Convert to float if necessary
console.log(service_data);
- $(this).closest('tr').find('.item-rate').val(unitPrice);
+ $(this).closest('tr').find('.item-rate1').val(unitPrice);
+ $(this).closest('tr').find('.item-tax').val(Number(service_data.tax));
$(this).closest('tr').find('.labour_cost').val(parseInt(service_data.labour_cost));
- await labourcost(service_data.labour_cost,$(this).closest('tr'));
+ await labourcost(service_data.labour_cost,service_data.tax,$(this).closest('tr'),'service_lb');
service_child_products(service_data,$(this).closest('tr'))
}
- calculateAmount($(this).closest('tr'),className);
+ calculateAmount($(this).closest('tr'),className,'parent');
updateCalculations();
});
@@ -732,22 +737,21 @@ $(document).ready(async function() {
// Access unit price from product and set it as rate
var unitPrice = parseInt(complaint_data.labour_charge); // Convert to float if necessary
- $(this).closest('tr').find('.item-rate').val(unitPrice);
+ $(this).closest('tr').find('.item-rate1').val(unitPrice);
+ $(this).closest('tr').find('.item-tax').val(Number(complaint_data.tax));
$(this).closest('tr').find('.labour_cost').val(parseInt(complaint_data.labour_charge));
- await labourcost(complaint_data.labour_charge,$(this).closest('tr'));
+ await labourcost(complaint_data.labour_charge,complaint_data.tax,$(this).closest('tr'),'complaint_lb');
}
- calculateAmount($(this).closest('tr'),className);
+ calculateAmount($(this).closest('tr'),'complaint','parent');
updateCalculations();
});
// Function to calculate amount based on rate and quantity
- function calculateAmount(row,type) {
- // console.log(row);
+ function calculateAmount(row,type,action) {
+ console.log(type);
var rate = $(row).find('.item-rate').val();
var quantity = $(row).find('.item-quantity').val();
- var amount = rate * quantity;
- $(row).find('.item-amount').val(amount);
// Retrieve CGST and SGST values from the database for the selected product
var productId = $(row).find('select[name="item_details[]"]').val();
@@ -762,48 +766,76 @@ $(document).ready(async function() {
// Calculate total tax by adding CGST and SGST
var tax = cgst + sgst;
$(row).find('.item-tax').val(tax.toFixed(2));
+ finrate = Number(product.unit_price) * quantity;
+ $(row).find('.item-rate').val(finrate);
+ rate = Number(product.unit_price);
+ var amount = (parseInt(rate) + (parseInt(rate) * tax / 100)) * quantity;
+ $(row).find('.item-amount').val(amount);
}
else if(type.includes("service")) {
- var productId = $(row).find('select[name="service_details[]"]').val();
- var product = services.find(function(item) {
- return item.service_id == productId;
- });
- var cgst = parseFloat(product.cgst);
- var igst = parseFloat(product.sgst);
+ // var productId = $(row).find('select[name="service_details[]"]').val();
+ // var product = services.find(function(item) {
+ // return item.service_id == productId;
+ // });
+ // var cgst = parseFloat(product.cgst);
+ // var igst = parseFloat(product.sgst);
- // Calculate total tax by adding CGST and SGST
- var tax = cgst + igst;
- console.log(tax);
- $(row).find('.item-tax').val(tax.toFixed(2));
+ // // Calculate total tax by adding CGST and SGST
+ // var tax = cgst + igst;
+ // console.log(tax);
+ if(action == 'parent') var $previousRow = row;
+ else var $previousRow = row.prevAll(".service_class").first();
+
+ var tax = $previousRow.find('.item-tax').val();
+ $(row).find('.item-tax').val(parseInt(tax).toFixed(2));
+
+ var $targetField = $previousRow.find('.item-rate1');
+ finrate = parseInt($targetField.val()) * quantity;
+ rate = $targetField.val();
+ $(row).find('.item-rate').val(finrate);
+
+ var amount = (parseInt(rate) + (parseInt(rate) * tax / 100)) *quantity;
+ $(row).find('.item-amount').val(amount);
}
else if(type.includes("complaint")) {
- var productId = $(row).find('select[name="complaint_details[]"]').val();
- var product = complaint.find(function(item) {
- return item.complaint_id == productId;
- });
- console.log(product);
- var cgst = parseFloat(product.cgst);
- var igst = parseFloat(product.sgst);
+ // var productId = $(row).find('select[name="complaint_details[]"]').val();
+ // var product = complaint.find(function(item) {
+ // return item.complaint_id == productId;
+ // });
+ // console.log(product);
+ // var cgst = parseFloat(product.cgst);
+ // var igst = parseFloat(product.sgst);
- // Calculate total tax by adding CGST and SGST
- var tax = cgst + igst;
- $(row).find('.item-tax').val(tax.toFixed(2));
+ // // Calculate total tax by adding CGST and SGST
+ // var tax = cgst + igst;
+ if(action == 'parent') var $previousRow = row;
+ else var $previousRow = row.prevAll(".complaint_class").first();
+
+ var tax = $previousRow.find('.item-tax').val();
+ $(row).find('.item-tax').val(parseInt(tax).toFixed(2));
+
+ var $targetField = $previousRow.find('.item-rate1');
+ finrate = parseInt($targetField.val()) * quantity;
+ $(row).find('.item-rate').val(finrate);
+
+ rate = $targetField.val();
+ var amount = (parseInt(rate) + (parseInt(rate) * tax / 100)) *quantity;
+ $(row).find('.item-amount').val(amount);
}
}
- const labourcost = async (data,tr) => {
- var newRow = ' ' +
- ' ' +
- ' ' +
- ' ' +
- ' ' +
+ const labourcost = async (cost,tax,tr,cls) => {
+ total_wih_tax = parseInt(cost) + (parseInt(cost) * (tax / 100));
+ var newRow = ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
' ' +
' ' +
' ';
-
- // $('#productItemTable tbody').append(newRow);
$(newRow).insertAfter(tr);
initializeSelect2();
}
@@ -820,14 +852,14 @@ $(document).ready(async function() {
var sgst = parseFloat(product.sgst);
// Calculate total tax by adding CGST and SGST
var tax = cgst + sgst;
-
+ total_wih_tax = parseInt(product.unit_price) + (parseInt(product.unit_price) * (tax / 100));
var newRow = '';
newRow += '';
newRow += ' ' +
- ' ' +
' ' +
+ ' ' +
' ' +
- ' ' +
+ ' ' +
' ' +
' ' +
' ';
@@ -841,19 +873,15 @@ $(document).ready(async function() {
}
// Event listener for quantity change
- $(document).on('input change', '.item-quantity', async function() {
- calculateAmount($(this).closest('tr'));
- updateCalculations();
- });
-
- $(document).on('click', '.item-quantity', async function() {
+ $(document).on('input', '.item-quantity', async function() {
+ calculateAmount($(this).closest('tr'), $(this).closest('tr').attr('class'),'child');
updateCalculations();
});
// Function to calculate subtotal
function calculateSubtotal() {
var subtotal = 0;
- $('.item-amount').each(function() {
+ $('.item-rate').each(function() {
subtotal += parseFloat($(this).val()) || 0;
});
return subtotal;
@@ -861,14 +889,16 @@ $(document).ready(async function() {
// Function to calculate total tax
function calculateTax() {
- var tax = 0;
- $('.item-tax').each(function() {
- var taxPercentage = parseFloat($(this).val()) || 0;
- var amount = parseFloat($(this).closest('tr').find('.item-amount').val()) || 0;
- var taxValue = (taxPercentage / 100) * amount; // Convert percentage to absolute value
- tax += taxValue;
+ var subtotal = 0;
+ $('.item-rate').each(function() {
+ subtotal += parseFloat($(this).val()) || 0;
});
- return tax;
+
+ var total = 0;
+ $('.item-amount').each(function() {
+ total += parseFloat($(this).val()) || 0;
+ });
+ return total - subtotal;
}
// Function to calculate total discount
@@ -890,12 +920,11 @@ $(document).ready(async function() {
// Function to calculate total
function calculateTotal() {
- var subtotal = calculateSubtotal();
- var tax = calculateTax();
- var discount = calculateDiscount();
- var total = subtotal + tax - discount;
- // return total;
- return Math.round(total);
+ var total = 0;
+ $('.item-amount').each(function() {
+ total += parseFloat($(this).val()) || 0;
+ });
+ return total;
}
// Update subtotal, tax, and total
@@ -928,8 +957,8 @@ $(document).ready(async function() {
}
newRow += ' ' +
- ' ' +
' ' +
+ ' ' +
' ' +
' ' +
' ' +
@@ -955,10 +984,10 @@ $(document).ready(async function() {
}
newRow += ' ' +
- ' ' +
- ' ' +
- ' ' +
- ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
' ' +
' ' +
' ';
@@ -971,6 +1000,19 @@ $(document).ready(async function() {
}
});
+ /** To achieve this functionality where entering a value in one input field automatically populates another input field
+ * ONLY APPLICABLE IN COMPLAINT ONLY
+ */
+ $(document).ready(function() {
+ /** TAX FIELD */
+ $(document).on('input change', '.item-quantity-service_lb', async function() {
+ var enteredValue = $(this).val();
+ var $previousRow = $(this).closest("tr").prevAll(".service_class").first();
+ var $targetField = $previousRow.find('.item-quantity');
+ $targetField.val(enteredValue);
+ });
+ });
+
$('#addcomplaint').click(function() {
complaint = ;
var newRow = ' ';
@@ -982,10 +1024,10 @@ $(document).ready(async function() {
}
newRow += ' ' +
- ' ' +
- ' ' +
- ' ' +
- ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
''+
' '+
''+
@@ -1001,14 +1043,26 @@ $(document).ready(async function() {
$('#productItemTable tbody').append(newRow);
initializeSelect2();
});
+ /** To achieve this functionality where entering a value in one input field automatically populates another input field
+ * ONLY APPLICABLE IN COMPLAINT ONLY
+ */
+ $(document).ready(function() {
+ /** TAX FIELD */
+ $(document).on('input change', '.item-quantity-complaint_lb', async function() {
+ var enteredValue = $(this).val();
+ var $previousRow = $(this).closest("tr").prevAll(".complaint_class").first();
+ var $targetField = $previousRow.find('.item-quantity');
+ $targetField.val(enteredValue);
+ });
+ });
$('#addCustomComplaint').click(function() {
complaint = ;
var newRow = ' ' +
- ' ' +
- ' ' +
- ' ' +
- ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
' ' +
''+
' '+
@@ -1023,38 +1077,52 @@ $(document).ready(async function() {
' ' +
' ';
- newRow += ' ' +
- ' ' +
- ' ' +
- ' ' +
- ' ' +
+ newRow += ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
' ' +
' ' +
' ';
+
$('#productItemTable tbody').append(newRow);
initializeSelect2();
-
- // Function to increment class name And this Class name for for remove the parent Custom Comlaint is remove the child to remove
- function incrementClassName(className) {
- var classNumber = parseInt(className.match(/\d+/)[0]);
- return className.replace(/\d+/, classNumber + 1);
- }
-
- // Initial class name
- var initialClassName = 'custom_complaint_class';
- var currentClassName;
-
- // Loop to check for existence of subsequent classes
- for (var i = 2000; i <= 2100; i++) {
- currentClassName = initialClassName + '_' + i;
- if ($('.' + currentClassName).length === 0) {
- // If the class doesn't exist, increment the last found class
- $('.' + initialClassName).removeClass(initialClassName).addClass(currentClassName);
- break;
- }
- }
});
+ /** To achieve this functionality where entering a value in one input field automatically populates another input field
+ * ONLY APPLICABLE IN CUSTOM COMPLAINT ONLY
+ */
+ $(document).ready(function() {
+ /** RATE FIELD */
+ $(document).on('input change', '.item-rate_cc', async function() {
+ var enteredValue = $(this).val();
+ var $previousRow = $(this).closest("tr").prevAll(".custom_complaint_class").first();
+ var $targetField = $previousRow.find('.item-rate1');
+ $targetField.val(enteredValue);
+ var $targetField2 = $previousRow.find('.labour_cost');
+ $targetField2.val(enteredValue);
+ updateCalculations();
+ });
+ /** TAX FIELD */
+ $(document).on('input change', '.item-tax_cc', async function() {
+ var enteredValue = $(this).val();
+ var $previousRow = $(this).closest("tr").prevAll(".custom_complaint_class").first();
+ var $targetField = $previousRow.find('.item-tax');
+ $targetField.val(enteredValue);
+ updateCalculations();
+ });
+ /** AMOUNT FIELD */
+ $(document).on('input change', '.item-amount_cc', async function() {
+ var enteredValue = $(this).val();
+ var $previousRow = $(this).closest("tr").prevAll(".custom_complaint_class").first();
+ var $targetField = $previousRow.find('.item-amount1');
+ $targetField.val(enteredValue);
+ updateCalculations();
+ });
+ });
+
+
$(document).on('input', '.item_dummy', function() {
var row = $(this).closest('tr');
var labourCostInput = row.prevAll('.custom_complaint_class:first').find('.labour_cost');
@@ -1062,7 +1130,9 @@ $(document).ready(async function() {
labourCostInput.val(dummyValue);
});
- /** REMOVE ITEMS FROM THE TABLE **/
+ /**
+ * REMOVE ITEMS FROM THE TABLE
+ * **/
delete_items_id = [{ 'service': [], 'complaint': [], 'custom_complaint': [] }];
$(document).on('click', '.remove-item', function() {
var $closestTR = $(this).closest('tr');
@@ -1082,7 +1152,7 @@ $(document).ready(async function() {
else if($closestTR.attr('class') == "custom_complaint_class")
{
id = $closestTR.find('input[name="id"]').val();
- delete_items_id[0].complaint.push(id);
+ delete_items_id[0].custom_complaint.push(id);
console.log(delete_items_id);
}
diff --git a/app/Views/service_form.php b/app/Views/service_form.php
index 0a84a0d..0e49166 100644
--- a/app/Views/service_form.php
+++ b/app/Views/service_form.php
@@ -42,7 +42,7 @@
>
-
+
@@ -61,8 +61,8 @@
-
-
+
+