From 4be07e21f08891d77b80e46f099075eeaabff5b9 Mon Sep 17 00:00:00 2001 From: Abhishek Negi Date: Wed, 28 Feb 2024 10:56:44 +0530 Subject: [PATCH 1/4] added amount diff feature in invoice listing --- Modules/Invoice/Entities/Invoice.php | 23 +++++++++++++++++++ .../Invoice/Resources/views/index.blade.php | 10 ++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Modules/Invoice/Entities/Invoice.php b/Modules/Invoice/Entities/Invoice.php index b862a9c712..9d0f7dd200 100644 --- a/Modules/Invoice/Entities/Invoice.php +++ b/Modules/Invoice/Entities/Invoice.php @@ -171,6 +171,29 @@ public function invoiceAmount() return trim(optional($country)->currency_symbol . $amount); } + public function invoiceAmountDifference() + { + $amountDifference = 0; + $lastInvoiceEndDate = $this->sent_on->subMonth()->endOfMonth(); + $amount = (float) $this->amount; + if ($this->client->type == 'indian') { + $amount += (float) $this->gst; + } + $currentMonthAmount = $amount; + $lastMonthAmountDetail = self::where('sent_on', '<', $lastInvoiceEndDate) + ->where('client_id', $this->client_id)->where('project_id', $this->project_id) + ->orderBy('sent_on', 'DESC') + ->first(); + $lastMonthAmount = $lastMonthAmountDetail ? ((float) $lastMonthAmountDetail->amount + (float) $lastMonthAmountDetail->gst) : 0; + $amountDifference = $currentMonthAmount - $lastMonthAmount; + if ($lastMonthAmount != 0) { + $percentage = number_format(($amountDifference / $lastMonthAmount) * 100, 2); + return "$amountDifference ($percentage%)"; + } else { + return $amountDifference; + } + } + public function invoiceAmounts() { $amount = (int) $this->amount; diff --git a/Modules/Invoice/Resources/views/index.blade.php b/Modules/Invoice/Resources/views/index.blade.php index b232ff401d..55d0e79b9c 100644 --- a/Modules/Invoice/Resources/views/index.blade.php +++ b/Modules/Invoice/Resources/views/index.blade.php @@ -113,11 +113,17 @@ class="fa fa-plus mr-1">Add Invoice @endphp {{ $loop->iteration }} - {{ $invoice->client->name }} + {{ $invoice->client->name }} {{ optional($invoice->project)->name ?: $invoice->client->name . ' Projects' }} {{ $invoice->invoice_number }} - {{ $invoice->invoiceAmount() }} + + {{ $invoice->invoiceAmount() }}
+ + {{ $invoice->invoiceAmountDifference() }} + + + {{ $invoice->sent_on->format(config('invoice.default-date-format')) }} Date: Wed, 28 Feb 2024 11:25:50 +0530 Subject: [PATCH 2/4] clii check fixed --- Modules/Invoice/Entities/Invoice.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/Invoice/Entities/Invoice.php b/Modules/Invoice/Entities/Invoice.php index 9d0f7dd200..d2f94c371b 100644 --- a/Modules/Invoice/Entities/Invoice.php +++ b/Modules/Invoice/Entities/Invoice.php @@ -188,6 +188,7 @@ public function invoiceAmountDifference() $amountDifference = $currentMonthAmount - $lastMonthAmount; if ($lastMonthAmount != 0) { $percentage = number_format(($amountDifference / $lastMonthAmount) * 100, 2); + return "$amountDifference ($percentage%)"; } else { return $amountDifference; From e4226231549ffceeddadd194ab2a12caf059e214 Mon Sep 17 00:00:00 2001 From: Abhishek Negi Date: Wed, 28 Feb 2024 11:35:58 +0530 Subject: [PATCH 3/4] syncing up --- Modules/Invoice/Entities/Invoice.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/Invoice/Entities/Invoice.php b/Modules/Invoice/Entities/Invoice.php index d2f94c371b..9f5e13a655 100644 --- a/Modules/Invoice/Entities/Invoice.php +++ b/Modules/Invoice/Entities/Invoice.php @@ -189,10 +189,10 @@ public function invoiceAmountDifference() if ($lastMonthAmount != 0) { $percentage = number_format(($amountDifference / $lastMonthAmount) * 100, 2); - return "$amountDifference ($percentage%)"; - } else { - return $amountDifference; + return "{$amountDifference} ({$percentage}%)"; } + + return $amountDifference; } public function invoiceAmounts() From 97f8f58fb99e671e86d482e51bd6198d2d651579 Mon Sep 17 00:00:00 2001 From: Abhishek Negi Date: Wed, 28 Feb 2024 11:42:16 +0530 Subject: [PATCH 4/4] minor changes --- Modules/Invoice/Entities/Invoice.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Invoice/Entities/Invoice.php b/Modules/Invoice/Entities/Invoice.php index 9f5e13a655..1233005c65 100644 --- a/Modules/Invoice/Entities/Invoice.php +++ b/Modules/Invoice/Entities/Invoice.php @@ -184,10 +184,10 @@ public function invoiceAmountDifference() ->where('client_id', $this->client_id)->where('project_id', $this->project_id) ->orderBy('sent_on', 'DESC') ->first(); - $lastMonthAmount = $lastMonthAmountDetail ? ((float) $lastMonthAmountDetail->amount + (float) $lastMonthAmountDetail->gst) : 0; + $lastMonthAmount = $lastMonthAmountDetail ? (float) $lastMonthAmountDetail->amount + (float) $lastMonthAmountDetail->gst : 0; $amountDifference = $currentMonthAmount - $lastMonthAmount; if ($lastMonthAmount != 0) { - $percentage = number_format(($amountDifference / $lastMonthAmount) * 100, 2); + $percentage = number_format($amountDifference / $lastMonthAmount * 100, 2); return "{$amountDifference} ({$percentage}%)"; }