1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Http/Controllers/ClientStatementController.php

64 lines
1.7 KiB
PHP
Raw Normal View History

<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-11 05:32:07 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. 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
*/
namespace App\Http\Controllers;
2023-10-26 04:57:44 +02:00
use App\Http\Requests\Statements\CreateStatementRequest;
2021-08-24 15:31:07 +02:00
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\Pdf\PdfMaker;
2023-04-26 03:21:20 +02:00
use Illuminate\Support\Facades\Response;
2021-08-24 13:18:32 +02:00
2019-03-28 22:34:58 +01:00
class ClientStatementController extends BaseController
{
2024-01-14 05:05:00 +01:00
use MakesHash;
use PdfMaker;
2021-08-24 15:31:07 +02:00
/** @var \App\Models\Invoice|\App\Models\Payment */
protected $entity;
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
*/
2021-08-24 13:18:32 +02:00
public function statement(CreateStatementRequest $request)
{
2023-01-17 01:00:12 +01:00
$send_email = false;
2023-02-16 02:36:09 +01:00
if ($request->has('send_email') && $request->send_email == 'true') {
2023-01-17 01:00:12 +01:00
$send_email = true;
2023-02-16 02:36:09 +01:00
}
2023-01-17 01:00:12 +01:00
$pdf = $request->client()->service()->statement(
2023-09-25 05:19:08 +02:00
$request->only(['start_date', 'end_date', 'show_payments_table', 'show_aging_table', 'status', 'show_credits_table', 'template']),
2023-02-16 02:36:09 +01:00
$send_email
);
2023-02-16 02:36:09 +01:00
if ($send_email) {
2023-01-17 01:00:12 +01:00
return response()->json(['message' => ctrans('texts.email_queued')], 200);
2023-02-16 02:36:09 +01:00
}
2023-01-17 01:00:12 +01:00
2021-08-24 15:31:07 +02:00
if ($pdf) {
return response()->streamDownload(function () use ($pdf) {
echo $pdf;
}, ctrans('texts.statement').'.pdf', ['Content-Type' => 'application/pdf']);
2021-08-24 15:31:07 +02:00
}
2023-01-17 01:00:12 +01:00
return response()->json(['message' => ctrans('texts.error_title')], 500);
2021-08-24 15:31:07 +02:00
}
}