2015-10-14 16:15:39 +02:00
|
|
|
@extends('header')
|
2015-07-21 20:51:56 +02:00
|
|
|
|
|
|
|
@section('head')
|
|
|
|
@parent
|
|
|
|
|
2015-12-10 12:03:45 +01:00
|
|
|
@include('money_script')
|
2015-07-21 20:51:56 +02:00
|
|
|
<link href="{{ asset('css/jsoneditor.min.css') }}" rel="stylesheet" type="text/css">
|
|
|
|
<script src="{{ asset('js/jsoneditor.min.js') }}" type="text/javascript"></script>
|
|
|
|
|
2016-01-07 08:08:30 +01:00
|
|
|
@foreach ($account->getFontFolders() as $font)
|
|
|
|
<script src="{{ asset('js/vfs_fonts/'.$font.'.js') }}" type="text/javascript"></script>
|
|
|
|
@endforeach
|
2016-06-05 21:55:23 +02:00
|
|
|
<script src="{{ asset('pdf.built.js') }}?no_cache={{ NINJA_VERSION }}" type="text/javascript"></script>
|
2015-07-21 20:51:56 +02:00
|
|
|
|
|
|
|
<style type="text/css">
|
|
|
|
|
|
|
|
select.form-control {
|
2016-06-05 21:55:23 +02:00
|
|
|
background: #FFFFFF !important;
|
2015-07-21 20:51:56 +02:00
|
|
|
margin-right: 12px;
|
|
|
|
}
|
|
|
|
table {
|
2016-06-05 21:55:23 +02:00
|
|
|
background: #FFFFFF !important;
|
2015-07-21 20:51:56 +02:00
|
|
|
}
|
|
|
|
|
2016-02-25 19:34:23 +01:00
|
|
|
/* http://stackoverflow.com/questions/4810841/how-can-i-pretty-print-json-using-javascript */
|
|
|
|
pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
|
|
|
|
.string { color: green; }
|
2016-02-25 22:33:48 +01:00
|
|
|
.number { color: red; }
|
2016-02-25 19:34:23 +01:00
|
|
|
.boolean { color: blue; }
|
2016-02-25 22:33:48 +01:00
|
|
|
.null { color: gray; }
|
|
|
|
.key { color: black; }
|
2016-02-25 19:34:23 +01:00
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
</style>
|
|
|
|
|
|
|
|
@stop
|
|
|
|
|
2016-06-05 21:55:23 +02:00
|
|
|
@section('content')
|
2015-10-14 16:15:39 +02:00
|
|
|
@parent
|
2015-07-21 20:51:56 +02:00
|
|
|
|
|
|
|
<script>
|
|
|
|
var invoiceDesigns = {!! $invoiceDesigns !!};
|
2016-01-07 08:08:30 +01:00
|
|
|
var invoiceFonts = {!! $invoiceFonts !!};
|
2016-06-05 21:55:23 +02:00
|
|
|
var invoice = {!! json_encode($invoice) !!};
|
2015-07-21 20:51:56 +02:00
|
|
|
var sections = ['content', 'styles', 'defaultStyle', 'pageMargins', 'header', 'footer'];
|
2015-07-26 22:05:38 +02:00
|
|
|
var customDesign = origCustomDesign = {!! $customDesign ?: 'JSON.parse(invoiceDesigns[0].javascript);' !!};
|
2015-07-21 20:51:56 +02:00
|
|
|
|
|
|
|
function getPDFString(cb, force) {
|
2016-07-04 09:46:41 +02:00
|
|
|
invoice.invoice_design_id = $('#invoice_design_id').val();
|
2016-04-19 04:35:18 +02:00
|
|
|
invoice.features = {
|
|
|
|
customize_invoice_design:{{ Auth::user()->hasFeature(FEATURE_CUSTOMIZE_INVOICE_DESIGN) ? 'true' : 'false' }},
|
|
|
|
remove_created_by:{{ Auth::user()->hasFeature(FEATURE_REMOVE_CREATED_BY) ? 'true' : 'false' }},
|
|
|
|
invoice_settings:{{ Auth::user()->hasFeature(FEATURE_INVOICE_SETTINGS) ? 'true' : 'false' }}
|
|
|
|
};
|
2015-07-21 20:51:56 +02:00
|
|
|
invoice.account.hide_quantity = {!! Auth::user()->account->hide_quantity ? 'true' : 'false' !!};
|
|
|
|
invoice.account.hide_paid_to_date = {!! Auth::user()->account->hide_paid_to_date ? 'true' : 'false' !!};
|
|
|
|
NINJA.primaryColor = '{!! Auth::user()->account->primary_color !!}';
|
|
|
|
NINJA.secondaryColor = '{!! Auth::user()->account->secondary_color !!}';
|
|
|
|
NINJA.fontSize = {!! Auth::user()->account->font_size !!};
|
2016-01-07 08:08:30 +01:00
|
|
|
NINJA.headerFont = {!! json_encode(Auth::user()->account->getHeaderFontName()) !!};
|
|
|
|
NINJA.bodyFont = {!! json_encode(Auth::user()->account->getBodyFontName()) !!};
|
2015-07-21 20:51:56 +02:00
|
|
|
|
|
|
|
generatePDF(invoice, getDesignJavascript(), force, cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDesignJavascript() {
|
|
|
|
var id = $('#invoice_design_id').val();
|
|
|
|
if (id == '-1') {
|
2016-06-05 21:55:23 +02:00
|
|
|
showMoreDesigns();
|
2015-07-21 20:51:56 +02:00
|
|
|
$('#invoice_design_id').val(1);
|
2016-06-05 21:55:23 +02:00
|
|
|
return invoiceDesigns[0].javascript;
|
2015-07-26 22:05:38 +02:00
|
|
|
} else if (customDesign) {
|
2015-07-21 20:51:56 +02:00
|
|
|
return JSON.stringify(customDesign);
|
2015-07-26 22:05:38 +02:00
|
|
|
} else {
|
|
|
|
return invoiceDesigns[0].javascript;
|
2015-07-21 20:51:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadEditor(section)
|
|
|
|
{
|
|
|
|
editorSection = section;
|
|
|
|
editor.set(customDesign[section]);
|
2015-07-28 09:00:00 +02:00
|
|
|
|
|
|
|
// the function throws an error if the editor is in code view
|
|
|
|
try {
|
2016-06-05 21:55:23 +02:00
|
|
|
editor.expandAll();
|
2015-07-28 09:00:00 +02:00
|
|
|
} catch(err) {}
|
2016-06-05 21:55:23 +02:00
|
|
|
}
|
2015-07-21 20:51:56 +02:00
|
|
|
|
|
|
|
function saveEditor(data)
|
2016-06-05 21:55:23 +02:00
|
|
|
{
|
2015-07-21 20:51:56 +02:00
|
|
|
setTimeout(function() {
|
2015-12-22 13:06:53 +01:00
|
|
|
customDesign[editorSection] = editor.get();
|
|
|
|
clearError();
|
|
|
|
refreshPDF();
|
|
|
|
}, 100)
|
2015-07-21 20:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSelectChange()
|
|
|
|
{
|
2016-06-05 21:55:23 +02:00
|
|
|
var id = $('#invoice_design_id').val();
|
2015-07-21 20:51:56 +02:00
|
|
|
if (parseInt(id)) {
|
2015-07-24 16:13:17 +02:00
|
|
|
var design = _.find(invoiceDesigns, function(design){ return design.id == id});
|
|
|
|
customDesign = JSON.parse(design.javascript);
|
2015-07-21 20:51:56 +02:00
|
|
|
} else {
|
|
|
|
customDesign = origCustomDesign;
|
|
|
|
}
|
|
|
|
|
|
|
|
loadEditor(editorSection);
|
2015-12-22 13:06:53 +01:00
|
|
|
clearError();
|
|
|
|
refreshPDF(true);
|
2015-07-21 20:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function submitForm()
|
|
|
|
{
|
2015-12-22 13:06:53 +01:00
|
|
|
if (!NINJA.isPDFValid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
$('#custom_design').val(JSON.stringify(customDesign));
|
|
|
|
$('form.warn-on-exit').submit();
|
|
|
|
}
|
|
|
|
|
2015-12-22 13:06:53 +01:00
|
|
|
window.onerror = function(e) {
|
|
|
|
$('#pdf-error').html(e.message ? e.message : e).show();
|
|
|
|
$('button.save-button').prop('disabled', true);
|
|
|
|
NINJA.isPDFValid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearError() {
|
|
|
|
NINJA.isPDFValid = true;
|
|
|
|
$('#pdf-error').hide();
|
|
|
|
$('button.save-button').prop('disabled', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
clearError();
|
2016-06-05 21:55:23 +02:00
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
var container = document.getElementById("jsoneditor");
|
|
|
|
var options = {
|
|
|
|
mode: 'form',
|
|
|
|
modes: ['form', 'code'],
|
|
|
|
change: function() {
|
|
|
|
saveEditor();
|
|
|
|
}
|
|
|
|
};
|
2015-12-22 13:06:53 +01:00
|
|
|
window.editor = new JSONEditor(container, options);
|
2015-07-21 20:51:56 +02:00
|
|
|
loadEditor('content');
|
2016-06-05 21:55:23 +02:00
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
|
|
|
var target = $(e.target).attr("href") // activated tab
|
|
|
|
target = target.substring(1); // strip leading #
|
|
|
|
loadEditor(target);
|
2015-12-22 13:06:53 +01:00
|
|
|
});
|
2016-02-25 19:34:23 +01:00
|
|
|
|
2016-01-07 08:08:30 +01:00
|
|
|
refreshPDF(true);
|
2016-02-25 19:34:23 +01:00
|
|
|
|
|
|
|
@if (isset($sampleInvoice) && $sampleInvoice)
|
|
|
|
var sample = {!! $sampleInvoice->toJSON() !!}
|
|
|
|
$('#sampleData').show().html(prettyJson(sample));
|
|
|
|
@endif
|
2015-07-21 20:51:56 +02:00
|
|
|
});
|
|
|
|
|
2016-06-05 21:55:23 +02:00
|
|
|
</script>
|
2015-07-21 20:51:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-6">
|
|
|
|
|
2016-06-05 21:55:23 +02:00
|
|
|
{!! Former::open()->addClass('warn-on-exit') !!}
|
2015-07-21 20:51:56 +02:00
|
|
|
{!! Former::populateField('invoice_design_id', $account->invoice_design_id) !!}
|
|
|
|
|
|
|
|
<div style="display:none">
|
|
|
|
{!! Former::text('custom_design') !!}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div role="tabpanel">
|
|
|
|
<ul class="nav nav-tabs" role="tablist" style="border: none">
|
|
|
|
<li role="presentation" class="active"><a href="#content" aria-controls="content" role="tab" data-toggle="tab">{{ trans('texts.content') }}</a></li>
|
|
|
|
<li role="presentation"><a href="#styles" aria-controls="styles" role="tab" data-toggle="tab">{{ trans('texts.styles') }}</a></li>
|
|
|
|
<li role="presentation"><a href="#defaultStyle" aria-controls="defaultStyle" role="tab" data-toggle="tab">{{ trans('texts.defaults') }}</a></li>
|
|
|
|
<li role="presentation"><a href="#pageMargins" aria-controls="margins" role="tab" data-toggle="tab">{{ trans('texts.margins') }}</a></li>
|
|
|
|
<li role="presentation"><a href="#header" aria-controls="header" role="tab" data-toggle="tab">{{ trans('texts.header') }}</a></li>
|
|
|
|
<li role="presentation"><a href="#footer" aria-controls="footer" role="tab" data-toggle="tab">{{ trans('texts.footer') }}</a></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2016-08-31 11:41:19 +02:00
|
|
|
<div id="jsoneditor" style="width: 100%; height: 743px;"></div>
|
2015-07-21 20:51:56 +02:00
|
|
|
<p> </p>
|
|
|
|
|
2015-07-24 16:13:17 +02:00
|
|
|
<div>
|
|
|
|
{!! Former::select('invoice_design_id')->style('display:inline;width:120px')->fromQuery($invoiceDesigns, 'name', 'id')->onchange('onSelectChange()')->raw() !!}
|
|
|
|
<div class="pull-right">
|
2015-08-16 19:14:03 +02:00
|
|
|
{!! Button::normal(trans('texts.help'))->withAttributes(['onclick' => 'showHelp()'])->appendIcon(Icon::create('question-sign')) !!}
|
2015-10-14 16:15:39 +02:00
|
|
|
{!! Button::normal(trans('texts.cancel'))->asLinkTo(URL::to('/settings/invoice_design'))->appendIcon(Icon::create('remove-circle')) !!}
|
2016-07-04 09:43:04 +02:00
|
|
|
@if (Auth::user()->hasFeature(FEATURE_CUSTOMIZE_INVOICE_DESIGN))
|
|
|
|
{!! Button::success(trans('texts.save'))->withAttributes(['onclick' => 'submitForm()'])->appendIcon(Icon::create('floppy-disk'))->withAttributes(['class' => 'save-button']) !!}
|
|
|
|
@endif
|
2015-07-24 16:13:17 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2015-07-21 20:51:56 +02:00
|
|
|
|
|
|
|
<script>
|
|
|
|
|
2016-06-05 21:55:23 +02:00
|
|
|
function showHelp() {
|
|
|
|
$('#helpModal').modal('show');
|
|
|
|
}
|
2015-08-16 19:14:03 +02:00
|
|
|
|
2016-06-05 21:55:23 +02:00
|
|
|
</script>
|
2015-08-16 19:14:03 +02:00
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
{!! Former::close() !!}
|
|
|
|
|
2015-08-16 19:14:03 +02:00
|
|
|
|
|
|
|
<div class="modal fade" id="helpModal" tabindex="-1" role="dialog" aria-labelledby="helpModalLabel" aria-hidden="true">
|
|
|
|
<div class="modal-dialog">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
|
|
|
<h4 class="modal-title" id="helpModalLabel">{{ trans('texts.help') }}</h4>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="panel-body" style="background-color: #fff">
|
2016-06-28 20:22:16 +02:00
|
|
|
{!! trans('texts.customize_help') !!}<br/>
|
2016-02-25 19:34:23 +01:00
|
|
|
|
|
|
|
<pre id="sampleData" style="display:none;height:200px;padding-top:16px;"></pre>
|
2016-03-15 21:24:09 +01:00
|
|
|
@if (empty($sampleInvoice))
|
|
|
|
<div class="help-block">{{ trans('texts.create_invoice_for_sample') }}</div>
|
|
|
|
@endif
|
2015-08-16 19:14:03 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="modal-footer" style="margin-top: 0px">
|
2016-06-05 21:55:23 +02:00
|
|
|
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('texts.close') }}</button>
|
2015-08-16 19:14:03 +02:00
|
|
|
</div>
|
2016-06-05 21:55:23 +02:00
|
|
|
|
2015-08-16 19:14:03 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-21 20:51:56 +02:00
|
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
2015-12-22 13:06:53 +01:00
|
|
|
<div id="pdf-error" class="alert alert-danger" style="display:none"></div>
|
2015-07-21 20:51:56 +02:00
|
|
|
|
|
|
|
@include('invoices.pdf', ['account' => Auth::user()->account, 'pdfHeight' => 800])
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2016-06-05 21:55:23 +02:00
|
|
|
@stop
|