paymentTermRepo = $paymentTermRepo; } /** * @SWG\Get( * path="/paymentTerms", * summary="List payment terms", * operationId="listPaymentTerms", * tags={"payment terms"}, * @SWG\Response( * response=200, * description="A list of payment terms", * @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/PaymentTerm")) * ), * @SWG\Response( * response="default", * description="an ""unexpected"" error" * ) * ) */ public function index() { $paymentTerms = PaymentTerm::scope() ->orWhere('account_id',0) ->orderBy('num_days', 'asc'); return $this->listResponse($paymentTerms); } /** * @SWG\Get( * path="/paymentTerms/{payment_term_id}", * summary="Retrieve a payment term", * operationId="getPaymentTermId", * tags={"payment term"}, * @SWG\Parameter( * in="path", * name="payment_term_id", * type="integer", * required=true * ), * @SWG\Response( * response=200, * description="A single payment term", * @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/PaymentTerm")) * ), * @SWG\Response( * response="default", * description="an ""unexpected"" error" * ) * ) */ public function show(PaymentTermRequest $request) { return $this->itemResponse($request->entity()); } /** * @SWG\Post( * path="/paymentTerms", * summary="Create a payment Term", * operationId="createPaymentTerm", * tags={"payment term"}, * @SWG\Parameter( * in="body", * name="payment term", * @SWG\Schema(ref="#/definitions/PaymentTerm") * ), * @SWG\Response( * response=200, * description="New payment Term", * @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/PaymentTerm")) * ), * @SWG\Response( * response="default", * description="an ""unexpected"" error" * ) * ) */ public function store(CreatePaymentTermRequest $request) { $paymentTerm = PaymentTerm::createNew(); $paymentTerm->num_days = Utils::parseInt(\Request::input('num_days')); $paymentTerm->name = 'Net ' . $paymentTerm->num_days; $paymentTerm->save(); return $this->itemResponse($paymentTerm); } /** * @SWG\Delete( * path="/paymentTerm/{num_days}", * summary="Delete a payment term", * operationId="deletePaymentTerm", * tags={"payment term"}, * @SWG\Parameter( * in="path", * name="num_days", * type="integer", * required=true * ), * @SWG\Response( * response=200, * description="Deleted payment Term", * @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/PaymentTerm")) * ), * @SWG\Response( * response="default", * description="an ""unexpected"" error" * ) * ) */ public function destroy($numDays) { $paymentTerm = PaymentTerm::where('num_days', $numDays)->first(); if(!$paymentTerm || $paymentTerm->account_id == 0) return $this->errorResponse(['message'=>'Cannot delete a default or non existent Payment Term'], 400); $this->paymentTermRepo->archive($paymentTerm); return $this->itemResponse($paymentTerm); } }