diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php
index 5a267c5..ac25baa 100755
--- a/app/Controllers/Jobcard.php
+++ b/app/Controllers/Jobcard.php
@@ -657,7 +657,7 @@ class Jobcard extends BaseController
$data['logged_user_role'] = $this->session->get('logged_user_role');
if($rework == 're-work') { $data['rework']= true; }
-
+ // dd($data);
@@ -677,6 +677,9 @@ class Jobcard extends BaseController
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") {
$data['status'] = $this->request->getPost('status');
diff --git a/app/Views/job_card_form.php b/app/Views/job_card_form.php
index a9fba7f..1dcaa35 100755
--- a/app/Views/job_card_form.php
+++ b/app/Views/job_card_form.php
@@ -716,7 +716,7 @@ $(document).ready(async function() {
newRow += '
| ' +
' | ' +
- ' | ' +
+ ' | ' +
''+
action+
''+
@@ -969,6 +969,8 @@ $(document).ready(function() {
$('form').submit(function() {
return validateProductAdded();
});
+
+
$(document).on('keyup change', '.item-amount', function() {
amount = $(this).val();
@@ -1030,6 +1032,9 @@ $(document).ready(function() {
display_rate = $(this).closest('tr').find('.rate-d-only');
display_rate.val(actual_amount.toFixed(2));
+ }else if(className == 'product'){
+ row = $(this).closest('tr');
+ calculateTotalAmount(row);
}
// Calculate amount and update amount input field
updateCalculations();
@@ -1325,14 +1330,16 @@ $(document).ready(function() {
// console.log(item);
return item.product_id == productId;
});
- console.log(product,'product');
+
$(quantity).attr('max', product.qty_stock);
+ tax = parseFloat(product.cgst) + parseFloat(product.sgst);
// 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('.rate-d-only').val(unitPrice);
- $(this).closest('tr').find('.item-rate').val(unitPrice);
-
+ $(this).closest('tr').find('.rate-d-only').val(unitPrice).attr('value', 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
// calculateAmount($(this).closest('tr'));
@@ -1453,33 +1460,38 @@ $(document).ready(function() {
// Retrieve CGST and SGST values from the database for the selected product
var productId = $(row).find('select[name="item_details[]"]').val();
if (type.includes("product")) {
- // var product = products.find(function(item) {
+
var product = productarray.find(function(item) {
return item.product_id == productId;
});
- console.log(product);
- if (product !== undefined) {
- var cgst = parseFloat(product.cgst);
- var sgst = parseFloat(product.sgst);
+
+ // if (product !== undefined) {
+ // var cgst = parseFloat(product.cgst);
+ // var sgst = parseFloat(product.sgst);
+
+ // // Calculate total tax by adding CGST and SGST
+ // var tax = cgst + sgst;
+ // $(row).find('.item-tax').val(tax.toFixed(0));
+ // finrate = Number(product.unit_price) * quantity;
+
+ // $(row).find('.item-rate').val(finrate);
+ // // rate = Number(product.unit_price);
+ // rate = Number(product.total_amount);
+ // var amount = rate * quantity;
+ // 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));
+
- // Calculate total tax by adding CGST and SGST
- var tax = cgst + sgst;
- $(row).find('.item-tax').val(tax.toFixed(0));
- finrate = Number(product.unit_price) * quantity;
- $(row).find('.item-rate').val(finrate);
- // rate = Number(product.unit_price);
- rate = Number(product.total_amount);
- var amount = rate * quantity;
- total_tax_amt = amount - finrate;
- }else{
- tax1 = $(row).find('.item-tax').val();
- rate1 = $(row).find('.rate-d-only').val();
- var amount = rate1 * quantity;
- total_tax_amt = amount;
- }
-
- $(row).find('.total-tax-amount').val(total_tax_amt.toFixed(2));
- $(row).find('.item-amount').val(amount.toFixed(2));
}
else if(type.includes("service")) {
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) => {
console.log(cost,tax,tr,cls);
console.log('cost,tax,tr,cls');
@@ -1580,7 +1615,7 @@ $(document).ready(function() {
' | | ' +
' | ' +
' | ' +
- ' | ' +
+ ' | ' +
' | ' +
' | ' +
' | ' +
@@ -1641,6 +1676,21 @@ $(document).ready(function() {
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 calculateSubtotal() {
var subtotal = 0;