added option to import payments from csv file

This commit is contained in:
Simon Pocrnjič
2025-10-02 22:09:05 +02:00
parent 971a9e89d1
commit 12de0186cf
21 changed files with 2828 additions and 824 deletions
+5 -23
View File
@@ -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
}