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;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
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;
|
2019-08-15 06:31:03 +02:00
|
|
|
use Yajra\DataTables\Facades\DataTables;
|
|
|
|
use Yajra\DataTables\Html\Builder;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class InvoiceController
|
|
|
|
* @package App\Http\Controllers\ClientPortal\InvoiceController
|
|
|
|
*/
|
|
|
|
|
|
|
|
class RecurringInvoiceController extends Controller
|
|
|
|
{
|
|
|
|
use MakesHash;
|
2019-11-05 23:52:57 +01:00
|
|
|
use MakesDates;
|
2019-08-15 06:31:03 +02:00
|
|
|
/**
|
|
|
|
* Show the list of Invoices
|
|
|
|
*
|
|
|
|
* @param \App\Filters\InvoiceFilters $filters The filters
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-08-15 13:10:02 +02:00
|
|
|
public function index(Builder $builder)
|
2019-08-15 07:19:00 +02:00
|
|
|
{
|
2019-08-15 13:10:02 +02:00
|
|
|
$invoices = RecurringInvoice::whereClientId(auth()->user()->client->id)
|
|
|
|
->whereIn('status_id', [RecurringInvoice::STATUS_PENDING, RecurringInvoice::STATUS_ACTIVE, RecurringInvoice::STATUS_COMPLETED])
|
|
|
|
->orderBy('status_id', 'asc')
|
2019-11-05 23:52:57 +01:00
|
|
|
->with('client')
|
2019-08-15 13:10:02 +02:00
|
|
|
->get();
|
2019-08-15 06:31:03 +02:00
|
|
|
|
|
|
|
if (request()->ajax()) {
|
2019-08-15 07:19:00 +02:00
|
|
|
return DataTables::of($invoices)->addColumn('action', function ($invoice) {
|
2019-12-30 22:59:12 +01:00
|
|
|
return '<a href="/client/recurring_invoices/'. $invoice->hashed_id .'" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i>'.ctrans('texts.view').'</a>';
|
|
|
|
})->addColumn('frequency_id', function ($invoice) {
|
|
|
|
return RecurringInvoice::frequencyForKey($invoice->frequency_id);
|
|
|
|
})
|
|
|
|
->editColumn('status_id', function ($invoice) {
|
2019-08-15 13:10:02 +02:00
|
|
|
return RecurringInvoice::badgeForStatus($invoice->status);
|
2019-08-15 06:31:03 +02:00
|
|
|
})
|
2019-12-30 22:59:12 +01:00
|
|
|
->editColumn('start_date', function ($invoice) {
|
2019-11-27 11:27:24 +01:00
|
|
|
return $this->formatDate($invoice->date, $invoice->client->date_format());
|
2019-11-05 23:52:57 +01:00
|
|
|
})
|
2019-12-30 22:59:12 +01:00
|
|
|
->editColumn('next_send_date', function ($invoice) {
|
2019-11-05 23:52:57 +01:00
|
|
|
return $this->formatDate($invoice->next_send_date, $invoice->client->date_format());
|
|
|
|
})
|
2019-12-30 22:59:12 +01:00
|
|
|
->editColumn('amount', function ($invoice) {
|
2019-11-05 23:52:57 +01:00
|
|
|
return Number::formatMoney($invoice->amount, $invoice->client);
|
|
|
|
})
|
2019-08-15 13:10:02 +02:00
|
|
|
->rawColumns(['action', 'status_id'])
|
2019-08-15 06:31:03 +02:00
|
|
|
->make(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$data['html'] = $builder;
|
|
|
|
|
|
|
|
return view('portal.default.recurring_invoices.index', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param \App\Models\Invoice $invoice The invoice
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2019-10-22 13:27:03 +02:00
|
|
|
public function show(ShowRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice)
|
2019-08-15 06:31:03 +02:00
|
|
|
{
|
2019-10-22 13:27:03 +02:00
|
|
|
$data = [
|
|
|
|
'invoice' => $recurring_invoice->load('invoices'),
|
|
|
|
];
|
|
|
|
|
|
|
|
return view('portal.default.recurring_invoices.show', $data);
|
2019-08-15 06:31:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-04 01:22:59 +01:00
|
|
|
public function requestCancellation(Request $request, RecurringInvoice $recurring_invoice)
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'invoice' => $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
|
|
|
|
|
|
|
return view('portal.default.recurring_invoices.request_cancellation', $data);
|
|
|
|
}
|
2019-08-15 06:31:03 +02:00
|
|
|
}
|