Skip to content

Commit

Permalink
Merge pull request #3432 from ColoredCow/feature/added-billing-amount…
Browse files Browse the repository at this point in the history
…-changes-in-invocie-page

#3431/Display Invoice Changes and Percentages in Invoice Screen
  • Loading branch information
P4NK4J authored Feb 28, 2024
2 parents 35dcd24 + 97f8f58 commit a725a09
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
24 changes: 24 additions & 0 deletions Modules/Invoice/Entities/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions Modules/Invoice/Resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,17 @@ class="fa fa-plus mr-1"></i>Add Invoice</a>
@endphp
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $invoice->client->name }}</td>
<td><a href="{{ route('reports.finance.dashboard.client', ['client_id' => $invoice->client->id]) }}">{{ $invoice->client->name }}</td>
<td>{{ optional($invoice->project)->name ?: $invoice->client->name . ' Projects' }}</td>
<td><a href="{{ route('invoice.edit', $invoice) }}">{{ $invoice->invoice_number }}</a>
</td>
<td>{{ $invoice->invoiceAmount() }}</td>
<td>
{{ $invoice->invoiceAmount() }} </br>
<span class="{{ $invoice->invoiceAmountDifference() >= 0 ? 'text-success' : 'text-danger' }} small">
{{ $invoice->invoiceAmountDifference() }}
</span>
</td>

<td class="text-center">
{{ $invoice->sent_on->format(config('invoice.default-date-format')) }}</td>
<td
Expand Down

0 comments on commit a725a09

Please sign in to comment.