mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-02 05:10:59 +00:00
* refactor: stabilize model identities for domain migration * refactor: extract module platform context * refactor: assign models to domain contexts * refactor: extract ai platform context * refactor: extract storage platform context * refactor: extract mail platform context * refactor: extract pdf platform context * refactor: extract operations platform context * refactor: move installation into operations platform * refactor: extract money domain context * refactor: extract taxation domain context * refactor: extract catalog domain context * refactor: extract metadata domain context * refactor: extract reporting domain context * refactor: extract purchases domain context * refactor: extract receivables domain context * refactor: extract accounts domain context * refactor: complete reporting statement boundary * refactor: extract contacts domain context * refactor: extract sales domain context * refactor: remove legacy application layers * fix: migrate legacy bouncer role identities
62 lines
2.3 KiB
PHP
62 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Reporting\Http\Controllers\Company;
|
|
|
|
use App\Domains\Contacts\Models\Customer;
|
|
use App\Domains\Reporting\Http\Requests\SendCustomerStatementRequest;
|
|
use App\Domains\Reporting\Mail\SendCustomerStatementMail;
|
|
use App\Domains\Reporting\Queries\CustomerStatementQuery;
|
|
use App\Domains\Reporting\Rendering\CustomerStatementPdfRenderer;
|
|
use App\Platform\Http\Controller;
|
|
use App\Platform\Mail\Contracts\MailConfigurator;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
class SendCustomerStatementController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly CustomerStatementQuery $customerStatementQuery,
|
|
private readonly CustomerStatementPdfRenderer $customerStatementPdfRenderer,
|
|
private readonly MailConfigurator $mailConfigurator,
|
|
) {}
|
|
|
|
public function __invoke(SendCustomerStatementRequest $request, Customer $customer): JsonResponse
|
|
{
|
|
$this->authorize('view', $customer);
|
|
$this->authorize('view report', $customer->company);
|
|
|
|
$type = $request->validated('type');
|
|
|
|
$statement = $this->customerStatementQuery->statement(
|
|
$customer,
|
|
$type,
|
|
Carbon::createFromFormat('Y-m-d', $request->validated('from_date')),
|
|
Carbon::createFromFormat('Y-m-d', $request->validated($type === CustomerStatementQuery::TYPE_OUTSTANDING ? 'as_of' : 'to_date')),
|
|
PHP_INT_MAX,
|
|
);
|
|
$pdf = $this->customerStatementPdfRenderer->render($statement);
|
|
|
|
$this->mailConfigurator->applyCompanyConfig($customer->company_id);
|
|
|
|
$mail = Mail::to($request->validated('to'));
|
|
if ($request->filled('cc')) {
|
|
$mail->cc($request->validated('cc'));
|
|
}
|
|
if ($request->filled('bcc')) {
|
|
$mail->bcc($request->validated('bcc'));
|
|
}
|
|
|
|
$mail->send(new SendCustomerStatementMail([
|
|
...$request->safe()->only(['to', 'cc', 'bcc', 'subject', 'body']),
|
|
'from' => config('mail.from.address'),
|
|
'from_name' => config('mail.from.name'),
|
|
'customer' => $customer,
|
|
'pdf' => $pdf,
|
|
'filename' => __('Customer Statement').' '.$customer->name.'.pdf',
|
|
]));
|
|
|
|
return response()->json(['success' => true]);
|
|
}
|
|
}
|