1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00
invoiceninja/app/Http/Controllers/ClientPortal/RecurringInvoiceController.php

106 lines
3.6 KiB
PHP
Raw Normal View History

2019-08-15 06:31:03 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2019-08-15 06:31:03 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2022-04-27 05:20:41 +02:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
2019-08-15 06:31:03 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2019-08-15 06:31:03 +02:00
*/
namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller;
use App\Http\Requests\ClientPortal\RecurringInvoices\RequestCancellationRequest;
use App\Http\Requests\ClientPortal\RecurringInvoices\ShowRecurringInvoiceRequest;
use App\Http\Requests\ClientPortal\RecurringInvoices\ShowRecurringInvoicesRequest;
2021-02-14 22:32:59 +01:00
use App\Jobs\Mail\NinjaMailer;
use App\Jobs\Mail\NinjaMailerJob;
2021-02-14 22:32:59 +01:00
use App\Jobs\Mail\NinjaMailerObject;
use App\Mail\RecurringInvoice\ClientContactRequestCancellationObject;
use App\Models\RecurringInvoice;
use App\Notifications\ClientContactRequestCancellation;
use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\Notifications\UserNotifies;
2020-10-28 11:10:49 +01:00
use Illuminate\Contracts\View\Factory;
use Illuminate\View\View;
2019-08-15 06:31:03 +02:00
/**
* Class InvoiceController.
2019-08-15 06:31:03 +02:00
*/
class RecurringInvoiceController extends Controller
{
use MakesHash;
use MakesDates;
use UserNotifies;
2020-03-23 18:10:42 +01:00
2019-08-15 06:31:03 +02:00
/**
2020-03-23 18:10:42 +01:00
* Show the list of recurring invoices.
2019-08-15 06:31:03 +02:00
*
2020-10-28 11:10:49 +01:00
* @return Factory|View
2019-08-15 06:31:03 +02:00
*/
public function index(ShowRecurringInvoicesRequest $request)
2019-08-15 07:19:00 +02:00
{
return $this->render('recurring_invoices.index');
2019-08-15 06:31:03 +02:00
}
/**
2020-03-23 18:10:42 +01:00
* Display the recurring invoice.
2019-08-15 06:31:03 +02:00
*
2020-03-23 18:10:42 +01:00
* @param ShowRecurringInvoiceRequest $request
* @param RecurringInvoice $recurring_invoice
2020-10-28 11:10:49 +01:00
* @return Factory|View
2019-08-15 06:31:03 +02:00
*/
public function show(ShowRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice)
2019-08-15 06:31:03 +02:00
{
2020-03-23 18:10:42 +01:00
return $this->render('recurring_invoices.show', [
'invoice' => $recurring_invoice->load('invoices'),
2020-03-23 18:10:42 +01:00
]);
2019-08-15 06:31:03 +02:00
}
public function requestCancellation(RequestCancellationRequest $request, RecurringInvoice $recurring_invoice)
{
nlog('outside cancellation');
2022-03-04 04:01:09 +01:00
if ($recurring_invoice->subscription?->allow_cancellation) {
nlog('inside the cancellation');
2022-03-04 04:01:09 +01:00
$nmo = new NinjaMailerObject;
$nmo->mailable = (new NinjaMailer((new ClientContactRequestCancellationObject($recurring_invoice, auth()->user()))->build()));
$nmo->company = $recurring_invoice->company;
$nmo->settings = $recurring_invoice->company->settings;
2022-03-04 04:01:09 +01:00
// $notifiable_users = $this->filterUsersByPermissions($recurring_invoice->company->company_users, $recurring_invoice, ['recurring_cancellation']);
$recurring_invoice->company->company_users->each(function ($company_user) use ($nmo) {
2022-03-04 04:01:09 +01:00
$methods = $this->findCompanyUserNotificationType($company_user, ['recurring_cancellation', 'all_notifications']);
//if mail is a method type -fire mail!!
if (($key = array_search('mail', $methods)) !== false) {
unset($methods[$key]);
$nmo->to_user = $company_user->user;
NinjaMailerJob::dispatch($nmo);
}
});
2021-02-14 22:32:59 +01:00
2022-03-04 04:01:09 +01:00
// $notifiable_users->each(function ($company_user) use($nmo){
// $nmo->to_user = $company_user->user;
// NinjaMailerJob::dispatch($nmo);
// });
//$recurring_invoice->user->notify(new ClientContactRequestCancellation($recurring_invoice, auth()->user()));
return $this->render('recurring_invoices.cancellation.index', [
'invoice' => $recurring_invoice,
]);
}
return back();
}
2019-08-15 06:31:03 +02:00
}