예제 #1
0
 /**
  * @see parent::loadRefsBack()
  */
 function loadRefsBack()
 {
     $ljoin = array("product" => "product_reference.product_id = product.product_id");
     $where = array("product_reference.societe_id" => " = '{$this->_id}'");
     $reference = new CProductReference();
     $this->_ref_product_references = $reference->loadList($where, "product.name", null, null, $ljoin);
     $this->_back["product_references"] = $this->_ref_product_references;
     $this->_ref_products = $this->loadBackRefs('products', "name");
     $this->_ref_product_orders = $this->loadBackRefs('product_orders', "date_ordered");
 }
$ratio = (double) CValue::get("ratio", 2);
CApp::setMemoryLimit('512M');
CApp::setTimeLimit(120);
$sql = new CRequest();
$sql->addTable("product_order_item");
$sql->addSelect("\r\n  product_order_item.order_item_id,\r\n  product_order_item.reference_id, \r\n  product_reference.price AS RP, \r\n  product_order_item.unit_price AS OP, \r\n  product_order_item.quantity AS OQ, \r\n  product_order.order_id, \r\n  product_order.order_number, \r\n  product_order.date_ordered");
$sql->addLJoin(array("product_reference" => "product_reference.reference_id = product_order_item.reference_id", "product_order" => "product_order.order_id = product_order_item.order_id"));
$sql->addWhere("\r\n  product_order.cancelled = '0' \r\n  AND (product_reference.cancelled = '0' OR product_reference.cancelled IS NULL)\r\n  AND product_reference.price != product_order_item.unit_price\r\n  AND (\r\n    product_order_item.unit_price > product_reference.price*{$ratio} OR \r\n    product_reference.price > product_order_item.unit_price*{$ratio}\r\n  )");
$sql->addOrder("product_reference.code");
$changes = $this->_spec->ds->loadList($sql->makeSelect());
$changes_struct = array();
$references = array();
$references_cahpp = array();
foreach ($changes as $_change) {
    if (!isset($references[$_change["reference_id"]])) {
        $_reference = new CProductReference();
        $_reference->load($_change["reference_id"]);
        $references[$_reference->_id] = $_reference;
        $article = new CCAHPPArticle();
        $where = array("reference_fournisseur" => $article->_spec->ds->prepare("=%", $_reference->supplier_code));
        if (!$article->loadObject($where)) {
            $where = array("cip" => $article->_spec->ds->prepare("=%", $_reference->loadRefProduct()->code));
            $article->loadObject($where);
        }
        $references_cahpp[$_reference->_id] = $article;
    }
    $_order_item = new CProductOrderItem();
    $_order_item->load($_change["order_item_id"]);
    $_order_item->loadOrder();
    $_change["order_item"] = $_order_item;
    $changes_struct[$_change["reference_id"]][] = $_change;
예제 #3
0
 /**
  * Fills the order in function of the stocks and future stocks
  *
  * @return void
  */
 function autofill()
 {
     $this->updateFormFields();
     $this->completeField('societe_id');
     // if the order has not been ordered yet
     // and not partially received
     // and not totally received
     // and not cancelled
     // and not deleted
     if (!$this->date_ordered && !$this->_received && !$this->cancelled && !$this->deleted) {
         // we empty the order
         foreach ($this->_ref_order_items as $item) {
             $item->delete();
         }
     }
     // we retrieve all the stocks
     $stock = new CProductStockGroup();
     $list_stocks = $stock->loadList();
     // for every stock
     foreach ($list_stocks as $stock) {
         $stock->loadRefsFwd();
         // if the stock is in the "red" or "orange" zone
         if ($stock->_zone_future < 2) {
             $current_stock = $stock->quantity;
             $expected_stock = $stock->getOptimumQuantity();
             if ($current_stock < $expected_stock) {
                 // we get the best reference for this product
                 $where = array('product_id' => " = '{$stock->_ref_product->_id}'", 'societe_id' => " = '{$this->societe_id}'");
                 $orderby = 'price ASC';
                 $best_reference = new CProductReference();
                 if ($best_reference->loadObject($where, $orderby) && $best_reference->quantity > 0) {
                     // we store the new order item in the current order
                     $order_item = new CProductOrderItem();
                     $order_item->order_id = $this->_id;
                     $order_item->quantity = $expected_stock - $current_stock;
                     $order_item->reference_id = $best_reference->_id;
                     $order_item->unit_price = $best_reference->price;
                     $order_item->store();
                 }
             }
         }
     }
 }
    $where['product.category_id'] = " = '{$category_id}'";
}
if ($societe_id) {
    $where['product_reference.societe_id'] = " = '{$societe_id}'";
}
if ($keywords) {
    $where[] = "product_reference.code LIKE '%{$keywords}%' OR \r\n              product.code LIKE '%{$keywords}%' OR \r\n              product.name LIKE '%{$keywords}%' OR \r\n              product.classe_comptable LIKE '%{$keywords}%' OR \r\n              product.description LIKE '%{$keywords}%'";
}
if (!$show_all) {
    $where[] = "product_reference.cancelled = '0' OR product_reference.cancelled IS NULL";
}
$where["product.name"] = $letter === "#" ? "RLIKE '^[^A-Z]'" : "LIKE '{$letter}%'";
$orderby = 'product.name ASC';
$leftjoin = array();
$leftjoin['product'] = 'product.product_id = product_reference.product_id';
$reference = new CProductReference();
$total = $reference->countList($where, null, $leftjoin);
$list_references = $reference->loadList($where, $orderby, intval($start) . "," . CAppUI::conf("dPstock CProductReference pagination_size"), null, $leftjoin);
foreach ($list_references as $ref) {
    $ref->loadRefsFwd();
    $ref->_ref_product->loadRefStock();
    $ref->_ref_product->getPendingOrderItems(false);
}
$smarty = new CSmartyDP();
$smarty->assign('list_references', $list_references);
$smarty->assign('total', $total);
$smarty->assign('mode', $mode);
$smarty->assign('start', $start);
$smarty->assign('letter', $letter);
$smarty->assign('reference_id', $reference_id);
$smarty->display('inc_references_list.tpl');
예제 #5
0
 * @version    $Revision$
 */
CCanDo::checkEdit();
$reference_id = CValue::getOrSession('reference_id');
$societe_id = CValue::getOrSession('societe_id');
$category_id = CValue::getOrSession('category_id');
$product_id = CValue::getOrSession('product_id');
$keywords = CValue::getOrSession('keywords');
$letter = CValue::getOrSession('letter', "%");
$show_all = CValue::getOrSession('show_all');
$filter = new CProduct();
$filter->societe_id = $societe_id;
$filter->category_id = $category_id;
CProductOrderItem::$_load_lite = true;
// Loads the expected Reference
$reference = new CProductReference();
// If a reference ID has been provided,
// we load it and its associated product
if ($reference->load($reference_id)) {
    $reference->loadRefsFwd();
    $reference->_ref_product->loadRefsFwd();
    $reference->loadRefsNotes();
} else {
    if ($product_id) {
        $reference->product_id = $product_id;
        $product = new CProduct();
        $product->load($product_id);
        $reference->_ref_product = $product;
    } else {
        if ($societe_id) {
            $reference->societe_id = $societe_id;
    // If it is a societe id
    if (!is_numeric($reference_id)) {
        list($societe_id, $product_id) = explode("-", $reference_id);
        $societe = new CSociete();
        $societe->load($societe_id);
        $product = new CProduct();
        $product->load($product_id);
        $reference = new CProductReference();
        $reference->product_id = $product->_id;
        $reference->societe_id = $societe->_id;
        $reference->quantity = 1;
        $reference->price = 0;
        $reference->store();
    } else {
        // If it is a reference id
        $reference = new CProductReference();
        $reference->load($reference_id);
    }
    if (!$reference->_id) {
        CAppUI::setMsg("Impossible de créer l'article, la réference n'existe pas", UI_MSG_ERROR);
    }
    $order_item = new CProductOrderItem();
    $order_item->reference_id = $reference->_id;
    $order_item->quantity = $quantity;
    $order_item->unit_price = $reference->price;
    if ($msg = $order_item->store()) {
        CAppUI::setMsg($msg);
    }
    $_POST["order_item_id"] = $order_item->_id;
}
$do->doIt();
예제 #7
0
    }
}
//CSQLDataSource::$trace = true;
// ---------------------
CProductOrderItemReception::$_load_lite = true;
$oir = new CProductOrderItemReception();
$oir_where = array("product_order_item_reception.units_fixed" => "= '0'");
$oir_ljoin = array("product_order_item" => "product_order_item_reception.order_item_id = product_order_item.order_item_id", "product_reference" => "product_order_item.reference_id = product_reference.reference_id", "product" => "product_reference.product_id = product.product_id");
// ---------------------
CProductOrderItem::$_load_lite = true;
$oi = new CProductOrderItem();
$oi_where = array("product_order_item.units_fixed" => "= '0'");
$oi_ljoin = array("product_reference" => "product_order_item.reference_id = product_reference.reference_id", "product" => "product_reference.product_id = product.product_id", "user_log" => "product_order_item.order_item_id = user_log.object_id AND user_log.object_class = 'CProductOrderItem'");
// ---------------------
CProductReference::$_load_lite = true;
$ref = new CProductReference();
$ref_where = array("product_reference.units_fixed = '0'");
// ---------------------
$references = $ref->loadList($ref_where, null, 50);
CAppUI::stepAjax("Correction de " . count($references) . " références");
// Chargement des CProductReference
foreach ($references as $_reference) {
    $_product = $_reference->loadRefProduct();
    //mbTrace($_product->_view, " ######################## ");
    $old_date = CMbDT::dateTime();
    $quantity_product = $_product->quantity;
    $quantity_reference = $_reference->orig_quantity;
    $price_reference = $_reference->orig_price;
    $logs = array();
    // LOG CProduct quantity
    $product_logs_quantity = $_product->loadLogsForField("quantity", true, null, true);
예제 #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('CProductOrderItem');
if (CValue::post("_create_order")) {
    $reference_id = CValue::post("reference_id");
    $reference = new CProductReference();
    $reference->reference_id = $reference_id;
    if (!$reference_id || !$reference->loadMatchingObject()) {
        CAppUI::setMsg("Impossible de créer l'article, la réference n'existe pas", UI_MSG_ERROR);
    }
    $where = array("product_order.societe_id" => "= '{$reference->societe_id}'", "product_order.object_class" => "IS NULL");
    $septic = null;
    $comments = null;
    // If a context is provided
    if ($context_guid = CValue::post("_context_guid")) {
        list($object_class, $object_id) = explode("-", $context_guid);
        $where["product_order.object_class"] = "= '{$object_class}'";
        $where["product_order.object_id"] = "= '{$object_id}'";
        if ($septic = CValue::post("septic")) {
            unset($_POST["context_guid"]);
            $where["product_order_item.septic"] = "= '{$septic}'";
        } else {