コード例 #1
0
ファイル: product.class.php プロジェクト: nrjacker4/crm-php
	/**
	 *  Adjust stock in a warehouse for product
	 *
	 *  @param  	User	$user           user asking change
	 *  @param  	int		$id_entrepot    id of warehouse
	 *  @param  	double	$nbpiece        nb of units
	 *  @param  	int		$movement       0 = add, 1 = remove
	 * 	@param		string	$label			Label of stock movement
	 * 	@param		double	$price			Price to use for stock eval
	 * 	@return     int     				<0 if KO, >0 if OK
	 */
	function correct_stock($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0)
	{
		if ($id_entrepot)
		{
			$this->db->begin();

			require_once(DOL_DOCUMENT_ROOT ."/product/stock/class/mouvementstock.class.php");

			$op[0] = "+".trim($nbpiece);
			$op[1] = "-".trim($nbpiece);

			$movementstock=new MouvementStock($this->db);
			$result=$movementstock->_create($user,$this->id,$id_entrepot,$op[$movement],$movement,$price,'',$label);

			if ($result >= 0)
			{
				$this->db->commit();
				return 1;
			}
			else
			{
				dol_print_error($this->db);
				$this->db->rollback();
				return -1;
			}
		}
	}
コード例 #2
0
 /**
  *  Adjust stock in a warehouse for product with batch number
  *
  *  @param  	User	$user           user asking change
  *  @param  	int		$id_entrepot    id of warehouse
  *  @param  	double	$nbpiece        nb of units
  *  @param  	int		$movement       0 = add, 1 = remove
  * 	@param		string	$label			Label of stock movement
  * 	@param		double	$price			Price to use for stock eval
  * 	@param		date	$dlc			eat-by date
  * 	@param		date	$dluo			sell-by date
  * 	@param		string	$lot			Lot number
  *  @param		string	$inventorycode	Inventory code
  * 	@return     int     				<0 if KO, >0 if OK
  */
 function correct_stock_batch($user, $id_entrepot, $nbpiece, $movement, $label = '', $price = 0, $dlc = '', $dluo = '', $lot = '', $inventorycode = '')
 {
     if ($id_entrepot) {
         $this->db->begin();
         require_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php';
         $op[0] = "+" . trim($nbpiece);
         $op[1] = "-" . trim($nbpiece);
         $movementstock = new MouvementStock($this->db);
         $result = $movementstock->_create($user, $this->id, $id_entrepot, $op[$movement], $movement, $price, $label, $inventorycode, '', $dlc, $dluo, $lot);
         if ($result >= 0) {
             $this->db->commit();
             return 1;
         } else {
             $this->error = $movementstock->error;
             $this->errors = $movementstock->errors;
             $this->db->rollback();
             return -1;
         }
     }
 }
コード例 #3
0
 /**
  * testMouvementCreate
  *
  * @return	int
  */
 public function testMouvementCreate()
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     // We create a product for tests
     $product1 = new Product($db);
     $product1->initAsSpecimen();
     $product1->ref .= ' 1';
     $product1->label .= ' 1';
     $product1id = $product1->create($user);
     $product2 = new Product($db);
     $product2->initAsSpecimen();
     $product2->ref .= ' 2';
     $product2->label .= ' 2';
     $product2id = $product2->create($user);
     // We create a product for tests
     $warehouse1 = new Entrepot($db);
     $warehouse1->initAsSpecimen();
     $warehouse1->libelle .= ' 1';
     $warehouse1->description .= ' 1';
     $warehouse1id = $warehouse1->create($user);
     $warehouse2 = new Entrepot($db);
     $warehouse2->initAsSpecimen();
     $warehouse2->libelle .= ' 2';
     $warehouse2->description .= ' 2';
     $warehouse2id = $warehouse2->create($user);
     $localobject = new MouvementStock($this->savdb);
     // Do a list of movement into warehouse 1
     // Create an input movement (type = 3) of price 9.9 -> shoul dupdate PMP to 9.9
     $result = $localobject->_create($user, $product1id, $warehouse1id, 10, 3, 9.9, 'Movement for unit test 1', 'Inventory Code Test');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an input movement (type = 3) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse1id, 10, 3, 9.699999999999999, 'Movement for unit test 2', 'Inventory Code Test');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an output movement (type = 2) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse1id, -5, 2, 999, 'Movement for unit test 3', 'Inventory Code Test');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse1id, 1, 0, 0, 'Input from transfer', 'Transfert X');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse1id, -2, 1, 0, 'Output from transfer', 'Transfert Y');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Do same but into warehouse 2
     // Create an input movement (type = 3) of price 9.9 -> shoul dupdate PMP to 9.9
     $result = $localobject->_create($user, $product1id, $warehouse2id, 10, 3, 9.9, 'Movement for unit test 1 wh 2', 'Inventory Code Test 2');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an input movement (type = 3) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse2id, 10, 3, 9.699999999999999, 'Movement for unit test 2 wh 2', 'Inventory Code Test 2');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an output movement (type = 2) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse2id, -5, 2, 999, 'Movement for unit test 3 wh 2', 'Inventory Code Test 2');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse2id, 1, 0, 0, 'Input from transfer wh 2', 'Transfert X 2');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     // Create an output movement (type = 1) of price 9.7 -> shoul dupdate PMP to 9.9/9.7 = 9.8
     $result = $localobject->_create($user, $product1id, $warehouse2id, -2, 1, 0, 'Output from transfer wh 2', 'Transfert Y 2');
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     return $localobject;
 }