Пример #1
0
 public function fetch_report_data()
 {
     global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['GiveUsMoneyDB']);
     $month = FormLib::get('month', date('n'));
     $year = FormLib::get('year', date('Y'));
     $end_of_last_month = mktime(0, 0, 0, $month, 0, $year);
     $ts = mktime(0, 0, 0, $month, 1, $year);
     $end_of_next_month = mktime(0, 0, 0, $month, date('t', $ts), $year);
     $end_last_dt = new DateTime(date('Y-m-d', $end_of_last_month));
     $end_next_dt = new DateTime(date('Y-m-d', $end_of_next_month));
     $loans = new GumLoanAccountsModel($dbc);
     $data = array();
     foreach ($loans->find('loanDate') as $loan) {
         $record = array($loan->accountNumber(), number_format($loan->principal(), 2), number_format($loan->interestRate() * 100, 2) . '%', $loan->termInMonths(), date('Y-m-d', strtotime($loan->loanDate())));
         $loanDT = new DateTime(date('Y-m-d', strtotime($loan->loanDate())));
         $days1 = $loanDT->diff($end_last_dt)->format('%r%a');
         $days2 = $loanDT->diff($end_next_dt)->format('%r%a');
         $bal_before = $loan->principal() * pow(1.0 + $loan->interestRate(), $days1 / 365.25);
         if ($days1 < 0) {
             $bal_before = $loan->principal();
         }
         $bal_after = $loan->principal() * pow(1.0 + $loan->interestRate(), $days2 / 365.25);
         if ($days2 < 0) {
             $bal_after = $loan->principal();
         }
         $record[] = number_format($bal_before, 2);
         $record[] = number_format($bal_after, 2);
         $record[] = number_format($bal_after - $bal_before, 2);
         $data[] = $record;
     }
     return $data;
 }
Пример #2
0
 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;
 }
Пример #3
0
<?php

/**
  Script to email end of fiscal year statements
  to all loan account holders
*/
if (basename(__FILE__) != basename($_SERVER['PHP_SELF'])) {
    return;
}
if (php_sapi_name() != 'cli') {
    return;
}
include dirname(__FILE__) . '/../../../../config.php';
if (!class_exists('FannieAPI')) {
    include $FANNIE_ROOT . 'classlib2.0/FannieAPI.php';
}
$dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['GiveUsMoneyDB']);
$endFY = mktime(0, 0, 0, GumLib::getSetting('FYendMonth'), GumLib::getSetting('FYendDay'), date('Y'));
echo "Sending statements for " . date('Y-m-d', $endFY) . "\n";
$url = 'http://localhost' . $FANNIE_URL . 'modules/plugins2.0/GiveUsMoneyPlugin/GumEmailPage.php';
$loans = new GumLoanAccountsModel($dbc);
// GumLoanAccounts.loanDate < end of fiscal year
$loans->loanDate(date('Y-m-d 00:00:00', $endFY), '<');
foreach ($loans->find('loanDate') as $loan) {
    echo 'Sending account# ' . $loan->accountNumber() . ' ' . $loan->loanDate() . "\n";
    $qs = '?id=' . $loan->accountNumber() . '&loanstatement=1';
    $ch = curl_init($url . $qs);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close($ch);
}
Пример #4
0
 public function get_id_handler()
 {
     global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB;
     $bridge = GumLib::getSetting('posLayer');
     $this->custdata = $bridge::getCustdata($this->id);
     $this->meminfo = $bridge::getMeminfo($this->id);
     // bridge may change selected database
     $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['GiveUsMoneyDB']);
     $this->maillog = new GumEmailLogModel($dbc);
     $this->maillog->card_no($this->id);
     $this->loans = array();
     $model = new GumLoanAccountsModel($dbc);
     $model->card_no($this->id);
     foreach ($model->find('loanDate') as $obj) {
         $this->loans[] = $obj;
     }
     $this->equity = array();
     $model = new GumEquitySharesModel($dbc);
     $model->card_no($this->id);
     foreach ($model->find('tdate') as $obj) {
         $this->equity[] = $obj;
     }
     $this->dividends = array();
     $model = new GumDividendsModel($dbc);
     $model->card_no($this->id);
     foreach ($model->find('yearEndDate') as $obj) {
         $this->dividends[] = $obj;
     }
     $this->settings = new GumSettingsModel($dbc);
     return true;
 }