/** * Edit stock for product * * @access public */ public function display_edit() { parent::display_edit(); $template = Template::get(); $classname = \Skeleton\Package\Stock\Config::$object_stock_interface; $product = $classname::get_by_id($_GET['id']); if (isset($_POST['product_supplier_id'])) { try { $product_supplier = \Skeleton\Package\Stock\Supplier::get_by_id($_POST['product_supplier_id']); \Skeleton\Package\Stock\Supplier::set_for_object($product, $product_supplier); } catch (\Exception $e) { $product_supplier = null; \Skeleton\Package\Stock\Supplier::set_for_object($product); } Session::set_sticky('updated', true); Session::redirect($this->get_module_path() . '?action=edit&id=' . $product->id); } $suppliers = \Skeleton\Package\Stock\Supplier::get_all(); $template->assign('suppliers', $suppliers); $supplier = \Skeleton\Package\Stock\Supplier::get_for_object($product); $template->assign('product_supplier', $supplier); try { $stock = \Skeleton\Package\Stock\Stock::get_last_by_object($product); $template->assign('stock', $stock->total); } catch (\Exception $e) { $template->assign('stock', 0); } $backorder = \Skeleton\Package\Stock\Purchase\Order\Item::get_backorder($product); $template->assign('backorder', $backorder); $count_backorder = \Skeleton\Package\Stock\Purchase\Order\Item::count_backorder($product); $template->assign('count_backorder', $count_backorder); if (class_exists('\\Skeleton\\Package\\Delivery\\Item')) { $to_deliver = \Skeleton\Package\Delivery\Item::get_undelivered_by_deliverable($product); $to_deliver_overview = []; foreach ($to_deliver as $delivery_item) { if (!isset($to_deliver_overview[$delivery_item->delivery_id])) { $to_deliver_overview[$delivery_item->delivery_id] = 0; } $to_deliver_overview[$delivery_item->delivery_id]++; } $template->assign('to_deliver_overview', $to_deliver_overview); $template->assign('to_deliver', $to_deliver); } $pager = new Pager('\\Skeleton\\Package\\Stock\\Stock'); $pager->add_sort_permission('created'); $pager->add_sort_permission('id'); $pager->add_condition('stock_object_id', $product->id); $pager->set_sort('id'); $pager->set_direction('desc'); $pager->page(); $template->assign('pager', $pager); }
/** * Create * * @access public */ public function display_create() { $template = Template::get(); $suppliers = Supplier::get_all(); $template->assign('suppliers', $suppliers); }