function show_overdue($template_name) { global $db; global $TPL; $current_user =& singleton("current_user"); $db = new db_alloc(); $temp = mktime(0, 0, 0, date("m"), date("d"), date("Y")); $today = date("Y", $temp) . "-" . date("m", $temp) . "-" . date("d", $temp); $q = prepare("SELECT itemName,itemType,item.itemID,dateBorrowed,dateToBeReturned,loan.personID \n FROM loan,item \n WHERE dateToBeReturned < '%s' \n\t\t\t\t\t AND dateReturned = '0000-00-00' \n\t\t\t\t\t AND item.itemID = loan.itemID\n ", $today); if (!have_entity_perm("loan", PERM_READ, $current_user, false)) { $q .= prepare("AND loan.personID = %d", $current_user->get_id()); } $db->query($q); while ($db->next_record()) { $i++; $item = new item(); $loan = new loan(); $item->read_db_record($db); $loan->read_db_record($db); $item->set_values(); $loan->set_values(); $person = new person(); $person->set_id($loan->get_value("personID")); $person->select(); $TPL["person"] = $person->get_name(); $TPL["overdue"] = "<a href=\"" . $TPL["url_alloc_item"] . "itemID=" . $item->get_id() . "&return=true\">Overdue!</a>"; include_template($template_name); } }
function show_items($template_name) { global $TPL; global $db; global $db2; $current_user =& singleton("current_user"); $today = date("Y") . "-" . date("m") . "-" . date("d"); $dbUsername = new db_alloc(); $db = new db_alloc(); $db2 = new db_alloc(); $db->query("select * from item order by itemName"); while ($db->next_record()) { $i++; $item = new item(); $item->read_db_record($db); $db2->query("select * from loan where itemID=" . $item->get_id() . " and dateReturned='0000-00-00'"); $db2->next_record(); $loan = new loan(); $loan->read_db_record($db2); $item->set_values(); // you need to have this repeated here for the a href bit below. if ($loan->get_value("dateReturned") == "0000-00-00") { if ($loan->have_perm(PERM_READ_WRITE)) { // if item is overdue if ($loan->get_value("dateToBeReturned") < $today) { $ret = "Return Now!"; } else { $ret = "Return"; } $TPL["itemAction"] = "<td><a href=\"" . $TPL["url_alloc_item"] . "itemID=" . $TPL["itemID"] . "&return=true\">{$ret}</a></td>"; } else { // if you don't have permission to borrow or return item. $TPL["itemAction"] = "<td> </td>"; } $TPL["status"] = "Due " . $loan->get_value("dateToBeReturned"); $dbUsername->query("select username from person where personID=" . $loan->get_value("personID")); $dbUsername->next_record(); $TPL["person"] = "from " . $dbUsername->f("username"); } else { // if the item is available $TPL["status"] = "Available"; $TPL["person"] = ""; $TPL["itemAction"] = "<td><a href=\"" . $TPL["url_alloc_item"] . "itemID=" . $TPL["itemID"] . "&borrow=true\">Borrow</a></td>"; $TPL["dueBack"] = ""; } $loan->set_values(); $item->set_values(); include_template($template_name); } }
$temp = mktime(0, 0, 0, date("m") + $_POST["timePeriod"], date("d"), date("Y")); $whenToReturn = date("Y", $temp) . "-" . date("m", $temp) . "-" . date("d", $temp); $today = date("Y") . "-" . date("m") . "-" . date("d"); if ($loanID) { $loan->set_id($loanID); $loan->select(); } if ($_POST["borrowItem"]) { $db->query("select * from loan where itemID=%d and dateReturned='0000-00-00'", $itemID); if ($db->next_record()) { // if the item is already borrowed alloc_redirect($TPL["url_alloc_item"] . "itemID={$itemID}&badBorrow=true&error=already_borrowed"); exit; } else { // else lets make a new loan! $loan = new loan(); $loan->read_globals(); $loan->set_value("dateToBeReturned", $whenToReturn); // if admin/manager then check to see if an alternate user was selected if ($_POST["userID"] && ($current_user->have_role("admin") || $current_user->have_role("manage"))) { if ($_POST["userID"] != $current_user->get_id()) { $person = new person(); $person->set_id($_POST["userID"]); $person->select(); } $loan->set_value("personID", $_POST["userID"]); } else { $loan->set_value("personID", $current_user->get_id()); } $loan->set_value("dateBorrowed", $today); $loan->set_value("dateReturned", "0000-00-00");
$item = new item(); $item->set_id($d->getFieldValue('id')); $item->select(); $row = array(); $row["idx"] = $hit->id; $author = $item->get_value("itemAuthor"); $author and $author = " by " . $author; $row["title"] = $item->get_id() . " " . $item->get_link() . $author; $row["score"] = sprintf('%d%%', $hit->score * 100); $row["desc"] = page::htmlentities($d->getFieldValue('desc')); // get availability of loan $db2 = new db_alloc(); $query = prepare("SELECT * FROM loan WHERE itemID = %d AND dateReturned='0000-00-00'", $item->get_id()); $db2->query($query); if ($db2->next_record()) { $loan = new loan(); $loan->read_db_record($db2); if ($loan->have_perm(PERM_READ_WRITE)) { // if item is overdue if ($loan->get_value("dateToBeReturned") < $today) { $status = "Overdue"; } else { $status = "Due on " . $loan->get_value("dateToBeReturned"); } $row["related"] = $status . " <a href=\"" . $TPL["url_alloc_item"] . "itemID=" . $item->get_id() . "&return=true\">Return</a>"; // Else you dont have permission to loan or return so just show status } else { $name = page::htmlentities($p[$loan->get_value("personID")]["name"]); if ($loan->get_value("dateToBeReturned") < $today) { $row["related"] = "Overdue from " . $name; } else {
public function actionDoupdate() { $loc = loan::find()->where(['id_loan' => $this->loan->id_loan])->one(); // 读取 payment if (!empty($this->loan->id_loan) && $this->loan->status == Dict::LOAN_STATUS_ACTIVE) { $payment = LoanBorrower::find()->where(['id_loan' => $this->loan->id_loan])->one(); $LoanPaymentPreferenceModel = LoanPaymentPreference::find()->where(['id_loan' => $this->loan->id_loan])->one(); $type_checked = $LoanPaymentPreferenceModel['type']; $bankAccountModel = LoanBankAcount::find()->andWhere(['id_loan' => $this->loan->id_loan, 'account_type' => '2'])->one(); $bankAccountModel_1 = LoanBankAcount::find()->andWhere(['id_loan' => $this->loan->id_loan, 'account_type' => '1'])->one(); $acheck = 2; if ($bankAccountModel['bank_name'] == $bankAccountModel_1['bank_name'] && $bankAccountModel['routing_number'] == $bankAccountModel_1['routing_number'] && $bankAccountModel['account_name'] == $bankAccountModel_1['account_name'] && $bankAccountModel['account_number'] == $bankAccountModel_1['account_number']) { $acheck = 1; } if (empty($bankAccountModel)) { $bankAccountModel = $bankAccountModel_1; $acheck = 1; $no_val = null; } else { $no_val = $bankAccountModel; } if ($type_checked != 1) { $acheck = 1; } } else { return $this->render("payment", ['status' => 0]); } // 读取 bank account if ($LoanPaymentPreferenceModel->load(Yii::$app->request->post())) { $paymentPost = Yii::$app->request->post('LoanPaymentPreference'); $achchecked = Yii::$app->request->post('optionsRadios'); $LoanBankAcount = Yii::$app->request->post('LoanBankAcount'); //得到LoanPaymentPreference数据 if (!empty($LoanPaymentPreferenceModel)) { $LoanPaymentPreferenceModel->type = $paymentPost['type']; $LoanPaymentPreferenceModel->save(); } $bankaccoun = LoanBankAcount::find()->andWhere(['id_loan' => $this->loan->id_loan, 'account_type' => '2'])->one(); if (empty($bankaccoun)) { $bankaccoun = new LoanBankAcount(); } if ($paymentPost['type'] == Dict::LOAN_PAYMENT_ACH) { if ($achchecked == 1) { $bannaccoun1 = LoanBankAcount::find()->andWhere(['id_loan' => $this->loan->id_loan, 'account_type' => '1'])->one(); $bankaccoun->bank_name = $bannaccoun1->bank_name; $bankaccoun->routing_number = $bannaccoun1->routing_number; $bankaccoun->account_name = $bannaccoun1->account_name; $bankaccoun->account_number = $bannaccoun1->account_number; } else { $bankaccoun->bank_name = $LoanBankAcount['bank_name']; $bankaccoun->routing_number = $LoanBankAcount['routing_number']; $bankaccoun->account_name = $LoanBankAcount['account_name']; $bankaccoun->account_number = $LoanBankAcount['account_number']; } $bankaccoun->id_loan = $this->loan->id_loan; $bankaccoun->account_type = 2; $bankaccoun->save(false); } else { $bankaccoun->id_loan = $this->loan->id_loan; $bankaccoun->account_type = 2; $bankaccoun->save(false); } $this->redirect('/loan/payment'); } $config_pay = Config::find()->where(['config_name' => "pay_to_adress"])->one(); $config_fee = Config::find()->where(['config_name' => "check_processing_fee"])->one(); $config['pay'] = $config_pay['config_value']; $config['fee'] = $config_fee['config_value']; $config['loc'] = $loc['loc'] * Dict::LOAN_PAYMENT_RATE / Dict::LOAN_PAYMENT_MONTH; $config['acheck'] = $acheck; $LoanPaymentPreferenceModel->type = $type_checked; return $this->render('update_payment', ['config' => $config, 'status' => Dict::LOAN_STATUS_ACTIVE, 'type_checked' => $type_checked, 'loan' => $this->loan, 'payment' => $payment, 'no_val' => $no_val, 'bankAccountModel' => $bankAccountModel, 'LoanPaymentPreference' => $LoanPaymentPreferenceModel, 'bankAccountModel_1' => $bankAccountModel_1]); }