function saveFormData($memNum) { $json = array('cardNo' => $memNum, 'startDate' => FormLib::get('MemDates_start'), 'endDate' => FormLib::get('MemDates_end')); $resp = \COREPOS\Fannie\API\member\MemberREST::post($memNum, $json); if ($resp['errors'] > 0) { return "Error: problem saving start/end dates<br />"; } else { return ""; } }
/** Update a member account based on a JSON encoded array */ public function get_json_handler() { $json = json_decode(base64_decode($this->json), true); if (!is_array($json)) { echo 'Invalid data!'; return false; } $rest = array('cardNo' => $json['card_no'], 'addressFirstLine' => $json['addr1'], 'addressSecondLine' => $json['addr2'], 'city' => $json['city'], 'state' => $json['state'], 'zip' => $json['zip'], 'customers' => array(array('accountHolder' => 1, 'firstName' => $json['fn'], 'lastName' => $json['ln'], 'phone' => $json['ph'], 'email' => $json['email']))); \COREPOS\Fannie\API\member\MemberREST::post($json['card_no'], $rest); header('Location: PIMemberPage.php?id=' . $json['card_no']); return false; }
function saveFormData($memNum) { $limit = FormLib::get_form_value('AR_limit', 0); $json = array('cardNo' => $memNum, 'chargeLimit' => $limit, 'customers' => array()); $account = self::getAccount(); $json['customerAccountID'] = $account['customerAccountID']; foreach ($account['customers'] as $c) { if ($c['accountHolder']) { $json['customers'][] = array('customerID' => $c['customerID'], 'customerAccountID' => $account['customerAccountID'], 'chargeAllowed' => $limit == 0 ? 0 : 1, 'accountHolder' => 1, 'cardNo' => $memNum); } elseif ($c['customerID']) { // unnecessary to specify all customers in old schema // new schema will only update correctly if IDs exist $json['customers'][] = array('customerID' => $c['customerID'], 'cardNo' => $memNum, 'chargeAllowed' => $limit == 0 ? 0 : 1, 'accountHolder' => 0); } } $resp = \COREPOS\Fannie\API\member\MemberREST::post($memNum, $json); if ($resp['errors'] > 0) { return 'Error: Problem saving A/R limit<br />'; } else { return ''; } }
function process_file($linedata) { $mn_index = $this->get_column_index('memnum'); $st_index = $this->get_column_index('street'); $st2_index = $this->get_column_index('street2'); $city_index = $this->get_column_index('city'); $state_index = $this->get_column_index('state'); $zip_index = $this->get_column_index('zip'); $ph_index = $this->get_column_index('ph1'); $ph2_index = $this->get_column_index('ph2'); $email_index = $this->get_column_index('email'); foreach ($linedata as $line) { // get info from file and member-type default settings // if applicable $cardno = $line[$mn_index]; if (!is_numeric($cardno)) { continue; } // skip bad record $street = $st_index !== False ? $line[$st_index] : ""; $street2 = $st2_index !== False ? $line[$st2_index] : ""; $city = $city_index !== False ? $line[$city_index] : ""; $state = $state_index !== False ? $line[$state_index] : ""; $zip = $zip_index !== False ? $line[$zip_index] : ""; $ph1 = $ph_index !== False ? $line[$ph_index] : ""; $ph2 = $ph2_index !== False ? $line[$ph2_index] : ""; $email = $email_index !== False ? $line[$email_index] : ""; $json = array('cardNo' => $cardno, 'addressFirstLine' => $street, 'addressSecondLine' => $street2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'customers' => array(array('phone' => $ph1, 'altPhone' => $ph2, 'email' => $email, 'accountHolder' => 1))); $resp = \COREPOS\Fannie\API\member\MemberREST::post($cardno, $json); if ($resp['errors'] > 0) { $this->stats['errors'][] = "Error importing member {$cardno}"; } else { $this->stats['imported']++; } } return true; }
function saveFormData($memNum) { /** Use primary member for default column values */ $account = self::getAccount(); if (!$account) { return "Error: Problem saving household members<br />"; } $json = array('cardNo' => $memNum, 'customerTypeID' => $account['customerTypeID'], 'memberStatus' => $account['memberStatus'], 'activeStatus' => $account['activeStatus'], 'customers' => array()); $primary = array('discount' => 0, 'staff' => 0, 'lowIncomeBenefits' => 0, 'chargeAllowed' => 0, 'checksAllowed' => 0); foreach ($account['customers'] as $c) { if ($c['accountHolder']) { $primary = $c; break; } } $fns = FormLib::get('HouseholdSeparateDiscounts_fn', array()); $lns = FormLib::get('HouseholdSeparateDiscounts_ln', array()); $discs = FormLib::get('HouseholdSeparateDiscounts_discount', array()); $checks = FormLib::get('HouseholdSeparateDiscounts_writeChecks', array()); $ssi = FormLib::get('HouseholdSeparateDiscounts_SSI', array()); $ids = FormLib::get('HouseholdMembers_ID', array()); $pn = 2; for ($i = 0; $i < count($lns); $i++) { $json['customers'][] = array('customerID' => $ids[$i], 'firstName' => $fns[$i], 'lastName' => $lns[$i], 'accountHolder' => 0, 'discount' => $discs[$i], 'staff' => $primary['staff'], 'lowIncomeBenefits' => in_array($pn, $ssi) ? 1 : 0, 'chargeAllowed' => $primary['chargeAllowed'], 'checksAllowed' => in_array($pn, $checks) ? 1 : 0); $pn++; } $resp = \COREPOS\Fannie\API\member\MemberREST::post($memNum, $json); if ($resp['errors'] > 0) { return "Error: Problem saving household members<br />"; } return ''; }
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(); } } }
function saveFormData($memNum) { $json = array('addressFirstLine' => FormLib::get_form_value('ContactInfo_addr1', ''), 'addressSecondLine' => FormLib::get_form_value('ContactInfo_addr2', ''), 'city' => FormLib::get_form_value('ContactInfo_city', ''), 'state' => FormLib::get_form_value('ContactInfo_state', ''), 'zip' => FormLib::get_form_value('ContactInfo_zip', ''), 'contactAllowed' => FormLib::get_form_value('ContactInfo_mail') !== '' ? 1 : 0, 'customers' => array()); $account = self::getAccount(); foreach ($account['customers'] as $c) { if ($c['accountHolder']) { $json['customers'][] = array('customerID' => $c['customerID'], 'accountHolder' => 1, 'lastName' => FormLib::get('ContactInfo_ln', ''), 'firstName' => FormLib::get('ContactInfo_fn', ''), 'phone' => FormLib::get_form_value('ContactInfo_ph1', ''), 'altPhone' => FormLib::get_form_value('ContactInfo_ph2', ''), 'email' => FormLib::get_form_value('ContactInfo_email', '')); } } /* Canadian Postal Code, and City and Province * Phone style: ###-###-#### */ if (preg_match("/^[A-Z]\\d[A-Z]/i", $json['zip'])) { $json['zip'] = strtoupper($json['zip']); if (strlen($json['zip']) == 6) { $json['zip'] = substr($json['zip'], 0, 3) . ' ' . substr($json['zip'], 3, 3); } // Postal code M* supply City and Province if (preg_match("/^M/", $json['zip']) && $json['city'] == '' && $json['state'] == '') { $json['city'] = 'Toronto'; $json['state'] = 'ON'; } // Phone# style: ###-###-#### if (preg_match("/^[MKLP]/", $json['zip'])) { if (preg_match("/^[-() .0-9]+\$/", $json['customers'][0]['phone'])) { $phone = preg_replace("/[^0-9]/", '', $json['customers'][0]['phone']); if (preg_match("/^\\d{10}\$/", $phone)) { $json['customers'][0]['phone'] = preg_replace("/(\\d{3})(\\d{3})(\\d{4})/", '${1}-${2}-${3}', $phone); } } if (preg_match("/^[-() .0-9]+\$/", $json['customers'][0]['altPhone'])) { $phone = preg_replace("/[^0-9]/", '', $json['customers'][0]['altPhone']); if (preg_match("/^\\d{10}\$/", $phone)) { $json['customers'][0]['altPhone'] = preg_replace("/(\\d{3})(\\d{3})(\\d{4})/", '${1}-${2}-${3}', $phone); } } } } $resp = \COREPOS\Fannie\API\member\MemberREST::post($memNum, $json); if ($resp['errors'] > 0) { return "Error: problem saving Contact Information<br />"; } else { return ''; } }
function process_file($linedata) { global $FANNIE_OP_DB, $FANNIE_NAMES_PER_MEM; $dbc = FannieDB::get($FANNIE_OP_DB); $mn_index = $this->get_column_index('memnum'); $fn_index = $this->get_column_index('fn'); $ln_index = $this->get_column_index('ln'); $t_index = $this->get_column_index('memtype'); $defaults_table = array(); // get defaults directly from the memtype table if possible $mt = $dbc->tableDefinition('memtype'); $defQ = $dbc->prepare_statement("SELECT memtype,custdataType,discount,staff,ssi from memtype"); if ($dbc->tableExists('memdefaults') && (!isset($mt['custdataType']) || !isset($mt['discount']) || !isset($mt['staff']) || !isset($mt['ssi']))) { $defQ = $dbc->prepare_statement("SELECT memtype,cd_type as custdataType,discount,staff,SSI as ssi from memdefaults"); } $defR = $dbc->exec_statement($defQ); while ($defW = $dbc->fetch_row($defR)) { $defaults_table[$defW['memtype']] = array('type' => $defW['custdataType'], 'discount' => $defW['discount'], 'staff' => $defW['staff'], 'SSI' => $defW['ssi']); } foreach ($linedata as $line) { // get info from file and member-type default settings // if applicable $cardno = $line[$mn_index]; if (!is_numeric($cardno)) { continue; // skip bad record } $json = array('cardNo' => $cardno, 'customerTypeID' => $t_index !== false ? $line[$t_index] : 0, 'contactAllowed' => 1, 'chargeBalance' => 0, 'chargeLimit' => 0, 'customers' => array()); $customer = array(); $customer['firstName'] = $line[$fn_index]; $customer['lastName'] = $line[$ln_index]; $type = "PC"; $discount = 0; $staff = 0; $SSI = 0; if ($t_index !== false) { if (isset($defaults_table[$mtype]['type'])) { $type = $defaults_table[$mtype]['type']; } if (isset($defaults_table[$mtype]['discount'])) { $discount = $defaults_table[$mtype]['discount']; } if (isset($defaults_table[$mtype]['staff'])) { $staff = $defaults_table[$mtype]['staff']; } if (isset($defaults_table[$mtype]['SSI'])) { $SSI = $defaults_table[$mtype]['SSI']; } } $json['memberStatus'] = $type; $customer['discount'] = $discount; $customer['staff'] = $staff; $customer['lowIncomeBenefits'] = $SSI; // determine person number if ($FANNIE_NAMES_PER_MEM == 1) { $customer['accountHolder'] = 1; } else { $account = \COREPOS\Fannie\API\member\MemberREST::get($cardno); if ($account) { $customer['accountHolder'] = 0; } else { $customer['accountHolder'] = 1; } } $json['customers'][] = $customer; $resp = \COREPOS\Fannie\API\member\MemberREST::post($cardno, $json); if ($resp['errors'] > 0) { $this->stats['errors'][] = "Error importing member {$cardno} ({$line[$fn_index]} {$line[$ln_index]})"; } else { $this->stats['imported']++; } } return true; }
protected function post_id_handler() { global $FANNIE_OP_DB, $FANNIE_TRANS_DB; $this->card_no = $this->id; if ($this->auth_mode == 'None') { return $this->unknownRequestHandler(); } $dbc = FannieDB::get($FANNIE_OP_DB); $note = FormLib::get_form_value('notetext'); $hash = FormLib::get_form_value('_notetext'); if (base64_decode($hash) != $note) { $noteP = $dbc->prepare_statement('INSERT INTO memberNotes (cardno, note, stamp, username) VALUES (?, ?, ' . $dbc->now() . ', ?)'); $noteR = $dbc->exec_statement($noteP, array($this->card_no, str_replace("\n", '<br />', $note), $this->current_user)); } $json = array('cardNo' => $this->id, 'customers' => array()); $account_holder = array('accountHolder' => 1); $account_holder['firstName'] = FormLib::get('FirstName'); $account_holder['lastName'] = FormLib::get('LastName'); $account_holder['customerID'] = FormLib::get('customerID'); $json['addressFirstLine'] = FormLib::get('address1'); $json['addressSecondLine'] = FormLib::get('address2'); $json['city'] = FormLib::get('city'); $json['state'] = FormLib::get('state'); $json['zip'] = FormLib::get('zip'); $account_holder['phone'] = FormLib::get('phone'); $account_holder['altPhone'] = FormLib::get('phone2'); $account_holder['email'] = FormLib::get('email'); $json['contactAllowed'] = FormLib::get('mailflag', 0); $upc = FormLib::get_form_value('upc', false); if ($upc !== false) { if ($upc != '') { $json['idCardUPC'] = BarcodeLib::padUPC($upc); } else { $json['idCardUPC'] = ''; } } if ($this->auth_mode == 'Full') { $json['customerTypeID'] = FormLib::get('memType'); $json['chargeLimit'] = FormLib::get('chargelimit'); $default = new MemtypeModel($dbc); $default->memtype($json['customerTypeID']); $default->load(); $account_holder['discount'] = $default->discount(); $account_holder['staff'] = $default->staff(); $account_holder['chargeAllowed'] = $json['chargeLimit'] == 0 ? 0 : 1; $account_holder['lowIncomeBenefits'] = $default->ssi(); $start = FormLib::get('start_date', ''); /** Interface hides 1900-01-01 dates from the end-user but that's not identical to 0000-00-00. A blank submission should preserve that 1900-01-01 date. */ if ($start == '' && FormLib::get('nonBlankStart') != '') { $start = FormLib::get('nonBlankStart'); } $json['startDate'] = $start; $json['endDate'] = FormLib::get('end_date'); } else { // get account defaults for additional names if needed $account = \COREPOS\Fannie\API\member\MemberREST::get($this->card_no); foreach ($account['customers'] as $c) { if ($c['accountHolder']) { $account_holder['discount'] = $c['discount']; $account_holder['staff'] = $c['staff']; $account_holder['lowIncomeBenefits'] = $c['lowIncomeBenefits']; $account_holder['chargeAllowed'] = $c['chargeAllowed']; } } } $json['customers'][] = $account_holder; $names = array('first' => FormLib::get_form_value('fn'), 'last' => FormLib::get_form_value('ln')); $fn = FormLib::get_form_value('fn'); $ln = FormLib::get_form_value('ln'); $hhID = FormLib::get('hhID'); for ($i = 0; $i < count($fn); $i++) { $set = array('first' => isset($fn[$i]) ? $fn[$i] : '', 'last' => isset($ln[$i]) ? $ln[$i] : '', 'id' => isset($hhID[$i]) ? $hhID[$i] : ''); $json['customers'][] = array('customerID' => $hhID[$i], 'accountHolder' => 0, 'firstName' => $set['first'], 'lastName' => $set['last'], 'discount' => $account_holder['discount'], 'staff' => $account_holder['staff'], 'lowIncomeBenefits' => $account_holder['lowIncomeBenefits'], 'chargeAllowed' => $account_holder['chargeAllowed']); } $resp = \COREPOS\Fannie\API\member\MemberREST::post($this->card_no, $json); $custdata = new CustdataModel($dbc); $custdata->CardNo($this->card_no); foreach ($custdata->find() as $c) { $c->pushToLanes(); } $cards = new MemberCardsModel($dbc); $cards->card_no($this->card_no); $cards->load(); $cards->pushToLanes(); header('Location: PIMemberPage.php?id=' . $this->card_no); return false; }
public function testREST() { $account = \COREPOS\Fannie\API\member\MemberREST::get(-999); $this->assertEquals($account, false); /** get account and verify structure **/ $TEST_ACCOUNT = 1; $account = \COREPOS\Fannie\API\member\MemberREST::get($TEST_ACCOUNT); $this->assertInternalType('array', $account); $all_fields = array('cardNo', 'memberStatus', 'activeStatus', 'customerTypeID', 'customerType', 'chargeBalance', 'chargeLimit', 'idCardUPC', 'startDate', 'endDate', 'addressFirstLine', 'addressSecondLine', 'city', 'state', 'zip', 'contactAllowed', 'contactMethod', 'modified', 'customers'); foreach ($all_fields as $field) { $this->assertArrayHaskey($field, $account, 'Account missing field: ' . $field); } $this->assertInternalType('array', $account['customers']); $customer_fields = array('customerID', 'firstName', 'lastName', 'chargeAllowed', 'checksAllowed', 'discount', 'accountHolder', 'staff', 'phone', 'altPhone', 'email', 'memberPricingAllowed', 'memberCouponsAllowed', 'lowIncomeBenefits', 'modified'); foreach ($account['customers'] as $customer) { foreach ($customer_fields as $field) { $this->assertArrayHasKey($field, $customer); } } $all = \COREPOS\Fannie\API\member\MemberREST::get(); foreach ($all as $a) { $this->assertArrayHasKey('cardNo', $a); if ($a['cardNo'] == $TEST_ACCOUNT) { $this->assertEquals($a, $account, 'get single and get all must match'); break; } } $account_changed = $account; $account_changed['idCardUPC'] = '12345'; $account_changed['startDate'] = date('Y-m-d 00:00:00'); $account_changed['endDate'] = date('Y-m-d 00:00:00', strtotime('+1 year')); $account_changed['addressFirstLine'] = '123 4th St'; $account_changed['addressSecondLine'] = 'Apt. 5'; $account_changed['city'] = 'somewhere'; $account_changed['state'] = 'NY'; $account_changed['zip'] = '12345'; $account_changed['customers'][0]['firstName'] = 'Test'; $account_changed['customers'][0]['lastName'] = 'User'; /** POST the original account and verify the result, then POST a modified account and verify, then restore original and verify */ $post_accounts = array($account, $account_changed, $account); foreach ($post_accounts as $a) { /** post account structure back and verify it did not change **/ $resp = \COREPOS\Fannie\API\member\MemberREST::post($TEST_ACCOUNT, $a); $this->assertInternalType('array', $resp); $this->assertArrayHasKey('errors', $resp); $this->assertEquals(0, $resp['errors']); $this->assertArrayHasKey('account', $resp); foreach ($all_fields as $field) { if ($field == 'modified' || $field == 'customers') { /** modified timestamp expected to change. Customers will be checked field by field */ continue; } $this->assertArrayHasKey($field, $resp['account']); $this->assertEquals($a[$field], $resp['account'][$field], "Mismatch for field: {$field}"); } for ($i = 0; $i < count($resp['account']['customers']); $i++) { $this->assertArrayHasKey($i, $a['customers']); foreach ($customer_fields as $field) { if ($field == 'modified') { $this->assertNotEquals($resp['account']['customers'][$i][$field], $a['customers'][$i][$field]); } else { $this->assertEquals($resp['account']['customers'][$i][$field], $a['customers'][$i][$field], "Mismatch for field: {$field}"); } } } } }
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; }
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(); } } } }
function saveFormData($memNum) { $dbc = $this->db(); $mtype = FormLib::get_form_value('MemType_type', 0); $inactive = FormLib::get('MemType_inactive'); // cannot alter type of inactive members. Must // re-activate first if ($inactive != '') { return ''; } // Default values for custdata fields that depend on Member Type. $json = array('cardNo' => $memNum, 'memberStatus' => 'REG', 'customerTypeID' => $mtype, 'customers' => array(array('accountHolder' => 1, 'staff' => 0, 'discount' => 0, 'lowIncomeBenefits' => 0))); $account = self::getAccount(); foreach ($account['customers'] as $c) { if ($c['accountHolder']) { $json['customers'][0]['customerID'] = $c['customerID']; } } $account['customerTypeID'] = $mtype; $account['memberStatus'] = 'REG'; // Get any special values for this Member Type. $mt = $dbc->tableDefinition('memtype'); $q = $dbc->prepare_statement("SELECT custdataType,discount,staff,ssi from memtype WHERE memtype=?"); if ($dbc->tableExists('memdefaults') && (!isset($mt['custdataType']) || !isset($mt['discount']) || !isset($mt['staff']) || !isset($mt['ssi']))) { $q = $dbc->prepare_statement("SELECT cd_type as custdataType,discount,staff,SSI as ssi\n FROM memdefaults WHERE memtype=?"); } $r = $dbc->exec_statement($q, array($mtype)); if ($dbc->num_rows($r) > 0) { $w = $dbc->fetch_row($r); $json['memberStatus'] = $w['custdataType']; $account['memberStatus'] = $w['custdataType']; $json['customers'][0]['discount'] = $w['discount']; $json['customers'][0]['staff'] = $w['staff']; $json['customers'][0]['lowIncomeBenefits'] = $w['ssi']; } $resp = \COREPOS\Fannie\API\member\MemberREST::post($memNum, $json); if ($resp['errors'] > 0) { return "Error: problem saving Member Type<br />"; } else { // update current account object so subsequent save // operations don't overwrite changes self::setAccount($account); return ""; } }