function SaveFormData($upc) { /* check if data was submitted */ if (FormLib::get('s_plu') === '') { return False; } $desc = FormLib::get('descript', ''); if (is_array($desc)) { $desc = array_pop($desc); } $longdesc = FormLib::get('s_longdesc', ''); if (trim($longdesc) !== '') { $desc = $longdesc; } $price = FormLib::get('price', 0); if (is_array($price)) { $price = array_pop($price); } $tare = FormLib::get('s_tare', 0); $shelf = FormLib::get('s_shelflife', 0); $bycount = FormLib::get('s_bycount', 0); $graphics = FormLib::get('s_graphics', 0); $type = FormLib::get('s_type', 'Random Weight'); $weight = $type == 'Random Weight' ? 0 : 1; $text = FormLib::get('s_text', ''); $align = FormLib::get('s_label', 'horizontal'); $netWeight = FormLib::get('s_netwt', 0); $label = \COREPOS\Fannie\API\item\ServiceScaleLib::attributesToLabel($align, $type == 'Fixed Weight' ? true : false, $graphics != 0 ? true : false); $dbc = $this->db(); // apostrophes might make a mess // double quotes definitely will // DGW quotes text fields w/o any escaping $desc = str_replace("'", "", $desc); $text = str_replace("'", "", $text); $desc = str_replace("\"", "", $desc); $text = str_replace("\"", "", $text); /** Safety check: A fixed-weight item sticked by the each flagged as scalable will interact with the register's quantity * upc functionality incorrectly */ if ($weight == 1 && $bycount == 1) { $p = new ProductsModel($dbc); $p->upc($upc); $p->store_id(1); if ($p->load()) { $p->Scale(0); $p->save(); } } $scaleItem = new ScaleItemsModel($dbc); $scaleItem->plu($upc); $action = 'ChangeOneItem'; if (!$scaleItem->load()) { // new record $action = "WriteOneItem"; } $scaleItem->price($price); $scaleItem->itemdesc($desc); $scaleItem->weight($type == 'Fixed Weight' ? 1 : 0); $scaleItem->bycount($bycount); $scaleItem->tare($tare); $scaleItem->shelflife($shelf); $scaleItem->text($text); $scaleItem->label($label); $scaleItem->graphics($graphics ? 121 : 0); $scaleItem->netWeight($netWeight); $scaleItem->save(); // extract scale PLU preg_match("/^002(\\d\\d\\d\\d)0/", $upc, $matches); $s_plu = $matches[1]; if ($s_plu == '0000') { preg_match("/^0020(\\d\\d\\d\\d)/", $upc, $matches); $s_plu = $matches[1]; } $item_info = array('RecordType' => $action, 'PLU' => $s_plu, 'Description' => $desc, 'Tare' => $tare, 'ShelfLife' => $shelf, 'Price' => $price, 'Label' => $label, 'ExpandedText' => $text, 'ByCount' => $bycount); if ($netWeight != 0) { $item_info['NetWeight'] = $netWeight; } if ($graphics) { $item_info['Graphics'] = 121; } // normalize type + bycount; they need to match if ($item_info['ByCount'] && $type == 'Random Weight') { $item_info['Type'] = 'By Count'; } else { if ($type == 'Fixed Weight') { $item_info['Type'] = 'Fixed Weight'; $item_info['ByCount'] = 1; } else { $item_info['Type'] = 'Random Weight'; $item_info['ByCount'] = 0; } } $scales = array(); $scaleIDs = FormLib::get('scaleID', array()); $model = new ServiceScalesModel($dbc); /** Send item to requested scales */ if (count($scaleIDs) > 0) { $chkMap = $dbc->prepare('SELECT upc FROM ServiceScaleItemMap WHERE serviceScaleID=? AND upc=?'); $addMap = $dbc->prepare('INSERT INTO ServiceScaleItemMap (serviceScaleID, upc) VALUES (?, ?)'); foreach ($scaleIDs as $scaleID) { $model->reset(); $model->serviceScaleID($scaleID); if (!$model->load()) { // scale doesn't exist continue; } $repr = array('host' => $model->host(), 'dept' => $model->scaleDeptName(), 'type' => $model->scaleType(), 'new' => false); $exists = $dbc->execute($chkMap, array($scaleID, $upc)); if ($dbc->num_rows($exists) == 0) { $repr['new'] = true; $dbc->execute($addMap, array($scaleID, $upc)); } $scales[] = $repr; } HobartDgwLib::writeItemsToScales($item_info, $scales); EpScaleLib::writeItemsToScales($item_info, $scales); } /** Delete item from scales if that option was unchecked */ $mapP = $dbc->prepare(' SELECT serviceScaleID FROM ServiceScaleItemMap WHERE upc=?'); $mapR = $dbc->execute($mapP, array($upc)); $delP = $dbc->prepare(' DELETE FROM ServiceScaleItemMap WHERE serviceScaleID=? AND upc=?'); if ($mapR && $dbc->numRows($mapR)) { $scales = array(); while ($mapW = $dbc->fetchRow($mapR)) { if (in_array($mapW['serviceScaleID'], $scaleIDs)) { // item sent to that scale continue; } $model->reset(); $model->serviceScaleID($mapW['serviceScaleID']); if (!$model->load()) { // scale doesn't exist continue; } $repr = array('host' => $model->host(), 'dept' => $model->scaleDeptName(), 'type' => $model->scaleType(), 'new' => false); $scales[] = $repr; $dbc->execute($delP, array($mapW['serviceScaleID'], $upc)); } if (count($scales) > 0) { HobartDgwLib::deleteItemsFromScales($item_info['PLU'], $scales); } } }
private function getScales($ids) { $model = new ServiceScalesModel($this->connection); $scales = array(); foreach ($ids as $scaleID) { $model->reset(); $model->serviceScaleID($scaleID); if (!$model->load()) { // scale doesn't exist continue; } $repr = array('host' => $model->host(), 'dept' => $model->scaleDeptName(), 'type' => $model->scaleType(), 'new' => false); $scales[] = $repr; } return $scales; }
function post_u_view() { global $FANNIE_OP_DB, $FANNIE_URL; $this->add_script($FANNIE_URL . '/src/javascript/jquery.js'); $this->add_css_file($FANNIE_URL . '/src/style.css'); $ret = ''; $ret .= '<form action="SyncFromSearch.php" method="post">'; $scales = new ServiceScalesModel(FannieDB::get($FANNIE_OP_DB)); $ret .= '<div class="panel panel-default"> <div class="panel-heading">Scales</div> <div class="panel-body">'; foreach ($scales->find('description') as $scale) { $ret .= sprintf('<input type="checkbox" class="scaleID" name="scaleID[]" id="scaleID%d" value="%d" /> <label for="scaleID%d">%s</label><br />', $scale->serviceScaleID(), $scale->serviceScaleID(), $scale->serviceScaleID(), $scale->description()); } $ret .= '</div></div>'; $ret .= '<p><button type="submit" name="sendall" value="1" class="btn btn-default">Sync All Items</button></p>'; $ret .= '<div id="alert-area"></div>'; $ret .= '<table class="table">'; $ret .= '<tr> <th>UPC</th> <th>Description</th> <th>Price</th> <th>Last Changed</th> <th>Send Now</th> </tr>'; $model = new ScaleItemsModel(FannieDB::get($FANNIE_OP_DB)); foreach ($this->upcs as $upc) { $model->plu($upc); if (!$model->load()) { continue; } $ret .= sprintf('<tr id="row%s"> <td>%s</td> <td>%s</td> <td>%.2f</td> <td>%s</td> <td><button type="button" class="btn btn-default" onclick="sendOne(\'%s\'); return false;">Sync Item</button></td> <input type="hidden" name="upcs[]" value="%s" /> </tr>', $model->plu(), $model->plu(), $model->mergeDescription(), $model->price(), $model->modified(), $model->plu(), $model->plu()); } $ret .= '</table>'; $ret .= '</form>'; return $ret; }
public function get_view() { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $scales = new ServiceScalesModel($dbc); $supers = array(); $result = $dbc->query('SELECT superID, super_name FROM superDeptNames ORDER BY super_name'); while ($row = $dbc->fetch_row($result)) { $supers[$row['superID']] = $row['super_name']; } $ret = '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">'; $ret .= '<table class="table"> <tr><th>Description</th><th>Host</th><th>Type</th><th>Scale Dept.</th><th>POS Super Dept</th> <th>Store # (EP)</th><th>Dept # (EP)</th><th>Address # (EP)</th> </tr>'; foreach ($scales->find('description') as $scale) { $ret .= sprintf('<tr> <input type="hidden" name="id[]" value="%d" /> <td><input type="text" name="description[]" class="form-control" value="%s" /></td> <td><input type="text" name="host[]" class="form-control" value="%s" /></td> <td><input type="text" name="type[]" class="form-control" value="%s" /></td> <td><input type="text" name="scaleDept[]" class="form-control" value="%s" /></td> ', $scale->serviceScaleID(), $scale->description(), $scale->host(), $scale->scaleType(), $scale->scaleDeptName()); $ret .= '<td><select name="super[]" class="form-control"> <option value="">None</option>'; foreach ($supers as $id => $name) { $ret .= sprintf('<option %s value="%d">%s</option>', $scale->superID() !== null && $scale->superID() == $id ? 'selected' : '', $id, $name); } $ret .= '</select></td>'; $ret .= sprintf(' <td><input type="text" name="store-no[]" class="form-control" value="%d" /></td> <td><input type="text" name="dept-no[]" class="form-control" value="%d" /></td> <td><input type="text" name="address-no[]" class="form-control" value="%d" /></td>', $scale->epStoreNo(), $scale->epDeptNo(), $scale->epScaleAddress()); $ret .= '</tr>'; } $ret .= '</table>'; $ret .= '<p><button type="submit" class="btn btn-default">Save Changes</button>'; $ret .= ' '; $ret .= '<button type="button" class="btn btn-default" onclick="location=\'ScaleEditor.php?new=true\';return false;">Add Scale</button> </p>'; $ret .= '</form>'; return $ret; }