mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 12:12:48 +01:00
Bug fixes
This commit is contained in:
parent
971e538d0e
commit
3d55dbc05b
@ -20,6 +20,6 @@ MAIL_FROM_ADDRESS
|
||||
MAIL_FROM_NAME
|
||||
MAIL_PASSWORD
|
||||
|
||||
#PHANTOMJS_CLOUD_KEY='a-demo-key-with-low-quota-per-ip-address'
|
||||
PHANTOMJS_CLOUD_KEY='a-demo-key-with-low-quota-per-ip-address'
|
||||
|
||||
LOG=single
|
||||
LOG=single
|
@ -94,7 +94,7 @@ class AppController extends BaseController
|
||||
"MAIL_USERNAME={$mail['username']}\n".
|
||||
"MAIL_FROM_NAME={$mail['from']['name']}\n".
|
||||
"MAIL_PASSWORD={$mail['password']}\n\n".
|
||||
"#PHANTOMJS_CLOUD_KEY='a-demo-key-with-low-quota-per-ip-address'";
|
||||
"PHANTOMJS_CLOUD_KEY='a-demo-key-with-low-quota-per-ip-address'";
|
||||
|
||||
// Write Config Settings
|
||||
$fp = fopen(base_path()."/.env", 'w');
|
||||
|
@ -165,9 +165,7 @@ class InvoiceController extends BaseController
|
||||
} else {
|
||||
$invoice->invoice_design->javascript = $invoice->invoice_design->pdfmake;
|
||||
}
|
||||
|
||||
$contact = $invitation->contact;
|
||||
$contact->setVisible([
|
||||
$contact = $invitation->contact; $contact->setVisible([
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email',
|
||||
@ -306,7 +304,6 @@ class InvoiceController extends BaseController
|
||||
'entityType' => $entityType,
|
||||
'showBreadcrumbs' => $clone,
|
||||
'invoice' => $invoice,
|
||||
'data' => false,
|
||||
'method' => $method,
|
||||
'invitationContactIds' => $contactIds,
|
||||
'url' => $url,
|
||||
@ -349,20 +346,17 @@ class InvoiceController extends BaseController
|
||||
|
||||
public function create($clientPublicId = 0, $isRecurring = false)
|
||||
{
|
||||
$client = null;
|
||||
$account = Auth::user()->account;
|
||||
$clientId = null;
|
||||
if ($clientPublicId) {
|
||||
$client = Client::scope($clientPublicId)->firstOrFail();
|
||||
$clientId = Client::getPrivateId($clientPublicId);
|
||||
}
|
||||
$entityType = $isRecurring ? ENTITY_RECURRING_INVOICE : ENTITY_INVOICE;
|
||||
$invoice = $account->createInvoice($entityType, $clientId);
|
||||
|
||||
$invoice = Invoice::createNew();
|
||||
$invoice->client = $client;
|
||||
$invoice->is_recurring = $isRecurring;
|
||||
$invoice->initialize();
|
||||
|
||||
$data = [
|
||||
'entityType' => $invoice->getEntityType(),
|
||||
'invoice' => $invoice,
|
||||
'data' => Input::old('data'),
|
||||
'method' => 'POST',
|
||||
'url' => 'invoices',
|
||||
'title' => trans('texts.new_invoice'),
|
||||
@ -391,6 +385,7 @@ class InvoiceController extends BaseController
|
||||
}
|
||||
|
||||
return [
|
||||
'data' => Input::old('data'),
|
||||
'account' => Auth::user()->account->load('country'),
|
||||
'products' => Product::scope()->with('default_tax_rate')->orderBy('id')->get(),
|
||||
'countries' => Cache::get('countries'),
|
||||
@ -440,9 +435,8 @@ class InvoiceController extends BaseController
|
||||
|
||||
if ($errors = $this->invoiceRepo->getErrors($input->invoice)) {
|
||||
Session::flash('error', trans('texts.invoice_error'));
|
||||
|
||||
return Redirect::to("{$entityType}s/create")
|
||||
->withInput()->withErrors($errors);
|
||||
$url = "{$entityType}s/" . ($publicId ?: 'create');
|
||||
return Redirect::to($url)->withInput()->withErrors($errors);
|
||||
} else {
|
||||
$invoice = $this->saveInvoice($publicId, $input, $entityType);
|
||||
$url = "{$entityType}s/".$invoice->public_id.'/edit';
|
||||
|
@ -81,15 +81,12 @@ class QuoteController extends BaseController
|
||||
return Redirect::to('/invoices/create');
|
||||
}
|
||||
|
||||
$client = null;
|
||||
$account = Auth::user()->account;
|
||||
$clientId = null;
|
||||
if ($clientPublicId) {
|
||||
$client = Client::scope($clientPublicId)->firstOrFail();
|
||||
$clientId = Client::getPrivateId($clientPublicId);
|
||||
}
|
||||
|
||||
$invoice = Invoice::createNew();
|
||||
$invoice->client = $client;
|
||||
$invoice->is_quote = true;
|
||||
$invoice->initialize();
|
||||
$invoice = $account->createInvoice(ENTITY_QUOTE, $clientId);
|
||||
|
||||
$data = [
|
||||
'entityType' => $invoice->getEntityType(),
|
||||
|
@ -243,6 +243,38 @@ class Account extends Eloquent
|
||||
return $height;
|
||||
}
|
||||
|
||||
public function createInvoice($entityType, $clientId = null)
|
||||
{
|
||||
$invoice = Invoice::createNew();
|
||||
|
||||
$invoice->invoice_date = Utils::today();
|
||||
$invoice->start_date = Utils::today();
|
||||
$invoice->invoice_design_id = $this->invoice_design_id;
|
||||
$invoice->client_id = $clientId;
|
||||
|
||||
if ($entityType === ENTITY_RECURRING_INVOICE) {
|
||||
$invoice->invoice_number = microtime(true);
|
||||
$invoice->is_recurring = true;
|
||||
} else {
|
||||
if ($entityType == ENTITY_QUOTE) {
|
||||
$invoice->is_quote = true;
|
||||
}
|
||||
|
||||
if ($this->hasClientNumberPattern($invoice) && !$client) {
|
||||
// do nothing, we don't yet know the value
|
||||
} else {
|
||||
$invoice->invoice_number = $this->getNextInvoiceNumber($invoice);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$clientId) {
|
||||
$invoice->client = Client::createNew();
|
||||
$invoice->client->public_id = 0;
|
||||
}
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
public function hasNumberPattern($isQuote)
|
||||
{
|
||||
return $isQuote ? ($this->quote_number_pattern ? true : false) : ($this->invoice_number_pattern ? true : false);
|
||||
@ -371,13 +403,6 @@ class Account extends Eloquent
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getLocale()
|
||||
{
|
||||
$language = Language::where('id', '=', $this->account->language_id)->first();
|
||||
|
||||
return $language->locale;
|
||||
}
|
||||
|
||||
public function loadLocalizationSettings($client = false)
|
||||
{
|
||||
$this->load('timezone', 'date_format', 'datetime_format', 'language');
|
||||
|
@ -9,14 +9,14 @@ class EntityModel extends Eloquent
|
||||
public $timestamps = true;
|
||||
protected $hidden = ['id'];
|
||||
|
||||
public static function createNew($parent = false)
|
||||
public static function createNew($context = null)
|
||||
{
|
||||
$className = get_called_class();
|
||||
$entity = new $className();
|
||||
|
||||
if ($parent) {
|
||||
$entity->user_id = $parent instanceof User ? $parent->id : $parent->user_id;
|
||||
$entity->account_id = $parent->account_id;
|
||||
if ($context) {
|
||||
$entity->user_id = $context instanceof User ? $context->id : $context->user_id;
|
||||
$entity->account_id = $context->account_id;
|
||||
} elseif (Auth::check()) {
|
||||
$entity->user_id = Auth::user()->id;
|
||||
$entity->account_id = Auth::user()->account_id;
|
||||
|
@ -6,7 +6,10 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Invoice extends EntityModel
|
||||
{
|
||||
use SoftDeletes;
|
||||
use SoftDeletes {
|
||||
SoftDeletes::trashed as parentTrashed;
|
||||
}
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
protected $casts = [
|
||||
@ -23,40 +26,14 @@ class Invoice extends EntityModel
|
||||
'year',
|
||||
'date:',
|
||||
];
|
||||
|
||||
public function initialize()
|
||||
|
||||
public function trashed()
|
||||
{
|
||||
$account = $this->account;
|
||||
|
||||
$this->invoice_date = Utils::today();
|
||||
$this->start_date = Utils::today();
|
||||
$this->invoice_design_id = $account->invoice_design_id;
|
||||
|
||||
if (!$this->invoice_number) {
|
||||
if ($this->is_recurring) {
|
||||
$this->invoice_number = microtime(true);
|
||||
} else {
|
||||
if ($account->hasClientNumberPattern($this) && !$this->client) {
|
||||
// do nothing, we don't yet know the value
|
||||
} else {
|
||||
$this->invoice_number = $account->getNextInvoiceNumber($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->client) {
|
||||
$this->client = Client::createNew($this);
|
||||
$this->client->public_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function isTrashed()
|
||||
{
|
||||
if ($this->client && $this->client->isTrashed()) {
|
||||
if ($this->client && $this->client->trashed()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return parent::isTrashed();
|
||||
return self::parentTrashed();
|
||||
}
|
||||
|
||||
public function account()
|
||||
|
@ -250,20 +250,17 @@ class InvoiceRepository
|
||||
|
||||
public function save($publicId, $data, $entityType)
|
||||
{
|
||||
$account = \Auth::user()->account;
|
||||
|
||||
if ($publicId) {
|
||||
$invoice = Invoice::scope($publicId)->firstOrFail();
|
||||
} else {
|
||||
$invoice = Invoice::createNew();
|
||||
$invoice->client_id = $data['client_id'];
|
||||
$invoice->is_recurring = $data['is_recurring'] ? true : false;
|
||||
if ($entityType == ENTITY_QUOTE) {
|
||||
$invoice->is_quote = true;
|
||||
if ($data['is_recurring']) {
|
||||
$entityType = ENTITY_RECURRING_INVOICE;
|
||||
}
|
||||
$invoice->initialize();
|
||||
$invoice = $account->createInvoice($entityType, $data['client_id']);
|
||||
}
|
||||
|
||||
$account = \Auth::user()->account;
|
||||
|
||||
if ((isset($data['set_default_terms']) && $data['set_default_terms'])
|
||||
|| (isset($data['set_default_footer']) && $data['set_default_footer'])) {
|
||||
if (isset($data['set_default_terms']) && $data['set_default_terms']) {
|
||||
|
@ -4,6 +4,14 @@
|
||||
@parent
|
||||
|
||||
<script src="{{ asset('js/pdf.built.js') }}" type="text/javascript"></script>
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
/* the value is auto set so we're removing the bold formatting */
|
||||
label.control-label[for=invoice_number] {
|
||||
font-weight: normal !important;
|
||||
}
|
||||
</style>
|
||||
@stop
|
||||
|
||||
@section('content')
|
||||
@ -21,6 +29,7 @@
|
||||
|
||||
{!! Former::open($url)->method($method)->addClass('warn-on-exit')->rules(array(
|
||||
'client' => 'required',
|
||||
'invoice_number' => 'required',
|
||||
'product_key' => 'max:255'
|
||||
)) !!}
|
||||
|
||||
@ -34,7 +43,7 @@
|
||||
<div class="row" style="min-height:195px" onkeypress="formEnterClick(event)">
|
||||
<div class="col-md-4" id="col_1">
|
||||
|
||||
@if ($invoice->id)
|
||||
@if ($invoice->id || $data)
|
||||
<div class="form-group">
|
||||
<label for="client" class="control-label col-lg-4 col-sm-4">Client</label>
|
||||
<div class="col-lg-8 col-sm-8">
|
||||
@ -57,7 +66,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if ($invoice && $invoice->id)
|
||||
@if ($invoice->id || $data)
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@ -107,9 +116,9 @@
|
||||
@if ($entityType == ENTITY_INVOICE)
|
||||
<div class="form-group" style="margin-bottom: 8px">
|
||||
<div class="col-lg-8 col-sm-8 col-sm-offset-4" style="padding-top: 10px">
|
||||
@if ($invoice && $invoice->recurring_invoice)
|
||||
@if ($invoice->recurring_invoice)
|
||||
{!! trans('texts.created_by_invoice', ['invoice' => link_to('/invoices/'.$invoice->recurring_invoice->public_id, trans('texts.recurring_invoice'))]) !!}
|
||||
@elseif ($invoice)
|
||||
@elseif ($invoice->id)
|
||||
@if (isset($lastSent) && $lastSent)
|
||||
{!! trans('texts.last_sent_on', ['date' => link_to('/invoices/'.$lastSent->public_id, $invoice->last_sent_date, ['id' => 'lastSent'])]) !!} <br/>
|
||||
@endif
|
||||
@ -149,7 +158,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<div class="table-responsive" style="padding-top:4px">
|
||||
<table class="table invoice-table">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -341,7 +350,7 @@
|
||||
{!! Former::text('data')->data_bind("value: ko.mapping.toJSON(model)") !!}
|
||||
{!! Former::text('pdfupload') !!}
|
||||
|
||||
@if ($invoice && $invoice->id)
|
||||
@if ($invoice->id)
|
||||
{!! Former::populateField('id', $invoice->public_id) !!}
|
||||
{!! Former::text('id') !!}
|
||||
@endif
|
||||
@ -361,7 +370,7 @@
|
||||
{!! Button::success(trans("texts.save_{$entityType}"))->withAttributes(array('id' => 'saveButton', 'onclick' => 'onSaveClick()'))->appendIcon(Icon::create('floppy-disk')) !!}
|
||||
{!! Button::info(trans("texts.email_{$entityType}"))->withAttributes(array('id' => 'emailButton', 'onclick' => 'onEmailClick()'))->appendIcon(Icon::create('send')) !!}
|
||||
|
||||
@if ($invoice && $invoice->id)
|
||||
@if ($invoice->id)
|
||||
{!! DropdownButton::normal(trans('texts.more_actions'))
|
||||
->withContents($actions)
|
||||
->dropup() !!}
|
||||
@ -968,9 +977,12 @@
|
||||
if (event.target.type == 'textarea') {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.preventDefault();
|
||||
|
||||
submitAction('');
|
||||
@if($invoice->trashed())
|
||||
return;
|
||||
@endif
|
||||
submitAction('');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1024,7 +1036,7 @@
|
||||
}
|
||||
|
||||
function showLearnMore() {
|
||||
$('#recurringModal').modal('show');
|
||||
$('#recurringModal').modal('show');
|
||||
}
|
||||
|
||||
function setInvoiceNumber(client) {
|
||||
@ -1037,16 +1049,6 @@
|
||||
model.invoice().invoice_number(number);
|
||||
}
|
||||
|
||||
function padToFour(number) {
|
||||
if (number<=9999) { number = ("000"+number).slice(-4); }
|
||||
return number;
|
||||
}
|
||||
|
||||
function padToThree(number) {
|
||||
if (number<=999) { number = ("00"+number).slice(-3); }
|
||||
return number;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
@stop
|
@ -203,11 +203,11 @@ function InvoiceModel(data) {
|
||||
self.frequency_id = ko.observable(4); // default to monthly
|
||||
self.terms = ko.observable('');
|
||||
self.default_terms = ko.observable(account.invoice_terms);
|
||||
self.terms_placeholder = ko.observable({{ !$invoice && $account->invoice_terms ? 'account.invoice_terms' : false}});
|
||||
self.terms_placeholder = ko.observable({{ !$invoice->id && $account->invoice_terms ? 'account.invoice_terms' : false}});
|
||||
self.set_default_terms = ko.observable(false);
|
||||
self.invoice_footer = ko.observable('');
|
||||
self.default_footer = ko.observable(account.invoice_footer);
|
||||
self.footer_placeholder = ko.observable({{ !$invoice && $account->invoice_footer ? 'account.invoice_footer' : false}});
|
||||
self.footer_placeholder = ko.observable({{ !$invoice->id && $account->invoice_footer ? 'account.invoice_footer' : false}});
|
||||
self.set_default_footer = ko.observable(false);
|
||||
self.public_notes = ko.observable('');
|
||||
self.po_number = ko.observable('');
|
||||
|
Loading…
Reference in New Issue
Block a user