コード例 #1
0
 * @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();
    }
}
$stock->updateFormFields();
// Loads the required Category and the complete list
$category = new CProductCategory();
$list_categories = $category->loadList(null, 'name');
コード例 #2
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();
                 }
             }
         }
     }
 }