public function get_view() { $dbc = FannieDB::getReadOnly($this->config->get('OP_DB')); $code = new ReasoncodesModel($dbc); $ret = '<form method="post"> <p><button type="submit" class="btn btn-default">Save Reasons</button></p> <table class="table table-bordered"> <tr> <th>#</th> <th>Reason</th> <th>Current Accounts</th> </tr>'; $countP = $dbc->prepare(' SELECT COUNT(*) FROM suspensions WHERE (reasoncode & ?) <> 0 '); for ($i = 0; $i < 30; $i++) { $code->mask(1 << $i); $count = $dbc->getValue($countP, array(1 << $i)); $reason = $code->load() ? $code->textStr() : ''; $ret .= sprintf('<tr> <td>%d<input type="hidden" name="mask[]" value="%d" /></td> <td><input type="text" class="form-control" name="reason[]" value="%s" /> <td>%d</td> </tr>', $i + 1, 1 << $i, $reason, $count); } $ret .= '</table>'; $ret .= '<p><button type="submit" class="btn btn-default">Save Reasons</button></p>'; $ret .= '</form>'; return $ret; }
/** 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 needs type'); return $ret; } // validate additional arguments switch (strtolower($args->type)) { case 'vendor': if (!property_exists($args, 'vendor_id')) { // vendor ID required $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters needs vendor_id'); return $ret; } elseif (!property_exists($args, 'sku') && !property_exists($args, 'upc')) { // either sku or upc is required $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters needs sku or upc'); 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 'vendor': $vendor = new \VendorItemsModel($dbc); $vendor->vendorID($args->vendor_id); if (property_exists($args, 'sku')) { $vendor->sku($args->sku); } elseif (property_exists($args, 'upc')) { $vendor->upc($args->upc); } foreach ($vendor->find() as $v) { $ret['sku'] = $v->sku(); $ret['upc'] = $v->upc(); $ret['size'] = $v->size(); $ret['units'] = $v->units(); $ret['brand'] = $v->brand(); $ret['description'] = $v->description(); $ret['cost'] = $v->cost(); break; } return $ret; } }
/** 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, 'field') || !property_exists($args, 'search')) { // missing required arguments $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters'); return $ret; } else { if (strlen($args->search) < 1) { // search term is too short $ret['error'] = array('code' => -32602, 'message' => 'Invalid parameters'); return $ret; } } $dbc = \FannieDB::getReadOnly(\FannieConfig::factory()->get('OP_DB')); switch (strtolower($args->field)) { case 'item': $res = false; if (!is_numeric($args->search)) { $prep = $dbc->prepare('SELECT p.upc, p.description FROM products AS p LEFT JOIN productUser AS u ON u.upc=p.upc WHERE p.description LIKE ? OR p.brand LIKE ? OR u.description LIKE ? OR u.brand LIKE ? GROUP BY p.upc, p.description ORDER BY p.description'); $term = '%' . $args->search . '%'; $res = $dbc->execute($prep, array($term, $term, $term, $term)); } elseif (ltrim($args->search, '0') != '') { $prep = $dbc->prepare(' SELECT p.upc, p.upc AS description FROM products AS p WHERE p.upc LIKE ? GROUP BY p.upc'); $res = $dbc->execute($prep, array('%' . $args->search . '%')); } while ($res && ($row = $dbc->fetch_row($res))) { $ret[] = array('label' => $row['description'], 'value' => $row['upc']); } case 'brand': $prep = $dbc->prepare('SELECT brand FROM products WHERE brand LIKE ? GROUP BY brand ORDER BY brand'); $res = $dbc->execute($prep, array($args->search . '%')); while ($row = $dbc->fetch_row($res)) { $ret[] = $row['brand']; } return $ret; case 'long_brand': $prep = $dbc->prepare(' SELECT u.brand FROM productUser AS u ' . DTrans::joinProducts('u', 'p', 'INNER') . ' WHERE u.brand LIKE ? GROUP BY u.brand ORDER BY u.brand'); $res = $dbc->execute($prep, array($args->search . '%')); while ($row = $dbc->fetch_row($res)) { $ret[] = $row['brand']; } return $ret; case 'vendor': $prep = $dbc->prepare('SELECT vendorID, vendorName FROM vendors WHERE vendorName LIKE ? ORDER BY vendorName'); $res = $dbc->execute($prep, array($args->search . '%')); while ($row = $dbc->fetch_row($res)) { $ret[] = $row['vendorName']; } if ($dbc->tableExists('prodExtra')) { $prep = $dbc->prepare('SELECT distributor FROM prodExtra WHERE distributor LIKE ? GROUP BY distributor ORDER BY distributor'); $res = $dbc->execute($prep, array($args->search . '%')); while ($row = $dbc->fetch_row($res)) { if (!in_array($row['distributor'], $ret)) { $ret[] = $row['distributor']; } } } return $ret; case 'mfirstname': case 'mlastname': case 'maddress': case 'mcity': case 'memail': return \COREPOS\Fannie\API\member\MemberREST::autoComplete($args->field, $args->search); case 'sku': $query = 'SELECT sku FROM vendorItems WHERE sku LIKE ? '; $param = array($args->search . '%'); if (property_exists($args, 'vendor_id')) { $query .= ' AND vendorID=? '; $param[] = $args->vendor_id; } $query .= 'GROUP BY sku ORDER BY sku'; $prep = $dbc->prepare($query); $res = $dbc->execute($prep, $param); while ($row = $dbc->fetch_row($res)) { $ret[] = $row['sku']; if (count($ret) > 50) { break; } } return $ret; case 'unit': $query = ' SELECT unitofmeasure FROM products WHERE unitofmeasure LIKE ? GROUP BY unitofmeasure ORDER BY unitofmeasure'; $param = array($args->search . '%'); $prep = $dbc->prepare($query); $res = $dbc->execute($prep, $param); while ($row = $dbc->fetchRow($res)) { $ret[] = $row['unitofmeasure']; if (count($ret) > 50) { break; } } return $ret; default: return $ret; } }
/** 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; } }
/** Render the current page if appropriate The page is only shown if it's accessed directly rather than through an include(). @param $custom_errors @deprecated This behavior is controlled by config variable FANNIE_CUSTOM_ERRORS. The optional parameter remains for th sake of compatibility but does not do anything. It will go away when all calls to this method have been cleaned up. */ public static function conditionalExec($custom_errors = true) { $frames = debug_backtrace(); // conditionalExec() is the only function on the stack if (count($frames) == 1) { $config = FannieConfig::factory(); $logger = new FannieLogger(); if ($config->get('SYSLOG_SERVER')) { $logger->setRemoteSyslog($config->get('SYSLOG_SERVER'), $config->get('SYSLOG_PORT'), $config->get('SYSLOG_PROTOCOL')); } $op_db = $config->get('OP_DB'); $dbc = FannieDB::get($op_db); self::setLogger($logger); // setup error logging self::setErrorHandlers(); // initialize locale & gettext self::i18n(); // draw current page $page = basename(filter_input(INPUT_SERVER, 'PHP_SELF')); $class = substr($page, 0, strlen($page) - 4); if ($class != 'index' && class_exists($class)) { $obj = new $class(); if ($dbc->isConnected($op_db)) { // write URL log self::logUsage($dbc, $op_db); /* $auth = self::authOverride($dbc, $op_db, $class); if ($auth) { $obj->setPermissions($auth); } */ } $obj->setConfig($config); $obj->setLogger($logger); if (is_a($obj, 'FannieReportPage')) { $dbc = FannieDB::getReadOnly($op_db); } $obj->setConnection($dbc); $obj->draw_page(); } else { trigger_error('Missing class ' . $class, E_USER_NOTICE); } } }
/** Get all email addresses associated with the given department @param $dept [int] department number @return [string] email address(es) or [boolean] false */ public static function getAddresses($dept) { $conf = \FannieConfig::factory(); $dbc = \FannieDB::getReadOnly($conf->get('OP_DB')); $query = 'SELECT superID from superdepts WHERE dept_ID=? GROUP BY superID'; $prep = $dbc->prepare($query); $res = $dbc->execute($prep, array($dept)); $emails = ''; while ($row = $dbc->fetch_row($res)) { $model = new \SuperDeptEmailsModel($dbc); $model->superID($row['superID']); if (!$model->load()) { continue; } $addr = $model->emailAddress(); if ($addr && !strstr($emails, $addr)) { if ($emails !== '') { $emails .= ', '; } $emails .= $addr; } } return $emails === '' ? false : $emails; }
public function get_view() { $dbc = FannieDB::getReadOnly($this->config->get('OP_DB')); $plans = new EquityPaymentPlansModel($dbc); $ret = '<table class="table table-bordered"> <tr> <th>Name</th> <th>Payment Amount</th> <th>Frequency</th> </tr>'; foreach ($plans->find('name') as $plan) { $ret .= sprintf(' <tr> <td>%s</td> <td>%.2f</td> <td>%s</td> <td><a class="btn btn-default btn-xs" href="%s?id=%d">%s</a></td> </tr>', $plan->name(), $plan->recurringPayment(), $plan->billingCycle(), filter_input(INPUT_SERVER, 'PHP_SELF'), $plan->equityPaymentPlanID(), \COREPOS\Fannie\API\lib\FannieUI::editIcon()); } $ret .= '</table>'; $ret .= '<p> <a href="?_method=put" class="btn btn-default">Create New Plan</a> </p>'; return $ret; }
/** Generate FROM and WHERE clauses with appropriate parameters and joins based on the standard form submissions. @return [keyed array] - query [string] from and where clauses - args [array] corresponding parameters */ public static function standardItemFromWhere() { $op_db = FannieConfig::config('OP_DB'); $dbc = FannieDB::getReadOnly($op_db); $start_date = self::getDate('date1', date('Y-m-d')); $end_date = self::getDate('date2', date('Y-m-d')); $dlog = DTransactionsModel::selectDlog($start_date, $end_date); $lookupType = self::get('lookup-type', 'dept'); $query = ' FROM ' . $dlog . ' AS t LEFT JOIN departments AS d ON t.department=d.dept_no ' . DTrans::joinProducts('t') . ' LEFT JOIN MasterSuperDepts AS m ON t.department=m.dept_ID LEFT JOIN subdepts AS b ON p.subdept=b.subdept_no LEFT JOIN vendors AS v ON p.default_vendor_id=v.vendorID LEFT JOIN prodExtra AS x ON t.upc=x.upc '; $args = array(); switch ($lookupType) { case 'dept': $super = FormLib::get('super-dept'); if ($super !== '' && $super >= 0) { $query .= ' LEFT JOIN superdepts AS s ON t.department=s.dept_ID '; } break; case 'manu': break; case 'vendor': $query .= ' LEFT JOIN vendors AS z ON x.distributor=z.vendorName '; break; case 'likecode': $query .= ' LEFT JOIN upcLike AS u ON t.upc=u.upc '; break; } $query .= ' WHERE t.tdate BETWEEN ? AND ? '; $args[] = $start_date . ' 00:00:00'; $args[] = $end_date . ' 23:59:59'; switch ($lookupType) { case 'dept': $super = FormLib::get('super-dept'); if ($super !== '' && $super >= 0) { $query .= ' AND s.superID=? '; $args[] = $super; if (is_array(FormLib::get('departments')) && count(FormLib::get('departments')) > 0) { $query .= ' AND t.department IN ('; foreach (FormLib::get('departments') as $d) { $query .= '?,'; $args[] = $d; } $query = substr($query, 0, strlen($query) - 1) . ')'; } elseif (FormLib::get('dept-start') !== '' && FormLib::get('dept-end') !== '') { $query .= ' AND t.department BETWEEN ? AND ? '; $args[] = FormLib::get('dept-start'); $args[] = FormLib::get('dept-end'); } } elseif ($super !== '' && $super == -2) { $query .= ' AND m.superID <> 0 '; if (is_array(FormLib::get('departments')) && count(FormLib::get('departments')) > 0) { $query .= ' AND t.department IN ('; foreach (FormLib::get('departments') as $d) { $query .= '?,'; $args[] = $d; } $query = substr($query, 0, strlen($query) - 1) . ')'; } elseif (FormLib::get('dept-start') !== '' && FormLib::get('dept-end') !== '') { $query .= ' AND t.department BETWEEN ? AND ? '; $args[] = FormLib::get('dept-start'); $args[] = FormLib::get('dept-end'); } } elseif ($super === '') { if (is_array(FormLib::get('departments')) && count(FormLib::get('departments')) > 0) { $query .= ' AND t.department IN ('; foreach (FormLib::get('departments') as $d) { $query .= '?,'; $args[] = $d; } $query = substr($query, 0, strlen($query) - 1) . ')'; } else { $query .= ' AND t.department BETWEEN ? AND ? '; $args[] = FormLib::get('dept-start', 1); $args[] = FormLib::get('dept-end', 1); } } if (is_array(FormLib::get('subdepts')) && count(FormLib::get('subdepts')) > 0) { $query .= ' AND p.subdept IN ('; foreach (FormLib::get('subdepts') as $s) { $query .= '?,'; $args[] = $s; } $query = substr($query, 0, strlen($query) - 1) . ')'; } break; case 'manu': $mtype = FormLib::get('mtype'); if ($mtype == 'prefix') { $query .= ' AND t.upc LIKE ? '; $args[] = '%' . FormLib::get('manufacturer') . '%'; } else { $query .= ' AND (p.brand LIKE ? OR x.manufacturer LIKE ?) '; $manu = '%' . FormLib::get('manufacturer') . '%'; $args[] = $manu; $args[] = $manu; $optimizeP = $dbc->prepare(' SELECT p.department FROM products AS p LEFT JOIN prodExtra AS x ON p.upc=x.upc WHERE (p.brand LIKE ? OR x.manufacturer LIKE ?) GROUP BY p.department'); $optimizeR = $dbc->execute($optimizeP, array($manu, $manu)); $dept_in = ''; while ($optimizeW = $dbc->fetch_row($optimizeR)) { $dept_in .= '?,'; $args[] = $optimizeW['department']; } if ($dept_in !== '') { $dept_in = substr($dept_in, 0, strlen($dept_in) - 1); $query .= ' AND t.department IN (' . $dept_in . ') '; } } break; case 'vendor': $query .= ' AND (p.default_vendor_id=? OR z.vendorID=?) '; $vID = FormLib::get('vendor', 1); $args[] = $vID; $args[] = $vID; $optimizeP = $dbc->prepare(' SELECT p.department FROM products AS p LEFT JOIN prodExtra AS x ON p.upc=x.upc LEFT JOIN vendors AS v ON x.distributor=v.vendorName WHERE (p.default_vendor_id=? OR v.vendorID=? GROUP BY p.department'); $optimizeR = $dbc->execute($optimizeP, array($vID, $vID)); $dept_in = ''; while ($optimizeW = $dbc->fetch_row($optimizeR)) { $dept_in .= '?,'; $args[] = $optimizeW['department']; } if ($dept_in !== '') { $dept_in = substr($dept_in, 0, strlen($dept_in) - 1); $query .= ' AND t.department IN (' . $dept_in . ') '; } break; case 'likecode': $query .= ' AND u.likeCode BETWEEN ? AND ? '; $args[] = FormLib::get('lc-start', 1); $args[] = FormLib::get('lc-end', 1); $optimizeP = $dbc->prepare(' SELECT p.department FROM products AS p INNER JOIN upcLike AS u ON p.upc=u.upc WHERE u.likeCode BETWEEN ? AND ? GROUP BY p.department'); $optimizeR = $dbc->execute($optimizeP, array(FormLib::get('lc-start', 1), FormLib::get('lc-end', 1))); $dept_in = ''; while ($optimizeW = $dbc->fetch_row($optimizeR)) { $dept_in .= '?,'; $args[] = $optimizeW['department']; } if ($dept_in !== '') { $dept_in = substr($dept_in, 0, strlen($dept_in) - 1); $query .= ' AND t.department IN (' . $dept_in . ') '; } break; case 'u': $upcs = FormLib::get('u', array()); if (count($upcs) == 0) { $upcs[] = 'NOTREALUPC'; } $query .= ' AND t.upc IN ('; foreach ($upcs as $u) { $query .= '?,'; $args[] = BarcodeLib::padUPC($u); } $query = substr($query, 0, strlen($query) - 1) . ') '; break; } return array('query' => $query, 'args' => $args); }