To Order - what is waiting to go on a purchase order: items * added by hand, or from products that are low on stock. Each is for a client * or for our own stock, with who it comes from and what it costs. Tick some * to make a purchase order to one vendor, put them on a draft one, or take * them off. The work is in functions/purchase_orders.php; the handlers are * agent/post/purchase_order.php. */ // Default Column Sortby/Order Filter $sort = "vendor_name"; $order = "ASC"; require_once "includes/inc_all.php"; poRequireLevel(1); $can_edit = poLevel() >= 2; $vendor_filter = intval($_GET['vendor'] ?? 0); $client_filter = intval($_GET['client'] ?? 0); $sortable_columns = [ 'order_item_name' => "order_item_name $order", 'client_name' => "order_item_client_id = 0 $order, client_name $order, order_item_name ASC", 'vendor_name' => "vendor_name IS NULL $order, vendor_name $order, order_item_name ASC", 'order_item_quantity' => "order_item_quantity $order", 'order_item_cost' => "order_item_cost IS NULL, order_item_cost $order", 'order_item_created_at' => "order_item_created_at $order", ]; if (!isset($sortable_columns[$sort])) { $sort = 'vendor_name'; } $where = "order_item_status = 'waiting'" . clientScopeSql('order_item_client_id') . ($vendor_filter ? " AND order_item_vendor_id = " . max(0, $vendor_filter) : '') . ($client_filter ? " AND order_item_client_id = " . max(0, $client_filter) : '') . ($q !== '' ? " AND (order_item_name LIKE '%$q%' OR order_item_description LIKE '%$q%' OR order_item_note LIKE '%$q%' OR vendor_name LIKE '%$q%' OR client_name LIKE '%$q%' OR product_name LIKE '%$q%')" : ''); $joins = "LEFT JOIN clients ON client_id = order_item_client_id AND order_item_client_id > 0 LEFT JOIN vendors ON vendor_id = order_item_vendor_id AND order_item_vendor_id > 0 LEFT JOIN products ON product_id = order_item_product_id AND order_item_product_id > 0 LEFT JOIN users ON user_id = order_item_created_by AND order_item_created_by > 0"; $items = []; $num_rows = [0]; $totals = ['count' => 0, 'amount' => 0, 'no_vendor' => 0, 'no_cost' => 0]; $low_stock = []; if (poReady()) { $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS order_items.*, client_name, vendor_name, product_name, user_name AS created_by_name FROM order_items $joins WHERE $where ORDER BY {$sortable_columns[$sort]}, order_item_id ASC LIMIT $record_from, $record_to"); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); while ($row = mysqli_fetch_assoc($sql)) { $items[] = $row; } // Across everything waiting the agent can see, whatever the search $totals = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(*) AS count, COALESCE(SUM(ROUND(order_item_quantity * COALESCE(order_item_cost, 0), 2)), 0) AS amount, COALESCE(SUM(order_item_vendor_id = 0), 0) AS no_vendor, COALESCE(SUM(order_item_cost IS NULL OR order_item_cost <= 0), 0) AS no_cost FROM order_items WHERE order_item_status = 'waiting'" . clientScopeSql('order_item_client_id'))); $low_stock = $can_edit ? orderItemsLowStock() : []; } $filter_url = function ($changes) { $params = array_merge($_GET, $changes); unset($params['page']); return '?' . http_build_query(array_filter($params, function ($v) { return $v !== '' && $v !== null && $v !== 0; })); }; $sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) { return '' . $label . ($sort === $column ? " $order_icon" : '') . ''; }; $csrf = $_SESSION['csrf_token']; $drafts = poReady() ? intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM purchase_orders WHERE po_status = 'draft'" . poScopeSql('po_id')))[0]) : 0; ?>
product low on stock and not on order - 4 ? ' and ' . (count($low_stock) - 4) . ' more' : '')) ?>.

To Order

waiting, about · with no vendor yet · without a cost
0; ?>
Amount
= 1 ? 'product.php?product_id=' . intval($row['order_item_product_id']) : ''; ?>
' . escapeHtml($row['order_item_name']) . '' : escapeHtml($row['order_item_name']) ?> Restock
Our stock Not set No cost' ?>
'items to order', 'icon' => 'fa-cart-plus', 'filtered' => $q !== '' || $vendor_filter || $client_filter, 'text' => 'What needs buying - for a client, or for your own stock. Tick items to make a purchase order to their vendor.', 'actions' => $can_edit ? [['label' => 'Add Item', 'modal' => 'modals/purchasing/order_item.php']] : [], ]; require_once "../includes/filter_footer.php"; ?>