예제 #1
0
 /**
  * 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);
 }
예제 #2
0
 /**
  * Create step 2
  *
  * @access public
  */
 public function display_create_step2()
 {
     if (!isset($_POST['supplier_id']) and !isset($_SESSION['skeleton-package-stock']['po']['supplier_id'])) {
         Session::redirect($this->get_module_path() . '?action=create');
     }
     if (!isset($_SESSION['skeleton-package-stock']['po'])) {
         $_SESSION['skeleton-package-stock']['po'] = [];
     }
     if (isset($_POST['supplier_id'])) {
         $_SESSION['skeleton-package-stock']['po']['supplier_id'] = $_POST['supplier_id'];
         unset($_SESSION['skeleton-package-stock']['po']['items']);
         $supplier = Supplier::get_by_id($_SESSION['skeleton-package-stock']['po']['supplier_id']);
         $purchase_list = $supplier->get_purchase_list();
         foreach ($purchase_list as $item) {
             $this->add_to_basket($item, 1, $item->get_purchase_price());
         }
     }
     $supplier = Supplier::get_by_id($_SESSION['skeleton-package-stock']['po']['supplier_id']);
     $classname = \Skeleton\Package\Stock\Config::$object_stock_interface;
     $pager = new Pager($classname);
     $pager->add_join('object_supplier', 'object_id', $classname::trait_get_database_table() . '.id');
     $pager->add_condition('object_supplier.supplier_id', $supplier->id);
     $pager->add_condition('object_supplier.object_classname', $classname);
     $fields = $classname::get_object_fields();
     $search_fields = [];
     foreach ($fields as $field) {
         if (substr($field['field'], -3) == '_id') {
             continue;
         }
         if ($field['field'] == 'id') {
             continue;
         }
         $search_fields[] = $field['field'];
     }
     if (isset($_POST['search'])) {
         $pager->set_search($_POST['search'], $search_fields);
     }
     $pager->page();
     $template = Template::get();
     $template->assign('supplier', $supplier);
     $template->assign('pager', $pager);
 }
예제 #3
0
 /**
  * get supplier
  *
  * @access public
  * @return \Skeleton\Package\Stock\Supplier $supplier
  */
 public function get_supplier()
 {
     return \Skeleton\Package\Stock\Supplier::get_by_id($this->supplier_id);
 }