@@ -93,14 +93,14 @@ public function collectTargetAccounts(): void
9393 if (in_array ($ type , ['reconciliation ' , 'initial-balance ' , 'expense ' , 'revenue ' ], true )) {
9494 continue ;
9595 }
96- $ iban = $ this ->filterSpaces ((string ) $ entry ->iban );
96+ $ iban = $ this ->filterSpaces ((string )$ entry ->iban );
9797
9898 if ('' !== $ iban ) {
9999 app ('log ' )->debug (sprintf ('Collected IBAN "%s" (%s) under ID #%d ' , $ iban , $ entry ->type , $ entry ->id ));
100100 $ return [$ iban ] = $ entry ->id ;
101101 $ types [$ iban ] = $ entry ->type ;
102102 }
103- $ number = sprintf ('%s. ' , (string ) $ entry ->number );
103+ $ number = sprintf ('%s. ' , (string )$ entry ->number );
104104 if ('. ' !== $ number ) {
105105 app ('log ' )->debug (sprintf ('Collected account nr "%s" (%s) under ID #%d ' , $ number , $ entry ->type , $ entry ->id ));
106106 $ return [$ number ] = $ entry ->id ;
@@ -213,12 +213,14 @@ private function generateTransaction(string $accountId, Transaction $entry): arr
213213 'error_if_duplicate_hash ' => $ this ->configuration ->isIgnoreDuplicateTransactions (),
214214 'transactions ' => [],
215215 ];
216+ $ valueDate = $ entry ->getValueDate ();
216217 $ transaction = [
217218 'type ' => 'withdrawal ' ,
218219 'date ' => $ entry ->getDate ()->format ('Y-m-d ' ),
219220 'datetime ' => $ entry ->getDate ()->toW3cString (),
220221 'amount ' => $ entry ->transactionAmount ,
221222 'description ' => $ entry ->getDescription (),
223+ 'payment_date ' => is_null ($ valueDate ) ? '' : $ valueDate ->format ('Y-m-d ' ),
222224 'order ' => 0 ,
223225 'currency_code ' => $ entry ->currencyCode ,
224226 'tags ' => [],
@@ -253,7 +255,7 @@ private function generateTransaction(string $accountId, Transaction $entry): arr
253255 private function getMappedAccountId (string $ name ): ?int
254256 {
255257 if (isset ($ this ->configuration ->getMapping ()['accounts ' ][$ name ])) {
256- return (int ) $ this ->configuration ->getMapping ()['accounts ' ][$ name ];
258+ return (int )$ this ->configuration ->getMapping ()['accounts ' ][$ name ];
257259 }
258260
259261 return null ;
@@ -345,9 +347,11 @@ public function setConfiguration(Configuration $configuration): void
345347
346348 /**
347349 * Handle transaction information when the amount is positive, and this is probably a deposit or a transfer.
350+ *
348351 * @param string $accountId
349352 * @param array $transaction
350353 * @param Transaction $entry
354+ *
351355 * @return array
352356 * @throws ImporterHttpException
353357 */
@@ -358,7 +362,7 @@ private function appendPositiveAmountInfo(string $accountId, array $transaction,
358362 $ transaction ['amount ' ] = $ entry ->transactionAmount ;
359363
360364 // destination is a Nordigen account (has to be!)
361- $ transaction ['destination_id ' ] = (int ) $ this ->accounts [$ accountId ];
365+ $ transaction ['destination_id ' ] = (int )$ this ->accounts [$ accountId ];
362366 app ('log ' )->debug (sprintf ('Destination ID is now #%d, which should be a Firefly III asset account. ' , $ transaction ['destination_id ' ]));
363367
364368 // append source iban and number (if present)
@@ -390,22 +394,25 @@ private function appendPositiveAmountInfo(string $accountId, array $transaction,
390394 $ transaction ['source_name ' ] = $ originalSourceName ;
391395 }
392396 }
397+
393398 return $ transaction ;
394399 }
395400
396401 /**
397402 * Handle transaction information when the amount is negative, and this is probably a withdrawal or a transfer.
403+ *
398404 * @param string $accountId
399405 * @param array $transaction
400406 * @param Transaction $entry
407+ *
401408 * @return array
402409 * @throws ImporterHttpException
403410 */
404411 private function appendNegativeAmountInfo (string $ accountId , array $ transaction , Transaction $ entry ): array
405412 {
406413
407414 $ transaction ['amount ' ] = bcmul ($ entry ->transactionAmount , '-1 ' );
408- $ transaction ['source_id ' ] = (int ) $ this ->accounts [$ accountId ]; // TODO entry may not exist, then what?
415+ $ transaction ['source_id ' ] = (int )$ this ->accounts [$ accountId ]; // TODO entry may not exist, then what?
409416
410417 // append source iban and number (if present)
411418 $ transaction = $ this ->appendAccountFields ($ transaction , $ entry , 'destination ' );
@@ -436,13 +443,15 @@ private function appendNegativeAmountInfo(string $accountId, array $transaction,
436443 $ transaction ['destination_name ' ] = $ originalDestName ;
437444 }
438445 }
446+
439447 return $ transaction ;
440448 }
441449
442450 /**
443451 * @param array $transaction
444452 * @param Transaction $entry
445453 * @param string $direction
454+ *
446455 * @return array
447456 */
448457 private function appendAccountFields (array $ transaction , Transaction $ entry , string $ direction ): array
@@ -473,51 +482,53 @@ private function appendAccountFields(array $transaction, Transaction $entry, str
473482 $ numberSearch = sprintf ('%s. ' , $ number );
474483
475484 // IBAN is also an ID, so use that!
476- if ('' !== (string ) $ iban && array_key_exists ((string ) $ iban , $ this ->targetAccounts )) {
485+ if ('' !== (string )$ iban && array_key_exists ((string )$ iban , $ this ->targetAccounts )) {
477486 app ('log ' )->debug (sprintf ('Recognized %s (IBAN) as a Firefly III asset account so this is a transfer. ' , $ iban ));
478487 $ transaction [$ idKey ] = $ this ->targetAccounts [$ iban ];
479488 $ transaction ['type ' ] = 'transfer ' ;
480489 }
481490
482491 // IBAN is not an ID, so just submit it as a field.
483- if ('' === (string ) $ iban || !array_key_exists ((string ) $ iban , $ this ->targetAccounts )) {
492+ if ('' === (string )$ iban || !array_key_exists ((string )$ iban , $ this ->targetAccounts )) {
484493 app ('log ' )->debug (sprintf ('"%s" is not a valid IBAN OR not recognized as Firefly III asset account so submitted as-is. ' , $ iban ));
485494 // source is the other side:
486495 $ transaction [$ nameKey ] = $ name ?? sprintf ('(unknown %s account) ' , $ direction );
487- if ('' !== (string ) $ iban ) {
496+ if ('' !== (string )$ iban ) {
488497 app ('log ' )->debug (sprintf ('Set field "%s" to "%s". ' , $ ibanKey , $ iban ));
489498 $ transaction [$ ibanKey ] = $ iban ;
490499 }
491- if ('' === (string ) $ iban ) {
500+ if ('' === (string )$ iban ) {
492501 app ('log ' )->debug (sprintf ('IBAN is "%s", so leave field "%s" empty. ' , $ iban , $ ibanKey ));
493502 }
494503 }
495504
496505 // source is also an ID, so use it!
497- if ('' !== (string ) $ number && '. ' !== $ numberSearch && array_key_exists ($ numberSearch , $ this ->targetAccounts )) {
506+ if ('' !== (string )$ number && '. ' !== $ numberSearch && array_key_exists ($ numberSearch , $ this ->targetAccounts )) {
498507 app ('log ' )->debug (sprintf ('Recognized "%s" (number) as a Firefly III asset account so this is a transfer. ' , $ number ));
499508 $ transaction [$ idKey ] = $ this ->targetAccounts [$ numberSearch ];
500509 $ transaction ['type ' ] = 'transfer ' ;
501510 }
502511
503- if ('' === (string ) $ number || '. ' === $ numberSearch || !array_key_exists ($ numberSearch , $ this ->targetAccounts )) {
512+ if ('' === (string )$ number || '. ' === $ numberSearch || !array_key_exists ($ numberSearch , $ this ->targetAccounts )) {
504513 app ('log ' )->debug (sprintf ('"%s" is not a valid account nr OR not recognized as Firefly III asset account so submitted as-is. ' , $ number ));
505514 // source is the other side:
506515 $ transaction [$ nameKey ] = $ name ?? sprintf ('(unknown %s account) ' , $ direction );
507- if ('' !== (string ) $ number ) {
516+ if ('' !== (string )$ number ) {
508517 app ('log ' )->debug (sprintf ('Set field "%s" to "%s". ' , $ numberKey , $ number ));
509518 $ transaction [$ numberKey ] = $ number ;
510519 }
511- if ('' === (string ) $ number ) {
520+ if ('' === (string )$ number ) {
512521 app ('log ' )->debug (sprintf ('Account number is "%s", so leave field "%s" empty. ' , $ number , $ numberKey ));
513522 }
514523 }
515524 app ('log ' )->debug (sprintf ('End of %s ' , __METHOD__ ));
525+
516526 return $ transaction ;
517527 }
518528
519529 /**
520530 * @param string $iban
531+ *
521532 * @return string
522533 */
523534 private function filterSpaces (string $ iban ): string
@@ -570,6 +581,7 @@ private function filterSpaces(string $iban): string
570581 "\u{FEFF}" , // zero width no -break space
571582 "\x20" , // plain old normal space
572583 ];
584+
573585 return str_replace ($ search , '' , $ iban );
574586 }
575587}
0 commit comments