function batchListDisplay($filter = '', $mode = '', $maxBatchID = '') { global $FANNIE_URL; $dbc = $this->con; if ($mode === '') { $mode = $this->config->get('BATCH_VIEW', 'all'); } $colors = array('#ffffff', '#ffffcc'); $c = 0; $ret = ""; $ret .= "<b>Display</b>: "; if ($mode != 'pending') { $ret .= "<a href=\"\" onclick=\"changeTimeSlice('pending'); return false;\">Pending</a> | "; } else { $ret .= "Pending | "; } if ($mode != 'current') { $ret .= "<a href=\"\" onclick=\"changeTimeSlice('current'); return false;\">Current</a> | "; } else { $ret .= "Current | "; } if ($mode != 'historical') { $ret .= "<a href=\"\" onclick=\"changeTimeSlice('historical'); return false;\">Historical</a> | "; } else { $ret .= "Historical | "; } if ($mode != 'all') { $ret .= "<a href=\"\" onclick=\"changeTimeSlice('all'); return false;\">All</a>"; } else { $ret .= "All<br />"; } $sort = \COREPOS\Fannie\API\lib\FannieUI::tableSortIcons(); $ret .= '<table class="table tablesorter tablesorter-core"><thead>'; $ret .= "<tr><th bgcolor={$colors[$c]}>Batch Name{$sort}</th>"; $ret .= "<th bgcolor={$colors[$c]}>Type{$sort}</th>"; $ret .= "<th bgcolor={$colors[$c]}>Items{$sort}</th>"; $ret .= "<th bgcolor={$colors[$c]}>Start date{$sort}</th>"; $ret .= "<th bgcolor={$colors[$c]}>End date{$sort}</th>"; $ret .= "<th bgcolor={$colors[$c]}>Owner/Super Dept.{$sort}</th>"; $ret .= "<th colspan=\"3\"> </th></tr></thead><tbody>"; // owner column might be in different places // depending if schema is up to date $ownerclause = "'' as owner FROM batches AS b"; $batchesTable = $dbc->tableDefinition('batches'); $owneralias = ''; if (isset($batchesTable['owner'])) { $ownerclause = 'b.owner FROM batches AS b'; $owneralias = 'b'; } else { if ($dbc->tableExists('batchowner')) { $ownerclause = 'o.owner FROM batches AS b LEFT JOIN batchowner AS o ON b.batchID=o.batchID'; $owneralias = 'o'; } } // the 'all' query // where clause is for str_ireplace below $fetchQ = "SELECT b.batchName,\n b.batchType,\n b.startDate,\n b.endDate,\n b.batchID,\n t.typeDesc,\n COUNT(l.upc) AS items,\n {$ownerclause}\n LEFT JOIN batchType AS t ON b.batchType = t.batchTypeID\n LEFT JOIN batchList AS l ON b.batchID=l.batchID\n WHERE 1=1 "; $args = array(); switch ($mode) { case 'pending': $fetchQ .= ' AND ' . $dbc->datediff("b.startDate", $dbc->now()) . ' > 0 '; break; case 'current': $fetchQ .= ' AND ' . $dbc->datediff("b.startDate", $dbc->now()) . ' <= 0 AND ' . $dbc->datediff("b.endDate", $dbc->now()) . ' >= 0 '; break; case 'historical': $fetchQ .= ' AND ' . $dbc->datediff("b.startDate", $dbc->now()) . ' <= 0 '; break; } // use a filter - only works in 'all' mode if ($filter != '') { $fetchQ .= ' AND ' . $owneralias . '.owner = ? '; $args[] = $filter; } $fetchQ .= ' GROUP BY b.batchName, b.batchType, b.startDate, b.endDate, b.batchID, t.typeDesc, ' . $owneralias . '.owner '; $fetchQ .= ' ORDER BY b.batchID DESC'; $fetchQ = $dbc->add_select_limit($fetchQ, 50); if (is_numeric($maxBatchID)) { $fetchQ = str_replace("WHERE ", "WHERE b.batchID < ? AND ", $fetchQ); array_unshift($args, $maxBatchID); } $fetchR = $dbc->exec_statement($fetchQ, $args); $count = 0; $lastBatchID = 0; while ($fetchW = $dbc->fetch_array($fetchR)) { /** strtotime() and date() are not reciprocal functions date('Y-m-d', strtotime('0000-00-00')) results in -0001-11-30 instead of the expected 0000-00-00 */ if ($fetchW['startDate'] == '0000-00-00 00:00:00') { $fetchW['startDate'] = ''; } if ($fetchW['endDate'] == '0000-00-00 00:00:00') { $fetchW['endDate'] = ''; } $c = ($c + 1) % 2; $id = $fetchW['batchID']; $ret .= '<tr id="batchRow' . $fetchW['batchID'] . '" class="batchRow">'; $ret .= "<td bgcolor={$colors[$c]} id=name{$id}><a id=namelink{$id} \n href=\"EditBatchPage.php?id={$id}\">{$fetchW['batchName']}</a></td>"; $ret .= "<td bgcolor={$colors[$c]} id=type{$id}>" . $fetchW['typeDesc'] . "</td>"; $ret .= "<td bgcolor={$colors[$c]}>" . $fetchW['items'] . "</td>"; $ret .= "<td bgcolor={$colors[$c]} id=startdate{$id}>" . (strtotime($fetchW['startDate']) ? date('Y-m-d', strtotime($fetchW['startDate'])) : '') . "</td>"; $ret .= "<td bgcolor={$colors[$c]} id=enddate{$id}>" . (strtotime($fetchW['endDate']) ? date('Y-m-d', strtotime($fetchW['endDate'])) : '') . "</td>"; $ret .= "<td bgcolor={$colors[$c]} id=owner{$id}>{$fetchW['owner']}</td>"; $ret .= "<td bgcolor={$colors[$c]} id=edit{$id}>\n <a href=\"\" onclick=\"editBatchLine({$id}); return false;\" class=\"batchEditLink btn btn-default btn-xs\">\n " . \COREPOS\Fannie\API\lib\FannieUI::editIcon() . "\n </a>\n <a href=\"\" onclick=\"saveBatchLine({$id}); return false;\" class=\"batchSaveLink btn btn-default btn-xs collapse\">\n " . \COREPOS\Fannie\API\lib\FannieUI::saveIcon() . "\n </a>\n </td>"; $ret .= "<td bgcolor={$colors[$c]}><a href=\"\" class=\"btn btn-danger btn-xs\"\n onclick=\"deleteBatch({$id},'" . str_replace("'", '', $fetchW['batchName']) . "'); return false;\">" . \COREPOS\Fannie\API\lib\FannieUI::deleteIcon() . '</a></td>'; $ret .= "<td bgcolor={$colors[$c]}><a href=\"batchReport.php?batchID={$id}\">Report</a></td>"; $ret .= "</tr>"; $count++; $lastBatchID = $fetchW[4]; } $ret .= "</tbody></table>"; if (is_numeric($maxBatchID)) { $ret .= sprintf("<a href=\"\" \n onclick=\"scroll(0,0); batchListPager('%s','%s',''); return false;\">First page</a>\n | ", $filter, $mode); } if ($count >= 50) { $ret .= sprintf("<a href=\"\" \n onclick=\"scroll(0,0); batchListPager('%s','%s',%d); return false;\">Next page</a>", $filter, $mode, $lastBatchID); } else { $ret .= "Next page"; } return $ret; }