Exemplo n.º 1
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()
}
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
$cards = new MemberCardsModel($sql);
$cards->card_no($memNum);
// delete existing records
foreach ($cards->find() as $obj) {
    $obj->delete();
}
// add record with correct upc
$cards->upc(str_pad($_REQUEST['cardUPC'], 13, '0', STR_PAD_LEFT));
$cards->save();
// update top name
$cust = new CustdataModel($sql);
$cust->CardNo($memNum);
$cust->personNum(1);
$cust->LastName($lName);
$cust->FirstName($fname);
$cust->blueLine($blueline);
$cust->save();
for ($i = 0; $i < 3; $i++) {
    if ($fnames[$i] == "''") {
        $fnames[$i] = "";
    }
    if ($lnames[$i] == "''") {
        $lnames[$i] = "";
    }
}
$count = 2;
// load settings for person 1, update just names on other records
$cust->reset();
$cust->CardNo($memNum);
$cust->personNum(1);
$cust->load();
Exemplo n.º 4
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();
     }
 }
Exemplo n.º 5
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;
 }