mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixed an API issue when only setting product_key in an invoice
This commit is contained in:
parent
a30153cabe
commit
0a2a97d89a
@ -220,6 +220,19 @@ class InvoiceApiController extends BaseAPIController
|
||||
|
||||
private function prepareItem($item)
|
||||
{
|
||||
// if only the product key is set we'll load the cost and notes
|
||||
if ($item['product_key'] && empty($item['cost']) && empty($item['notes'])) {
|
||||
$product = Product::findProductByKey($item['product_key']);
|
||||
if ($product) {
|
||||
if (empty($item['cost'])) {
|
||||
$item['cost'] = $product->cost;
|
||||
}
|
||||
if (empty($item['notes'])) {
|
||||
$item['notes'] = $product->notes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fields = [
|
||||
'cost' => 0,
|
||||
'product_key' => '',
|
||||
@ -233,19 +246,6 @@ class InvoiceApiController extends BaseAPIController
|
||||
}
|
||||
}
|
||||
|
||||
// if only the product key is set we'll load the cost and notes
|
||||
if ($item['product_key'] && (is_null($item['cost']) || is_null($item['notes']))) {
|
||||
$product = Product::findProductByKey($item['product_key']);
|
||||
if ($product) {
|
||||
if (is_null($item['cost'])) {
|
||||
$item['cost'] = $product->cost;
|
||||
}
|
||||
if (is_null($item['notes'])) {
|
||||
$item['notes'] = $product->notes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,9 @@ class AppServiceProvider extends ServiceProvider {
|
||||
Validator::extend('valid_invoice_items', function($attribute, $value, $parameters) {
|
||||
$total = 0;
|
||||
foreach ($value as $item) {
|
||||
$total += $item['qty'] * $item['cost'];
|
||||
$qty = isset($item['qty']) ? $item['qty'] : 1;
|
||||
$cost = isset($item['cost']) ? $item['cost'] : 1;
|
||||
$total += $qty * $cost;
|
||||
}
|
||||
return $total <= MAX_INVOICE_AMOUNT;
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user