Esempio n. 1
0
 /**
   Update newer tables then sync changes to
   older tables
 */
 private static function postAccount($dbc, $id, $json)
 {
     $ret = array('errors' => 0, 'error-msg' => '');
     $config = \FannieConfig::factory();
     $account = new \CustomerAccountsModel($dbc);
     $customers = new \CustomersModel($dbc);
     $account->cardNo($id);
     foreach ($account->getColumns() as $col_name => $info) {
         if ($col_name == 'cardNo') {
             continue;
         }
         if ($col_name == 'customerAccountID') {
             continue;
         }
         if ($col_name == 'modified') {
             continue;
         }
         if (isset($json[$col_name])) {
             $account->{$col_name}($json[$col_name]);
         }
     }
     if (!$account->save()) {
         $ret['errors']++;
     }
     if (isset($json['customers']) && is_array($json['customers'])) {
         $columns = $customers->getColumns();
         foreach ($json['customers'] as $c_json) {
             $customers->reset();
             $customers->cardNo($id);
             $deletable = 0;
             foreach ($columns as $col_name => $info) {
                 if ($col_name == 'cardNo') {
                     continue;
                 }
                 if ($col_name == 'modified') {
                     continue;
                 }
                 if ($col_name == 'customerID' && isset($c_json[$col_name]) && $c_json[$col_name] != 0) {
                     $deletable++;
                 } elseif ($col_name == 'firstName' && isset($c_json[$col_name]) && $c_json[$col_name] == '') {
                     $deletable++;
                 } elseif ($col_name == 'lastName' && isset($c_json[$col_name]) && $c_json[$col_name] == '') {
                     $deletable++;
                 }
                 if (isset($c_json[$col_name])) {
                     $customers->{$col_name}($c_json[$col_name]);
                 }
             }
             if ($deletable == 3) {
                 // submitted an ID and blank name fields
                 $customers->delete();
             } elseif ($deletable == 2 && $customers->customerID() == 0) {
                 // skip creating member
             } elseif (!$customers->save()) {
                 $ret['errors']++;
             }
         }
     }
     // mirror changes to older tables
     if ($config->get('CUST_SCHEMA') == 1) {
         $account->legacySync($id);
         $customers->legacySync($id);
     }
     $ret['account'] = self::get($id);
     return $ret;
 }
Esempio n. 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;
 }