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 @@
-