/** * 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; } }
} 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'); } }
/** * 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; } }
?> <!-- 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 . '">'; } print '<table class="border" width="100%">';
/** * 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; }
/** * 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; } }