From dc4a28cd0be10ad8356dd9baa64e002d80fbd3d7 Mon Sep 17 00:00:00 2001 From: sonikf <93765174+sonikf@users.noreply.github.com> Date: Thu, 6 Nov 2025 18:09:36 +0200 Subject: [PATCH] NEW Add option to create standalone reception (#36134) * Enable create menu for standalone reception * Enable create menu for standalone reception * Add Reception date * Add option to create standalone reception * fix pre-commit --- htdocs/core/menus/init_menu_auguria.sql | 2 +- htdocs/core/menus/standard/eldy.lib.php | 2 +- htdocs/langs/en_US/receptions.lang | 2 + htdocs/reception/card.php | 2080 +++++++++++++++-------- 4 files changed, 1362 insertions(+), 724 deletions(-) diff --git a/htdocs/core/menus/init_menu_auguria.sql b/htdocs/core/menus/init_menu_auguria.sql index ad0bbe330d3..532a3de62e0 100644 --- a/htdocs/core/menus/init_menu_auguria.sql +++ b/htdocs/core/menus/init_menu_auguria.sql @@ -140,7 +140,7 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left -- Product - Reception insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', 'isModEnabled("reception")', __HANDLER__, 'left', 1350__+MAX_llx_menu__, 'commercial', 'receptions', 3__+MAX_llx_menu__, '/reception/index.php?mainmenu=commercial&leftmenu=receptions', 'Receptions', 0, 'receptions', '$user->rights->reception->lire', '', 2, 6, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', 'isModEnabled("reception") && $leftmenu=="receptions"', __HANDLER__, 'left', 1351__+MAX_llx_menu__, 'commercial', '', 1350__+MAX_llx_menu__, '/reception/card.php?mainmenu=commercial&action=create2&leftmenu=receptions', 'NewSending', 1, 'receptions', '$user->rights->reception->creer', '', 2, 0, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', 'isModEnabled("reception") && $leftmenu=="receptions"', __HANDLER__, 'left', 1351__+MAX_llx_menu__, 'commercial', '', 1350__+MAX_llx_menu__, '/reception/card.php?mainmenu=commercial&action=create&leftmenu=receptions', 'NewSending', 1, 'receptions', '$user->rights->reception->creer', '', 2, 0, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', 'isModEnabled("reception") && $leftmenu=="receptions"', __HANDLER__, 'left', 1352__+MAX_llx_menu__, 'commercial', '', 1350__+MAX_llx_menu__, '/reception/list.php?mainmenu=commercial&leftmenu=receptions', 'List', 1, 'receptions', '$user->rights->reception->lire', '', 2, 1, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', 'isModEnabled("reception") && $leftmenu=="receptions"', __HANDLER__, 'left', 1353__+MAX_llx_menu__, 'commercial', '', 1350__+MAX_llx_menu__, '/reception/stats/index.php?mainmenu=commercial&leftmenu=receptions', 'Statistics', 1, 'receptions', '$user->rights->reception->lire', '', 2, 2, __ENTITY__); diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index e130120c719..76b1269beb6 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -2302,7 +2302,7 @@ function get_left_menu_products($mainmenu, &$newmenu, $usemenuhider = 1, $leftme if (isModEnabled('reception')) { $langs->load("receptions"); $newmenu->add("/reception/index.php?leftmenu=receptions", $langs->trans("Receptions"), 0, $user->hasRight('reception', 'lire'), '', $mainmenu, 'receptions', 0, '', '', '', img_picto('', 'dollyrevert', 'class="pictofixedwidth", style="text-align: right;"')); - $newmenu->add("/reception/card.php?action=create2&leftmenu=receptions", $langs->trans("NewReception"), 1, $user->hasRight('reception', 'creer')); + $newmenu->add("/reception/card.php?action=create&leftmenu=receptions", $langs->trans("NewReception"), 1, $user->hasRight('reception', 'creer')); $newmenu->add("/reception/list.php?leftmenu=receptions", $langs->trans("List"), 1, $user->hasRight('reception', 'lire')); if ($usemenuhider || empty($leftmenu) || $leftmenu == "receptions") { $newmenu->add("/reception/list.php?leftmenu=receptions&search_status=0", $langs->trans("StatusReceptionDraftShort"), 2, $user->hasRight('reception', 'lire')); diff --git a/htdocs/langs/en_US/receptions.lang b/htdocs/langs/en_US/receptions.lang index f6f3eff2781..701710c0e51 100644 --- a/htdocs/langs/en_US/receptions.lang +++ b/htdocs/langs/en_US/receptions.lang @@ -57,3 +57,5 @@ ReceptionMustBeInTheSameCurrencyThanOther=Reception have to be int the same curr AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation=Automatic validation is not possible when stock is decreased on invoice validation ReceptionSentByEMail=Reception sent by email ReceptionValidated=Reception validated +DateReception=Reception date +SetReceptionDate=Set reception date diff --git a/htdocs/reception/card.php b/htdocs/reception/card.php index 7e59c67bb3e..39fb2f5f5c5 100644 --- a/htdocs/reception/card.php +++ b/htdocs/reception/card.php @@ -14,6 +14,7 @@ * Copyright (C) 2018 Quentin Vial-Gouteyron * Copyright (C) 2024-2025 MDW * Copyright (C) 2024-2025 Frédéric France + * Copyright (C) 2025 Nick Fragoulis * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,6 +40,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php'; @@ -67,6 +69,7 @@ if (isModEnabled('project')) { * @var Conf $conf * @var DoliDB $db * @var HookManager $hookmanager + * @var Societe $mysoc * @var Translate $langs * @var User $user */ @@ -80,22 +83,22 @@ if (isModEnabled('productbatch')) { $langs->load('productbatch'); } -$origin = GETPOST('origin', 'alpha') ? GETPOST('origin', 'alpha') : 'reception'; // Example: commande, propal -$origin_id = GETPOSTINT('id') ? GETPOSTINT('id') : ''; -$id = $origin_id; -if (empty($origin_id)) { +$origin = GETPOST('origin', 'alpha'); // Example: commande, propal +$origin_id = GETPOSTINT('origin_id') ? GETPOSTINT('id') : ''; +$id = GETPOSTINT('id'); +if (empty($origin_id) && !empty($origin)) { $origin_id = GETPOSTINT('origin_id'); // Id of order or propal } -if (empty($origin_id)) { +if (empty($origin_id) && !empty($origin)) { $origin_id = GETPOSTINT('object_id'); // Id of order or propal } -if (empty($origin_id)) { +if (empty($origin_id) && !empty($origin)) { $origin_id = GETPOSTINT('originid'); // Id of order or propal } $ref = GETPOST('ref', 'alpha'); $line_id = GETPOSTINT('lineid') ? GETPOSTINT('lineid') : 0; $facid = GETPOSTINT('facid'); - +$socid = GETPOSTINT('socid'); $action = GETPOST('action', 'alpha'); //Select mail models is same action as presend if (GETPOST('modelselected')) { @@ -106,6 +109,14 @@ $cancel = GETPOST('cancel', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha'); $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); +$contactid = GETPOSTINT('contactid'); +$projectid = GETPOSTINT('projectid'); + + +$cancel = GETPOST('cancel', 'alpha'); +$rank = (GETPOSTINT('rank') > 0) ? GETPOSTINT('rank') : -1; +$lineid = GETPOSTINT('lineid'); +$backtopage = GETPOST('backtopage', 'alpha'); //PDF $hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0)); $hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0)); @@ -127,32 +138,14 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'inclu $hookmanager->initHooks(array('receptioncard', 'globalcard')); $date_delivery = dol_mktime(GETPOSTINT('date_deliveryhour'), GETPOSTINT('date_deliverymin'), 0, GETPOSTINT('date_deliverymonth'), GETPOSTINT('date_deliveryday'), GETPOSTINT('date_deliveryyear')); +$date_reception = dol_mktime(GETPOSTINT('date_receptionhour'), GETPOSTINT('date_receptionmin'), 0, GETPOSTINT('date_receptionmonth'), GETPOSTINT('date_receptionday'), GETPOSTINT('date_receptionyear')); -if ($id > 0 || !empty($ref)) { - $object->fetch($id, $ref); - $object->fetch_thirdparty(); - - $typeobject = ''; - if (!empty($object->origin)) { - $origin = $object->origin; - $typeobject = $object->origin; - - $object->fetch_origin(); - } - - // Set $origin_id and $objectsrc - if (($origin == 'order_supplier' || $origin == 'supplier_order') && is_object($object->origin_object) && isModEnabled("supplier_order")) { - $origin_id = $object->origin_object->id; - $objectsrc = $object->origin_object; - } -} // Security check -$socid = ''; if ($user->socid) { $socid = $user->socid; } - +$result = restrictedArea($user, 'reception', $object->id, ''); // TODO Test on reception module on only if (isModEnabled("reception") || $origin == 'reception' || empty($origin)) { $result = restrictedArea($user, 'reception', $object->id); @@ -168,6 +161,7 @@ if (isModEnabled("reception") || $origin == 'reception' || empty($origin)) { if (isModEnabled("reception")) { $permissiontoread = $user->hasRight('reception', 'lire'); $permissiontoadd = $user->hasRight('reception', 'creer'); + $permissiontoedit = $user->hasRight('reception', 'creer'); // Used by the include of actions_lineupdown.inc.php $permissiondellink = $user->hasRight('reception', 'creer'); // Used by the include of actions_dellink.inc.php $permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'creer')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'reception_advance', 'validate'))); $permissiontodelete = $user->hasRight('reception', 'supprimer'); @@ -180,17 +174,25 @@ if (isModEnabled("reception")) { } $permissiontoeditextra = $permissiontoadd; if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) { - // For action 'update_extras', is there a specific permission set for the attribute to update + // For action 'update_extras' there is a specific permission set for the attribute to update $permissiontoeditextra = dol_eval($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]); } -$error = 0; +$editColspan = 0; +$objectsrc = null; +$typeobject = null; +$ref_customer = null; +$shipping_method_id = null; +$warehouse_id = null; +$note_public = null; +$note_private = null; /* * Actions */ +$error = 0; $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { @@ -198,6 +200,18 @@ if ($reshook < 0) { } if (empty($reshook)) { + $backurlforlist = DOL_URL_ROOT.'/reception/list.php'; + + if (empty($backtopage) || ($cancel && empty($id))) { + if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) { + if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) { + $backtopage = $backurlforlist; + } else { + $backtopage = DOL_URL_ROOT.'/reception/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__'); + } + } + } + if ($cancel) { if (!empty($backtopageforcancel)) { header("Location: ".$backtopageforcancel); @@ -210,6 +224,13 @@ if (empty($reshook)) { $action = ''; } + if ($cancel) { + if (!$origin) { + $action = ''; + $object->fetch($object->id); // show reception also after canceling modification + } + } + include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once' // Reopen @@ -290,191 +311,236 @@ if (empty($reshook)) { // Create reception if ($action == 'add' && $permissiontoadd) { - $error = 0; - $db->begin(); - $object->note = GETPOST('note', 'alpha'); - $object->note_private = GETPOST('note', 'alpha'); - $object->origin = $origin; - $object->origin_id = $origin_id; - $object->fk_project = GETPOSTINT('projectid'); - $object->weight = GETPOSTINT('weight') == '' ? null : GETPOSTINT('weight'); - $object->trueHeight = GETPOSTINT('trueHeight') == '' ? null : GETPOSTINT('trueHeight'); - $object->trueWidth = GETPOSTINT('trueWidth') == '' ? null : GETPOSTINT('trueWidth'); - $object->trueDepth = GETPOSTINT('trueDepth') == '' ? null : GETPOSTINT('trueDepth'); - $object->size_units = GETPOSTINT('size_units'); - $object->weight_units = GETPOSTINT('weight_units'); - - // On va boucler sur chaque ligne du document d'origine pour completer object reception - // avec info diverses + qte a livrer - - if ($object->origin == "supplierorder") { - $object->origin = 'order_supplier'; - $classname = 'CommandeFournisseur'; - } else { - $classname = ucfirst($object->origin); - } - $objectsrc = new $classname($db); - $objectsrc->fetch($object->origin_id); - - $object->socid = $objectsrc->socid; - $object->ref_supplier = GETPOST('ref_supplier', 'alpha'); - $object->model_pdf = GETPOST('model'); - $object->date_delivery = $date_delivery; // Date delivery planned - $object->fk_delivery_address = $objectsrc->fk_delivery_address; - $object->shipping_method_id = GETPOSTINT('shipping_method_id'); - $object->tracking_number = GETPOST('tracking_number', 'alpha'); - $object->note_private = GETPOST('note_private', 'restricthtml'); - $object->note_public = GETPOST('note_public', 'restricthtml'); - $object->fk_incoterms = GETPOSTINT('incoterm_id'); - $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); - - $batch_line = array(); - $stockLine = array(); - $array_options = array(); - - $totalqty = 0; - - $num = 0; - foreach ($_POST as $key => $value) { - // without batch module enabled - - if (strpos($key, 'qtyasked') !== false) { - $num++; - } + if (GETPOSTINT('socid') < 1) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdParty")), null, 'errors'); + $action = 'create'; } - // Loop lines to calculate $totalqty - for ($i = 1; $i <= $num; $i++) { - $idl = "idl".$i; // id line source + if (!$origin && getDolGlobalString('RECEPTION_STANDALONE')) { + $object->socid = GETPOSTINT('socid'); + $object->fetch_thirdparty(); + $object->note = GETPOST('note', 'alpha'); + $object->note_private = GETPOST('note', 'alpha'); + $object->origin = $origin; // deprecated + $object->origin_type = $origin; + $object->origin_id = $origin_id; + $object->fk_project = GETPOSTINT('projectid'); + $object->weight = GETPOSTINT('weight') == '' ? null : GETPOSTINT('weight'); + $object->trueHeight = GETPOSTINT('trueHeight') == '' ? null : GETPOSTINT('trueHeight'); + $object->trueWidth = GETPOSTINT('trueWidth') == '' ? null : GETPOSTINT('trueWidth'); + $object->trueDepth = GETPOSTINT('trueDepth') == '' ? null : GETPOSTINT('trueDepth'); + $object->size_units = GETPOSTINT('size_units'); + $object->weight_units = GETPOSTINT('weight_units'); + $object->ref_supplier = GETPOST('ref_supplier', 'alpha'); + $object->model_pdf = GETPOST('model'); + $object->date_delivery = $date_delivery; // Date delivery planned + $object->date_reception = $date_reception; + $object->shipping_method_id = GETPOSTINT('shipping_method_id'); + $object->tracking_number = GETPOST('tracking_number', 'alpha'); + $object->note_private = GETPOST('note_private', 'restricthtml'); + $object->note_public = GETPOST('note_public', 'restricthtml'); + $object->fk_incoterms = GETPOSTINT('incoterm_id'); + $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); - //$sub_qty = array(); - //$subtotalqty = 0; - - //$j = 0; - //$batch = "batchl".$i."_0"; - //$stockLocation = "ent1".$i."_0"; - $qty = "qtyl".$i; // qty - - //reception line for product with no batch management and no multiple stock location - if (GETPOST($qty, 'alpha') > 0) { - $totalqty += price2num(GETPOST($qty, 'alpha'), 'MS'); - } - - // Extrafields - $array_options[$i] = $extrafields->getOptionalsFromPost($object->table_element_line, (string) $i); - } - - - if ($totalqty > 0) { // There is at least one thing to ship - for ($i = 1; $i <= $num; $i++) { - $idl = "idl".$i; // id line source - $lineToTest = ''; - $lineId = GETPOSTINT($idl); - foreach ($objectsrc->lines as $linesrc) { - if ($linesrc->id == $lineId) { - $lineToTest = $linesrc; - break; - } - } - if (empty($lineToTest)) { - continue; - } - $qty = "qtyl".$i; - $comment = "comment".$i; - // EATBY <-> DLUO and SELLBY <-> DLC, see productbatch.class.php - $eatby = "dluo".$i; - $sellby = "dlc".$i; - $batch = "batch".$i; - $cost_price = "cost_price".$i; - - //var_dump(GETPOST("productl".$i, 'int').' '.GETPOST('entl'.$i, 'int').' '.GETPOST($idl, 'int').' '.GETPOST($qty, 'int').' '.GETPOST($batch, 'alpha')); - - //if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && getDolGlobalString('RECEPTION_GETS_ALL_ORDER_PRODUCTS')) || (GETPOST($qty, 'int') < 0 && getDolGlobalString('RECEPTION_ALLOW_NEGATIVE_QTY'))) { - if (GETPOSTFLOAT($qty) > 0 || (GETPOSTFLOAT($qty) == 0 && getDolGlobalString('RECEPTION_GETS_ALL_ORDER_PRODUCTS'))) { - $ent = "entl".$i; - $idl = "idl".$i; - - $entrepot_id = is_numeric(GETPOST($ent)) ? GETPOSTINT($ent) : GETPOSTINT('entrepot_id'); - - /* - if (!empty($lineToTest)) { - $fk_product = $lineToTest->fk_product; - } else { - $fk_product = $linesrc->fk_product; - }*/ - $fk_product = GETPOSTINT("productl".$i); - - if ($entrepot_id < 0) { - $entrepot_id = ''; - } - if (!($fk_product > 0) && !getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { - $entrepot_id = 0; - } - - $eatby = GETPOST($eatby, 'alpha'); - $sellby = GETPOST($sellby, 'alpha'); - $eatbydate = str_replace('/', '-', $eatby); - $sellbydate = str_replace('/', '-', $sellby); - - if (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) { - $ret = $object->addline($entrepot_id, GETPOSTINT($idl), (float) price2num(GETPOST($qty), 'MS'), $array_options[$i], GETPOST($comment), strtotime($eatbydate), strtotime($sellbydate), GETPOST($batch), GETPOSTFLOAT($cost_price, 'MU')); - } else { - $ret = $object->addline($entrepot_id, GETPOSTINT($idl), (float) price2num(GETPOST($qty), 'MS'), $array_options[$i], GETPOST($comment), strtotime($eatbydate), strtotime($sellbydate), GETPOST($batch)); - } - if ($ret < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - } - } + $product = new Product($db); // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) { $error++; } - if (!$error) { - $ret = $object->create($user); // This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception. + if (!$error) { + $ret = $object->create($user); if ($ret <= 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; - } else { - // Define output language - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { - $object->fetch_thirdparty(); - $outputlangs = $langs; - $newlang = ''; - if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { - $newlang = $object->thirdparty->default_lang; - } - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($object->id); // Reload to get new records + } + } + } + if ($origin && $origin_id > 0) { + $object->note = GETPOST('note', 'alpha'); + $object->note_private = GETPOST('note', 'alpha'); + $object->origin = $origin; + $object->origin_id = $origin_id; + $object->fk_project = GETPOSTINT('projectid'); + $object->weight = GETPOSTINT('weight') == '' ? null : GETPOSTINT('weight'); + $object->trueHeight = GETPOSTINT('trueHeight') == '' ? null : GETPOSTINT('trueHeight'); + $object->trueWidth = GETPOSTINT('trueWidth') == '' ? null : GETPOSTINT('trueWidth'); + $object->trueDepth = GETPOSTINT('trueDepth') == '' ? null : GETPOSTINT('trueDepth'); + $object->size_units = GETPOSTINT('size_units'); + $object->weight_units = GETPOSTINT('weight_units'); - $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result < 0) { - dol_print_error($db, $object->error, $object->errors); + $object->ref_supplier = GETPOST('ref_supplier', 'alpha'); + $object->model_pdf = GETPOST('model'); + $object->date_delivery = $date_delivery; // Date delivery planned + $object->date_reception = $date_reception; + $object->shipping_method_id = GETPOSTINT('shipping_method_id'); + $object->tracking_number = GETPOST('tracking_number', 'alpha'); + $object->note_private = GETPOST('note_private', 'restricthtml'); + $object->note_public = GETPOST('note_public', 'restricthtml'); + $object->fk_incoterms = GETPOSTINT('incoterm_id'); + $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); + if ($object->origin == "supplierorder") { + $object->origin = 'order_supplier'; + $classname = 'CommandeFournisseur'; + } else { + $classname = ucfirst($object->origin); + } + $objectsrc = new $classname($db); + $objectsrc->fetch($object->origin_id); + $object->socid = $objectsrc->socid; + $object->fk_delivery_address = $objectsrc->fk_delivery_address; + + $product = new Product($db); + $batch_line = array(); + $stockLine = array(); + $array_options = array(); + + $totalqty = 0; + + $num = 0; + foreach ($_POST as $key => $value) { + // without batch module enabled + + if (strpos($key, 'qtyasked') !== false) { + $num++; + } + } + + // Loop lines to calculate $totalqty + for ($i = 1; $i <= $num; $i++) { + $idl = "idl".$i; // id line source + + //$sub_qty = array(); + //$subtotalqty = 0; + + //$j = 0; + //$batch = "batchl".$i."_0"; + //$stockLocation = "ent1".$i."_0"; + $qty = "qtyl".$i; // qty + + //reception line for product with no batch management and no multiple stock location + if (GETPOST($qty, 'alpha') > 0) { + $totalqty += price2num(GETPOST($qty, 'alpha'), 'MS'); + } + + // Extrafields + $array_options[$i] = $extrafields->getOptionalsFromPost($object->table_element_line, (string) $i); + } + + + if ($totalqty > 0) { // There is at least one thing to ship + for ($i = 1; $i <= $num; $i++) { + $idl = "idl".$i; // id line source + $lineToTest = ''; + $lineId = GETPOSTINT($idl); + foreach ($objectsrc->lines as $linesrc) { + if ($linesrc->id == $lineId) { + $lineToTest = $linesrc; + break; + } + } + if (empty($lineToTest)) { + continue; + } + $qty = "qtyl".$i; + $comment = "comment".$i; + // EATBY <-> DLUO and SELLBY <-> DLC, see productbatch.class.php + $eatby = "dluo".$i; + $sellby = "dlc".$i; + $batch = "batch".$i; + $cost_price = "cost_price".$i; + + //var_dump(GETPOST("productl".$i, 'int').' '.GETPOST('entl'.$i, 'int').' '.GETPOST($idl, 'int').' '.GETPOST($qty, 'int').' '.GETPOST($batch, 'alpha')); + + //if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && getDolGlobalString('RECEPTION_GETS_ALL_ORDER_PRODUCTS')) || (GETPOST($qty, 'int') < 0 && getDolGlobalString('RECEPTION_ALLOW_NEGATIVE_QTY'))) { + if (GETPOSTFLOAT($qty) > 0 || (GETPOSTFLOAT($qty) == 0 && getDolGlobalString('RECEPTION_GETS_ALL_ORDER_PRODUCTS'))) { + $ent = "entl".$i; + $idl = "idl".$i; + + $entrepot_id = is_numeric(GETPOST($ent)) ? GETPOSTINT($ent) : GETPOSTINT('entrepot_id'); + + /* + if (!empty($lineToTest)) { + $fk_product = $lineToTest->fk_product; + } else { + $fk_product = $linesrc->fk_product; + }*/ + $fk_product = GETPOSTINT("productl".$i); + + if ($entrepot_id < 0) { + $entrepot_id = ''; + } + if (!($fk_product > 0) && !getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { + $entrepot_id = 0; + } + + $eatby = GETPOST($eatby, 'alpha'); + $sellby = GETPOST($sellby, 'alpha'); + $eatbydate = str_replace('/', '-', $eatby); + $sellbydate = str_replace('/', '-', $sellby); + + if (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) { + $ret = $object->addline($entrepot_id, GETPOSTINT($idl), (float) price2num(GETPOST($qty), 'MS'), $array_options[$i], GETPOST($comment), strtotime($eatbydate), strtotime($sellbydate), GETPOST($batch), GETPOSTFLOAT($cost_price, 'MU')); + } else { + $ret = $object->addline($entrepot_id, GETPOSTINT($idl), (float) price2num(GETPOST($qty), 'MS'), $array_options[$i], GETPOST($comment), strtotime($eatbydate), strtotime($sellbydate), GETPOST($batch)); + } + if ($ret < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; } } } - } - } else { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("QtyToReceive").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); - $error++; - } + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost(null, $object); + if ($ret < 0) { + $error++; + } + if (!$error) { + $ret = $object->create($user); // This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception. + + if ($ret <= 0) { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } else { + // Define output language + if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { + $object->fetch_thirdparty(); + $outputlangs = $langs; + $newlang = ''; + if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model = $object->model_pdf; + $ret = $object->fetch($object->id); // Reload to get new records + + $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + if ($result < 0) { + dol_print_error($db, $object->error, $object->errors); + } + } + } + } + } else { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("QtyToReceive").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); + $error++; + } + } if (!$error) { $db->commit(); - header("Location: card.php?id=".$object->id); + header("Location: card.php?id=" . $object->id); exit; } else { $db->rollback(); @@ -536,6 +602,43 @@ if (empty($reshook)) { if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } + } elseif ($action == 'setdate_reception' && $user->hasRight('reception', 'creer')) { + $datereception = dol_mktime(GETPOSTINT('recep_hour'), GETPOSTINT('recep_min'), 0, GETPOSTINT('recep_month'), GETPOSTINT('recep_day'), GETPOSTINT('recep_year')); + + $object->fetch($id); + $result = $object->setReceptionDate($user, $datereception); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $permissiontoadd) { + // Remove a product line + $result = $object->deleteLine($user, $lineid); + if ($result > 0) { + // reorder lines + $object->line_order(true); + // Define output language + $outputlangs = $langs; + $newlang = ''; + if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { + $ret = $object->fetch($object->id); // Reload to get new records + $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + + header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id); + exit; + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } } elseif (in_array($action, array('settracking_number', 'settracking_url', 'settrueWeight', 'settrueWidth', 'settrueHeight', 'settrueDepth', 'setshipping_method_id')) && $permissiontoadd) { // Action update $error = 0; @@ -564,13 +667,11 @@ if (empty($reshook)) { $object->shipping_method_id = GETPOSTINT('shipping_method_id'); } - if (!$error) { - if ($object->update($user) >= 0) { - header("Location: card.php?id=".$object->id); - exit; - } - setEventMessages($object->error, $object->errors, 'errors'); + if ($object->update($user) >= 0) { + header("Location: card.php?id=" . $object->id); + exit; } + setEventMessages($object->error, $object->errors, 'errors'); $action = ""; } elseif ($action == 'builddoc' && $permissiontoread) { @@ -653,99 +754,338 @@ if (empty($reshook)) { setEventMessages($line->error, $line->errors, 'errors'); } } elseif ($action == 'updateline' && GETPOST('save') && $permissiontoadd) { - // Update a line - // Clean parameters - $qty = 0; - $entrepot_id = 0; - $batch_id = 0; + if (!$origin && getDolGlobalString('RECEPTION_STANDALONE')) { + // Update a line + // Clean parameters - $lines = $object->lines; - $num_prod = count($lines); - for ($i = 0; $i < $num_prod; $i++) { - if ($lines[$i]->id == $line_id) { // we have found line to update - $line = new CommandeFournisseurDispatch($db); - $line->fetch($line_id); - // Extrafields Lines - $extrafields->fetch_name_optionals_label($object->table_element_line); - $line->array_options = $extrafields->getOptionalsFromPost($object->table_element_line); + if (!$object->fetch($id) > 0) { + dol_print_error($db); + } + $object->fetch_thirdparty(); + $qty = GETPOST('qty', 'alpha'); + $description = ''; + $element_type = 'reception'; + $fk_unit = ''; + $fk_product = 0; + $rang = 0; - $line->fk_product = $lines[$i]->fk_product; - - - if ($lines[$i]->fk_product > 0) { - // single warehouse reception line - $stockLocation = "entl".$line_id; - $qty = "qtyl".$line_id; - $comment = "comment".$line_id; - - - $line->id = $line_id; - $line->fk_entrepot = GETPOSTINT($stockLocation); - $line->qty = GETPOSTFLOAT($qty, 'MS'); - $line->comment = GETPOST($comment, 'alpha'); - - if (isModEnabled('productbatch')) { - $batch = "batch".$line_id; - $dlc = "dlc".$line_id; - $dluo = "dluo".$line_id; - // EATBY <-> DLUO - $eatby = GETPOST($dluo, 'alpha'); - $eatbydate = str_replace('/', '-', $eatby); - // SELLBY <-> DLC - $sellby = GETPOST($dlc, 'alpha'); - $sellbydate = str_replace('/', '-', $sellby); - $line->batch = GETPOST($batch, 'alpha'); - $line->eatby = strtotime($eatbydate); - $line->sellby = strtotime($sellbydate); - } - - if ($line->update($user) < 0) { - setEventMessages($line->error, $line->errors, 'errors'); - $error++; - } - } else { // Product no predefined - $qty = "qtyl".$line_id; - $line->id = $line_id; - $line->qty = GETPOSTFLOAT($qty, 'MS'); - $line->fk_entrepot = 0; - if ($line->update($user) < 0) { - setEventMessages($line->error, $line->errors, 'errors'); - $error++; - } - unset($_POST[$qty]); + // Extrafields + $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafields->getOptionalsFromPost($object->table_element_line); + // Unset extrafield + if (is_array($extralabelsline)) { + // Get extra fields + foreach ($extralabelsline as $key => $value) { + unset($_POST["options_" . $key]); } } - } - unset($_POST["lineid"]); + $receptionline = new ReceptionLineBatch($db); + $receptionline->fetch(GETPOSTINT('lineid')); - if (!$error) { - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { - // Define output language - $outputlangs = $langs; - $newlang = ''; - if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('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->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + if (!$error) { + $result = $object->updatelinefree(GETPOSTINT('lineid'), (float) $qty, $element_type, $fk_product, GETPOSTINT('units'), $rang, $description, 0, $array_options); + + if ($result >= 0) { + if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { + // Define output language + $outputlangs = $langs; + $newlang = ''; + if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + $outputlangs->load('products'); + } + + $ret = $object->fetch($object->id); // Reload to get new records + $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + unset($_POST['qty']); + unset($_POST['units']); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } elseif ($origin && $origin_id > 0) { + // Update a line + // 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) { // we have found line to update + $line = new CommandeFournisseurDispatch($db); + $line->fetch($line_id); + // Extrafields Lines + $extrafields->fetch_name_optionals_label($object->table_element_line); + $line->array_options = $extrafields->getOptionalsFromPost($object->table_element_line); + + $line->fk_product = $lines[$i]->fk_product; + + if ($lines[$i]->fk_product > 0) { + // single warehouse reception line + $stockLocation = "entl".$line_id; + $qty = "qtyl".$line_id; + $comment = "comment".$line_id; + + $line->id = $line_id; + $line->fk_entrepot = GETPOSTINT($stockLocation); + $line->qty = GETPOSTFLOAT($qty, 'MS'); + $line->comment = GETPOST($comment, 'alpha'); + + if (isModEnabled('productbatch')) { + $batch = "batch".$line_id; + $dlc = "dlc".$line_id; + $dluo = "dluo".$line_id; + // EATBY <-> DLUO + $eatby = GETPOST($dluo, 'alpha'); + $eatbydate = str_replace('/', '-', $eatby); + // SELLBY <-> DLC + $sellby = GETPOST($dlc, 'alpha'); + $sellbydate = str_replace('/', '-', $sellby); + $line->batch = GETPOST($batch, 'alpha'); + $line->eatby = strtotime($eatbydate); + $line->sellby = strtotime($sellbydate); + } + + if ($line->update($user) < 0) { + setEventMessages($line->error, $line->errors, 'errors'); + $error++; + } + } else { // Product no predefined + $qty = "qtyl".$line_id; + $line->id = $line_id; + $line->qty = GETPOSTFLOAT($qty, 'MS'); + $line->fk_entrepot = 0; + if ($line->update($user) < 0) { + setEventMessages($line->error, $line->errors, 'errors'); + $error++; + } + unset($_POST[$qty]); + } + } + } + + unset($_POST["lineid"]); + + if (!$error) { + if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { + // Define output language + $outputlangs = $langs; + $newlang = ''; + if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if (getDolGlobalInt('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->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } else { + header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To reshow the record we edit + exit(); } - } else { - header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To reshow the record we edit - exit(); } } elseif ($action == 'updateline' && $permissiontoadd && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) { header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To reshow the record we edit exit(); + } elseif ($action == 'addline' && !$origin && getDolGlobalString('RECEPTION_STANDALONE') && $permissiontoadd) { // Add a new line + $langs->load('errors'); + $error = 0; + $line_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); + $predef = ''; + $description = ''; + $fk_elementdet = ''; + $element_type = 'reception'; + $fk_unit = ''; + $idprod = 0; + $fk_product = 0; + $fk_entrepot = ''; + $rang = ''; + $prod_entry_mode = GETPOST('prod_entry_mode', 'aZ09'); + if ($prod_entry_mode == 'free') { + $idprod = 0; + } else { + $idprod = GETPOSTINT('idprod'); + if (getDolGlobalString('MAIN_DISABLE_FREE_LINES') && $idprod <= 0) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")), null, 'errors'); + $error++; + } + } + + $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2); + + // Extrafields + $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef); + // Unset extrafield + if (is_array($extralabelsline)) { + // Get extra fields + foreach ($extralabelsline as $key => $value) { + unset($_POST["options_".$key]); + } + } + + if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors'); + $error++; + } + + if ($qty == '') { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors'); + $error++; + } + if ($qty < 0) { + setEventMessages($langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv('Qty')), null, 'errors'); + $error++; + } + if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors'); + $error++; + } + + if (!$error && isModEnabled('variants') && $prod_entry_mode != 'free') { + if ($combinations = GETPOST('combinations', 'array')) { + // Check if there is a product with the given combination + $prodcomb = new ProductCombination($db); + + if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) { + $idprod = $res->fk_product_child; + $fk_product = $idprod; // Update $fk_product with the fetched child product + } else { + setEventMessages($langs->trans('ErrorProductCombinationNotFound'), null, 'errors'); + $error++; + } + } + } + + if (!$error && ($qty >= 0) && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) { + // Clean parameters + if (!empty($idprod) && $idprod > 0) { + $prod = new Product($db); + $prod->fetch($idprod); + $desc = $prod->label; + $description = $desc; + // Define output language + if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) { + $outputlangs = $langs; + $newlang = ''; + if (GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if (empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + + $description = (!empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description; + } else { + $description = $prod->description; + } + if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 0) { + $description = dol_concatdesc($desc, $line_desc, false, getDolGlobalString('MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION') ? true : false); + } else { + $description = $line_desc; + } + + // Add custom code and origin country into description + if (!getDolGlobalString('MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) { + $tmptxt = '('; + if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) { + $outputlangs = $langs; + $newlang = ''; + if (GETPOST('lang_id', 'alpha')) { + $newlang = GETPOST('lang_id', 'alpha'); + } + if (empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + $outputlangs->load('products'); + } + if (!empty($prod->customcode)) { + $tmptxt .= $outputlangs->transnoentitiesnoconv("CustomsCode").': '.$prod->customcode; + } + if (!empty($prod->customcode) && !empty($prod->country_code)) { + $tmptxt .= ' - '; + } + if (!empty($prod->country_code)) { + $tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, '', $db, $outputlangs, 0); + } + } else { + if (!empty($prod->customcode)) { + $tmptxt .= $langs->transnoentitiesnoconv("CustomsCode").': '.$prod->customcode; + } + if (!empty($prod->customcode) && !empty($prod->country_code)) { + $tmptxt .= ' - '; + } + if (!empty($prod->country_code)) { + $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, '', $db, $langs, 0); + } + } + $tmptxt .= ')'; + $description = dol_concatdesc($desc, $tmptxt); + } + $type = $prod->type; + $fk_unit = $prod->fk_unit; + } else { + $label = (GETPOST('product_label') ? GETPOST('product_label') : ''); + $desc = $line_desc; + $type = GETPOST('type'); + $fk_unit = GETPOST('units', 'alpha'); + $description = $desc; + $fk_elementdet = ''; + } + $desc = dol_htmlcleanlastbr($desc); + + if (!$error) { + // Insert line + $result = $object->addlinefree((float) $qty, $element_type, $idprod, $fk_unit, min($rank, count($object->lines) + 1), $description, $array_options); + + if ($result > 0) { + $ret = $object->fetch($object->id); // Reload to get new records + $object->fetch_thirdparty(); + if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { + // Define output language + $outputlangs = $langs; + $newlang = GETPOST('lang_id', 'alpha'); + if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } else { + header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To redisplay the form being edited + exit(); + } + } + } } include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; @@ -768,7 +1108,9 @@ if (empty($reshook)) { */ $title = $object->ref.' - '.$langs->trans('Reception'); - +if ($action == 'create') { + $title = $langs->trans("NewReception"); +} llxHeader('', $title, 'Reception', '', 0, 0, '', '', '', 'mod-reception page-card'); $form = new Form($db); @@ -777,13 +1119,15 @@ $formproduct = new FormProduct($db); $formproject = null; if (isModEnabled('project')) { $formproject = new FormProjets($db); +} else { + $formproject = null; } $product_static = new Product($db); $reception_static = new Reception($db); $warehousestatic = new Entrepot($db); -if ($action == 'create2') { +if ($action == 'create' && !getDolGlobalString('RECEPTION_STANDALONE')) { print load_fiche_titre($langs->trans("CreateReception"), '', 'dollyrevert'); print '
'.$langs->trans("ReceptionCreationIsDoneFromOrder"); @@ -793,15 +1137,197 @@ if ($action == 'create2') { } // Mode creation. -if ($action == 'create') { +if ($action == 'create' && $permissiontoadd) { $recept = new Reception($db); - print load_fiche_titre($langs->trans("CreateReception")); - if (!$origin) { - setEventMessages($langs->trans("ErrorBadParameters"), null, 'errors'); - } + print load_fiche_titre($langs->trans("NewReception"), '', 'dollyrevert'); + if (empty($origin) && getDolGlobalString('RECEPTION_STANDALONE')) { + $soc = new Societe($db); + if ($socid > 0) { + $res = $soc->fetch($socid); + } - if ($origin) { + $note_private = $object->getDefaultCreateValueFor('note_private'); + $note_public = $object->getDefaultCreateValueFor('note_public'); + + print '
'; + print ''; + print ''; + print ''; // will be set to 1 by javascript so we know post is done after a company change + print ''; + print ''; + + print dol_get_fiche_head([]); + + print ''; + + + // Thirdparty + print ''; + print ''; + if ($socid > 0) { + print ''; + } else { + print ''; + } + print ''."\n"; + + // Project + if (isModEnabled('project') && is_object($formproject)) { + $projectid = GETPOSTINT('projectid'); + if (empty($projectid) && !empty($object->fk_project)) { + $projectid = (int) $object->fk_project; + } + $langs->load("projects"); + print ''; + print ''; + print ''; + } + + // Reception Date + print ''; + print '\n"; + print ''; + + // Date delivery planned + print ''; + print '\n"; + print ''; + + // Weight + print ''; + + // Dim + print ''; + + // Delivery method + print ""; + print '\n"; + + // Tracking number + print ""; + print '\n"; + + // 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 ($objectsrc->fetch_optionals() > 0) { + $recept->array_options = array_merge($recept->array_options, $objectsrc->array_options); + } + print $recept->showOptionals($extrafields, 'create', $parameters); + } + + // Incoterms + if (isModEnabled('incoterm')) { + print ''; + print ''; + print ''; + } + + // Template to use by default + print ''; + print '"; + + // Note Public + $htmltext =''; + print ''; + print ''; + print ''; + print ''; + print '"; + } + + print "
' . $langs->trans('ThirdParty') . ''; + print $soc->getNomUrl(1); + print ''; + print ''; + print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company('', 'socid', '', 'SelectThirdParty', 1, 0, array(), 0, 'minwidth175 maxwidth500 widthcentpercentminusxx'); + // reload page to retrieve customer information + if (!getDolGlobalString('RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED')) { + print ''; + } + print ' '; + print '
' . $langs->trans("Project") . ''; + print img_picto('', 'project', 'class="pictofixedwidth"'); + print $formproject->select_projects($soc->id, $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 1, 0, 'widthcentpercentminusxx'); + print ' id) . '">'; + print '
'.$langs->trans("DateReception").''; + print img_picto('', 'action', 'class="pictofixedwidth"'); + $date_reception = ($date_reception ? $date_reception : $object->date_reception); // $date_reception comes from GETPOST + print $form->selectDate($date_reception ? $date_reception : -1, 'date_reception', 1, 1, 1); + print "
'.$langs->trans("DateDeliveryPlanned").''; + print img_picto('', 'action', 'class="pictofixedwidth"'); + $date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date); // $date_delivery comes from GETPOST + print $form->selectDate($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1); + print "
'; + print $langs->trans("Weight"); + print ''; + print img_picto('', 'fa-balance-scale', 'class="pictofixedwidth"'); + print ' '; + $text = $formproduct->selectMeasuringUnits("weight_units", "weight", (string) GETPOSTINT('weight_units'), 0, 2); + $htmltext = $langs->trans("KeepEmptyForAutoCalculation"); + print $form->textwithpicto($text, $htmltext); + print '
'; + print $langs->trans("Width").' x '.$langs->trans("Height").' x '.$langs->trans("Depth"); + print ' '; + print img_picto('', 'fa-ruler', 'class="pictofixedwidth"'); + print ''; + print ' x '; + print ' x '; + print ' '; + $text = $formproduct->selectMeasuringUnits("size_units", "size", (string) GETPOSTINT('size_units'), 0, 2); + $htmltext = $langs->trans("KeepEmptyForAutoCalculation"); + print $form->textwithpicto($text, $htmltext); + print '
".$langs->trans("ReceptionMethod")."'; + $recept->fetch_delivery_methods(); + print $form->selectarray("shipping_method_id", $recept->meths, GETPOSTINT('shipping_method_id'), 1, 0, 0, "", 1); + if ($user->admin) { + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + } + print "
".$langs->trans("TrackingNumber")."'; + print img_picto('', 'barcode', 'class="pictofixedwidth"'); + print ''; + print "
'; + print img_picto('', 'incoterm', 'class="pictofixedwidth"'); + print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : '')); + print '
'.$langs->trans('Model').''; + print img_picto('', 'pdf', 'class="pictofixedwidth"'); + include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php'; + $list = ModelePdfReception::liste_modeles($db); + print $form->selectarray('model', $list, getDolGlobalString('RECEPTION_ADDON_PDF'), 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx', 1); + print "
'; + print $form->textwithpicto($langs->trans('NotePublic'), $htmltext); + print ''; + $doleditor = new DolEditor('note_public', (string) $note_public, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%'); + print $doleditor->Create(1); + + // Note Private + if (!$user->socid) { + print '
'; + print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext); + print ''; + $doleditor = new DolEditor('note_private', (string) $note_private, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%'); + print $doleditor->Create(1); + print "
\n"; + + print dol_get_fiche_end(); + + print $form->buttonsSaveCancel("CreateDraft"); + + print "
\n"; + } elseif ($origin) { if ($origin == 'supplierorder') { $classname = 'CommandeFournisseur'; } else { @@ -870,7 +1396,7 @@ if ($action == 'create') { $projectid = $objectsrc->fk_project; } if ($origin == 'project') { - $projectid = ($originid ? $originid : 0); + $projectid = ($origin_id ? $origin_id : 0); } $langs->load("projects"); @@ -883,6 +1409,15 @@ if ($action == 'create') { print ''; } + // Reception Date + print ''.$langs->trans("DateReception").''; + print ''; + print img_picto('', 'action', 'class="pictofixedwidth"'); + $date_reception = ($date_reception ? $date_reception : $object->date_reception); // $date_reception comes from GETPOST + print $form->selectDate($date_reception ? $date_reception : -1, 'date_reception', 1, 1, 1); + print "\n"; + print ''; + // Date delivery planned print ''.$langs->trans("DateDeliveryPlanned").''; print ''; @@ -1359,7 +1894,7 @@ if ($action == 'create') { dol_print_error($db); } } -} elseif ($id || $ref) { +} elseif ($object->id > 0) { /* *************************************************************************** */ /* */ /* Edit and view mode */ @@ -1475,22 +2010,46 @@ if ($action == 'create') { // Thirdparty $morehtmlref .= '
'.$object->thirdparty->getNomUrl(1); // Project - if (isModEnabled('project')) { - $langs->load("projects"); - $morehtmlref .= '
'; - if (0) { // @phpstan-ignore-line Do not change on reception - $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); - if ($action != 'classify' && $permissiontoadd) { - $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; + if ($origin && $origin_id > 0) { + if (isModEnabled('project')) { + $langs->load("projects"); + $morehtmlref .= '
'; + if (0) { // @phpstan-ignore-line Do not change on shipment + $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); + if ($action != 'classify') { + $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; + } + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $objectsrc->socid, (string) $objectsrc->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300'); + } else { + if (!empty($objectsrc) && !empty($objectsrc->fk_project)) { + $proj = new Project($db); + $proj->fetch($objectsrc->fk_project); + $morehtmlref .= $proj->getNomUrl(1); + if ($proj->title) { + $morehtmlref .= ' - '.dol_escape_htmltag($proj->title).''; + } + } } - $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300'); - } else { - if (!empty($objectsrc) && !empty($objectsrc->fk_project)) { - $proj = new Project($db); - $proj->fetch($objectsrc->fk_project); - $morehtmlref .= $proj->getNomUrl(1); - if ($proj->title) { - $morehtmlref .= ' - '.dol_escape_htmltag($proj->title).''; + } + } elseif (!$origin && getDolGlobalString('RECEPTION_STANDALONE')) { + // Project + if (isModEnabled('project')) { + $langs->load("projects"); + $morehtmlref .= '
'; + if ($permissiontoadd) { + $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); + if ($action != 'classify') { + $morehtmlref .= '' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' '; + } + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300'); + } else { + if (!empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref .= $proj->getNomUrl(1); + if ($proj->title) { + $morehtmlref .= ' - ' . dol_escape_htmltag($proj->title) . ''; + } } } } @@ -1537,6 +2096,29 @@ if ($action == 'create') { print ''.dol_print_date($object->date_creation, "dayhour", "tzuserrel")."\n"; print ''; + // Reception Date + print ''; + print ''; + if ($action != 'editdate_reception') { + print ''; + } + print '
'; + print $langs->trans('DateReception'); + print '' . img_edit($langs->trans('SetReceptionDate'), 1) . '
'; + print ''; + if ($action == 'editdate_reception') { + print '
'; + print ''; + print ''; + print $form->selectDate($object->date_reception ? $object->date_reception : -1, 'recep_', 1, 1, 0, "setdate_reception", 1, 0); + print ''; + print '
'; + } else { + print $object->date_reception ? dol_print_date($object->date_reception, 'dayhour') : ' '; + } + print ''; + print ''; + // Delivery date planned print ''; print '
'; @@ -1735,429 +2317,483 @@ if ($action == 'create') { print '
'; - - // Lines of products - if ($action == 'editline') { - print '
- - - - '; - } - print '

'; - - print '
'; - print ''; - print ''; - print ''; - // # - if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) { - print ''; - } - // Product/Service - print ''; - // Comment - print ''; - // Qty - print ''; - if ($origin && $origin_id > 0) { - print ''; - } - - $editColspan = 3; - if ($action == 'editline') { - if (!isModEnabled('stock')) { - $editColspan--; - } - if (!isModEnabled('productbatch')) { - $editColspan--; - } - print ''; - } else { - $statusreceived = $object::STATUS_CLOSED; - if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION")) { - $statusreceived = $object::STATUS_VALIDATED; - } - if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION_CLOSE")) { - $statusreceived = $object::STATUS_CLOSED; - } - if ($object->statut < $statusreceived) { - print ''; - } else { - print ''; - } - if (isModEnabled('stock')) { - print ''; - } - - if (isModEnabled('productbatch')) { - print ''; - } - } - print ''; - print ''; - //print ''; - if ($object->statut == 0) { - print ''; - print ''; - } - print "\n"; - print ''; - - $var = false; - - $outputlangs = $langs; - if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) { - $object->fetch_thirdparty(); - $newlang = ''; - if (/* empty($newlang) && */ GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (empty($newlang)) { - $newlang = $object->thirdparty->default_lang; - } - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - } - - // Get list of products already sent for same source object into $alreadysent - $alreadysent = array(); - - $origin = 'commande_fournisseur'; - - if ($origin && $origin_id > 0) { - $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end"; - $sql .= ", ed.rowid as receptionline_id, ed.qty, ed.fk_reception as reception_id, ed.fk_entrepot"; - $sql .= ", e.rowid as reception_id, e.ref as reception_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_reception"; - //if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received"; - $sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch'; - $sql .= ', p.description as product_desc'; - $sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as ed"; - $sql .= ", ".MAIN_DB_PREFIX."reception as e"; - $sql .= ", ".MAIN_DB_PREFIX.$origin."det as obj"; - //if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.fk_reception = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."deliverydet as ld ON ld.fk_delivery = l.rowid AND obj.rowid = ld.fk_origin_line"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid"; - $sql .= " WHERE e.entity IN (".getEntity('reception').")"; - $sql .= " AND obj.fk_commande = ".((int) $origin_id); - $sql .= " AND obj.rowid = ed.fk_elementdet"; - $sql .= " AND ed.fk_reception = e.rowid"; - $sql .= " AND ed.fk_reception !=".((int) $object->id); - //if ($filter) $sql.= $filter; - $sql .= " ORDER BY obj.fk_product"; - - dol_syslog("get list of reception lines", LOG_DEBUG); - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - - while ($i < $num) { - $obj = $db->fetch_object($resql); - if ($obj) { - // $obj->rowid is rowid in $origin."det" table - $alreadysent[$obj->rowid][$obj->receptionline_id] = array('reception_ref' => $obj->reception_ref, 'reception_id' => $obj->reception_id, 'warehouse' => $obj->fk_entrepot, 'qty' => $obj->qty, 'date_valid' => $obj->date_valid, 'date_delivery' => $obj->date_delivery); - } - $i++; - } - } - //var_dump($alreadysent); - } - - $arrayofpurchaselinealreadyoutput = array(); - - // Loop on each product to send/sent. Warning: $lines must be sorted by ->fk_commandefourndet (it is a regroupment key on output) - print ''; - for ($i = 0; $i < $num_prod; $i++) { - print ''; // id of order line - print ''; - - // # - if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) { - print ''; - } - - // Predefined product or service - if ($lines[$i]->fk_product > 0) { - // Define output language - if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) { - $prod = new Product($db); - $prod->fetch($lines[$i]->fk_product); - $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product->label; - } else { - $label = (!empty($lines[$i]->product->label) ? $lines[$i]->product->label : $lines[$i]->product->product_label); - } - - print '\n"; - } else { - print '\n"; - } - - if ($action == 'editline' && $lines[$i]->id == $line_id) { - print ''; - } else { - print ''; - } - - - // Qty ordered - print ''; - - // Qty in other receptions (with reception and warehouse used) - if ($origin && $origin_id > 0) { - print ''; - } - - if ($action == 'editline' && $lines[$i]->id == $line_id) { - // edit mode - print ''; - } else { - // Qty to receive or received - print ''; - - // Warehouse source - if (isModEnabled('stock')) { - if ($lines[$i]->fk_entrepot > 0) { - $entrepot = new Entrepot($db); - $entrepot->fetch($lines[$i]->fk_entrepot); - - print ''; - } else { - print ''; - } - } - - // Batch number management - if (isModEnabled('productbatch')) { - if (isset($lines[$i]->batch)) { - print ''; - print ''; - } else { - print ''; - } - } - } - - // Weight - print ''; - - // Volume - print ''; - - - if ($action == 'editline' && $lines[$i]->id == $line_id) { - print ''; - } elseif ($object->statut == Reception::STATUS_DRAFT) { - // edit-delete buttons - print ''; - print ''; - - // Display lines extrafields - if (isset($rowExtrafieldsStart, $rowExtrafieldsView, $rowEnd)) { // @phan-suppress-current-line PhanPluginUndeclaredVariableIsset - print $rowExtrafieldsStart; - print $rowExtrafieldsView; - print $rowEnd; - } - } - print ""; - - $arrayofpurchaselinealreadyoutput[$lines[$i]->fk_commandefourndet] = $lines[$i]->fk_commandefourndet; - - // Display lines extrafields - $extralabelslines = $extrafields->attributes[$lines[$i]->table_element]; - if (!empty($extralabelslines) && is_array($extralabelslines) && count($extralabelslines) > 0) { - $colspan = 8; - if (isModEnabled('stock')) { - $colspan++; - } - if (isModEnabled('productbatch')) { - $colspan++; - } - - $line = new CommandeFournisseurDispatch($db); - $line->id = $lines[$i]->id; - $line->fetch_optionals(); - - if ($action == 'editline' && $lines[$i]->id == $line_id) { - print $line->showOptionals($extrafields, 'edit', array('colspan' => $colspan), ''); - } else { - print $line->showOptionals($extrafields, 'view', array('colspan' => $colspan), ''); - } - } - } - print ''; - - // TODO Show also lines ordered but not delivered - - print "
 '.$langs->trans("Products").''.$langs->trans("Comment").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyInOtherReceptions").''; - if ($object->statut <= 1) { - print $langs->trans("QtyToReceive").' - '; - } else { - print $langs->trans("QtyReceived").' - '; - } - if (isModEnabled('stock')) { - print $langs->trans("WarehouseTarget").' - '; - } - if (isModEnabled('productbatch')) { - print $langs->trans("Batch"); - } - print ''.$langs->trans("QtyToReceive").''.$langs->trans("QtyReceived").''.$langs->trans("WarehouseTarget").''.$langs->trans("Batch").''.$langs->trans("CalculatedWeight").''.$langs->trans("CalculatedVolume").''.$langs->trans("Size").'
'.($i + 1).''; - if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) { - $text = $lines[$i]->product->getNomUrl(1); - $text .= ' - '.$label; - $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($lines[$i]->product->description)); - print $form->textwithtooltip($text, $description, 3, 0, '', (string) $i); - print_date_range(!empty($lines[$i]->date_start) ? $lines[$i]->date_start : 0, !empty($lines[$i]->date_end) ? $lines[$i]->date_end : 0); - if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) { - print (!empty($lines[$i]->product->description) && $lines[$i]->description != $lines[$i]->product->description) ? '
'.dol_htmlentitiesbr($lines[$i]->description) : ''; - } - } - print "
'; - if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) { - if ($lines[$i]->product_type == Product::TYPE_SERVICE) { - $text = img_object($langs->trans('Service'), 'service'); - } else { - $text = img_object($langs->trans('Product'), 'product'); - } - - if (!empty($lines[$i]->label)) { - $text .= ' '.$lines[$i]->label.''; - print $form->textwithtooltip($text, $lines[$i]->description, 3, 0, '', (string) $i); - } else { - print $text.' '.nl2br($lines[$i]->description); - } - - print_date_range($lines[$i]->date_start, $lines[$i]->date_end); - } - print "'.dol_escape_htmltag($lines[$i]->comment).''; - if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) { - print $lines[$i]->qty_asked; - } - print ''; - $htmltooltip = ''; - $qtyalreadyreceived = 0; - if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) { - foreach ($alreadysent as $key => $val) { - if ($lines[$i]->fk_commandefourndet == $key) { - $j = 0; - foreach ($val as $receptionline_id => $receptionline_var) { - if ($receptionline_var['reception_id'] == $lines[$i]->fk_reception) { - continue; // We want to show only "other receptions" - } - - $j++; - if ($j > 1) { - $htmltooltip .= '
'; - } - $reception_static->fetch($receptionline_var['reception_id']); - $htmltooltip .= $reception_static->getNomUrl(1, '', 0, 0, 1); - $htmltooltip .= ' - '.$receptionline_var['qty']; - - $htmltext = $langs->trans("DateValidation").' : '.(empty($receptionline_var['date_valid']) ? $langs->trans("Draft") : dol_print_date($receptionline_var['date_valid'], 'dayhour')); - if (isModEnabled('stock') && $receptionline_var['warehouse'] > 0) { - $warehousestatic->fetch($receptionline_var['warehouse']); - $htmltext .= '
'.$langs->trans("From").' : '.$warehousestatic->getNomUrl(1, '', 0, 1); - } - $htmltooltip .= ' '.$form->textwithpicto('', $htmltext, 1); - - $qtyalreadyreceived += $receptionline_var['qty']; - } - if ($j) { - $htmltooltip = $langs->trans("QtyInOtherReceptions").'...

'.$htmltooltip.'
'; - } - } - } - } - print $form->textwithpicto((string) $qtyalreadyreceived, $htmltooltip, 1, 'info', '', 0, 3, 'tooltip'.$lines[$i]->id); - print '
'; - if (isModEnabled('stock')) { - if ($lines[$i]->fk_product > 0) { - print ''; - print ''; - // Qty to receive or received - print ''; - // Warehouse source - print ''; - // Batch number management - if ($conf->productbatch->enabled && !empty($lines[$i]->product->status_batch)) { - print ''; - } - print ''; - } else { - print ''; - print ''; - // Qty to receive or received - print ''; - // Warehouse source - print ''; - // Batch number management - print ''; - print ''; - } - } - print '
'.$formproduct->selectWarehouses($lines[$i]->fk_entrepot, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).'
'; - if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { - print $langs->trans('SellByDate').' : '; - print $form->selectDate($lines[$i]->sellby, 'dlc'.$line_id, 0, 0, 1, "").'
'; - } - if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { - print $langs->trans('EatByDate').' : '; - print $form->selectDate($lines[$i]->eatby, 'dluo'.$line_id, 0, 0, 1, ""); - } - print '
'.$lines[$i]->qty.''; - print $entrepot->getNomUrl(1); - print ''; - $detail = $langs->trans("NA"); - if ($lines[$i]->product->status_batch > 0 && $lines[$i]->fk_product > 0) { - require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; - $productlot = new Productlot($db); - $reslot = $productlot->fetch(0, $lines[$i]->fk_product, $lines[$i]->batch); - if ($reslot > 0) { - $detail = $productlot->getNomUrl(1); - } else { - // lot is not created and info is only in reception lines - $batchinfo = $langs->trans("Batch").': '.$lines[$i]->batch; - if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { - $batchinfo .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($lines[$i]->sellby, "day"); - } - if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { - $batchinfo .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($lines[$i]->eatby, "day"); - } - $detail = $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"), $batchinfo); - } - } - print $detail . ''; - if (!empty($lines[$i]->fk_product_type) && $lines[$i]->fk_product_type == Product::TYPE_PRODUCT) { - print $lines[$i]->product->weight * $lines[$i]->qty.' '.measuringUnitString(0, "weight", $lines[$i]->product->weight_units); - } else { - print ' '; - } - print ''; - if (!empty($lines[$i]->fk_product_type) && $lines[$i]->fk_product_type == Product::TYPE_PRODUCT) { - print $lines[$i]->product->volume * $lines[$i]->qty.' '.measuringUnitString(0, "volume", $lines[$i]->product->volume_units); - } else { - print ' '; - } - print ''; - print '
'; - print '
'; - print '
'; - print 'id.'">'.img_edit().''; - print ''; - print 'id.'">'.img_delete().''; - print '
\n"; - print '
'; - - print dol_get_fiche_end(); + /* + * Lines of simple reception + */ + if (!$origin_id && getDolGlobalString('RECEPTION_STANDALONE')) { + if (!empty($object->table_element_line)) { + // Show object lines + $result = $object->getLinesArray(); - $object->fetchObjectLinked($object->id, $object->element); + print ' + + + + + + '; + if (!empty($conf->use_javascript_ajax) && $object->status == $object::STATUS_DRAFT) { + include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; + } + + print '
'; + if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) { + print ''; + } + + if (!empty($object->lines)) { + $object->printObjectLines($action, $mysoc, null, GETPOSTINT('lineid'), 0, '/reception/tpl'); + } + + // Form to add new line + if ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines') { + if ($action != 'editline') { + // Add products/services form + + $parameters = array(); + $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } + if (empty($reshook)) { + $object->formAddObjectLine(0, $mysoc, $soc); + } + } + } + + if (!empty($object->lines) || ($object->status == Reception::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) { + print '
'; + } + print '
'; + + print "
\n"; + } + } elseif (!empty($object->origin) && $object->origin_id > 0) { + // Lines of products of origin + if ($action == 'editline') { + print '
+ + + + '; + } + print '

'; + + print '
'; + print ''; + print ''; + print ''; + // # + if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) { + print ''; + } + // Product/Service + print ''; + // Comment + print ''; + // Qty + print ''; + if ($origin && $origin_id > 0) { + print ''; + } + + $editColspan = 3; + if ($action == 'editline') { + if (!isModEnabled('stock')) { + $editColspan--; + } + if (empty($conf->productbatch->enabled)) { + $editColspan--; + } + print ''; + } else { + $statusreceived = $object::STATUS_CLOSED; + if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION")) { + $statusreceived = $object::STATUS_VALIDATED; + } + if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION_CLOSE")) { + $statusreceived = $object::STATUS_CLOSED; + } + if ($object->statut < $statusreceived) { + print ''; + } else { + print ''; + } + if (isModEnabled('stock')) { + print ''; + } + + if (isModEnabled('productbatch')) { + print ''; + } + } + print ''; + print ''; + //print ''; + if ($object->statut == 0) { + print ''; + print ''; + } + print "\n"; + print ''; + + $var = false; + + $outputlangs = $langs; + if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) { + $object->fetch_thirdparty(); + $newlang = ''; + if (/* empty($newlang) && */ GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if (empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + } + + // Get list of products already sent for same source object into $alreadysent + $alreadysent = array(); + + //$origin = 'commande_fournisseur'; + + if ($origin && $origin_id > 0) { + $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end"; + $sql .= ", ed.rowid as receptionline_id, ed.qty, ed.fk_reception as reception_id, ed.fk_entrepot"; + $sql .= ", e.rowid as reception_id, e.ref as reception_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_reception"; + //if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received"; + $sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch'; + $sql .= ', p.description as product_desc'; + $sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as ed"; + $sql .= ", ".MAIN_DB_PREFIX."reception as e"; + $sql .= ", ".MAIN_DB_PREFIX.$origin."det as obj"; + //if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.fk_reception = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."deliverydet as ld ON ld.fk_delivery = l.rowid AND obj.rowid = ld.fk_origin_line"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid"; + $sql .= " WHERE e.entity IN (".getEntity('reception').")"; + $sql .= " AND obj.fk_commande = ".((int) $origin_id); + $sql .= " AND obj.rowid = ed.fk_elementdet"; + $sql .= " AND ed.fk_reception = e.rowid"; + $sql .= " AND ed.fk_reception !=".((int) $object->id); + //if ($filter) $sql.= $filter; + $sql .= " ORDER BY obj.fk_product"; + + dol_syslog("get list of reception lines", LOG_DEBUG); + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + + while ($i < $num) { + $obj = $db->fetch_object($resql); + if ($obj) { + // $obj->rowid is rowid in $origin."det" table + $alreadysent[$obj->rowid][$obj->receptionline_id] = array('reception_ref' => $obj->reception_ref, 'reception_id' => $obj->reception_id, 'warehouse' => $obj->fk_entrepot, 'qty' => $obj->qty, 'date_valid' => $obj->date_valid, 'date_delivery' => $obj->date_delivery); + } + $i++; + } + } + //var_dump($alreadysent); + } + + $arrayofpurchaselinealreadyoutput = array(); + + // Loop on each product to send/sent. Warning: $lines must be sorted by ->fk_commandefourndet (it is a regroupment key on output) + print ''; + for ($i = 0; $i < $num_prod; $i++) { + print ''; // id of order line + print ''; + + // # + if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) { + print ''; + } + + // Predefined product or service + if ($lines[$i]->fk_product > 0) { + // Define output language + if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) { + $prod = new Product($db); + $prod->fetch($lines[$i]->fk_product); + $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product->label; + } else { + $label = (!empty($lines[$i]->product->label) ? $lines[$i]->product->label : $lines[$i]->product->product_label); + } + + print '\n"; + } else { + print '\n"; + } + + if ($action == 'editline' && $lines[$i]->id == $line_id) { + print ''; + } else { + print ''; + } + + + // Qty ordered + print ''; + + // Qty in other receptions (with reception and warehouse used) + if ($origin && $origin_id > 0) { + print ''; + } + + if ($action == 'editline' && $lines[$i]->id == $line_id) { + // edit mode + print ''; + } else { + // Qty to receive or received + print ''; + + // Warehouse source + if (isModEnabled('stock')) { + if ($lines[$i]->fk_entrepot > 0) { + $entrepot = new Entrepot($db); + $entrepot->fetch($lines[$i]->fk_entrepot); + + print ''; + } else { + print ''; + } + } + + // Batch number management + if (isModEnabled('productbatch')) { + if (isset($lines[$i]->batch)) { + print ''; + print ''; + } else { + print ''; + } + } + } + + // Weight + print ''; + + // Volume + print ''; + + + if ($action == 'editline' && $lines[$i]->id == $line_id) { + print ''; + } elseif ($object->statut == Reception::STATUS_DRAFT) { + // edit-delete buttons + print ''; + print ''; + + // Display lines extrafields + if (isset($rowExtrafieldsStart, $rowExtrafieldsView, $rowEnd)) { // @phan-suppress-current-line PhanPluginUndeclaredVariableIsset + print $rowExtrafieldsStart; + print $rowExtrafieldsView; + print $rowEnd; + } + } + print ""; + + $arrayofpurchaselinealreadyoutput[$lines[$i]->fk_commandefourndet] = $lines[$i]->fk_commandefourndet; + + // Display lines extrafields + $extralabelslines = $extrafields->attributes[$lines[$i]->table_element]; + if (!empty($extralabelslines) && is_array($extralabelslines) && count($extralabelslines) > 0) { + $colspan = 8; + if (isModEnabled('stock')) { + $colspan++; + } + if (isModEnabled('productbatch')) { + $colspan++; + } + + $line = new CommandeFournisseurDispatch($db); + $line->id = $lines[$i]->id; + $line->fetch_optionals(); + + if ($action == 'editline' && $lines[$i]->id == $line_id) { + print $line->showOptionals($extrafields, 'edit', array('colspan' => $colspan), ''); + } else { + print $line->showOptionals($extrafields, 'view', array('colspan' => $colspan), ''); + } + } + } + print ''; + + // TODO Show also lines ordered but not delivered + + print "
 '.$langs->trans("Products").''.$langs->trans("Comment").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyInOtherReceptions").''; + if ($object->statut <= 1) { + print $langs->trans("QtyToReceive").' - '; + } else { + print $langs->trans("QtyReceived").' - '; + } + if (isModEnabled('stock')) { + print $langs->trans("WarehouseTarget").' - '; + } + if (isModEnabled('productbatch')) { + print $langs->trans("Batch"); + } + print ''.$langs->trans("QtyToReceive").''.$langs->trans("QtyReceived").''.$langs->trans("WarehouseTarget").''.$langs->trans("Batch").''.$langs->trans("CalculatedWeight").''.$langs->trans("CalculatedVolume").''.$langs->trans("Size").'
'.($i + 1).''; + if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) { + $text = $lines[$i]->product->getNomUrl(1); + $text .= ' - '.$label; + $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($lines[$i]->product->description)); + print $form->textwithtooltip($text, $description, 3, 0, '', (string) $i); + print_date_range(!empty($lines[$i]->date_start) ? $lines[$i]->date_start : 0, !empty($lines[$i]->date_end) ? $lines[$i]->date_end : 0); + if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) { + print (!empty($lines[$i]->product->description) && $lines[$i]->description != $lines[$i]->product->description) ? '
'.dol_htmlentitiesbr($lines[$i]->description) : ''; + } + } + print "
'; + if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) { + if ($lines[$i]->product_type == Product::TYPE_SERVICE) { + $text = img_object($langs->trans('Service'), 'service'); + } else { + $text = img_object($langs->trans('Product'), 'product'); + } + + if (!empty($lines[$i]->label)) { + $text .= ' '.$lines[$i]->label.''; + print $form->textwithtooltip($text, $lines[$i]->description, 3, 0, '', (string) $i); + } else { + print $text.' '.nl2br($lines[$i]->description); + } + + print_date_range($lines[$i]->date_start, $lines[$i]->date_end); + } + print "'.dol_escape_htmltag($lines[$i]->comment).''; + if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) { + print $lines[$i]->qty_asked; + } + print ''; + $htmltooltip = ''; + $qtyalreadyreceived = 0; + if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) { + foreach ($alreadysent as $key => $val) { + if ($lines[$i]->fk_commandefourndet == $key) { + $j = 0; + foreach ($val as $receptionline_id => $receptionline_var) { + if ($receptionline_var['reception_id'] == $lines[$i]->fk_reception) { + continue; // We want to show only "other receptions" + } + + $j++; + if ($j > 1) { + $htmltooltip .= '
'; + } + $reception_static->fetch($receptionline_var['reception_id']); + $htmltooltip .= $reception_static->getNomUrl(1, 'nolink', 0, 0, 1); + $htmltooltip .= ' - '.$receptionline_var['qty']; + + $htmltext = $langs->trans("DateValidation").' : '.(empty($receptionline_var['date_valid']) ? $langs->trans("Draft") : dol_print_date($receptionline_var['date_valid'], 'dayhour')); + if (isModEnabled('stock') && $receptionline_var['warehouse'] > 0) { + $warehousestatic->fetch($receptionline_var['warehouse']); + $htmltext .= '
'.$langs->trans("From").' : '.$warehousestatic->getNomUrl(1, '', 0, 1); + } + $htmltooltip .= ' '.$form->textwithpicto('', $htmltext, 1); + + $qtyalreadyreceived += $receptionline_var['qty']; + } + if ($j) { + $htmltooltip = $langs->trans("QtyInOtherReceptions").'...

'.$htmltooltip.'
'; + } + } + } + } + print $form->textwithpicto((string) $qtyalreadyreceived, $htmltooltip, 1, 'info', '', 0, 3, 'tooltip'.$lines[$i]->id); + print '
'; + if (isModEnabled('stock')) { + if ($lines[$i]->fk_product > 0) { + print ''; + print ''; + // Qty to receive or received + print ''; + // Warehouse source + print ''; + // Batch number management + if ($conf->productbatch->enabled && !empty($lines[$i]->product->status_batch)) { + print ''; + } + print ''; + } else { + print ''; + print ''; + // Qty to receive or received + print ''; + // Warehouse source + print ''; + // Batch number management + print ''; + print ''; + } + } + print '
'.$formproduct->selectWarehouses($lines[$i]->fk_entrepot, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).'
'; + if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { + print $langs->trans('SellByDate').' : '; + print $form->selectDate($lines[$i]->sellby, 'dlc'.$line_id, 0, 0, 1, "").'
'; + } + if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { + print $langs->trans('EatByDate').' : '; + print $form->selectDate($lines[$i]->eatby, 'dluo'.$line_id, 0, 0, 1, ""); + } + print '
'.$lines[$i]->qty.''; + print $entrepot->getNomUrl(1); + print ''; + $detail = $langs->trans("NA"); + if ($lines[$i]->product->status_batch > 0 && $lines[$i]->fk_product > 0) { + require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; + $productlot = new Productlot($db); + $reslot = $productlot->fetch(0, $lines[$i]->fk_product, $lines[$i]->batch); + if ($reslot > 0) { + $detail = $productlot->getNomUrl(1); + } else { + // lot is not created and info is only in reception lines + $batchinfo = $langs->trans("Batch").': '.$lines[$i]->batch; + if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) { + $batchinfo .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($lines[$i]->sellby, "day"); + } + if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) { + $batchinfo .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($lines[$i]->eatby, "day"); + } + $detail = $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"), $batchinfo); + } + } + print $detail . ''; + if (!empty($lines[$i]->fk_product_type) && $lines[$i]->fk_product_type == Product::TYPE_PRODUCT) { + print $lines[$i]->product->weight * $lines[$i]->qty.' '.measuringUnitString(0, "weight", $lines[$i]->product->weight_units); + } else { + print ' '; + } + print ''; + if (!empty($lines[$i]->fk_product_type) && $lines[$i]->fk_product_type == Product::TYPE_PRODUCT) { + print $lines[$i]->product->volume * $lines[$i]->qty.' '.measuringUnitString(0, "volume", $lines[$i]->product->volume_units); + } else { + print ' '; + } + print ''; + print '
'; + print '
'; + print '
'; + print 'id.'">'.img_edit().''; + print ''; + print 'id.'">'.img_delete().''; + print '
\n"; + print '
'; + + + print dol_get_fiche_end(); + + + $object->fetchObjectLinked($object->id, $object->element); + } /* - * Boutons actions + * Button actions */ if (($user->socid == 0) && ($action != 'presend')) { @@ -2185,7 +2821,7 @@ if ($action == 'create') { print ''.$langs->trans("ReOpen").''; } - // Send + // Send mail if (empty($user->socid)) { if ($object->statut > 0) { if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('reception', 'reception_advance', 'send')) { @@ -2197,7 +2833,7 @@ if ($action == 'create') { } // Create bill - if (isModEnabled("supplier_invoice") && ($object->statut == Reception::STATUS_VALIDATED || $object->statut == Reception::STATUS_CLOSED)) { + if (isModEnabled("supplier_invoice") && ($object->statut == Reception::STATUS_VALIDATED || $object->statut == Reception::STATUS_CLOSED) && !getDolGlobalString('RECEPTION_STANDALONE')) { if ($user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight('supplier_invoice', 'creer')) { if (getDolGlobalString('WORKFLOW_BILL_ON_RECEPTION') !== '0') { print ''.$langs->trans("CreateBill").'';