Created
February 27, 2018 19:11
-
-
Save dnetix/fd307a85696e75b807582116e2580e68 to your computer and use it in GitHub Desktop.
Asobancaria 2001 testing generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This will generate a 2001 Asobancaria file | |
*/ | |
$name = 'testing.txt'; | |
$nit = '8909002860'; | |
$date = date('Ymd'); | |
/** | |
* 013 - BBVA | |
* 007 - Bancolombia | |
* 001 - Banco Bogota | |
* 051 - Davivienda | |
* 023 - Banco de Occidente | |
* 002 - Banco Popular | |
*/ | |
$bankCode = '013'; | |
$accountNumber = '00840514521'; | |
$accountType = 1; | |
// Data source, on batchs | |
$data = [ | |
'1' => [ | |
[ | |
'reference' => '8040159550', | |
'amount' => '3500000', | |
'origin' => '31', | |
'channel' => '53', | |
'operationId' => rand(0, 999999), | |
'authorization' => rand(0, 999999), | |
'thirdEntity' => '000', | |
'branch' => '9999', | |
'refundReason' => '', | |
], | |
[ | |
'reference' => '8110120390', | |
'amount' => rand(100000, 999999999), | |
'origin' => '31', | |
'channel' => '53', | |
'operationId' => rand(0, 999999), | |
'authorization' => rand(0, 999999), | |
'thirdEntity' => '000', | |
'branch' => '9999', | |
'refundReason' => '', | |
], | |
[ | |
'reference' => '8909011724', | |
'amount' => rand(100000, 999999999), | |
'origin' => '31', | |
'channel' => '53', | |
'operationId' => rand(0, 999999), | |
'authorization' => rand(0, 999999), | |
'thirdEntity' => '000', | |
'branch' => '9999', | |
'refundReason' => '', | |
], | |
[ | |
'reference' => '1040035000', | |
'amount' => 15000000, | |
'origin' => '31', | |
'channel' => '53', | |
'operationId' => rand(0, 999999), | |
'authorization' => rand(0, 999999), | |
'thirdEntity' => '000', | |
'branch' => '9999', | |
'refundReason' => '', | |
], | |
[ | |
'reference' => '123456789', | |
'amount' => 1230000, | |
'origin' => '31', | |
'channel' => '53', | |
'operationId' => rand(0, 999999), | |
'authorization' => rand(0, 999999), | |
'thirdEntity' => '000', | |
'branch' => '9999', | |
'refundReason' => '', | |
], | |
] | |
]; | |
$lineBreak = "\n"; | |
// ------- THIS PART DOES NOT NEED TO BE TOUCHED | |
$file = fopen(__DIR__ . '/' . $name, 'w'); | |
function parse($text, $length, $filler = ' ', $left = true) | |
{ | |
if ($left) { | |
return str_pad(substr($text, 0, $length), $length, $filler, STR_PAD_LEFT); | |
} | |
return str_pad(substr($text, 0, $length), $length, $filler, STR_PAD_RIGHT); | |
} | |
function parseAmount($amount, $length) | |
{ | |
$amount = intval(round(($amount * 100),0)); | |
return parse($amount, $length, '0'); | |
} | |
function write($line, $lenght = 162) | |
{ | |
global $file, $lineBreak; | |
if ($lenght) { | |
$line = str_pad($line, $lenght, ' ', STR_PAD_RIGHT); | |
} | |
fwrite($file, $line . $lineBreak); | |
} | |
// Create the header | |
$line = '01' . parse($nit, 10) . parse($date, 8) . parse($bankCode, 3) . parse($accountNumber, 17, '0') . date('YmdHi') . '1' . $accountType; | |
write($line); | |
// Go through the batches and create them | |
$batchCount = 1; | |
$registryCount = 0; | |
$amountTotal = 0; | |
foreach ($data as $batch => $subdata) { | |
$batchRegisters = 0; | |
$batchAmount = 0; | |
$line = '05' . parse($batch, 13) . parse($batchCount, 4, '0'); | |
write($line); | |
foreach ($subdata as $row) { | |
$registryCount++; | |
$line = '06' . parse($row['reference'], 48, '0') . parseAmount($row['amount'], 14) . parse($row['origin'], 2) . parse($row['channel'], 2) . parse($row['operationId'], 6, '0') . parse($row['authorization'], 6, '0') . parse($row['thirdEntity'], 3) . parse($row['branch'], 4) . parse($registryCount, 7, '0') . parse($row['refundReason'], 3); | |
write($line); | |
$batchAmount += $row['amount']; | |
$batchRegisters++; | |
} | |
$line = '08' . parse($batchRegisters, 9, '0') . parseAmount($batchAmount, 18) . parse($batchCount, 4, '0'); | |
write($line); | |
$amountTotal += $batchAmount; | |
$batchCount++; | |
} | |
$line = '09' . parse($registryCount, 9, '0') . parseAmount($amountTotal, 18); | |
write($line); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment