diff --git a/app/Http/Controllers/ProposalController.php b/app/Http/Controllers/ProposalController.php index 0824cb51c17c..29d0503e60df 100644 --- a/app/Http/Controllers/ProposalController.php +++ b/app/Http/Controllers/ProposalController.php @@ -121,8 +121,8 @@ class ProposalController extends BaseController public function bulk() { - $action = Input::get('action'); - $ids = Input::get('public_id') ? Input::get('public_id') : Input::get('ids'); + $action = Input::get('bulk_action') ?: Input::get('action'); + $ids = Input::get('bulk_public_id') ?: (Input::get('public_id') ?: Input::get('ids')); $count = $this->proposalService->bulk($ids, $action); diff --git a/app/Models/Proposal.php b/app/Models/Proposal.php index ad8d4db5ee73..37ffe27b2402 100644 --- a/app/Models/Proposal.php +++ b/app/Models/Proposal.php @@ -68,6 +68,14 @@ class Proposal extends EntityModel return $this->belongsTo('App\Models\Invoice')->withTrashed(); } + /** + * @return mixed + */ + public function invitations() + { + return $this->hasMany('App\Models\ProposalInvitation')->orderBy('proposal_invitations.contact_id'); + } + /** * @return mixed */ diff --git a/app/Ninja/Datatables/ProposalDatatable.php b/app/Ninja/Datatables/ProposalDatatable.php index 00f2b18bacc1..596f28f7a430 100644 --- a/app/Ninja/Datatables/ProposalDatatable.php +++ b/app/Ninja/Datatables/ProposalDatatable.php @@ -24,6 +24,16 @@ class ProposalDatatable extends EntityDatatable return link_to("quotes/{$model->invoice_public_id}", $model->invoice_number)->toHtml(); }, ], + [ + 'client', + function ($model) { + if (! Auth::user()->can('viewByOwner', [ENTITY_CLIENT, $model->client_user_id])) { + return $model->client; + } + + return link_to("clients/{$model->client_public_id}", $model->client)->toHtml(); + }, + ], [ 'template', function ($model) { diff --git a/app/Ninja/Presenters/ProposalPresenter.php b/app/Ninja/Presenters/ProposalPresenter.php index f2b43cf817e8..7f4c826f1072 100644 --- a/app/Ninja/Presenters/ProposalPresenter.php +++ b/app/Ninja/Presenters/ProposalPresenter.php @@ -3,11 +3,31 @@ namespace App\Ninja\Presenters; use Utils; +use DropdownButton; /** * Class ProposalPresenter. */ class ProposalPresenter extends EntityPresenter { + public function moreActions() + { + $proposal = $this->entity; + $invitation = $proposal->invitations->first(); + $actions = []; + + $actions[] = ['url' => $invitation->getLink('proposal'), 'label' => trans("texts.view_as_recipient")]; + + $actions[] = DropdownButton::DIVIDER; + + if (! $proposal->trashed()) { + $actions[] = ['url' => 'javascript:onArchiveClick()', 'label' => trans("texts.archive_proposal")]; + } + if (! $proposal->is_deleted) { + $actions[] = ['url' => 'javascript:onDeleteClick()', 'label' => trans("texts.delete_proposal")]; + } + + return $actions; + } } diff --git a/app/Ninja/Repositories/ProposalRepository.php b/app/Ninja/Repositories/ProposalRepository.php index 3d3b18a6ab98..6e7bf01a008c 100644 --- a/app/Ninja/Repositories/ProposalRepository.php +++ b/app/Ninja/Repositories/ProposalRepository.php @@ -41,7 +41,7 @@ class ProposalRepository extends BaseRepository 'proposals.is_deleted', 'proposals.private_notes', 'proposals.html as content', - 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"), 'clients.user_id as client_user_id', 'clients.public_id as client_public_id', 'invoices.invoice_number as quote', diff --git a/resources/views/proposals/edit.blade.php b/resources/views/proposals/edit.blade.php index ac4ea1f9d730..2d940b8e3169 100644 --- a/resources/views/proposals/edit.blade.php +++ b/resources/views/proposals/edit.blade.php @@ -60,6 +60,12 @@ {!! Button::success(trans("texts.save")) ->submit() ->appendIcon(Icon::create('floppy-disk')) !!} + + @if ($proposal) + {!! DropdownButton::normal(trans('texts.more_actions')) + ->withContents($proposal->present()->moreActions()) !!} + @endif + {!! Former::close() !!} @@ -147,6 +153,18 @@ return html; } + @if ($proposal) + function onArchiveClick() { + submitForm_proposal('archive', {{ $proposal->id }}); + } + + function onDeleteClick() { + sweetConfirm(function() { + submitForm_proposal('delete', {{ $proposal->id }}); + }); + } + @endif + $(function() { var invoiceId = {{ ! empty($invoicePublicId) ? $invoicePublicId : 0 }}; var $invoiceSelect = $('select#invoice_id'); @@ -183,6 +201,7 @@ + @include('partials.bulk_form', ['entityType' => ENTITY_PROPOSAL]) @include('proposals.grapesjs', ['entity' => $proposal])