This commit is contained in:
atm-lena 2022-02-08 15:54:31 +01:00
parent 6a94a6ebac
commit 8db75f0d04
6 changed files with 167 additions and 14 deletions

View File

@ -89,6 +89,7 @@ $permissiontodelete = $user->rights->bom->delete || ($permissiontoadd && isset($
$upload_dir = $conf->bom->multidir_output[isset($object->entity) ? $object->entity : 1];
/*
* Actions
*/

View File

@ -26,8 +26,9 @@
// $object must be defined
// $permissiontoadd must be defined
// $permissiontodelete must be defined
// $backurlforlist must be defined
// $backurlforlist may be defined
// $backtopage may be defined
// $noback may be defined
// $triggermodname may be defined
if (!empty($permissionedit) && empty($permissiontoadd)) {
@ -127,7 +128,9 @@ if ($action == 'add' && !empty($permissiontoadd)) {
}
}
// var_dump($object); exit;
if (!$error) {
$result = $object->create($user);
if ($result > 0) {
// Creation OK
@ -137,8 +140,11 @@ if ($action == 'add' && !empty($permissiontoadd)) {
}
$urltogo = $backtopage ? str_replace('__ID__', $result, $backtopage) : $backurlforlist;
$urltogo = preg_replace('/--IDFORBACKTOPAGE--/', $object->id, $urltogo); // New method to autoselect project after a New on another form object creation
header("Location: ".$urltogo);
exit;
if(!empty($noback)) {
header("Location: " . $urltogo);
exit;
}
} else {
$error++;
// Creation KO
@ -305,8 +311,10 @@ if ($action == 'confirm_delete' && !empty($permissiontodelete)) {
// Delete OK
setEventMessages("RecordDeleted", null, 'mesgs');
header("Location: ".$backurlforlist);
exit;
if(!empty($noback)) {
header("Location: " . $backurlforlist);
exit;
}
} else {
$error++;
if (!empty($object->errors)) {
@ -349,8 +357,10 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissionto
setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs');
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
if(!empty($noback)) {
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
exit;
}
} else {
$error++;
setEventMessages($object->error, $object->errors, 'errors');
@ -488,8 +498,10 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd))
$newid = $result;
}
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$newid); // Open record of new object
exit;
if(!empty($noback)) {
header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $newid); // Open record of new object
exit;
}
} else {
$error++;
setEventMessages($objectutil->error, $objectutil->errors, 'errors');

View File

@ -107,3 +107,4 @@ THMEstimatedHelp=This rate makes it possible to define a forecast cost of the it
BOM=Bill Of Materials
CollapseBOMHelp=You can define the default display of the details of the nomenclature in the configuration of the BOM module
MOAndLines=Manufacturing Orders and lines
MoChildGenerate=Generate Child Mo

View File

@ -120,6 +120,7 @@ class Mo extends CommonObject
'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000, 'notnull'=>-1,),
'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>1, 'visible'=>0, 'position'=>1010),
'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>2, 'position'=>1000, 'default'=>0, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated', '2'=>'InProgress', '3'=>'StatusMOProduced', '9'=>'Canceled')),
'fk_parent_line' => array('type'=>'integer:MoLine:mrp/class/mo.class.php', 'label'=>'ParentMo', 'enabled'=>1, 'visible'=>0, 'position'=>1020, 'default'=>0, 'notnull'=>0, 'index'=>1,'showoncombobox'=>0),
);
public $rowid;
public $entity;
@ -201,6 +202,8 @@ class Mo extends CommonObject
*/
public $lines = array();
public $fk_parent_line;
/**
@ -669,6 +672,7 @@ class Mo extends CommonObject
}
$resultline = $moline->create($user, false); // Never use triggers here
if ($resultline <= 0) {
$error++;
$this->error = $moline->error;
@ -1202,12 +1206,13 @@ class Mo extends CommonObject
*
* @return array|int array of lines if OK, <0 if KO
*/
public function getLinesArray()
public function getLinesArray($role = '')
{
$this->lines = array();
$objectline = new MoLine($this->db);
$result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_mo = '.((int) $this->id)));
if($role) $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_mo = '.((int) $this->id),'role' => $role));
else $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_mo = '.((int) $this->id)));
if (is_numeric($result)) {
$this->error = $this->error;
@ -1609,8 +1614,10 @@ class MoLine extends CommonObjectLine
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < min($limit, $num)) {
while ($i < ($limit ? min($limit, $num) : $num)) {
$obj = $this->db->fetch_object($resql);
$record = new self($this->db);
@ -1655,4 +1662,92 @@ class MoLine extends CommonObjectLine
return $this->deleteCommon($user, $notrigger);
//return $this->deleteCommon($user, $notrigger, 1);
}
/**
* Return a link to the object card (with optionaly the picto)
*
* @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
* @param string $option On what the link point to ('nolink', '', 'production', ...)
* @param int $notooltip 1=Disable tooltip
* @param string $morecss Add more css on link
* @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
* @return string String with URL
*/
public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
{
global $conf, $langs, $hookmanager;
if (!empty($conf->dol_no_mouse_hover)) {
$notooltip = 1; // Force disable tooltips
}
$result = '';
$moparent = new Mo($this->db);
$moparent->fetch($this->fk_mo);
$label = img_picto('', $moparent->picto).' <u class="paddingrightonly">'.$langs->trans("ManufacturingOrder").'</u>';
if (isset($moparent->status)) {
$label .= ' '.$moparent->getLibStatut(5);
}
$label .= '<br>';
$label .= '<b>'.$langs->trans('Ref').':</b> '.$moparent->ref;
if (isset($moparent->label)) {
$label .= '<br><b>'.$langs->trans('Label').':</b> '.$moparent->label;
}
$url = DOL_URL_ROOT.'/mrp/mo_card.php?id='.$moparent->id;
if ($option == 'production') {
$url = DOL_URL_ROOT.'/mrp/mo_production.php?id='.$moparent->id;
}
if ($option != 'nolink') {
// Add param to save lastsearch_values or not
$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 ($add_save_lastsearch_values) {
$url .= '&save_lastsearch_values=1';
}
}
$linkclose = '';
if (empty($notooltip)) {
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$label = $langs->trans("ShowMo");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
} else {
$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
}
$linkstart = '<a href="'.$url.'"';
$linkstart .= $linkclose.'>';
$linkend = '</a>';
$result .= $linkstart;
if ($withpicto) {
$result .= img_object(($notooltip ? '' : $label), ($moparent->picto ? $moparent->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
}
if ($withpicto != 2) {
$result .= $moparent->ref;
}
$result .= $linkend;
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
global $action, $hookmanager;
$hookmanager->initHooks(array('modao'));
$parameters = array('id'=>$moparent->id, 'getnomurl'=>$result);
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $moparent, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) {
$result = $hookmanager->resPrint;
} else {
$result .= $hookmanager->resPrint;
}
return $result;
}
}

View File

@ -44,8 +44,11 @@ $cancel = GETPOST('cancel', 'aZ09');
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'mocard'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha');
$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
$TBomLineId = GETPOST('bomlineid', 'array');
//$lineid = GETPOST('lineid', 'int');
//var_dump($_POST); exit;
// Initialize technical objects
$object = new Mo($db);
$objectbom = new BOM($db);
@ -111,6 +114,7 @@ if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) {
$error = 0;
@ -120,7 +124,7 @@ if (empty($reshook)) {
if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
$backtopage = $backurlforlist;
} else {
} else {
$backtopage = DOL_URL_ROOT.'/mrp/mo_card.php?id='.($id > 0 ? $id : '__ID__');
}
}
@ -129,11 +133,51 @@ if (empty($reshook)) {
$backtopage = $backtopageforcancel;
}
$triggermodname = 'MRP_MO_MODIFY'; // Name of trigger action code to execute when we modify record
// Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
if($action == 'add' && empty($id)){
$noback = "";
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
$mo_parent = $object;
$moline = new MoLine($db);
$objectbomchildline = new BOMLine($db);
foreach($TBomLineId as $id_bom_line){
$object = new Mo($db);
$objectbomchildline->fetch($id_bom_line);
$TMoLines = $moline->fetchAll('', '', '1', '', array('origin_id' => $id_bom_line));
foreach ($TMoLines as $moline){
$_POST['fk_bom'] = $objectbomchildline->fk_bom_child;
$_POST['fk_parent_line'] = $moline->id;
$_POST['qty'] = $moline->qty;
$_POST['fk_product'] = $moline->fk_product;
}
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
}
$noback = 0;
header("Location: ".$urltogo);
exit;
}
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
// Actions when linking object each other
include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';

View File

@ -80,7 +80,7 @@ print '<td class="center">';
print '</td>';
print '<td class="center">';
print '<input type="checkbox" name="createofchildbom_'.$tmpproduct->id.'">';
print '<input type="checkbox" name="bomlineid[]" value="'.$line->id.'">';
print '</td>';
print '</tr>'."\n";