Skip to content

Commit

Permalink
add exec_date to meta data, and fix tests
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.php.net/repository/pear/packages/Payment_DTA/trunk@316502 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
mschuett committed Sep 11, 2011
1 parent 3ede1d4 commit fb32958
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 5 deletions.
14 changes: 13 additions & 1 deletion DTA.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ function getFileContent()
* @access public
* @return array Returns an array with keys: "sender_name",
* "sender_bank_code", "sender_account", "sum_amounts",
* "type", "sum_bankcodes", "sum_accounts", "count", "date"
* "type", "sum_bankcodes", "sum_accounts", "count", "date", "exec_date"
*/
function getMetaData()
{
Expand All @@ -682,6 +682,18 @@ function getMetaData()
$meta["sum_accounts"] = floatval($this->sum_accounts);
$meta["type"] = strval(($this->type == DTA_CREDIT) ? "CREDIT" : "DEBIT");

$meta["exec_date"] = $meta["date"];
// use timestamp to be consistent with $meta["date"]
if ($this->account_file_sender["exec_date"] !== "") {
$ftime = strptime($this->account_file_sender["exec_date"], '%d%m%Y');
if ($ftime) {
$meta["exec_date"] = mktime(0, 0, 0,
$ftime['tm_mon'] + 1,
$ftime['tm_mday'],
$ftime['tm_year'] + 1900
);
}
}
return $meta;
}

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/example_begleitzettel.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

<tr>
<td>Ausführungsdatum:</td>
<td><?php print strftime("%d.%m.%y", $meta["date"]); ?></td>
<td><?php print strftime("%d.%m.%y", $meta["exec_date"]); ?></td>
</tr>

<tr> <td colspan="2">&nbsp;</td> </tr>
Expand Down
55 changes: 52 additions & 3 deletions tests/DTATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2151,13 +2151,61 @@ public function testParserInvalidERecord()
'0000000123456 ';
*/

public function testExec_Date()
public function testSetExec_date() {
/* derived from testContent */
$exec_date = '31082010';
$dta = new DTA(DTA_CREDIT);
$DTA_test_account = array(
'name' => "Senders Name",
'bank_code' => "16050000",
'account_number' => "3503007767",
'exec_date' => $exec_date
);
$this->assertTrue($dta->setAccountFileSender($DTA_test_account));

$dta->addExchange(array(
"name" => "Franz Mueller",
"bank_code" => 33334444,
"account_number" => 13579000,
),
(float) 1234.56,
"Test-Verwendungszweck"
);
$dta->addExchange(array(
"name" => "Franz Mueller",
"bank_code" => 33334444,
"account_number" => 13579000
),
(float) 321.9,
"Test-Verwendungszweck"
);

$date = strftime("%d%m%y", time());

$expected = // 64 chars per line:
'0128AGK1605000000000000SENDERS NAME '.$date.' 3503'.
'0077670000000000 '.$exec_date.' 1'.
'0187C16050000333344440013579000000000000000051000 00000000000160'.
'50000350300776700000123456 FRANZ MUELLER '.
'SENDERS NAME TEST-VERWENDUNGSZWECK 1 00 '.
' '.
'0187C16050000333344440013579000000000000000051000 00000000000160'.
'50000350300776700000032190 FRANZ MUELLER '.
'SENDERS NAME TEST-VERWENDUNGSZWECK 1 00 '.
' '.
'0128E 000000200000000000000000000002715800000000000066668888'.
'0000000155646 ';
$this->assertSame($expected, $dta->getFileContent());

}
public function testParseExec_Date()
{
/* extended from testParserTimestamp, but also re-create DTA */
$date = "300810"; // 2010-08-30
$date = "300810"; // 2010-08-30 --> A7
$exec_date = "31082010"; // 2010-08-31 --> A11b
$teststring = // same as in testContent(), but fixed timestamp
'0128AGK1605000000000000SENDERS NAME '.$date.' 3503'.
'0077670000000000 1'.
'0077670000000000 '.$exec_date.' 1'.
'0187C16050000333344440013579000000000000000051000 00000000000160'.
'50000350300776700000123456 FRANZ MUELLER '.
'SENDERS NAME TEST-VERWENDUNGSZWECK 1 00 '.
Expand All @@ -2171,6 +2219,7 @@ public function testExec_Date()
$dta = new DTA($teststring);
$meta = $dta->getMetaData();
$this->assertEquals($date, strftime("%d%m%y", $meta["date"]));
$this->assertSame($exec_date, strftime("%d%m%Y", $meta["exec_date"]));

$dtastring = $dta->getFileContent();
$this->assertEquals($teststring, $dtastring);
Expand Down

0 comments on commit fb32958

Please sign in to comment.