Esempio n. 1
0
 protected function deactivate_account($cardno, $reason, $type)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $account = \COREPOS\Fannie\API\member\MemberREST::get($cardno);
     $cas_model = new CustomerAccountSuspensionsModel($dbc);
     $cas_model->card_no($cardno);
     $current_id = 0;
     $chkQ = $dbc->prepare_statement("SELECT cardno FROM suspensions WHERE cardno=?");
     $chkR = $dbc->exec_statement($chkQ, array($cardno));
     if ($dbc->num_rows($chkR) > 0) {
         // if account is already suspended, just update the reason
         $upQ = $dbc->prepare_statement("UPDATE suspensions SET reasoncode=?, type=?\n                WHERE cardno=?");
         $upR = $dbc->exec_statement($upQ, array($reason, substr($type, 0, 1), $cardno));
         $m_status = 0;
         if (substr($type, 0, 1) == 'T') {
             $m_status = 2;
         } else {
             $m_status = 1;
         }
         $cas_model->active(1);
         $changed = false;
         // find most recent active record
         $current = $cas_model->find('tdate', true);
         foreach ($current as $obj) {
             if ($obj->reasonCode() != $reason || $obj->suspensionTypeID() != $m_status) {
                 $changed = true;
             }
             $cas_model->savedType($obj->savedType());
             $cas_model->savedMemType($obj->savedMemType());
             $cas_model->savedDiscount($obj->savedDiscount());
             $cas_model->savedChargeLimit($obj->savedChargeLimit());
             $cas_model->savedMailFlag($obj->savedMailFlag());
             // copy "saved" values from current active
             // suspension record. should only be one
             break;
         }
         // only add a record if something changed.
         // count($current) of zero means there is no
         // record. once the migration to the new data
         // structure is complete, that check won't
         // be necessary
         if ($changed || count($current) == 0) {
             $cas_model->reasonCode($reason);
             $cas_model->username($this->current_user);
             $cas_model->tdate(date('Y-m-d H:i:s'));
             $cas_model->suspensionTypeID($m_status);
             $current_id = $cas_model->save();
         }
     } else {
         // new suspension
         // get current values and save them in suspensions table
         $discount = 0;
         foreach ($account['customers'] as $c) {
             if ($c['accountHolder']) {
                 $discount = $c['discount'];
                 break;
             }
         }
         $now = date('Y-m-d H:i:s');
         $insQ = $dbc->prepare("INSERT INTO suspensions \n                (cardno, type, memtype1, memtype2, reason, suspDate, mailflag, discount, chargelimit, reasoncode) \n                VALUES (?,?,?,?,''," . $dbc->now() . ",?,?,?,?)");
         $insArgs = array($cardno, substr($type, 0, 1), $account['customerTypeID'], $account['memberStatus'], $account['contactAllowed'], $discount, $account['chargeLimit'], $reason);
         $insR = $dbc->execute($insQ, $insArgs);
         // log action
         $username = $this->current_user;
         $histQ = $dbc->prepare_statement("INSERT INTO suspension_history (username, postdate,\n                post, cardno, reasoncode) VALUES (?," . $dbc->now() . ",'',?,?)");
         $histR = $dbc->exec_statement($histQ, array($username, $cardno, $reason));
         $cas_model->savedType($account['memberStatus']);
         $cas_model->savedMemType($account['customerTypeID']);
         $cas_model->savedDiscount($discount);
         $cas_model->savedChargeLimit($account['chargeLimit']);
         $cas_model->savedMailFlag($account['contactAllowed']);
         $cas_model->suspensionTypeID(substr($type, 0, 1) == 'T' ? 2 : 1);
         $cas_model->tdate(date('Y-m-d H:i:s'));
         $cas_model->username($this->current_user);
         $cas_model->reasonCode($reason);
         $cas_model->active(1);
         $current_id = $cas_model->save();
     }
     /**
       Clear privileges and save the account
     */
     $account['activeStatus'] = $type;
     $account['customerTypeID'] = 0;
     $account['chargeLimit'] = 0;
     $account['contactAllowed'] = 0;
     for ($i = 0; $i < count($account['customers']); $i++) {
         $account['customers'][$i]['discount'] = 0;
     }
     \COREPOS\Fannie\API\member\MemberREST::post($cardno, $account);
     // only one CustomerAccountSuspensions record should be active
     if ($current_id != 0) {
         $cas_model->reset();
         $cas_model->card_no($cardno);
         $cas_model->active(1);
         foreach ($cas_model->find() as $obj) {
             if ($obj->customerAccountSuspensionID() != $current_id) {
                 $obj->active(0);
                 $obj->save();
             }
         }
     }
 }
Esempio n. 2
0
 function post_id_handler()
 {
     global $FANNIE_OP_DB;
     if (!FannieAuth::validateUserQuiet('editmembers') && !FannieAuth::validateUserQuiet('editmembers_csc')) {
         return $this->unknown_request_handler();
     }
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $status = FormLib::get_form_value('status', 'INACT');
     $codes = FormLib::get_form_value('reasoncodes', array());
     $code = 0;
     foreach ($codes as $selected_code) {
         $code = $code | (int) $selected_code;
     }
     $cas_model = new CustomerAccountSuspensionsModel($dbc);
     $cas_model->card_no($this->id);
     $current_id = 0;
     $account = \COREPOS\Fannie\API\member\MemberREST::get($this->id);
     if ($code == 0) {
         // reactivate account
         // add history/log record, restore settings, delete suspensions record
         $history = new SuspensionHistoryModel($dbc);
         $history->username($this->current_user);
         $history->cardno($this->id);
         $history->reasoncode(-1);
         $history->post('Account reactivated');
         $history->postdate(date('Y-m-d H:i:s'));
         $history->save();
         $cas_model->reasonCode(0);
         $cas_model->suspensionTypeID(0);
         $cas_model->active(0);
         $cas_model->username($this->current_user);
         $cas_model->tdate(date('Y-m-d H:i:s'));
         $cas_model->save();
         if (isset($this->__models['suspended'])) {
             $json = array('cardNo' => $this->id, 'activeStatus' => '', 'memberStatus' => $this->__models['suspended']->memtype2(), 'customerTypeID' => $this->__models['suspended']->memtype1(), 'chargeLimit' => $this->__models['suspended']->chargelimit(), 'contactAllowed' => $this->__models['suspended']->mailflag(), 'customers' => array());
             foreach ($account['customers'] as $c) {
                 $c['discount'] = $this->__models['suspended']->discount();
                 $c['chargeAllowed'] = 1;
                 $json['customers'][] = $c;
             }
             \COREPOS\Fannie\API\member\MemberREST::post($this->id, $json);
             $cust = new CustdataModel($dbc);
             $cust->CardNo($this->id);
             foreach ($cust->find() as $obj) {
                 $obj->pushToLanes();
             }
             $this->__models['suspended']->delete();
         }
     } elseif (isset($this->__models['suspended'])) {
         // account already suspended
         // add history/log record, update suspended record
         $m_status = 0;
         if ($status == 'TERM') {
             $this->__models['suspended']->type('T');
             $m_status = 2;
         } else {
             $this->__models['suspended']->type('I');
             $m_status = 1;
         }
         $this->__models['suspended']->reasoncode($code);
         $this->__models['suspended']->suspDate(date('Y-m-d H:i:s'));
         $this->__models['suspended']->save();
         $history = new SuspensionHistoryModel($dbc);
         $history->username($this->current_user);
         $history->cardno($this->id);
         $history->reasoncode($code);
         $history->postdate(date('Y-m-d H:i:s'));
         $history->save();
         $changed = false;
         $cas_model->active(1);
         // find most recent active record
         $current = $cas_model->find('tdate', true);
         foreach ($current as $obj) {
             if ($obj->reasonCode() != $code || $obj->suspensionTypeID() != $m_status) {
                 $changed = true;
             }
             $cas_model->savedType($obj->savedType());
             $cas_model->savedMemType($obj->savedMemType());
             $cas_model->savedDiscount($obj->savedDiscount());
             $cas_model->savedChargeLimit($obj->savedChargeLimit());
             $cas_model->savedMailFlag($obj->savedMailFlag());
             // copy "saved" values from current active
             // suspension record. should only be one
             break;
         }
         // only add a record if something changed.
         // count($current) of zero means there is no
         // record. once the migration to the new data
         // structure is complete, that check won't
         // be necessary
         if ($changed || count($current) == 0) {
             $cas_model->reasonCode($code);
             $cas_model->username($this->current_user);
             $cas_model->tdate(date('Y-m-d H:i:s'));
             $cas_model->suspensionTypeID($m_status);
             $current_id = $cas_model->save();
         }
         $json = array('cardNo' => $this->id, 'activeStatus' => $status);
         \COREPOS\Fannie\API\member\MemberREST::post($this->id, $json);
     } else {
         // suspend active account
         // create suspensions and log/history records
         // set custdata & meminfo to inactive
         $discount = 0;
         foreach ($account['customers'] as $c) {
             if ($c['accountHolder']) {
                 $discount = $c['discount'];
                 break;
             }
         }
         $susp = new SuspensionsModel($dbc);
         $susp->cardno($this->id);
         $susp->type($status == 'TERM' ? 'T' : 'I');
         $susp->memtype1($account['customerTypeID']);
         $susp->memtype2($account['memberStatus']);
         $susp->suspDate(date('Y-m-d H:i:s'));
         $susp->reason('');
         $susp->mailflag($account['contactAllowed']);
         $susp->discount($discount);
         $susp->chargelimit($account['chargeLimit']);
         $susp->reasoncode($code);
         $susp->save();
         $cas_model->savedType($account['memberStatus']);
         $cas_model->savedMemType($account['customerTypeID']);
         $cas_model->savedDiscount($discount);
         $cas_model->savedChargeLimit($account['chargeLimit']);
         $cas_model->savedMailFlag($account['contactAllowed']);
         $cas_model->suspensionTypeID($status == 'TERM' ? 2 : 1);
         $cas_model->tdate(date('Y-m-d H:i:s'));
         $cas_model->username($this->current_user);
         $cas_model->reasonCode($code);
         $cas_model->active(1);
         $current_id = $cas_model->save();
         $history = new SuspensionHistoryModel($dbc);
         $history->username($this->current_user);
         $history->cardno($this->id);
         $history->reasoncode($code);
         $history->postdate(date('Y-m-d H:i:s'));
         $history->save();
         $json = array('cardNo' => $this->id, 'chargeLimit' => 0, 'activeStatus' => $status, 'customerTypeID' => 0, 'contactAllowed' => 0, 'customers' => array());
         foreach ($account['customers'] as $c) {
             $c['discount'] = 0;
             $json['customers'][] = $c;
         }
         \COREPOS\Fannie\API\member\MemberREST::post($this->id, $json);
     }
     // only one CustomerAccountSuspensions record should be active
     if ($current_id != 0) {
         $cas_model->reset();
         $cas_model->card_no($this->id);
         $cas_model->active(1);
         foreach ($cas_model->find() as $obj) {
             if ($obj->customerAccountSuspensionID() != $current_id) {
                 $obj->active(0);
                 $obj->save();
             }
         }
     }
     header('Location: PIMemberPage.php?id=' . $this->id);
     return False;
 }
Esempio n. 3
0
function activate($memNum)
{
    global $sql;
    $model = new CustomerAccountSuspensionsModel($sql);
    $model->card_no($memNum);
    $username = checkLogin();
    $uid = getUID($username);
    $auditQ = "insert custUpdate select now(),{$uid},1,* from custdata where cardno={$memNum}";
    //$auditR = $sql->query($auditQ);
    $query = $sql->prepare("select type,memtype1,memtype2,discount,chargelimit,mailflag from suspensions where cardno=?");
    $result = $sql->execute($query, array($memNum));
    $row = $sql->fetch_array($result);
    // type S shouldn't exist any more, in here to deal with historical rows
    $mQ = $sql->prepare("update meminfo set ads_OK=? where card_no=?");
    $cQ = $sql->prepare("update custdata set memType=?, Type=?,ChargeOk=1,Discount=?,MemDiscountLimit=?,ChargeLimit=?\n        where CardNo=?");
    if ($row[0] == 'I' || $row[0] == 'T' || $row[0] == 'S') {
        $mR = $sql->execute($mQ, array($row['mailflag'], $memNum));
        $cR = $sql->execute($cQ, array($row['memtype1'], $row['memtype2'], $row['discount'], $row['chargelimit'], $row['chargelimit'], $memNum));
    } else {
        if ($row[0] == 'X') {
            $mR = $sql->execute($mQ, array($row['mailflag'], $memNum));
            $cR = $sql->execute($cQ, array($row['memtype1'], $row['memtype2'], $row['discount'], $row['chargelimit'], $row['chargelimit'], $memNum));
        }
    }
    $query = $sql->prepare("delete from suspensions where cardno=?");
    $result = $sql->execute($query, array($memNum));
    $username = validateUserQuiet('editmembers');
    $now = date("Y-m-d h:i:s");
    $query = $sql->prepare("insert into suspension_history (username, postdate, post, cardno, reasoncode)\n            values (?,?,'Account reactivated',?,-1)");
    $result = $sql->execute($query, array($username, $now, $memNum));
    // add record to denote account was activated
    // this record is not considered "active" because
    // the account is not suspended
    $model->reasonCode(0);
    $model->suspensionTypeID(0);
    $model->username($username);
    $model->tdate($now);
    $model->active(0);
    $model->save();
    $model->reset();
    $model->card_no($memNum);
    $model->active(1);
    foreach ($model->find() as $obj) {
        $obj->active(0);
        $obj->save();
    }
}