From 263ed94ab4c99c42ff935d31caafba3a323894d7 Mon Sep 17 00:00:00 2001 From: farhantock Date: Tue, 27 Feb 2024 10:48:41 +0700 Subject: [PATCH 1/3] Contact Sales --- .../Controllers/ContactSalesController.php | 115 ++++++++++++++++++ app/Models/ContactSales.php | 27 ++++ 2 files changed, 142 insertions(+) create mode 100644 app/Http/Controllers/ContactSalesController.php create mode 100644 app/Models/ContactSales.php diff --git a/app/Http/Controllers/ContactSalesController.php b/app/Http/Controllers/ContactSalesController.php new file mode 100644 index 0000000..bfe4521 --- /dev/null +++ b/app/Http/Controllers/ContactSalesController.php @@ -0,0 +1,115 @@ +validate($request, [ + 'name' => 'required', + 'role' => 'required', + 'email' => 'required', + 'number_phone' => 'required', + 'status' => 'required', + ]); + + $data = $request->all(); + + $data['created_by'] = '@System'; + $data['status'] = 'New Request'; + + $result = ContactSales::create($data); + + if ($result) { + return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Your message has been successfully received by our Sales team! Someone from our team will be in touch with you shortly.', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Your message has been failed!', 'code' => 400], 400); + } + } + + public function edit($id) + { + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + die(); + } + + $result = ContactSales::find($id); + + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get data Contact Sales, please try again later!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $data = ContactSales::find($id); + + + if ($data) { + $result = $data->update($request->all()); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Contact Sales not found!', 'code' => 400], 400); + die(); + } + + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'data Contact Sales successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Contact Sales failed updated!', 'code' => 400], 400); + } + } + + public function delete($id) + { + $data = ContactSales::find($id); + + if ($data) { + $delete = $data->delete(); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Contact Sales not found!', 'code' => 400], 400); + die(); + } + + + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'data Contact Sales successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Contact Sales failed deleted!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_contact_sales'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function list() + { + $data = ContactSales::all(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list Contact Sales, please try again later!', 'code' => 400], 400); + } + } +} diff --git a/app/Models/ContactSales.php b/app/Models/ContactSales.php new file mode 100644 index 0000000..9707bb9 --- /dev/null +++ b/app/Models/ContactSales.php @@ -0,0 +1,27 @@ + Date: Tue, 27 Feb 2024 10:49:05 +0700 Subject: [PATCH 2/3] update CURD productTransaction --- .../ProductTransactionController.php | 84 ++++++++++++++++++- app/Models/Demo.php | 1 - 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProductTransactionController.php b/app/Http/Controllers/ProductTransactionController.php index c5d7a12..9ee9836 100644 --- a/app/Http/Controllers/ProductTransactionController.php +++ b/app/Http/Controllers/ProductTransactionController.php @@ -22,9 +22,91 @@ class ProductTransactionController extends Controller $result = ProductTransaction::create($data); if ($result) { - return response()->json(['status' => 'success','data' => $result, 'message' => 'Add Transaction successfully!', 'code' => 200], 200); + return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Add Transaction successfully!', 'code' => 200], 200); } else { return response()->json(['status' => 'failed', 'message' => 'Add data Transaction failed!', 'code' => 400], 400); } } + + public function edit($id) + { + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + die(); + } + + $result = ProductTransaction::find($id); + + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get data Transaction, please try again later!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + if (!$id || (int) $id < 0 || $id == "") { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $data = ProductTransaction::find($id); + + + if ($data) { + $result = $data->update($request->all()); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Transaction not found!', 'code' => 400], 400); + die(); + } + + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'data Transaction successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Transaction failed updated!', 'code' => 400], 400); + } + } + + public function delete($id) + { + $data = ProductTransaction::find($id); + + if ($data) { + $delete = $data->delete(); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Transaction not found!', 'code' => 400], 400); + die(); + } + + + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'data Transaction successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data Transaction failed deleted!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 't_transaction'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function list() + { + $data = ProductTransaction::all(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list Transaction, please try again later!', 'code' => 400], 400); + } + } } diff --git a/app/Models/Demo.php b/app/Models/Demo.php index ded3b3a..7b1f0a1 100644 --- a/app/Models/Demo.php +++ b/app/Models/Demo.php @@ -22,6 +22,5 @@ class Demo extends Model 'created_by', 'updated_at', 'updated_by', - 'company_id' ]; } From 54effe3195a133902b2e406eb49bd58a059fc7df Mon Sep 17 00:00:00 2001 From: farhantock Date: Tue, 27 Feb 2024 10:49:12 +0700 Subject: [PATCH 3/3] update endpoint --- routes/web.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/routes/web.php b/routes/web.php index b2d7b20..76955c6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -33,6 +33,12 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro $router->post('/role-menu/search', 'RoleMenuController@search'); $router->get('/role-menu/get-role/{id}', 'RoleMenuController@listMenu'); + $router->post('/sales-contact/add', 'ContactSalesController@add'); + $router->get('/sales-contact/edit/{id}', 'ContactSalesController@edit'); + $router->put('/sales-contact/update/{id}', 'ContactSalesController@update'); + $router->post('/sales-contact/search', 'ContactSalesController@search'); + $router->delete('/sales-contact/delete/{id}', 'ContactSalesController@delete'); + $router->group(['middleware' => ['auth', 'cors']], function () use ($router) { $router->get('/dashboard/get-company-cashflow/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getCompanyCashFlow'); // project expenditure @@ -589,5 +595,10 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro $router->get('/demo-management/list', 'DemoController@list'); $router->get('information-storage/{company_name}', 'Controller@storage'); + $router->post('/product-transaction/edit/{id}', 'ProductTransactionController@add'); + $router->put('/product-transaction/update/{id}', 'ProductTransactionController@update'); + $router->post('/product-transaction/search', 'ProductTransactionController@search'); + $router->delete('/product-transaction/delete/{id}', 'ProductTransactionController@delete'); + $router->get('/product-transaction/list', 'ProductTransactionController@list'); }); });