From 7f6c123501257b48f194c8d096664472bce234d1 Mon Sep 17 00:00:00 2001 From: sriramv Date: Mon, 29 Apr 2024 15:15:54 +0530 Subject: [PATCH] FIX_service_and_jobCard_issue:ss --- app/Controllers/Jobcard.php | 10 +- app/Models/JobcardComplaintModel.php | 2 +- app/Models/JobcardServiceModel.php | 2 +- app/Views/job_card_form.php | 193 ++++++++++++--------------- 4 files changed, 96 insertions(+), 111 deletions(-) diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php index 6efdb08..243be8d 100644 --- a/app/Controllers/Jobcard.php +++ b/app/Controllers/Jobcard.php @@ -129,6 +129,7 @@ class Jobcard extends BaseController $jobs=$JobcardModel->where('job_card_id', $job_card_id)->get()->getRowArray(); $data['jobs']=$jobs; $VehicleModel = new VehicleModel(); + $vehicles = $VehicleModel->where('isactive',1)->where('vehicle_id',$jobs['vehicle_id']) ->where('branch_id',$this->session->get('logged_user_branch_id')) ->first(); @@ -142,14 +143,15 @@ class Jobcard extends BaseController $model_name = $BikemodelsModel->where('model_id',$modelId)->select('model_name')->first(); $data['make_model'] = $make_name['make'].' ' . $model_name['model_name']; // Encode the modelId before searching - $encodedModelId = json_encode([$modelId]); + $encodedModelId = json_encode([$makeId]); // echo $encodedModelId;die; // Load the ProductModel // Query the database to find the product based on make_id and model_id - $product = $productModel->where('make_id', $makeId) - ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false) + $product = $productModel + // ->where('make_id', $makeId) + ->where('JSON_CONTAINS(make_id, \'' . $encodedModelId . '\')', null, false) ->findAll(); $data['product']=$product; @@ -236,6 +238,7 @@ class Jobcard extends BaseController // Insert into the service table $service['job_card_id'] = $job_card_id; $service['service_id'] = $item->service_id; + $service['labour_cost'] = $item->labour_cost; $service['qty'] = $item->quality; $service['tax'] = $item->tax; $service['amount'] = $item->amount; @@ -282,6 +285,7 @@ class Jobcard extends BaseController // Insert into the service table $service['job_card_id'] = $job_card_id; $service['complaint_id'] = $item->complaint_id; + $service['labour_cost'] = $item->labour_cost; $service['qty'] = $item->quality; $service['tax'] = $item->tax; $service['amount'] = $item->amount; diff --git a/app/Models/JobcardComplaintModel.php b/app/Models/JobcardComplaintModel.php index b8e6fad..4266225 100644 --- a/app/Models/JobcardComplaintModel.php +++ b/app/Models/JobcardComplaintModel.php @@ -5,5 +5,5 @@ class JobcardComplaintModel extends Model { protected $table = 'job_card_complaint'; protected $primaryKey = 'job_card_complaint_id'; - protected $allowedFields = ['job_card_complaint_id','job_card_id','complaint_id','product_id', 'qty', 'tax', 'amount','isactive']; + protected $allowedFields = ['job_card_complaint_id','job_card_id','complaint_id', 'labour_cost','product_id', 'qty', 'tax', 'amount','isactive']; } \ No newline at end of file diff --git a/app/Models/JobcardServiceModel.php b/app/Models/JobcardServiceModel.php index c86ef92..03740f1 100644 --- a/app/Models/JobcardServiceModel.php +++ b/app/Models/JobcardServiceModel.php @@ -5,7 +5,7 @@ class JobcardServiceModel extends Model { protected $table = 'job_card_service'; protected $primaryKey = 'job_card_service_id'; - protected $allowedFields = ['job_card_service_id', 'job_card_id', 'service_id', 'product_id', 'qty','tax','amount', 'isactive']; + protected $allowedFields = ['job_card_service_id', 'job_card_id', 'service_id', 'labour_cost', 'product_id', 'qty','tax','amount', 'isactive']; } \ No newline at end of file diff --git a/app/Views/job_card_form.php b/app/Views/job_card_form.php index 049507c..46b9d57 100644 --- a/app/Views/job_card_form.php +++ b/app/Views/job_card_form.php @@ -107,62 +107,11 @@ Rate Tax Amount - + Action - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
@@ -356,11 +305,12 @@ $(document).ready(async function() { '' + ''; - + // console.log(value); tr = $('#productItemTable tbody').append(newRow); initializeSelect2(); /** APPEND CHILD PRODUCT */ await edit_product_data(value.product); + editlabourcost(value.labour_cost); } } @@ -401,6 +351,7 @@ $(document).ready(async function() { initializeSelect2(); /** APPEND CHILD PRODUCT */ await edit_product_data(value.product); + editlabourcost(value.labour_cost) } } @@ -428,18 +379,34 @@ $(document).ready(async function() { ''; - $('#productItemTable tbody').append(newRow); + $('#productItemTable tbody').append(newRow); initializeSelect2(); /** APPEND CHILD PRODUCT */ await edit_product_data(value.product); + // editlabourcost(value.product) } } + function editlabourcost(data) { + var newRow = '' + + '' + + '' + + '' + + '' + + '' + + '' + + ''; + + + $('#productItemTable tbody').append(newRow); + // $(newRow).insertAfter(tr); + initializeSelect2(); + } + function edit_product_data(products) { for (const product of products) { - var newRow = ` - + var newRow = ` element + var selectFirstElement = firstTd.querySelector("input"); var selectElement = secondTd.querySelector("select, textarea"); var selectThirdElement = thirdTd.querySelector("input"); var selectFifthElement = fifthTd.querySelector("input"); @@ -595,6 +571,7 @@ $(document).ready(async function() { var tax = selectFifthElement.value; var amount = selectsixthElement.value; var id = selecteightElement.value; + var labour_cost = selectFirstElement.value; // Output the class name and selected value // console.log("Class Name: " + className + ", Selected Value: " + selectedValue); @@ -613,12 +590,12 @@ $(document).ready(async function() { else if(className.includes("service")) { mapTable = "service"; - dataMapArray[0].service.push({'id': id, 'service_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount }); + dataMapArray[0].service.push({'id': id, 'labour_cost': labour_cost, 'service_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount }); } else if(className.includes("complaint")) { mapTable = "complaint"; - dataMapArray[0].complaint.push({ 'id': id, 'complaint_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount }); + dataMapArray[0].complaint.push({ 'id': id, 'labour_cost': labour_cost, 'complaint_id' : selectedValue , 'quality' : quality, 'tax': tax, 'amount': amount }); } else if(className.includes("custom-comp")) { @@ -660,7 +637,6 @@ $(document).ready(async function() { // Event listener for product selection $(document).on('change', 'select[name="item_details[]"]', function() { - // data_contruction_for_save(); // Get class name of the select element var className = $(this).attr('class'); var productId = $(this).val(); @@ -671,7 +647,6 @@ $(document).ready(async function() { var product = products.find(function(item) { return item.product_id == productId; }); - // Access unit price from product and set it as rate var unitPrice = parseFloat(product.unit_price); // Convert to float if necessary $(this).closest('tr').find('.item-rate').val(unitPrice); @@ -686,10 +661,7 @@ $(document).ready(async function() { }); // Event listener for product selection - $(document).on('change', 'select[name="service_details[]"]', function() { - - // data_contruction_for_save(); - + $(document).on('change', 'select[name="service_details[]"]', async function() { // Get class name of the select element var className = $(this).attr('class'); var productId = $(this).val(); @@ -700,13 +672,13 @@ $(document).ready(async function() { var service_data = services.find(function(item) { return item.service_id == productId; }); - // 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('.labour_cost').val(parseInt(service_data.labour_cost)); + await labourcost(service_data.labour_cost,$(this).closest('tr')); service_child_products(service_data,$(this).closest('tr')) - // Calculate amount and update amount input field - // calculateAmount($(this).closest('tr')); } calculateAmount($(this).closest('tr'),className); @@ -714,14 +686,12 @@ $(document).ready(async function() { }); // Event listener for product selection - $(document).on('change', 'select[name="complaint_details[]"]', function() { - // data_contruction_for_save(); + $(document).on('change', 'select[name="complaint_details[]"]', async function() { // Get class name of the select element var className = $(this).attr('class'); var productId = $(this).val(); var quantity = $(this).closest('tr').find('.item-quantity').val(1); - if(className.includes("complaint")) { // Find product details from JSON var complaint_data = complaint.find(function(item) { @@ -731,9 +701,8 @@ $(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); - - // Calculate amount and update amount input field - // calculateAmount($(this).closest('tr')); + $(this).closest('tr').find('.labour_cost').val(parseInt(complaint_data.labour_charge)); + await labourcost(complaint_data.labour_charge,$(this).closest('tr')); } calculateAmount($(this).closest('tr'),className); @@ -793,6 +762,22 @@ $(document).ready(async function() { } + const labourcost = async (data,tr) => { + var newRow = '' + + '' + + '' + + '' + + '' + + '' + + '' + + ''; + + + // $('#productItemTable tbody').append(newRow); + $(newRow).insertAfter(tr); + initializeSelect2(); + } + const service_child_products = async (data,tr) => { console.log(); console.log(JSON.parse(data.product_id)); @@ -840,25 +825,25 @@ $(document).ready(async function() { // Function to calculate subtotal function calculateSubtotal() { - var subtotal = 0; - $('.item-amount').each(function() { - subtotal += parseFloat($(this).val()) || 0; - }); - return subtotal; + var subtotal = 0; + $('.item-amount').each(function() { + subtotal += parseFloat($(this).val()) || 0; + }); + return subtotal; } // 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; - }); - return tax; + 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; + }); + return tax; } @@ -884,12 +869,12 @@ $(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 subtotal = calculateSubtotal(); + var tax = calculateTax(); + var discount = calculateDiscount(); + var total = subtotal + tax - discount; + // return total; + return Math.round(total); } @@ -945,7 +930,7 @@ $(document).ready(async function() { $('#addService').click(function() { servicearray = ; // console.log(servicearray); - var newRow = '