function process_file($linedata) { global $FANNIE_OP_DB, $FANNIE_TRANS_DB; $EMP_NO = $this->config->get('EMP_NO'); $LANE_NO = $this->config->get('REGISTER_NO'); $OFFSET_DEPT = $this->config->get('MISC_DEPT'); $card_no = $this->get_column_index('card_no'); $classA = $this->get_column_index('classA'); $classB = $this->get_column_index('classB'); $note = $this->get_column_index('note'); $dbc = FannieDB::get($FANNIE_OP_DB); $dtrans_table = $FANNIE_TRANS_DB . $dbc->sep() . 'dtransactions'; $prep = $dbc->prepare('SELECT MAX(trans_no) as tn FROM ' . $dtrans_table . ' WHERE emp_no=? AND register_no=?'); $result = $dbc->execute($prep, array($EMP_NO, $LANE_NO)); $trans = 1; if ($dbc->num_rows($result) > 0) { $row = $dbc->fetch_row($result); if ($row['tn'] != '') { $trans = $row['tn'] + 1; } } foreach ($linedata as $data) { if (!isset($data[$card_no])) { continue; } elseif (!is_numeric($data[$card_no])) { continue; } $cn = trim($data[$card_no]); $a_amt = trim($data[$classA], '$ '); $b_amt = trim($data[$classB], '$ '); $offset_amt = $a_amt + $b_amt; if ($offset_amt == 0) { continue; } $now = date('Y-m-d H:i:s'); $custdata = new CustdataModel($dbc); $custdata->CardNo($cn); $custdata->personNum(1); $custdata->load(); $meminfo = new MeminfoModel($dbc); $meminfo->card_no($cn); $meminfo->load(); $susp = new SuspensionsModel($dbc); $susp->cardno($cn); $susp->load(); $susp->type('T'); $susp->memtype1($custdata->memType()); $susp->memtype2($custdata->Type()); $susp->suspDate($now); $susp->discount($custdata->Discount()); $susp->chargelimit($custdata->ChargeLimit()); $susp->mailflag($meminfo->ads_OK()); $susp->reasoncode(64); $susp->save(); $suspHistory = new SuspensionHistoryModel($dbc); $suspHistory->username('abandon-import'); $suspHistory->postdate($now); $suspHistory->cardno($cn); $suspHistory->reasoncode(64); $suspHistory->save(); $meminfo->ads_OK(0); $meminfo->save(); $custdata->reset(); $custdata->CardNo($cn); foreach ($custdata->find() as $obj) { $obj->Type('TERM'); $obj->memType(0); $obj->Discount(0); $obj->ChargeLimit(0); $obj->MemDiscountLimit(0); $obj->save(); } if (isset($data[$note]) && !empty($data[$note])) { $memNote = new MemberNotesModel($dbc); $memNote->cardno($cn); $memNote->note($data[$note]); $memNote->stamp($now); $memNote->username('abandon-import'); $memNote->save(); } $trans_id = 1; if ($a_amt > 0) { $record = DTrans::$DEFAULTS; $record['register_no'] = $LANE_NO; $record['emp_no'] = $EMP_NO; $record['trans_no'] = $trans; $record['upc'] = $a_amt . 'DP992'; $record['description'] = 'Class A Equity'; $record['trans_type'] = 'D'; $record['department'] = 992; $record['unitPrice'] = -1 * $a_amt; $record['total'] = -1 * $a_amt; $record['regPrice'] = -1 * $a_amt; $record['card_no'] = $cn; $record['trans_id'] = $trans_id; $trans_id++; $info = DTrans::parameterize($record, 'datetime', $dbc->now()); $prep = $dbc->prepare("INSERT INTO {$dtrans_table} ({$info['columnString']}) VALUES ({$info['valueString']})"); $dbc->execute($prep, $info['arguments']); } if ($b_amt > 0) { $record = DTrans::$DEFAULTS; $record['register_no'] = $LANE_NO; $record['emp_no'] = $EMP_NO; $record['trans_no'] = $trans; $record['upc'] = $a_amt . 'DP991'; $record['description'] = 'Class B Equity'; $record['trans_type'] = 'D'; $record['department'] = 991; $record['unitPrice'] = -1 * $b_amt; $record['total'] = -1 * $b_amt; $record['regPrice'] = -1 * $b_amt; $record['card_no'] = $cn; $record['trans_id'] = $trans_id; $trans_id++; $info = DTrans::parameterize($record, 'datetime', $dbc->now()); $prep = $dbc->prepare("INSERT INTO {$dtrans_table} ({$info['columnString']}) VALUES ({$info['valueString']})"); $dbc->execute($prep, $info['arguments']); } $record = DTrans::$DEFAULTS; $record['register_no'] = $LANE_NO; $record['emp_no'] = $EMP_NO; $record['trans_no'] = $trans; $record['upc'] = $offset_amt . 'DP' . $OFFSET_DEPT; $record['description'] = 'Abandon Equity'; $record['trans_type'] = 'D'; $record['department'] = $OFFSET_DEPT; $record['unitPrice'] = $offset_amt; $record['total'] = $offset_amt; $record['regPrice'] = $offset_amt; $record['card_no'] = $cn; $record['trans_id'] = $trans_id; $trans_id++; $info = DTrans::parameterize($record, 'datetime', $dbc->now()); $prep = $dbc->prepare("INSERT INTO {$dtrans_table} ({$info['columnString']}) VALUES ({$info['valueString']})"); $dbc->execute($prep, $info['arguments']); $record = DTrans::$DEFAULTS; $record['register_no'] = $LANE_NO; $record['emp_no'] = $EMP_NO; $record['trans_no'] = $trans; $record['upc'] = '0'; $record['description'] = '63350'; $record['trans_type'] = 'C'; $record['trans_subtype'] = 'CM'; $record['card_no'] = $cn; $record['trans_id'] = $trans_id; $info = DTrans::parameterize($record, 'datetime', $dbc->now()); $prep = $dbc->prepare("INSERT INTO {$dtrans_table} ({$info['columnString']}) VALUES ({$info['valueString']})"); $dbc->execute($prep, $info['arguments']); $trans++; } return true; }
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; }