From 837821ebb637f8fc87bc3f9b72d23bb6b98520f9 Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Mon, 28 Jan 2019 05:12:20 +0100 Subject: [PATCH 1/2] Create movement_card.php --- htdocs/product/stock/movement_card.php | 1194 ++++++++++++++++++++++++ 1 file changed, 1194 insertions(+) create mode 100644 htdocs/product/stock/movement_card.php diff --git a/htdocs/product/stock/movement_card.php b/htdocs/product/stock/movement_card.php new file mode 100644 index 00000000000..abf7d21284b --- /dev/null +++ b/htdocs/product/stock/movement_card.php @@ -0,0 +1,1194 @@ + + * Copyright (C) 2004-2017 Laurent Destailleur + * Copyright (C) 2005-2014 Regis Houssin + * Copyright (C) 2015 Juanjo Menent + * Copyright (C) 2018 Ferran Marcet + * + * 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 . + */ + +/** + * \file htdocs/product/stock/movement_card.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'; +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"); + +// Security check +$result=restrictedArea($user,'stock'); + +$id=GETPOST('id','int'); +$ref = GETPOST('ref','alpha'); +$msid=GETPOST('msid','int'); +$product_id=GETPOST("product_id"); +$action=GETPOST('action','aZ09'); +$cancel=GETPOST('cancel','alpha'); +$contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'movementlist'; + +$idproduct = GETPOST('idproduct','int'); +$year = GETPOST("year"); +$month = GETPOST("month"); +$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'); + +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; +$page = GETPOST("page",'int'); +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $limit * $page; +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); +$hookmanager->initHooks(array('movementlist')); +$extrafields = new ExtraFields($db); +$formfile = new FormFile($db); + +// fetch optionals attributes and labels +$extralabels = $extrafields->fetch_name_optionals_label('movement'); +$search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_'); + +$arrayfields=array( + 'm.rowid'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), + 'm.datem'=>array('label'=>$langs->trans("Date"), 'checked'=>1), + 'p.ref'=>array('label'=>$langs->trans("ProductRef"), 'checked'=>1, 'css'=>'maxwidth100'), + 'p.label'=>array('label'=>$langs->trans("ProductLabel"), 'checked'=>1), + 'm.batch'=>array('label'=>$langs->trans("BatchNumberShort"), 'checked'=>1, 'enabled'=>(! empty($conf->productbatch->enabled))), + 'pl.eatby'=>array('label'=>$langs->trans("EatByDate"), 'checked'=>0, 'enabled'=>(! empty($conf->productbatch->enabled))), + 'pl.sellby'=>array('label'=>$langs->trans("SellByDate"), 'checked'=>0, 'position'=>10, 'enabled'=>(! empty($conf->productbatch->enabled))), + 'e.ref'=>array('label'=>$langs->trans("Warehouse"), 'checked'=>1, 'enabled'=>(! $id > 0)), // If we are on specific warehouse, we hide it + 'm.fk_user_author'=>array('label'=>$langs->trans("Author"), 'checked'=>0), + 'm.inventorycode'=>array('label'=>$langs->trans("InventoryCodeShort"), 'checked'=>1), + 'm.label'=>array('label'=>$langs->trans("MovementLabel"), 'checked'=>1), + 'm.type_mouvement'=>array('label'=>$langs->trans("TypeMovement"), 'checked'=>1), + 'origin'=>array('label'=>$langs->trans("Origin"), 'checked'=>1), + 'm.value'=>array('label'=>$langs->trans("Qty"), 'checked'=>1), + 'm.price'=>array('label'=>$langs->trans("UnitPurchaseValue"), 'checked'=>0), + //'m.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), + //'m.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500) +); + + + +/* + * Actions + */ + +$usercanread = (($user->rights->stock->mouvement->lire)); +$usercancreate = (($user->rights->stock->mouvement->creer)); +$usercandelete = (($user->rights->stock->mouvement->supprimer)); + +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'); + +include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; + +// Do we click on 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 +{ + $year=''; + $month=''; + $search_ref=''; + $search_movement=""; + $search_type_mouvement=""; + $search_inventorycode=""; + $search_product_ref=""; + $search_product=""; + $search_warehouse=""; + $search_user=""; + $search_batch=""; + $search_qty=''; + $sall=""; + $toselect=''; + $search_array_options=array(); +} + +// 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($_POST["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'); + + //$eatby=GETPOST('eatby'); + //$sellby=GETPOST('sellby'); + $eatby=dol_mktime(0, 0, 0, GETPOST('eatbymonth'), GETPOST('eatbyday'), GETPOST('eatbyyear')); + $sellby=dol_mktime(0, 0, 0, GETPOST('sellbymonth'), GETPOST('sellbyday'), GETPOST('sellbyyear')); + + $result=$product->correct_stock_batch( + $user, + $id, + GETPOST("nbpiece",'int'), + GETPOST("mouvement"), + GETPOST("label",'san_alpha'), + GETPOST('unitprice'), + $eatby,$sellby,$batch, + GETPOST('inventorycode'), + $origin_element, + $origin_id + ); // We do not change value of stock for a correction + } + else + { + $result=$product->correct_stock( + $user, + $id, + GETPOST("nbpiece",'int'), + GETPOST("mouvement"), + GETPOST("label",'san_alpha'), + GETPOST('unitprice'), + GETPOST('inventorycode'), + $origin_element, + $origin_id + ); // 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'); + $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') + ); + // 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') + ); + } + } + else + { + // Remove stock + $result1=$product->correct_stock( + $user, + $id, + GETPOST("nbpiece"), + 1, + GETPOST("label"), + $pricesrc, + GETPOST('inventorycode') + ); + + // Add stock + $result2=$product->correct_stock( + $user, + GETPOST("id_entrepot_destination"), + GETPOST("nbpiece"), + 0, + GETPOST("label"), + $pricedest, + GETPOST('inventorycode') + ); + } + 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'; + } + } + } +} + + +/* + * Build document + */ +// The builddoc action for object of a movement must be on the movement card +// Actions to build doc +$upload_dir = $conf->stock->dir_output . "movement/"; +$permissioncreate = $user->rights->stock->creer; +include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; + + +if (empty($reshook) && $action != 'remove_file') +{ + $objectclass='MouvementStock'; + $objectlabel='Movements'; + $permtoread = $user->rights->stock->lire; + $permtodelete = $user->rights->stock->supprimer; + $uploaddir = $conf->stock->dir_output . "/movement/"; + include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; +} + + + +/* + * 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); +$formother=new FormOther($db); +$formproduct=new FormProduct($db); +if (!empty($conf->projet->enabled)) $formproject=new FormProjets($db); + +$sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.entity,"; +$sql.= " e.ref as stock, e.rowid as entrepot_id, e.lieu,"; +$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.= " pl.rowid as lotid, pl.eatby, pl.sellby,"; +$sql.= " u.login, u.photo, u.lastname, u.firstname"; +// Add fields from extrafields +foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_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.=$hookmanager->resPrint; +$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e,"; +$sql.= " ".MAIN_DB_PREFIX."product as p,"; +$sql.= " ".MAIN_DB_PREFIX."stock_mouvement as m"; +if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."movement_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 = ".$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 ='".$id."'"; +if ($month > 0) +{ + if ($year > 0) + $sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'"; + else + $sql.= " AND date_format(m.datem, '%m') = '$month'"; +} +elseif ($year > 0) +{ + $sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'"; +} +if ($idproduct > 0) $sql.= " AND p.rowid = '".$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('u.login', $search_user); +if (! empty($search_batch)) $sql.= natural_search('m.batch', $search_batch); +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; +$sql.= $db->order($sortfield,$sortorder); + +$nbtotalofrecords = ''; +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) +{ + $result = $db->query($sql); + $nbtotalofrecords = $db->num_rows($result); + if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 + { + $page = 0; + $offset = 0; + } +} + +if(empty($search_inventorycode)) +{ + $sql.= $db->plimit($limit+1, $offset); +} +else +{ + $limit = 0; +} + +//print $sql; + +$resql = $db->query($sql); + +if(!empty($search_inventorycode)) $limit = $db->num_rows($resql); + +if ($resql) +{ + $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); + + $arrayofselected=is_array($toselect)?$toselect:array(); + + + $i = 0; + $help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; + if ($msid) $texte = $langs->trans('StockMovementForId', $msid); + else + { + $texte = $langs->trans("ListOfStockMovements"); + if ($id) $texte.=' ('.$langs->trans("ForThisWarehouse").')'; + } + llxHeader("",$texte,$help_url); + + /* + * Show tab only if we ask a particular warehouse + */ + if ($object->id > 0) + { + $head = stock_prepare_head($object); + + dol_fiche_head($head, 'movements', $langs->trans("Warehouse"), -1, 'stock'); + + + $linkback = ''.$langs->trans("BackToList").''; + + $morehtmlref='
'; + $morehtmlref.=$langs->trans("LocationSummary").' : '.$object->lieu; + $morehtmlref.='
'; + + $shownav = 1; + if ($user->societe_id && ! in_array('stock', explode(',',$conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav=0; + + dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref); + + + print '
'; + print '
'; + print '
'; + + print ''; + + print ''; + + // Description + print ''; + + $calcproductsunique=$object->nb_different_products(); + $calcproducts=$object->nb_products(); + + // Total nb of different products + print '"; + + // Nb of products + print '"; + + print '
'.$langs->trans("Description").''.dol_htmlentitiesbr($object->description).'
'.$langs->trans("NumberOfDifferentProducts").''; + print empty($calcproductsunique['nb'])?'0':$calcproductsunique['nb']; + print "
'.$langs->trans("NumberOfProducts").''; + $valtoshow=price2num($calcproducts['nb'], 'MS'); + print empty($valtoshow)?'0':$valtoshow; + print "
'; + + print '
'; + print '
'; + print '
'; + print '
'; + + print ''; + + // Value + print '"; + + // Last movement + $sql = "SELECT MAX(m.datem) as datem"; + $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m"; + $sql .= " WHERE m.fk_entrepot = '".$object->id."'"; + $resqlbis = $db->query($sql); + if ($resqlbis) + { + $obj = $db->fetch_object($resqlbis); + $lastmovementdate=$db->jdate($obj->datem); + } + else + { + dol_print_error($db); + } + + print '"; + + print "
'.$langs->trans("EstimatedStockValueShort").''; + print price((empty($calcproducts['value'])?'0':price2num($calcproducts['value'],'MT')), 0, $langs, 0, -1, -1, $conf->currency); + print "
'.$langs->trans("LastMovement").''; + if ($lastmovementdate) + { + print dol_print_date($lastmovementdate,'dayhour'); + } + else + { + print $langs->trans("None"); + } + print "
"; + + print '
'; + print '
'; + print '
'; + + print '
'; + + dol_fiche_end(); + } + + + /* + * Correct stock + */ + if ($action == "correction") + { + include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php'; + print '
'; + } + + /* + * Transfer of units + */ + if ($action == "transfert") + { + include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php'; + print '
'; + } + + + /* ************************************************************************** */ + /* */ + /* Barre d'action */ + /* */ + /* ************************************************************************** */ + + if ((empty($action) || $action == 'list') && $id > 0) + { + print "
\n"; + + if ($user->rights->stock->mouvement->creer) + { + print ''.$langs->trans("CorrectStock").''; + } + + if ($user->rights->stock->mouvement->creer) + { + print ''.$langs->trans("TransferStock").''; + } + + print '

'; + } + + $param=''; + if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; + if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; + if ($id > 0) $param.='&id='.$id; + 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 (!empty($sref)) $param.='&sref='.urlencode($sref); // FIXME $sref is not defined + if (!empty($snom)) $param.='&snom='.urlencode($snom); // FIXME $snom is not defined + if ($search_user) $param.='&search_user='.urlencode($search_user); + if ($idproduct > 0) $param.='&idproduct='.$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( + // 'presend'=>$langs->trans("SendByMail"), + // 'builddoc'=>$langs->trans("PDFMerge"), + ); + //if ($user->rights->stock->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete"); + if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array(); + $massactionbutton=$form->selectMassAction('', $arrayofmassactions); + + print '
'; + if ($optioncss != '') print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + if ($id > 0) print ''; + + if ($id > 0) print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,$massactionbutton,$num, $nbtotalofrecords, '', 0, '', '', $limit); + else print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,$massactionbutton,$num, $nbtotalofrecords, 'title_generic', 0, '', '', $limit); + + if ($sall) + { + foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); + print '
'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'
'; + } + + $moreforfilter=''; + + $parameters=array(); + $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // 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 '
'; + print $moreforfilter; + print '
'; + } + + $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; + $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields + + print '
'; + print ''."\n"; + + // Lignes des champs de filtre + print ''; + if (! empty($arrayfields['m.rowid']['checked'])) + { + // Ref + print ''; + } + if (! empty($arrayfields['m.datem']['checked'])) + { + print ''; + } + if (! empty($arrayfields['p.ref']['checked'])) + { + // Product Ref + print ''; + } + if (! empty($arrayfields['p.label']['checked'])) + { + // Product label + print ''; + } + // Batch + if (! empty($arrayfields['m.batch']['checked'])) + { + print ''; + } + if (! empty($arrayfields['pl.eatby']['checked'])) + { + print ''; + } + if (! empty($arrayfields['pl.sellby']['checked'])) + { + print ''; + } + // Warehouse + if (! empty($arrayfields['e.ref']['checked'])) + { + print ''; + } + if (! empty($arrayfields['m.fk_user_author']['checked'])) + { + // Author + print ''; + } + if (! empty($arrayfields['m.inventorycode']['checked'])) + { + // Inventory code + print ''; + } + if (! empty($arrayfields['m.label']['checked'])) + { + // Label of movement + print ''; + } + if (! empty($arrayfields['m.type_mouvement']['checked'])) + { + // Type of movement + print ''; + } + if (! empty($arrayfields['origin']['checked'])) + { + // Origin of movement + print ''; + } + if (! empty($arrayfields['m.value']['checked'])) + { + // Qty + print ''; + } + if (! empty($arrayfields['m.price']['checked'])) + { + // Price + print ''; + } + + + // 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); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + // Date creation + if (! empty($arrayfields['m.datec']['checked'])) + { + print ''; + } + // Date modification + if (! empty($arrayfields['m.tms']['checked'])) + { + print ''; + } + // Actions + print ''; + print "\n"; + + print ''; + 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); + 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,'align="center"',$sortfield,$sortorder); + if (! empty($arrayfields['pl.eatby']['checked'])) print_liste_field_titre($arrayfields['pl.eatby']['label'],$_SERVER["PHP_SELF"],'pl.eatby','',$param,'align="center"',$sortfield,$sortorder); + if (! empty($arrayfields['pl.sellby']['checked'])) print_liste_field_titre($arrayfields['pl.sellby']['label'],$_SERVER["PHP_SELF"],'pl.sellby','',$param,'align="center"',$sortfield,$sortorder); + if (! empty($arrayfields['e.ref']['checked'])) print_liste_field_titre($arrayfields['e.ref']['label'],$_SERVER["PHP_SELF"], "e.ref","",$param,"",$sortfield,$sortorder); // We are on a specific warehouse card, no filter on other should be possible + 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['m.type_mouvement']['checked'])) print_liste_field_titre($arrayfields['m.type_mouvement']['label'],$_SERVER["PHP_SELF"], "m.type_mouvement","",$param,'align="center"',$sortfield,$sortorder); + if (! empty($arrayfields['origin']['checked'])) print_liste_field_titre($arrayfields['origin']['label'],$_SERVER["PHP_SELF"], "","",$param,"",$sortfield,$sortorder); + if (! empty($arrayfields['m.value']['checked'])) print_liste_field_titre($arrayfields['m.value']['label'],$_SERVER["PHP_SELF"], "m.value","",$param,'align="right"',$sortfield,$sortorder); + if (! empty($arrayfields['m.price']['checked'])) print_liste_field_titre($arrayfields['m.price']['label'],$_SERVER["PHP_SELF"], "m.price","",$param,'align="right"',$sortfield,$sortorder); + + // 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); // 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,'align="center" class="nowrap"',$sortfield,$sortorder); + if (! empty($arrayfields['m.tms']['checked'])) print_liste_field_titre($arrayfields['p.tms']['label'],$_SERVER["PHP_SELF"],"p.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch '); + print "\n"; + + + $arrayofuniqueproduct=array(); + + while ($i < min($num,$limit)) + { + $objp = $db->fetch_object($resql); + + $userstatic->id=$objp->fk_user_author; + $userstatic->login=$objp->login; + $userstatic->lastname=$objp->lastname; + $userstatic->firstname=$objp->firstname; + $userstatic->photo=$objp->photo; + + $productstatic->id=$objp->rowid; + $productstatic->ref=$objp->product_ref; + $productstatic->label=$objp->produit; + $productstatic->type=$objp->type; + $productstatic->entity=$objp->entity; + $productstatic->status_batch=$objp->tobatch; + + $productlot->id = $objp->lotid; + $productlot->batch= $objp->batch; + $productlot->eatby= $objp->eatby; + $productlot->sellby= $objp->sellby; + + $warehousestatic->id=$objp->entrepot_id; + $warehousestatic->libelle=$objp->stock; + $warehousestatic->lieu=$objp->lieu; + + $arrayofuniqueproduct[$objp->rowid]=$objp->produit; + if(!empty($objp->fk_origin)) { + $origin = $movement->get_origin($objp->fk_origin, $objp->origintype); + } else { + $origin = ''; + } + + print ''; + // Id movement + if (! empty($arrayfields['m.rowid']['checked'])) + { + print ''; // This is primary not movement id + } + if (! empty($arrayfields['m.datem']['checked'])) + { + // Date + print ''; + } + if (! empty($arrayfields['p.ref']['checked'])) + { + // Product ref + print '\n"; + } + if (! empty($arrayfields['p.label']['checked'])) + { + // Product label + print '\n"; + } + if (! empty($arrayfields['m.batch']['checked'])) + { + print ''; + } + if (! empty($arrayfields['pl.eatby']['checked'])) + { + print ''; + } + if (! empty($arrayfields['pl.sellby']['checked'])) + { + print ''; + } + // Warehouse + if (! empty($arrayfields['e.ref']['checked'])) + { + print '\n"; + } + // Author + if (! empty($arrayfields['m.fk_user_author']['checked'])) + { + print '\n"; + } + if (! empty($arrayfields['m.inventorycode']['checked'])) + { + // Inventory code + print ''; + } + if (! empty($arrayfields['m.label']['checked'])) + { + // Label of movement + print ''; + } + if (! empty($arrayfields['m.type_mouvement']['checked'])) + { + // Type of movement + switch($objp->type_mouvement){ + case "0": + print ''; + break; + case "1": + print ''; + break; + case "2": + print ''; + break; + case "3": + print ''; + break; + } + } + if (! empty($arrayfields['origin']['checked'])) + { + // Origin of movement + print ''; + } + if (! empty($arrayfields['m.value']['checked'])) + { + // Qty + print ''; + } + if (! empty($arrayfields['m.price']['checked'])) + { + // Price + print ''; + } + // Action column + print ''; + if (! $i) $totalarray['nbfield']++; + + print "\n"; + $i++; + } + $db->free($resql); + + print "
'; + print ''; + print ''; + print ''; + if (empty($conf->productbatch->enabled)) print ' '; + //else print '
'; + $syear = $year?$year:-1; + print ''; + //print $formother->selectyear($syear,'year',1, 20, 5); + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + //print ''; + print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200'); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + //print ''; + print ''; + 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 ''; + print '  '; + print ''; + print ''; + print ''; + print '  '; + print ''; + print ''; + print ''; + $searchpicto=$form->showFilterAndCheckAddButtons(0); + print $searchpicto; + print '
'.$objp->mid.''.dol_print_date($db->jdate($objp->datem),'dayhour').''; + print $productstatic->getNomUrl(1,'stock',16); + print "'; + /*$productstatic->id=$objp->rowid; + $productstatic->ref=$objp->produit; + $productstatic->type=$objp->type; + print $productstatic->getNomUrl(1,'',16);*/ + print $productstatic->label; + print "'; + 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 ''. dol_print_date($objp->eatby,'day') .''. dol_print_date($objp->sellby,'day') .''; + print $warehousestatic->getNomUrl(1); + print "'; + print $userstatic->getNomUrl(-1); + print "'.'' + .$objp->inventorycode + .'' + .''.$objp->label.''.$langs->trans('StockIncreaseAfterCorrectTransfer').''.$langs->trans('StockDecreaseAfterCorrectTransfer').''.$langs->trans('StockDecrease').''.$langs->trans('StockIncrease').''.$origin.''; + if ($objp->qt > 0) print '+'; + print $objp->qty; + print ''; + if ($objp->price != 0) print price($objp->price); + print ''; + 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->rowid, $arrayofselected)) $selected=1; + print ''; + } + print '
"; + print '
'; + print "
"; + + // Add number of product when there is a filter on period + if (count($arrayofuniqueproduct) == 1 && is_numeric($year)) + { + print "
"; + + $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 ''; + print $langs->trans("NbOfProductBeforePeriod", $productlabelselected, dol_print_date($datebefore,'day','gmt')); + //print ''; + //print ''; + print ': '.$balancebefore; + print "
\n"; + //print ''; + //print ''; + print $langs->trans("NbOfProductAfterPeriod", $productlabelselected, dol_print_date($dateafter,'day','gmt')); + //print ''; + //print ''; + print ': '.$balanceafter; + print "
\n"; + //print ''; + } +} +else +{ + dol_print_error($db); +} + + + +/* + * Documents generes + */ +//Area for doc and last events of warehouse are stored on the main card of warehouse +$modulepart='movement'; + +if ($action != 'create' && $action != 'edit' && $action != 'delete' && $id>0) +{ + print '
'; + print '
'; + print ''; // ancre + + // Documents + $objectref = dol_sanitizeFileName($object->ref); + // Add inventorycode & type_mouvement to filename of the pdf + if(!empty($search_inventorycode)) $objectref.="_".$id."_".$search_inventorycode; + if($search_type_mouvement) $objectref.="_".$search_type_mouvement; + $relativepath = $comref . '/' . $objectref . '.pdf'; + $filedir = $conf->stock->dir_output . '/movement/' . $objectref; + + $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id."&search_inventorycode=".$search_inventorycode."&search_type_mouvement=$search_type_mouvement"; + $genallowed=$usercanread; + $delallowed=$usercancreate; + + $genallowed=$user->rights->stock->lire; + $delallowed=$user->rights->stock->creer; + + print $formfile->showdocuments($modulepart,$objectref,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$object->default_lang, '', $object); + $somethingshown=$formfile->numoffiles; + + print '
'; + + $MAXEVENT = 10; + + $morehtmlright = ''; + $morehtmlright.= $langs->trans("SeeAll"); + $morehtmlright.= ''; + + // List of actions on element + include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; + $formactions = new FormActions($db); + $somethingshown = $formactions->showactions($object, 'mouvement', 0, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for product + + print '
'; +} + + +// End of page +llxFooter(); +$db->close(); From 2ba7bb9d4e49e107d4aad51eb9f240d649ce1058 Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Mon, 28 Jan 2019 17:13:24 +0100 Subject: [PATCH 2/2] Add & Update pdf_stdmouvement.modules.php Fix Bug Generate pdf --- .../stock/doc/pdf_stdmouvement.modules.php | 196 ++++++++++-------- 1 file changed, 109 insertions(+), 87 deletions(-) diff --git a/htdocs/core/modules/stock/doc/pdf_stdmouvement.modules.php b/htdocs/core/modules/stock/doc/pdf_stdmouvement.modules.php index 16d979d60ee..65c1275a129 100644 --- a/htdocs/core/modules/stock/doc/pdf_stdmouvement.modules.php +++ b/htdocs/core/modules/stock/doc/pdf_stdmouvement.modules.php @@ -17,12 +17,12 @@ */ /** - * \file htdocs/core/modules/stock/doc/pdf_standard.modules.php + * \file htdocs/core/modules/stock/doc/pdf_stdmouvement.modules.php * \ingroup societe - * \brief File of class to build PDF documents for stocks/services + * \brief File of class to build PDF documents for stocks movements */ -require_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_stock.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_movement.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.'/fourn/class/fournisseur.product.class.php'; @@ -35,7 +35,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; /** * Class to build documents using ODF templates generator */ -class pdf_stdmouvement extends ModelePDFMouvement +class pdf_stdmouvement extends ModelePDFMovement { /** * @var DoliDb Database handler @@ -59,9 +59,9 @@ class pdf_stdmouvement extends ModelePDFMouvement /** * @var array() Minimum version of PHP required by module. - * e.g.: PHP ≥ 5.3 = array(5, 3) + * e.g.: PHP ≥ 5.4 = array(5, 4) */ - public $phpmin = array(5, 2); + public $phpmin = array(5, 4); /** * Dolibarr version of the loaded document @@ -69,15 +69,46 @@ class pdf_stdmouvement extends ModelePDFMouvement */ public $version = 'dolibarr'; + /** + * @var int page_largeur + */ public $page_largeur; + + /** + * @var int page_hauteur + */ public $page_hauteur; + + /** + * @var array format + */ public $format; + + /** + * @var int marge_gauche + */ public $marge_gauche; + + /** + * @var int marge_droite + */ public $marge_droite; + + /** + * @var int marge_haute + */ public $marge_haute; + + /** + * @var int marge_basse + */ public $marge_basse; - public $emetteur; // Objet societe qui emet + /** + * Issuer + * @var Societe + */ + public $emetteur; /** @@ -89,8 +120,8 @@ class pdf_stdmouvement extends ModelePDFMouvement { global $conf,$langs,$mysoc; - $langs->load("main"); - $langs->load("companies"); + // Load traductions files requiredby by page + $langs->loadLangs(array("main", "companies")); $this->db = $db; $this->name = "stdmouvement"; @@ -115,14 +146,14 @@ class pdf_stdmouvement extends ModelePDFMouvement // Recupere emetteur $this->emetteur=$mysoc; if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined - + // Define position of columns $this->wref = 15; $this->posxidref = $this->marge_gauche; - $this->posxdatemouv = $this->marge_gauche+8;; + $this->posxdatemouv = $this->marge_gauche+8; $this->posxdesc=37; $this->posxlabel=50; - $this->posxtva=80; + $this->posxtva=80; $this->posxqty=105; $this->posxup=119; $this->posxunit=136; @@ -149,6 +180,7 @@ class pdf_stdmouvement extends ModelePDFMouvement } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps /** * Function to build a document on disk using the generic odt module. * @@ -160,22 +192,18 @@ class pdf_stdmouvement extends ModelePDFMouvement * @param int $hideref Do not show ref * @return int 1 if OK, <=0 if KO */ - function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) + function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) { + // phpcs:enable global $user,$langs,$conf,$mysoc,$db,$hookmanager; if (! is_object($outputlangs)) $outputlangs=$langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; - $outputlangs->load("main"); - $outputlangs->load("dict"); - $outputlangs->load("companies"); - $outputlangs->load("bills"); - $outputlangs->load("stocks"); - $outputlangs->load("orders"); - $outputlangs->load("deliveries"); - + // Load traductions files requiredby by page + $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "stocks", "orders", "deliveries")); + /** * TODO: get from object */ @@ -219,7 +247,7 @@ class pdf_stdmouvement extends ModelePDFMouvement // fetch optionals attributes and labels $extralabels = $extrafields->fetch_name_optionals_label('movement'); - $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); + $search_array_options=$extrafields->getOptionalsFromPost('movement','','search_'); $productlot=new ProductLot($db); $productstatic=new Product($db); @@ -259,7 +287,7 @@ class pdf_stdmouvement extends ModelePDFMouvement else $sql.= " AND date_format(m.datem, '%m') = '$month'"; } - else if ($year > 0) + elseif ($year > 0) { $sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'"; } @@ -308,7 +336,7 @@ class pdf_stdmouvement extends ModelePDFMouvement if ($conf->stock->dir_output) { - + if ($resql) { $product = new Product($db); @@ -340,11 +368,11 @@ class pdf_stdmouvement extends ModelePDFMouvement if ($id) $texte.=' ('.$langs->trans("ForThisWarehouse").')'; } } - + // Definition of $dir and $file if ($object->specimen) { - $dir = $conf->stock->dir_output . "/mouvement"; + $dir = $conf->stock->dir_output . "/movement"; $file = $dir . "/SPECIMEN.pdf"; } else @@ -352,14 +380,14 @@ class pdf_stdmouvement extends ModelePDFMouvement $objectref = dol_sanitizeFileName($object->ref); if(!empty($search_inventorycode)) $objectref.="_".$id."_".$search_inventorycode; if($search_type_mouvement) $objectref.="_".$search_type_mouvement; - $dir = $conf->stock->dir_output . "/mouvement/" . $objectref; + $dir = $conf->stock->dir_output . "/movement/" . $objectref; $file = $dir . "/" . $objectref . ".pdf"; } - + $stockFournisseur = new ProductFournisseur($this->db); $supplierprices = $stockFournisseur->list_product_fournisseur_price($object->id); $object->supplierprices = $supplierprices; - + $productstatic=new Product($db); if (! file_exists($dir)) @@ -439,14 +467,15 @@ class pdf_stdmouvement extends ModelePDFMouvement /* Affichage de la liste des produits du MouvementStock */ /* */ /* ************************************************************************** */ - - $nexY+=5; + + $nexY+=5; $nexY = $pdf->GetY(); $nexY+=10; $totalunit=0; $totalvalue=$totalvaluesell=0; - + $arrayofuniqueproduct = array(); + //dol_syslog('List products', LOG_DEBUG); $resql = $db->query($sql); if ($resql) @@ -474,7 +503,7 @@ class pdf_stdmouvement extends ModelePDFMouvement if ($objtp->label != '') $objp->produit = $objtp->label; } } - + $curY = $nexY; $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage $pdf->SetTextColor(0,0,0); @@ -482,7 +511,7 @@ class pdf_stdmouvement extends ModelePDFMouvement $pdf->setTopMargin($tab_top_newpage); $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. $pageposbefore=$pdf->getPage(); - + // Description of product line $curX = $this->posxdesc-1; @@ -535,7 +564,7 @@ class pdf_stdmouvement extends ModelePDFMouvement } $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut - + // $objp = $db->fetch_object($resql); $userstatic->id=$objp->fk_user_author; @@ -565,8 +594,8 @@ class pdf_stdmouvement extends ModelePDFMouvement $origin = $movement->get_origin($objp->fk_origin, $objp->origintype); } else { $origin = ''; - } - + } + // Id movement. $pdf->SetXY($this->posxidref, $curY); $pdf->MultiCell($this->posxdesc-$this->posxidref-0.8, 3, $objp->mid, 0, 'L'); @@ -585,8 +614,8 @@ class pdf_stdmouvement extends ModelePDFMouvement // Lot/serie $pdf->SetXY($this->posxqty, $curY); - $pdf->MultiCell($this->posxup-$this->posxqty-0.8, 3, $productlot->batch, 0, 'R'); - + $pdf->MultiCell($this->posxup-$this->posxqty-0.8, 3, $productlot->batch, 0, 'R'); + // Inv. code $pdf->SetXY($this->posxup, $curY); $pdf->MultiCell($this->posxunit-$this->posxup-0.8, 3, $objp->inventorycode, 0, 'R'); @@ -595,7 +624,7 @@ class pdf_stdmouvement extends ModelePDFMouvement $pdf->SetXY($this->posxunit, $curY); $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 3, $objp->label, 0, 'R'); $totalvalue+=price2num($objp->ppmp*$objp->value,'MT'); - + // Origin $pricemin=$objp->price; $pdf->SetXY($this->posxdiscount, $curY); @@ -608,9 +637,9 @@ class pdf_stdmouvement extends ModelePDFMouvement $pdf->SetXY($this->postotalht, $curY); $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $objp->qty, 0, 'R', 0); - + $totalvaluesell+=price2num($pricemin*$objp->value,'MT'); - + $nexY+=3.5; // Passe espace entre les lignes // Add line if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1)) @@ -623,7 +652,7 @@ class pdf_stdmouvement extends ModelePDFMouvement } $nexY+=2; // Passe espace entre les lignes - + // Detect if some page were added automatically and output _tableau for past pages while ($pagenb < $pageposafter) { @@ -668,9 +697,9 @@ class pdf_stdmouvement extends ModelePDFMouvement */ $nexY = $pdf->GetY(); $nexY+=5; - $curY = $nexY; + $curY = $nexY; - $pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26))); + $pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26))); $pdf->line($this->marge_gauche, $curY-1, $this->page_largeur-$this->marge_droite, $curY-1); $pdf->SetLineStyle(array('dash'=>0)); @@ -680,11 +709,10 @@ class pdf_stdmouvement extends ModelePDFMouvement // Total $pdf->SetXY($this->posxidref, $curY); $pdf->MultiCell($this->posxdesc-$this->posxidref, 3, $langs->trans("Total"), 0, 'L'); - + // Total Qty $pdf->SetXY($this->postotalht, $curY); $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $totalunit, 0, 'R', 0); - } else { @@ -720,8 +748,8 @@ class pdf_stdmouvement extends ModelePDFMouvement $curY = $tab_top + 7; $nexY = $tab_top + 7; - $tab_top = $tab_top_newpage+21; - + $tab_top = $tab_top_newpage+21; + // Show square if ($pagenb == 1) { @@ -733,7 +761,7 @@ class pdf_stdmouvement extends ModelePDFMouvement $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code); $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } - + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; // Affiche zone infos @@ -790,7 +818,7 @@ class pdf_stdmouvement extends ModelePDFMouvement * @param string $currency Currency code * @return void */ - function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='') + function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '') { global $conf; @@ -820,14 +848,14 @@ class pdf_stdmouvement extends ModelePDFMouvement // Output Rect //$this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect prend une longueur en 3eme param et 4eme param - + $pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26))); - $pdf->SetDrawColor(220,26,26); + $pdf->SetDrawColor(220,26,26); $pdf->line($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite, $tab_top); $pdf->SetLineStyle(array('dash'=>0)); $pdf->SetDrawColor(128,128,128); $pdf->SetTextColor(0,0,120); - + //Ref mouv if (empty($hidetop)) { @@ -835,7 +863,7 @@ class pdf_stdmouvement extends ModelePDFMouvement $pdf->SetXY($this->posxidref, $tab_top+1); $pdf->MultiCell($this->posxdatemouv-$this->posxdatemouv-0.8,3, $outputlangs->transnoentities("Ref"),'','L'); } - + //Date mouv //$pdf->line($this->posxlabel-1, $tab_top, $this->posxlabel-1, $tab_top + $tab_height); if (empty($hidetop)) @@ -847,7 +875,7 @@ class pdf_stdmouvement extends ModelePDFMouvement //Ref Product //$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height); if (empty($hidetop)) - { + { $pdf->SetXY($this->posxdesc-1, $tab_top+1); $pdf->MultiCell($this->posxlabel-$this->posxdesc,2, $outputlangs->transnoentities("Ref. Product"),'','C'); } @@ -862,7 +890,7 @@ class pdf_stdmouvement extends ModelePDFMouvement //Lot/serie Product //$pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height); - if (empty($hidetop)) + if (empty($hidetop)) { $pdf->SetXY($this->posxqty, $tab_top + 1); $pdf->MultiCell($this->posxup - $this->posxqty, 2, $outputlangs->transnoentities("Lot/Série"), '','C'); @@ -877,34 +905,33 @@ class pdf_stdmouvement extends ModelePDFMouvement } //Label mouvement - //$pdf->line($this->posxunit, $tab_top, $this->posxunit, $tab_top + $tab_height); + //$pdf->line($this->posxunit, $tab_top, $this->posxunit, $tab_top + $tab_height); if (empty($hidetop)) { $pdf->SetXY($this->posxunit, $tab_top+1); $pdf->MultiCell($this->posxdiscount-$this->posxunit,2, $outputlangs->transnoentities("Label Mouvement"),'','C'); } - + //Origin - //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height); + //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height); if (empty($hidetop)) { $pdf->SetXY($this->posxdiscount+2, $tab_top+1); $pdf->MultiCell($this->postotalht-$this->posxdiscount-0.8,2, $outputlangs->transnoentities("Origin"),'','C'); } - + //Qty - //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height); + //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height); if (empty($hidetop)) { $pdf->SetXY($this->postotalht+2, $tab_top+1); $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht,2, $outputlangs->transnoentities("Qty"),'','C'); } - - $pdf->SetDrawColor(220,26,26); + + $pdf->SetDrawColor(220,26,26); $pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26))); - $pdf->line($this->marge_gauche, $tab_top+11, $this->page_largeur-$this->marge_droite, $tab_top+11); + $pdf->line($this->marge_gauche, $tab_top+11, $this->page_largeur-$this->marge_droite, $tab_top+11); $pdf->SetLineStyle(array('dash'=>0)); - } /** @@ -917,16 +944,13 @@ class pdf_stdmouvement extends ModelePDFMouvement * @param string $titlekey Translation key to show as title of document * @return void */ - function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="") + function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey = "") { global $conf,$langs,$db,$hookmanager; - $outputlangs->load("main"); - $outputlangs->load("bills"); - $outputlangs->load("propal"); - $outputlangs->load("companies"); - $outputlangs->load("orders"); - $outputlangs->load("stocks"); + // Load traductions files requiredby by page + $outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders", "stocks")); + $default_font_size = pdf_getPDFFontSize($outputlangs); if ($object->type == 1) $titlekey='ServiceSheet'; @@ -990,22 +1014,22 @@ class pdf_stdmouvement extends ModelePDFMouvement $pdf->SetXY($posx,$posy); $pdf->SetTextColor(0,0,60); $pdf->MultiCell(100, 3, $outputlangs->transnoentities("LocationSummary").' :', '', 'R'); - + $posy+=4; $pdf->SetXY($posx-50,$posy); $pdf->MultiCell(150, 3, $object->lieu, '', 'R'); - - + + // Parent MouvementStock $posy+=4; $pdf->SetXY($posx,$posy); $pdf->SetTextColor(0,0,60); $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ParentWarehouse").' :', '', 'R'); - + $posy+=4; $pdf->SetXY($posx-50,$posy); $e = new MouvementStock($db); - if(!empty($object->fk_parent) && $e->fetch($object->fk_parent) > 0) + if(!empty($object->fk_parent) && $e->fetch($object->fk_parent) > 0) { $pdf->MultiCell(150, 3, $e->libelle, '', 'R'); } @@ -1013,14 +1037,14 @@ class pdf_stdmouvement extends ModelePDFMouvement { $pdf->MultiCell(150, 3, $outputlangs->transnoentities("None"), '', 'R'); } - + // Description $nexY = $pdf->GetY(); $nexY+=5; $pdf->SetXY($posx,$posy); $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, ''.$outputlangs->transnoentities("Description").' : '.nl2br($object->description), 0, 1); $nexY = $pdf->GetY(); - + $calcproductsunique=$object->nb_different_products(); $calcproducts=$object->nb_products(); @@ -1032,12 +1056,12 @@ class pdf_stdmouvement extends ModelePDFMouvement $valtoshow=price2num($calcproducts['nb'], 'MS'); $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, ''.$outputlangs->transnoentities("NumberOfProducts").' : '.(empty($valtoshow)?'0':$valtoshow), 0, 1); $nexY = $pdf->GetY(); - + // Value $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, ''.$outputlangs->transnoentities("EstimatedStockValueShort").' : '. price((empty($calcproducts['value'])?'0':price2num($calcproducts['value'],'MT')), 0, $langs, 0, -1, -1, $conf->currency), 0, 1); $nexY = $pdf->GetY(); - - + + // Last movement $sql = "SELECT max(m.datem) as datem"; $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m"; @@ -1065,7 +1089,7 @@ class pdf_stdmouvement extends ModelePDFMouvement $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, ''.$outputlangs->transnoentities("LastMovement").' : '.$toWrite, 0, 1); $nexY = $pdf->GetY(); - + /*if ($object->ref_client) { $posy+=5; @@ -1148,12 +1172,10 @@ class pdf_stdmouvement extends ModelePDFMouvement * @param int $hidefreetext 1=Hide free text * @return int Return height of bottom margin including footer text */ - function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0) + function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0) { global $conf; $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; return pdf_pagefoot($pdf,$outputlangs,'PRODUCT_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext); } - } -