예제 #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
 /**
  * Add packet
  *
  * @access public
  */
 public function display_add_shipment()
 {
     $delivery = \Skeleton\Package\Delivery\Delivery::get_by_id($_GET['id']);
     $shipment = new Shipment();
     $shipment->delivery_id = $delivery->id;
     if ($_POST['address_input'] == 'manual') {
         unset($_POST['shipment']['street']);
         unset($_POST['shipment']['housenumber']);
     } else {
         unset($_POST['shipment']['line1']);
         unset($_POST['shipment']['line2']);
         unset($_POST['shipment']['line3']);
     }
     if (isset($_POST['shipment']['courier'])) {
         list($courier_object_classname, $courier_object_id) = explode('/', $_POST['shipment']['courier']);
         $_POST['shipment']['courier_object_classname'] = $courier_object_classname;
         $_POST['shipment']['courier_object_id'] = $courier_object_id;
         unset($_POST['shipment']['courier']);
     }
     $shipment->load_array($_POST['shipment']);
     $shipment->save();
     foreach ($_POST['shipment_item'] as $deliverable_object_classname => $array) {
         foreach ($array as $deliverable_object_id => $values) {
             $deliverable = $deliverable_object_classname::get_by_id($deliverable_object_id);
             $delivery_items = \Skeleton\Package\Delivery\Item::get_by_delivery_deliverable($delivery, $deliverable);
             // Remove the delivery_items that are already shipped
             foreach ($delivery_items as $key => $delivery_item) {
                 if ($delivery_item->shipment_item_id != 0) {
                     unset($delivery_items[$key]);
                 }
             }
             if (count($delivery_items) < $values['to_ship']) {
                 throw new \Exception('This should not happen, more items are requested for shipment than allowed');
             }
             for ($i = 1; $i <= $values['to_ship']; $i++) {
                 $delivery_item = array_shift($delivery_items);
                 $shipment_item = new \Skeleton\Package\Delivery\Shipment\Item();
                 $shipment_item->delivery_item_id = $delivery_item->id;
                 $shipment_item->shipment_id = $shipment->id;
                 $shipment_item->weight = $values['weight'];
                 $shipment_item->save();
                 $delivery_item->shipment_item_id = $shipment_item->id;
                 $delivery_item->save();
             }
         }
     }
     $shipment->handle();
     $delivery->check_shipped();
     Session::Redirect($this->get_module_path() . '?action=edit&id=' . $delivery->id);
 }
예제 #3
0
 /**
  * Get purchase_list
  * Get a list of products that needs to be delivered and are not in stock
  *
  * @access public
  * @return array $products
  */
 public function get_purchase_list()
 {
     $delivery_items = \Skeleton\Package\Delivery\Item::get_undelivered();
     $to_deliver = [];
     foreach ($delivery_items as $delivery_item) {
         if (!isset($to_deliver[$delivery_item->deliverable_object_classname . '-' . $delivery_item->deliverable_object_id])) {
             $to_deliver[$delivery_item->deliverable_object_classname . '-' . $delivery_item->deliverable_object_id] = 0;
         }
         $to_deliver[$delivery_item->deliverable_object_classname . '-' . $delivery_item->deliverable_object_id]++;
     }
     foreach ($this->get_backorder() as $purchase_order_item) {
         $product = $purchase_order_item->get_stock_object();
         if (!isset($to_deliver[get_class($product) . '-' . $product->id])) {
             continue;
         }
         $backordered = $purchase_order_item->amount - $purchase_order_item->delivered;
         $to_deliver[get_class($product) . '-' . $product->id] -= $backordered;
         if ($to_deliver[get_class($product) . '-' . $product->id] < 0) {
             unset($to_deliver[get_class($product) . '-' . $product->id]);
         }
     }
     $purchase_list = [];
     foreach ($to_deliver as $key => $count) {
         list($classname, $id) = explode('-', $key);
         $class = $classname::get_by_id($id);
         $supplier = self::get_for_object($class);
         if ($supplier === null) {
             continue;
         }
         if ($supplier->id != $this->id) {
             continue;
         }
         $stock = Stock::get($class);
         if ($stock > $count) {
             continue;
         }
         $to_deliver_count = $count - $stock;
         for ($i = 1; $i <= $to_deliver_count; $i++) {
             $purchase_list[] = $class;
         }
     }
     return $purchase_list;
 }
예제 #4
0
 /**
  * Get delivery_item
  *
  * @access public
  * @return \Skeleton\Package\Delivery\Item $delivery_item
  */
 public function get_delivery_item()
 {
     return \Skeleton\Package\Delivery\Item::get_by_id($this->delivery_item_id);
 }
예제 #5
0
 /**
  * Get delivery_items
  *
  * @access public
  * @return array $delivery_items
  */
 public function get_delivery_items()
 {
     return \Skeleton\Package\Delivery\Item::get_by_delivery($this);
 }