Browse Source

Merge branch 'staging' of https://git.oslog.id/ibnu/generic-ospro-backend into dev-wahyun

pull/1/head
wahyuun 9 months ago
parent
commit
be4e9d796f
  1. 115
      app/Http/Controllers/ContactSalesController.php
  2. 12
      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);
}
}
}

12
app/Http/Controllers/ProductTransactionController.php

@ -77,4 +77,16 @@ class ProductTransactionController extends Controller
$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',
'updated_at',
'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->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
@ -594,5 +600,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');
});
});

Loading…
Cancel
Save