forked from thelia-modules/CreditAccount
/
CreditAccount.php
43 lines (34 loc) · 1.08 KB
/
CreditAccount.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace CreditAccount\Model;
use CreditAccount\Model\Base\CreditAccount as BaseCreditAccount;
use Propel\Runtime\Connection\ConnectionInterface;
class CreditAccount extends BaseCreditAccount
{
private $updateAmount = 0;
private $person = 0;
private $orderId = 0;
public function addAmount($amount, $orderId, $person = 'Customer')
{
if ($amount !== null) {
$amount = (double) $amount;
$this->updateAmount += $amount;
$this->person = $person;
$this->orderId = $orderId;
$this->setAmount($this->getAmount() + $amount);
}
return $this;
}
public function postSave(ConnectionInterface $con = null)
{
if ($this->updateAmount != 0) {
$history = new CreditAmountHistory();
$history
->setCreditAccountId($this->getId())
->setAmount($this->updateAmount)
->setWho($this->person)
->setOrderId($this->orderId)
->save($con);
$this->updateAmount = 0;
}
}
}