Skip to content

Commit

Permalink
Implement Tax Rates on invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Dec 20, 2019
1 parent 31deddd commit dad716c
Show file tree
Hide file tree
Showing 12 changed files with 772 additions and 164 deletions.
87 changes: 75 additions & 12 deletions resources/views/receipt.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,35 @@
<tr>
<th align="left">Description</th>
<th align="right">Date</th>

@if ($invoice->hasTax())
<th align="right">Tax</th>
@endif

<th align="right">Amount</th>
</tr>

<!-- Display The Invoice Items -->
@foreach ($invoice->invoiceItems() as $item)
<tr class="row">
<td colspan="2">{{ $item->description }}</td>

@if ($invoice->hasTax())
<td>
@if ($inclusiveTaxPercentage = $item->inclusiveTaxPercentage())
{{ $inclusiveTaxPercentage }}% incl.
@endif

@if ($item->hasBothInclusiveAndExclusiveTax())
+
@endif

@if ($exclusiveTaxPercentage = $item->exclusiveTaxPercentage())
{{ $exclusiveTaxPercentage }}%
@endif
</td>
@endif

<td>{{ $item->total() }}</td>
</tr>
@endforeach
Expand All @@ -137,22 +159,39 @@
{{ $subscription->startDateAsCarbon()->formatLocalized('%B %e, %Y') }} -
{{ $subscription->endDateAsCarbon()->formatLocalized('%B %e, %Y') }}
</td>

@if ($invoice->hasTax())
<td>
@if ($inclusiveTaxPercentage = $subscription->inclusiveTaxPercentage())
{{ $inclusiveTaxPercentage }}% incl.
@endif

@if ($subscription->hasBothInclusiveAndExclusiveTax())
+
@endif

@if ($exclusiveTaxPercentage = $subscription->exclusiveTaxPercentage())
{{ $exclusiveTaxPercentage }}%
@endif
</td>
@endif

<td>{{ $subscription->total() }}</td>
</tr>
@endforeach

<!-- Display The Subtotal -->
@if ($invoice->hasDiscount() || $invoice->tax_percent || $invoice->hasStartingBalance())
@if ($invoice->hasDiscount() || $invoice->hasTax() || $invoice->hasStartingBalance())
<tr>
<td colspan="2" style="text-align: right;">Subtotal</td>
<td colspan="{{ $invoice->hasTax() ? 3 : 2 }}" style="text-align: right;">Subtotal</td>
<td>{{ $invoice->subtotal() }}</td>
</tr>
@endif

<!-- Display The Discount -->
@if ($invoice->hasDiscount())
<tr>
<td colspan="2" style="text-align: right;">
<td colspan="{{ $invoice->hasTax() ? 3 : 2 }}" style="text-align: right;">
@if ($invoice->discountIsPercentage())
{{ $invoice->coupon() }} ({{ $invoice->percentOff() }}% Off)
@else
Expand All @@ -164,26 +203,50 @@
</tr>
@endif

<!-- Display The Tax Amount -->
@if ($invoice->tax_percent)
<tr>
<td colspan="2" style="text-align: right;">Tax ({{ $invoice->tax_percent }}%)</td>
<td>{{ $invoice->tax() }}</td>
</tr>
<!-- Display The Taxes -->
@if ($invoice->hasTax())
@unless ($invoice->isNotTaxExempt())
<tr>
<td colspan="{{ $invoice->hasTax() ? 3 : 2 }}" style="text-align: right;">
@if ($invoice->isTaxExempt())
Tax is exempted
@else
Tax to be paid on reverse charge basis
@endif
</td>
<td></td>
</tr>
@else
@foreach ($invoice->taxes() as $tax)
<tr>
<td colspan="3" style="text-align: right;">
{{ $tax->display_name }} {{ $tax->jurisdiction ? ' - '.$tax->jurisdiction : '' }}
({{ $tax->percentage }}%{{ $tax->isInclusive() ? ' incl.' : '' }})
</td>
<td>{{ $tax->amount() }}</td>
</tr>
@endforeach
@endunless
@endif

<!-- Starting Balance -->
@if ($invoice->hasStartingBalance())
<tr>
<td colspan="2" style="text-align: right;">Customer Balance</td>
<td colspan="{{ $invoice->hasTax() ? 3 : 2 }}" style="text-align: right;">
Customer Balance
</td>
<td>{{ $invoice->startingBalance() }}</td>
</tr>
@endif

<!-- Display The Final Total -->
<tr>
<td colspan="2" style="text-align: right;"><strong>Total</strong></td>
<td><strong>{{ $invoice->total() }}</strong></td>
<td colspan="{{ $invoice->hasTax() ? 3 : 2 }}" style="text-align: right;">
<strong>Total</strong>
</td>
<td>
<strong>{{ $invoice->total() }}</strong>
</td>
</tr>
</table>
</td>
Expand Down
30 changes: 30 additions & 0 deletions src/Billable.php
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,36 @@ public function taxRates()
return [];
}

/**
* Determine if the customer is not exempted from taxes.
*
* @return bool
*/
public function isNotTaxExempt()
{
return $this->asStripeCustomer()->tax_exempt === StripeCustomer::TAX_EXEMPT_NONE;
}

/**
* Determine if the customer is exempted from taxes.
*
* @return bool
*/
public function isTaxExempt()
{
return $this->asStripeCustomer()->tax_exempt === StripeCustomer::TAX_EXEMPT_EXEMPT;
}

/**
* Determine if reverse charge applies to the customer.
*
* @return bool
*/
public function reverseChargeApplies()
{
return $this->asStripeCustomer()->tax_exempt === StripeCustomer::TAX_EXEMPT_REVERSE;
}

/**
* Get the default Stripe API options for the current Billable model.
*
Expand Down
Loading

0 comments on commit dad716c

Please sign in to comment.