diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php index d1c2e55..393010c 100755 --- a/app/Controllers/Jobcard.php +++ b/app/Controllers/Jobcard.php @@ -18,8 +18,6 @@ use App\Models\OutsourceModel; use App\Models\BikemodelsModel; use App\Models\BikemakeModel; use App\Models\VehicleModel; -use App\Models\SalesOrderModel; -use App\Models\SalesOrderProductModel; use App\Models\UsersModel; use App\Models\RoleModel; use App\Models\JobcardFileModel; @@ -32,13 +30,29 @@ class Jobcard extends BaseController { public $session; use ResponseTrait; - public $BikemodelsModel; - public $BikemakeModel; - public $BusinessModel; - public $JobcardModel; - public $JobcardOSModel; - public $BranchModel; - public $UsersModel; + + protected $BikemodelsModel; + protected $BikemakeModel; + protected $BusinessModel; + protected $JobcardModel; + protected $JobcardOSModel; + protected $BranchModel; + protected $UsersModel; + protected $JobcardComplaintModel; + protected $JobcardCustomComplaintModel; + protected $JobcardServiceModel; + protected $JobcardProductModel; + protected $JobcardSubServiceModel; + protected $ProductModel; + protected $ServiceModel; + protected $ClientModel; + protected $ComplaintModel; + protected $OutsourceModel; + protected $VehicleModel; + protected $RoleModel; + protected $JobcardFileModel; + + public function __construct() { @@ -50,17 +64,30 @@ class Jobcard extends BaseController $this->JobcardOSModel = new JobcardOSModel(); $this->BranchModel = new BranchModel(); $this->UsersModel = new UsersModel(); + $this->JobcardComplaintModel = new JobcardComplaintModel(); + $this->JobcardCustomComplaintModel = new JobcardCustomComplaintModel(); + $this->JobcardServiceModel = new JobcardServiceModel(); + $this->JobcardProductModel = new JobcardProductModel(); + $this->JobcardSubServiceModel = new JobcardSubServiceModel(); + $this->ProductModel = new ProductModel(); + $this->ServiceModel = new ServiceModel(); + $this->ClientModel = new ClientModel(); + $this->ComplaintModel = new ComplaintModel(); + $this->OutsourceModel = new OutsourceModel(); + $this->VehicleModel = new VehicleModel(); + $this->RoleModel = new RoleModel(); + $this->JobcardFileModel = new JobcardFileModel(); } public function job_card_index() { - $JobcardModel = new JobcardModel(); + $data['id'] = $this->session->get('logged_user'); $data['role'] = $this->session->get('logged_user_role'); - $jobs= $JobcardModel->getJobCardsWithProductsAndService($this->session->get('logged_user_branch_id'), $data); - $data['jobs']=$jobs; + $data['jobs'] = $this->JobcardModel->getJobCardsWithProductsAndService($this->session->get('logged_user_branch_id'), $data); + $data['logged_user_role'] = $this->session->get('logged_user_role'); // echo "
";
// print_r($data);die;
@@ -235,7 +262,7 @@ class Jobcard extends BaseController
public function download_os()
{
- $JobcardProductModel = new JobcardProductModel();
+
$outsource = $this->JobcardModel->download_os($this->session->get('logged_user_branch_id'));
if (count($outsource) > 0) {
@@ -243,7 +270,7 @@ class Jobcard extends BaseController
foreach ($outsource as &$value) {
$products = [];
$product_ids = !empty(json_decode($value['product_id'], true)) ? json_decode($value['product_id'], true) : [0];
- $product = $JobcardProductModel->select('job_card_product.job_card_product_id,job_card_product.product_id,job_card_product.qty,products.product_name as pname')
+ $product = $this->JobcardProductModel->select('job_card_product.job_card_product_id,job_card_product.product_id,job_card_product.qty,products.product_name as pname')
->join('products', 'products.product_id = job_card_product.product_id')
->whereIn('job_card_product.job_card_product_id', $product_ids)->find();
@@ -318,7 +345,6 @@ class Jobcard extends BaseController
}
public function individual_download_os($job_card_id){
- $JobcardProductModel = new JobcardProductModel();
$outsource = $this->JobcardOSModel->individual_download_os($job_card_id);
if (count($outsource) > 0) {
@@ -326,7 +352,7 @@ class Jobcard extends BaseController
foreach ($outsource as &$value) {
$products = [];
$product_ids = !empty(json_decode($value['product_id'], true)) ? json_decode($value['product_id'], true) : [0];
- $product = $JobcardProductModel->select('job_card_product.job_card_product_id,job_card_product.product_id,job_card_product.qty,products.product_name as pname')
+ $product = $this->JobcardProductModel->select('job_card_product.job_card_product_id,job_card_product.product_id,job_card_product.qty,products.product_name as pname')
->join('products', 'products.product_id = job_card_product.product_id')
->whereIn('job_card_product.job_card_product_id', $product_ids)->find();
@@ -408,28 +434,29 @@ class Jobcard extends BaseController
$data['page_name']="Create Job Card";
$data['jobs'] = [];
$data['jobcardfiles'] = [];
- $ClientModel = new ClientModel();
- $client=$ClientModel
- ->where('isactive',1)
- ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
- $VehicleModel = new VehicleModel();
- $vehicle = $VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id'));
- $ProductModel = new ProductModel();
- $product=$ProductModel->select('products.*, manufacturer.manufacturer_name')
+
+ $client = $this->ClientModel
+ ->where('isactive',1)
+ ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+
+
+ $vehicle = $this->VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id'));
+
+ $product = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'products.manufacturer_id = manufacturer.manufacturer_id')
->where('products.isactive',1)
->where('products.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();
+ $service = $this->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();
+
+ $complaint = $this->ComplaintModel->where('isactive',1)->findAll();
- $OutsourceModel = new OutsourceModel();
- $os_data=$OutsourceModel->where('is_active',1)->findAll();
+
+ $os_data = $this->OutsourceModel->where('is_active',1)->findAll();
$data['complaint']= $complaint;
$data['product_1']=$product;
@@ -441,31 +468,23 @@ class Jobcard extends BaseController
$data['vehicle']=$vehicle;
$data['logged_user_role'] = $this->session->get('logged_user_role');
- } else if ($job_card_id !== '0')
- {
+ } else if ($job_card_id !== '0') {
// echo json_encode($this->session->get('logged_user_role'));die;
- $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();
- $JobcardFileModel = new JobcardFileModel();
+
+
+
+
+
/*** SERVICE DATA ***/
- $servicedata = $JobcardModel->service_data($job_card_id, $this->session->get('logged_user_branch_id'));
+ $servicedata = $this->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, manufacturer.manufacturer_name')
+ $product = $this->JobcardProductModel->select('job_card_product.* , products.product_name as pname, products.qty_stock, manufacturer.manufacturer_name')
->join('products', 'products.product_id = job_card_product.product_id')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->whereIn('job_card_product.job_card_product_id', $product_ids)->findAll();
@@ -473,7 +492,7 @@ class Jobcard extends BaseController
// 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')
+ $service = $this->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;
@@ -482,11 +501,11 @@ class Jobcard extends BaseController
// print_r($value);die;
$data['editservicedata'] = $servicedata;
/*** COMPLAINT DATA ***/
- $complaintdata = $JobcardModel->complaint_data($job_card_id, $this->session->get('logged_user_branch_id'));
+ $complaintdata = $this->JobcardModel->complaint_data($job_card_id, $this->session->get('logged_user_branch_id'));
// Using '&' to reference the original array element
foreach ($complaintdata as &$value) {
$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,manufacturer.manufacturer_name')
+ $product = $this->JobcardProductModel->select('job_card_product.* , products.product_name as pname, products.qty_stock,manufacturer.manufacturer_name')
->join('products', 'products.product_id = job_card_product.product_id')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->whereIn('job_card_product_id', $product_ids)
@@ -496,11 +515,11 @@ class Jobcard extends BaseController
$data['editcomplaintdata'] = $complaintdata;
/*** CUSTOM COMPLAINT DATA ***/
- $ccomplaintdata = $JobcardModel->ccomplaint_data($job_card_id, $this->session->get('logged_user_branch_id'));
+ $ccomplaintdata = $this->JobcardModel->ccomplaint_data($job_card_id, $this->session->get('logged_user_branch_id'));
// Using '&' to reference the original array element
foreach ($ccomplaintdata as &$value) {
$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, manufacturer.manufacturer_name')
+ $product = $this->JobcardProductModel->select('job_card_product.* , products.product_name as pname, products.qty_stock, manufacturer.manufacturer_name')
->join('products', 'products.product_id = job_card_product.product_id')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->whereIn('job_card_product_id', $product_ids)
@@ -510,11 +529,11 @@ class Jobcard extends BaseController
$data['editccomplaintdata'] = $ccomplaintdata;
/*** OUTSOURCING DATA ***/
- $os_data = $JobcardModel->os_data($job_card_id, $this->session->get('logged_user_branch_id'));
+ $os_data = $this->JobcardModel->os_data($job_card_id, $this->session->get('logged_user_branch_id'));
// Using '&' to reference the original array element
foreach ($os_data as &$value) {
$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, manufacturer.manufacturer_name')
+ $product = $this->JobcardProductModel->select('job_card_product.* , products.product_name as pname, products.qty_stock, manufacturer.manufacturer_name')
->join('products', 'products.product_id = job_card_product.product_id')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->whereIn('job_card_product_id', $product_ids)
@@ -523,44 +542,44 @@ class Jobcard extends BaseController
}
$data['editosdata'] = $os_data;
- $complaint=$ComplaintModel->where('isactive',1)->findAll();
+ $complaint = $this->ComplaintModel->where('isactive',1)->findAll();
$data['complaint']= $complaint;
- $data['os_data'] = $OutsourceModel->where('is_active',1)->findAll();
+ $data['os_data'] = $this->OutsourceModel->where('is_active',1)->findAll();
$data['page_name']="Edit Job Card";
- $ClientModel = new ClientModel();
- $client=$ClientModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
- $JobcardModel = new JobcardModel();
- $jobs=$JobcardModel->where('job_card_id', $job_card_id)->get()->getRowArray();
+ $client = $this->ClientModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+
+
+ $jobs = $this->JobcardModel->where('job_card_id', $job_card_id)->get()->getRowArray();
$data['jobs']=$jobs;
- $jobcardfiles=$JobcardFileModel->where(['job_card_id'=>$job_card_id,'isactive'=>1])->findAll();
+ $jobcardfiles = $this->JobcardFileModel->where(['job_card_id'=>$job_card_id,'isactive'=>1])->findAll();
$data['jobcardfiles'] = $jobcardfiles;
- $VehicleModel = new VehicleModel();
+
- $vehicles = $VehicleModel->where('isactive',1)->where('vehicle_id',$jobs['vehicle_id'])
+ $vehicles = $this->VehicleModel->where('isactive',1)->where('vehicle_id',$jobs['vehicle_id'])
->where('branch_id',$this->session->get('logged_user_branch_id'))
->first();
// print_r($jobs['vehicle_id']);die;
$makeId = $vehicles['make'];
$modelId = $vehicles['model'];
- $BikemakeModel = new BikemakeModel();
- $BikemodelsModel = new BikemodelsModel();
+
+
- $make_name = $BikemakeModel->where('make_id',$makeId)->select('make')->first();
- $model_name = $BikemodelsModel->where('model_id',$modelId)->select('model_name')->first();
+ $make_name = $this->BikemakeModel->where('make_id',$makeId)->select('make')->first();
+ $model_name = $this->BikemodelsModel->where('model_id',$modelId)->select('model_name')->first();
$data['make_model'] = $make_name['make'].' ' . $model_name['model_name'];
// Encode the modelId before searching
$encodedModelId = json_encode([$makeId]);
$encoded_make_id = json_encode(['0']);
- $product1 = $productModel->select('products.* , manufacturer.manufacturer_name')
+ $product1 = $this->ProductModel->select('products.* , manufacturer.manufacturer_name')
->where('JSON_CONTAINS(make_id, \'' . $encodedModelId . '\')', null, false)
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('qty_stock >',0)
->findAll();
- $product2 = $productModel->select('products.* , manufacturer.manufacturer_name')
+ $product2 = $this->ProductModel->select('products.* , manufacturer.manufacturer_name')
->orWhere('JSON_CONTAINS(make_id, \'' . $encoded_make_id . '\')', null, false)
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('qty_stock >',0)
@@ -569,16 +588,9 @@ class Jobcard extends BaseController
// $data['product']=$product;
$data['product']=$product;
- // echo json_encode($product);die;
-
- // Load the ServiceModel
- $ServiceModel = new ServiceModel();
$encodedMakeId = json_encode([$makeId]);
- // Query the database to find the product based on make_id and model_id
- // $service = $ServiceModel->where('JSON_CONTAINS(makes_id, \'' . $encodedMakeId . '\')', null, false)
- // ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
- // ->findAll();
- $service1 = $ServiceModel->where('makes_id LIKE \'%"' . $makeId . '"%\'', null, false)
+
+ $service1 = $this->ServiceModel->where('makes_id LIKE \'%"' . $makeId . '"%\'', null, false)
->where('models_id LIKE \'%"' . $modelId . '"%\'', null, false)
->orWhere('category', 0)
->findAll();
@@ -586,7 +598,7 @@ class Jobcard extends BaseController
$encodedMakeId1 = 0;
$encodedModelId1 = 0;
- $common_services = $ServiceModel->where('makes_id LIKE \'%"' . $encodedMakeId1 . '"%\'', null, false)
+ $common_services = $this->ServiceModel->where('makes_id LIKE \'%"' . $encodedMakeId1 . '"%\'', null, false)
->where('models_id LIKE \'%"' . $encodedModelId1 . '"%\'', null, false)
->findAll();
$service = array_merge($common_services, $service1);
@@ -596,14 +608,13 @@ class Jobcard extends BaseController
$data['service']=$service;
// echo "";
// print_r($service);die;
- $jobs_product= $JobcardCustomComplaintModel->where('job_card_id', $job_card_id)->findAll();
+ $jobs_product= $this->JobcardCustomComplaintModel->where('job_card_id', $job_card_id)->findAll();
$data['jobs_product']=$jobs_product;
- $jobs_service= $JobcardServiceModel->where('job_card_id', $job_card_id)->findAll();
+ $jobs_service= $this->JobcardServiceModel->where('job_card_id', $job_card_id)->findAll();
$data['jobs_service']=$jobs_service;
$data['client']=$client;
- // print_r($jobs_product);die;
- $VehicleModel = new VehicleModel();
- $vehicle=$VehicleModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+
+ $vehicle = $this->VehicleModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$data['vehicle']=$vehicle;
$data['logged_user_role'] = $this->session->get('logged_user_role');
if($rework == 're-work') { $data['rework']= true; }
@@ -614,11 +625,11 @@ class Jobcard extends BaseController
}
- $RoleModel = new RoleModel();
- $data['workers'] = $RoleModel->get_workers($this->session->get('logged_user_branch_id'));
+
+ $data['workers'] = $this->RoleModel->get_workers($this->session->get('logged_user_branch_id'));
$data['job_card_id'] = $job_card_id;
- $bikeMakeModel = new BikeMakeModel();
- $data['makeData'] =$bikeMakeModel->findAll();
+
+ $data['makeData'] =$this->BikemakeModel->findAll();
@@ -629,21 +640,17 @@ class Jobcard extends BaseController
public function add_jobs()
{
- $JobcardModel = new JobcardModel();
+
if($this->session->get('logged_user_role') == "Store Manager") {
$data['status'] = $this->request->getPost('status');
$job_card_id = $this->request->getPost('job_card_id');
- $JobcardModel->update($job_card_id, $data); // issued status update
+ $this->JobcardModel->update($job_card_id, $data); // issued status update
$issued_product_id = $this->request->getPost('issued_items');
$this->update_store_status($issued_product_id, $data['status']);
return redirect()->to('job_card_index');
}
- $JobcardProductModel = new JobcardProductModel();
- $JobcardSubServiceModel = new JobcardSubServiceModel();
- $JobcardServiceModel = new JobcardServiceModel();
- $JobcardComplaintModel = new JobcardComplaintModel();
- $JobcardCustomComplaintModel = new JobcardCustomComplaintModel();
- $JobcardOSModel = new JobcardOSModel();
+
+
$this->delete_items($this->request->getPost('delete_items'));
$rework = $this->request->getPost('rework');
@@ -691,19 +698,19 @@ class Jobcard extends BaseController
$job_card_data['status'] = $status;
$job_card_data['isactive'] = 0;
}
- $JobcardModel->update($job_card_id, $job_card_data);
+ $this->JobcardModel->update($job_card_id, $job_card_data);
} else {
$job_card_data['inv_no'] = InvNoHelper::generateInvoiceNumber();
- $JobcardModel->insert($job_card_data);
- $job_card_id = $JobcardModel->getInsertID(); // Get the last inserted ID
+ $this->JobcardModel->insert($job_card_data);
+ $job_card_id = $this->JobcardModel->getInsertID(); // Get the last inserted ID
if(isset($rework)) {
- $job_card = $JobcardModel->find($rework);
- $JobcardModel->update($job_card_id, ['order_number' => $job_card['order_number'], 'is_rework' => 1 ]);
+ $job_card = $this->JobcardModel->find($rework);
+ $this->JobcardModel->update($job_card_id, ['order_number' => $job_card['order_number'], 'is_rework' => 1 ]);
} else {
$orderNumber = 'JC-' . date('md') . '-' . str_pad($job_card_id, 5, '0', STR_PAD_LEFT);
- $JobcardModel->update($job_card_id, ['order_number' => $orderNumber]);
+ $this->JobcardModel->update($job_card_id, ['order_number' => $orderNumber]);
}
}
@@ -722,8 +729,8 @@ class Jobcard extends BaseController
$service['amount'] = $item->amount;
if(empty($item->id)) {
- $JobcardServiceModel->insert($service);
- $service_id = $JobcardServiceModel->getInsertID();
+ $this->JobcardServiceModel->insert($service);
+ $service_id = $this->JobcardServiceModel->getInsertID();
}
else {
if($status == 'Cancelled')
@@ -731,12 +738,12 @@ class Jobcard extends BaseController
$service = [];
$service['isactive'] = 0;
}
- $JobcardServiceModel->update($item->id, $service);
+ $this->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); }
+ if(isset($item->product)) { $this->product_data_insertion($job_card_id, $service_id, $this->JobcardServiceModel, $item, $this->JobcardProductModel, $status, $rework); }
+ if(isset($item->sub_service)) { $this->sub_service_data_insertion($job_card_id, $service_id, $this->JobcardServiceModel, $item, $this->JobcardSubServiceModel, $status, $rework); }
}
@@ -752,8 +759,8 @@ class Jobcard extends BaseController
$service['tax'] = (int)$item->tax;
$service['amount'] = $item->amount;
if(empty($item->id)) {
- $JobcardComplaintModel->insert($service);
- $complaint_id = $JobcardComplaintModel->getInsertID();
+ $this->JobcardComplaintModel->insert($service);
+ $complaint_id = $this->JobcardComplaintModel->getInsertID();
}
else {
if($status == 'Cancelled')
@@ -761,11 +768,11 @@ class Jobcard extends BaseController
$service = [];
$service['isactive'] = 0;
}
- $JobcardComplaintModel->update($item->id, $service);
+ $this->JobcardComplaintModel->update($item->id, $service);
$complaint_id = $item->id;
}
- if(isset($item->product)) { $this->product_data_insertion($job_card_id, $complaint_id, $JobcardComplaintModel, $item, $JobcardProductModel, $status, $rework); }
+ if(isset($item->product)) { $this->product_data_insertion($job_card_id, $complaint_id, $this->JobcardComplaintModel, $item, $this->JobcardProductModel, $status, $rework); }
}
/********** INSERT CUSTOM COMPLAINT DATA ************/
@@ -780,8 +787,8 @@ class Jobcard extends BaseController
$service['tax'] = $item->tax;
$service['amount'] = $item->amount;
if(empty($item->id) || $item->id == "product") {
- $JobcardCustomComplaintModel->insert($service);
- $cc_complaint_id = $JobcardCustomComplaintModel->getInsertID();
+ $this->JobcardCustomComplaintModel->insert($service);
+ $cc_complaint_id = $this->JobcardCustomComplaintModel->getInsertID();
}
else {
if($status == 'Cancelled')
@@ -789,11 +796,11 @@ class Jobcard extends BaseController
$service = [];
$service['isactive'] = 0;
}
- $JobcardCustomComplaintModel->update($item->id, $service);
+ $this->JobcardCustomComplaintModel->update($item->id, $service);
$cc_complaint_id = $item->id;
}
- if(isset($item->product)) { $this->product_data_insertion($job_card_id, $cc_complaint_id, $JobcardCustomComplaintModel, $item, $JobcardProductModel, $status, $rework); }
+ if(isset($item->product)) { $this->product_data_insertion($job_card_id, $cc_complaint_id, $this->JobcardCustomComplaintModel, $item, $this->JobcardProductModel, $status, $rework); }
}
/********** INSERT OUTSOURCE DATA ************/
@@ -808,8 +815,8 @@ class Jobcard extends BaseController
$service['tax'] = $item->tax;
$service['amount'] = $item->amount;
if(empty($item->id)) {
- $JobcardOSModel->insert($service);
- $os_id = $JobcardOSModel->getInsertID();
+ $this->JobcardOSModel->insert($service);
+ $os_id = $this->JobcardOSModel->getInsertID();
}
else {
if($status == 'Cancelled')
@@ -817,11 +824,11 @@ class Jobcard extends BaseController
$service = [];
$service['isactive'] = 0;
}
- $JobcardOSModel->update($item->id, $service);
+ $this->JobcardOSModel->update($item->id, $service);
$os_id = $item->id;
}
- if(isset($item->product)) { $this->product_data_insertion($job_card_id, $os_id, $JobcardOSModel, $item, $JobcardProductModel, $status, $rework); }
+ if(isset($item->product)) { $this->product_data_insertion($job_card_id, $os_id, $this->JobcardOSModel, $item, $this->JobcardProductModel, $status, $rework); }
}
// Get the files from the request
@@ -855,20 +862,19 @@ class Jobcard extends BaseController
public function update_store_status($issued_product_id, $status)
{
if($status == 'Issued') {
- $JobcardProductModel = new JobcardProductModel();
- $productModel = new ProductModel();
+
$product_data = json_decode($issued_product_id);
foreach ($product_data as $key => $value) {
- $jc_product = $JobcardProductModel->where('job_card_product_id', $value->id)->findAll();
+ $jc_product = $this->JobcardProductModel->where('job_card_product_id', $value->id)->findAll();
if($jc_product[0]['status'] == 0)
{
$data['issued_qty'] = $value->qty;
if($value->qty == $jc_product[0]['qty']) { $data['status'] = 1; }
- $res = $JobcardProductModel->update($value->id, $data);
+ $res = $this->JobcardProductModel->update($value->id, $data);
if($res)
{
$deduct_qty = $value->qty - $jc_product[0]['issued_qty'];
- $this->updateProductQuantity($productModel, $jc_product[0]['product_id'], $deduct_qty);
+ // $this->updateProductQuantity($this->ProductModel, $jc_product[0]['product_id'], $deduct_qty);
}
}
}
@@ -891,8 +897,8 @@ class Jobcard extends BaseController
$product['tax'] = $pt->tax;
$product['amount'] = $pt->amount / $pt->qty; //(isset($rework) ? 0 : $pt->amount / $pt->qty );
if(empty($pt->id)) {
- $JobcardProductModel->insert($product);
- $job_card_product_id = $JobcardProductModel->getInsertID();
+ $this->JobcardProductModel->insert($product);
+ $job_card_product_id = $this->JobcardProductModel->getInsertID();
}
else {
if($status == 'Cancelled')
@@ -902,10 +908,10 @@ class Jobcard extends BaseController
$product['product_id'] = $pt->p_id;
$product['is_active'] = 0;
}
- $old_data = $JobcardProductModel->find($pt->id);
+ $old_data = $this->JobcardProductModel->find($pt->id);
if($pt->qty != $old_data['issued_qty'] && $pt->qty > $old_data['issued_qty']) { $product['status'] = 0; }
// echo $pt->id;die;
- $JobcardProductModel->update($pt->id, $product);
+ $this->JobcardProductModel->update($pt->id, $product);
$job_card_product_id = $pt->id;
}
array_push($id, $job_card_product_id);
@@ -932,8 +938,8 @@ class Jobcard extends BaseController
$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();
+ $this->JobcardSubServiceModel->insert($product);
+ $job_card_sub_service_id = $this->JobcardSubServiceModel->getInsertID();
}
else {
if($status == 'Cancelled')
@@ -943,10 +949,10 @@ class Jobcard extends BaseController
$product['sub_service_id'] = $pt->s_id;
$product['is_active'] = 0;
}
- $old_data = $JobcardSubServiceModel->find($pt->id);
+ $old_data = $this->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);
+ $this->JobcardSubServiceModel->update($pt->id, $product);
$job_card_sub_service_id = $pt->id;
}
array_push($id, $job_card_sub_service_id);
@@ -971,21 +977,15 @@ class Jobcard extends BaseController
public function delete_items($delArr)
{
- $JobcardProductModel = new JobcardProductModel();
- $JobcardSubServiceModel = new JobcardSubServiceModel();
- $JobcardServiceModel = new JobcardServiceModel();
- $JobcardComplaintModel = new JobcardComplaintModel();
- $JobcardCustomComplaintModel = new JobcardCustomComplaintModel();
- $JobcardOSModel = new JobcardOSModel();
+
+
$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();
+ $this->JobcardProductModel->where($conditions)->delete();
}
}
@@ -993,9 +993,7 @@ class Jobcard extends BaseController
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();
+ $this->JobcardSubServiceModel->where($conditions)->delete();
}
}
@@ -1003,10 +1001,10 @@ class Jobcard extends BaseController
if(!empty($service_data)) {
foreach ($service_data as $item) {
$conditions = [ 'job_card_service_id' => $item ];
- $service_deleted_data = $JobcardServiceModel->where($conditions)->findAll();
+ $service_deleted_data = $this->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();
+ $this->JobcardServiceModel->where($conditions)->delete();
}
}
@@ -1014,10 +1012,10 @@ class Jobcard extends BaseController
if(!empty($complaint_data)) {
foreach ($complaint_data as $item) {
$conditions = [ 'job_card_complaint_id' => $item ];
- $complaint_deleted_data = $JobcardComplaintModel->where($conditions)->findAll();
+ $complaint_deleted_data = $this->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();
+ $this->JobcardComplaintModel->where($conditions)->delete();
}
}
@@ -1025,10 +1023,10 @@ class Jobcard extends BaseController
if(!empty($ccomplaint_data)) {
foreach ($ccomplaint_data as $item) {
$conditions = [ 'job_card_cc_id' => $item ];
- $cc_deleted_data = $JobcardCustomComplaintModel->where($conditions)->findAll();
+ $cc_deleted_data = $this->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();
+ $this->JobcardCustomComplaintModel->where($conditions)->delete();
}
}
@@ -1036,51 +1034,49 @@ class Jobcard extends BaseController
if(!empty($os_data)) {
foreach ($os_data as $item) {
$conditions = [ 'job_card_os_id' => $item ];
- $os_deleted_data = $JobcardOSModel->where($conditions)->findAll();
+ $os_deleted_data = $this->JobcardOSModel->where($conditions)->findAll();
if(isset($os_deleted_data[0]['product_id']))
$this->product_delete($os_deleted_data[0]['product_id']);
- $JobcardOSModel->where($conditions)->delete();
+ $this->JobcardOSModel->where($conditions)->delete();
}
}
}
/** DELETE JOB CARD-PRODUCT */
public function product_delete($product) {
- $JobcardProductModel = new JobcardProductModel();
$product_ids = json_decode($product, true);
if (empty($product_ids)) return true;
foreach ($product_ids as $item) {
$conditions = [ 'job_card_product_id' => $item ];
- $JobcardProductModel->where($conditions)->delete();
+ $this->JobcardProductModel->where($conditions)->delete();
}
return true;
}
public function product_data_maintanence($id_array,$status)
{
- $ProductModel = new ProductModel();
- $JobcardProductModel = new JobcardProductModel();
+
foreach ($id_array as $key => $product_id) {
- $product = $JobcardProductModel->find($product_id);
+ $product = $this->JobcardProductModel->find($product_id);
$qty = isset($product['issued_qty']) ? $product['issued_qty'] : 0;
if ($status == 'Issued') {
- // $this->subractProductQuantity($ProductModel, $product['product_id'], $qty);
+ // $this->subractProductQuantity( $product['product_id'], $qty);
}elseif ($status == 'Cancelled'){
- $this->subractProductQuantity($ProductModel, $product['product_id'], $qty);
+ $this->subractProductQuantity( $product['product_id'], $qty);
$data['status'] = 0;
// echo $product['job_card_product_id'];die;
- // $JobcardProductModel->where('job_card_product_id',$product['job_card_product_id'])->update($data);
+ // $this->JobcardProductModel->where('job_card_product_id',$product['job_card_product_id'])->update($data);
}
}
}
- private function addBackProductQuantity($ProductModel, $product_id, $sold_qty)
+ private function addBackProductQuantity( $product_id, $sold_qty)
{
// Fetch current product quantity
- $product = $ProductModel->find($product_id);
+ $product = $this->ProductModel->find($product_id);
$data['qty_stock'] = $product['qty_stock'] + $sold_qty;
@@ -1094,14 +1090,14 @@ class Jobcard extends BaseController
}
// Update quantity in Product table
- $ProductModel->update($product_id, $data );
+ $this->ProductModel->update($product_id, $data );
}
- private function subractProductQuantity($ProductModel, $product_id, $sold_qty)
+ private function subractProductQuantity( $product_id, $sold_qty)
{
// Fetch current product quantity
- $product = $ProductModel->find($product_id);
+ $product = $this->ProductModel->find($product_id);
$data['qty_stock'] = $product['qty_stock'] - $sold_qty;
@@ -1115,38 +1111,22 @@ class Jobcard extends BaseController
}
// Update quantity in Product table
- $ProductModel->update($product_id, $data );
+ $this->ProductModel->update($product_id, $data );
}
- public function delete_sales_product()
- {
- $sales_order_product_id = $this->request->getPost('sales_order_product_id');
-
- if (!empty($sales_order_product_id)) {
- $SalesOrderProductModel = new SalesOrderProductModel();
- $data['isactive'] = 0;
-
- if ($SalesOrderProductModel->update($sales_order_product_id, $data)) {
- // Return success response
- return $this->response->setJSON(['success' => true]);
- }
- }
-
- // Return error response if deletion fails
- return $this->response->setJSON(['success' => false]);
- }
+
public function delete_jobcard($job_card_id)
{
- $model = new JobcardModel();
+
$where = ['job_card_id' => $job_card_id, 'isactive' => 1]; // Assuming 'isactive' is a column in your database
- $existingProduct = $model->where($where)->first();
+ $existingProduct = $this->JobcardModel->where($where)->first();
if ($existingProduct) {
$data['isactive'] = 0;
- if ($model->update($job_card_id, $data)) {
+ if ($this->JobcardModel->update($job_card_id, $data)) {
session()->setFlashdata('success', 'Deleted successfully.');
$this->logger->info("Job Card: has been Inactivated successfully. Inactivated ID = ".$job_card_id);
}
@@ -1159,18 +1139,17 @@ class Jobcard extends BaseController
public function save_vehicle(){
// Load ClientModel
- $VehicleModel = new VehicleModel();
-
+
if($this->request->getPost('formType') == 'create')
{
- $ClientModel = new ClientModel();
+
$client['client_name'] = $this->request->getPost('createclientName');
$client['mobile_no'] = $this->request->getPost('createclientMobile');
$client['client_type'] = $this->request->getPost('createclientType');
$client['branch_id'] = $this->session->get('logged_user_branch_id');
- $client_id = $ClientModel->insert($client);
+ $client_id = $this->ClientModel->insert($client);
if($client_id){
@@ -1210,9 +1189,9 @@ class Jobcard extends BaseController
// Attempt to insert the client data
- $id = $VehicleModel->insert($data);
+ $id = $this->VehicleModel->insert($data);
if ($id) {
- $vehicleData = $VehicleModel->where('vehicle_id',$id)->first();
+ $vehicleData = $this->VehicleModel->where('vehicle_id',$id)->first();
// If insertion succeeds, return success response
return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','vehicleData'=>$vehicleData]);
@@ -1242,10 +1221,10 @@ class Jobcard extends BaseController
$encodedModelId = json_encode([$modelId]);
// Load the ProductModel
- $ServiceModel = new ServiceModel();
+
// Query the database to find the service based on make_id and model_id
- $service1 = $ServiceModel->where('makes_id LIKE \'%"' . $makeId . '"%\'', null, false)
+ $service1 = $this->ServiceModel->where('makes_id LIKE \'%"' . $makeId . '"%\'', null, false)
->where('models_id LIKE \'%"' . $modelId . '"%\'', null, false)
->where('category',1)
->where('isactive' ,1)
@@ -1254,13 +1233,13 @@ class Jobcard extends BaseController
$encodedMakeId1 = 0;
$encodedModelId1 =0;
- $common_services = $ServiceModel->where('makes_id LIKE \'%"' . $encodedMakeId1 . '"%\'', null, false)
+ $common_services = $this->ServiceModel->where('makes_id LIKE \'%"' . $encodedMakeId1 . '"%\'', null, false)
->where('models_id LIKE \'%"' . $encodedModelId1 . '"%\'', null, false)
->where('category',1)
->where('isactive' ,1)
->findAll();
- $service2 = $ServiceModel->where('category',0)
+ $service2 = $this->ServiceModel->where('category',0)
->where('isactive' ,1)
->findAll();
$service = array_merge($common_services, $service1, $service2);
@@ -1280,18 +1259,18 @@ class Jobcard extends BaseController
function uploadAdditionalFile($myfiles)
{
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
- $model = new JobcardFileModel();
- $id = $model->insert($myfiles);
- $aff = $model->affectedRows();
- return $aff > 0 ? $model->insertID() : 0;
+
+ $id = $this->JobcardFileModel->insert($myfiles);
+ $aff = $this->JobcardFileModel->affectedRows();
+ return $aff > 0 ? $this->JobcardFileModel->insertID() : 0;
}
public function deleteJobCardFile()
{
$file_id = $this->request->getPost('file_id');
- $model = new JobcardFileModel();
+
$where = ['file_id' => $file_id, 'isactive' => 1 ];
- $existingFile = $model->where($where)->first();
+ $existingFile = $this->JobcardFileModel->where($where)->first();
if ($existingFile) {
@@ -1299,7 +1278,7 @@ class Jobcard extends BaseController
$data['updated_by'] = $this->session->has('logged_user');
- if ($model->update($file_id, $data)) {
+ if ($this->JobcardFileModel->update($file_id, $data)) {
// session()->setFlashdata('success', 'Deleted successfully.');
return $this->response->setJSON(['success' => true, 'message' => 'File deleted successfully.','file_id'=>$file_id]);
$this->logger->info("job card file : has been deleted successfully. Inactivated ID = ".$file_id);
diff --git a/app/Controllers/Products.php b/app/Controllers/Products.php
index 1002bba..73b12eb 100755
--- a/app/Controllers/Products.php
+++ b/app/Controllers/Products.php
@@ -16,6 +16,12 @@ use CodeIgniter\API\ResponseTrait;
class Products extends BaseController
{
protected $additionalProductNameModal;
+ protected $ProductModel;
+ protected $BikemakeModel;
+ protected $BikemodelsModel;
+ protected $VendorModel;
+ protected $ManufacturerModel;
+ protected $ProductCategoryModel;
public $session;
use ResponseTrait;
@@ -23,17 +29,23 @@ class Products extends BaseController
public function __construct()
{
$this->session = session();
- $this->additionalProductNameModal = new AdditionalProductNameModal();
+ $this->ProductModel = new ProductModel();
+ $this->BikemakeModel = new BikemakeModel();
+ $this->BikemodelsModel = new BikemodelsModel();
+ $this->VendorModel = new VendorModel();
+ $this->ManufacturerModel = new ManufacturerModel();
+ $this->ProductCategoryModel = new ProductCategoryModel();
+ $this->additionalProductNameModal = new AdditionalProductNameModal();
}
public function product_index($manufacturer_id = null)
{
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
if ($manufacturer_id) {
- $ProductModel = new ProductModel();
- $ManufacturerModel = new ManufacturerModel();
- $products = $ProductModel->where('manufacturer_id',$manufacturer_id)->orderBy('product_name')->findAll();
- $manufacturer = $ManufacturerModel->where('manufacturer_id',$manufacturer_id)->select('manufacturer_name')->first();
+
+
+ $products = $this->ProductModel->where('manufacturer_id',$manufacturer_id)->orderBy('product_name')->findAll();
+ $manufacturer = $this->ManufacturerModel->where('manufacturer_id',$manufacturer_id)->select('manufacturer_name')->first();
$data['products']=$products;
$data['manufacturer_id'] = $manufacturer_id;
@@ -41,8 +53,8 @@ class Products extends BaseController
return view('product_list',$data);
} else {
- $ProductModel = new ProductModel();
- $products = $ProductModel->get_products($this->session->get('logged_user_branch_id'));
+
+ $products = $this->ProductModel->get_products($this->session->get('logged_user_branch_id'));
$data['products']=$products;
// echo "";
// print_r($products);die;
@@ -61,56 +73,56 @@ class Products extends BaseController
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
if ($product_id === '0') {
- $data['products'] = [];
- $ProductModel = new ProductModel();
- $tax=$ProductModel->getTax();
+
+ $tax = $this->ProductModel->getTax();
$data['tax']=$tax;
- $BikemakeModel = new BikemakeModel();
- $data['make'] = $BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('make')->findAll();
- $VendorModel = new VendorModel();
- $data['vendors']=$VendorModel->orderBy('vendor_name')->findAll();
- $ManufacturerModel = new ManufacturerModel();
+
+ $data['make'] = $this->BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('make')->findAll();
+
+ $data['vendors'] = $this->VendorModel->orderBy('vendor_name')->findAll();
+
- $data['manufacturers']=$ManufacturerModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('manufacturer_name')->findAll();
+ $data['manufacturers'] = $this->ManufacturerModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('manufacturer_name')->findAll();
$data['page_name']="Add Product";
- $ProductCategoryModel = new ProductCategoryModel();
- $productcategory = $ProductCategoryModel->orderBy('product_category_id')->findAll();
+
+ $productcategory = $this->ProductCategoryModel->orderBy('product_category_id')->findAll();
$data['productcategory']=$productcategory;
$data['vendorsProduct'] =[];
+
+
} else if ($product_id !== '0') {
$data['page_name']="Edit Product";
- $ProductModel = new ProductModel();
- $products=$ProductModel->where('product_id', $product_id)->get()->getRowArray();
+
+ $products = $this->ProductModel->where('product_id', $product_id)->get()->getRowArray();
$products['make_id'] = json_decode($products['make_id'], true);
$products['models_id'] = json_decode($products['models_id'], true);
- $data['products']=$products;
+ $data['products'] = $products;
- $BikemakeModel = new BikemakeModel();
- $data['make'] = $BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('make')->findAll();
- $BikemodelsModel = new BikemodelsModel();
+
+ $data['make'] = $this->BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('make')->findAll();
+
$make_id = $products['make_id'];
- $BikemodelsModel = new BikemodelsModel();
+
$models = [];
if( $products['make_id'] != null) {
foreach ($products['make_id'] as $make_id) {
- // $models[] = $BikemodelsModel->where('make_id', $make_id)->findAll();
- $models[] = $BikemodelsModel->where('make_id', $make_id)->orderBy('model_name')->findAll();
+ $models[] = $this->BikemodelsModel->where('make_id', $make_id)->orderBy('model_name')->findAll();
}
}
$data['models'] = $models;
- $tax=$ProductModel->getTax();
+ $tax = $this->ProductModel->getTax();
$data['tax']=$tax;
- $VendorModel = new VendorModel();
- $data['vendors']=$VendorModel->orderBy('vendor_name')->findAll();
- $ManufacturerModel = new ManufacturerModel();
- $data['manufacturers']=$ManufacturerModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('manufacturer_name', 'ASC')->findAll();
+
+ $data['vendors'] = $this->VendorModel->orderBy('vendor_name')->findAll();
+
+ $data['manufacturers'] = $this->ManufacturerModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('manufacturer_name', 'ASC')->findAll();
$vendorIds = json_decode($products['vendor'], true);
@@ -119,9 +131,9 @@ class Products extends BaseController
$vendors = [];
- $VendorModel = new VendorModel();
+
foreach ($vendorIds as $vendorId) {
- $vendor = $VendorModel->find($vendorId);
+ $vendor = $this->VendorModel->find($vendorId);
if ($vendor) {
$vendors[] = ['id' => $vendor['vendor_id'], 'name' => $vendor['vendor_name']];
}
@@ -136,20 +148,17 @@ class Products extends BaseController
}
$data['product_id'] = $product_id;
- $ProductCategoryModel = new ProductCategoryModel();
- $productcategory = $ProductCategoryModel->orderBy('product_category_id')->findAll();
+
+ $productcategory = $this->ProductCategoryModel->orderBy('product_category_id')->findAll();
$additionalProdutName = $this->additionalProductNameModal
->where('product_id', $product_id)
->where('isactive', 1)
->orderBy('product_names_id', 'asc')
->findAll();
- $data['productcategory']=$productcategory;
- $data['additionalProdutName']=$additionalProdutName;
+ $data['productcategory'] = $productcategory;
+ $data['additionalProdutName'] = $additionalProdutName;
- // dd($data);
- // print_r($data);die;
- // echo "";
- // print_r($data['manufacturers']);die;
+
echo view('product_form',$data);
}
@@ -159,7 +168,7 @@ class Products extends BaseController
// dd($this->request->getPost());
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
- $ProductModel = new ProductModel();
+
$tax= $this->request->getPost('tax')/2;
$ml = 0; $box = 0; $qty_per_box = 0; $barrel = 0; $ltr_per_barrel = 0;
@@ -214,10 +223,10 @@ class Products extends BaseController
// print_r($data);die;
if (!empty($product_id)) {
- $ProductModel->update($product_id, $data);
+ $this->ProductModel->update($product_id, $data);
} else {
- $ProductModel->insert($data);
- $product_id = $ProductModel->getInsertID();
+ $this->ProductModel->insert($data);
+ $product_id = $this->ProductModel->getInsertID();
}
//for insert or update Additional Product Names
@@ -226,21 +235,22 @@ class Products extends BaseController
$orderNumber = 'TM' . str_pad($product_id, 8, '0', STR_PAD_LEFT);
// Update sales order with generated order number
- $ProductModel->update($product_id, ['sku_id' => $orderNumber]);
- return redirect()->to('product_index');
+ $this->ProductModel->update($product_id, ['sku_id' => $orderNumber]);
+
+ return redirect()->to('product_index');
}
public function delete_product($product_id)
{
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
- $model = new ProductModel();
+
$where = ['product_id' => $product_id, 'isactive' => 1 , 'branch_id' => $this->session->get('logged_user_branch_id')]; // Assuming 'isactive' is a column in your database
- $existingProduct = $model->where($where)->first();
+ $existingProduct = $this->ProductModel->where($where)->first();
if ($existingProduct) {
$data['isactive'] = 0;
- if ($model->update($product_id, $data)) {
+ if ($this->ProductModel->update($product_id, $data)) {
session()->setFlashdata('success', 'Deleted successfully.');
$this->logger->info("Users: has been Inactivated successfully. Inactivated ID = ".$product_id);
}
@@ -256,8 +266,8 @@ class Products extends BaseController
$model_ids = $this->request->getPost('model_ids');
$make_id = $this->request->getPost('make_id');
- $vendorModel = new VendorModel();
- $Vendors = $vendorModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+
+ $Vendors = $this->VendorModel->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
if($Vendors){
$data = [];
@@ -307,8 +317,8 @@ class Products extends BaseController
public function get_models()
{
- $make_ids = $this->request->getPost('make_id'); // Assuming you are sending make_id via POST
- $BikemodelsModel = new BikemodelsModel(); // Adjust this according to your actual model name
+ $make_ids = $this->request->getPost('make_id');
+
@@ -318,7 +328,7 @@ class Products extends BaseController
if ($make_ids) {
foreach ($make_ids as $make_id) {
// Fetch models based on the selected make ID
- $models = $BikemodelsModel->where('make_id', $make_id)->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('model_name')->findAll();
+ $models = $this->BikemodelsModel->where('make_id', $make_id)->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('model_name')->findAll();
// Iterate over each fetched model and format it as needed
foreach ($models as $model) {
@@ -342,10 +352,10 @@ class Products extends BaseController
{
$response = []; // Initialize an empty array to hold the response data
- // Assuming BikemakeModel and BikemodelsModel are properly defined
+
- $BikemakeModel = new BikemakeModel();
- $BikemodelsModel = new BikemodelsModel();
+
+
$make = $this->request->getPost('make');
$model = $this->request->getPost('model');
@@ -358,8 +368,8 @@ class Products extends BaseController
];
// Insert the make into the database
- $BikemakeModel->insert($data);
- $make_id = $BikemakeModel->getInsertID();
+ $this->BikemakeModel->insert($data);
+ $make_id = $this->BikemakeModel->getInsertID();
$modelData = [
'model_name' => $model,
@@ -368,7 +378,7 @@ class Products extends BaseController
];
// Insert the model into the database
- $BikemodelsModel->insert($modelData);
+ $this->BikemodelsModel->insert($modelData);
// Set success status in the response
$response['success'] = true;
@@ -383,15 +393,15 @@ class Products extends BaseController
public function get_makes()
{
- $BikeMakeModel = new BikeMakeModel(); // Adjust this according to your actual model name
- $makes = $BikeMakeModel->findAll();
+
+ $makes = $this->BikemakeModel->findAll();
return $this->response->setJSON($makes);
}
public function save_model()
{
$response = [];
- $BikemodelsModel = new BikemodelsModel();
+
$make_id = $this->request->getPost('make_id');
$model = $this->request->getPost('modelvalue');
@@ -403,9 +413,9 @@ class Products extends BaseController
];
- $model_id = $BikemodelsModel->insert($modelData);
+ $model_id = $this->BikemodelsModel->insert($modelData);
- $modelData = $BikemodelsModel->where('make_id',$make_id)->findAll();
+ $modelData = $this->BikemodelsModel->where('make_id',$make_id)->findAll();
$response['success'] = true;
@@ -423,7 +433,7 @@ class Products extends BaseController
public function save_manufacturer()
{
$response = [];
- $ManufacturerModel = new ManufacturerModel();
+
$manufacturer_name = $this->request->getPost('manufacturer_name');
$quality = $this->request->getPost('quality');
@@ -435,9 +445,9 @@ class Products extends BaseController
];
- $manufacturer_id = $ManufacturerModel->insert($modelData);
+ $manufacturer_id = $this->ManufacturerModel->insert($modelData);
- $modelData = $ManufacturerModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('manufacturer_name')->findAll();
+ $modelData = $this->ManufacturerModel->where('business_id', $this->session->get('logged_user_business_id'))->orderBy('manufacturer_name')->findAll();
$response['success'] = true;
@@ -455,13 +465,13 @@ class Products extends BaseController
public function product_list_for_service()
{
- $ProductModel = new ProductModel();
+
// Assuming you have a model for products and one for manufacturers
- $products = $ProductModel
- ->select('products.*, manufacturer.manufacturer_name')
- ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
- ->where('products.branch_id', $this->session->get('logged_user_branch_id'))
- ->findAll();
+ $products = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name')
+ ->join('products', 'products.product_id = product_names.product_id')
+ ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
+ ->where('products.isactive', 1)
+ ->findAll();
return $this->response->setJSON($products);
}
@@ -473,11 +483,11 @@ class Products extends BaseController
$product_id = $this->request->getPost('product_id');
$isactive = $this->request->getPost('isactive');
- $ProductModel = new ProductModel();
+
$data = [
'isactive' => $isactive
];
- $updated = $ProductModel->update($product_id, $data);
+ $updated = $this->ProductModel->update($product_id, $data);
if ($updated) {
$result = $data;
@@ -574,16 +584,15 @@ class Products extends BaseController
public function get_product_addtional_details($product_id)
{
- $ProductModel = new ProductModel();
- $products = $ProductModel->where('product_id', $product_id)->get()->getRowArray();
+
+ $products = $this->ProductModel->where('product_id', $product_id)->get()->getRowArray();
$products['models_id'] = json_decode($products['models_id'], true);
- $BikemodelsModel = new BikemodelsModel();
$models = [];
if( $products['models_id'] != null) {
foreach ($products['models_id'] as $model_id) {
- $model = $BikemodelsModel->select('model_name')->where('model_id', $model_id)->get()->getRow();
+ $model = $this->BikemodelsModel->select('model_name')->where('model_id', $model_id)->get()->getRow();
array_push($models,$model);
}
}
diff --git a/app/Controllers/Purchase.php b/app/Controllers/Purchase.php
index a5c1b66..e462084 100755
--- a/app/Controllers/Purchase.php
+++ b/app/Controllers/Purchase.php
@@ -3,68 +3,70 @@
namespace App\Controllers;
use App\Models\PurchaseOrderModel;
- use App\Models\ProductModel;
- use App\Models\VendorModel;
- use App\Models\BranchModel;
- use App\Models\BusinessModel;
- use App\Models\PurchaseOrderChildModel;
- use Mpdf\Mpdf;
- use App\Helpers\MailHelper;
+use App\Models\ProductModel;
+use App\Models\VendorModel;
+use App\Models\BranchModel;
+use App\Models\BusinessModel;
+use App\Models\PurchaseOrderChildModel;
+use Mpdf\Mpdf;
+use App\Helpers\MailHelper;
class Purchase extends BaseController
{
public $session;
+ protected $PurchaseOrderModel;
+ protected $ProductModel;
+ protected $VendorModel;
+ protected $BranchModel;
+ protected $BusinessModel;
+ protected $PurchaseOrderChildModel;
public function __construct()
{
$this->session = session();
+ $this->PurchaseOrderModel = new PurchaseOrderModel();
+ $this->ProductModel = new ProductModel();
+ $this->VendorModel = new VendorModel();
+ $this->BranchModel = new BranchModel();
+ $this->BusinessModel = new BusinessModel();
+ $this->PurchaseOrderChildModel = new PurchaseOrderChildModel();
}
public function purchase_index()
{
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
- $PurchaseOrderModel = new PurchaseOrderModel();
+
- // $purchase = $PurchaseOrderModel->where('purchase_order.branch_id', $this->session->get('logged_user_business_id'))
- // ->select('purchase_order.*, vendor.vendor_name')
- // ->join('vendor', 'vendor.vendor_id = purchase_order.vendor_id')
- // ->findAll();
- $purchase = $PurchaseOrderModel->getPurchaseOrdersWithProducts($this->session->get('logged_user_branch_id'));
- // echo "";
- // print_r($product);die;
+ $data['purchase'] = $this->PurchaseOrderModel->getPurchaseOrdersWithProducts($this->session->get('logged_user_branch_id'));
+
- // echo json_encode($purchase);die;
- $data['purchase']=$purchase;
-
- // echo "";
- // print_r($data);die;
return view('purchase_list',$data);
}
public function new_purchase($purchase_order_id)
{
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
- $ProductModel = new ProductModel();
+
if ($purchase_order_id === '0') {
$data['purchase'] = [];
- $PurchaseOrderModel = new PurchaseOrderModel();
+
- $VendorModel = new VendorModel();
- $vendor = $VendorModel->where('branch_id',$this->session->get('logged_user_branch_id'))
+
+ $vendor = $this->VendorModel->where('branch_id',$this->session->get('logged_user_branch_id'))
->where('isactive', 1)
->select('vendor_id,vendor_name')
->findAll();
- $BranchModel = new BranchModel();
- $BusinessModel = new BusinessModel();
- $branch = $BranchModel->where('branch_id', $this->session->get('logged_user_branch_id'))->get()->getRowArray();
- $business = $BusinessModel->where('business_id', $this->session->get('logged_user_business_id'))->get()->getRowArray();
- $product=$ProductModel->where('isactive',1)
+
+
+ $branch = $this->BranchModel->where('branch_id', $this->session->get('logged_user_branch_id'))->get()->getRowArray();
+ $business = $this->BusinessModel->where('business_id', $this->session->get('logged_user_business_id'))->get()->getRowArray();
+ $product = $this->ProductModel->where('isactive',1)
->where('branch_id',$this->session->get('logged_user_branch_id'))
->findAll();
$data['product']=$product;
@@ -78,11 +80,11 @@ class Purchase extends BaseController
} else if ($purchase_order_id !== '0') {
$data['page_name']="Edit Purchase Order";
- $PurchaseOrderModel = new PurchaseOrderModel();
- $purchase=$PurchaseOrderModel->where('purchase_order_id', $purchase_order_id)->get()->getRowArray();
+
+ $purchase = $this->PurchaseOrderModel->where('purchase_order_id', $purchase_order_id)->get()->getRowArray();
- $VendorModel = new VendorModel();
- $vendor = $VendorModel->where('branch_id',$this->session->get('logged_user_business_id'))
+
+ $vendor = $this->VendorModel->where('branch_id',$this->session->get('logged_user_business_id'))
->where('isactive', 1)
->select('vendor_id,vendor_name')
->findAll();
@@ -92,17 +94,17 @@ class Purchase extends BaseController
- $VendorModel = new VendorModel();
- $vendor = $VendorModel->findAll();
+
+ $vendor = $this->VendorModel->findAll();
$data['vendor'] = $vendor;
-//
+
$data['vendor_id'] = $purchase['vendor_id'];
// print_r($vendor);die;
$vendorId=$purchase['vendor_id'];
$encodedVendorId = json_encode([$vendorId]);
// Query the database to find the product based on make_id and model_id
- $product = $ProductModel->select('products.*, manufacturer.manufacturer_name')
+ $product = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false)
->findAll();
@@ -112,12 +114,12 @@ class Purchase extends BaseController
- $PurchaseOrderChildModel = new PurchaseOrderChildModel();
- $purchase_product=$PurchaseOrderChildModel->where('purchase_order_id', $purchase_order_id)->findAll();
- $data['purchase_product']=$purchase_product;
+
+ $purchase_product = $this->PurchaseOrderChildModel->where('purchase_order_id', $purchase_order_id)->findAll();
+ $data['purchase_product'] = $purchase_product;
}
- $productAll= $ProductModel->select('products.*, manufacturer.manufacturer_name')
+ $productAll = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('products.isactive',1)
->findAll();
@@ -132,37 +134,37 @@ class Purchase extends BaseController
// $data['page_name']="Edit Purchase Order";
- // $PurchaseOrderModel = new PurchaseOrderModel();
- // $purchase=$PurchaseOrderModel->where('purchase_order_id', $purchase_order_id)->get()->getRowArray();
+
+ // $purchase = $this->PurchaseOrderModel->where('purchase_order_id', $purchase_order_id)->get()->getRowArray();
- // $VendorModel = new VendorModel();
- // $vendor = $VendorModel->where('branch_id',$this->session->get('logged_user_business_id'))->select('vendor_id,vendor_name')->findAll();
+
+ // $vendor = $this->VendorModel->where('branch_id',$this->session->get('logged_user_business_id'))->select('vendor_id,vendor_name')->findAll();
// $data['vendor']=$vendor;
// $data['purchase'] = $purchase;
- // $VendorModel = new VendorModel();
- // $vendor = $VendorModel->findAll();
+
+ // $vendor = $this->VendorModel->findAll();
// $data['vendor'] = $vendor;
// $data['vendor_id'] = $purchase['vendor_id'];
// // print_r($vendor);die;
// $vendorId=$purchase['vendor_id'];
// $encodedVendorId = json_encode([$vendorId]);
- // $productModel = new ProductModel();
+
// // Query the database to find the product based on make_id and model_id
- // $product = $productModel->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false)
+ // $product = $this->productModel->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false)
// ->findAll();
// $data['product']=$product;
// // print_r($product);die;
$data['purchase'] = [];
- $PurchaseOrderModel = new PurchaseOrderModel();
- $purchase=$PurchaseOrderModel->where('purchase_order_id', $purchase_order_id)->get()->getRowArray();
+
+ $purchase = $this->PurchaseOrderModel->where('purchase_order_id', $purchase_order_id)->get()->getRowArray();
- $VendorModel = new VendorModel();
- $vendor = $VendorModel->where('branch_id',$this->session->get('logged_user_business_id'))->select('vendor_id,vendor_name')->findAll();
+
+ $vendor = $this->VendorModel->where('branch_id',$this->session->get('logged_user_business_id'))->select('vendor_id,vendor_name')->findAll();
$data['vendor']=$vendor;
unset($purchase['purchase_order_id']);
@@ -170,21 +172,22 @@ class Purchase extends BaseController
- $VendorModel = new VendorModel();
- $vendor = $VendorModel->findAll();
+
+ $vendor = $this->VendorModel->findAll();
$data['vendor'] = $vendor;
// $data['vendor_id'] = $purchase['vendor_id'];
- $BranchModel = new BranchModel();
- $BusinessModel = new BusinessModel();
- $branch = $BranchModel->where('branch_id', $this->session->get('logged_user_branch_id'))->get()->getRowArray();
- $business = $BusinessModel->where('business_id', $this->session->get('logged_user_business_id'))->get()->getRowArray();
- $ProductModel = new ProductModel();
- $product=$ProductModel
- ->where('isactive',1)
- ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+
+
+ $branch = $this->BranchModel->where('branch_id', $this->session->get('logged_user_branch_id'))->get()->getRowArray();
+ $business = $this->BusinessModel->where('business_id', $this->session->get('logged_user_business_id'))->get()->getRowArray();
+
+ $product = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
+ ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
+ ->where('products.isactive',1)
+ ->where('products.branch_id',$this->session->get('logged_user_branch_id'))->findAll();
$data['product']=$product;
$data['branch'] = $branch;
$data['business'] = $business;
@@ -193,9 +196,9 @@ class Purchase extends BaseController
$data['vendor']=$vendor;
$data['vendor_id'] = [];
- $PurchaseOrderChildModel = new PurchaseOrderChildModel();
+
- $purchase_product = $PurchaseOrderChildModel
+ $purchase_product = $this->PurchaseOrderChildModel
->select('product_id, qty, received_qty, isactive, is_selected')
->where('purchase_order_id', $purchase_order_id)
->where('(is_selected = 0 OR (qty > received_qty AND received_qty != 0) )')
@@ -205,16 +208,16 @@ class Purchase extends BaseController
- // echo json_encode($purchase_product);die;
+ $data['purchase_order_id']= $purchase_order_id;
echo view('purchase_form',$data);
}
public function add_purchase()
{
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
- $PurchaseOrderModel = new PurchaseOrderModel();
- $ProductModel = new ProductModel();
- $PurchaseOrderChildModel = new PurchaseOrderChildModel();
+
+
+
$data = [
'vendor_id' => $this->request->getPost('vendor_id'),
'order_date' => $this->request->getPost('order_date'),
@@ -239,18 +242,18 @@ class Purchase extends BaseController
// echo $purchase_order_id;die;
if (!empty($purchase_order_id)) {
- $PurchaseOrderModel->update($purchase_order_id, $data);
+ $this->PurchaseOrderModel->update($purchase_order_id, $data);
} else {
- $PurchaseOrderModel->insert($data);
- $purchase_order_id = $PurchaseOrderModel->getInsertID();
+
+ $purchase_order_id = $this->PurchaseOrderModel->getInsertID();
}
$orderNumber = 'PO-' . date('md') . '-' . str_pad($purchase_order_id, 5, '0', STR_PAD_LEFT);
- // print_r($orderNumber);die;
+
// Update sales order with generated order number
- $PurchaseOrderModel->update($purchase_order_id, ['order_number' => $orderNumber]);
- // print_r();die;
+ $this->PurchaseOrderModel->update($purchase_order_id, ['order_number' => $orderNumber]);
+
// Prepare data for sales order product
$product_ids = $this->request->getPost('item_details');
$quantities = $this->request->getPost('quantity');
@@ -268,7 +271,7 @@ class Purchase extends BaseController
$selected_item = (isset($selected_items[$key]) && $selected_items[$key] == 'checked') ? 1 : 0;
// print_r($selected_item);die;
if ($status == 'Received' && $selected_item == 1) {
- $this->addBackProductQuantity($ProductModel, $product_id, $qty);
+ $this->addBackProductQuantity( $product_id, $qty);
}
$discount = isset($discounts[$key]) ? $discounts[$key] : 0;
@@ -300,20 +303,20 @@ class Purchase extends BaseController
$child_data['qty'] = $qty;
}
- // print_r($child_data);die;
+
if (!empty($purchase_order_child_id[$key])) {
- // print_r($purchase_order_child_id[$key]);die;
- $PurchaseOrderChildModel->update($purchase_order_child_id[$key], $child_data);
+
+ $this->PurchaseOrderChildModel->update($purchase_order_child_id[$key], $child_data);
} else {
- $PurchaseOrderChildModel->insert($child_data);
+ $this->PurchaseOrderChildModel->insert($child_data);
// send purhase data through mail
- $VendorModel = new VendorModel();
- $vendor = $VendorModel->where('vendor_id',$this->request->getPost('vendor_id'))->findAll();
+
+ $vendor = $this->VendorModel->where('vendor_id',$this->request->getPost('vendor_id'))->findAll();
$mail_status = $this->download_purchase_invoice($purchase_order_id, $vendor[0]['vendor_email']);
// echo $mail_status;die;
@@ -326,10 +329,10 @@ class Purchase extends BaseController
}
- private function addBackProductQuantity($ProductModel, $product_id, $sold_qty)
+ private function addBackProductQuantity($product_id, $sold_qty)
{
// Fetch current product quantity
- $product = $ProductModel->find($product_id);
+ $product = $this->ProductModel->find($product_id);
$data['qty_stock'] = $product['qty_stock'] + $sold_qty;
@@ -343,20 +346,20 @@ class Purchase extends BaseController
}
// Update quantity in Product table
- $ProductModel->update($product_id, $data );
+ $this->ProductModel->update($product_id, $data );
}
public function delete_purchase($purchase_order_id)
{
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
- $PurchaseOrderModel = new PurchaseOrderModel();
+
$where = ['purchase_order_id' => $purchase_order_id, 'isactive' => 1 ]; // Assuming 'isactive' is a column in your database
- $existingPurchase = $PurchaseOrderModel->where($where)->first();
+ $existingPurchase = $this->PurchaseOrderModel->where($where)->first();
if ($existingPurchase) {
$data['isactive'] = 0;
- if ($PurchaseOrderModel->update($purchase_order_id, $data)) {
+ if ($this->PurchaseOrderModel->update($purchase_order_id, $data)) {
session()->setFlashdata('success', 'Deleted successfully.');
$this->logger->info("Purchase Order: has been Inactivated successfully. Inactivated ID = ".$purchase_order_id);
}
@@ -372,9 +375,9 @@ class Purchase extends BaseController
public function get_vendor($vendor_id)
{
- $VendorModel = new VendorModel();
+
- $products =$VendorModel->where('vendor_id',$vendor_id)->select('vendor_name,contact_person_name1,contact_person_mobile1')->get()->getRowArray();
+ $products =$this->VendorModel->where('vendor_id',$vendor_id)->select('vendor_name,contact_person_name1,contact_person_mobile1')->get()->getRowArray();
return json_encode($products);
@@ -387,18 +390,17 @@ public function getVendorProducts()
// $makeId = $this->request->getPost('');
$vendorId = $this->request->getPost('vendor_id');
- $VendorModel = new VendorModel();
- $VendorData = $VendorModel->where('vendor_id',$vendorId)->first();
+
+ $VendorData = $this->VendorModel->where('vendor_id',$vendorId)->first();
// Encode the modelId before searching
$encodedVendorId = json_encode([$vendorId]);
- // Load the ProductModel
- $productModel = new ProductModel();
+
// Query the database to find the product based on make_id and model_id
- $product = $productModel->select('products.*, manufacturer.manufacturer_name')
+ $product = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('JSON_CONTAINS(vendor, \'' . $encodedVendorId . '\')', null, false)
->where('products.isactive',1)
@@ -418,10 +420,10 @@ public function delete_purchase_product()
$purchase_order_child_id = $this->request->getPost('purchase_order_child_id');
if (!empty($purchase_order_child_id)) {
- $PurchaseOrderChildModel = new PurchaseOrderChildModel();
+
$data['isactive'] = 0;
- if ($PurchaseOrderChildModel->update($purchase_order_child_id, $data)) {
+ if ($this->PurchaseOrderChildModel->update($purchase_order_child_id, $data)) {
// Return success response
return $this->response->setJSON(['success' => true]);
}
@@ -433,10 +435,9 @@ public function delete_purchase_product()
public function download_purchase_invoice($purchase_order_id, $mail = null)
{
// Fetch the invoice data based on $invoice_id
- $model = new PurchaseOrderModel();
- $data = $model->getPurchasePdf($purchase_order_id);
+ $data = $this->PurchaseOrderModel->getPurchasePdf($purchase_order_id);
- $items = $model->getPurchaseOrderProductsForPdf($purchase_order_id);
+ $items = $this->PurchaseOrderModel->getPurchaseOrderProductsForPdf($purchase_order_id);
// Create an mPDF object
$mpdf = new Mpdf([
'mode' => '',
diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php
index 1cce0dd..31ea2c3 100755
--- a/app/Controllers/Sales.php
+++ b/app/Controllers/Sales.php
@@ -17,6 +17,7 @@ use App\Models\AdditionalProductNameModal;
use Mpdf\Mpdf;
use CodeIgniter\API\ResponseTrait;
use App\Helpers\InvNoHelper;
+use App\Helpers\ClientDetailsUpdate;
class Sales extends BaseController
{
@@ -25,6 +26,13 @@ class Sales extends BaseController
protected $BikemodelsModel;
protected $BikemakeModel;
protected $additionalProductNameModal;
+ protected $SalesOrderModel;
+ protected $SalesOrderProductModel;
+ protected $ProductModel;
+ protected $ClientModel;
+ protected $VehicleModel;
+ protected $BranchModel;
+
public function __construct()
{
@@ -32,17 +40,20 @@ class Sales extends BaseController
$this->BikemodelsModel = new BikemodelsModel();
$this->BikemakeModel = new BikemakeModel();
$this->additionalProductNameModal = new AdditionalProductNameModal();
+ $this->SalesOrderModel = new SalesOrderModel();
+ $this->SalesOrderProductModel = new SalesOrderProductModel();
+ $this->ProductModel = new ProductModel();
+ $this->ClientModel = new ClientModel();
+ $this->VehicleModel = new VehicleModel();
+ $this->BranchModel = new BranchModel();
}
public function sales_order_index()
{
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
- $SalesOrderModel = new SalesOrderModel();
- $sales=$SalesOrderModel->getSalesOrdersWithProducts($this->session->get('logged_user_branch_id'));
- $data['sales']=$sales;
-
- // echo"";
- // print_r($sales);die;
+
+ $data['sales'] = $this->SalesOrderModel->getSalesOrdersWithProducts($this->session->get('logged_user_branch_id'));
+
return view('sales_list',$data);
}
@@ -54,67 +65,59 @@ class Sales extends BaseController
if ($sales_order_id === '0') {
$data['page_name']="Create Sales Order";
$data['sales'] = [];
- $ClientModel = new ClientModel();
- $client = $ClientModel->where('isactive',1)
- ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
- $VehicleModel = new VehicleModel();
- $vehicle = $VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id'));
+
+ $data['client'] = $this->ClientModel->where('isactive',1)
+ ->where('branch_id',$this->session->get('logged_user_branch_id'))
+ ->findAll();
+
+ $data['vehicle'] = $this->VehicleModel->getCustomerandVehicle($this->session->get('logged_user_branch_id'));
- $ProductModel = new ProductModel();
- $product=$ProductModel->select('products.*, manufacturer.manufacturer_name')
+
+ $data['product'] = $this->ProductModel->select('products.*, manufacturer.manufacturer_name')
->join('manufacturer', 'products.manufacturer_id = manufacturer.manufacturer_id')
->where('products.isactive', 1)
->where('products.branch_id', $this->session->get('logged_user_branch_id'))
->where('products.isactive', 1)
->findAll();
- $data['product']=$product;
- $data['client']=$client;
- $data['vehicle']=$vehicle;
-
} else if ($sales_order_id !== '0') {
- $data['page_name']="Edit Sale Order";
- $ClientModel = new ClientModel();
- $client=$ClientModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
- $SalesOrderModel = new SalesOrderModel();
- $sales=$SalesOrderModel->where('sales_order_id', $sales_order_id)->get()->getRowArray();
- $data['sales']=$sales;
+ $data['page_name'] = "Edit Sale Order";
+
+ $data['client'] = $this->ClientModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+
+ $data['sales'] = $this->SalesOrderModel->where('sales_order_id', $sales_order_id)->get()->getRowArray();
+
- $VehicleModel = new VehicleModel();
- $vehicles = $VehicleModel->where('isactive',1)->where('vehicle_id',$sales['vehicle_id'])
+
+ $vehicles = $this->VehicleModel->where('isactive',1)->where('vehicle_id',$data['sales']['vehicle_id'])
->where('branch_id',$this->session->get('logged_user_branch_id'))
->first();
$makeId = $vehicles['make'];
- $modelId = $vehicles['model'];
+ $modelId = $vehicles['model'];
// Encode the modelId before searching
$encodedMakeId = json_encode([$makeId]);
$encodedModelId = json_encode([$modelId]);
- // print_r("aadhavan");
- // print_r($encodedMakeId);die;
- // Load the ProductModel
- $productModel = new ProductModel();
+ // Query the database to find the product based on make_id and model_id
+ $makeproduct = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name')
+ ->join('products', 'products.product_id = product_names.product_id')
+ ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
+ ->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
+ ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
+ ->where('qty_stock >',0)
+ ->where('products.isactive', 1)
+ ->findAll();
- // Query the database to find the product based on make_id and model_id
- $makeproduct = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name')
- ->join('products', 'products.product_id = product_names.product_id')
- ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
- ->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
- ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
- ->where('qty_stock >',0)
- ->where('products.isactive', 1)
- ->findAll();
+ $encodedMakeId = json_encode(['0']);
+ $encodedModelId = json_encode(['0']);
- $encodedMakeId = json_encode(['0']);
- $encodedModelId = json_encode(['0']);
-
- $common_product = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name')
+ $common_product = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name')
->join('products', 'products.product_id = product_names.product_id')
->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('JSON_CONTAINS(make_id, \'' . $encodedMakeId . '\')', null, false)
@@ -123,40 +126,33 @@ class Sales extends BaseController
->where('products.isactive', 1)
->findAll();
- $product = array_merge($common_product, $makeproduct);
+ $product = array_merge($common_product, $makeproduct);
- $data['product']=$product;
+ $data['product']=$product;
- $SalesProductOrderModel = new SalesOrderProductModel();
- $sales_product=$SalesProductOrderModel->where('sales_order_id', $sales_order_id)->findAll();
- $data['sales_product']=$sales_product;
- $data['client']=$client;
+
+ $sales_product = $this->SalesOrderProductModel->where('sales_order_id', $sales_order_id)->findAll();
+ $data['sales_product']=$sales_product;
+
- $VehicleModel = new VehicleModel();
- $vehicle=$VehicleModel
- ->where('isactive',1)
- ->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
- $data['vehicle']=$vehicle;
+
+ $data['vehicle'] = $this->VehicleModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+
}
$data['sales_order_id'] = $sales_order_id;
- $bikeMakeModel = new BikeMakeModel();
- $data['makeData'] =$bikeMakeModel->findAll();
+
+ $data['makeData'] = $this->BikemakeModel->findAll();
return view('sales_order_form',$data);
}
public function add_sales()
{
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
- $SalesOrderModel = new SalesOrderModel();
- $ProductModel = new ProductModel();
- $SalesOrderProductModel = new SalesOrderProductModel();
-
-
-
+
// Prepare data for sales order
$status = $this->request->getPost('status') != '' ? $this->request->getPost('status') : 'Draft';
$data = [
@@ -176,7 +172,13 @@ class Sales extends BaseController
'branch_id'=> $this->session->get('logged_user_branch_id'),
];
+ $update_client_address = $this->request->getPost('update_client_address');
+ if(isset($update_client_address) && $update_client_address == 'on')
+ {
+ ClientDetailsUpdate::updateClientAddress($this->request->getPost('vehicle_id'),$data);
+ }
+
// Insert or update sales order
$sales_order_id = $this->request->getPost('sales_order_id');
@@ -186,18 +188,18 @@ class Sales extends BaseController
if ($status === "Approved") {
$data['mode_of_payment'] = $this->request->getPost('mode_of_payment');
}
- $SalesOrderModel->update($sales_order_id, $data);
+ $this->SalesOrderModel->update($sales_order_id, $data);
} else {
//create sales-order
$data['inv_no'] = InvNoHelper::generateInvoiceNumber();
- $SalesOrderModel->insert($data);
- $sales_order_id = $SalesOrderModel->getInsertID();
+ $this->SalesOrderModel->insert($data);
+ $sales_order_id = $this->SalesOrderModel->getInsertID();
// Update sales order with generated order number
$orderNumber = 'SO-' . date('md') . '-' . str_pad($sales_order_id, 5, '0', STR_PAD_LEFT);
- $SalesOrderModel->update($sales_order_id, ['order_number' => $orderNumber]);
+ $this->SalesOrderModel->update($sales_order_id, ['order_number' => $orderNumber]);
}
@@ -221,16 +223,16 @@ class Sales extends BaseController
$qty = isset($quantities[$key]) ? $quantities[$key] : 0;
if ($status == 'Approved') {
- $this->subractProductQuantity($ProductModel, $product_id, $qty);
+ $this->subractProductQuantity( $product_id, $qty);
}elseif ($status == 'Cancelled'){
- // $this->addBackProductQuantity($ProductModel, $product_id, $qty);
+ // $this->addBackProductQuantity( $product_id, $qty);
}
$discount = isset($discounts[$key]) ? $discounts[$key] : 0;
$discount_type = isset($discount_types[$key]) ? $discount_types[$key] : '';
$tax=isset($itemtax[$key]) ? $itemtax[$key] : 0;
$rate=isset($unitprice[$key]) ? $unitprice[$key] : 0;
$amount = isset($amounts[$key]) ? $amounts[$key] : 0;
- // $new_qty = $this->calculateUpdatedQuantity($ProductModel, $product_id, $qty);
+ // $new_qty = $this->calculateUpdatedQuantity( $product_id, $qty);
// print_r($discount_type);die;
$product_data = [
'sales_order_id' => $sales_order_id,
@@ -247,10 +249,10 @@ class Sales extends BaseController
// print_r($product_data);die;
if (!empty($sales_product_id[$key])) {
- $SalesOrderProductModel->update($sales_product_id[$key], $product_data);
+ $this->SalesOrderProductModel->update($sales_product_id[$key], $product_data);
} else {
- $SalesOrderProductModel->insert($product_data);
+ $this->SalesOrderProductModel->insert($product_data);
}
@@ -261,10 +263,10 @@ class Sales extends BaseController
return redirect()->to('sales_order_index');
}
- private function addBackProductQuantity($ProductModel, $product_id, $sold_qty)
+ private function addBackProductQuantity($product_id, $sold_qty)
{
// Fetch current product quantity
- $product = $ProductModel->find($product_id);
+ $product = $this->ProductModel->find($product_id);
$data['qty_stock'] = $product['qty_stock'] + $sold_qty;
@@ -278,14 +280,14 @@ class Sales extends BaseController
}
// Update quantity in Product table
- $ProductModel->update($product_id, $data );
+ $this->ProductModel->update($product_id, $data );
}
- private function subractProductQuantity($ProductModel, $product_id, $sold_qty)
+ private function subractProductQuantity( $product_id, $sold_qty)
{
// Fetch current product quantity
- $product = $ProductModel->find($product_id);
+ $product = $this->ProductModel->find($product_id);
$data['qty_stock'] = $product['qty_stock'] - $sold_qty;
@@ -299,7 +301,7 @@ class Sales extends BaseController
}
// Update quantity in Product table
- $ProductModel->update($product_id, $data );
+ $this->ProductModel->update($product_id, $data );
}
public function delete_sales_product()
@@ -308,10 +310,9 @@ class Sales extends BaseController
$sales_order_product_id = $this->request->getPost('sales_order_product_id');
if (!empty($sales_order_product_id)) {
- $SalesOrderProductModel = new SalesOrderProductModel();
$data['isactive'] = 0;
- if ($SalesOrderProductModel->update($sales_order_product_id, $data)) {
+ if ($this->SalesOrderProductModel->update($sales_order_product_id, $data)) {
// Return success response
return $this->response->setJSON(['success' => true]);
}
@@ -325,14 +326,14 @@ class Sales extends BaseController
public function delete_sale($sales_order_id)
{
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
- $model = new SalesOrderModel();
+
$where = ['sales_order_id' => $sales_order_id, 'isactive' => 1]; // Assuming 'isactive' is a column in your database
- $existingProduct = $model->where($where)->first();
+ $existingProduct = $this->SalesOrderModel->where($where)->first();
if ($existingProduct) {
$data['isactive'] = 0;
- if ($model->update($sales_order_id, $data)) {
+ if ($this->SalesOrderModel->update($sales_order_id, $data)) {
session()->setFlashdata('success', 'Deleted successfully.');
$this->logger->info("Users: has been Inactivated successfully. Inactivated ID = ".$sales_order_id);
}
@@ -347,21 +348,19 @@ class Sales extends BaseController
{
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
// Fetch the invoice data based on $invoice_id
- $model = new SalesOrderModel();
- $saleOrderCount = count($model->where('status','Approved')->findAll());
- $VehicleModel = new VehicleModel();
- $BranchModel = new BranchModel();
- $BusinessModel = new BusinessModel();
- $BikemodelsModel = new BikemodelsModel();
- $BikemakeModel = new BikemakeModel();
- $data['sales'] = $model->getSalesPdf($sales_order_id);
- $data['branch'] = $BranchModel->where('branch_id', $data['sales'][0]->branch_id)->first();
- $data['vehicle'] = $VehicleModel->select('vehicle.reg_no,vehicle.colour,vehicle.email,vehicle.mobile_no,vehicle.year_of_manufacturing, make.make as make_name, model.model_name')
+
+ $saleOrderCount = count($this->SalesOrderModel->where('status','Approved')->findAll());
+
+
+
+ $data['sales'] = $this->SalesOrderModel->getSalesPdf($sales_order_id);
+ $data['branch'] = $this->BranchModel->where('branch_id', $data['sales'][0]->branch_id)->first();
+ $data['vehicle'] = $this->VehicleModel->select('vehicle.reg_no,vehicle.colour,vehicle.email,vehicle.mobile_no,vehicle.year_of_manufacturing, make.make as make_name, model.model_name')
->join('model', 'model.model_id = vehicle.model', 'left')
->join('make', 'make.make_id = vehicle.make', 'left')
->where('vehicle.vehicle_id', $data['sales'][0]->vehicle_id)
->first();
- $data['items'] = $model->getSalesOrderProductsForPdf($sales_order_id);
+ $data['items'] = $this->SalesOrderModel->getSalesOrderProductsForPdf($sales_order_id);
$mpdf = new Mpdf([
'mode' => '',
@@ -406,21 +405,19 @@ class Sales extends BaseController
// Fetch the invoice data based on $invoice_id
- $model = new SalesOrderModel();
- $saleOrderCount = count($model->where('status','Approved')->findAll());
- $VehicleModel = new VehicleModel();
- $BranchModel = new BranchModel();
- $BusinessModel = new BusinessModel();
- $BikemodelsModel = new BikemodelsModel();
- $BikemakeModel = new BikemakeModel();
- $data['sales'] = $model->getSalesPdf($sales_order_id);
- $data['branch'] = $BranchModel->where('branch_id', $data['sales'][0]->branch_id)->first();
- $data['vehicle'] = $VehicleModel->select('vehicle.reg_no,vehicle.colour,vehicle.email,vehicle.mobile_no,vehicle.year_of_manufacturing, make.make as make_name, model.model_name')
+
+ $saleOrderCount = count($this->SalesOrderModel->where('status','Approved')->findAll());
+
+
+
+ $data['sales'] = $this->SalesOrderModel->getSalesPdf($sales_order_id);
+ $data['branch'] = $this->BranchModel->where('branch_id', $data['sales'][0]->branch_id)->first();
+ $data['vehicle'] = $this->VehicleModel->select('vehicle.reg_no,vehicle.colour,vehicle.email,vehicle.mobile_no,vehicle.year_of_manufacturing, make.make as make_name, model.model_name')
->join('model', 'model.model_id = vehicle.model', 'left')
->join('make', 'make.make_id = vehicle.make', 'left')
->where('vehicle.vehicle_id', $data['sales'][0]->vehicle_id)
->first();
- $data['items'] = $model->getSalesOrderProductsForPdf($sales_order_id);
+ $data['items'] = $this->SalesOrderModel->getSalesOrderProductsForPdf($sales_order_id);
$html = view('invoice_pdf_template', $data);
@@ -430,19 +427,19 @@ class Sales extends BaseController
public function save_vehicle(){
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
- // Load ClientModel
- $VehicleModel = new VehicleModel();
+
+
if($this->request->getPost('formType') == 'create')
{
- $ClientModel = new ClientModel();
+
$client['client_name'] = $this->request->getPost('createclientName');
$client['mobile_no'] = $this->request->getPost('createclientMobile');
$client['client_type'] = $this->request->getPost('createclientType');
$client['branch_id'] = $this->session->get('logged_user_branch_id');
- $client_id = $ClientModel->insert($client);
+ $client_id = $this->ClientModel->insert($client);
if($client_id){
@@ -482,9 +479,9 @@ class Sales extends BaseController
// Attempt to insert the client data
- $id = $VehicleModel->insert($data);
+ $id = $this->VehicleModel->insert($data);
if ($id) {
- $vehicleData = $VehicleModel->where('vehicle_id',$id)->first();
+ $vehicleData = $this->VehicleModel->where('vehicle_id',$id)->first();
// If insertion succeeds, return success response
return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','vehicleData'=>$vehicleData, 'vehicle_id' => $id]);
@@ -512,14 +509,6 @@ class Sales extends BaseController
$encodedMakeId = json_encode([$makeId]);
$encodedModelId = json_encode([$modelId]);
- // Load the ProductModel
- $productModel = new ProductModel();
- $bikemodelsModel = new BikemodelsModel();
- $BikemakeModel = new BikemakeModel();
-
- $makeGeneral = $BikemakeModel->where('make' , 'General')->first();
- $modelGeneral = $bikemodelsModel->where('model_name' , 'General')->first();
-
// Query the database to find the product based on make_id and model_id
$makeproduct = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name')
diff --git a/app/Controllers/Service.php b/app/Controllers/Service.php
index 7b92fe8..12b74a8 100755
--- a/app/Controllers/Service.php
+++ b/app/Controllers/Service.php
@@ -7,27 +7,38 @@ use App\Models\BikemakeModel;
use App\Models\VendorModel;
use App\Models\BikemodelsModel;
use App\Models\ProductModel;
-
+use App\Models\AdditionalProductNameModal;
use CodeIgniter\API\ResponseTrait;
class Service extends BaseController
{
public $session;
-
+ protected $additionalProductNameModal;
+ protected $ServiceModel;
+ protected $BikemakeModel;
+ protected $vendorModel;
+ protected $BikemodelsModel;
+ protected $ProductModel;
use ResponseTrait;
public function __construct()
{
$this->session = session();
+ $this->additionalProductNameModal = new AdditionalProductNameModal();
+ $this->ServiceModel = new ServiceModel();
+ $this->BikemakeModel = new BikemakeModel();
+ $this->vendorModel = new VendorModel();
+ $this->BikemodelsModel = new BikemodelsModel();
+ $this->ProductModel = new ProductModel();
}
public function service_index()
{
- $ServiceModel = new ServiceModel();
- $services = $ServiceModel->where('branch_id',$this->session->get('logged_user_branch_id'))->orderBy('service_name','ASC')->findAll();
+
+ $services = $this->ServiceModel->where('branch_id',$this->session->get('logged_user_branch_id'))->orderBy('service_name','ASC')->findAll();
foreach ($services as &$service) {
// Convert JSON strings to arrays
@@ -36,11 +47,10 @@ class Service extends BaseController
// Fetch make names
$makeNames = [];
- $BikemakeModel = new BikemakeModel();
foreach ($makes_ids as $make_id) {
if (!empty($make_id)) { // Check if $make_id is not null or empty
- $make = $BikemakeModel->find($make_id);
+ $make = $this->BikemakeModel->find($make_id);
if ($make) {
$makeNames[] = $make['make'];
}
@@ -49,11 +59,10 @@ class Service extends BaseController
// Fetch model names
$modelNames = [];
- $BikemodelsModel = new BikemodelsModel();
foreach ($models_ids as $model_id) {
if (!empty($model_id)) { // Check if $model_id is not null or empty
- $model = $BikemodelsModel->find($model_id);
+ $model = $this->BikemodelsModel->find($model_id);
if ($model) {
$modelNames[] = $model['model_name'];
}
@@ -73,82 +82,53 @@ class Service extends BaseController
public function new_service($service_id)
{
- $ProductModel = new ProductModel();
+ $data['product'] = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name')
+ ->join('products', 'products.product_id = product_names.product_id')
+ ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
+ ->where('products.isactive', 1)
+ ->findAll();
+
+ $data['tax'] = $this->ServiceModel->getTax();
+
if ($service_id === '0') {
-
+
+ $data['page_name'] = "Add Service";
$data['services'] = [];
- $ServiceModel = new ServiceModel();
- $tax=$ServiceModel->getTax();
- $data['tax']=$tax;
- $BikemakeModel = new BikemakeModel();
- $data['make'] = $BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->findAll();
+ $data['make'] = $this->BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->findAll();
$data['models'] = [];
- $service=$ServiceModel->where('isactive',1)->where('category','0')->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
- // echo $this->session->get('logged_user_branch_id');die;
- $data['service']=$service;
- $product=$ProductModel->select('products.*, manufacturer.manufacturer_name')
- ->join('manufacturer', 'products.manufacturer_id = manufacturer.manufacturer_id')
- ->where('products.isactive',1)
- ->where('products.branch_id',$this->session->get('logged_user_branch_id'))
- ->findAll(); // echo json_encode($service);die;
- $data['product']=$product;
- $data['page_name']="Add Service";
+ $data['service'] = $this->ServiceModel->where('isactive',1)->where('category','0')->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+
} else if ($service_id !== '0') {
- $ServiceModel = new ServiceModel();
- $services=$ServiceModel->where('service_id', $service_id)->get()->getRowArray();
-
+ $data['page_name'] = "Edit Service";
+ $services = $this->ServiceModel->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);
- $data['page_name']="Edit Service";
-
- $product=$ProductModel->select('products.*, manufacturer.manufacturer_name')
- ->join('manufacturer', 'products.manufacturer_id = manufacturer.manufacturer_id')
- ->where('products.isactive',1)
- ->where('products.branch_id',$this->session->get('logged_user_branch_id'))
- ->findAll();
- $data['product']=$product;
-
+
$models = [];
- $BikemodelsModel = new BikemodelsModel();
-
if( $services['makes_id'] != null) {
foreach ($services['makes_id'] as $make_id) {
- $models[] = $BikemodelsModel->where('make_id', $make_id)->findAll();
+ $models[] = $this->BikemodelsModel->where('make_id', $make_id)->findAll();
}
}
-
$data['models'] = $models;
-
- // Load make data
- $BikemakeModel = new BikemakeModel();
- $data['make'] = $BikemakeModel->where('business_id', $this->session->get('logged_user_business_id'))->findAll();
-
- $tax=$ServiceModel->getTax();
- $data['tax']=$tax;
-
- $data['services']=$services;
-
- $service=$ServiceModel->where('isactive',1)->where('category','0')->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
- // echo $this->session->get('logged_user_branch_id');die;
- // echo json_encode($service);die;
- $data['service']=$service;
+ $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_id'] = $service_id;
- // echo"";
- // print_r($data);die;
+
echo view('service_form',$data);
+
}
public function add_service()
{
- $ServiceModel = new ServiceModel();
- // echo json_encode($this->request->getPost());die;
$tax= $this->request->getPost('tax')/2;
@@ -178,12 +158,12 @@ class Service extends BaseController
$service_id = $this->request->getPost('service_id');
- if (!empty($service_id)) {
-
- $ServiceModel->update($service_id, $data);
+ if (!empty($service_id))
+ {
+ $this->ServiceModel->update($service_id, $data);
} else {
$data['branch_id'] = $this->session->get('logged_user_branch_id');
- $ServiceModel->insert($data);
+ $this->ServiceModel->insert($data);
}
@@ -192,14 +172,14 @@ class Service extends BaseController
public function delete_service($service_id)
{
- $ServiceModel = new ServiceModel();
+
$where = ['service_id' => $service_id, 'isactive' => 1]; // Assuming 'isactive' is a column in your database
- $existingService = $ServiceModel->where($where)->first();
+ $existingService = $this->ServiceModel->where($where)->first();
if ($existingService) {
$data['isactive'] = 0;
- if ($ServiceModel->update($service_id, $data)) {
+ if ($this->ServiceModel->update($service_id, $data)) {
session()->setFlashdata('success', 'Deleted successfully.');
$this->logger->info("Users: has been Inactivated successfully. Inactivated ID = ".$service_id);
}
@@ -209,28 +189,20 @@ class Service extends BaseController
return redirect()->to('service_index');
}
- // Retrieve the make_id from the AJAX request
+
public function get_vendors_by_model()
{
$make_id = $this->request->getPost('make_id');
$model_ids = $this->request->getPost('model_ids');
- // print_r( $model_ids);die;
-
- // If make_id or model_ids is not provided, return an empty response
- // Create an instance of VendorModel
- $vendorModel = new VendorModel();
-
- // Call the get_vendors_by_model method from the model
- $vendors = $vendorModel->get_vendors_by_model($make_id, $model_ids);
- // Return the response as JSON
- // return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.']);
+ $vendors = $this->vendorModel->get_vendors_by_model($make_id, $model_ids);
+
if ($vendors) {
- // Return the retrieved vendors as JSON response
+
return $this->response->setJSON($vendors);
} else {
- // If no vendors were found, return an empty response or handle the error accordingly
+
return $this->response->setJSON([]);
}
}
@@ -240,17 +212,16 @@ class Service extends BaseController
$make_id = $this->request->getPost('make_id');
$model_ids = $this->request->getPost('model_ids');
- $ProductModel = new ProductModel();
+
$products = [];
array_push($model_ids,'0');
- foreach ($model_ids as $modelId) {
- // Assuming $ProductModel is your Product model class
- // and you have a Manufacturer model class for the manufacturers table
- $product = $ProductModel->select('products.*, manufacturer.manufacturer_name AS manufacturer_name')
- ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
- ->where('products.isactive', 1)
+ foreach ($model_ids as $modelId) {
+ $product = $this->additionalProductNameModal->select('products.*, manufacturer.manufacturer_name, product_names.product_names_id, product_names.additional_product_name')
+ ->join('products', 'products.product_id = product_names.product_id')
+ ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id')
->where('JSON_CONTAINS(products.models_id, \'["' . $modelId . '"]\')', null, false)
+ ->where('products.isactive', 1)
->findAll();
$products = array_merge($products, $product);
@@ -267,9 +238,6 @@ class Service extends BaseController
{
$selected_makes = $this->request->getPost('selected_makes');
- // Load the BikemakeModel to fetch models
- $BikemodelModel = new BikemodelsModel();
-
// Initialize an empty array to store formatted model data
$formatted_models = [];
@@ -277,7 +245,7 @@ class Service extends BaseController
if ($selected_makes) {
foreach ($selected_makes as $make_id) {
// Fetch models based on the selected make ID
- $models = $BikemodelModel->where('make_id', $make_id)->where('business_id', $this->session->get('logged_user_business_id'))->findAll();
+ $models = $this->BikemodelsModel->where('make_id', $make_id)->where('business_id', $this->session->get('logged_user_business_id'))->findAll();
// Iterate over each fetched model and format it as needed
foreach ($models as $model) {
@@ -307,11 +275,11 @@ class Service extends BaseController
$service_id = $this->request->getPost('service_id');
$isactive = $this->request->getPost('isactive');
- $ServiceModel = new ServiceModel();
+
$data = [
'isactive' => $isactive
];
- $updated = $ServiceModel->update($service_id, $data);
+ $updated = $this->ServiceModel->update($service_id, $data);
if ($updated) {
$result = $data;
diff --git a/app/Helpers/ClientDetailsUpdate.php b/app/Helpers/ClientDetailsUpdate.php
new file mode 100644
index 0000000..63f4186
--- /dev/null
+++ b/app/Helpers/ClientDetailsUpdate.php
@@ -0,0 +1,44 @@
+where('vehicle_id', $vehicle_id)->get()->getRow()->client_id;
+
+ $data = [
+
+ 'address' => $address['billing_address'],
+ 'city' => $address['billing_city'],
+ 'state' => $address['billing_state'],
+ 'postal_code' => $address['billing_postal_code']
+
+ ];
+
+ $update = $ClientModel->update($client_id, $data);
+
+ if($update){
+ return true;
+ }
+
+
+ }
+
+
+
+
+
+}
+?>
\ No newline at end of file
diff --git a/app/Views/job_card_form.php b/app/Views/job_card_form.php
index 522d3cb..14f5d7f 100755
--- a/app/Views/job_card_form.php
+++ b/app/Views/job_card_form.php
@@ -158,6 +158,9 @@
+
+
+
@@ -438,35 +441,35 @@ $(document).ready(async function() {
for (const value of edit_service_data) {
servicearray = ;
// console.log(servicearray);
- var newRow = `
-
- ';
-
+
+ newRow += ' ';
+
+ newRow += ' ';
+
+
// console.log(value);
tr = $('#productItemTable tbody').append(newRow);
initializeSelect2();
@@ -715,15 +718,13 @@ $(document).ready(async function() {
' ' +
' ';
- newRow += ' ';
+ newRow += ' ';
newRow += ' ' +
' ' +
' ' +
- ''+
- action+
- ''+
- ' ';
+ ' ';
+
newRow += ' ';
@@ -1984,16 +1985,16 @@ $(document).ready(function() {
}
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 clicked row
-}
-$closestTR.remove();
+ 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 clicked row
+ }
+ $closestTR.remove();
updateCalculations();
});
@@ -2019,31 +2020,31 @@ $closestTR.remove();