invoiceninja/app/models/Credit.php

56 lines
1 KiB
PHP
Raw Normal View History

2013-12-01 22:58:25 +02:00
<?php
2013-12-04 18:20:14 +02:00
class Credit extends EntityModel
2015-01-11 14:30:08 +02:00
{
public function invoice()
{
return $this->belongsTo('Invoice')->withTrashed();
}
public function client()
{
return $this->belongsTo('Client')->withTrashed();
}
public function getName()
{
return '';
}
public function getEntityType()
{
return ENTITY_CREDIT;
}
public function apply($amount)
{
if ($amount > $this->balance) {
$applied = $this->balance;
$this->balance = 0;
} else {
$applied = $amount;
$this->balance = $this->balance - $amount;
}
$this->save();
return $applied;
}
2013-12-01 22:58:25 +02:00
}
2015-01-11 14:30:08 +02:00
Credit::created(function ($credit) {
Activity::createCredit($credit);
2014-01-14 11:52:56 +00:00
});
2015-01-11 14:30:08 +02:00
Credit::updating(function ($credit) {
Activity::updateCredit($credit);
2014-01-14 11:52:56 +00:00
});
2015-01-11 14:30:08 +02:00
Credit::deleting(function ($credit) {
Activity::archiveCredit($credit);
2014-11-23 23:47:10 +02:00
});
2015-01-11 14:30:08 +02:00
Credit::restoring(function ($credit) {
Activity::restoreCredit($credit);
});