Esempio n. 1
0
 public function get_add_payid_handler()
 {
     global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB, $FANNIE_TRANS_DB, $FANNIE_ROOT;
     $ret = array();
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $model = new CustdataModel($dbc);
     $model->CardNo($this->add);
     if (count($model->find()) == 0) {
         $ret['error'] = 'Mem# ' . $this->add . ' does not exist!';
     } else {
         $model->personNum(1);
         $model->load();
         $ret['name'] = $model->LastName() . ', ' . $model->FirstName();
         $dbc = FannieDB::get($FANNIE_TRANS_DB);
         $model = new ArLiveBalanceModel($dbc);
         $model->card_no($this->add);
         $balance = 0;
         if ($model->load()) {
             $balance = $model->balance();
         }
         $ret['balance'] = $balance;
         $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['StaffArPayrollDB']);
         $model = new StaffArAccountsModel($dbc);
         $model->card_no($this->add);
         $model->nextPayment(0);
         $model->payrollIdentifier($this->payid);
         $model->save();
     }
     echo json_encode($ret);
     return false;
 }
Esempio n. 2
0
function updateCustomerAllLanes($cardno)
{
    global $sql;
    deleteCustomerAllLanes($cardno);
    $model = new CustdataModel($sql);
    $model->CardNo($cardno);
    foreach ($model->find('personNum') as $obj) {
        $obj->pushToLanes();
    }
    redoCard($cardno);
}
Esempio n. 3
0
 public static function getCustdata($card_no)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $model = new CustdataModel($dbc);
     $model->CardNo($card_no);
     $model->personNum(1);
     if ($model->load()) {
         return $model;
     } else {
         return false;
     }
 }
Esempio n. 4
0
 public function preprocess()
 {
     global $FANNIE_OP_DB, $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS;
     if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) {
         $this->errors[] = "The Coop Cred plugin is not enabled.";
         return False;
     }
     if (array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) && $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] != "") {
         $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     } else {
         $this->errors[] = "The Coop Cred database is not assigned in the " . "Coop Cred plugin configuration.";
         return False;
     }
     $this->cardNo = (int) FormLib::get('memNum', 0);
     $this->programID = (int) FormLib::get('programID', 0);
     $ccpModel = new CCredProgramsModel($dbc);
     $ccpModel->programID($this->programID);
     $prog = array_pop($ccpModel->find());
     if ($prog != null) {
         $this->programName = $prog->programName();
         $this->programBankID = $prog->bankID();
     } else {
         $this->errors[] = "Error: Program ID {$this->programID} is not known.";
         return False;
     }
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $cdModel = new CustdataModel($dbc);
     $cdModel->CardNo($this->cardNo);
     $cdModel->personNum(1);
     $mem = array_pop($cdModel->find());
     if ($mem != null) {
         $this->memberFullName = $mem->FirstName() . " " . $mem->LastName();
     } else {
         $noop = 1;
         $this->errors[] = "Error: Member {$this->cardNo} is not known.";
         return False;
     }
     /* 25Mar2015 Under bootstrap the non-sortable format doesn't really work.
      */
     $this->sortable = True;
     return parent::preprocess();
 }
Esempio n. 5
0
 function get_id_first_last_handler()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     if (empty($this->id) && empty($this->last)) {
         return True;
     }
     // invalid search
     if (!empty($this->id)) {
         $custdata = new CustdataModel($dbc);
         $custdata->CardNo($this->id);
         $custdata->Type('PC');
         if (count($custdata->find()) > 0) {
             header('Location: GumMainPage.php?id=' . $this->id);
             return False;
         }
         $cards = new MemberCardsModel($dbc);
         $cards->upc(str_pad($this->id, 13, '0', STR_PAD_LEFT));
         foreach ($cards->find() as $obj) {
             header('Location: GumMainPage.php?id=' . $obj->card_no());
             return False;
         }
     } else {
         $q = $dbc->prepare_statement('SELECT CardNo, LastName, FirstName FROM
             custdata WHERE LastName LIKE ? AND FirstName LIKE ?
             AND Type = \'PC\'
             ORDER BY LastName,FirstName,CardNo');
         $r = $dbc->exec_statement($q, array($this->last . '%', $this->first . '%'));
         $this->__models['custdata'] = array();
         while ($w = $dbc->fetch_row($r)) {
             $this->__models['custdata'][] = $w;
         }
         if (count($this->__models['custdata']) == 1) {
             header('Location: GumMainPage.php?id=' . $this->__models['custdata'][0]['CardNo']);
             return False;
         }
     }
     return true;
 }
Esempio n. 6
0
 function results_content()
 {
     global $FANNIE_OP_DB, $FANNIE_SERVER_DBMS;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $mtype = FormLib::get_form_value('memtype', 0);
     $num = FormLib::get_form_value('num', 0);
     $name = FormLib::get_form_value('name', 'NEW MEMBER');
     $manual_start = FormLib::get_form_value('start', false);
     if (!is_numeric($manual_start)) {
         $manual_start = false;
     }
     $mt = $dbc->tableDefinition('memtype');
     $defaultsQ = $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']))) {
         $defaultsQ = $dbc->prepare_statement("SELECT cd_type as custdataType,discount,staff,SSI as ssi\n                    FROM memdefaults WHERE memtype=?");
     }
     $defaultsR = $dbc->exec_statement($defaultsQ, array($mtype));
     $defaults = $dbc->fetch_row($defaultsR);
     /**
       1Jul2015
       Use FannieREST API calls to create new members
       Not tested yet.
     $json = array(
         'customerTypeID' => $mtype,
         'memberStatus' => $mt['custdataType'],
         'addressFirstLine' => '',
         'addressSecondLine' => '',
         'city' => '',
         'state' => '',
         'zip' => '',
         'contactAllowed' => 1,
         'contactMethod' => 'mail',
         'customers' => array(
             array(
                 'firstName' => '',
                 'lastName' => $name,
                 'phone' => '',
                 'altPhone' => '',
                 'email' => 1,
                 'discount' => $mt['discount'],
                 'staff' => $mt['staff'],
                 'lowIncomeBenefits' => $mt['ssi'],
             ),
         ),
     );
     
     $start = PHP_INT_MAX;
     $end = 0;
     for ($i=0; $i<$num; $i++) {
         if ($manual_start) {
             $resp = \COREPOS\Fannie\API\member\MemberREST::post($manual_start+$i, $json);
         } else {
             $resp = \COREPOS\Fannie\API\member\MemberREST::post(0, $json);
         }
     
         if (isset($resp['account']) && $resp['account']['cardNo'] > $end) {
             $end = $resp['account']['cardNo'];
         }
         if (isset($resp['account']) && $resp['account']['cardNo'] < $start) {
             $start = $resp['account']['cardNo'];
         }
     }
     */
     /* going to create memberships
        part of the insert arrays can
        be prepopulated */
     $meminfo = array('last_name' => "''", 'first_name' => "''", 'othlast_name' => "''", 'othfirst_name' => "''", 'street' => "''", 'city' => "''", 'state' => "''", 'zip' => "''", 'phone' => "''", 'email_1' => "''", 'email_2' => "''", 'ads_OK' => 1);
     /* everything's set but the actual member #s */
     $numQ = $dbc->prepare_statement("SELECT MAX(CardNo) FROM custdata");
     if ($FANNIE_SERVER_DBMS == 'MSSQL') {
         $numQ = $dbc->prepare_statement("SELECT MAX(CAST(CardNo AS int)) FROM custdata");
     }
     $numR = $dbc->exec_statement($numQ);
     $start = 1;
     if ($dbc->num_rows($numR) > 0) {
         $numW = $dbc->fetch_row($numR);
         if (!empty($numW[0])) {
             $start = $numW[0] + 1;
         }
     }
     if ($manual_start) {
         $start = (int) $manual_start;
     }
     $end = $start + $num - 1;
     $ret = "<b>Starting number</b>: {$start}<br />";
     $ret .= "<b>Ending number</b>: {$end}<br />";
     $model = new CustdataModel($dbc);
     $model->personNum(1);
     $model->LastName($name);
     $model->FirstName('');
     $model->CashBack(999.99);
     $model->Balance(0);
     $model->memCoupons(0);
     $model->Discount($defaults['discount']);
     $model->Type($defaults['custdataType']);
     $model->staff($defaults['staff']);
     $model->SSI($defaults['ssi']);
     $model->memType($mtype);
     $meminfo = new MeminfoModel($dbc);
     $chkP = $dbc->prepare_statement('SELECT CardNo FROM custdata WHERE CardNo=?');
     $mdP = $dbc->prepare_statement("INSERT INTO memDates VALUES (?,NULL,NULL)");
     $mcP = $dbc->prepare_statement("INSERT INTO memContact (card_no,pref) VALUES (?,1)");
     for ($i = $start; $i <= $end; $i++) {
         // skip if record already exists
         $chkR = $dbc->exec_statement($chkP, array($i));
         if ($dbc->num_rows($chkR) > 0) {
             continue;
         }
         $model->CardNo($i);
         $model->blueLine($i . ' ' . $name);
         $model->save();
         $meminfo->card_no($i);
         $meminfo->save();
         $dbc->exec_statement($mdP, array($i));
         $dbc->exec_statement($mcP, array($i));
     }
     return $ret;
 }
Esempio n. 7
0
/* audit logging */
$uid = getUID($username);
$auditQ = "insert custUpdate select " . $sql->now() . ",{$uid},1,\n    CardNo,personNum,LastName,FirstName,\n    CashBack,Balance,Discount,ChargeLimit,ChargeOK,\n    WriteChecks,StoreCoupons,Type,memType,staff,SSI,Purchases,\n    NumberOfChecks,memCoupons,blueLine,Shown,id from custdata where cardno={$memID}";
//$auditR = $sql->query($auditQ);
$MI_FIELDS = array();
$memNum = $_POST['memNum'];
$MI_FIELDS['street'] = $_POST['address1'] . (!empty($_POST['address2']) ? "\n" . $_POST['address2'] : '');
$MI_FIELDS['city'] = $_POST['city'];
$MI_FIELDS['state'] = $_POST['state'];
$MI_FIELDS['zip'] = $_POST['zip'];
$MI_FIELDS['phone'] = $_POST['phone'];
$MI_FIELDS['email_2'] = $_POST['phone2'];
$MI_FIELDS['email_1'] = $_POST['email'];
$MI_FIELDS['ads_OK'] = $_POST['mailflag'];
$cust = new CustdataModel($dbc);
$cust->CardNo($memNum);
$cust->personNum(1);
$cust->load();
// get all current values
$cust->MemDiscountLimit($_POST['chargeLimit']);
$cust->ChargeLimit($_POST['chargeLimit']);
$cust->ChargeOk($_POST['chargeLimit'] == 0 ? 0 : 1);
$cust->memType($_POST['discList']);
$cust->Type('REG');
$cust->Staff(0);
$cust->Discount(0);
$cards = new MemberCardsModel($dbc);
$cards->card_no($memNum);
$cards->upc($_REQUEST['cardUPC']);
$cards->save();
$mcP = $sql->prepare("UPDATE memContact SET pref=? WHERE card_no=?");
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
 /**
   Assign blueLine values to account based on template configuration
   @param $id [int] account identifier
 */
 public static function setBlueLines($id)
 {
     $config = \FannieConfig::factory();
     $template = $config->get('BLUELINE_TEMPLATE');
     if ($template == '') {
         $template = '{{ACCOUNTNO}} {{FIRSTINITIAL}}. {{LASTNAME}}';
     }
     $dbc = \FannieDB::get($config->get('OP_DB'));
     $custdata = new \CustdataModel($dbc);
     $custdata->CardNo($id);
     $account = self::get($id);
     $personNum = 2;
     foreach ($account['customers'] as $c) {
         if (!isset($c['accountHolder'])) {
             continue;
         }
         if ($c['accountHolder']) {
             $custdata->personNum(1);
         } else {
             $custdata->personNum($personNum);
             $personNum++;
         }
         $blueline = $template;
         $blueline = str_replace('{{ACCOUNTNO}}', $id, $blueline);
         $blueline = str_replace('{{ACCOUNTTYPE}}', $account['customerType'], $blueline);
         $blueline = str_replace('{{FIRSTNAME}}', $c['firstName'], $blueline);
         $blueline = str_replace('{{LASTNAME}}', $c['lastName'], $blueline);
         $blueline = str_replace('{{FIRSTINITIAL}}', substr($c['firstName'], 0, 1), $blueline);
         $blueline = str_replace('{{LASTINITIAL}}', substr($c['lastName'], 0, 1), $blueline);
         $custdata->blueLine($blueline);
         $custdata->save();
     }
 }
Esempio n. 10
0
 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;
 }
Esempio n. 11
0
 /**
   Update various legacy tables to match an
   existing CustomerAccounts record. 
   @param $card_no [int] member number
   @return [boolean] success
 */
 public function legacySync($card_no)
 {
     $dbc = $this->connection;
     $custdata = new CustdataModel($dbc);
     $custdata->CardNo($card_no);
     $meminfo = new MeminfoModel($dbc);
     $meminfo->card_no($card_no);
     $memDates = new MemDatesModel($dbc);
     $memDates->card_no($card_no);
     $cards = new MemberCardsModel($dbc);
     $cards->card_no($card_no);
     $contact = new MemContactModel($dbc);
     $contact->card_no($card_no);
     $suspensions = new SuspensionsModel($dbc);
     $suspensions->cardno($card_no);
     $this->reset();
     $this->cardNo($card_no);
     if (!$this->load()) {
         return false;
     }
     if ($this->activeStatus() != '') {
         $suspensions->cardno($card_no);
         $suspensions->memtype1($this->customerTypeID());
         $suspensions->memtype2($this->memberStatus());
         $suspensions->chargelimit($this->chargeLimit());
         $suspensions->mailflag($this->contactAllowed());
         $suspensions->save();
     } else {
         $custdata->Type($this->memberStatus());
         $custdata->memType($this->customerTypeID());
         $custdata->ChargeLimit($this->chargeLimit());
         $custdata->MemDiscountLimit($this->chargeLimit());
         $meminfo->ads_OK($this->contactAllowed());
     }
     $custdata->Balance($this->chargeBalance());
     $allCustdata = new CustdataModel($dbc);
     $allCustdata->CardNo($card_no);
     foreach ($allCustdata as $c) {
         $custdata->personNum($c->personNum());
         $custdata->save();
     }
     $cards->upc($this->idCardUPC());
     $cards->save();
     $memDates->start_date($this->startDate());
     $memDates->end_date($this->endDate());
     $memDates->save();
     if ($this->addressSecondLine() != '') {
         $meminfo->street($this->addressFirstLine() . "\n" . $this->addressSecondLine());
     } else {
         $meminfo->street($this->addressFirstLine());
     }
     $meminfo->city($this->city());
     $meminfo->state($this->state());
     $meminfo->zip($this->zip());
     $meminfo->save();
     if ($this->contactAllowed() == 0) {
         $contact->pref(0);
     } else {
         switch ($this->contactMethod()) {
             case 'mail':
                 $contact->pref(1);
                 break;
             case 'email':
                 $contact->pref(2);
                 break;
             case 'both':
                 $contact->pref(3);
                 break;
         }
     }
     $contact->save();
     return true;
 }
Esempio n. 12
0
 /**
   Update various legacy tables to match 
   existing Customer records. 
   @param $card_no [int] member number
   @return [boolean] success
 */
 public function legacySync($card_no)
 {
     $dbc = $this->connection;
     $custdata = new CustdataModel($dbc);
     $custdata->CardNo($card_no);
     $meminfo = new MeminfoModel($dbc);
     $meminfo->card_no($card_no);
     $this->reset();
     $this->cardNo($card_no);
     $this->accountHolder(1);
     if (count($this->find()) != 1) {
         // no customer records
         // or invalid customer records
         return false;
     }
     $account = new CustomerAccountsModel($dbc);
     $account->cardNo($card_no);
     if (!$account->load()) {
         return false;
     }
     foreach ($this->find() as $c) {
         $meminfo->phone($c->phone());
         $meminfo->email_2($c->altPhone());
         $meminfo->email_1($c->email());
         $meminfo->save();
         $custdata->personNum(1);
         $custdata->FirstName($c->firstName());
         $custdata->LastName($c->lastName());
         $custdata->blueLine($card_no . ' ' . $c->lastName());
         $custdata->ChargeOk($c->chargeAllowed());
         $custdata->WriteChecks($c->checksAllowed());
         $custdata->staff($c->staff());
         $custdata->SSI($c->lowIncomeBenefits());
         $custdata->Discount($c->discount());
         $custdata->save();
     }
     $person = 2;
     $this->accountHolder(0);
     foreach ($this->find() as $c) {
         $custdata->personNum($person);
         $custdata->FirstName($c->firstName());
         $custdata->LastName($c->lastName());
         $custdata->blueLine($card_no . ' ' . $c->lastName());
         $custdata->ChargeOk($c->chargeAllowed());
         $custdata->WriteChecks($c->checksAllowed());
         $custdata->staff($c->staff());
         $custdata->SSI($c->lowIncomeBenefits());
         $custdata->Discount($c->discount());
         $custdata->save();
         $person++;
     }
     return true;
 }
Esempio n. 13
0
function addTempMembers($dbc = "")
{
    //global $dbConn2;
    global $tempMemberRange;
    /* End of range to fill with NEW MEMBER records.
     * 0 means "do no fill"
     */
    global $tempMemberRangeMax;
    /* Placeholder custdata.LastName that will be:
     * - ignored when it occurrs in the range of synced records
     * - assigned to new placeholder records if filling is being done.
     */
    global $tempMemberLastName;
    /* custdata.memType for placeholder records.
     * Must be real.
     */
    global $tempMemberMemberType;
    /* memContact.pref for placeholder records.
     * Must be real.
     */
    global $tempMemberContactPref;
    $retval = null;
    $errors = '';
    if ($dbc == "") {
        $errors = "addTempMembers() no database connection supplied.";
        return $errors;
    }
    /* Much of what follows is lifted from $MEM/NewMemberTool.php
     */
    $name = $tempMemberLastName;
    /* Validate in memtypes.memtype
     */
    $mtype = $tempMemberMemberType;
    $memtypes = new MemtypeModel($dbc);
    $memtypes->memtype($mtype);
    $mtypes = $memtypes->find();
    if (count($mtypes) == 0) {
        $errors = "Member type {$mtype} is not known.";
        return $errors;
    }
    /* Validate in memContactPrefs.pref_id
     */
    $pref = $tempMemberContactPref;
    $memprefs = new MemContactPrefsModel($dbc);
    $memprefs->pref_id($pref);
    $mprefs = $memprefs->find();
    if (count($mprefs) == 0) {
        $errors = "Contact preference {$pref} is not known.";
        return $errors;
    }
    $mt = $dbc->tableDefinition('memtype');
    $dQuery = "SELECT custdataType,discount,staff,ssi from memtype " . "WHERE memtype=?";
    $defaultsQ = $dbc->prepare_statement($dQuery);
    if ($dbc->tableExists('memdefaults') && (!isset($mt['custdataType']) || !isset($mt['discount']) || !isset($mt['staff']) || !isset($mt['ssi']))) {
        $dQuery = "SELECT cd_type as custdataType,discount,staff,SSI as ssi " . "FROM memdefaults WHERE memtype=?";
        $defaultsQ = $dbc->prepare_statement($dQuery);
    }
    $defaultsR = $dbc->exec_statement($defaultsQ, array($mtype));
    $defaults = $dbc->fetch_row($defaultsR);
    $start = $tempMemberRange + 1;
    $end = $tempMemberRangeMax;
    $custdata = new CustdataModel($dbc);
    /* Pre-populate most custdata fields. */
    $custdata->personNum(1);
    $custdata->LastName($name);
    $custdata->FirstName('');
    $custdata->CashBack(999.99);
    $custdata->Balance(0);
    $custdata->memCoupons(0);
    $custdata->Discount($defaults['discount']);
    $custdata->Type($defaults['custdataType']);
    $custdata->staff($defaults['staff']);
    $custdata->SSI($defaults['ssi']);
    $custdata->memType($mtype);
    $meminfo = new MeminfoModel($dbc);
    /* Pre-populate most meminfo fields. */
    $meminfo->last_name('');
    $meminfo->first_name('');
    $meminfo->othlast_name('');
    $meminfo->othfirst_name('');
    $meminfo->street('');
    $meminfo->city('');
    $meminfo->state('');
    $meminfo->zip('');
    $meminfo->phone('');
    $meminfo->email_1('');
    $meminfo->email_2('');
    $chkP = $dbc->prepare_statement('SELECT CardNo FROM custdata WHERE CardNo=?');
    $mdP = $dbc->prepare_statement("INSERT INTO memDates VALUES (?,NULL,NULL)");
    $mcP = $dbc->prepare_statement("INSERT INTO memContact (card_no,pref) VALUES (?,?)");
    $membersAdded = 0;
    for ($i = $start; $i <= $end; $i++) {
        // skip if record already exists
        $chkR = $dbc->exec_statement($chkP, array($i));
        if ($dbc->num_rows($chkR) > 0) {
            continue;
        }
        $custdata->CardNo($i);
        $custdata->blueLine($i . ' ' . $name);
        $custdata->save();
        $meminfo->card_no($i);
        $meminfo->save();
        /* memDates */
        $dbc->exec_statement($mdP, array($i));
        /* memContact */
        $dbc->exec_statement($mcP, array($i, $pref));
        $membersAdded++;
    }
    $retval = $errors ? $errors : $membersAdded;
    return $retval;
    // addTempMembers()
}
Esempio n. 14
0
 function preprocess()
 {
     global $FANNIE_COUNTRY, $FANNIE_MEMBER_MODULES, $FANNIE_OP_DB;
     $this->country = isset($FANNIE_COUNTRY) && !empty($FANNIE_COUNTRY) ? $FANNIE_COUNTRY : "US";
     $this->memNum = FormLib::get_form_value('memNum', False);
     if ($this->memNum !== false) {
         $this->title .= $this->memNum;
         $this->header .= $this->memNum;
         /* start building prev/next links */
         $list = FormLib::get_form_value('l');
         list($prevLink, $nextLink) = self::memLinksPrevNext($this->memNum, $list);
         if (!empty($prevLink)) {
             $this->header .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $prevLink;
         }
         if (!empty($nextLink)) {
             $this->header .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $nextLink;
         }
         $this->header .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . '<a href="javascript:history.back();">Back</a>';
         $this->header .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . '<a href="MemberSearchPage.php">Find</a>';
         /* end building prev/next links */
         /* form was submitted. save input. */
         if (FormLib::get_form_value('saveBtn', False) !== False) {
             $whichBtn = FormLib::get_form_value('saveBtn');
             /** get current account settings for reference **/
             $account = \COREPOS\Fannie\API\member\MemberREST::get($this->memNum);
             \COREPOS\Fannie\API\member\MemberModule::setAccount($account);
             FannieAPI::listModules('MemberModule');
             foreach ($FANNIE_MEMBER_MODULES as $mm) {
                 if (class_exists($mm)) {
                     $instance = new $mm();
                     $this->msgs .= $instance->saveFormData($this->memNum);
                 }
             }
             $dbc = FannieDB::get($FANNIE_OP_DB);
             $custdata = new CustdataModel($dbc);
             $custdata->CardNo($this->memNum);
             $members = $custdata->find();
             if (is_array($members)) {
                 foreach ($members as $m) {
                     $m->pushToLanes();
                 }
             }
             if (!empty($this->msgs)) {
                 // implies: errors occurred
                 // stay on this page
                 $this->msgs .= '<hr />';
             } else {
                 // By default, go back to search page w/ review info.
                 // If user clicked Save & Next and another match is
                 // available, edit the next match
                 $loc = 'MemberSearchPage.php?review=' . $this->memNum;
                 if ($whichBtn == 'Save & Next' && !empty($next)) {
                     $loc = 'MemberEditor.php?memNum=' . $next;
                 }
                 if (is_array($list)) {
                     $loc .= array_reduce($list, function ($c, $i) {
                         return $c . '&l[]=' . $i;
                     }, '');
                 }
                 header('Location: ' . $loc);
                 return False;
             }
         }
     } else {
         // cannot operate without a member number
         // php sapi check makes page unit-testable
         if (php_sapi_name() !== 'cli') {
             header('Location: MemberSearchPage.php');
         }
         return false;
     }
     return true;
     // preprocess()
 }
Esempio n. 15
0
 protected function get_orderID_customer_handler()
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $TRANS = $this->config->get('TRANS_DB') . $dbc->sep();
     $orderID = $this->orderID;
     try {
         $memNum = $this->form->memNum;
     } catch (Exception $ex) {
         $memNum = '0';
     }
     $canEdit = FannieAuth::validateUserQuiet('ordering_edit');
     if (empty($orderID)) {
         $orderID = $this->createEmptyOrder();
     }
     $names = array();
     $personNum = 1;
     $status_row = array('Type' => 'REG', 'status' => '');
     $dbc->selectDB($this->config->get('TRANS_DB'));
     $orderModel = new SpecialOrdersModel($dbc);
     $orderModel->specialOrderID($orderID);
     $orderModel->load();
     $dbc->selectDB($this->config->get('OP_DB'));
     // detect member UPC entry
     if ($memNum > 9999999) {
         $cards = new MemberCardsModel($dbc);
         $cards->upc(BarcodeLib::padUPC($memNum));
         $memNum = '';
         foreach ($cards->find() as $c) {
             $memNum = $c->card_no();
             break;
         }
     }
     // look up member id if applicable
     if ($memNum === "0") {
         $findMem = $dbc->prepare("SELECT card_no,voided FROM {$TRANS}PendingSpecialOrder WHERE order_id=?");
         $memR = $dbc->execute($findMem, array($orderID));
         if ($dbc->numRows($memR) > 0) {
             $memW = $dbc->fetchRow($memR);
             $memNum = $memW['card_no'];
             $personNum = $memW['voided'];
         }
     } elseif ($memNum == "") {
         $prep = $dbc->prepare("UPDATE {$TRANS}PendingSpecialOrder SET card_no=?,voided=0\n                WHERE order_id=?");
         $dbc->execute($prep, array(0, $orderID));
     } else {
         $prep = $dbc->prepare("UPDATE {$TRANS}PendingSpecialOrder SET card_no=?\n                WHERE order_id=?");
         $dbc->execute($prep, array($memNum, $orderID));
         // clear contact fields if member number changed
         // so that defaults are reloaded from meminfo
         $dbc->selectDB($this->config->get('TRANS_DB'));
         $orderModel->street('');
         $orderModel->phone('');
         $orderModel->save();
         $orderModel->specialOrderID($orderID);
         $orderModel->load();
         $dbc->selectDB($this->config->get('OP_DB'));
         // look up personnum, correct if it hasn't been set
         $pendQ = $dbc->prepare_statement("SELECT voided FROM {$TRANS}PendingSpecialOrder\n                WHERE order_id=?");
         $personNum = $dbc->getValue($pendQ, array($orderID));
         if ($personNum == 0) {
             $personNum = 1;
             $upP = $dbc->prepare_statement("UPDATE {$TRANS}PendingSpecialOrder SET voided=?\n                    WHERE order_id=?");
             $upR = $dbc->exec_statement($upP, array($personNum, $orderID));
         }
     }
     if ($memNum != 0) {
         $custdata = new CustdataModel($dbc);
         $custdata->CardNo($memNum);
         foreach ($custdata->find('personNum') as $c) {
             $names[$c->personNum()] = array($c->FirstName(), $c->LastName());
         }
         // load member contact info into order
         // on first go so it can be edited separately
         $current_street = $orderModel->street();
         $current_phone = $orderModel->phone();
         if (empty($current_street) && empty($current_phone)) {
             $contactQ = $dbc->prepare_statement("SELECT street,city,state,zip,phone,email_1,email_2\n                        FROM meminfo WHERE card_no=?");
             $contactR = $dbc->exec_statement($contactQ, array($memNum));
             if ($dbc->num_rows($contactR) > 0) {
                 $contact_row = $dbc->fetch_row($contactR);
                 $dbc->selectDB($this->config->get('TRANS_DB'));
                 $orderModel->street($contact_row['street']);
                 $orderModel->city($contact_row['city']);
                 $orderModel->state($contact_row['state']);
                 $orderModel->zip($contact_row['zip']);
                 $orderModel->phone($contact_row['phone']);
                 $orderModel->altPhone($contact_row['email_2']);
                 $orderModel->email($contact_row['email_1']);
                 $orderModel->save();
                 $orderModel->specialOrderID($orderID);
                 $orderModel->load();
                 $dbc->selectDB($this->config->get('OP_DB'));
             }
         }
         if ($custdata->load()) {
             $status_row['Type'] = $custdata->Type();
             if ($status_row['Type'] == 'INACT') {
                 $status_row['status'] = 'Inactive';
             } elseif ($status_row['Type'] == 'INACT2') {
                 $status_row['status'] = 'Inactive';
             } elseif ($status_row['Type'] == 'TERM') {
                 $status_row['status'] = 'Terminated';
             }
         }
     }
     $prep = $dbc->prepare_statement("SELECT entry_date FROM {$TRANS}SpecialOrderHistory \n                WHERE order_id=? AND entry_type='CONFIRMED'");
     $confirm_date = $dbc->getValue($prep, array($orderID));
     $callback = 2;
     $user = '******';
     $orderDate = "";
     $prep = $dbc->prepare_statement("SELECT datetime,numflag,mixMatch FROM \n                {$TRANS}PendingSpecialOrder WHERE order_id=? AND trans_id=0");
     $res = $dbc->exec_statement($prep, array($orderID));
     if ($dbc->num_rows($res) > 0) {
         list($orderDate, $callback, $user) = $dbc->fetch_row($res);
     }
     $status = array(0 => "New, No Call", 3 => "New, Call", 1 => "Called/waiting", 2 => "Pending", 4 => "Placed", 5 => "Arrived");
     $order_status = $orderModel->statusFlag();
     $ret = "";
     $ret .= sprintf('<input type="hidden" id="orderID" value="%d" />', $orderID);
     $ret .= '<div class="row form-inline"><div class="col-sm-4 text-left">';
     $ret .= sprintf('<b>Owner Number</b>: <input type="text" size="6"
             id="memNum" value="%s" class="form-control price-field input-sm" 
             />', $memNum == 0 ? '' : $memNum);
     $ret .= '<br />';
     $ret .= '<b>Owner</b>: ' . ($status_row['Type'] == 'PC' ? 'Yes' : 'No');
     $ret .= sprintf('<input type="hidden" id="isMember" value="%s" />', $status_row['Type']);
     $ret .= '<br />';
     if (!empty($status_row['status'])) {
         $ret .= '<b>Account status</b>: ' . $status_row['status'];
         $ret .= '<br />';
     }
     $ret .= '</div><div class="col-sm-4 text-center">';
     if ($canEdit) {
         $ret .= '<b>Status</b>: ';
         $ret .= '<select id="orderStatus" class="form-control input-sm">';
         foreach ($status as $k => $v) {
             $ret .= sprintf('<option %s value="%d">%s</option>', $k == $order_status ? 'selected' : '', $k, $v);
         }
         $ret .= '</select><p />';
     }
     $ret .= '<b>Store</b>: ';
     $ret .= '<select id="orderStore" class="form-control input-sm">';
     $ret .= '<option value="0">Choose...</option>';
     $stores = new StoresModel($dbc);
     $ret .= $stores->toOptions($orderModel->storeID());
     $ret .= '</select>';
     $ret .= '</div><div class="col-sm-4 text-right">';
     $ret .= "<a href=\"\" class=\"btn btn-default btn-sm done-btn\">Done</a>";
     $username = FannieAuth::checkLogin();
     $prints = array();
     $cachepath = sys_get_temp_dir() . "/ordercache/";
     if (file_exists("{$cachepath}{$username}.prints")) {
         $prints = unserialize(file_get_contents("{$cachepath}{$username}.prints"));
     } else {
         $fptr = fopen("{$cachepath}{$username}.prints", 'w');
         fwrite($fptr, serialize($prints));
         fclose($fptr);
     }
     $ret .= sprintf('<br />Queue tags <input type="checkbox" %s class="print-cb" />', isset($prints[$orderID]) ? 'checked' : '', $username, $orderID);
     $ret .= sprintf('<br /><a href="tagpdf.php?oids[]=%d" target="_tags%d">Print Now</a>', $orderID, $orderID);
     $ret .= '</div></div>';
     $extra = "";
     $extra .= '<div class="row"><div class="col-sm-6 text-left">';
     $extra .= "<b>Taken by</b>: " . $user . "<br />";
     $extra .= "<b>On</b>: " . date("M j, Y g:ia", strtotime($orderDate)) . "<br />";
     $extra .= '</div><div class="col-sm-6 text-right form-inline">';
     $extra .= '<b>Call to Confirm</b>: ';
     $extra .= '<select id="ctcselect" class="form-control input-sm">';
     $extra .= '<option value="2"></option>';
     if ($callback == 1) {
         $extra .= '<option value="1" selected>Yes</option>';
         $extra .= '<option value="0">No</option>';
     } else {
         if ($callback == 0) {
             $extra .= '<option value="1">Yes</option>';
             $extra .= '<option value="0" selected>No</option>';
         } else {
             $extra .= '<option value="1">Yes</option>';
             $extra .= '<option value="0">No</option>';
         }
     }
     $extra .= '</select><br />';
     $extra .= '<span id="confDateSpan">' . (!empty($confirm_date) ? 'Confirmed ' . $confirm_date : 'Not confirmed') . "</span> ";
     $extra .= '<input type="checkbox" id="confirm-date" ';
     if (!empty($confirm_date)) {
         $extra .= "checked";
     }
     $extra .= ' /><br />';
     $extra .= "<a href=\"\" class=\"btn btn-default btn-sm done-btn\">Done</a>";
     $extra .= '</div></div>';
     $ret .= '<table class="table table-bordered">';
     // names
     if (empty($names)) {
         $ret .= sprintf('<tr><th>First Name</th><td>
                 <input type="text" id="t_firstName" name="fn"
                 class="form-control input-sm conact-field"
                 value="%s" 
                 /></td>', $orderModel->firstName());
         $ret .= sprintf('<th>Last Name</th><td><input 
                 type="text" id="t_lastName" value="%s" name="ln"
                 class="form-control input-sm contact-field"
                 /></td>', $orderModel->lastName());
     } else {
         $ret .= '<tr><th>Name</th><td colspan="2"><select id="s_personNum"
             class="form-control input-sm">';
         foreach ($names as $p => $n) {
             $ret .= sprintf('<option value="%d" %s>%s %s</option>', $p, $p == $personNum ? 'selected' : '', $n[0], $n[1]);
         }
         $ret .= '</select></td>';
         $ret .= '<td>&nbsp;</td>';
     }
     $ret .= '<td colspan="4" class="form-inline">For Department:
         <select id="nDept" class="form-control input-sm contact-field" 
             name="noteDept">
         <option value="0">Choose...</option>';
     $superQ = $dbc->prepare_statement("select superID,super_name from MasterSuperDepts\n            where superID > 0\n            group by superID,super_name\n            order by super_name");
     $superR = $dbc->exec_statement($superQ);
     while ($superW = $dbc->fetch_row($superR)) {
         $ret .= sprintf('<option value="%d" %s>%s</option>', $superW['superID'], $superW['superID'] == $orderModel->noteSuperID() ? 'selected' : '', $superW['super_name']);
     }
     $ret .= "</select></td></tr>";
     // address
     $street = $orderModel->street();
     $street2 = '';
     if (strstr($street, "\n")) {
         list($street, $street2) = explode("\n", $street, 2);
     }
     $ret .= sprintf('
         <tr>
             <th>Address</th>
             <td>
                 <input type="text" id="t_addr1" value="%s" 
                     class="form-control input-sm contact-field"
                     name="addr" />
             </td>
             <th>E-mail</th>
             <td>
                 <input type="text" id="t_email" value="%s" 
                     class="form-control input-sm contact-field"
                     name="email" />
             </td>
             <td rowspan="2" colspan="4">
                 <textarea id="nText" rows="5" cols="25" 
                     class="form-control input-sm contact-field" name="noteText"
                     >%s</textarea>
             </td>
         </tr>
         <tr>
             <th>Addr (2)</th>
             <td>
                 <input type="text" id="t_addr2" value="%s" 
                     class="form-control input-sm contact-field"
                     name="addr2" />
             </td>
             <th>City</th>
             <td>
                 <input type="text" id="t_city" name="city"
                     class="form-control input-sm contact-field"
                     value="%s" size="10" />
             </td>
         </tr>
         <tr>
             <th>Phone</th>
             <td>
                 <input type="text" id="t_ph1" name="ph1"
                     class="form-control input-sm contact-field"
                     value="%s" />
             </td>
             <th>Alt. Phone</th>
             <td>
                 <input type="text" id="t_ph2" value="%s" name="ph2"
                     class="form-control input-sm contact-field" />
             </td>
             <th>State</th>
             <td>
                 <input type="text" id="t_state" value="%s" size="2" 
                     class="form-control input-sm contact-field"
                     name="state"  />
             </td>
             <th>Zip</th>
             <td>
                 <input type="text" id="t_zip" value="%s" size="5" 
                     class="form-control input-sm contact-field"
                     name="zip" />
             </td>
         </tr>', $street, $orderModel->email(), $orderModel->notes(), $street2, $orderModel->city(), $orderModel->phone(), $orderModel->altPhone(), $orderModel->state(), $orderModel->zip());
     $ret .= '</table>';
     echo json_encode(array('customer' => $ret, 'footer' => $extra));
     return false;
 }
Esempio n. 16
0
 public function post_id_fn_city_ph1_ln_state_ph2_addr1_zip_email_addr2_handler()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $cust = new CustdataModel($dbc);
     $cust->CardNo($this->id);
     $cust->personNum(1);
     $cust->FirstName($this->fn);
     $cust->LastName($this->ln);
     $cust->save();
     $mem = new MeminfoModel($dbc);
     $mem->card_no($this->id);
     $mem->city($this->city);
     $mem->state($this->state);
     $mem->zip($this->zip);
     $mem->phone($this->ph1);
     $mem->email_1($this->email);
     $mem->email_2($this->ph2);
     $street = $this->addr1;
     if (!empty($this->addr2)) {
         $street .= "\n" . $this->addr2;
     }
     $mem->street($street);
     $mem->save();
     header('Location: GumMainPage.php?id=' . $this->id);
     return false;
 }
Esempio n. 17
0
 public function run()
 {
     global $FANNIE_OP_DB, $FANNIE_PLUGIN_SETTINGS, $argv;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $custdata = new CustdataModel($dbc);
     $meminfo = new MeminfoModel($dbc);
     $APIKEY = 'a92f83d3e5f7fe52d4579e7902c6491d-us8';
     $LISTID = '54100d18af';
     $APIKEY = $FANNIE_PLUGIN_SETTINGS['MailChimpApiKey'];
     $LISTID = $FANNIE_PLUGIN_SETTINGS['MailChimpListID'];
     if (empty($APIKEY) || empty($LISTID)) {
         $this->cronMsg('Missing API key or List ID', FannieLogger::NOTICE);
         return false;
     }
     if (!class_exists('Mailchimp')) {
         $this->cronMsg('MailChimp library is not installed', FannieLogger::NOTICE);
         return false;
     }
     $mc = new MailChimpEx($APIKEY);
     if ($FANNIE_PLUGIN_SETTINGS['MailChimpMergeVarField'] != 1) {
         $vars = $mc->lists->mergeVars(array($LISTID));
         $field_id = false;
         if ($vars['data']) {
             $current = array_pop($vars['data']);
             foreach ($current['merge_vars'] as $index => $info) {
                 if ($info['tag'] == 'CARDNO') {
                     $field_id = $info['id'];
                     break;
                 }
             }
             if ($field_id !== false) {
                 echo 'Found member# field' . "\n";
             } else {
                 echo 'Adding member# field' . "\n";
                 $new = $mc->lists->mergeVarAdd($LISTID, 'CARDNO', 'Owner Number', array('field_type' => 'number', 'public' => false));
                 $field_id = $new['id'];
             }
         }
         if ($field_id === false) {
             $this->cronMsg('Error: could not locate / create owner number field!', FannieLogger::NOTICE);
             return false;
         }
     }
     // end create owner number field if needed
     $statuses = array('subscribed', 'unsubscribed', 'cleaned');
     $cleans = array();
     $memlist = '';
     /**
       Examine all list members
     */
     foreach ($statuses as $status) {
         $this->cronMsg('==== Checking ' . $status . ' emails ====', FannieLogger::INFO);
         $full_list = $mc->lists->export($LISTID, $status);
         $headers = array_shift($full_list);
         $columns = array();
         foreach ($headers as $index => $name) {
             $columns[strtoupper($name)] = $index;
         }
         $line_count = 1;
         foreach ($full_list as $record) {
             /**
               Print progress meter in verbose mode
             */
             if (isset($argv[2]) && ($argv[2] == '-v' || $argv[2] == '--verbose')) {
                 printf("Processing %d/%d\r", $line_count, count($full_list));
             }
             $line_count++;
             $card_no = $record[$columns['OWNER NUMBER']];
             $email = $record[$columns['EMAIL ADDRESS']];
             $fn = $record[$columns['FIRST NAME']];
             $ln = $record[$columns['LAST NAME']];
             $changed = isset($columns['LAST_CHANGED']) && isset($record[$columns['LAST_CHANGED']]) ? $record[$columns['LAST_CHANGED']] : 0;
             /** MailChimp has a POS member number tag **/
             if (!empty($card_no)) {
                 switch ($status) {
                     /**
                       If subscribed list member has been tagged with a POS member number, compare
                       MailChimp fields to POS fields. If name disagrees, use POS value
                       for both. If email disagrees, use MailChimp value for both.
                     */
                     case 'subscribed':
                         $memlist .= sprintf('%d,', $card_no);
                         $custdata->reset();
                         $custdata->CardNo($card_no);
                         $custdata->personNum(1);
                         $custdata->load();
                         $update = array();
                         $meminfo->reset();
                         $meminfo->card_no($card_no);
                         $meminfo->load();
                         if ($meminfo->email_1() != $email && strtotime($changed) > strtotime($meminfo->modified())) {
                             $this->cronMsg(sprintf("MISMATCH: POS says %s, MailChimp says %s, Mailchimp is newer", $meminfo->email_1(), $email), FannieLogger::INFO);
                             $meminfo->email_1($email);
                             $meminfo->save();
                         } elseif ($meminfo->email_1() != $email) {
                             $update['EMAIL'] = $meminfo->email_1();
                             $this->cronMsg(sprintf("MISMATCH: POS says %s, MailChimp says %s, POS is newer", $meminfo->email_1(), $email), FannieLogger::INFO);
                         }
                         if (strtoupper(trim($custdata->FirstName())) != strtoupper($fn)) {
                             $this->cronMsg(sprintf("MISMATCH: POS says %s, MailChimp says %s", $custdata->FirstName(), $fn), FannieLogger::INFO);
                             $update['FNAME'] = trim($custdata->FirstName());
                         }
                         if (strtoupper(trim($custdata->LastName())) != strtoupper($ln)) {
                             $this->cronMsg(sprintf("MISMATCH: POS says %s, MailChimp says %s", $custdata->LastName(), $ln), FannieLogger::INFO);
                             $update['LNAME'] = trim($custdata->LastName());
                         }
                         if (count($update) > 0) {
                             $email_struct = array('euid' => $record[$columns['EUID']], 'leid' => $record[$columns['LEID']]);
                             $this->cronMsg(sprintf("Updating name field(s) for member #%d", $card_no), FannieLogger::INFO);
                             try {
                                 $mc->lists->updateMember($LISTID, $email_struct, $update, '', false);
                             } catch (Exception $ex) {
                                 echo $ex;
                                 var_dump($update);
                             }
                             sleep(1);
                         }
                         break;
                         /**
                           Just track the number to avoid re-adding them to the list
                         */
                     /**
                       Just track the number to avoid re-adding them to the list
                     */
                     case 'unsubscribed':
                         $memlist .= sprintf('%d,', $card_no);
                         break;
                         /**
                           Cleaned in MailChimp means the address isn't deliverable
                           In this situation, remove the bad address from POS
                           and delete the address from MailChimp. The member can be
                           re-added when a correct email is entered into POS.
                         */
                     /**
                       Cleaned in MailChimp means the address isn't deliverable
                       In this situation, remove the bad address from POS
                       and delete the address from MailChimp. The member can be
                       re-added when a correct email is entered into POS.
                     */
                     case 'cleaned':
                         $meminfo->reset();
                         $meminfo->card_no($card_no);
                         $meminfo->email_1('');
                         $meminfo->save();
                         $this->cronMsg(sprintf('CLEANING Member %d, email %s', $card_no, $email), FannieLogger::INFO);
                         $cleans[] = $record;
                         break;
                 }
                 /**
                   If list member is not tagged with a POS member number, try to
                   locate them in POS by name and/or email address. If found,
                   tag them in MailChimp with the POS member number. This whole
                   situation only occurs if the initial list is imported without
                   member numbers.
                 */
             } else {
                 switch ($status) {
                     // subscribed users can be updated easily
                     case 'subscribed':
                         $update = array();
                         $meminfo->reset();
                         $meminfo->email_1($email);
                         $matches = $meminfo->find();
                         if (count($matches) == 1) {
                             $update['CARDNO'] = $matches[0]->card_no();
                         } else {
                             $custdata->reset();
                             $custdata->FirstName($fn);
                             $custdata->LastName($ln);
                             $custdata->personNum(1);
                             $custdata->Type('PC');
                             $matches = $custdata->find();
                             if (count($matches) == 1) {
                                 $update['CARDNO'] = $matches[0]->CardNo();
                             }
                         }
                         if (isset($update['CARDNO'])) {
                             $email_struct = array('email' => $email, 'euid' => $record[$columns['EUID']], 'leid' => $record[$columns['LEID']]);
                             $this->cronMsg("Assigning member # to account " . $email, FannieLogger::INFO);
                             $mc->lists->updateMember($LISTID, $email_struct, $update, '', false);
                             sleep(1);
                             $memlist .= sprintf('%d,', $update['CARDNO']);
                         }
                         break;
                         /**
                           Unsubscribed are currently ignored. The can't be updated as is.
                           They could be deleted entirely via unsubscribe, resubscribed with
                           an owner number, and then unsubscribed again. That's not currently
                           implemented. It does check for the email address on the POS side
                           to prevent re-adding it.
                         */
                     /**
                       Unsubscribed are currently ignored. The can't be updated as is.
                       They could be deleted entirely via unsubscribe, resubscribed with
                       an owner number, and then unsubscribed again. That's not currently
                       implemented. It does check for the email address on the POS side
                       to prevent re-adding it.
                     */
                     case 'unsubscribed':
                         $meminfo->reset();
                         $this->cronMsg('Checking unsubscribed ' . $email, FannieLogger::INFO);
                         $meminfo->email_1($email);
                         $matches = $meminfo->find();
                         foreach ($matches as $opted_out) {
                             $memlist .= sprintf('%d,', $opted_out->card_no());
                             $this->cronMsg('Excluding member ' . $opted_out->card_no(), FannieLogger::INFO);
                         }
                         break;
                         /**
                           Cleaned are bad addresses. Delete them from POS database
                           then from Mail Chimp.
                         */
                     /**
                       Cleaned are bad addresses. Delete them from POS database
                       then from Mail Chimp.
                     */
                     case 'cleaned':
                         $meminfo->reset();
                         $meminfo->email_1($email);
                         foreach ($meminfo->find() as $bad_address) {
                             $bad_address->email_1('');
                             $bad_address->save();
                             $this->cronMsg(sprintf('CLEANING untagged member %d, email %s', $bad_address->card_no(), $email), FannieLogger::INFO);
                         }
                         $cleans[] = $record;
                         break;
                 }
             }
         }
         // foreach list member record
     }
     // foreach list status
     /**
       Removed bounced from the MailChimp list now that
       POS has been updated
     */
     $removal_batch = array();
     foreach ($cleans as $record) {
         if (empty($record[$columns['EMAIL ADDRESS']])) {
             continue;
         }
         $email_struct = array('email' => $record[$columns['EMAIL ADDRESS']], 'euid' => $record[$columns['EUID']], 'leid' => $record[$columns['LEID']]);
         $removal_batch[] = $email_struct;
     }
     if (count($removal_batch) > 0) {
         $this->cronMsg(sprintf('Removing %d addresses with status "cleaned"', count($removal_batch)), FannieLogger::INFO);
         $result = $mc->lists->batchUnsubscribe($LISTID, $removal_batch, true, false, false);
     }
     /**
       Finally, find new members and add them to MailChimp
     */
     if ($memlist === '') {
         $memlist = '-1,';
     }
     $memlist = substr($memlist, 0, strlen($memlist) - 1);
     $query = 'SELECT m.card_no,
                 m.email_1,
                 c.FirstName,
                 c.LastName
               FROM meminfo AS m
                 INNER JOIN custdata AS c ON c.CardNo=m.card_no AND c.personNum=1
               WHERE c.Type = \'PC\'
                 AND m.email_1 IS NOT NULL
                 AND m.email_1 <> \'\'
                 AND m.card_no NOT IN (' . $memlist . ')';
     $result = $dbc->query($query);
     $add_batch = array();
     while ($row = $dbc->fetch_row($result)) {
         if (!filter_var($row['email_1'], FILTER_VALIDATE_EMAIL)) {
             continue;
         }
         $new = array('email' => array('email' => $row['email_1']), 'email_type' => 'html', 'merge_vars' => array('FNAME' => $row['FirstName'], 'LNAME' => $row['LastName'], 'CARDNO' => $row['card_no']));
         $add_batch[] = $new;
     }
     if (count($add_batch) > 0) {
         $this->cronMsg(sprintf('Adding %d new members', count($add_batch)), FannieLogger::INFO);
         $added = $mc->lists->batchSubscribe($LISTID, $add_batch, false, true);
     }
     return true;
 }
Esempio n. 18
0
</tr>
</table>

<?php 
$memNum = $memID;
if (!isset($_POST['submit']) && !isset($_GET['fixedaddress'])) {
    echo "&nbsp;&nbsp;&nbsp;Reason for suspending membership {$memNum}<br />";
    echo "<form action=alterstatus.php method=post>";
    echo "<input type=hidden name=memNum value={$memID}>";
    $sus = new SuspensionsModel($sql);
    $sus->cardno($memNum);
    $sus->load();
    $curReasonCode = $sus->reasonCode();
    $cust = new CustdataModel($sql);
    $cust->CardNo($memNum);
    $cust->personNum(1);
    $cust->load();
    $curType = $cust->Type();
    $stats = array('INACT' => 'Inactive', 'TERM' => 'Termed', 'INACT2' => 'Term pending');
    echo "<select name=status>";
    foreach ($stats as $k => $v) {
        echo "<option value=" . $k;
        if ($k == $curType) {
            echo " selected";
        }
        echo ">" . $v . "</option>";
    }
    echo "</select>";
    $query = "select textStr,mask from reasoncodes";
    $result = $sql->query($query);
Esempio n. 19
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. 20
-1
 public function post_handler()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $fy = FormLib::get('fy');
     $per_page = FormLib::get('per_page');
     $custdata = new CustdataModel($dbc);
     $meminfo = new MeminfoModel($dbc);
     $query = $dbc->prepare('
         SELECT p.cardno,
             p.cash_pat,
             m.zip,
             p.check_number
         FROM patronage AS p
             INNER JOIN meminfo AS m ON p.cardno=m.card_no
             INNER JOIN custdata AS c ON p.cardno=c.CardNo AND c.personNum=1
         WHERE p.FY=?
         ORDER BY m.zip,
             c.LastName,
             c.FirstName');
     $result = $dbc->execute($query, array($fy));
     $pdf = new FPDF('P', 'mm', 'Letter');
     $pdf->SetMargins(6.35, 6.35, 6.35);
     // quarter-inch margins
     $pdf->SetAutoPageBreak(false);
     $filename = '';
     $this->files = array();
     $filenumber = 1;
     set_time_limit(0);
     while ($w = $dbc->fetch_row($result)) {
         if (empty($filename)) {
             $filename = $filenumber . '-' . substr($w['zip'], 0, 5);
         }
         $dbc = FannieDB::get($FANNIE_OP_DB);
         $custdata->CardNo($w['cardno']);
         $custdata->personNum(1);
         $custdata->load();
         $meminfo->card_no($w['cardno']);
         $meminfo->load();
         if ($w['check_number'] == '') {
             $patronage = new PatronageModel($dbc);
             $patronage->cardno($w['cardno']);
             $patronage->FY($fy);
             $number = GumLib::allocateCheck($patronage, false);
             $dbc = FannieDB::get($FANNIE_OP_DB);
             $patronage->check_number($number);
             $patronage->save();
             $w['check_number'] = $number;
         }
         $pdf->AddPage();
         $pdf->Image('rebate_body.png', 10, 0, 190);
         $check = new GumCheckTemplate($custdata, $meminfo, $w['cash_pat'], 'Rebate ' . $fy, $w['check_number']);
         $check->renderAsPDF($pdf);
         if ($pdf->PageNo() == $per_page) {
             $filename .= '-' . substr($w['zip'], 0, 5) . '.pdf';
             $filenumber++;
             $pdf->Output('/tmp/' . $filename, 'F');
             $this->files[] = $filename;
             $filename = '';
             $pdf = new FPDF('P', 'mm', 'Letter');
             $pdf->SetMargins(6.35, 6.35, 6.35);
             // quarter-inch margins
             $pdf->SetAutoPageBreak(false);
         }
     }
     $filename .= '-End.pdf';
     $pdf->Output('/tmp/' . $filename, 'F');
     $this->files[] = $filename;
     return true;
 }