diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index bc647c31999..e33176bf391 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -46,7 +46,10 @@ require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; -if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php'; +if (! empty($conf->productbatch->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php'; + require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productstockentrepot.class.php'; +} if (! empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; @@ -597,16 +600,184 @@ if (empty($reshook)) } } + /* + * delete a line + */ elseif ($action == 'deleteline' && ! empty($line_id)) { $object->fetch($id); + $lines = $object->lines; $line = new ExpeditionLigne($db); - $line->id = $line_id; - $result = $line->delete($user); - if($result >= 0) { + + $num_prod = count($lines); + for ($i = 0 ; $i < $num_prod ; $i++) + { + if (count($lines[$i]->details_entrepot) > 1) + { + // delete multi warehouse lines + foreach ($lines[$i]->details_entrepot as $details_entrepot) { + $line->id = GETPOST("lineid".$details_entrepot->line_id); + if (!error && $line->delete($user) < 0) + { + $error++; + } + } + } + else if ($lines[$i] == $line_id) + { + // delete single warehouse line + $line->id = $line_id; + if (!error && $line->delete($user) < 0) + { + $error++; + } + } + } + + if(! $error) { header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id); exit(); } + else + { + setEventMessages($line->error, $line->errors, 'errors'); + } + } + + /* + * Update a line + */ + else if ($action == 'updateline' && $user->rights->expedition->creer && GETPOST('save')) + { + // Clean parameters + + $qty=0; + $entrepot_id = 0; + $batch_id = 0; + + $lines = $object->lines; + $num_prod = count($lines); + for ($i = 0 ; $i < $num_prod ; $i++) + { + if ($lines[$i]->id == $line_id) + { + // line to update + $line = new ExpeditionLigne($db); + + $line->fk_product = $lines[$i]->fk_product; + if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0) + { + // line with lot + foreach ($lines[$i]->detail_batch as $detail_batch) + { + $lotStock = new Productbatch($db); + $batch="batchl".$detail_batch->fk_expeditiondet."_".$detail_batch->fk_origin_stock; + $qty = "qtyl".$detail_batch->fk_expeditiondet.'_'.$detail_batch->id; + $batch_id = GETPOST($batch,'int'); + if (! empty($batch_id)) + { + if ($lotStock->fetch($batch_id) > 0) + { + $line->id = $detail_batch->fk_expeditiondet; + $line->detail_batch->fk_origin_stock = $batch_id; + $line->detail_batch->batch = $lotStock->batch; + $line->detail_batch->id = $detail_batch->id; + $line->entrepot_id = $lotStock->warehouseid; + $line->qty = GETPOST($qty, 'int'); + if ($line->update($user) < 0) { + setEventMessages($line->error, $line->errors, 'errors'); + $error++; + } + } + else + { + setEventMessages($lotStock->error, $lotStock->errors, 'errors'); + $error++; + } + } + } + } + else + { + // line without lot + if ($lines[$i]->entrepot_id > 0) + { + // single warehouse shipment line + $stockLocation="entl".$line_id; + $qty = "qtyl".$line_id; + $line->id = $line_id; + $line->entrepot_id = GETPOST($stockLocation,'int'); + $line->qty = GETPOST($qty, 'int'); + if ($line->update($user) < 0) { + setEventMessages($line->error, $line->errors, 'errors'); + $error++; + } + } + else if (count($lines[$i]->details_entrepot) > 1) + { + // multi warehouse shipment lines + foreach ($lines[$i]->details_entrepot as $detail_entrepot) + { + if (! $error) { + $stockLocation="entl".$detail_entrepot->line_id; + $qty = "qtyl".$detail_entrepot->line_id; + $warehouse = GETPOST($stockLocation,'int'); + if (!empty ($warehouse)) + { + $line->id = $detail_entrepot->line_id; + $line->entrepot_id = $warehouse; + $line->qty = GETPOST($qty, 'int'); + if ($line->update($user) < 0) { + setEventMessages($line->error, $line->errors, 'errors'); + $error++; + } + } + } + } + } + } + } + } + + // Extrafields Lines + $extrafieldsline = new ExtraFields($db); + $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline); + // Unset extrafield POST Data + if (is_array($extralabelsline)) { + foreach ($extralabelsline as $key => $value) { + unset($_POST["options_" . $key]); + } + } + + if (! $error) { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + // Define output language + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) + $newlang = GETPOST('lang_id','aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) + $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + + $ret = $object->fetch($object->id); // Reload to get new records + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + else + { + header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition + exit(); + } + } + + else if ($action == 'updateline' && $user->rights->expedition->creer && GETPOST('cancel','alpha') == $langs->trans('Cancel')) { + header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition + exit(); } include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; @@ -1743,6 +1914,15 @@ else if ($id || $ref) /* * Lines of products */ + if ($action == 'editline') + { + print '