/**
  * @see parent::delete()
  */
 function delete()
 {
     $this->completeField('delivery_id', 'quantity', 'date_delivery', 'date_reception');
     $this->loadRefsFwd();
     $stock = $this->getStock();
     $stock->loadRefsFwd();
     $infinite_group_stock = CAppUI::conf('dPstock CProductStockGroup infinite_quantity') == '1';
     $stock_service = new CProductStockService();
     $stock_service->product_id = $stock->product_id;
     $stock_service->object_id = $this->_ref_delivery->service_id;
     $stock_service->object_class = "CService";
     // XXX
     $stock_service->loadMatchingObject();
     if (!$infinite_group_stock && $this->date_delivery) {
         $stock->quantity += $this->quantity;
         if ($msg = $stock->store()) {
             return $msg;
         }
     }
     if ($stock_service->_id && $this->date_reception) {
         $stock_service->quantity -= $this->quantity;
         if ($msg = $stock_service->store()) {
             return $msg;
         }
     }
     // Calcul du stock du sejour
     if ($this->_code_cis && $this->_ref_delivery->sejour_id && CModule::getActive("pharmacie")) {
         $stock_sejour = CStockSejour::getFromCIS($this->_code_cis, $this->_ref_delivery->sejour_id);
         if ($stock_sejour->_id) {
             $codes_cip = CMedicamentProduit::getArticleCodes($this->_code_cis);
             $ds = $this->getDS();
             $where = array();
             $where["product.code"] = $ds->prepareIn($codes_cip);
             $where["product_delivery.sejour_id"] = $ds->prepare("= '{$this->_ref_delivery->sejour_id}'");
             $ljoin = array();
             $ljoin["product_stock_group"] = "product_stock_group.stock_id = product_delivery.stock_id\r\n                                           AND product_delivery.stock_class = 'CProductStockGroup'";
             $ljoin["product"] = "product.product_id = product_stock_group.product_id";
             $delivery = new CProductDelivery();
             $delivery->loadObject($where, "product_delivery.date_dispensation DESC", null, $ljoin);
             // Si la delivrance actuelle est la derniere pour ce sejour et ce CIS
             if ($delivery->_id == $this->delivery_id) {
                 // Mise a jour de la quantité du stock en quantité d'administration
                 $code_cip = $this->_ref_delivery->loadRefStock()->loadRefProduct()->code;
                 $product = CMedicamentArticle::get($code_cip);
                 if ($product->getId()) {
                     $ratio = $product->_ratio_cis_cip;
                     // Mise à jour du stock
                     $stock_sejour->datetime = $this->_ref_delivery->datetime_min;
                     $stock_sejour->quantite -= $this->quantity / $ratio;
                     $stock_sejour->quantite = round($stock_sejour->quantite, 4);
                     if ($msg = $stock_sejour->store()) {
                         return $msg;
                     }
                 }
             }
         }
     }
     return parent::delete();
 }
Пример #2
0
    $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();
    }
}
$stock->updateFormFields();
$list_services = CProductStockGroup::getServicesList();
foreach ($list_services as $_service) {
    $stock_service = new CProductStockService();
    $stock_service->object_id = $_service->_id;
    $stock_service->object_class = $_service->_class;
    $stock_service->product_id = $stock->product_id;
    if (!$stock_service->loadMatchingObject()) {
        $stock_service->quantity = $stock->_ref_product->quantity;
        $stock_service->order_threshold_min = $stock->_ref_product->quantity;
        $stock_service->order_threshold_optimum = max($stock->getOptimumQuantity(), $stock_service->quantity);
    }
    $_service->_ref_stock = $stock_service;
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign('stock', $stock);
$smarty->assign('list_services', $list_services);
$smarty->display('inc_edit_stock_group.tpl');
Пример #3
0
 /**
  * Load target stock
  *
  * @return CProductStockService
  */
 function loadRefTargetStock()
 {
     $this->loadRefStock();
     $stock_service = new CProductStockService();
     $this->completeField("service_id");
     if ($this->service_id) {
         $stock_service->product_id = $this->_ref_stock->product_id;
         $stock_service->object_id = $this->service_id;
         $stock_service->object_class = "CService";
         // XXX
         $stock_service->loadMatchingObject();
     }
     return $this->_ref_stock_service = $stock_service;
 }