FIX Creation of reception (missing extrafields). Lose data if error.
Conflicts: htdocs/reception/card.php
This commit is contained in:
parent
ab4941a558
commit
5a260865dc
@ -62,7 +62,7 @@ if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
|
||||
if (!empty($conf->productbatch->enabled)) $langs->load('productbatch');
|
||||
|
||||
$origin = GETPOST('origin', 'alpha') ?GETPOST('origin', 'alpha') : 'reception'; // Example: commande, propal
|
||||
$origin_id = GETPOST('id', 'int') ?GETPOST('id', 'int') : '';
|
||||
$origin_id = GETPOST('id', 'int') ? GETPOST('id', 'int') : '';
|
||||
$id = $origin_id;
|
||||
if (empty($origin_id)) $origin_id = GETPOST('origin_id', 'int'); // Id of order or propal
|
||||
if (empty($origin_id)) $origin_id = GETPOST('object_id', 'int'); // Id of order or propal
|
||||
@ -87,7 +87,7 @@ $action = GETPOST('action', 'alpha');
|
||||
if (GETPOST('modelselected')) {
|
||||
$action = 'presend';
|
||||
}
|
||||
$confirm = GETPOST('confirm', 'alpha');
|
||||
$confirm = GETPOST('confirm', 'alpha');
|
||||
$cancel = GETPOST('cancel', 'alpha');
|
||||
|
||||
//PDF
|
||||
@ -707,14 +707,13 @@ if ($action == 'create')
|
||||
if ($origin == 'supplierorder')$classname = 'CommandeFournisseur';
|
||||
else $classname = ucfirst($origin);
|
||||
|
||||
$object = new $classname($db);
|
||||
if ($object->fetch($origin_id)) // This include the fetch_lines
|
||||
{
|
||||
$objectsrc = new $classname($db);
|
||||
if ($objectsrc->fetch($origin_id)) { // This include the fetch_lines
|
||||
$soc = new Societe($db);
|
||||
$soc->fetch($object->socid);
|
||||
$soc->fetch($objectsrc->socid);
|
||||
|
||||
$author = new User($db);
|
||||
$author->fetch($object->user_author_id);
|
||||
$author->fetch($objectsrc->user_author_id);
|
||||
|
||||
if (!empty($conf->stock->enabled)) $entrepot = new Entrepot($db);
|
||||
|
||||
@ -722,10 +721,8 @@ if ($action == 'create')
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
print '<input type="hidden" name="origin" value="'.$origin.'">';
|
||||
print '<input type="hidden" name="origin_id" value="'.$object->id.'">';
|
||||
print '<input type="hidden" name="ref_int" value="'.$object->ref_int.'">';
|
||||
if (GETPOST('entrepot_id', 'int'))
|
||||
{
|
||||
print '<input type="hidden" name="origin_id" value="'.$objectsrc->id.'">';
|
||||
if (GETPOST('entrepot_id', 'int')) {
|
||||
print '<input type="hidden" name="entrepot_id" value="'.GETPOST('entrepot_id', 'int').'">';
|
||||
}
|
||||
|
||||
@ -735,13 +732,11 @@ if ($action == 'create')
|
||||
|
||||
// Ref
|
||||
print '<tr><td class="titlefieldcreate fieldrequired">';
|
||||
if ($origin == 'supplierorder' && !empty($conf->fournisseur->enabled))
|
||||
{
|
||||
print $langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/fourn/commande/card.php?id='.$object->id.'">'.img_object($langs->trans("ShowOrder"), 'order').' '.$object->ref;
|
||||
if ($origin == 'supplierorder' && ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled))) {
|
||||
print $langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/fourn/commande/card.php?id='.$objectsrc->id.'">'.img_object($langs->trans("ShowOrder"), 'order').' '.$objectsrc->ref;
|
||||
}
|
||||
if ($origin == 'propal' && !empty($conf->propal->enabled))
|
||||
{
|
||||
print $langs->trans("RefProposal").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/comm/card.php?id='.$object->id.'">'.img_object($langs->trans("ShowProposal"), 'propal').' '.$object->ref;
|
||||
if ($origin == 'propal' && !empty($conf->propal->enabled)) {
|
||||
print $langs->trans("RefProposal").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/comm/card.php?id='.$objectsrc->id.'">'.img_object($langs->trans("ShowProposal"), 'propal').' '.$objectsrc->ref;
|
||||
}
|
||||
print '</a></td>';
|
||||
print "</tr>\n";
|
||||
@ -751,7 +746,7 @@ if ($action == 'create')
|
||||
if ($origin == 'supplier_order') print $langs->trans('SupplierOrder');
|
||||
else print $langs->trans('RefSupplier');
|
||||
print '</td><td colspan="3">';
|
||||
print '<input type="text" name="ref_supplier" value="'.$object->ref_supplier.'" />';
|
||||
print '<input type="text" name="ref_supplier" value="'.$objectsrc->ref_supplier.'" />';
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
@ -764,8 +759,12 @@ if ($action == 'create')
|
||||
if (!empty($conf->projet->enabled))
|
||||
{
|
||||
$projectid = GETPOST('projectid', 'int') ?GETPOST('projectid', 'int') : 0;
|
||||
if (empty($projectid) && !empty($object->fk_project)) $projectid = $object->fk_project;
|
||||
if ($origin == 'project') $projectid = ($originid ? $originid : 0);
|
||||
if (empty($projectid) && !empty($objectsrc->fk_project)) {
|
||||
$projectid = $objectsrc->fk_project;
|
||||
}
|
||||
if ($origin == 'project') {
|
||||
$projectid = ($originid ? $originid : 0);
|
||||
}
|
||||
|
||||
$langs->load("projects");
|
||||
print '<tr>';
|
||||
@ -779,7 +778,7 @@ if ($action == 'create')
|
||||
// Date delivery planned
|
||||
print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
|
||||
print '<td colspan="3">';
|
||||
$date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date); // $date_delivery comes from GETPOST
|
||||
$date_delivery = ($date_delivery ? $date_delivery : $objectsrc->delivery_date); // $date_delivery comes from GETPOST
|
||||
print $form->selectDate($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1);
|
||||
print "</td>\n";
|
||||
print '</tr>';
|
||||
@ -787,16 +786,15 @@ if ($action == 'create')
|
||||
// Note Public
|
||||
print '<tr><td>'.$langs->trans("NotePublic").'</td>';
|
||||
print '<td colspan="3">';
|
||||
$doleditor = new DolEditor('note_public', $object->note_public, '', 60, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
|
||||
$doleditor = new DolEditor('note_public', $objectsrc->note_public, '', 60, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%');
|
||||
print $doleditor->Create(1);
|
||||
print "</td></tr>";
|
||||
|
||||
// Note Private
|
||||
if ($object->note_private && !$user->socid)
|
||||
{
|
||||
if ($objectsrc->note_private && !$user->socid) {
|
||||
print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
|
||||
print '<td colspan="3">';
|
||||
$doleditor = new DolEditor('note_private', $object->note_private, '', 60, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
|
||||
$doleditor = new DolEditor('note_private', $objectsrc->note_private, '', 60, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%');
|
||||
print $doleditor->Create(1);
|
||||
print "</td></tr>";
|
||||
}
|
||||
@ -837,15 +835,15 @@ if ($action == 'create')
|
||||
|
||||
// Other attributes
|
||||
$parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'cols' => '3', 'socid'=>$socid);
|
||||
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $recept, $action); // Note that $action and $object may have been modified by hook
|
||||
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $recept, $action); // Note that $action and $objectsrc may have been modified by hook
|
||||
print $hookmanager->resPrint;
|
||||
|
||||
// Here $object can be of an object Order
|
||||
// Here $object can be of an object Reception
|
||||
$extrafields->fetch_name_optionals_label($object->table_element);
|
||||
if (empty($reshook) && !empty($extrafields->attributes[$object->table_element]['label'])) {
|
||||
// copy from order
|
||||
if ($object->fetch_optionals() > 0) {
|
||||
$recept->array_options = array_merge($recept->array_options, $object->array_options);
|
||||
if ($objectsrc->fetch_optionals() > 0) {
|
||||
$recept->array_options = array_merge($recept->array_options, $objectsrc->array_options);
|
||||
}
|
||||
print $object->showOptionals($extrafields, 'edit', $parameters);
|
||||
}
|
||||
@ -854,9 +852,9 @@ if ($action == 'create')
|
||||
if (!empty($conf->incoterm->enabled))
|
||||
{
|
||||
print '<tr>';
|
||||
print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $object->label_incoterms, 1).'</label></td>';
|
||||
print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $objectsrc->label_incoterms, 1).'</label></td>';
|
||||
print '<td colspan="3" class="maxwidthonsmartphone">';
|
||||
print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
|
||||
print $form->select_incoterms((!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : ''), (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : ''));
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
@ -876,15 +874,15 @@ if ($action == 'create')
|
||||
|
||||
print dol_get_fiche_end();
|
||||
|
||||
|
||||
// Reception lines
|
||||
$numAsked = 0;
|
||||
$dispatchLines = array();
|
||||
foreach ($_POST as $key => $value)
|
||||
{
|
||||
foreach ($_POST as $key => $value) {
|
||||
// If create form is coming from the button "Create Reception" of previous page
|
||||
|
||||
// without batch module enabled
|
||||
if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg))
|
||||
{
|
||||
$reg = array();
|
||||
if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
|
||||
$numAsked++;
|
||||
|
||||
// $numline=$reg[2] + 1; // line of product
|
||||
@ -915,6 +913,25 @@ if ($action == 'create')
|
||||
$fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2];
|
||||
$dispatchLines[$numAsked] = array('prod' => GETPOST($prod, 'int'), 'qty' =>GETPOST($qty), 'ent' =>GETPOST($ent, 'int'), 'pu' =>GETPOST($pu), 'comment' =>GETPOST('comment'), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'), 'DLC'=> $dDLC, 'DLUO'=> $dDLUO, 'lot'=> GETPOST($lot, 'alpha'));
|
||||
}
|
||||
|
||||
// If create form is coming from same page post was sent but an error occured
|
||||
if (preg_match('/^productid([0-9]+)$/i', $key, $reg)) {
|
||||
$numAsked++;
|
||||
|
||||
// eat-by date dispatch
|
||||
// $numline=$reg[2] + 1; // line of product
|
||||
$numline = $numAsked;
|
||||
$prod = 'productid'.$reg[1];
|
||||
$comment = 'comment'.$reg[1];
|
||||
$qty = 'qtyl'.$reg[1];
|
||||
$ent = 'entl'.$reg[1];
|
||||
$pu = 'pul'.$reg[1];
|
||||
$lot = 'batch'.$reg[1];
|
||||
$dDLUO = dol_mktime(12, 0, 0, GETPOST('dluo'.$reg[1].'month', 'int'), GETPOST('dluo'.$reg[1].'day', 'int'), GETPOST('dluo'.$reg[1].'year', 'int'));
|
||||
$dDLC = dol_mktime(12, 0, 0, GETPOST('dlc'.$reg[1].'month', 'int'), GETPOST('dlc'.$reg[1].'day', 'int'), GETPOST('dlc'.$reg[1].'year', 'int'));
|
||||
$fk_commandefourndet = 'fk_commandefournisseurdet'.$reg[1];
|
||||
$dispatchLines[$numAsked] = array('prod' => GETPOST($prod, 'int'), 'qty' =>GETPOST($qty), 'ent' =>GETPOST($ent, 'int'), 'pu' =>GETPOST($pu), 'comment' =>GETPOST($comment), 'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'), 'DLC'=> $dDLC, 'DLUO'=> $dDLUO, 'lot'=> GETPOST($lot, 'alpha'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -944,7 +961,7 @@ if ($action == 'create')
|
||||
print '<table class="noborder centpercent">';
|
||||
|
||||
// Load receptions already done for same order
|
||||
$object->loadReceptions();
|
||||
$objectsrc->loadReceptions();
|
||||
|
||||
if ($numAsked)
|
||||
{
|
||||
@ -980,14 +997,13 @@ if ($action == 'create')
|
||||
while ($indiceAsked <= $numAsked)
|
||||
{
|
||||
$product = new Product($db);
|
||||
foreach ($object->lines as $supplierLine) {
|
||||
foreach ($objectsrc->lines as $supplierLine) {
|
||||
if ($dispatchLines[$indiceAsked]['fk_commandefourndet'] == $supplierLine->id) {
|
||||
$line = $supplierLine;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Show product and description
|
||||
$type = $line->product_type ? $line->product_type : $line->fk_product_type;
|
||||
// Try to enhance type detection using date_start and date_end for free lines where type
|
||||
@ -995,7 +1011,7 @@ if ($action == 'create')
|
||||
if (!empty($line->date_start)) $type = 1;
|
||||
if (!empty($line->date_end)) $type = 1;
|
||||
|
||||
print '<!-- line '.$line->rowid.' for product -->'."\n";
|
||||
print '<!-- line fk_commandefourndet='.$line->id.' for product='.$line->fk_product.' -->'."\n";
|
||||
print '<tr class="oddeven">'."\n";
|
||||
|
||||
|
||||
@ -1008,6 +1024,7 @@ if ($action == 'create')
|
||||
|
||||
print '<td>';
|
||||
print '<a name="'.$line->id.'"></a>'; // ancre pour retourner sur la ligne
|
||||
print '<input type="hidden" name="productid'.$indiceAsked.'" value="'.$line->fk_product.'">';
|
||||
|
||||
// Show product and description
|
||||
$product_static->type = $line->fk_product_type;
|
||||
@ -1049,17 +1066,15 @@ if ($action == 'create')
|
||||
|
||||
// Qty
|
||||
print '<td class="center">'.$line->qty;
|
||||
print '<input type="hidden" name="fk_commandefournisseurdet'.$indiceAsked.'" value=\''.$line->id.'\' />';
|
||||
print '<textarea style="display:none;" name="comment'.$indiceAsked.'" >'.$line->desc.'</textarea>';
|
||||
print '<input type="hidden" name="fk_commandefournisseurdet'.$indiceAsked.'" value="'.$line->id.'">';
|
||||
print '<input type="hidden" name="pul'.$indiceAsked.'" value="'.$line->pu_ht.'">';
|
||||
print '<input name="qtyasked'.$indiceAsked.'" id="qtyasked'.$indiceAsked.'" type="hidden" value="'.$line->qty.'">';
|
||||
print '</td>';
|
||||
$qtyProdCom = $line->qty;
|
||||
|
||||
// Qty already received
|
||||
print '<td class="center">';
|
||||
|
||||
|
||||
$quantityDelivered = $object->receptions[$line->id];
|
||||
$quantityDelivered = $objectsrc->receptions[$line->id];
|
||||
print $quantityDelivered;
|
||||
print '<input name="qtydelivered'.$indiceAsked.'" id="qtydelivered'.$indiceAsked.'" type="hidden" value="'.$quantityDelivered.'">';
|
||||
print '</td>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user