コード例 #1
0
ファイル: SIEDumper.php プロジェクト: johanwilfer/siephp
 /**
  * Dumps the Company and the data to SIE-format. Returns the SIE-contents as a string
  * @param Data\Company $sie
  * @return string
  */
 public function dump(Data\Company $sie)
 {
     // mandatory
     $data = $this->getLine('FLAGGA', array('0'));
     $data .= $this->getLine('FORMAT', array('PC8'));
     $data .= $this->getLine('SIETYP', array('4'));
     $data .= $this->getLine('PROGRAM', array($this->options['generator']));
     $data .= $this->getLine('GEN', array($this->options['generated_date'], $this->options['generated_sign']));
     $data .= $this->getLine('FNAMN', array($sie->getCompanyName()));
     // optional
     if ($sie->getCompanyNumber() !== null) {
         $data .= $this->getLine('ORGNR', array($sie->getCompanyNumber()));
     }
     // accounts
     foreach ($sie->getAccounts() as $account) {
         $data .= $this->getLine('KONTO', array($account->getId(), $account->getName()));
     }
     // objects
     foreach ($sie->getDimensions() as $dimension) {
         foreach ($dimension->getObjects() as $object) {
             $data .= $this->getLine('OBJEKT', array($dimension->getId(), $object->getId(), $object->getName()));
         }
     }
     // fiscal year - add a #RAR line for each year
     $fiscalYears = $sie->getFiscalYears();
     $year = 0;
     foreach ($fiscalYears as $fiscalYear) {
         $data .= $this->getLine('RAR', array($year--, $fiscalYear->getDateStart()->format('Ymd'), $fiscalYear->getDateEnd()->format('Ymd')));
     }
     // balance data per fiscal year
     $year = 0;
     foreach ($fiscalYears as $fiscalYear) {
         foreach ($fiscalYear->getAccountBalances() as $balance) {
             $data .= $this->getLine('IB', array($year, $balance->getAccount()->getId(), $balance->getIncomingBalance()));
             $data .= $this->getLine('UB', array($year, $balance->getAccount()->getId(), $balance->getOutgoingBalance()));
         }
         $year--;
     }
     // end head with a blank line (not needed but looks nice)
     $data .= $this->delimiter_newline;
     // verifications
     foreach ($sie->getVerificationSeriesAll() as $series) {
         foreach ($series->getVerifications() as $ver) {
             $data .= $this->getLine('VER', array($series->getId(), $ver->getId(), $ver->getDate(), $ver->getText(), $ver->getRegistrationDate(), $ver->GetRegistrationSign()));
             // transactions for this verification
             $data .= '{' . $this->delimiter_newline;
             foreach ($ver->getTransactions() as $trans) {
                 $data .= '    ' . $this->getLine('TRANS', array($trans->getAccount()->getId(), $trans->getObjectsAsArrayPairs(), $trans->getAmount(), $trans->getDate() ? $trans->getDate() : $ver->getDate(), $trans->getText(), $trans->getQuantity(), $trans->getRegistrationSign()));
             }
             $data .= '}' . $this->delimiter_newline;
             $data .= $this->delimiter_newline;
         }
     }
     return $data;
 }