validate(['source' => 'sometimes|required|integer|min:1', 'page' => 'sometimes|integer|min:1|max:100000', 'proposal_page' => 'sometimes|integer|min:1|max:100000', 'event_page' => 'sometimes|integer|min:1|max:100000', 'per_page' => 'sometimes|integer|in:25,100', 'q' => 'sometimes|nullable|string|max:100', 'recognition' => 'sometimes|in:all,recognised,unrecognised']); abort_if(array_diff(array_keys($r->query()), array_keys($d)) !== [], 422); return $d; } public function index(Request $r, SupplierPayables $s) { return response()->json($s->listing($r->user(), $this->listingOptions($r)))->header('Cache-Control', 'no-store'); } public function page(Request $r, SupplierPayables $s) { $data = $s->listing($r->user(), $this->listingOptions($r)); $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'); $flow=[]; if(config('general_ledger.synthetic_enabled')===true&&isset($data['listing_query']['source'])&&app(\App\Modules\Identity\Services\Permissions::class)->has($r->user()->id,$scope['tenant_id'],$scope['company_id'],'general_ledger.view',$scope['unit_id'])){ $flow=['ledger_flow_url'=>'/general-ledger/flow?source='.$data['listing_query']['source'],'ledger_flow_scope'=>$scope]; } return response(Workspace::render($data, $flow+['host' => 'ERP SGF', 'actor' => $r->user()->name, 'organisation' => $company.' / '.$unit, 'api' => '/api/supplier-payables', 'document_filter' => 'source', 'report_url' => '/supplier-payables/report', '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()); } } }