GWM : JC calculation
This commit is contained in:
parent
f2f818a62b
commit
d93b7c68d5
@ -657,7 +657,7 @@ class Jobcard extends BaseController
|
|||||||
$data['logged_user_role'] = $this->session->get('logged_user_role');
|
$data['logged_user_role'] = $this->session->get('logged_user_role');
|
||||||
if($rework == 're-work') { $data['rework']= true; }
|
if($rework == 're-work') { $data['rework']= true; }
|
||||||
|
|
||||||
|
// dd($data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -677,6 +677,9 @@ class Jobcard extends BaseController
|
|||||||
|
|
||||||
public function add_jobs()
|
public function add_jobs()
|
||||||
{
|
{
|
||||||
|
// $data = json_decode($_POST['products']);
|
||||||
|
// $service_data = $data[0]->service;
|
||||||
|
// dd($service_data);
|
||||||
|
|
||||||
if($this->session->get('logged_user_role') == "Store Manager") {
|
if($this->session->get('logged_user_role') == "Store Manager") {
|
||||||
$data['status'] = $this->request->getPost('status');
|
$data['status'] = $this->request->getPost('status');
|
||||||
|
|||||||
@ -716,7 +716,7 @@ $(document).ready(async function() {
|
|||||||
<?php } ?>
|
<?php } ?>
|
||||||
newRow += '<td> <input type="text" class="form-control taxable-value item-tax" name="item-tax[]" value="' + product.tax + '" readonly /></td>' +
|
newRow += '<td> <input type="text" class="form-control taxable-value item-tax" name="item-tax[]" value="' + product.tax + '" readonly /></td>' +
|
||||||
'<td><input type="text" class="form-control total-tax-amount" value="'+total_tax_amt.toFixed(2)+'" readonly /></td>' +
|
'<td><input type="text" class="form-control total-tax-amount" value="'+total_tax_amt.toFixed(2)+'" readonly /></td>' +
|
||||||
'<td><input type="text" class="form-control item-amount" name="amount[]" value="' + Math.round(total_wih_tax).toFixed(2) + '" onblur="floatInput(event)" readonly/></center></td>' +
|
'<td><input type="text" class="form-control item-amount" name="amount[]" value="' + Math.round(total_wih_tax).toFixed(2) + '" onblur="floatInput(event)" /></center></td>' +
|
||||||
'<td>'+
|
'<td>'+
|
||||||
action+
|
action+
|
||||||
'<input value="product" name="item_type" hidden>'+
|
'<input value="product" name="item_type" hidden>'+
|
||||||
@ -970,6 +970,8 @@ $(document).ready(function() {
|
|||||||
return validateProductAdded();
|
return validateProductAdded();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$(document).on('keyup change', '.item-amount', function() {
|
$(document).on('keyup change', '.item-amount', function() {
|
||||||
amount = $(this).val();
|
amount = $(this).val();
|
||||||
tax = $(this).closest('tr').find('.item-tax').val();
|
tax = $(this).closest('tr').find('.item-tax').val();
|
||||||
@ -1030,6 +1032,9 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
display_rate = $(this).closest('tr').find('.rate-d-only');
|
display_rate = $(this).closest('tr').find('.rate-d-only');
|
||||||
display_rate.val(actual_amount.toFixed(2));
|
display_rate.val(actual_amount.toFixed(2));
|
||||||
|
}else if(className == 'product'){
|
||||||
|
row = $(this).closest('tr');
|
||||||
|
calculateTotalAmount(row);
|
||||||
}
|
}
|
||||||
// Calculate amount and update amount input field
|
// Calculate amount and update amount input field
|
||||||
updateCalculations();
|
updateCalculations();
|
||||||
@ -1325,13 +1330,15 @@ $(document).ready(function() {
|
|||||||
// console.log(item);
|
// console.log(item);
|
||||||
return item.product_id == productId;
|
return item.product_id == productId;
|
||||||
});
|
});
|
||||||
console.log(product,'product');
|
|
||||||
|
|
||||||
$(quantity).attr('max', product.qty_stock);
|
$(quantity).attr('max', product.qty_stock);
|
||||||
|
tax = parseFloat(product.cgst) + parseFloat(product.sgst);
|
||||||
// Access unit price from product and set it as rate
|
// Access unit price from product and set it as rate
|
||||||
var unitPrice = parseFloat(product.unit_price); // Convert to float if necessary
|
var unitPrice = parseFloat(product.unit_price); // Convert to float if necessary
|
||||||
$(this).closest('tr').find('.rate-d-only').val(unitPrice);
|
$(this).closest('tr').find('.rate-d-only').val(unitPrice).attr('value', unitPrice);
|
||||||
$(this).closest('tr').find('.item-rate').val(unitPrice);
|
$(this).closest('tr').find('.item-rate').val(unitPrice).attr('value', unitPrice);
|
||||||
|
$(this).closest('tr').find('.item-tax').val(tax).attr('value', tax);
|
||||||
|
|
||||||
// Calculate amount and update amount input field
|
// Calculate amount and update amount input field
|
||||||
// calculateAmount($(this).closest('tr'));
|
// calculateAmount($(this).closest('tr'));
|
||||||
@ -1453,33 +1460,38 @@ $(document).ready(function() {
|
|||||||
// Retrieve CGST and SGST values from the database for the selected product
|
// Retrieve CGST and SGST values from the database for the selected product
|
||||||
var productId = $(row).find('select[name="item_details[]"]').val();
|
var productId = $(row).find('select[name="item_details[]"]').val();
|
||||||
if (type.includes("product")) {
|
if (type.includes("product")) {
|
||||||
// var product = products.find(function(item) {
|
|
||||||
var product = productarray.find(function(item) {
|
var product = productarray.find(function(item) {
|
||||||
return item.product_id == productId;
|
return item.product_id == productId;
|
||||||
});
|
});
|
||||||
console.log(product);
|
|
||||||
if (product !== undefined) {
|
|
||||||
var cgst = parseFloat(product.cgst);
|
|
||||||
var sgst = parseFloat(product.sgst);
|
|
||||||
|
|
||||||
// Calculate total tax by adding CGST and SGST
|
// if (product !== undefined) {
|
||||||
var tax = cgst + sgst;
|
// var cgst = parseFloat(product.cgst);
|
||||||
$(row).find('.item-tax').val(tax.toFixed(0));
|
// var sgst = parseFloat(product.sgst);
|
||||||
finrate = Number(product.unit_price) * quantity;
|
|
||||||
$(row).find('.item-rate').val(finrate);
|
// // Calculate total tax by adding CGST and SGST
|
||||||
// rate = Number(product.unit_price);
|
// var tax = cgst + sgst;
|
||||||
rate = Number(product.total_amount);
|
// $(row).find('.item-tax').val(tax.toFixed(0));
|
||||||
var amount = rate * quantity;
|
// finrate = Number(product.unit_price) * quantity;
|
||||||
total_tax_amt = amount - finrate;
|
|
||||||
}else{
|
// $(row).find('.item-rate').val(finrate);
|
||||||
tax1 = $(row).find('.item-tax').val();
|
// // rate = Number(product.unit_price);
|
||||||
rate1 = $(row).find('.rate-d-only').val();
|
// rate = Number(product.total_amount);
|
||||||
var amount = rate1 * quantity;
|
// var amount = rate * quantity;
|
||||||
total_tax_amt = amount;
|
// total_tax_amt = amount - finrate;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
taxPercentage = $(row).find('.item-tax').val();
|
||||||
|
itemRate = $(row).find('.item-rate').val();
|
||||||
|
subtotal = itemRate * quantity;
|
||||||
|
taxAmount = subtotal * taxPercentage / 100;
|
||||||
|
totalAmount = subtotal + taxAmount;
|
||||||
|
|
||||||
|
|
||||||
|
$(row).find('.total-tax-amount').val(taxAmount.toFixed(2)).attr('value', taxAmount.toFixed(2));
|
||||||
|
$(row).find('.item-amount').val(totalAmount.toFixed(2)).attr('value', totalAmount.toFixed(2));
|
||||||
|
|
||||||
|
|
||||||
$(row).find('.total-tax-amount').val(total_tax_amt.toFixed(2));
|
|
||||||
$(row).find('.item-amount').val(amount.toFixed(2));
|
|
||||||
}
|
}
|
||||||
else if(type.includes("service")) {
|
else if(type.includes("service")) {
|
||||||
if(action == 'parent') var $previousRow = row;
|
if(action == 'parent') var $previousRow = row;
|
||||||
@ -1536,6 +1548,29 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function calculateTotalAmount(row) {
|
||||||
|
|
||||||
|
var tax = $(row).find('.item-tax').val();
|
||||||
|
var quantity = $(row).find('.item-quantity').val();
|
||||||
|
var final_amount = $(row).find('.item-amount').val();
|
||||||
|
var taxRate = tax/100;
|
||||||
|
|
||||||
|
|
||||||
|
var amt = final_amount/((1+taxRate));
|
||||||
|
|
||||||
|
$(row).find('.item-result').val(parseFloat(amt).toFixed(2)).attr('value', amt.toFixed(2));
|
||||||
|
|
||||||
|
var taxAmount = final_amount-amt;
|
||||||
|
console.log(taxAmount);
|
||||||
|
$(row).find('.tax-amount').val(parseFloat(taxAmount).toFixed(2)).attr('value', taxAmount.toFixed(2));
|
||||||
|
|
||||||
|
var rate = amt / quantity;
|
||||||
|
|
||||||
|
$(row).find('.item-rate').val(parseFloat(rate).toFixed(2)).attr('value', parseFloat(rate).toFixed(2));
|
||||||
|
$(row).find('.rate-d-only').val(parseFloat(rate).toFixed(2)).attr('value', parseFloat(rate).toFixed(2));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const labourcost = async (cost,tax,tr,cls) => {
|
const labourcost = async (cost,tax,tr,cls) => {
|
||||||
console.log(cost,tax,tr,cls);
|
console.log(cost,tax,tr,cls);
|
||||||
console.log('cost,tax,tr,cls');
|
console.log('cost,tax,tr,cls');
|
||||||
@ -1580,7 +1615,7 @@ $(document).ready(function() {
|
|||||||
'<td><input type="number" class="form-control item-quantity" min="0" max="'+Number(product.qty_stock)+'" value="1" name="quantity[]"/></td>' +
|
'<td><input type="number" class="form-control item-quantity" min="0" max="'+Number(product.qty_stock)+'" value="1" name="quantity[]"/></td>' +
|
||||||
'<td><input type="text" class="form-control taxable-value item-tax" name="item-tax[]" value="' + tax + '" readonly /></td>' +
|
'<td><input type="text" class="form-control taxable-value item-tax" name="item-tax[]" value="' + tax + '" readonly /></td>' +
|
||||||
'<td><input type="text" class="form-control total-tax-amount" value="'+ total_tax_amt.toFixed(2) +'" readonly /></td>' +
|
'<td><input type="text" class="form-control total-tax-amount" value="'+ total_tax_amt.toFixed(2) +'" readonly /></td>' +
|
||||||
'<td><input type="text" class="form-control item-amount" name="amount1[]" value="' + Math.round(total_wih_tax).toFixed(2) + '" onblur="floatInput(event)" readonly/></td>' +
|
'<td><input type="text" class="form-control item-amount" name="amount1[]" value="' + Math.round(total_wih_tax).toFixed(2) + '" onblur="floatInput(event)" /></td>' +
|
||||||
'<td><center><i class="fa fa-trash remove-item"></i></center><input value="product" name="item_type" hidden></td>' +
|
'<td><center><i class="fa fa-trash remove-item"></i></center><input value="product" name="item_type" hidden></td>' +
|
||||||
'<td hidden><input type="hidden" name="id" value=""></td>' +
|
'<td hidden><input type="hidden" name="id" value=""></td>' +
|
||||||
'<td hidden><input value="'+product.product_name+'" name="name"></td>' +
|
'<td hidden><input value="'+product.product_name+'" name="name"></td>' +
|
||||||
@ -1641,6 +1676,21 @@ $(document).ready(function() {
|
|||||||
updateCalculations();
|
updateCalculations();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//gwm
|
||||||
|
$(document).on('keyup change', '.rate-d-only', function() {
|
||||||
|
alert();
|
||||||
|
|
||||||
|
className = $(this).closest('tr').attr('class');
|
||||||
|
if(className == 'product') {
|
||||||
|
calculateAmount($(this).closest('tr'), $(this).closest('tr').attr('class'),'child');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate amount and update amount input field
|
||||||
|
updateCalculations();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Function to calculate subtotal
|
// Function to calculate subtotal
|
||||||
function calculateSubtotal() {
|
function calculateSubtotal() {
|
||||||
var subtotal = 0;
|
var subtotal = 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user