Skip to content

Commit d46fa42

Browse files
Merge pull request #108 from khalidmaquilang/hotfix/si-123-remaining-sort-bug
SI-123 | Hotfix | add virtual field
2 parents feae789 + e26b6dd commit d46fa42

File tree

4 files changed

+58
-20
lines changed

4 files changed

+58
-20
lines changed

app/Models/PurchaseOrder.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,15 @@ class PurchaseOrder extends Model
4949
* @var string[]
5050
*/
5151
protected $appends = [
52-
'remaining_amount',
5352
'formatted_remaining_amount',
5453
];
5554

56-
/**
57-
* @return float
58-
*/
59-
public function getRemainingAmountAttribute(): float
60-
{
61-
return $this->total_amount - $this->paid_amount;
62-
}
63-
6455
/**
6556
* @return string
6657
*/
6758
public function getFormattedRemainingAmountAttribute(): string
6859
{
69-
return number_format($this->getRemainingAmountAttribute(), 2).' '.$this->company->getCurrency();
60+
return number_format($this->remaining_amount, 2).' '.$this->company->getCurrency();
7061
}
7162

7263
/**

app/Models/Sale.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,16 @@ class Sale extends Model
6262
* @var string[]
6363
*/
6464
protected $appends = [
65-
'remaining_amount',
6665
'formatted_remaining_amount',
6766
'formatted_discount',
6867
];
6968

70-
/**
71-
* @return float
72-
*/
73-
public function getRemainingAmountAttribute(): float
74-
{
75-
return $this->total_amount - $this->paid_amount;
76-
}
77-
7869
/**
7970
* @return string
8071
*/
8172
public function getFormattedRemainingAmountAttribute(): string
8273
{
83-
return number_format($this->getRemainingAmountAttribute(), 2).' '.$this->company->getCurrency();
74+
return number_format($this->remaining_amount, 2).' '.$this->company->getCurrency();
8475
}
8576

8677
/**
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('purchase_orders', function (Blueprint $table) {
15+
$table->decimal('remaining_amount')->virtualAs('total_amount - paid_amount')->after('paid_amount');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('purchase_orders', function (Blueprint $table) {
25+
$table->dropColumn('remaining_amount');
26+
});
27+
}
28+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('sales', function (Blueprint $table) {
15+
$table->decimal('remaining_amount')->virtualAs('total_amount - paid_amount')->after('paid_amount');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('sales', function (Blueprint $table) {
25+
$table->dropColumn('remaining_amount');
26+
});
27+
}
28+
};

0 commit comments

Comments
 (0)