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 = "";
|
||||
$wordarray = str_split($word);
|
||||
foreach ($wordarray as $v) {
|
||||
if(ctype_alpha($v)){
|
||||
$newword .= ord(strtolower($v)) - 87;
|
||||
}else{
|
||||
$newword .= $v;
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
@ -39,24 +82,7 @@ class IBAN
|
||||
$rekeningnr = str_pad($rekeningnr, 10, 0, STR_PAD_LEFT);
|
||||
|
||||
$bignum = $banknumber . $rekeningnr . $landnumber . "00";
|
||||
|
||||
$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;
|
||||
}
|
||||
$checkdigits = $this->getCheckDigits($bignum);
|
||||
|
||||
$rekeningnrarr = str_split($rekeningnr, 4);
|
||||
return $landcode.$checkdigits." ".$bankcode." ".$rekeningnrarr[0]." ".$rekeningnrarr[1]." ".$rekeningnrarr[2];
|
||||
|
@ -14,26 +14,80 @@
|
||||
|
||||
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\Helper\IBAN;
|
||||
use Inforbank\Application\Helper\Klant;
|
||||
use Inforbank\Application\Helper\Redirect;
|
||||
use Inforbank\Application\Helper\Rekeningen;
|
||||
use Slim\App;
|
||||
|
||||
class Overboeking
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
class Overboeking {
|
||||
|
||||
public function __construct(App $app) {
|
||||
$app->get('/overboeking', function ($request, $response, $args) {
|
||||
$klant = Klant::getCurrentUser();
|
||||
$rekeningen = Rekeningen::getCurrentUserRekeningen();
|
||||
|
||||
|
||||
|
||||
return $this->renderer->render($response, 'overboeking.phtml', [
|
||||
'klant' => $klant,
|
||||
'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;
|
||||
$rekeningnr = $args['rekeningnummer'];
|
||||
|
||||
//Controleer of deze rekening wel van de ingelogde klant is
|
||||
foreach($rekeningen as $rek){
|
||||
if($rek['nr'] === $rekeningnr){
|
||||
$rekening = $rek;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$rekening){
|
||||
return $this->renderer->render($response, 'transacties.phtml', [
|
||||
'klant' => $klant,
|
||||
'rekening' => false
|
||||
]);
|
||||
}
|
||||
$container = Application::getContainer();
|
||||
$db = $container->db;
|
||||
$transacties = $db->transacties->where('van', '12345678')->or('naar', $rekeningnr);
|
||||
@ -53,7 +59,6 @@ class Transacties
|
||||
"type" => $transactie['type']
|
||||
);
|
||||
}
|
||||
|
||||
return $this->renderer->render($response, 'transacties.phtml', [
|
||||
'klant' => $klant,
|
||||
'rekening' => $rekening,
|
||||
|
@ -1,14 +1,16 @@
|
||||
<?php include '__header.phtml'; ?>
|
||||
|
||||
<select>
|
||||
<form method="post" action="">
|
||||
<select name="van">
|
||||
<?php
|
||||
foreach($rekeningen as $rekening){
|
||||
echo "<option>" . $rekening['rekeningnr'] . "</option>\n";
|
||||
echo "<option value=" . $rekening['nr'] . ">" . $rekening['iban'] . "</option>\n";
|
||||
}
|
||||
?>
|
||||
</select><br/>
|
||||
<input type="text" placeholder="naar"></input><br/>
|
||||
<input type="number" placeholder="bedrag"></input><br/>
|
||||
<textarea maxlength=40></textarea>
|
||||
|
||||
<input name="naar" type="text" placeholder="naar"></input><br/>
|
||||
<input name="bedrag" type="decimal" placeholder="bedrag"></input><br/>
|
||||
<textarea name="omschrijving" maxlength=40></textarea><br/>
|
||||
<button type="submit">Betalen</button>
|
||||
</form>
|
||||
<?php include '__footer.phtml'; ?>
|
||||
|
Reference in New Issue
Block a user