Overboekingen
Je kan een soort van een overboeking doen
This commit is contained in:
parent
32cb70e6d9
commit
c275c8f874
@ -21,11 +21,54 @@ class IBAN
|
|||||||
$newword = "";
|
$newword = "";
|
||||||
$wordarray = str_split($word);
|
$wordarray = str_split($word);
|
||||||
foreach ($wordarray as $v) {
|
foreach ($wordarray as $v) {
|
||||||
|
if(ctype_alpha($v)){
|
||||||
$newword .= ord(strtolower($v)) - 87;
|
$newword .= ord(strtolower($v)) - 87;
|
||||||
|
}else{
|
||||||
|
$newword .= $v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $newword;
|
return $newword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getCheckDigits($bignum){
|
||||||
|
//Modulo staartdeling
|
||||||
|
$modulo97 = (int)substr($bignum, 0, 6);
|
||||||
|
$modulo97 = $modulo97 % 97;
|
||||||
|
$modulo97 = (1000000 * $modulo97) + (int)substr($bignum, 6, 6);
|
||||||
|
$modulo97 = $modulo97 % 97;
|
||||||
|
$modulo97 = (1000000 * $modulo97) + (int)substr($bignum, 12, 6);
|
||||||
|
$modulo97 = $modulo97 % 97;
|
||||||
|
$modulo97 = (1000000 * $modulo97) + (int)substr($bignum, 18, 6);
|
||||||
|
$modulo97 = $modulo97 % 97;
|
||||||
|
$checkdigits = 98 - $modulo97;
|
||||||
|
if (strlen($checkdigits) < 2) {
|
||||||
|
$checkdigits = '0' . $checkdigits;
|
||||||
|
}
|
||||||
|
return $checkdigits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isValidIBAN($iban){
|
||||||
|
$iban = str_replace(" ", "", $iban);
|
||||||
|
$landcode = substr($iban, 0, 2);
|
||||||
|
$controle = substr($iban, 2, 2);
|
||||||
|
$identificatie = substr($iban, 4);
|
||||||
|
$identificatie .= $landcode;
|
||||||
|
$identificatie .= "00";
|
||||||
|
$nummer = $this->wordToNumbers($identificatie);
|
||||||
|
return $controle == $this->getCheckDigits($nummer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRekeningNummer($iban){
|
||||||
|
return substr(str_replace(" ", "", $iban), 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBank($iban){
|
||||||
|
return substr(str_replace(" ", "", $iban), 4, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLand($iban){
|
||||||
|
return substr(str_replace(" ", "", $iban), 0, 2);
|
||||||
|
}
|
||||||
|
|
||||||
public function getIBAN($rekeningnr)
|
public function getIBAN($rekeningnr)
|
||||||
{
|
{
|
||||||
@ -39,24 +82,7 @@ class IBAN
|
|||||||
$rekeningnr = str_pad($rekeningnr, 10, 0, STR_PAD_LEFT);
|
$rekeningnr = str_pad($rekeningnr, 10, 0, STR_PAD_LEFT);
|
||||||
|
|
||||||
$bignum = $banknumber . $rekeningnr . $landnumber . "00";
|
$bignum = $banknumber . $rekeningnr . $landnumber . "00";
|
||||||
|
$checkdigits = $this->getCheckDigits($bignum);
|
||||||
$modulo97 = '';
|
|
||||||
$checkdigits = '00';
|
|
||||||
|
|
||||||
// begin modulo staartdeling
|
|
||||||
$modulo97 = (int)substr($bignum, 0, 6);
|
|
||||||
$modulo97 = $modulo97 % 97;
|
|
||||||
$modulo97 = (1000000 * $modulo97) + (int)substr($bignum, 6, 6);
|
|
||||||
$modulo97 = $modulo97 % 97;
|
|
||||||
$modulo97 = (1000000 * $modulo97) + (int)substr($bignum, 12, 6);
|
|
||||||
$modulo97 = $modulo97 % 97;
|
|
||||||
$modulo97 = (1000000 * $modulo97) + (int)substr($bignum, 18, 6);
|
|
||||||
$modulo97 = $modulo97 % 97;
|
|
||||||
$checkdigits = 98 - $modulo97;
|
|
||||||
// einde modulo staartdeling
|
|
||||||
if (strlen($checkdigits) < 2) {
|
|
||||||
$checkdigits = '0' . $checkdigits;
|
|
||||||
}
|
|
||||||
|
|
||||||
$rekeningnrarr = str_split($rekeningnr, 4);
|
$rekeningnrarr = str_split($rekeningnr, 4);
|
||||||
return $landcode.$checkdigits." ".$bankcode." ".$rekeningnrarr[0]." ".$rekeningnrarr[1]." ".$rekeningnrarr[2];
|
return $landcode.$checkdigits." ".$bankcode." ".$rekeningnrarr[0]." ".$rekeningnrarr[1]." ".$rekeningnrarr[2];
|
||||||
|
@ -14,26 +14,80 @@
|
|||||||
|
|
||||||
namespace Inforbank\Application;
|
namespace Inforbank\Application;
|
||||||
|
|
||||||
use \Slim\App;
|
|
||||||
use Inforbank\Application\Helper\Klant;
|
|
||||||
use Inforbank\Application\Helper\Rekeningen;
|
|
||||||
use Inforbank\Application\Helper\IBAN;
|
|
||||||
use Inforbank\Application;
|
use Inforbank\Application;
|
||||||
|
use Inforbank\Application\Helper\IBAN;
|
||||||
|
use Inforbank\Application\Helper\Klant;
|
||||||
|
use Inforbank\Application\Helper\Redirect;
|
||||||
|
use Inforbank\Application\Helper\Rekeningen;
|
||||||
|
use Slim\App;
|
||||||
|
|
||||||
class Overboeking
|
class Overboeking {
|
||||||
{
|
|
||||||
public function __construct(App $app)
|
public function __construct(App $app) {
|
||||||
{
|
|
||||||
$app->get('/overboeking', function ($request, $response, $args) {
|
$app->get('/overboeking', function ($request, $response, $args) {
|
||||||
$klant = Klant::getCurrentUser();
|
$klant = Klant::getCurrentUser();
|
||||||
$rekeningen = Rekeningen::getCurrentUserRekeningen();
|
$rekeningen = Rekeningen::getCurrentUserRekeningen();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $this->renderer->render($response, 'overboeking.phtml', [
|
return $this->renderer->render($response, 'overboeking.phtml', [
|
||||||
'klant' => $klant,
|
'klant' => $klant,
|
||||||
'rekeningen' => $rekeningen
|
'rekeningen' => $rekeningen
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$app->post('/overboeking', function ($request, $response, $args) {
|
||||||
|
$post = $request->getParsedBody();
|
||||||
|
$van = $post['van'];
|
||||||
|
$naar = $post['naar'];
|
||||||
|
$bedrag = $post['bedrag'];
|
||||||
|
$omschrijving = $post['omschrijving'];
|
||||||
|
|
||||||
|
$rekeningen = Rekeningen::getCurrentUserRekeningen();
|
||||||
|
|
||||||
|
$vanRekening = false;
|
||||||
|
//TODO fatsoenlijke errorafhandeling en redirect
|
||||||
|
//Controleer of de rekening wel van de ingelogde klant is
|
||||||
|
foreach ($rekeningen as $rek) {
|
||||||
|
if ($rek['nr'] === $van) {
|
||||||
|
$vanRekening = $rek;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!$vanRekening) {
|
||||||
|
//error: rekening is niet van klant
|
||||||
|
return Redirect::create($request, $response, "/eigenaar");
|
||||||
|
}
|
||||||
|
$ibanHelper = new IBAN();
|
||||||
|
if (!$ibanHelper->isValidIBAN($naar)) {
|
||||||
|
//error: ongeldige iban
|
||||||
|
return Redirect::create($request, $response, "/ongeldig");
|
||||||
|
} else if (!($ibanHelper->getLand($naar) == "NL" && $ibanHelper->getBank($naar) === "INFO")) {
|
||||||
|
//error: andere bank
|
||||||
|
return Redirect::create($request, $response, "/andere");
|
||||||
|
}
|
||||||
|
$naarRekeningnr = $ibanHelper->getRekeningNummer($naar);
|
||||||
|
//TODO kijk of de rekening wel bestaat
|
||||||
|
if ($naarRekeningnr == $vanRekening['nr']) {
|
||||||
|
//error: afzender is hetzelfde als ontvanger
|
||||||
|
return Redirect::create($request, $response, "/zelfde");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TODO geldigheid bedrag onderzoeken
|
||||||
|
//$bedragValue = (double) $bedrag;
|
||||||
|
//TODO omschrijving in database stoppen
|
||||||
|
if (strlen($omschrijving) > 40) {
|
||||||
|
//error: te lange omschrijving
|
||||||
|
}
|
||||||
|
$db = Application::getContainer()->db;
|
||||||
|
$db->transacties->insert([
|
||||||
|
"van" => $vanRekening['nr'],
|
||||||
|
"naar" => $naarRekeningnr,
|
||||||
|
"bedrag" => $bedrag,
|
||||||
|
"type" => "GT" //GT staat voor internetbankieren
|
||||||
|
]);
|
||||||
|
|
||||||
|
//TODO update saldo
|
||||||
|
return Redirect::create($request, $response, "/");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -32,13 +32,19 @@ class Transacties
|
|||||||
$rekening = false;
|
$rekening = false;
|
||||||
$rekeningnr = $args['rekeningnummer'];
|
$rekeningnr = $args['rekeningnummer'];
|
||||||
|
|
||||||
|
//Controleer of deze rekening wel van de ingelogde klant is
|
||||||
foreach($rekeningen as $rek){
|
foreach($rekeningen as $rek){
|
||||||
if($rek['nr'] === $rekeningnr){
|
if($rek['nr'] === $rekeningnr){
|
||||||
$rekening = $rek;
|
$rekening = $rek;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!$rekening){
|
||||||
|
return $this->renderer->render($response, 'transacties.phtml', [
|
||||||
|
'klant' => $klant,
|
||||||
|
'rekening' => false
|
||||||
|
]);
|
||||||
|
}
|
||||||
$container = Application::getContainer();
|
$container = Application::getContainer();
|
||||||
$db = $container->db;
|
$db = $container->db;
|
||||||
$transacties = $db->transacties->where('van', '12345678')->or('naar', $rekeningnr);
|
$transacties = $db->transacties->where('van', '12345678')->or('naar', $rekeningnr);
|
||||||
@ -53,7 +59,6 @@ class Transacties
|
|||||||
"type" => $transactie['type']
|
"type" => $transactie['type']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->renderer->render($response, 'transacties.phtml', [
|
return $this->renderer->render($response, 'transacties.phtml', [
|
||||||
'klant' => $klant,
|
'klant' => $klant,
|
||||||
'rekening' => $rekening,
|
'rekening' => $rekening,
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
<?php include '__header.phtml'; ?>
|
<?php include '__header.phtml'; ?>
|
||||||
|
|
||||||
<select>
|
<form method="post" action="">
|
||||||
|
<select name="van">
|
||||||
<?php
|
<?php
|
||||||
foreach($rekeningen as $rekening){
|
foreach($rekeningen as $rekening){
|
||||||
echo "<option>" . $rekening['rekeningnr'] . "</option>\n";
|
echo "<option value=" . $rekening['nr'] . ">" . $rekening['iban'] . "</option>\n";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</select><br/>
|
</select><br/>
|
||||||
<input type="text" placeholder="naar"></input><br/>
|
<input name="naar" type="text" placeholder="naar"></input><br/>
|
||||||
<input type="number" placeholder="bedrag"></input><br/>
|
<input name="bedrag" type="decimal" placeholder="bedrag"></input><br/>
|
||||||
<textarea maxlength=40></textarea>
|
<textarea name="omschrijving" maxlength=40></textarea><br/>
|
||||||
|
<button type="submit">Betalen</button>
|
||||||
|
</form>
|
||||||
<?php include '__footer.phtml'; ?>
|
<?php include '__footer.phtml'; ?>
|
||||||
|
Reference in New Issue
Block a user