1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Http/Controllers/ProposalCategoryController.php

129 lines
4.0 KiB
PHP
Raw Normal View History

2018-01-31 10:10:15 +01:00
<?php
namespace App\Http\Controllers;
use App\Http\Requests\CreateProposalCategoryRequest;
use App\Http\Requests\ProposalCategoryRequest;
use App\Http\Requests\UpdateProposalCategoryRequest;
use App\Models\Invoice;
use App\Models\ProposalCategory;
use App\Ninja\Datatables\ProposalCategoryDatatable;
use App\Ninja\Repositories\ProposalCategoryRepository;
use App\Services\ProposalCategoryService;
use Auth;
use Input;
use Session;
use View;
class ProposalCategoryController extends BaseController
{
protected $proposalCategoryRepo;
protected $proposalCategoryService;
protected $entityType = ENTITY_PROPOSAL_CATEGORY;
public function __construct(ProposalCategoryRepository $proposalCategoryRepo, ProposalCategoryService $proposalCategoryService)
{
$this->proposalCategoryRepo = $proposalCategoryRepo;
$this->proposalCategoryService = $proposalCategoryService;
}
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
return View::make('list_wrapper', [
'entityType' => ENTITY_PROPOSAL_CATEGORY,
'datatable' => new ProposalCategoryDatatable(),
'title' => trans('texts.proposal_categories'),
]);
}
public function getDatatable($expensePublicId = null)
{
$search = Input::get('sSearch');
$userId = Auth::user()->filterId();
return $this->proposalCategoryService->getDatatable($search, $userId);
}
public function create(ProposalCategoryRequest $request)
{
$data = [
'account' => auth()->user()->account,
2018-01-31 13:21:33 +01:00
'category' => null,
2018-01-31 10:10:15 +01:00
'method' => 'POST',
2018-01-31 12:59:53 +01:00
'url' => 'proposals/categories',
2018-01-31 10:10:15 +01:00
'title' => trans('texts.new_proposal_category'),
'quotes' => Invoice::scope()->with('client.contacts')->quotes()->orderBy('id')->get(),
'templates' => ProposalCategory::scope()->orderBy('name')->get(),
'quotePublicId' => $request->quote_id,
];
2018-01-31 12:59:53 +01:00
return View::make('proposals/categories.edit', $data);
2018-01-31 10:10:15 +01:00
}
2018-01-31 15:33:33 +01:00
public function show($publicId)
{
Session::reflash();
return redirect("proposals/categories/$publicId/edit");
}
2018-01-31 10:10:15 +01:00
public function edit(ProposalCategoryRequest $request)
{
$proposalCategory = $request->entity();
$data = [
'account' => auth()->user()->account,
2018-01-31 13:21:33 +01:00
'category' => $proposalCategory,
2018-01-31 10:10:15 +01:00
'method' => 'PUT',
2018-01-31 12:59:53 +01:00
'url' => 'proposals/categories/' . $proposalCategory->public_id,
2018-01-31 10:10:15 +01:00
'title' => trans('texts.edit_proposal_category'),
];
2018-01-31 12:51:18 +01:00
return View::make('proposals/categories.edit', $data);
2018-01-31 10:10:15 +01:00
}
public function store(CreateProposalCategoryRequest $request)
{
$proposalCategory = $this->proposalCategoryService->save($request->input());
Session::flash('message', trans('texts.created_proposal_category'));
return redirect()->to($proposalCategory->getRoute());
}
public function update(UpdateProposalCategoryRequest $request)
{
$proposalCategory = $this->proposalCategoryService->save($request->input(), $request->entity());
Session::flash('message', trans('texts.updated_proposal_category'));
$action = Input::get('action');
if (in_array($action, ['archive', 'delete', 'restore'])) {
return self::bulk();
}
return redirect()->to($proposalCategory->getRoute());
}
public function bulk()
{
$action = Input::get('action');
$ids = Input::get('public_id') ? Input::get('public_id') : Input::get('ids');
$count = $this->proposalCategoryService->bulk($ids, $action);
if ($count > 0) {
$field = $count == 1 ? "{$action}d_proposal_category" : "{$action}d_proposal_categories";
$message = trans("texts.$field", ['count' => $count]);
Session::flash('message', $message);
}
2018-01-31 12:59:53 +01:00
return redirect()->to('/proposals/categories');
2018-01-31 10:10:15 +01:00
}
}