Exemplo 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();
             }
         }
     }
 }
Exemplo 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;
 }
Exemplo n.º 3
0
function deactivate($memNum, $type, $reason, $reasonCode)
{
    global $sql;
    $username = checkLogin();
    $uid = getUID($username);
    $auditQ = "insert custUpdate select now(),{$uid},1,* from custdata where cardno={$memNum}";
    //$auditR = $sql->query($auditQ);
    $model = new CustomerAccountSuspensionsModel($sql);
    $model->card_no($memNum);
    if ($type == 'TERM') {
        $query = $sql->prepare("select memType,Type,ChargeLimit,Discount from custdata where CardNo=?");
        $result = $sql->execute($query, array($memNum));
        $row = $sql->fetch_array($result);
        $otherQ = $sql->prepare("select ads_OK from meminfo where card_no=?");
        $otherR = $sql->execute($otherQ, array($memNum));
        $otherW = $sql->fetch_array($otherR);
        $mailflag = $otherW['ads_OK'];
        $now = date('Y-m-d h:i:s');
        $query = $sql->prepare("insert into suspensions (cardno, type, memtype1, memtype2, reason, suspDate, mailflag,\n                discount, chargelimit, reasoncode) values (?,'T',?,?,?,?,?,?,?,?)");
        //echo $query."<br />";
        $result = $sql->execute($query, array($memNum, $row['memType'], $row['Type'], $reason, $now, $mailflag, $row['Discount'], $row['ChargeLimit'], $reasonCode));
        $model->savedType($row['Type']);
        $model->savedMemType($row['memType']);
        $model->savedDiscount($row['Discount']);
        $model->savedChargeLimit($row['ChargeLimit']);
        $model->savedMailFlag($mailflag);
        $model->reasonCode($reason);
        $model->tdate($now);
        $model->suspensionTypeID(2);
        $username = validateUserQuiet('editmembers');
        $model->username($username);
        $query = $sql->prepare("insert into suspension_history (username, postdate, post, cardno, reasoncode) \n                values (?, ?, ?, ?, ?)");
        $result = $sql->execute($query, array($username, $now, $reason, $memNum, $reasonCode));
        $mQ = $sql->prepare("update meminfo set ads_OK=0 where card_no = ?");
        $cQ = $sql->prepare("update custdata set memType=0, Type='TERM',ChargeOk=0,Discount=0,MemDiscountLimit=0,ChargeLimit=0 \n            where CardNo=?");
        $mR = $sql->execute($mQ, array($memNum));
        $cR = $sql->execute($cQ, array($memNum));
    } elseif ($type == 'INACT' || $type == 'INACT2') {
        $query = $sql->prepare("select memType,Type,ChargeLimit,Discount from custdata where CardNo=?");
        $result = $sql->execute($query, array($memNum));
        $row = $sql->fetch_array($result);
        $otherQ = $sql->prepare("select ads_OK from meminfo where card_no=?");
        $otherR = $sql->execute($otherQ, array($memNum));
        $otherW = $sql->fetch_array($otherR);
        $mailflag = $otherW['ads_OK'];
        $now = date('Y-m-d h:i:s');
        $query = $sql->prepare("insert into suspensions (cardno, type, memtype1, memtype2, reason, suspDate, mailflag,\n                discount, chargelimit, reasoncode) values (?,'I',?,?,?,?,?,?,?,?)");
        //echo $query."<br />";
        $result = $sql->execute($query, array($memNum, $row['memType'], $row['Type'], $reason, $now, $mailflag, $row['Discount'], $row['ChargeLimit'], $reasonCode));
        $model->savedType($row['Type']);
        $model->savedMemType($row['memType']);
        $model->savedDiscount($row['Discount']);
        $model->savedChargeLimit($row['ChargeLimit']);
        $model->savedMailFlag($mailflag);
        $model->reasonCode($reason);
        $model->tdate($now);
        $model->suspensionTypeID(1);
        $username = validateUserQuiet('editmembers');
        $model->username($username);
        $query = $sql->prepare("insert into suspension_history (username, postdate, post, cardno, reasoncode) \n                values (?, ?, ?, ?, ?)");
        $result = $sql->execute($query, array($username, $now, $reason, $memNum, $reasonCode));
        $mQ = $sql->prepare("update meminfo set ads_OK=0 where card_no = ?");
        $cQ = $sql->prepare("update custdata set memType=0, Type=?,ChargeOk=0,Discount=0,MemDiscountLimit=0,ChargeLimit=0 \n            where CardNo=?");
        $mR = $sql->execute($mQ, array($memNum));
        $cR = $sql->execute($cQ, array($type, $memNum));
    }
    $model->active(1);
    $new_id = $model->save();
    // only most recent should be active
    $model->reset();
    $model->card_no($memNum);
    $model->active(1);
    foreach ($model->find() as $obj) {
        if ($obj->customerAccountSuspensionID() != $new_id) {
            $obj->active(0);
            $obj->save();
        }
    }
}