2018-01-31 10:10:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Http\Requests\CreateProposalTemplateRequest;
|
|
|
|
use App\Http\Requests\ProposalTemplateRequest;
|
|
|
|
use App\Http\Requests\UpdateProposalTemplateRequest;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\ProposalTemplate;
|
|
|
|
use App\Ninja\Datatables\ProposalTemplateDatatable;
|
|
|
|
use App\Ninja\Repositories\ProposalTemplateRepository;
|
|
|
|
use App\Services\ProposalTemplateService;
|
|
|
|
use Auth;
|
|
|
|
use Input;
|
|
|
|
use Session;
|
|
|
|
use View;
|
|
|
|
|
|
|
|
class ProposalTemplateController extends BaseController
|
|
|
|
{
|
|
|
|
protected $proposalTemplateRepo;
|
|
|
|
protected $proposalTemplateService;
|
|
|
|
protected $entityType = ENTITY_PROPOSAL_TEMPLATE;
|
|
|
|
|
|
|
|
public function __construct(ProposalTemplateRepository $proposalTemplateRepo, ProposalTemplateService $proposalTemplateService)
|
|
|
|
{
|
|
|
|
$this->proposalTemplateRepo = $proposalTemplateRepo;
|
|
|
|
$this->proposalTemplateService = $proposalTemplateService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
return View::make('list_wrapper', [
|
|
|
|
'entityType' => ENTITY_PROPOSAL_TEMPLATE,
|
|
|
|
'datatable' => new ProposalTemplateDatatable(),
|
|
|
|
'title' => trans('texts.proposal_templates'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDatatable($expensePublicId = null)
|
|
|
|
{
|
|
|
|
$search = Input::get('sSearch');
|
|
|
|
$userId = Auth::user()->filterId();
|
|
|
|
|
|
|
|
return $this->proposalTemplateService->getDatatable($search, $userId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create(ProposalTemplateRequest $request)
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'account' => auth()->user()->account,
|
2018-02-04 17:42:13 +01:00
|
|
|
'template' => null,
|
2018-01-31 10:10:15 +01:00
|
|
|
'method' => 'POST',
|
2018-01-31 12:59:53 +01:00
|
|
|
'url' => 'proposals/templates',
|
2018-01-31 10:10:15 +01:00
|
|
|
'title' => trans('texts.new_proposal_template'),
|
2018-01-31 12:51:18 +01:00
|
|
|
'templates' => ProposalTemplate::scope()->orderBy('name')->get(),
|
2018-01-31 10:10:15 +01:00
|
|
|
];
|
|
|
|
|
2018-01-31 12:51:18 +01:00
|
|
|
return View::make('proposals/templates/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/templates/$publicId/edit");
|
|
|
|
}
|
|
|
|
|
2018-01-31 10:10:15 +01:00
|
|
|
public function edit(ProposalTemplateRequest $request)
|
|
|
|
{
|
|
|
|
$proposalTemplate = $request->entity();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'account' => auth()->user()->account,
|
2018-02-04 17:42:13 +01:00
|
|
|
'template' => $proposalTemplate,
|
2018-01-31 10:10:15 +01:00
|
|
|
'method' => 'PUT',
|
2018-01-31 12:59:53 +01:00
|
|
|
'url' => 'proposals/templates/' . $proposalTemplate->public_id,
|
2018-01-31 10:10:15 +01:00
|
|
|
'title' => trans('texts.edit_proposal_template'),
|
2018-02-04 17:42:13 +01:00
|
|
|
'templates' => ProposalTemplate::scope()->orderBy('name')->get(),
|
2018-01-31 10:10:15 +01:00
|
|
|
];
|
|
|
|
|
2018-01-31 12:51:18 +01:00
|
|
|
return View::make('proposals/templates/edit', $data);
|
2018-01-31 10:10:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function store(CreateProposalTemplateRequest $request)
|
|
|
|
{
|
|
|
|
$proposalTemplate = $this->proposalTemplateService->save($request->input());
|
|
|
|
|
|
|
|
Session::flash('message', trans('texts.created_proposal_template'));
|
|
|
|
|
|
|
|
return redirect()->to($proposalTemplate->getRoute());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(UpdateProposalTemplateRequest $request)
|
|
|
|
{
|
|
|
|
$proposalTemplate = $this->proposalTemplateService->save($request->input(), $request->entity());
|
|
|
|
|
|
|
|
Session::flash('message', trans('texts.updated_proposal_template'));
|
|
|
|
|
|
|
|
$action = Input::get('action');
|
|
|
|
if (in_array($action, ['archive', 'delete', 'restore'])) {
|
|
|
|
return self::bulk();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->to($proposalTemplate->getRoute());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bulk()
|
|
|
|
{
|
|
|
|
$action = Input::get('action');
|
|
|
|
$ids = Input::get('public_id') ? Input::get('public_id') : Input::get('ids');
|
|
|
|
|
|
|
|
$count = $this->proposalTemplateService->bulk($ids, $action);
|
|
|
|
|
|
|
|
if ($count > 0) {
|
|
|
|
$field = $count == 1 ? "{$action}d_proposal_template" : "{$action}d_proposal_templates";
|
|
|
|
$message = trans("texts.$field", ['count' => $count]);
|
|
|
|
Session::flash('message', $message);
|
|
|
|
}
|
|
|
|
|
2018-01-31 12:59:53 +01:00
|
|
|
return redirect()->to('/proposals/templates');
|
2018-01-31 10:10:15 +01:00
|
|
|
}
|
|
|
|
}
|