Fixes for tests

This commit is contained in:
David Bomba 2022-05-13 11:13:25 +10:00
parent 00a99698ac
commit fd67d8202e
2 changed files with 52 additions and 0 deletions

View File

@ -15,6 +15,7 @@ use App\Libraries\Currency\Conversion\CurrencyApi;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use App\Models\Company; use App\Models\Company;
use App\Models\Expense; use App\Models\Expense;
use App\Models\Payment;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
class ProfitLoss class ProfitLoss
@ -33,6 +34,10 @@ class ProfitLoss
private float $income_taxes = 0; private float $income_taxes = 0;
private float $credit = 0;
private float $credit_taxes = 0;
private array $expenses; private array $expenses;
private array $income_map; private array $income_map;
@ -206,6 +211,47 @@ class ProfitLoss
} }
private function paymentEloquentIncome()
{
$amount_payment_paid = 0;
$amount_credit_paid = 0;
Payment::where('company_id', $this->company->id)
->whereIn('status_id', [1,4,5])
->where('is_deleted', 0)
->whereBetween('date', [$this->start_date, $this->end_date])
->whereHas('client', function ($query) {
$query->where('is_deleted',0);
})
->with(['company','client'])
->cursor()
->each(function ($payment) use($amount_payment_paid, $amount_credit_paid){
$company = $payment->company;
$client = $payment->client;
foreach($payment->paymentables as $pivot)
{
if($pivot->paymentable instanceOf \App\Models\Invoice){
$amount_payment_paid += $pivot->amount - $pivot->refunded;
//calc tax amount - pro rata if necessary
}
if($pivot->paymentable instanceOf \App\Models\Credit){
$amount_credit_paid += $pivot->amount - $pivot->refunded;
}
}
});
}
/** /**
=> [ => [

View File

@ -11,6 +11,7 @@
namespace Tests\Feature\Export; namespace Tests\Feature\Export;
use App\DataMapper\ClientSettings; use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings;
use App\Factory\InvoiceFactory; use App\Factory\InvoiceFactory;
use App\Models\Account; use App\Models\Account;
use App\Models\Client; use App\Models\Client;
@ -93,8 +94,13 @@ class ProfitAndLossReportTest extends TestCase
'email' => $this->faker->unique()->safeEmail, 'email' => $this->faker->unique()->safeEmail,
]); ]);
$settings = CompanySettings::defaults();
$settings->client_online_payment_notification = false;
$settings->client_manual_payment_notification = false;
$this->company = Company::factory()->create([ $this->company = Company::factory()->create([
'account_id' => $this->account->id, 'account_id' => $this->account->id,
'settings' => $settings
]); ]);
$this->payload = [ $this->payload = [