mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Working on exchange rates
This commit is contained in:
parent
2c54bbfdf0
commit
cb99cee59d
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Libraries\CurlUtils;
|
||||||
use Carbon;
|
use Carbon;
|
||||||
use Str;
|
use Str;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Currency;
|
||||||
use App\Ninja\Mailers\ContactMailer as Mailer;
|
use App\Ninja\Mailers\ContactMailer as Mailer;
|
||||||
use App\Ninja\Mailers\UserMailer;
|
use App\Ninja\Mailers\UserMailer;
|
||||||
use App\Ninja\Repositories\AccountRepository;
|
use App\Ninja\Repositories\AccountRepository;
|
||||||
@ -73,6 +75,7 @@ class SendReminders extends Command
|
|||||||
$this->chargeLateFees();
|
$this->chargeLateFees();
|
||||||
$this->setReminderEmails();
|
$this->setReminderEmails();
|
||||||
$this->sendScheduledReports();
|
$this->sendScheduledReports();
|
||||||
|
$this->loadExchangeRates();
|
||||||
|
|
||||||
$this->info('Done');
|
$this->info('Done');
|
||||||
|
|
||||||
@ -163,6 +166,20 @@ class SendReminders extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function loadExchangeRates()
|
||||||
|
{
|
||||||
|
$this->info('Loading latest exchange rates...');
|
||||||
|
|
||||||
|
$data = CurlUtils::get('https://api.fixer.io/latest');
|
||||||
|
$data = json_decode($data);
|
||||||
|
|
||||||
|
Currency::whereCode('EUR')->update(['exchange_rate' => 1]);
|
||||||
|
|
||||||
|
foreach ($data->rates as $code => $rate) {
|
||||||
|
Currency::whereCode($code)->update(['exchange_rate' => $rate]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
@ -39,7 +39,8 @@
|
|||||||
"fullcalendar": "^3.5.1",
|
"fullcalendar": "^3.5.1",
|
||||||
"toastr": "^2.1.3",
|
"toastr": "^2.1.3",
|
||||||
"jt.timepicker": "jquery-timepicker-jt#^1.11.12",
|
"jt.timepicker": "jquery-timepicker-jt#^1.11.12",
|
||||||
"qrcode.js": "qrcode-js#*"
|
"qrcode.js": "qrcode-js#*",
|
||||||
|
"money.js": "^0.1.3"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"jquery": "~1.11"
|
"jquery": "~1.11"
|
||||||
|
@ -43,6 +43,10 @@ class AddRemember2faToken extends Migration
|
|||||||
Schema::table('tasks', function ($table) {
|
Schema::table('tasks', function ($table) {
|
||||||
$table->foreign('task_status_id')->references('id')->on('task_statuses')->onDelete('cascade');
|
$table->foreign('task_status_id')->references('id')->on('task_statuses')->onDelete('cascade');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Schema::table('currencies', function ($table) {
|
||||||
|
$table->decimal('exchange_rate', 13, 4)->nullable();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,5 +70,9 @@ class AddRemember2faToken extends Migration
|
|||||||
});
|
});
|
||||||
|
|
||||||
Schema::dropIfExists('task_statuses');
|
Schema::dropIfExists('task_statuses');
|
||||||
|
|
||||||
|
Schema::table('currencies', function ($table) {
|
||||||
|
$table->dropColumn('exchange_rate');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,6 +160,7 @@ elixir(function(mix) {
|
|||||||
bowerDir + '/dropzone/dist/dropzone.js',
|
bowerDir + '/dropzone/dist/dropzone.js',
|
||||||
bowerDir + '/typeahead.js/dist/typeahead.jquery.js',
|
bowerDir + '/typeahead.js/dist/typeahead.jquery.js',
|
||||||
bowerDir + '/accounting/accounting.js',
|
bowerDir + '/accounting/accounting.js',
|
||||||
|
bowerDir + '/money.js/money.js',
|
||||||
bowerDir + '/spectrum/spectrum.js',
|
bowerDir + '/spectrum/spectrum.js',
|
||||||
bowerDir + '/moment/moment.js',
|
bowerDir + '/moment/moment.js',
|
||||||
bowerDir + '/moment-timezone/builds/moment-timezone-with-data.js',
|
bowerDir + '/moment-timezone/builds/moment-timezone-with-data.js',
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -159,7 +159,7 @@
|
|||||||
{!! Former::select('invoice_currency_id')->addOption('','')
|
{!! Former::select('invoice_currency_id')->addOption('','')
|
||||||
->label(trans('texts.invoice_currency'))
|
->label(trans('texts.invoice_currency'))
|
||||||
->data_placeholder(Utils::getFromCache($account->getCurrencyId(), 'currencies')->name)
|
->data_placeholder(Utils::getFromCache($account->getCurrencyId(), 'currencies')->name)
|
||||||
->data_bind('combobox: invoice_currency_id, disable: true')
|
->data_bind('combobox: invoiceCurrencyId, disable: true')
|
||||||
->fromQuery($currencies, 'name', 'id') !!}
|
->fromQuery($currencies, 'name', 'id') !!}
|
||||||
</span>
|
</span>
|
||||||
<span style="display:none;" data-bind="visible: client_id">
|
<span style="display:none;" data-bind="visible: client_id">
|
||||||
@ -479,6 +479,26 @@
|
|||||||
}, self);
|
}, self);
|
||||||
|
|
||||||
|
|
||||||
|
self.invoiceCurrencyId = ko.computed({
|
||||||
|
read: function () {
|
||||||
|
return self.invoice_currency_id();
|
||||||
|
},
|
||||||
|
write: function(invoiceCurrencyId) {
|
||||||
|
self.invoice_currency_id(invoiceCurrencyId);
|
||||||
|
var fromCode = self.expenseCurrencyCode();
|
||||||
|
var toCode = self.invoiceCurrencyCode();
|
||||||
|
if (currencyMap[fromCode].exchange_rate && currencyMap[toCode].exchange_rate) {
|
||||||
|
var rate = fx.convert(1, {
|
||||||
|
from: fromCode,
|
||||||
|
to: toCode,
|
||||||
|
});
|
||||||
|
self.exchange_rate(roundToFour(rate));
|
||||||
|
} else {
|
||||||
|
self.exchange_rate(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, self);
|
||||||
|
|
||||||
self.getCurrency = function(currencyId) {
|
self.getCurrency = function(currencyId) {
|
||||||
return currencyMap[currencyId || self.account_currency_id()];
|
return currencyMap[currencyId || self.account_currency_id()];
|
||||||
};
|
};
|
||||||
|
@ -15,6 +15,13 @@
|
|||||||
countryMap[country.id] = country;
|
countryMap[country.id] = country;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fx.base = 'EUR';
|
||||||
|
fx.rates = {!! cache('currencies')
|
||||||
|
->keyBy('code')
|
||||||
|
->map(function($item, $key) {
|
||||||
|
return $item->exchange_rate ?: 1;
|
||||||
|
}); !!};
|
||||||
|
|
||||||
var NINJA = NINJA || {};
|
var NINJA = NINJA || {};
|
||||||
@if (Auth::check())
|
@if (Auth::check())
|
||||||
NINJA.primaryColor = "{{ Auth::user()->account->primary_color }}";
|
NINJA.primaryColor = "{{ Auth::user()->account->primary_color }}";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user