Ejemplo n.º 1
0
 public function get_id_handler()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $cardno = $this->id;
     $notice = new CustomerNotificationsModel($dbc);
     if (isset($_REQUEST['savebtn'])) {
         $pk = isset($_REQUEST['pref_k']) ? $_REQUEST['pref_k'] : array();
         $pv = isset($_REQUEST['pref_v']) ? $_REQUEST['pref_v'] : array();
         if (is_array($pk) && is_array($pv) && count($pk) == count($pv)) {
             $availModel = new CustAvailablePrefsModel($dbc);
             $prefModel = new CustPreferencesModel($dbc);
             for ($i = 0; $i < count($pk); $i++) {
                 $availModel->pref_key($pk[$i]);
                 $availModel->load();
                 $prefModel->pref_key($pk[$i]);
                 $prefModel->card_no($cardno);
                 $prefModel->custAvailablePrefID($availModel->custAvailablePrefID());
                 $prefModel->pref_value($pv[$i]);
                 $prefModel->save();
                 if ($pk[$i] == 'email_receipt' && filter_var($pv[$i], FILTER_VALIDATE_EMAIL)) {
                     $notice->reset();
                     $notice->cardNo($cardno);
                     $notice->source('email_receipt');
                     $notice->type('memlist');
                     $exists = $notice->find();
                     if (count($exists) > 0) {
                         $notice = array_pop($exists);
                     }
                     $notice->message('&#x2709;');
                     $notice->save();
                 } elseif ($pk[$i] == 'email_receipt') {
                     $notice->reset();
                     $notice->cardNo($cardno);
                     $notice->source('email_receipt');
                     $notice->type('memlist');
                     foreach ($notice->find() as $obj) {
                         $obj->delete();
                     }
                 }
             }
             $this->add_onload_command("showBootstrapAlert('#alert-area', 'success', 'Saved Settings');\n");
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 public function run()
 {
     $dbc = FannieDB::get($this->config->get('OP_DB'));
     $equityP = $dbc->prepare('
         SELECT e.payments,
             e.startdate
         FROM ' . $this->config->get('TRANS_DB') . $dbc->sep() . 'equity_live_balance AS e
         WHERE e.memnum = ?
     ');
     $accounts = \COREPOS\Fannie\API\member\MemberREST::get();
     foreach ($accounts as $account) {
         if ($account['startDate'] != '' && $account['startDate'] != '0000-00-00 00:00:00') {
             // date has been assigned already
             continue;
         }
         $equityR = $dbc->execute($equityP, array($account['cardNo']));
         if (!$equityR || $dbc->numRows($equityR) == 0) {
             // no equity
             continue;
         }
         $equity = $dbc->fetchRow($equityR);
         /**
           If an equity payment has been made,
           assign start date to that equity payment's date.
           If equity is not fully paid, set the end
           date one year in the future.
         */
         if ($equity['payments'] > 0) {
             if ($account['startDate'] == '' || $account['startDate'] == '0000-00-00 00:00:00') {
                 $account['startDate'] = $equity['startdate'];
             }
             if ($equity['payments'] < 100) {
                 $ts = strtotime($equity['startdate']);
                 $next_year = date('Y-m-d', mktime(0, 0, 0, date('n', $ts), date('j', $ts), date('Y', $ts) + 1));
                 $account['endDate'] = $next_year;
             }
             $account['contactAllowed'] = 1;
             $resp = \COREPOS\Fannie\API\member\MemberREST::post($account['cardNo'], $account);
             if ($resp['errors'] > 0) {
                 $this->cronMsg('Error setting account dates for account #' . $account['cardNo']);
             }
         }
     }
     /**
       Re-fetch accounts with update dates
       and set notification message in custReceiptMessages
       and/or CustomerNotifications
     */
     $accounts = \COREPOS\Fannie\API\member\MemberREST::get();
     $old_table = false;
     if ($dbc->tableExists('custReceiptMessage')) {
         $dbc->query("DELETE FROM custReceiptMessage WHERE msg_text LIKE 'EQUITY OWED% == %'");
         $old_table = true;
     }
     $new_table = false;
     if ($dbc->tableExists('CustomerNotifications')) {
         $dbc->query('DELETE FROM CustomerNotifications WHERE source=\'SetMemDatesTask\'');
         $new_table = true;
     }
     foreach ($accounts as $account) {
         if ($account['endDate'] == '' || $account['endDate'] == '0000-00-00 00:00:00') {
             // no due date
             continue;
         }
         if ($account['memberStatus'] != 'PC') {
             // not a member
             continue;
         }
         $equityR = $dbc->execute($equityP, array($account['cardNo']));
         if (!$equityR || $dbc->numRows($equityR) == 0) {
             // no equity
             continue;
         }
         $equity = $dbc->fetchRow($equityR);
         if ($equity['payments'] >= 100) {
             // clear end date from paid-in-full
             $account['endDate'] = '0000-00-00 00:00:00';
             $resp = \COREPOS\Fannie\API\member\MemberREST::post($account['cardNo'], $account);
             continue;
         }
         $msg = 'EQUITY OWED $' . sprintf('%.2f', 100 - $equity['payments']) . ' == DUE DATE ' . date('m/d/Y', strtotime($account['endDate']));
         if ($old_table) {
             $model = new CustReceiptMessageModel($dbc);
             $model->card_no($account['cardNo']);
             $model->msg_text($msg);
             $model->modifier_module('WfcEquityMessage');
             $model->save();
         }
         if ($new_table) {
             $model = new CustomerNotificationsModel($dbc);
             $model->cardNo($account['cardNo']);
             $model->source('SetMemDatesTask');
             $model->type('receipt');
             $model->message($msg);
             $model->modifierModule('WfcEquityMessage');
             $model->save();
         }
     }
 }