diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 9e6c45b..feabbab 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -14,6 +14,8 @@ $routes->set404Override(); $routes->get('/', 'Login::index'); $routes->get('log_out', 'Login::index'); $routes->post("authenticate", "Login::authenticate"); +$routes->get("edit_account/(:any)", "Users::edit_account/$1"); +$routes->post("add_account", "Users::add_account"); // $routes->get("new_user/(:any)", "Users::new_user/$1"); // $routes->get("delete_user/(:any)", "Users::delete_user/$1"); //end Login// @@ -34,6 +36,14 @@ $routes->get("new_business/(:any)", "Business::new_business/$1"); $routes->get("delete_business/(:any)", "Business::delete_business/$1"); // end business// +//Branch// +$routes->get('branch_index/(:any)', 'Branch::branch_index/$1'); +$routes->post('add_branch/(:any)', 'Branch::new_branch/$1'); +$routes->post('edit_branch/(:any)', 'Branch::edit_branch/$1'); +$routes->get("get_branch/(:any)", "Branch::get_branch/$1"); +$routes->get("delete_branch/(:any)", "Branch::delete_branch/$1"); +// end Branch// + // Products// $routes->get('product_index/', 'Products::product_index'); $routes->get('product_index/(:any)', 'Products::product_index/$1'); @@ -58,6 +68,18 @@ $routes->post("save_vehicle", "Sales::save_vehicle"); $routes->post("getProducts", "Sales::getProducts"); //end salle order// + +//Job Card // +$routes->get('job_card_index/', 'Jobcard::job_card_index'); +$routes->post("add_jobs", "Jobcard::add_jobs"); +$routes->get("new_jobcard/(:any)", "Jobcard::new_jobcard/$1"); +$routes->get("delete_jobcard/(:any)", "Jobcard::delete_jobcard/$1"); +// $routes->post("delete_sales_product", "Jobcard::delete_sales_product"); +// $routes->get("download_invoice/(:any)", "Jobcard::download_invoice/$1"); +// $routes->post("save_vehicle", "Jobcard::save_vehicle"); +$routes->post("getServices", "Jobcard::getServices"); +//End Job Card // + //Client// $routes->get('client_index/', 'Client::client_index'); $routes->post("add_client", "Client::add_client"); diff --git a/app/Controllers/Branch.php b/app/Controllers/Branch.php new file mode 100644 index 0000000..e06f5a7 --- /dev/null +++ b/app/Controllers/Branch.php @@ -0,0 +1,101 @@ +where('business_id',$business_id)->first(); + $branch=$BranchModel->where('business_id',$business_id)->findAll(); + $data['branch']=$branch; + $data['business_name']=$business['business_name']; + $data['business_id']=$business['business_id']; + + return view('branch_list',$data); + } + + + public function new_business($business_id) + { + + + if ($business_id === '0') { + + $data['business'] = []; + $data['page_name']="Add Business"; + } else if ($business_id !== '0') { + + $BusinessModel = new BusinessModel(); + $business=$BusinessModel->getBusinessById($business_id); + $data['business']=$business; + $data['page_name']="Edit Business" ; + } + $data['business_id'] = $business_id; + + return view('business_form',$data); + } + public function new_branch($business_id) + { + if ($business_id) { + $data = $this->request->getPost(); + $data['business_id'] = $business_id; + // print_r($data);die; + $BranchModel = new BranchModel(); + + $BranchModel->insert($data); + } + } + + + public function get_branch($branch_id) + { + if ($branch_id) { + $BranchModel = new BranchModel(); + $branch =$BranchModel->where('branch_id',$branch_id)->first(); + + return json_encode($branch); + } + } + + + public function edit_branch($branch_id) + { + if ($branch_id) { + $data = $this->request->getPost(); + $BranchModel = new BranchModel(); + + $BranchModel->update($branch_id,$data); + return json_encode(true); + } + } + + public function delete_branch($branch_id) + { + $model = new BranchModel(); + $where = ['branch_id' => $branch_id, 'isactive' => 1]; // Assuming 'isactive' is a column in your database + $existingBranch = $model->where($where)->first(); + + if ($existingBranch) { + $data['isactive'] = 0; + + if ($model->update($branch_id, $data)) { + session()->setFlashdata('success', 'Deleted successfully.'); + $this->logger->info("Branch: has been Inactivated successfully. Inactivated ID = ".$branch_id); + } + } + + + return redirect()->to('branch_index/' . $existingBranch['business_id']); + } + +} \ No newline at end of file diff --git a/app/Controllers/Business.php b/app/Controllers/Business.php index 1db0708..d695bea 100644 --- a/app/Controllers/Business.php +++ b/app/Controllers/Business.php @@ -77,7 +77,7 @@ class Business extends BaseController 'country' => $this->request->getPost('country'), 'isactive' => 1 // Assuming this is a default value or handled separately ]; - // print_r($data);die; + // print_r($data);die; $business_id = $this->request->getPost('business_id'); diff --git a/app/Controllers/Jobcard.php b/app/Controllers/Jobcard.php new file mode 100644 index 0000000..006e2a4 --- /dev/null +++ b/app/Controllers/Jobcard.php @@ -0,0 +1,467 @@ +session = session(); + $this->BikemodelsModel = new BikemodelsModel(); + $this->BikemakeModel = new BikemakeModel(); + + } + + public function job_card_index() + { + + $JobcardModel = new JobcardModel(); + $jobs=$JobcardModel->getJobCardsWithProductsAndService($this->session->get('logged_user_branch_id')); + + $data['jobs']=$jobs; + // echo "
";
+ // print_r($jobs);die;
+ return view('jobs_list',$data);
+ }
+
+
+ public function new_jobcard($job_card_id)
+ {
+ if ($job_card_id === '0') {
+ $data['page_name']="Create Job Card";
+ $data['jobs'] = [];
+ $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->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+ $ServiceModel = new ServiceModel();
+ $service=$ServiceModel->where('isactive',1)->where('branch_id',$this->session->get('logged_user_branch_id'))->findAll();
+ $data['product_1']=$product;
+ $data['product']="";
+ $data['service_1']=$service;
+ $data['service']="";
+ $data['client']=$client;
+ $data['vehicle']=$vehicle;
+
+ } else if ($job_card_id !== '0')
+ {
+ $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();
+ $data['jobs']=$jobs;
+ $VehicleModel = new VehicleModel();
+ $vehicles = $VehicleModel->where('isactive',1)->where('vehicle_id',$jobs['vehicle_id'])
+ ->where('branch_id',$this->session->get('logged_user_branch_id'))
+ ->first();
+ $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();
+ $data['make_model'] = $make_name['make'].' ' . $model_name['model_name'];
+ // Encode the modelId before searching
+ $encodedModelId = json_encode([$modelId]);
+
+ // Load the ProductModel
+ $productModel = new ProductModel();
+
+ // Query the database to find the product based on make_id and model_id
+ $product = $productModel->where('make_id', $makeId)
+ ->where('JSON_CONTAINS(models_id, \'' . $encodedModelId . '\')', null, false)
+ ->findAll();
+ $data['product']=$product;
+
+ // 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();
+ $service = $ServiceModel->where('makes_id LIKE \'%"' . $makeId . '"%\'', null, false)
+ ->where('models_id LIKE \'%"' . $modelId . '"%\'', null, false)
+ ->findAll();
+ $data['product']=$product;
+ $data['service']=$service;
+ $JobcardProductModel = new JobcardProductModel();
+ $jobs_product= $JobcardProductModel->where('job_card_id', $job_card_id)->findAll();
+ $data['jobs_product']=$jobs_product;
+ $JobcardServiceModel = new JobcardServiceModel();
+ $jobs_service= $JobcardServiceModel->where('job_card_id', $job_card_id)->findAll();
+ $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();
+ $data['vehicle']=$vehicle;
+ }
+ // print_r($data);die;
+ $data['job_card_id'] = $job_card_id;
+ $bikeMakeModel = new BikeMakeModel();
+ $data['makeData'] =$bikeMakeModel->findAll();
+ // echo "";
+ // print_r($data);die;
+ return view('job_card_form',$data);
+ }
+
+
+ public function add_jobs()
+ {
+ $JobcardModel = new JobcardModel();
+ $ProductModel = new ProductModel();
+ $JobcardProductModel = new JobcardProductModel(); // Assuming you have a model for sales_order_product
+
+ $JobcardServiceModel = new JobcardServiceModel();
+
+ // Prepare data for sales order
+ $data = [
+ 'client_name' => $this->request->getPost('client_id'),
+ 'vehicle_id'=>$this->request->getPost('vehicle_id'),
+ 'billing_address' => $this->request->getPost('billing_address'),
+ 'billing_city' => $this->request->getPost('city'),
+ 'mobile_no' => $this->request->getPost('mobile_no'),
+ 'billing_state' => $this->request->getPost('state'),
+ 'billing_postal_code' => $this->request->getPost('postalcode'),
+ // 'billing_country' => $this->request->getPost('country'),
+ // 'terms_condition' => $this->request->getPost('terms_condition'),
+ // 'subtotal' => $this->request->getPost('sub_total'),
+ // 'tax' => $this->request->getPost('invoice_tax'),
+
+ 'total'=> $this->request->getPost('grand_total'),
+ 'status'=> $this->request->getPost('status'),
+ 'isactive' => 1, // Assuming this is a default value or handled separately
+ 'branch_id'=> $this->session->get('logged_user_branch_id'),
+ ];
+ // print_r($data);die;
+ // Insert or update sales order
+ $job_card_id = $this->request->getPost('job_card_id');
+ if (!empty($job_card_id)) {
+ // print_r("hello");die;
+ $JobcardModel->update($job_card_id, $data);
+ } else {
+ $JobcardModel->insert($data);
+ $job_card_id = $JobcardModel->getInsertID(); // Get the last inserted ID
+ }
+ $orderNumber = 'JC-' . date('md') . '-' . str_pad($job_card_id, 5, '0', STR_PAD_LEFT);
+ // print_r($orderNumber);die;
+ // Update sales order with generated order number
+ $JobcardModel->update($job_card_id, ['order_number' => $orderNumber]);
+ // Prepare data for sales order product
+ // echo "";
+ // print_r($this->request->getPost());die;
+ $product_ids = $this->request->getPost('item_details');
+ $quantities = $this->request->getPost('quantity');
+ $discounts = $this->request->getPost('discount_amount');
+ $discount_types = $this->request->getPost('discount_type');
+ $amounts = $this->request->getPost('amount');
+ $itemtax=$this->request->getPost('item-tax');
+ $unitprice=$this->request->getPost('unit-price');
+ $job_card_product_id = $this->request->getPost('job_card_product_id');
+ // print_r($product_ids);die;
+
+ // print_r($status);die;
+ $status = $this->request->getPost('status');
+ foreach ($product_ids as $key => $product_id) {
+ $qty = isset($quantities[$key]) ? $quantities[$key] : 0;
+ if ($status == 'Created') {
+ // echo "hello";die;
+ $this->updateProductQuantity($ProductModel, $product_id, $qty);
+ }elseif ($status == 'Cancelled'){
+ // echo "cancel";die;
+
+ // echo"hello";die;
+ $this->addBackProductQuantity($ProductModel, $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);
+ // print_r($discount_type);die;
+ $product_data = [
+ 'job_card_id' => $job_card_id,
+ 'product_id' => $product_id,
+ 'qty' => $qty,
+ 'discount' => $discount,
+ 'discount_type' => $discount_type,
+ 'net_price'=>$rate,
+ 'tax'=>$tax,
+ 'amount' => $amount,
+ 'isactive'=>1,
+ ];
+ // print_r($product_data);die;
+ if (!empty($job_card_product_id[$key])) {
+
+
+ $JobcardProductModel->update($job_card_product_id[$key], $product_data);
+
+ } else {
+ $JobcardProductModel->insert($product_data);
+
+ }
+
+ }
+
+ return redirect()->to('job_card_index');
+ }
+
+ private function addBackProductQuantity($ProductModel, $product_id, $sold_qty)
+ {
+ // Fetch current product quantity
+ $product = $ProductModel->find($product_id);
+ $current_qty = $product['qty_stock'];
+
+ // Calculate updated quantity
+ $new_qty = $current_qty + $sold_qty;
+
+ // Update quantity in Product table
+ $ProductModel->update($product_id, ['qty_stock' => $new_qty]);
+ }
+ private function updateProductQuantity($ProductModel, $product_id, $sold_qty)
+ {
+ // Fetch current product quantity
+ $product = $ProductModel->find($product_id);
+ $current_qty = $product['qty_stock'];
+
+ // Calculate updated quantity
+ $new_qty = $current_qty - $sold_qty;
+
+ // Update quantity in Product table
+ $ProductModel->update($product_id, ['qty_stock' => $new_qty]);
+ }
+
+ 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();
+
+ if ($existingProduct) {
+ $data['isactive'] = 0;
+
+ if ($model->update($job_card_id, $data)) {
+ session()->setFlashdata('success', 'Deleted successfully.');
+ $this->logger->info("Job Card: has been Inactivated successfully. Inactivated ID = ".$job_card_id);
+ }
+ }
+
+
+ return redirect()->to('job_card_index');
+ }
+ public function download_invoice($sales_order_id)
+ {
+ // echo "hello"; die;
+ // Fetch the invoice data based on $invoice_id
+ $model = new SalesOrderModel();
+ $data = $model->getSalesPdf($sales_order_id);
+
+ $items = $model->getSalesOrderProductsForPdf($sales_order_id);
+
+
+
+ // print_r($items);die();
+
+ // print_r($invoiceItems);die();
+
+ // Create an mPDF object
+ $mpdf = new Mpdf([
+ 'mode' => '',
+ 'format' => 'A5',
+ 'default_font_size' => 0,
+ 'default_font' => '',
+
+ // 'margin_right' => 1,
+ 'margin_top' => 6,
+ 'margin_bottom' => 6,
+ 'margin_header' => 6,
+ 'margin_footer' =>-30,
+ 'orientation' => 'P',
+ ]);
+
+
+
+ $mpdf->autoLangToFont = true; $mpdf->autoScriptToLang = true;
+ // Set PDF properties
+ $mpdf->SetTitle('Invoice');
+ $mpdf->SetAuthor($data[0]->branch_name);
+ $mpdf->SetCreator('');
+
+
+
+ // Generate the PDF content (HTML)
+ if ($data[0]->status === 'Draft') {
+ // Set the watermark text and options
+ $mpdf->SetWatermarkText('Draft');
+ $mpdf->showWatermarkText = true;
+ }
+ if ($data[0]->status === 'Cancelled') {
+ // Set the watermark text and options
+ $mpdf->SetWatermarkText('Cancelled');
+ $mpdf->showWatermarkText = true;
+ }
+ if ($data[0]->status === 'Void') {
+ // Set the watermark text and options
+ $mpdf->SetWatermarkText('Void');
+ $mpdf->showWatermarkText = true;
+ }
+
+
+ // Generate the PDF content (HTML) with data
+ $html = view('invoice_pdf_template', ['sales' => $data,'items'=>$items]);
+ // echo $html;die;
+ // Load HTML into the mPDF instance
+ $mpdf->WriteHTML($html);
+
+ // Output the PDF to the browser for download
+ $mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D');
+ }
+
+
+ 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);
+
+ if($client_id){
+
+ $data = [
+ 'client_id' => $client_id,
+ 'mobile_no' => $this->request->getPost('createclientMobile'),
+ 'reg_no' => $this->request->getPost('reg_no'),
+ 'model' => $this->request->getPost('model'),
+ 'make' => $this->request->getPost('make'),
+ 'branch_id'=> $this->session->get('logged_user_branch_id'),
+ 'city'=>'Chennai',
+ 'state'=>'Tamil Nadu',
+ 'isactive' => 1
+ ];
+
+ }
+
+
+ }else{
+
+ $data = [
+ 'client_id' => $this->request->getPost('client_id'),
+ 'mobile_no' => $this->request->getPost('mobile_no'),
+ 'reg_no' => $this->request->getPost('reg_no'),
+ 'model' => $this->request->getPost('model'),
+ 'make' => $this->request->getPost('make'),
+ 'branch_id'=> $this->session->get('logged_user_branch_id'),
+ 'city'=>'Chennai',
+ 'state'=>'Tamil Nadu',
+ 'isactive' => 1
+ ];
+
+
+ }
+
+
+
+
+ // Attempt to insert the client data
+ $id = $VehicleModel->insert($data);
+ if ($id) {
+ $vehicleData = $VehicleModel->where('vehicle_id',$id)->first();
+
+ // If insertion succeeds, return success response
+ return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','vehicleData'=>$vehicleData]);
+ } else {
+ // If insertion fails, return error response
+ return $this->response->setJSON(['success' => false, 'message' => 'Failed to save client.']);
+ }
+ }
+
+ public function get_vehicle_products(){
+
+ }
+
+
+
+
+ public function getServices()
+ {
+ // Retrieve make_id and model_id from the request
+ $makeId = $this->request->getPost('make_id');
+ $modelId = $this->request->getPost('model_id');
+
+ // Encode the makeId before searching
+ $encodedMakeId = json_encode([$makeId]);
+
+ // Encode the modelId before searching
+ $encodedModelId = json_encode([$modelId]);
+
+ // Load the ProductModel
+ $ServiceModel = new ServiceModel();
+
+ // Query the database to find the service based on make_id and model_id
+ $service = $ServiceModel->where('makes_id LIKE \'%"' . $makeId . '"%\'', null, false)
+ ->where('models_id LIKE \'%"' . $modelId . '"%\'', null, false)
+ ->findAll();
+
+ $modelName = $this->BikemodelsModel->where('model_id',$modelId)->get()->getRow()->model_name;
+ $makeName = $this->BikemakeModel->where('make_id',$makeId)->get()->getRow()->make;
+
+ if($service){
+ // Send JSON response
+ return $this->response->setJSON(['service'=>$service , 'modelName'=>$modelName ,'makeName'=>$makeName] );
+ } else {
+ // If service is not found, return an empty response or appropriate message
+ return $this->response->setJSON(['service'=>[] , 'modelName'=>$modelName ,'makeName'=>$makeName]);
+ }
+ }
+ // Check if service exists
+
+}
diff --git a/app/Controllers/Purchase.php b/app/Controllers/Purchase.php
index 4086a38..7920bb7 100644
--- a/app/Controllers/Purchase.php
+++ b/app/Controllers/Purchase.php
@@ -21,7 +21,8 @@ class Purchase extends BaseController
{
$PurchaseOrderModel = new PurchaseOrderModel();
- $purchase = $PurchaseOrderModel->select('purchase_order.*, vendor.vendor_name')
+ $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();
// echo "";
@@ -41,7 +42,7 @@ class Purchase extends BaseController
$PurchaseOrderModel = new PurchaseOrderModel();
$VendorModel = new VendorModel();
- $vendor = $VendorModel->select('vendor_id,vendor_name')->findAll();
+ $vendor = $VendorModel->where('branch_id',$this->session->get('logged_user_branch_id'))->select('vendor_id,vendor_name')->findAll();
$BranchModel = new BranchModel();
@@ -63,7 +64,7 @@ class Purchase extends BaseController
$purchase=$PurchaseOrderModel->where('purchase_order_id', $purchase_order_id)->get()->getRowArray();
$VendorModel = new VendorModel();
- $vendor = $VendorModel->select('vendor_id,vendor_name')->findAll();
+ $vendor = $VendorModel->where('branch_id',$this->session->get('logged_user_business_id'))->select('vendor_id,vendor_name')->findAll();
$data['vendor']=$vendor;
$data['purchase'] = $purchase;
$data['vendor_id'] = $purchase['vendor_id'];
diff --git a/app/Controllers/Service.php b/app/Controllers/Service.php
index abf8b1d..9f6a7de 100644
--- a/app/Controllers/Service.php
+++ b/app/Controllers/Service.php
@@ -22,7 +22,7 @@ class Service extends BaseController
{
$ServiceModel = new ServiceModel();
- $services = $ServiceModel->findAll();
+ $services = $ServiceModel->where('branch_id',$this->session->get('logged_user_business_id'))->findAll();
foreach ($services as &$service) {
// Convert JSON strings to arrays
@@ -146,7 +146,7 @@ class Service extends BaseController
$ServiceModel->update($service_id, $data);
} else {
-
+ $data['branch_id'] = $this->session->get('logged_user_business_id');
$ServiceModel->insert($data);
}
diff --git a/app/Controllers/Users.php b/app/Controllers/Users.php
index c007829..f3ad5a1 100644
--- a/app/Controllers/Users.php
+++ b/app/Controllers/Users.php
@@ -44,6 +44,14 @@ class Users extends BaseController
public function new_user($user_id)
{
+ $uri = $this->request->getUri();
+
+ // Get the query parameters
+ $queryParams = $uri->getQuery();
+
+ // echo "";
+ // print_r($queryParams);
+ // die;
// echo $user_id;die;
if ($user_id === '0') {
@@ -78,46 +86,124 @@ class Users extends BaseController
return view('user_form',$data);
}
+
+ public function edit_account($user_id)
+ {
+ $uri = $this->request->getUri();
+
+ // Get the query parameters
+ $queryParams = $uri->getQuery();
+ if ($user_id === '0') {
+ $data['users'] = [];
+ $BusinessModel=new BusinessModel();
+ $business=$BusinessModel->findAll();
+ // print_r($business);die;
+ $rolemodel = new RoleModel();
+
+ $roles =$rolemodel->getRoles();
+
+ $data['business'] = $business;
+ $data['roles'] = $roles;
+ } else if ($user_id !== '0') {
+
+ $UsersModel = new UsersModel();
+ $users=$UsersModel->getUserById($user_id);
+ $BusinessModel=new BusinessModel();
+ $business=$BusinessModel->findAll();
+ $BranchModel=new BranchModel();
+ $branch=$BranchModel->where("business_id",$users['business_id'])->findAll();
+ $data['users']=$users;
+ $data['business'] = $business;
+ $data['branches'] = $branch;
+ $rolemodel = new RoleModel();
+
+ $roles =$rolemodel->getRoles();
+
+ $data['roles'] = $roles;
+
+ }
+ $data['user_id'] = $user_id;
+ return view('edit_account_form',$data);
+ }
+
public function add_user()
-{
- // Load UsersModel
- $UsersModel = new UsersModel();
+ {
+ // Load UsersModel
+ $UsersModel = new UsersModel();
- // Get form data
- $data = [
- 'name' => $this->request->getPost('name'),
- 'email' => $this->request->getPost('email'),
- 'mobile_no' => $this->request->getPost('mobile'),
- 'role' => $this->request->getPost('role'),
- 'business_id' => $this->request->getPost('business'),
- 'branch_id' => $this->request->getPost('branch'),
- 'isactive' => 1 // Assuming this is a default value or handled separately
- ];
+ // Get form data
+ $data = [
+ 'name' => $this->request->getPost('name'),
+ 'email' => $this->request->getPost('email'),
+ 'mobile_no' => $this->request->getPost('mobile'),
+ 'role' => $this->request->getPost('role'),
+ 'business_id' => $this->request->getPost('business'),
+ 'branch_id' => $this->request->getPost('branch'),
+ 'isactive' => 1 // Assuming this is a default value or handled separately
+ ];
- // Hash the password
- $password = $this->request->getPost('password');
- $hashedPassword = password_hash($password, PASSWORD_DEFAULT); // Use PASSWORD_DEFAULT for bcrypt hashing
+ // Hash the password
+ $password = $this->request->getPost('password');
+ $hashedPassword = password_hash($password, PASSWORD_DEFAULT); // Use PASSWORD_DEFAULT for bcrypt hashing
- // Add hashed password to the data array
- $data['password'] = $hashedPassword;
+ // Add hashed password to the data array
+ $data['password'] = $hashedPassword;
- // Get user_id from the form
- $user_id = $this->request->getPost('user_id');
+ // Get user_id from the form
+ $user_id = $this->request->getPost('user_id');
- // Check if user_id is provided
- if (!empty($user_id)) {
- // Update existing user
- $UsersModel->update($user_id, $data);
- } else {
- // Insert new user
- $UsersModel->insert($data);
+ // Check if user_id is provided
+ if (!empty($user_id)) {
+ // Update existing user
+ $UsersModel->update($user_id, $data);
+ } else {
+ // Insert new user
+ $UsersModel->insert($data);
+ }
+
+ // Redirect to user listing page or wherever appropriate
+ return redirect()->to('index'); // Change '/users' to your desired redirect URL
}
- // Redirect to user listing page or wherever appropriate
- return redirect()->to('index'); // Change '/users' to your desired redirect URL
-}
+ public function add_account()
+ {
+ // Load UsersModel
+ $UsersModel = new UsersModel();
+ // Get form data
+ $data = [
+ 'name' => $this->request->getPost('name'),
+ 'email' => $this->request->getPost('email'),
+ 'mobile_no' => $this->request->getPost('mobile'),
+ 'role' => $this->request->getPost('role'),
+ 'business_id' => $this->request->getPost('business'),
+ 'branch_id' => $this->request->getPost('branch'),
+ 'isactive' => 1 // Assuming this is a default value or handled separately
+ ];
+
+ // Hash the password
+ $password = $this->request->getPost('password');
+ $hashedPassword = password_hash($password, PASSWORD_DEFAULT); // Use PASSWORD_DEFAULT for bcrypt hashing
+
+ // Add hashed password to the data array
+ $data['password'] = $hashedPassword;
+
+ // Get user_id from the form
+ $user_id = $this->request->getPost('user_id');
+
+ // Check if user_id is provided
+ if (!empty($user_id)) {
+ // Update existing user
+ $UsersModel->update($user_id, $data);
+ } else {
+ // Insert new user
+ $UsersModel->insert($data);
+ }
+
+ // Redirect to user listing page or wherever appropriate
+ return redirect()->to('dashboard'); // Change '/users' to your desired redirect URL
+ }
public function delete_user($user_id)
{
diff --git a/app/Models/BranchModel.php b/app/Models/BranchModel.php
index 2d2eaf8..1372756 100644
--- a/app/Models/BranchModel.php
+++ b/app/Models/BranchModel.php
@@ -5,7 +5,7 @@ class BranchModel extends Model
{
protected $table = 'branches';
protected $primaryKey = 'branch_id';
- protected $allowedFields = ['business_id','branch_id','','branch_name','email','mobile','address','city','state','postal_code','country','isactive'];
+ protected $allowedFields = ['business_id','branch_id','','branch_name','email','mobile_no','address','city','state','postal_code','country','isactive'];
public function getBranchesByBusinessId($business_id)
{
diff --git a/app/Models/JobcardModel.php b/app/Models/JobcardModel.php
index fa8b476..ab8a996 100644
--- a/app/Models/JobcardModel.php
+++ b/app/Models/JobcardModel.php
@@ -5,7 +5,32 @@ class JobcardModel extends Model
{
protected $table = 'job_card';
protected $primaryKey = 'job_card_id';
- protected $allowedFields = ['job_card_id','vehicle_id','sale_order','client_mobile_no','client_name','delivery_on','fuel','kilometer','materiality','customer_complaints','billing_address','billing_city','billing_state','billing_country','billing_postal_code','isactive'];
+ protected $allowedFields = ['job_card_id','vehicle_id','branch_id','order_number','sale_order','client_mobile_no','client_name','delivery_on','fuel','kilometer','materiality','customer_complaints','billing_address','billing_city','billing_state','billing_country','billing_postal_code','isactive','total','tax','subtotal','discount','status'];
+
+
+ public function getJobCardsWithProductsAndService($logged_user_branch_id)
+ {
+ // Select required fields from both tables
+ // $this->select('job_card.*, COUNT(sales_order_product.job_card_id) AS product_count,vehicle.reg_no');
+ // $this->select('job_card.*, COUNT(job_card_product.job_card_id) AS product_count, COUNT(job_card_service.job_card_id) AS service_count,vehicle.reg_no');
+ $this->select('job_card.*, COUNT(job_card_product.job_card_id) AS product_count, vehicle.reg_no');
+
+ // Join the sales_order_product table based on job_card_id
+ $this->join('job_card_product', 'job_card_product.job_card_id = job_card.job_card_id');
+ // $this->join('job_card_service', 'job_card_service.job_card_id = job_card.job_card_id');
+ $this->join('vehicle', 'vehicle.vehicle_id = job_card.vehicle_id');
+
+ // Group by job_card_id to get count of products per sales order
+ $this->groupBy('job_card.job_card_id');
+
+ // Add condition to fetch only active sales orders
+ $this->where('job_card_product.isactive', 1);
+ // $this->where('job_card_service.isactive', 1);
+ $this ->where('job_card.branch_id',$logged_user_branch_id);
+ $this->orderBy('job_card.job_card_id','DESC');
+ // Get the results
+ return $this->findAll();
+ }
}
\ No newline at end of file
diff --git a/app/Models/PurchaseOrderModel.php b/app/Models/PurchaseOrderModel.php
index 429dff8..957e9e4 100644
--- a/app/Models/PurchaseOrderModel.php
+++ b/app/Models/PurchaseOrderModel.php
@@ -5,7 +5,7 @@ class PurchaseOrderModel extends Model
{
protected $table = 'purchase_order';
protected $primaryKey = 'purchase_order_id';
- protected $allowedFields = ['purchase_order_id','vendor_id','status','billing_address','billing_city','billing_state','billing_country','billing_postal_code','shipping_address','shipping_city','shipping_state','shipping_country','shipping_postal_code','terms_condition','isactive','order_date','contact_person_name','contact_person_mobile','description'];
+ protected $allowedFields = ['purchase_order_id','branch_id','vendor_id','status','billing_address','billing_city','billing_state','billing_country','billing_postal_code','shipping_address','shipping_city','shipping_state','shipping_country','shipping_postal_code','terms_condition','isactive','order_date','contact_person_name','contact_person_mobile','description'];
}
\ No newline at end of file
diff --git a/app/Models/ServiceModel.php b/app/Models/ServiceModel.php
index 28f65f2..ea423cb 100644
--- a/app/Models/ServiceModel.php
+++ b/app/Models/ServiceModel.php
@@ -5,7 +5,7 @@ class ServiceModel extends Model
{
protected $table = 'services';
protected $primaryKey = 'service_id';
- protected $allowedFields = ['service_id','service_name','price','cgst','igst','description','makes_id','models_id','isactive'];
+ protected $allowedFields = ['service_id','branch_id','service_name','price','cgst','igst','description','makes_id','models_id','isactive'];
public function getTax()
diff --git a/app/Views/bike_model_list.php b/app/Views/bike_model_list.php
index a6cd70f..e931742 100644
--- a/app/Views/bike_model_list.php
+++ b/app/Views/bike_model_list.php
@@ -7,7 +7,7 @@