diff --git a/Modules/Invoice/Entities/Invoice.php b/Modules/Invoice/Entities/Invoice.php index b862a9c712..1233005c65 100644 --- a/Modules/Invoice/Entities/Invoice.php +++ b/Modules/Invoice/Entities/Invoice.php @@ -171,6 +171,30 @@ 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}%)"; + } + + 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