Exemplo n.º 1
0
 /**
  * Deliver
  *
  * @access public
  * @param string $amount
  * @param object $trigger
  * @param string $comment
  */
 public function deliver($amount, $trigger, $comment = '')
 {
     $stock_object = $this->get_stock_object();
     \Skeleton\Package\Stock\Stock::change($stock_object, $amount, $trigger, $comment);
     $this->delivered += $amount;
     $this->save();
     $purchase_order = \Skeleton\Package\Stock\Purchase\Order::get_by_id($this->purchase_order_id);
     $purchase_order->check_delivered();
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 /**
  * validate shipment
  *
  * @access public
  */
 public function display_validate_shipment()
 {
     $delivery_id = $_POST['delivery_id'];
     $form = parse_str($_POST['form'], $_POST);
     $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']);
     $validated = true;
     if (!$shipment->validate($shipment_errors)) {
         $validated = false;
     }
     $total_items = 0;
     $shipment_item_errors = [];
     if (isset($_POST['shipment_item'])) {
         foreach ($_POST['shipment_item'] as $deliverable_object_classname => $array) {
             foreach ($array as $deliverable_object_id => $values) {
                 $total_items += $values['to_ship'];
                 if (!class_exists('\\Skeleton\\Package\\Stock\\Stock')) {
                     continue;
                 }
                 $object = $deliverable_object_classname::get_by_id($deliverable_object_id);
                 $stock = \Skeleton\Package\Stock\Stock::get($object);
                 if ($stock < $values['to_ship']) {
                     $shipment_item_errors[] = 'stock_error';
                     $validated = false;
                 }
             }
         }
     }
     if ($total_items <= 0) {
         $shipment_item_errors[] = 'no products shipped';
         $validated = false;
     }
     $result = ['shipment_errors' => $shipment_errors, 'shipment_item_errors' => $shipment_item_errors, 'validated' => $validated];
     echo json_encode($result);
     $this->template = false;
 }
Exemplo n.º 4
0
 /**
  * Handle
  *
  * @access public
  */
 public function handle()
 {
     $this->get_courier()->handle($this);
     /**
      * Manage the stock
      */
     if (!class_exists('\\Skeleton\\Package\\Stock\\Stock')) {
         return;
     }
     foreach ($this->get_overview() as $item) {
         \Skeleton\Package\Stock\Stock::change($item['deliverable'], $item['shipped'] * -1, $this, 'Delivery ' . $this->delivery_id);
     }
 }
Exemplo n.º 5
0
 /**
  * Add a movement
  *
  * @access public
  */
 public function display_add_movement()
 {
     $classname = \Skeleton\Package\Stock\Config::$object_stock_interface;
     $product = $classname::get_by_id($_GET['id']);
     \Skeleton\Package\Stock\Stock::change($product, $_POST['stock_movement']['movement'], $_SESSION['user'], $_POST['stock_movement']['comment']);
     Session::redirect('/' . $this->get_module_path() . '?action=edit&id=' . $product->id);
 }
Exemplo n.º 6
0
 /**
  * Get overview
  * This function is used to show an overview of the items to be shipped
  *
  * @access public
  * @return array $delivery_items_overview
  */
 public function get_overview()
 {
     $items = $this->get_delivery_items();
     $result = [];
     foreach ($items as $item) {
         $deliverable = $item->get_deliverable();
         if (!isset($result[$deliverable->id])) {
             $result[$deliverable->id] = ['deliverable' => $deliverable, 'shipped' => 0, 'total' => 0];
             if (class_exists('\\Skeleton\\Package\\Stock\\Stock')) {
                 $result[$deliverable->id]['stock'] = \Skeleton\Package\Stock\Stock::get($deliverable);
             }
         }
         $result[$deliverable->id]['total']++;
         if ($item->shipment_item_id != 0) {
             $result[$deliverable->id]['shipped']++;
         }
     }
     return $result;
 }