diff --git a/app/Console/Commands/InitLookup.php b/app/Console/Commands/InitLookup.php index f37de078be..7caf1944fe 100644 --- a/app/Console/Commands/InitLookup.php +++ b/app/Console/Commands/InitLookup.php @@ -360,6 +360,7 @@ class InitLookup extends Command DB::statement('truncate lookup_users'); DB::statement('truncate lookup_contacts'); DB::statement('truncate lookup_invitations'); + DB::statement('truncate lookup_proposal_invitations'); DB::statement('truncate lookup_account_tokens'); DB::statement('SET FOREIGN_KEY_CHECKS = 1'); } diff --git a/app/Http/Controllers/ProposalController.php b/app/Http/Controllers/ProposalController.php index 29d0503e60..75e5d0f13f 100644 --- a/app/Http/Controllers/ProposalController.php +++ b/app/Http/Controllers/ProposalController.php @@ -134,4 +134,11 @@ class ProposalController extends BaseController return redirect()->to('/proposals'); } + + public function download(ProposalRequest $request) + { + $proposal = $request->entity(); + + + } } diff --git a/app/Http/Middleware/DatabaseLookup.php b/app/Http/Middleware/DatabaseLookup.php index b01f68e9b0..6f8546376b 100644 --- a/app/Http/Middleware/DatabaseLookup.php +++ b/app/Http/Middleware/DatabaseLookup.php @@ -7,6 +7,7 @@ use Closure; use App\Models\LookupAccount; use App\Models\LookupContact; use App\Models\LookupInvitation; +use App\Models\LookupProposalInvitation; use App\Models\LookupAccountToken; use App\Models\LookupUser; use Auth; @@ -43,6 +44,8 @@ class DatabaseLookup } elseif ($guard == 'contact') { if ($key = request()->invitation_key) { LookupInvitation::setServerByField('invitation_key', $key); + } elseif ($key = request()->proposal_invitation_key) { + LookupProposalInvitation::setServerByField('invitation_key', $key); } elseif ($key = request()->contact_key ?: session('contact_key')) { LookupContact::setServerByField('contact_key', $key); } elseif ($key = request()->account_key) { diff --git a/app/Jobs/PurgeAccountData.php b/app/Jobs/PurgeAccountData.php index 01e5f89a33..a43a3f0a90 100644 --- a/app/Jobs/PurgeAccountData.php +++ b/app/Jobs/PurgeAccountData.php @@ -76,6 +76,7 @@ class PurgeAccountData extends Job $lookupAccount = LookupAccount::whereAccountKey($account->account_key)->firstOrFail(); DB::table('lookup_contacts')->where('lookup_account_id', '=', $lookupAccount->id)->delete(); DB::table('lookup_invitations')->where('lookup_account_id', '=', $lookupAccount->id)->delete(); + DB::table('lookup_proposal_invitations')->where('lookup_account_id', '=', $lookupAccount->id)->delete(); config(['database.default' => $current]); } diff --git a/app/Models/LookupProposalInvitation.php b/app/Models/LookupProposalInvitation.php new file mode 100644 index 0000000000..cd5b348db3 --- /dev/null +++ b/app/Models/LookupProposalInvitation.php @@ -0,0 +1,47 @@ +message_id) { + return; + } + + $current = config('database.default'); + config(['database.default' => DB_NINJA_LOOKUP]); + + $lookupAccount = LookupAccount::whereAccountKey($accountKey) + ->firstOrFail(); + + $lookupInvitation = LookupProposalInvitation::whereLookupAccountId($lookupAccount->id) + ->whereInvitationKey($invitation->invitation_key) + ->firstOrFail(); + + $lookupInvitation->message_id = $invitation->message_id; + $lookupInvitation->save(); + + config(['database.default' => $current]); + } + +} diff --git a/app/Models/ProposalInvitation.php b/app/Models/ProposalInvitation.php index c2895ffcbb..0bfc6c1cc2 100644 --- a/app/Models/ProposalInvitation.php +++ b/app/Models/ProposalInvitation.php @@ -3,7 +3,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\SoftDeletes; -//use App\Models\LookupProposalInvitation; +use App\Models\LookupProposalInvitation; use App\Models\Traits\Inviteable; /** @@ -60,7 +60,6 @@ class ProposalInvitation extends EntityModel } } -/* ProposalInvitation::creating(function ($invitation) { LookupProposalInvitation::createNew($invitation->account->account_key, [ @@ -68,7 +67,8 @@ ProposalInvitation::creating(function ($invitation) ]); }); -ProposalInvitation::updating(function ($invitation) { +ProposalInvitation::updating(function ($invitation) +{ $dirty = $invitation->getDirty(); if (array_key_exists('message_id', $dirty)) { LookupProposalInvitation::updateInvitation($invitation->account->account_key, $invitation); @@ -83,4 +83,3 @@ ProposalInvitation::deleted(function ($invitation) ]); } }); -*/ diff --git a/database/migrations/2018_01_10_073825_add_subscription_format.php b/database/migrations/2018_01_10_073825_add_subscription_format.php index 7404894f9a..0afa41feef 100644 --- a/database/migrations/2018_01_10_073825_add_subscription_format.php +++ b/database/migrations/2018_01_10_073825_add_subscription_format.php @@ -128,6 +128,14 @@ class AddSubscriptionFormat extends Migration $table->unique(['account_id', 'public_id']); }); + Schema::create('lookup_proposal_invitations', function ($table) { + $table->increments('id'); + $table->unsignedInteger('lookup_account_id')->index(); + $table->string('invitation_key')->unique(); + $table->string('message_id')->nullable()->unique(); + + $table->foreign('lookup_account_id')->references('id')->on('lookup_accounts')->onDelete('cascade'); + }); } /** @@ -150,5 +158,6 @@ class AddSubscriptionFormat extends Migration Schema::dropIfExists('proposal_snippets'); Schema::dropIfExists('proposal_categories'); Schema::dropIfExists('proposal_invitations'); + Schema::dropIfExists('lookup_proposal_invitations'); } } diff --git a/resources/views/proposals/edit.blade.php b/resources/views/proposals/edit.blade.php index 2d940b8e31..5376136b77 100644 --- a/resources/views/proposals/edit.blade.php +++ b/resources/views/proposals/edit.blade.php @@ -57,6 +57,10 @@ ->appendIcon(Icon::create('remove-circle')) ->asLinkTo(HTMLUtils::previousUrl('/proposals')) !!} + {!! Button::primary(trans('texts.download_pdf')) + ->withAttributes(['onclick' => 'onDownloadClick()']) + ->appendIcon(Icon::create('download-alt')) !!} + {!! Button::success(trans("texts.save")) ->submit() ->appendIcon(Icon::create('floppy-disk')) !!} @@ -86,6 +90,10 @@ return true; } + function onDownloadClick() { + location.href = "{{ url("/proposals/{$proposal->public_id}/download") }}"; + } + function loadTemplate() { var templateId = $('select#proposal_template_id').val(); var template = templateMap[templateId]; @@ -164,7 +172,7 @@ }); } @endif - + $(function() { var invoiceId = {{ ! empty($invoicePublicId) ? $invoicePublicId : 0 }}; var $invoiceSelect = $('select#invoice_id'); diff --git a/routes/web.php b/routes/web.php index 4ef849abb7..89083d9186 100644 --- a/routes/web.php +++ b/routes/web.php @@ -227,6 +227,7 @@ Route::group(['middleware' => ['lookup:user', 'auth:user']], function () { Route::post('proposals/bulk', 'ProposalController@bulk'); Route::get('proposals/{proposals}/edit', 'ProposalController@edit'); + Route::get('proposals/{proposals}/download', 'ProposalController@download'); Route::get('proposals/create/{invoice_id?}/{proposal_template_id?}', 'ProposalController@create'); Route::resource('proposals', 'ProposalController'); Route::get('api/proposals', 'ProposalController@getDatatable');