2019-08-15 06:31:03 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. 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;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2019-10-22 13:27:03 +02:00
|
|
|
use App\Http\Requests\ClientPortal\ShowRecurringInvoiceRequest;
|
2019-08-15 06:31:03 +02:00
|
|
|
use App\Models\RecurringInvoice;
|
2019-11-04 21:50:10 +01:00
|
|
|
use App\Notifications\ClientContactRequestCancellation;
|
|
|
|
use App\Notifications\ClientContactResetPassword;
|
2019-11-05 23:52:57 +01:00
|
|
|
use App\Utils\Number;
|
|
|
|
use App\Utils\Traits\MakesDates;
|
2019-08-15 06:31:03 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Http\Request;
|
2019-11-04 01:22:59 +01:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
2019-11-04 21:50:10 +01:00
|
|
|
use Illuminate\Support\Facades\Notification;
|
2020-04-09 04:18:07 +02:00
|
|
|
use Yajra\DataTables\Facades\DataTables;
|
2019-08-15 06:31:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class InvoiceController
|
|
|
|
* @package App\Http\Controllers\ClientPortal\InvoiceController
|
|
|
|
*/
|
|
|
|
|
|
|
|
class RecurringInvoiceController extends Controller
|
|
|
|
{
|
|
|
|
use MakesHash;
|
2019-11-05 23:52:57 +01:00
|
|
|
use MakesDates;
|
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-03-23 18:10:42 +01:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\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
|
|
|
{
|
2019-08-15 13:10:02 +02:00
|
|
|
$invoices = RecurringInvoice::whereClientId(auth()->user()->client->id)
|
2020-03-23 18:10:42 +01:00
|
|
|
->whereIn('status_id', [RecurringInvoice::STATUS_PENDING, RecurringInvoice::STATUS_ACTIVE, RecurringInvoice::STATUS_COMPLETED])
|
|
|
|
->orderBy('status_id', 'asc')
|
|
|
|
->with('client')
|
|
|
|
->paginate(10);
|
2019-08-15 06:31:03 +02:00
|
|
|
|
2020-03-23 18:10:42 +01:00
|
|
|
return $this->render('recurring_invoices.index', [
|
|
|
|
'invoices' => $invoices,
|
|
|
|
]);
|
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
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\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)
|
|
|
|
{
|
|
|
|
//todo double check the user is able to request a cancellation
|
2019-11-04 21:50:10 +01:00
|
|
|
//can add locale specific by chaining ->locale();
|
|
|
|
$recurring_invoice->user->notify(new ClientContactRequestCancellation($recurring_invoice, auth()->user()));
|
2019-11-04 01:22:59 +01:00
|
|
|
|
2020-03-23 18:10:42 +01:00
|
|
|
return $this->render('recurring_invoices.cancellation.index', [
|
|
|
|
'invoice' => $recurring_invoice,
|
|
|
|
]);
|
2019-11-04 01:22:59 +01:00
|
|
|
}
|
2019-08-15 06:31:03 +02:00
|
|
|
}
|