From 8cff663d521a09fb28c328c291b31ba609abee62 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Jan 2022 14:11:08 +1100 Subject: [PATCH 1/3] Minor fixes for counter reset --- app/Utils/Traits/GeneratesCounter.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/Utils/Traits/GeneratesCounter.php b/app/Utils/Traits/GeneratesCounter.php index 2feebd7888..d84793295f 100644 --- a/app/Utils/Traits/GeneratesCounter.php +++ b/app/Utils/Traits/GeneratesCounter.php @@ -532,41 +532,41 @@ trait GeneratesCounter switch ($reset_counter_frequency) { case RecurringInvoice::FREQUENCY_DAILY: - $new_reset_date = now()->addDay(); + $new_reset_date = $reset_date->addDay(); break; case RecurringInvoice::FREQUENCY_WEEKLY: - $new_reset_date = now()->addWeek(); + $new_reset_date = $reset_date->addWeek(); break; case RecurringInvoice::FREQUENCY_TWO_WEEKS: - $new_reset_date = now()->addWeeks(2); + $new_reset_date = $reset_date->addWeeks(2); break; case RecurringInvoice::FREQUENCY_FOUR_WEEKS: - $new_reset_date = now()->addWeeks(4); + $new_reset_date = $reset_date->addWeeks(4); break; case RecurringInvoice::FREQUENCY_MONTHLY: - $new_reset_date = now()->addMonth(); + $new_reset_date = $reset_date->addMonth(); break; case RecurringInvoice::FREQUENCY_TWO_MONTHS: - $new_reset_date = now()->addMonths(2); + $new_reset_date = $reset_date->addMonths(2); break; case RecurringInvoice::FREQUENCY_THREE_MONTHS: - $new_reset_date = now()->addMonths(3); + $new_reset_date = $reset_date->addMonths(3); break; case RecurringInvoice::FREQUENCY_FOUR_MONTHS: - $new_reset_date = now()->addMonths(4); + $new_reset_date = $reset_date->addMonths(4); break; case RecurringInvoice::FREQUENCY_SIX_MONTHS: - $new_reset_date = now()->addMonths(6); + $new_reset_date = $reset_date->addMonths(6); break; case RecurringInvoice::FREQUENCY_ANNUALLY: - $new_reset_date = now()->addYear(); + $new_reset_date = $reset_date->addYear(); break; case RecurringInvoice::FREQUENCY_TWO_YEARS: - $new_reset_date = now()->addYears(2); + $new_reset_date = $reset_date->addYears(2); break; default: - $new_reset_date = now()->addYear(); + $new_reset_date = $reset_date->addYear(); break; } From 57ea035c62318600e964a06859e29340cf0a2785 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Jan 2022 15:32:04 +1100 Subject: [PATCH 2/3] Add touchPdf() to Credit Service --- app/Services/Credit/CreditService.php | 36 +++++++++++++++++++++++++++ app/Services/Credit/MarkSent.php | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index 22bd94a564..465fd522f5 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -12,6 +12,7 @@ namespace App\Services\Credit; use App\Factory\PaymentFactory; +use App\Jobs\Entity\CreateEntityPdf; use App\Jobs\Util\UnlinkFile; use App\Models\Credit; use App\Models\Payment; @@ -98,6 +99,8 @@ class CreditService if($this->credit->balance > 0) return $this; + $this->markSent(); + $payment_repo = new PaymentRepository(new CreditRepository()); //set credit balance to zero @@ -132,6 +135,7 @@ class CreditService ->client ->service() ->updatePaidToDate($adjustment) + ->setStatus(Credit::STATUS_APPLIED) ->save(); event('eloquent.created: App\Models\Payment', $payment); @@ -176,6 +180,38 @@ class CreditService return $this; } + /** + * Sometimes we need to refresh the + * PDF when it is updated etc. + * @return InvoiceService + */ + public function touchPdf($force = false) + { + try { + + if($force){ + + $this->credit->invitations->each(function ($invitation) { + CreateEntityPdf::dispatchNow($invitation); + }); + + return $this; + } + + $this->credit->invitations->each(function ($invitation) { + CreateEntityPdf::dispatch($invitation); + }); + + } + catch(\Exception $e){ + + nlog("failed creating invoices in Touch PDF"); + + } + + return $this; + } + public function fillDefaults() { $settings = $this->credit->client->getMergedSettings(); diff --git a/app/Services/Credit/MarkSent.php b/app/Services/Credit/MarkSent.php index b02e85e50d..1a39b3960c 100644 --- a/app/Services/Credit/MarkSent.php +++ b/app/Services/Credit/MarkSent.php @@ -42,7 +42,7 @@ class MarkSent ->setStatus(Credit::STATUS_SENT) ->applyNumber() ->adjustBalance($this->credit->amount) - ->deletePdf() + ->touchPdf() ->save(); event(new CreditWasMarkedSent($this->credit, $this->credit->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); From 1034622fbca14ce3c824a1c07f5af29d47552e31 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 20 Jan 2022 09:26:52 +1100 Subject: [PATCH 3/3] updates for payment currencyid --- app/Http/Controllers/ClientPortal/PaymentController.php | 3 +++ app/Repositories/PaymentRepository.php | 2 ++ app/Services/Credit/CreditService.php | 1 + 3 files changed, 6 insertions(+) diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index 7bdb1c2dbd..0e42d64f47 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -119,6 +119,9 @@ class PaymentController extends Controller } else { $payment = PaymentFactory::create($payment_hash->fee_invoice->company_id, $payment_hash->fee_invoice->user_id); $payment->client_id = $payment_hash->fee_invoice->client_id; + + $payment->saveQuietly(); + $payment->currency_id = $payment->client->getSetting('currency_id'); $payment->saveQuietly(); $payment_hash->payment_id = $payment->id; diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index a4a70c834c..b66356a42d 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -106,6 +106,7 @@ class PaymentRepository extends BaseRepository { $payment->fill($data); $payment->is_manual = true; $payment->status_id = Payment::STATUS_COMPLETED; + $payment->save(); /*Save documents*/ @@ -207,6 +208,7 @@ class PaymentRepository extends BaseRepository { $payment->exchange_rate = $exchange_rate->exchangeRate($client_currency, $company_currency, Carbon::parse($payment->date)); // $payment->exchange_currency_id = $client_currency; $payment->exchange_currency_id = $company_currency; + $payment->currency_id = $client_currency; } diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index 465fd522f5..8bd2e8c891 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -119,6 +119,7 @@ class CreditService $payment->status_id = Payment::STATUS_COMPLETED; $payment->type_id = PaymentType::CREDIT; $payment->is_manual = true; + $payment->currency_id = $this->credit->client->getSetting('currency_id'); $payment->date = now(); $payment->saveQuietly();