Browse Source

Merge pull request 'Dev-Farhan' (#55) from Dev-Farhan into staging

Reviewed-on: ibnu/generic-ospro-backend#55
pull/1/head
farhantock 10 months ago
parent
commit
5e01c504ed
  1. 115
      app/Http/Controllers/ContactSalesController.php
  2. 82
      app/Http/Controllers/ProductTransactionController.php
  3. 27
      app/Models/ContactSales.php
  4. 1
      app/Models/Demo.php
  5. 11
      routes/web.php

115
app/Http/Controllers/ContactSalesController.php

@ -0,0 +1,115 @@
<?php
namespace App\Http\Controllers;
use App\Models\ContactSales;
use Illuminate\Http\Request;
class ContactSalesController extends Controller
{
public function add(Request $request)
{
$this->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);
}
}
}

82
app/Http/Controllers/ProductTransactionController.php

@ -27,4 +27,86 @@ class ProductTransactionController extends Controller
return response()->json(['status' => 'failed', 'message' => 'Add data Transaction failed!', 'code' => 400], 400); 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);
}
}
} }

27
app/Models/ContactSales.php

@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ContactSales extends Model
{
protected $table = 'm_contact_sales';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name',
'company_name',
'email',
'role',
'number_phone',
'status',
'message',
'created_at',
'created_by',
'updated_at',
'updated_by',
];
}

1
app/Models/Demo.php

@ -22,6 +22,5 @@ class Demo extends Model
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by', 'updated_by',
'company_id'
]; ];
} }

11
routes/web.php

@ -33,6 +33,12 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/role-menu/search', 'RoleMenuController@search'); $router->post('/role-menu/search', 'RoleMenuController@search');
$router->get('/role-menu/get-role/{id}', 'RoleMenuController@listMenu'); $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->group(['middleware' => ['auth', 'cors']], function () use ($router) {
$router->get('/dashboard/get-company-cashflow/{company_id}/{all_project}/{hierarchy}/{role_name}', 'DashboardBoDController@getCompanyCashFlow'); // project expenditure $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('/demo-management/list', 'DemoController@list');
$router->get('information-storage/{company_name}', 'Controller@storage'); $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');
}); });
}); });

Loading…
Cancel
Save