Fixing style errors.

This commit is contained in:
stickler-ci 2021-07-29 14:20:50 +00:00
parent 3f42689633
commit 9805281733
15 changed files with 478 additions and 862 deletions

View File

@ -70,13 +70,11 @@ $setupnotempty = 0;
* Actions * Actions
*/ */
if ((float) DOL_VERSION >= 6) if ((float) DOL_VERSION >= 6) {
{
include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
} }
if ($action == 'updateMask') if ($action == 'updateMask') {
{
$maskconststocktransfer = GETPOST('maskconststocktransfer', 'alpha'); $maskconststocktransfer = GETPOST('maskconststocktransfer', 'alpha');
$maskstocktransfer = GETPOST('maskStockTransfer', 'alpha'); $maskstocktransfer = GETPOST('maskStockTransfer', 'alpha');
@ -84,14 +82,12 @@ if ($action == 'updateMask')
if (!$res > 0) $error++; if (!$res > 0) $error++;
if (!$error) if (!$error) {
{
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else { } else {
setEventMessages($langs->trans("Error"), null, 'errors'); setEventMessages($langs->trans("Error"), null, 'errors');
} }
} elseif ($action == 'specimen') } elseif ($action == 'specimen') {
{
$modele = GETPOST('module', 'alpha'); $modele = GETPOST('module', 'alpha');
$tmpobjectkey = GETPOST('object'); $tmpobjectkey = GETPOST('object');
@ -101,25 +97,21 @@ if ($action == 'updateMask')
// Search template files // Search template files
$file = ''; $classname = ''; $filefound = 0; $file = ''; $classname = ''; $filefound = 0;
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
foreach ($dirmodels as $reldir) foreach ($dirmodels as $reldir) {
{
$file = dol_buildpath($reldir."core/modules/stocktransfer/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0); $file = dol_buildpath($reldir."core/modules/stocktransfer/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
if (file_exists($file)) if (file_exists($file)) {
{
$filefound = 1; $filefound = 1;
$classname = "pdf_".$modele; $classname = "pdf_".$modele;
break; break;
} }
} }
if ($filefound) if ($filefound) {
{
require_once $file; require_once $file;
$module = new $classname($db); $module = new $classname($db);
if ($module->write_file($tmpobject, $langs) > 0) if ($module->write_file($tmpobject, $langs) > 0) {
{
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf"); header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
return; return;
} else { } else {
@ -133,28 +125,23 @@ if ($action == 'updateMask')
} }
// Activate a model // Activate a model
elseif ($action == 'set') elseif ($action == 'set') {
{
$ret = addDocumentModel($value, 'stocktransfer', $label, $scandir); $ret = addDocumentModel($value, 'stocktransfer', $label, $scandir);
} elseif ($action == 'del') } elseif ($action == 'del') {
{
$tmpobjectkey = GETPOST('object'); $tmpobjectkey = GETPOST('object');
$ret = delDocumentModel($value, $type); $ret = delDocumentModel($value, $type);
if ($ret > 0) if ($ret > 0) {
{
$constforval = strtoupper($tmpobjectkey).'_ADDON_PDF'; $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
if ($conf->global->$constforval == "$value") dolibarr_del_const($db, $constforval, $conf->entity); if ($conf->global->$constforval == "$value") dolibarr_del_const($db, $constforval, $conf->entity);
} }
} }
// Set default model // Set default model
elseif ($action == 'setdoc') elseif ($action == 'setdoc') {
{
$tmpobjectkey = GETPOST('object'); $tmpobjectkey = GETPOST('object');
$constforval = strtoupper($tmpobjectkey).'_ADDON_PDF'; $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
{
// The constant that was read before the new set // The constant that was read before the new set
// We therefore requires a variable to have a coherent view // We therefore requires a variable to have a coherent view
$conf->global->$constforval = $value; $conf->global->$constforval = $value;
@ -162,12 +149,10 @@ elseif ($action == 'setdoc')
// On active le modele // On active le modele
$ret = delDocumentModel($value, $type); $ret = delDocumentModel($value, $type);
if ($ret > 0) if ($ret > 0) {
{
$ret = addDocumentModel($value, $type, $label, $scandir); $ret = addDocumentModel($value, $type, $label, $scandir);
} }
} elseif ($action == 'setmod') } elseif ($action == 'setmod') {
{
// TODO Check if numbering module chosen can be activated // TODO Check if numbering module chosen can be activated
// by calling method canBeActivated // by calling method canBeActivated
$tmpobjectkey = GETPOST('object'); $tmpobjectkey = GETPOST('object');
@ -279,19 +264,14 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
clearstatcache(); clearstatcache();
foreach ($dirmodels as $reldir) foreach ($dirmodels as $reldir) {
{
$dir = dol_buildpath($reldir."core/modules/".$moduledir); $dir = dol_buildpath($reldir."core/modules/".$moduledir);
if (is_dir($dir)) if (is_dir($dir)) {
{
$handle = opendir($dir); $handle = opendir($dir);
if (is_resource($handle)) if (is_resource($handle)) {
{ while (($file = readdir($handle)) !== false) {
while (($file = readdir($handle)) !== false) if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php') {
{
if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php')
{
$file = substr($file, 0, dol_strlen($file) - 4); $file = substr($file, 0, dol_strlen($file) - 4);
require_once $dir.'/'.$file.'.php'; require_once $dir.'/'.$file.'.php';
@ -302,8 +282,7 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
if ($module->isEnabled()) if ($module->isEnabled()) {
{
dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php'); dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
print '<tr class="oddeven"><td>'.$module->name."</td><td>\n"; print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
@ -320,8 +299,7 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
print '<td class="center">'; print '<td class="center">';
$constforvar = 'STOCKTRANSFER_'.strtoupper($myTmpObjectKey).'_ADDON'; $constforvar = 'STOCKTRANSFER_'.strtoupper($myTmpObjectKey).'_ADDON';
if ($conf->global->$constforvar == $file) if ($conf->global->$constforvar == $file) {
{
print img_picto($langs->trans("Activated"), 'switch_on'); print img_picto($langs->trans("Activated"), 'switch_on');
} else { } else {
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&object='.strtolower($myTmpObjectKey).'&value='.$file.'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&object='.strtolower($myTmpObjectKey).'&value='.$file.'">';
@ -380,12 +358,10 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
$sql .= " WHERE type = '".$type."'"; $sql .= " WHERE type = '".$type."'";
$sql .= " AND entity = ".$conf->entity; $sql .= " AND entity = ".$conf->entity;
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$i = 0; $i = 0;
$num_rows = $db->num_rows($resql); $num_rows = $db->num_rows($resql);
while ($i < $num_rows) while ($i < $num_rows) {
{
$array = $db->fetch_array($resql); $array = $db->fetch_array($resql);
array_push($def, $array[0]); array_push($def, $array[0]);
$i++; $i++;
@ -406,31 +382,23 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
clearstatcache(); clearstatcache();
foreach ($dirmodels as $reldir) foreach ($dirmodels as $reldir) {
{ foreach (array('', '/doc') as $valdir) {
foreach (array('', '/doc') as $valdir)
{
$realpath = $reldir."core/modules/".$moduledir.$valdir; $realpath = $reldir."core/modules/".$moduledir.$valdir;
$dir = dol_buildpath($realpath); $dir = dol_buildpath($realpath);
if (is_dir($dir)) if (is_dir($dir)) {
{
$handle = opendir($dir); $handle = opendir($dir);
if (is_resource($handle)) if (is_resource($handle)) {
{ while (($file = readdir($handle)) !== false) {
while (($file = readdir($handle)) !== false)
{
$filelist[] = $file; $filelist[] = $file;
} }
closedir($handle); closedir($handle);
arsort($filelist); arsort($filelist);
foreach ($filelist as $file) foreach ($filelist as $file) {
{ if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) if (file_exists($dir.'/'.$file)) {
{
if (file_exists($dir.'/'.$file))
{
$name = substr($file, 4, dol_strlen($file) - 16); $name = substr($file, 4, dol_strlen($file) - 16);
$classname = substr($file, 0, dol_strlen($file) - 12); $classname = substr($file, 0, dol_strlen($file) - 12);
@ -441,8 +409,7 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0; if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0;
if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0; if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0;
if ($modulequalified) if ($modulequalified) {
{
print '<tr class="oddeven"><td width="100">'; print '<tr class="oddeven"><td width="100">';
print (empty($module->name) ? $name : $module->name); print (empty($module->name) ? $name : $module->name);
print "</td><td>\n"; print "</td><td>\n";
@ -451,8 +418,7 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
print '</td>'; print '</td>';
// Active // Active
if (in_array($name, $def)) if (in_array($name, $def)) {
{
print '<td class="center">'."\n"; print '<td class="center">'."\n";
print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">';
print img_picto($langs->trans("Enabled"), 'switch_on'); print img_picto($langs->trans("Enabled"), 'switch_on');
@ -467,8 +433,7 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
// Default // Default
print '<td class="center">'; print '<td class="center">';
$constforvar = 'STOCKTRANSFER_'.strtoupper($myTmpObjectKey).'_ADDON'; $constforvar = 'STOCKTRANSFER_'.strtoupper($myTmpObjectKey).'_ADDON';
if ($conf->global->$constforvar == $name) if ($conf->global->$constforvar == $name) {
{
print img_picto($langs->trans("Default"), 'on'); print img_picto($langs->trans("Default"), 'on');
} else { } else {
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>'; print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
@ -478,8 +443,7 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
// Info // Info
$htmltooltip = ''.$langs->trans("Name").': '.$module->name; $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
$htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown")); $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
if ($module->type == 'pdf') if ($module->type == 'pdf') {
{
$htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
} }
$htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file; $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
@ -494,8 +458,7 @@ foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
// Preview // Preview
print '<td class="center">'; print '<td class="center">';
if ($module->type == 'pdf') if ($module->type == 'pdf') {
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'generic').'</a>'; print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'&object='.$myTmpObjectKey.'">'.img_object($langs->trans("Preview"), 'generic').'</a>';
} else { } else {
print img_object($langs->trans("PreviewNotAvailable"), 'generic'); print img_object($langs->trans("PreviewNotAvailable"), 'generic');

View File

@ -1641,7 +1641,7 @@ function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabM
} }
} }
if($conf->stocktransfer->enabled) { if ($conf->stocktransfer->enabled) {
$newmenu->add('/product/stock/stocktransfer/stocktransfer_list.php', $langs->trans("ModuleStockTransferName"), 0, $user->rights->stocktransfer->stocktransfer->read, '', $mainmenu, 'stocktransfer', 0, '', '', '', img_picto('', 'stock', 'class="pictofixedwidth"')); $newmenu->add('/product/stock/stocktransfer/stocktransfer_list.php', $langs->trans("ModuleStockTransferName"), 0, $user->rights->stocktransfer->stocktransfer->read, '', $mainmenu, 'stocktransfer', 0, '', '', '', img_picto('', 'stock', 'class="pictofixedwidth"'));
$newmenu->add('/product/stock/stocktransfer/stocktransfer_card.php?action=create', $langs->trans('StockTransferNew'), 1, $user->rights->stocktransfer->stocktransfer->write); $newmenu->add('/product/stock/stocktransfer/stocktransfer_card.php?action=create', $langs->trans('StockTransferNew'), 1, $user->rights->stocktransfer->stocktransfer->write);
$newmenu->add('/product/stock/stocktransfer/stocktransfer_list.php', $langs->trans('List'), 1, $user->rights->stocktransfer->stocktransfer->read); $newmenu->add('/product/stock/stocktransfer/stocktransfer_list.php', $langs->trans('List'), 1, $user->rights->stocktransfer->stocktransfer->read);

View File

@ -348,26 +348,26 @@ class modStockTransfer extends DolibarrModules
// 0=Menu for internal users, 1=external users, 2=both // 0=Menu for internal users, 1=external users, 2=both
'user'=>2 'user'=>2
); );
$this->menu[$r++]=array( $this->menu[$r++]=array(
// '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'fk_menu'=>'fk_mainmenu=products,fk_leftmenu=stock', 'fk_menu'=>'fk_mainmenu=products,fk_leftmenu=stock',
// This is a Left menu entry // This is a Left menu entry
'type'=>'left', 'type'=>'left',
'titre'=>$langs->trans('StockTransferList'), 'titre'=>$langs->trans('StockTransferList'),
'mainmenu'=>'products', 'mainmenu'=>'products',
'leftmenu'=>'stocktransfer_stocktransferlist', 'leftmenu'=>'stocktransfer_stocktransferlist',
'url'=>'/stocktransfer/stocktransfer_list.php', 'url'=>'/stocktransfer/stocktransfer_list.php',
// Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'langs'=>'stocktransfer@stocktransfer', 'langs'=>'stocktransfer@stocktransfer',
'position'=>1100+$r, 'position'=>1100+$r,
// Define condition to show or hide menu entry. Use '$conf->stocktransfer->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. // Define condition to show or hide menu entry. Use '$conf->stocktransfer->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
'enabled'=>'$conf->stocktransfer->enabled', 'enabled'=>'$conf->stocktransfer->enabled',
// Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules // Use 'perms'=>'$user->rights->stocktransfer->level1->level2' if you want your menu with a permission rules
'perms'=>'1', 'perms'=>'1',
'target'=>'', 'target'=>'',
// 0=Menu for internal users, 1=external users, 2=both // 0=Menu for internal users, 1=external users, 2=both
'user'=>2, 'user'=>2,
);*/ );*/
/* END MODULEBUILDER LEFTMENU STOCKTRANSFER */ /* END MODULEBUILDER LEFTMENU STOCKTRANSFER */
@ -464,13 +464,11 @@ class modStockTransfer extends DolibarrModules
$dirodt=DOL_DATA_ROOT.'/doctemplates/stocktransfer'; $dirodt=DOL_DATA_ROOT.'/doctemplates/stocktransfer';
$dest=$dirodt.'/template_stocktransfers.odt'; $dest=$dirodt.'/template_stocktransfers.odt';
if (file_exists($src) && ! file_exists($dest)) if (file_exists($src) && ! file_exists($dest)) {
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
dol_mkdir($dirodt); dol_mkdir($dirodt);
$result=dol_copy($src, $dest, 0, 0); $result=dol_copy($src, $dest, 0, 0);
if ($result < 0) if ($result < 0) {
{
$langs->load("errors"); $langs->load("errors");
$this->error=$langs->trans('ErrorFailToCopyFile', $src, $dest); $this->error=$langs->trans('ErrorFailToCopyFile', $src, $dest);
return 0; return 0;
@ -489,20 +487,21 @@ class modStockTransfer extends DolibarrModules
// Rôles // Rôles
$resql = $db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STDEST" AND element = "StockTransfer" AND source = "internal"'); $resql = $db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STDEST" AND element = "StockTransfer" AND source = "internal"');
$res = $db->fetch_object($resql); $res = $db->fetch_object($resql);
if(empty($res)) $db->query('INSERT INTO '.MAIN_DB_PREFIX.'c_type_contact(rowid, element, source, code, libelle, active, module, position) VALUES('.$this->getNextId().', "StockTransfer", "internal", "STRESP", "Responsable du transfert de stocks", 1, NULL, 0)'); if (empty($res)) $db->query('INSERT INTO '.MAIN_DB_PREFIX.'c_type_contact(rowid, element, source, code, libelle, active, module, position) VALUES('.$this->getNextId().', "StockTransfer", "internal", "STRESP", "Responsable du transfert de stocks", 1, NULL, 0)');
$resql = $db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STFROM" AND element = "StockTransfer" AND source = "external"'); $resql = $db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STFROM" AND element = "StockTransfer" AND source = "external"');
$res = $db->fetch_object($resql); $res = $db->fetch_object($resql);
if(empty($res)) $db->query('INSERT INTO '.MAIN_DB_PREFIX.'c_type_contact(rowid, element, source, code, libelle, active, module, position) VALUES('.$this->getNextId().', "StockTransfer", "external", "STFROM", "Contact expéditeur transfert de stocks", 1, NULL, 0)'); if (empty($res)) $db->query('INSERT INTO '.MAIN_DB_PREFIX.'c_type_contact(rowid, element, source, code, libelle, active, module, position) VALUES('.$this->getNextId().', "StockTransfer", "external", "STFROM", "Contact expéditeur transfert de stocks", 1, NULL, 0)');
$resql = $db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STDEST" AND element = "StockTransfer" AND source = "external"'); $resql = $db->query('SELECT rowid FROM '.MAIN_DB_PREFIX.'c_type_contact WHERE code = "STDEST" AND element = "StockTransfer" AND source = "external"');
$res = $db->fetch_object($resql); $res = $db->fetch_object($resql);
if(empty($res)) $db->query('INSERT INTO '.MAIN_DB_PREFIX.'c_type_contact(rowid, element, source, code, libelle, active, module, position) VALUES('.$this->getNextId().', "StockTransfer", "external", "STDEST", "Contact destinataire transfert de stocks", 1, NULL, 0)'); if (empty($res)) $db->query('INSERT INTO '.MAIN_DB_PREFIX.'c_type_contact(rowid, element, source, code, libelle, active, module, position) VALUES('.$this->getNextId().', "StockTransfer", "external", "STDEST", "Contact destinataire transfert de stocks", 1, NULL, 0)');
return $this->_init($sql, $options); return $this->_init($sql, $options);
} }
function getNextId() { function getNextId()
{
global $db; global $db;
@ -510,8 +509,7 @@ class modStockTransfer extends DolibarrModules
$newid = 0; $newid = 0;
$sql = "SELECT max(rowid) newid from ".MAIN_DB_PREFIX."c_type_contact"; $sql = "SELECT max(rowid) newid from ".MAIN_DB_PREFIX."c_type_contact";
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result) {
{
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$newid = ($obj->newid + 1); $newid = ($obj->newid + 1);
} else { } else {

View File

@ -209,23 +209,18 @@ class pdf_eagle extends ModelePdfStockTransfer
// Loop on each lines to detect if there is at least one image to show // Loop on each lines to detect if there is at least one image to show
$realpatharray = array(); $realpatharray = array();
if (!empty($conf->global->MAIN_GENERATE_SHIPMENT_WITH_PICTURE)) if (!empty($conf->global->MAIN_GENERATE_SHIPMENT_WITH_PICTURE)) {
{
$objphoto = new Product($this->db); $objphoto = new Product($this->db);
for ($i = 0; $i < $nblines; $i++) for ($i = 0; $i < $nblines; $i++) {
{
if (empty($object->lines[$i]->fk_product)) continue; if (empty($object->lines[$i]->fk_product)) continue;
$objphoto = new Product($this->db); $objphoto = new Product($this->db);
$objphoto->fetch($object->lines[$i]->fk_product); $objphoto->fetch($object->lines[$i]->fk_product);
if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
{
$pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/"; $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product').$object->lines[$i]->fk_product."/photos/";
$dir = $conf->product->dir_output.'/'.$pdir; $dir = $conf->product->dir_output.'/'.$pdir;
} } else {
else
{
$pdir = get_exdir(0, 2, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/'; $pdir = get_exdir(0, 2, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
$dir = $conf->product->dir_output.'/'.$pdir; $dir = $conf->product->dir_output.'/'.$pdir;
} }
@ -235,17 +230,12 @@ class pdf_eagle extends ModelePdfStockTransfer
foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) { foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) { if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) {
// If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
if ($obj['photo_vignette']) if ($obj['photo_vignette']) {
{
$filename = $obj['photo_vignette']; $filename = $obj['photo_vignette'];
} } else {
else
{
$filename = $obj['photo']; $filename = $obj['photo'];
} }
} } else {
else
{
$filename = $obj['photo']; $filename = $obj['photo'];
} }
@ -259,35 +249,27 @@ class pdf_eagle extends ModelePdfStockTransfer
if (count($realpatharray) == 0) $this->posxpicture = $this->posxqty; if (count($realpatharray) == 0) $this->posxpicture = $this->posxqty;
if ($conf->stocktransfer->dir_output) if ($conf->stocktransfer->dir_output) {
{
// Definition de $dir et $file // Definition de $dir et $file
if ($object->specimen) if ($object->specimen) {
{
$dir = $conf->stocktransfer->dir_output; $dir = $conf->stocktransfer->dir_output;
$file = $dir."/SPECIMEN.pdf"; $file = $dir."/SPECIMEN.pdf";
} } else {
else
{
$stocktransferref = dol_sanitizeFileName($object->ref); $stocktransferref = dol_sanitizeFileName($object->ref);
$dir = $conf->stocktransfer->dir_output.'/'.$object->element."/".$stocktransferref; $dir = $conf->stocktransfer->dir_output.'/'.$object->element."/".$stocktransferref;
$file = $dir."/".$stocktransferref.".pdf"; $file = $dir."/".$stocktransferref.".pdf";
} }
if (!file_exists($dir)) if (!file_exists($dir)) {
{ if (dol_mkdir($dir) < 0) {
if (dol_mkdir($dir) < 0)
{
$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
return 0; return 0;
} }
} }
if (file_exists($dir)) if (file_exists($dir)) {
{
// Add pdfgeneration hook // Add pdfgeneration hook
if (!is_object($hookmanager)) if (!is_object($hookmanager)) {
{
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
$hookmanager = new HookManager($this->db); $hookmanager = new HookManager($this->db);
} }
@ -307,15 +289,13 @@ class pdf_eagle extends ModelePdfStockTransfer
if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS > 0) $heightforfooter += 6; if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS > 0) $heightforfooter += 6;
$pdf->SetAutoPageBreak(1, 0); $pdf->SetAutoPageBreak(1, 0);
if (class_exists('TCPDF')) if (class_exists('TCPDF')) {
{
$pdf->setPrintHeader(false); $pdf->setPrintHeader(false);
$pdf->setPrintFooter(false); $pdf->setPrintFooter(false);
} }
$pdf->SetFont(pdf_getPDFFont($outputlangs)); $pdf->SetFont(pdf_getPDFFont($outputlangs));
// Set path to the background PDF File // Set path to the background PDF File
if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
{
$pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
$tplidx = $pdf->importPage(1); $tplidx = $pdf->importPage(1);
} }
@ -351,11 +331,9 @@ class pdf_eagle extends ModelePdfStockTransfer
// Incoterm // Incoterm
$height_incoterms = 0; $height_incoterms = 0;
if ($conf->incoterm->enabled) if ($conf->incoterm->enabled) {
{
$desc_incoterms = $object->getIncotermsForPDF(); $desc_incoterms = $object->getIncotermsForPDF();
if ($desc_incoterms) if ($desc_incoterms) {
{
$tab_top = 88; $tab_top = 88;
$pdf->SetFont('', '', $default_font_size - 1); $pdf->SetFont('', '', $default_font_size - 1);
@ -372,8 +350,7 @@ class pdf_eagle extends ModelePdfStockTransfer
} }
} }
if (!empty($object->note_public) || !empty($object->tracking_number)) if (!empty($object->note_public) || !empty($object->tracking_number)) {
{
$tab_top = 88 + $height_incoterms; $tab_top = 88 + $height_incoterms;
$tab_top_alt = $tab_top; $tab_top_alt = $tab_top;
@ -382,24 +359,20 @@ class pdf_eagle extends ModelePdfStockTransfer
//$tab_top_alt += 1; //$tab_top_alt += 1;
// Tracking number // Tracking number
if (!empty($object->tracking_number)) if (!empty($object->tracking_number)) {
{
$pdf->writeHTMLCell(60, 4, $this->posxdesc - 1, $tab_top - 1, $outputlangs->transnoentities("TrackingNumber")." : ".$object->tracking_number, 0, 1, false, true, 'L'); $pdf->writeHTMLCell(60, 4, $this->posxdesc - 1, $tab_top - 1, $outputlangs->transnoentities("TrackingNumber")." : ".$object->tracking_number, 0, 1, false, true, 'L');
$tab_top_alt = $pdf->GetY(); $tab_top_alt = $pdf->GetY();
$object->getUrlTrackingStatus($object->tracking_number); $object->getUrlTrackingStatus($object->tracking_number);
if (!empty($object->tracking_url)) if (!empty($object->tracking_url)) {
{ if ($object->shipping_method_id > 0) {
if ($object->shipping_method_id > 0)
{
// Get code using getLabelFromKey // Get code using getLabelFromKey
$code = $outputlangs->getLabelFromKey($this->db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code'); $code = $outputlangs->getLabelFromKey($this->db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
$label = ''; $label = '';
if ($object->tracking_url != $object->tracking_number) $label .= $outputlangs->trans("LinkToTrackYourPackage")."<br>"; if ($object->tracking_url != $object->tracking_number) $label .= $outputlangs->trans("LinkToTrackYourPackage")."<br>";
$label .= $outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code)); $label .= $outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
//var_dump($object->tracking_url != $object->tracking_number);exit; //var_dump($object->tracking_url != $object->tracking_number);exit;
if ($object->tracking_url != $object->tracking_number) if ($object->tracking_url != $object->tracking_number) {
{
$label .= " : "; $label .= " : ";
$label .= $object->tracking_url; $label .= $object->tracking_url;
} }
@ -412,8 +385,7 @@ class pdf_eagle extends ModelePdfStockTransfer
} }
// Notes // Notes
if (!empty($object->note_public)) if (!empty($object->note_public)) {
{
$pdf->SetFont('', '', $default_font_size - 1); // Dans boucle pour gerer multi-page $pdf->SetFont('', '', $default_font_size - 1); // Dans boucle pour gerer multi-page
$pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1); $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1);
} }
@ -427,9 +399,7 @@ class pdf_eagle extends ModelePdfStockTransfer
$tab_height = $tab_height - $height_note; $tab_height = $tab_height - $height_note;
$tab_top = $nexY + 6; $tab_top = $nexY + 6;
} } else {
else
{
$height_note = 0; $height_note = 0;
} }
@ -439,8 +409,7 @@ class pdf_eagle extends ModelePdfStockTransfer
$TCacheEntrepots=array(); $TCacheEntrepots=array();
// Loop on each lines // Loop on each lines
for ($i = 0; $i < $nblines; $i++) for ($i = 0; $i < $nblines; $i++) {
{
$curY = $nexY; $curY = $nexY;
$pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
$pdf->SetTextColor(0, 0, 0); $pdf->SetTextColor(0, 0, 0);
@ -458,8 +427,7 @@ class pdf_eagle extends ModelePdfStockTransfer
$posYAfterDescription = 0; $posYAfterDescription = 0;
// We start with Photo of product line // We start with Photo of product line
if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) // If photo too high, we moved completely on new page if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // If photo too high, we moved completely on new page
{
$pdf->AddPage('', '', true); $pdf->AddPage('', '', true);
if (!empty($tplidx)) $pdf->useTemplate($tplidx); if (!empty($tplidx)) $pdf->useTemplate($tplidx);
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
@ -470,12 +438,10 @@ class pdf_eagle extends ModelePdfStockTransfer
// Allows data in the first page if description is long enough to break in multiples pages // Allows data in the first page if description is long enough to break in multiples pages
if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
$showpricebeforepagebreak = 1; $showpricebeforepagebreak = 1;
else else $showpricebeforepagebreak = 0;
$showpricebeforepagebreak = 0;
} }
if (isset($imglinesize['width']) && isset($imglinesize['height'])) if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
{
$curX = $this->posxpicture - 1; $curX = $this->posxpicture - 1;
$pdf->Image($realpatharray[$i], $curX + (($this->posxqty - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi $pdf->Image($realpatharray[$i], $curX + (($this->posxqty - $this->posxpicture - $imglinesize['width']) / 2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
// $pdf->Image does not increase value return by getY, so we save it manually // $pdf->Image does not increase value return by getY, so we save it manually
@ -486,7 +452,7 @@ class pdf_eagle extends ModelePdfStockTransfer
$curX = $this->posxdesc - 1; $curX = $this->posxdesc - 1;
$pdf->startTransaction(); $pdf->startTransaction();
if(method_exists($object->lines[$i], 'fetch_product')) { if (method_exists($object->lines[$i], 'fetch_product')) {
$object->lines[$i]->fetch_product(); $object->lines[$i]->fetch_product();
$object->lines[$i]->label = $object->lines[$i]->product->label; $object->lines[$i]->label = $object->lines[$i]->product->label;
$object->lines[$i]->description = $object->lines[$i]->product->description; $object->lines[$i]->description = $object->lines[$i]->product->description;
@ -495,8 +461,7 @@ class pdf_eagle extends ModelePdfStockTransfer
pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc); pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
$pageposafter = $pdf->getPage(); $pageposafter = $pdf->getPage();
if ($pageposafter > $pageposbefore) // There is a pagebreak if ($pageposafter > $pageposbefore) { // There is a pagebreak
{
$pdf->rollbackTransaction(true); $pdf->rollbackTransaction(true);
$pageposafter = $pageposbefore; $pageposafter = $pageposbefore;
//print $pageposafter.'-'.$pageposbefore;exit; //print $pageposafter.'-'.$pageposbefore;exit;
@ -506,28 +471,22 @@ class pdf_eagle extends ModelePdfStockTransfer
$pageposafter = $pdf->getPage(); $pageposafter = $pdf->getPage();
$posyafter = $pdf->GetY(); $posyafter = $pdf->GetY();
//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit; //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) // There is no space left for total+free text if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
{ if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
if ($i == ($nblines - 1)) // No more lines, and no space left to show total, so we create a new page
{
$pdf->AddPage('', '', true); $pdf->AddPage('', '', true);
if (!empty($tplidx)) $pdf->useTemplate($tplidx); if (!empty($tplidx)) $pdf->useTemplate($tplidx);
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
$pdf->setPage($pageposafter + 1); $pdf->setPage($pageposafter + 1);
} }
} } else {
else
{
// We found a page break // We found a page break
// Allows data in the first page if description is long enough to break in multiples pages // Allows data in the first page if description is long enough to break in multiples pages
if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE))
$showpricebeforepagebreak = 1; $showpricebeforepagebreak = 1;
else else $showpricebeforepagebreak = 0;
$showpricebeforepagebreak = 0;
} }
} } else // No pagebreak
else // No pagebreak
{ {
$pdf->commitTransaction(); $pdf->commitTransaction();
} }
@ -555,7 +514,7 @@ class pdf_eagle extends ModelePdfStockTransfer
$pdf->SetXY($this->posxqty, $curY); $pdf->SetXY($this->posxqty, $curY);
// Lot / série // Lot / série
if(!empty($conf->productbatch->enabled)) { if (!empty($conf->productbatch->enabled)) {
$pdf->SetXY($this->posxlot, $curY); $pdf->SetXY($this->posxlot, $curY);
$pdf->MultiCell(($this->posxqty - $this->posxlot), 3, $object->lines[$i]->batch, '', 'C'); $pdf->MultiCell(($this->posxqty - $this->posxlot), 3, $object->lines[$i]->batch, '', 'C');
} }
@ -567,7 +526,7 @@ class pdf_eagle extends ModelePdfStockTransfer
// Warehouse source // Warehouse source
$wh_source = new Entrepot($db); $wh_source = new Entrepot($db);
if(!empty($TCacheEntrepots[$object->lines[$i]->fk_warehouse_source])) $wh_source = $TCacheEntrepots[$object->lines[$i]->fk_warehouse_source]; if (!empty($TCacheEntrepots[$object->lines[$i]->fk_warehouse_source])) $wh_source = $TCacheEntrepots[$object->lines[$i]->fk_warehouse_source];
else { else {
$wh_source->fetch($object->lines[$i]->fk_warehouse_source); $wh_source->fetch($object->lines[$i]->fk_warehouse_source);
$TCacheEntrepots[$object->lines[$i]->fk_warehouse_source] = $wh_source; $TCacheEntrepots[$object->lines[$i]->fk_warehouse_source] = $wh_source;
@ -577,7 +536,7 @@ class pdf_eagle extends ModelePdfStockTransfer
// Warehouse destination // Warehouse destination
$wh_destination = new Entrepot($db); $wh_destination = new Entrepot($db);
if(!empty($TCacheEntrepots[$object->lines[$i]->fk_warehouse_destination])) $wh_destination = $TCacheEntrepots[$object->lines[$i]->fk_warehouse_destination]; if (!empty($TCacheEntrepots[$object->lines[$i]->fk_warehouse_destination])) $wh_destination = $TCacheEntrepots[$object->lines[$i]->fk_warehouse_destination];
else { else {
$wh_destination->fetch($object->lines[$i]->fk_warehouse_destination); $wh_destination->fetch($object->lines[$i]->fk_warehouse_destination);
$TCacheEntrepots[$object->lines[$i]->fk_warehouse_destination] = $wh_destination; $TCacheEntrepots[$object->lines[$i]->fk_warehouse_destination] = $wh_destination;
@ -585,8 +544,7 @@ class pdf_eagle extends ModelePdfStockTransfer
$pdf->SetXY($this->posxwarehousedestination, $curY); $pdf->SetXY($this->posxwarehousedestination, $curY);
$pdf->MultiCell(($this->posxpuht - $this->posxwarehousedestination), 3, $wh_destination->ref.(!empty($wh_destination->lieu) ? ' - '.$wh_destination->lieu : ''), '', 'C'); $pdf->MultiCell(($this->posxpuht - $this->posxwarehousedestination), 3, $wh_destination->ref.(!empty($wh_destination->lieu) ? ' - '.$wh_destination->lieu : ''), '', 'C');
if (!empty($conf->global->STOCKTRANSFER_PDF_DISPLAY_AMOUNT_HT)) if (!empty($conf->global->STOCKTRANSFER_PDF_DISPLAY_AMOUNT_HT)) {
{
$pdf->SetXY($this->posxpuht, $curY); $pdf->SetXY($this->posxpuht, $curY);
$pdf->MultiCell(($this->posxtotalht - $this->posxpuht - 1), 3, price($object->lines[$i]->subprice, 0, $outputlangs), '', 'R'); $pdf->MultiCell(($this->posxtotalht - $this->posxpuht - 1), 3, price($object->lines[$i]->subprice, 0, $outputlangs), '', 'R');
@ -598,8 +556,7 @@ class pdf_eagle extends ModelePdfStockTransfer
if ($weighttxt && $voltxt) $nexY += 2; if ($weighttxt && $voltxt) $nexY += 2;
// Add line // Add line
if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
{
$pdf->setPage($pageposafter); $pdf->setPage($pageposafter);
$pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80))); $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
//$pdf->SetDrawColor(190,190,200); //$pdf->SetDrawColor(190,190,200);
@ -608,15 +565,11 @@ class pdf_eagle extends ModelePdfStockTransfer
} }
// Detect if some page were added automatically and output _tableau for past pages // Detect if some page were added automatically and output _tableau for past pages
while ($pagenb < $pageposafter) while ($pagenb < $pageposafter) {
{
$pdf->setPage($pagenb); $pdf->setPage($pagenb);
if ($pagenb == 1) if ($pagenb == 1) {
{
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
} } else {
else
{
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
} }
$this->_pagefoot($pdf, $object, $outputlangs, 1); $this->_pagefoot($pdf, $object, $outputlangs, 1);
@ -625,14 +578,10 @@ class pdf_eagle extends ModelePdfStockTransfer
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
} }
if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
{ if ($pagenb == 1) {
if ($pagenb == 1)
{
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
} } else {
else
{
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
} }
$this->_pagefoot($pdf, $object, $outputlangs, 1); $this->_pagefoot($pdf, $object, $outputlangs, 1);
@ -645,13 +594,10 @@ class pdf_eagle extends ModelePdfStockTransfer
} }
// Show square // Show square
if ($pagenb == 1) if ($pagenb == 1) {
{
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
} } else {
else
{
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
} }
@ -672,8 +618,7 @@ class pdf_eagle extends ModelePdfStockTransfer
$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs); $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
global $action; global $action;
$reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) if ($reshook < 0) {
{
$this->error = $hookmanager->error; $this->error = $hookmanager->error;
$this->errors = $hookmanager->errors; $this->errors = $hookmanager->errors;
} }
@ -684,15 +629,11 @@ class pdf_eagle extends ModelePdfStockTransfer
$this->result = array('fullpath'=>$file); $this->result = array('fullpath'=>$file);
return 1; // No error return 1; // No error
} } else {
else
{
$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
return 0; return 0;
} }
} } else {
else
{
$this->error = $langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR"); $this->error = $langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
return 0; return 0;
} }
@ -745,8 +686,7 @@ class pdf_eagle extends ModelePdfStockTransfer
$totalOrdered = $tmparray['ordered']; $totalOrdered = $tmparray['ordered'];
$totalToShip = $tmparray['toship']; $totalToShip = $tmparray['toship'];
// Set trueVolume and volume_units not currently stored into database // Set trueVolume and volume_units not currently stored into database
if ($object->trueWidth && $object->trueHeight && $object->trueDepth) if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
{
$object->trueVolume = price(($object->trueWidth * $object->trueHeight * $object->trueDepth), 0, $outputlangs, 0, 0); $object->trueVolume = price(($object->trueWidth * $object->trueHeight * $object->trueDepth), 0, $outputlangs, 0, 0);
$object->volume_units = $object->size_units * 3; $object->volume_units = $object->size_units * 3;
} }
@ -760,20 +700,17 @@ class pdf_eagle extends ModelePdfStockTransfer
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1); $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1);
if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_ORDERED)) if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_ORDERED)) {
{
$pdf->SetXY($this->posxwarehousesource, $tab2_top + $tab2_hl * $index); $pdf->SetXY($this->posxwarehousesource, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($this->posxwarehousedestination - $this->posxwarehousesource, $tab2_hl, $totalOrdered, 0, 'C', 1); $pdf->MultiCell($this->posxwarehousedestination - $this->posxwarehousesource, $tab2_hl, $totalOrdered, 0, 'C', 1);
} }
if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_QTYTOSHIP)) if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_QTYTOSHIP)) {
{
$pdf->SetXY($this->posxwarehousedestination, $tab2_top + $tab2_hl * $index); $pdf->SetXY($this->posxwarehousedestination, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($this->posxpuht - $this->posxwarehousedestination, $tab2_hl, $totalToShip, 0, 'C', 1); $pdf->MultiCell($this->posxpuht - $this->posxwarehousedestination, $tab2_hl, $totalToShip, 0, 'C', 1);
} }
if (!empty($conf->global->STOCKTRANSFER_PDF_DISPLAY_AMOUNT_HT)) if (!empty($conf->global->STOCKTRANSFER_PDF_DISPLAY_AMOUNT_HT)) {
{
$pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index); $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1); $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1);
@ -781,18 +718,15 @@ class pdf_eagle extends ModelePdfStockTransfer
$pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1); $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1);
} }
if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_WEIGHT_AND_VOLUME)) if (empty($conf->global->STOCKTRANSFER_PDF_HIDE_WEIGHT_AND_VOLUME)) {
{
// Total Weight // Total Weight
if ($totalWeighttoshow) if ($totalWeighttoshow) {
{
$pdf->SetXY($this->posxqty, $tab2_top + $tab2_hl * $index); $pdf->SetXY($this->posxqty, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell(($this->posxwarehousesource - $this->posxqty), $tab2_hl, $totalWeighttoshow, 0, 'C', 1); $pdf->MultiCell(($this->posxwarehousesource - $this->posxqty), $tab2_hl, $totalWeighttoshow, 0, 'C', 1);
$index++; $index++;
} }
if ($totalVolumetoshow) if ($totalVolumetoshow) {
{
$pdf->SetXY($this->posxqty, $tab2_top + $tab2_hl * $index); $pdf->SetXY($this->posxqty, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell(($this->posxwarehousesource - $this->posxqty), $tab2_hl, $totalVolumetoshow, 0, 'C', 1); $pdf->MultiCell(($this->posxwarehousesource - $this->posxqty), $tab2_hl, $totalVolumetoshow, 0, 'C', 1);
@ -839,15 +773,14 @@ class pdf_eagle extends ModelePdfStockTransfer
$pdf->SetDrawColor(128, 128, 128); $pdf->SetDrawColor(128, 128, 128);
$pdf->SetFont('', '', $default_font_size - 1); $pdf->SetFont('', '', $default_font_size - 1);
if (empty($hidetop)) if (empty($hidetop)) {
{
$pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5); $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
$pdf->SetXY($this->posxdesc - 1, $tab_top + 1); $pdf->SetXY($this->posxdesc - 1, $tab_top + 1);
$pdf->MultiCell($this->posxwarehousesource - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L'); $pdf->MultiCell($this->posxwarehousesource - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L');
} }
if(!empty($conf->productbatch->enabled) && $this->atLeastOneBatch) { if (!empty($conf->productbatch->enabled) && $this->atLeastOneBatch) {
$pdf->line($this->posxlot - 1, $tab_top, $this->posxlot - 1, $tab_top + $tab_height); $pdf->line($this->posxlot - 1, $tab_top, $this->posxlot - 1, $tab_top + $tab_height);
if (empty($hidetop)) { if (empty($hidetop)) {
$pdf->SetXY($this->posxlot - 8, $tab_top + 1); $pdf->SetXY($this->posxlot - 8, $tab_top + 1);
@ -856,23 +789,20 @@ class pdf_eagle extends ModelePdfStockTransfer
} }
$pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height); $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height);
if (empty($hidetop)) if (empty($hidetop)) {
{
$pdf->SetXY($this->posxqty - 1, $tab_top + 1); $pdf->SetXY($this->posxqty - 1, $tab_top + 1);
$pdf->MultiCell(($this->posxwarehousesource - $this->posxqty), 2, $outputlangs->transnoentities("Qty"), '', 'C'); $pdf->MultiCell(($this->posxwarehousesource - $this->posxqty), 2, $outputlangs->transnoentities("Qty"), '', 'C');
} }
$pdf->line($this->posxwarehousesource - 1, $tab_top, $this->posxwarehousesource - 1, $tab_top + $tab_height); $pdf->line($this->posxwarehousesource - 1, $tab_top, $this->posxwarehousesource - 1, $tab_top + $tab_height);
if (empty($hidetop)) if (empty($hidetop)) {
{
$pdf->SetXY($this->posxwarehousesource - 1, $tab_top + 1); $pdf->SetXY($this->posxwarehousesource - 1, $tab_top + 1);
$pdf->MultiCell(($this->posxwarehousedestination - $this->posxwarehousesource), 2, $outputlangs->transnoentities("WarehouseSource"), '', 'C'); $pdf->MultiCell(($this->posxwarehousedestination - $this->posxwarehousesource), 2, $outputlangs->transnoentities("WarehouseSource"), '', 'C');
} }
$pdf->line($this->posxwarehousedestination - 1, $tab_top, $this->posxwarehousedestination - 1, $tab_top + $tab_height); $pdf->line($this->posxwarehousedestination - 1, $tab_top, $this->posxwarehousedestination - 1, $tab_top + $tab_height);
if (empty($hidetop)) if (empty($hidetop)) {
{
$pdf->SetXY($this->posxwarehousedestination-2.5, $tab_top + 1); $pdf->SetXY($this->posxwarehousedestination-2.5, $tab_top + 1);
$pdf->MultiCell(($this->posxpuht - $this->posxwarehousedestination+4), 2, $outputlangs->transnoentities("WarehouseTarget"), '', 'C'); $pdf->MultiCell(($this->posxpuht - $this->posxwarehousedestination+4), 2, $outputlangs->transnoentities("WarehouseTarget"), '', 'C');
} }
@ -894,18 +824,18 @@ class pdf_eagle extends ModelePdfStockTransfer
}*/ }*/
} }
function atLeastOneBatch($object) { function atLeastOneBatch($object)
{
$atLeastOneBatch = false; $atLeastOneBatch = false;
foreach ($object->lines as $line) { foreach ($object->lines as $line) {
if(!empty($line->batch)) { if (!empty($line->batch)) {
return true; return true;
} }
} }
return false; return false;
} }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
@ -929,8 +859,7 @@ class pdf_eagle extends ModelePdfStockTransfer
pdf_pagehead($pdf, $outputlangs, $this->page_hauteur); pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
// Show Draft Watermark // Show Draft Watermark
if ($object->statut == 0 && (!empty($conf->global->SHIPPING_DRAFT_WATERMARK))) if ($object->statut == 0 && (!empty($conf->global->SHIPPING_DRAFT_WATERMARK))) {
{
pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->SHIPPING_DRAFT_WATERMARK); pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->SHIPPING_DRAFT_WATERMARK);
} }
@ -947,47 +876,36 @@ class pdf_eagle extends ModelePdfStockTransfer
// Logo // Logo
$logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo; $logo = $conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
if ($this->emetteur->logo) if ($this->emetteur->logo) {
{ if (is_readable($logo)) {
if (is_readable($logo))
{
$height = pdf_getHeightForLogo($logo); $height = pdf_getHeightForLogo($logo);
$pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
} } else {
else
{
$pdf->SetTextColor(200, 0, 0); $pdf->SetTextColor(200, 0, 0);
$pdf->SetFont('', 'B', $default_font_size - 2); $pdf->SetFont('', 'B', $default_font_size - 2);
$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L'); $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L'); $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
} }
} } else {
else
{
$text = $this->emetteur->name; $text = $this->emetteur->name;
$pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L'); $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
} }
// Show barcode // Show barcode
if (!empty($conf->barcode->enabled)) if (!empty($conf->barcode->enabled)) {
{
$posx = 105; $posx = 105;
} } else {
else
{
$posx = $this->marge_gauche + 3; $posx = $this->marge_gauche + 3;
} }
//$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30); //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
if (!empty($conf->barcode->enabled)) if (!empty($conf->barcode->enabled)) {
{
// TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
//$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3); //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
//$pdf->Image($logo,10, 5, 0, 24); //$pdf->Image($logo,10, 5, 0, 24);
} }
$pdf->SetDrawColor(128, 128, 128); $pdf->SetDrawColor(128, 128, 128);
if (!empty($conf->barcode->enabled)) if (!empty($conf->barcode->enabled)) {
{
// TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
//$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3); //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
//$pdf->Image($logo,10, 5, 0, 24); //$pdf->Image($logo,10, 5, 0, 24);
@ -1012,8 +930,7 @@ class pdf_eagle extends ModelePdfStockTransfer
$pdf->MultiCell($w, 4, $outputlangs->transnoentities("Ref")." : ".$object->ref, '', 'R'); $pdf->MultiCell($w, 4, $outputlangs->transnoentities("Ref")." : ".$object->ref, '', 'R');
// Date reelle depart // Date reelle depart
if (!empty($object->date_prevue_depart)) if (!empty($object->date_prevue_depart)) {
{
$posy += 4; $posy += 4;
$pdf->SetXY($posx, $posy); $pdf->SetXY($posx, $posy);
$pdf->SetTextColor(0, 0, 60); $pdf->SetTextColor(0, 0, 60);
@ -1021,8 +938,7 @@ class pdf_eagle extends ModelePdfStockTransfer
} }
// Date reelle arrivée // Date reelle arrivée
if (!empty($object->date_prevue_arrivee)) if (!empty($object->date_prevue_arrivee)) {
{
$posy += 4; $posy += 4;
$pdf->SetXY($posx, $posy); $pdf->SetXY($posx, $posy);
$pdf->SetTextColor(0, 0, 60); $pdf->SetTextColor(0, 0, 60);
@ -1030,8 +946,7 @@ class pdf_eagle extends ModelePdfStockTransfer
} }
// Date reelle depart // Date reelle depart
if (!empty($object->date_reelle_depart)) if (!empty($object->date_reelle_depart)) {
{
$posy += 4; $posy += 4;
$pdf->SetXY($posx, $posy); $pdf->SetXY($posx, $posy);
$pdf->SetTextColor(0, 0, 60); $pdf->SetTextColor(0, 0, 60);
@ -1039,16 +954,14 @@ class pdf_eagle extends ModelePdfStockTransfer
} }
// Date reelle arrivée // Date reelle arrivée
if (!empty($object->date_reelle_arrivee)) if (!empty($object->date_reelle_arrivee)) {
{
$posy += 4; $posy += 4;
$pdf->SetXY($posx, $posy); $pdf->SetXY($posx, $posy);
$pdf->SetTextColor(0, 0, 60); $pdf->SetTextColor(0, 0, 60);
$pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateReelleArrivee")." : ".dol_print_date($object->date_reelle_arrivee, "day", false, $outputlangs, true), '', 'R'); $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateReelleArrivee")." : ".dol_print_date($object->date_reelle_arrivee, "day", false, $outputlangs, true), '', 'R');
} }
if (!empty($object->thirdparty->code_client)) if (!empty($object->thirdparty->code_client)) {
{
$posy += 4; $posy += 4;
$pdf->SetXY($posx, $posy); $pdf->SetXY($posx, $posy);
$pdf->SetTextColor(0, 0, 60); $pdf->SetTextColor(0, 0, 60);
@ -1064,15 +977,13 @@ class pdf_eagle extends ModelePdfStockTransfer
$origin_id = $object->origin_id; $origin_id = $object->origin_id;
// TODO move to external function // TODO move to external function
if (!empty($conf->$origin->enabled)) // commonly $origin='commande' if (!empty($conf->$origin->enabled)) { // commonly $origin='commande'
{
$outputlangs->load('orders'); $outputlangs->load('orders');
$classname = ucfirst($origin); $classname = ucfirst($origin);
$linkedobject = new $classname($this->db); $linkedobject = new $classname($this->db);
$result = $linkedobject->fetch($origin_id); $result = $linkedobject->fetch($origin_id);
if ($result >= 0) if ($result >= 0) {
{
//$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects //$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
$pdf->SetFont('', '', $default_font_size - 2); $pdf->SetFont('', '', $default_font_size - 2);
@ -1087,8 +998,7 @@ class pdf_eagle extends ModelePdfStockTransfer
} }
} }
if ($showaddress) if ($showaddress) {
{
// Sender properties // Sender properties
$carac_emetteur = ''; $carac_emetteur = '';
// Add internal contact of origin element if defined // Add internal contact of origin element if defined
@ -1096,8 +1006,7 @@ class pdf_eagle extends ModelePdfStockTransfer
$arrayidcontact = $object->getIdContact('external', 'STFROM'); $arrayidcontact = $object->getIdContact('external', 'STFROM');
$usecontact = false; $usecontact = false;
if (count($arrayidcontact) > 0) if (count($arrayidcontact) > 0) {
{
/*$object->fetch_user(reset($arrayidcontact)); /*$object->fetch_user(reset($arrayidcontact));
$carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";*/ $carac_emetteur .= ($carac_emetteur ? "\n" : '').$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";*/
$usecontact = true; $usecontact = true;
@ -1107,9 +1016,9 @@ class pdf_eagle extends ModelePdfStockTransfer
if ($usecontact) $thirdparty = $object->contact; if ($usecontact) $thirdparty = $object->contact;
else $thirdparty = $this->emetteur; else $thirdparty = $this->emetteur;
if(!empty($thirdparty)) $carac_emetteur_name = pdfBuildThirdpartyName($thirdparty, $outputlangs); if (!empty($thirdparty)) $carac_emetteur_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
if($usecontact) $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, $object->contact, 1, 'targetwithdetails', $object); if ($usecontact) $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, $object->contact, 1, 'targetwithdetails', $object);
else $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object); else $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
// Show sender // Show sender
@ -1146,8 +1055,7 @@ class pdf_eagle extends ModelePdfStockTransfer
// If SHIPPING contact defined, we use it // If SHIPPING contact defined, we use it
$usecontact = false; $usecontact = false;
$arrayidcontact = $object->getIdContact('external', 'STDEST'); $arrayidcontact = $object->getIdContact('external', 'STDEST');
if (count($arrayidcontact) > 0) if (count($arrayidcontact) > 0) {
{
$usecontact = true; $usecontact = true;
$result = $object->fetch_contact($arrayidcontact[0]); $result = $object->fetch_contact($arrayidcontact[0]);
} }
@ -1160,7 +1068,7 @@ class pdf_eagle extends ModelePdfStockTransfer
$thirdparty = $object->thirdparty; $thirdparty = $object->thirdparty;
} }
if(!empty($thirdparty)) $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs); if (!empty($thirdparty)) $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
$carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact) ? $object->contact : null), $usecontact, 'targetwithdetails', $object); $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (!empty($object->contact) ? $object->contact : null), $usecontact, 'targetwithdetails', $object);

View File

@ -114,8 +114,7 @@ class mod_stocktransfer_advanced extends ModeleNumRefStockTransfer
/*$mysoc->code_client = $old_code_client; /*$mysoc->code_client = $old_code_client;
$mysoc->typent_code = $old_code_type;*/ $mysoc->typent_code = $old_code_type;*/
if (!$numExample) if (!$numExample) {
{
$numExample = $langs->trans('NotConfigured'); $numExample = $langs->trans('NotConfigured');
} }
return $numExample; return $numExample;
@ -136,8 +135,7 @@ class mod_stocktransfer_advanced extends ModeleNumRefStockTransfer
// We get cursor rule // We get cursor rule
$mask = $conf->global->STOCKTRANSFER_STOCKTRANSFER_ADVANCED_MASK; $mask = $conf->global->STOCKTRANSFER_STOCKTRANSFER_ADVANCED_MASK;
if (!$mask) if (!$mask) {
{
$this->error = 'NotConfigured'; $this->error = 'NotConfigured';
return 0; return 0;
} }

View File

@ -92,19 +92,16 @@ class mod_stocktransfer_standard extends ModeleNumRefStockTransfer
$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
if ($object->ismultientitymanaged == 1) { if ($object->ismultientitymanaged == 1) {
$sql .= " AND entity = ".$conf->entity; $sql .= " AND entity = ".$conf->entity;
} } elseif ($object->ismultientitymanaged == 2) {
elseif ($object->ismultientitymanaged == 2) {
// TODO // TODO
} }
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$row = $db->fetch_row($resql); $row = $db->fetch_row($resql);
if ($row) { $coyymm = substr($row[0], 0, 6); $max = $row[0]; } if ($row) { $coyymm = substr($row[0], 0, 6); $max = $row[0]; }
} }
if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
{
$langs->load("errors"); $langs->load("errors");
$this->error = $langs->trans('ErrorNumRefModel', $max); $this->error = $langs->trans('ErrorNumRefModel', $max);
return false; return false;
@ -130,20 +127,16 @@ class mod_stocktransfer_standard extends ModeleNumRefStockTransfer
$sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
if ($object->ismultientitymanaged == 1) { if ($object->ismultientitymanaged == 1) {
$sql .= " AND entity = ".$conf->entity; $sql .= " AND entity = ".$conf->entity;
} } elseif ($object->ismultientitymanaged == 2) {
elseif ($object->ismultientitymanaged == 2) {
// TODO // TODO
} }
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if ($obj) $max = intval($obj->max); if ($obj) $max = intval($obj->max);
else $max = 0; else $max = 0;
} } else {
else
{
dol_syslog("mod_stocktransfer_standard::getNextValue", LOG_DEBUG); dol_syslog("mod_stocktransfer_standard::getNextValue", LOG_DEBUG);
return -1; return -1;
} }

View File

@ -196,23 +196,17 @@ class StockTransfer extends CommonObject
}*/ }*/
// Unset fields that are disabled // Unset fields that are disabled
foreach ($this->fields as $key => $val) foreach ($this->fields as $key => $val) {
{ if (isset($val['enabled']) && empty($val['enabled'])) {
if (isset($val['enabled']) && empty($val['enabled']))
{
unset($this->fields[$key]); unset($this->fields[$key]);
} }
} }
// Translate some data of arrayofkeyval // Translate some data of arrayofkeyval
if (is_object($langs)) if (is_object($langs)) {
{ foreach ($this->fields as $key => $val) {
foreach ($this->fields as $key => $val) if (is_array($val['arrayofkeyval'])) {
{ foreach ($val['arrayofkeyval'] as $key2 => $val2) {
if (is_array($val['arrayofkeyval']))
{
foreach ($val['arrayofkeyval'] as $key2 => $val2)
{
$this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2); $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
} }
} }
@ -229,9 +223,9 @@ class StockTransfer extends CommonObject
*/ */
public function create(User $user, $notrigger = false) public function create(User $user, $notrigger = false)
{ {
$this->status = (int)$this->status; $this->status = (int) $this->status;
if($this->fk_warehouse_source <= 0) $this->fk_warehouse_source = 0; if ($this->fk_warehouse_source <= 0) $this->fk_warehouse_source = 0;
if($this->fk_warehouse_destination <= 0) $this->fk_warehouse_destination = 0; if ($this->fk_warehouse_destination <= 0) $this->fk_warehouse_destination = 0;
return $this->createCommon($user, $notrigger); return $this->createCommon($user, $notrigger);
} }
@ -277,14 +271,11 @@ class StockTransfer extends CommonObject
$object->status = self::STATUS_DRAFT; $object->status = self::STATUS_DRAFT;
// ... // ...
// Clear extrafields that are unique // Clear extrafields that are unique
if (is_array($object->array_options) && count($object->array_options) > 0) if (is_array($object->array_options) && count($object->array_options) > 0) {
{
$extrafields->fetch_name_optionals_label($this->table_element); $extrafields->fetch_name_optionals_label($this->table_element);
foreach ($object->array_options as $key => $option) foreach ($object->array_options as $key => $option) {
{
$shortkey = preg_replace('/options_/', '', $key); $shortkey = preg_replace('/options_/', '', $key);
if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
{
//var_dump($key); var_dump($clonedObj->array_options[$key]); exit; //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
unset($object->array_options[$key]); unset($object->array_options[$key]);
} }
@ -300,20 +291,16 @@ class StockTransfer extends CommonObject
$this->errors = $object->errors; $this->errors = $object->errors;
} }
if (!$error) if (!$error) {
{
// copy internal contacts // copy internal contacts
if ($this->copy_linked_contact($object, 'internal') < 0) if ($this->copy_linked_contact($object, 'internal') < 0) {
{
$error++; $error++;
} }
} }
if (!$error) if (!$error) {
{
// copy external contacts if same company // copy external contacts if same company
if (property_exists($this, 'socid') && $this->socid == $object->socid) if (property_exists($this, 'socid') && $this->socid == $object->socid) {
{
if ($this->copy_linked_contact($object, 'external') < 0) if ($this->copy_linked_contact($object, 'external') < 0)
$error++; $error++;
} }
@ -368,17 +355,17 @@ class StockTransfer extends CommonObject
return ($a->rang < $b->rang) ? -1 : 1; return ($a->rang < $b->rang) ? -1 : 1;
} }
function getValorisationTotale() { function getValorisationTotale()
{
$total_pmp = 0; $total_pmp = 0;
if(empty($this->lines)) $this->fetchLines(); if (empty($this->lines)) $this->fetchLines();
if(!empty($this->lines)) { if (!empty($this->lines)) {
foreach ($this->lines as $l) $total_pmp+= ($l->pmp * $l->qty); foreach ($this->lines as $l) $total_pmp+= ($l->pmp * $l->qty);
} }
return $total_pmp; return $total_pmp;
} }
/** /**
@ -411,14 +398,11 @@ class StockTransfer extends CommonObject
foreach ($filter as $key => $value) { foreach ($filter as $key => $value) {
if ($key == 't.rowid') { if ($key == 't.rowid') {
$sqlwhere[] = $key.'='.$value; $sqlwhere[] = $key.'='.$value;
} } elseif (strpos($key, 'date') !== false) {
elseif (strpos($key, 'date') !== false) {
$sqlwhere[] = $key.' = \''.$this->db->idate($value).'\''; $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
} } elseif ($key == 'customsql') {
elseif ($key == 'customsql') {
$sqlwhere[] = $value; $sqlwhere[] = $value;
} } else {
else {
$sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
} }
} }
@ -438,8 +422,7 @@ class StockTransfer extends CommonObject
if ($resql) { if ($resql) {
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
$i = 0; $i = 0;
while ($i < ($limit ? min($limit, $num) : $num)) while ($i < ($limit ? min($limit, $num) : $num)) {
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$record = new self($this->db); $record = new self($this->db);
@ -481,8 +464,8 @@ class StockTransfer extends CommonObject
*/ */
public function delete(User $user, $notrigger = false) public function delete(User $user, $notrigger = false)
{ {
if(empty($this->lines)) $this->fetchLines(); if (empty($this->lines)) $this->fetchLines();
if(!empty($this->lines)) { if (!empty($this->lines)) {
foreach ($this->lines as $l) $res = $this->deleteLine($user, $l->id); foreach ($this->lines as $l) $res = $this->deleteLine($user, $l->id);
} }
return $this->deleteCommon($user, $notrigger); return $this->deleteCommon($user, $notrigger);
@ -500,8 +483,7 @@ class StockTransfer extends CommonObject
public function deleteLine(User $user, $idline, $notrigger = false) public function deleteLine(User $user, $idline, $notrigger = false)
{ {
global $db; global $db;
if ($this->status < 0) if ($this->status < 0) {
{
$this->error = 'ErrorDeleteLineNotAllowedByObjectStatus'; $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
return -2; return -2;
} }
@ -528,8 +510,7 @@ class StockTransfer extends CommonObject
$error = 0; $error = 0;
// Protection // Protection
if ($this->status == self::STATUS_VALIDATED) if ($this->status == self::STATUS_VALIDATED) {
{
dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING); dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
return 0; return 0;
} }
@ -547,12 +528,9 @@ class StockTransfer extends CommonObject
$this->db->begin(); $this->db->begin();
// Define new ref // Define new ref
if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
{
$num = $this->getNextNumRef(); $num = $this->getNextNumRef();
} } else {
else
{
$num = $this->ref; $num = $this->ref;
} }
$this->newref = $num; $this->newref = $num;
@ -568,15 +546,13 @@ class StockTransfer extends CommonObject
dol_syslog(get_class($this)."::validate()", LOG_DEBUG); dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) if (!$resql) {
{
dol_print_error($this->db); dol_print_error($this->db);
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
$error++; $error++;
} }
if (!$error && !$notrigger) if (!$error && !$notrigger) {
{
// Call trigger // Call trigger
$result = $this->call_trigger('STOCKTRANSFER_VALIDATE', $user); $result = $this->call_trigger('STOCKTRANSFER_VALIDATE', $user);
if ($result < 0) $error++; if ($result < 0) $error++;
@ -584,13 +560,11 @@ class StockTransfer extends CommonObject
} }
} }
if (!$error) if (!$error) {
{
$this->oldref = $this->ref; $this->oldref = $this->ref;
// Rename directory if dir was a temporary ref // Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref)) if (preg_match('/^[\(]?PROV/i', $this->ref)) {
{
// Now we rename also files into index // Now we rename also files into index
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'stocktransfer/".$this->db->escape($this->newref)."'"; $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'stocktransfer/".$this->db->escape($this->newref)."'";
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransfer/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransfer/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
@ -602,17 +576,14 @@ class StockTransfer extends CommonObject
$newref = dol_sanitizeFileName($num); $newref = dol_sanitizeFileName($num);
$dirsource = $conf->stocktransfer->dir_output.'/stocktransfer/'.$oldref; $dirsource = $conf->stocktransfer->dir_output.'/stocktransfer/'.$oldref;
$dirdest = $conf->stocktransfer->dir_output.'/stocktransfer/'.$newref; $dirdest = $conf->stocktransfer->dir_output.'/stocktransfer/'.$newref;
if (!$error && file_exists($dirsource)) if (!$error && file_exists($dirsource)) {
{
dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest); dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest)) {
{
dol_syslog("Rename ok"); dol_syslog("Rename ok");
// Rename docs starting with $oldref with $newref // Rename docs starting with $oldref with $newref
$listoffiles = dol_dir_list($conf->stocktransfer->dir_output.'/stocktransfer/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); $listoffiles = dol_dir_list($conf->stocktransfer->dir_output.'/stocktransfer/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
foreach ($listoffiles as $fileentry) foreach ($listoffiles as $fileentry) {
{
$dirsource = $fileentry['name']; $dirsource = $fileentry['name'];
$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
$dirsource = $fileentry['path'].'/'.$dirsource; $dirsource = $fileentry['path'].'/'.$dirsource;
@ -625,19 +596,15 @@ class StockTransfer extends CommonObject
} }
// Set new ref and current status // Set new ref and current status
if (!$error) if (!$error) {
{
$this->ref = $num; $this->ref = $num;
$this->status = self::STATUS_VALIDATED; $this->status = self::STATUS_VALIDATED;
} }
if (!$error) if (!$error) {
{
$this->db->commit(); $this->db->commit();
return 1; return 1;
} } else {
else
{
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
@ -654,8 +621,7 @@ class StockTransfer extends CommonObject
public function setDraft($user, $notrigger = 0) public function setDraft($user, $notrigger = 0)
{ {
// Protection // Protection
if ($this->status <= self::STATUS_DRAFT) if ($this->status <= self::STATUS_DRAFT) {
{
return 0; return 0;
} }
@ -679,8 +645,7 @@ class StockTransfer extends CommonObject
public function cancel($user, $notrigger = 0) public function cancel($user, $notrigger = 0)
{ {
// Protection // Protection
if ($this->status != self::STATUS_VALIDATED) if ($this->status != self::STATUS_VALIDATED) {
{
return 0; return 0;
} }
@ -704,8 +669,7 @@ class StockTransfer extends CommonObject
public function reopen($user, $notrigger = 0) public function reopen($user, $notrigger = 0)
{ {
// Protection // Protection
if ($this->status != self::STATUS_CLOSED) if ($this->status != self::STATUS_CLOSED) {
{
return 0; return 0;
} }
@ -746,8 +710,7 @@ class StockTransfer extends CommonObject
$url = dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?id='.$this->id; $url = dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?id='.$this->id;
if ($option != 'nolink') if ($option != 'nolink') {
{
// Add param to save lastsearch_values or not // Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
@ -755,17 +718,14 @@ class StockTransfer extends CommonObject
} }
$linkclose = ''; $linkclose = '';
if (empty($notooltip)) if (empty($notooltip)) {
{ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{
$label = $langs->trans("ShowStockTransfer"); $label = $langs->trans("ShowStockTransfer");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
} }
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
} } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
$linkstart = '<a href="'.$url.'"'; $linkstart = '<a href="'.$url.'"';
$linkstart .= $linkclose.'>'; $linkstart .= $linkclose.'>';
@ -789,14 +749,12 @@ class StockTransfer extends CommonObject
$pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint); $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) { if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
$result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>'; $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>';
} } else {
else {
$result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>'; $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>';
} }
$result .= '</div>'; $result .= '</div>';
} } else {
else {
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
} }
} }
@ -839,8 +797,7 @@ class StockTransfer extends CommonObject
public function LibStatut($status, $mode = 0) public function LibStatut($status, $mode = 0)
{ {
// phpcs:enable // phpcs:enable
if (empty($this->labelStatus) || empty($this->labelStatusShort)) if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
{
global $langs; global $langs;
//$langs->load("stocktransfer@stocktransfer"); //$langs->load("stocktransfer@stocktransfer");
$this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft'); $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
@ -873,28 +830,23 @@ class StockTransfer extends CommonObject
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
$sql .= ' WHERE t.rowid = '.$id; $sql .= ' WHERE t.rowid = '.$id;
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{ if ($this->db->num_rows($result)) {
if ($this->db->num_rows($result))
{
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$this->id = $obj->rowid; $this->id = $obj->rowid;
if ($obj->fk_user_author) if ($obj->fk_user_author) {
{
$cuser = new User($this->db); $cuser = new User($this->db);
$cuser->fetch($obj->fk_user_author); $cuser->fetch($obj->fk_user_author);
$this->user_creation = $cuser; $this->user_creation = $cuser;
} }
if ($obj->fk_user_valid) if ($obj->fk_user_valid) {
{
$vuser = new User($this->db); $vuser = new User($this->db);
$vuser->fetch($obj->fk_user_valid); $vuser->fetch($obj->fk_user_valid);
$this->user_validation = $vuser; $this->user_validation = $vuser;
} }
if ($obj->fk_user_cloture) if ($obj->fk_user_cloture) {
{
$cluser = new User($this->db); $cluser = new User($this->db);
$cluser->fetch($obj->fk_user_cloture); $cluser->fetch($obj->fk_user_cloture);
$this->user_cloture = $cluser; $this->user_cloture = $cluser;
@ -906,9 +858,7 @@ class StockTransfer extends CommonObject
} }
$this->db->free($result); $this->db->free($result);
} } else {
else
{
dol_print_error($this->db); dol_print_error($this->db);
} }
} }
@ -936,14 +886,11 @@ class StockTransfer extends CommonObject
$objectline = new StockTransferLine($this->db); $objectline = new StockTransferLine($this->db);
$result = $objectline->fetchAll('ASC', 'rang', 0, 0, array('customsql'=>'fk_stocktransfer = '.$this->id)); $result = $objectline->fetchAll('ASC', 'rang', 0, 0, array('customsql'=>'fk_stocktransfer = '.$this->id));
if (is_numeric($result)) if (is_numeric($result)) {
{
$this->error = $this->error; $this->error = $this->error;
$this->errors = $this->errors; $this->errors = $this->errors;
return $result; return $result;
} } else {
else
{
$this->lines = $result; $this->lines = $result;
return $this->lines; return $this->lines;
} }
@ -963,8 +910,7 @@ class StockTransfer extends CommonObject
$conf->global->STOCKTRANSFER_STOCKTRANSFER_ADDON = 'mod_stocktransfer_standard'; $conf->global->STOCKTRANSFER_STOCKTRANSFER_ADDON = 'mod_stocktransfer_standard';
} }
if (!empty($conf->global->STOCKTRANSFER_STOCKTRANSFER_ADDON)) if (!empty($conf->global->STOCKTRANSFER_STOCKTRANSFER_ADDON)) {
{
$mybool = false; $mybool = false;
$file = $conf->global->STOCKTRANSFER_STOCKTRANSFER_ADDON.".php"; $file = $conf->global->STOCKTRANSFER_STOCKTRANSFER_ADDON.".php";
@ -972,16 +918,14 @@ class StockTransfer extends CommonObject
// Include file with class // Include file with class
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
foreach ($dirmodels as $reldir) foreach ($dirmodels as $reldir) {
{
$dir = dol_buildpath($reldir."core/modules/stocktransfer/"); $dir = dol_buildpath($reldir."core/modules/stocktransfer/");
// Load file with numbering class (if found) // Load file with numbering class (if found)
$mybool |= @include_once $dir.$file; $mybool |= @include_once $dir.$file;
} }
if ($mybool === false) if ($mybool === false) {
{
dol_print_error('', "Failed to include file ".$file); dol_print_error('', "Failed to include file ".$file);
return ''; return '';
} }
@ -990,12 +934,9 @@ class StockTransfer extends CommonObject
$obj = new $classname(); $obj = new $classname();
$numref = $obj->getNextValue($this); $numref = $obj->getNextValue($this);
if ($numref != '' && $numref != '-1') if ($numref != '' && $numref != '-1') {
{
return $numref; return $numref;
} } else {
else
{
$this->error = $obj->error; $this->error = $obj->error;
//dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error); //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
return ""; return "";
@ -1004,9 +945,7 @@ class StockTransfer extends CommonObject
print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname; print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
return ""; return "";
} }
} } else {
else
{
print $langs->trans("ErrorNumberingModuleNotSetup", $this->element); print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
return ""; return "";
} }

View File

@ -174,23 +174,17 @@ class StockTransferLine extends CommonObject
}*/ }*/
// Unset fields that are disabled // Unset fields that are disabled
foreach ($this->fields as $key => $val) foreach ($this->fields as $key => $val) {
{ if (isset($val['enabled']) && empty($val['enabled'])) {
if (isset($val['enabled']) && empty($val['enabled']))
{
unset($this->fields[$key]); unset($this->fields[$key]);
} }
} }
// Translate some data of arrayofkeyval // Translate some data of arrayofkeyval
if (is_object($langs)) if (is_object($langs)) {
{ foreach ($this->fields as $key => $val) {
foreach ($this->fields as $key => $val) if (is_array($val['arrayofkeyval'])) {
{ foreach ($val['arrayofkeyval'] as $key2 => $val2) {
if (is_array($val['arrayofkeyval']))
{
foreach ($val['arrayofkeyval'] as $key2 => $val2)
{
$this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2); $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
} }
} }
@ -248,14 +242,11 @@ class StockTransferLine extends CommonObject
$object->status = self::STATUS_DRAFT; $object->status = self::STATUS_DRAFT;
// ... // ...
// Clear extrafields that are unique // Clear extrafields that are unique
if (is_array($object->array_options) && count($object->array_options) > 0) if (is_array($object->array_options) && count($object->array_options) > 0) {
{
$extrafields->fetch_name_optionals_label($this->table_element); $extrafields->fetch_name_optionals_label($this->table_element);
foreach ($object->array_options as $key => $option) foreach ($object->array_options as $key => $option) {
{
$shortkey = preg_replace('/options_/', '', $key); $shortkey = preg_replace('/options_/', '', $key);
if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
{
//var_dump($key); var_dump($clonedObj->array_options[$key]); exit; //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
unset($object->array_options[$key]); unset($object->array_options[$key]);
} }
@ -271,20 +262,16 @@ class StockTransferLine extends CommonObject
$this->errors = $object->errors; $this->errors = $object->errors;
} }
if (!$error) if (!$error) {
{
// copy internal contacts // copy internal contacts
if ($this->copy_linked_contact($object, 'internal') < 0) if ($this->copy_linked_contact($object, 'internal') < 0) {
{
$error++; $error++;
} }
} }
if (!$error) if (!$error) {
{
// copy external contacts if same company // copy external contacts if same company
if (property_exists($this, 'socid') && $this->socid == $object->socid) if (property_exists($this, 'socid') && $this->socid == $object->socid) {
{
if ($this->copy_linked_contact($object, 'external') < 0) if ($this->copy_linked_contact($object, 'external') < 0)
$error++; $error++;
} }
@ -360,14 +347,11 @@ class StockTransferLine extends CommonObject
foreach ($filter as $key => $value) { foreach ($filter as $key => $value) {
if ($key == 't.rowid') { if ($key == 't.rowid') {
$sqlwhere[] = $key.'='.$value; $sqlwhere[] = $key.'='.$value;
} } elseif (strpos($key, 'date') !== false) {
elseif (strpos($key, 'date') !== false) {
$sqlwhere[] = $key.' = \''.$this->db->idate($value).'\''; $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
} } elseif ($key == 'customsql') {
elseif ($key == 'customsql') {
$sqlwhere[] = $value; $sqlwhere[] = $value;
} } else {
else {
$sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
} }
} }
@ -387,8 +371,7 @@ class StockTransferLine extends CommonObject
if ($resql) { if ($resql) {
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
$i = 0; $i = 0;
while ($i < ($limit ? min($limit, $num) : $num)) while ($i < ($limit ? min($limit, $num) : $num)) {
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$record = new self($this->db); $record = new self($this->db);
@ -444,8 +427,7 @@ class StockTransferLine extends CommonObject
*/ */
public function deleteLine(User $user, $idline, $notrigger = false) public function deleteLine(User $user, $idline, $notrigger = false)
{ {
if ($this->status < 0) if ($this->status < 0) {
{
$this->error = 'ErrorDeleteLineNotAllowedByObjectStatus'; $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
return -2; return -2;
} }
@ -453,7 +435,8 @@ class StockTransferLine extends CommonObject
return $this->deleteLineCommon($user, $idline, $notrigger); return $this->deleteLineCommon($user, $idline, $notrigger);
} }
function doStockMovement($label, $fk_entrepot, $direction=1) { function doStockMovement($label, $fk_entrepot, $direction = 1)
{
global $db, $conf, $user, $langs; global $db, $conf, $user, $langs;
@ -469,8 +452,7 @@ class StockTransferLine extends CommonObject
$movementstock->origin = new StockTransfer($db); $movementstock->origin = new StockTransfer($db);
$movementstock->origin->id = $this->fk_stocktransfer; $movementstock->origin->id = $this->fk_stocktransfer;
if (empty($this->batch)) // no batch for line if (empty($this->batch)) { // no batch for line
{
/*$result = $p->correct_stock( /*$result = $p->correct_stock(
$user, $user,
$fk_entrepot, $fk_entrepot,
@ -489,8 +471,7 @@ class StockTransferLine extends CommonObject
setEventMessages($p->errors, $p->errorss, 'errors'); setEventMessages($p->errors, $p->errorss, 'errors');
return 0; return 0;
} }
} } else {
else {
if ($p->hasbatch()) { if ($p->hasbatch()) {
$arraybatchinfo = $p->loadBatchInfo($this->batch); $arraybatchinfo = $p->loadBatchInfo($this->batch);
if (count($arraybatchinfo) > 0) { if (count($arraybatchinfo) > 0) {
@ -529,7 +510,6 @@ class StockTransferLine extends CommonObject
} }
return 1; return 1;
} }
/** /**
@ -548,8 +528,7 @@ class StockTransferLine extends CommonObject
$error = 0; $error = 0;
// Protection // Protection
if ($this->status == self::STATUS_VALIDATED) if ($this->status == self::STATUS_VALIDATED) {
{
dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING); dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
return 0; return 0;
} }
@ -567,12 +546,9 @@ class StockTransferLine extends CommonObject
$this->db->begin(); $this->db->begin();
// Define new ref // Define new ref
if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
{
$num = $this->getNextNumRef(); $num = $this->getNextNumRef();
} } else {
else
{
$num = $this->ref; $num = $this->ref;
} }
$this->newref = $num; $this->newref = $num;
@ -588,15 +564,13 @@ class StockTransferLine extends CommonObject
dol_syslog(get_class($this)."::validate()", LOG_DEBUG); dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) if (!$resql) {
{
dol_print_error($this->db); dol_print_error($this->db);
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
$error++; $error++;
} }
if (!$error && !$notrigger) if (!$error && !$notrigger) {
{
// Call trigger // Call trigger
$result = $this->call_trigger('STOCKTRANSFERLINE_VALIDATE', $user); $result = $this->call_trigger('STOCKTRANSFERLINE_VALIDATE', $user);
if ($result < 0) $error++; if ($result < 0) $error++;
@ -604,13 +578,11 @@ class StockTransferLine extends CommonObject
} }
} }
if (!$error) if (!$error) {
{
$this->oldref = $this->ref; $this->oldref = $this->ref;
// Rename directory if dir was a temporary ref // Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref)) if (preg_match('/^[\(]?PROV/i', $this->ref)) {
{
// Now we rename also files into index // Now we rename also files into index
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'stocktransferline/".$this->db->escape($this->newref)."'"; $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'stocktransferline/".$this->db->escape($this->newref)."'";
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransferline/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransferline/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
@ -622,17 +594,14 @@ class StockTransferLine extends CommonObject
$newref = dol_sanitizeFileName($num); $newref = dol_sanitizeFileName($num);
$dirsource = $conf->stocktransfer->dir_output.'/stocktransferline/'.$oldref; $dirsource = $conf->stocktransfer->dir_output.'/stocktransferline/'.$oldref;
$dirdest = $conf->stocktransfer->dir_output.'/stocktransferline/'.$newref; $dirdest = $conf->stocktransfer->dir_output.'/stocktransferline/'.$newref;
if (!$error && file_exists($dirsource)) if (!$error && file_exists($dirsource)) {
{
dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest); dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest)) {
{
dol_syslog("Rename ok"); dol_syslog("Rename ok");
// Rename docs starting with $oldref with $newref // Rename docs starting with $oldref with $newref
$listoffiles = dol_dir_list($conf->stocktransfer->dir_output.'/stocktransferline/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); $listoffiles = dol_dir_list($conf->stocktransfer->dir_output.'/stocktransferline/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
foreach ($listoffiles as $fileentry) foreach ($listoffiles as $fileentry) {
{
$dirsource = $fileentry['name']; $dirsource = $fileentry['name'];
$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
$dirsource = $fileentry['path'].'/'.$dirsource; $dirsource = $fileentry['path'].'/'.$dirsource;
@ -645,19 +614,15 @@ class StockTransferLine extends CommonObject
} }
// Set new ref and current status // Set new ref and current status
if (!$error) if (!$error) {
{
$this->ref = $num; $this->ref = $num;
$this->status = self::STATUS_VALIDATED; $this->status = self::STATUS_VALIDATED;
} }
if (!$error) if (!$error) {
{
$this->db->commit(); $this->db->commit();
return 1; return 1;
} } else {
else
{
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
@ -674,8 +639,7 @@ class StockTransferLine extends CommonObject
public function setDraft($user, $notrigger = 0) public function setDraft($user, $notrigger = 0)
{ {
// Protection // Protection
if ($this->status <= self::STATUS_DRAFT) if ($this->status <= self::STATUS_DRAFT) {
{
return 0; return 0;
} }
@ -699,8 +663,7 @@ class StockTransferLine extends CommonObject
public function cancel($user, $notrigger = 0) public function cancel($user, $notrigger = 0)
{ {
// Protection // Protection
if ($this->status != self::STATUS_VALIDATED) if ($this->status != self::STATUS_VALIDATED) {
{
return 0; return 0;
} }
@ -724,8 +687,7 @@ class StockTransferLine extends CommonObject
public function reopen($user, $notrigger = 0) public function reopen($user, $notrigger = 0)
{ {
// Protection // Protection
if ($this->status != self::STATUS_CANCELED) if ($this->status != self::STATUS_CANCELED) {
{
return 0; return 0;
} }
@ -766,8 +728,7 @@ class StockTransferLine extends CommonObject
$url = dol_buildpath('/stocktransfer/stocktransferline_card.php', 1).'?id='.$this->id; $url = dol_buildpath('/stocktransfer/stocktransferline_card.php', 1).'?id='.$this->id;
if ($option != 'nolink') if ($option != 'nolink') {
{
// Add param to save lastsearch_values or not // Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
@ -775,17 +736,14 @@ class StockTransferLine extends CommonObject
} }
$linkclose = ''; $linkclose = '';
if (empty($notooltip)) if (empty($notooltip)) {
{ if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{
$label = $langs->trans("ShowStockTransferLine"); $label = $langs->trans("ShowStockTransferLine");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
} }
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
} } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
$linkstart = '<a href="'.$url.'"'; $linkstart = '<a href="'.$url.'"';
$linkstart .= $linkclose.'>'; $linkstart .= $linkclose.'>';
@ -809,14 +767,12 @@ class StockTransferLine extends CommonObject
$pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint); $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) { if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
$result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>'; $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>';
} } else {
else {
$result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>'; $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>';
} }
$result .= '</div>'; $result .= '</div>';
} } else {
else {
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
} }
} }
@ -859,8 +815,7 @@ class StockTransferLine extends CommonObject
public function LibStatut($status, $mode = 0) public function LibStatut($status, $mode = 0)
{ {
// phpcs:enable // phpcs:enable
if (empty($this->labelStatus) || empty($this->labelStatusShort)) if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
{
global $langs; global $langs;
//$langs->load("stocktransfer@stocktransfer"); //$langs->load("stocktransfer@stocktransfer");
$this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft'); $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
@ -891,28 +846,23 @@ class StockTransferLine extends CommonObject
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
$sql .= ' WHERE t.rowid = '.$id; $sql .= ' WHERE t.rowid = '.$id;
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{ if ($this->db->num_rows($result)) {
if ($this->db->num_rows($result))
{
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$this->id = $obj->rowid; $this->id = $obj->rowid;
if ($obj->fk_user_author) if ($obj->fk_user_author) {
{
$cuser = new User($this->db); $cuser = new User($this->db);
$cuser->fetch($obj->fk_user_author); $cuser->fetch($obj->fk_user_author);
$this->user_creation = $cuser; $this->user_creation = $cuser;
} }
if ($obj->fk_user_valid) if ($obj->fk_user_valid) {
{
$vuser = new User($this->db); $vuser = new User($this->db);
$vuser->fetch($obj->fk_user_valid); $vuser->fetch($obj->fk_user_valid);
$this->user_validation = $vuser; $this->user_validation = $vuser;
} }
if ($obj->fk_user_cloture) if ($obj->fk_user_cloture) {
{
$cluser = new User($this->db); $cluser = new User($this->db);
$cluser->fetch($obj->fk_user_cloture); $cluser->fetch($obj->fk_user_cloture);
$this->user_cloture = $cluser; $this->user_cloture = $cluser;
@ -924,9 +874,7 @@ class StockTransferLine extends CommonObject
} }
$this->db->free($result); $this->db->free($result);
} } else {
else
{
dol_print_error($this->db); dol_print_error($this->db);
} }
} }
@ -954,14 +902,11 @@ class StockTransferLine extends CommonObject
$objectline = new StockTransferLineLine($this->db); $objectline = new StockTransferLineLine($this->db);
$result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_stocktransferline = '.$this->id)); $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_stocktransferline = '.$this->id));
if (is_numeric($result)) if (is_numeric($result)) {
{
$this->error = $this->error; $this->error = $this->error;
$this->errors = $this->errors; $this->errors = $this->errors;
return $result; return $result;
} } else {
else
{
$this->lines = $result; $this->lines = $result;
return $this->lines; return $this->lines;
} }
@ -981,8 +926,7 @@ class StockTransferLine extends CommonObject
$conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON = 'mod_stocktransferline_standard'; $conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON = 'mod_stocktransferline_standard';
} }
if (!empty($conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON)) if (!empty($conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON)) {
{
$mybool = false; $mybool = false;
$file = $conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON.".php"; $file = $conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON.".php";
@ -990,16 +934,14 @@ class StockTransferLine extends CommonObject
// Include file with class // Include file with class
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
foreach ($dirmodels as $reldir) foreach ($dirmodels as $reldir) {
{
$dir = dol_buildpath($reldir."core/modules/stocktransfer/"); $dir = dol_buildpath($reldir."core/modules/stocktransfer/");
// Load file with numbering class (if found) // Load file with numbering class (if found)
$mybool |= @include_once $dir.$file; $mybool |= @include_once $dir.$file;
} }
if ($mybool === false) if ($mybool === false) {
{
dol_print_error('', "Failed to include file ".$file); dol_print_error('', "Failed to include file ".$file);
return ''; return '';
} }
@ -1008,12 +950,9 @@ class StockTransferLine extends CommonObject
$obj = new $classname(); $obj = new $classname();
$numref = $obj->getNextValue($this); $numref = $obj->getNextValue($this);
if ($numref != '' && $numref != '-1') if ($numref != '' && $numref != '-1') {
{
return $numref; return $numref;
} } else {
else
{
$this->error = $obj->error; $this->error = $obj->error;
//dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error); //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
return ""; return "";
@ -1022,9 +961,7 @@ class StockTransferLine extends CommonObject
print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname; print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
return ""; return "";
} }
} } else {
else
{
print $langs->trans("ErrorNumberingModuleNotSetup", $this->element); print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
return ""; return "";
} }

View File

@ -42,8 +42,7 @@ function stocktransferPrepareHead($object)
$head[$h][2] = 'card'; $head[$h][2] = 'card';
$h++; $h++;
if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
{
$nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external')); $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
$head[$h][0] = dol_buildpath('/product/stock/stocktransfer/stocktransfer_contact.php', 1).'?id='.$object->id; $head[$h][0] = dol_buildpath('/product/stock/stocktransfer/stocktransfer_contact.php', 1).'?id='.$object->id;
$head[$h][1] = $langs->trans('ContactsAddresses'); $head[$h][1] = $langs->trans('ContactsAddresses');
@ -52,8 +51,7 @@ function stocktransferPrepareHead($object)
$h++; $h++;
} }
if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
{
$nbNote = 0; $nbNote = 0;
if (!empty($object->note_private)) $nbNote++; if (!empty($object->note_private)) $nbNote++;
if (!empty($object->note_public)) $nbNote++; if (!empty($object->note_public)) $nbNote++;

View File

@ -55,13 +55,10 @@ $action = GETPOST('action', 'alpha');
$cancel = GETPOST('cancel', 'aZ09'); $cancel = GETPOST('cancel', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha');
if (GETPOST('actioncode', 'array')) if (GETPOST('actioncode', 'array')) {
{
$actioncode = GETPOST('actioncode', 'array', 3); $actioncode = GETPOST('actioncode', 'array', 3);
if (!count($actioncode)) $actioncode = '0'; if (!count($actioncode)) $actioncode = '0';
} } else {
else
{
$actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT)); $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
} }
$search_agenda_label = GETPOST('search_agenda_label'); $search_agenda_label = GETPOST('search_agenda_label');
@ -105,18 +102,15 @@ $parameters = array('id'=>$id);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $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 ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) if (empty($reshook)) {
{
// Cancel // Cancel
if (GETPOST('cancel', 'alpha') && !empty($backtopage)) if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
{
header("Location: ".$backtopage); header("Location: ".$backtopage);
exit; exit;
} }
// Purge search criteria // Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
{
$actioncode = ''; $actioncode = '';
$search_agenda_label = ''; $search_agenda_label = '';
} }
@ -130,8 +124,7 @@ if (empty($reshook))
$form = new Form($db); $form = new Form($db);
if ($object->id > 0) if ($object->id > 0) {
{
$title = $langs->trans("Agenda"); $title = $langs->trans("Agenda");
//if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title; //if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
$help_url = ''; $help_url = '';
@ -209,8 +202,7 @@ if ($object->id > 0)
$out = '&origin='.$object->element.'&originid='.$object->id; $out = '&origin='.$object->element.'&originid='.$object->id;
$permok = $user->rights->agenda->myactions->create; $permok = $user->rights->agenda->myactions->create;
if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
{
//$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'; //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
if (get_class($objthirdparty) == 'Societe') $out .= '&amp;socid='.$objthirdparty->id; if (get_class($objthirdparty) == 'Societe') $out .= '&amp;socid='.$objthirdparty->id;
$out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;backtopage=1&amp;percentage=-1'; $out .= (!empty($objcon->id) ? '&amp;contactid='.$objcon->id : '').'&amp;backtopage=1&amp;percentage=-1';
@ -222,22 +214,17 @@ if ($object->id > 0)
print '<div class="tabsAction">'; print '<div class="tabsAction">';
if (!empty($conf->agenda->enabled)) if (!empty($conf->agenda->enabled)) {
{ if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create))
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'">'.$langs->trans("AddAction").'</a>'; print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'">'.$langs->trans("AddAction").'</a>';
} } else {
else
{
print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("AddAction").'</a>'; print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("AddAction").'</a>';
} }
} }
print '</div>'; print '</div>';
if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
{
$param = '&id='.$object->id.'&socid='.$socid; $param = '&id='.$object->id.'&socid='.$socid;
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);

View File

@ -101,8 +101,7 @@ $search_array_options = $extrafields->getOptionalsFromPost($object->table_elemen
// Initialize array of search criterias // Initialize array of search criterias
$search_all = trim(GETPOST("search_all", 'alpha')); $search_all = trim(GETPOST("search_all", 'alpha'));
$search = array(); $search = array();
foreach ($object->fields as $key => $val) foreach ($object->fields as $key => $val) {
{
if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha'); if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha');
} }
@ -140,8 +139,7 @@ $parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $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 ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) if (empty($reshook)) {
{
$error = 0; $error = 0;
$backurlforlist = dol_buildpath('/product/stock/stocktransfer/stocktransfer_list.php', 1); $backurlforlist = dol_buildpath('/product/stock/stocktransfer/stocktransfer_list.php', 1);
@ -169,30 +167,27 @@ if (empty($reshook))
// Action to build doc // Action to build doc
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
if ($action == 'set_thirdparty' && $permissiontoadd) if ($action == 'set_thirdparty' && $permissiontoadd) {
{
$object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, 'STOCKTRANSFER_MODIFY'); $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, 'STOCKTRANSFER_MODIFY');
} }
if ($action == 'classin' && $permissiontoadd) if ($action == 'classin' && $permissiontoadd) {
{
$object->setProject(GETPOST('projectid', 'int')); $object->setProject(GETPOST('projectid', 'int'));
} }
if($action == 'addline' && $permissiontoadd) { if ($action == 'addline' && $permissiontoadd) {
if ($qty <= 0) {
if($qty <= 0) {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors');
$action = 'view'; $action = 'view';
} }
if($fk_warehouse_source <= 0) { if ($fk_warehouse_source <= 0) {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors');
$action = 'view'; $action = 'view';
} }
if($fk_warehouse_destination <= 0) { if ($fk_warehouse_destination <= 0) {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors');
$action = 'view'; $action = 'view';
@ -200,25 +195,23 @@ if (empty($reshook))
$prod = new Product($db); $prod = new Product($db);
$prod->fetch($fk_product); $prod->fetch($fk_product);
if ($prod->hasbatch()) if ($prod->hasbatch()) {
{ if (empty($batch)) {
if (empty($batch))
{
$error++; $error++;
$langs->load("errors"); $langs->load("errors");
setEventMessages($langs->trans("ErrorTryToMakeMoveOnProductRequiringBatchData", $prod->ref), null, 'errors'); setEventMessages($langs->trans("ErrorTryToMakeMoveOnProductRequiringBatchData", $prod->ref), null, 'errors');
} }
} else { } else {
if(!empty($batch)) { if (!empty($batch)) {
$error++; $error++;
setEventMessages($langs->trans('StockTransferNoBatchForProduct', $prod->getNomUrl()), '', 'errors'); setEventMessages($langs->trans('StockTransferNoBatchForProduct', $prod->getNomUrl()), '', 'errors');
} }
} }
if(empty($error)) { if (empty($error)) {
$line = new StockTransferLine($db); $line = new StockTransferLine($db);
$records = $line->fetchAll('', '', 0, 0, array('customsql'=>' fk_stocktransfer = '.$id.' AND fk_product = '.$fk_product.' AND fk_warehouse_source = '.$fk_warehouse_source.' AND fk_warehouse_destination = '.$fk_warehouse_destination.' AND ('.(empty($batch) ? 'batch = "" or batch IS NULL' : 'batch = "'.$batch.'"' ).')')); $records = $line->fetchAll('', '', 0, 0, array('customsql'=>' fk_stocktransfer = '.$id.' AND fk_product = '.$fk_product.' AND fk_warehouse_source = '.$fk_warehouse_source.' AND fk_warehouse_destination = '.$fk_warehouse_destination.' AND ('.(empty($batch) ? 'batch = "" or batch IS NULL' : 'batch = "'.$batch.'"' ).')'));
if(!empty($records[key($records)])) $line = $records[key($records)]; if (!empty($records[key($records)])) $line = $records[key($records)];
$line->fk_stocktransfer = $id; $line->fk_stocktransfer = $id;
$line->qty += $qty; $line->qty += $qty;
$line->fk_warehouse_source = $fk_warehouse_source; $line->fk_warehouse_source = $fk_warehouse_source;
@ -227,28 +220,27 @@ if (empty($reshook))
$line->batch = $batch; $line->batch = $batch;
$line->pmp = $prod->pmp; $line->pmp = $prod->pmp;
if($line->id > 0) $line->update($user); if ($line->id > 0) $line->update($user);
else { else {
$line->rang = count($object->lines) + 1; $line->rang = count($object->lines) + 1;
$line->create($user); $line->create($user);
} }
$object->fetchLines(); $object->fetchLines();
} }
} elseif($action === 'updateline' && $permissiontoadd) { } elseif ($action === 'updateline' && $permissiontoadd) {
if ($qty <= 0) {
if($qty <= 0) {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors');
$action = 'editline'; $action = 'editline';
} }
if($fk_warehouse_source <= 0) { if ($fk_warehouse_source <= 0) {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors');
$action = 'editline'; $action = 'editline';
} }
if($fk_warehouse_destination <= 0) { if ($fk_warehouse_destination <= 0) {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors');
$action = 'editline'; $action = 'editline';
@ -256,24 +248,22 @@ if (empty($reshook))
$prod = new Product($db); $prod = new Product($db);
$prod->fetch($fk_product); $prod->fetch($fk_product);
if ($prod->hasbatch()) if ($prod->hasbatch()) {
{ if (empty($batch)) {
if (empty($batch))
{
$error++; $error++;
$langs->load("errors"); $langs->load("errors");
setEventMessages($langs->trans("ErrorTryToMakeMoveOnProductRequiringBatchData", $prod->ref), null, 'errors'); setEventMessages($langs->trans("ErrorTryToMakeMoveOnProductRequiringBatchData", $prod->ref), null, 'errors');
$action = 'editline'; $action = 'editline';
} }
} else { } else {
if(!empty($batch)) { if (!empty($batch)) {
$error++; $error++;
setEventMessages($langs->trans('StockTransferNoBatchForProduct', $prod->getNomUrl()), '', 'errors'); setEventMessages($langs->trans('StockTransferNoBatchForProduct', $prod->getNomUrl()), '', 'errors');
$action = 'editline'; $action = 'editline';
} }
} }
if(empty($error)) { if (empty($error)) {
$line = new StockTransferLine($db); $line = new StockTransferLine($db);
$line->fetch($lineid); $line->fetch($lineid);
$line->qty = $qty; $line->qty = $qty;
@ -287,18 +277,18 @@ if (empty($reshook))
} }
// Décrémentation // Décrémentation
if($action == 'confirm_destock' && $confirm == 'yes' && $object->status == $object::STATUS_VALIDATED) { if ($action == 'confirm_destock' && $confirm == 'yes' && $object->status == $object::STATUS_VALIDATED) {
$lines = $object->getLinesArray(); $lines = $object->getLinesArray();
if(!empty($lines)) { if (!empty($lines)) {
$db->begin(); $db->begin();
foreach ($lines as $line) { foreach ($lines as $line) {
$res = $line->doStockMovement($label, $line->fk_warehouse_source); $res = $line->doStockMovement($label, $line->fk_warehouse_source);
if($res <= 0) $error++; if ($res <= 0) $error++;
} }
if(empty($error)) $db->commit(); if (empty($error)) $db->commit();
else $db->rollback(); else $db->rollback();
} }
if(empty($error)) { if (empty($error)) {
$object->setStatut($object::STATUS_TRANSFERED, $id); $object->setStatut($object::STATUS_TRANSFERED, $id);
$object->status = $object::STATUS_TRANSFERED; $object->status = $object::STATUS_TRANSFERED;
$object->date_reelle_depart = date('Y-m-d'); $object->date_reelle_depart = date('Y-m-d');
@ -308,18 +298,18 @@ if (empty($reshook))
} }
// Annulation décrémentation // Annulation décrémentation
if($action == 'confirm_destockcancel' && $confirm == 'yes' && $object->status == $object::STATUS_TRANSFERED) { if ($action == 'confirm_destockcancel' && $confirm == 'yes' && $object->status == $object::STATUS_TRANSFERED) {
$lines = $object->getLinesArray(); $lines = $object->getLinesArray();
if(!empty($lines)) { if (!empty($lines)) {
$db->begin(); $db->begin();
foreach ($lines as $line) { foreach ($lines as $line) {
$res = $line->doStockMovement($label, $line->fk_warehouse_source, 0); $res = $line->doStockMovement($label, $line->fk_warehouse_source, 0);
if($res <= 0) $error++; if ($res <= 0) $error++;
} }
if(empty($error)) $db->commit(); if (empty($error)) $db->commit();
else $db->rollback(); else $db->rollback();
} }
if(empty($error)) { if (empty($error)) {
$object->setStatut($object::STATUS_VALIDATED, $id); $object->setStatut($object::STATUS_VALIDATED, $id);
$object->status = $object::STATUS_VALIDATED; $object->status = $object::STATUS_VALIDATED;
$object->date_reelle_depart = null; $object->date_reelle_depart = null;
@ -329,18 +319,18 @@ if (empty($reshook))
} }
// Incrémentation // Incrémentation
if($action == 'confirm_addstock' && $confirm == 'yes' && $object->status == $object::STATUS_TRANSFERED) { if ($action == 'confirm_addstock' && $confirm == 'yes' && $object->status == $object::STATUS_TRANSFERED) {
$lines = $object->getLinesArray(); $lines = $object->getLinesArray();
if(!empty($lines)) { if (!empty($lines)) {
$db->begin(); $db->begin();
foreach ($lines as $line) { foreach ($lines as $line) {
$res = $line->doStockMovement($label, $line->fk_warehouse_destination, 0); $res = $line->doStockMovement($label, $line->fk_warehouse_destination, 0);
if($res <= 0) $error++; if ($res <= 0) $error++;
} }
if(empty($error)) $db->commit(); if (empty($error)) $db->commit();
else $db->rollback(); else $db->rollback();
} }
if(empty($error)) { if (empty($error)) {
$object->setStatut($object::STATUS_CLOSED, $id); $object->setStatut($object::STATUS_CLOSED, $id);
$object->status = $object::STATUS_CLOSED; $object->status = $object::STATUS_CLOSED;
$object->date_reelle_arrivee = date('Y-m-d'); $object->date_reelle_arrivee = date('Y-m-d');
@ -350,18 +340,18 @@ if (empty($reshook))
} }
// Annulation incrémentation // Annulation incrémentation
if($action == 'confirm_addstockcancel' && $confirm == 'yes' && $object->status == $object::STATUS_CLOSED) { if ($action == 'confirm_addstockcancel' && $confirm == 'yes' && $object->status == $object::STATUS_CLOSED) {
$lines = $object->getLinesArray(); $lines = $object->getLinesArray();
if(!empty($lines)) { if (!empty($lines)) {
$db->begin(); $db->begin();
foreach ($lines as $line) { foreach ($lines as $line) {
$res = $line->doStockMovement($label, $line->fk_warehouse_destination); $res = $line->doStockMovement($label, $line->fk_warehouse_destination);
if($res <= 0) $error++; if ($res <= 0) $error++;
} }
if(empty($error)) $db->commit(); if (empty($error)) $db->commit();
else $db->rollback(); else $db->rollback();
} }
if(empty($error)) { if (empty($error)) {
$object->setStatut($object::STATUS_TRANSFERED, $id); $object->setStatut($object::STATUS_TRANSFERED, $id);
$object->status = $object::STATUS_TRANSFERED; $object->status = $object::STATUS_TRANSFERED;
$object->date_reelle_arrivee = null; $object->date_reelle_arrivee = null;
@ -399,8 +389,8 @@ jQuery(document).ready(function() {';
// Affichage alerte date prévue de départ si transfert concerné // Affichage alerte date prévue de départ si transfert concerné
$date_prevue_depart = $object->date_prevue_depart; $date_prevue_depart = $object->date_prevue_depart;
$date_prevue_depart_plus_delai = $date_prevue_depart; $date_prevue_depart_plus_delai = $date_prevue_depart;
if($object->lead_time_for_warning > 0) $date_prevue_depart_plus_delai = strtotime(date('Y-m-d', $date_prevue_depart) . ' + '.$object->lead_time_for_warning.' day'); if ($object->lead_time_for_warning > 0) $date_prevue_depart_plus_delai = strtotime(date('Y-m-d', $date_prevue_depart) . ' + '.$object->lead_time_for_warning.' day');
if(!empty($date_prevue_depart) && $date_prevue_depart_plus_delai < strtotime(date('Y-m-d'))) { if (!empty($date_prevue_depart) && $date_prevue_depart_plus_delai < strtotime(date('Y-m-d'))) {
print "$('.valuefield.fieldname_date_prevue_depart').append('"; print "$('.valuefield.fieldname_date_prevue_depart').append('";
print img_warning($langs->trans('Alert').' - '.$langs->trans('Late')); print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
print "');"; print "');";
@ -411,8 +401,7 @@ print '});
// Part to create // Part to create
if ($action == 'create') if ($action == 'create') {
{
print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("StockTransfer")), '', 'object_'.$object->picto); print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("StockTransfer")), '', 'object_'.$object->picto);
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
@ -450,8 +439,7 @@ if ($action == 'create')
} }
// Part to edit record // Part to edit record
if (($id || $ref) && $action == 'edit') if (($id || $ref) && $action == 'edit') {
{
//if($object->status < 3) { //if($object->status < 3) {
print load_fiche_titre($langs->trans("StockTransfer"), '', 'object_' . $object->picto); print load_fiche_titre($langs->trans("StockTransfer"), '', 'object_' . $object->picto);
@ -485,8 +473,7 @@ if (($id || $ref) && $action == 'edit')
} }
// Part to show record // Part to show record
if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
{
$res = $object->fetch_optionals(); $res = $object->fetch_optionals();
$head = stocktransferPrepareHead($object); $head = stocktransferPrepareHead($object);
@ -495,13 +482,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
$formconfirm = ''; $formconfirm = '';
// Confirmation to delete // Confirmation to delete
if ($action == 'delete') if ($action == 'delete') {
{
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteStockTransfer'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteStockTransfer'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
} }
// Confirmation to delete line // Confirmation to delete line
if ($action == 'deleteline') if ($action == 'deleteline') {
{
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
} }
// Clone confirmation // Clone confirmation
@ -540,8 +525,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
} }
// Confirmation of action xxxx // Confirmation of action xxxx
if ($action == 'xxx') if ($action == 'xxx') {
{
$formquestion = array(); $formquestion = array();
/* /*
$forcecombo=0; $forcecombo=0;
@ -651,8 +635,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
* Lines * Lines
*/ */
if (!empty($object->table_element_line)) if (!empty($object->table_element_line)) {
{
// Show object lines // Show object lines
/*$result = $object->getLinesArray(); /*$result = $object->getLinesArray();
@ -709,9 +692,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
<input type="hidden" name="mode" value=""> <input type="hidden" name="mode" value="">
<input type="hidden" name="id" value="' . $object->id.'"> <input type="hidden" name="id" value="' . $object->id.'">
'; ';
if($lineid > 0) print '<input type="hidden" name="lineid" value="'.$lineid.'" />'; if ($lineid > 0) print '<input type="hidden" name="lineid" value="'.$lineid.'" />';
print '<table id="tablelines" class="liste centpercent">'; print '<table id="tablelines" class="liste centpercent">';
//print '<div class="tagtable centpercent">'; //print '<div class="tagtable centpercent">';
$param = ''; $param = '';
@ -725,7 +708,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print getTitleFieldOfList($langs->trans('Qty'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'center tagtd maxwidthonsmartphone '); print getTitleFieldOfList($langs->trans('Qty'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'center tagtd maxwidthonsmartphone ');
print getTitleFieldOfList($langs->trans('AverageUnitPricePMPShort'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'center tagtd maxwidthonsmartphone '); print getTitleFieldOfList($langs->trans('AverageUnitPricePMPShort'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'center tagtd maxwidthonsmartphone ');
print getTitleFieldOfList($langs->trans('PMPValue'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'center tagtd maxwidthonsmartphone '); print getTitleFieldOfList($langs->trans('PMPValue'), 0, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'center tagtd maxwidthonsmartphone ');
if(empty($object->status)) { if (empty($object->status)) {
print getTitleFieldOfList('', 0); print getTitleFieldOfList('', 0);
print getTitleFieldOfList('', 0); print getTitleFieldOfList('', 0);
print getTitleFieldOfList('', 0); print getTitleFieldOfList('', 0);
@ -738,8 +721,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
$warehousestatics = new Entrepot($db); $warehousestatics = new Entrepot($db);
$warehousestatict = new Entrepot($db); $warehousestatict = new Entrepot($db);
foreach ($listofdata as $key => $line) foreach ($listofdata as $key => $line) {
{
$productstatic->fetch($line->fk_product); $productstatic->fetch($line->fk_product);
$warehousestatics->fetch($line->fk_warehouse_source); $warehousestatics->fetch($line->fk_warehouse_source);
$warehousestatict->fetch($line->fk_warehouse_destination); $warehousestatict->fetch($line->fk_warehouse_destination);
@ -752,25 +734,24 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<tr id="row-'.$line->id.'" class="drag drop oddeven" '.$domData.'>'; print '<tr id="row-'.$line->id.'" class="drag drop oddeven" '.$domData.'>';
print '<td class="titlefield">'; print '<td class="titlefield">';
if($action === 'editline' && $line->id == $lineid) $form->select_produits($line->fk_product, 'fk_product', $filtertype, $limit, 0, -1, 2, '', 0, array(), 0, 0, 0, 'minwidth200imp maxwidth300', 1); if ($action === 'editline' && $line->id == $lineid) $form->select_produits($line->fk_product, 'fk_product', $filtertype, $limit, 0, -1, 2, '', 0, array(), 0, 0, 0, 'minwidth200imp maxwidth300', 1);
else print $productstatic->getNomUrl(1).' - '.$productstatic->label; else print $productstatic->getNomUrl(1).' - '.$productstatic->label;
print '</td>'; print '</td>';
if ($conf->productbatch->enabled) if ($conf->productbatch->enabled) {
{
print '<td>'; print '<td>';
if($action === 'editline' && $line->id == $lineid) print '<input type="text" value="'.$line->batch.'" name="batch" class="flat maxwidth50"/>'; if ($action === 'editline' && $line->id == $lineid) print '<input type="text" value="'.$line->batch.'" name="batch" class="flat maxwidth50"/>';
else print $line->batch; else print $line->batch;
print '</td>'; print '</td>';
} }
print '<td>'; print '<td>';
if($action === 'editline' && $line->id == $lineid) print $formproduct->selectWarehouses($line->fk_warehouse_source, 'fk_warehouse_source', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200', $TExcludedWarehouseSource); if ($action === 'editline' && $line->id == $lineid) print $formproduct->selectWarehouses($line->fk_warehouse_source, 'fk_warehouse_source', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200', $TExcludedWarehouseSource);
else print $warehousestatics->getNomUrl(1); else print $warehousestatics->getNomUrl(1);
print '</td>'; print '</td>';
print '<td>'; print '<td>';
if($action === 'editline' && $line->id == $lineid) print $formproduct->selectWarehouses($line->fk_warehouse_destination,'fk_warehouse_destination', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200', $TExcludedWarehouseDestination); if ($action === 'editline' && $line->id == $lineid) print $formproduct->selectWarehouses($line->fk_warehouse_destination, 'fk_warehouse_destination', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, array(), 'minwidth200imp maxwidth200', $TExcludedWarehouseDestination);
else print $warehousestatict->getNomUrl(1); else print $warehousestatict->getNomUrl(1);
print '</td>'; print '</td>';
if($action === 'editline' && $line->id == $lineid) print '<td class="center"><input type="text" class="flat maxwidth50" name="qty" value="'.$line->qty.'"></td>'; if ($action === 'editline' && $line->id == $lineid) print '<td class="center"><input type="text" class="flat maxwidth50" name="qty" value="'.$line->qty.'"></td>';
else print '<td class="center">'.$line->qty.'</td>'; else print '<td class="center">'.$line->qty.'</td>';
print '<td class="center">'; print '<td class="center">';
print price($line->pmp, 0, '', 1, -1, -1, $conf->currency); print price($line->pmp, 0, '', 1, -1, -1, $conf->currency);
@ -778,9 +759,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<td class="center">'; print '<td class="center">';
print price($line->pmp * $line->qty, 0, '', 1, -1, -1, $conf->currency); print price($line->pmp * $line->qty, 0, '', 1, -1, -1, $conf->currency);
print '</td>'; print '</td>';
if(empty($object->status)) { if (empty($object->status)) {
if ($action === 'editline' && $line->id == $lineid) {
if($action === 'editline' && $line->id == $lineid) {
//print '<td class="right" colspan="2"><input type="submit" class="button" name="addline" value="' . dol_escape_htmltag($langs->trans('Save')) . '"></td>'; //print '<td class="right" colspan="2"><input type="submit" class="button" name="addline" value="' . dol_escape_htmltag($langs->trans('Save')) . '"></td>';
print '<td class="center valignmiddle" colspan="2"><input type="submit" class="button buttongen marginbottomonly" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'"><br>'; print '<td class="center valignmiddle" colspan="2"><input type="submit" class="button buttongen marginbottomonly" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'"><br>';
print '<input type="submit" class="button buttongen marginbottomonly" id="cancellinebutton" name="cancel" value="'.$langs->trans("Cancel").'"></td>'; print '<input type="submit" class="button buttongen marginbottomonly" id="cancellinebutton" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
@ -819,9 +799,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '</tr>'; print '</tr>';
} }
if(empty($object->status) && $action !== 'editline') { if (empty($object->status) && $action !== 'editline') {
print '<tr class="oddeven">'; print '<tr class="oddeven">';
// Product // Product
print '<td class="titlefield">'; print '<td class="titlefield">';
$filtertype = 0; $filtertype = 0;
if (!empty($conf->global->STOCK_SUPPORTS_SERVICES)) $filtertype = ''; if (!empty($conf->global->STOCK_SUPPORTS_SERVICES)) $filtertype = '';
@ -844,21 +824,21 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// On stock ceux qui ne doivent pas être proposés dans la liste // On stock ceux qui ne doivent pas être proposés dans la liste
$TExcludedWarehouseSource=array(); $TExcludedWarehouseSource=array();
if(!empty($object->fk_warehouse_source)) { if (!empty($object->fk_warehouse_source)) {
$source_ent = new Entrepot($db); $source_ent = new Entrepot($db);
$source_ent->fetch($object->fk_warehouse_source); $source_ent->fetch($object->fk_warehouse_source);
foreach ($formproduct->cache_warehouses as $TDataCacheWarehouse) { foreach ($formproduct->cache_warehouses as $TDataCacheWarehouse) {
if(strpos($TDataCacheWarehouse['full_label'], $source_ent->label) === false) $TExcludedWarehouseSource[] = $TDataCacheWarehouse['id']; if (strpos($TDataCacheWarehouse['full_label'], $source_ent->label) === false) $TExcludedWarehouseSource[] = $TDataCacheWarehouse['id'];
} }
} }
// On stock ceux qui ne doivent pas être proposés dans la liste // On stock ceux qui ne doivent pas être proposés dans la liste
$TExcludedWarehouseDestination=array(); $TExcludedWarehouseDestination=array();
if(!empty($object->fk_warehouse_destination)) { if (!empty($object->fk_warehouse_destination)) {
$dest_ent = new Entrepot($db); $dest_ent = new Entrepot($db);
$dest_ent->fetch($object->fk_warehouse_destination); $dest_ent->fetch($object->fk_warehouse_destination);
foreach ($formproduct->cache_warehouses as $TDataCacheWarehouse) { foreach ($formproduct->cache_warehouses as $TDataCacheWarehouse) {
if(strpos($TDataCacheWarehouse['full_label'], $dest_ent->label) === false) $TExcludedWarehouseDestination[] = $TDataCacheWarehouse['id']; if (strpos($TDataCacheWarehouse['full_label'], $dest_ent->label) === false) $TExcludedWarehouseDestination[] = $TDataCacheWarehouse['id'];
} }
} }
@ -887,7 +867,6 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// Grad and drop lines // Grad and drop lines
print '<td></td>'; print '<td></td>';
print '</tr>'; print '</tr>';
} }
print '</table>'; print '</table>';
@ -902,25 +881,21 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) if (empty($reshook)) {
{
// Send // Send
if (empty($user->socid)) { if (empty($user->socid)) {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>'."\n"; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>'."\n";
} }
// Back to draft // Back to draft
if ($object->status == $object::STATUS_VALIDATED) if ($object->status == $object::STATUS_VALIDATED) {
{ if ($permissiontoadd) {
if ($permissiontoadd)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes">'.$langs->trans("SetToDraft").'</a>'; print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes">'.$langs->trans("SetToDraft").'</a>';
} }
} }
// Modify // Modify
if ($permissiontoadd) if ($permissiontoadd) {
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit">'.$langs->trans("Modify").'</a>'."\n"; print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit">'.$langs->trans("Modify").'</a>'."\n";
} }
/*else /*else
@ -929,38 +904,26 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
}*/ }*/
// Validate // Validate
if ($object->status == $object::STATUS_DRAFT) if ($object->status == $object::STATUS_DRAFT) {
{ if ($permissiontoadd) {
if ($permissiontoadd) if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
{
if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0))
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=valid">'.$langs->trans("Validate").'</a>'; print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=valid">'.$langs->trans("Validate").'</a>';
} } else {
else
{
$langs->load("errors"); $langs->load("errors");
print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>'; print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
} }
} }
} } elseif ($object->status == $object::STATUS_VALIDATED) {
elseif($object->status == $object::STATUS_VALIDATED) {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=destock">'.$langs->trans("StockTransferDecrementation").'</a>'; print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=destock">'.$langs->trans("StockTransferDecrementation").'</a>';
} } elseif ($object->status == $object::STATUS_TRANSFERED) {
elseif($object->status == $object::STATUS_TRANSFERED) {
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=destockcancel">'.$langs->trans("StockTransferDecrementationCancel").'</a>'; print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=destockcancel">'.$langs->trans("StockTransferDecrementationCancel").'</a>';
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=addstock">'.$langs->trans("StockTransferIncrementation").'</a>'; print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=addstock">'.$langs->trans("StockTransferIncrementation").'</a>';
} } elseif ($object->status == $object::STATUS_CLOSED) {
elseif($object->status == $object::STATUS_CLOSED) {
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=addstockcancel">'.$langs->trans("StockTransferIncrementationCancel").'</a>'; print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=addstockcancel">'.$langs->trans("StockTransferIncrementationCancel").'</a>';
} }
// Clone // Clone
if ($permissiontoadd) if ($permissiontoadd) {
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=stocktransfer">'.$langs->trans("ToClone").'</a>'."\n"; print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=stocktransfer">'.$langs->trans("ToClone").'</a>'."\n";
} }
@ -990,8 +953,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
*/ */
// Delete (need delete permission, or if draft, just need create/modify permission) // Delete (need delete permission, or if draft, just need create/modify permission)
if ($object->status < $object::STATUS_TRANSFERED && $permissiontoadd) if ($object->status < $object::STATUS_TRANSFERED && $permissiontoadd) {
{
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>'."\n"; print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>'."\n";
} }
/*else /*else
@ -1008,8 +970,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
$action = 'presend'; $action = 'presend';
} }
if ($action != 'presend') if ($action != 'presend') {
{
print '<div class="fichecenter"><div class="fichehalfleft">'; print '<div class="fichecenter"><div class="fichehalfleft">';
print '<a name="builddoc"></a>'; // ancre print '<a name="builddoc"></a>'; // ancre

View File

@ -52,27 +52,20 @@ $result = restrictedArea($user, 'stocktransfer', $id, '', 'stocktransfer');
$object = new StockTransfer($db); $object = new StockTransfer($db);
// Load object // Load object
if ($id > 0 || !empty($ref)) if ($id > 0 || !empty($ref)) {
{
$ret = $object->fetch($id, $ref); $ret = $object->fetch($id, $ref);
if ($ret == 0) if ($ret == 0) {
{
$langs->load("errors"); $langs->load("errors");
setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors'); setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
$error++; $error++;
} } elseif ($ret < 0) {
elseif ($ret < 0)
{
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
$error++; $error++;
} }
} }
if (!$error) if (!$error) {
{
$object->fetch_thirdparty(); $object->fetch_thirdparty();
} } else {
else
{
header('Location: '.dol_buildpath('/stocktransfer/stocktransfer_list.php', 1)); header('Location: '.dol_buildpath('/stocktransfer/stocktransfer_list.php', 1));
exit; exit;
} }
@ -82,54 +75,40 @@ else
* Add a new contact * Add a new contact
*/ */
if ($action == 'addcontact' && $user->rights->stocktransfer->stocktransfer->write) if ($action == 'addcontact' && $user->rights->stocktransfer->stocktransfer->write) {
{ if ($object->id > 0) {
if ($object->id > 0) $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
{ $result = $object->add_contact($contactid, !empty($_POST["typecontact"]) ? $_POST["typecontact"] : $_POST["type"], $_POST["source"]);
$contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); }
$result = $object->add_contact($contactid, !empty($_POST["typecontact"]) ? $_POST["typecontact"] : $_POST["type"], $_POST["source"]);
}
if ($result >= 0) if ($result >= 0) {
{
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit; exit;
} } else {
else if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
{
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$langs->load("errors"); $langs->load("errors");
setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
} } else {
else
{
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
} }
} }
// Toggle the status of a contact // Toggle the status of a contact
elseif ($action == 'swapstatut' && $user->rights->stocktransfer->stocktransfer->write) elseif ($action == 'swapstatut' && $user->rights->stocktransfer->stocktransfer->write) {
{ if ($object->id > 0) {
if ($object->id > 0) $result = $object->swapContactStatus(GETPOST('ligne'));
{
$result = $object->swapContactStatus(GETPOST('ligne'));
} }
} }
// Deletes a contact // Deletes a contact
elseif ($action == 'deletecontact' && $user->rights->stocktransfer->stocktransfer->write) elseif ($action == 'deletecontact' && $user->rights->stocktransfer->stocktransfer->write) {
{
$result = $object->delete_contact($lineid); $result = $object->delete_contact($lineid);
if ($result >= 0) if ($result >= 0) {
{
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit; exit;
} } else {
else
{
dol_print_error($db); dol_print_error($db);
} }
} }
@ -151,9 +130,8 @@ $form = new Form($db);
$formcompany = new FormCompany($db); $formcompany = new FormCompany($db);
$formother = new FormOther($db); $formother = new FormOther($db);
if ($object->id > 0) if ($object->id > 0) {
{ $head = stocktransferPrepareHead($object);
$head = stocktransferPrepareHead($object);
dol_fiche_head($head, 'contact', $langs->trans("StockTransfer"), -1, 'stock'); dol_fiche_head($head, 'contact', $langs->trans("StockTransfer"), -1, 'stock');
@ -167,42 +145,40 @@ if ($object->id > 0)
$morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
$morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1); $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
// Thirdparty // Thirdparty
if(!empty($object->thirdparty)) { if (!empty($object->thirdparty)) {
$morehtmlref .= '<br>' . $langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1, 'customer'); $morehtmlref .= '<br>' . $langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1, 'customer');
} }
// Project // Project
if (!empty($conf->projet->enabled)) if (!empty($conf->projet->enabled)) {
{ $langs->load("projects");
$langs->load("projects"); $morehtmlref .= '<br>'.$langs->trans('Project').' ';
$morehtmlref .= '<br>'.$langs->trans('Project').' '; if ($user->rights->stocktransfer->stocktransfer->write) {
if ($user->rights->stocktransfer->stocktransfer->write) if ($action != 'classify') {
{ //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
if ($action != 'classify') { $morehtmlref .= ' : ';
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>'; }
$morehtmlref .= ' : '; if ($action == 'classify') {
} //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
if ($action == 'classify') { $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); $morehtmlref .= '<input type="hidden" name="action" value="classin">';
$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'; $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
$morehtmlref .= '<input type="hidden" name="action" value="classin">'; $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">'; $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); $morehtmlref .= '</form>';
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; } else {
$morehtmlref .= '</form>'; $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
} 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)) {
} else { $proj = new Project($db);
if (!empty($object->fk_project)) { $proj->fetch($object->fk_project);
$proj = new Project($db); $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
$proj->fetch($object->fk_project); $morehtmlref .= $proj->ref;
$morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">'; $morehtmlref .= '</a>';
$morehtmlref .= $proj->ref; } else {
$morehtmlref .= '</a>'; $morehtmlref .= '';
} else { }
$morehtmlref .= ''; }
}
}
} }
$morehtmlref .= '</div>'; $morehtmlref .= '</div>';
@ -213,8 +189,7 @@ if ($object->id > 0)
$user->rights->stocktransfer->write = $user->rights->stocktransfer->stocktransfer->write; $user->rights->stocktransfer->write = $user->rights->stocktransfer->stocktransfer->write;
// Contacts lines (modules that overwrite templates must declare this into descriptor) // Contacts lines (modules that overwrite templates must declare this into descriptor)
$dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
foreach ($dirtpls as $reldir) foreach ($dirtpls as $reldir) {
{
$res = @include dol_buildpath($reldir.'/contacts.tpl.php'); $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
if ($res) break; if ($res) break;
} }

View File

@ -108,8 +108,7 @@ $help_url = '';
//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; //$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('', $title, $help_url); llxHeader('', $title, $help_url);
if ($object->id) if ($object->id) {
{
/* /*
* Show tabs * Show tabs
*/ */
@ -121,8 +120,7 @@ if ($object->id)
// Build file list // Build file list
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
$totalsize = 0; $totalsize = 0;
foreach ($filearray as $key => $file) foreach ($filearray as $key => $file) {
{
$totalsize += $file['size']; $totalsize += $file['size'];
} }
@ -200,9 +198,7 @@ if ($object->id)
$relativepathwithnofile = 'stocktransfer/'.dol_sanitizeFileName($object->ref).'/'; $relativepathwithnofile = 'stocktransfer/'.dol_sanitizeFileName($object->ref).'/';
include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php'; include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
} } else {
else
{
accessforbidden('', 0, 1); accessforbidden('', 0, 1);
} }

View File

@ -111,30 +111,25 @@ if (!$sortorder) $sortorder = "ASC";
// Initialize array of search criterias // Initialize array of search criterias
$search_all = GETPOST('search_all', 'alphanohtml') ? trim(GETPOST('search_all', 'alphanohtml')) : trim(GETPOST('sall', 'alphanohtml')); $search_all = GETPOST('search_all', 'alphanohtml') ? trim(GETPOST('search_all', 'alphanohtml')) : trim(GETPOST('sall', 'alphanohtml'));
$search = array(); $search = array();
foreach ($object->fields as $key => $val) foreach ($object->fields as $key => $val) {
{
if (GETPOST('search_'.$key, 'alpha') !== '') $search[$key] = GETPOST('search_'.$key, 'alpha'); if (GETPOST('search_'.$key, 'alpha') !== '') $search[$key] = GETPOST('search_'.$key, 'alpha');
} }
// List of fields to search into when doing a "search in all" // List of fields to search into when doing a "search in all"
$fieldstosearchall = array(); $fieldstosearchall = array();
foreach ($object->fields as $key => $val) foreach ($object->fields as $key => $val) {
{
if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label']; if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label'];
} }
// Definition of fields for list // Definition of fields for list
$arrayfields = array(); $arrayfields = array();
foreach ($object->fields as $key => $val) foreach ($object->fields as $key => $val) {
{
// If $val['visible']==0, then we never show the field // If $val['visible']==0, then we never show the field
if (!empty($val['visible'])) $arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>($val['enabled'] && ($val['visible'] != 3)), 'position'=>$val['position']); if (!empty($val['visible'])) $arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>($val['enabled'] && ($val['visible'] != 3)), 'position'=>$val['position']);
} }
// Extra fields // Extra fields
if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) {
{ foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val)
{
if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) { if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) {
$arrayfields["ef.".$key] = array( $arrayfields["ef.".$key] = array(
'label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'label'=>$extrafields->attributes[$object->table_element]['label'][$key],
@ -156,8 +151,7 @@ $permissiontodelete = $user->rights->stocktransfer->stocktransfer->delete;
// Security check // Security check
if (empty($conf->stocktransfer->enabled)) accessforbidden('Module not enabled'); if (empty($conf->stocktransfer->enabled)) accessforbidden('Module not enabled');
$socid = 0; $socid = 0;
if ($user->socid > 0) // Protection if external user if ($user->socid > 0) { // Protection if external user
{
//$socid = $user->socid; //$socid = $user->socid;
accessforbidden(); accessforbidden();
} }
@ -177,24 +171,20 @@ $parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $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 ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) if (empty($reshook)) {
{
// Selection of new fields // Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Purge search criteria // Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
{ foreach ($object->fields as $key => $val) {
foreach ($object->fields as $key => $val)
{
$search[$key] = ''; $search[$key] = '';
} }
$toselect = ''; $toselect = '';
$search_array_options = array(); $search_array_options = array();
} }
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') 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')) || 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 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
} }
@ -223,8 +213,7 @@ $title = $langs->trans('StockTransferList');
// Build and execute select // Build and execute select
// -------------------------------------------------------------------- // --------------------------------------------------------------------
$sql = 'SELECT '; $sql = 'SELECT ';
foreach ($object->fields as $key => $val) foreach ($object->fields as $key => $val) {
{
$sql .= 't.'.$key.', '; $sql .= 't.'.$key.', ';
} }
// Add fields from extrafields // Add fields from extrafields
@ -240,8 +229,7 @@ $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
if (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 (t.rowid = ef.fk_object)"; if (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 (t.rowid = ef.fk_object)";
if ($object->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (".getEntity($object->element).")"; if ($object->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
else $sql .= " WHERE 1 = 1"; else $sql .= " WHERE 1 = 1";
foreach ($search as $key => $val) foreach ($search as $key => $val) {
{
if ($key == 'status' && $search[$key] == -1) continue; if ($key == 'status' && $search[$key] == -1) continue;
$mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0); $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
if (strpos($object->fields[$key]['type'], 'integer:') === 0) { if (strpos($object->fields[$key]['type'], 'integer:') === 0) {
@ -280,28 +268,22 @@ $sql .= $db->order($sortfield, $sortorder);
// Count total nb of records // Count total nb of records
$nbtotalofrecords = ''; $nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
{
$resql = $db->query($sql); $resql = $db->query($sql);
$nbtotalofrecords = $db->num_rows($resql); $nbtotalofrecords = $db->num_rows($resql);
if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0 if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
{
$page = 0; $page = 0;
$offset = 0; $offset = 0;
} }
} }
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
{
$num = $nbtotalofrecords; $num = $nbtotalofrecords;
} } else {
else
{
if ($limit) $sql .= $db->plimit($limit + 1, $offset); if ($limit) $sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql); $resql = $db->query($sql);
if (!$resql) if (!$resql) {
{
dol_print_error($db); dol_print_error($db);
exit; exit;
} }
@ -310,8 +292,7 @@ else
} }
// Direct jump if only one record found // Direct jump if only one record found
if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
{
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$id = $obj->rowid; $id = $obj->rowid;
header("Location: ".dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?id='.$id); header("Location: ".dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?id='.$id);
@ -344,8 +325,7 @@ $arrayofselected = is_array($toselect) ? $toselect : array();
$param = ''; $param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
foreach ($search as $key => $val) foreach ($search as $key => $val) {
{
if (is_array($search[$key]) && count($search[$key])) foreach ($search[$key] as $skey) $param .= '&search_'.$key.'[]='.urlencode($skey); if (is_array($search[$key]) && count($search[$key])) foreach ($search[$key] as $skey) $param .= '&search_'.$key.'[]='.urlencode($skey);
else $param .= '&search_'.$key.'='.urlencode($search[$key]); else $param .= '&search_'.$key.'='.urlencode($search[$key]);
} }
@ -385,8 +365,7 @@ $objecttmp = new StockTransfer($db);
$trackid = 'xxxx'.$object->id; $trackid = 'xxxx'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
if ($search_all) if ($search_all) {
{
foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'; print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
} }
@ -401,8 +380,7 @@ $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $ob
if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
else $moreforfilter = $hookmanager->resPrint; else $moreforfilter = $hookmanager->resPrint;
if (!empty($moreforfilter)) if (!empty($moreforfilter)) {
{
print '<div class="liste_titre liste_titre_bydiv centpercent">'; print '<div class="liste_titre liste_titre_bydiv centpercent">';
print $moreforfilter; print $moreforfilter;
print '</div>'; print '</div>';
@ -419,21 +397,18 @@ print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwit
// Fields title search // Fields title search
// -------------------------------------------------------------------- // --------------------------------------------------------------------
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
foreach ($object->fields as $key => $val) foreach ($object->fields as $key => $val) {
{
$cssforfield = (empty($val['css']) ? '' : $val['css']); $cssforfield = (empty($val['css']) ? '' : $val['css']);
if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right'; elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right';
if (!empty($arrayfields['t.'.$key]['checked'])) if (!empty($arrayfields['t.'.$key]['checked'])) {
{
print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">'; print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
if (is_array($val['arrayofkeyval'])) print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75'); if (is_array($val['arrayofkeyval'])) print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75');
elseif (strpos($val['type'], 'integer:') === 0) { elseif (strpos($val['type'], 'integer:') === 0) {
print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1); print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1);
} } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
elseif (!preg_match('/^(date|timestamp)/', $val['type'])) print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
print '</td>'; print '</td>';
} }
} }
@ -455,15 +430,13 @@ print '</tr>'."\n";
// Fields title label // Fields title label
// -------------------------------------------------------------------- // --------------------------------------------------------------------
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
foreach ($object->fields as $key => $val) foreach ($object->fields as $key => $val) {
{
$cssforfield = (empty($val['css']) ? '' : $val['css']); $cssforfield = (empty($val['css']) ? '' : $val['css']);
if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap'; elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right'; elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right';
if (!empty($arrayfields['t.'.$key]['checked'])) if (!empty($arrayfields['t.'.$key]['checked'])) {
{
print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n"; print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
} }
} }
@ -480,10 +453,8 @@ print '</tr>'."\n";
// Detect if we need a fetch on each output line // Detect if we need a fetch on each output line
$needToFetchEachLine = 0; $needToFetchEachLine = 0;
if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
{ foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val)
{
if (preg_match('/\$object/', $val)) $needToFetchEachLine++; // There is at least one compute field that use $object if (preg_match('/\$object/', $val)) $needToFetchEachLine++; // There is at least one compute field that use $object
} }
} }
@ -493,8 +464,7 @@ if (is_array($extrafields->attributes[$object->table_element]['computed']) && co
// -------------------------------------------------------------------- // --------------------------------------------------------------------
$i = 0; $i = 0;
$totalarray = array(); $totalarray = array();
while ($i < ($limit ? min($num, $limit) : $num)) while ($i < ($limit ? min($num, $limit) : $num)) {
{
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if (empty($obj)) break; // Should not happen if (empty($obj)) break; // Should not happen
@ -503,8 +473,7 @@ while ($i < ($limit ? min($num, $limit) : $num))
// Show here line of result // Show here line of result
print '<tr class="oddeven">'; print '<tr class="oddeven">';
foreach ($object->fields as $key => $val) foreach ($object->fields as $key => $val) {
{
$cssforfield = (empty($val['css']) ? '' : $val['css']); $cssforfield = (empty($val['css']) ? '' : $val['css']);
if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center'; if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
elseif ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center'; elseif ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
@ -515,23 +484,21 @@ while ($i < ($limit ? min($num, $limit) : $num))
if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') $cssforfield .= ($cssforfield ? ' ' : '').'right'; if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') $cssforfield .= ($cssforfield ? ' ' : '').'right';
//if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100'; //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
if (!empty($arrayfields['t.'.$key]['checked'])) if (!empty($arrayfields['t.'.$key]['checked'])) {
{
print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>'; print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
if ($key == 'status') print $object->getLibStatut(5); if ($key == 'status') print $object->getLibStatut(5);
else { else {
print $object->showOutputField($val, $key, $object->$key, ''); print $object->showOutputField($val, $key, $object->$key, '');
if($key === 'date_prevue_depart' && $object->lead_time_for_warning > 0 && $object->$key > 0) { if ($key === 'date_prevue_depart' && $object->lead_time_for_warning > 0 && $object->$key > 0) {
$date_prevue_depart = $object->$key; $date_prevue_depart = $object->$key;
$date_prevue_depart_plus_delai = $date_prevue_depart; $date_prevue_depart_plus_delai = $date_prevue_depart;
if($object->lead_time_for_warning > 0) $date_prevue_depart_plus_delai = strtotime(date('Y-m-d', $date_prevue_depart) . ' + '.$object->lead_time_for_warning.' day'); if ($object->lead_time_for_warning > 0) $date_prevue_depart_plus_delai = strtotime(date('Y-m-d', $date_prevue_depart) . ' + '.$object->lead_time_for_warning.' day');
if($date_prevue_depart_plus_delai < strtotime(date('Y-m-d'))) print img_warning($langs->trans('Alert').' - '.$langs->trans('Late')); if ($date_prevue_depart_plus_delai < strtotime(date('Y-m-d'))) print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
} }
} }
print '</td>'; print '</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) $totalarray['nbfield']++;
if (!empty($val['isameasure'])) if (!empty($val['isameasure'])) {
{
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key; if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
$totalarray['val']['t.'.$key] += $object->$key; $totalarray['val']['t.'.$key] += $object->$key;
} }
@ -545,8 +512,7 @@ while ($i < ($limit ? min($num, $limit) : $num))
print $hookmanager->resPrint; print $hookmanager->resPrint;
// Action column // Action column
print '<td class="nowrap center">'; 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 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; $selected = 0;
if (in_array($object->id, $arrayofselected)) $selected = 1; if (in_array($object->id, $arrayofselected)) $selected = 1;
print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>'; print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
@ -563,8 +529,7 @@ while ($i < ($limit ? min($num, $limit) : $num))
include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
// If no record found // If no record found
if ($num == 0) if ($num == 0) {
{
$colspan = 1; $colspan = 1;
foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; } foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>'; print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
@ -582,8 +547,7 @@ print '</div>'."\n";
print '</form>'."\n"; print '</form>'."\n";
if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
{
$hidegeneratedfilelistifempty = 1; $hidegeneratedfilelistifempty = 1;
if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0; if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0;

View File

@ -90,8 +90,7 @@ $form = new Form($db);
$help_url = ''; $help_url = '';
llxHeader('', $langs->trans('ModuleStockTransferName'), $help_url); llxHeader('', $langs->trans('ModuleStockTransferName'), $help_url);
if ($id > 0 || !empty($ref)) if ($id > 0 || !empty($ref)) {
{
$object->fetch_thirdparty(); $object->fetch_thirdparty();
$head = stocktransferPrepareHead($object); $head = stocktransferPrepareHead($object);