diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php index 006e2a4..531f8e0 100644 --- a/app/Controllers/Jobcard.php +++ b/app/Controllers/Jobcard.php @@ -3,18 +3,23 @@ namespace App\Controllers; use App\Models\JobcardModel; -use App\Models\JobcardProductModel; +use App\Models\JobcardCustomComplaintModel; use App\Models\JobcardServiceModel; use App\Models\ProductModel; use App\Models\ServiceModel; use App\Models\ClientModel; +use App\Models\ComplaintModel; use App\Models\BikemodelsModel; use App\Models\BikemakeModel; use App\Models\VehicleModel; +use App\Models\SalesOrderModel; +use App\Models\SalesOrderProductModel; use Mpdf\Mpdf; class Jobcard extends BaseController { public $session; + public $BikemodelsModel; + public $BikemakeModel; public function __construct() { @@ -51,7 +56,14 @@ class Jobcard extends BaseController $ProductModel = new ProductModel(); $product=$ProductModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); $ServiceModel = new ServiceModel(); + // echo $this->session->get('logged_user_branch_id');die; $service=$ServiceModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll(); + // echo json_encode($service);die; + + $ComplaintModel = new ComplaintModel(); + $complaint=$ComplaintModel->where('isactive',1)->findAll(); + + $data['complaint']= $complaint; $data['product_1']=$product; $data['product']=""; $data['service_1']=$service; @@ -104,8 +116,8 @@ class Jobcard extends BaseController ->findAll(); $data['product']=$product; $data['service']=$service; - $JobcardProductModel = new JobcardProductModel(); - $jobs_product= $JobcardProductModel->where('job_card_id', $job_card_id)->findAll(); + $JobcardCustomComplaintModel = new JobcardCustomComplaintModel(); + $jobs_product= $JobcardCustomComplaintModel->where('job_card_id', $job_card_id)->findAll(); $data['jobs_product']=$jobs_product; $JobcardServiceModel = new JobcardServiceModel(); $jobs_service= $JobcardServiceModel->where('job_card_id', $job_card_id)->findAll(); @@ -128,13 +140,13 @@ class Jobcard extends BaseController public function add_jobs() { + // echo $this->request->getPost('products');die; $JobcardModel = new JobcardModel(); $ProductModel = new ProductModel(); - $JobcardProductModel = new JobcardProductModel(); // Assuming you have a model for sales_order_product - + $JobcardCustomComplaintModel = new JobcardCustomComplaintModel(); $JobcardServiceModel = new JobcardServiceModel(); - // Prepare data for sales order + // Job card INSERT $data = [ 'client_name' => $this->request->getPost('client_id'), 'vehicle_id'=>$this->request->getPost('vehicle_id'), @@ -143,11 +155,6 @@ class Jobcard extends BaseController 'mobile_no' => $this->request->getPost('mobile_no'), 'billing_state' => $this->request->getPost('state'), 'billing_postal_code' => $this->request->getPost('postalcode'), - // 'billing_country' => $this->request->getPost('country'), - // 'terms_condition' => $this->request->getPost('terms_condition'), - // 'subtotal' => $this->request->getPost('sub_total'), - // 'tax' => $this->request->getPost('invoice_tax'), - 'total'=> $this->request->getPost('grand_total'), 'status'=> $this->request->getPost('status'), 'isactive' => 1, // Assuming this is a default value or handled separately @@ -166,10 +173,36 @@ class Jobcard extends BaseController $orderNumber = 'JC-' . date('md') . '-' . str_pad($job_card_id, 5, '0', STR_PAD_LEFT); // print_r($orderNumber);die; // Update sales order with generated order number - $JobcardModel->update($job_card_id, ['order_number' => $orderNumber]); + // $JobcardModel->update($job_card_id, ['order_number' => $orderNumber]); // Prepare data for sales order product // echo "
";
// print_r($this->request->getPost());die;
+
+ /********** INSERT SERVICE DATA ************/
+ $data = json_decode($_POST['products']);
+ $service_data = $data[0]->service;
+
+ foreach ($service_data as $item) {
+ // Insert into the service table
+ $service['job_card_id'] = $job_card_id;
+ $service['service_id'] = $item->service_id;
+ $service['quality'] = $item->quality;
+ $service['tax'] = $item->tax;
+ $service['amount'] = $item->amount;
+ $JobcardServiceModel->insert($service);
+ $service_id = $JobcardModel->getInsertID();
+
+ // Insert into the product table
+ foreach ($item->product as $product) {
+ $product['product_id'] = $product->p_id;
+ $product['qty'] = $product->qty;
+ $product['tax'] = $product->tax;
+ $product['amount'] = $product->amount;
+ $ProductModel->insert($product);
+ }
+ }
+
+
$product_ids = $this->request->getPost('item_details');
$quantities = $this->request->getPost('quantity');
$discounts = $this->request->getPost('discount_amount');
@@ -216,10 +249,10 @@ class Jobcard extends BaseController
if (!empty($job_card_product_id[$key])) {
- $JobcardProductModel->update($job_card_product_id[$key], $product_data);
+ $JobcardCustomComplaintModel->update($job_card_product_id[$key], $product_data);
} else {
- $JobcardProductModel->insert($product_data);
+ $JobcardCustomComplaintModel->insert($product_data);
}
diff --git a/app/Models/JobOtherWorksModel.php b/app/Models/JobOtherWorksModel.php
deleted file mode 100644
index 54801ed..0000000
--- a/app/Models/JobOtherWorksModel.php
+++ /dev/null
@@ -1,11 +0,0 @@
-select('job_card.*, COUNT(sales_order_product.job_card_id) AS product_count,vehicle.reg_no');
- // $this->select('job_card.*, COUNT(job_card_product.job_card_id) AS product_count, COUNT(job_card_service.job_card_id) AS service_count,vehicle.reg_no');
- $this->select('job_card.*, COUNT(job_card_product.job_card_id) AS product_count, vehicle.reg_no');
+ // $this->select('job_card.*, COUNT(job_card_service.job_card_id) AS product_count, COUNT(job_card_service.job_card_id) AS service_count,vehicle.reg_no');
+ $this->select('job_card.*, COUNT(job_card_service.job_card_id) AS product_count, vehicle.reg_no');
// Join the sales_order_product table based on job_card_id
- $this->join('job_card_product', 'job_card_product.job_card_id = job_card.job_card_id');
+ $this->join('job_card_service', 'job_card_service.job_card_id = job_card.job_card_id');
// $this->join('job_card_service', 'job_card_service.job_card_id = job_card.job_card_id');
$this->join('vehicle', 'vehicle.vehicle_id = job_card.vehicle_id');
@@ -25,7 +25,7 @@ class JobcardModel extends Model
$this->groupBy('job_card.job_card_id');
// Add condition to fetch only active sales orders
- $this->where('job_card_product.isactive', 1);
+ $this->where('job_card_service.isactive', 1);
// $this->where('job_card_service.isactive', 1);
$this ->where('job_card.branch_id',$logged_user_branch_id);
$this->orderBy('job_card.job_card_id','DESC');
diff --git a/app/Models/JobcardProductModel.php b/app/Models/JobcardProductModel.php
index 1d28de1..e93a990 100644
--- a/app/Models/JobcardProductModel.php
+++ b/app/Models/JobcardProductModel.php
@@ -5,7 +5,5 @@ class JobcardProductModel extends Model
{
protected $table = 'job_card_product';
protected $primaryKey = 'job_card_product_id';
- protected $allowedFields = ['job_card_product_id','item_name','qty','total','net_price','selling_price','discount','job_card_id','isactive'];
-
-
+ protected $allowedFields = ['job_card_product_id', 'product_id', 'qty', 'tax', 'isactive'];
}
\ No newline at end of file
diff --git a/app/Models/JobcardServiceModel.php b/app/Models/JobcardServiceModel.php
index 71b44c5..1683f73 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','service_name','qty','total','selling_price','discount','net_price','job_card_id','isactive'];
+ protected $allowedFields = ['job_card_service_id', 'job_card_id', 'service_id', 'product_id', 'qty', 'isactive'];
}
\ No newline at end of file
diff --git a/app/Views/job_card_form.php b/app/Views/job_card_form.php
index 4e86a29..8afdac0 100644
--- a/app/Views/job_card_form.php
+++ b/app/Views/job_card_form.php
@@ -20,10 +20,11 @@