FIX_service_and_jobCard_issue:ss

This commit is contained in:
sriramv 2024-04-29 15:15:54 +05:30
parent ad7775387d
commit 7f6c123501
4 changed files with 96 additions and 111 deletions

View File

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

View File

@ -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'];
}

View File

@ -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'];
}

View File

@ -107,62 +107,11 @@
<th>Rate</th>
<th>Tax</th>
<th>Amount</th>
<th hidden></th>
<th style="width: 10px;">Action</th>
<th hidden></th>
</tr>
</thead>
<tbody>
<!-- Dynamically add rows for item details -->
<?php if (isset($product) && !empty($product)) : ?>
<?php foreach ($product as $salechild) :
if ($salechild['isactive'] == 1) : ?>
<tr>
<td hidden style="width:10%;">
<input type="number" class="form-control labour-cost" name="labour_cost[]">
</td>
<td>
<select class="form-control book-select SelExample product" name="item_details[]" required data-toggle="select2" id="" style="width: 249px !important;">
<option value="">Select a Product</option>
<?php foreach ($product as $value) : ?>
<?php if ((int)$value["isactive"] === 1) : ?>
<option value="<?= $value["product_id"] ?>" <?= isset($salechild['product_id']) && $salechild['product_id'] == $value["product_id"] ? 'selected' : '' ?>>
<?= $value["product_name"]; ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</td>
<td style="width:10%;">
<input type="number" class="form-control item-quantity" name="quantity[]" min="0" value="<?= isset($salechild['qty']) ? $salechild['qty'] : '' ?>">
</td>
<td style="width:10%;">
<input type="text" class="form-control item-rate" name="unit-price[]" readonly value="<?= isset($salechild['net_price']) ? $salechild['net_price'] : '' ?>">
</td>
<td style="width:10%;">
<input type="text" class="form-control item-tax" name="item-tax[]" value="<?= isset($salechild['tax']) ? $salechild['tax'] : '' ?>">
</td>
<!-- <td style="width:12%;">
<input type="number" class="form-control item-discount-amount" min="0" name="discount_amount[]" value="<?= isset($salechild['discount']) ? $salechild['discount'] : '' ?>">
</td>
<td style="width:10%;">
<select class="form-control item-discount-type" name="discount_type[]">
<option value="" <?= isset($salechild['discount_type']) && $salechild['discount_type'] == '₹' ? 'selected' : '' ?>>₹</option>
<option value="%" <?= isset($salechild['discount_type']) && $salechild['discount_type'] == '%' ? 'selected' : '' ?>>%</option>
</select>
</td> -->
<td style="width:12%;">
<input type="text" class="form-control item-amount" name="amount[]" value="<?= isset($salechild['amount']) ? $salechild['amount'] : '' ?>">
</td>
<td hidden><input type="hidden" value="<?= isset($salechild['job_card_product_id']) ? $salechild['job_card_product_id'] : '' ?>"name="job_card_product_id[]"></td>
<td style="width:12%;">
<center><i class="fa fa-trash remove-item"></i></center>
</td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<!-- You can add more rows as needed using JavaScript -->
</tbody>
</table>
<div class="form-group text-right m-b-0">
@ -356,11 +305,12 @@ $(document).ready(async function() {
'<td hidden><input name="id" value="'+value.job_card_service_id+'"></td>' +
'</tr>';
// 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() {
'</tr>';
$('#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 = '<tr class="dummy"><td hidden style="width:10%;"><input type="number" class="form-control labour-cost" name="labour_cost[]"></td><td style="padding-left: 40px !important;"><i class="fa fa-caret-right" style="font-size: 20px;margin-top: 8px;position: absolute;margin-left: -18px;" aria-hidden="true"></i><input type="text" class="form-control labour-cost" value="Labour Cost"></td>' +
'<td style="width:10%;"></td>' +
'<td style="width:10%;"></td>' +
'<td style="width:8%;"></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]" value="' + data + '" readonly/></td>' +
'<td hidden></td>' +
'<td hidden></td>' +
'</tr>';
$('#productItemTable tbody').append(newRow);
// $(newRow).insertAfter(tr);
initializeSelect2();
}
function edit_product_data(products) {
for (const product of products) {
var newRow = `<tr><td hidden style="width:10%;">
<input type="number" class="form-control labour-cost" name="labour_cost[]"></td>
var newRow = `<tr><td hidden style="width:10%;"><input type="number" class="form-control labour-cost" name="labour_cost"></td>
<td style="padding-left: 40px !important;"><i class="fa fa-caret-right" style="font-size: 20px;margin-top: 8px;position: absolute;margin-left: -18px;" aria-hidden="true"></i>
<select class="form-control book-select SelExample product" name="item_details[]" required data-toggle="select2" style="width: 249px !important;">`;
@ -468,7 +435,14 @@ $(document).ready(async function() {
// Event listener for vehicle selection change
$('.vehicle-select').change(function() {
var vehicleId = $(this).val();
fetch_data(vehicleId)
});
if($('.vehicle-select').val()) {
fetch_data($('.vehicle-select').val())
}
function fetch_data(vehicleId) {
if (vehicleId !== '') {
// Find the selected vehicle
var selectedVehicle = vehicles.find(function(vehicle) {
@ -528,7 +502,7 @@ $(document).ready(async function() {
console.error('Make ID not found for the selected vehicle');
}
}
});
}
});
<?php
@ -572,13 +546,15 @@ $(document).ready(async function() {
// Loop through each <tr> element
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 fifthTd = row.querySelector("td:nth-child(5)");
var sixthTd = row.querySelector("td:nth-child(6)");
var eigthTd = row.querySelector("td:nth-child(8)");
var thirdTd = row.querySelector("td:nth-child(3)");
var fifthTd = row.querySelector("td:nth-child(5)");
var sixthTd = row.querySelector("td:nth-child(6)");
var eigthTd = row.querySelector("td:nth-child(8)");
// Check if the second <td> element contains a <select> 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 = '<tr class="dummy"><td hidden style="width:10%;"><input type="number" class="form-control labour-cost" name="labour_cost[]"></td><td style="padding-left: 40px !important;"><i class="fa fa-caret-right" style="font-size: 20px;margin-top: 8px;position: absolute;margin-left: -18px;" aria-hidden="true"></i><input type="text" class="form-control labour-cost" value="Labour Cost"></td>' +
'<td style="width:10%;"></td>' +
'<td style="width:10%;"></td>' +
'<td style="width:8%;"></td>' +
'<td style="width:12%;"><input type="text" class="form-control item-amount" name="amount[]" value="' + data + '" readonly/></td>' +
'<td hidden></td>' +
'<td hidden></td>' +
'</tr>';
// $('#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 = <?php echo isset($service_1) ? json_encode($service_1) : json_encode($service) ?>;
// console.log(servicearray);
var newRow = '<tr class="service_class"><td hidden style="width:10%;"> <input type="number" class="form-control labour-cost" name="labour_cost[]"></td><td><select class="form-control book-select SelExample service" name="service_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Service</option>';
var newRow = '<tr class="service_class"><td hidden style="width:10%;"> <input type="number" class="form-control labour_cost" name="labour_cost"></td><td><select class="form-control book-select SelExample service" name="service_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Service</option>';
for (var i = 0; i < servicearray.length; i++)
{
@ -972,7 +957,7 @@ $(document).ready(async function() {
$('#addcomplaint').click(function() {
complaint = <?php echo json_encode($complaint) ?>;
// console.log(productarray);
var newRow = '<tr class="complaint_class"><td hidden style="width:10%;"> <input type="number" class="form-control labour-cost" name="labour_cost[]"></td><td><select class="form-control book-select SelExample complaint" id="complaint_detail" name="complaint_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Complaint</option>';
var newRow = '<tr class="complaint_class"><td hidden style="width:10%;"> <input type="number" class="form-control labour_cost" name="labour_cost[]"></td><td><select class="form-control book-select SelExample complaint" id="complaint_detail" name="complaint_details[]" required data-toggle="select2" style="width: 249px !important;"><option value="">Select a Complaint</option>';
for (var i = 0; i < complaint.length; i++)
{
@ -1113,7 +1098,7 @@ $(document).ready(async function() {
return vehicle.vehicle_id == vehicleId;
});
console.log(selectedClient);
$('input[name="client_id"]').val(selectedClient.client_name);
$('input[name="billing_address"]').val(selectedClient.address);
@ -1140,10 +1125,6 @@ $(document).ready(async function() {
var selectedClients = clients.find(function(client) {
return client.client_id == clientId;
});
// Populate the billing address, city, state, country, and postal code fields
$('input[id="clientMobile"]').val(selectedClients.mobile_no);
}
@ -1232,7 +1213,7 @@ $(document).ready(async function() {
window.location.reload();
} else {
toastr.warning("Failed to save vehicle. Please try again");
toastr.warning("Failed to save vehicle. Please try again");
}
},
error: function(xhr, status, error) {