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()
}
示例#2
0
    $cust->personNum($count);
    $cust->FirstName($fnames[$i]);
    $cust->LastName($lnames[$i]);
    $cust->BlueLine($cust->CardNo() . ' ' . $cust->LastName());
    $cust->save();
    // save next personNum
    $count++;
}
// remove names that were blank on the form
for ($i = $count; $i < 5; $i++) {
    $cust->personNum($i);
    $cust->delete();
}
$meminfo = new MeminfoModel($dbc);
$meminfo->card_no($memNum);
$meminfo->street($MI_FIELDS['street']);
$meminfo->city($MI_FIELDS['city']);
$meminfo->state($MI_FIELDS['state']);
$meminfo->phone($MI_FIELDS['phone']);
$meminfo->email_2($MI_FIELDS['email_2']);
$meminfo->email_1($MI_FIELDS['email_1']);
$meminfo->ads_OK($MI_FIELDS['ads_OK']);
$meminfo->save();
$memdate = new MemDatesModel($dbc);
$memdate->card_no($memNum);
$memdate->start_date($_POST['startDate']);
$memdate->end_date($_POST['endDate']);
$memdate->save();
// FIRE ALL UPDATE
include 'custUpdates.php';
updateCustomerAllLanes($memNum);
示例#3
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;
 }
示例#4
0
 /**
   Update older tables.
 */
 private static function postCustdata($dbc, $id, $json)
 {
     $config = \FannieConfig::factory();
     $ret = array('errors' => 0, 'error-msg' => '');
     /** save dates if provided **/
     if (isset($json['startDate']) || isset($json['endDate'])) {
         $dates = new \MemDatesModel($dbc);
         $dates->start_date($json['startDate']);
         $dates->end_date($json['endDate']);
         $dates->card_no($id);
         if (!$dates->save()) {
             $ret['errors']++;
             $ret['error-msg'] .= 'ErrDates ';
         }
     }
     /** save UPC if provided **/
     if (isset($json['idCardUPC'])) {
         $cards = new \MemberCardsModel($dbc);
         $cards->card_no($id);
         if ($json['idCardUPC'] != '') {
             $cards->upc(\BarcodeLib::padUPC($json['idCardUPC']));
         } else {
             $cards->upc('');
         }
         if (!$cards->save()) {
             $ret['errors']++;
         }
     }
     /** save contact method if provided **/
     if (isset($json['contactMethod'])) {
         $contact = new \MemContactModel($dbc);
         $contact->card_no($id);
         if (isset($json['contactAllowed']) && !$json['contactAllowed']) {
             $contact->pref(0);
         } elseif ($json['contactMethod'] == 'email') {
             $contact->pref(2);
         } elseif ($json['contactMethod'] == 'both') {
             $contact->pref(3);
         } else {
             $contact->pref(1);
         }
         if (!$contact->save()) {
             $ret['errors']++;
             $ret['error-msg'] .= 'ErrUPC ';
         }
     }
     /**
       Custdata and meminfo are messier. Start with account-level
       settings.
     */
     $custdata = new \CustdataModel($dbc);
     $custdata->CardNo($id);
     $custdata_changed = false;
     $meminfo = new \MeminfoModel($dbc);
     $meminfo->card_no($id);
     if (isset($json['addressFirstLine'])) {
         $street = $json['addressFirstLine'];
         if (isset($json['addressSecondLine'])) {
             $street .= "\n" . $json['addressSecondLine'];
         }
         $meminfo->street($street);
     }
     if (isset($json['city'])) {
         $meminfo->city($json['city']);
     }
     if (isset($json['state'])) {
         $meminfo->state($json['state']);
     }
     if (isset($json['zip'])) {
         $meminfo->zip($json['zip']);
     }
     if (isset($json['contactAllowed'])) {
         $meminfo->ads_OK($json['contactAllowed']);
     }
     if (isset($json['activeStatus']) && $json['activeStatus'] != '') {
         $custdata->Type($json['activeStatus']);
         $custdata_changed = true;
     } elseif (isset($json['memberStatus'])) {
         $custdata->Type($json['memberStatus']);
         $custdata_changed = true;
     }
     if (isset($json['customerTypeID'])) {
         $custdata->memType($json['customerTypeID']);
         $custdata_changed = true;
     }
     if (isset($json['chargeLimit'])) {
         $custdata->ChargeLimit($json['chargeLimit']);
         $custdata->MemDiscountLimit($json['chargeLimit']);
         $custdata_changed = true;
     }
     if (isset($json['chargeBalance'])) {
         $custdata->Balance($json['chargeBalance']);
         $custdata_changed = true;
     }
     /**
       Now loop through per-person settings. Assign the primary account holder's
       email address and phone number to the global meminfo, but save the other
       settings using a different per-person custdata instance
     */
     if (isset($json['customers']) && is_array($json['customers']) && count($json['customers']) > 0) {
         $personNum = 2;
         foreach ($json['customers'] as $c_json) {
             if (!isset($c_json['accountHolder'])) {
                 $ret['errors']++;
                 $ret['error-msg'] .= 'ErrAcctHolder ';
                 continue;
             }
             $loopCD = new \CustdataModel($dbc);
             $loopCD->CardNo($id);
             $loopCD_changed = false;
             if ($c_json['accountHolder']) {
                 $loopCD->personNum(1);
                 if (isset($c_json['phone'])) {
                     $meminfo->phone($c_json['phone']);
                 }
                 if (isset($c_json['altPhone'])) {
                     $meminfo->email_2($c_json['altPhone']);
                 }
                 if (isset($c_json['email'])) {
                     $meminfo->email_1($c_json['email']);
                 }
             } elseif (isset($c_json['firstName']) && isset($c_json['lastName']) && $c_json['firstName'] == '' && $c_json['lastName'] == '') {
                 // blank name fields on non-account holder mean
                 // the customer was removed from the account
                 continue;
             } else {
                 $loopCD->personNum($personNum);
                 $personNum++;
             }
             if (isset($c_json['firstName'])) {
                 $loopCD->FirstName($c_json['firstName']);
                 $loopCD_changed = true;
             }
             if (isset($c_json['lastName'])) {
                 $loopCD->LastName($c_json['lastName']);
                 $loopCD_changed = true;
             }
             if (isset($c_json['chargeAllowed'])) {
                 $loopCD->ChargeOk($c_json['chargeAllowed']);
                 $loopCD_changed = true;
             }
             if (isset($c_json['checksAllowed'])) {
                 $loopCD->WriteChecks($c_json['checksAllowed']);
                 $loopCD_changed = true;
             }
             if (isset($c_json['staff'])) {
                 $loopCD->staff($c_json['staff']);
                 $loopCD_changed = true;
             }
             if (isset($c_json['discount'])) {
                 $loopCD->Discount($c_json['discount']);
                 $loopCD_changed = true;
             }
             if (isset($c_json['lowIncomeBenefits'])) {
                 $loopCD->SSI($c_json['lowIncomeBenefits']);
                 $loopCD_changed = true;
             }
             if ($loopCD_changed && !$loopCD->save()) {
                 $ret['errors']++;
                 $ret['error-msg'] .= 'ErrPerson ';
             }
         }
         $cleanP = $dbc->prepare('DELETE FROM custdata WHERE CardNo=? AND personNum>=?');
         $cleanR = $dbc->execute($cleanP, array($id, $personNum));
     }
     if (!$meminfo->save()) {
         $ret['errors']++;
         $ret['error-msg'] .= 'ErrMeminfo ';
     }
     /**
       Finally, apply account-level settings to
       all custdata records for the account.
     */
     if ($custdata_changed) {
         $allCD = new \CustdataModel($dbc);
         $allCD->CardNo($id);
         foreach ($allCD->find() as $c) {
             $custdata->personNum($c->personNum());
             if (!$custdata->save()) {
                 $ret['errors']++;
                 $ret['error-msg'] .= 'ErrGlobal ';
             }
         }
     }
     self::setBlueLines($id);
     // in classic mode sync changes back to the new table if present
     if ($config->get('CUST_SCHEMA') != 1 && $dbc->tableExists('CustomerAccounts')) {
         self::postAccount($dbc, $id, $json);
     }
     $ret['account'] = self::get($id);
     return $ret;
 }
示例#5
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;
 }