GWM:Client-Quick-Create
This commit is contained in:
parent
28fe55efa7
commit
8156ab34a4
@ -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');
|
||||
|
||||
@ -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.']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user