public function post_id_principal_term_rate_loandate_handler() { global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['GiveUsMoneyDB']); $model = new GumLoanAccountsModel($dbc); $existing_accounts = array(); $next_account = 1; $model->card_no($this->id); foreach ($model->find() as $obj) { $existing_accounts[] = $obj->accountNumber(); $next_account++; } $new = sprintf("%09d-%03d", $this->id, $next_account); while (in_array($new, $existing_accounts)) { $next_account++; $new = sprintf("%09d-%03d", $this->id, $next_account); } $model->accountNumber($new); $model->loanDate($this->loandate); $model->principal($this->principal); $model->termInMonths($this->term); $model->interestRate($this->rate / 100.0); $newid = $model->save(); $model->gumLoanAccountID($newid); $model->accountNumber($new); $model->load(); $emp = GumLib::getSetting('emp_no', 1001); $reg = GumLib::getSetting('register_no', 30); $dept = GumLib::getSetting('loanPosDept', 993); $desc = GumLib::getSetting('loanDescription', 'Member Loan'); $offset = GumLib::getSetting('offsetPosDept', 800); $bridge = GumLib::getSetting('posLayer', 'GumCoreLayer'); if (class_exists($bridge)) { $line1 = array('department' => $dept, 'description' => $desc, 'amount' => $model->principal(), 'card_no' => $model->card_no()); $line2 = array('department' => $offset, 'description' => 'OFFSET ' . $desc, 'amount' => -1 * $model->principal(), 'card_no' => $model->card_no()); $trans_identifier = $bridge::writeTransaction($emp, $reg, array($line1, $line2)); if ($trans_identifier !== true && $trans_identifier !== false) { $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['GiveUsMoneyDB']); $ledger = new GumLoanLedgerModel($dbc); $ledger->accountNumber($model->accountNumber()); $ledger->amount($model->principal()); $ledger->tdate(date('Y-m-d H:i:s')); $ledger->trans_num($trans_identifier); $ledger->save(); } } header('Location: GumMainPage.php?id=' . $this->id); return false; }
public function get_id_loanstatement_handler() { global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB, $FANNIE_ROOT; $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['GiveUsMoneyDB']); $loan = new GumLoanAccountsModel($dbc); $loan->accountNumber($this->id); $loan->load(); $bridge = GumLib::getSetting('posLayer'); $this->custdata = $bridge::getCustdata($loan->card_no()); $this->meminfo = $bridge::getMeminfo($loan->card_no()); // bridge may change selected database $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['GiveUsMoneyDB']); $preamble = 'Hello Owner, ' . "\n"; $preamble .= 'Here is a statement on your owner loan to WFC as of ' . date('m/d/Y', mktime(0, 0, 0, GumLib::getSetting('FYendMonth'), GumLib::getSetting('FYendDay'), date('Y'))) . ', the end of the co-op\'s fiscal year. This is just for your information -' . ' no action is required and you do not have to report interest income until your' . ' loan is repaid. Thank you for your support.' . ' If you have any questions, please contact finance@wholefoods.coop (218) 728-0884, ext. 1.'; $info_section = 'First Name: ' . $this->custdata->FirstName() . "\n" . 'Last Name: ' . $this->custdata->LastName() . "\n" . 'Address: ' . $this->meminfo->street() . "\n" . 'City: ' . $this->meminfo->city() . "\n" . 'State: ' . $this->meminfo->state() . "\n" . 'Zip Code: ' . $this->meminfo->zip() . "\n" . 'Loan Amount: ' . number_format($loan->principal(), 2) . "\n" . 'Loan Date: ' . date('m/d/Y', strtotime($loan->loanDate())) . "\n" . 'Loan Term: ' . $loan->termInMonths() / 12 . ' years' . "\n" . 'Interest Rate: ' . number_format($loan->interestRate() * 100, 2) . "%\n"; $ld = strtotime($loan->loanDate()); $ed = mktime(0, 0, 0, date('n', $ld) + $loan->termInMonths(), date('j', $ld), date('Y', $ld)); $info_section .= 'Maturity Date: ' . date('m/d/Y', $ed) . "\n"; $schedule = GumLib::loanSchedule($loan); $interest = 0.0; $balance = 0.0; $html = '<table style="border-spacing:1em;"> <tr><th colspan="4" style="text-align:center;">Schedule</th></tr> <tr><th>Year Ending</th><th>Days</th><th>Interest</th><th>Balance</th></tr>'; $text = 'Annual Schedule:' . "\n"; foreach ($schedule['schedule'] as $year) { if (strtotime($year['end_date']) > time()) { break; } $html .= '<tr> <td>' . $year['end_date'] . '</td> <td>' . $year['days'] . '</td> <td>' . number_format($year['interest'], 2) . '</td> <td>' . number_format($year['balance'], 2) . '</td> </tr>'; $text .= 'Year Ending: ' . $year['end_date'] . "\n" . 'Days: ' . $year['days'] . "\n" . 'Interest: ' . number_format($year['interest'], 2) . "\n" . 'Balance: ' . number_format($year['balance'], 2) . "\n\n"; $interest += $year['interest']; $balance = $year['balance']; } $html .= '<tr><th>Balance</th><th>' . number_format($loan->principal(), 2) . '</th><th>' . number_format($interest, 2) . '</th><th>' . number_format($balance, 2) . '</th></tr>'; $html .= '</table>'; $text = wordwrap($preamble) . "\n" . $info_section . $text; $html = '<p>' . wordwrap(nl2br($preamble)) . '</p>' . '<p>' . nl2br($info_section) . '</p>' . wordwrap($html); $html = '<html><body>' . $html . '</body></html>'; $uid = FannieAuth::getUID($this->current_user); $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['GiveUsMoneyDB']); $log = new GumEmailLogModel($dbc); $log->card_no($loan->card_no()); $log->tdate(date('Y-m-d H:i:s')); $log->uid($uid); $log->messageType('Statement (' . $this->id . ')'); $mail = new PHPMailer(); $mail->isSMTP(); $mail->Host = '127.0.0.1'; $mail->Port = 25; $mail->SMTPAuth = false; $mail->From = '*****@*****.**'; $mail->FromName = 'Whole Foods Co-op'; $mail->addReplyTo('*****@*****.**'); $mail->addAddress($this->meminfo->email_1()); $mail->isHTML(true); $mail->Subject = 'Owner Loan Statement'; $mail->Body = $html; $mail->AltBody = $text; if (FormLib::get('sendAs') == 'print') { echo $html; return false; } else { if ($mail->send()) { $log->save(); header('Location: GumEmailPage.php?id=' . $loan->card_no()); } else { echo 'Error: unable to send email. Notify IT'; } } return false; }