Link.FYI

Pastebin

Create New My Pastes

Code (PHP) pasted on 2019-01-17, 20:34 Raw Source

  1. <?php
  2.  
  3. namespace LyraFinances\filter;
  4.  
  5. use LyraFinances\exceptions\BadPaymentEntryException;
  6. use LyraFinances\interfaces\Filter;
  7. use LyraFinances\models\Payment;
  8.  
  9. /**
  10.  * Class VolksbankCsvFilter
  11.  * @todo this one is difficult; you've to read out the file header.
  12.  * @package LyraFinances\filter
  13.  */
  14. class VolksbankCsvFilter extends AbstractCsvFilter implements Filter
  15. {
  16.     /**
  17.      * @var int
  18.      */
  19.     protected $skipLines = 13;
  20.     /**
  21.      * @var int
  22.      */
  23.     protected $cols = 13;
  24.     /**
  25.      * @var array
  26.      */
  27.     protected $skippedLines = [];
  28.     /**
  29.      * @var array
  30.      */
  31.     protected $fields = [
  32.         'Buchungstag',
  33.         'Valuta',
  34.         'Auftraggeber/Zahlungsempfänger',
  35.         'Empfänger/Zahlungspflichtiger',
  36.         'Konto-Nr.',
  37.         'IBAN',
  38.         'BLZ',
  39.         'BIC',
  40.         'Vorgang/Verwendungszweck',
  41.         'Kundenreferenz',
  42.         'Währung',
  43.         'Umsatz',
  44.         ' '
  45.     ];
  46.  
  47.     /**
  48.      * @param array $csv
  49.      *
  50.      * @return Payment
  51.      * @throws \Exception
  52.      */
  53.     public function filter(array $csv = []): Payment
  54.     {
  55.         /**
  56.          * some information, like the account are within the header of the file.
  57.          */
  58.         if (empty($csv[3])) {
  59.             throw new BadPaymentEntryException();
  60.         }
  61.  
  62.         $payment = new Payment();
  63.         $payment->setAccount($this->skippedLines[5][1]);
  64.         $payment->setDate($this->getDateFromString(empty($csv[1]) ? $csv[0] : $csv[1]));
  65.         $type = substr($csv[8], 0, strpos($csv[8], "\n"));
  66.         $payment->setType($type);
  67.         $text = substr($csv[8], strlen($type)+1);
  68.         $payment->setText($text);
  69.         $payment->setRecipientPayer($csv[3]);
  70.         $amount = $this->getFloatFromMoney($csv[11]);
  71.         if ($csv[12] == 'S') {
  72.             $amount = -($amount);
  73.         }
  74.         $payment->setAmount($amount);
  75.  
  76.         var_dump($payment);
  77.         return new Payment();
  78.     }
  79. }
  80. <?php
  81.  
  82. namespace LyraFinances\filter;
  83.  
  84. use LyraFinances\interfaces\Filter;
  85. use LyraFinances\models\Payment;
  86.  
  87. /**
  88.  * Class SparkasseCsvFilter
  89.  * @package LyraFinances\filter
  90.  */
  91. class SparkasseCsvFilter extends AbstractCsvFilter implements Filter
  92. {
  93.     /**
  94.      * @var int
  95.      */
  96.     protected $skipLines = 1;
  97.     /**
  98.      * @var int
  99.      */
  100.     protected $cols = 17;
  101.  
  102.     /**
  103.      * @var array
  104.      */
  105.     protected $fields = [
  106.         'Auftragskonto',
  107.         'Buchungstag',
  108.         'Valutadatum',
  109.         'Buchungstext',
  110.         'Verwendungszweck',
  111.         'Glaeubiger ID',
  112.         'Mandatsreferenz',
  113.         'Kundenreferenz (End-to-End)',
  114.         'Sammlerreferenz',
  115.         'Lastschrift Ursprungsbetrag',
  116.         'Auslagenersatz Ruecklastschrift',
  117.         'Beguenstigter/Zahlungspflichtiger',
  118.         'Kontonummer/IBAN',
  119.         'BIC (SWIFT-Code)',
  120.         'Betrag',
  121.         'Waehrung',
  122.         'Info'
  123.     ];
  124.  
  125.     /**
  126.      * @param array $csv
  127.      *
  128.      * @return Payment
  129.      * @throws \Exception
  130.      */
  131.     public function filter(array $csv = []): Payment
  132.     {
  133.         $payment = new Payment();
  134.         $payment->setAccount($csv[0]);
  135.         $payment->setDate($this->getDateFromString(empty($csv[2]) ? $csv[1] : $csv[2]));
  136.         $payment->setText($csv[4]);
  137.         $payment->setType($csv[3]);
  138.         $payment->setRecipientPayer($csv[12]);
  139.         $payment->setAmount($this->getFloatFromMoney($csv[14]));
  140.  
  141.         return $payment;
  142.     }
  143. }
  144.