12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544 |
- <?php
- /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
- * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
- * Copyright (C) 2018-2022 Ferran Marcet <fmarcet@2byte.es>
- * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
- *
- * 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
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/product/stock/movement_list.php
- * \ingroup stock
- * \brief Page to list stock movements
- */
- require '../../main.inc.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
- require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
- require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
- require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
- require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
- require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
- if (!empty($conf->projet->enabled)) {
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
- require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
- }
- // Load translation files required by the page
- $langs->loadLangs(array('products', 'stocks', 'orders'));
- if (!empty($conf->productbatch->enabled)) {
- $langs->load("productbatch");
- }
- $id = GETPOST('id', 'int');
- $ref = GETPOST('ref', 'alpha');
- $msid = GETPOST('msid', 'int');
- $product_id = GETPOST("product_id", 'int');
- $action = GETPOST('action', 'aZ09');
- $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
- $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
- $cancel = GETPOST('cancel', 'alpha');
- $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'movementlist';
- $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
- $idproduct = GETPOST('idproduct', 'int');
- $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
- $search_date_startday = GETPOST('search_date_startday', 'int');
- $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
- $search_date_startyear = GETPOST('search_date_startyear', 'int');
- $search_date_endday = GETPOST('search_date_endday', 'int');
- $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
- $search_date_endyear = GETPOST('search_date_endyear', 'int');
- $search_date_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int'), 'tzuserrel');
- $search_date_end = dol_mktime(23, 59, 59, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int'), 'tzuserrel');
- $search_ref = GETPOST('search_ref', 'alpha');
- $search_movement = GETPOST("search_movement");
- $search_product_ref = trim(GETPOST("search_product_ref"));
- $search_product = trim(GETPOST("search_product"));
- $search_warehouse = trim(GETPOST("search_warehouse"));
- $search_inventorycode = trim(GETPOST("search_inventorycode"));
- $search_user = trim(GETPOST("search_user"));
- $search_batch = trim(GETPOST("search_batch"));
- $search_qty = trim(GETPOST("search_qty"));
- $search_type_mouvement = GETPOST('search_type_mouvement', 'int');
- $search_fk_projet=GETPOST("search_fk_projet", 'int');
- $optioncss = GETPOST('optioncss', 'alpha');
- $type = GETPOST("type", "int");
- // Load variable for pagination
- $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
- $sortfield = GETPOST('sortfield', 'aZ09comma');
- $sortorder = GETPOST('sortorder', 'aZ09comma');
- $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
- if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
- // If $page is not defined, or '' or -1 or if we click on clear filters
- $page = 0;
- }
- $offset = $limit * $page;
- $pageprev = $page - 1;
- $pagenext = $page + 1;
- if (!$sortfield) {
- $sortfield = "m.datem";
- }
- if (!$sortorder) {
- $sortorder = "DESC";
- }
- $pdluoid = GETPOST('pdluoid', 'int');
- // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
- $object = new MouvementStock($db);
- $extrafields = new ExtraFields($db);
- $diroutputmassaction = $conf->stock->dir_output.'/temp/massgeneration/'.$user->id;
- $hookmanager->initHooks(array('movementlist'));
- $formfile = new FormFile($db);
- // fetch optionals attributes and labels
- $extrafields->fetch_name_optionals_label($object->table_element);
- $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
- $arrayfields = array(
- 'm.rowid'=>array('label'=>"Ref", 'checked'=>1, 'position'=>1),
- 'm.datem'=>array('label'=>"Date", 'checked'=>1, 'position'=>2),
- 'p.ref'=>array('label'=>"ProductRef", 'checked'=>1, 'css'=>'maxwidth100', 'position'=>3),
- 'p.label'=>array('label'=>"ProductLabel", 'checked'=>0, 'position'=>5),
- 'm.batch'=>array('label'=>"BatchNumberShort", 'checked'=>1, 'position'=>8, 'enabled'=>(!empty($conf->productbatch->enabled))),
- 'pl.eatby'=>array('label'=>"EatByDate", 'checked'=>0, 'position'=>9, 'enabled'=>(!empty($conf->productbatch->enabled))),
- 'pl.sellby'=>array('label'=>"SellByDate", 'checked'=>0, 'position'=>10, 'enabled'=>(!empty($conf->productbatch->enabled))),
- 'e.ref'=>array('label'=>"Warehouse", 'checked'=>1, 'position'=>100, 'enabled'=>(!$id > 0)), // If we are on specific warehouse, we hide it
- 'm.fk_user_author'=>array('label'=>"Author", 'checked'=>0, 'position'=>120),
- 'm.inventorycode'=>array('label'=>"InventoryCodeShort", 'checked'=>1, 'position'=>130),
- 'm.label'=>array('label'=>"MovementLabel", 'checked'=>1, 'position'=>140),
- 'm.type_mouvement'=>array('label'=>"TypeMovement", 'checked'=>0, 'position'=>150),
- 'origin'=>array('label'=>"Origin", 'checked'=>1, 'position'=>155),
- 'm.fk_projet'=>array('label'=>'Project', 'checked'=>0, 'position'=>180),
- 'm.value'=>array('label'=>"Qty", 'checked'=>1, 'position'=>200),
- 'm.price'=>array('label'=>"UnitPurchaseValue", 'checked'=>0, 'position'=>210, 'enabled'=>empty($conf->global->STOCK_MOVEMENT_LIST_HIDE_UNIT_PRICE))
- //'m.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
- //'m.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500)
- );
- include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
- if (!empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
- unset($arrayfields['pl.sellby']);
- }
- if (!empty($conf->global->PRODUCT_DISABLE_EATBY)) {
- unset($arrayfields['pl.eatby']);
- }
- $tmpwarehouse = new Entrepot($db);
- if ($id > 0 || !empty($ref)) {
- $tmpwarehouse->fetch($id, $ref);
- $id = $tmpwarehouse->id;
- }
- // Security check
- //$result=restrictedArea($user, 'stock', $id, 'entrepot&stock');
- $result = restrictedArea($user, 'stock');
- // Security check
- if (!$user->rights->stock->mouvement->lire) {
- accessforbidden();
- }
- $uploaddir = $conf->stock->dir_output.'/movements';
- $permissiontoread = $user->rights->stock->mouvement->lire;
- $permissiontoadd = $user->rights->stock->mouvement->creer;
- $permissiontodelete = $user->rights->stock->mouvement->creer; // There is no deletion permission for stock movement as we shoul dnever delete
- $usercanread = $user->rights->stock->mouvement->lire;
- $usercancreate = $user->rights->stock->mouvement->creer;
- $usercandelete = $user->rights->stock->mouvement->creer;
- $error = 0;
- /*
- * Actions
- */
- if (GETPOST('cancel', 'alpha')) {
- $action = 'list';
- $massaction = '';
- }
- if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
- $massaction = '';
- }
- $parameters = array();
- $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
- if ($reshook < 0) {
- setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
- }
- if (empty($reshook)) {
- // Selection of new fields
- include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
- // Purge search criteria
- if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
- $search_date_startday = '';
- $search_date_startmonth = '';
- $search_date_startyear = '';
- $search_date_endday = '';
- $search_date_endmonth = '';
- $search_date_endyear = '';
- $search_date_start = '';
- $search_date_end = '';
- $search_ref = '';
- $search_movement = "";
- $search_type_mouvement = "";
- $search_inventorycode = "";
- $search_product_ref = "";
- $search_product = "";
- $search_warehouse = "";
- $search_user = "";
- $search_batch = "";
- $search_qty = '';
- $search_fk_projet=0;
- $sall = "";
- $toselect = array();
- $search_array_options = array();
- }
- if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
- || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
- $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
- }
- // Mass actions
- $objectclass = 'MouvementStock';
- $objectlabel = 'MouvementStock';
- if (!$error && $massaction == "builddoc" && $permissiontoread && !GETPOST('button_search')) {
- if (empty($diroutputmassaction)) {
- dol_print_error(null, 'include of actions_massactions.inc.php is done but var $diroutputmassaction was not defined');
- exit;
- }
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
- $objecttmp = new $objectclass($db);
- $listofobjectid = array();
- foreach ($toselect as $toselectid) {
- $objecttmp = new $objectclass($db); // must create new instance because instance is saved into $listofobjectref array for future use
- $result = $objecttmp->fetch($toselectid);
- if ($result > 0) {
- $listofobjectid[$toselectid] = $toselectid;
- }
- }
- $arrayofinclusion = array();
- foreach ($listofobjectref as $tmppdf) {
- $arrayofinclusion[] = '^'.preg_quote(dol_sanitizeFileName($tmppdf), '/').'\.pdf$';
- }
- foreach ($listofobjectref as $tmppdf) {
- $arrayofinclusion[] = '^'.preg_quote(dol_sanitizeFileName($tmppdf), '/').'_[a-zA-Z0-9-_]+\.pdf$'; // To include PDF generated from ODX files
- }
- $listoffiles = dol_dir_list($uploaddir, 'all', 1, implode('|', $arrayofinclusion), '\.meta$|\.png', 'date', SORT_DESC, 0, true);
- // Define output language (Here it is not used because we do only merging existing PDF)
- $outputlangs = $langs;
- $newlang = '';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
- $newlang = GETPOST('lang_id', 'aZ09');
- }
- //elseif ($conf->global->MAIN_MULTILANGS && empty($newlang) && is_object($objecttmp->thirdparty)) { // On massaction, we can have several values for $objecttmp->thirdparty
- // $newlang = $objecttmp->thirdparty->default_lang;
- //}
- if (!empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- // Create output dir if not exists
- dol_mkdir($diroutputmassaction);
- // Defined name of merged file
- $filename = strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
- $filename = preg_replace('/\s/', '_', $filename);
- // Save merged file
- /*
- if ($year) {
- $filename .= '_'.$year;
- }
- if ($month) {
- $filename .= '_'.$month;
- }
- */
- $now = dol_now();
- $file = $diroutputmassaction.'/'.$filename.'_'.dol_print_date($now, 'dayhourlog').'.pdf';
- // Create PDF
- // TODO Create the pdf including list of movement ids found into $listofobjectid
- // ...
- if (!$error) {
- $langs->load("exports");
- setEventMessages($langs->trans('FileSuccessfullyBuilt', $filename.'_'.dol_print_date($now, 'dayhourlog')), null, 'mesgs');
- }
- $massaction = '';
- $action = '';
- }
- include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
- }
- if ($action == 'update_extras') {
- $tmpwarehouse->oldcopy = dol_clone($tmpwarehouse);
- // Fill array 'array_options' with data from update form
- $ret = $extrafields->setOptionalsFromPost(null, $tmpwarehouse, GETPOST('attribute', 'restricthtml'));
- if ($ret < 0) {
- $error++;
- }
- if (!$error) {
- $result = $tmpwarehouse->insertExtraFields();
- if ($result < 0) {
- setEventMessages($tmpwarehouse->error, $tmpwarehouse->errors, 'errors');
- $error++;
- }
- }
- if ($error) {
- $action = 'edit_extras';
- }
- }
- // Correct stock
- if ($action == "correct_stock") {
- $product = new Product($db);
- if (!empty($product_id)) {
- $result = $product->fetch($product_id);
- }
- $error = 0;
- if (empty($product_id)) {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
- $action = 'correction';
- }
- if (!is_numeric(GETPOST("nbpiece"))) {
- $error++;
- setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
- $action = 'correction';
- }
- if (!$error) {
- $origin_element = '';
- $origin_id = null;
- if (GETPOST('projectid', 'int')) {
- $origin_element = 'project';
- $origin_id = GETPOST('projectid', 'int');
- }
- if ($product->hasbatch()) {
- $batch = GETPOST('batch_number', 'alphanohtml');
- //$eatby=GETPOST('eatby');
- //$sellby=GETPOST('sellby');
- $eatby = dol_mktime(0, 0, 0, GETPOST('eatbymonth', 'int'), GETPOST('eatbyday', 'int'), GETPOST('eatbyyear', 'int'));
- $sellby = dol_mktime(0, 0, 0, GETPOST('sellbymonth', 'int'), GETPOST('sellbyday', 'int'), GETPOST('sellbyyear', 'int'));
- $result = $product->correct_stock_batch(
- $user,
- $id,
- GETPOST("nbpiece", 'int'),
- GETPOST("mouvement", 'int'),
- GETPOST("label", 'alphanohtml'),
- price2num(GETPOST('unitprice'), 'MT'),
- $eatby,
- $sellby,
- $batch,
- GETPOST('inventorycode', 'alphanohtml'),
- $origin_element,
- $origin_id,
- 0,
- $extrafields
- ); // We do not change value of stock for a correction
- } else {
- $result = $product->correct_stock(
- $user,
- $id,
- GETPOST("nbpiece", 'int'),
- GETPOST("mouvement", "int"),
- GETPOST("label", 'alphanohtml'),
- price2num(GETPOST('unitprice'), 'MT'),
- GETPOST('inventorycode', 'alphanohtml'),
- $origin_element,
- $origin_id,
- 0,
- $extrafields
- ); // We do not change value of stock for a correction
- }
- if ($result > 0) {
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
- exit;
- } else {
- $error++;
- setEventMessages($product->error, $product->errors, 'errors');
- $action = 'correction';
- }
- }
- if (!$error) {
- $action = '';
- }
- }
- // Transfer stock from a warehouse to another warehouse
- if ($action == "transfert_stock" && !$cancel) {
- $product = new Product($db);
- if (!empty($product_id)) {
- $result = $product->fetch($product_id);
- }
- if (!(GETPOST("id_entrepot_destination", 'int') > 0)) {
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
- $error++;
- $action = 'transfert';
- }
- if (empty($product_id)) {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
- $action = 'transfert';
- }
- if (!GETPOST("nbpiece", 'int')) {
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumberOfUnit")), null, 'errors');
- $error++;
- $action = 'transfert';
- }
- if ($id == GETPOST("id_entrepot_destination", 'int')) {
- setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors');
- $error++;
- $action = 'transfert';
- }
- if (!empty($conf->productbatch->enabled)) {
- $product = new Product($db);
- $result = $product->fetch($product_id);
- if ($product->hasbatch() && !GETPOST("batch_number")) {
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("batch_number")), null, 'errors');
- $error++;
- $action = 'transfert';
- }
- }
- if (!$error) {
- if ($id) {
- $object = new Entrepot($db);
- $result = $object->fetch($id);
- $db->begin();
- $product->load_stock('novirtual'); // Load array product->stock_warehouse
- // Define value of products moved
- $pricesrc = 0;
- if (isset($product->pmp)) {
- $pricesrc = $product->pmp;
- }
- $pricedest = $pricesrc;
- if ($product->hasbatch()) {
- $pdluo = new Productbatch($db);
- if ($pdluoid > 0) {
- $result = $pdluo->fetch($pdluoid);
- if ($result) {
- $srcwarehouseid = $pdluo->warehouseid;
- $batch = $pdluo->batch;
- $eatby = $pdluo->eatby;
- $sellby = $pdluo->sellby;
- } else {
- setEventMessages($pdluo->error, $pdluo->errors, 'errors');
- $error++;
- }
- } else {
- $srcwarehouseid = $id;
- $batch = GETPOST('batch_number', 'alphanohtml');
- $eatby = $d_eatby;
- $sellby = $d_sellby;
- }
- if (!$error) {
- // Remove stock
- $result1 = $product->correct_stock_batch(
- $user,
- $srcwarehouseid,
- GETPOST("nbpiece", 'int'),
- 1,
- GETPOST("label", 'san_alpha'),
- $pricesrc,
- $eatby,
- $sellby,
- $batch,
- GETPOST('inventorycode'),
- '',
- null,
- 0,
- $extrafields
- );
- // Add stock
- $result2 = $product->correct_stock_batch(
- $user,
- GETPOST("id_entrepot_destination", 'int'),
- GETPOST("nbpiece", 'int'),
- 0,
- GETPOST("label", 'san_alpha'),
- $pricedest,
- $eatby,
- $sellby,
- $batch,
- GETPOST('inventorycode', 'alphanohtml'),
- '',
- null,
- 0,
- $extrafields
- );
- }
- } else {
- // Remove stock
- $result1 = $product->correct_stock(
- $user,
- $id,
- GETPOST("nbpiece"),
- 1,
- GETPOST("label", 'san_alpha'),
- $pricesrc,
- GETPOST('inventorycode', 'alphanohtml'),
- '',
- null,
- 0,
- $extrafields
- );
- // Add stock
- $result2 = $product->correct_stock(
- $user,
- GETPOST("id_entrepot_destination"),
- GETPOST("nbpiece"),
- 0,
- GETPOST("label", 'san_alpha'),
- $pricedest,
- GETPOST('inventorycode', 'alphanohtml'),
- '',
- null,
- 0,
- $extrafields
- );
- }
- if (!$error && $result1 >= 0 && $result2 >= 0) {
- $db->commit();
- if ($backtopage) {
- header("Location: ".$backtopage);
- exit;
- } else {
- header("Location: movement_list.php?id=".$object->id);
- exit;
- }
- } else {
- setEventMessages($product->error, $product->errors, 'errors');
- $db->rollback();
- $action = 'transfert';
- }
- }
- }
- }
- /*
- * View
- */
- $productlot = new ProductLot($db);
- $productstatic = new Product($db);
- $warehousestatic = new Entrepot($db);
- $movement = new MouvementStock($db);
- $userstatic = new User($db);
- $form = new Form($db);
- $formproduct = new FormProduct($db);
- if (!empty($conf->projet->enabled)) {
- $formproject = new FormProjets($db);
- }
- // Build and execute select
- // --------------------------------------------------------------------
- $sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.tosell, p.tobuy, p.tobatch, p.fk_product_type as type, p.entity,";
- $sql .= " e.ref as warehouse_ref, e.rowid as entrepot_id, e.lieu, e.fk_parent, e.statut,";
- $sql .= " m.rowid as mid, m.value as qty, m.datem, m.fk_user_author, m.label, m.inventorycode, m.fk_origin, m.origintype,";
- $sql .= " m.batch, m.price,";
- $sql .= " m.type_mouvement,";
- $sql .= " m.fk_projet as fk_project,";
- $sql .= " pl.rowid as lotid, pl.eatby, pl.sellby,";
- $sql .= " u.login, u.photo, u.lastname, u.firstname, u.email as user_email, u.statut as user_status";
- // Add fields from extrafields
- if (!empty($extrafields->attributes[$object->table_element]['label'])) {
- foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
- $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
- }
- }
- // Add fields from hooks
- $parameters = array();
- $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
- $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
- $sql = preg_replace('/,\s*$/', '', $sql);
- $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
- $sql .= " ".MAIN_DB_PREFIX."product as p,";
- $sql .= " ".MAIN_DB_PREFIX."stock_mouvement as m";
- if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (m.rowid = ef.fk_object)";
- }
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON m.batch = pl.batch AND m.fk_product = pl.fk_product";
- $sql .= " WHERE m.fk_product = p.rowid";
- if ($msid > 0) {
- $sql .= " AND m.rowid = ".((int) $msid);
- }
- $sql .= " AND m.fk_entrepot = e.rowid";
- $sql .= " AND e.entity IN (".getEntity('stock').")";
- if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
- $sql .= " AND p.fk_product_type = 0";
- }
- if ($id > 0) {
- $sql .= " AND e.rowid = ".((int) $id);
- }
- if (!empty($search_date_start)) {
- $sql .= " AND m.datem >= '" . $db->idate($search_date_start) . "'";
- }
- if (!empty($search_date_end)) {
- $sql .= " AND m.datem <= '" . $db->idate($search_date_end) . "'";
- }
- if ($idproduct > 0) {
- $sql .= " AND p.rowid = ".((int) $idproduct);
- }
- if (!empty($search_ref)) {
- $sql .= natural_search('m.rowid', $search_ref, 1);
- }
- if (!empty($search_movement)) {
- $sql .= natural_search('m.label', $search_movement);
- }
- if (!empty($search_inventorycode)) {
- $sql .= natural_search('m.inventorycode', $search_inventorycode);
- }
- if (!empty($search_product_ref)) {
- $sql .= natural_search('p.ref', $search_product_ref);
- }
- if (!empty($search_product)) {
- $sql .= natural_search('p.label', $search_product);
- }
- if ($search_warehouse != '' && $search_warehouse != '-1') {
- $sql .= natural_search('e.rowid', $search_warehouse, 2);
- }
- if (!empty($search_user)) {
- $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_user);
- }
- if (!empty($search_batch)) {
- $sql .= natural_search('m.batch', $search_batch);
- }
- if (!empty($product_id) && $product_id != '-1') {
- $sql .= natural_search('p.rowid', $product_id);
- }
- if (!empty($search_fk_projet) && $search_fk_projet != '-1') {
- $sql .= natural_search('m.fk_projet', $search_fk_projet);
- }
- if ($search_qty != '') {
- $sql .= natural_search('m.value', $search_qty, 1);
- }
- if ($search_type_mouvement != '' && $search_type_mouvement != '-1') {
- $sql .= natural_search('m.type_mouvement', $search_type_mouvement, 2);
- }
- // Add where from extra fields
- include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
- // Add where from hooks
- $parameters = array();
- $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
- $sql .= $hookmanager->resPrint;
- /* If a group by is required
- $sql .= " GROUP BY ";
- foreach($object->fields as $key => $val) {
- $sql .= "t.".$key.", ";
- }
- // Add fields from extrafields
- if (!empty($extrafields->attributes[$object->table_element]['label'])) {
- foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
- $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
- }
- }
- // Add where from hooks
- $parameters = array();
- $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
- $sql .= $hookmanager->resPrint;
- $sql = preg_replace('/,\s*$/', '', $sql);
- */
- // Add HAVING from hooks
- /*
- $parameters = array();
- $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
- $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
- */
- // Count total nb of records
- $nbtotalofrecords = '';
- if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
- /* This old and fast method to get and count full list returns all record so use a high amount of memory.
- $resql = $db->query($sql);
- $nbtotalofrecords = $db->num_rows($resql);
- */
- /* The slow method does not consume memory on mysql (not tested on pgsql) */
- /*$resql = $db->query($sql, 0, 'auto', 1);
- while ($db->fetch_object($resql)) {
- $nbtotalofrecords++;
- }*/
- /* The fast and low memory method to get and count full list converts the sql into a sql count */
- $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
- $resql = $db->query($sqlforcount);
- $objforcount = $db->fetch_object($resql);
- $nbtotalofrecords = $objforcount->nbtotalofrecords;
- if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
- $page = 0;
- $offset = 0;
- }
- $db->free($resql);
- }
- // Complete request and execute it with limit
- $sql .= $db->order($sortfield, $sortorder);
- if ($limit) {
- $sql .= $db->plimit($limit + 1, $offset);
- }
- $resql = $db->query($sql);
- if (!$resql) {
- dol_print_error($db);
- exit;
- }
- $product = new Product($db);
- $object = new Entrepot($db);
- if ($idproduct > 0) {
- $product->fetch($idproduct);
- }
- if ($id > 0 || $ref) {
- $result = $object->fetch($id, $ref);
- if ($result < 0) {
- dol_print_error($db);
- }
- }
- $num = $db->num_rows($resql);
- // Output page
- // --------------------------------------------------------------------
- $i = 0;
- $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks';
- if ($msid) {
- $title = $langs->trans('StockMovementForId', $msid);
- } else {
- $title = $langs->trans("ListOfStockMovements");
- if ($id) {
- $title .= ' ('.$langs->trans("ForThisWarehouse").')';
- }
- }
- llxHeader('', $title, $help_url);
- $arrayofselected = is_array($toselect) ? $toselect : array();
- /*
- * Show tab only if we ask a particular warehouse
- */
- if ($object->id > 0) {
- $head = stock_prepare_head($object);
- print dol_get_fiche_head($head, 'movements', $langs->trans("Warehouse"), -1, 'stock');
- $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
- $morehtmlref = '<div class="refidno">';
- $morehtmlref .= $langs->trans("LocationSummary").' : '.$object->lieu;
- // Project
- if (!empty($conf->projet->enabled)) {
- $langs->load("projects");
- $morehtmlref .= '<br>'.img_picto('', 'project').' '.$langs->trans('Project').' ';
- if ($usercancreate && 1 == 2) {
- if ($action != 'classify') {
- $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
- }
- if ($action == 'classify') {
- $projectid = $object->fk_project;
- $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
- $morehtmlref .= '<input type="hidden" name="action" value="classin">';
- $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
- $morehtmlref .= $formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500');
- $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
- $morehtmlref .= '</form>';
- } else {
- $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
- }
- } else {
- if (!empty($object->fk_project)) {
- $proj = new Project($db);
- $proj->fetch($object->fk_project);
- $morehtmlref .= ' : '.$proj->getNomUrl(1);
- if ($proj->title) {
- $morehtmlref .= ' - '.$proj->title;
- }
- } else {
- $morehtmlref .= '';
- }
- }
- }
- $morehtmlref .= '</div>';
- $shownav = 1;
- if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
- $shownav = 0;
- }
- dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref);
- print '<div class="fichecenter">';
- print '<div class="fichehalfleft">';
- print '<div class="underbanner clearboth"></div>';
- print '<table class="border centpercent tableforfield">';
- print '<tr>';
- // Description
- print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>'.dol_htmlentitiesbr($object->description).'</td></tr>';
- $calcproductsunique = $object->nb_different_products();
- $calcproducts = $object->nb_products();
- // Total nb of different products
- print '<tr><td>'.$langs->trans("NumberOfDifferentProducts").'</td><td>';
- print empty($calcproductsunique['nb']) ? '0' : $calcproductsunique['nb'];
- print "</td></tr>";
- // Nb of products
- print '<tr><td>'.$langs->trans("NumberOfProducts").'</td><td>';
- $valtoshow = price2num($calcproducts['nb'], 'MS');
- print empty($valtoshow) ? '0' : $valtoshow;
- print "</td></tr>";
- print '</table>';
- print '</div>';
- print '<div class="fichehalfright">';
- print '<div class="underbanner clearboth"></div>';
- print '<table class="border centpercent tableforfield">';
- // Value
- print '<tr><td class="titlefield">'.$langs->trans("EstimatedStockValueShort").'</td><td>';
- print price((empty($calcproducts['value']) ? '0' : price2num($calcproducts['value'], 'MT')), 0, $langs, 0, -1, -1, $conf->currency);
- print "</td></tr>";
- // Last movement
- $sql = "SELECT MAX(m.datem) as datem";
- $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
- $sql .= " WHERE m.fk_entrepot = ".((int) $object->id);
- $resqlbis = $db->query($sql);
- if ($resqlbis) {
- $objbis = $db->fetch_object($resqlbis);
- $lastmovementdate = $db->jdate($objbis->datem);
- } else {
- dol_print_error($db);
- }
- print '<tr><td>'.$langs->trans("LastMovement").'</td><td>';
- if ($lastmovementdate) {
- print dol_print_date($lastmovementdate, 'dayhour');
- } else {
- print $langs->trans("None");
- }
- print "</td></tr>";
- // Other attributes
- include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
- // Categories
- if ($conf->categorie->enabled) {
- print '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td colspan="3">';
- print $form->showCategories($object->id, Categorie::TYPE_WAREHOUSE, 1);
- print "</td></tr>";
- }
- print "</table>";
- print '</div>';
- print '</div>';
- print '<div class="clearboth"></div>';
- print dol_get_fiche_end();
- }
- // Correct stock
- if ($action == "correction") {
- include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php';
- print '<br>';
- }
- // Transfer of units
- if ($action == "transfert") {
- include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php';
- print '<br>';
- }
- // Action bar
- if ((empty($action) || $action == 'list') && $id > 0) {
- print "<div class=\"tabsAction\">\n";
- if ($user->rights->stock->mouvement->creer) {
- print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=correction">'.$langs->trans("CorrectStock").'</a>';
- }
- if ($user->rights->stock->mouvement->creer) {
- print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&action=transfert">'.$langs->trans("TransferStock").'</a>';
- }
- print '</div><br>';
- }
- $param = '';
- if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
- $param .= '&contextpage='.urlencode($contextpage);
- }
- if ($limit > 0 && $limit != $conf->liste_limit) {
- $param .= '&limit='.urlencode($limit);
- }
- if ($id > 0) {
- $param .= '&id='.urlencode($id);
- }
- if ($search_date_startday) {
- $param .= '&search_date_startday='.urlencode($search_date_startday);
- }
- if ($search_date_startmonth) {
- $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
- }
- if ($search_date_startyear) {
- $param .= '&search_date_startyear='.urlencode($search_date_startyear);
- }
- if ($search_date_endday) {
- $param .= '&search_date_endday='.urlencode($search_date_endday);
- }
- if ($search_date_endmonth) {
- $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
- }
- if ($search_date_endyear) {
- $param .= '&search_date_endyear='.urlencode($search_date_endyear);
- }
- if ($search_movement) {
- $param .= '&search_movement='.urlencode($search_movement);
- }
- if ($search_inventorycode) {
- $param .= '&search_inventorycode='.urlencode($search_inventorycode);
- }
- if ($search_type_mouvement) {
- $param .= '&search_type_mouvement='.urlencode($search_type_mouvement);
- }
- if ($search_product_ref) {
- $param .= '&search_product_ref='.urlencode($search_product_ref);
- }
- if ($search_product) {
- $param .= '&search_product='.urlencode($search_product);
- }
- if ($search_batch) {
- $param .= '&search_batch='.urlencode($search_batch);
- }
- if ($search_warehouse > 0) {
- $param .= '&search_warehouse='.urlencode($search_warehouse);
- }
- if ($search_user) {
- $param .= '&search_user='.urlencode($search_user);
- }
- if ($idproduct > 0) {
- $param .= '&idproduct='.urlencode($idproduct);
- }
- // Add $param from extra fields
- include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
- // List of mass actions available
- $arrayofmassactions = array();
- if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
- $arrayofmassactions['builddoc'] = img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("GeneratePDF");
- }
- // By default, we should never accept deletion of stock movement
- if (!empty($conf->global->STOCK_ALLOW_DELETE_OF_MOVEMENT) && $permissiontodelete) {
- $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
- }
- if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
- $arrayofmassactions = array();
- }
- $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
- print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
- if ($optioncss != '') {
- print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
- }
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
- print '<input type="hidden" name="action" value="list">';
- print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
- print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
- print '<input type="hidden" name="type" value="'.$type.'">';
- print '<input type="hidden" name="page" value="'.$page.'">';
- print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
- if ($id > 0) {
- print '<input type="hidden" name="id" value="'.$id.'">';
- }
- if ($id > 0) {
- print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'movement', 0, '', '', $limit, 0, 0, 1);
- } else {
- print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'movement', 0, '', '', $limit, 0, 0, 1);
- }
- // Add code for pre mass action (confirmation or email presend form)
- $topicmail = "SendStockMovement";
- $modelmail = "movementstock";
- $objecttmp = new MouvementStock($db);
- $trackid = 'mov'.$object->id;
- include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
- if ($sall) {
- foreach ($fieldstosearchall as $key => $val) {
- $fieldstosearchall[$key] = $langs->trans($val);
- }
- print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
- }
- $moreforfilter = '';
- $parameters = array('arrayfields'=>&$arrayfields);
- $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
- if (empty($reshook)) {
- $moreforfilter .= $hookmanager->resPrint;
- } else {
- $moreforfilter = $hookmanager->resPrint;
- }
- if (!empty($moreforfilter)) {
- print '<div class="liste_titre liste_titre_bydiv centpercent">';
- print $moreforfilter;
- print '</div>';
- }
- $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
- $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
- $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
- print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
- print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
- // Fields title search
- // --------------------------------------------------------------------
- print '<tr class="liste_titre">';
- if (!empty($arrayfields['m.rowid']['checked'])) {
- // Ref
- print '<td class="liste_titre left">';
- print '<input class="flat maxwidth25" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
- print '</td>';
- }
- if (! empty($arrayfields['m.datem']['checked'])) {
- // Date
- print '<td class="liste_titre center">';
- print '<div class="nowrap">';
- print $form->selectDate($search_date_start?$search_date_start:-1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'), 'tzuserrel');
- print '</div>';
- print '<div class="nowrap">';
- print $form->selectDate($search_date_end?$search_date_end:-1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'), 'tzuserrel');
- print '</div>';
- print '</td>';
- }
- if (!empty($arrayfields['p.ref']['checked'])) {
- // Product Ref
- print '<td class="liste_titre left">';
- print '<input class="flat maxwidth75" type="text" name="search_product_ref" value="'.dol_escape_htmltag($idproduct ? $product->ref : $search_product_ref).'">';
- print '</td>';
- }
- if (!empty($arrayfields['p.label']['checked'])) {
- // Product label
- print '<td class="liste_titre left">';
- print '<input class="flat maxwidth100" type="text" name="search_product" value="'.dol_escape_htmltag($idproduct ? $product->label : $search_product).'">';
- print '</td>';
- }
- // Batch
- if (!empty($arrayfields['m.batch']['checked'])) {
- print '<td class="liste_titre center"><input class="flat maxwidth75" type="text" name="search_batch" value="'.dol_escape_htmltag($search_batch).'"></td>';
- }
- if (!empty($arrayfields['pl.eatby']['checked'])) {
- print '<td class="liste_titre left">';
- print '</td>';
- }
- if (!empty($arrayfields['pl.sellby']['checked'])) {
- print '<td class="liste_titre left">';
- print '</td>';
- }
- // Warehouse
- if (!empty($arrayfields['e.ref']['checked'])) {
- print '<td class="liste_titre maxwidthonsmartphone left">';
- //print '<input class="flat" type="text" size="8" name="search_warehouse" value="'.($search_warehouse).'">';
- print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200');
- print '</td>';
- }
- if (!empty($arrayfields['m.fk_user_author']['checked'])) {
- // Author
- print '<td class="liste_titre left">';
- print '<input class="flat" type="text" size="6" name="search_user" value="'.dol_escape_htmltag($search_user).'">';
- print '</td>';
- }
- if (!empty($arrayfields['m.inventorycode']['checked'])) {
- // Inventory code
- print '<td class="liste_titre left">';
- print '<input class="flat" type="text" size="4" name="search_inventorycode" value="'.dol_escape_htmltag($search_inventorycode).'">';
- print '</td>';
- }
- if (!empty($arrayfields['m.label']['checked'])) {
- // Label of movement
- print '<td class="liste_titre left">';
- print '<input class="flat" type="text" size="8" name="search_movement" value="'.dol_escape_htmltag($search_movement).'">';
- print '</td>';
- }
- if (!empty($arrayfields['origin']['checked'])) {
- // Origin of movement
- print '<td class="liste_titre left">';
- print ' ';
- print '</td>';
- }
- if (!empty($arrayfields['m.fk_projet']['checked'])) {
- // fk_project
- print '<td class="liste_titre" align="left">';
- print ' ';
- print '</td>';
- }
- if (!empty($arrayfields['m.type_mouvement']['checked'])) {
- // Type of movement
- print '<td class="liste_titre center">';
- //print '<input class="flat" type="text" size="3" name="search_type_mouvement" value="'.dol_escape_htmltag($search_type_mouvement).'">';
- print '<select id="search_type_mouvement" name="search_type_mouvement" class="maxwidth150">';
- print '<option value="" '.(($search_type_mouvement == "") ? 'selected="selected"' : '').'> </option>';
- print '<option value="0" '.(($search_type_mouvement == "0") ? 'selected="selected"' : '').'>'.$langs->trans('StockIncreaseAfterCorrectTransfer').'</option>';
- print '<option value="1" '.(($search_type_mouvement == "1") ? 'selected="selected"' : '').'>'.$langs->trans('StockDecreaseAfterCorrectTransfer').'</option>';
- print '<option value="2" '.(($search_type_mouvement == "2") ? 'selected="selected"' : '').'>'.$langs->trans('StockDecrease').'</option>';
- print '<option value="3" '.(($search_type_mouvement == "3") ? 'selected="selected"' : '').'>'.$langs->trans('StockIncrease').'</option>';
- print '</select>';
- print ajax_combobox('search_type_mouvement');
- // TODO: add new function $formentrepot->selectTypeOfMovement(...) like
- // print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200');
- print '</td>';
- }
- if (!empty($arrayfields['m.value']['checked'])) {
- // Qty
- print '<td class="liste_titre right">';
- print '<input class="flat" type="text" size="4" name="search_qty" value="'.dol_escape_htmltag($search_qty).'">';
- print '</td>';
- }
- if (!empty($arrayfields['m.price']['checked'])) {
- // Price
- print '<td class="liste_titre" align="left">';
- print ' ';
- print '</td>';
- }
- // Extra fields
- include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
- // Fields from hook
- $parameters = array('arrayfields'=>$arrayfields);
- $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
- print $hookmanager->resPrint;
- // Date creation
- if (!empty($arrayfields['m.datec']['checked'])) {
- print '<td class="liste_titre">';
- print '</td>';
- }
- // Date modification
- if (!empty($arrayfields['m.tms']['checked'])) {
- print '<td class="liste_titre">';
- print '</td>';
- }
- // Action column
- print '<td class="liste_titre maxwidthsearch">';
- $searchpicto = $form->showFilterButtons();
- print $searchpicto;
- print '</td>';
- print '</tr>'."\n";
- // Fields title label
- // --------------------------------------------------------------------
- print '<tr class="liste_titre">';
- if (!empty($arrayfields['m.rowid']['checked'])) {
- print_liste_field_titre($arrayfields['m.rowid']['label'], $_SERVER["PHP_SELF"], 'm.rowid', '', $param, '', $sortfield, $sortorder);
- }
- if (!empty($arrayfields['m.datem']['checked'])) {
- print_liste_field_titre($arrayfields['m.datem']['label'], $_SERVER["PHP_SELF"], 'm.datem', '', $param, '', $sortfield, $sortorder, 'center ');
- }
- if (!empty($arrayfields['p.ref']['checked'])) {
- print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
- }
- if (!empty($arrayfields['p.label']['checked'])) {
- print_liste_field_titre($arrayfields['p.label']['label'], $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder);
- }
- if (!empty($arrayfields['m.batch']['checked'])) {
- print_liste_field_titre($arrayfields['m.batch']['label'], $_SERVER["PHP_SELF"], 'm.batch', '', $param, '', $sortfield, $sortorder, 'center ');
- }
- if (!empty($arrayfields['pl.eatby']['checked'])) {
- print_liste_field_titre($arrayfields['pl.eatby']['label'], $_SERVER["PHP_SELF"], 'pl.eatby', '', $param, '', $sortfield, $sortorder, 'center ');
- }
- if (!empty($arrayfields['pl.sellby']['checked'])) {
- print_liste_field_titre($arrayfields['pl.sellby']['label'], $_SERVER["PHP_SELF"], 'pl.sellby', '', $param, '', $sortfield, $sortorder, 'center ');
- }
- if (!empty($arrayfields['e.ref']['checked'])) {
- // We are on a specific warehouse card, no filter on other should be possible
- print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, "", $sortfield, $sortorder);
- }
- if (!empty($arrayfields['m.fk_user_author']['checked'])) {
- print_liste_field_titre($arrayfields['m.fk_user_author']['label'], $_SERVER["PHP_SELF"], "m.fk_user_author", "", $param, "", $sortfield, $sortorder);
- }
- if (!empty($arrayfields['m.inventorycode']['checked'])) {
- print_liste_field_titre($arrayfields['m.inventorycode']['label'], $_SERVER["PHP_SELF"], "m.inventorycode", "", $param, "", $sortfield, $sortorder);
- }
- if (!empty($arrayfields['m.label']['checked'])) {
- print_liste_field_titre($arrayfields['m.label']['label'], $_SERVER["PHP_SELF"], "m.label", "", $param, "", $sortfield, $sortorder);
- }
- if (!empty($arrayfields['origin']['checked'])) {
- print_liste_field_titre($arrayfields['origin']['label'], $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder);
- }
- if (!empty($arrayfields['m.fk_projet']['checked'])) {
- print_liste_field_titre($arrayfields['m.fk_projet']['label'], $_SERVER["PHP_SELF"], "m.fk_projet", "", $param, '', $sortfield, $sortorder);
- }
- if (!empty($arrayfields['m.type_mouvement']['checked'])) {
- print_liste_field_titre($arrayfields['m.type_mouvement']['label'], $_SERVER["PHP_SELF"], "m.type_mouvement", "", $param, '', $sortfield, $sortorder, 'center ');
- }
- if (!empty($arrayfields['m.value']['checked'])) {
- print_liste_field_titre($arrayfields['m.value']['label'], $_SERVER["PHP_SELF"], "m.value", "", $param, '', $sortfield, $sortorder, 'right ');
- }
- if (!empty($arrayfields['m.price']['checked'])) {
- print_liste_field_titre($arrayfields['m.price']['label'], $_SERVER["PHP_SELF"], "m.price", "", $param, '', $sortfield, $sortorder, 'right ');
- }
- // Extra fields
- include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
- // Hook fields
- $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
- $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
- print $hookmanager->resPrint;
- if (!empty($arrayfields['m.datec']['checked'])) {
- print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
- }
- if (!empty($arrayfields['m.tms']['checked'])) {
- print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
- }
- // Action column
- print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
- print '</tr>'."\n";
- $arrayofuniqueproduct = array();
- // Loop on record
- // --------------------------------------------------------------------
- $i = 0;
- $totalarray = array();
- $totalarray['nbfield'] = 0;
- while ($i < ($limit ? min($num, $limit) : $num)) {
- $obj = $db->fetch_object($resql);
- if (empty($obj)) {
- break; // Should not happen
- }
- $userstatic->id = $obj->fk_user_author;
- $userstatic->login = $obj->login;
- $userstatic->lastname = $obj->lastname;
- $userstatic->firstname = $obj->firstname;
- $userstatic->photo = $obj->photo;
- $userstatic->email = $obj->user_email;
- $userstatic->statut = $obj->user_status;
- // Multilangs
- if (!empty($conf->global->MAIN_MULTILANGS)) { // If multilang is enabled
- // TODO Use a cache
- $sql = "SELECT label";
- $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
- $sql .= " WHERE fk_product = ".((int) $obj->rowid);
- $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'";
- $sql .= " LIMIT 1";
- $result = $db->query($sql);
- if ($result) {
- $objtp = $db->fetch_object($result);
- if (!empty($objtp->label)) {
- $obj->produit = $objtp->label;
- }
- }
- }
- $productstatic->id = $obj->rowid;
- $productstatic->ref = $obj->product_ref;
- $productstatic->label = $obj->produit;
- $productstatic->type = $obj->type;
- $productstatic->entity = $obj->entity;
- $productstatic->status = $obj->tosell;
- $productstatic->status_buy = $obj->tobuy;
- $productstatic->status_batch = $obj->tobatch;
- $productlot->id = $obj->lotid;
- $productlot->batch = $obj->batch;
- $productlot->eatby = $obj->eatby;
- $productlot->sellby = $obj->sellby;
- $warehousestatic->id = $obj->entrepot_id;
- $warehousestatic->ref = $obj->warehouse_ref;
- $warehousestatic->label = $obj->warehouse_ref;
- $warehousestatic->lieu = $obj->lieu;
- $warehousestatic->fk_parent = $obj->fk_parent;
- $warehousestatic->statut = $obj->statut;
- $movement->type = $obj->type_mouvement;
- $arrayofuniqueproduct[$obj->rowid] = $obj->produit;
- if (!empty($obj->fk_origin)) {
- $origin = $movement->get_origin($obj->fk_origin, $obj->origintype);
- } else {
- $origin = '';
- }
- print '<tr class="oddeven">';
- // Id movement
- if (!empty($arrayfields['m.rowid']['checked'])) {
- print '<td>';
- print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"');
- print $obj->mid;
- print '</td>'; // This is primary not movement id
- }
- if (!empty($arrayfields['m.datem']['checked'])) {
- // Date
- print '<td class="nowraponall center">'.dol_print_date($db->jdate($obj->datem), 'dayhour', 'tzuserrel').'</td>';
- }
- if (!empty($arrayfields['p.ref']['checked'])) {
- // Product ref
- print '<td class="nowraponall">';
- print $productstatic->getNomUrl(1, 'stock', 16);
- print "</td>\n";
- }
- if (!empty($arrayfields['p.label']['checked'])) {
- // Product label
- print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($productstatic->label).'">';
- print $productstatic->label;
- print "</td>\n";
- }
- if (!empty($arrayfields['m.batch']['checked'])) {
- print '<td class="center nowraponall">';
- if ($productlot->id > 0) {
- print $productlot->getNomUrl(1);
- } else {
- print $productlot->batch; // the id may not be defined if movement was entered when lot was not saved or if lot was removed after movement.
- }
- print '</td>';
- }
- if (!empty($arrayfields['pl.eatby']['checked'])) {
- print '<td class="center">'.dol_print_date($obj->eatby, 'day').'</td>';
- }
- if (!empty($arrayfields['pl.sellby']['checked'])) {
- print '<td class="center">'.dol_print_date($obj->sellby, 'day').'</td>';
- }
- // Warehouse
- if (!empty($arrayfields['e.ref']['checked'])) {
- print '<td class="tdoverflowmax100">';
- print $warehousestatic->getNomUrl(1);
- print "</td>\n";
- }
- // Author
- if (!empty($arrayfields['m.fk_user_author']['checked'])) {
- print '<td class="tdoverflowmax100">';
- print $userstatic->getNomUrl(-1);
- print "</td>\n";
- }
- if (!empty($arrayfields['m.inventorycode']['checked'])) {
- // Inventory code
- print '<td><a href="'.$_SERVER["PHP_SELF"].'?search_inventorycode='.urlencode('^'.$obj->inventorycode.'$').'&search_type_mouvement='.urlencode($obj->type_mouvement).'">'.$obj->inventorycode.'</a></td>';
- }
- if (!empty($arrayfields['m.label']['checked'])) {
- // Label of movement
- print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->label).'">'.$obj->label.'</td>';
- }
- if (!empty($arrayfields['origin']['checked'])) {
- // Origin of movement
- print '<td class="nowraponall">'.$origin.'</td>';
- }
- if (!empty($arrayfields['m.fk_projet']['checked'])) {
- // fk_project
- print '<td>';
- if ($obj->fk_project != 0) {
- print $movement->get_origin($obj->fk_project, 'project');
- }
- print '</td>';
- }
- if (!empty($arrayfields['m.type_mouvement']['checked'])) {
- // Type of movement
- print '<td class="center">';
- print $movement->getTypeMovement();
- print '</td>';
- }
- if (!empty($arrayfields['m.value']['checked'])) {
- // Qty
- print '<td class="right">';
- if ($obj->qty > 0) {
- print '<span class="stockmovemententry">';
- print '+';
- print $obj->qty;
- print '</span>';
- } else {
- print '<span class="stockmovementexit">';
- print $obj->qty;
- print '</span>';
- }
- print '</td>';
- }
- if (!empty($arrayfields['m.price']['checked'])) {
- // Price
- print '<td class="right">';
- if ($obj->price != 0) {
- print price($obj->price);
- }
- print '</td>';
- }
- // Extra fields
- $object = $movement;
- include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
- // Fields from hook
- $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
- $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
- print $hookmanager->resPrint;
- // Action column
- print '<td class="nowrap center">';
- if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
- $selected = 0;
- if (in_array($obj->mid, $arrayofselected)) {
- $selected = 1;
- }
- print '<input id="cb'.$obj->mid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->mid.'"'.($selected ? ' checked="checked"' : '').'>';
- }
- print '</td>';
- if (!$i) {
- $totalarray['nbfield']++;
- }
- print '</tr>'."\n";
- $i++;
- }
- $db->free($resql);
- print "</table>";
- print '</div>';
- print "</form>";
- // Add number of product when there is a filter on period
- if (count($arrayofuniqueproduct) == 1 && is_numeric($year)) {
- print "<br>";
- $productidselected = 0;
- foreach ($arrayofuniqueproduct as $key => $val) {
- $productidselected = $key;
- $productlabelselected = $val;
- }
- $datebefore = dol_get_first_day($year ? $year : strftime("%Y", time()), $month ? $month : 1, true);
- $dateafter = dol_get_last_day($year ? $year : strftime("%Y", time()), $month ? $month : 12, true);
- $balancebefore = $movement->calculateBalanceForProductBefore($productidselected, $datebefore);
- $balanceafter = $movement->calculateBalanceForProductBefore($productidselected, $dateafter);
- //print '<tr class="total"><td class="liste_total">';
- print $langs->trans("NbOfProductBeforePeriod", $productlabelselected, dol_print_date($datebefore, 'day', 'gmt'));
- //print '</td>';
- //print '<td class="liste_total right" colspan="6">';
- print ': '.$balancebefore;
- print "<br>\n";
- //print '</td></tr>';
- //print '<tr class="total"><td class="liste_total">';
- print $langs->trans("NbOfProductAfterPeriod", $productlabelselected, dol_print_date($dateafter, 'day', 'gmt'));
- //print '</td>';
- //print '<td class="liste_total right" colspan="6">';
- print ': '.$balanceafter;
- print "<br>\n";
- //print '</td></tr>';
- }
- if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
- $hidegeneratedfilelistifempty = 1;
- if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
- $hidegeneratedfilelistifempty = 0;
- }
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
- $formfile = new FormFile($db);
- // Show list of available documents
- $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
- $urlsource .= str_replace('&', '&', $param);
- $filedir = $diroutputmassaction;
- $genallowed = $permissiontoread;
- $delallowed = $permissiontoadd;
- print $formfile->showdocuments('massfilesarea_mymodule', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
- }
- // End of page
- llxFooter();
- $db->close();
|