Beispiel #1
0
 function saveFormData($memNum)
 {
     global $FANNIE_MEMBER_UPC_PREFIX, $FANNIE_ROOT;
     $dbc = $this->db();
     if (!class_exists("MemberCardsModel")) {
         include $FANNIE_ROOT . 'classlib2.0/data/models/MemberCardsModel.php';
     }
     $prefix = isset($FANNIE_MEMBER_UPC_PREFIX) ? $FANNIE_MEMBER_UPC_PREFIX : "";
     $plen = strlen($prefix);
     $form_upc = FormLib::get_form_value('memberCard', '');
     // Restore prefix and leading 0's to upc.
     if ($form_upc && strlen($form_upc) < 13) {
         $clen = 13 - $plen;
         $form_upc = sprintf("{$prefix}%0{$clen}d", $form_upc);
     }
     $model = new MemberCardsModel($dbc);
     $model->card_no($memNum);
     $model->upc($form_upc);
     $saved = $model->save();
     $model->pushToLanes();
     if (!$saved) {
         return 'Error: problem saving Member Card<br />';
     } else {
         return '';
     }
     // saveFormData
 }
Beispiel #2
0
$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));
if ($cust->memType() == 1 || $cust->memType() == 3) {
    $cust->Type('PC');
}
if ($cust->memType() == 3 || $cust->memType() == 9) {
    $cust->Discount(12);
    $cust->Staff(1);
}
$cust->FirstName($_POST['fName']);
$cust->LastName($_POST['lName']);
$cust->BlueLine($cust->CardNo() . ' ' . $cust->LastName());
$cust->save();
Beispiel #3
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;
 }
Beispiel #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;
 }
 /**
   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;
 }