Fixes for profit and loss reports

This commit is contained in:
David Bomba 2023-06-18 13:35:51 +10:00
parent f2d2cf2f4a
commit 1b1d7df53c
4 changed files with 21 additions and 18 deletions

View File

@ -527,11 +527,11 @@ class Account extends BaseModel
public function emailsSent()
{
if (is_null(Cache::get($this->key))) {
if (is_null(Cache::get("email_quota".$this->key))) {
return 0;
}
return Cache::get($this->key);
return Cache::get("email_quota".$this->key);
}
public function emailQuotaExceeded() :bool

View File

@ -40,7 +40,9 @@ class CompanyRepository extends BaseRepository
$company->fill($data);
/** Only required to handle v4 migration workloads */
if(Ninja::isHosted() && $company->isDirty('is_disabled') && !$company->is_disabled) {
// if(Ninja::isHosted() && $company->isDirty('is_disabled') && !$company->is_disabled) {
if($company->isDirty('is_disabled') && !$company->is_disabled) {
nlog("trigger");
Ninja::triggerForwarding($company->company_key, $company->owner()->email);
}

View File

@ -11,18 +11,19 @@
namespace App\Services\Report;
use App\Libraries\Currency\Conversion\CurrencyApi;
use App\Libraries\MultiDB;
use App\Models\Company;
use App\Models\Currency;
use App\Models\Expense;
use App\Models\Payment;
use App\Utils\Ninja;
use App\Utils\Number;
use League\Csv\Writer;
use App\Models\Company;
use App\Models\Expense;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\Currency;
use App\Libraries\MultiDB;
use Illuminate\Support\Str;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Str;
use League\Csv\Writer;
use App\Libraries\Currency\Conversion\CurrencyApi;
class ProfitLoss
{
@ -279,8 +280,6 @@ class ProfitLoss
->with(['company', 'client'])
->cursor()
->each(function ($payment) {
$company = $payment->company;
$client = $payment->client;
$map = new \stdClass;
$amount_payment_paid = 0;
@ -293,8 +292,8 @@ class ProfitLoss
$tax_amount_credit_converted = $tax_amount_credit_converted = 0;
foreach ($payment->paymentables as $pivot) {
if ($pivot->paymentable instanceof \App\Models\Invoice) {
$invoice = $pivot->paymentable;
if ($pivot->paymentable_type == 'invoices') {
$invoice = Invoice::withTrashed()->find($pivot->paymentable_id);
$amount_payment_paid += $pivot->amount - $pivot->refunded;
$amount_payment_paid_converted += $amount_payment_paid / ($payment->exchange_rate ?: 1);
@ -303,7 +302,7 @@ class ProfitLoss
$tax_amount_converted += (($amount_payment_paid / $invoice->amount) * $invoice->total_taxes) / $payment->exchange_rate;
}
if ($pivot->paymentable instanceof \App\Models\Credit) {
if ($pivot->paymentable_type == 'credits') {
$amount_credit_paid += $pivot->amount - $pivot->refunded;
$amount_credit_paid_converted += $amount_payment_paid / ($payment->exchange_rate ?: 1);

View File

@ -156,15 +156,17 @@ class Ninja
public static function triggerForwarding(string $company_key, string $email)
{
try {
Http::withHeaders([
$x = Http::withHeaders([
'X-API-HOSTED-SECRET' => config('ninja.ninja_hosted_secret'),
])->post(config('ninja.license_url').'/api/v1/enable_forwarding', [
'account_key' => $company_key,
'email' => $email,
]);
nlog($x->body());
}
catch (\Exception $e) {
nlog("attempt forwarding for{$email} - {$company_key}");
nlog("Attempt forwarding for {$email} - {$company_key} Failed");
}
}