From f2f818a62b31650f2f28b4a4ccf2ce2663cee33d Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Wed, 9 Apr 2025 08:21:55 +0000 Subject: [PATCH] service and jobcard --- app/Controllers/Jobcard.php | 67 +++++++--- app/Controllers/Service.php | 43 +++--- app/Models/JobcardModel.php | 2 +- app/Models/ServiceModel.php | 28 ---- app/Models/ServicesModel.php | 18 ++- app/Views/job_card_form.php | 96 ++++++++++---- app/Views/service_form.php | 251 +++++++++++++++++++---------------- app/Views/service_list.php | 8 +- 8 files changed, 302 insertions(+), 211 deletions(-) delete mode 100755 app/Models/ServiceModel.php diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php index 8d6d34a..5a267c5 100755 --- a/app/Controllers/Jobcard.php +++ b/app/Controllers/Jobcard.php @@ -11,7 +11,7 @@ use App\Models\JobcardServiceModel; use App\Models\JobcardProductModel; use App\Models\JobcardSubServiceModel; use App\Models\ProductModel; -use App\Models\ServiceModel; +use App\Models\ServicesModel; use App\Models\ClientModel; use App\Models\ComplaintModel; use App\Models\OutsourceModel; @@ -71,7 +71,7 @@ class Jobcard extends BaseController $this->JobcardProductModel = new JobcardProductModel(); $this->JobcardSubServiceModel = new JobcardSubServiceModel(); $this->ProductModel = new ProductModel(); - $this->ServiceModel = new ServiceModel(); + $this->ServiceModel = new ServicesModel(); $this->ClientModel = new ClientModel(); $this->ComplaintModel = new ComplaintModel(); $this->OutsourceModel = new OutsourceModel(); @@ -492,7 +492,9 @@ class Jobcard extends BaseController - + $type = $this->JobcardModel->select('job_card.type') + ->where('job_card.job_card_id', $job_card_id) + ->get()->getRow()->type; /*** SERVICE DATA ***/ $servicedata = $this->JobcardModel->service_data($job_card_id, $this->session->get('logged_user_branch_id')); // Using '&' to reference the original array element @@ -616,14 +618,32 @@ class Jobcard extends BaseController $encodedMakeId1 = 0; $encodedModelId1 = 0; - - $services2 = $this->ServiceModel->where('cubic_capacity_id', $ccId) - ->findAll(); - // $service = array_merge($common_services, $service1); + $selectServiceString = ($type == "With General") ? "services.wg_price,services.wg_labour_cost as labour_cost" : "services.wog_price,services.wog_labour_cost as labour_cost"; + + // Query the database to find the service - cubic_capacity_id .. category 1 na standlone and ccId must + $service1 = $this->ServiceModel->select('services.service_id,services.branch_id,services.cubic_capacity_id,services.service_name,services.category,services.tax,services.cgst,services.sgst,services.description, services.product_id,services.sub_service_id,services.created_at,services.created_by,services.updated_at,services.updated_by,services.isactive,cubic_capacity.value') + ->select($selectServiceString) + ->join('cubic_capacity', 'cubic_capacity.id = services.cubic_capacity_id','left') + ->where('cubic_capacity_id', $ccId) + ->where('category',1) + ->where('services.isactive' ,1) + ->findAll(); + + + // Query the database to find the service - default values .. category 0 na common and ccId no need + $service2 = $this->ServiceModel->select('services.service_id,services.branch_id,services.cubic_capacity_id,services.service_name,services.category,services.tax,services.cgst,services.sgst,services.description, services.product_id,services.sub_service_id,services.created_at,services.created_by,services.updated_at,services.updated_by,services.isactive,cubic_capacity.value') + ->select($selectServiceString) + ->join('cubic_capacity', 'cubic_capacity.id = services.cubic_capacity_id','left') + ->where('category',0) + ->where('services.isactive' ,1) + ->findAll(); + + // final service + $service = array_merge($service1, $service2); $data['product']=$product; - $data['service']=$services2; + $data['service_1']=$service; // echo "
";
             // print_r($service);die;
             $jobs_product= $this->JobcardCustomComplaintModel->where('job_card_id', $job_card_id)->findAll();
@@ -640,7 +660,7 @@ class Jobcard extends BaseController
            
                 
           
-            
+
         }
 
         
@@ -680,6 +700,7 @@ class Jobcard extends BaseController
         $job_card_data = [
             'client_name' => $this->request->getPost('client_id'),
             'client_mobile_no' => $this->request->getPost('mobile_no'),
+            'type' => $this->request->getPost('type'),
             'vehicle_id'=>$this->request->getPost('vehicle_id'),
             'branch_id'=> $this->session->get('logged_user_branch_id'),
             'billing_address' => $this->request->getPost('billing_address'),
@@ -1232,7 +1253,10 @@ class Jobcard extends BaseController
         $ccId = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->cubic_capacity_id;
         $modelName = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->model_name;
 
-        $complaint = $this->ComplaintModel->where('cubic_capacity_id',$ccId)->where('isactive',1)->findAll();
+        // $complaint = $this->ComplaintModel->where('cubic_capacity_id',$ccId)
+        $complaint = $this->ComplaintModel->select('complaints.*,cubic_capacity.value')            
+                                    ->join('cubic_capacity', 'cubic_capacity.id = complaints.cubic_capacity_id','left')
+                                    ->where('complaints.isactive',1)->findAll();
 
         if($complaint){
             // Send JSON response
@@ -1248,19 +1272,28 @@ class Jobcard extends BaseController
         // Retrieve make_id and model_id from the request
         $makeId = $this->request->getPost('make_id');
         $modelId = $this->request->getPost('model_id');
+        $type = $this->request->getPost('type');
+        $selectServiceString = ($type == "With General") ? "services.wg_price,services.wg_labour_cost as labour_cost" : "services.wog_price,services.wog_labour_cost as labour_cost"; 
 
         $ccId = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->cubic_capacity_id;
 
-        // Query the database to find the service - cubic_capacity_id
-        $service1 = $this->ServiceModel->where('cubic_capacity_id', $ccId)
+        // Query the database to find the service - cubic_capacity_id .. category 1 na standlone and ccId must
+        $service1 = $this->ServiceModel->select('services.service_id,services.branch_id,services.cubic_capacity_id,services.service_name,services.category,services.tax,services.cgst,services.sgst,services.description, services.product_id,services.sub_service_id,services.created_at,services.created_by,services.updated_at,services.updated_by,services.isactive,cubic_capacity.value')            
+                        ->select($selectServiceString)
+                        ->join('cubic_capacity', 'cubic_capacity.id = services.cubic_capacity_id','left')
+                        ->where('cubic_capacity_id', $ccId)
                         ->where('category',1)
-                        ->where('isactive' ,1)
+                        ->where('services.isactive' ,1)
                         ->findAll();
 
-       // Query the database to find the service - default values
-        $service2 = $this->ServiceModel->where('category',0)
-                                 ->where('isactive' ,1)
-                                 ->findAll();
+
+       // Query the database to find the service - default values .. category 0 na common and ccId no need
+       $service2 = $this->ServiceModel->select('services.service_id,services.branch_id,services.cubic_capacity_id,services.service_name,services.category,services.tax,services.cgst,services.sgst,services.description, services.product_id,services.sub_service_id,services.created_at,services.created_by,services.updated_at,services.updated_by,services.isactive,cubic_capacity.value')            
+                        ->select($selectServiceString)
+                        ->join('cubic_capacity', 'cubic_capacity.id = services.cubic_capacity_id','left')
+                        ->where('category',0)
+                        ->where('services.isactive' ,1)
+                        ->findAll();
 
         // final service
         $service = array_merge($service1, $service2);
diff --git a/app/Controllers/Service.php b/app/Controllers/Service.php
index cb34a95..9f859fb 100755
--- a/app/Controllers/Service.php
+++ b/app/Controllers/Service.php
@@ -2,7 +2,7 @@
 
 namespace App\Controllers;
 
-use App\Models\ServiceModel;
+use App\Models\ServicesModel;
 use App\Models\BikemakeModel;
 use App\Models\VendorModel; 
 use App\Models\BikemodelsModel; 
@@ -16,7 +16,7 @@ class Service extends BaseController
 
     public $session;
     protected $additionalProductNameModal;
-    protected $ServiceModel;
+    protected $ServicesModel;
     protected $BikemakeModel;
     protected $vendorModel;
     protected $BikemodelsModel;
@@ -29,7 +29,7 @@ class Service extends BaseController
 
 		$this->session = session();
         $this->additionalProductNameModal =   new AdditionalProductNameModal();
-        $this->ServiceModel = new ServiceModel();
+        $this->ServicesModel = new ServicesModel();
         $this->BikemakeModel = new BikemakeModel();
         $this->vendorModel = new VendorModel();
         $this->BikemodelsModel = new BikemodelsModel();
@@ -40,7 +40,7 @@ class Service extends BaseController
     public function service_index()
     {
 
-        $services = $this->ServiceModel->select('services.*,cubic_capacity.value')            
+        $services = $this->ServicesModel->select('services.*,cubic_capacity.value')            
                                     ->join('cubic_capacity', 'cubic_capacity.id = services.cubic_capacity_id','left')
                                     ->where('services.branch_id',$this->session->get('logged_user_branch_id'))
                                     ->orderBy('services.service_name','ASC')->findAll();
@@ -91,14 +91,13 @@ class Service extends BaseController
            
     public function new_service($service_id)
     {
-       
         $data['product'] = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')            
                                     ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
                                     ->where('JSON_CONTAINS(products.models_id, \'["0"]\')', null, false)
                                     ->where('products.isactive', 1)
                                     ->findAll();
 
-        $data['tax'] = $this->ServiceModel->getTax();      
+        $data['tax'] = $this->ServicesModel->getTax();      
         $data['cubiccapacity']= $this->ComplaintModel->getCubicCapacityName();
 
         if ($service_id === '0') {
@@ -107,12 +106,12 @@ class Service extends BaseController
             $data['services'] = [];  
             $data['make'] = $this->BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->findAll();
             $data['models'] = [];
-            $data['service'] = $this->ServiceModel->where('isactive',1)->where('category','0')->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+            $data['service'] = $this->ServicesModel->where('isactive',1)->where('category','0')->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
     
         } else if ($service_id !== '0') {
 
             $data['page_name'] = "Edit Service";
-            $services = $this->ServiceModel->where('service_id', $service_id)->get()->getRowArray();
+            $services = $this->ServicesModel->where('service_id', $service_id)->get()->getRowArray();
             // $services['models_id'] = json_decode($services['models_id'], true);
             // $services['makes_id'] = json_decode($services['makes_id'], true);
 
@@ -126,8 +125,8 @@ class Service extends BaseController
             // $data['models'] = $models; 
             // $data['make'] = $this->BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->findAll();
             $data['services'] = $services;  
-            $data['service'] = $this->ServiceModel->where('isactive',1)->where('category','0')->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
-                
+            $data['service'] = $this->ServicesModel->where('isactive',1)->where('category','0')->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+            // dd($data['service']);
         }
         $data['service_id'] = $service_id;
        
@@ -139,9 +138,9 @@ class Service extends BaseController
     public function add_service()
     {    
         $tax= $this->request->getPost('tax')/2;
-        $final_price = ($this->request->getPost('productCost') ? $this->request->getPost('productCost') : 0) + 
-                       ($this->request->getPost('serviceCost') ? $this->request->getPost('serviceCost') : 0) + 
-                       ($this->request->getPost('labour_cost_With_Tax') ? $this->request->getPost('labour_cost_With_Tax') : 0);
+        // $final_price = ($this->request->getPost('productCost') ? $this->request->getPost('productCost') : 0) + 
+        //                ($this->request->getPost('serviceCost') ? $this->request->getPost('serviceCost') : 0) + 
+        //                ($this->request->getPost('labour_cost_With_Tax') ? $this->request->getPost('labour_cost_With_Tax') : 0);
 
         // print $final_price;
         // print_r($this->request->getPost());
@@ -159,9 +158,11 @@ class Service extends BaseController
             'cgst' => $tax,
             'sgst' =>  $tax,
             'tax' =>  $this->request->getPost('tax'),
-            'labour_cost' => $this->request->getPost('labour_cost'),
-            'labour_cost_with_cost' => $this->request->getPost('labour_cost_with_cost'),
-            'price' => $final_price,
+            'wg_labour_cost' => $this->request->getPost('wg_labour_cost'),
+            'wog_labour_cost' => $this->request->getPost('wog_labour_cost'),
+            'wg_price' => $this->request->getPost('wg_price_withtax'),
+            'wog_price' => $this->request->getPost('wog_price_withtax'),
+            // 'price' => $final_price,
             // 'makes_id' => $make_json,
             // 'models_id' => $model_json, 
             'description' => $this->request->getPost('description'),
@@ -172,10 +173,10 @@ class Service extends BaseController
        
         if (!empty($service_id)) 
         {
-            $this->ServiceModel->update($service_id, $data);
+            $this->ServicesModel->update($service_id, $data);
         } else {
             $data['branch_id'] = $this->session->get('logged_user_branch_id');
-            $this->ServiceModel->insert($data);
+            $this->ServicesModel->insert($data);
         }
     
         
@@ -186,12 +187,12 @@ class Service extends BaseController
     {
    
         $where = ['service_id' => $service_id, 'isactive' => 1]; // Assuming 'isactive' is a column in your database
-        $existingService = $this->ServiceModel->where($where)->first();
+        $existingService = $this->ServicesModel->where($where)->first();
     
         if ($existingService) {
             $data['isactive'] = 0;
             
-            if ($this->ServiceModel->update($service_id, $data)) {
+            if ($this->ServicesModel->update($service_id, $data)) {
                 session()->setFlashdata('success', 'Deleted successfully.');
                 $this->logger->info("Users: has been Inactivated successfully. Inactivated ID = ".$service_id); 
             }
@@ -309,7 +310,7 @@ class Service extends BaseController
             $data = [
                 'isactive' => $isactive
             ];
-            $updated = $this->ServiceModel->update($service_id, $data);
+            $updated = $this->ServicesModel->update($service_id, $data);
 
             if ($updated) {
                 $result = $data;
diff --git a/app/Models/JobcardModel.php b/app/Models/JobcardModel.php
index 607b366..d40d6e4 100755
--- a/app/Models/JobcardModel.php
+++ b/app/Models/JobcardModel.php
@@ -9,7 +9,7 @@ class JobcardModel extends Model
     'order_number','client_mobile_no','client_name',
     'billing_address','billing_city','billing_state','billing_country',
     'billing_postal_code','fuel_qty', 'meter', 'delivery_date', 'note',
-    'status','assigned_to', 'is_rework','subtotal','tax', 'discount','total','isactive','mode_of_payment','trial_mechanic'];
+    'status','assigned_to', 'is_rework','subtotal','tax', 'discount','total','isactive','mode_of_payment','trial_mechanic','type'];
 
 
 
diff --git a/app/Models/ServiceModel.php b/app/Models/ServiceModel.php
deleted file mode 100755
index fcdc13a..0000000
--- a/app/Models/ServiceModel.php
+++ /dev/null
@@ -1,28 +0,0 @@
-table('tax')->get();
-        
-        // Check if query returned results
-        if ($query->resultID->num_rows > 0) {
-            return $query->getResultArray();
-        } else {
-            return []; // Return an empty array if no tax data found
-        }
-    }
-
-}
-?>
\ No newline at end of file
diff --git a/app/Models/ServicesModel.php b/app/Models/ServicesModel.php
index 0c8febd..8e999aa 100755
--- a/app/Models/ServicesModel.php
+++ b/app/Models/ServicesModel.php
@@ -5,7 +5,23 @@ class ServicesModel extends Model
 {
     protected $table = 'services';
     protected $primaryKey = 'service_id';
-    protected $allowedFields = ['service_id','service_name','price','commission_rate','cgst','sgst','purchase_cost','description','isactive','cubic_capacity_id'];
+    protected $allowedFields = ['service_id','branch_id','category','service_name','wg_labour_cost','cgst','sgst','wg_price','wog_price','tax','wog_labour_cost','description','makes_id','models_id','product_id','sub_service_id','isactive','cubic_capacity_id'];
+
+    public function getTax()
+    {
+        // Get a database instance
+        $db = \Config\Database::connect();
+        
+        // Query the tax table
+        $query = $db->table('tax')->get();
+        
+        // Check if query returned results
+        if ($query->resultID->num_rows > 0) {
+            return $query->getResultArray();
+        } else {
+            return []; // Return an empty array if no tax data found
+        }
+    }
 
     
 }
\ No newline at end of file
diff --git a/app/Views/job_card_form.php b/app/Views/job_card_form.php
index 3340ec0..a9fba7f 100755
--- a/app/Views/job_card_form.php
+++ b/app/Views/job_card_form.php
@@ -85,6 +85,19 @@
                     
                     
 
+                    
+
+ + +
+
+
+
+
@@ -110,7 +123,7 @@
- +
@@ -196,7 +209,7 @@
- Select a Mechanic' ?> @@ -815,6 +828,31 @@ $(document).ready(function() { productarray = []; servicearray = []; $(document).ready(function() { + + + var jc_id = ""; + console.log("Job Card ID:", jc_id); + + if(jc_id == 0) { + $('.type-select').prop('disabled', false); + } else { + $('.type-select').prop('disabled', true); + } + + $('.type-select').change(function() { + $('#productItemTable tbody').empty(); + $('.vehicle-select').val('').select2(); + $('#makeAndModel').val(''); + $('input[name="client_id"]').val(''); + $('input[name="mobile_no"]').val(''); + $('input[name="billing_address"]').val(''); + $('input[name="city"]').val(''); + $('input[name="state"]').val(''); + $('input[name="country"]').val(''); + $('input[name="mobile_no"]').val(''); + $('input[name="postalcode"]').val(''); + }); + // Event listener for vehicle selection change $('.vehicle-select').change(function() { $('#productItemTable tbody').empty(); @@ -837,6 +875,11 @@ $(document).ready(function() { // Extract makeId from the selected vehicle var makeId = selectedVehicle.make; var modelId = selectedVehicle.model; + var type = $('#type').val(); + if(type == ""){ + alert("Please Select the Type"); + return true; + } // console.log(modelId); // Make sure makeId exists @@ -870,7 +913,8 @@ $(document).ready(function() { data: { make_id: makeId, model_id:modelId, - vehicle_id: vehicleId + vehicle_id: vehicleId, + type : type }, success: function(response) { console.log(response); @@ -910,7 +954,7 @@ $(document).ready(function() { @@ -1105,7 +1149,8 @@ $(document).ready(function() { }); var products = ; - var services = ; + // var services = ; + var mapTable; function data_contruction_for_save() { @@ -1309,7 +1354,7 @@ $(document).ready(function() { if(className.includes("service")) { // Find product details from JSON - var service_data = services.find(function(item) { + var service_data = servicearray.find(function(item) { return item.service_id == productId; }); // Access unit price from product and set it as rate @@ -1413,18 +1458,26 @@ $(document).ready(function() { return item.product_id == productId; }); console.log(product); - 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; + // 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)); } @@ -2467,11 +2520,4 @@ $(document).ready(function() { button.innerHTML = '

'; } } - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/Views/service_form.php b/app/Views/service_form.php index 05a1d40..c1187a6 100755 --- a/app/Views/service_form.php +++ b/app/Views/service_form.php @@ -21,6 +21,10 @@
" method="post" id="serviceForm">

Service Details :

+
+ + +
-
- - -

Select Items :

@@ -80,38 +80,45 @@ $cgst = isset($services['cgst']) ? $services['cgst'] : 0; // CGST value (half of the tax amount) $sgst = isset($services['sgst']) ? $services['sgst'] : 0; // SGST value (half of the tax amount) $tax = $cgst + $sgst; // Total tax (sum of CGST and SGST) - if(isset($services['labour_cost'])){ - $labour_cost = ($services['labour_cost'] / 100) * $tax; - $labour_cost = round($labour_cost + $services['labour_cost']); - }else{ - $labour_cost = ''; - } ?> -
- - -
-
- - - +
+
- - + +
+
+ + +
+ +
+ +
+ + +
+ +
+ + +
+ +
+
- +
@@ -301,10 +308,18 @@ $(document).ready(function() { data = ; servicedata = ; - var service_id = ""; if (service_id != 0) { - $("#productSelect").trigger('change'); - $('#serviceSelected').trigger('change'); + + var category = ; + if (category == 1) { + $('#cc_hide').css('display', 'block'); + $('#service_hide').css('display' ,'block'); + $('#cubiccapacity').attr('required', false).attr('readonly', true); + } else { + $('#cc_hide').css('display', 'none'); + $('#service_hide').css('display' ,'none'); + $('#cubiccapacity').attr('required', true).attr('readonly', false); + } } }); @@ -374,92 +389,90 @@ document.getElementById('category').addEventListener('change', function() { + // function getPriceForProductId(productId) { + // for (var i = 0; i < data.length; i++) { + // if (data[i].product_id === productId) { + // // Return the purchase_cost if the product_id matches + // return data[i].unit_price; + // } + // } + // } -