/** * 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'); }
/** * Show list of books which students can keep for next schoolyear, ordered by schoolyear. */ function showBooksForNextYear() { require_once 'AdminBooklistInterface.php'; if (isset($_POST['grade'])) { require_once PATH_INCLUDE . '/Schbas/Loan.php'; require_once PATH_ACCESS . '/BookManager.php'; $gradelevel = $_POST['grade']; $loanHelper = new \Babesk\Schbas\Loan($this->_dataContainer); $booksThisYear = $loanHelper->booksInGradelevelToLoanGet($gradelevel); $booksNextYear = $loanHelper->booksInGradelevelToLoanGet($gradelevel + 1); //Use ArrayCollection for filter() and contains() $booksThisYear = new ArrayCollection($booksThisYear); $booksNextYear = new ArrayCollection($booksNextYear); // Only books that are both in this gradelevel and next gradelevel // will be displayed $books = $booksThisYear->filter(function ($book) use($booksNextYear) { return $booksNextYear->contains($book); }); $this->showPdf($books->toArray()); } else { $this->BookInterface->ShowSelectionForBooksToKeep(); } }
/** * 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 bookOverview() { $loanHelper = new \Babesk\Schbas\Loan($this->_dataContainer); $schoolyear = $this->_em->getRepository('DM:SystemSchoolyears')->findOneByActive(true); $gradeId = filter_input(INPUT_POST, 'grade'); if (!$gradeId) { $this->_interface->dieError('Keine Klasse übergeben'); } $grade = $this->_em->find('DM:SystemGrades', $gradeId); $query = $this->_em->createQuery('SELECT u FROM DM:SystemUsers u INNER JOIN u.attendances a INNER JOIN a.schoolyear s WITH s = :schoolyear INNER JOIN a.grade g WITH g = :grade ORDER BY u.name, u.forename '); $query->setParameter('grade', $grade); $query->setParameter('schoolyear', $schoolyear); $users = $query->getResult(); // The only difference between the PDF for booksToReturn and // booksToLoan is the title and the included books $pdfTitle = ''; $syName = $schoolyear->getLabel(); $gradename = $grade->getGradelevel() . $grade->getLabel(); // [{ user: {<userdata>}, books: [{<bookdata>}] }] $usersWithBooks = []; if (isset($_POST['booksToReturn'])) { $pdfTitle = "Abzugebende Bücher für {$gradename} ({$syName})"; foreach ($users as $user) { $books = $loanHelper->lendBooksToReturnOfUserGet($user, $schoolyear); $usersWithBooks[] = ['user' => $user, 'books' => $books]; } } else { if (isset($_POST['booksToLoan'])) { $pdfTitle = "Noch auszuleihende Bücher für {$gradename} ({$syName})"; foreach ($users as $user) { $books = $loanHelper->loanBooksOfUserGet($user, ['schoolyear' => $schoolyear]); $usersWithBooks[] = ['user' => $user, 'books' => $books]; } } } $date = date('d.m.Y H:i:s'); $this->_smarty->assign('grade', $grade); $this->_smarty->assign('date', $date); $this->_smarty->assign('usersWithBooks', $usersWithBooks); $this->_smarty->assign('pdfTitle', $pdfTitle); $pdfContent = $this->_smarty->fetch(PATH_SMARTY_TPL . '/pdf/schbas-books-overview.pdf.tpl'); $pdf = new GeneralPdf($this->_pdo); $pdf->create($pdfTitle, $pdfContent); $pdf->output(); }
/** * 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 showParticipationConfirmation() { $settingsRepo = $this->_em->getRepository('DM:SystemGlobalSettings'); $user = $this->_em->find('DM:SystemUsers', $_SESSION['uid']); $prepSchoolyear = $this->preparationSchoolyearGet(); $gradeQuery = $this->_em->createQuery('SELECT g FROM DM:SystemGrades g INNER JOIN g.attendances a WITH a.schoolyear = :schoolyear AND a.user = :user '); $gradeQuery->setParameter('schoolyear', $prepSchoolyear); $gradeQuery->setParameter('user', $user); $grade = $gradeQuery->getOneOrNullResult(); if (!$grade) { $this->_interface->dieError('Der Schüler ist nicht im nächsten Schuljahr eingetragen. ' . 'Bitte informieren sie die Schule.'); } // $letterDateIso = $settingsRepo // ->findOneByName('schbasDateCoverLetter') // ->getValue(); // $letterDate = date('d.m.Y', strtotime($letterDateIso)); $letterDate = date('d.m.Y'); $schbasDeadlineTransferIso = $settingsRepo->findOneByName('schbasDeadlineTransfer')->getValue(); $schbasDeadlineTransfer = date('d.m.Y', strtotime($schbasDeadlineTransferIso)); $schbasDeadlineClaimIso = $settingsRepo->findOneByName('schbasDeadlineClaim')->getValue(); $schbasDeadlineClaim = date('d.m.Y', strtotime($schbasDeadlineClaimIso)); $bankAccount = $settingsRepo->findOneByName('bank_details')->getValue(); $bankData = explode('|', $bankAccount); //get loan fees $loanHelper = new \Babesk\Schbas\Loan($this->_dataContainer); $fees = $loanHelper->loanPriceOfAllBookAssignmentsForUserCalculate($user); list($feeNormal, $feeReduced) = $fees; $feedback = ''; $loanChoice = filter_input(INPUT_POST, 'loanChoice'); $loanFee = filter_input(INPUT_POST, 'loanFee'); $siblings = filter_input(INPUT_POST, 'siblings'); $eb_name = filter_input(INPUT_POST, 'eb_name'); $eb_vorname = filter_input(INPUT_POST, 'eb_vorname'); $eb_adress = filter_input(INPUT_POST, 'eb_adress'); $eb_tel = filter_input(INPUT_POST, 'eb_tel'); if ($loanChoice == 'noLoan') { $feedback = 'nl'; } else { if ($loanFee == 'loanSoli') { $feedback = 'ls'; } else { if ($loanFee == 'loanNormal') { $feedback = 'ln'; } else { if ($loanFee == 'loanReduced') { $feedback = 'lr'; } } } } $this->_smarty->assign('user', $user); $this->_smarty->assign('grade', $grade); $this->_smarty->assign('schoolyear', $prepSchoolyear->getLabel()); $this->_smarty->assign('letterDate', $letterDate); $this->_smarty->assign('schbasDeadlineClaim', $schbasDeadlineClaim); $this->_smarty->assign('bankData', $bankData); $this->_smarty->assign('feeNormal', $feeNormal); $this->_smarty->assign('feeReduced', $feeReduced); $this->_smarty->assign('loanFee', $loanFee); $this->_smarty->assign('siblings', $siblings); $this->_smarty->assign('loanChoice', $loanChoice); $this->_smarty->assign('parentName', $eb_name); $this->_smarty->assign('parentForename', $eb_vorname); $this->_smarty->assign('parentAddress', $eb_adress); $this->_smarty->assign('parentTelephone', $eb_tel); $this->_smarty->assign('schbasDeadlineTransfer', $schbasDeadlineTransfer); $content = $this->_smarty->fetch(PATH_SMARTY_TPL . '/pdf/schbas-participation-confirmation.pdf.tpl'); $schbasPdf = new \Babesk\Schbas\SchbasPdf($user->getId(), $grade->getGradelevel()); $barcode = $user->getId() . ' ' . $feedback; $schbasPdf->create($content, $barcode); $schbasPdf->output(); }
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!'); } }