Proposals

This commit is contained in:
Hillel Coren 2018-02-01 08:47:17 +02:00
parent 11a3e9ab1e
commit 8f4cba1ed8
9 changed files with 113 additions and 28 deletions

View File

@ -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);

View File

@ -22,6 +22,7 @@ class Proposal extends EntityModel
* @var array
*/
protected $fillable = [
'template_id',
];
/**

View File

@ -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;

View File

@ -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']);

View File

@ -0,0 +1,56 @@
<?php
use App\Models\ProposalTemplate;
class ProposalTemplatesSeeder extends Seeder
{
public function run()
{
Eloquent::unguard();
$designs = [
'Clean',
'Bold',
'Modern',
'Plain',
'Business',
'Creative',
'Elegant',
'Hipster',
'Playful',
'Photo',
];
for ($i = 0; $i < count($designs); $i++) {
$design = $designs[$i];
$fileName = storage_path() . '/templates/' . strtolower($design) . '.js';
if (file_exists($fileName)) {
$pdfmake = file_get_contents($fileName);
if ($pdfmake) {
$record = InvoiceDesign::whereName($design)->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,
]);
}
}
}

View File

@ -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',

View File

@ -19,7 +19,13 @@
@section('content')
{!! Former::open() !!}
{!! Former::open($url)
->method($method)
->id('mainForm')
->rules([
'quote_id' => 'required',
'template_id' => 'required',
]) !!}
<div class="row">
<div class="col-lg-12">
@ -30,13 +36,13 @@
{!! Former::select('quote_id')->addOption('', '')
->label(trans('texts.quote'))
->addGroupClass('quote-select') !!}
</div>
<div class="col-md-6">
{!! Former::select('template_id')->addOption('', '')
->label(trans('texts.template'))
->addGroupClass('template-select') !!}
</div>
<div class="col-md-6">
</div>
</div>
</div>
@ -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])

View File

@ -19,7 +19,13 @@
@section('content')
{!! Former::open() !!}
{!! Former::open($url)
->method($method)
->id('mainForm')
->rules([
'quote_id' => 'required',
'template_id' => 'required',
]) !!}
<div class="row">
<div class="col-lg-12">

View File

@ -19,7 +19,13 @@
@section('content')
{!! Former::open() !!}
{!! Former::open($url)
->method($method)
->id('mainForm')
->rules([
'quote_id' => 'required',
'template_id' => 'required',
]) !!}
<div class="row">
<div class="col-lg-12">