예제 #1
0
 function preprocess()
 {
     global $FANNIE_URL;
     $this->uid = ltrim(FannieAuth::getUID($this->current_user), "0");
     $this->title = "Cal";
     $this->header = "Calendars";
     $plugin = new CalendarPlugin();
     $this->add_script($FANNIE_URL . 'src/javascript/jquery.js');
     $this->add_script($FANNIE_URL . 'src/javascript/jquery-ui.js');
     $this->add_script($plugin->pluginURL() . '/javascript/calendar.js');
     $this->add_script($plugin->pluginURL() . '/javascript/ajax.js');
     $view = FormLib::get_form_value('view', 'index');
     if (FormLib::get('calID') === '') {
         $view = 'index';
     }
     if ($view == 'month') {
         $this->window_dressing = False;
     } else {
         $this->add_css_file($FANNIE_URL . 'src/javascript/jquery-ui.css');
     }
     if (file_exists(dirname(__FILE__) . '/css/' . $view . '.css')) {
         $this->add_css_file($plugin->pluginURL() . '/css/' . $view . '.css');
     }
     return True;
 }
예제 #2
0
 function preprocess()
 {
     global $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS;
     if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) {
         $this->errors .= _("Error: The Coop Cred Plugin is not enabled.");
         return True;
     }
     if (!array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) || $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] == "") {
         $this->errors .= _("Error: Coop Cred Database not named in Plugin Settings.");
         return True;
     }
     /* Get values from the Whole-Project (Plugin) config table.
      */
     $this->first = 0;
     if (FormLib::get_form_value('action') == '') {
         $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
         $config = new CCredConfigModel($dbc);
         $id = FormLib::get_form_value('configno') != '' ? (int) FormLib::get_form_value('configno') : 1;
         $config->configID($id);
         if (!$config->load()) {
             // Create the initial config record with default values.
             $saved = $config->save();
             if ($saved === False) {
                 $this->errors .= _("Error: Could not create initial " . "Coop Cred configuration record.");
                 return True;
             }
         }
         $this->first = 1;
     }
     $this->authUserNumber = 0;
     $authName = FannieAuth::checkLogin();
     if (!($authName == 'null' || $authName == 'init' || $authName == False)) {
         $this->authUserNumber = FannieAuth::getUID($authName);
     }
     /* The first (unless this is an update) time proceed directly to edit.
      */
     if ($this->first) {
         return True;
     }
     /* Support ajax calls to this program.
      * If there is a form submission with an action go do it.
      * The form submission may be via AJAX instead of <form ...>
      *  with action= in the query string with other parameters.
      */
     if (FormLib::get_form_value('action') !== '') {
         $this->ajax_response(FormLib::get_form_value('action'));
         /* How to handle errors/problems esp. in save?
          * Possibly code readinessCheck()
          */
         return False;
     }
     /* If the call was not by form, e.g. from the initial menu
      * or the <form action=> is '' (when does that happen?)
      * FanniePage::draw_page() continues to $this->body_content()
      *  which returns the the program-select form.
      */
     return True;
     // preprocess()
 }
예제 #3
0
 public function pluginEnable()
 {
     ob_start();
     $try = FannieAuth::createClass('timesheet_access', 'Grants user permission to use the
          Timesheet plugin');
     ob_end_clean();
     if ($try === False) {
         echo 'Failed to create authentication class.
             Make sure authentication is enabled in
             Fannie and you\'re logged in as an admin
             then try turning Timesheet on and off
             again';
     }
 }
예제 #4
0
 /**
   Log page load in usageStats table
   @param $dbc [SQLManager] database connection
   @return [boolean] success / fail
 */
 protected static function logUsage(SQLManager $dbc, $op_db)
 {
     if (php_sapi_name() === 'cli') {
         // don't log cli usage
         return false;
     }
     $user = FannieAuth::checkLogin();
     if ($user === false) {
         $user = '******';
     }
     $prep = $dbc->prepare('INSERT INTO usageStats
             (tdate, pageName, referrer, userHash, ipHash)
          VALUES
             (?, ?, ?, ?, ?)');
     $args = array(date('Y-m-d H:i:s'), basename(filter_input(INPUT_SERVER, 'PHP_SELF')));
     $referrer = isset($_SERVER['HTTP_REFERER']) ? basename($_SERVER['HTTP_REFERER']) : 'n/a';
     $referrer = filter_input(INPUT_SERVER, 'HTTP_REFERER');
     $args[] = $referrer === null ? 'n/a' : basename($referrer);
     $args[] = sha1($user);
     $ip_addr = filter_input(INPUT_SERVER, 'REMOTE_ADDR');
     $args[] = sha1($ip_addr);
     return $dbc->execute($prep, $args);
 }
예제 #5
0
 public function preprocess()
 {
     $this->empID = FormLib::get('id');
     if ($this->empID === '' || !is_numeric($this->empID)) {
         $this->empID = FannieAuth::getUID($this->current_user);
     }
     if (!FannieAuth::validateUserQuiet('view_all_hours')) {
         /* see if logged in user has access to any
               department. if so, see if the selected employee
               is in that department
            */
         $validated = false;
         $depts = array(10, 11, 12, 13, 20, 21, 30, 40, 41, 50, 60, 998);
         $sql = WfcHtLib::hours_dbconnect();
         $checkQ = $sql->prepare_statement("select department from employees where empID=?");
         $checkR = $sql->exec_statement($checkQ, array($this->empID));
         $checkW = $sql->fetch_row($checkR);
         if (FannieAuth::validateUserQuiet('view_all_hours', $checkW['department'])) {
             $validated = true;
         }
         /* no access permissions found, so only allow the
               logged in user to see themself
            */
         if (!$validated) {
             $this->empID = FannieAuth::getUID($this->current_user);
         }
     }
     $sql = WfcHtLib::hours_dbconnect();
     $deptQ = $sql->prepare_statement("select department from employees where empID=?");
     $deptR = $sql->exec_statement($deptQ, array($this->empID));
     $deptW = $sql->fetch_row($deptR);
     if ($deptW['department'] < 998) {
         header("Location: WfcHtViewEmpPage.php?id=" . $this->empID);
         return false;
     }
     return true;
 }
예제 #6
0
 /**
   Check if the user is logged in
 */
 public function checkAuth()
 {
     foreach ($this->auth_classes as $class) {
         $try = false;
         if (is_array($class) && count($class) == 3) {
             $try = FannieAuth::validateUserQuiet($class[0], $class[1], $class[2]);
         } else {
             $try = FannieAuth::validateUserQuiet($class);
         }
         if ($try) {
             $this->current_user = $try;
             return true;
         }
     }
     $try = FannieAuth::checkLogin();
     if ($try && empty($this->auth_classes)) {
         $this->current_user = $try;
         return true;
     }
     return false;
 }
예제 #7
0
 public function body_content()
 {
     $edit = FannieAuth::validateUserQuiet('edit_employees');
     $sort = "e.name";
     if (FormLib::get('sort') !== '') {
         switch (strtolower(FormLib::get('sort'))) {
             case 'name':
                 $sort = 'e.name';
                 break;
             case 'adpid':
                 $sort = 'e.adpid';
                 break;
             case 'ptolevel':
                 $sort = 'e.ptolevel';
                 break;
             case 'ptoremaining':
                 $sort = 'p.ptoremaining';
                 break;
             case 'hours':
                 $sort = 'u.hours';
                 break;
             case 'totalhours':
                 $sort = 'h.totalhours';
                 break;
         }
     }
     $dir = "asc";
     if (FormLib::get('dir') !== '') {
         switch (strtolower(FormLib::get('dir'))) {
             case 'asc':
                 $dir = 'asc';
                 break;
             case 'desc':
                 $dir = 'desc';
                 break;
         }
     }
     $otherdir = "desc";
     if ($dir == "desc") {
         $otherdir = "asc";
     }
     $sql = WfcHtLib::hours_dbconnect();
     $fetchQ = "select e.name,e.adpID,\n            case when e.department>=998 then 'Salary' else e.PTOLevel end as PTOLevel,\n            case when e.department>=998 then '&nbsp;' else h.totalHours end as totalHours,\n            c.cusp,e.empID,\n            case when s.totalTaken is null then p.ptoremaining else e.adpID-s.totalTaken end as ptoremaining,\n            case when e.department>=998 then '&nbsp;' else u.hours end as hours\n            from employees as e left join hoursalltime as h on e.empID=h.empID\n            left join cusping as c on e.empID=c.empID\n            left join pto as p on e.empID=p.empID\n            left join uto as u on e.empID=u.empID\n            left join salarypto_ytd s on e.empID=s.empID\n            {$this->dept_restrict}\n            order by {$sort} {$dir}";
     $fetchP = $sql->prepare_statement($fetchQ);
     $fetchR = $sql->exec_statement($fetchP, $this->dept_args);
     ob_start();
     if (FannieAuth::validateUserQuiet('view_all_hours')) {
         $sql = WfcHtLib::hours_dbconnect();
         $deptsQ = "select name,deptID from Departments order by name";
         $deptsR = $sql->query($deptsQ);
         echo "Show Department: ";
         echo "<select class=\"form-control\" onchange=\"top.location='{$_SERVER['PHP_SELF']}?showdept='+this.value;\">";
         echo "<option value=\"\">All</option>";
         while ($deptsW = $sql->fetch_row($deptsR)) {
             if ($this->selected_dept == $deptsW[1]) {
                 echo "<option value={$deptsW['1']} selected>{$deptsW['0']}</option>";
             } else {
                 echo "<option value={$deptsW['1']}>{$deptsW['0']}</option>";
             }
         }
         if ($this->selected_dept == -1) {
             echo "<option selected value=\"-1\">DELETED</option>";
         } else {
             echo "<option value=\"-1\">DELETED</option>";
         }
         echo "</select>";
     } else {
         if (strlen($this->dept_list) > 4) {
             $sql = WfcHtLib::hours_dbconnect();
             $deptsQ = "select name,deptID from Departments WHERE deptID IN {$this->dept_list} order by name";
             $deptsP = $sql->prepare_statement($deptsQ);
             $deptsR = $sql->exec_statement($deptsP, $this->list_args);
             echo "Show Department: ";
             echo "<select class=\"form-control\" onchange=\"top.location='{$_SERVER['PHP_SELF']}?showdept='+this.value;\">";
             echo "<option value=\"\">All</option>";
             while ($deptsW = $sql->fetch_row($deptsR)) {
                 if ($this->selected_dept == $deptsW[1]) {
                     echo "<option value={$deptsW['1']} selected>{$deptsW['0']}</option>";
                 } else {
                     echo "<option value={$deptsW['1']}>{$deptsW['0']}</option>";
                 }
             }
             echo "</select>";
         }
     }
     echo "<table class=\"table\"><tr>";
     if ($sort == "e.name") {
         echo "<th><a href={$_SERVER['PHP_SELF']}?sort=name&dir={$otherdir}&showdept={$this->selected_dept}>Name</a></th>";
     } else {
         echo "<th><a href={$_SERVER['PHP_SELF']}?sort=name&dir=asc&showdept={$this->selected_dept}>Name</a></th>";
     }
     if ($sort == "e.adpid") {
         echo "<th><a href={$_SERVER['PHP_SELF']}?sort=adpid&dir={$otherdir}&showdept={$this->selected_dept}>ADP ID</a></th>";
     } else {
         echo "<th><a href={$_SERVER['PHP_SELF']}?sort=adpid&dir=asc&showdept={$this->selected_dept}>ADP ID</a></th>";
     }
     if ($sort == "e.ptolevel") {
         echo "<th><a href={$_SERVER['PHP_SELF']}?sort=ptolevel&dir={$otherdir}&showdept={$this->selected_dept}>PTO Level</a></th>";
     } else {
         echo "<th><a href={$_SERVER['PHP_SELF']}?sort=ptolevel&dir=asc&showdept={$this->selected_dept}>PTO Level</a></th>";
     }
     if ($sort == "p.ptoremaining") {
         echo "<th><a href={$_SERVER['PHP_SELF']}?sort=ptoremaining&dir={$otherdir}&showdept={$this->selected_dept}>Avail. PTO</a></th>";
     } else {
         echo "<th><a href={$_SERVER['PHP_SELF']}?sort=ptoremaining&dir=desc&showdept={$this->selected_dept}>Avail. PTO</a></th>";
     }
     if ($sort == "u.hours") {
         echo "<th><a href={$_SERVER['PHP_SELF']}?sort=hours&dir={$otherdir}&showdept={$this->selected_dept}>Avail. UTO</a></th>";
     } else {
         echo "<th><a href={$_SERVER['PHP_SELF']}?sort=hours&dir=desc&showdept={$this->selected_dept}>Avail. UTO</a></th>";
     }
     if ($sort == "u.hours") {
         echo "<th><a href={$_SERVER['PHP_SELF']}?sort=totalhours&dir={$otherdir}&showdept={$this->selected_dept}>Total Hours</a></th>";
     } else {
         echo "<th><a href={$_SERVER['PHP_SELF']}?sort=totalhours&dir=desc&showdept={$this->selected_dept}>Total Hours</a></th>";
     }
     echo "</tr>";
     while ($fetchW = $sql->fetch_row($fetchR)) {
         if ($fetchW[4] == "PRE") {
             echo "<tr class=\"pre\">";
         } elseif ($fetchW[4] == "POST") {
             echo "<tr class=\"post\">";
         } elseif ($fetchW[4] == "!!!") {
             echo "<tr class=\"earned\">";
         } else {
             echo "<tr>";
         }
         echo "<td><a href=WfcHtViewEmpPage.php?id={$fetchW['5']}>{$fetchW['0']}</a>";
         echo "</td>";
         echo "<td>{$fetchW['1']}</td>";
         echo "<td align=center>{$fetchW['2']}</td>";
         echo "<td align=right>" . (is_numeric($fetchW[6]) ? sprintf("%.2f", $fetchW[6]) : $fetchW[6]) . "</td>";
         echo "<td align=right>" . (is_numeric($fetchW[7]) ? sprintf("%.2f", $fetchW[7]) : $fetchW[7]) . "</td>";
         echo "<td align=right>" . (is_numeric($fetchW[3]) ? sprintf("%.2f", $fetchW[3]) : $fetchW[3]) . "</td>";
         if ($edit) {
             echo "<td><a href=WfcHtEditPage.php?id={$fetchW['5']}>Edit</a></td>";
             if ($this->selected_dept == "-1") {
                 echo "<td><a href={$_SERVER['PHP_SELF']}?action=undelete&id={$fetchW['5']}>Undelete</a></td>";
             } else {
                 echo "<td><a href={$_SERVER['PHP_SELF']}?action=delete&id={$fetchW['5']}>Delete</a></td>";
             }
         }
         echo "</tr>";
     }
     echo '</table>';
     return ob_get_clean();
 }
예제 #8
0
 public static function weekView($id, $year, $week)
 {
     $sql = CalendarPluginDB::get();
     $calendarModel = new CalendarsModel($sql);
     $calendarModel->calendarID($id);
     $calendarModel->load();
     $name = $calendarModel->name();
     $uid = FannieAuth::getUID(FannieAuth::checkLogin());
     $EDIT = CalendarPluginPermissions::can_write($uid, $id);
     $OWNER = CalendarPluginPermissions::is_owner($uid, $id);
     $startTS = strtotime($year . '-W' . str_pad($week, 2, '0', STR_PAD_LEFT) . '-1');
     $endTS = mktime(0, 0, 0, date('n', $startTS), date('j', $startTS) + 6, date('Y', $startTS));
     $query = 'SELECT eventDate, eventText, eventID
               FROM monthview_events
               WHERE calendarID=?
                 AND eventDate BETWEEN ? AND ?';
     $prep = $sql->prepare($query);
     $args = array($id, date('Y-m-d 00:00:00', $startTS), date('Y-m-d 23:59:59', $endTS));
     $result = $sql->execute($prep, $args);
     $cal_data = array();
     while ($row = $sql->fetch_row($result)) {
         $cal_ts = strtotime($row['eventDate']);
         $cal_data[$cal_ts] = array('id' => $row['eventID'], 'text' => $row['eventText']);
     }
     $startT = 7;
     $endT = 21;
     $prevWeek = mktime(0, 0, 0, date('n', $startTS), date('j', $startTS) - 7, date('Y', $startTS));
     $nextWeek = mktime(0, 0, 0, date('n', $startTS), date('j', $startTS) + 7, date('Y', $startTS));
     $ret = '<table cellpadding="4" cellspacing="0" border="1">';
     // paging
     $ret .= '<tr>';
     $ret .= sprintf('<td colspan="3" align="left">
                     <a href="?view=week&calID=%d&week=%d&year=%d">Prev</a></td>', $id, date('W', $prevWeek), date('Y', $prevWeek));
     $ret .= '<td align="center">' . date('Y', $startTS) . '</td>';
     $ret .= sprintf('<td colspan="4" align="right">
                     <a href="?view=week&calID=%d&week=%d&year=%d">Next</a></td>', $id, date('W', $nextWeek), date('Y', $nextWeek));
     $ret .= '</tr>';
     $ret .= '<tr><th>' . $name . '</th>';
     for ($i = 0; $i < 7; $i++) {
         $ts = mktime(0, 0, 0, date('n', $startTS), date('j', $startTS) + $i, date('Y', $startTS));
         $ret .= '<th>' . date('M j', $ts) . '<br />' . date('l', $ts) . '</th>';
     }
     $ret .= '</tr>';
     for ($hour = $startT; $hour < $endT; $hour++) {
         $ret .= '<tr>';
         $ret .= '<td>' . date('h:i A', mktime($hour, 0)) . '</td>';
         for ($i = 0; $i < 7; $i++) {
             $entry_ts = mktime($hour, 0, 0, date('n', $startTS), date('j', $startTS) + $i, date('Y', $startTS));
             if ($EDIT) {
                 $ret .= sprintf('<td id="weekEntry%d" class="weekEntry"
                                 onclick="weekClickCallback(%d);"
                                 ondblclick="saveCallback(%d);">
                                 <input type="hidden" class="weekEntryTS" value="%d" />
                                 <span class="weekEntryContent">%s</span>', $entry_ts, $entry_ts, $entry_ts, $entry_ts, isset($cal_data[$entry_ts]) ? $cal_data[$entry_ts]['text'] : '');
                 if (isset($cal_data[$entry_ts])) {
                     $ret .= sprintf('<input type="hidden" class="weekEntryEventID" value="%d" />', $cal_data[$entry_ts]['id']);
                 }
             } else {
                 $ret .= '<td class="weekEntry"><span class="weekEntryContent">';
                 $ret .= isset($cal_data[$entry_ts]) ? $cal_data[$entry_ts]['text'] : '';
                 $ret .= '</span>';
             }
             $ret .= '</td>';
         }
         $ret .= '</tr>';
         $ret .= '<tr>';
         $ret .= '<td>' . date('h:i A', mktime($hour, 30)) . '</td>';
         for ($i = 0; $i < 7; $i++) {
             $entry_ts = mktime($hour, 30, 0, date('n', $startTS), date('j', $startTS) + $i, date('Y', $startTS));
             if ($EDIT) {
                 $ret .= sprintf('<td id="weekEntry%d" class="weekEntry"
                                 onclick="weekClickCallback(%d);"
                                 ondblclick="saveCallback(%d);">
                                 <input type="hidden" class="weekEntryTS" value="%d" />
                                 <span class="weekEntryContent">%s</span>', $entry_ts, $entry_ts, $entry_ts, $entry_ts, isset($cal_data[$entry_ts]) ? $cal_data[$entry_ts]['text'] : '');
                 if (isset($cal_data[$entry_ts])) {
                     $ret .= sprintf('<input type="hidden" class="weekEntryEventID" value="%d" />', $cal_data[$entry_ts]['id']);
                 }
             } else {
                 $ret .= '<td class="weekEntry"><span class="weekEntryContent">';
                 $ret .= isset($cal_data[$entry_ts]) ? $cal_data[$entry_ts]['text'] : '';
                 $ret .= '</span>';
             }
             $ret .= '</td>';
         }
         $ret .= '</tr>';
     }
     $ret .= '</table>';
     $ret .= '<input type="hidden" id="calendarID" value="' . $id . '" />';
     return $ret;
 }
예제 #9
0
 public function get_view()
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $TRANS = $this->config->get('TRANS_DB') . $dbc->sep();
     $cachepath = sys_get_temp_dir() . "/ordercache/";
     if (!is_dir($cachepath)) {
         mkdir($cachepath);
     }
     $key = dechex(str_replace(" ", "", str_replace(".", "", microtime())));
     $prints = array();
     $username = FannieAuth::checkLogin();
     if (file_exists("{$cachepath}{$username}.prints")) {
         $prints = unserialize(file_get_contents("{$cachepath}{$username}.prints"));
     } else {
         $fp = fopen("{$cachepath}{$username}.prints", 'w');
         fwrite($fp, serialize($prints));
         fclose($fp);
     }
     $f1 = FormLib::get('f1');
     $f2 = FormLib::get('f2');
     $f3 = FormLib::get('f3');
     $ret = '';
     if ($this->card_no) {
         $ret .= sprintf('(<a href="%s?f1=%s&f2=%s&f3=%s&order=%s">Back to All Owners</a>)<br />', $_SERVER['PHP_SELF'], $f1, $f2, $f3, FormLib::get('order'));
     }
     $status = array(0 => "New, No Call", 3 => "New, Call", 1 => "Called/waiting", 2 => "Pending", 4 => "Placed", 5 => "Arrived");
     /**
       Lookup list of super departments
       for filtering purposes
     */
     $assignments = array();
     $q = $dbc->prepare("\n            SELECT superID,\n                super_name \n            FROM MasterSuperDepts\n            WHERE superID > 0\n            GROUP BY superID,\n                super_name \n            ORDER BY superID");
     $r = $dbc->exec_statement($q);
     while ($w = $dbc->fetch_row($r)) {
         $assignments[$w['superID']] = $w['super_name'];
     }
     unset($assignments[0]);
     /**
       Lookup list of vendors for filtering purposes
       These are vendors mentioned in an order which
       may not overlap perfectly with the actual
       vendors table
     */
     $suppliers = array('');
     $q = $dbc->prepare("\n            SELECT mixMatch \n            FROM {$TRANS}PendingSpecialOrder \n            WHERE trans_type='I'\n            GROUP BY mixMatch \n            ORDER BY mixMatch");
     $r = $dbc->exec_statement($q);
     while ($w = $dbc->fetch_row($r)) {
         $suppliers[] = $w['mixMatch'];
     }
     $filterstring = "";
     $filterargs = array();
     if ($f1 !== '') {
         $f1 = (int) $f1;
         $filterstring .= ' AND statusFlag=?';
         $filterargs[] = $f1;
     }
     $ret .= '<a href="index.php">Main Menu</a>';
     $ret .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
     $ret .= "Current Orders";
     $ret .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
     $ret .= sprintf('<a href="OldSpecialOrdersPage.php%s">Old Orders</a>', $this->card_no ? '?card_no=' . $this->card_no : '');
     $ret .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
     $ret .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
     $ret .= '<input type="checkbox" id="acbx" onclick="$(\'tr.arrived\').each(function(){$(this).toggle();});" />';
     $ret .= '<label for="acbx">Hide Printed</label>';
     $ret .= '<p />';
     $ret .= '<div class="form-inline">';
     $ret .= "<b>Status</b>: ";
     $ret .= '<select id="f_1" class="form-control input-sm" onchange="refilter();">';
     $ret .= '<option value="">All</option>';
     foreach ($status as $k => $v) {
         $ret .= sprintf("<option %s value=\"%d\">%s</option>", $k === $f1 ? 'selected' : '', $k, $v);
     }
     $ret .= '</select>';
     $ret .= '&nbsp;';
     $ret .= '<b>Buyer</b>: <select id="f_2" class="form-control input-sm" onchange="refilter();">';
     $ret .= '<option value="">All</option>';
     foreach ($assignments as $k => $v) {
         $ret .= sprintf("<option %s value=\"%d\">%s</option>", $k == $f2 ? 'selected' : '', $k, $v);
     }
     $ret .= sprintf('<option %s value="2%%2C8">Meat+Cool</option>', $f2 == "2,8" ? 'selected' : '');
     $ret .= '</select>';
     $ret .= '&nbsp;';
     $ret .= '<b>Supplier</b>: <select id="f_3" class="form-control input-sm" onchange="refilter();">';
     foreach ($suppliers as $v) {
         $ret .= sprintf("<option %s>%s</option>", $v === $f3 ? 'selected' : '', $v);
     }
     $ret .= '</select>';
     $ret .= '</div>';
     /**
       Also filter by member number if applicable
     */
     if ($this->card_no) {
         $filterstring .= " AND p.card_no=?";
         $filterargs[] = $this->card_no;
         $ret .= sprintf('<input type="hidden" id="cardno" value="%d" />', $this->card_no);
     }
     $q = "SELECT min(datetime) as orderDate,p.order_id,sum(total) as value,\n            count(*)-1 as items,\n            o.statusFlag AS status_flag,\n            o.subStatus AS sub_status,\n            CASE WHEN MAX(p.card_no)=0 THEN MAX(o.lastName) ELSE MAX(c.LastName) END as name,\n            MIN(CASE WHEN trans_type='I' THEN charflag ELSE 'ZZZZ' END) as charflag,\n            MAX(p.card_no) AS card_no\n            FROM {$TRANS}PendingSpecialOrder as p\n                LEFT JOIN custdata AS c ON c.CardNo=p.card_no AND personNum=p.voided\n                LEFT JOIN {$TRANS}SpecialOrders AS o ON p.order_id=o.specialOrderID\n            WHERE 1=1 {$filterstring}\n            GROUP BY p.order_id,statusFlag,subStatus\n            HAVING \n                count(*) > 1 OR\n                SUM(CASE WHEN o.notes LIKE '' THEN 0 ELSE 1 END) > 0\n            ORDER BY MIN(datetime)";
     $p = $dbc->prepare($q);
     $r = $dbc->execute($p, $filterargs);
     $orders = array();
     $valid_ids = array();
     while ($w = $dbc->fetch_row($r)) {
         $orders[] = $w;
         $valid_ids[$w['order_id']] = true;
     }
     if ($f2 !== '' || $f3 !== '') {
         $filter = "";
         $args = array();
         if ($f2 !== '') {
             $filter .= "AND (m.superID IN (?) OR o.noteSuperID IN (?))";
             $args = array($f2, $f2);
         }
         if ($f3 !== '') {
             $filter .= "AND p.mixMatch=?";
             $args[] = $f3;
         }
         $q = "SELECT p.order_id FROM {$TRANS}PendingSpecialOrder AS p\n                LEFT JOIN MasterSuperDepts AS m ON p.department=m.dept_ID\n                LEFT JOIN {$TRANS}SpecialOrders AS o ON p.order_id=o.specialOrderID\n                WHERE 1=1 {$filter}\n                GROUP BY p.order_id";
         $p = $dbc->prepare($q);
         $r = $dbc->execute($p, $args);
         $valid_ids = array();
         while ($w = $dbc->fetch_row($r)) {
             $valid_ids[$w['order_id']] = true;
         }
         /**
           This may be redundant. Notes tagged by super
           department should be captured in the previous
           query. 
         */
         if ($f2 !== '' && $f3 === '') {
             $q2 = $dbc->prepare_statement("\n                    SELECT o.specialOrderID \n                    FROM {$TRANS}SpecialOrders AS o\n                    WHERE o.noteSuperID IN (?)\n                    GROUP BY o.specialOrderID");
             $r2 = $dbc->exec_statement($q2, array($f2));
             while ($w2 = $dbc->fetch_row($r2)) {
                 $valid_ids[$w2['specialOrderID']] = true;
             }
         }
     }
     /**
       Turn the list of valid order IDs into
       query parameters. Next step is to look
       up line items in the each order to list
       all items and vendors on the order summary 
       row
     */
     $oids = "(";
     $oargs = array();
     foreach ($valid_ids as $id => $nonsense) {
         $oids .= "?,";
         $oargs[] = $id;
     }
     $oids = rtrim($oids, ",") . ")";
     if (empty($oargs)) {
         $oids = '(?)';
         $oargs = array(-1);
         // avoid invalid query
     }
     $itemsQ = $dbc->prepare_statement("\n            SELECT order_id,\n                description,\n                mixMatch \n            FROM {$TRANS}PendingSpecialOrder \n            WHERE order_id IN {$oids}\n                AND trans_id > 0");
     $itemsR = $dbc->exec_statement($itemsQ, $oargs);
     $items = array();
     $suppliers = array();
     while ($itemsW = $dbc->fetch_row($itemsR)) {
         if (!isset($items[$itemsW['order_id']])) {
             $items[$itemsW['order_id']] = $itemsW['description'];
         } else {
             $items[$itemsW['order_id']] .= "; " . $itemsW['description'];
         }
         if (!empty($itemsW['mixMatch'])) {
             if (!isset($suppliers[$itemsW['order_id']])) {
                 $suppliers[$itemsW['order_id']] = $itemsW['mixMatch'];
             } else {
                 $suppliers[$itemsW['order_id']] .= "; " . $itemsW['mixMatch'];
             }
         }
     }
     $lenLimit = 10;
     foreach ($items as $id => $desc) {
         if (strlen($desc) <= $lenLimit) {
             continue;
         }
         $min = substr($desc, 0, $lenLimit);
         $rest = substr($desc, $lenLimit);
         $desc = sprintf('%s<span id="exp%d" style="display:none;">%s</span>
                 <a href="" onclick="$(\'#exp%d\').toggle();return false;">+</a>', $min, $id, $rest, $id);
         $items[$id] = $desc;
     }
     $lenLimit = 10;
     foreach ($suppliers as $id => $desc) {
         if (strlen($desc) <= $lenLimit) {
             continue;
         }
         $min = substr($desc, 0, $lenLimit);
         $rest = substr($desc, $lenLimit);
         $desc = sprintf('%s<span id="sup%d" style="display:none;">%s</span>
                 <a href="" onclick="$(\'#sup%d\').toggle();return false;">+</a>', $min, $id, $rest, $id);
         $suppliers[$id] = $desc;
     }
     $ret .= '<p />';
     $ret .= '<form id="pdfform" action="SpecialOrderTags.php" method="get">';
     $ret .= sprintf('<table class="table table-bordered table-striped tablesorter tablesorter-core">
                 <thead>
                 <tr>
                 <th>Order Date</th>
                 <th>Name</th>
                 <th>Desc</th>
                 <th>Supplier</th>
                 <th>Items</th>
                 <th>$</th>
                 <th>Status</th>
                 <th>Printed</th>', base64_encode("min(datetime)"), base64_encode("CASE WHEN MAX(p.card_no)=0 THEN MAX(o.lastName) ELSE MAX(c.LastName) END"), base64_encode("sum(total)"), base64_encode("count(*)-1"), base64_encode("statusFlag"));
     $ret .= sprintf('<td><img src="%s" alt="Print" 
             onclick="$(\'#pdfform\').submit();" /></td>', $this->config->get('URL') . 'src/img/buttons/action_print.gif');
     $ret .= '</tr></thead><tbody>';
     $fp = fopen($cachepath . $key, "w");
     foreach ($orders as $w) {
         $id = $w['order_id'];
         if (!isset($valid_ids[$id])) {
             continue;
         }
         $ret .= '<tr class="' . ($w['charflag'] == 'P' ? 'arrived' : 'notarrived') . '">';
         list($date, $time) = explode(' ', $w['orderDate'], 2);
         $ret .= sprintf('<td><a href="OrderViewPage.php?orderID=%d&k=%s">%s</a></td>', $id, $key, $date);
         $ret .= sprintf('<td><a href="" onclick="applyMemNum(%d); return false;">%s</a></td>', $w['card_no'], $w['name']);
         $ret .= '<td class="small">' . (isset($items[$id]) ? $items[$id] : '&nbsp;') . '</td>';
         $ret .= '<td class="small">' . (isset($suppliers[$id]) ? $suppliers[$id] : '&nbsp;') . '</td>';
         $ret .= sprintf('<td>%d</td>', $w['items']);
         $ret .= sprintf('<td>%.2f</td>', $w['value']);
         $ret .= '<td class="form-inline">
             <select id="s_status" class="form-control input-sm" onchange="updateStatus(' . $w['order_id'] . ',$(this).val());">';
         foreach ($status as $k => $v) {
             $ret .= sprintf('<option %s value="%d">%s</option>', $w['status_flag'] == $k ? 'selected' : '', $k, $v);
         }
         $ret .= "</select> <span id=\"statusdate{$id}\">" . ($w['sub_status'] == 0 ? 'No Date' : date('m/d/Y', $w['sub_status'])) . "</span></td>";
         $ret .= "<td align=center>" . ($w['charflag'] == 'P' ? 'Yes' : 'No') . "</td>";
         $ret .= sprintf('<td><input type="checkbox" %s name="oids[]" value="%d" 
                         onclick="togglePrint(\'%s\',%d);" /></td>', isset($prints[$id]) ? 'checked' : '', $id, $username, $id);
         $ret .= '</tr>';
         fwrite($fp, $w['order_id'] . "\n");
     }
     fclose($fp);
     $ret .= "</tbody></table>";
     $this->add_script('../src/javascript/tablesorter/jquery.tablesorter.js');
     $this->add_onload_command("\$('.tablesorter').tablesorter();");
     return $ret;
 }
예제 #10
0
    function body_content()
    {
        global $FANNIE_URL;
        $user = FannieAuth::checkLogin();
        ob_start();
        ?>
        <form style='margin-top:1.0em;' id="osForm" onsubmit="setdate(); return false;" >
        <div class="form-group form-inline">
        <label>Date</label>:<input class="form-control date-field" type=text id=date name=arg />
        <select class="form-control" name="mode">
            <option value="cashier">Cashier</option>
            <option value="drawer">Drawer</option>
        </select>
        <?php 
        $_REQUEST['store'] = 1;
        $sp = FormLib::storePicker();
        echo $sp['html'];
        ?>
        <button type=submit class="btn btn-default">Set</button>
        <input type=hidden id=user value="<?php 
        if (isset($user)) {
            echo $user;
        }
        ?>
" />
        </div>
        </form>

        <div id="loading-bar" class="collapse">
            <?php 
        echo \COREPOS\Fannie\API\lib\FannieUI::loadingBar();
        ?>
        </div>
        <div id="forms"></div>
        <?php 
        return ob_get_clean();
    }
예제 #11
0
 public function get_id_dreceipt_did_handler()
 {
     global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB;
     $bridge = GumLib::getSetting('posLayer');
     $this->custdata = $bridge::getCustdata($this->id);
     $this->meminfo = $bridge::getMeminfo($this->id);
     $uid = FannieAuth::getUID($this->current_user);
     // bridge may change selected database
     $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['GiveUsMoneyDB']);
     $model = new GumDividendsModel($dbc);
     $model->gumDividendID($this->did);
     $model->load();
     $msg = 'Dear ' . $this->custdata->FirstName() . ' ' . $this->custdata->LastName() . ',' . "\n";
     $msg .= "\n";
     $msg .= 'Attached is a 1099 for the Class C dividend issued ' . date('Y-m-d', strtotime($model->yearEndDate())) . "\n";
     $msg .= wordwrap('Whole Foods Co-op recognizes and thanks you for your support and purchase of Class C Stock. It is important that we maintain your current contact information so that we can deliver any dividends you may earn. Please reply to this email or to finance@wholefoods.coop with any questions or concerns. Or you may also call 218-728-0884, ask for Finance, and we will gladly assist you.') . "\n";
     $msg .= "\n";
     $msg .= 'Dale Maiers' . "\n";
     $msg .= 'Finance Manager' . "\n";
     $subject = 'SAMPLE WFC Owner Financing: Class C Stock Dividend';
     $to = $this->meminfo->email_1();
     $mail = new PHPMailer();
     $mail->From = '*****@*****.**';
     $mail->FromName = 'Whole Foods Co-op';
     $mail->AddAddress('*****@*****.**');
     $mail->AddAddress('*****@*****.**');
     $mail->Subject = $subject;
     $mail->Body = $msg;
     $year = date('Y', strtotime($model->yearEndDate()));
     $taxID = new GumTaxIdentifiersModel($dbc);
     $taxID->card_no($this->id);
     $taxID->load();
     $ssn = 'n/a';
     if ($taxID->maskedTaxIdentifier() != '') {
         $ssn = 'xxx-xx-' . $taxID->maskedTaxIdentifier();
     }
     $amount = array(1 => $model->dividendAmount());
     $pdf = new FPDF('P', 'mm', 'Letter');
     $pdf->AddPage();
     $form = new GumTaxFormTemplate($this->custdata, $this->meminfo, $ssn, $year, $amount);
     $form->renderAsPDF($pdf, 15);
     $raw_pdf = $pdf->Output('wfc.pdf', 'S');
     $mail->AddStringAttachment($raw_pdf, 'wfc.pdf', 'base64', 'application/pdf');
     if ($mail->Send()) {
         header('Location: GumEmailPage.php?id=' . $this->id);
     } else {
         echo $mail->ErrorInfo;
     }
     return false;
 }
예제 #12
0
 function process_file($linedata)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $skuCol = $this->get_column_index('sku');
     $costCol = $this->get_column_index('cost');
     $uQtyCol = $this->get_column_index('unitQty');
     $cQtyCol = $this->get_column_index('caseQty');
     $uSizeCol = $this->get_column_index('unitSize');
     $cSizeCol = $this->get_column_index('caseSize');
     $brandCol = $this->get_column_index('brand');
     $descCol = $this->get_column_index('desc');
     $upcCol = $this->get_column_index('upc');
     $upccCol = $this->get_column_index('upcc');
     $vendorID = FormLib::get('vendorID');
     $inv = FormLib::get('identifier', '');
     $orderDate = FormLib::get('orderDate', date('Y-m-d H:i:s'));
     $recvDate = FormLib::get('recvDate', '');
     $order = new PurchaseOrderModel($dbc);
     $order->vendorID($vendorID);
     $order->creationDate($orderDate);
     $order->placedDate($orderDate);
     $order->placed(1);
     $order->userID(FannieAuth::getUID());
     $order->vendorOrderID($inv);
     $order->vendorInvoiceID($inv);
     $orderID = $order->save();
     $item = new PurchaseOrderItemsModel($dbc);
     $info = new VendorItemsModel($dbc);
     $ret = '';
     foreach ($linedata as $line) {
         if (!isset($line[$skuCol])) {
             continue;
         }
         if (!isset($line[$costCol])) {
             continue;
         }
         $sku = $line[$skuCol];
         $cost = $line[$costCol];
         $cost = trim($cost, ' ');
         $cost = trim($cost, '$');
         if (!is_numeric($cost)) {
             $ret .= "<i>Omitting item {$sku}. Cost {$cost} isn't a number</i><br />";
             continue;
         }
         $unitQty = $uQtyCol !== false && isset($line[$uQtyCol]) ? $line[$uQtyCol] : 0;
         $caseQty = $cQtyCol !== false && isset($line[$cQtyCol]) ? $line[$cQtyCol] : 0;
         if ($unitQty == 0 && $caseQty == 0) {
             // no qty specified.
             continue;
         }
         $unitSize = $uSizeCol !== false && isset($line[$uSizeCol]) ? $line[$uSizeCol] : 0;
         $caseSize = $cSizeCol !== false && isset($line[$cSizeCol]) ? $line[$cSizeCol] : 0;
         $brand = $brandCol !== '' && isset($line[$brandCol]) ? $line[$brandCol] : '';
         $desc = $descCol !== false && isset($line[$descCol]) ? $line[$descCol] : '';
         $upc = '';
         if ($upcCol !== false && isset($line[$upcCol])) {
             $upc = BarcodeLib::padUPC($line[$upcCol]);
         } elseif ($upccCol !== false && isset($line[$upccCol])) {
             $upc = BarcodeLib::padUPC($line[$upccCol]);
             $upc = '0' . substr($upc, 0, 12);
         }
         $info->reset();
         $info->vendorID($vendorID);
         $info->sku($sku);
         if ($info->load()) {
             if ($brand === '') {
                 $brand = $info->brand();
             }
             if ($desc === '') {
                 $desc = $info->description();
             }
             if ($unitSize === 0) {
                 $unitSize = $info->size();
             }
             if ($caseSize === 0) {
                 $caseSize = $info->units();
             }
             $upc = $info->upc();
         }
         if ($caseQty == 0 && $unitQty != 0) {
             if ($caseSize == 0) {
                 $caseQty = $unitQty;
                 $caseSize = 1;
             } else {
                 $caseQty = $unitQty / $caseSize;
             }
         } elseif ($caseQty != 0 && $unitQty == 0) {
             if ($caseSize == 0) {
                 $unitQty = $caseQty;
                 $caseSize = 1;
             } else {
                 $unitQty = $caseQty * $caseSize;
             }
         } elseif ($caseQty != 0 && $unitQty != 0) {
             if ($caseSize == 0) {
                 $caseSize = $caseQty / $unitQty;
             }
         }
         $unitCost = $cost / $unitQty;
         $item->orderID($orderID);
         $item->sku($sku);
         if ($item->load()) {
             // multiple records for same item
             $item->quantity($caseQty + $item->quantity());
             if ($recvDate !== '') {
                 $item->receivedTotalCost($cost + $item->receivedTotalCost());
                 $item->receivedQty($caseQty + $item->receivedQty());
                 $item->receivedDate($recvDate);
             }
         } else {
             $item->quantity($caseQty);
             if ($recvDate !== '') {
                 $item->receivedTotalCost($cost);
                 $item->receivedQty($caseQty);
                 $item->receivedDate($recvDate);
             }
         }
         $item->unitCost($unitCost);
         $item->caseSize($caseSize);
         $item->brand($brand);
         $item->description($desc);
         $item->internalUPC($upc);
         $item->save();
     }
     $ret .= "<p>Import Complete";
     $ret .= '<br />';
     $ret .= '<a href="' . $this->config->get('URL') . 'purchasing/ViewPurchaseOrders.php?id=' . $orderID . '">View Order</a></p>';
     $this->results = $ret;
     return true;
 }
예제 #13
0
 function calculate_sidebar()
 {
     global $FANNIE_OP_DB;
     $userID = FannieAuth::getUID($this->current_user);
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $q = 'SELECT p.orderID, vendorName, 
         sum(case when i.orderID is null then 0 else 1 END) as rows, 
         MAX(creationDate) as date,
         sum(unitCost*caseSize*quantity) as estimatedCost
         FROM PurchaseOrder as p 
         INNER JOIN vendors as v ON p.vendorID=v.vendorID
         LEFT JOIN PurchaseOrderItems as i
         ON p.orderID=i.orderID
         WHERE p.userID=?
         GROUP BY p.orderID, vendorName
         ORDER BY vendorName';
     $p = $dbc->prepare_statement($q);
     $r = $dbc->exec_statement($p, array($userID));
     $ret = '<ul id="vendorList">';
     while ($w = $dbc->fetch_row($r)) {
         $ret .= '<li><span id="orderInfoVendor">' . $w['vendorName'] . '</span>';
         $ret .= '<ul class="vendorSubList"><li>' . $w['date'];
         $ret .= '<li># of Items: <span class="orderInfoCount">' . $w['rows'] . '</span>';
         $ret .= '<li>Est. cost: $<span class="orderInfoCost">' . sprintf('%.2f', $w['estimatedCost']) . '</span>';
         $ret .= '</ul></li>';
     }
     $ret .= '</ul>';
     return $ret;
 }
예제 #14
0
    protected function get_orderID_items_handler()
    {
        $dbc = $this->connection;
        $dbc->selectDB($this->config->get('OP_DB'));
        $ret = <<<HTML
<form> 
<div class="form-inline">
    <div class="input-group">
        <span class="input-group-addon">UPC</span> 
        <input type="text" id="newupc" class="form-control input-sm" maxlength="35" />
    </div>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <div class="input-group">
        <span class="input-group-addon">Cases</span> 
        <input id="newcases" maxlength="2" value="1" size="3" class="form-control input-sm" />
    </div>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button type="submit" class="btn btn-default btn-sm">Add Item</button>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <button type="button" class="btn btn-default btn-sm btn-search">Search</button>
</div>
</form>
<p />
HTML;
        if (FannieAuth::validateUserQuiet('ordering_edit')) {
            $ret .= $this->editableItemList($this->orderID);
        } else {
            $ret .= itemList($this->orderID);
        }
        $ret .= '<p />';
        $ret .= '<b><a href="" onclick="$(\'#manualclosebuttons\').toggle();return false;">Manually close order</a></b>';
        $ret .= sprintf('<span id="manualclosebuttons" class="collapse"> as:
                <a href="" class="btn btn-default close-order-btn" data-close="7">Completed</a>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="" class="btn btn-default close-order-btn" data-close="8">Canceled</a>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="" class="btn btn-default close-order-btn" data-close="9">Inquiry</a>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
                <div class="alert alert-danger">Closing an order means slips for these
                items will no longer scan at the registers</div></span>', $this->orderID, $this->orderID, $this->orderID);
        echo $ret;
        return false;
    }
예제 #15
0
 function save_item($isNew)
 {
     $FANNIE_PRODUCT_MODULES = $this->config->get('PRODUCT_MODULES');
     $FANNIE_URL = $this->config->get('URL');
     $upc = FormLib::get_form_value('upc', '');
     if ($upc === '' || !is_numeric($upc)) {
         return '<span style="color:red;">Error: bad UPC:</span> ' . $upc;
     }
     $upc = BarcodeLib::padUPC($upc);
     $audited = false;
     if (FannieAuth::validateUserQuiet('pricechange')) {
         // validated; nothing to do
     } elseif (FannieAuth::validateUserQuiet('audited_pricechange')) {
         $audited = true;
     } elseif (($range = FannieAuth::validateUserLimited('pricechange')) !== false) {
         // validated for certain departments; nothing to do
     } else {
         // not authorized to make edits
         return '<span style="color:red;">Error: Log in to edit</span>';
     }
     uasort($FANNIE_PRODUCT_MODULES, array('ItemEditorPage', 'sortModules'));
     $form = new \COREPOS\common\mvc\FormValueContainer();
     foreach ($FANNIE_PRODUCT_MODULES as $class => $params) {
         $mod = new $class();
         $mod->setConnection($this->connection);
         $mod->setConfig($this->config);
         $mod->setForm($form);
         $mod->SaveFormData($upc);
     }
     /* push updates to the lanes */
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $FANNIE_COOP_ID = $this->config->get('COOP_ID');
     if (isset($FANNIE_COOP_ID) && $FANNIE_COOP_ID == 'WEFC_Toronto') {
         updateAllLanes($upc, array('products', 'productUser'));
     } else {
         updateProductAllLanes($upc);
     }
     if ($audited) {
         $lc = FormLib::get('likeCode', -1);
         $no_update = FormLib::get('LikeCodeNoUpdate', false);
         if ($lc != -1 && !$no_update) {
             \COREPOS\Fannie\API\lib\AuditLib::itemUpdate($upc, $lc);
         } else {
             \COREPOS\Fannie\API\lib\AuditLib::itemUpdate($upc);
         }
     }
     $ret = "<table class=\"table\">";
     foreach ($FANNIE_PRODUCT_MODULES as $class => $params) {
         $mod = new $class();
         $rows = $mod->summaryRows($upc);
         foreach ($rows as $row) {
             $ret .= '<tr>' . $row . '</tr>';
         }
     }
     $ret .= '</table>';
     return $ret;
 }
예제 #16
0
 public function run($args = array())
 {
     global $FANNIE_URL;
     $data = array();
     $action = FormLib::get_form_value('action');
     if ($action !== '') {
         $data[] = $action;
         switch ($action) {
             case 'save_or_add_event':
                 $calID = FormLib::get('id', 0);
                 $text = FormLib::get('text');
                 $text = str_replace('<br>', "\n", $text);
                 $text = htmlspecialchars($text);
                 $text = str_replace("\n", '<br>', $text);
                 $db = CalendarPluginDB::get();
                 $event = new MonthviewEventsModel($db);
                 $eventID = FormLib::get('eventID', false);
                 if ($eventID !== false) {
                     $event->eventID($eventID);
                     $event->eventText($text);
                     if (!empty($text)) {
                         $event->save();
                     } else {
                         $event->delete();
                     }
                 } else {
                     $date = FormLib::get('datestr');
                     $uid = FormLib::get('uid');
                     $event->eventDate($date);
                     $event->calendarID($calID);
                     $event->uid($uid);
                     $event->eventText($text);
                     if (!empty($text)) {
                         $eventID = $event->save();
                         $data = array();
                         echo $eventID;
                     }
                 }
                 $calendar = new CalendarsModel($db);
                 $calendar->calendarID($calID);
                 $calendar->modified(1);
                 $calendar->save();
                 break;
             case 'monthview_save':
                 $date = FormLib::get_form_value('date');
                 $id = FormLib::get_form_value('id', 0);
                 $text = FormLib::get_form_value('text');
                 $uid = FormLib::get_form_value('uid', 0);
                 $db = CalendarPluginDB::get();
                 $chkP = $db->prepare_statement("SELECT calendarID FROM monthview_events \n                        WHERE eventDate=? and uid=? and calendarID=?");
                 $rowCheck = $db->exec_statement($chkP, array($date, $uid, $id));
                 if ($db->num_rows($rowCheck) <= 0 && $text != "") {
                     $insP = $db->prepare_statement("INSERT INTO monthview_events \n                                                    (calendarID, eventDate, eventText, uid) VALUES (?,?,?,?)");
                     $db->exec_statement($insP, array($id, $date, $text, $uid));
                 } else {
                     if ($text == "") {
                         $delP = $db->prepare_statement("DELETE FROM monthview_events WHERE\n                            calendarID=? AND eventDate=?\n                            AND uid=?");
                         $db->exec_statement($delP, array($id, $date, $uid));
                     } else {
                         $upP = $db->prepare_statement("UPDATE monthview_events SET\n                            eventText=?\n                            WHERE calendarID=? AND eventDate=?\n                            AND uid=?");
                         $db->exec_statement($upP, array($text, $id, $date, $uid));
                     }
                 }
                 $calendar = new CalendarsModel($db);
                 $calendar->calendarID($id);
                 $calendar->modified(1);
                 $calendar->save();
                 break;
             case 'createCalendar':
                 $name = FormLib::get_form_value('name');
                 $uid = FormLib::get_form_value('uid', 0);
                 $db = CalendarPluginDB::get();
                 $p = $db->prepare_statement("INSERT INTO calendars (name) VALUES (?)");
                 $db->exec_statement($p, array($name));
                 $id = $db->insert_id();
                 $p = $db->prepare_statement("INSERT INTO permissions (calendarID,uid,classID)\n                                VALUES (?,?,4)");
                 $db->exec_statement($p, array($id, $uid));
                 $data[] = "<p class=\"index\"><a href=\"?calID={$id}&view=month\">{$name}</a></p>";
                 break;
             case 'createSubscription':
                 $db = CalendarPluginDB::get();
                 $name = FormLib::get('name');
                 $url = FormLib::get('url');
                 $uid = FormLib::get_form_value('uid', 0);
                 $subscription = new CalendarSubscriptionsModel($db);
                 $subscription->url($url);
                 $subscriptionID = $subscription->save();
                 $calendar = new CalendarsModel($db);
                 $calendar->name($name);
                 $calendar->calendarSubscriptionID($subscriptionID);
                 $calendarID = $calendar->save();
                 $permissions = new PermissionsModel($db);
                 $permissions->calendarID($calendarID);
                 $permissions->uid($uid);
                 $permissions->classID(4);
                 $permissions->save();
                 $data[] = 'Subscribed';
                 break;
             case 'savePrefs':
                 $calID = FormLib::get_form_value('calID');
                 $name = str_replace("'", "''", $_GET['name']);
                 $name = FormLib::get_form_value('name');
                 $viewers = FormLib::get_form_value('viewers', array());
                 $writers = FormLib::get_form_value('writers', array());
                 $db = CalendarPluginDB::get();
                 $calendar = new CalendarsModel($db);
                 $calendar->calendarID($calID);
                 $calendar->load();
                 $calendar->name($name);
                 $calendar->save();
                 $p = $db->prepare_statement("DELETE FROM permissions WHERE calendarID=? and classID < 4");
                 $db->exec_statement($p, array($calID));
                 $insP = $db->prepare_statement("INSERT INTO permissions (calendarID,uid,classID) VALUES (?,?,?)");
                 if ($viewers != "") {
                     foreach (explode(",", $viewers) as $v) {
                         $db->exec_statement($insP, array($calID, $v, 1));
                     }
                 }
                 if ($writers != "") {
                     foreach (explode(",", $writers) as $w) {
                         $db->exec_statement($insP, array($calID, $w, 2));
                     }
                 }
                 if (FormLib::get('url')) {
                     $url = FormLib::get('url');
                     $sub = new CalendarSubscriptionsModel($db);
                     $sub->calendarSubscriptionID($calendar->calendarSubscriptionID());
                     $sub->url($url);
                     $sub->save();
                 }
                 break;
             case 'weekview_save':
                 $timestamp = FormLib::get_form_value('ts');
                 $date = date('Y-m-d H:i:00', $timestamp);
                 $calID = FormLib::get_form_value('id', 0);
                 $text = trim(FormLib::get_form_value('text'));
                 $eID = FormLib::get('eventID', false);
                 $uid = FannieAuth::getUID(FannieAuth::checkLogin());
                 $pat = '/#(\\d+)/';
                 $rep = '<a href="' . $FANNIE_URL . 'modules/plugins2.0/PIKiller/PIMemberPage.php?id=${1}" onclick="noBubble(event);">#${1}</a>';
                 $text = preg_replace($pat, $rep, $text);
                 $db = CalendarPluginDB::get();
                 $model = new MonthviewEventsModel($db);
                 if ($eID) {
                     $model->eventID($eID);
                 }
                 if (empty($text) && $eID) {
                     // delete empty event
                     // no eID implies event doesn't exist
                     // just opened/closed w/o content
                     $model->delete();
                 } else {
                     if (!empty($text)) {
                         $model->uid($uid);
                         $model->eventDate($date);
                         $model->eventText($text);
                         $model->calendarID($calID);
                         $newID = $model->save();
                         if (!$eID) {
                             $data[] = $newID;
                         }
                     }
                 }
                 break;
         }
     }
     return $data;
 }
예제 #17
0
 /**
   Main page. Vendor is selected. Find/create order
   based on vendorID & userID
 */
 function get_id_view()
 {
     global $FANNIE_OP_DB;
     $vendorID = $this->id;
     $userID = FannieAuth::getUID($this->current_user);
     $orderID = $this->getOrderID($vendorID, $userID);
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $q = 'SELECT vendorName, 
         sum(case when i.orderID is null then 0 else 1 END) as rows, 
         MAX(creationDate) as date,
         sum(unitCost*caseSize*quantity) as estimatedCost
         FROM PurchaseOrder as p 
         INNER JOIN vendors as v ON p.vendorID=v.vendorID
         LEFT JOIN PurchaseOrderItems as i
         ON p.orderID=i.orderID
         WHERE p.orderID=?';
     $p = $dbc->prepare_statement($q);
     $r = $dbc->exec_statement($p, array($orderID));
     $w = $dbc->fetch_row($r);
     $ret = '<div id="orderInfo">
         <span id="orderInfoVendor">' . $w['vendorName'] . '</span>';
     $ret .= ' ' . $w['date'];
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= ' # of Items: <span id="orderInfoCount">' . $w['rows'] . '</span>';
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= ' Est. cost: $<span id="orderInfoCost">' . sprintf('%.2f', $w['estimatedCost']) . '</span>';
     $ret .= '</div><hr />';
     $ret .= '<div id="ItemSearch">';
     $ret .= '<form class="form-inline" action="" onsubmit="itemSearch();return false;">';
     $ret .= '<div class="form-group">';
     $ret .= '<label class="control-label">UPC/SKU</label><input class="form-control" type="text" id="searchField" />';
     $ret .= '</div>';
     $ret .= '<div class="form-group">';
     $ret .= '&nbsp;&nbsp;&nbsp;';
     $ret .= '<button type="submit" class="btn btn-default">Search</button>';
     $ret .= '&nbsp;&nbsp;&nbsp;';
     $ret .= '<button type="button" class="btn btn-default" onclick="location=\'PurchasingIndexPage.php\'; return false;">Home</button>';
     $ret .= '&nbsp;&nbsp;&nbsp;';
     $ret .= '<button type="button" class="btn btn-default" onclick="location=\'ViewPurchaseOrders.php?id=' . $orderID . '\'; return false;">View Order</button>';
     $ret .= '</div>';
     $ret .= '</form>';
     $ret .= '</div>';
     $ret .= '<p><div id="SearchResults"></div></p>';
     $ret .= sprintf('<input type="hidden" id="id" value="%d" />', $this->id);
     $this->add_onload_command("\$('#searchField').focus();\n");
     $this->add_script('js/editone.js');
     return $ret;
 }
예제 #18
0
 public function post_id_handler()
 {
     $dbc = FannieDB::get($this->config->get('OP_DB'));
     $ret = array('error' => false);
     $date = FormLib::get('order-date', date('Y-m-d'));
     $po_num = FormLib::get('po-number');
     $inv_num = FormLib::get('inv-number');
     $sku = FormLib::get('sku', array());
     $upc = FormLib::get('upc', array());
     $cases = FormLib::get('cases', array());
     $caseSize = FormLib::get('case-size', array());
     $total = FormLib::get('total', array());
     $brand = FormLib::get('brand', array());
     $description = FormLib::get('description', array());
     if (count($sku) == 0) {
         $ret['error'] = true;
         $ret['message'] = 'Order must have at least one item';
         echo json_encode($ret);
         return false;
     }
     /**
       Queries to check for vendorItems entries
     */
     $skuP = $dbc->prepare('
         SELECT size
         FROM vendorItems
         WHERE vendorID=?
             AND sku=?');
     $upcP = $dbc->prepare('
         SELECT size
         FROM vendorItems
         WHERE vendorID=?
             AND upc=?');
     $vitem = new VendorItemsModel($dbc);
     /**
       Create parent record for the order
     */
     $po = new PurchaseOrderModel($dbc);
     $po->vendorID($this->id);
     $po->creationDate($date);
     $po->placed(1);
     $po->placedDate($date);
     $po->userID(FannieAuth::getUID());
     $po->vendorOrderID($po_num);
     $po->vendorInvoiceID($inv_num);
     // if an orderID is supplied, update the existing order
     if (FormLib::get('order-id') !== '' && is_numeric(FormLib::get('order-id'))) {
         $orderID = FormLib::get('order-id');
         $po->orderID($orderID);
         $po->save();
     } else {
         $orderID = $po->save();
     }
     if (!$orderID) {
         $ret['error'] = true;
         $ret['message'] = 'Could not create new order';
         echo json_encode($ret);
         return false;
     }
     /**
       Create item records for the order
     */
     $pitem = new PurchaseOrderItemsModel($dbc);
     for ($i = 0; $i < count($sku); $i++) {
         $pitem->reset();
         $pitem->orderID($orderID);
         $pitem->sku($sku[$i]);
         $units = $caseSize[$i];
         $qty = $cases[$i];
         $unitCost = $total[$i] / $qty / $units;
         /**
           Multiple same-SKU records
           Sum the quantities and costs to merge
           into a single record
         */
         if ($pitem->load()) {
             $qty += $pitem->receivedQty();
             $total[$i] += $pitem->receivedTotalCost();
         }
         $pitem->quantity($qty);
         $pitem->caseSize($units);
         $pitem->unitSize('');
         $pitem->unitCost($unitCost);
         $pitem->receivedDate($date);
         $pitem->receivedQty($qty);
         $pitem->receivedTotalCost($total[$i]);
         $pitem->brand($brand[$i]);
         $pitem->description($description[$i]);
         $pitem->internalUPC($upc[$i]);
         /**
           Try to look up unit size using
           vendorID+sku or vendorID+upc.
           This avoids making unit size a required
           field *and* checks for an existing
           vendorItems record
         */
         $size = false;
         $skuR = $dbc->execute($skuP, array($this->id, $sku[$i]));
         if ($skuR && $dbc->numRows($skuR)) {
             $size = true;
             $w = $dbc->fetchRow($skuR);
             $pitem->unitSize($w['size']);
         }
         if ($size === false) {
             $upcR = $dbc->execute($upcP, array($this->id, $upc[$i]));
             if ($upcR && $dbc->numRows($upcR)) {
                 $size = true;
                 $w = $dbc->fetchRow($upcR);
                 $pitem->unitSize($w['size']);
             }
         }
         $pitem->save();
         /**
           If no vendorItems record exists for this
           SKU or UPC then create one
         */
         if ($size === false) {
             $vitem->reset();
             $vitem->vendorID($this->id);
             $vitem->sku($sku[$i]);
             $vitem->upc($upc[$i]);
             $vitem->brand($brand[$i]);
             $vitem->description($description[$i]);
             $vitem->size('');
             $vitem->units($qty);
             $vitem->cost($unitCost);
             $vitem->saleCost(0.0);
             $vitem->vendorDept(0);
             $vitem->save();
         }
     }
     $ret['order_id'] = $orderID;
     echo json_encode($ret);
     return false;
 }
예제 #19
0
파일: AuditLib.php 프로젝트: phpsmith/IS4C
 public static function batchNotification($batchID, $upc, $type, $is_likecode = false)
 {
     $conf = \FannieConfig::factory();
     $dbc = \FannieDB::getReadOnly($conf->get('OP_DB'));
     $likecode = '';
     $desc = '';
     $dept = 0;
     if ($is_likecode) {
         if (substr($upc, 0, 2) == 'LC') {
             $likecode = substr($upc, 2);
         } else {
             $likecode = $upc;
         }
         // upc is a like code. find the description
         // and a valid upc (hence inner join)
         $infoQ = 'SELECT p.department,
                 l.likeCodeDesc 
               FROM upcLike AS u
                 ' . DTrans::joinProducts('u', 'p', 'INNER') . '
                 LEFT JOIN likeCodes AS l ON u.likeCode=l.likeCode
               WHERE u.likeCode=?';
         $infoP = $dbc->prepare($infoQ);
         $infoR = $dbc->execute($infoP, array($likecode));
         if ($dbc->num_rows($infoR) == 0) {
             // invalid like code
             return false;
         }
         $infoW = $dbc->fetch_row($infoR);
         $desc = $infoW['likeCodeDesc'];
         $dept = $infoW['department'];
     } else {
         $product = new \ProductsModel($dbc);
         $product->upc($upc);
         $product->load();
         $desc = $product->description();
         $dept = $product->department();
     }
     $to_addr = self::getAddresses($dept);
     if ($to_addr === false) {
         // no one set to receive notices
         return false;
     }
     $batch = new \BatchesModel($dbc);
     $batch->batchID($batchID);
     $batch->load();
     $batchList = new \BatchListModel($dbc);
     $batchList->upc($upc);
     $batchList->batchID($batchID);
     $batchList->load();
     $subject = "Batch Update notification: " . $batch->batchName();
     $message = "Batch " . $batch->batchName() . " has been changed\n";
     if ($is_likecode) {
         $message .= 'Like code ' . $likecode . '(' . $desc . ') ';
     } else {
         $message .= 'Item ' . $upc . '(' . $desc . ') ';
     }
     switch ($type) {
         case self::BATCH_ADD:
             $message .= "has been added to the batch\n";
             $message .= 'Sale Price: $' . $batchList->salePrice() . "\n";
             break;
         case self::BATCH_EDIT:
             $message .= "has been re-priced\n";
             $message .= 'Sale Price: $' . $batchList->salePrice() . "\n";
             break;
         case self::BATCH_DELETE:
             $message .= "has been deleted from the batch\n";
             break;
         default:
             $message .= "may have experienced unknown changes\n";
             return false;
             // remove after testing; don't send lots of these in error
             break;
     }
     $message .= "\n";
     $message .= "View this batch:\n";
     $url = $conf->get('URL');
     $server_name = filter_input(INPUT_SERVER, 'SERVER_NAME');
     $message .= "http://{$server_name}{$url}batches/newbatch/EditBatchPage.php?id={$batchID}\n";
     $message .= "\n";
     $message .= "View this item:\n";
     $message .= "http://{$server_name}/{$url}item/ItemEditorPage.php?searchupc={$upc}\n";
     $message .= "\n";
     $username = \FannieAuth::checkLogin();
     if (!$username) {
         $username = '******';
     }
     $message .= "This change was made by user {$username}\n";
     $from = "From: automail\r\n";
     mail($to_addr, $subject, $message, $from);
     return true;
 }
예제 #20
0
 function post_id_handler()
 {
     global $FANNIE_OP_DB;
     if (!FannieAuth::validateUserQuiet('editmembers') && !FannieAuth::validateUserQuiet('editmembers_csc')) {
         return $this->unknown_request_handler();
     }
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $status = FormLib::get_form_value('status', 'INACT');
     $codes = FormLib::get_form_value('reasoncodes', array());
     $code = 0;
     foreach ($codes as $selected_code) {
         $code = $code | (int) $selected_code;
     }
     $cas_model = new CustomerAccountSuspensionsModel($dbc);
     $cas_model->card_no($this->id);
     $current_id = 0;
     $account = \COREPOS\Fannie\API\member\MemberREST::get($this->id);
     if ($code == 0) {
         // reactivate account
         // add history/log record, restore settings, delete suspensions record
         $history = new SuspensionHistoryModel($dbc);
         $history->username($this->current_user);
         $history->cardno($this->id);
         $history->reasoncode(-1);
         $history->post('Account reactivated');
         $history->postdate(date('Y-m-d H:i:s'));
         $history->save();
         $cas_model->reasonCode(0);
         $cas_model->suspensionTypeID(0);
         $cas_model->active(0);
         $cas_model->username($this->current_user);
         $cas_model->tdate(date('Y-m-d H:i:s'));
         $cas_model->save();
         if (isset($this->__models['suspended'])) {
             $json = array('cardNo' => $this->id, 'activeStatus' => '', 'memberStatus' => $this->__models['suspended']->memtype2(), 'customerTypeID' => $this->__models['suspended']->memtype1(), 'chargeLimit' => $this->__models['suspended']->chargelimit(), 'contactAllowed' => $this->__models['suspended']->mailflag(), 'customers' => array());
             foreach ($account['customers'] as $c) {
                 $c['discount'] = $this->__models['suspended']->discount();
                 $c['chargeAllowed'] = 1;
                 $json['customers'][] = $c;
             }
             \COREPOS\Fannie\API\member\MemberREST::post($this->id, $json);
             $cust = new CustdataModel($dbc);
             $cust->CardNo($this->id);
             foreach ($cust->find() as $obj) {
                 $obj->pushToLanes();
             }
             $this->__models['suspended']->delete();
         }
     } elseif (isset($this->__models['suspended'])) {
         // account already suspended
         // add history/log record, update suspended record
         $m_status = 0;
         if ($status == 'TERM') {
             $this->__models['suspended']->type('T');
             $m_status = 2;
         } else {
             $this->__models['suspended']->type('I');
             $m_status = 1;
         }
         $this->__models['suspended']->reasoncode($code);
         $this->__models['suspended']->suspDate(date('Y-m-d H:i:s'));
         $this->__models['suspended']->save();
         $history = new SuspensionHistoryModel($dbc);
         $history->username($this->current_user);
         $history->cardno($this->id);
         $history->reasoncode($code);
         $history->postdate(date('Y-m-d H:i:s'));
         $history->save();
         $changed = false;
         $cas_model->active(1);
         // find most recent active record
         $current = $cas_model->find('tdate', true);
         foreach ($current as $obj) {
             if ($obj->reasonCode() != $code || $obj->suspensionTypeID() != $m_status) {
                 $changed = true;
             }
             $cas_model->savedType($obj->savedType());
             $cas_model->savedMemType($obj->savedMemType());
             $cas_model->savedDiscount($obj->savedDiscount());
             $cas_model->savedChargeLimit($obj->savedChargeLimit());
             $cas_model->savedMailFlag($obj->savedMailFlag());
             // copy "saved" values from current active
             // suspension record. should only be one
             break;
         }
         // only add a record if something changed.
         // count($current) of zero means there is no
         // record. once the migration to the new data
         // structure is complete, that check won't
         // be necessary
         if ($changed || count($current) == 0) {
             $cas_model->reasonCode($code);
             $cas_model->username($this->current_user);
             $cas_model->tdate(date('Y-m-d H:i:s'));
             $cas_model->suspensionTypeID($m_status);
             $current_id = $cas_model->save();
         }
         $json = array('cardNo' => $this->id, 'activeStatus' => $status);
         \COREPOS\Fannie\API\member\MemberREST::post($this->id, $json);
     } else {
         // suspend active account
         // create suspensions and log/history records
         // set custdata & meminfo to inactive
         $discount = 0;
         foreach ($account['customers'] as $c) {
             if ($c['accountHolder']) {
                 $discount = $c['discount'];
                 break;
             }
         }
         $susp = new SuspensionsModel($dbc);
         $susp->cardno($this->id);
         $susp->type($status == 'TERM' ? 'T' : 'I');
         $susp->memtype1($account['customerTypeID']);
         $susp->memtype2($account['memberStatus']);
         $susp->suspDate(date('Y-m-d H:i:s'));
         $susp->reason('');
         $susp->mailflag($account['contactAllowed']);
         $susp->discount($discount);
         $susp->chargelimit($account['chargeLimit']);
         $susp->reasoncode($code);
         $susp->save();
         $cas_model->savedType($account['memberStatus']);
         $cas_model->savedMemType($account['customerTypeID']);
         $cas_model->savedDiscount($discount);
         $cas_model->savedChargeLimit($account['chargeLimit']);
         $cas_model->savedMailFlag($account['contactAllowed']);
         $cas_model->suspensionTypeID($status == 'TERM' ? 2 : 1);
         $cas_model->tdate(date('Y-m-d H:i:s'));
         $cas_model->username($this->current_user);
         $cas_model->reasonCode($code);
         $cas_model->active(1);
         $current_id = $cas_model->save();
         $history = new SuspensionHistoryModel($dbc);
         $history->username($this->current_user);
         $history->cardno($this->id);
         $history->reasoncode($code);
         $history->postdate(date('Y-m-d H:i:s'));
         $history->save();
         $json = array('cardNo' => $this->id, 'chargeLimit' => 0, 'activeStatus' => $status, 'customerTypeID' => 0, 'contactAllowed' => 0, 'customers' => array());
         foreach ($account['customers'] as $c) {
             $c['discount'] = 0;
             $json['customers'][] = $c;
         }
         \COREPOS\Fannie\API\member\MemberREST::post($this->id, $json);
     }
     // only one CustomerAccountSuspensions record should be active
     if ($current_id != 0) {
         $cas_model->reset();
         $cas_model->card_no($this->id);
         $cas_model->active(1);
         foreach ($cas_model->find() as $obj) {
             if ($obj->customerAccountSuspensionID() != $current_id) {
                 $obj->active(0);
                 $obj->save();
             }
         }
     }
     header('Location: PIMemberPage.php?id=' . $this->id);
     return False;
 }
예제 #21
0
 function get_orders($placed)
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $month = FormLib::get('month');
     $year = FormLib::get('year');
     $start = date('Y-m-01 00:00:00', mktime(0, 0, 0, $month, 1, $year));
     $end = date('Y-m-t 23:59:59', mktime(0, 0, 0, $month, 1, $year));
     $query = 'SELECT p.orderID, p.vendorID, MIN(creationDate) as creationDate,
             MIN(placedDate) as placedDate, COUNT(i.orderID) as records,
             SUM(i.unitCost*i.caseSize*i.quantity) as estimatedCost,
             SUM(i.receivedTotalCost) as receivedCost, v.vendorName,
             MAX(i.receivedDate) as receivedDate,
             p.vendorInvoiceID
         FROM PurchaseOrder as p
             LEFT JOIN PurchaseOrderItems AS i ON p.orderID = i.orderID
             LEFT JOIN vendors AS v ON p.vendorID=v.vendorID
         WHERE placed=? 
             AND creationDate BETWEEN ? AND ? ';
     if (!$this->show_all) {
         $query .= 'AND userID=? ';
     }
     $query .= 'GROUP BY p.orderID, p.vendorID, v.vendorName 
                ORDER BY MIN(creationDate) DESC';
     $args = array($placed, $start, $end);
     if (!$this->show_all) {
         $args[] = FannieAuth::getUID($this->current_user);
     }
     $prep = $dbc->prepare_statement($query);
     $result = $dbc->exec_statement($prep, $args);
     $ret = '<div class="table-responsive">
         <table class="table table-striped table-bordered tablesorter">';
     $ret .= '<thead><tr><th>Created</th><th>Invoice#</th><th>Vendor</th><th># Items</th><th>Est. Cost</th>
         <th>Placed</th><th>Received</th><th>Rec. Cost</th></tr></thead><tbody>';
     $count = 1;
     while ($w = $dbc->fetch_row($result)) {
         $ret .= sprintf('<tr><td><a href="ViewPurchaseOrders.php?id=%d">%s</a></td>
                 <td>%s</td>
                 <td>%s</td><td>%d</td><td>%.2f</td>
                 <td>%s</td><td>%s</td><td>%.2f</td></tr>', $w['orderID'], $w['creationDate'], $w['vendorInvoiceID'], $w['vendorName'], $w['records'], $w['estimatedCost'], $placed == 1 ? $w['placedDate'] : '&nbsp;', !empty($w['receivedDate']) ? $w['receivedDate'] : '&nbsp;', !empty($w['receivedCost']) ? $w['receivedCost'] : 0.0);
     }
     $ret .= '</tbody></table></div>';
     return $ret;
 }
예제 #22
0
 /**
   Log updates to many products at once
   @param $upcs [array] of UPCs
   @param $type [string] update type
   @param $user [string] username
   @return [boolean] success
 */
 public function logManyUpdates($upcs, $type = 'UNKNOWN', $user = false)
 {
     if (count($upcs) == 0) {
         // nothing to log
         return true;
     }
     $col_map = array('upc' => 'p.upc', 'description' => 'description', 'price' => 'normal_price', 'salePrice' => 'special_price', 'cost' => 'cost', 'dept' => 'department', 'tax' => 'tax', 'fs' => 'foodstamp', 'scale' => 'scale', 'modified' => 'modified', 'forceQty' => 'qttyEnforced', 'noDisc' => 'discount', 'inUse' => 'inUse', 'likeCode' => 'likeCode', 'storeID' => 'store_id');
     if (!$user) {
         $user = FannieAuth::getUID(FannieAuth::checkLogin());
     }
     $select_cols = '?,?,';
     $insert_cols = 'updateType,' . $this->connection->identifier_escape('user') . ',';
     foreach ($col_map as $insert => $select) {
         $insert_cols .= $this->connection->identifier_escape($insert) . ',';
         // identifier escape does not handle alias prefix
         $select_cols .= ($select == 'p.upc' ? $select : $this->connection->identifier_escape($select)) . ',';
     }
     $insert_cols = substr($insert_cols, 0, strlen($insert_cols) - 1);
     $select_cols = substr($select_cols, 0, strlen($select_cols) - 1);
     $args = array($type, $user);
     $upc_in = '';
     foreach ($upcs as $upc) {
         $args[] = $upc;
         $upc_in .= '?,';
     }
     $upc_in = substr($upc_in, 0, strlen($upc_in) - 1);
     $query = 'INSERT INTO prodUpdate (' . $insert_cols . ')
               SELECT ' . $select_cols . '
               FROM products AS p
                 LEFT JOIN upcLike AS u ON p.upc=u.upc
               WHERE p.upc IN (' . $upc_in . ')';
     $prep = $this->connection->prepare($query);
     $res = $this->connection->execute($prep, $args);
     return $res ? true : false;
 }
예제 #23
0
 public function get_view()
 {
     $dbc = $this->connection;
     $dbc->selectDB($this->config->get('OP_DB'));
     $TRANS = $this->config->get('TRANS_DB') . $dbc->sep();
     $oids = FormLib::get('oids', array());
     if (!is_array($oids) || count($oids) == 0) {
         return '<div class="alert alert-danger">No order(s) selected</div>';
     }
     ?>
     <script type="text/javascript">
     function toggleChecked(status){
         $(".cbox").each( function() {
             $(this).attr("checked",status);
         });
     }
     </script>
     <?php 
     echo '<form method="get">';
     echo '<input type="checkbox" id="sa" onclick="toggleChecked(this.checked);" />';
     echo '<label for="sa"><b>Select All</b></label>';
     echo '<table class="table table-bordered table-striped small">';
     $username = FannieAuth::checkLogin();
     $cachepath = sys_get_temp_dir() . "/ordercache/";
     if (file_exists("{$cachepath}{$username}.prints")) {
         $prints = unserialize(file_get_contents("{$cachepath}{$username}.prints"));
         foreach ($prints as $oid => $data) {
             if (!in_array($oid, $_REQUEST['oids'])) {
                 $_REQUEST['oids'][] = $oid;
             }
         }
     }
     $infoP = $dbc->prepare_statement("SELECT min(datetime) as orderDate,sum(total) as value,\n            count(*)-1 as items,\n            CASE WHEN MAX(p.card_no)=0 THEN MAX(o.lastName) ELSE MAX(c.LastName) END as name\n            FROM {$TRANS}PendingSpecialOrder AS p\n            LEFT JOIN custdata AS c ON c.CardNo=p.card_no AND personNum=p.voided\n            LEFT JOIN {$TRANS}SpecialOrders AS o ON o.specialOrderID=p.order_id \n            WHERE p.order_id=?");
     $itemP = $dbc->prepare_statement("SELECT description,department,quantity,ItemQtty,total,trans_id\n            FROM {$TRANS}PendingSpecialOrder WHERE order_id=? AND trans_id > 0");
     foreach ($_REQUEST['oids'] as $oid) {
         $r = $dbc->exec_statement($infoP, array($oid));
         $w = $dbc->fetch_row($r);
         printf('<tr><td colspan="2">Order #%d (%s, %s)</td><td>Amt: $%.2f</td>
             <td>Items: %d</td><td>&nbsp;</td></tr>', $oid, $w['orderDate'], $w['name'], $w['value'], $w['items']);
         $r = $dbc->exec_statement($itemP, array($oid));
         while ($w = $dbc->fetch_row($r)) {
             if ($w['department'] == 0) {
                 echo '<tr><td>&nbsp;</td>';
                 echo '<td colspan="4">';
                 echo 'No department set for: ' . $w['description'];
                 echo '</td></tr>';
             } else {
                 printf('<tr><td>&nbsp;</td><td>%s (%d)</td><td>%d x %d</td>
                 <td>$%.2f</td>
                 <td><input type="checkbox" class="cbox" name="toIDs[]" value="%d:%d" /></td>
                 </tr>', $w['description'], $w['department'], $w['ItemQtty'], $w['quantity'], $w['total'], $w['trans_id'], $oid);
             }
         }
     }
     echo '</table>';
     echo '<p>';
     echo '<button type="submit" class="btn btn-default">Print Tags</button>';
     echo '</p>';
     echo '</form>';
 }
예제 #24
0
 function post_u_view()
 {
     global $FANNIE_OP_DB, $FANNIE_URL;
     $this->addScript('from-search.js');
     $ret = '<form action="BatchFromSearch.php" method="post">';
     $ret .= '<div class="form-group form-inline">';
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $types = $dbc->query('SELECT batchTypeID, typeDesc, discType FROM batchType');
     $discTypes = array();
     $ret .= '<select name="batchType" id="batchType" class="form-control"
         onchange="discountTypeFixup()">';
     while ($row = $dbc->fetch_row($types)) {
         $ret .= sprintf('<option value="%d">%s</option>', $row['batchTypeID'], $row['typeDesc']);
         $discTypes[] = $row;
     }
     $ret .= '</select>';
     foreach ($discTypes as $row) {
         $ret .= sprintf('<input type="hidden" id="discType%d" value="%d" />', $row['batchTypeID'], $row['discType']);
     }
     $name = FannieAuth::checkLogin();
     $ret .= '
             <label>Name</label>: ';
     $ret .= '<input type="text" class="form-control" name="batchName" value="' . ($name ? $name : 'Batch') . ' ' . date('M j') . '" />';
     $ret .= '
             <label>Start</label>: <input type="text" class="form-control date-field" id="startDate" value="' . date('Y-m-d') . '" name="startDate" />
             ';
     $ret .= '
             <label>End</label>: <input type="text" class="form-control date-field" id="endDate" value="' . date('Y-m-d') . '" name="endDate" />
             </div>';
     $owners = $dbc->query('SELECT super_name FROM MasterSuperDepts GROUP BY super_name ORDER BY super_name');
     $ret .= '<div class="form-group form-inline">
         <label>Owner</label>: <select name="batchOwner" class="form-control" id="batchOwner"><option value=""></option>';
     while ($row = $dbc->fetch_row($owners)) {
         $ret .= '<option>' . $row['super_name'] . '</option>';
     }
     $ret .= '<option>IT</option></select>
             <button type="submit" name="createBatch" value="1"
                 class="btn btn-default">Create Batch</button>
             </div>';
     $ret .= '<hr />';
     list($in_sql, $args) = $dbc->safeInClause($this->upcs);
     $query = 'SELECT p.upc, p.description, p.normal_price, m.superID,
             MAX(CASE WHEN v.srp IS NULL THEN 0.00 ELSE v.srp END) as srp
             FROM products AS p
                 LEFT JOIN vendorItems AS v ON p.upc=v.upc AND p.default_vendor_id=v.vendorID
                 LEFT JOIN MasterSuperDepts AS m ON p.department=m.dept_ID
             WHERE p.upc IN ( ' . $in_sql . ')
             GROUP BY p.upc, p.description, p.normal_price, m.superID
             ORDER BY p.upc';
     $prep = $dbc->prepare($query);
     $result = $dbc->execute($prep, $args);
     $ret .= '<div id="saleTools" class="form-group form-inline">';
     $ret .= '<label>Markdown</label>
             <div class="input-group">
                 <input type="text" id="mdPercent" class="form-control" value="10" onchange="markDown(this.value);" />
                 <span class="input-group-addon">%</span>
             </div>
             <button type="submit" class="btn btn-default" onclick="markDown($(\'#mdPercent\').val()); return false">Go</button>';
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= '<label>or</label>
             <div class="input-group">
                 <span class="input-group-addon">$</span>
                 <input type="text" id="mdDollar" class="form-control" value="0.00" onchange="discount(this.value);" />
             </div>
             <button type="submit" class="btn btn-default" onclick="discount($(\'#mdDollar\').val()); return false">Go</button>';
     $ret .= '</div>';
     $ret .= '<div id="priceChangeTools" class="form-group form-inline">';
     $ret .= '<button type="submit" class="btn btn-default" onclick="useSRPs(); return false;">Use Vendor SRPs</button>';
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= '<select name="preferredVendor" class="form-control" onchange="reCalcSRPs();">
         <option value="0">Auto Choose Vendor</option>';
     $vendors = new VendorsModel($dbc);
     foreach ($vendors->find('vendorName') as $vendor) {
         $ret .= sprintf('<option value="%d">%s</option>', $vendor->vendorID(), $vendor->vendorName());
     }
     $ret .= '</select>';
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= '<label>Markup</label>
             <div class="input-group">
                 <input type="text" id="muPercent" class="form-control" value="10" onchange="markUp(this.value);" />
                 <span class="input-group-addon">%</span>
             </div>
             <button type="submit" class="btn btn-default" onclick="markUp($(\'#muPercent\').val()); return false">Go</button>';
     $ret .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
     $ret .= '<label>Tags</label> <select name="tagset" class="form-control" id="tagset"><option value="">No Tags</option>';
     $queues = new ShelfTagQueuesModel($dbc);
     $ret .= $queues->toOptions();
     $ret .= '</select>';
     $ret .= '</div>';
     $ret .= '<table class="table">';
     $ret .= '<tr><th>UPC</th><th>Description</th><th>Retail</th>
             <th id="newPriceHeader">Sale Price</th></tr>';
     $superDetect = array();
     while ($row = $dbc->fetch_row($result)) {
         $ret .= sprintf('<tr class="batchItem">
                         <td><input type="hidden" name="upc[]" class="itemUPC" value="%s" />%s</td>
                         <td>%s</td>
                         <td>$%.2f<input type="hidden" class="currentPrice" value="%.2f" /></td>
                         <td><div class="input-group">
                             <span class="input-group-addon">$</span>
                             <input type="text" name="price[]" class="itemPrice form-control" value="0.00" />
                             <input type="hidden" class="itemSRP" value="%.2f" />
                         </div>
                         </td>
                         </tr>', $row['upc'], $row['upc'], $row['description'], $row['normal_price'], $row['normal_price'], $row['srp']);
         if (!isset($superDetect[$row['superID']])) {
             $superDetect[$row['superID']] = 0;
         }
         $superDetect[$row['superID']]++;
     }
     $ret .= '</table>';
     $ret .= '</form>';
     // auto-detect likely owner & tag set by super department
     $tagPage = array_search(max($superDetect), $superDetect);
     if ($tagPage !== false) {
         $this->add_onload_command("\$('#tagset').val({$tagPage});\n");
         $this->add_onload_command("\$('#batchOwner').val(\$('#tagset option:selected').text());\n");
     }
     // show sale or price change tools as appropriate
     $this->add_onload_command('discountTypeFixup();');
     // don't let enter key on these fields trigger form submission
     $this->add_onload_command("\$('#mdPercent').bind('keypress', noEnter);\n");
     $this->add_onload_command("\$('#mdDollar').bind('keypress', noEnter);\n");
     $this->add_onload_command("\$('#muPercent').bind('keypress', noEnter);\n");
     return $ret;
 }
예제 #25
0
 public function get_id_view()
 {
     global $FANNIE_OP_DB;
     $uid = FannieAuth::getUID(FannieAuth::checkLogin());
     $dbc = CalendarPluginDB::get();
     $event = new MonthviewEventsModel($dbc);
     $event->eventID($this->id);
     $event->load();
     list($date, $time) = explode(' ', $event->eventDate());
     $ret = '<h3>' . $date . '</h3>';
     $ret .= '<div class="eventDesc">' . $event->eventText() . '</div>';
     $ret .= '<hr />';
     $attending = false;
     $ret .= '<h3>Attendees</h3>';
     $ret .= '<ol>';
     $query = 'SELECT m.uid, u.real_name
               FROM attendees AS m
                 INNER JOIN ' . $FANNIE_OP_DB . $dbc->sep() . 'Users AS u ON m.uid=u.uid
               WHERE m.eventID=?
               ORDER BY attendeeID';
     $prep = $dbc->prepare($query);
     $result = $dbc->execute($prep, $this->id);
     $num = $result ? $dbc->num_rows($result) : 0;
     while ($row = $dbc->fetch_row($result)) {
         $ret .= '<li>' . $row['real_name'] . '</li>';
         if ($row['uid'] == $uid) {
             $attending = true;
         }
     }
     $ret .= '</ol>';
     if (!$attending && $num < $event->attendeeLimit()) {
         $ret .= sprintf('<a href="CalendarAttendedEventPage.php?id=%d&join_id=%d">Sign up for this Event</a>', $this->id, $uid);
     } else {
         if (!$attending) {
             $ret .= 'This event is at capacity';
         } else {
             $ret .= sprintf('<a href="CalendarAttendedEventPage.php?id=%d&leave_id=%d">Take myself off the List</a>', $this->id, $uid);
         }
     }
     $ret .= '<div style="margin-top:20px"><a href="CalendarMainPage.php">Home</a></div>';
     return $ret;
 }
예제 #26
0
 public function pluginEnable()
 {
     FannieAuth::createClass('GiveUsMoney', 'Grants permission to use the GiveUsMoney plugin');
 }
예제 #27
0
    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>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <label>Scale
                <input type="checkbox" value="{{store_id}}" name="Scale[]" 
                    class="scale-checkbox syncable-checkbox"
                    ' . ($rowItem['scale'] == 1 ? 'checked' : '') . ' />
                </label>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <label>QtyFrc
                <input type="checkbox" value="{{store_id}}" name="QtyFrc[]" 
                    class="qty-checkbox syncable-checkbox"
                    ' . ($rowItem['qttyEnforced'] == 1 ? 'checked' : '') . ' />
                </label>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <label>WIC
                <input type="checkbox" value="{{store_id}}" name="prod-wicable[]" 
                    class="prod-wicable-checkbox syncable-checkbox"
                    ' . ($rowItem['wicable'] == 1 ? 'checked' : '') . '  />
                </label>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <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;
    }
예제 #28
0
 protected function get_id_view()
 {
     global $FANNIE_OP_DB, $FANNIE_URL;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $limitedEdit = $this->auth_mode == 'Full' ? False : True;
     ob_start();
     echo '<form action="PIMemberPage.php" ';
     if (FormLib::get_form_value('edit', False) === False) {
         echo 'method="get">';
     } else {
         echo 'method="post">';
     }
     echo '<input type="hidden" name="id" value="' . $this->card_no . '" />';
     echo "<table>";
     echo "<tr>";
     echo "<td class=\"greenbg yellowtxt\">Owner Num</td>";
     echo "<td class=\"greenbg yellowtxt\">" . $this->card_no . "</td>";
     $status = $this->account['activeStatus'];
     if ($status == '') {
         $status = $this->account['memberStatus'];
     }
     switch ($status) {
         case 'PC':
             $status = 'ACTIVE';
             break;
         case 'REG':
             $status = 'NONMEM';
             break;
         case 'INACT2':
             $status = 'TERM (PENDING)';
             break;
     }
     if (isset($this->__models['suspended'])) {
         echo "<td bgcolor='#cc66cc'>{$status}</td>";
         echo "<td colspan=1>";
         if ($this->__models['suspended']->reason() != '') {
             echo $this->__models['suspended']->reason();
         } else {
             $reasons = new ReasoncodesModel($dbc);
             foreach ($reasons->find('mask') as $r) {
                 if (((int) $r->mask() & (int) $this->__models['suspended']->reasoncode()) != 0) {
                     echo $r->textStr() . ' ';
                 }
             }
         }
         echo '</td>';
     } else {
         echo "<td>{$status}</td>";
     }
     echo "<td colspan=2><a href=PISuspensionPage.php?id=" . $this->card_no . ">History</a>";
     if ($this->auth_mode == 'Full') {
         echo '&nbsp;&nbsp;&nbsp;<a href="PISuspensionPage.php?edit=1&id=' . $this->card_no . '">Change Status</a>';
     } else {
         if ($this->auth_mode == 'Limited' && isset($this->__models['suspended']) && $this->__models['suspended']->reasoncode() == 16) {
             echo '&nbsp;&nbsp;&nbsp;<a href="PISuspensionPage.php?fixaddress=1&id=' . $this->card_no . '"
             onclick="return confirm(\'Address is correct?\');">Address Corrected</a>';
         }
     }
     echo '</td>';
     echo "<td><a href=\"{$FANNIE_URL}ordering/clearinghouse.php?card_no=" . $this->card_no . "\">Special Orders</a></td>";
     if (FannieAuth::validateUserQuiet('GiveUsMoney')) {
         echo "<td><a href=\"{$FANNIE_URL}modules/plugins2.0/GiveUsMoneyPlugin/GumMainPage.php?id=" . $this->card_no . "\">Owner Loans</a></td>";
     }
     echo "</tr>";
     echo "<tr>";
     echo '<input type="hidden" name="customerID" value="' . $this->primary_customer['customerID'] . '" />';
     echo "<td class=\"yellowbg\">First Name: </td>";
     echo '<td>' . $this->text_or_field('FirstName', $this->primary_customer['firstName']) . '</td>';
     echo "<td class=\"yellowbg\">Last Name: </td>";
     echo '<td>' . $this->text_or_field('LastName', $this->primary_customer['lastName']) . '</td>';
     echo '</tr>';
     echo "<tr>";
     echo "<td class=\"yellowbg\">Address1: </td>";
     echo '<td>' . $this->text_or_field('address1', $this->account['addressFirstLine']) . '</td>';
     echo "<td class=\"yellowbg\">Gets mailings: </td>";
     echo '<td>' . $this->text_or_select('mailflag', $this->account['contactAllowed'], array(1, 0), array('Yes', 'No')) . '</td>';
     echo "</tr>";
     echo "<tr>";
     echo "<td class=\"yellowbg\">Address2: </td>";
     echo '<td>' . $this->text_or_field('address2', $this->account['addressSecondLine']) . '</td>';
     echo "<td class=\"yellowbg\">UPC: </td>";
     echo '<td colspan=\\"2\\">' . $this->text_or_field('upc', $this->account['idCardUPC']) . '</td>';
     echo "</tr>";
     echo "<tr>";
     echo "<td class=\"yellowbg\">City: </td>";
     echo '<td>' . $this->text_or_field('city', $this->account['city']) . '</td>';
     echo "<td class=\"yellowbg\">State: </td>";
     echo '<td>' . $this->text_or_field('state', $this->account['state']) . '</td>';
     echo "<td class=\"yellowbg\">Zip: </td>";
     echo '<td>' . $this->text_or_field('zip', $this->account['zip']) . '</td>';
     echo "</tr>";
     echo "<tr>";
     echo "<td class=\"yellowbg\">Phone Number: </td>";
     echo '<td>' . $this->text_or_field('phone', $this->primary_customer['phone']) . '</td>';
     echo "<td class=\"yellowbg\">Start Date: </td>";
     $start = $this->account['startDate'];
     if (strstr($start, ' ') !== False) {
         list($start, $junk) = explode(' ', $start, 2);
     }
     if ($start == '1900-01-01') {
         echo '<input type="hidden" name="nonBlankStart" value="' . $start . '" />';
     }
     if ($start == '1900-01-01' || $start == '0000-00-00') {
         $start = '';
     }
     echo '<td>' . $this->text_or_field('start_date', $start, array(), $limitedEdit) . '</td>';
     echo "<td class=\"yellowbg\">End Date: </td>";
     $end = $this->account['endDate'];
     if (strstr($end, ' ') !== False) {
         list($end, $junk) = explode(' ', $end, 2);
     }
     if ($end == '1900-01-01' || $end == '0000-00-00') {
         $end = '';
     }
     echo '<td>' . $this->text_or_field('end_date', $end, array(), $limitedEdit) . '</td>';
     echo "</tr>";
     echo "<tr>";
     echo "<td class=\"yellowbg\">Alt. Phone: </td>";
     echo '<td>' . $this->text_or_field('phone2', $this->primary_customer['altPhone']) . '</td>';
     echo "<td class=\"yellowbg\">E-mail: </td>";
     echo '<td>' . $this->text_or_field('email', $this->primary_customer['email']) . '</td>';
     echo "</tr>";
     echo "<tr>";
     echo "<td class=\"yellowbg\">Stock Purchased: </td>";
     echo "<td>" . sprintf('%.2f', $this->__models['equity']->payments()) . '</td>';
     echo "<td class=\"yellowbg\">Mem Type: </td>";
     $labels = array();
     $opts = array();
     $memtypes = new MemtypeModel($dbc);
     foreach ($memtypes->find('memtype') as $mt) {
         $labels[] = $mt->memDesc();
         $opts[] = $mt->memtype();
     }
     echo '<td>' . $this->text_or_select('memType', $this->account['customerTypeID'], $opts, $labels, array(), $limitedEdit) . '</td>';
     echo "<td class=\"yellowbg\">Discount: </td>";
     echo '<td>' . $this->primary_customer['discount'] . '</td>';
     echo "</tr>";
     echo "<tr>";
     echo "<td class=\"yellowbg\">Charge Limit: </td>";
     echo '<td>' . $this->text_or_field('chargelimit', $this->account['chargeLimit'], array(), $limitedEdit) . '</td>';
     echo "<td class=\"yellowbg\">Current Balance: </td>";
     echo '<td>' . sprintf('%.2f', $this->__models['ar']->balance()) . '</td>';
     echo "</tr>";
     echo "<tr class=\"yellowbg\"><td colspan=6></td></tr>";
     echo "<tr>";
     echo '<td colspan="2" class="greenbg yellowtxt">Additional household members</td>';
     echo '<td></td>';
     echo '<td class="greenbg yellowtxt">Additional Notes</td>';
     echo "<td><a href=PINoteHistoryPage.php?id=" . $this->card_no . ">Notes history</a></td>";
     echo "</tr>";
     echo "<tr>";
     echo '<td></td>';
     echo '<td class="yellowbg">First Name</td>';
     echo '<td class="yellowbg">Last Name</td>';
     echo "<td colspan=4 width=\"300px\" valign=\"top\" rowspan=8>";
     echo $this->text_or_area('notetext', $this->__models['note'], array('rows' => 7, 'cols' => 50), 2);
     echo "</td>";
     echo '</tr>';
     $i = 0;
     foreach ($this->account['customers'] as $c) {
         if ($c['accountHolder']) {
             continue;
         }
         echo '<tr>';
         echo '<td class="yellowbg">' . ($i + 1) . '</td>';
         echo '<td>' . $this->text_or_field('fn[]', $c['firstName']) . '</td>';
         echo '<td>' . $this->text_or_field('ln[]', $c['lastName']) . '</td>';
         echo '<input type="hidden" name="hhID[]" value="' . $c['customerID'] . '" />';
         $i++;
     }
     for ($i; $i < 3; $i++) {
         echo '<tr>';
         echo '<td class="yellowbg">' . ($i + 1) . '</td>';
         echo '<td>' . $this->text_or_field('fn[]', '') . '</td>';
         echo '<td>' . $this->text_or_field('ln[]', '') . '</td>';
         echo '<input type="hidden" name="hhID[]" value="0" />';
     }
     echo '</tr>';
     echo '<tr>';
     echo '<td colspan="3">';
     if (FormLib::get_form_value('edit', False) === False) {
         if ($this->current_user) {
             echo '<input type="hidden" name="edit" />';
             echo '<input type="submit" value="Edit Member" />';
         } else {
             echo '<input type="hidden" name="login" />';
             echo '<input type="submit" value="Log In" />';
         }
         echo '&nbsp;&nbsp;';
         echo '<a href="PIMemberPage.php?id=' . ($this->card_no - 1) . '">Prev Mem</a>';
         echo '&nbsp;&nbsp;';
         echo '<a href="PIMemberPage.php?id=' . ($this->card_no + 1) . '">Next Mem</a>';
     } else {
         echo '<input type="submit" value="Save Member" />';
     }
     echo '</td>';
     echo '</tr>';
     echo "</table>";
     return ob_get_clean();
 }
예제 #29
0
 function preprocess()
 {
     global $FANNIE_PLUGIN_LIST, $FANNIE_PLUGIN_SETTINGS;
     if (!isset($FANNIE_PLUGIN_LIST) || !in_array('CoopCred', $FANNIE_PLUGIN_LIST)) {
         $this->errors .= _("Error: The Coop Cred Plugin is not enabled.");
         return True;
     }
     if (!array_key_exists('CoopCredDatabase', $FANNIE_PLUGIN_SETTINGS) || $FANNIE_PLUGIN_SETTINGS['CoopCredDatabase'] == "") {
         $this->errors .= _("Error: Coop Cred Database not named in Plugin Settings.");
         return True;
     }
     /* Get values from the Whole-Project (Plugin) config table.
      */
     $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['CoopCredDatabase']);
     $config = new CCredConfigModel($dbc);
     $config->configID(1);
     if (!$config->load()) {
         $this->errors .= _("Error: Coop Cred configuration not available.");
         return True;
     }
     $this->dummyTenderCode = $config->dummyTenderCode();
     $this->dummyDepartment = $config->dummyDepartment();
     $this->deptMin = $config->deptMin();
     $this->deptMax = $config->deptMax();
     $this->dummyBanker = $config->dummyBanker();
     $this->bankerMin = $config->bankerMin();
     $this->bankerMax = $config->bankerMax();
     /* For CCredPrograms.modifiedBy
      */
     $this->authUserNumber = 0;
     $authName = FannieAuth::checkLogin();
     if (!($authName == 'null' || $authName == 'init' || $authName == False)) {
         $this->authUserNumber = FannieAuth::getUID($authName);
     }
     /* Support ajax calls to this program.
      * If there is a form submission with an action go do it.
      * The form submission may be via AJAX instead of <form ...>
      *  with action= in the query string with other parameters.
      */
     if (FormLib::get_form_value('action') !== '') {
         $this->ajax_response(FormLib::get_form_value('action'));
         /* How to handle errors/problems esp. in save?
          * Possibly code readinessCheck()
          */
         return False;
     }
     /* If the call was not by form, e.g. from the initial menu
      * or the <form action=> is '' (when does that happen?)
      * FanniePage::draw_page() continues to $this->body_content()
      *  which returns the the program-select form.
      */
     return True;
     // preprocess()
 }
예제 #30
0
 function getFooter()
 {
     global $FANNIE_URL;
     $ret = '</table>';
     if (FannieAuth::checkLogin() !== false) {
         $ret .= '<p><span id="logininfo" style="top:50px;">';
         $ret .= 'Logged in as: ' . FannieAuth::checkLogin();
         $ret .= '&nbsp;&nbsp;&nbsp;[';
         $ret .= ' <a href="' . $FANNIE_URL . 'auth/ui/loginform.php?logout=yes">Logout</a> ]';
         $ret .= '</span></p>';
     } else {
         $ret .= FannieAuth::checkLogin();
     }
     $ret .= '</body></html>';
     return $ret;
 }