added option to import payments from csv file
This commit is contained in:
+5
-23
@@ -2,13 +2,11 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Models\Activity;
|
||||
|
||||
class Payment extends Model
|
||||
{
|
||||
@@ -17,7 +15,8 @@ class Payment extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'account_id',
|
||||
'amount_cents',
|
||||
'amount',
|
||||
'balance_before',
|
||||
'currency',
|
||||
'reference',
|
||||
'paid_at',
|
||||
@@ -31,7 +30,8 @@ protected function casts(): array
|
||||
return [
|
||||
'paid_at' => 'datetime',
|
||||
'meta' => 'array',
|
||||
'amount_cents' => 'integer',
|
||||
'amount' => 'decimal:4',
|
||||
'balance_before' => 'decimal:4',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -55,23 +55,5 @@ public function type(): BelongsTo
|
||||
return $this->belongsTo(\App\Models\PaymentType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor to expose decimal amount for JSON serialization and UI convenience.
|
||||
*/
|
||||
protected function amount(): Attribute
|
||||
{
|
||||
return Attribute::get(function () {
|
||||
$cents = (int) ($this->attributes['amount_cents'] ?? 0);
|
||||
|
||||
return $cents / 100;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutator to set amount via decimal; stores in cents.
|
||||
*/
|
||||
public function setAmountAttribute($value): void
|
||||
{
|
||||
$this->attributes['amount_cents'] = (int) round(((float) $value) * 100);
|
||||
}
|
||||
// amount is stored as decimal(20,4); default Eloquent get/set is sufficient
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user