diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php index 90b2f7b..de2156e 100644 --- a/app/Controllers/Jobcard.php +++ b/app/Controllers/Jobcard.php @@ -9,6 +9,7 @@ use App\Models\JobcardCustomComplaintModel; use App\Models\JobcardOSModel; use App\Models\JobcardServiceModel; use App\Models\JobcardProductModel; +use App\Models\JobcardSubServiceModel; use App\Models\ProductModel; use App\Models\ServiceModel; use App\Models\ClientModel; @@ -427,23 +428,36 @@ class Jobcard extends BaseController $productModel = new ProductModel(); $JobcardModel = new JobcardModel(); $JobcardProductModel = new JobcardProductModel(); + $JobcardSubServiceModel = new JobcardSubServiceModel(); $JobcardServiceModel = new JobcardServiceModel(); $JobcardComplaintModel = new JobcardComplaintModel(); $JobcardCustomComplaintModel = new JobcardCustomComplaintModel(); $JobcardOSModel = new JobcardOSModel(); $ComplaintModel = new ComplaintModel(); $OutsourceModel = new OutsourceModel(); + $ServiceModel = new ServiceModel(); /*** SERVICE DATA ***/ $servicedata = $JobcardModel->service_data($job_card_id, $this->session->get('logged_user_branch_id')); // Using '&' to reference the original array element + foreach ($servicedata as &$value) { + // sub product datas $product_ids = !empty(json_decode($value['product_id'], true)) ? json_decode($value['product_id'], true) : [0]; $product = $JobcardProductModel->select('job_card_product.* , products.product_name as pname, products.qty_stock') ->join('products', 'products.product_id = job_card_product.product_id') ->whereIn('job_card_product.job_card_product_id', $product_ids)->findAll(); $value['product'] = $product; + + // sub service data + $service_ids = !empty(json_decode($value['sub_service_id'], true)) ? json_decode($value['sub_service_id'], true) : [0]; + $service = $JobcardSubServiceModel->select('job_card_sub_service.* , services.service_name as s_name') + ->join('services', 'services.service_id = job_card_sub_service.sub_service_id') + ->whereIn('job_card_sub_service.job_card_sub_service_id', $service_ids)->findAll(); + $value['sub_service'] = $service; } + // echo "
";
+            // print_r($value);die;
             $data['editservicedata'] = $servicedata;
             /*** COMPLAINT DATA ***/
             $complaintdata = $JobcardModel->complaint_data($job_card_id, $this->session->get('logged_user_branch_id'));
@@ -519,7 +533,7 @@ class Jobcard extends BaseController
                             ->where('qty_stock >',0)
                             ->findAll();
             $product = array_merge($product1, $product2);
-            $data['product']=$product;
+            // $data['product']=$product;
             $data['product']=$product;
 
             // echo json_encode($product);die;
@@ -572,6 +586,8 @@ class Jobcard extends BaseController
         // echo $this->request->getPost('delete_items');die;
         // echo $this->request->getPost('issued_items');die;
         // echo json_encode($this->request->getPost());die;
+        // echo "
";
+        // print_r($this->request->getPost());die;
         $JobcardModel = new JobcardModel();
         if($this->session->get('logged_user_role') == "Store Manager") {
             $data['status'] = $this->request->getPost('status');
@@ -582,6 +598,7 @@ class Jobcard extends BaseController
             return redirect()->to('job_card_index');
         }
         $JobcardProductModel = new JobcardProductModel();
+        $JobcardSubServiceModel = new JobcardSubServiceModel();
         $JobcardServiceModel = new JobcardServiceModel();
         $JobcardComplaintModel = new JobcardComplaintModel();
         $JobcardCustomComplaintModel = new JobcardCustomComplaintModel();
@@ -642,6 +659,9 @@ class Jobcard extends BaseController
         $data = json_decode($_POST['products']);
         $service_data = $data[0]->service;
 
+                // echo "
";
+        // print_r($service_data);die;
+
         foreach ($service_data as $item) {
             // Insert into the service table
             $service['job_card_id'] = $job_card_id;
@@ -664,10 +684,12 @@ class Jobcard extends BaseController
                 $JobcardServiceModel->update($item->id, $service);
                 $service_id = $item->id;
             }
-            
+            // do same as sub_service product_data_insertion
             if(isset($item->product)) { $this->product_data_insertion($job_card_id, $service_id, $JobcardServiceModel, $item, $JobcardProductModel, $status, $rework); }
+            if(isset($item->sub_service)) { $this->sub_service_data_insertion($job_card_id, $service_id, $JobcardServiceModel, $item, $JobcardSubServiceModel, $status, $rework); }
         }
 
+
         /********** INSERT COMPLAINT DATA ************/
         $complaint_data = $data[0]->complaint;
 
@@ -782,9 +804,14 @@ class Jobcard extends BaseController
     {
         // Insert into the product table
         $id = [];
+        // echo "
";
+        // print_r($item);die;
         foreach ($item->product as $pt) {
             $product['job_card_id'] =  $job_card_id;
             $product['product_id'] = $pt->p_id;
+            if(isset($pt->name)){
+                $product['name'] = $pt->name;
+            }
             $product['qty'] = $pt->qty;
             $product['tax'] = $pt->tax;
             $product['amount'] = $pt->amount / $pt->qty; //(isset($rework) ? 0 : $pt->amount / $pt->qty );
@@ -814,9 +841,63 @@ class Jobcard extends BaseController
         }
     }
 
+
+    public function sub_service_data_insertion($job_card_id, $parent_id, $ParentModel, $item, $JobcardSubServiceModel, $status, $rework)
+    {
+        // Insert into the product table
+        $id = [];
+        foreach ($item->sub_service as $pt) {
+            
+            $product['job_card_id'] =  $job_card_id;
+            $product['sub_service_id'] = $pt->s_id;
+            if(isset($pt->name)){
+                $product['name'] = $pt->name;
+            }
+            $product['qty'] = $pt->qty;
+            $product['tax'] = $pt->tax;
+            $product['amount'] = $pt->amount / $pt->qty; //(isset($rework) ? 0 : $pt->amount / $pt->qty );
+            if(empty($pt->id)) {
+                $JobcardSubServiceModel->insert($product);
+                $job_card_sub_service_id = $JobcardSubServiceModel->getInsertID();
+            }
+            else {
+                if($status == 'Cancelled')
+                {
+                    $product = [];
+                    $product['job_card_id'] =  $job_card_id;
+                    $product['sub_service_id'] = $pt->s_id;
+                    $product['is_active'] = 0;
+                }
+                $old_data = $JobcardSubServiceModel->find($pt->id);
+                if($pt->qty != $old_data['issued_qty'] && $pt->qty > $old_data['issued_qty']) { $product['status'] = 0; }
+                // echo $pt->id;die;
+                $JobcardSubServiceModel->update($pt->id, $product);
+                $job_card_sub_service_id = $pt->id;
+            }
+            array_push($id, $job_card_sub_service_id);
+        }
+
+        // $job_card_service_id = $parent_id;
+        // $res =$ParentModel->update($parent_id, ['sub_service_id' => json_encode($id) ]);
+        $parent_data_get = $ParentModel->where('job_card_id', $job_card_id)->first();
+
+        $job_card_service_id = $parent_data_get['job_card_service_id'];
+        $res= $ParentModel->update($job_card_service_id, ['sub_service_id' => json_encode($id)]);
+        if($res) {
+                    // print_r($parent_id);
+        // print_r($id);
+        // die;
+            // $this->product_data_maintanence($id, $status);
+        }
+    }
+
+    
+
+
     public function delete_items($delArr)
     {
         $JobcardProductModel = new JobcardProductModel();
+        $JobcardSubServiceModel = new JobcardSubServiceModel();
         $JobcardServiceModel = new JobcardServiceModel();
         $JobcardComplaintModel = new JobcardComplaintModel();
         $JobcardCustomComplaintModel = new JobcardCustomComplaintModel();
@@ -833,6 +914,16 @@ class Jobcard extends BaseController
             }
         }
 
+        $sub_service_data = $data[0]->sub_service;
+        if(!empty($sub_service_data)) {
+            foreach ($sub_service_data as $item) {
+                $conditions = [ 'job_card_sub_service_id' => $item ];
+                // $product_deleted_data = $JobcardProductModel->where($conditions)->findAll();
+                // $this->product_delete($service_deleted_data[0]['product_id']);
+                $JobcardSubServiceModel->where($conditions)->delete();
+            }
+        }
+
         $service_data = $data[0]->service;
         if(!empty($service_data)) {
             foreach ($service_data as $item) {
diff --git a/app/Controllers/Outsourcing.php b/app/Controllers/Outsourcing.php
index 3c33f72..fe5b66b 100644
--- a/app/Controllers/Outsourcing.php
+++ b/app/Controllers/Outsourcing.php
@@ -34,6 +34,7 @@ class Outsourcing extends BaseController
                 "labour_cost" => $this->request->getPost('labour_cost'),
                 "cost_with_tax" => $this->request->getPost('cost_with_tax'),
                 "tax" => $this->request->getPost('tax'),
+                "description" => $this->request->getPost('description'),
             ];
 
             if ($this->request->getPost('id') == '') {
diff --git a/app/Models/JobcardProductModel.php b/app/Models/JobcardProductModel.php
index 4a79c3c..5373dba 100644
--- a/app/Models/JobcardProductModel.php
+++ b/app/Models/JobcardProductModel.php
@@ -5,5 +5,5 @@ class JobcardProductModel extends Model
 {
     protected $table = 'job_card_product';
     protected $primaryKey = 'job_card_product_id';
-    protected $allowedFields = ['job_card_product_id','job_card_id' , 'product_id', 'qty', 'tax', 'amount', 'status', 'issued_qty', 'is_active'];
+    protected $allowedFields = ['job_card_product_id','job_card_id' ,'name', 'product_id', 'qty', 'tax', 'amount', 'status', 'issued_qty', 'is_active'];
 }
\ No newline at end of file
diff --git a/app/Models/JobcardServiceModel.php b/app/Models/JobcardServiceModel.php
index 03740f1..52fe7fc 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', 'labour_cost', 'product_id', 'qty','tax','amount', 'isactive'];
+    protected $allowedFields = ['job_card_service_id', 'job_card_id', 'service_id', 'labour_cost', 'product_id','sub_service_id', 'qty','tax','amount', 'isactive'];
 
     
 }
\ No newline at end of file
diff --git a/app/Models/JobcardSubServiceModel.php b/app/Models/JobcardSubServiceModel.php
new file mode 100644
index 0000000..0325d6e
--- /dev/null
+++ b/app/Models/JobcardSubServiceModel.php
@@ -0,0 +1,9 @@
+
                 " class="btn btn-secondary waves-effect">Cancel
                     
@@ -26,7 +25,7 @@
     
-
" method="post"> + " method="post" style="line-height:0.5;"> @@ -177,16 +176,16 @@ @@ -385,6 +384,7 @@ $(document).ready(async function() { tr = $('#productItemTable tbody').append(newRow); // initializeSelect2(); /** APPEND CHILD PRODUCT */ + await edit_sub_service_data(value.sub_service); await edit_product_data(value.product); editlabourcost(value,'service_lb'); } @@ -570,7 +570,7 @@ $(document).ready(async function() { action = '
'; } var newRow = ` - + '+ ''; - newRow += ''; + newRow += ''; - newRow += ''; + newRow += ''; + newRow += '' ; + + $('#productItemTable tbody').append(newRow); + // $(newRow).insertAfter(tr); + // initializeSelect2(); + } + + } + + function edit_sub_service_data(sub_services) { + + for (const sub_service of sub_services) { + sub_service.amount = 0; + total_wih_tax =( Number(sub_service.amount) + (Number(sub_service.amount) * (sub_service.tax / 100)) )* sub_service.qty; + total_tax_amt = Number(sub_service.amount) * (sub_service.tax / 100); + + var action; + if(logged_user == 'Store Manager') + { + action = `
`; + } + else + { + action = '
'; + } + var newRow = ` + + ' + + '' + + '' + + ''; + + newRow += ''; + + newRow += ' ' + + '' + + '' + + ''+ + action+ + ''+ + ''; + + newRow += ''; + + newRow += ''; + + newRow += '' ; $('#productItemTable tbody').append(newRow); // $(newRow).insertAfter(tr); @@ -783,7 +833,8 @@ $(window).on('load', function() { 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.toFixed(2)); + // labour_rate.val(actual_amount.toFixed(2)); + labour_rate.val(parseInt(actual_amount, 10)); item_rate = previousRow.find('.item-rate1'); item_rate.val(actual_amount.toFixed(2)); @@ -934,6 +985,10 @@ $(window).on('load', function() { var fifthTd = row.querySelector("td:nth-child(6)"); var sixthTd = row.querySelector("td:nth-child(4)"); var eigthTd = row.querySelector("td:nth-child(10)"); + if (row.querySelector("td:nth-child(11)")) { + var ninthTd = row.querySelector("td:nth-child(11)"); + } + // Check if the second element contains a element @@ -954,16 +1012,20 @@ $(window).on('load', function() { var amount = selectsixthElement.value; var id = selecteightElement.value; var labour_cost = selectFirstElement.value; + var name =''; + if(selectninthElement){ + var name = selectninthElement.value; + } // Output the class name and selected value // console.log("Class Name: " + className + ", Selected Value: " + selectedValue); if (className.includes("product")) { if(mapTable == "service") { - addProductToLastObjectByKey(dataMapArray, "service", [{ 'id': id, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]); + addProductToLastObjectByKey(dataMapArray, "service", [{ 'id': id, 'name' : name, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]); } else if(mapTable == "complaint") { - addProductToLastObjectByKey(dataMapArray, "complaint", [{ 'id': id, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]); + addProductToLastObjectByKey(dataMapArray, "complaint", [{ 'id': id, 'name' :name, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]); } else if(mapTable == "custom-comp") { addProductToLastObjectByKey(dataMapArray, "custom_complaint", [{ 'id': id, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]); @@ -972,6 +1034,14 @@ $(window).on('load', function() { addProductToLastObjectByKey(dataMapArray, "os", [{ 'id': id, 'p_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }]); } } + + else if (className.includes("sub_service") ) + { + if(mapTable == "service"){ + addSubServiceToLastObjectByKey(dataMapArray, "service", [{ 'id': id, 'name' : name, 's_id' : selectedValue , 'qty' : quality, 'tax': tax, 'amount': amount }],true); + } + + } else if(className.includes("service")) { mapTable = "service"; @@ -1012,10 +1082,25 @@ $(window).on('load', function() { } } } - console.log(array,'dataMapArray11'); } + function addSubServiceToLastObjectByKey(array, key, sub_service) { + for (const obj of array) { + if (obj[key]) { + const lastObjectIndex = obj[key].length - 1; + const lastObject = obj[key][lastObjectIndex]; + + if (!lastObject.sub_service) { + lastObject.sub_service = sub_service; + } + else { + lastObject.sub_service.push(sub_service[0]); + } + } + } + } + $(document).ready(function() { $('#submit-btn').click(function(event) { var isValid = $('#form-submit')[0].checkValidity(); @@ -1090,7 +1175,8 @@ $(window).on('load', function() { $(this).closest('tr').find('.item-tax').val(Number(service_data.tax)); $(this).closest('tr').find('.labour_cost').val(unitPrice); await labourcost(service_data.labour_cost,service_data.tax,$(this).closest('tr'),'service_lb'); - service_child_products(service_data,$(this).closest('tr')) + service_child_products(service_data,$(this).closest('tr')); + service_child_services(service_data,$(this).closest('tr')); } calculateAmount($(this).closest('tr'),className,'parent'); @@ -1270,20 +1356,22 @@ $(window).on('load', function() { } const service_child_products = async (data,tr) => { - console.log(JSON.parse(data.product_id)); + // console.log("products"); + // console.log(products); + // console.log(JSON.parse(data.product_id)); JSON.parse(data.product_id).forEach(async(element,index) => { + if(element == 0) return; var product = products.find(function(item) { return item.product_id == element && item.qty_stock > 0; }); - var cgst = parseFloat(product.cgst); var sgst = parseFloat(product.sgst); // Calculate total tax by adding CGST and SGST var tax = cgst + sgst; total_wih_tax = ( Number(product.unit_price) ) + ( Number(product.unit_price) * (tax / 100) ); total_tax_amt = Number(product.unit_price) * (tax / 100); - var newRow = '' + '' + @@ -1294,6 +1382,7 @@ $(window).on('load', function() { '' + '
' + '' + + '' + ''; @@ -1304,6 +1393,47 @@ $(window).on('load', function() { }); } + + const service_child_services = async (data,tr) => { + + JSON.parse(data.sub_service_id).forEach(async(element,index) => { + + if(element == 0) return; + var service = services.find(function(item) { + return item.service_id == element ; + }); + + + var cgst = parseFloat(service.cgst); + var sgst = parseFloat(service.sgst); + // Calculate total tax by adding CGST and SGST + var tax = cgst + sgst; + total_wih_tax = ( Number(service.labour_cost) ) + ( Number(service.labour_cost) * (tax / 100) ); + total_tax_amt = Number(service.labour_cost) * (tax / 100); + var newRow = '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
' + + '' + + '' + + ''; + + + // $('#productItemTable tbody').append(newRow); + $(newRow).insertAfter(tr); + // initializeSelect2(); + + }); + } + + + // Event listener for quantity change $(document).on('input', '.item-quantity', async function() { calculateAmount($(this).closest('tr'), $(this).closest('tr').attr('class'),'child'); @@ -1428,7 +1558,7 @@ $(window).on('load', function() { selected_pr.push(rowProductid); }); - var newRow = '' + '
' + '' + + '' + ''; // $('#productItemTable tbody').append(newRow); @@ -1615,7 +1746,7 @@ $(window).on('load', function() { var $targetField = $previousRow.find('.item-rate1'); $targetField.val(enteredValue); var $targetField2 = $previousRow.find('.labour_cost'); - $targetField2.val(enteredValue); + $targetField2.val(int(enteredValue)); updateCalculations(); }); /** TAX FIELD */ @@ -1701,7 +1832,7 @@ $(window).on('load', function() { /** * REMOVE ITEMS FROM THE TABLE * **/ - delete_items_id = [{ 'service': [], 'complaint': [], 'custom_complaint': [], 'os': [], 'product' : [] }]; + delete_items_id = [{ 'service': [], 'complaint': [] , 'sub_service': [], 'custom_complaint': [], 'os': [], 'product' : [] }]; $(document).on('click', '.remove-item', function() { var $closestTR = $(this).closest('tr'); @@ -1717,6 +1848,12 @@ $(window).on('load', function() { delete_items_id[0].complaint.push(id); console.log(delete_items_id); } + else if($closestTR.attr('class') == "sub_service") + { + id = $closestTR.find('input[name="id"]').val(); + delete_items_id[0].sub_service.push(id); + console.log(delete_items_id); + } else if($closestTR.attr('class') == "custom_complaint_class") { id = $closestTR.find('input[name="id"]').val(); @@ -1736,14 +1873,16 @@ $(window).on('load', function() { 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') || $closestTR.next().hasClass('os_class')) { - break; + if ($closestTR.attr('class') !== "product" && $closestTR.attr('class') !== "sub_service") { + while ($closestTR.next().length > 0 ) { + if ($closestTR.next().hasClass('service_class') || $closestTR.next().hasClass('complaint_class') || $closestTR.next().hasClass('custom_complaint_class') || $closestTR.next().hasClass('os_class')) { + break; + } + // Remove the next row + $closestTR.next().remove(); } - // Remove the next row - $closestTR.next().remove(); + // Remove the clicked row } - // Remove the clicked row $closestTR.remove(); updateCalculations(); }); diff --git a/app/Views/outsourcing_list.php b/app/Views/outsourcing_list.php index 526c9a8..29bef15 100644 --- a/app/Views/outsourcing_list.php +++ b/app/Views/outsourcing_list.php @@ -23,6 +23,7 @@ Tax Labour Charge With Tax Labour Charge + Description Status Actions @@ -34,6 +35,7 @@ + Active @@ -91,6 +93,10 @@
+
+ + +
@@ -129,6 +135,7 @@ labour_cost: $('#labour_cost').val(), tax: $('#tax').val(), cost_with_tax: $('#cost_with_tax').val(), + description: $('#description').val(), }; $.ajax({ @@ -161,6 +168,7 @@ $('#name').val(response.os_data[0].name); $('#labour_cost').val(response.os_data[0].labour_cost); $('#cost_with_tax').val(response.os_data[0].cost_with_tax); + $('#description').val(response.os_data[0].description); var tax = parseFloat(response.os_data[0].tax); var selectElement = document.getElementById('tax'); diff --git a/app/Views/outsourcing_template.php b/app/Views/outsourcing_template.php index 912bf7c..8c2b32b 100644 --- a/app/Views/outsourcing_template.php +++ b/app/Views/outsourcing_template.php @@ -188,7 +188,6 @@ p { Bike Detail Out Source List - $item) : ?> @@ -212,11 +211,6 @@ p { - - $item) : ?> - ( x )
- - diff --git a/app/Views/product_form.php b/app/Views/product_form.php index 02e0605..70c1031 100644 --- a/app/Views/product_form.php +++ b/app/Views/product_form.php @@ -238,8 +238,8 @@

Description Details :


- -
diff --git a/app/Views/sales_order_form.php b/app/Views/sales_order_form.php index c21b3a0..d42d0bc 100644 --- a/app/Views/sales_order_form.php +++ b/app/Views/sales_order_form.php @@ -20,7 +20,7 @@
- " method="post"> + " method="post" style="line-height:0.5;">
diff --git a/app/Views/service_form.php b/app/Views/service_form.php index 8c96753..48500c9 100644 --- a/app/Views/service_form.php +++ b/app/Views/service_form.php @@ -64,7 +64,7 @@ - @@ -105,7 +105,16 @@
- + +
@@ -128,8 +137,8 @@

Description Details :

- - + +
@@ -344,7 +353,8 @@ document.getElementById('category').addEventListener('change', function() { } else if(this.value == '' ) { $('#productCost').val(0); - labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val()); + // labour_cost = ($('#labour_cost').val() == '') ? 0 : parseInt($('#labour_cost').val()); + labour_cost = ($('#LabourCostWithTax').val() == '') ? 0 : parseInt($('#LabourCostWithTax').val()); add = parseInt($('#productCost').val()) + parseInt($('#serviceCost').val()) + labour_cost; console.log("New value of #serviceCost:", add); @@ -426,7 +436,10 @@ document.getElementById('category').addEventListener('change', function() { var labour_cost = labour_cost_With_Tax / parseFloat((tax / 100) + 1); $("input[name='labour_cost']").val(labour_cost.toFixed(2)); - add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val()) + parseInt(labour_cost.toFixed(2)); + // add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val()) + parseInt(labour_cost.toFixed(2)); + add = parseInt($('#serviceCost').val()) + parseInt($('#productCost').val()) + parseInt(labour_cost_With_Tax); + // console.log("add"); + // console.log(add); $('#price').val(add); }