mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on custom invoice numbers
This commit is contained in:
parent
a0ec032f69
commit
17f853f907
@ -59,7 +59,7 @@ class CreateRandomData extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$invoice = Invoice::createNew($user);
|
$invoice = Invoice::createNew($user);
|
||||||
$invoice->invoice_number = $user->account->getNextInvoiceNumber();
|
$invoice->invoice_number = $user->account->getNextInvoiceNumber($invoice);
|
||||||
$invoice->amount = $invoice->balance = $price;
|
$invoice->amount = $invoice->balance = $price;
|
||||||
$invoice->created_at = date('Y-m-d', strtotime(date("Y-m-d") . ' - ' . rand(1, 100) . ' days'));
|
$invoice->created_at = date('Y-m-d', strtotime(date("Y-m-d") . ' - ' . rand(1, 100) . ' days'));
|
||||||
$client->invoices()->save($invoice);
|
$client->invoices()->save($invoice);
|
||||||
|
@ -308,7 +308,7 @@ class AccountController extends BaseController
|
|||||||
$client->work_phone = '';
|
$client->work_phone = '';
|
||||||
$client->work_email = '';
|
$client->work_email = '';
|
||||||
|
|
||||||
$invoice->invoice_number = $account->getNextInvoiceNumber();
|
$invoice->invoice_number = '0000';
|
||||||
$invoice->invoice_date = Utils::fromSqlDate(date('Y-m-d'));
|
$invoice->invoice_date = Utils::fromSqlDate(date('Y-m-d'));
|
||||||
$invoice->account = json_decode($account->toJson());
|
$invoice->account = json_decode($account->toJson());
|
||||||
$invoice->amount = $invoice->balance = 100;
|
$invoice->amount = $invoice->balance = 100;
|
||||||
|
@ -87,7 +87,7 @@ class InvoiceApiController extends Controller
|
|||||||
|
|
||||||
// check if the invoice number is set and unique
|
// check if the invoice number is set and unique
|
||||||
if (!isset($data['invoice_number']) && !isset($data['id'])) {
|
if (!isset($data['invoice_number']) && !isset($data['id'])) {
|
||||||
$data['invoice_number'] = Auth::user()->account->getNextInvoiceNumber(false, '', $client, Auth::user());
|
// do nothing... invoice number will be set automatically
|
||||||
} else if (isset($data['invoice_number'])) {
|
} else if (isset($data['invoice_number'])) {
|
||||||
$invoice = Invoice::scope()->where('invoice_number', '=', $data['invoice_number'])->first();
|
$invoice = Invoice::scope()->where('invoice_number', '=', $data['invoice_number'])->first();
|
||||||
if ($invoice) {
|
if ($invoice) {
|
||||||
|
@ -248,7 +248,7 @@ class InvoiceController extends BaseController
|
|||||||
|
|
||||||
if ($clone) {
|
if ($clone) {
|
||||||
$invoice->id = null;
|
$invoice->id = null;
|
||||||
$invoice->invoice_number = $account->getNextInvoiceNumber($invoice->is_quote, '', $invoice->client, Auth::user());
|
$invoice->invoice_number = $account->getNextInvoiceNumber($invoice);
|
||||||
$invoice->balance = $invoice->amount;
|
$invoice->balance = $invoice->amount;
|
||||||
$invoice->invoice_status_id = 0;
|
$invoice->invoice_status_id = 0;
|
||||||
$invoice->invoice_date = date_create()->format('Y-m-d');
|
$invoice->invoice_date = date_create()->format('Y-m-d');
|
||||||
@ -350,26 +350,23 @@ class InvoiceController extends BaseController
|
|||||||
public function create($clientPublicId = 0, $isRecurring = false)
|
public function create($clientPublicId = 0, $isRecurring = false)
|
||||||
{
|
{
|
||||||
$client = null;
|
$client = null;
|
||||||
if ($isRecurring) {
|
|
||||||
$invoiceNumber = microtime(true);
|
|
||||||
} else {
|
|
||||||
$invoiceNumber = Auth::user()->account->getDefaultInvoiceNumber(false, false, false, Auth::user());
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($clientPublicId) {
|
if ($clientPublicId) {
|
||||||
$client = Client::scope($clientPublicId)->firstOrFail();
|
$client = Client::scope($clientPublicId)->firstOrFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = array(
|
$invoice = Invoice::createNew();
|
||||||
'entityType' => ENTITY_INVOICE,
|
$invoice->client = $client;
|
||||||
'invoice' => null,
|
$invoice->is_recurring = $isRecurring;
|
||||||
|
$invoice->initialize();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'entityType' => $invoice->getEntityType(),
|
||||||
|
'invoice' => $invoice,
|
||||||
'data' => Input::old('data'),
|
'data' => Input::old('data'),
|
||||||
'invoiceNumber' => $invoiceNumber,
|
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'url' => 'invoices',
|
'url' => 'invoices',
|
||||||
'title' => trans('texts.new_invoice'),
|
'title' => trans('texts.new_invoice'),
|
||||||
'isRecurring' => $isRecurring,
|
];
|
||||||
'client' => $client);
|
|
||||||
$data = array_merge($data, self::getViewModel());
|
$data = array_merge($data, self::getViewModel());
|
||||||
|
|
||||||
return View::make('invoices.edit', $data);
|
return View::make('invoices.edit', $data);
|
||||||
|
@ -82,22 +82,23 @@ class QuoteController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$client = null;
|
$client = null;
|
||||||
$invoiceNumber = Auth::user()->account->getDefaultInvoiceNumber(true);
|
|
||||||
$account = Account::with('country')->findOrFail(Auth::user()->account_id);
|
|
||||||
|
|
||||||
if ($clientPublicId) {
|
if ($clientPublicId) {
|
||||||
$client = Client::scope($clientPublicId)->firstOrFail();
|
$client = Client::scope($clientPublicId)->firstOrFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = array(
|
$invoice = Invoice::createNew();
|
||||||
'account' => $account,
|
$invoice->client = $client;
|
||||||
'invoice' => null,
|
$invoice->is_quote = true;
|
||||||
|
$invoice->initialize();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'entityType' => $invoice->getEntityType(),
|
||||||
|
'invoice' => $invoice,
|
||||||
'data' => Input::old('data'),
|
'data' => Input::old('data'),
|
||||||
'invoiceNumber' => $invoiceNumber,
|
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'url' => 'invoices',
|
'url' => 'invoices',
|
||||||
'title' => trans('texts.new_quote'),
|
'title' => trans('texts.new_quote'),
|
||||||
'client' => $client, );
|
];
|
||||||
$data = array_merge($data, self::getViewModel());
|
$data = array_merge($data, self::getViewModel());
|
||||||
|
|
||||||
return View::make('invoices.edit', $data);
|
return View::make('invoices.edit', $data);
|
||||||
|
@ -248,16 +248,16 @@ class Account extends Eloquent
|
|||||||
return $isQuote ? ($this->quote_number_pattern ? true : false) : ($this->invoice_number_pattern ? true : false);
|
return $isQuote ? ($this->quote_number_pattern ? true : false) : ($this->invoice_number_pattern ? true : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasClientNumberPattern($isQuote)
|
public function hasClientNumberPattern($invoice)
|
||||||
{
|
{
|
||||||
$pattern = $this->getNumberPattern($isQuote);
|
$pattern = $invoice->is_quote ? $this->quote_number_pattern : $this->invoice_number_pattern;
|
||||||
|
|
||||||
return strstr($pattern, '$custom');
|
return strstr($pattern, '$custom');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNumberPattern($isQuote, $client = null, $user = null)
|
public function getNumberPattern($invoice)
|
||||||
{
|
{
|
||||||
$pattern = $isQuote ? $this->quote_number_pattern : $this->invoice_number_pattern;
|
$pattern = $invoice->is_quote ? $this->quote_number_pattern : $this->invoice_number_pattern;
|
||||||
|
|
||||||
if (!$pattern) {
|
if (!$pattern) {
|
||||||
return false;
|
return false;
|
||||||
@ -267,11 +267,11 @@ class Account extends Eloquent
|
|||||||
$replace = [date('Y')];
|
$replace = [date('Y')];
|
||||||
|
|
||||||
$search[] = '{$counter}';
|
$search[] = '{$counter}';
|
||||||
$replace[] = str_pad($this->getCounter($isQuote), 4, '0', STR_PAD_LEFT);
|
$replace[] = str_pad($this->getCounter($invoice->is_quote), 4, '0', STR_PAD_LEFT);
|
||||||
|
|
||||||
if ($user) {
|
if (strstr($pattern, '{$userId}')) {
|
||||||
$search[] = '{$userId}';
|
$search[] = '{$userId}';
|
||||||
$replace[] = str_pad($user->public_id, 2, '0', STR_PAD_LEFT);
|
$replace[] = str_pad($invoice->user->public_id, 2, '0', STR_PAD_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
$matches = false;
|
$matches = false;
|
||||||
@ -284,16 +284,16 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
$pattern = str_replace($search, $replace, $pattern);
|
$pattern = str_replace($search, $replace, $pattern);
|
||||||
|
|
||||||
if ($client) {
|
if ($invoice->client->id) {
|
||||||
$pattern = $this->getClientInvoiceNumber($pattern, $isQuote, $client);
|
$pattern = $this->getClientInvoiceNumber($pattern, $invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $pattern;
|
return $pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getClientInvoiceNumber($pattern, $isQuote, $client)
|
private function getClientInvoiceNumber($pattern, $invoice)
|
||||||
{
|
{
|
||||||
if (!$client) {
|
if (!$invoice->client) {
|
||||||
return $pattern;
|
return $pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,8 +305,8 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
$replace = [
|
$replace = [
|
||||||
//str_pad($client->public_id, 3, '0', STR_PAD_LEFT),
|
//str_pad($client->public_id, 3, '0', STR_PAD_LEFT),
|
||||||
$client->custom_value1,
|
$invoice->client->custom_value1,
|
||||||
$client->custom_value2,
|
$invoice->client->custom_value2,
|
||||||
];
|
];
|
||||||
|
|
||||||
return str_replace($search, $replace, $pattern);
|
return str_replace($search, $replace, $pattern);
|
||||||
@ -314,13 +314,13 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
// if we're using a pattern we don't know the next number until a client
|
// if we're using a pattern we don't know the next number until a client
|
||||||
// is selected, to support this the default value is blank
|
// is selected, to support this the default value is blank
|
||||||
public function getDefaultInvoiceNumber($isQuote = false, $prefix = '', $client = null, $user = null)
|
public function getDefaultInvoiceNumber($invoice = false, $prefix = '')
|
||||||
{
|
{
|
||||||
if ($this->hasClientNumberPattern($isQuote)) {
|
if ($this->hasClientNumberPattern($invoice)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getNextInvoiceNumber($isQuote = false, $prefix = '', $client, $user);
|
return $this->getNextInvoiceNumber($invoice, $prefix = '');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCounter($isQuote)
|
public function getCounter($isQuote)
|
||||||
@ -328,14 +328,14 @@ class Account extends Eloquent
|
|||||||
return $isQuote && !$this->share_counter ? $this->quote_number_counter : $this->invoice_number_counter;
|
return $isQuote && !$this->share_counter ? $this->quote_number_counter : $this->invoice_number_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNextInvoiceNumber($isQuote = false, $prefix = '', $client = null, $user = null)
|
public function getNextInvoiceNumber($invoice, $prefix = '')
|
||||||
{
|
{
|
||||||
if ($this->hasNumberPattern($isQuote)) {
|
if ($this->hasNumberPattern($invoice->is_quote)) {
|
||||||
return $this->getNumberPattern($isQuote, $client, $user);
|
return $this->getNumberPattern($invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
$counter = $this->getCounter($isQuote);
|
$counter = $this->getCounter($invoice->is_quote);
|
||||||
$prefix .= $isQuote ? $this->quote_number_prefix : $this->invoice_number_prefix;
|
$prefix .= $invoice->is_quote ? $this->quote_number_prefix : $this->invoice_number_prefix;
|
||||||
$counterOffset = 0;
|
$counterOffset = 0;
|
||||||
|
|
||||||
// confirm the invoice number isn't already taken
|
// confirm the invoice number isn't already taken
|
||||||
@ -348,7 +348,7 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
// update the invoice counter to be caught up
|
// update the invoice counter to be caught up
|
||||||
if ($counterOffset > 1) {
|
if ($counterOffset > 1) {
|
||||||
if ($isQuote && !$this->share_counter) {
|
if ($invoice->is_quote && !$this->share_counter) {
|
||||||
$this->quote_number_counter += $counterOffset - 1;
|
$this->quote_number_counter += $counterOffset - 1;
|
||||||
} else {
|
} else {
|
||||||
$this->invoice_number_counter += $counterOffset - 1;
|
$this->invoice_number_counter += $counterOffset - 1;
|
||||||
|
@ -20,11 +20,47 @@ class Invoice extends EntityModel
|
|||||||
'custom1',
|
'custom1',
|
||||||
'custom2',
|
'custom2',
|
||||||
'userId',
|
'userId',
|
||||||
//'clientId', // need to update after saving
|
|
||||||
'year',
|
'year',
|
||||||
'date:',
|
'date:',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function initialize()
|
||||||
|
{
|
||||||
|
$account = $this->account;
|
||||||
|
|
||||||
|
$this->invoice_date = Utils::today();
|
||||||
|
$this->start_date = Utils::today();
|
||||||
|
$this->invoice_design_id = $account->invoice_design_id;
|
||||||
|
$this->terms = $account->invoice_terms;
|
||||||
|
$this->invoice_footer = $account->invoice_footer;
|
||||||
|
|
||||||
|
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()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::isTrashed();
|
||||||
|
}
|
||||||
|
|
||||||
public function account()
|
public function account()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Models\Account');
|
return $this->belongsTo('App\Models\Account');
|
||||||
|
@ -139,7 +139,7 @@ class AccountRepository
|
|||||||
$invoice->user_id = $account->users()->first()->id;
|
$invoice->user_id = $account->users()->first()->id;
|
||||||
$invoice->public_id = $publicId;
|
$invoice->public_id = $publicId;
|
||||||
$invoice->client_id = $client->id;
|
$invoice->client_id = $client->id;
|
||||||
$invoice->invoice_number = $account->getNextInvoiceNumber();
|
$invoice->invoice_number = $account->getNextInvoiceNumber($invoice);
|
||||||
$invoice->invoice_date = date_create()->format('Y-m-d');
|
$invoice->invoice_date = date_create()->format('Y-m-d');
|
||||||
$invoice->amount = PRO_PLAN_PRICE;
|
$invoice->amount = PRO_PLAN_PRICE;
|
||||||
$invoice->balance = PRO_PLAN_PRICE;
|
$invoice->balance = PRO_PLAN_PRICE;
|
||||||
|
@ -254,10 +254,12 @@ class InvoiceRepository
|
|||||||
$invoice = Invoice::scope($publicId)->firstOrFail();
|
$invoice = Invoice::scope($publicId)->firstOrFail();
|
||||||
} else {
|
} else {
|
||||||
$invoice = Invoice::createNew();
|
$invoice = Invoice::createNew();
|
||||||
|
$invoice->client_id = $data['client_id'];
|
||||||
|
$invoice->is_recurring = $data['is_recurring'] ? true : false;
|
||||||
if ($entityType == ENTITY_QUOTE) {
|
if ($entityType == ENTITY_QUOTE) {
|
||||||
$invoice->is_quote = true;
|
$invoice->is_quote = true;
|
||||||
}
|
}
|
||||||
|
$invoice->initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
$account = \Auth::user()->account;
|
$account = \Auth::user()->account;
|
||||||
@ -283,11 +285,6 @@ class InvoiceRepository
|
|||||||
$invoice->invoice_date = isset($data['invoice_date_sql']) ? $data['invoice_date_sql'] : Utils::toSqlDate($data['invoice_date']);
|
$invoice->invoice_date = isset($data['invoice_date_sql']) ? $data['invoice_date_sql'] : Utils::toSqlDate($data['invoice_date']);
|
||||||
$invoice->has_tasks = isset($data['has_tasks']) ? $data['has_tasks'] : false;
|
$invoice->has_tasks = isset($data['has_tasks']) ? $data['has_tasks'] : false;
|
||||||
|
|
||||||
if (!$publicId) {
|
|
||||||
$invoice->client_id = $data['client_id'];
|
|
||||||
$invoice->is_recurring = $data['is_recurring'] ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($invoice->is_recurring) {
|
if ($invoice->is_recurring) {
|
||||||
if ($invoice->start_date && $invoice->start_date != Utils::toSqlDate($data['start_date'])) {
|
if ($invoice->start_date && $invoice->start_date != Utils::toSqlDate($data['start_date'])) {
|
||||||
$invoice->last_sent_date = null;
|
$invoice->last_sent_date = null;
|
||||||
@ -478,7 +475,7 @@ class InvoiceRepository
|
|||||||
}
|
}
|
||||||
$clone->invoice_number = $account->invoice_number_prefix.$invoiceNumber;
|
$clone->invoice_number = $account->invoice_number_prefix.$invoiceNumber;
|
||||||
} else {
|
} else {
|
||||||
$clone->invoice_number = $account->getNextInvoiceNumber($invoice->is_quote, '', $invoice->client, Auth::user());
|
$clone->invoice_number = $account->getNextInvoiceNumber($invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ([
|
foreach ([
|
||||||
@ -631,7 +628,7 @@ class InvoiceRepository
|
|||||||
$invoice = Invoice::createNew($recurInvoice);
|
$invoice = Invoice::createNew($recurInvoice);
|
||||||
$invoice->client_id = $recurInvoice->client_id;
|
$invoice->client_id = $recurInvoice->client_id;
|
||||||
$invoice->recurring_invoice_id = $recurInvoice->id;
|
$invoice->recurring_invoice_id = $recurInvoice->id;
|
||||||
$invoice->invoice_number = $recurInvoice->account->getNextInvoiceNumber(false, 'R', $recurInvoice->client, $recurInvoice->user);
|
$invoice->invoice_number = $recurInvoice->account->getNextInvoiceNumber($recurInvoice, 'R');
|
||||||
$invoice->amount = $recurInvoice->amount;
|
$invoice->amount = $recurInvoice->amount;
|
||||||
$invoice->balance = $recurInvoice->amount;
|
$invoice->balance = $recurInvoice->amount;
|
||||||
$invoice->invoice_date = date_create()->format('Y-m-d');
|
$invoice->invoice_date = date_create()->format('Y-m-d');
|
||||||
|
@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
|
|
||||||
@if ($invoice && $invoice->id)
|
@if ($invoice->id)
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
@if ($isRecurring)
|
@if ($invoice->is_recurring)
|
||||||
<li>{!! link_to('invoices', trans('texts.recurring_invoice')) !!}</li>
|
<li>{!! link_to('invoices', trans('texts.recurring_invoice')) !!}</li>
|
||||||
@else
|
@else
|
||||||
<li>{!! link_to(($entityType == ENTITY_QUOTE ? 'quotes' : 'invoices'), trans('texts.' . ($entityType == ENTITY_QUOTE ? 'quotes' : 'invoices'))) !!}</li>
|
<li>{!! link_to(($entityType == ENTITY_QUOTE ? 'quotes' : 'invoices'), trans('texts.' . ($entityType == ENTITY_QUOTE ? 'quotes' : 'invoices'))) !!}</li>
|
||||||
@ -34,7 +34,7 @@
|
|||||||
<div class="row" style="min-height:195px" onkeypress="formEnterClick(event)">
|
<div class="row" style="min-height:195px" onkeypress="formEnterClick(event)">
|
||||||
<div class="col-md-4" id="col_1">
|
<div class="col-md-4" id="col_1">
|
||||||
|
|
||||||
@if ($invoice && $invoice->id)
|
@if ($invoice->id)
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="client" class="control-label col-lg-4 col-sm-4">Client</label>
|
<label for="client" class="control-label col-lg-4 col-sm-4">Client</label>
|
||||||
<div class="col-lg-8 col-sm-8">
|
<div class="col-lg-8 col-sm-8">
|
||||||
@ -356,7 +356,7 @@
|
|||||||
|
|
||||||
{!! Button::primary(trans('texts.download_pdf'))->withAttributes(array('onclick' => 'onDownloadClick()'))->appendIcon(Icon::create('download-alt')) !!}
|
{!! Button::primary(trans('texts.download_pdf'))->withAttributes(array('onclick' => 'onDownloadClick()'))->appendIcon(Icon::create('download-alt')) !!}
|
||||||
|
|
||||||
@if (!$invoice || (!$invoice->trashed() && !$invoice->client->trashed()))
|
@if (!$invoice->trashed())
|
||||||
|
|
||||||
{!! Button::success(trans("texts.save_{$entityType}"))->withAttributes(array('id' => 'saveButton', 'onclick' => 'onSaveClick()'))->appendIcon(Icon::create('floppy-disk')) !!}
|
{!! 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')) !!}
|
{!! Button::info(trans("texts.email_{$entityType}"))->withAttributes(array('id' => 'emailButton', 'onclick' => 'onEmailClick()'))->appendIcon(Icon::create('send')) !!}
|
||||||
@ -528,7 +528,6 @@
|
|||||||
var invoiceDesigns = {!! $invoiceDesigns !!};
|
var invoiceDesigns = {!! $invoiceDesigns !!};
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
// create client dictionary
|
// create client dictionary
|
||||||
for (var i=0; i<clients.length; i++) {
|
for (var i=0; i<clients.length; i++) {
|
||||||
var client = clients[i];
|
var client = clients[i];
|
||||||
@ -559,9 +558,10 @@
|
|||||||
model.addTaxRate({!! $taxRate !!});
|
model.addTaxRate({!! $taxRate !!});
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
@if ($invoice)
|
|
||||||
var invoice = {!! $invoice !!};
|
var invoice = {!! $invoice !!};
|
||||||
ko.mapping.fromJS(invoice, model.invoice().mapping, model.invoice);
|
ko.mapping.fromJS(invoice, model.invoice().mapping, model.invoice);
|
||||||
|
|
||||||
|
@if ($invoice->id)
|
||||||
var invitationContactIds = {!! json_encode($invitationContactIds) !!};
|
var invitationContactIds = {!! json_encode($invitationContactIds) !!};
|
||||||
var client = clientMap[invoice.client.public_id];
|
var client = clientMap[invoice.client.public_id];
|
||||||
if (client) { // in case it's deleted
|
if (client) { // in case it's deleted
|
||||||
@ -631,8 +631,8 @@
|
|||||||
|
|
||||||
$('#invoice_date, #due_date, #start_date, #end_date, #last_sent_date').datepicker();
|
$('#invoice_date, #due_date, #start_date, #end_date, #last_sent_date').datepicker();
|
||||||
|
|
||||||
@if ($client && !$invoice)
|
@if ($invoice->client && !$invoice->id)
|
||||||
$('input[name=client]').val({{ $client->public_id }});
|
$('input[name=client]').val({{ $invoice->client->public_id }});
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
var $input = $('select#client');
|
var $input = $('select#client');
|
||||||
@ -644,7 +644,7 @@
|
|||||||
// we enable searching by contact but the selection must be the client
|
// we enable searching by contact but the selection must be the client
|
||||||
$('.client-input').val(getClientDisplayName(selected));
|
$('.client-input').val(getClientDisplayName(selected));
|
||||||
// if there's an invoice number pattern we'll apply it now
|
// if there's an invoice number pattern we'll apply it now
|
||||||
@if ($account->hasClientNumberPattern($entityType == ENTITY_QUOTE))
|
@if ($account->hasClientNumberPattern($invoice))
|
||||||
setInvoiceNumber(selected);
|
setInvoiceNumber(selected);
|
||||||
@endif
|
@endif
|
||||||
} else {
|
} else {
|
||||||
@ -681,7 +681,7 @@
|
|||||||
})(field);
|
})(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
@if ($client || $invoice || count($clients) == 0)
|
@if ($invoice->id || count($clients) == 0)
|
||||||
$('#invoice_number').focus();
|
$('#invoice_number').focus();
|
||||||
@else
|
@else
|
||||||
$('.client_select input.form-control').focus();
|
$('.client_select input.form-control').focus();
|
||||||
@ -704,7 +704,7 @@
|
|||||||
|
|
||||||
applyComboboxListeners();
|
applyComboboxListeners();
|
||||||
|
|
||||||
@if ($client)
|
@if ($invoice->client->id)
|
||||||
$input.trigger('change');
|
$input.trigger('change');
|
||||||
@else
|
@else
|
||||||
refreshPDF(true);
|
refreshPDF(true);
|
||||||
@ -945,13 +945,13 @@
|
|||||||
submitAction('convert');
|
submitAction('convert');
|
||||||
}
|
}
|
||||||
|
|
||||||
@if ($client && $invoice)
|
@if ($invoice->id)
|
||||||
function onPaymentClick() {
|
function onPaymentClick() {
|
||||||
window.location = '{{ URL::to('payments/create/' . $client->public_id . '/' . $invoice->public_id ) }}';
|
window.location = '{{ URL::to('payments/create/' . $invoice->client->public_id . '/' . $invoice->public_id ) }}';
|
||||||
}
|
}
|
||||||
|
|
||||||
function onCreditClick() {
|
function onCreditClick() {
|
||||||
window.location = '{{ URL::to('credits/create/' . $client->public_id . '/' . $invoice->public_id ) }}';
|
window.location = '{{ URL::to('credits/create/' . $invoice->client->public_id . '/' . $invoice->public_id ) }}';
|
||||||
}
|
}
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@ -1030,14 +1030,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setInvoiceNumber(client) {
|
function setInvoiceNumber(client) {
|
||||||
@if ($invoice)
|
@if ($invoice->id)
|
||||||
return;
|
return;
|
||||||
@endif
|
@endif
|
||||||
var number = '{{ $account->getNumberPattern($entityType == ENTITY_QUOTE, false, Auth::user()) }}';
|
var number = '{{ $account->getNumberPattern($invoice) }}';
|
||||||
number = number.replace('{$custom1}', client.custom_value1);
|
number = number.replace('{$custom1}', client.custom_value1);
|
||||||
number = number.replace('{$custom2}', client.custom_value1);
|
number = number.replace('{$custom2}', client.custom_value2);
|
||||||
//number = number.replace('{$clientId}', client.public_id < 0 ? '???' : padToThree(client.public_id));
|
|
||||||
//number = number.replace('{$counter}', padToFour(client.{{ $entityType }}_number_counter));
|
|
||||||
model.invoice().invoice_number(number);
|
model.invoice().invoice_number(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,21 +211,21 @@ function InvoiceModel(data) {
|
|||||||
self.set_default_footer = ko.observable(false);
|
self.set_default_footer = ko.observable(false);
|
||||||
self.public_notes = ko.observable('');
|
self.public_notes = ko.observable('');
|
||||||
self.po_number = ko.observable('');
|
self.po_number = ko.observable('');
|
||||||
self.invoice_date = ko.observable('{{ Utils::today() }}');
|
self.invoice_date = ko.observable('');
|
||||||
self.invoice_number = ko.observable('{{ isset($invoiceNumber) ? $invoiceNumber : '' }}');
|
self.invoice_number = ko.observable('');
|
||||||
self.due_date = ko.observable('');
|
self.due_date = ko.observable('');
|
||||||
self.start_date = ko.observable('{{ Utils::today() }}');
|
self.start_date = ko.observable('');
|
||||||
self.end_date = ko.observable('');
|
self.end_date = ko.observable('');
|
||||||
self.last_sent_date = ko.observable('');
|
self.last_sent_date = ko.observable('');
|
||||||
self.tax_name = ko.observable();
|
self.tax_name = ko.observable();
|
||||||
self.tax_rate = ko.observable();
|
self.tax_rate = ko.observable();
|
||||||
self.is_recurring = ko.observable({{ $isRecurring ? 'true' : 'false' }});
|
self.is_recurring = ko.observable(false);
|
||||||
self.auto_bill = ko.observable();
|
self.auto_bill = ko.observable();
|
||||||
self.invoice_status_id = ko.observable(0);
|
self.invoice_status_id = ko.observable(0);
|
||||||
self.invoice_items = ko.observableArray();
|
self.invoice_items = ko.observableArray();
|
||||||
self.amount = ko.observable(0);
|
self.amount = ko.observable(0);
|
||||||
self.balance = ko.observable(0);
|
self.balance = ko.observable(0);
|
||||||
self.invoice_design_id = ko.observable({{ $account->invoice_design_id }});
|
self.invoice_design_id = ko.observable(1);
|
||||||
self.partial = ko.observable(0);
|
self.partial = ko.observable(0);
|
||||||
self.has_tasks = ko.observable(false);
|
self.has_tasks = ko.observable(false);
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ class InvoiceCest
|
|||||||
|
|
||||||
$this->faker = Factory::create();
|
$this->faker = Factory::create();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
public function createInvoice(AcceptanceTester $I)
|
public function createInvoice(AcceptanceTester $I)
|
||||||
{
|
{
|
||||||
$clientEmail = $this->faker->safeEmail;
|
$clientEmail = $this->faker->safeEmail;
|
||||||
@ -75,7 +75,7 @@ class InvoiceCest
|
|||||||
$I->click('#lastSent');
|
$I->click('#lastSent');
|
||||||
$I->see($invoiceNumber);
|
$I->see($invoiceNumber);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
public function editInvoice(AcceptanceTester $I)
|
public function editInvoice(AcceptanceTester $I)
|
||||||
{
|
{
|
||||||
$I->wantTo('edit an invoice');
|
$I->wantTo('edit an invoice');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user