/**
  * @see parent::getPerm()
  */
 function getPerm($permType)
 {
     if (!$this->_ref_stock || !$this->_ref_service) {
         $this->loadRefsFwd();
     }
     if ($this->_ref_service) {
         return $this->_ref_stock->getPerm($permType) && $this->_ref_service->getPerm($permType);
     }
     return $this->_ref_stock->getPerm($permType);
 }
 /**
  * @see parent::updatePlainFields()
  */
 function updatePlainFields()
 {
     parent::updatePlainFields();
     $this->completeField("group_id");
     if (!$this->group_id) {
         $this->group_id = CProductStockGroup::getHostGroup();
     }
 }
/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage Stock
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkEdit();
$stock_id = CValue::getOrSession('stock_id');
$category_id = CValue::getOrSession('category_id');
$product_id = CValue::get('product_id');
$letter = CValue::getOrSession('letter', "%");
// Loads the stock in function of the stock ID or the product ID
$stock = new CProductStockGroup();
// If stock_id has been provided, we load the associated product
if ($stock_id) {
    $stock->stock_id = $stock_id;
    $stock->loadMatchingObject();
    $stock->loadRefsFwd();
    $stock->_ref_product->loadRefsFwd();
} else {
    if ($product_id) {
        $product = new CProduct();
        $product->load($product_id);
        $stock->product_id = $product_id;
        $stock->_ref_product = $product;
    } else {
        $stock->loadRefsFwd();
    }
 * $Id$
 *
 * @package    Mediboard
 * @subpackage Stock
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkEdit();
$start = intval(CValue::get("start", 0));
$keywords = CValue::get("keywords");
$without_supplier = CValue::get("without_supplier");
// Chargement des receptions de l'etablissement
$reception = new CProductReception();
$where = array();
$where["group_id"] = "= '" . CProductStockGroup::getHostGroup() . "'";
if (!$without_supplier) {
    $where["societe_id"] = "IS NOT NULL";
}
$receptions = $reception->seek($keywords, $where, "{$start}, 25", true, null, "date DESC");
$total = $reception->_totalSeek;
foreach ($receptions as $_reception) {
    $_reception->countReceptionItems();
}
// Smarty template
$smarty = new CSmartyDP();
$smarty->assign("reception", $reception);
$smarty->assign("receptions", $receptions);
$smarty->assign("total", $total);
$smarty->assign("start", $start);
$smarty->display('inc_receptions_list.tpl');
<?php

/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage Stock
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkEdit();
$stock_location_id = CValue::getOrSession('stock_location_id');
$stock_location = new CProductStockLocation();
$stock_location->load($stock_location_id);
$stock_location->loadRefsStocks();
$stock_location->loadTargetObject();
$stock_location->_type = $stock_location->_id ? $stock_location->_ref_object->_guid : null;
$classes = $stock_location->_specs["object_class"]->_locales;
$where = array("group_id" => "='" . CGroups::loadCurrent()->_id . "'");
$types = array();
foreach ($classes as $_class => $_locale) {
    $object = new $_class();
    $types[$_locale] = $object->loadListWithPerms(PERM_READ, $where);
}
// Smarty template
$smarty = new CSmartyDP();
$smarty->assign('stock_location', $stock_location);
$smarty->assign('types', $types);
$smarty->assign("host_group_id", CProductStockGroup::getHostGroup());
$smarty->display('inc_form_stock_location.tpl');
 /**
  * Computes this product's consumption between two dates
  *
  * @param CProduct[] $products     Products list
  * @param string     $since        [optional] Start offset
  * @param string     $date_max     [optional] Max date
  *
  * @param CService[] $services     Services
  * @param bool       $include_loss Include lost items
  *
  * @return float[]
  */
 static function getConsumptionMultipleProducts($products, $since = "-1 MONTH", $date_max = null, $services = null, $include_loss = true)
 {
     $ds = CSQLDataSource::get("std");
     $where = array("product_stock_group.product_id" => $ds->prepareIn(CMbArray::pluck($products, "_id")), "product_stock_group.group_id" => "= '" . CProductStockGroup::getHostGroup() . "'", "product_delivery.stock_class" => "= 'CProductStockGroup'", "product_delivery_trace.date_delivery > '" . CMbDT::date($since) . "'");
     if ($date_max) {
         $where[] = "product_delivery_trace.date_delivery <= '" . CMbDT::date($date_max) . "'";
     }
     if (!empty($services)) {
         $where["product_delivery.service_id"] = $ds->prepareIn(CMbArray::pluck($services, "_id"));
     } else {
         if ($include_loss) {
             $where["product_delivery.service_id"] = "IS NOT NULL";
         }
     }
     $ljoin = array("product_delivery" => "product_delivery.delivery_id = product_delivery_trace.delivery_id", "product_stock_group" => "product_delivery.stock_id = product_stock_group.stock_id");
     $sql = new CRequest();
     $sql->addTable("product_delivery_trace");
     $sql->addSelect(array("product_stock_group.product_id", "SUM(product_delivery_trace.quantity) AS sum"));
     $sql->addLJoin($ljoin);
     $sql->addGroup("product_stock_group.product_id");
     $sql->addWhere($where);
     if (empty($services)) {
         $total = $ds->loadHashList($sql->makeSelect());
     } else {
         $sql->addGroup("product_delivery.service_id");
         $sql->addSelect(array("product_delivery.service_id"));
         $total = $ds->loadList($sql->makeSelect());
     }
     return $total;
 }
Esempio n. 7
0
 /**
  * Search a product
  *
  * @param string  $type     The type of orders we are looking for [waiting|locked|pending|received|cancelled]
  * @param string  $keywords [optional]
  * @param integer $limit    = 30 [optional]
  * @param array   $where    Where additionnal
  *
  * @return self[] The list of orders
  */
 function search($type, $keywords = "", $limit = 30, $where = array())
 {
     global $g;
     $leftjoin = array();
     $leftjoin['product_order_item'] = 'product_order.order_id = product_order_item.order_id';
     $leftjoin['product_order_item_reception'] = 'product_order_item.order_item_id = product_order_item_reception.order_item_id';
     $leftjoin['product_reference'] = 'product_order_item.reference_id = product_reference.reference_id';
     $leftjoin['product'] = 'product_reference.product_id = product.product_id';
     // if keywords have been provided
     if ($keywords) {
         $societe = new CSociete();
         $where_or = array();
         // we seek among the societes
         $where_societe_or = array();
         foreach ($societe->getSeekables() as $field => $spec) {
             $where_societe_or[] = "societe.{$field} LIKE '%{$keywords}%'";
         }
         $where_societe[] = implode(' OR ', $where_societe_or);
         // we seek among the orders
         foreach ($this->getSeekables() as $field => $spec) {
             $where_or[] = "product_order.{$field} LIKE '%{$keywords}%'";
         }
         $where_or[] = 'product_order.societe_id ' . CSQLDataSource::prepareIn(array_keys($societe->loadList($where_societe)));
         $where[] = implode(' OR ', $where_or);
     }
     $orderby = 'product_order.date_ordered DESC, product_order_item_reception.date DESC';
     $where['product_order.deleted'] = " = 0";
     $where['product_order.cancelled'] = " = 0";
     $where['product_order.locked'] = " = 0";
     $where['product_order.date_ordered'] = "IS NULL";
     $where['product_order.received'] = " != '1'";
     // Exclude return orders (Bon de retour)
     $query = "!= % OR product_order.comments IS NULL";
     $where['product_order.comments'] = $this->_spec->ds->prepare($query, CProductOrder::$_return_form_label);
     switch ($type) {
         case 'waiting':
             break;
         case 'locked':
             $where['product_order.locked'] = " = 1";
             break;
         case 'pending':
             $where['product_order.locked'] = " = 1";
             $where['product_order.date_ordered'] = "IS NOT NULL";
             break;
         case 'received':
             $where['product_order.locked'] = " = 1";
             $where['product_order.date_ordered'] = "IS NOT NULL";
             $where['product_order.received'] = " = '1'";
             break;
         default:
         case 'cancelled':
             $where['product_order.cancelled'] = " = 1";
             unset($where['product_order.locked']);
             unset($where['product_order.received']);
             unset($where['product_order.date_ordered']);
             break;
     }
     $where['product_order.group_id'] = " = '" . CProductStockGroup::getHostGroup() . "'";
     $old_limit = $limit;
     if ($type === 'pending') {
         $limit = 200;
     }
     $groupby = "product_order.order_id";
     /** @var self[] $orders_list */
     $orders_list = $this->loadList($where, $orderby, $limit, $groupby, $leftjoin);
     // bons de facturation seulement
     if ($type === 'pending') {
         foreach ($orders_list as $_id => $_order) {
             if (!$_order->containsRenewalLines()) {
                 unset($orders_list[$_id]);
             }
         }
         $this->_search_count = count($orders_list);
         $orders_list = CRequest::artificialLimit($orders_list, $old_limit);
     } else {
         $this->_search_count = count($this->countMultipleList($where, null, $groupby, $leftjoin));
     }
     /*if ($type === 'pending') {
         $list = array();
         foreach ($orders_list as $_order) {
           if ($_order->countReceivedItems() < $_order->countBackRefs("order_items")) {
             $list[] = $_order;
           }
         }
         $orders_list = $list;
       }
       
       else if ($type === 'received') {
         $list = array();
         foreach ($orders_list as $_order) {
           if ($_order->countReceivedItems() >= $_order->countBackRefs("order_items")) {
             $list[] = $_order;
           }
         }
         $orders_list = $list;
       }*/
     foreach ($orders_list as $_order) {
         $_order->loadRefsFwd();
     }
     return $orders_list;
 }
    $leftjoin['product_reference'] = 'product_reference.product_id = product_stock_group.product_id';
    // stock to reference
    $leftjoin['product_order_item'] = 'product_order_item.reference_id = product_reference.reference_id';
    // reference to order item
    $leftjoin['product_order'] = 'product_order.order_id = product_order_item.order_id';
    // order item to order
    $where[] = 'product_order_item.order_item_id NOT IN (
    SELECT product_order_item.order_item_id FROM product_order_item
    LEFT JOIN product_order_item_reception ON product_order_item_reception.order_item_id = product_order_item.order_item_id
    LEFT JOIN product_order ON product_order.order_id = product_order_item.order_id
    WHERE product_order.deleted = 0 AND product_order.cancelled = 0
    HAVING SUM(product_order_item_reception.quantity) < product_order_item.quantity
  )';
}
$pagination_size = CAppUI::conf("dPstock CProductStockGroup pagination_size");
$stock = new CProductStockGroup();
$list_stocks = $stock->loadList($where, 'product.name ASC', intval($start) . ",{$pagination_size}", "product_stock_group.stock_id", $leftjoin);
foreach ($list_stocks as $_stock) {
    $_stock->_ref_product->getPendingOrderItems(false);
}
if (!$only_ordered_stocks) {
    $list_stocks_count = $stock->countList($where, null, $leftjoin);
} else {
    $list_stocks_count = count($stock->loadList($where, null, null, "product_stock_group.stock_id", $leftjoin));
}
// Smarty template
$smarty = new CSmartyDP();
$smarty->assign('stock', $stock);
$smarty->assign('stock_id', $stock_id);
$smarty->assign('list_stocks', $list_stocks);
$smarty->assign('list_stocks_count', $list_stocks_count);
Esempio n. 9
0
 * @subpackage soins
 * @version $Revision: 6067 $
 * @author SARL OpenXtrem
 * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html 
 */
$service_id = CValue::get('service_id');
$date_min = CValue::get('date_min');
$date_max = CValue::get('date_max');
$service = new CService();
$orders = array();
if ($service->load($service_id) && $date_min && $date_max) {
    $stocks = $service->loadBackRefs('product_stock_services');
    if ($stocks) {
        foreach ($stocks as $stock) {
            $stock->loadRefsFwd();
            $stock_group = CProductStockGroup::getFromCode($stock->_ref_product->code);
            $target_quantity = $stock->order_threshold_optimum ? $stock->order_threshold_optimum : $stock->order_threshold_max;
            if (CAppUI::conf('dPstock CProductStockService infinite_quantity') != 1) {
                $effective_quantity = $stock->quantity;
                $where = array('product_delivery.date_dispensation' => "BETWEEN '{$date_min} 00:00:00' AND '{$date_max} 23:59:59'", 'product_delivery.stock_id' => " = '{$stock_group->_id}'", 'product_delivery.stock_class' => " = '{$stock_group->_class}'", 'product.category_id' => " = '" . CAppUI::conf('dPmedicament CBcbProduitLivretTherapeutique product_category_id') . "'");
                $ljoin = array('product_stock_group' => 'product_delivery.stock_id = product_stock_group.stock_id', 'product' => 'product.product_id = product_stock_group.product_id');
                $delivery = new CProductDelivery();
                $deliveries = $delivery->loadList($where, null, null, null, $ljoin);
                foreach ($deliveries as $delivery) {
                    if ($delivery->order == 1 && $delivery->quantity > 0) {
                        $effective_quantity += $delivery->quantity;
                    }
                }
                if ($target_quantity > $effective_quantity) {
                    // This the GROUP stock!
                    $orders[$stock_group->_id] = $target_quantity - $effective_quantity;
Esempio n. 10
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;
 }
Esempio n. 12
0
<?php

/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage Stock
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
$do = new CDoObjectAddEdit('CProductOrder');
// New order
if (CValue::post('order_id') == 0) {
    $order = new CProductOrder();
    $order->group_id = CProductStockGroup::getHostGroup();
    $order->societe_id = CValue::post('societe_id');
    $order->order_number = CValue::post('order_number');
    $order->locked = 0;
    $order->cancelled = 0;
    if ($msg = $order->store()) {
        CAppUI::setMsg($msg);
    } else {
        if (CValue::post('_autofill') == 1) {
            $order->autofill();
        }
        CAppUI::setMsg($do->createMsg);
        CAppUI::redirect('m=dPstock&a=vw_aed_order&dialog=1&order_id=' . $order->order_id);
    }
}
$do->doIt();
 * $Id$
 *
 * @package    Mediboard
 * @subpackage Stock
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkEdit();
$stock_id = CValue::getOrSession('stock_service_id');
$category_id = CValue::get('category_id');
$object_id = CValue::get('object_id');
$keywords = CValue::get('keywords');
$start = CValue::get('start');
CValue::setSession('category_id', $category_id);
$where = array("service.group_id" => "= '" . CProductStockGroup::getHostGroup() . "'");
if ($object_id) {
    $where['product_stock_service.object_id'] = " = '{$object_id}'";
    $where['product_stock_service.object_class'] = " = 'CService'";
    // XXX
}
if ($category_id) {
    $where['product.category_id'] = " = '{$category_id}'";
}
if ($keywords) {
    $where[] = "product.code LIKE '%{$keywords}%' OR \r\n              product.name LIKE '%{$keywords}%' OR \r\n              product.description LIKE '%{$keywords}%'";
}
$leftjoin = array("product" => "product.product_id = product_stock_service.product_id", "service" => "service.service_id = product_stock_service.object_id");
$stock = new CProductStockService();
$list_stocks_count = $stock->countList($where, null, $leftjoin);
$pagination_size = CAppUI::conf("dPstock CProductStockService pagination_size");
 /**
  * Get the related stock
  *
  * @return CProductStockGroup
  */
 function getStock()
 {
     if ($this->_ref_stock_group) {
         return $this->_ref_stock_group;
     }
     $this->loadReference();
     $this->loadOrder();
     $stock = new CProductStockGroup();
     $stock->group_id = $this->_ref_order->group_id;
     $stock->product_id = $this->_ref_reference->product_id;
     $stock->loadMatchingObject();
     return $this->_ref_stock_group = $stock;
 }
Esempio n. 15
0
<?php

/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage Stock
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
// If it is a return to the group stock
if (isset($_POST['_return']) && isset($_POST['_code'])) {
    $stock_service = CProductStockService::getFromCode($_POST['_code']);
    $stock_group = CProductStockGroup::getFromCode($_POST['_code']);
    $_POST['quantity'] = -abs($_POST['quantity']);
    $_POST['_code'] = null;
    $_POST['_return'] = null;
    if ($stock_service && $stock_group) {
        $delivery = new CProductDelivery();
        $where = array('stock_id' => "= '{$stock_group->_id}'", 'stock_class' => "= 'CProductStockGroup'", 'service_id' => "= '{$stock_service->service_id}'", 'quantity' => "< 0");
        if (!$delivery->loadObject($where)) {
            $delivery->stock_id = $stock_group->_id;
            $delivery->stock_class = $stock_group->_class;
            $delivery->service_id = $stock_service->service_id;
        }
        $delivery->quantity += $_POST['quantity'];
        $delivery->date_dispensation = CMbDT::dateTime();
        if ($msg = $delivery->store()) {
            CAppUI::setMsg($msg, UI_MSG_ERROR);
        }
<?php

/**
 * $Id: httpreq_edit_stock_group.php 25962 2014-11-20 10:26:34Z phenxdesign $
 *
 * @package    Mediboard
 * @subpackage Stock
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 25962 $
 */
CCanDo::checkEdit();
$stock_id = CValue::get('stock_id');
$product_id = CValue::get('product_id');
// Loads the stock in function of the stock ID or the product ID
$stock = new CProductStockGroup();
// If stock_id has been provided, we load the associated product
if ($stock_id) {
    $stock->stock_id = $stock_id;
    $stock->loadMatchingObject();
    $stock->loadRefsFwd();
    $stock->_ref_product->loadRefsFwd();
} else {
    if ($product_id) {
        $product = new CProduct();
        $product->load($product_id);
        $stock->product_id = $product_id;
        $stock->_ref_product = $product;
    } else {
        $stock->loadRefsFwd();
    }
Esempio n. 17
0
// Loads the stock
$stock = new CProductStockService();
// If stock_id has been provided, we load the associated product
if ($stock_service_id) {
    $stock->load($stock_service_id);
    $stock->loadRefsFwd();
    $stock->_ref_product->loadRefsFwd();
} else {
    if ($product_id) {
        $product = new CProduct();
        $product->load($product_id);
        $stock->product_id = $product_id;
        $stock->_ref_product = $product;
        $stock->updateFormFields();
    } else {
        $stock->loadRefsFwd();
        // pour le _ref_product
    }
}
// Categories list
$list_categories = new CProductCategory();
$list_categories = $list_categories->loadList(null, 'name');
$list_services = CProductStockGroup::getServicesList();
// Création du template
$smarty = new CSmartyDP();
$smarty->assign('stock', $stock);
$smarty->assign('category_id', $category_id);
$smarty->assign('service_id', $service_id);
$smarty->assign('list_categories', $list_categories);
$smarty->assign('list_services', $list_services);
$smarty->display('vw_idx_stock_service.tpl');
Esempio n. 18
0
                //if (count($stocks) == 20) continue;
                $stock = new CProductStockGroup();
                $stock->product_id = $stock_service->_ref_product->_id;
                $stock->group_id = $group_id;
                if ($stock->loadMatchingObject()) {
                    $stock->updateFormFields();
                    $stock->_ref_stock_service = $stock_service;
                    $stock->quantity = max(0, $stock_service->getOptimumQuantity() - $stock_service->quantity);
                    $stocks[$stock->_id] = $stock;
                }
            }
        }
    } else {
        $where["product_stock_group.group_id"] = "= '{$group_id}'";
        $ljoin = array('product' => 'product.product_id = product_stock_group.product_id');
        $stock = new CProductStockGroup();
        /** @var CProductStockGroup[] $stocks */
        $stocks = $stock->seek($keywords, $where, $limit, true, $ljoin, 'product.name');
        $count_stocks = $stock->_totalSeek;
        if ($stocks) {
            foreach ($stocks as $_id => $_stock) {
                if ($_stock->_ref_product->cancelled) {
                    unset($stocks[$_id]);
                } else {
                    $_stock->quantity = min($_stock->quantity, $_stock->getOptimumQuantity());
                }
            }
        }
    }
}
// Load the already ordered dispensations