forked from nemiah/phpFinTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSdo.php
More file actions
70 lines (60 loc) · 2.1 KB
/
Sdo.php
File metadata and controls
70 lines (60 loc) · 2.1 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Fhp\Segment\Common;
use Fhp\Segment\BaseDeg;
/**
* Mehrfach verwendetes Element: Saldo (Version 2)
*
* @link https://www.hbci-zka.de/dokumente/spezifikation_deutsch/fintsv3/FinTS_3.0_Messages_Geschaeftsvorfaelle_2015-08-07_final_version.pdf
* Section: B.4
*
* Note: Version 2 is compatible with version 1, which essentially just inlined the Btg.
* @link https://www.hbci-zka.de/dokumente/spezifikation_deutsch/archiv/HBCI_V2.x_FV.zip
* File: Gesamtdok_HBCI21o.pdf
* Section: II.5.3.4
*/
class Sdo extends BaseDeg
{
public const CREDIT = 'C'; // "Haben"
public const DEBIT = 'D'; // "Soll"
/**
* Allowed values:
* "C" = Credit (the signum of $wert is positive)
* "D" = Debit (the signum of $wert is negative)
*/
public string $sollHabenKennzeichen;
public Btg $betrag;
/** JJJJMMTT gemäß ISO 8601 */
public string $datum;
/** hhmmss gemäß ISO 8601, local time (no time zone support). */
public ?string $uhrzeit = null;
public function getAmount(): float
{
if ($this->sollHabenKennzeichen === self::CREDIT) {
return $this->betrag->wert;
}
if ($this->sollHabenKennzeichen === self::DEBIT) {
return -1 * $this->betrag->wert;
}
throw new \InvalidArgumentException("Invalid sollHabenKennzeichen: $this->sollHabenKennzeichen");
}
public function getCurrency(): string
{
return $this->betrag->waehrung;
}
public function getTimestamp(): \DateTime
{
return \DateTime::createFromFormat('Ymd His', $this->datum . ' ' . ($this->uhrzeit ?? '000000'));
}
public static function create(float $amount, string $currency, \DateTime $timestamp): Sdo
{
$result = new Sdo();
$result->sollHabenKennzeichen = $amount < 0 ? self::DEBIT : self::CREDIT;
$result->betrag = Btg::create($amount, $currency);
$result->datum = $timestamp->format('Ymd');
$result->uhrzeit = $timestamp->format('His');
if ($result->uhrzeit == '000000') {
$result->uhrzeit = null;
}
return $result;
}
}