40 lines
1.7 KiB
PHP
40 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Purchasing;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tempo\Finance\Payables\Workspace;
|
|
|
|
final class SupplierPayablesController extends Controller
|
|
{
|
|
public function index(Request $r, SupplierPayables $s)
|
|
{
|
|
return response()->json($s->listing($r->user()))->header('Cache-Control', 'no-store');
|
|
}
|
|
|
|
public function page(Request $r, SupplierPayables $s)
|
|
{
|
|
$data = $s->listing($r->user());
|
|
$scope = $s->scope($r->user());
|
|
$company = DB::table('companies')->where('tenant_id', $scope['tenant_id'])->where('id', $scope['company_id'])->value('name');
|
|
$unit = DB::table('units')->where('tenant_id', $scope['tenant_id'])->where('company_id', $scope['company_id'])->where('id', $scope['unit_id'])->value('name');
|
|
|
|
return response(Workspace::render($data, ['host' => 'ERP SGF', 'actor' => $r->user()->name, 'organisation' => $company.' / '.$unit, 'api' => '/api/supplier-payables', 'csrf' => csrf_token(), 'context' => $r->session()->get('company_context.token')]))->header('Cache-Control', 'no-store');
|
|
}
|
|
|
|
public function command(Request $r, string $action, SupplierPayables $s)
|
|
{
|
|
$d = $r->validate(['id' => 'required|integer|min:1', 'reason' => 'required|string|min:3|max:2000']);
|
|
abort_if(array_diff(array_keys($r->all()), ['id', 'reason']) !== [], 422);
|
|
try {
|
|
return response()->json($s->engine($r->user())->command($action, $d['id'], $d['reason'], (string) $r->header('Idempotency-Key')));
|
|
} catch (\DomainException $e) {
|
|
abort(409, $e->getMessage());
|
|
} catch (\InvalidArgumentException $e) {
|
|
abort(422, $e->getMessage());
|
|
}
|
|
}
|
|
}
|