function get_id_first_last_handler() { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); if (empty($this->id) && empty($this->last)) { return True; } // invalid search if (!empty($this->id)) { $custdata = new CustdataModel($dbc); $custdata->CardNo($this->id); $custdata->Type('PC'); if (count($custdata->find()) > 0) { header('Location: GumMainPage.php?id=' . $this->id); return False; } $cards = new MemberCardsModel($dbc); $cards->upc(str_pad($this->id, 13, '0', STR_PAD_LEFT)); foreach ($cards->find() as $obj) { header('Location: GumMainPage.php?id=' . $obj->card_no()); return False; } } else { $q = $dbc->prepare_statement('SELECT CardNo, LastName, FirstName FROM custdata WHERE LastName LIKE ? AND FirstName LIKE ? AND Type = \'PC\' ORDER BY LastName,FirstName,CardNo'); $r = $dbc->exec_statement($q, array($this->last . '%', $this->first . '%')); $this->__models['custdata'] = array(); while ($w = $dbc->fetch_row($r)) { $this->__models['custdata'][] = $w; } if (count($this->__models['custdata']) == 1) { header('Location: GumMainPage.php?id=' . $this->__models['custdata'][0]['CardNo']); return False; } } return true; }
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 }
$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(); // save personNum=1
/** 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; }
protected function get_orderID_customer_handler() { $dbc = $this->connection; $dbc->selectDB($this->config->get('OP_DB')); $TRANS = $this->config->get('TRANS_DB') . $dbc->sep(); $orderID = $this->orderID; try { $memNum = $this->form->memNum; } catch (Exception $ex) { $memNum = '0'; } $canEdit = FannieAuth::validateUserQuiet('ordering_edit'); if (empty($orderID)) { $orderID = $this->createEmptyOrder(); } $names = array(); $personNum = 1; $status_row = array('Type' => 'REG', 'status' => ''); $dbc->selectDB($this->config->get('TRANS_DB')); $orderModel = new SpecialOrdersModel($dbc); $orderModel->specialOrderID($orderID); $orderModel->load(); $dbc->selectDB($this->config->get('OP_DB')); // detect member UPC entry if ($memNum > 9999999) { $cards = new MemberCardsModel($dbc); $cards->upc(BarcodeLib::padUPC($memNum)); $memNum = ''; foreach ($cards->find() as $c) { $memNum = $c->card_no(); break; } } // look up member id if applicable if ($memNum === "0") { $findMem = $dbc->prepare("SELECT card_no,voided FROM {$TRANS}PendingSpecialOrder WHERE order_id=?"); $memR = $dbc->execute($findMem, array($orderID)); if ($dbc->numRows($memR) > 0) { $memW = $dbc->fetchRow($memR); $memNum = $memW['card_no']; $personNum = $memW['voided']; } } elseif ($memNum == "") { $prep = $dbc->prepare("UPDATE {$TRANS}PendingSpecialOrder SET card_no=?,voided=0\n WHERE order_id=?"); $dbc->execute($prep, array(0, $orderID)); } else { $prep = $dbc->prepare("UPDATE {$TRANS}PendingSpecialOrder SET card_no=?\n WHERE order_id=?"); $dbc->execute($prep, array($memNum, $orderID)); // clear contact fields if member number changed // so that defaults are reloaded from meminfo $dbc->selectDB($this->config->get('TRANS_DB')); $orderModel->street(''); $orderModel->phone(''); $orderModel->save(); $orderModel->specialOrderID($orderID); $orderModel->load(); $dbc->selectDB($this->config->get('OP_DB')); // look up personnum, correct if it hasn't been set $pendQ = $dbc->prepare_statement("SELECT voided FROM {$TRANS}PendingSpecialOrder\n WHERE order_id=?"); $personNum = $dbc->getValue($pendQ, array($orderID)); if ($personNum == 0) { $personNum = 1; $upP = $dbc->prepare_statement("UPDATE {$TRANS}PendingSpecialOrder SET voided=?\n WHERE order_id=?"); $upR = $dbc->exec_statement($upP, array($personNum, $orderID)); } } if ($memNum != 0) { $custdata = new CustdataModel($dbc); $custdata->CardNo($memNum); foreach ($custdata->find('personNum') as $c) { $names[$c->personNum()] = array($c->FirstName(), $c->LastName()); } // load member contact info into order // on first go so it can be edited separately $current_street = $orderModel->street(); $current_phone = $orderModel->phone(); if (empty($current_street) && empty($current_phone)) { $contactQ = $dbc->prepare_statement("SELECT street,city,state,zip,phone,email_1,email_2\n FROM meminfo WHERE card_no=?"); $contactR = $dbc->exec_statement($contactQ, array($memNum)); if ($dbc->num_rows($contactR) > 0) { $contact_row = $dbc->fetch_row($contactR); $dbc->selectDB($this->config->get('TRANS_DB')); $orderModel->street($contact_row['street']); $orderModel->city($contact_row['city']); $orderModel->state($contact_row['state']); $orderModel->zip($contact_row['zip']); $orderModel->phone($contact_row['phone']); $orderModel->altPhone($contact_row['email_2']); $orderModel->email($contact_row['email_1']); $orderModel->save(); $orderModel->specialOrderID($orderID); $orderModel->load(); $dbc->selectDB($this->config->get('OP_DB')); } } if ($custdata->load()) { $status_row['Type'] = $custdata->Type(); if ($status_row['Type'] == 'INACT') { $status_row['status'] = 'Inactive'; } elseif ($status_row['Type'] == 'INACT2') { $status_row['status'] = 'Inactive'; } elseif ($status_row['Type'] == 'TERM') { $status_row['status'] = 'Terminated'; } } } $prep = $dbc->prepare_statement("SELECT entry_date FROM {$TRANS}SpecialOrderHistory \n WHERE order_id=? AND entry_type='CONFIRMED'"); $confirm_date = $dbc->getValue($prep, array($orderID)); $callback = 2; $user = '******'; $orderDate = ""; $prep = $dbc->prepare_statement("SELECT datetime,numflag,mixMatch FROM \n {$TRANS}PendingSpecialOrder WHERE order_id=? AND trans_id=0"); $res = $dbc->exec_statement($prep, array($orderID)); if ($dbc->num_rows($res) > 0) { list($orderDate, $callback, $user) = $dbc->fetch_row($res); } $status = array(0 => "New, No Call", 3 => "New, Call", 1 => "Called/waiting", 2 => "Pending", 4 => "Placed", 5 => "Arrived"); $order_status = $orderModel->statusFlag(); $ret = ""; $ret .= sprintf('<input type="hidden" id="orderID" value="%d" />', $orderID); $ret .= '<div class="row form-inline"><div class="col-sm-4 text-left">'; $ret .= sprintf('<b>Owner Number</b>: <input type="text" size="6" id="memNum" value="%s" class="form-control price-field input-sm" />', $memNum == 0 ? '' : $memNum); $ret .= '<br />'; $ret .= '<b>Owner</b>: ' . ($status_row['Type'] == 'PC' ? 'Yes' : 'No'); $ret .= sprintf('<input type="hidden" id="isMember" value="%s" />', $status_row['Type']); $ret .= '<br />'; if (!empty($status_row['status'])) { $ret .= '<b>Account status</b>: ' . $status_row['status']; $ret .= '<br />'; } $ret .= '</div><div class="col-sm-4 text-center">'; if ($canEdit) { $ret .= '<b>Status</b>: '; $ret .= '<select id="orderStatus" class="form-control input-sm">'; foreach ($status as $k => $v) { $ret .= sprintf('<option %s value="%d">%s</option>', $k == $order_status ? 'selected' : '', $k, $v); } $ret .= '</select><p />'; } $ret .= '<b>Store</b>: '; $ret .= '<select id="orderStore" class="form-control input-sm">'; $ret .= '<option value="0">Choose...</option>'; $stores = new StoresModel($dbc); $ret .= $stores->toOptions($orderModel->storeID()); $ret .= '</select>'; $ret .= '</div><div class="col-sm-4 text-right">'; $ret .= "<a href=\"\" class=\"btn btn-default btn-sm done-btn\">Done</a>"; $username = FannieAuth::checkLogin(); $prints = array(); $cachepath = sys_get_temp_dir() . "/ordercache/"; if (file_exists("{$cachepath}{$username}.prints")) { $prints = unserialize(file_get_contents("{$cachepath}{$username}.prints")); } else { $fptr = fopen("{$cachepath}{$username}.prints", 'w'); fwrite($fptr, serialize($prints)); fclose($fptr); } $ret .= sprintf('<br />Queue tags <input type="checkbox" %s class="print-cb" />', isset($prints[$orderID]) ? 'checked' : '', $username, $orderID); $ret .= sprintf('<br /><a href="tagpdf.php?oids[]=%d" target="_tags%d">Print Now</a>', $orderID, $orderID); $ret .= '</div></div>'; $extra = ""; $extra .= '<div class="row"><div class="col-sm-6 text-left">'; $extra .= "<b>Taken by</b>: " . $user . "<br />"; $extra .= "<b>On</b>: " . date("M j, Y g:ia", strtotime($orderDate)) . "<br />"; $extra .= '</div><div class="col-sm-6 text-right form-inline">'; $extra .= '<b>Call to Confirm</b>: '; $extra .= '<select id="ctcselect" class="form-control input-sm">'; $extra .= '<option value="2"></option>'; if ($callback == 1) { $extra .= '<option value="1" selected>Yes</option>'; $extra .= '<option value="0">No</option>'; } else { if ($callback == 0) { $extra .= '<option value="1">Yes</option>'; $extra .= '<option value="0" selected>No</option>'; } else { $extra .= '<option value="1">Yes</option>'; $extra .= '<option value="0">No</option>'; } } $extra .= '</select><br />'; $extra .= '<span id="confDateSpan">' . (!empty($confirm_date) ? 'Confirmed ' . $confirm_date : 'Not confirmed') . "</span> "; $extra .= '<input type="checkbox" id="confirm-date" '; if (!empty($confirm_date)) { $extra .= "checked"; } $extra .= ' /><br />'; $extra .= "<a href=\"\" class=\"btn btn-default btn-sm done-btn\">Done</a>"; $extra .= '</div></div>'; $ret .= '<table class="table table-bordered">'; // names if (empty($names)) { $ret .= sprintf('<tr><th>First Name</th><td> <input type="text" id="t_firstName" name="fn" class="form-control input-sm conact-field" value="%s" /></td>', $orderModel->firstName()); $ret .= sprintf('<th>Last Name</th><td><input type="text" id="t_lastName" value="%s" name="ln" class="form-control input-sm contact-field" /></td>', $orderModel->lastName()); } else { $ret .= '<tr><th>Name</th><td colspan="2"><select id="s_personNum" class="form-control input-sm">'; foreach ($names as $p => $n) { $ret .= sprintf('<option value="%d" %s>%s %s</option>', $p, $p == $personNum ? 'selected' : '', $n[0], $n[1]); } $ret .= '</select></td>'; $ret .= '<td> </td>'; } $ret .= '<td colspan="4" class="form-inline">For Department: <select id="nDept" class="form-control input-sm contact-field" name="noteDept"> <option value="0">Choose...</option>'; $superQ = $dbc->prepare_statement("select superID,super_name from MasterSuperDepts\n where superID > 0\n group by superID,super_name\n order by super_name"); $superR = $dbc->exec_statement($superQ); while ($superW = $dbc->fetch_row($superR)) { $ret .= sprintf('<option value="%d" %s>%s</option>', $superW['superID'], $superW['superID'] == $orderModel->noteSuperID() ? 'selected' : '', $superW['super_name']); } $ret .= "</select></td></tr>"; // address $street = $orderModel->street(); $street2 = ''; if (strstr($street, "\n")) { list($street, $street2) = explode("\n", $street, 2); } $ret .= sprintf(' <tr> <th>Address</th> <td> <input type="text" id="t_addr1" value="%s" class="form-control input-sm contact-field" name="addr" /> </td> <th>E-mail</th> <td> <input type="text" id="t_email" value="%s" class="form-control input-sm contact-field" name="email" /> </td> <td rowspan="2" colspan="4"> <textarea id="nText" rows="5" cols="25" class="form-control input-sm contact-field" name="noteText" >%s</textarea> </td> </tr> <tr> <th>Addr (2)</th> <td> <input type="text" id="t_addr2" value="%s" class="form-control input-sm contact-field" name="addr2" /> </td> <th>City</th> <td> <input type="text" id="t_city" name="city" class="form-control input-sm contact-field" value="%s" size="10" /> </td> </tr> <tr> <th>Phone</th> <td> <input type="text" id="t_ph1" name="ph1" class="form-control input-sm contact-field" value="%s" /> </td> <th>Alt. Phone</th> <td> <input type="text" id="t_ph2" value="%s" name="ph2" class="form-control input-sm contact-field" /> </td> <th>State</th> <td> <input type="text" id="t_state" value="%s" size="2" class="form-control input-sm contact-field" name="state" /> </td> <th>Zip</th> <td> <input type="text" id="t_zip" value="%s" size="5" class="form-control input-sm contact-field" name="zip" /> </td> </tr>', $street, $orderModel->email(), $orderModel->notes(), $street2, $orderModel->city(), $orderModel->phone(), $orderModel->altPhone(), $orderModel->state(), $orderModel->zip()); $ret .= '</table>'; echo json_encode(array('customer' => $ret, 'footer' => $extra)); return false; }
$fnames = $_POST["hfname"]; $lnames = $_POST["hlname"]; for ($i = 0; $i < count($fnames); $i++) { $fnames[$i] = str_replace("'", "", $fnames[$i]); } for ($i = 0; $i < count($lnames); $i++) { $lnames[$i] = str_replace("'", "", $lnames[$i]); } $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] = "";