@@ -25,7 +25,7 @@ class Statementor extends \Ease\Sand
2525 use \Ease\Logger\Logging;
2626 public \DateTime $since ;
2727 public \DateTime $until ;
28- private string $scope ;
28+ public string $currency = ' CZK ' ;
2929
3030 /**
3131 * DateTime Formating eg. 2021-08-01T10:00:00.0Z.
@@ -36,10 +36,14 @@ class Statementor extends \Ease\Sand
3636 * DateTime Formating eg. 2021-08-01T10:00:00.0Z.
3737 */
3838 public static string $dateFormat = ' Y-m-d' ;
39+ private string $scope ;
3940 private string $accountNumber = ' ' ;
40-
41- public function __construct(string $accountNumber = ' ' , string $scope = ' ' )
41+ private string $accountUuid = ' ' ;
42+
43+ public function __construct(string $accountUuid , string $accountNumber = ' ' , string $scope = ' ' )
4244 {
45+ $this -> setAccountUuid ($accountUuid );
46+
4347 if ($accountNumber ) {
4448 $this -> setAccountNumber ($accountNumber );
4549 }
@@ -67,7 +71,7 @@ class Statementor extends \Ease\Sand
6771 /**
6872 * Obtain Statements from ČSas.
6973 *
70- * @param string $format pdf, xml, xml-data, abo-standard, abo-internal, abo-standard-extended, abo-internal-extended, csv-comma, csv-semicolon, mt940
74+ * @param string $format pdf, xml, xml-data, abo-standard, abo-internal, abo-standard-extended, abo-internal-extended, csv-comma, csv-semicolon, mt940
7175 */
7276 public function getStatements($format = 'pdf'): array
7377 {
@@ -79,20 +83,14 @@ class Statementor extends \Ease\Sand
7983 try {
8084 do {
8185
82- $result = $apiInstance -> getAccountStatements ($this -> getAccountNumber (), $this -> getSince ()-> format (' Y-m-d' ), $this -> getUntil ()-> format (' Y-m-d' ),$format );
83-
84- if (empty($result )) {
85- $this -> addStatusMessage (sprintf(_(' No transactions from %s to %s' ), $this -> since -> format (self::$dateFormat ), $this -> until -> format (self::$dateFormat )));
86- $result [' lastPage' ] = true ;
87- $result [' last' ] = true ;
88- }
86+ $result = $apiInstance -> getAccountStatements ($this -> getAccountNumber (), $this -> getSince ()-> format (' Y-m-d' ), $this -> getUntil ()-> format (' Y-m-d' ), $format );
8987
90- if (\array_key_exists('statements', $result)) {
91- $statements = array_merge($statements , $result [' statements' ]);
88+ if ($result -> getAccountStatements ()) {
89+ $statements = array_merge($statements , $result -> getAccountStatements ());
90+ } else {
91+ $this -> addStatusMessage (sprintf(_(' No transactions from %s to %s' ), $this -> since -> format (self::$dateFormat ), $this -> until -> format (self::$dateFormat )));
9292 }
93-
94- sleep(1);
95- } while ($result['last'] === false);
93+ } while ($result->getNextPage());
9694 } catch (\Ease\Exception $e) {
9795 echo ' Exception when calling GetTransactionListApi->getTransactionList: ' , $e -> getMessage (), \PHP_EOL;
9896 }
@@ -201,7 +199,9 @@ class Statementor extends \Ease\Sand
201199 $this -> since = $this -> since -> setTime (0, 0);
202200 $this -> until = $this -> until -> setTime (23, 59, 59, 999);
203201 }
202+
204203 $this->scope = $scope;
204+
205205 return $this->getScope();
206206 }
207207
@@ -224,21 +224,27 @@ class Statementor extends \Ease\Sand
224224 public function download(string $saveTo, array $statements, string $format = 'pdf', string $currencyCode = 'CZK'): array
225225 {
226226 $saved = [];
227- $apiInstance = new PremiumAPI\DownloadStatementApi ();
227+ $apiInstance = new \SpojeNet\CSas\Accounts\DefaultApi ();
228228 $success = 0;
229229
230230 foreach ($statements as $statement ) {
231- $statementFilename = str_replace(' /' , ' _' , $statement -> statementNumber ).' _' .
232- $statement -> accountNumber .' _' .
233- $statement -> accountId .' _' .
234- $statement -> currency .' _' .$statement -> dateFrom .' .' .$format ;
235- $requestBody = new \VitexSoftware\Raiffeisenbank\Model\DownloadStatementRequest([
236- ' accountNumber' => $this -> accountNumber ,
237- ' currency' => $currencyCode ,
238- ' statementId' => $statement -> statementId ,
239- ' statementFormat' => $format ]);
240- $pdfStatementRaw = $apiInstance -> downloadStatement (ApiClient::getxRequestId(), ' cs' , $requestBody );
241- sleep(1);
231+ // ' accountStatementId' => ' getAccountStatementId' ,
232+ // ' year' => ' getYear' ,
233+ // ' month' => ' getMonth' ,
234+ // ' sequenceNumber' => ' getSequenceNumber' ,
235+ // ' period' => ' getPeriod' ,
236+ // ' dateFrom' => ' getDateFrom' ,
237+ // ' dateTo' => ' getDateTo' ,
238+ // ' formats' => ' getFormats' ,
239+
240+ $statementFilename =
241+ $statement -> getSequenceNumber ().' _' .
242+ $this -> getAccountNumber ().' _' .
243+ $statement -> getAccountStatementId ().' _' .
244+ $this -> currency .' _' .$statement -> getDateFrom ()-> format (' Y-m-d' ).' .' .$format ;
245+
246+ $pdfStatementRaw = $apiInstance -> downloadAccountStatement ($this -> getAccountUuid (), $statement -> getAccountStatementId (), $format );
247+
242248
243249 if (file_put_contents($saveTo .' /' .$statementFilename , $pdfStatementRaw -> fread ($pdfStatementRaw -> getSize ()))) {
244250 $saved [$statementFilename ] = $saveTo .' /' .$statementFilename ;
@@ -269,8 +275,18 @@ class Statementor extends \Ease\Sand
269275 return $this -> until ;
270276 }
271277
272- public function getAccountNumber(): string {
278+ public function getAccountNumber(): string
279+ {
273280 return $this -> accountNumber ;
274281 }
275282
283+ public function setAccountUuid($accountUuid): void
284+ {
285+ $this -> accountUuid = $accountUuid ;
286+ }
287+
288+ public function getAccountUuid(): string
289+ {
290+ return $this -> accountUuid ;
291+ }
276292}
0 commit comments