mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Fixes for ACH notification with WePay
This commit is contained in:
parent
f604e463c2
commit
eaa6ba1d39
@ -131,6 +131,7 @@ class DemoMode extends Command
|
||||
'enabled_modules' => 32767,
|
||||
'company_key' => 'KEY',
|
||||
'enable_shop_api' => true,
|
||||
'markdown_email_enabled' => false,
|
||||
]);
|
||||
|
||||
$settings = $company->settings;
|
||||
|
@ -73,7 +73,7 @@ class WePayFailureNotification extends Notification
|
||||
public function toSlack($notifiable)
|
||||
{
|
||||
|
||||
(new SlackMessage)
|
||||
return (new SlackMessage)
|
||||
->success()
|
||||
->from(ctrans('texts.notification_bot'))
|
||||
->image('https://app.invoiceninja.com/favicon.png')
|
||||
|
@ -12,8 +12,10 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Factory\ExpenseFactory;
|
||||
use App\Libraries\Currency\Conversion\CurrencyApi;
|
||||
use App\Models\Expense;
|
||||
use App\Utils\Traits\GeneratesCounter;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* ExpenseRepository.
|
||||
@ -34,6 +36,10 @@ class ExpenseRepository extends BaseRepository
|
||||
public function save(array $data, Expense $expense) : ?Expense
|
||||
{
|
||||
$expense->fill($data);
|
||||
|
||||
if(!$expense->id)
|
||||
$expense = $this->processExchangeRates($data, $expense);
|
||||
|
||||
$expense->number = empty($expense->number) ? $this->getNextExpenseNumber($expense) : $expense->number;
|
||||
$expense->save();
|
||||
|
||||
@ -57,4 +63,27 @@ class ExpenseRepository extends BaseRepository
|
||||
ExpenseFactory::create(auth()->user()->company()->id, auth()->user()->id)
|
||||
);
|
||||
}
|
||||
|
||||
public function processExchangeRates($data, $expense)
|
||||
{
|
||||
|
||||
if(array_key_exists('exchange_rate', $data) && isset($data['exchange_rate']) && $data['exchange_rate'] != 1){
|
||||
return $expense;
|
||||
}
|
||||
|
||||
$expense_currency = $data['currency_id'];
|
||||
$company_currency = $expense->company->settings->currency_id;
|
||||
|
||||
if ($company_currency != $expense_currency) {
|
||||
|
||||
$exchange_rate = new CurrencyApi();
|
||||
|
||||
$expense->exchange_rate = $exchange_rate->exchangeRate($expense_currency, $company_currency, Carbon::parse($expense->date));
|
||||
|
||||
return $expense;
|
||||
}
|
||||
|
||||
return $expense;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,9 @@
|
||||
|
||||
namespace App\Services\Report;
|
||||
|
||||
use App\Libraries\Currency\Conversion\CurrencyApi;
|
||||
use App\Models\Company;
|
||||
use App\Models\Expense;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class ProfitLoss
|
||||
@ -26,6 +28,8 @@ class ProfitLoss
|
||||
|
||||
private $end_date;
|
||||
|
||||
protected CurrencyApi $currency_api;
|
||||
|
||||
/*
|
||||
payload variables.
|
||||
|
||||
@ -51,8 +55,9 @@ class ProfitLoss
|
||||
|
||||
protected Company $company;
|
||||
|
||||
public function __construct(Company $company, array $payload)
|
||||
public function __construct(Company $company, array $payload, CurrencyApi $currency_api)
|
||||
{
|
||||
$this->currency_api = $currency_api;
|
||||
|
||||
$this->company = $company;
|
||||
|
||||
@ -148,6 +153,55 @@ class ProfitLoss
|
||||
}
|
||||
|
||||
private function expenseCalc()
|
||||
{
|
||||
|
||||
$expenses = Expense::where('company_id', $this->company->id)
|
||||
->where('is_deleted', 0)
|
||||
->withTrashed()
|
||||
->whereBetween('date', [$this->start_date, $this->end_date])
|
||||
->cursor();
|
||||
|
||||
|
||||
if($this->is_tax_included)
|
||||
return $this->calculateExpensesWithTaxes($expenses);
|
||||
|
||||
return $this->calculateExpensesWithoutTaxes($expenses);
|
||||
|
||||
}
|
||||
|
||||
private function calculateExpensesWithTaxes($expenses)
|
||||
{
|
||||
|
||||
foreach($expenses as $expense)
|
||||
{
|
||||
|
||||
if(!$expense->calculate_tax_by_amount && !$expense->uses_inclusive_taxes)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function calculateExpensesWithoutTaxes($expenses)
|
||||
{
|
||||
$total = 0;
|
||||
$converted_total = 0;
|
||||
|
||||
foreach($expenses as $expense)
|
||||
{
|
||||
$total += $expense->amount;
|
||||
$total += $this->getConvertedTotal($expense);
|
||||
}
|
||||
}
|
||||
|
||||
private function getConvertedTotal($expense)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private function expenseCalcWithTax()
|
||||
{
|
||||
|
||||
return \DB::select( \DB::raw("
|
||||
|
Loading…
Reference in New Issue
Block a user