From c0e5132108d24617836d30a27ae5c46af83f8c4e Mon Sep 17 00:00:00 2001 From: wdammak <26695620+wdammak@users.noreply.github.com> Date: Wed, 9 May 2018 15:07:11 +0100 Subject: [PATCH] Documents generes movement warehouse --- htdocs/product/stock/mouvement.php | 153 ++++++++++++++++++++++++++++- 1 file changed, 149 insertions(+), 4 deletions(-) diff --git a/htdocs/product/stock/mouvement.php b/htdocs/product/stock/mouvement.php index 883cd316c76..edabf9184da 100644 --- a/htdocs/product/stock/mouvement.php +++ b/htdocs/product/stock/mouvement.php @@ -26,6 +26,7 @@ */ 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'; @@ -68,6 +69,7 @@ $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'); @@ -84,6 +86,7 @@ $pdluoid=GETPOST('pdluoid','int'); $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'); @@ -101,6 +104,7 @@ $arrayfields=array( '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("LabelMovement"), 'checked'=>1), + 'm.type_mouvement'=>array('label'=>$langs->trans("Type Mouvement"), '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), @@ -114,6 +118,10 @@ $arrayfields=array( * 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=''; } @@ -130,6 +138,8 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x', $month=''; $search_ref=''; $search_movement=""; + $search_type_mouvement=""; + $search_inventorycode=""; $search_product_ref=""; $search_product=""; $search_warehouse=""; @@ -389,7 +399,58 @@ if ($action == "transfert_stock" && ! $cancel) } } -if (empty($reshook)) + +/* + * Build document + */ +if ($action == 'builddoc') // En get ou en post +{ + if ($id > 0 || $ref) + { + $object = new MouvementStock($db); + $result = $object->fetch($id, $ref); + if ($result <= 0) + { + print 'No record found'; + exit; + } + } + + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); + + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + $ret=$object->fetch($id); // Reload to get new records + $result= $object->generateDocument($object->modelpdf, $outputlangs); + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $action=''; + } +} + +// Delete file in doc form +elseif ($action == 'remove_file') +{ + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + $upload_dir = $conf->stock->dir_output."/mouvement" ; + $file = $upload_dir . '/' . GETPOST('file'); + $ret=dol_delete_file($file,0,0,0,$object); + if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs'); + else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors'); +} + +if (empty($reshook) && $action != 'remove_file') { $objectclass='MouvementStock'; $objectlabel='Movements'; @@ -419,6 +480,7 @@ $sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.tobatch, p.f $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 @@ -460,6 +522,7 @@ if ($search_warehouse > 0) $sql.= " AND e.rowid = '".$db->escape($searc 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) $sql.= " AND m.type_mouvement = '".$db->escape($search_type_mouvement)."'"; // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; // Add where from hooks @@ -480,11 +543,21 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) } } -$sql.= $db->plimit($limit+1, $offset); +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); @@ -663,6 +736,7 @@ if ($resql) 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); @@ -801,6 +875,22 @@ if ($resql) print '