Beispiel #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;
 }
Beispiel #2
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;
     }
 }
Beispiel #3
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();
 }
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()
}
Beispiel #5
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;
 }
Beispiel #6
0
$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=?");
$sql->execute($mcP, array($MI_FIELDS['ads_OK'], $memNum));
 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;
 }
Beispiel #8
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();
     }
 }
 /**
   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;
 }
Beispiel #10
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;
 }
Beispiel #11
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;
 }
Beispiel #12
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);
    echo "<table>";
Beispiel #13
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;
 }
Beispiel #14
-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;
 }