diff --git a/app/Http/Controllers/PurchaseOrderController.php b/app/Http/Controllers/PurchaseOrderController.php index 12b8cb143da5..1682380e02f1 100644 --- a/app/Http/Controllers/PurchaseOrderController.php +++ b/app/Http/Controllers/PurchaseOrderController.php @@ -851,4 +851,71 @@ class PurchaseOrderController extends BaseController echo $file; }, $purchase_order->numberFormatter().".pdf", $headers); } + /** + * @OA\Get( + * path="/api/v1/credit/{invitation_key}/download_e_purchase_order", + * operationId="downloadEPurchaseOrder", + * tags={"purchase_orders"}, + * summary="Download a specific E-Purchase-Order by invitation key", + * description="Downloads a specific E-Purchase-Order", + * @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Parameter( + * name="invitation_key", + * in="path", + * description="The E-Purchase-Order Invitation Key", + * example="D2J234DFA", + * required=true, + * @OA\Schema( + * type="string", + * format="string", + * ), + * ), + * @OA\Response( + * response=200, + * description="Returns the E-Purchase-Order pdf", + * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + * @param $invitation_key + * @return \Symfony\Component\HttpFoundation\BinaryFileResponse + */ + public function downloadEPurchaseOrder($invitation_key) + { + $invitation = $this->purchase_order_repository->getInvitationByKey($invitation_key); + + if (! $invitation) { + return response()->json(['message' => 'no record found'], 400); + } + + $contact = $invitation->contact; + $purchase_order = $invitation->purchase_order; + + $file = $purchase_order->service()->getEPurchaseOrder($contact); + $file_name = $purchase_order->getFileName("xml"); + + $headers = ['Content-Type' => 'application/xml']; + + if (request()->input('inline') == 'true') { + $headers = array_merge($headers, ['Content-Disposition' => 'inline']); + } + + return response()->streamDownload(function () use ($file) { + echo $file; + }, $file_name, $headers); + } } diff --git a/routes/api.php b/routes/api.php index 311360ae66d8..bc8b9cbb4bd1 100644 --- a/routes/api.php +++ b/routes/api.php @@ -204,6 +204,8 @@ Route::group(['middleware' => ['throttle:api', 'api_db', 'token_auth', 'locale'] Route::get('credits/{credit}/{action}', [CreditController::class, 'action'])->name('credits.action'); Route::post('credits/bulk', [CreditController::class, 'bulk'])->name('credits.bulk'); Route::get('credit/{invitation_key}/download', [CreditController::class, 'downloadPdf'])->name('credits.downloadPdf'); + Route::get('credit/{invitation_key}/download_e_credit', [CreditController::class, 'downloadECredit'])->name('credits.downloadECredit'); + Route::resource('designs', DesignController::class); // name = (payments. index / create / show / update / destroy / edit Route::post('designs/bulk', [DesignController::class, 'bulk'])->name('designs.bulk'); @@ -281,12 +283,14 @@ Route::group(['middleware' => ['throttle:api', 'api_db', 'token_auth', 'locale'] Route::put('purchase_orders/{purchase_order}/upload', [PurchaseOrderController::class, 'upload']); Route::get('purchase_orders/{purchase_order}/{action}', [PurchaseOrderController::class, 'action'])->name('purchase_orders.action'); Route::get('purchase_order/{invitation_key}/download', [PurchaseOrderController::class, 'downloadPdf'])->name('purchase_orders.downloadPdf'); + Route::get('purchase_order/{invitation_key}/download_e_purchase_order', [PurchaseOrderController::class, 'downloadEPurchaseOrder'])->name('purchase_orders.downloadEPurchaseOrder'); Route::resource('quotes', QuoteController::class); // name = (quotes. index / create / show / update / destroy / edit Route::get('quotes/{quote}/{action}', [QuoteController::class, 'action'])->name('quotes.action'); Route::post('quotes/bulk', [QuoteController::class, 'bulk'])->name('quotes.bulk'); Route::put('quotes/{quote}/upload', [QuoteController::class, 'upload']); Route::get('quote/{invitation_key}/download', [QuoteController::class, 'downloadPdf'])->name('quotes.downloadPdf'); + Route::get('quote/{invitation_key}/download_e_quote', [QuoteController::class, 'downloadEQuote'])->name('quotes.downloadEQuote'); Route::resource('recurring_expenses', RecurringExpenseController::class); Route::post('recurring_expenses/bulk', [RecurringExpenseController::class, 'bulk'])->name('recurring_expenses.bulk');