function process_file($linedata) { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $dn_index = $this->get_column_index('dept_no'); $desc_index = $this->get_column_index('desc'); $margin_index = $this->get_column_index('margin'); $tax_index = $this->get_column_index('tax'); $fs_index = $this->get_column_index('fs'); // prepare statements $marP = $dbc->prepare_statement("INSERT INTO deptMargin (dept_ID,margin) VALUES (?,?)"); $scP = $dbc->prepare_statement("INSERT INTO deptSalesCodes (dept_ID,salesCode) VALUES (?,?)"); $model = new DepartmentsModel($dbc); foreach ($linedata as $line) { // get info from file and member-type default settings // if applicable $dept_no = $line[$dn_index]; $desc = $line[$desc_index]; $margin = $margin_index !== False ? $line[$margin_index] : 0; if ($margin > 1) { $margin /= 100.0; } $tax = $tax_index !== False ? $line[$tax_index] : 0; $fs = $fs_index !== False ? $line[$fs_index] : 0; if (!is_numeric($dept_no)) { continue; } // skip header/blank rows if (strlen($desc) > 30) { $desc = substr($desc, 0, 30); } $model->reset(); $model->dept_no($dept_no); $model->dept_name($desc); $model->dept_tax($tax); $model->dept_fs($fs); $model->dept_limit(50); $model->dept_minimum(0.01); $model->dept_discount(1); $model->dept_see_id(0); $model->modified(date('Y-m-d H:i:s')); $model->modifiedby(1); $model->margin($margin); $model->salesCode($dept_no); $imported = $model->save(); if ($imported) { $this->stats['imported']++; } else { $this->stats['errors'][] = 'Error imported department #' . $dept_no; } if ($dbc->tableExists('deptMargin')) { $insR = $dbc->exec_statement($marP, array($dept_no, $margin)); } if ($dbc->tableExists('deptSalesCodes')) { $insR = $dbc->exec_statement($scP, array($dept_no, $dept_no)); } } return true; }
function MarginFS($upc, $cost, $deptID) { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $price = 'None'; $prod = new ProductsModel($dbc); $prod->upc($upc); if ($prod->load()) { $price = $prod->normal_price(); } $dm = 'Unknown'; $dept = new DepartmentsModel($dbc); $dept->dept_no($deptID); if ($dept->load()) { $dm = $dept->margin(); } if ((empty($dm) || $dm == 'Unknown') && $dbc->tableExists('deptMargin')) { $prep = $dbc->prepare_statement("SELECT margin FROM deptMargin WHERE dept_ID=?"); $dm = $dbc->exec_statement($prep, array($deptID)); if ($dbc->num_rows($dm) > 0) { $row = $dbc->fetch_row($dm); $dm = $dm['margin']; } } $ret = "Desired margin on this department is "; if ($dm == "Unknown") { $ret .= $dm; } else { $ret .= sprintf("%.2f%%", $dm * 100); } $ret .= "<br />"; $actual = 0; if ($price != 0) { $actual = ($price - $cost) / $price; } if ($actual > $dm && is_numeric($dm) || !is_numeric($dm)) { $ret .= sprintf("<span style=\"color:green;\">Current margin on this item is %.2f%%<br />", $actual * 100); } else { if (!is_numeric($price)) { $ret .= "<span style=\"color:green;\">No price has been saved for this item<br />"; } else { $ret .= sprintf("<span style=\"color:red;\">Current margin on this item is %.2f%%</span><br />", $actual * 100); $srp = getSRP($cost, $dm); $ret .= sprintf("Suggested price: \$%.2f ", $srp); $ret .= sprintf("(<a href=\"\" onclick=\"setPrice(%.2f); return false;\">Use this price</a>)", $srp); } } echo $ret; }
protected function hookAddColumnsalesCode() { if ($this->connection->table_exists('deptSalesCodes')) { $dataR = $this->connection->query('SELECT dept_ID, salesCode FROM deptSalesCodes'); $tempModel = new DepartmentsModel($this->connection); while ($dataW = $this->connection->fetch_row($dataR)) { $tempModel->reset(); $tempModel->dept_no($dataW['dept_ID']); if ($tempModel->load()) { $tempModel->salesCode($dataW['salesCode']); $tempModel->save(); } } } }
public function post_start_number_handler() { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $dept_no = FormLib::get('department', 0); $desc = FormLib::get('description', 'NEW PLU'); if (empty($desc)) { $desc = 'NEW PLU'; } $dept = new DepartmentsModel($dbc); $dept->dept_no($dept_no); $dept->load(); $model = new ProductsModel($dbc); $model->normal_price(0); $model->pricemethod(0); $model->quantity(0); $model->groupprice(0); $model->special_price(0); $model->specialpricemethod(0); $model->specialquantity(0); $model->specialgroupprice(0); $model->advertised(0); $model->tareweight(0); $model->start_date(''); $model->end_date(''); $model->discounttype(0); $model->wicable(0); $model->inUse(1); $model->tax($dept->dept_tax()); $model->foodstamp($dept->dept_fs()); $model->discount($dept->dept_discount()); $model->department($dept_no); for ($i = 0; $i < $this->number; $i++) { $upc = BarcodeLib::padUPC($this->start + $i); $model->upc($upc); $model->store_id(1); $model->description($desc . ' ' . ($i + 1)); $model->save(); } header('Location: ItemEditorPage.php?searchupc=' . $this->start); return false; }
private function ajax_save_dept() { global $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_OP_DB); $id = FormLib::get_form_value('did', 0); $name = FormLib::get_form_value('name', ''); $tax = FormLib::get_form_value('tax', 0); $fs = FormLib::get_form_value('fs', 0); $disc = FormLib::get_form_value('disc', 1); $min = FormLib::get_form_value('min', 0.01); $max = FormLib::get_form_value('max', 50.0); $margin = FormLib::get_form_value('margin', 0); $margin = (double) $margin / 100.0; $pcode = FormLib::get_form_value('pcode', $id); if (!is_numeric($pcode)) { $pcode = (int) $id; } $new = FormLib::get_form_value('new', 0); $model = new DepartmentsModel($dbc); $model->dept_no($id); $model->dept_name($name); $model->dept_tax($tax); $model->dept_fs($fs); $model->dept_discount($disc); $model->dept_minimum($min); $model->dept_limit($max); $model->modified(date('Y-m-d H:i:s')); $model->margin($margin); $model->salesCode($pcode); if ($new == 1) { $model->modifiedby(1); $model->dept_see_id(0); } $saved = $model->save(); if ($new == 1) { if ($saved === False) { echo 'Error: could not create department'; return; } $superP = $dbc->prepare_statement('INSERT INTO superdepts (superID,dept_ID) VALUES (0,?)'); $superR = $dbc->exec_statement($superP, array($id)); } else { if ($saved === False) { echo 'Error: could not save changes'; return; } } if ($dbc->tableExists('deptMargin')) { $chkM = $dbc->prepare_statement('SELECT dept_ID FROM deptMargin WHERE dept_ID=?'); $mR = $dbc->exec_statement($chkM, array($id)); if ($dbc->num_rows($mR) > 0) { $up = $dbc->prepare_statement('UPDATE deptMargin SET margin=? WHERE dept_ID=?'); $dbc->exec_statement($up, array($margin, $id)); } else { $ins = $dbc->prepare_statement('INSERT INTO deptMargin (dept_ID,margin) VALUES (?,?)'); $dbc->exec_statement($ins, array($id, $margin)); } } if ($dbc->tableExists('deptSalesCodes')) { $chkS = $dbc->prepare_statement('SELECT dept_ID FROM deptSalesCodes WHERE dept_ID=?'); $rS = $dbc->exec_statement($chkS, array($id)); if ($dbc->num_rows($rS) > 0) { $up = $dbc->prepare_statement('UPDATE deptSalesCodes SET salesCode=? WHERE dept_ID=?'); $dbc->exec_statement($up, array($pcode, $id)); } else { $ins = $dbc->prepare_statement('INSERT INTO deptSalesCodes (dept_ID,salesCode) VALUES (?,?)'); $dbc->exec_statement($ins, array($id, $pcode)); } } $json = array(); $json['did'] = $id; $json['msg'] = 'Department ' . $id . ' - ' . $name . ' Saved'; echo json_encode($json); }
/** Do whatever the service is supposed to do. Should override this. @param $args array of data @return an array of data */ public function run($args = array()) { $ret = array(); if (!property_exists($args, 'type')) { // missing required arguments $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters'); return $ret; } // validate additional arguments switch (strtolower($args->type)) { case 'settings': if (!property_exists($args, 'dept_no')) { // missing required arguments $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters'); return $ret; } break; case 'children': if (!property_exists($args, 'superID') && !property_exists($args, 'dept_no')) { // missing required arguments $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters'); return $ret; } if (property_exists($args, 'superID') && is_array($args->superID) && count($args->superID) != 2) { // range must specify exactly two superIDs $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters'); return $ret; } if (property_exists($args, 'dept_no') && is_array($args->dept_no) && count($args->dept_no) != 2) { // range must specify exactly two dept_nos $et['error'] = array('code' => -32602, 'message' => 'Invalid parameters'); return $ret; } break; default: // unknown type argument $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters'); return $ret; } // lookup results $dbc = \FannieDB::getReadOnly(\FannieConfig::factory()->get('OP_DB')); switch (strtolower($args->type)) { case 'settings': $model = new DepartmentsModel($dbc); $model->dept_no($args->dept_no); $model->load(); $ret['tax'] = $model->dept_tax(); $ret['fs'] = $model->dept_fs(); $ret['discount'] = $model->dept_discount(); $ret['seeID'] = $model->dept_see_id(); $ret['margin'] = $model->margin(); return $ret; case 'children': $query = ''; $params = array(); if (property_exists($args, 'dept_no')) { $query = ' SELECT s.subdept_no AS id, s.subdept_name AS name FROM departments AS d INNER JOIN subdepts AS s ON d.dept_no=s.dept_ID '; if (property_exists($args, 'superID') && is_numeric($args->superID)) { $query .= ' INNER JOIN superdepts AS a ON d.dept_no=a.dept_ID '; } if (is_array($args->dept_no)) { $query .= ' WHERE d.dept_no BETWEEN ? AND ? '; $params[] = $args->dept_no[0]; $params[] = $args->dept_no[1]; } else { $query .= ' WHERE d.dept_no = ? '; $params[] = $args->dept_no; } if (property_exists($args, 'superID') && is_numeric($args->superID)) { $query .= ' AND a.superID = ? '; $params[] = $args->superID; } $query .= ' ORDER BY s.subdept_no'; } else { $query = ' SELECT d.dept_no AS id, d.dept_name AS name FROM superdepts AS s INNER JOIN departments AS d ON d.dept_no=s.dept_ID '; if (is_array($args->superID)) { $query .= ' WHERE s.superID BETWEEN ? AND ? '; $params[] = $args->superID[0]; $params[] = $args->superID[1]; } else { $query .= ' WHERE s.superID = ? '; $params[] = $args->superID; } $query .= ' ORDER BY d.dept_no'; // support meta-options for all departments if (!is_array($args->superID) && $args->superID < 0) { if ($args->superID == -1) { $query = ' SELECT d.dept_no AS id, d.dept_name AS name FROM departments AS d ORDER BY d.dept_no'; $params = array(); } elseif ($args->superID == -2) { $query = ' SELECT d.dept_no AS id, d.dept_name AS name FROM departments AS d INNER JOIN MasterSuperDepts AS m ON d.dept_no=m.dept_ID WHERE m.superID <> 0 ORDER BY d.dept_no'; $params = array(); } } } $prep = $dbc->prepare($query); $res = $dbc->execute($prep, $params); while ($w = $dbc->fetch_row($res)) { $ret[] = array('id' => $w['id'], 'name' => $w['name']); } return $ret; } }
/** Add an open ring record to dtransactions on the backend @param $connection [SQLManager] database connection @param $department [integer] department number $param $amount [number] ring amount @param $trans_no [integer] transaction number (dtransactions.trans_no) @param $params [array] of column_name => value If emp_no and register_no values are not specified, the defaults are the configuration settings FANNIE_EMP_NO and FANNIE_REGISTER_NO. The following columns are automatically calculated based on department number and amount: - upc - description - trans_type - trans_status - unitPrice - total - regPrice - quantity - ItemQtty Negative amounts result in a refund trans_status This method calls DTrans::addItem() so columns datetime and trans_id are also automatically assigned. */ public static function addOpenRing(SQLManager $connection, $department, $amount, $trans_no, $params = array()) { $config = FannieConfig::factory(); $model = new DepartmentsModel($connection); $model->whichDB($config->get('OP_DB')); $model->dept_no($department); $model->load(); $params['trans_type'] = 'D'; $params['department'] = $department; $params['unitPrice'] = $amount; $params['total'] = $amount; $params['regPrice'] = $amount; $params['quantity'] = 1; $params['ItemQtty'] = 1; if ($amount < 0) { $params['quantity'] = -1; $params['trans_status'] = 'R'; } $params['description'] = $model->dept_name(); $params['upc'] = abs($amount) . 'DP' . $department; return self::addItem($connection, $trans_no, $params); }
public function showEditForm($upc, $display_mode = 1, $expand_mode = 1) { $FANNIE_PRODUCT_MODULES = FannieConfig::config('PRODUCT_MODULES', array()); $upc = BarcodeLib::padUPC($upc); $trimmed = ltrim($upc, '0'); $barcode_type = ''; if (strlen($trimmed) == '12') { // probably EAN-13 w/o check digi $barcode_type = 'EAN'; } elseif (strlen($trimmed) == 11 && $trimmed[0] == '2') { // variable price UPC $barcode_type = 'Scale'; } elseif (strlen($trimmed) <= 11 && strlen($trimmed) >= 6) { // probably UPC-A w/o check digit $barcode_type = 'UPC'; } else { $barcode_type = 'PLU'; } $ret = '<div id="BaseItemFieldset" class="panel panel-default">'; $dbc = $this->db(); $q = ' SELECT p.description, p.pricemethod, p.normal_price, p.cost, CASE WHEN p.size IS NULL OR p.size=\'\' OR p.size=\'0\' AND v.size IS NOT NULL THEN v.size ELSE p.size END AS size, p.unitofmeasure, p.modified, p.last_sold, p.special_price, p.end_date, p.subdept, p.department, p.tax, p.foodstamp, p.scale, p.qttyEnforced, p.discount, p.line_item_discountable, p.brand AS manufacturer, x.distributor, u.description as ldesc, p.default_vendor_id, v.units AS caseSize, v.sku, p.inUse, p.idEnforced, p.local, p.deposit, p.discounttype, p.wicable, p.store_id FROM products AS p LEFT JOIN prodExtra AS x ON p.upc=x.upc LEFT JOIN productUser AS u ON p.upc=u.upc LEFT JOIN vendorItems AS v ON p.upc=v.upc AND p.default_vendor_id = v.vendorID WHERE p.upc=?'; $p_def = $dbc->tableDefinition('products'); if (!isset($p_def['last_sold'])) { $q = str_replace('p.last_sold', 'NULL as last_sold', $q); } $p = $dbc->prepare($q); $r = $dbc->exec_statement($p, array($upc)); $store_model = new StoresModel($dbc); $store_model->hasOwnItems(1); $stores = array(); foreach ($store_model->find('storeID') as $obj) { $stores[$obj->storeID()] = $obj; } $items = array(); $rowItem = array(); $prevUPC = False; $nextUPC = False; $likeCode = False; if ($dbc->num_rows($r) > 0) { //existing item while ($w = $dbc->fetch_row($r)) { $items[$w['store_id']] = $w; $rowItem = $w; } /** Lookup default vendor & normalize */ $product = new ProductsModel($dbc); $product->upc($upc); $product->load(); $vendor = new VendorsModel($dbc); $vendor->vendorID($product->default_vendor_id()); if ($vendor->load()) { $rowItem['distributor'] = $vendor->vendorName(); } /* find previous and next items in department */ $pnP = $dbc->prepare_statement('SELECT upc FROM products WHERE department=? ORDER BY upc'); $pnR = $dbc->exec_statement($pnP, array($product->department())); $passed_it = False; while ($pnW = $dbc->fetch_row($pnR)) { if (!$passed_it && $upc != $pnW[0]) { $prevUPC = $pnW[0]; } else { if (!$passed_it && $upc == $pnW[0]) { $passed_it = True; } else { if ($passed_it) { $nextUPC = $pnW[0]; break; } } } } $lcP = $dbc->prepare_statement('SELECT likeCode FROM upcLike WHERE upc=?'); $lcR = $dbc->exec_statement($lcP, array($upc)); if ($dbc->num_rows($lcR) > 0) { $lcW = $dbc->fetch_row($lcR); $likeCode = $lcW['likeCode']; } if (FannieConfig::config('STORE_MODE') == 'HQ') { $default_id = array_keys($items); $default_id = $default_id[0]; $default_item = $items[$default_id]; foreach ($stores as $id => $info) { if (!isset($items[$id])) { $items[$id] = $default_item; } } } } else { // default values for form fields $rowItem = array('description' => '', 'normal_price' => 0, 'pricemethod' => 0, 'size' => '', 'unitofmeasure' => '', 'modified' => '', 'ledesc' => '', 'manufacturer' => '', 'distributor' => '', 'default_vendor_id' => 0, 'department' => 0, 'subdept' => 0, 'tax' => 0, 'foodstamp' => 0, 'scale' => 0, 'qttyEnforced' => 0, 'discount' => 1, 'line_item_discountable' => 1, 'caseSize' => '', 'sku' => '', 'inUse' => 1, 'idEnforced' => 0, 'local' => 0, 'deposit' => 0, 'cost' => 0, 'discounttype' => 0, 'wicable' => 0); /** Check for entries in the vendorItems table to prepopulate fields for the new item */ $vendorP = "\n SELECT \n i.description,\n i.brand as manufacturer,\n i.cost,\n v.vendorName as distributor,\n d.margin,\n i.vendorID,\n i.srp,\n i.size,\n i.units,\n i.sku,\n i.vendorID as default_vendor_id\n FROM vendorItems AS i \n LEFT JOIN vendors AS v ON i.vendorID=v.vendorID\n LEFT JOIN vendorDepartments AS d ON i.vendorDept=d.deptID AND d.vendorID=i.vendorID\n WHERE i.upc=?"; $args = array($upc); $vID = FormLib::get_form_value('vid', ''); if ($vID !== '') { $vendorP .= ' AND i.vendorID=?'; $args[] = $vID; } $vendorP .= ' ORDER BY i.vendorID'; $vendorP = $dbc->prepare_statement($vendorP); $vendorR = $dbc->exec_statement($vendorP, $args); if ($dbc->num_rows($vendorR) > 0) { $v = $dbc->fetch_row($vendorR); $ret .= "<div><i>This product is in the " . $v['distributor'] . " catalog. Values have\n been filled in where possible</i></div>"; $rowItem['description'] = $v['description']; $rowItem['manufacturer'] = $v['manufacturer']; $rowItem['cost'] = $v['cost']; $rowItem['distributor'] = $v['distributor']; $rowItem['normal_price'] = $v['srp']; $rowItem['default_vendor_id'] = $v['vendorID']; $rowItem['size'] = $v['size']; $rowItem['caseSize'] = $v['units']; $rowItem['sku'] = $v['sku']; while ($v = $dbc->fetch_row($vendorR)) { $ret .= sprintf('This product is also in <a href="?searchupc=%s&vid=%d">%s</a><br />', $upc, $v['vendorID'], $v['distributor']); } } /** Look for items with a similar UPC to guess what department this item goes in. If found, use department settings to fill in some defaults */ $rowItem['department'] = 0; $search = substr($upc, 0, 12); $searchP = $dbc->prepare('SELECT department FROM products WHERE upc LIKE ?'); while (strlen($search) >= 8) { $searchR = $dbc->execute($searchP, array($search . '%')); if ($dbc->numRows($searchR) > 0) { $searchW = $dbc->fetchRow($searchR); $rowItem['department'] = $searchW['department']; break; } $search = substr($search, 0, strlen($search) - 1); } /** If no match is found, pick the most commonly used department */ if ($rowItem['department'] == 0) { $commonQ = ' SELECT department, COUNT(*) FROM products GROUP BY department ORDER BY COUNT(*) DESC'; $commonR = $dbc->query($commonQ); if ($commonR && $dbc->numRows($commonR)) { $commonW = $dbc->fetchRow($commonR); $rowItem['department'] = $commonW['department']; } } /** Get defaults for chosen department */ $dmodel = new DepartmentsModel($dbc); $dmodel->dept_no($rowItem['department']); if ($dmodel->load()) { $rowItem['tax'] = $dmodel->dept_tax(); $rowItem['foodstamp'] = $dmodel->dept_fs(); $rowItem['discount'] = $dmodel->dept_discount(); } foreach ($stores as $id => $obj) { $items[$id] = $rowItem; } } $ret .= '<div class="panel-heading">'; if ($prevUPC) { $ret .= ' <a class="btn btn-default btn-xs small" href="ItemEditorPage.php?searchupc=' . $prevUPC . '" title="Previous item in this department"> <span class="glyphicon glyphicon-chevron-left"></span></a> '; } $ret .= '<strong>UPC</strong> <span class="text-danger">'; switch ($barcode_type) { case 'EAN': case 'UPC': $ret .= substr($upc, 0, 3) . '<a class="text-danger iframe fancyboxLink" href="../reports/ProductLine/ProductLineReport.php?prefix=' . substr($upc, 3, 5) . '" title="Product Line">' . '<strong>' . substr($upc, 3, 5) . '</strong>' . '</a>' . substr($upc, 8); break; case 'Scale': $ret .= substr($upc, 0, 3) . '<strong>' . substr($upc, 3, 4) . '</strong>' . substr($upc, 7); break; case 'PLU': $trimmed = ltrim($upc, '0'); if (strlen($trimmed) < 13) { $ret .= str_repeat('0', 13 - strlen($trimmed)) . '<strong>' . $trimmed . '</strong>'; } else { $ret .= $upc; } break; default: $ret .= $upc; } $ret .= '</span>'; $ret .= '<input type="hidden" id="upc" name="upc" value="' . $upc . '" />'; if ($nextUPC) { $ret .= ' <a class="btn btn-default btn-xs small" href="ItemEditorPage.php?searchupc=' . $nextUPC . '" title="Next item in this department"> <span class="glyphicon glyphicon-chevron-right"></span></a>'; } $ret .= ' <label style="color:darkmagenta;">Modified</label> <span style="color:darkmagenta;">' . $rowItem['modified'] . '</span>'; $ret .= ' | <label style="color:darkmagenta;">Last Sold</label> <span style="color:darkmagenta;">' . (empty($rowItem['last_sold']) ? 'n/a' : $rowItem['last_sold']) . '</span>'; $ret .= '</div>'; // end panel-heading $ret .= '<div class="panel-body">'; $new_item = false; if ($dbc->num_rows($r) == 0) { // new item $ret .= "<div class=\"alert alert-warning\">Item not found. You are creating a new one.</div>"; $new_item = true; } $nav_tabs = '<ul id="store-tabs" class="nav nav-tabs small" role="tablist">'; $ret .= '{{nav_tabs}}<div class="tab-content">'; $active_tab = true; foreach ($items as $store_id => $rowItem) { $tabID = 'store-tab-' . $store_id; $store_description = 'n/a'; if (isset($stores[$store_id])) { $store_description = $stores[$store_id]->description(); } $nav_tabs .= '<li role="presentation" ' . ($active_tab ? 'class="active"' : '') . '>' . '<a href="#' . $tabID . '" aria-controls="' . $tabID . '" ' . 'onclick="$(\'.tab-content .chosen-select:visible\').chosen();"' . 'role="tab" data-toggle="tab">' . $store_description . '</a></li>'; $ret .= '<div role="tabpanel" class="tab-pane' . ($active_tab ? ' active' : '') . '" id="' . $tabID . '">'; $ret .= '<input type="hidden" class="store-id" name="store_id[]" value="' . $store_id . '" />'; $ret .= '<table class="table table-bordered">'; $limit = 30 - strlen(isset($rowItem['description']) ? $rowItem['description'] : ''); $ret .= <<<HTML <tr> <th class="text-right">Description</th> <td colspan="5"> <div class="input-group" style="width:100%;"> <input type="text" maxlength="30" class="form-control syncable-input" required name="descript[]" id="descript" value="{{description}}" onkeyup="\$(this).next().html(30-(this.value.length));" /> <span class="input-group-addon">{{limit}}</span> </div> </td> <th class="text-right">Cost</th> <td> <div class="input-group"> <span class="input-group-addon">\$</span> <input type="text" id="cost{{store_id}}" name="cost[]" class="form-control price-field cost-input syncable-input" value="{{cost}}" data-store-id="{{store_id}}" onkeydown="if (typeof nosubmit == 'function') nosubmit(event);" onkeyup="if (typeof nosubmit == 'function') nosubmit(event);" onchange="\$('.default_vendor_cost').val(this.value);" /> </div> </td> <th class="text-right">Price</th> <td> <div class="input-group"> <span class="input-group-addon">\$</span> <input type="text" id="price{{store_id}}" name="price[]" class="form-control price-field price-input syncable-input" data-store-id="{{store_id}}" required value="{{normal_price}}" /> </div> </td> </tr> HTML; $ret = str_replace('{{description}}', $rowItem['description'], $ret); $ret = str_replace('{{limit}}', $limit, $ret); $ret = str_replace('{{cost}}', sprintf('%.2f', $rowItem['cost']), $ret); $ret = str_replace('{{normal_price}}', sprintf('%.2f', $rowItem['normal_price']), $ret); // no need to display this field twice if (!isset($FANNIE_PRODUCT_MODULES['ProdUserModule'])) { $ret .= ' <tr> <th>Long Desc.</th> <td colspan="5"> <input type="text" size="60" name="puser_description" maxlength="255" ' . (!$active_tab ? ' disabled ' : '') . ' value="' . $rowItem['ldesc'] . '" class="form-control" /> </td> </tr>'; } $ret .= ' <tr> <th class="text-right">Brand</th> <td colspan="5"> <input type="text" name="manufacturer[]" class="form-control input-sm brand-field syncable-input" value="' . $rowItem['manufacturer'] . '" /> </td>'; /** Check products.default_vendor_id to see if it is a valid reference to the vendors table */ $normalizedVendorID = false; if (isset($rowItem['default_vendor_id']) && $rowItem['default_vendor_id'] != 0) { $normalizedVendor = new VendorsModel($dbc); $normalizedVendor->vendorID($rowItem['default_vendor_id']); if ($normalizedVendor->load()) { $normalizedVendorID = $normalizedVendor->vendorID(); } } /** Use a <select> box if the current vendor corresponds to a valid entry OR if no vendor entry exists. Only allow free text if it's already in place */ $ret .= ' <th class="text-right">Vendor</th> '; if ($normalizedVendorID || empty($rowItem['distributor'])) { $ret .= '<td colspan="3" class="form-inline"><select name="distributor[]" class="chosen-select form-control vendor_field syncable-input" onchange="vendorChanged(this.value);">'; $ret .= '<option value="0">Select a vendor</option>'; $vendors = new VendorsModel($dbc); foreach ($vendors->find('vendorName') as $v) { $ret .= sprintf('<option %s>%s</option>', $v->vendorID() == $normalizedVendorID ? 'selected' : '', $v->vendorName()); } $ret .= '</select>'; } else { $ret .= "<td colspan=\"3\"><input type=text name=distributor[] size=8 value=\"" . (isset($rowItem['distributor']) ? $rowItem['distributor'] : "") . "\" class=\"form-control vendor-field syncable-input\" />"; } $ret .= ' <button type="button" title="Create new vendor" class="btn btn-default btn-sm newVendorButton"> <span class="glyphicon glyphicon-plus"></span></button>'; $ret .= '</td></tr>'; // end row if (isset($rowItem['discounttype']) && $rowItem['discounttype'] != 0) { /* show sale info */ $batchP = $dbc->prepare_statement("\n SELECT b.batchName, \n b.batchID \n FROM batches AS b \n LEFT JOIN batchList as l on b.batchID=l.batchID \n WHERE '" . date('Y-m-d') . "' BETWEEN b.startDate AND b.endDate \n AND (l.upc=? OR l.upc=?)"); $batchR = $dbc->exec_statement($batchP, array($upc, 'LC' . $likeCode)); $batch = array('batchID' => 0, 'batchName' => "Unknown"); if ($dbc->num_rows($batchR) > 0) { $batch = $dbc->fetch_row($batchR); } $ret .= '<td class="alert-success" colspan="8">'; $ret .= sprintf("<strong>Sale Price:</strong>\n %.2f (<em>Batch: <a href=\"%sbatches/newbatch/EditBatchPage.php?id=%d\">%s</a></em>)", $rowItem['special_price'], FannieConfig::config('URL'), $batch['batchID'], $batch['batchName']); list($date, $time) = explode(' ', $rowItem['end_date']); $ret .= "<strong>End Date:</strong>\n {$date} \n (<a href=\"EndItemSale.php?id={$upc}\">Unsale Now</a>)"; $ret .= '</td>'; } $supers = array(); $depts = array(); $subs = array(); $range_limit = FannieAuth::validateUserLimited('pricechange'); $deptQ = ' SELECT dept_no, dept_name, subdept_no, subdept_name, s.dept_ID, MIN(m.superID) AS superID FROM departments AS d LEFT JOIN subdepts AS s ON d.dept_no=s.dept_ID LEFT JOIN superdepts AS m ON d.dept_no=m.dept_ID '; if (is_array($range_limit) && count($range_limit) == 2) { $deptQ .= ' WHERE m.superID BETWEEN ? AND ? '; } else { $range_limit = array(); } $deptQ .= ' GROUP BY d.dept_no, d.dept_name, s.subdept_no, s.subdept_name, s.dept_ID ORDER BY d.dept_no, s.subdept_name'; $p = $dbc->prepare($deptQ); $r = $dbc->execute($p, $range_limit); $superID = ''; while ($w = $dbc->fetch_row($r)) { if (!isset($depts[$w['dept_no']])) { $depts[$w['dept_no']] = $w['dept_name']; } if ($w['dept_no'] == $rowItem['department']) { $superID = $w['superID']; } if (!isset($supers[$w['superID']])) { $supers[$w['superID']] = array(); } $supers[$w['superID']][] = $w['dept_no']; if ($w['subdept_no'] == '') { continue; } if (!isset($subs[$w['dept_ID']])) { $subs[$w['dept_ID']] = ''; } $subs[$w['dept_ID']] .= sprintf('<option %s value="%d">%d %s</option>', $w['subdept_no'] == $rowItem['subdept'] ? 'selected' : '', $w['subdept_no'], $w['subdept_no'], $w['subdept_name']); } $ret .= '<tr> <th class="text-right">Dept</th> <td colspan="7" class="form-inline"> <select id="super-dept{{store_id}}" name="super[]" class="form-control chosen-select syncable-input" onchange="chainSuperDepartment(\'../ws/\', this.value, {dept_start:\'#department{{store_id}}\', callback:function(){$(\'#department{{store_id}}\').trigger(\'chosen:updated\');baseItemChainSubs({{store_id}});}});">'; $names = new SuperDeptNamesModel($dbc); if (is_array($range_limit) && count($range_limit) == 2) { $names->superID($range_limit[0], '>='); $names->superID($range_limit[1], '<='); } foreach ($names->find('superID') as $obj) { $ret .= sprintf('<option %s value="%d">%s</option>', $obj->superID() == $superID ? 'selected' : '', $obj->superID(), $obj->super_name()); } $ret .= '</select> <select name="department[]" id="department{{store_id}}" class="form-control chosen-select syncable-input" onchange="baseItemChainSubs({{store_id}});">'; foreach ($depts as $id => $name) { if (is_numeric($superID) && is_array($supers[$superID])) { if (!in_array($id, $supers[$superID]) && $id != $rowItem['department']) { continue; } } $ret .= sprintf('<option %s value="%d">%d %s</option>', $id == $rowItem['department'] ? 'selected' : '', $id, $id, $name); } $ret .= '</select>'; $jsVendorID = $rowItem['default_vendor_id'] > 0 ? $rowItem['default_vendor_id'] : 'no-vendor'; $ret .= '<select name="subdept[]" id="subdept{{store_id}}" class="form-control chosen-select syncable-input">'; $ret .= isset($subs[$rowItem['department']]) ? $subs[$rowItem['department']] : '<option value="0">None</option>'; $ret .= '</select>'; $ret .= '</td> <th class="small text-right">SKU</th> <td colspan="2"> <input type="text" name="vendorSKU" class="form-control input-sm" value="' . $rowItem['sku'] . '" onchange="$(\'#vsku' . $jsVendorID . '\').val(this.value);" ' . ($jsVendorID == 'no-vendor' || !$active_tab ? 'disabled' : '') . ' id="product-sku-field" /> </td> </tr>'; $taxQ = $dbc->prepare_statement('SELECT id,description FROM taxrates ORDER BY id'); $taxR = $dbc->exec_statement($taxQ); $rates = array(); while ($taxW = $dbc->fetch_row($taxR)) { array_push($rates, array($taxW[0], $taxW[1])); } array_push($rates, array("0", "NoTax")); $ret .= '<tr> <th class="small text-right">Tax</th> <td> <select name="tax[]" id="tax{{store_id}}" class="form-control input-sm syncable-input">'; foreach ($rates as $r) { $ret .= sprintf('<option %s value="%d">%s</option>', isset($rowItem['tax']) && $rowItem['tax'] == $r[0] ? 'selected' : '', $r[0], $r[1]); } $ret .= '</select></td>'; $ret .= '<td colspan="4" class="small"> <label>FS <input type="checkbox" value="{{store_id}}" name="FS[]" id="FS{{store_id}}" class="syncable-checkbox" ' . ($rowItem['foodstamp'] == 1 ? 'checked' : '') . ' /> </label> <label>Scale <input type="checkbox" value="{{store_id}}" name="Scale[]" class="scale-checkbox syncable-checkbox" ' . ($rowItem['scale'] == 1 ? 'checked' : '') . ' /> </label> <label>QtyFrc <input type="checkbox" value="{{store_id}}" name="QtyFrc[]" class="qty-checkbox syncable-checkbox" ' . ($rowItem['qttyEnforced'] == 1 ? 'checked' : '') . ' /> </label> <label>WIC <input type="checkbox" value="{{store_id}}" name="prod-wicable[]" class="prod-wicable-checkbox syncable-checkbox" ' . ($rowItem['wicable'] == 1 ? 'checked' : '') . ' /> </label> <label>InUse <input type="checkbox" value="{{store_id}}" name="prod-in-use[]" class="in-use-checkbox syncable-checkbox" ' . ($rowItem['inUse'] == 1 ? 'checked' : '') . ' onchange="$(\'#extra-in-use-checkbox\').prop(\'checked\', $(this).prop(\'checked\'));" /> </label> </td> <th class="small text-right">Discount</th> <td class="col-sm-1"> <select id="discount-select{{store_id}}" name="discount[]" class="form-control input-sm syncable-input">'; $disc_opts = array(0 => 'No', 1 => 'Yes', 2 => 'Trans Only', 3 => 'Line Only'); if ($rowItem['discount'] == 1 && $rowItem['line_item_discountable'] == 1) { $rowItem['discount'] = 1; } elseif ($rowItem['discount'] == 1 && $rowItem['line_item_discountable'] == 0) { $rowItem['discount'] = 2; } elseif ($rowItem['discount'] == 0 && $rowItem['line_item_discountable'] == 1) { $rowItem['discount'] = 3; } foreach ($disc_opts as $id => $val) { $ret .= sprintf('<option %s value="%d">%s</option>', $id == $rowItem['discount'] ? 'selected' : '', $id, $val); } $ret .= '</select></td> <th class="small text-right">Deposit</th> <td colspan="2"> <input type="text" name="deposit-upc[]" class="form-control input-sm syncable-input" value="' . ($rowItem['deposit'] != 0 ? $rowItem['deposit'] : '') . '" placeholder="Deposit Item PLU/UPC" onchange="$(\'#deposit\').val(this.value);" /> </td> </tr>'; $ret .= ' <tr> <th class="small text-right">Case Size</th> <td class="col-sm-1"> <input type="text" name="caseSize" class="form-control input-sm" id="product-case-size" value="' . $rowItem['caseSize'] . '" onchange="$(\'#vunits' . $jsVendorID . '\').val(this.value);" ' . ($jsVendorID == 'no-vendor' || !$active_tab ? 'disabled' : '') . ' /> </td> <th class="small text-right">Pack Size</th> <td class="col-sm-1"> <input type="text" name="size[]" class="form-control input-sm product-pack-size syncable-input" value="' . $rowItem['size'] . '" onchange="$(\'#vsize' . $jsVendorID . '\').val(this.value);" /> </td> <th class="small text-right">Unit of measure</th> <td class="col-sm-1"> <input type="text" name="unitm[]" class="form-control input-sm unit-of-measure syncable-input" value="' . $rowItem['unitofmeasure'] . '" /> </td> <th class="small text-right">Age Req</th> <td class="col-sm-1"> <select name="id-enforced[]" class="form-control input-sm id-enforced syncable-input" onchange="$(\'#idReq\').val(this.value);">'; $ages = array('n/a' => 0, 18 => 18, 21 => 21); foreach ($ages as $label => $age) { $ret .= sprintf('<option %s value="%d">%s</option>', $age == $rowItem['idEnforced'] ? 'selected' : '', $age, $label); } $ret .= '</select> </td> <th class="small text-right">Local</th> <td> <select name="prod-local[]" class="form-control input-sm prod-local syncable-input" onchange="$(\'#local-origin-id\').val(this.value);">'; $local_opts = array(0 => 'No'); $origin = new OriginsModel($dbc); $local_opts = array_merge($local_opts, $origin->getLocalOrigins()); if (count($local_opts) == 1) { $local_opts[1] = 'Yes'; // generic local if no origins defined } foreach ($local_opts as $id => $val) { $ret .= sprintf('<option value="%d" %s>%s</option>', $id, $id == $rowItem['local'] ? 'selected' : '', $val); } $ret .= '</select> </td> </tr> </div>'; $ret .= '</table>'; $ret .= '</div>'; $ret = str_replace('{{store_id}}', $store_id, $ret); $active_tab = false; if (FannieConfig::config('STORE_MODE') != 'HQ') { break; } } $ret .= '</div>'; // sync button will copy current tab values to all other store tabs if (!$new_item && FannieConfig::config('STORE_MODE') == 'HQ') { $nav_tabs .= '<li><label title="Apply update to all stores"> <input type="checkbox" id="store-sync" checked /> Sync</label></li>'; } $nav_tabs .= '</ul>'; // only show the store tabs in HQ mode if (FannieConfig::config('STORE_MODE') == 'HQ') { $ret = str_replace('{{nav_tabs}}', $nav_tabs, $ret); } else { $ret = str_replace('{{nav_tabs}}', '', $ret); } $ret .= <<<HTML <div id="newVendorDialog" title="Create new Vendor" class="collapse"> <fieldset> <label for="newVendorName">Vendor Name</label> <input type="text" name="newVendorName" id="newVendorName" class="form-control" /> </fieldset> </div> HTML; $ret .= '</div>'; // end panel-body $ret .= '</div>'; // end panel return $ret; }
private function calculateMargin($price, $cost, $deptID, $upc) { $dbc = $this->db(); $desired_margin = 'Unknown'; $dept = new DepartmentsModel($dbc); $dept->dept_no($deptID); $dept_name = 'n/a'; if ($dept->load()) { $desired_margin = $dept->margin() * 100; $dept_name = $dept->dept_name(); } $ret = "Desired margin on this department (" . $dept_name . ") is " . $desired_margin . "%"; $ret .= "<br />"; $vendorP = $dbc->prepare(' SELECT d.margin, n.vendorName, d.name, s.margin AS specialMargin FROM products AS p INNER JOIN vendorItems AS v ON p.upc=v.upc AND v.vendorID=p.default_vendor_id INNER JOIN vendorDepartments AS d ON v.vendorID=d.vendorID AND v.vendorDept=d.deptID INNER JOIN vendors AS n ON v.vendorID=n.vendorID LEFT JOIN VendorSpecificMargins AS s ON p.department=s.deptID AND p.default_vendor_id=s.vendorID WHERE p.upc = ? '); $vendorR = $dbc->execute($vendorP, array($upc)); if ($vendorR && $dbc->num_rows($vendorR) > 0) { $w = $dbc->fetch_row($vendorR); $desired_margin = $w['margin'] * 100; if ($w['specialMargin']) { $desired_margin = 100 * $w['specialMargin']; $w['name'] = 'Custom'; } $ret .= sprintf('Desired margin for this vendor category (%s) is %.2f%%<br />', $w['vendorName'] . ':' . $w['name'], $desired_margin); } $shippingP = $dbc->prepare(' SELECT v.shippingMarkup, v.discountRate, v.vendorName FROM products AS p INNER JOIN vendors AS v ON p.default_vendor_id = v.vendorID WHERE p.upc=?'); $shippingR = $dbc->execute($shippingP, array($upc)); $shipping_markup = 0.0; $vendor_discount = 0.0; if ($shippingR && $dbc->numRows($shippingR) > 0) { $w = $dbc->fetchRow($shippingR); if ($w['discountRate'] > 0) { $ret .= sprintf('Discount rate for this vendor (%s) is %.2f%%<br />', $w['vendorName'], $w['discountRate'] * 100); $vendor_discount = $w['discountRate']; } if ($w['shippingMarkup'] > 0) { $ret .= sprintf('Shipping markup for this vendor (%s) is %.2f%%<br />', $w['vendorName'], $w['shippingMarkup'] * 100); $shipping_markup = $w['discountRate']; } } $cost = Margin::adjustedCost($cost, $vendor_discount, $shipping_markup); $actual_margin = Margin::toMargin($cost, $price, array(100, 2)); if ($actual_margin > $desired_margin && is_numeric($desired_margin)) { $ret .= sprintf("<span class=\"alert-success\">Current margin on this item is %.2f%%</span><br />", $actual_margin); } elseif (!is_numeric($price)) { $ret .= "<span class=\"alert-danger\">No price has been saved for this item</span><br />"; } else { $ret .= sprintf("<span class=\"alert-danger\">Current margin on this item is %.2f%%</span><br />", $actual_margin); $srp = $this->getSRP($cost, $desired_margin / 100.0); $ret .= sprintf("Suggested price: \$%.2f ", $srp); $ret .= sprintf("(<a href=\"\" onclick=\"\$('.price-input').val(%.2f); \$('.price-input:visible').trigger('change'); return false;\">Use this price</a>)", $srp); } return $ret; }
public function run() { global $FANNIE_PLUGIN_SETTINGS, $FANNIE_AR_DEPARTMENTS, $FANNIE_TRANS_DB, $FANNIE_OP_DB; $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['StaffArPayrollDB']); $chkQ = 'SELECT staffArDateID FROM StaffArDates WHERE ' . $dbc->datediff($dbc->now(), 'tdate') . ' = 0 '; $chkR = $dbc->query($chkQ); if ($dbc->num_rows($chkR) == 0) { // not scheduled for today return true; } /** Update plugin's table from legacy table, if present. Can go away once WFC transistions away from legacy table. */ $legacy_table = $FANNIE_TRANS_DB . $dbc->sep() . 'staffAR'; if ($dbc->tableExists($legacy_table)) { $query = 'SELECT cardNo, adjust FROM ' . $legacy_table; $result = $dbc->query($query); $cards = ''; $args = array(); while ($row = $dbc->fetch_row($result)) { $model = new StaffArAccountsModel($dbc); $model->card_no($row['cardNo']); $model->nextPayment($row['adjust']); $model->save(); $cards .= '?,'; $args[] = $row['cardNo']; } // remove records that aren't in legacy table if (count($args) > 0) { $cards = substr($cards, 0, strlen($cards) - 1); $query = "DELETE FROM StaffArAccounts WHERE card_no NOT IN ({$cards})"; $prep = $dbc->prepare($query); $dbc->execute($prep, $args); } } // end legacy table handling // build department list $ar_dept = 0; $ret = preg_match_all("/[0-9]+/", $FANNIE_AR_DEPARTMENTS, $depts); $depts = array_pop($depts); if (!is_array($depts) || count($depts) == 0) { $this->cronMsg('Could not locate any AR departments in Fannie configuration', FannieLogger::NOTICE); return false; } else { $ar_dept = $depts[0]; } $dept_desc = ''; $dept_model = new DepartmentsModel($dbc); $dept_model->whichDB($FANNIE_OP_DB); $dept_model->dept_no($ar_dept); if ($dept_model->load()) { $dept_desc = $dept_model->dept_name(); } $dtrans = $FANNIE_TRANS_DB . $dbc->sep() . 'dtransactions'; $emp = isset($FANNIE_PLUGIN_SETTINGS['StaffArPayrollEmpNo']) ? $FANNIE_PLUGIN_SETTINGS['StaffArPayrollEmpNo'] : 1001; $reg = isset($FANNIE_PLUGIN_SETTINGS['StaffArPayrollRegNo']) ? $FANNIE_PLUGIN_SETTINGS['StaffArPayrollRegNo'] : 20; $query = 'SELECT MAX(trans_no) as maxt FROM ' . $dtrans . ' WHERE emp_no=? AND register_no=?'; $prep = $dbc->prepare($query); $result = $dbc->execute($prep, array($emp, $reg)); $trans_no = 1; if ($dbc->num_rows($result) > 0) { $row = $dbc->fetch_row($result); if ($row['maxt'] != '') { $trans_no = $row['maxt'] + 1; } } $model = new StaffArAccountsModel($dbc); foreach ($model->find() as $obj) { if ($obj->nextPayment() == 0) { // no need to write empty records continue; } $record = DTrans::$DEFAULTS; $record['emp_no'] = $emp; $record['register_no'] = $reg; $record['trans_no'] = $trans_no; $record['trans_id'] = 1; $record['trans_type'] = 'D'; $record['card_no'] = $obj->card_no(); $record['department'] = $ar_dept; $record['description'] = $dept_desc; $record['upc'] = sprintf('%.2fDP%d', $obj->nextPayment(), $ar_dept); $record['total'] = sprintf('%.2f', $obj->nextPayment()); $record['unitPrice'] = sprintf('%.2f', $obj->nextPayment()); $record['regPrice'] = sprintf('%.2f', $obj->nextPayment()); $p = DTrans::parameterize($record, 'datetime', date("'Y-m-d 23:59:59'", strtotime('yesterday'))); $query = "INSERT INTO {$dtrans} ({$p['columnString']}) VALUES ({$p['valueString']})"; $prep = $dbc->prepare($query); $write = $dbc->execute($prep, $p['arguments']); if ($write === false) { $this->cronMsg('Error making staff AR deduction for #' . $obj->card_no(), FannieLogger::ERROR); } $trans_no++; } }