diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 34744782fa82..17c8b764a62b 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -76,9 +76,6 @@ class CheckData extends Command config(['database.default' => $database]); } - if (! $this->option('client_id')) { - $this->checkPaidToDate(); - } $this->checkInvoiceBalances(); $this->checkInvoicePayments(); @@ -286,11 +283,6 @@ class CheckData extends Command } } - private function checkPaidToDate() - { - //Check the client paid to date value matches the sum of payments by the client - } - private function checkInvoiceBalances() { @@ -327,7 +319,7 @@ class CheckData extends Command $total_invoice_payments = 0; - foreach($client->invoices->where('is_deleted', false) as $invoice) + foreach($client->invoices as $invoice) { $total_amount = $invoice->payments->sum('pivot.amount'); $total_refund = $invoice->payments->sum('pivot.refunded'); @@ -357,7 +349,7 @@ class CheckData extends Command Client::cursor()->each(function ($client) use($wrong_balances){ - $client->invoices->where('is_deleted', false)->each(function ($invoice) use($wrong_balances){ + $client->invoices->where('is_deleted', false)->each(function ($invoice) use($wrong_balances, $client){ $total_amount = $invoice->payments->sum('pivot.amount'); $total_refund = $invoice->payments->sum('pivot.refunded'); @@ -387,8 +379,8 @@ class CheckData extends Command foreach(Client::cursor() as $client) { - $invoice_balance = $client->invoices->where('is_deleted', false)->sum('balance'); - $invoice_amounts = $client->invoices->where('is_deleted', false)->sum('amount') - $invoice_balance; + $invoice_balance = $client->invoices->sum('balance'); + $invoice_amounts = $client->invoices->sum('amount') - $invoice_balance; $ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first(); diff --git a/app/Models/Client.php b/app/Models/Client.php index e139572690ee..754119dc6a2c 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -192,7 +192,7 @@ class Client extends BaseModel implements HasLocalePreference public function invoices() { - return $this->hasMany(Invoice::class); + return $this->hasMany(Invoice::class)->withTrashed(); } public function shipping_country() diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 9500cbf62986..50cffcfd250b 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -196,7 +196,7 @@ class Invoice extends BaseModel public function payments() { - return $this->morphToMany(Payment::class, 'paymentable')->withPivot('amount', 'refunded')->withTimestamps(); + return $this->morphToMany(Payment::class, 'paymentable')->withPivot('amount', 'refunded')->withTimestamps()->withTrashed(); ; } diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index 8a1d0a0ca6d7..fca09eb897ab 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -84,12 +84,9 @@ class InvoiceRepository extends BaseRepository return; } - $invoice->is_deleted = true; - $invoice->save(); - - $invoice->delete(); - - event(new InvoiceWasDeleted($invoice, $invoice->company)); + $invoice->service()->handleCancellation()->save(); + + $invoice = $this->invoice_repo->delete($invoice); return $invoice; } diff --git a/config/ninja.php b/config/ninja.php index 21197611dbe5..0fd26a26c041 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -12,8 +12,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => env('APP_URL', ''), 'app_domain' => env('APP_DOMAIN', ''), - 'app_version' => '5.0.11', - 'minimum_client_version' => '5.0.11', + 'app_version' => '5.0.12', + 'minimum_client_version' => '5.0.12', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''), 'google_maps_api_key' => env('GOOGLE_MAPS_API_KEY'),