Exemplo n.º 1
0
 public static function post()
 {
     $page = new Page();
     $page->data['title'] = 'Kassa';
     if (isset($_POST['to_enter_transaction_view'])) {
         $errMsgs = CashRegisterEnterCardViewValidator::validate($_POST);
         if (empty($errMsgs)) {
             try {
                 $_SESSION['Stippers']['CashRegister']['user'] = UserDB::getFullUserByCardNumber($_POST['card_number']);
                 if (!$_SESSION['Stippers']['CashRegister']['user']) {
                     CashRegisterController::buildEnterCardView($page, true);
                     $page->data['CashRegisterEnterCardView']['errMsgs']['global'] = '<h2 class="error_message" id="enter_card_form_error_message">Dit kaartnummer is niet gekoppeld aan een gebruiker.</h2>';
                 } else {
                     CashRegisterController::buildEnterTransactionView($page, false);
                 }
             } catch (Exception $ex) {
                 CashRegisterController::buildEnterCardView($page, true);
                 $page->data['CashRegisterEnterCardView']['errMsgs']['global'] = '<h2 class="error_message" id="enter_card_form_error_message">Kan gebruiker niet ophalen, probeer opnieuw.</h2>';
             }
         } else {
             CashRegisterController::buildEnterCardView($page, true);
             $page->data['CashRegisterEnterCardView']['errMsgs'] = array_merge($page->data['CashRegisterEnterCardView']['errMsgs'], $errMsgs);
         }
     } elseif (isset($_POST['register_transaction'])) {
         $errMsgs = CashRegisterEnterTransactionViewValidator::validate($_POST);
         if (empty($errMsgs)) {
             try {
                 $decrMoney = $_POST['decrease_money'] == '' ? 0 : SafeMath::getCentsFromString($_POST['decrease_money']);
                 $executingBrowserName = BrowserDB::getBrowserById($_SESSION['Stippers']['browser']->browserId)->name;
                 $trans = new MoneyTransaction(null, $_SESSION['Stippers']['CashRegister']['user']->userId, $_SESSION['Stippers']['CashRegister']['user']->balance, 0, $decrMoney, MoneyTransactionConfig::DEFAULT_DISCOUNT_PERC, false, null, $executingBrowserName, null);
                 if ($trans->getBalAfter() < 0) {
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['tryAgainUrl'] = $_SERVER['REQUEST_URI'];
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['errorTitle'] = 'Saldo te laag';
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['errorDescription'] = 'Het saldo de kaart is te laag.<br>Je komt onder nul uit.';
                     $page->addView('error/ErrorMessageWithDescriptionWithLinkView');
                 } else {
                     MoneyTransactionDB::addTransaction($_SESSION['Stippers']['CashRegister']['user'], $trans);
                     $page->data['CashRegisterTransactionResultView']['balBefore'] = $trans->getBalBefore() / 100;
                     $page->data['CashRegisterTransactionResultView']['balAfter'] = $trans->getBalAfter() / 100;
                     $page->data['CashRegisterTransactionResultView']['discount'] = $trans->getDiscount() / 100;
                     $page->data['CashRegisterTransactionResultView']['decrMoney'] = $trans->getDecrMoney() / 100;
                     $page->addView('cashRegister/CashRegisterTransactionResultView');
                 }
             } catch (Exception $ex) {
                 CashRegisterController::buildEnterTransactionView($page, true);
                 $page->data['CashRegisterEnterTransactionView']['errMsgs']['global'] = '<h2 class="error_message" id="enter_transaction_form_error_message">Kan transactie niet registreren, probeer opnieuw.</h2>';
             }
         } else {
             CashRegisterController::buildEnterTransactionView($page, true);
             $page->data['CashRegisterEnterTransactionView']['errMsgs'] = array_merge($page->data['CashRegisterEnterTransactionView']['errMsgs'], $errMsgs);
         }
     }
     $page->showWithMenu();
 }
 public static function validate(array $data)
 {
     $errMsgs = array();
     //Get cents with safe precision
     $incrMoney = SafeMath::getCentsFromString($data['increase_money']);
     $decrMoney = SafeMath::getCentsFromString($data['decrease_money']);
     if ($data['increase_money'] != '' && ($incrMoney === false || $incrMoney > 99999) || $data['decrease_money'] != '' && ($decrMoney === false || $decrMoney > 99999)) {
         $errMsgs['global'] = '<h2 class="error_message" id="enter_transaction_form_error_message">Voer geldige bedragen in.</h2>';
     } elseif ($data['increase_money'] < 0 || $data['decrease_money'] < 0) {
         $errMsgs['global'] = '<h2 class="error_message" id="enter_transaction_form_error_message">Je kan enkel positieve bedragen ingeven.</h2>';
     } elseif ($data['increase_money'] == '' && $data['decrease_money'] == '') {
         $errMsgs['global'] = '<h2 class="error_message" id="enter_transaction_form_error_message">Je hebt geen transactie ingegeven.</h2>';
     }
     return $errMsgs;
 }
 public static function post()
 {
     $page = new Page();
     $page->data['title'] = 'Geld beheren';
     $errMsgs = ManageUserMoneyEnterTransactionViewValidator::validate($_POST);
     if (empty($errMsgs)) {
         try {
             $incrMoney = $_POST['increase_money'] == '' ? 0 : SafeMath::getCentsFromString($_POST['increase_money']);
             $decrMoney = $_POST['decrease_money'] == '' ? 0 : SafeMath::getCentsFromString($_POST['decrease_money']);
             $fromPrize = isset($_POST['from_prize']);
             if (isset($_SESSION['Stippers']['browser'])) {
                 $executingBrowserName = BrowserDB::getBrowserById($_SESSION['Stippers']['browser']->browserId)->name;
             } else {
                 $executingBrowserName = null;
             }
             if (isset($_SESSION['Stippers']['user'])) {
                 $executingUser = $_SESSION['Stippers']['user']->userId;
             } else {
                 $executingUser = null;
             }
             $trans = new MoneyTransaction(null, $_SESSION['Stippers']['ManageUserMoney']['user']->userId, $_SESSION['Stippers']['ManageUserMoney']['user']->balance, $incrMoney, $decrMoney, MoneyTransactionConfig::DEFAULT_DISCOUNT_PERC, $fromPrize, null, $executingBrowserName, $executingUser);
             if ($trans->getBalAfter() < 0) {
                 $page->data['ErrorMessageWithDescriptionWithLinkView']['tryAgainUrl'] = $_SERVER['REQUEST_URI'];
                 $page->data['ErrorMessageWithDescriptionWithLinkView']['errorTitle'] = 'Saldo te laag';
                 $page->data['ErrorMessageWithDescriptionWithLinkView']['errorDescription'] = 'Het saldo de kaart is te laag.<br>Je komt onder nul uit.';
                 $page->addView('error/ErrorMessageWithDescriptionWithLinkView');
             } else {
                 MoneyTransactionDB::addTransaction($_SESSION['Stippers']['ManageUserMoney']['user'], $trans);
                 $page->data['ManageUserMoneyTransactionResultView']['balBefore'] = $trans->getBalBefore() / 100;
                 $page->data['ManageUserMoneyTransactionResultView']['balAfter'] = $trans->getBalAfter() / 100;
                 $page->data['ManageUserMoneyTransactionResultView']['discount'] = $trans->getDiscount() / 100;
                 $page->data['ManageUserMoneyTransactionResultView']['incrMoney'] = $trans->getIncrMoney() / 100;
                 $page->data['ManageUserMoneyTransactionResultView']['decrMoney'] = $trans->getDecrMoney() / 100;
                 $page->addView('manageUserMoney/ManageUserMoneyTransactionResultView');
             }
         } catch (Exception $ex) {
             ManageUserMoneyController::buildEnterTransactionView($page, true);
             $page->data['ManageUserMoneyEnterTransactionView']['errMsgs']['global'] = '<h2 class="error_message" id="enter_transaction_form_error_message">Kan transactie niet registreren, probeer opnieuw.</h2>';
         }
     } else {
         ManageUserMoneyController::buildEnterTransactionView($page, true);
         $page->data['ManageUserMoneyEnterTransactionView']['errMsgs'] = array_merge($page->data['ManageUserMoneyEnterTransactionView']['errMsgs'], $errMsgs);
     }
     $page->showWithMenu();
 }