1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Improvement to invoice import

This commit is contained in:
Hillel Coren 2016-12-22 13:53:14 +02:00
parent 80cc8ae2b4
commit 655da01338
8 changed files with 41 additions and 18 deletions

View File

@ -1707,8 +1707,8 @@ class Account extends Eloquent
*/
public function showCustomField($field, $entity = false)
{
if ($this->hasFeature(FEATURE_INVOICE_SETTINGS)) {
return $this->$field ? true : false;
if ($this->hasFeature(FEATURE_INVOICE_SETTINGS) && $this->$field) {
return true;
}
if (!$entity) {

View File

@ -203,6 +203,7 @@ trait PresentsInvoice
'website',
'phone',
'blank',
'adjustment',
];
foreach ($fields as $field) {

View File

@ -143,7 +143,6 @@ class BaseTransformer extends TransformerAbstract
*/
protected function getInvoiceNumber($number)
{
$number = strtolower($number);
return str_pad($number, 4, '0', STR_PAD_LEFT);
}

View File

@ -23,22 +23,45 @@ class InvoiceTransformer extends BaseTransformer
}
return new Item($data, function ($data) {
return [
$invoice = [
'client_id' => $this->getClientId($data->customer_name),
'invoice_number' => $this->getInvoiceNumber($data->invoice_number),
'paid' => (float) $data->total - (float) $data->balance,
'po_number' => $this->getString($data, 'purchaseorder'),
'due_date_sql' => $data->due_date,
'invoice_date_sql' => $data->invoice_date,
'custom_value1' => (float) $data->latefee_amount + (float) $data->adjustment + (float) $data->shipping_charge,
'custom_taxes1' => false,
'invoice_items' => [
[
'product_key' => '',
'product_key' => $this->getString($data, 'item_name'),
'notes' => $this->getString($data, 'item_desc'),
'cost' => (float) $data->total,
'qty' => 1,
'cost' => (float) $data->item_price,
'qty' => (float) $data->quantity,
'tax_name1' => (float) $data->item_tax1 ? trans('texts.tax') : '',
'tax_rate1' => (float) $data->item_tax1,
'tax_name2' => (float) $data->item_tax2 ? trans('texts.tax') : '',
'tax_rate2' => (float) $data->item_tax2,
]
],
];
// we don't support line item discounts so we need to include
// the discount as a separate line item
if ((float) $data->discount_amount) {
$invoice['invoice_items'][] = [
'product_key' => '',
'notes' => trans('texts.discount'),
'cost' => (float) $data->discount_amount * -1,
'qty' => 1,
'tax_name1' => (float) $data->item_tax1 ? trans('texts.tax') : '',
'tax_rate1' => (float) $data->item_tax1,
'tax_name2' => (float) $data->item_tax2 ? trans('texts.tax') : '',
'tax_rate2' => (float) $data->item_tax2,
];
}
return $invoice;
});
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -503,10 +503,10 @@ NINJA.subtotals = function(invoice, hideBalance)
}
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 == '1') {
data.push([{text: account.custom_invoice_label1, style: ['subtotalsLabel', 'customTax1Label']}, {text: formatMoneyInvoice(invoice.custom_value1, invoice), style: ['subtotals', 'customTax1']}]);
data.push([{text: account.custom_invoice_label1 || invoiceLabels.adjustment, style: ['subtotalsLabel', 'customTax1Label']}, {text: formatMoneyInvoice(invoice.custom_value1, invoice), style: ['subtotals', 'customTax1']}]);
}
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 == '1') {
data.push([{text: account.custom_invoice_label2, style: ['subtotalsLabel', 'customTax2Label']}, {text: formatMoneyInvoice(invoice.custom_value2, invoice), style: ['subtotals', 'customTax2']}]);
data.push([{text: account.custom_invoice_label2 || invoiceLabels.adjustment, style: ['subtotalsLabel', 'customTax2Label']}, {text: formatMoneyInvoice(invoice.custom_value2, invoice), style: ['subtotals', 'customTax2']}]);
}
for (var key in invoice.item_taxes) {
@ -527,10 +527,10 @@ NINJA.subtotals = function(invoice, hideBalance)
}
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') {
data.push([{text: account.custom_invoice_label1, style: ['subtotalsLabel', 'custom1Label']}, {text: formatMoneyInvoice(invoice.custom_value1, invoice), style: ['subtotals', 'custom1']}]);
data.push([{text: account.custom_invoice_label1 || invoiceLabels.adjustment, style: ['subtotalsLabel', 'custom1Label']}, {text: formatMoneyInvoice(invoice.custom_value1, invoice), style: ['subtotals', 'custom1']}]);
}
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 != '1') {
data.push([{text: account.custom_invoice_label2, style: ['subtotalsLabel', 'custom2Label']}, {text: formatMoneyInvoice(invoice.custom_value2, invoice), style: ['subtotals', 'custom2']}]);
data.push([{text: account.custom_invoice_label2 || invoiceLabels.adjustment, style: ['subtotalsLabel', 'custom2Label']}, {text: formatMoneyInvoice(invoice.custom_value2, invoice), style: ['subtotals', 'custom2']}]);
}
var paid = invoice.amount - invoice.balance;

View File

@ -417,7 +417,7 @@
<tr>
<td class="hide-border" colspan="3"/>
<td style="display:none" class="hide-border" data-bind="visible: $root.invoice_item_taxes.show"/>
<td colspan="{{ $account->hide_quantity ? 1 : 2 }}">{{ $account->custom_invoice_label1 }}</td>
<td colspan="{{ $account->hide_quantity ? 1 : 2 }}">{{ $account->custom_invoice_label1 ?: trans('texts.adjustment') }}</td>
<td style="text-align: right;padding-right: 28px" colspan="2"><input name="custom_value1" class="form-control" data-bind="value: custom_value1, valueUpdate: 'afterkeydown'"/></td>
</tr>
@endif
@ -426,7 +426,7 @@
<tr>
<td class="hide-border" colspan="3"/>
<td style="display:none" class="hide-border" data-bind="visible: $root.invoice_item_taxes.show"/>
<td colspan="{{ $account->hide_quantity ? 1 : 2 }}">{{ $account->custom_invoice_label2 }}</td>
<td colspan="{{ $account->hide_quantity ? 1 : 2 }}">{{ $account->custom_invoice_label2 ?: trans('texts.adjustment') }}</td>
<td style="text-align: right;padding-right: 28px" colspan="2"><input name="custom_value2" class="form-control" data-bind="value: custom_value2, valueUpdate: 'afterkeydown'"/></td>
</tr>
@endif
@ -474,7 +474,7 @@
<tr>
<td class="hide-border" colspan="3"/>
<td style="display:none" class="hide-border" data-bind="visible: $root.invoice_item_taxes.show"/>
<td colspan="{{ $account->hide_quantity ? 1 : 2 }}">{{ $account->custom_invoice_label1 }}</td>
<td colspan="{{ $account->hide_quantity ? 1 : 2 }}">{{ $account->custom_invoice_label1 ?: trans('texts.adjustment') }}</td>
<td style="text-align: right;padding-right: 28px" colspan="2"><input name="custom_value1" class="form-control" data-bind="value: custom_value1, valueUpdate: 'afterkeydown'"/></td>
</tr>
@endif
@ -483,7 +483,7 @@
<tr>
<td class="hide-border" colspan="3"/>
<td style="display:none" class="hide-border" data-bind="visible: $root.invoice_item_taxes.show"/>
<td colspan="{{ $account->hide_quantity ? 1 : 2 }}">{{ $account->custom_invoice_label2 }}</td>
<td colspan="{{ $account->hide_quantity ? 1 : 2 }}">{{ $account->custom_invoice_label2 ?: trans('texts.adjustment') }}</td>
<td style="text-align: right;padding-right: 28px" colspan="2"><input name="custom_value2" class="form-control" data-bind="value: custom_value2, valueUpdate: 'afterkeydown'"/></td>
</tr>
@endif