1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

Proposals

This commit is contained in:
Hillel Coren 2018-02-08 13:41:22 +02:00
parent e822ec04b3
commit 3da023c1a6
15 changed files with 64 additions and 15 deletions

View File

@ -70,15 +70,27 @@ class ProposalTemplateController extends BaseController
return redirect("proposals/templates/$publicId/edit");
}
public function edit(ProposalTemplateRequest $request)
public function edit(ProposalTemplateRequest $request, $publicId = false, $clone = false)
{
$proposalTemplate = $request->entity();
$template = $request->entity();
if ($clone) {
$template->id = null;
$template->public_id = null;
$template->name = '';
$template->private_notes = '';
$method = 'POST';
$url = 'proposals/templates';
} else {
$method = 'PUT';
$url = 'proposals/templates/' . $template->public_id;
}
$data = [
'account' => auth()->user()->account,
'template' => $proposalTemplate,
'method' => 'PUT',
'url' => 'proposals/templates/' . $proposalTemplate->public_id,
'template' => $template,
'method' => $method,
'url' => $url,
'title' => trans('texts.edit_proposal_template'),
'templates' => ProposalTemplate::scope()->orderBy('name')->get(),
];
@ -86,6 +98,11 @@ class ProposalTemplateController extends BaseController
return View::make('proposals/templates/edit', $data);
}
public function cloneProposal(ProposalTemplateRequest $request, $publicId)
{
return self::edit($request, $publicId, true);
}
public function store(CreateProposalTemplateRequest $request)
{
$proposalTemplate = $this->proposalTemplateService->save($request->input());

View File

@ -22,7 +22,7 @@ class CreateProposalCategoryRequest extends ProposalCategoryRequest
public function rules()
{
return [
'name' => 'required',
'name' => sprintf('required|unique:proposal_categories,name,,id,account_id,%s', $this->user()->account_id),
];
}
}

View File

@ -22,7 +22,7 @@ class CreateProposalSnippetRequest extends ProposalSnippetRequest
public function rules()
{
return [
'name' => 'required',
'name' => sprintf('required|unique:proposal_snippets,name,,id,account_id,%s', $this->user()->account_id),
];
}
}

View File

@ -22,7 +22,7 @@ class CreateProposalTemplateRequest extends ProposalTemplateRequest
public function rules()
{
return [
'name' => 'required',
'name' => sprintf('required|unique:proposal_templates,name,,id,account_id,%s', $this->user()->account_id),
];
}
}

View File

@ -26,7 +26,7 @@ class UpdateProposalCategoryRequest extends ProposalCategoryRequest
}
return [
'name' => 'required',
'name' => sprintf('required|unique:proposal_categories,name,,id,account_id,%s', $this->user()->account_id),
];
}
}

View File

@ -26,7 +26,7 @@ class UpdateProposalSnippetRequest extends ProposalSnippetRequest
}
return [
'name' => 'required',
'name' => sprintf('required|unique:proposal_snippets,name,%s,id,account_id,%s', $this->entity()->id, $this->user()->account_id),
];
}
}

View File

@ -26,7 +26,7 @@ class UpdateProposalTemplateRequest extends ProposalTemplateRequest
}
return [
'name' => 'required',
'name' => sprintf('required|unique:proposal_templates,name,%s,id,account_id,%s', $this->entity()->id, $this->user()->account_id),
];
}
}

View File

@ -87,6 +87,7 @@ class HistoryUtils
ENTITY_TASK,
ENTITY_EXPENSE,
ENTITY_PROJECT,
ENTITY_PROPOSAL,
//ENTITY_RECURRING_EXPENSE,
];
@ -142,6 +143,9 @@ class HistoryUtils
} elseif (method_exists($entity, 'client') && $entity->client) {
$object->client_id = $entity->client->public_id;
$object->client_name = $entity->client->getDisplayName();
} elseif (method_exists($entity, 'invoice') && $entity->invoice) {
$object->client_id = $entity->invoice->client->public_id;
$object->client_name = $entity->invoice->client->getDisplayName();
} else {
$object->client_id = 0;
$object->client_name = 0;

View File

@ -17,6 +17,10 @@ class Proposal extends EntityModel
* @var array
*/
protected $dates = ['deleted_at'];
/**
* @var string
*/
protected $presenter = 'App\Ninja\Presenters\ProposalPresenter';
/**
* @var array
@ -82,7 +86,7 @@ class Proposal extends EntityModel
public function getDisplayName()
{
return 'TODO';
return $this->invoice->invoice_number;
}
}

View File

@ -115,7 +115,7 @@ class ExpenseDatatable extends EntityDatatable
return URL::to("expenses/{$model->public_id}/clone");
},
function ($model) {
return Auth::user()->can('create', ENTITY_EXPENSE);
return Auth::user()->can('viewByOwner', [ENTITY_EXPENSE, $model->user_id]) && Auth::user()->can('create', ENTITY_EXPENSE);
},
],
[

View File

@ -96,7 +96,7 @@ class InvoiceDatatable extends EntityDatatable
return URL::to("invoices/{$model->public_id}/clone");
},
function ($model) {
return Auth::user()->can('create', ENTITY_INVOICE);
return Auth::user()->can('viewByOwner', [ENTITY_INVOICE, $model->user_id]) && Auth::user()->can('create', ENTITY_INVOICE);
},
],
[
@ -105,7 +105,7 @@ class InvoiceDatatable extends EntityDatatable
return URL::to("quotes/{$model->public_id}/clone");
},
function ($model) {
return Auth::user()->can('create', ENTITY_QUOTE);
return Auth::user()->can('viewByOwner', [ENTITY_INVOICE, $model->user_id]) && Auth::user()->can('create', ENTITY_QUOTE);
},
],
[

View File

@ -53,6 +53,15 @@ class ProposalTemplateDatatable extends EntityDatatable
return Auth::user()->can('editByOwner', [ENTITY_PROPOSAL_TEMPLATE, $model->user_id]);
},
],
[
trans('texts.clone_proposal_template'),
function ($model) {
return URL::to("proposals/templates/{$model->public_id}/clone");
},
function ($model) {
return Auth::user()->can('editByOwner', [ENTITY_PROPOSAL_TEMPLATE, $model->user_id]);
},
],
];
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Ninja\Presenters;
use Utils;
/**
* Class ProposalPresenter.
*/
class ProposalPresenter extends EntityPresenter
{
}

View File

@ -2727,6 +2727,7 @@ $LANG = array(
'icon' => 'Icon',
'proposal_not_found' => 'The requested proposal is not available',
'create_proposal_category' => 'Create category',
'clone_proposal_template' => 'Clone Template',
);

View File

@ -218,6 +218,7 @@ Route::group(['middleware' => ['lookup:user', 'auth:user']], function () {
Route::resource('proposals/snippets', 'ProposalSnippetController');
Route::get('api/proposal_snippets', 'ProposalSnippetController@getDatatable');
Route::get('proposals/templates/{proposal_templates}/clone', 'ProposalTemplateController@cloneProposal');
Route::post('proposals/templates/bulk', 'ProposalTemplateController@bulk');
Route::get('proposals/templates/{proposal_templates}/edit', 'ProposalTemplateController@edit');
Route::get('proposals/templates/create', 'ProposalTemplateController@create');