From 70c5913f1de88a4b4fa45b1f46379b1d4e0fda53 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 15 Jun 2020 16:06:32 +1000 Subject: [PATCH] fixes for currency type --- app/Jobs/Util/UploadAvatar.php | 3 ++ app/Models/Currency.php | 3 +- app/Services/Invoice/HandleReversal.php | 42 ++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/app/Jobs/Util/UploadAvatar.php b/app/Jobs/Util/UploadAvatar.php index 033907df6bbe..144c50240232 100644 --- a/app/Jobs/Util/UploadAvatar.php +++ b/app/Jobs/Util/UploadAvatar.php @@ -47,6 +47,9 @@ class UploadAvatar implements ShouldQueue $path = Storage::putFile('public/' . $this->directory, new File(sys_get_temp_dir().'/'.$tmp_file)); +info($path); +info($tmp_file); + $url = Storage::url($path); //return file path diff --git a/app/Models/Currency.php b/app/Models/Currency.php index 809766520d17..3fe1729308cf 100644 --- a/app/Models/Currency.php +++ b/app/Models/Currency.php @@ -25,6 +25,7 @@ class Currency extends StaticModel 'updated_at' => 'timestamp', 'created_at' => 'timestamp', 'deleted_at' => 'timestamp', - 'precision' => 'integer', + 'precision' => 'string', + //'precision' => 'integer', ]; } diff --git a/app/Services/Invoice/HandleReversal.php b/app/Services/Invoice/HandleReversal.php index 55f5f72b940c..00989431d425 100644 --- a/app/Services/Invoice/HandleReversal.php +++ b/app/Services/Invoice/HandleReversal.php @@ -45,15 +45,13 @@ class HandleReversal extends AbstractService } if($this->invoice->status_id == Invoice::STATUS_CANCELLED) - $this->invoice->service()->reverseCancellation(); + $this->invoice = $this->invoice->service()->reverseCancellation()->save(); - /*Consider if we have just cancelled the invoice here... this is broken!*/ $balance_remaining = $this->invoice->balance; $total_paid = $this->invoice->amount - $this->invoice->balance; /*Adjust payment applied and the paymentables to the correct amount */ - $paymentables = Paymentable::wherePaymentableType(Invoice::class) ->wherePaymentableId($this->invoice->id) ->get(); @@ -115,6 +113,42 @@ class HandleReversal extends AbstractService return $this->invoice; //create a ledger row for this with the resulting Credit ( also include an explanation in the notes section ) } + + + // public function run2() + // { + + // /* Check again!! */ + // if (!$this->invoice->invoiceReversable($this->invoice)) { + // return $this->invoice; + // } + + // if($this->invoice->status_id == Invoice::STATUS_CANCELLED) + // $this->invoice = $this->invoice->service()->reverseCancellation()->save(); + + // //$balance_remaining = $this->invoice->balance; + + // //$total_paid = $this->invoice->amount - $this->invoice->balance; + + // /*Adjust payment applied and the paymentables to the correct amount */ + // $paymentables = Paymentable::wherePaymentableType(Invoice::class) + // ->wherePaymentableId($this->invoice->id) + // ->get(); + + // $total_paid = 0; + + // $paymentables->each(function ($paymentable) use ($total_paid) { + + // $reversable_amount = $paymentable->amount - $paymentable->refunded; + // $total_paid -= $reversable_amount; + // $paymentable->amount = $paymentable->refunded; + // $paymentable->save(); + // }); + + // //Unwinding any payments made to this invoice + + + // } } -// The client paid to date amount is reduced by the calculated amount of (invoice balance - invoice amount). + \ No newline at end of file