コード例 #1
0
 /**
  * Create or update batch record (update table llx_product_batch)
  *
  * @param	array|int	$dluo	Could be either 
  *                              - int if id of product_batch
  *                              - or complete array('fk_product_stock'=>, 'eatby'=>, 'sellby'=> , 'batchnumber'=>)
  * @param	int			$qty	Quantity of product with batch number. May be a negative amount.
  * @return 	int   				<0 if KO, else return productbatch id
  */
 function _create_batch($dluo, $qty)
 {
     $pdluo = new Productbatch($this->db);
     $result = 0;
     // Try to find an existing record with same batch number or id
     if (is_numeric($dluo)) {
         $result = $pdluo->fetch($dluo);
         if (empty($pdluo->id)) {
             // We didn't find the line. May be it was deleted before by a previous move in same transaction.
             $this->error = 'Error. You ask a move on a record for a serial that does not exists anymore. May be you take the same serial on samewarehouse several times in same shipment or it was used by another shipment. Remove this shipment and prepare another one.';
             $this->errors[] = $this->error;
             $result = -2;
         }
     } else {
         if (is_array($dluo)) {
             if (isset($dluo['fk_product_stock'])) {
                 $vfk_product_stock = $dluo['fk_product_stock'];
                 $veatby = $dluo['eatby'];
                 $vsellby = $dluo['sellby'];
                 $vbatchnumber = $dluo['batchnumber'];
                 $result = $pdluo->find($vfk_product_stock, $veatby, $vsellby, $vbatchnumber);
             } else {
                 dol_syslog(get_class($this) . "::_create_batch array param dluo must contain at least key fk_product_stock" . $error, LOG_ERR);
                 $result = -1;
             }
         } else {
             dol_syslog(get_class($this) . "::_create_batch error invalid param dluo" . $error, LOG_ERR);
             $result = -1;
         }
     }
     if ($result >= 0) {
         // No error
         if ($pdluo->id > 0) {
             //print "Avant ".$pdluo->qty." Apres ".($pdluo->qty + $qty)."<br>";
             $pdluo->qty += $qty;
             if ($pdluo->qty == 0) {
                 $result = $pdluo->delete(0, 1);
             } else {
                 $result = $pdluo->update(0, 1);
             }
         } else {
             $pdluo->fk_product_stock = $vfk_product_stock;
             $pdluo->qty = $qty;
             $pdluo->eatby = $veatby;
             $pdluo->sellby = $vsellby;
             $pdluo->batch = $vbatchnumber;
             $result = $pdluo->create(0, 1);
             if ($result < 0) {
                 $this->error = $pdluo->error;
                 $this->errors = $pdluo->errors;
             }
         }
     }
     return $result;
 }
コード例 #2
0
 /**
  * Create or update batch record
  *
  * @param	variant		$dluo	Could be either int if id of product_batch or array with at leat fk_product_stock
  * @param	int			$qty	Quantity of product with batch number
  * @return 	int   				<0 if KO, else return productbatch id
  */
 function _create_batch($dluo, $qty)
 {
     $pdluo = new Productbatch($this->db);
     //Try to find an existing record with batch same batch number or id
     if (is_numeric($dluo)) {
         $result = $pdluo->fetch($dluo);
     } else {
         if (is_array($dluo)) {
             if (isset($dluo['fk_product_stock'])) {
                 $vfk_product_stock = $dluo['fk_product_stock'];
                 $veatby = $dluo['eatby'];
                 $vsellby = $dluo['sellby'];
                 $vbatchnumber = $dluo['batchnumber'];
                 $result = $pdluo->find($vfk_product_stock, $veatby, $vsellby, $vbatchnumber);
             } else {
                 dol_syslog(get_class($this) . "::_create_batch array param dluo must contain at least key fk_product_stock" . $error, LOG_ERR);
                 $result = -1;
             }
         } else {
             dol_syslog(get_class($this) . "::_create_batch error invalid param dluo" . $error, LOG_ERR);
             $result = -1;
         }
     }
     //batch record found so we update it
     if ($result > 0) {
         if ($pdluo->id > 0) {
             $pdluo->qty += $qty;
             if ($pdluo->qty == 0) {
                 $result = $pdluo->delete(0, 1);
             } else {
                 $result = $pdluo->update(0, 1);
             }
         } else {
             $pdluo->fk_product_stock = $vfk_product_stock;
             $pdluo->qty = $qty;
             $pdluo->eatby = $veatby;
             $pdluo->sellby = $vsellby;
             $pdluo->batch = $vbatchnumber;
             $result = $pdluo->create(0, 1);
         }
         return $result;
     } else {
         return -1;
     }
 }