diff --git a/app/Services/Report/ProfitLoss.php b/app/Services/Report/ProfitLoss.php index 20220fa76aea..2c506a1613f6 100644 --- a/app/Services/Report/ProfitLoss.php +++ b/app/Services/Report/ProfitLoss.php @@ -15,6 +15,7 @@ use App\Libraries\Currency\Conversion\CurrencyApi; use App\Libraries\MultiDB; use App\Models\Company; use App\Models\Expense; +use App\Models\Payment; use Illuminate\Support\Carbon; class ProfitLoss @@ -33,6 +34,10 @@ class ProfitLoss private float $income_taxes = 0; + private float $credit = 0; + + private float $credit_taxes = 0; + private array $expenses; 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; + + } + + } + + }); + } + /** => [ diff --git a/tests/Feature/Export/ProfitAndLossReportTest.php b/tests/Feature/Export/ProfitAndLossReportTest.php index 0d7a6e5f2935..5904c4227e31 100644 --- a/tests/Feature/Export/ProfitAndLossReportTest.php +++ b/tests/Feature/Export/ProfitAndLossReportTest.php @@ -11,6 +11,7 @@ namespace Tests\Feature\Export; use App\DataMapper\ClientSettings; +use App\DataMapper\CompanySettings; use App\Factory\InvoiceFactory; use App\Models\Account; use App\Models\Client; @@ -93,8 +94,13 @@ class ProfitAndLossReportTest extends TestCase '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([ 'account_id' => $this->account->id, + 'settings' => $settings ]); $this->payload = [