/** * Ausleihtabelle anzeigen */ function RetourTableData($card_id) { $loanHelper = new \Babesk\Schbas\Loan($this->_dataContainer); $prepSy = $loanHelper->schbasPreparationSchoolyearGet(); $uid = $this->GetUser($card_id); $user = $this->_em->find('DM:SystemUsers', $uid); $query = $this->_em->createQuery('SELECT b, e, l FROM DM:SchbasBook b INNER JOIN b.exemplars e INNER JOIN e.lending l WITH l.user = :user '); $query->setParameter('user', $user); $loanbooks = $query->getResult(); if (!count($loanbooks)) { $this->_interface->dieMsg('Der Benutzer hat keine Bücher ausgeliehen.'); } $grade = $this->_em->getRepository('DM:SystemUsers')->getActiveGradeByUser($user); $userData = "{$user->getForename()} {$user->getName()} "; if ($grade) { $userData .= "({$grade->getGradelevel()}{$grade->getLabel()})"; } $accountingQb = $this->_em->createQueryBuilder()->select('u, a, lc')->from('DM:SystemUsers', 'u')->leftJoin('u.schbasAccounting', 'a', 'WITH', 'a.schoolyear = :prepSchoolyear')->leftJoin('a.loanChoice', 'lc')->where('u = :user'); $accountingQb->setParameter('prepSchoolyear', $prepSy); $accountingQb->setParameter('user', $user); $user = $accountingQb->getQuery()->getOneOrNullResult(); $this->_smarty->assign('cardid', $card_id); $this->_smarty->assign('uid', $uid); $this->_smarty->assign('data', $loanbooks); $this->_smarty->assign('fullname', $userData); $this->_smarty->assign('user', $user); $this->_smarty->assign('adress', $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); $this->displayTpl('retourbooks.tpl'); }
protected function calculateData() { $loanHelper = new \Babesk\Schbas\Loan($this->_dataContainer); $schoolyear = $loanHelper->schbasPreparationSchoolyearGet(); $schoolyearId = $schoolyear->getId(); $stmt = $this->_pdo->query("SELECT lc.name AS loanChoiceName, COUNT(*) AS count\n\t\t\t\tFROM SchbasAccounting sa\n\t\t\t\tINNER JOIN SchbasLoanChoices lc ON lc.ID = sa.loanChoiceId\n\t\t\t\tWHERE sa.schoolyearId = {$schoolyearId}\n\t\t\t\tGROUP BY loanChoiceId\n\t\t"); $usercount = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); $stmt = $this->_pdo->query("SELECT lc.name AS loanChoiceName,\n\t\t\t\t\tCONCAT(SUM(payedAmount), '€') AS payedAmount\n\t\t\t\tFROM SchbasAccounting sa\n\t\t\t\tINNER JOIN SchbasLoanChoices lc ON lc.ID = sa.loanChoiceId\n\t\t\t\tWHERE lc.abbreviation IN('ln', 'lr')\n\t\t\t\t\tAND sa.schoolyearId = {$schoolyearId}\n\t\t\t\tGROUP BY loanChoiceId\n\t\t"); $payedAmount = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); $data = array('usercount' => $usercount, 'payedAmount' => $payedAmount); return $data; }
private function loanDisplay($cardnumber) { $loanHelper = new \Babesk\Schbas\Loan($this->_dataContainer); $prepSchoolyear = $loanHelper->schbasPreparationSchoolyearGet(); $user = $this->userByCardnumberGet($cardnumber); $loanChoice = false; $accounting = $this->_em->getRepository('DM:SchbasAccounting')->findOneBy(['user' => $user, 'schoolyear' => $prepSchoolyear]); if ($accounting !== Null) { $userPaid = $this->userPaidForLoanCheck($accounting); $userSelfpayer = $this->selfpayerCheck($accounting); $loanChoice = $accounting->getLoanChoice()->getAbbreviation(); $formSubmitted = true; } else { $userPaid = false; $userSelfpayer = false; $formSubmitted = false; } $exemplarsLent = $this->exemplarsStillLendByUserGet($user); $booksSelfpaid = $user->getSelfpayingBooks(); // The books that are already lend to the user will be highlighted $booksToLoan = $loanHelper->loanBooksOfUserGet($user, ['includeAlreadyLend' => true]); $booksToLoanWithLent = []; foreach ($booksToLoan as $book) { $alreadyLent = false; foreach ($exemplarsLent as $exemplar) { if ($book === $exemplar->getBook() && $book->getId() == $exemplar->getBook()->getId()) { $alreadyLent = true; break; } } $booksToLoanWithLent[] = ['book' => $book, 'alreadyLent' => $alreadyLent]; } $this->_smarty->assign('user', $user); $this->_smarty->assign('formSubmitted', $formSubmitted); $this->_smarty->assign('loanChoice', $loanChoice); $this->_smarty->assign('userPaid', $userPaid); $this->_smarty->assign('userSelfpayer', $userSelfpayer); $this->_smarty->assign('exemplarsLent', $exemplarsLent); $this->_smarty->assign('booksSelfpaid', $booksSelfpaid); $this->_smarty->assign('booksToLoan', $booksToLoanWithLent); $this->displayTpl('user-loan-list.tpl'); }
/** * Checks if the user has the subject. If not, remove the book-assignment * It calls the Db to check the subjects, so if you change the subject * beforehand make sure to commit those to the db. * It also calculates the correct book from the classes. * * This could be so much better. Sorry, future me... * * @param object $user The user of the book-assignment * @param object $subject The subject of the book of the book-assignment. * @return bool true if a bookAssignment was removed, else false */ protected function removeBookAssignmentIfSubjectRemoved($user, $subject) { require_once PATH_INCLUDE . '/Schbas/Loan.php'; $loanHelper = new \Babesk\Schbas\Loan($this->_dataContainer); $schoolyear = $loanHelper->schbasPreparationSchoolyearGet(); $userGrade = $this->_em->getRepository('DM:SystemUsers')->getGradeByUserAndSchoolyear($user, $schoolyear); if (!$userGrade) { return false; } $userSubjects = $loanHelper->userSubjectsCalc($user, $userGrade->getGradelevel()); if (!in_array($subject->getAbbreviation(), $userSubjects)) { $bookAssignments = $loanHelper->findBookAssignmentsForUserBySubject($user, $subject, $schoolyear); if ($bookAssignments && count($bookAssignments)) { foreach ($bookAssignments as $bookAssignment) { $this->_em->remove($bookAssignment); } $this->_em->flush(); return true; } else { return false; } } else { return false; } }
private function executePayment($UID, $payment) { $loanHelper = new \Babesk\Schbas\Loan($this->_dataContainer); $schoolyear = $loanHelper->schbasPreparationSchoolyearGet(); $schoolyearId = $schoolyear->getId(); $UID = str_replace("Payment", "", $UID); try { TableMng::query("UPDATE SchbasAccounting\n\t\t\t\t\tSET payedAmount = {$payment}\n\t\t\t\t\tWHERE userId = {$UID} AND schoolyearId = {$schoolyearId}\n\t\t\t"); } catch (Exception $e) { } }
/** * Calculates the amount of book-exemplars that users buy for themselfes * @param Paginator $paginator doctrines paginator containing the books * @return array book-ids as the key with the values being * the amount of book-exemplars needed * '<bookId>' => [ * 'exemplarsSelfpayed' => * '<exemplarCount>' * ] */ protected function bookExemplarsSelfpayedGet($paginator) { $loanHelper = new \Babesk\Schbas\Loan($this->_dataContainer); $prepSchoolyear = $loanHelper->schbasPreparationSchoolyearGet(); $booksSelfpayed = []; foreach ($paginator as $book) { $query = $this->_em->createQuery('SELECT COUNT(u) FROM DM:SchbasBook b INNER JOIN b.selfpayingBookEntities sb INNER JOIN sb.user u INNER JOIN u.attendances a WITH a.schoolyear = :schoolyear WHERE b = :book '); $query->setParameter('schoolyear', $prepSchoolyear); $query->setParameter('book', $book); $count = $query->getSingleScalarResult(); $booksSelfpayed[$book->getId()]['exemplarsSelfpayed'] = $count; } return $booksSelfpayed; }
private function paidAmountChange($userId, $amount) { try { $loanHelper = new \Babesk\Schbas\Loan($this->_dataContainer); $user = $this->_em->getRepository('DM:SystemUsers')->findOneById($userId); $schoolyear = $loanHelper->schbasPreparationSchoolyearGet(); if (!isset($user)) { throw new Exception('User not found!'); } $accounting = $this->_em->getRepository('DM:SchbasAccounting')->findOneBy(['user' => $user, 'schoolyear' => $schoolyear]); $accounting->setPayedAmount($amount); $paid = $accounting->getPayedAmount(); $toPay = $accounting->getAmountToPay(); $missing = $toPay - $paid; $this->_em->persist($accounting); $this->_em->flush(); die(json_encode(array('userId' => $userId, 'paid' => $paid, 'missing' => $missing))); } catch (Exception $e) { $this->_logger->log('Error updating the paid amount of an user', 'error', Null, json_encode(array('uid' => $userId, 'amount' => $amount, 'msg' => $e->getMessage()))); http_response_code(500); } }
/** * Automatically create the assignments. * Dies with json. * * @param array $data An array containing options: * { * 'existingAssignmentsAction': '<action>', * 'addGradelevelToUsers': '<gradelevelIncrease?>' * } */ protected function assignmentsCreate($data) { if (empty($data) || !isset($data['existingAssignmentsAction'])) { $this->_logger->logO('missing parameters for ' . __METHOD__, ['sev' => 'warning']); } $loanBookMan = new \Babesk\Schbas\Loan($this->_dataContainer); $loanGenerator = new \Babesk\Schbas\ShouldLendGeneration($this->_dataContainer); $sy = $loanBookMan->schbasPreparationSchoolyearGet(); $assignmentsExist = $this->assignmentsForSchoolyearExistCheck($sy); if ($assignmentsExist && $data['existingAssignmentsAction'] == 'delete-existing') { $this->deleteExistingAssignmentsForSchoolyear($sy); } $res = $loanGenerator->generate(); if ($res) { dieJson('Die Zuweisungen wurden erfolgreich erstellt.'); } else { $this->_logger->log('Could not create the assignments', 'error'); http_response_code(500); dieJson('Konnte die Zuweisungen nicht erstellen!'); } }