1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Http/Controllers/RecurringInvoiceController.php

246 lines
7.4 KiB
PHP
Raw Normal View History

2019-04-02 08:36:49 +02:00
<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
2019-04-02 08:36:49 +02:00
namespace App\Http\Controllers;
2019-05-03 00:29:04 +02:00
use App\Factory\CloneRecurringInvoiceFactory;
use App\Factory\CloneRecurringInvoiceToQuoteFactory;
use App\Factory\RecurringInvoiceFactory;
use App\Filters\RecurringInvoiceFilters;
use App\Http\Requests\RecurringInvoice\ActionRecurringInvoiceRequest;
use App\Http\Requests\RecurringInvoice\CreateRecurringInvoiceRequest;
use App\Http\Requests\RecurringInvoice\DestroyRecurringInvoiceRequest;
use App\Http\Requests\RecurringInvoice\EditRecurringInvoiceRequest;
use App\Http\Requests\RecurringInvoice\ShowRecurringInvoiceRequest;
use App\Http\Requests\RecurringInvoice\StoreRecurringInvoiceRequest;
use App\Http\Requests\RecurringInvoice\UpdateRecurringInvoiceRequest;
use App\Jobs\Entity\ActionEntity;
use App\Models\RecurringInvoice;
use App\Repositories\BaseRepository;
use App\Repositories\RecurringInvoiceRepository;
use App\Transformers\RecurringInvoiceTransformer;
use App\Utils\Traits\MakesHash;
2019-04-02 08:36:49 +02:00
use Illuminate\Http\Request;
2019-05-03 00:29:04 +02:00
use Illuminate\Support\Facades\Log;
2019-04-02 08:36:49 +02:00
2019-05-03 00:29:04 +02:00
/**
* Class RecurringInvoiceController
* @package App\Http\Controllers\RecurringInvoiceController
*/
class RecurringInvoiceController extends BaseController
2019-04-02 08:36:49 +02:00
{
2019-05-03 00:29:04 +02:00
use MakesHash;
protected $entity_type = RecurringInvoice::class;
protected $entity_transformer = RecurringInvoiceTransformer::class;
/**
* @var RecurringInvoiceRepository
*/
protected $recurring_invoice_repo;
protected $base_repo;
/**
* RecurringInvoiceController constructor.
*
* @param \App\Repositories\RecurringInvoiceRepository $recurring_invoice_repo The RecurringInvoice repo
*/
public function __construct(RecurringInvoiceRepository $recurring_invoice_repo)
{
parent::__construct();
$this->recurring_invoice_repo = $recurring_invoice_repo;
}
2019-04-02 08:36:49 +02:00
/**
2019-05-03 00:29:04 +02:00
* Show the list of recurring_invoices
*
* @param \App\Filters\RecurringInvoiceFilters $filters The filters
2019-04-02 08:36:49 +02:00
*
* @return \Illuminate\Http\Response
*/
2019-05-03 00:29:04 +02:00
public function index(RecurringInvoiceFilters $filters)
2019-04-02 08:36:49 +02:00
{
2019-05-03 00:29:04 +02:00
$recurring_invoices = RecurringInvoice::filter($filters);
return $this->listResponse($recurring_invoices);
2019-04-02 08:36:49 +02:00
}
/**
* Show the form for creating a new resource.
*
2019-05-03 00:29:04 +02:00
* @param \App\Http\Requests\RecurringInvoice\CreateRecurringInvoiceRequest $request The request
*
2019-04-02 08:36:49 +02:00
* @return \Illuminate\Http\Response
*/
2019-05-03 00:29:04 +02:00
public function create(CreateRecurringInvoiceRequest $request)
2019-04-02 08:36:49 +02:00
{
2019-05-03 00:29:04 +02:00
$recurring_invoice = RecurringInvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id);
return $this->itemResponse($recurring_invoice);
2019-04-02 08:36:49 +02:00
}
2019-05-03 00:29:04 +02:00
2019-04-02 08:36:49 +02:00
/**
* Store a newly created resource in storage.
*
2019-05-03 00:29:04 +02:00
* @param \App\Http\Requests\RecurringInvoice\StoreRecurringInvoiceRequest $request The request
*
2019-04-02 08:36:49 +02:00
* @return \Illuminate\Http\Response
*/
2019-05-03 00:29:04 +02:00
public function store(StoreRecurringInvoiceRequest $request)
2019-04-02 08:36:49 +02:00
{
2019-05-03 00:29:04 +02:00
2019-05-30 01:58:00 +02:00
$recurring_invoice = $this->recurring_invoice_repo->save($request->all(), RecurringInvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id));
2019-05-03 00:29:04 +02:00
return $this->itemResponse($recurring_invoice);
2019-04-02 08:36:49 +02:00
}
/**
* Display the specified resource.
*
2019-05-03 00:29:04 +02:00
* @param \App\Http\Requests\RecurringInvoice\ShowRecurringInvoiceRequest $request The request
* @param \App\Models\RecurringInvoice $recurring_invoice The RecurringInvoice
*
2019-04-02 08:36:49 +02:00
* @return \Illuminate\Http\Response
*/
2019-05-03 00:29:04 +02:00
public function show(ShowRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice)
2019-04-02 08:36:49 +02:00
{
2019-05-03 00:29:04 +02:00
return $this->itemResponse($recurring_invoice);
2019-04-02 08:36:49 +02:00
}
/**
* Show the form for editing the specified resource.
*
2019-05-03 00:29:04 +02:00
* @param \App\Http\Requests\RecurringInvoice\EditRecurringInvoiceRequest $request The request
* @param \App\Models\RecurringInvoice $recurring_invoice The RecurringInvoice
*
2019-04-02 08:36:49 +02:00
* @return \Illuminate\Http\Response
*/
2019-05-03 00:29:04 +02:00
public function edit(EditRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice)
2019-04-02 08:36:49 +02:00
{
2019-05-03 00:29:04 +02:00
return $this->itemResponse($recurring_invoice);
}
2019-04-02 08:36:49 +02:00
/**
* Update the specified resource in storage.
*
2019-05-03 00:29:04 +02:00
* @param \App\Http\Requests\RecurringInvoice\UpdateRecurringInvoiceRequest $request The request
* @param \App\Models\RecurringInvoice $recurring_invoice The RecurringInvoice
*
2019-04-02 08:36:49 +02:00
* @return \Illuminate\Http\Response
*/
2019-05-03 00:29:04 +02:00
public function update(UpdateRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice)
2019-04-02 08:36:49 +02:00
{
2019-05-03 00:29:04 +02:00
2019-05-30 01:58:00 +02:00
$recurring_invoice = $this->recurring_invoice_repo->save($request->all(), $recurring_invoice);
2019-05-03 00:29:04 +02:00
return $this->itemResponse($recurring_invoice);
2019-04-02 08:36:49 +02:00
}
/**
* Remove the specified resource from storage.
*
2019-05-03 00:29:04 +02:00
* @param \App\Http\Requests\RecurringInvoice\DestroyRecurringInvoiceRequest $request
* @param \App\Models\RecurringInvoice $recurring_invoice
*
* @return \Illuminate\Http\Response
2019-04-02 08:36:49 +02:00
*/
2019-05-03 00:29:04 +02:00
public function destroy(DestroyRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice)
2019-04-02 08:36:49 +02:00
{
2019-05-03 00:29:04 +02:00
$recurring_invoice->delete();
return response()->json([], 200);
}
/**
* Perform bulk actions on the list view
*
* @return Collection
*/
public function bulk()
{
$action = request()->input('action');
$ids = request()->input('ids');
$recurring_invoices = RecurringInvoice::withTrashed()->find($ids);
$recurring_invoices->each(function ($recurring_invoice, $key) use($action){
if(auth()->user()->can('edit', $recurring_invoice))
2019-05-03 09:35:49 +02:00
$this->recurring_invoice_repo->{$action}($recurring_invoice);
2019-05-03 00:29:04 +02:00
});
//todo need to return the updated dataset
return $this->listResponse(RecurringInvoice::withTrashed()->whereIn('id', $ids));
}
public function action(ActionRecurringInvoiceRequest $request, RecurringInvoice $recurring_invoice, $action)
{
switch ($action) {
case 'clone_to_RecurringInvoice':
// $recurring_invoice = CloneRecurringInvoiceFactory::create($recurring_invoice, auth()->user()->id);
// return $this->itemResponse($recurring_invoice);
break;
case 'clone_to_quote':
// $quote = CloneRecurringInvoiceToQuoteFactory::create($recurring_invoice, auth()->user()->id);
// todo build the quote transformer and return response here
break;
case 'history':
# code...
break;
case 'delivery_note':
# code...
break;
case 'mark_paid':
# code...
break;
case 'archive':
# code...
break;
case 'delete':
# code...
break;
case 'email':
//dispatch email to queue
break;
default:
# code...
break;
}
2019-04-02 08:36:49 +02:00
}
2019-05-03 00:29:04 +02:00
2019-04-02 08:36:49 +02:00
}