コード例 #1
0
 /**
  *	Load an object from its id and create a new one in database
  *
  *	@param	int		$fromid     Id of object to clone
  * 	@return	int					New id of clone
  */
 function createFromClone($fromid)
 {
     global $user, $langs;
     $error = 0;
     $object = new Productbatch($this->db);
     $object->context['createfromclone'] = 'createfromclone';
     $this->db->begin();
     // Load source object
     $object->fetch($fromid);
     $object->id = 0;
     $object->statut = 0;
     // Clear fields
     // ...
     // Create clone
     $result = $object->create($user);
     // Other options
     if ($result < 0) {
         $this->error = $object->error;
         $error++;
     }
     if (!$error) {
     }
     unset($object->context['createfromclone']);
     // End
     if (!$error) {
         $this->db->commit();
         return $object->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
コード例 #2
0
ファイル: expedition.class.php プロジェクト: Albertopf/prueba
 /**
  * Add a shipment line with batch record
  *
  * @param 	array		$dbatch		Array of value (key 'detail' -> Array, key 'qty' total quantity for line, key ix_l : original line index)
  * @param	array		$array_options		extrafields array
  * @return	int						<0 if KO, >0 if OK
  */
 function addline_batch($dbatch, $array_options = 0)
 {
     global $conf, $langs;
     $num = count($this->lines);
     if ($dbatch['qty'] > 0) {
         $line = new ExpeditionLigne($this->db);
         $tab = array();
         foreach ($dbatch['detail'] as $key => $value) {
             if ($value['q'] > 0) {
                 // $value['q']=qty to move
                 // $value['id_batch']=id into llx_product_batch of record to move
                 //var_dump($value);
                 $linebatch = new ExpeditionLineBatch($this->db);
                 $ret = $linebatch->fetchFromStock($value['id_batch']);
                 // load serial, sellby, eatby
                 if ($ret < 0) {
                     $this->error = $linebatch->error;
                     return -1;
                 }
                 $linebatch->dluo_qty = $value['q'];
                 $tab[] = $linebatch;
                 if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) {
                     require_once DOL_DOCUMENT_ROOT . '/product/class/productbatch.class.php';
                     $prod_batch = new Productbatch($this->db);
                     $prod_batch->fetch($value['id_batch']);
                     if ($prod_batch->qty < $linebatch->dluo_qty) {
                         $this->errors[] = $langs->trans('ErrorStockIsNotEnough');
                         dol_syslog(get_class($this) . "::addline_batch error=Product " . $prod_batch->batch . ": " . $this->errorsToString(), LOG_ERR);
                         $this->db->rollback();
                         return -1;
                     }
                 }
                 //var_dump($linebatch);
             }
         }
         $line->entrepot_id = $linebatch->entrepot_id;
         $line->origin_line_id = $dbatch['ix_l'];
         $line->qty = $dbatch['qty'];
         $line->detail_batch = $tab;
         // extrafields
         if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) {
             // For avoid conflicts if trigger used
             $line->array_options = $array_options;
         }
         //var_dump($line);
         $this->lines[$num] = $line;
         return 1;
     }
 }
コード例 #3
0
ファイル: product.php プロジェクト: TAASA/Dolibarr-ERP-3.8.1
                    exit;
                } else {
                    header("Location: product.php?id=" . $product->id);
                    exit;
                }
            } else {
                setEventMessages($product->error, $product->errors, 'errors');
                $db->rollback();
                $action = 'transfert';
            }
        }
    }
}
// Update batch information
if ($action == 'updateline' && GETPOST('save') == $langs->trans('Save')) {
    $pdluo = new Productbatch($db);
    $result = $pdluo->fetch(GETPOST('pdluoid', 'int'));
    if ($result > 0) {
        if ($pdluo->id) {
            if (!GETPOST("sellby") && !GETPOST("eatby") && !GETPOST("batch_number")) {
                setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("atleast1batchfield")), 'errors');
            } else {
                $d_eatby = dol_mktime(12, 0, 0, $_POST['eatbymonth'], $_POST['eatbyday'], $_POST['eatbyyear']);
                $d_sellby = dol_mktime(12, 0, 0, $_POST['sellbymonth'], $_POST['sellbyday'], $_POST['sellbyyear']);
                $pdluo->batch = GETPOST("batch_number", 'san_alpha');
                $pdluo->eatby = $d_eatby;
                $pdluo->sellby = $d_sellby;
                $result = $pdluo->update($user);
                if ($result < 0) {
                    setEventMessages($pdluo->error, $pdluo->errors, 'errors');
                }
コード例 #4
0
 /**
  *    Load information about stock of a product into stock_reel, stock_warehouse[] (including stock_warehouse[idwarehouse]->detail_batch for batch products)
  *
  *    @return     	int             < 0 if KO, > 0 if OK
  *    @see			load_virtual_stock, getBatchInfo
  */
 function load_stock()
 {
     $this->stock_reel = 0;
     $this->stock_warehouse = array();
     $sql = "SELECT ps.reel, ps.fk_entrepot, ps.pmp, ps.rowid";
     $sql .= " FROM " . MAIN_DB_PREFIX . "product_stock as ps";
     $sql .= ", " . MAIN_DB_PREFIX . "entrepot as w";
     $sql .= " WHERE w.entity IN (" . getEntity('stock', 1) . ")";
     $sql .= " AND w.rowid = ps.fk_entrepot";
     $sql .= " AND ps.fk_product = " . $this->id;
     dol_syslog(get_class($this) . "::load_stock", LOG_DEBUG);
     $result = $this->db->query($sql);
     if ($result) {
         $num = $this->db->num_rows($result);
         $i = 0;
         if ($num > 0) {
             while ($i < $num) {
                 $row = $this->db->fetch_object($result);
                 $this->stock_warehouse[$row->fk_entrepot] = new stdClass();
                 $this->stock_warehouse[$row->fk_entrepot]->real = $row->reel;
                 $this->stock_warehouse[$row->fk_entrepot]->pmp = $row->pmp;
                 $this->stock_warehouse[$row->fk_entrepot]->id = $row->rowid;
                 if ($this->hasbatch()) {
                     $this->stock_warehouse[$row->fk_entrepot]->detail_batch = Productbatch::findAll($this->db, $row->rowid, 1);
                 }
                 $this->stock_reel += $row->reel;
                 $i++;
             }
         }
         $this->db->free($result);
         $this->load_virtual_stock();
         // This also load stats_commande_fournisseur, ...
         return 1;
     } else {
         $this->error = $this->db->lasterror();
         return -1;
     }
 }
コード例 #5
0
 * $backtopage
 */
?>

<!-- BEGIN PHP TEMPLATE STOCKCORRECTION.TPL.PHP -->
<?php 
$productref = '';
if ($object->element == 'product') {
    $productref = $object->ref;
}
$langs->load("productbatch");
if (empty($id)) {
    $id = $object->id;
}
$pdluoid = GETPOST('pdluoid', 'int');
$pdluo = new Productbatch($db);
if ($pdluoid > 0) {
    $result = $pdluo->fetch($pdluoid);
    if ($result > 0) {
        $pdluoid = $pdluo->id;
    } else {
        dol_print_error($db, $pdluo->error, $pdluo->errors);
    }
}
print load_fiche_titre($langs->trans("StockTransfer"), '', 'title_generic.png');
print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $id . '" method="post">' . "\n";
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="transfert_stock">';
print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
if ($pdluoid) {
    print '<input type="hidden" name="pdluoid" value="' . $pdluoid . '">';
コード例 #6
0
            print price(price2num($product->price * $obj->reel, 'MT'), 1) . '</td>';
        } else {
            print $langs->trans("Variable");
        }
        print '</tr>';
        $total += $obj->reel;
        if (price2num($obj->pmp)) {
            $totalwithpmp += $obj->reel;
        }
        $totalvalue = $totalvalue + price2num($obj->pmp * $obj->reel, 'MU');
        // Ditto : Show PMP from movement or from product
        $totalvaluesell = $totalvaluesell + price2num($product->price * $obj->reel, 'MU');
        // Ditto : Show PMP from movement or from product
        //Batch Detail
        if (!empty($conf->productbatch->enabled) && $product->hasbatch()) {
            $details = Productbatch::findAll($db, $obj->product_stock_id);
            if ($details < 0) {
                dol_print_error($db);
            }
            foreach ($details as $pdluo) {
                print "\n" . '<tr><td width="10%"></td><td width="10%" align="right">' . dol_print_date($pdluo->eatby, 'day') . '</td>';
                print '<td align="right" width="10%">' . dol_print_date($pdluo->sellby, 'day') . '</td>';
                print '<td align="right" width="10%">' . $pdluo->batch . '</td>';
                print '<td align="right" width="10%">' . $pdluo->qty . ($pdluo->qty < 0 ? ' ' . img_warning() : '') . '</td>';
                print '<td colspan="4" width="50%"></td></tr>';
            }
        }
        $i++;
        $var = !$var;
    }
} else {
コード例 #7
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;
 }
コード例 #8
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;
     }
 }