Ejemplo n.º 1
0
if (isset($_POST['_code'])) {
    $stock = CProductStockGroup::getFromCode($_POST['_code']);
    if ($stock) {
        $_POST['stock_class'] = "CProductStockGroup";
        $_POST['stock_id'] = $stock->_id;
        $_POST['_code'] = null;
    }
}
if (isset($_POST['product_id'])) {
    $product = new CProduct();
    $product->load($_POST['product_id']);
    if ($product->loadRefStock()->_id) {
        $_POST["stock_class"] = $product->_ref_stock_group->_class;
        $_POST["stock_id"] = $product->_ref_stock_group->_id;
        unset($_POST['product_id']);
    } else {
        if (isset($_POST['manual'])) {
            $stock_group = new CProductStockGroup();
            $stock_group->product_id = $product->_id;
            $stock_group->group_id = CProductStockGroup::getHostGroup();
            $stock_group->quantity = $_POST["quantity"];
            $stock_group->order_threshold_min = $_POST["quantity"];
            CAppUI::displayMsg($stock_group->store(), "CProductStockGroup-msg-create");
            $_POST["stock_class"] = $stock_group->_class;
            $_POST["stock_id"] = $stock_group->_id;
            unset($_POST['product_id']);
        }
    }
}
$do = new CDoObjectAddEdit('CProductDelivery');
$do->doIt();
 /**
  * @see parent::store()
  */
 function store()
 {
     $this->completeField("reception_id");
     $is_new = !$this->_id;
     if ($is_new && $this->cancelled === null) {
         $this->cancelled = 0;
     }
     if ($is_new) {
         $this->loadRefOrderItem();
         $this->_ref_order_item->loadOrder();
     }
     if ($is_new && !$this->reception_id) {
         $order = $this->_ref_order_item->_ref_order;
         $reception = new CProductReception();
         $reception->date = CMbDT::dateTime();
         $reception->societe_id = $order->societe_id;
         $reception->group_id = CProductStockGroup::getHostGroup();
         // Recherche de receptions ayant un numero de reception similaire pour gerer l'increment
         if ($order->order_number) {
             $where = array("reference" => "LIKE '{$order->order_number}%'");
             $number = $reception->countList($where) + 1;
             $reception->reference = "{$order->order_number}-{$number}";
         }
         if ($msg = $reception->store()) {
             return $msg;
         }
         $this->reception_id = $reception->_id;
     }
     if ($is_new) {
         $this->_ref_order_item->loadRefsFwd();
         $this->_ref_order_item->_ref_reference->loadRefsFwd();
         $this->_ref_order_item->_ref_reference->_ref_product->loadRefStock();
         $product =& $this->_ref_order_item->_ref_reference->_ref_product;
         $product->updateFormFields();
         if ($product->loadRefStock()) {
             $stock = $product->_ref_stock_group;
             $stock->quantity += $this->quantity;
         } else {
             $qty = $this->quantity;
             $stock = new CProductStockGroup();
             $stock->product_id = $product->_id;
             $stock->group_id = CProductStockGroup::getHostGroup();
             $stock->quantity = $qty;
             $stock->order_threshold_min = $qty;
             CAppUI::setMsg("Un nouveau stock a été créé", UI_MSG_OK);
             //CAppUI::setMsg("Un nouveau stock pour [%s] a été créé", UI_MSG_OK, $product->_view);
         }
         if ($msg = $stock->store()) {
             return $msg;
         }
     }
     if ($msg = parent::store()) {
         return $msg;
     }
     // If the order is received, we set the flag
     if ($is_new) {
         $order = $this->_ref_order_item->_ref_order;
         if (!$order->received) {
             $count_renewed = $order->countRenewedItems();
             $count_received = $order->countReceivedItems() - (count($order->_ref_order_items) - $count_renewed);
             if ($count_renewed && $count_received >= $count_renewed) {
                 $order->received = 1;
                 $order->store();
             }
         }
     }
     return null;
 }