2019-08-15 06:31:03 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-08-15 06:31:03 +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-08-15 06:31:03 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\ClientPortal;
|
|
|
|
|
2020-04-23 00:49:23 +02:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Http\Requests\ClientPortal\ShowRecurringInvoiceRequest;
|
2021-02-14 22:32:59 +01:00
|
|
|
use App\Jobs\Mail\NinjaMailer;
|
2021-02-14 23:12:14 +01:00
|
|
|
use App\Jobs\Mail\NinjaMailerJob;
|
2021-02-14 22:32:59 +01:00
|
|
|
use App\Jobs\Mail\NinjaMailerObject;
|
|
|
|
use App\Mail\RecurringInvoice\ClientContactRequestCancellationObject;
|
2020-09-06 11:38:10 +02:00
|
|
|
use App\Models\RecurringInvoice;
|
|
|
|
use App\Notifications\ClientContactRequestCancellation;
|
|
|
|
use App\Utils\Traits\MakesDates;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
2021-02-14 23:12:14 +01:00
|
|
|
use App\Utils\Traits\Notifications\UserNotifies;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Illuminate\Contracts\View\Factory;
|
2020-09-06 11:38:10 +02:00
|
|
|
use Illuminate\Http\Request;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Illuminate\View\View;
|
2019-08-15 06:31:03 +02:00
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class InvoiceController.
|
2019-08-15 06:31:03 +02:00
|
|
|
*/
|
|
|
|
class RecurringInvoiceController extends Controller
|
|
|
|
{
|
|
|
|
use MakesHash;
|
2019-11-05 23:52:57 +01:00
|
|
|
use MakesDates;
|
2021-02-14 23:12:14 +01:00
|
|
|
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
|
|
|
*/
|
2020-04-08 14:19:07 +02:00
|
|
|
public function index()
|
2019-08-15 07:19:00 +02:00
|
|
|
{
|
2020-04-23 00:49:23 +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
|
|
|
*/
|
2019-10-22 13:27: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', [
|
2019-10-22 13:27:03 +02:00
|
|
|
'invoice' => $recurring_invoice->load('invoices'),
|
2020-03-23 18:10:42 +01:00
|
|
|
]);
|
2019-08-15 06:31:03 +02:00
|
|
|
}
|
|
|
|
|
2019-11-04 01:22:59 +01:00
|
|
|
public function requestCancellation(Request $request, RecurringInvoice $recurring_invoice)
|
|
|
|
{
|
2021-04-01 16:38:46 +02:00
|
|
|
if (is_null($recurring_invoice->subscription_id) || optional($recurring_invoice->subscription)->allow_cancellation) {
|
|
|
|
$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;
|
2021-02-14 23:12:14 +01:00
|
|
|
|
2021-04-01 16:38:46 +02:00
|
|
|
$notifiable_users = $this->filterUsersByPermissions($recurring_invoice->company->company_users, $recurring_invoice, ['recurring_cancellation']);
|
2021-02-14 23:12:14 +01:00
|
|
|
|
2021-04-01 16:38:46 +02:00
|
|
|
$notifiable_users->each(function ($company_user) use($nmo){
|
2021-02-14 23:12:14 +01:00
|
|
|
|
2021-04-01 16:38:46 +02:00
|
|
|
$nmo->to_user = $company_user->user;
|
|
|
|
NinjaMailerJob::dispatch($nmo);
|
2021-02-14 23:12:14 +01:00
|
|
|
|
2021-04-01 16:38:46 +02:00
|
|
|
});
|
2021-02-14 22:32:59 +01:00
|
|
|
|
2021-04-01 16:38:46 +02:00
|
|
|
//$recurring_invoice->user->notify(new ClientContactRequestCancellation($recurring_invoice, auth()->user()));
|
2019-11-04 01:22:59 +01:00
|
|
|
|
2021-04-01 16:38:46 +02:00
|
|
|
return $this->render('recurring_invoices.cancellation.index', [
|
|
|
|
'invoice' => $recurring_invoice,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return back();
|
2019-11-04 01:22:59 +01:00
|
|
|
}
|
2019-08-15 06:31:03 +02:00
|
|
|
}
|