From 5fbdde6d61bd8f9688b380adf560161eb2e49760 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 9 Jun 2023 14:45:38 +1000 Subject: [PATCH] fixes for payments --- app/Console/Commands/CheckData.php | 29 ++++++++++++++++++++++++ app/Filters/PaymentFilters.php | 5 ++++ app/Jobs/Cron/UpdateCalculatedFields.php | 2 +- app/Models/BaseModel.php | 1 + app/Services/Client/ClientService.php | 2 +- app/Services/Credit/CreditService.php | 7 ------ app/Services/Report/ARSummaryReport.php | 2 +- 7 files changed, 38 insertions(+), 10 deletions(-) diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 5e6a18f1c9c4..1bb41116abe1 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -435,11 +435,40 @@ class CheckData extends Command private function checkEntityInvitations() { + RecurringInvoiceInvitation::where('deleted_at', "0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]); InvoiceInvitation::where('deleted_at', "0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]); QuoteInvitation::where('deleted_at', "0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]); CreditInvitation::where('deleted_at', "0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]); + InvoiceInvitation::where('sent_date', '0000-00-00 00:00:00')->cursor()->each(function ($ii) { + $ii->sent_date = null; + $ii->saveQuietly(); + }); + InvoiceInvitation::where('viewed_date', '0000-00-00 00:00:00')->cursor()->each(function ($ii) { + $ii->viewed_date = null; + $ii->saveQuietly(); + }); + + QuoteInvitation::where('sent_date', '0000-00-00 00:00:00')->cursor()->each(function ($ii) { + $ii->sent_date = null; + $ii->saveQuietly(); + }); + QuoteInvitation::where('viewed_date', '0000-00-00 00:00:00')->cursor()->each(function ($ii) { + $ii->viewed_date = null; + $ii->saveQuietly(); + }); + + CreditInvitation::where('sent_date', '0000-00-00 00:00:00')->cursor()->each(function ($ii) { + $ii->sent_date = null; + $ii->saveQuietly(); + }); + CreditInvitation::where('viewed_date', '0000-00-00 00:00:00')->cursor()->each(function ($ii) { + $ii->viewed_date = null; + $ii->saveQuietly(); + }); + + collect([Invoice::class, Quote::class, Credit::class, PurchaseOrder::class])->each(function ($entity) { if ($entity::doesntHave('invitations')->count() > 0) { diff --git a/app/Filters/PaymentFilters.php b/app/Filters/PaymentFilters.php index 58ab78f23687..236eeba519c0 100644 --- a/app/Filters/PaymentFilters.php +++ b/app/Filters/PaymentFilters.php @@ -102,8 +102,13 @@ class PaymentFilters extends QueryFilters if (count($payment_filters) >0) { $query->whereIn('status_id', $payment_filters); } + + if(in_array('partially_unapplied', $status_parameters)) { + $query->where('amount', '>', 'applied')->where('refunded', 0); + } }); + return $this->builder; } diff --git a/app/Jobs/Cron/UpdateCalculatedFields.php b/app/Jobs/Cron/UpdateCalculatedFields.php index 18e8c3f500f6..dcfdb6d48e90 100644 --- a/app/Jobs/Cron/UpdateCalculatedFields.php +++ b/app/Jobs/Cron/UpdateCalculatedFields.php @@ -11,6 +11,7 @@ namespace App\Jobs\Cron; +use App\Models\Payment; use App\Models\Project; use App\Libraries\MultiDB; use Illuminate\Support\Facades\Auth; @@ -65,7 +66,6 @@ class UpdateCalculatedFields $project->save(); }); - } } } diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 8f1dfb3e19c6..c6234bf12728 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -32,6 +32,7 @@ use Illuminate\Support\Str; * @property \App\Models\Company $company * @method static \Illuminate\Database\Eloquent\Builder|BaseModel|Illuminate\Database\Eloquent\Relations\BelongsTo|\Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo|\App\Models\Company company() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel with() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel newQuery() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel query() diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index d2fc9795099f..6492bdde5f89 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -80,7 +80,7 @@ class ClientService $amount = Payment::where('client_id', $this->client->id) ->where('is_deleted', 0) ->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED]) - ->sum(DB::Raw('amount - refunded - applied')); + ->sum(DB::Raw('amount - applied')); DB::connection(config('database.default'))->transaction(function () use ($amount) { $this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first(); diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index d9051df17224..4adc71cd290c 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -130,13 +130,6 @@ class CreditService ->credits() ->attach($this->credit->id, ['amount' => $adjustment]); - //reduce client paid_to_date by $this->credit->balance amount - // $this->credit - // ->client - // ->service() - // ->updatePaidToDate($adjustment) - // ->save(); - $client = $this->credit->client->fresh(); $client->service() ->updatePaidToDate($adjustment) diff --git a/app/Services/Report/ARSummaryReport.php b/app/Services/Report/ARSummaryReport.php index b561d0fbf538..c0299ce9a650 100644 --- a/app/Services/Report/ARSummaryReport.php +++ b/app/Services/Report/ARSummaryReport.php @@ -123,7 +123,7 @@ class ARSummaryReport extends BaseExport ->where('balance', '>', 0) ->where('is_deleted', 0) ->where(function ($query){ - $query->where('due_date', '<', now()->startOfDay()) + $query->where('due_date', '>', now()->startOfDay()) ->orWhereNull('due_date'); }) ->sum('balance');