Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for displaying negative numbers #8324

Merged
merged 3 commits into from Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -23,6 +23,8 @@ class SubscriptionPurchaseController extends Controller
{
public function index(Subscription $subscription, Request $request)
{
App::setLocale($subscription->company->locale());

/* Make sure the contact is logged into the correct company for this subscription */
if (auth()->guard('contact')->user() && auth()->guard('contact')->user()->company_id != $subscription->company_id) {
auth()->guard('contact')->logout();
Expand All @@ -42,6 +44,9 @@ public function index(Subscription $subscription, Request $request)

public function upgrade(Subscription $subscription, Request $request)
{

App::setLocale($subscription->company->locale());

/* Make sure the contact is logged into the correct company for this subscription */
if (auth()->guard('contact')->user() && auth()->guard('contact')->user()->company_id != $subscription->company_id) {
auth()->guard('contact')->logout();
Expand Down
7 changes: 7 additions & 0 deletions app/Http/Livewire/BillingPortalPurchasev2.php
Expand Up @@ -271,13 +271,20 @@ private function emailOtpCode($code)
*/
public function handleCoupon()
{

$this->resetErrorBag('coupon');
$this->resetValidation('coupon');

if ($this->coupon == $this->subscription->promo_code) {
$this->valid_coupon = true;
$this->buildBundle();
} else {
$this->discount = 0;
$this->valid_coupon = false;
$this->buildBundle();
$errors = $this->getErrorBag();
$errors->add('coupon', ctrans('texts.invalid_coupon'));
return $this;
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Livewire/SubscriptionsTable.php
Expand Up @@ -39,9 +39,9 @@ public function render()
->where('company_id', $this->company->id)
->whereNotNull('subscription_id')
->where('is_deleted', false)
->where('status_id', RecurringInvoice::STATUS_ACTIVE)
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
->whereIn('status_id', [RecurringInvoice::STATUS_ACTIVE, RecurringInvoice::STATUS_PAUSED])
->withTrashed()
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
->paginate($this->per_page);

return render('components.livewire.subscriptions-table', [
Expand Down
1 change: 0 additions & 1 deletion app/Services/PdfMaker/Design.php
Expand Up @@ -13,7 +13,6 @@
namespace App\Services\PdfMaker;

use App\Models\Credit;
use App\Models\Invoice;
use App\Models\Quote;
use App\Services\PdfMaker\Designs\Utilities\BaseDesign;
use App\Services\PdfMaker\Designs\Utilities\DesignHelpers;
Expand Down
8 changes: 8 additions & 0 deletions app/Utils/Number.php
Expand Up @@ -201,6 +201,8 @@ public static function formatMoney($value, $entity) :string
public static function formatMoneyNoRounding($value, $entity) :string
{
$currency = $entity->currency();

$_value = $value;

$thousand = $currency->thousand_separator;
$decimal = $currency->decimal_separator;
Expand Down Expand Up @@ -247,6 +249,12 @@ public static function formatMoneyNoRounding($value, $entity) :string
} elseif ($swapSymbol) {
return "{$value} ".trim($symbol);
} elseif ($entity->getSetting('show_currency_code') === false) {

if ($_value < 0) {
$value = substr($value, 1);
$symbol = "-{$symbol}";
}

return "{$symbol}{$value}";
} else {
return self::formatValue($value, $currency);
Expand Down
1 change: 1 addition & 0 deletions lang/en/texts.php
Expand Up @@ -5010,6 +5010,7 @@
'change_plan_description' => 'Upgrade or downgrade your current plan.',
'add_company_logo' => 'Add Logo',
'add_stripe' => 'Add Stripe',
'invalid_coupon' => 'Invalid Coupon',
);


Expand Down
Expand Up @@ -253,6 +253,14 @@
<span>{{ ctrans('texts.apply') }}</span>
</button>
</div>
@if($errors && $errors->has('coupon'))
@error("coupon")
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">
<span class="block sm:inline text-sm">{{ $message }} </span>
<span class="absolute top-0 bottom-0 right-0 px-4 py-3">
</div>
@enderror
@endif
</div>
</form>
@endif
Expand Down Expand Up @@ -347,7 +355,6 @@ class="relative -ml-px inline-flex items-center space-x-2 rounded border border-
<span class="absolute top-0 bottom-0 right-0 px-4 py-3">
</div>
@enderror

</div>
</form>
@endif
Expand Down
Expand Up @@ -15,6 +15,11 @@
<table class="min-w-full shadow rounded border border-gray-200 mt-4 credits-table">
<thead>
<tr>
<th class="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-white uppercase border-b border-gray-200 bg-primary">
<p role="button" wire:click="sortBy('status_id')" class="cursor-pointer">
{{ ctrans('texts.status') }}
</p>
</th>
<th class="px-6 py-3 text-xs font-medium leading-4 tracking-wider text-left text-white uppercase border-b border-gray-200 bg-primary">
<p role="button" wire:click="sortBy('number')" class="cursor-pointer">
{{ ctrans('texts.subscription') }}
Expand Down Expand Up @@ -47,6 +52,9 @@
<tbody>
@forelse($recurring_invoices as $recurring_invoice)
<tr class="bg-white group hover:bg-gray-100">
<td class="px-6 py-4 whitespace-nowrap text-sm leading-5 text-gray-500">
{!! $recurring_invoice->badgeForStatus($recurring_invoice->status_id) !!}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm leading-5 text-gray-500">
{{ $recurring_invoice->subscription->name }}
</td>
Expand Down