1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 23:52:33 +01:00
invoiceninja/app/models/Credit.php
Hillel Coren af37de4feb bug fixes
2014-02-19 15:28:29 +02:00

57 lines
813 B
PHP
Executable File

<?php
class Credit extends EntityModel
{
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;
}
}
Credit::created(function($credit)
{
Activity::createCredit($credit);
});
Credit::updating(function($credit)
{
Activity::updateCredit($credit);
});
Credit::deleting(function($credit)
{
Activity::archiveCredit($credit);
});