2019-02-04 13:06:19 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 05:32:07 +02:00
|
|
|
*/
|
2019-02-04 13:06:19 +01:00
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2021-08-24 13:18:32 +02:00
|
|
|
use App\Http\Requests\Statements\CreateStatementRequest;
|
2021-08-24 15:31:07 +02:00
|
|
|
use App\Models\Design;
|
|
|
|
use App\Models\InvoiceInvitation;
|
|
|
|
use App\Services\PdfMaker\Design as PdfDesignModel;
|
|
|
|
use App\Services\PdfMaker\Design as PdfMakerDesign;
|
|
|
|
use App\Services\PdfMaker\PdfMaker as PdfMakerService;
|
|
|
|
use App\Utils\HostedPDF\NinjaPdf;
|
|
|
|
use App\Utils\HtmlEngine;
|
2021-08-25 03:41:07 +02:00
|
|
|
use App\Utils\PhantomJS\Phantom;
|
2021-08-24 15:31:07 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use App\Utils\Traits\Pdf\PdfMaker;
|
2021-08-24 13:18:32 +02:00
|
|
|
|
2019-03-28 22:34:58 +01:00
|
|
|
class ClientStatementController extends BaseController
|
2019-02-04 13:06:19 +01:00
|
|
|
{
|
2021-08-24 15:31:07 +02:00
|
|
|
use MakesHash, PdfMaker;
|
|
|
|
|
|
|
|
/** @var \App\Models\Invoice|\App\Models\Payment */
|
|
|
|
protected $entity;
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
public function __construct()
|
2019-03-28 22:34:58 +01:00
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2021-08-25 04:03:58 +02:00
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param CreateStatementRequest $request
|
|
|
|
* @return Response
|
|
|
|
*
|
|
|
|
* @OA\Post(
|
|
|
|
* path="/api/v1/client_statement",
|
|
|
|
* operationId="clientStatement",
|
|
|
|
* tags={"clients"},
|
|
|
|
* summary="Return a PDF of the client statement",
|
|
|
|
* description="Return a PDF of the client statement",
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
|
|
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
|
|
|
* @OA\RequestBody(
|
|
|
|
* description="Statment Options",
|
|
|
|
* required=true,
|
|
|
|
* @OA\MediaType(
|
|
|
|
* mediaType="application/json",
|
|
|
|
* @OA\Schema(
|
|
|
|
* type="object",
|
|
|
|
* @OA\Property(
|
|
|
|
* property="start_date",
|
|
|
|
* description="The start date of the statement period - format Y-m-d",
|
|
|
|
* type="string",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="end_date",
|
|
|
|
* description="The start date of the statement period - format Y-m-d",
|
|
|
|
* type="string",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="client_id",
|
|
|
|
* description="The hashed ID of the client",
|
|
|
|
* type="string",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="show_payments_table",
|
|
|
|
* description="Flag which determines if the payments table is shown",
|
|
|
|
* type="boolean",
|
|
|
|
* ),
|
|
|
|
* @OA\Property(
|
|
|
|
* property="show_aging_table",
|
|
|
|
* description="Flag which determines if the aging table is shown",
|
|
|
|
* type="boolean",
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* )
|
|
|
|
* ),
|
|
|
|
* @OA\Response(
|
|
|
|
* response=200,
|
|
|
|
* description="Returns the client object",
|
|
|
|
* @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\JsonContent(ref="#/components/schemas/Client"),
|
|
|
|
* ),
|
|
|
|
* @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"),
|
|
|
|
* ),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
|
2021-08-24 13:18:32 +02:00
|
|
|
public function statement(CreateStatementRequest $request)
|
2022-01-04 05:33:10 +01:00
|
|
|
{
|
2021-09-20 14:54:44 +02:00
|
|
|
$pdf = $request->client()->service()->statement(
|
2022-01-03 08:22:10 +01:00
|
|
|
$request->only(['start_date', 'end_date', 'show_payments_table', 'show_aging_table', 'status'])
|
2021-09-20 14:54:44 +02:00
|
|
|
);
|
2021-09-14 13:55:33 +02:00
|
|
|
|
2021-08-24 15:31:07 +02:00
|
|
|
if ($pdf) {
|
|
|
|
return response()->streamDownload(function () use ($pdf) {
|
|
|
|
echo $pdf;
|
2022-01-03 08:22:10 +01:00
|
|
|
}, ctrans('texts.statement') . '.pdf', ['Content-Type' => 'application/pdf']);
|
2021-08-24 15:31:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json(['message' => 'Something went wrong. Please check logs.']);
|
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|