mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Merge pull request #9735 from turbo124/v5-develop
Fixes for exchange rate
This commit is contained in:
commit
bfac91851a
@ -12,37 +12,38 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App;
|
||||
use App\Models\User;
|
||||
use App\Utils\Ninja;
|
||||
use App\Models\Quote;
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Vendor;
|
||||
use App\Models\Account;
|
||||
use App\Models\Company;
|
||||
use App\Models\Contact;
|
||||
use App\Models\Expense;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\CompanyUser;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\CompanyLedger;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\VendorContact;
|
||||
use App\Models\BankTransaction;
|
||||
use App\Models\QuoteInvitation;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Factory\ClientContactFactory;
|
||||
use App\Factory\VendorContactFactory;
|
||||
use App\Jobs\Company\CreateCompanyToken;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Account;
|
||||
use App\Models\BankTransaction;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyLedger;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\CompanyUser;
|
||||
use App\Models\Contact;
|
||||
use App\Models\Credit;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\Quote;
|
||||
use App\Models\QuoteInvitation;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Models\RecurringInvoiceInvitation;
|
||||
use App\Models\User;
|
||||
use App\Models\Vendor;
|
||||
use App\Models\VendorContact;
|
||||
use App\Utils\Ninja;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/*
|
||||
@ -130,6 +131,7 @@ class CheckData extends Command
|
||||
$this->checkContactEmailAndSendEmailStatus();
|
||||
$this->checkPaymentCurrency();
|
||||
$this->checkSubdomainsSet();
|
||||
$this->checkExpenseCurrency();
|
||||
|
||||
if (Ninja::isHosted()) {
|
||||
$this->checkAccountStatuses();
|
||||
@ -1158,7 +1160,21 @@ class CheckData extends Command
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function checkExpenseCurrency()
|
||||
{
|
||||
Expense::with('company')
|
||||
->withTrashed()
|
||||
->whereNull('exchange_rate')
|
||||
->orWhere('exchange_rate', 0)
|
||||
->cursor()
|
||||
->each(function ($expense){
|
||||
$expense->exchange_rate = 1;
|
||||
$expense->saveQuietly();
|
||||
|
||||
$this->logMessage("Fixing - exchange rate for expense :: {$expense->id}");
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -11,16 +11,17 @@
|
||||
|
||||
namespace App\Jobs\Cron;
|
||||
|
||||
use App\Events\Expense\ExpenseWasCreated;
|
||||
use App\Factory\RecurringExpenseToExpenseFactory;
|
||||
use App\Utils\Ninja;
|
||||
use App\Libraries\MultiDB;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\Models\RecurringExpense;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\GeneratesCounter;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Utils\Traits\GeneratesCounter;
|
||||
use App\Events\Expense\ExpenseWasCreated;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use App\Factory\RecurringExpenseToExpenseFactory;
|
||||
use App\Libraries\Currency\Conversion\CurrencyApi;
|
||||
|
||||
class RecurringExpensesCron
|
||||
{
|
||||
@ -109,6 +110,15 @@ class RecurringExpensesCron
|
||||
$expense->payment_date = now()->format('Y-m-d');
|
||||
}
|
||||
|
||||
if ((int)$expense->company->settings->currency_id != $expense->currency_id) {
|
||||
$exchange_rate = new CurrencyApi();
|
||||
|
||||
$expense->exchange_rate = $exchange_rate->exchangeRate($expense->currency_id, (int)$expense->company->settings->currency_id, Carbon::parse($expense->date));
|
||||
}
|
||||
else {
|
||||
$expense->exchange_rate = 1;
|
||||
}
|
||||
|
||||
$expense->number = $this->getNextExpenseNumber($expense);
|
||||
$expense->saveQuietly();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user