Refining how expenses convert to products

This commit is contained in:
Hillel Coren 2016-01-27 22:38:21 +02:00
parent a7f2d3354c
commit bdeb062657
5 changed files with 13 additions and 7 deletions

View File

@ -296,7 +296,7 @@ class InvoiceController extends BaseController
return [ return [
'data' => Input::old('data'), 'data' => Input::old('data'),
'account' => Auth::user()->account->load('country'), 'account' => Auth::user()->account->load('country'),
'products' => Product::scope()->with('default_tax_rate')->orderBy('id')->get(), 'products' => Product::scope()->with('default_tax_rate')->orderBy('product_key')->get(),
'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(),
'currencies' => Cache::get('currencies'), 'currencies' => Cache::get('currencies'),
'languages' => Cache::get('languages'), 'languages' => Cache::get('languages'),

View File

@ -402,6 +402,7 @@ class InvoiceRepository extends BaseRepository
continue; continue;
} }
$task = false;
if (isset($item['task_public_id']) && $item['task_public_id']) { if (isset($item['task_public_id']) && $item['task_public_id']) {
$task = Task::scope($item['task_public_id'])->where('invoice_id', '=', null)->firstOrFail(); $task = Task::scope($item['task_public_id'])->where('invoice_id', '=', null)->firstOrFail();
$task->invoice_id = $invoice->id; $task->invoice_id = $invoice->id;
@ -409,6 +410,7 @@ class InvoiceRepository extends BaseRepository
$task->save(); $task->save();
} }
$expense = false;
if (isset($item['expense_public_id']) && $item['expense_public_id']) { if (isset($item['expense_public_id']) && $item['expense_public_id']) {
$expense = Expense::scope($item['expense_public_id'])->where('invoice_id', '=', null)->firstOrFail(); $expense = Expense::scope($item['expense_public_id'])->where('invoice_id', '=', null)->firstOrFail();
$expense->invoice_id = $invoice->id; $expense->invoice_id = $invoice->id;
@ -424,11 +426,8 @@ class InvoiceRepository extends BaseRepository
$product = Product::createNew(); $product = Product::createNew();
$product->product_key = trim($item['product_key']); $product->product_key = trim($item['product_key']);
} }
$product->notes = ($task || $expense) ? '' : $item['notes'];
$product->notes = $invoice->has_tasks ? '' : $item['notes']; $product->cost = $expense ? 0 : $item['cost'];
$product->notes = $invoice->has_expenses ? '' : $item['notes'];
$product->cost = $item['cost'];
$product->save(); $product->save();
} }
} }

View File

@ -1130,4 +1130,5 @@ return array(
'info' => 'Info', 'info' => 'Info',
'imported_expenses' => 'Successfully created :count_vendors vendor(s) and :count_expenses expense(s)', 'imported_expenses' => 'Successfully created :count_vendors vendor(s) and :count_expenses expense(s)',
'iframe_url_help3' => 'Note: if you plan on accepting credit cards we strongly recommend having HTTPS enabled on your site.',
); );

View File

@ -96,6 +96,7 @@
+ window.location.search.substring(1); + window.location.search.substring(1);
&lt;/script&gt;</pre> &lt;/script&gt;</pre>
<p>{{ trans('texts.iframe_url_help2') }}</p> <p>{{ trans('texts.iframe_url_help2') }}</p>
<p><b>{{ trans('texts.iframe_url_help3') }}</b></p>
</div> </div>
<div class="modal-footer" style="margin-top: 0px"> <div class="modal-footer" style="margin-top: 0px">

View File

@ -937,10 +937,15 @@
var product = products[i]; var product = products[i];
if (product.product_key == key) { if (product.product_key == key) {
var model = ko.dataFor(this); var model = ko.dataFor(this);
if (model.expense_public_id()) {
return;
}
if (product.notes) { if (product.notes) {
model.notes(product.notes); model.notes(product.notes);
} }
if (product.cost) {
model.cost(accounting.toFixed(product.cost, 2)); model.cost(accounting.toFixed(product.cost, 2));
}
if (!model.qty()) { if (!model.qty()) {
model.qty(1); model.qty(1);
} }