Пример #1
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;
 }
Пример #2
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;
 }