diff --git a/app/Config/Routes.php b/app/Config/Routes.php index de4c7ba..1f09fcf 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -58,6 +58,7 @@ $routes->get('client_index/', 'Client::client_index'); $routes->post("add_client", "Client::add_client"); $routes->get("new_client/(:any)", "Client::new_client/$1"); $routes->get("delete_client/(:any)", "Client::delete_client/$1"); +$routes->post("save_client", "Client::client_quick_create"); //end clent //Vendor// $routes->get('vendor_index/', 'Vendor::vendor_index'); diff --git a/app/Controllers/Client.php b/app/Controllers/Client.php index 7f63ade..a4388ac 100644 --- a/app/Controllers/Client.php +++ b/app/Controllers/Client.php @@ -104,5 +104,43 @@ class Client extends BaseController return redirect()->to('client_index'); } + + public function client_quick_create(){ + // Load ClientModel + $ClientModel = new ClientModel(); + + // Validate inputs + $validationRules = [ + 'client_name' => 'required|max_length[100]', + 'mobile_no' => 'required' // Assuming mobile number is 10 digits long + ]; + + if (!$this->validate($validationRules)) { + // If validation fails, return validation errors + return $this->response->setJSON(['success' => false, 'errors' => $this->validator->getErrors()]); + } + + // If validation passes, proceed to save the client + $data = [ + 'client_name' => $this->request->getPost('client_name'), + 'mobile_no' => $this->request->getPost('mobile_no'), + 'branch_id'=> $this->session->get('logged_user_branch_id'), + 'city'=>'Chennai', + 'state'=>'Tamil Nadu', + 'isactive' => 1 + ]; + + // Attempt to insert the client data + $id = $ClientModel->insert($data); + if ($id) { + $clientData = $ClientModel->where('client_id',$id)->first(); + + // If insertion succeeds, return success response + return $this->response->setJSON(['success' => true, 'message' => 'Client saved successfully.','clientData'=>$clientData]); + } else { + // If insertion fails, return error response + return $this->response->setJSON(['success' => false, 'message' => 'Failed to save client.']); + } + } } \ No newline at end of file