2013-12-01 21:58:25 +01:00
|
|
|
<?php
|
|
|
|
|
2013-12-04 17:20:14 +01:00
|
|
|
class Credit extends EntityModel
|
2013-12-31 10:43:39 +01:00
|
|
|
{
|
2013-12-01 21:58:25 +01:00
|
|
|
public function invoice()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Invoice');
|
|
|
|
}
|
|
|
|
|
2013-12-05 16:23:24 +01:00
|
|
|
public function client()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Client');
|
|
|
|
}
|
|
|
|
|
2013-12-01 21:58:25 +01:00
|
|
|
public function getName()
|
|
|
|
{
|
2014-01-08 21:09:47 +01:00
|
|
|
return '';
|
2013-12-01 21:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getEntityType()
|
|
|
|
{
|
|
|
|
return ENTITY_CREDIT;
|
|
|
|
}
|
2014-01-16 22:12:46 +01:00
|
|
|
|
|
|
|
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 21:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Credit::created(function($credit)
|
|
|
|
{
|
2013-12-05 16:23:24 +01:00
|
|
|
Activity::createCredit($credit);
|
2014-01-14 12:52:56 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
Credit::updating(function($credit)
|
|
|
|
{
|
|
|
|
Activity::updateCredit($credit);
|
|
|
|
});
|
|
|
|
|
|
|
|
Credit::deleting(function($credit)
|
|
|
|
{
|
|
|
|
Activity::archiveCredit($credit);
|
2013-12-01 21:58:25 +01:00
|
|
|
});
|