Skip to content

Commit 3f5e6cc

Browse files
merge
2 parents 14891ec + d46fa42 commit 3f5e6cc

File tree

4 files changed

+58
-12
lines changed

4 files changed

+58
-12
lines changed

app/Models/PurchaseOrder.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,15 @@ class PurchaseOrder extends Model
5252
* @var string[]
5353
*/
5454
protected $appends = [
55-
'remaining_amount',
5655
'formatted_remaining_amount',
5756
];
5857

59-
/**
60-
* @return float
61-
*/
62-
public function getRemainingAmountAttribute(): float
63-
{
64-
return $this->total_amount - $this->paid_amount;
65-
}
66-
6758
/**
6859
* @return string
6960
*/
7061
public function getFormattedRemainingAmountAttribute(): string
7162
{
72-
return number_format($this->getRemainingAmountAttribute(), 2).' '.$this->company->getCurrency();
63+
return number_format($this->remaining_amount, 2).' '.$this->company->getCurrency();
7364
}
7465

7566
/**

app/Models/Sale.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class Sale extends Model
6666
* @var string[]
6767
*/
6868
protected $appends = [
69-
'remaining_amount',
7069
'formatted_remaining_amount',
7170
'formatted_discount',
7271
];
@@ -113,7 +112,7 @@ public function getRemainingAmountAttribute(): float
113112
*/
114113
public function getFormattedRemainingAmountAttribute(): string
115114
{
116-
return number_format($this->getRemainingAmountAttribute(), 2).' '.$this->company->getCurrency();
115+
return number_format($this->remaining_amount, 2).' '.$this->company->getCurrency();
117116
}
118117

119118
/**
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)