mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Updates for exchange rate validation
This commit is contained in:
parent
a3febc9388
commit
6bbf3dface
@ -135,25 +135,44 @@ class QuoteItemExport extends BaseExport
|
||||
|
||||
$transformed_items = [];
|
||||
|
||||
foreach ($quote->line_items as $item) {
|
||||
$item_array = [];
|
||||
$transformed_items = [];
|
||||
|
||||
foreach (array_values($this->input['report_keys']) as $key) {
|
||||
if (str_contains($key, 'item.')) {
|
||||
$key = str_replace('item.', '', $key);
|
||||
$item_array[$key] = $item->{$key};
|
||||
foreach ($quote->line_items as $item) {
|
||||
$item_array = [];
|
||||
|
||||
foreach (array_values($this->input['report_keys']) as $key) { //items iterator produces item array
|
||||
|
||||
if (str_contains($key, "item.")) {
|
||||
|
||||
$key = str_replace("item.", "", $key);
|
||||
|
||||
$keyval = $key;
|
||||
|
||||
$keyval = str_replace("custom_value", "quote", $key);
|
||||
|
||||
if($key == 'type_id')
|
||||
$keyval = 'type';
|
||||
|
||||
if($key == 'tax_id')
|
||||
$keyval = 'tax_category';
|
||||
|
||||
if (property_exists($item, $key)) {
|
||||
$item_array[$keyval] = $item->{$key};
|
||||
} else {
|
||||
$item_array[$keyval] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$entity = [];
|
||||
|
||||
foreach (array_values($this->input['report_keys']) as $key) {
|
||||
$keyval = array_search($key, $this->entity_keys);
|
||||
foreach (array_values($this->input['report_keys']) as $key) { //create an array of report keys only
|
||||
$keyval = array_search($key, $this->entity_keys);
|
||||
|
||||
if (array_key_exists($key, $transformed_items)) {
|
||||
$entity[$keyval] = $transformed_items[$key];
|
||||
} else {
|
||||
$entity[$keyval] = '';
|
||||
$entity[$keyval] = "";
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,16 +192,26 @@ class QuoteItemExport extends BaseExport
|
||||
foreach (array_values($this->input['report_keys']) as $key) {
|
||||
$keyval = array_search($key, $this->entity_keys);
|
||||
|
||||
if(!$keyval) {
|
||||
$keyval = array_search(str_replace("quote.", "", $key), $this->entity_keys) ?? $key;
|
||||
}
|
||||
|
||||
if(!$keyval) {
|
||||
$keyval = $key;
|
||||
}
|
||||
|
||||
if (array_key_exists($key, $transformed_quote)) {
|
||||
$entity[$keyval] = $transformed_quote[$key];
|
||||
} else {
|
||||
$entity[$keyval] = '';
|
||||
} elseif (array_key_exists($keyval, $transformed_quote)) {
|
||||
$entity[$keyval] = $transformed_quote[$keyval];
|
||||
}
|
||||
else {
|
||||
$entity[$keyval] = $this->resolveKey($keyval, $quote, $this->quote_transformer);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->decorateAdvancedFields($quote, $entity);
|
||||
}
|
||||
|
||||
private function decorateAdvancedFields(Quote $quote, array $entity) :array
|
||||
{
|
||||
if (in_array('currency_id', $this->input['report_keys'])) {
|
||||
|
@ -49,7 +49,7 @@ class CreditFactory
|
||||
$credit->user_id = $user_id;
|
||||
$credit->company_id = $company_id;
|
||||
$credit->recurring_id = null;
|
||||
|
||||
$credit->exchange_rate = 1;
|
||||
return $credit;
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,8 @@ class PurchaseOrderFactory
|
||||
$purchase_order->user_id = $user_id;
|
||||
$purchase_order->company_id = $company_id;
|
||||
$purchase_order->recurring_id = null;
|
||||
|
||||
$purchase_order->exchange_rate = 1;
|
||||
|
||||
return $purchase_order;
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ class QuoteFactory
|
||||
$quote->user_id = $user_id;
|
||||
$quote->company_id = $company_id;
|
||||
$quote->paid_to_date = 0;
|
||||
$quote->exchange_rate = 1;
|
||||
|
||||
return $quote;
|
||||
}
|
||||
|
@ -67,7 +67,8 @@ class StoreCreditRequest extends Request
|
||||
$rules['tax_name1'] = 'bail|sometimes|string|nullable';
|
||||
$rules['tax_name2'] = 'bail|sometimes|string|nullable';
|
||||
$rules['tax_name3'] = 'bail|sometimes|string|nullable';
|
||||
|
||||
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
|
||||
|
||||
if ($this->invoice_id) {
|
||||
$rules['invoice_id'] = new ValidInvoiceCreditRule();
|
||||
}
|
||||
@ -88,7 +89,11 @@ class StoreCreditRequest extends Request
|
||||
$input = $this->decodePrimaryKeys($input);
|
||||
|
||||
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
|
||||
//$input['line_items'] = json_encode($input['line_items']);
|
||||
|
||||
if (array_key_exists('exchange_rate', $input) && is_null($input['exchange_rate'])) {
|
||||
$input['exchange_rate'] = 1;
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,8 @@ class UpdateCreditRequest extends Request
|
||||
$rules['tax_name1'] = 'bail|sometimes|string|nullable';
|
||||
$rules['tax_name2'] = 'bail|sometimes|string|nullable';
|
||||
$rules['tax_name3'] = 'bail|sometimes|string|nullable';
|
||||
|
||||
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
@ -81,6 +82,10 @@ class UpdateCreditRequest extends Request
|
||||
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
|
||||
}
|
||||
|
||||
if (array_key_exists('exchange_rate', $input) && is_null($input['exchange_rate'])) {
|
||||
$input['exchange_rate'] = 1;
|
||||
}
|
||||
|
||||
$input['id'] = $this->credit->id;
|
||||
|
||||
$this->replace($input);
|
||||
|
@ -72,7 +72,8 @@ class StoreInvoiceRequest extends Request
|
||||
$rules['tax_name1'] = 'bail|sometimes|string|nullable';
|
||||
$rules['tax_name2'] = 'bail|sometimes|string|nullable';
|
||||
$rules['tax_name3'] = 'bail|sometimes|string|nullable';
|
||||
|
||||
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,8 @@ class UpdateInvoiceRequest extends Request
|
||||
$rules['tax_name2'] = 'bail|sometimes|string|nullable';
|
||||
$rules['tax_name3'] = 'bail|sometimes|string|nullable';
|
||||
$rules['status_id'] = 'bail|sometimes|not_in:5'; //do not all cancelled invoices to be modfified.
|
||||
|
||||
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
|
||||
|
||||
// not needed.
|
||||
// $rules['partial_due_date'] = 'bail|sometimes|required_unless:partial,0,null';
|
||||
|
||||
@ -95,6 +96,10 @@ class UpdateInvoiceRequest extends Request
|
||||
unset($input['documents']);
|
||||
}
|
||||
|
||||
if (array_key_exists('exchange_rate', $input) && is_null($input['exchange_rate'])) {
|
||||
$input['exchange_rate'] = 1;
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,8 @@ class StorePurchaseOrderRequest extends Request
|
||||
}
|
||||
|
||||
$rules['status_id'] = 'nullable|integer|in:1,2,3,4,5';
|
||||
|
||||
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
@ -77,6 +78,10 @@ class StorePurchaseOrderRequest extends Request
|
||||
$input['amount'] = 0;
|
||||
$input['balance'] = 0;
|
||||
|
||||
if (array_key_exists('exchange_rate', $input) && is_null($input['exchange_rate'])) {
|
||||
$input['exchange_rate'] = 1;
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ class UpdatePurchaseOrderRequest extends Request
|
||||
}
|
||||
|
||||
$rules['status_id'] = 'sometimes|integer|in:1,2,3,4,5';
|
||||
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
@ -79,6 +80,10 @@ class UpdatePurchaseOrderRequest extends Request
|
||||
$input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : [];
|
||||
}
|
||||
|
||||
if (array_key_exists('exchange_rate', $input) && is_null($input['exchange_rate'])) {
|
||||
$input['exchange_rate'] = 1;
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ class StoreQuoteRequest extends Request
|
||||
$rules['discount'] = 'sometimes|numeric';
|
||||
|
||||
$rules['is_amount_discount'] = ['boolean'];
|
||||
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
|
||||
|
||||
// $rules['number'] = new UniqueQuoteNumberRule($this->all());
|
||||
$rules['line_items'] = 'array';
|
||||
@ -72,6 +73,10 @@ class StoreQuoteRequest extends Request
|
||||
$input['amount'] = 0;
|
||||
$input['balance'] = 0;
|
||||
|
||||
if (array_key_exists('exchange_rate', $input) && is_null($input['exchange_rate'])) {
|
||||
$input['exchange_rate'] = 1;
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ class UpdateQuoteRequest extends Request
|
||||
$rules['line_items'] = 'array';
|
||||
$rules['discount'] = 'sometimes|numeric';
|
||||
$rules['is_amount_discount'] = ['boolean'];
|
||||
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
@ -75,6 +76,10 @@ class UpdateQuoteRequest extends Request
|
||||
unset($input['documents']);
|
||||
}
|
||||
|
||||
if (array_key_exists('exchange_rate', $input) && is_null($input['exchange_rate'])) {
|
||||
$input['exchange_rate'] = 1;
|
||||
}
|
||||
|
||||
$input['id'] = $this->quote->id;
|
||||
|
||||
$this->replace($input);
|
||||
|
@ -67,7 +67,8 @@ class StoreRecurringInvoiceRequest extends Request
|
||||
$rules['tax_name2'] = 'bail|sometimes|string|nullable';
|
||||
$rules['tax_name3'] = 'bail|sometimes|string|nullable';
|
||||
$rules['due_date_days'] = 'bail|sometimes|string';
|
||||
|
||||
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
@ -143,6 +144,10 @@ class StoreRecurringInvoiceRequest extends Request
|
||||
unset($input['number']);
|
||||
}
|
||||
|
||||
if (array_key_exists('exchange_rate', $input) && is_null($input['exchange_rate'])) {
|
||||
$input['exchange_rate'] = 1;
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,8 @@ class UpdateRecurringInvoiceRequest extends Request
|
||||
$rules['tax_name1'] = 'bail|sometimes|string|nullable';
|
||||
$rules['tax_name2'] = 'bail|sometimes|string|nullable';
|
||||
$rules['tax_name3'] = 'bail|sometimes|string|nullable';
|
||||
|
||||
$rules['exchange_rate'] = 'bail|sometimes|gt:0';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
@ -121,6 +122,10 @@ class UpdateRecurringInvoiceRequest extends Request
|
||||
unset($input['documents']);
|
||||
}
|
||||
|
||||
if (array_key_exists('exchange_rate', $input) && is_null($input['exchange_rate'])) {
|
||||
$input['exchange_rate'] = 1;
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user