diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php index 1614604..652bc70 100644 --- a/app/Controllers/Jobcard.php +++ b/app/Controllers/Jobcard.php @@ -2,6 +2,7 @@ namespace App\Controllers; use App\Models\BusinessModel; +use App\Models\BranchModel; use App\Models\JobcardModel; use App\Models\JobcardComplaintModel; use App\Models\JobcardCustomComplaintModel; @@ -27,6 +28,7 @@ class Jobcard extends BaseController public $BikemakeModel; public $BusinessModel; public $JobcardModel; + public $BranchModel; public function __construct() { @@ -35,6 +37,7 @@ class Jobcard extends BaseController $this->BikemakeModel = new BikemakeModel(); $this->BusinessModel = new BusinessModel(); $this->JobcardModel = new JobcardModel(); + $this->BranchModel = new BranchModel(); } @@ -56,9 +59,20 @@ class Jobcard extends BaseController $data['vehicle'] = $this->JobcardModel->get_jobcard_vehicle_details($job_card_id); $bus_id = $this->session->get('logged_user_business_id'); $data['job_card'] = $this->JobcardModel->where('job_card_id',$job_card_id)->findAll(); - $data['company_address'] = $this->BusinessModel->where('business_id', $bus_id)->where('isactive', 1)->findAll(); + $data['company_address'] = $this->BranchModel->where('branch_id', $this->session->get('logged_user_branch_id'))->where('business_id', $bus_id)->where('isactive', 1)->findAll(); + // echo json_encode($data['company_address']);die; $productdata = $this->JobcardModel->get_jobcard_products_details($job_card_id); // echo json_encode($productdata);die; + + if($data['job_card'][0]['inv_no'] == '') + { + /** GENERATE INV NO */ + $uniqueId = sprintf('%06d', mt_rand(0, 999999)); + $date = date('Ymdhms'); + $invoiceNumber = 'INV' . '-' . $date . $uniqueId; + $this->JobcardModel->update($job_card_id,['inv_no' => $invoiceNumber]); + $data['job_card'][0]['inv_no'] = $invoiceNumber; + } $servicedata = $this->JobcardModel->get_jobcard_service($job_card_id); $complaintdata = $this->JobcardModel->get_jobcard_complaint($job_card_id); @@ -70,7 +84,7 @@ class Jobcard extends BaseController // Calculate total amount and total tax foreach ($labourcost as $product) { $totalAmount += $product["labour_amount"]; - $totalTax += $product["labour_amount"] * ($product["tax"] / 100); + $totalTax = $product["tax"]; } // Calculate total @@ -115,7 +129,7 @@ class Jobcard extends BaseController // Generate the PDF content (HTML) with data $html = view('invoice_pdf_template_jobcard', $data); - +echo $html;die; // Load HTML into the mPDF instance $mpdf->WriteHTML($html); @@ -305,6 +319,7 @@ class Jobcard extends BaseController 'store_item_issued'=> $this->request->getPost('store_item_issued'), 'subtotal'=> $this->request->getPost('sub_total'), 'tax'=> $this->request->getPost('invoicetax'), + 'discount'=> ($this->request->getPost('discount')) == '' ? 0 : $this->request->getPost('discount'), 'total'=> $this->request->getPost('grand_total'), 'isactive' => 1 ]; @@ -425,16 +440,28 @@ class Jobcard extends BaseController public function delete_items($delArr) { + $JobcardProductModel = new JobcardProductModel(); $JobcardServiceModel = new JobcardServiceModel(); $JobcardComplaintModel = new JobcardComplaintModel(); $JobcardCustomComplaintModel = new JobcardCustomComplaintModel(); $data = json_decode($delArr); + $product_data = $data[0]->product; + if(!empty($product_data)) { + foreach ($product_data as $item) { + $conditions = [ 'job_card_product_id' => $item ]; + // $product_deleted_data = $JobcardProductModel->where($conditions)->findAll(); + // $this->product_delete($service_deleted_data[0]['product_id']); + $JobcardProductModel->where($conditions)->delete(); + } + } + $service_data = $data[0]->service; if(!empty($service_data)) { foreach ($service_data as $item) { $conditions = [ 'job_card_service_id' => $item ]; $service_deleted_data = $JobcardServiceModel->where($conditions)->findAll(); + if(isset($service_deleted_data[0]['product_id'])) $this->product_delete($service_deleted_data[0]['product_id']); $JobcardServiceModel->where($conditions)->delete(); } @@ -445,6 +472,7 @@ class Jobcard extends BaseController foreach ($complaint_data as $item) { $conditions = [ 'job_card_complaint_id' => $item ]; $complaint_deleted_data = $JobcardComplaintModel->where($conditions)->findAll(); + if(isset($complaint_deleted_data[0]['product_id'])) $this->product_delete($complaint_deleted_data[0]['product_id']); $JobcardComplaintModel->where($conditions)->delete(); } @@ -455,6 +483,7 @@ class Jobcard extends BaseController foreach ($ccomplaint_data as $item) { $conditions = [ 'job_card_cc_id' => $item ]; $cc_deleted_data = $JobcardCustomComplaintModel->where($conditions)->findAll(); + if(isset($cc_deleted_data[0]['product_id'])) $this->product_delete($cc_deleted_data[0]['product_id']); $JobcardCustomComplaintModel->where($conditions)->delete(); } diff --git a/app/Models/JobcardModel.php b/app/Models/JobcardModel.php index aff855a..ebc91b0 100644 --- a/app/Models/JobcardModel.php +++ b/app/Models/JobcardModel.php @@ -5,10 +5,10 @@ class JobcardModel extends Model { protected $table = 'job_card'; protected $primaryKey = 'job_card_id'; - protected $allowedFields = ['job_card_id','vehicle_id','branch_id', + protected $allowedFields = ['job_card_id','inv_no','vehicle_id','branch_id', 'order_number','client_mobile_no','client_name', 'billing_address','billing_city','billing_state','billing_country', - 'billing_postal_code','status','assigned_to', 'store_item_issued','subtotal','tax','total','isactive']; + 'billing_postal_code','status','assigned_to', 'store_item_issued','subtotal','tax', 'discount','total','isactive']; @@ -80,7 +80,7 @@ class JobcardModel extends Model public function get_jobcard_service($job_id) { - $this->select('job_card.*, job_card_service.*, services.service_name as product_name, services.labour_cost as labour_amount'); + $this->select('job_card.*, job_card_service.*, services.service_name as product_name, job_card_service.labour_cost as labour_amount'); $this->join('job_card_service', 'job_card_service.job_card_id = job_card.job_card_id'); $this->join('services', 'services.service_id = job_card_service.service_id'); $this->where('job_card.isactive', 1); @@ -90,7 +90,7 @@ class JobcardModel extends Model public function get_jobcard_complaint($job_id) { - $this->select('job_card.*, job_card_complaint.*, complaints.name as product_name, complaints.labour_charge as labour_amount'); + $this->select('job_card.*, job_card_complaint.*, complaints.name as product_name, job_card_complaint.labour_cost as labour_amount'); $this->join('job_card_complaint', 'job_card_complaint.job_card_id = job_card.job_card_id'); $this->join('complaints', 'complaints.complaint_id = job_card_complaint.complaint_id'); $this->where('job_card.isactive', 1); diff --git a/app/Views/invoice_pdf_template.php b/app/Views/invoice_pdf_template.php index 6506b58..1bc72f6 100644 --- a/app/Views/invoice_pdf_template.php +++ b/app/Views/invoice_pdf_template.php @@ -20,8 +20,8 @@ table.invoice-related-table {width: 100%;border-collapse: collapse;} table.invoice-related-table th,table.invoice-related-table td {border: none;padding: 8px;text-align: left;} table.invoice-related-table th {background-color: #DAC2AD;font-weight: bold;} - table.invoice-related-table thead tr th{border: 0.5px solid black;"} - table.invoice-related-table thead tr{border: 0.5px solid black;"} + table.invoice-related-table thead tr th{border: 0.5px solid black;} + table.invoice-related-table thead tr{border: 0.5px solid black;} .business-stamp, .terms {text-align: center;margin-top: 20px;} .subtotal-table {width: 100%;margin-top: 20px;} .subtotal-table table {width: 100%;border-collapse: collapse;border: 1px solid black;} diff --git a/app/Views/invoice_pdf_template_jobcard.php b/app/Views/invoice_pdf_template_jobcard.php index 1dc36bb..ba84884 100644 --- a/app/Views/invoice_pdf_template_jobcard.php +++ b/app/Views/invoice_pdf_template_jobcard.php @@ -154,7 +154,7 @@ p {

THE MECHANIC
,
GSTNO: '.$value['gstno'] ?>
- State Name: '.$value['state'].', code'.$value['code'] ?>
+ State Name: '.$value['state'].', code'.$value['state_code'] ?>
Contact: '.$value['postal_code'] ?>
Email: '.$value['email'] ?>


@@ -175,7 +175,7 @@ p { Invoice No. - 1657 + Bike Name @@ -245,17 +245,17 @@ p { nos % - - - - + + + + Total Amount with Tax - + diff --git a/app/Views/job_card_form.php b/app/Views/job_card_form.php index d99fcbf..6cd7111 100644 --- a/app/Views/job_card_form.php +++ b/app/Views/job_card_form.php @@ -96,14 +96,14 @@ - +
-
@@ -325,9 +330,11 @@ $(document).ready(async function() { newRow += '' + - '' + + '' + + '' + '' + '' + + '' + '' + '
' + '' + @@ -358,9 +365,11 @@ $(document).ready(async function() { } newRow += '' + - '' + + '' + + '' + '' + '' + + '' + '' + '
'+ '
'+ @@ -389,9 +398,11 @@ $(document).ready(async function() { if(edit_ccomplaint_data.length > 0) { for (const value of edit_ccomplaint_data) { var newRow = ' ' + - '' + + '' + + '' + '' + '' + + '' + '' + '
'+ '
'+ @@ -415,13 +426,16 @@ $(document).ready(async function() { } } - function editlabourcost(data,cls) { + function editlabourcost(data,cls) { total_wih_tax = parseInt(data.labour_cost) + (parseInt(data.labour_cost) * (data.tax / 100)); + total_tax_amt = total_wih_tax - parseInt(data.labour_cost); var newRow = '' + - '' + - '' + - '' + - '' + + '' + + '' + + '' + + '' + + '' + + '' + '' + '' + ''; @@ -434,18 +448,22 @@ $(document).ready(async function() { function edit_product_data(products) { for (const product of products) { - total_wih_tax = parseInt(product.amount) + (parseInt(product.amount) * (product.tax / 100)); + total_wih_tax =( parseInt(product.amount) + (parseInt(product.amount) * (product.tax / 100)) )* product.qty; + console.log(total_wih_tax); + total_tax_amt = total_wih_tax - ( parseInt(product.amount) * product.qty); var newRow = ` ' + - '' + + '' + + '' + '' + - ' ' + - '' + - '' + + ' ' + + '' + + '' + + '
' + '' + ''; @@ -553,6 +571,67 @@ $(document).ready(async function() { }); $(document).on('keyup change', '.item-amount', function() { + amount = $(this).val(); + tax = $(this).closest('tr').find('.item-tax').val(); + actual_amount = Number(amount) / (1 + (Number(tax)/100)); + actual_amount = Math.round(actual_amount) + className = $(this).closest('tr').attr('class'); + if(className == 'service_lb') { + previousRow = $(this).closest('tr').prevAll(".service_class").first(); + + labour_rate = previousRow.find('.labour_cost'); + labour_rate.val(actual_amount); + + item_rate = previousRow.find('.item-rate1'); + item_rate.val(actual_amount); + + item_rate = $(this).closest('tr').find('.item-rate'); + item_rate.val(actual_amount); + + tax_amount = amount - actual_amount; + tax_rate = $(this).closest('tr').find('.total-tax-amount'); + tax_rate.val(Math.round(tax_amount)); + + display_rate = $(this).closest('tr').find('.rate-d-only'); + display_rate.val(actual_amount); + } + else if(className == 'complaint_lb') { + previousRow = $(this).closest('tr').prevAll(".complaint_class").first(); + + labour_rate = previousRow.find('.labour_cost'); + labour_rate.val(actual_amount); + + item_rate = previousRow.find('.item-rate1'); + item_rate.val(actual_amount); + + item_rate = $(this).closest('tr').find('.item-rate'); + item_rate.val(actual_amount); + + tax_amount = amount - actual_amount; + tax_rate = $(this).closest('tr').find('.total-tax-amount'); + tax_rate.val(Math.round(tax_amount)); + + display_rate = $(this).closest('tr').find('.rate-d-only'); + display_rate.val(actual_amount); + } + else if(className == 'custom_complaint_lb') { + previousRow = $(this).closest('tr').prevAll(".custom_complaint_class").first(); + labour_rate = previousRow.find('.labour_cost'); + labour_rate.val(actual_amount); + + item_rate = previousRow.find('.item-rate1'); + item_rate.val(actual_amount); + + item_rate = $(this).closest('tr').find('.item-rate'); + item_rate.val(actual_amount); + + tax_amount = amount - actual_amount; + tax_rate = $(this).closest('tr').find('.total-tax-amount'); + tax_rate.val(Math.round(tax_amount)); + + display_rate = $(this).closest('tr').find('.rate-d-only'); + display_rate.val(actual_amount); + } // Calculate amount and update amount input field updateCalculations(); }); @@ -572,10 +651,10 @@ $(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(4)"); - var fifthTd = row.querySelector("td:nth-child(5)"); - var sixthTd = row.querySelector("td:nth-child(3)"); - var eigthTd = row.querySelector("td:nth-child(8)"); + var thirdTd = row.querySelector("td:nth-child(5)"); + var fifthTd = row.querySelector("td:nth-child(6)"); + var sixthTd = row.querySelector("td:nth-child(4)"); + var eigthTd = row.querySelector("td:nth-child(10)"); // Check if the second element contains a ' + - '' + + '' + + '' + '' + - '' + + '' + + '' + '' + '' + '' + @@ -857,14 +928,17 @@ $(document).ready(async function() { // 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)); + total_tax_amt = total_wih_tax - parseInt(product.unit_price); var newRow = '' + - '' + - '' + - ' ' + + '' + + '' + + '' + + ' ' + + '' + '' + - '' + + '
' + '' + ''; @@ -888,9 +962,20 @@ $(document).ready(async function() { $('.item-rate').each(function() { subtotal += parseFloat($(this).val()) || 0; }); + return subtotal; } + // Function to calculate subtotal + function get_tax_percentage() { + var tax = 0; + $('.taxable-value').each(function(index) { + tax += parseFloat($(this).val()) || 0; + }); + + return tax; + } + // Function to calculate total tax function calculateTax() { var subtotal = 0; @@ -903,24 +988,21 @@ $(document).ready(async function() { total += parseFloat($(this).val()) || 0; }); return total - subtotal; - } + } - // Function to calculate total discount - function calculateDiscount() { - var totalDiscount = 0; - $('.item-discount-amount').each(function(index, element) { - var discountAmount = parseFloat($(element).val()) || 0; - var discountType = $(element).closest('tr').find('.item-discount-type').val(); - if (discountType === '%') { - var rate = $(element).closest('tr').find('.item-rate').val(); - var quantity = $(element).closest('tr').find('.item-quantity').val(); - var amount = rate * quantity; - discountAmount = amount * discountAmount / 100; - } - totalDiscount += discountAmount; - }); - return totalDiscount; - } + // Event listener for discount change + $(document).on('input', '#discount_amt', function() { + console.log(get_tax_percentage()); + discount_amt = Number($(this).val()); + sb_tot = calculateSubtotal() - discount_amt; + tot = sb_tot + calculateTax(); + + // console.log(get_tax_percentage()); + + $('#subtotal').val(sb_tot.toFixed(2)); + $('#invoicetax').val(calculateTax().toFixed(2)); + $('#grandtotal').val(tot.toFixed(2)); + }); // Function to calculate total function calculateTotal() { @@ -928,15 +1010,30 @@ $(document).ready(async function() { $('.item-amount').each(function() { total += parseFloat($(this).val()) || 0; }); + // discount_percentage = Number($('#discount_amt').val()); + // // Calculate the discount + // discount = total * (discount_percentage / 100); + // total_with_discount = total - discount; return total; } // Update subtotal, tax, and total function updateCalculations() { - $('#subtotal').val(calculateSubtotal().toFixed(2)); - $('#invoicetax').val(calculateTax().toFixed(2)); - $('#discount').val(calculateDiscount().toFixed(2)); - $('#grandtotal').val(calculateTotal().toFixed(2)); + if($('#discount_amt').val()) + { + discount_amt = Number($('#discount_amt').val()); + sb_tot = calculateSubtotal() - discount_amt; + tot = sb_tot + calculateTax(); + $('#subtotal').val(sb_tot.toFixed(2)); + $('#invoicetax').val(calculateTax().toFixed(2)); + $('#grandtotal').val(tot.toFixed(2)); + } + else + { + $('#subtotal').val(calculateSubtotal().toFixed(2)); + $('#invoicetax').val(calculateTax().toFixed(2)); + $('#grandtotal').val(calculateTotal().toFixed(2)); + } } // Event listener for discount change @@ -961,9 +1058,11 @@ $(document).ready(async function() { } newRow += '' + - '' + + '' + + '' + '' + '' + + '' + '' + '
' + '' + @@ -988,9 +1087,11 @@ $(document).ready(async function() { } newRow += '' + - '' + + '' + + '' + '' + '' + + '' + '' + '
' + '' + @@ -1028,9 +1129,11 @@ $(document).ready(async function() { } newRow += '' + - '' + + '' + + '' + '' + '' + + '' + '' + '
'+ '
'+ @@ -1063,10 +1166,12 @@ $(document).ready(async function() { $('#addCustomComplaint').click(function() { complaint = ; var newRow = ' ' + - '' + + '' + + '' + '' + - '' + + '' + '' + + '' + '' + '
'+ '
'+ @@ -1082,10 +1187,12 @@ $(document).ready(async function() { ''; newRow += '' + - '' + - '' + - '' + - '' + + '' + + '' + + '' + + '' + + '' + + '' + '' + '' + ''; @@ -1137,7 +1244,7 @@ $(document).ready(async function() { /** * REMOVE ITEMS FROM THE TABLE * **/ - delete_items_id = [{ 'service': [], 'complaint': [], 'custom_complaint': [] }]; + delete_items_id = [{ 'service': [], 'complaint': [], 'custom_complaint': [], 'product' : [] }]; $(document).on('click', '.remove-item', function() { var $closestTR = $(this).closest('tr'); @@ -1159,6 +1266,12 @@ $(document).ready(async function() { delete_items_id[0].custom_complaint.push(id); console.log(delete_items_id); } + else if($closestTR.attr('class') == "product") + { + id = $closestTR.find('input[name="id"]').val(); + delete_items_id[0].product.push(id); + console.log(delete_items_id); + } while ($closestTR.next().length > 0 && $closestTR.attr('class') != "product") { if ($closestTR.next().hasClass('service_class') || $closestTR.next().hasClass('complaint_class') || $closestTR.next().hasClass('custom_complaint_class')) {