Proposals

This commit is contained in:
Hillel Coren 2018-02-04 18:42:13 +02:00
parent 1474627dda
commit 59143f3526
13 changed files with 93 additions and 47 deletions

View File

@ -88,6 +88,8 @@ class ProposalController extends BaseController
'title' => trans('texts.edit_proposal'), 'title' => trans('texts.edit_proposal'),
'quotes' => Invoice::scope()->with('client.contacts')->quotes()->orderBy('id')->get(), 'quotes' => Invoice::scope()->with('client.contacts')->quotes()->orderBy('id')->get(),
'templates' => ProposalTemplate::whereAccountId($account->id)->orWhereNull('account_id')->orderBy('name')->get(), 'templates' => ProposalTemplate::whereAccountId($account->id)->orWhereNull('account_id')->orderBy('name')->get(),
'quotePublicId' => $proposal->quote ? $proposal->quote->public_id : null,
'templatePublicId' => $proposal->proposal_template ? $proposal->proposal_template->public_id : null,
]; ];
return View::make('proposals.edit', $data); return View::make('proposals.edit', $data);

View File

@ -53,13 +53,11 @@ class ProposalTemplateController extends BaseController
{ {
$data = [ $data = [
'account' => auth()->user()->account, 'account' => auth()->user()->account,
'proposalTemplate' => null, 'template' => null,
'method' => 'POST', 'method' => 'POST',
'url' => 'proposals/templates', 'url' => 'proposals/templates',
'title' => trans('texts.new_proposal_template'), 'title' => trans('texts.new_proposal_template'),
'quotes' => Invoice::scope()->with('client.contacts')->quotes()->orderBy('id')->get(),
'templates' => ProposalTemplate::scope()->orderBy('name')->get(), 'templates' => ProposalTemplate::scope()->orderBy('name')->get(),
'quotePublicId' => $request->quote_id,
]; ];
return View::make('proposals/templates/edit', $data); return View::make('proposals/templates/edit', $data);
@ -78,12 +76,11 @@ class ProposalTemplateController extends BaseController
$data = [ $data = [
'account' => auth()->user()->account, 'account' => auth()->user()->account,
'proposalTemplate' => $proposalTemplate, 'template' => $proposalTemplate,
'method' => 'PUT', 'method' => 'PUT',
'url' => 'proposals/templates/' . $proposalTemplate->public_id, 'url' => 'proposals/templates/' . $proposalTemplate->public_id,
'title' => trans('texts.edit_proposal_template'), 'title' => trans('texts.edit_proposal_template'),
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), 'templates' => ProposalTemplate::scope()->orderBy('name')->get(),
'clientPublicId' => $proposalTemplate->client ? $proposalTemplate->client->public_id : null,
]; ];
return View::make('proposals/templates/edit', $data); return View::make('proposals/templates/edit', $data);

View File

@ -23,7 +23,7 @@ class CreateProposalRequest extends ProposalRequest
{ {
return [ return [
'quote_id' => 'required', 'quote_id' => 'required',
'template_id' => 'required', 'proposal_template_id' => 'required',
]; ];
} }
} }

View File

@ -22,7 +22,7 @@ class Proposal extends EntityModel
* @var array * @var array
*/ */
protected $fillable = [ protected $fillable = [
'template_id', 'private_notes',
]; ];
/** /**
@ -62,6 +62,14 @@ class Proposal extends EntityModel
return $this->belongsTo('App\Models\Invoice')->withTrashed(); return $this->belongsTo('App\Models\Invoice')->withTrashed();
} }
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function proposal_template()
{
return $this->belongsTo('App\Models\ProposalTemplate')->withTrashed();
}
public function getDisplayName() public function getDisplayName()
{ {
return 'TODO'; return 'TODO';

View File

@ -22,6 +22,8 @@ class ProposalTemplate extends EntityModel
* @var array * @var array
*/ */
protected $fillable = [ protected $fillable = [
'name',
'private_notes',
]; ];
/** /**

View File

@ -17,31 +17,37 @@ class ProposalDatatable extends EntityDatatable
[ [
'quote', 'quote',
function ($model) { function ($model) {
if (! Auth::user()->can('viewByOwner', [ENTITY_QUOTE, $model->user_id])) { if (! Auth::user()->can('viewByOwner', [ENTITY_QUOTE, $model->quote_user_id])) {
return $model->quote_number; return $model->quote_number;
} }
return link_to("quotes/{$model->quote_public_id}", $model->quote_number)->toHtml(); return link_to("quotes/{$model->quote_public_id}", $model->quote_number)->toHtml();
//$str = link_to("quotes/{$model->quote_public_id}", $model->quote_number)->toHtml();
//return $this->addNote($str, $model->private_notes);
}, },
], ],
[ [
'template', 'template',
function ($model) { function ($model) {
return $model->template_name; if (! Auth::user()->can('viewByOwner', [ENTITY_PROPOSAL_TEMPLATE, $model->template_user_id])) {
return $model->template;
}
return link_to("proposals/templates/{$model->template_public_id}/edit", $model->template)->toHtml();
}, },
], ],
[ [
'created', 'created_at',
function ($model) { function ($model) {
return Utils::fromSqlDate($model->created_at); if (! Auth::user()->can('viewByOwner', [ENTITY_PROPOSAL, $model->user_id])) {
return Utils::timestampToDateString(strtotime($model->created_at));
}
return link_to("proposals/{$model->public_id}/edit", Utils::timestampToDateString(strtotime($model->created_at)))->toHtml();
}, },
], ],
[ [
'valid_until', 'private_notes',
function ($model) { function ($model) {
return Utils::fromSqlDate($model->due_date); return $this->showWithTooltip($model->private_notes);
}, },
], ],
]; ];

View File

@ -34,6 +34,12 @@ class ProposalSnippetDatatable extends EntityDatatable
return link_to("proposals/categories/{$model->category_public_id}/edit", $model->category)->toHtml(); return link_to("proposals/categories/{$model->category_public_id}/edit", $model->category)->toHtml();
}, },
], ],
[
'private_notes',
function ($model) {
return $this->showWithTooltip($model->private_notes);
},
],
]; ];
} }

View File

@ -15,17 +15,23 @@ class ProposalTemplateDatatable extends EntityDatatable
{ {
return [ return [
[ [
'quote', 'name',
function ($model) { function ($model) {
if (! Auth::user()->can('editByOwner', [ENTITY_PROPOSAL_TEMPLATE, $model->user_id])) { if (! Auth::user()->can('editByOwner', [ENTITY_PROPOSAL_TEMPLATE, $model->user_id])) {
return $model->name; return $model->name;
} }
return link_to("proposal_templates/{$model->public_id}", $model->name)->toHtml(); return link_to("proposals/templates/{$model->public_id}", $model->name)->toHtml();
//$str = link_to("quotes/{$model->quote_public_id}", $model->quote_number)->toHtml(); //$str = link_to("quotes/{$model->quote_public_id}", $model->quote_number)->toHtml();
//return $this->addNote($str, $model->private_notes); //return $this->addNote($str, $model->private_notes);
}, },
], ],
[
'private_notes',
function ($model) {
return $this->showWithTooltip($model->private_notes);
},
],
]; ];
} }
@ -33,9 +39,9 @@ class ProposalTemplateDatatable extends EntityDatatable
{ {
return [ return [
[ [
trans('texts.edit_template'), trans('texts.edit_proposal_template'),
function ($model) { function ($model) {
return URL::to("proposal_templates/{$model->public_id}/edit"); return URL::to("proposals/templates/{$model->public_id}/edit");
}, },
function ($model) { function ($model) {
return Auth::user()->can('editByOwner', [ENTITY_PROPOSAL_TEMPLATE, $model->user_id]); return Auth::user()->can('editByOwner', [ENTITY_PROPOSAL_TEMPLATE, $model->user_id]);

View File

@ -4,6 +4,7 @@ namespace App\Ninja\Repositories;
use App\Models\Proposal; use App\Models\Proposal;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\ProposalTemplate;
use Auth; use Auth;
use DB; use DB;
use Utils; use Utils;
@ -27,6 +28,7 @@ class ProposalRepository extends BaseRepository
->leftjoin('invoices', 'invoices.id', '=', 'proposals.quote_id') ->leftjoin('invoices', 'invoices.id', '=', 'proposals.quote_id')
->leftjoin('clients', 'clients.id', '=', 'invoices.client_id') ->leftjoin('clients', 'clients.id', '=', 'invoices.client_id')
->leftJoin('contacts', 'contacts.client_id', '=', 'clients.id') ->leftJoin('contacts', 'contacts.client_id', '=', 'clients.id')
->leftJoin('proposal_templates', 'proposal_templates.id', '=', 'proposals.proposal_template_id')
->where('clients.deleted_at', '=', null) ->where('clients.deleted_at', '=', null)
->where('contacts.deleted_at', '=', null) ->where('contacts.deleted_at', '=', null)
->where('contacts.is_primary', '=', true) ->where('contacts.is_primary', '=', true)
@ -34,12 +36,19 @@ class ProposalRepository extends BaseRepository
'proposals.public_id', 'proposals.public_id',
'proposals.user_id', 'proposals.user_id',
'proposals.deleted_at', 'proposals.deleted_at',
'proposals.created_at',
'proposals.is_deleted', 'proposals.is_deleted',
'proposals.private_notes', 'proposals.private_notes',
DB::raw("COALESCE(NULLIF(clients.name,''), NULLIF(CONCAT(contacts.first_name, ' ', contacts.last_name),''), NULLIF(contacts.email,'')) client_name"), DB::raw("COALESCE(NULLIF(clients.name,''), NULLIF(CONCAT(contacts.first_name, ' ', contacts.last_name),''), NULLIF(contacts.email,'')) client_name"),
'clients.user_id as client_user_id', 'clients.user_id as client_user_id',
'clients.public_id as client_public_id', 'clients.public_id as client_public_id',
'invoices.invoice_number as quote' 'invoices.invoice_number as quote',
'invoices.invoice_number as quote_number',
'invoices.public_id as quote_public_id',
'invoices.user_id as quote_user_id',
'proposal_templates.name as template',
'proposal_templates.public_id as template_public_id',
'proposal_templates.user_id as template_user_id'
); );
$this->applyFilters($query, ENTITY_PROPOSAL); $this->applyFilters($query, ENTITY_PROPOSAL);
@ -73,6 +82,10 @@ class ProposalRepository extends BaseRepository
$proposal->quote_id = $input['quote_id'] ? Invoice::getPrivateId($input['quote_id']) : null; $proposal->quote_id = $input['quote_id'] ? Invoice::getPrivateId($input['quote_id']) : null;
} }
if (isset($input['proposal_template_id'])) {
$proposal->proposal_template_id = $input['proposal_template_id'] ? ProposalTemplate::getPrivateId($input['proposal_template_id']) : null;
}
$proposal->save(); $proposal->save();
return $proposal; return $proposal;

View File

@ -23,22 +23,13 @@ class ProposalTemplateRepository extends BaseRepository
{ {
$query = DB::table('proposal_templates') $query = DB::table('proposal_templates')
->where('proposal_templates.account_id', '=', Auth::user()->account_id) ->where('proposal_templates.account_id', '=', Auth::user()->account_id)
->leftjoin('invoices', 'invoices.id', '=', 'proposal_templates.quote_id')
->leftjoin('clients', 'clients.id', '=', 'invoices.client_id')
->leftJoin('contacts', 'contacts.client_id', '=', 'clients.id')
->where('clients.deleted_at', '=', null)
->where('contacts.deleted_at', '=', null)
->where('contacts.is_primary', '=', true)
->select( ->select(
'proposal_templates.name as proposal', 'proposal_templates.name',
'proposal_templates.public_id', 'proposal_templates.public_id',
'proposal_templates.user_id', 'proposal_templates.user_id',
'proposal_templates.deleted_at', 'proposal_templates.deleted_at',
'proposal_templates.is_deleted', 'proposal_templates.is_deleted',
'proposal_templates.private_notes', 'proposal_templates.private_notes'
DB::raw("COALESCE(NULLIF(clients.name,''), NULLIF(CONCAT(contacts.first_name, ' ', contacts.last_name),''), NULLIF(contacts.email,'')) client_name"),
'clients.user_id as client_user_id',
'clients.public_id as client_public_id'
); );
$this->applyFilters($query, ENTITY_PROPOSAL_TEMPLATE); $this->applyFilters($query, ENTITY_PROPOSAL_TEMPLATE);

View File

@ -46,7 +46,7 @@ class AddSubscriptionFormat extends Migration
$table->softDeletes(); $table->softDeletes();
$table->boolean('is_deleted')->default(false); $table->boolean('is_deleted')->default(false);
$table->unsignedInteger('proposal_category_id'); $table->unsignedInteger('proposal_category_id')->nullable();
$table->string('name'); $table->string('name');
$table->text('private_notes'); $table->text('private_notes');
@ -89,7 +89,7 @@ class AddSubscriptionFormat extends Migration
$table->boolean('is_deleted')->default(false); $table->boolean('is_deleted')->default(false);
$table->unsignedInteger('quote_id')->index(); $table->unsignedInteger('quote_id')->index();
$table->unsignedInteger('template_id')->index(); $table->unsignedInteger('proposal_template_id')->index();
$table->text('private_notes'); $table->text('private_notes');
$table->mediumText('html'); $table->mediumText('html');
$table->mediumText('css'); $table->mediumText('css');
@ -97,7 +97,7 @@ class AddSubscriptionFormat extends Migration
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('quote_id')->references('id')->on('invoices')->onDelete('cascade'); $table->foreign('quote_id')->references('id')->on('invoices')->onDelete('cascade');
$table->foreign('template_id')->references('id')->on('proposal_templates')->onDelete('cascade'); $table->foreign('proposal_template_id')->references('id')->on('proposal_templates')->onDelete('cascade');
$table->unsignedInteger('public_id')->index(); $table->unsignedInteger('public_id')->index();
$table->unique(['account_id', 'public_id']); $table->unique(['account_id', 'public_id']);

View File

@ -24,7 +24,7 @@
->id('mainForm') ->id('mainForm')
->rules([ ->rules([
'quote_id' => 'required', 'quote_id' => 'required',
'template_id' => 'required', 'proposal_template_id' => 'required',
]) !!} ]) !!}
@if ($proposal) @if ($proposal)
@ -44,13 +44,14 @@
{!! Former::select('quote_id')->addOption('', '') {!! Former::select('quote_id')->addOption('', '')
->label(trans('texts.quote')) ->label(trans('texts.quote'))
->addGroupClass('quote-select') !!} ->addGroupClass('quote-select') !!}
{!! Former::select('template_id')->addOption('', '') {!! Former::select('proposal_template_id')->addOption('', '')
->label(trans('texts.template')) ->label(trans('texts.template'))
->addGroupClass('template-select') !!} ->addGroupClass('template-select') !!}
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
{!! Former::textarea('private_notes')
->style('height: 100px') !!}
</div> </div>
</div> </div>
</div> </div>
@ -92,14 +93,23 @@
$quoteSelect.append(new Option(quote.invoice_number + ' - ' + getClientDisplayName(quote.client), quote.public_id)); $quoteSelect.append(new Option(quote.invoice_number + ' - ' + getClientDisplayName(quote.client), quote.public_id));
} }
@include('partials/entity_combobox', ['entityType' => ENTITY_QUOTE]) @include('partials/entity_combobox', ['entityType' => ENTITY_QUOTE])
if (quoteId) {
var quote = quoteMap[quoteId];
setComboboxValue($('.quote-select'), quote.public_id, quote.invoice_number + ' - ' + getClientDisplayName(quote.client));
}
var $proposal_templateSelect = $('select#template_id'); var templateId = {{ ! empty($templatePublicId) ? $templatePublicId : 0 }};
var $proposal_templateSelect = $('select#proposal_template_id');
for (var i = 0; i < templates.length; i++) { for (var i = 0; i < templates.length; i++) {
var template = templates[i]; var template = templates[i];
templateMap[template.public_id] = template; templateMap[template.public_id] = template;
$proposal_templateSelect.append(new Option(template.name, template.public_id)); $proposal_templateSelect.append(new Option(template.name, template.public_id));
} }
@include('partials/entity_combobox', ['entityType' => ENTITY_PROPOSAL_TEMPLATE]) @include('partials/entity_combobox', ['entityType' => ENTITY_PROPOSAL_TEMPLATE])
if (templateId) {
var template = templateMap[templateId];
setComboboxValue($('.template-select'), template.public_id, template.name);
}
var editor = grapesjs.init({ var editor = grapesjs.init({
container : '#gjs', container : '#gjs',

View File

@ -23,8 +23,7 @@
->method($method) ->method($method)
->id('mainForm') ->id('mainForm')
->rules([ ->rules([
'quote_id' => 'required', 'name' => 'required',
'template_id' => 'required',
]) !!} ]) !!}
@if ($template) @if ($template)
@ -42,16 +41,16 @@
<div class="panel-body"> <div class="panel-body">
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
{!! Former::select('quote_id')->addOption('', '') {!! Former::text('name') !!}
->label(trans('texts.quote'))
->addGroupClass('quote-select') !!}
</div> <!--
<div class="col-md-6">
{!! Former::select('template_id')->addOption('', '') {!! Former::select('template_id')->addOption('', '')
->label(trans('texts.template')) ->label(trans('texts.template'))
->addGroupClass('template-select') !!} ->addGroupClass('template-select') !!}
-->
</div>
<div class="col-md-6">
{!! Former::textarea('private_notes') !!}
</div> </div>
</div> </div>
</div> </div>
@ -77,7 +76,12 @@
var templates = {!! $templates !!}; var templates = {!! $templates !!};
var templateMap = {}; var templateMap = {};
function onSaveClick() {
$('#mainForm').submit();
}
$(function() { $(function() {
/*
var $proposal_templateSelect = $('select#template_id'); var $proposal_templateSelect = $('select#template_id');
for (var i = 0; i < templates.length; i++) { for (var i = 0; i < templates.length; i++) {
var template = templates[i]; var template = templates[i];
@ -85,6 +89,7 @@
$templateSelect.append(new Option(template.name, template.public_id)); $templateSelect.append(new Option(template.name, template.public_id));
} }
@include('partials/entity_combobox', ['entityType' => ENTITY_PROPOSAL_TEMPLATE]) @include('partials/entity_combobox', ['entityType' => ENTITY_PROPOSAL_TEMPLATE])
*/
var editor = grapesjs.init({ var editor = grapesjs.init({
container : '#gjs', container : '#gjs',