diff --git a/app/Http/Controllers/ProposalController.php b/app/Http/Controllers/ProposalController.php index 0998a6699bf5..4968ab3ecfa1 100644 --- a/app/Http/Controllers/ProposalController.php +++ b/app/Http/Controllers/ProposalController.php @@ -52,14 +52,16 @@ class ProposalController extends BaseController public function create(ProposalRequest $request) { + $account = auth()->user()->account; + $data = [ - 'account' => auth()->user()->account, + 'account' => $account, 'proposal' => null, 'method' => 'POST', 'url' => 'proposals', 'title' => trans('texts.new_proposal'), 'quotes' => Invoice::scope()->with('client.contacts')->quotes()->orderBy('id')->get(), - 'templates' => ProposalTemplate::scope()->orderBy('name')->get(), + 'templates' => ProposalTemplate::whereAccountId($account->id)->orWhereNull('account_id')->orderBy('name')->get(), 'quotePublicId' => $request->quote_id, ]; @@ -75,16 +77,17 @@ class ProposalController extends BaseController public function edit(ProposalRequest $request) { + $account = auth()->user()->account; $proposal = $request->entity(); $data = [ - 'account' => auth()->user()->account, + 'account' => $account, 'proposal' => $proposal, 'method' => 'PUT', 'url' => 'proposals/' . $proposal->public_id, 'title' => trans('texts.edit_proposal'), - 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), - 'clientPublicId' => $proposal->client ? $proposal->client->public_id : null, + 'quotes' => Invoice::scope()->with('client.contacts')->quotes()->orderBy('id')->get(), + 'templates' => ProposalTemplate::whereAccountId($account->id)->orWhereNull('account_id')->orderBy('name')->get(), ]; return View::make('proposals.edit', $data); diff --git a/app/Models/Proposal.php b/app/Models/Proposal.php index aa5d77c416b7..5228e11a933d 100644 --- a/app/Models/Proposal.php +++ b/app/Models/Proposal.php @@ -22,6 +22,7 @@ class Proposal extends EntityModel * @var array */ protected $fillable = [ + 'template_id', ]; /** diff --git a/app/Ninja/Repositories/ProposalRepository.php b/app/Ninja/Repositories/ProposalRepository.php index 00c2fbe9eb57..a2fd618ca97f 100644 --- a/app/Ninja/Repositories/ProposalRepository.php +++ b/app/Ninja/Repositories/ProposalRepository.php @@ -3,6 +3,7 @@ namespace App\Ninja\Repositories; use App\Models\Proposal; +use App\Models\Invoice; use Auth; use DB; use Utils; @@ -62,13 +63,16 @@ class ProposalRepository extends BaseRepository public function save($input, $proposal = false) { - $publicId = isset($data['public_id']) ? $data['public_id'] : false; - if (! $proposal) { $proposal = Proposal::createNew(); } $proposal->fill($input); + + if (isset($input['quote_id'])) { + $proposal->quote_id = $input['quote_id'] ? Invoice::getPrivateId($input['quote_id']) : null; + } + $proposal->save(); return $proposal; 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 8b48211c7bf8..090e74fa4ff7 100644 --- a/database/migrations/2018_01_10_073825_add_subscription_format.php +++ b/database/migrations/2018_01_10_073825_add_subscription_format.php @@ -49,7 +49,7 @@ class AddSubscriptionFormat extends Migration $table->unsignedInteger('proposal_category_id'); $table->string('name'); $table->text('private_notes'); - + $table->mediumText('html'); $table->mediumText('css'); @@ -62,15 +62,14 @@ class AddSubscriptionFormat extends Migration Schema::create('proposal_templates', function ($table) { $table->increments('id'); - $table->unsignedInteger('account_id'); - $table->unsignedInteger('user_id'); + $table->unsignedInteger('account_id')->nullable(); + $table->unsignedInteger('user_id')->nullable(); $table->timestamps(); $table->softDeletes(); $table->boolean('is_deleted')->default(false); $table->text('private_notes'); $table->string('name'); - $table->text('tags'); $table->mediumText('html'); $table->mediumText('css'); @@ -90,7 +89,7 @@ class AddSubscriptionFormat extends Migration $table->boolean('is_deleted')->default(false); $table->unsignedInteger('quote_id')->index(); - $table->unsignedInteger('temlate_id')->index(); + $table->unsignedInteger('template_id')->index(); $table->text('private_notes'); $table->mediumText('html'); $table->mediumText('css'); @@ -98,7 +97,7 @@ class AddSubscriptionFormat extends Migration $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('quote_id')->references('id')->on('invoices')->onDelete('cascade'); - $table->foreign('temlate_id')->references('id')->on('proposal_templates')->onDelete('cascade'); + $table->foreign('template_id')->references('id')->on('proposal_templates')->onDelete('cascade'); $table->unsignedInteger('public_id')->index(); $table->unique(['account_id', 'public_id']); diff --git a/database/seeds/ProposalTemplatesSeeder.php b/database/seeds/ProposalTemplatesSeeder.php new file mode 100644 index 000000000000..0afbeb8111eb --- /dev/null +++ b/database/seeds/ProposalTemplatesSeeder.php @@ -0,0 +1,56 @@ +first(); + if (! $record) { + $record = new InvoiceDesign(); + $record->id = $i + 1; + $record->name = $design; + } + $record->pdfmake = json_encode(json_decode($pdfmake)); // remove the white space + $record->save(); + } + } + } + + for ($i = 1; $i <= 3; $i++) { + $name = 'Custom' . $i; + $id = $i + 10; + + if (InvoiceDesign::whereName($name)->orWhere('id', '=', $id)->first()) { + continue; + } + + InvoiceDesign::create([ + 'id' => $id, + 'name' => $name, + ]); + } + } +} diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 566614562942..2f7b709fd223 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2700,13 +2700,13 @@ $LANG = array( 'archive_proposal_template' => 'Archive Template', 'delete_proposal_template' => 'Delete Template', 'restored_proposal_template' => 'Restore Template', - 'created_proposal_template' => 'Successfully created temlate', - 'updated_proposal_template' => 'Successfully updated temlate', - 'archived_proposal_template' => 'Successfully archived temlate', - 'deleted_proposal_template' => 'Successfully archived temlate', - 'archived_proposal_templates' => 'Successfully archived :count temlates', - 'deleted_proposal_templates' => 'Successfully archived :count temlates', - 'restored_proposal_template' => 'Successfully restored temlate', + 'created_proposal_template' => 'Successfully created template', + 'updated_proposal_template' => 'Successfully updated template', + 'archived_proposal_template' => 'Successfully archived template', + 'deleted_proposal_template' => 'Successfully archived template', + 'archived_proposal_templates' => 'Successfully archived :count templates', + 'deleted_proposal_templates' => 'Successfully archived :count templates', + 'restored_proposal_template' => 'Successfully restored template', 'proposal_category' => 'Category', 'proposal_categories' => 'Categories', 'new_proposal_category' => 'New Category', diff --git a/resources/views/proposals/edit.blade.php b/resources/views/proposals/edit.blade.php index 5410fff96b85..3f5227b926be 100644 --- a/resources/views/proposals/edit.blade.php +++ b/resources/views/proposals/edit.blade.php @@ -19,7 +19,13 @@ @section('content') - {!! Former::open() !!} + {!! Former::open($url) + ->method($method) + ->id('mainForm') + ->rules([ + 'quote_id' => 'required', + 'template_id' => 'required', + ]) !!}
@@ -30,13 +36,13 @@ {!! Former::select('quote_id')->addOption('', '') ->label(trans('texts.quote')) ->addGroupClass('quote-select') !!} - -
-
{!! Former::select('template_id')->addOption('', '') ->label(trans('texts.template')) ->addGroupClass('template-select') !!} +
+
+
@@ -65,8 +71,12 @@ var templates = {!! $templates !!}; var templateMap = {}; + function onSaveClick() { + $('#mainForm').submit(); + } + $(function() { - var quoteId = {{ $quotePublicId ?: 0 }}; + var quoteId = {{ ! empty($quotePublicId) ? $quotePublicId : 0 }}; var $quoteSelect = $('select#quote_id'); for (var i = 0; i < quotes.length; i++) { var quote = quotes[i]; @@ -79,7 +89,7 @@ for (var i = 0; i < templates.length; i++) { var template = templates[i]; templateMap[template.public_id] = template; - $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]) diff --git a/resources/views/proposals/snippets/edit.blade.php b/resources/views/proposals/snippets/edit.blade.php index 7caba1fe5f59..a61017347fd6 100644 --- a/resources/views/proposals/snippets/edit.blade.php +++ b/resources/views/proposals/snippets/edit.blade.php @@ -19,7 +19,13 @@ @section('content') - {!! Former::open() !!} + {!! Former::open($url) + ->method($method) + ->id('mainForm') + ->rules([ + 'quote_id' => 'required', + 'template_id' => 'required', + ]) !!}
diff --git a/resources/views/proposals/templates/edit.blade.php b/resources/views/proposals/templates/edit.blade.php index a56ad361c298..4626abb09516 100644 --- a/resources/views/proposals/templates/edit.blade.php +++ b/resources/views/proposals/templates/edit.blade.php @@ -19,7 +19,13 @@ @section('content') - {!! Former::open() !!} + {!! Former::open($url) + ->method($method) + ->id('mainForm') + ->rules([ + 'quote_id' => 'required', + 'template_id' => 'required', + ]) !!}