mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Proposals
This commit is contained in:
parent
89f3671205
commit
0658b77e71
@ -51,18 +51,47 @@ class ProposalTemplateController extends BaseController
|
|||||||
|
|
||||||
public function create(ProposalTemplateRequest $request)
|
public function create(ProposalTemplateRequest $request)
|
||||||
{
|
{
|
||||||
$data = [
|
$data = array_merge($this->getViewmodel(), [
|
||||||
'account' => auth()->user()->account,
|
|
||||||
'template' => 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'),
|
||||||
'templates' => ProposalTemplate::scope()->orderBy('name')->get(),
|
]);
|
||||||
];
|
|
||||||
|
|
||||||
return View::make('proposals/templates/edit', $data);
|
return View::make('proposals/templates/edit', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getViewmodel()
|
||||||
|
{
|
||||||
|
$customTemplates = ProposalTemplate::scope()->orderBy('name')->get();
|
||||||
|
$defaultTemplates = ProposalTemplate::whereNull('account_id')->orderBy('public_id')->get();
|
||||||
|
|
||||||
|
$customLabel = trans('texts.custom');
|
||||||
|
$defaultLabel = trans('texts.default');
|
||||||
|
|
||||||
|
foreach ($customTemplates as $template) {
|
||||||
|
if (! isset($options[$customLabel])) {
|
||||||
|
$options[$customLabel] = [];
|
||||||
|
}
|
||||||
|
$options[trans('texts.custom')][$template->public_id] = $template->name;
|
||||||
|
}
|
||||||
|
foreach ($defaultTemplates as $template) {
|
||||||
|
if (! isset($options[$defaultLabel])) {
|
||||||
|
$options[$defaultLabel] = [];
|
||||||
|
}
|
||||||
|
$options[trans('texts.default')][$template->public_id] = $template->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'account' => auth()->user()->account,
|
||||||
|
'customTemplates' => $customTemplates,
|
||||||
|
'defaultTemplates' => $defaultTemplates,
|
||||||
|
'templateOptions' => $options,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
public function show($publicId)
|
public function show($publicId)
|
||||||
{
|
{
|
||||||
Session::reflash();
|
Session::reflash();
|
||||||
@ -86,14 +115,12 @@ class ProposalTemplateController extends BaseController
|
|||||||
$url = 'proposals/templates/' . $template->public_id;
|
$url = 'proposals/templates/' . $template->public_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = [
|
$data = array_merge($this->getViewmodel(), [
|
||||||
'account' => auth()->user()->account,
|
|
||||||
'template' => $template,
|
'template' => $template,
|
||||||
'method' => $method,
|
'method' => $method,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'title' => trans('texts.edit_proposal_template'),
|
'title' => trans('texts.edit_proposal_template'),
|
||||||
'templates' => ProposalTemplate::scope()->orderBy('name')->get(),
|
]);
|
||||||
];
|
|
||||||
|
|
||||||
return View::make('proposals/templates/edit', $data);
|
return View::make('proposals/templates/edit', $data);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
$this->call('GatewayTypesSeeder');
|
$this->call('GatewayTypesSeeder');
|
||||||
$this->call('BanksSeeder');
|
$this->call('BanksSeeder');
|
||||||
$this->call('InvoiceStatusSeeder');
|
$this->call('InvoiceStatusSeeder');
|
||||||
|
$this->call('ProposalTemplatesSeeder');
|
||||||
$this->call('PaymentStatusSeeder');
|
$this->call('PaymentStatusSeeder');
|
||||||
$this->call('CurrenciesSeeder');
|
$this->call('CurrenciesSeeder');
|
||||||
$this->call('DateFormatsSeeder');
|
$this->call('DateFormatsSeeder');
|
||||||
|
@ -23,34 +23,22 @@ class ProposalTemplatesSeeder extends Seeder
|
|||||||
|
|
||||||
for ($i = 0; $i < count($designs); $i++) {
|
for ($i = 0; $i < count($designs); $i++) {
|
||||||
$design = $designs[$i];
|
$design = $designs[$i];
|
||||||
$fileName = storage_path() . '/templates/' . strtolower($design) . '.js';
|
$baseFileName = storage_path() . '/templates/' . strtolower($design);
|
||||||
if (file_exists($fileName)) {
|
$htmlFileName = $baseFileName . '.html';
|
||||||
$pdfmake = file_get_contents($fileName);
|
$cssFileName = $baseFileName . '.css';
|
||||||
if ($pdfmake) {
|
if (file_exists($htmlFileName) && file_exists($cssFileName)) {
|
||||||
$record = InvoiceDesign::whereName($design)->first();
|
$template = ProposalTemplate::whereName($design)->whereAccountId(0)->first();
|
||||||
if (! $record) {
|
|
||||||
$record = new InvoiceDesign();
|
if (! $template) {
|
||||||
$record->id = $i + 1;
|
$template = new ProposalTemplate();
|
||||||
$record->name = $design;
|
$template->public_id = $i + 1;
|
||||||
}
|
$template->name = $design;
|
||||||
$record->pdfmake = json_encode(json_decode($pdfmake)); // remove the white space
|
|
||||||
$record->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($i = 1; $i <= 3; $i++) {
|
$template->html = file_get_contents($htmlFileName);
|
||||||
$name = 'Custom' . $i;
|
$template->css = file_get_contents($cssFileName);
|
||||||
$id = $i + 10;
|
$template->save();
|
||||||
|
|
||||||
if (InvoiceDesign::whereName($name)->orWhere('id', '=', $id)->first()) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InvoiceDesign::create([
|
|
||||||
'id' => $id,
|
|
||||||
'name' => $name,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ class UpdateSeeder extends Seeder
|
|||||||
$this->call('CurrenciesSeeder');
|
$this->call('CurrenciesSeeder');
|
||||||
$this->call('DateFormatsSeeder');
|
$this->call('DateFormatsSeeder');
|
||||||
$this->call('InvoiceDesignsSeeder');
|
$this->call('InvoiceDesignsSeeder');
|
||||||
|
$this->call('ProposalTemplatesSeeder');
|
||||||
$this->call('PaymentTermsSeeder');
|
$this->call('PaymentTermsSeeder');
|
||||||
$this->call('PaymentTypesSeeder');
|
$this->call('PaymentTypesSeeder');
|
||||||
$this->call('LanguageSeeder');
|
$this->call('LanguageSeeder');
|
||||||
|
@ -2733,6 +2733,7 @@ $LANG = array(
|
|||||||
'proposal_subject' => 'New proposal :number from :account',
|
'proposal_subject' => 'New proposal :number from :account',
|
||||||
'proposal_message' => 'To view your proposal for :amount, click the link below.',
|
'proposal_message' => 'To view your proposal for :amount, click the link below.',
|
||||||
'emailed_proposal' => 'Successfully emailed proposal',
|
'emailed_proposal' => 'Successfully emailed proposal',
|
||||||
|
'load_template' => 'Load Template',
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -34,12 +34,6 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
{!! Former::text('name') !!}
|
{!! Former::text('name') !!}
|
||||||
|
|
||||||
<!--
|
|
||||||
{!! Former::select('proposal_template_id')->addOption('', '')
|
|
||||||
->label(trans('texts.template'))
|
|
||||||
->addGroupClass('template-select') !!}
|
|
||||||
-->
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
{!! Former::textarea('private_notes') !!}
|
{!! Former::textarea('private_notes') !!}
|
||||||
@ -51,6 +45,15 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<center class="buttons">
|
<center class="buttons">
|
||||||
|
|
||||||
|
{!! Former::select()
|
||||||
|
->style('display:inline;width:170px;background-color:white !important')
|
||||||
|
->placeholder(trans('texts.load_template'))
|
||||||
|
->onchange('onTemplateSelectChange()')
|
||||||
|
->addClass('template-select')
|
||||||
|
->options($templateOptions)
|
||||||
|
->raw() !!}
|
||||||
|
|
||||||
@include('proposals.grapesjs_help')
|
@include('proposals.grapesjs_help')
|
||||||
|
|
||||||
{!! Button::normal(trans('texts.cancel'))
|
{!! Button::normal(trans('texts.cancel'))
|
||||||
@ -74,8 +77,11 @@
|
|||||||
<div id="gjs"></div>
|
<div id="gjs"></div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var templates = {!! $templates !!};
|
var customTemplates = {!! $customTemplates !!};
|
||||||
var templateMap = {};
|
var customTemplateMap = {};
|
||||||
|
|
||||||
|
var defaultTemplates = {!! $defaultTemplates !!};
|
||||||
|
var defaultTemplateMap = {};
|
||||||
|
|
||||||
function onFormSubmit() {
|
function onFormSubmit() {
|
||||||
$('#html').val(grapesjsEditor.getHtml());
|
$('#html').val(grapesjsEditor.getHtml());
|
||||||
@ -84,16 +90,29 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
function onTemplateSelectChange() {
|
||||||
/*
|
var templateId = $('.template-select').val();
|
||||||
var $proposal_templateSelect = $('select#template_id');
|
var group = $('.template-select :selected').parent().attr('label');
|
||||||
for (var i = 0; i < templates.length; i++) {
|
|
||||||
var template = templates[i];
|
if (group == "{{ trans('texts.default') }}") {
|
||||||
templateMap[template.public_id] = template;
|
var template = defaultTemplateMap[templateId];
|
||||||
$templateSelect.append(new Option(template.name, template.public_id));
|
} else {
|
||||||
|
var template = customTemplateMap[templateId];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$('.template-select').val(null).blur();
|
||||||
|
}
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
for (var i=0; i<customTemplates.length; i++) {
|
||||||
|
var template = customTemplates[i];
|
||||||
|
customTemplateMap[template.public_id] = template;
|
||||||
|
}
|
||||||
|
for (var i=0; i<defaultTemplates.length; i++) {
|
||||||
|
var template = defaultTemplates[i];
|
||||||
|
defaultTemplateMap[template.public_id] = template;
|
||||||
}
|
}
|
||||||
@include('partials/entity_combobox', ['entityType' => ENTITY_PROPOSAL_TEMPLATE])
|
|
||||||
*/
|
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user