mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #6099 from turbo124/v5-develop
Set Exchange Rates on invoice when marked as paid
This commit is contained in:
commit
ceefde5378
@ -28,6 +28,7 @@ class CompanySettings extends BaseSettings
|
|||||||
public $lock_invoices = 'off'; //off,when_sent,when_paid //@implemented
|
public $lock_invoices = 'off'; //off,when_sent,when_paid //@implemented
|
||||||
|
|
||||||
public $enable_client_portal_tasks = false; //@ben to implement
|
public $enable_client_portal_tasks = false; //@ben to implement
|
||||||
|
public $show_all_tasks_client_portal = 'all'; // all, uninvoiced, invoiced
|
||||||
public $enable_client_portal_password = false; //@implemented
|
public $enable_client_portal_password = false; //@implemented
|
||||||
public $enable_client_portal = true; //@implemented
|
public $enable_client_portal = true; //@implemented
|
||||||
public $enable_client_portal_dashboard = false; // @TODO There currently is no dashboard so this is pending
|
public $enable_client_portal_dashboard = false; // @TODO There currently is no dashboard so this is pending
|
||||||
@ -268,6 +269,7 @@ class CompanySettings extends BaseSettings
|
|||||||
public $hide_empty_columns_on_pdf = false;
|
public $hide_empty_columns_on_pdf = false;
|
||||||
|
|
||||||
public static $casts = [
|
public static $casts = [
|
||||||
|
'show_all_tasks_client_portal' => 'string',
|
||||||
'entity_send_time' => 'int',
|
'entity_send_time' => 'int',
|
||||||
'shared_invoice_credit_counter' => 'bool',
|
'shared_invoice_credit_counter' => 'bool',
|
||||||
'reply_to_name' => 'string',
|
'reply_to_name' => 'string',
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoice Ninja (https://invoiceninja.com).
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
*
|
*
|
||||||
@ -98,6 +97,7 @@ class StripeConnectController extends BaseController
|
|||||||
$company_gateway->gateway_key = 'd14dd26a47cecc30fdd65700bfb67b34';
|
$company_gateway->gateway_key = 'd14dd26a47cecc30fdd65700bfb67b34';
|
||||||
$company_gateway->fees_and_limits = $fees_and_limits;
|
$company_gateway->fees_and_limits = $fees_and_limits;
|
||||||
$company_gateway->setConfig([]);
|
$company_gateway->setConfig([]);
|
||||||
|
$company_gateway->token_billing = 'always';
|
||||||
// $company_gateway->save();
|
// $company_gateway->save();
|
||||||
|
|
||||||
$payload = [
|
$payload = [
|
||||||
|
@ -29,7 +29,6 @@ class StripeController extends BaseController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return response()->json(['message' => 'Unauthorized'], 403);
|
return response()->json(['message' => 'Unauthorized'], 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +44,6 @@ class StripeController extends BaseController
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return response()->json(['message' => 'Unauthorized'], 403);
|
return response()->json(['message' => 'Unauthorized'], 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoice Ninja (https://invoiceninja.com).
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
*
|
*
|
||||||
|
@ -105,6 +105,7 @@ class WepaySignup extends Component
|
|||||||
$cg->update_details = false;
|
$cg->update_details = false;
|
||||||
$cg->config = encrypt(config('ninja.testvars.checkout'));
|
$cg->config = encrypt(config('ninja.testvars.checkout'));
|
||||||
$cg->fees_and_limits = $fees_and_limits;
|
$cg->fees_and_limits = $fees_and_limits;
|
||||||
|
$cg->token_billing = 'always';
|
||||||
$cg->save();
|
$cg->save();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -55,8 +55,15 @@ class QueryLogging
|
|||||||
//nlog($request->method().' - '.urldecode($request->url()).": $count queries - ".$time);
|
//nlog($request->method().' - '.urldecode($request->url()).": $count queries - ".$time);
|
||||||
// if($count > 50)
|
// if($count > 50)
|
||||||
//nlog($queries);
|
//nlog($queries);
|
||||||
|
$ip = '';
|
||||||
|
|
||||||
LightLogs::create(new DbQuery($request->method(), urldecode($request->url()), $count, $time, request()->ip()))
|
if(request()->header('Cf-Connecting-Ip'))
|
||||||
|
$ip = request()->header('Cf-Connecting-Ip');
|
||||||
|
else{
|
||||||
|
$ip = request()->ip();
|
||||||
|
}
|
||||||
|
|
||||||
|
LightLogs::create(new DbQuery($request->method(), urldecode($request->url()), $count, $time, $ip))
|
||||||
->batch();
|
->batch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class RecurringInvoicesCron
|
|||||||
nlog("Sending recurring invoices ".Carbon::now()->format('Y-m-d h:i:s'));
|
nlog("Sending recurring invoices ".Carbon::now()->format('Y-m-d h:i:s'));
|
||||||
|
|
||||||
if (! config('ninja.db.multi_db_enabled')) {
|
if (! config('ninja.db.multi_db_enabled')) {
|
||||||
$recurring_invoices = RecurringInvoice::whereDate('next_send_date', '<=', now())
|
$recurring_invoices = RecurringInvoice::whereDate('next_send_date', '<=', now()->toDateTimeString())
|
||||||
->whereNotNull('next_send_date')
|
->whereNotNull('next_send_date')
|
||||||
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||||
->where('remaining_cycles', '!=', '0')
|
->where('remaining_cycles', '!=', '0')
|
||||||
@ -64,7 +64,7 @@ class RecurringInvoicesCron
|
|||||||
foreach (MultiDB::$dbs as $db) {
|
foreach (MultiDB::$dbs as $db) {
|
||||||
MultiDB::setDB($db);
|
MultiDB::setDB($db);
|
||||||
|
|
||||||
$recurring_invoices = RecurringInvoice::whereDate('next_send_date', '<=', now())
|
$recurring_invoices = RecurringInvoice::whereDate('next_send_date', '<=', now()->toDateTimeString())
|
||||||
->whereNotNull('next_send_date')
|
->whereNotNull('next_send_date')
|
||||||
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
|
||||||
->where('remaining_cycles', '!=', '0')
|
->where('remaining_cycles', '!=', '0')
|
||||||
|
@ -55,7 +55,7 @@ class ReminderJob implements ShouldQueue
|
|||||||
{
|
{
|
||||||
nlog("Sending invoice reminders " . now()->format('Y-m-d h:i:s'));
|
nlog("Sending invoice reminders " . now()->format('Y-m-d h:i:s'));
|
||||||
|
|
||||||
Invoice::whereDate('next_send_date', '<=', now())
|
Invoice::whereDate('next_send_date', '<=', now()->toDateTimeString())
|
||||||
->where('is_deleted', 0)
|
->where('is_deleted', 0)
|
||||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
|
||||||
->where('balance', '>', 0)
|
->where('balance', '>', 0)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoice Ninja (https://invoiceninja.com).
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
*
|
*
|
||||||
|
@ -16,12 +16,14 @@ use App\Events\Payment\PaymentWasCreated;
|
|||||||
use App\Factory\PaymentFactory;
|
use App\Factory\PaymentFactory;
|
||||||
use App\Jobs\Invoice\InvoiceWorkflowSettings;
|
use App\Jobs\Invoice\InvoiceWorkflowSettings;
|
||||||
use App\Jobs\Payment\EmailPayment;
|
use App\Jobs\Payment\EmailPayment;
|
||||||
|
use App\Libraries\Currency\Conversion\CurrencyApi;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Services\AbstractService;
|
use App\Services\AbstractService;
|
||||||
use App\Services\Client\ClientService;
|
use App\Services\Client\ClientService;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use App\Utils\Traits\GeneratesCounter;
|
use App\Utils\Traits\GeneratesCounter;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
class MarkPaid extends AbstractService
|
class MarkPaid extends AbstractService
|
||||||
{
|
{
|
||||||
@ -63,6 +65,8 @@ class MarkPaid extends AbstractService
|
|||||||
/* Create a payment relationship to the invoice entity */
|
/* Create a payment relationship to the invoice entity */
|
||||||
$payment->save();
|
$payment->save();
|
||||||
|
|
||||||
|
$this->setExchangeRate($payment);
|
||||||
|
|
||||||
$payment->invoices()->attach($this->invoice->id, [
|
$payment->invoices()->attach($this->invoice->id, [
|
||||||
'amount' => $payment->amount,
|
'amount' => $payment->amount,
|
||||||
]);
|
]);
|
||||||
@ -70,6 +74,7 @@ class MarkPaid extends AbstractService
|
|||||||
$this->invoice->next_send_date = null;
|
$this->invoice->next_send_date = null;
|
||||||
|
|
||||||
$this->invoice->service()
|
$this->invoice->service()
|
||||||
|
->setExchangeRate()
|
||||||
->updateBalance($payment->amount * -1)
|
->updateBalance($payment->amount * -1)
|
||||||
->updatePaidToDate($payment->amount)
|
->updatePaidToDate($payment->amount)
|
||||||
->setStatus(Invoice::STATUS_PAID)
|
->setStatus(Invoice::STATUS_PAID)
|
||||||
@ -96,4 +101,22 @@ class MarkPaid extends AbstractService
|
|||||||
|
|
||||||
return $this->invoice;
|
return $this->invoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function setExchangeRate(Payment $payment)
|
||||||
|
{
|
||||||
|
|
||||||
|
$client_currency = $payment->client->getSetting('currency_id');
|
||||||
|
$company_currency = $payment->client->company->settings->currency_id;
|
||||||
|
|
||||||
|
if ($company_currency != $client_currency) {
|
||||||
|
|
||||||
|
$exchange_rate = new CurrencyApi();
|
||||||
|
|
||||||
|
$payment->exchange_rate = $exchange_rate->exchangeRate($client_currency, $company_currency, Carbon::parse($payment->date));
|
||||||
|
$payment->exchange_currency_id = $client_currency;
|
||||||
|
$payment->save();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user