/**
  * @see parent::updatePlainFields()
  */
 function updatePlainFields()
 {
     parent::updatePlainFields();
     $this->completeField("group_id");
     if (!$this->group_id) {
         $this->group_id = CProductStockGroup::getHostGroup();
     }
 }
<?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');
 * $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');
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
 /**
  * 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;
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 8
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");
 *
 * @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();
$category_id = CValue::get('category_id');
$stock_id = CValue::getOrSession('stock_id');
$keywords = CValue::get('keywords');
$start = CValue::get('start');
$letter = CValue::getOrSession('letter', "%");
$only_ordered_stocks = CValue::get('only_ordered_stocks');
CValue::setSession('category_id', $category_id);
$where = array("product_stock_group.group_id" => "= '" . CProductStockGroup::getHostGroup() . "'", "product.name" => $letter === "#" ? "RLIKE '^[^A-Z]'" : "LIKE '{$letter}%'");
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_group.product_id');
if ($only_ordered_stocks) {
    $where['product_order.cancelled'] = '= 0';
    // order not cancelled
    $where['product_order.deleted'] = '= 0';
    // order not deleted
    $where['product_order.date_ordered'] = 'IS NOT NULL';
    // order not deleted
    $where['product_order_item.renewal'] = '= 1';