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 @@
                     product_name ?>
                      
                     qty ?>
-                    
+                    nos
                     tax ?>%
                     
                     
@@ -174,22 +174,22 @@
             
                 
                 Total Taxable Value
-                
+                tax ?>
             
             
                 
                 CGST
-                
+                tax / 2 ?>
             
             
                 
                 SGST
-                
+                tax / 2 ?>
             
             
                 
                 Total
-                
+                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 = `
                                 
-                                `;
 
             for (var i = 0; i < servicearray.length; i++) 
             {
                 var service = servicearray[i];
+                if(value.service_id == service.service_id)
                 newRow += '';
             }
 
 
 
             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 = ' ' + - '' + - '' + - '' + - '' + + '' + + '' + + '' + + '' + '
'+ '
'+ '
'+ @@ -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 = ` ' + - '' + '' + + '' + ' ' + - '' + + '' + '' + '' + ''; @@ -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 ' + - '' + - '' + - '' + - '' + + 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 = '' + - '' + '' + + '' + ' ' + - '' + + '' + '' + '' + ''; @@ -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 = ' ' + - '' + - '' + - '' + - '' + + '' + + '' + + '' + + '' + '
'+ '
'+ '
'+ @@ -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 @@
> - - + +