diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 3de176a1995..aee1f6ba0bf 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -28,6 +28,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php'; require_once DOL_DOCUMENT_ROOT.'/bom/lib/bom.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp.lib.php'; + // Load translation files required by the page $langs->loadLangs(array("mrp", "other")); @@ -581,47 +583,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''; print "\n"; - ?> - - - + + + + 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 @@ -311,8 +315,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)) { @@ -355,8 +361,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'); @@ -494,8 +502,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'); diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 8a3093b0f0a..a108e80e523 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -8437,7 +8437,7 @@ class Form * @param array $compatibleImportElementsList Array of compatibles elements object for "import from" action * @return int <0 if KO, >=0 if OK */ - public function showLinkedObjectBlock($object, $morehtmlright = '', $compatibleImportElementsList = false) + public function showLinkedObjectBlock($object, $morehtmlright = '', $compatibleImportElementsList = false, $title = 'RelatedObjects') { global $conf, $langs, $hookmanager; global $bc, $action; @@ -8456,7 +8456,7 @@ class Form $nbofdifferenttypes = count($object->linkedObjects); print ''; - print load_fiche_titre($langs->trans('RelatedObjects'), $morehtmlright, '', 0, 0, 'showlinkedobjectblock'); + print load_fiche_titre($langs->trans($title), $morehtmlright, '', 0, 0, 'showlinkedobjectblock'); print '
'; @@ -8527,11 +8527,6 @@ class Form if (empty($conf->expedition->enabled)) { continue; // Do not show if module disabled } - } elseif ($objecttype == 'mo') { - $tplpath = 'mrp/mo'; - if (empty($conf->mrp->enabled)) { - continue; // Do not show if module disabled - } } elseif ($objecttype == 'ficheinter') { $tplpath = 'fichinter'; if (empty($conf->ficheinter->enabled)) { diff --git a/htdocs/langs/en_US/mrp.lang b/htdocs/langs/en_US/mrp.lang index 224273d84e6..7f29b774b29 100644 --- a/htdocs/langs/en_US/mrp.lang +++ b/htdocs/langs/en_US/mrp.lang @@ -109,6 +109,6 @@ 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 -BOMNetNeeds=Net Needs -TreeStructure=Tree structure -GroupByProduct=Group by product \ No newline at end of file +MoChildGenerate=Generate Child Mo +ParentMo=MO Parent +MOChild=MO Child diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index f742a04a619..b99d03050ce 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -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,11 @@ class Mo extends CommonObject */ public $lines = array(); + /** + * @var integer Mo parent line + * */ + + public $fk_parent_line; /** @@ -1267,15 +1273,18 @@ class Mo extends CommonObject /** * Create an array of lines - * + * @param string $rolefilter string lines role filter * @return array|int array of lines if OK, <0 if KO */ - public function getLinesArray() + public function getLinesArray($rolefilter = '') { $this->lines = array(); $objectline = new MoLine($this->db); - $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_mo = '.((int) $this->id))); + + $TFilters = array('customsql'=>'fk_mo = '.((int) $this->id)); + if (!empty($rolefilter)) $TFilters['role'] = $rolefilter; + $result = $objectline->fetchAll('ASC', 'position', 0, 0, $TFilters); if (is_numeric($result)) { $this->error = $this->error; @@ -1380,6 +1389,13 @@ class Mo extends CommonObject $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE) ? '- '.$langs->trans("StockOnReception").'
' : ''); print ''; + // Product or sub-bom + print ''.$langs->trans('Description'); + if (!empty($conf->global->BOM_SUB_BOM)) { + print '   '.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'  '; + print ''.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").' '; + } + print ''; print ''.$langs->trans('Ref').''; print ''.$langs->trans('Qty'); if ($this->bom->bomtype == 0) { @@ -1392,9 +1408,9 @@ class Mo extends CommonObject print ''.$form->textwithpicto($langs->trans("VirtualStock"), $langs->trans("VirtualStockDesc")).''; print ''.$langs->trans('QtyFrozen').''; print ''.$langs->trans('DisableStockChange').''; - //print ''.$langs->trans('Efficiency').''; + print ''.$langs->trans('MoChildGenerate').''; //print ''.$form->showCheckAddButtons('checkforselect', 1).''; - print ''; + // print ''; print ''; $i = 0; @@ -1478,6 +1494,81 @@ class Mo extends CommonObject return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); } + + + /** + * Function used to return childs of Mo + * + * @return array if OK, -1 if KO + */ + public function getMoChilds() + { + + $TMoChilds = array(); + $error = 0; + + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."mrp_mo as mo_child"; + $sql.= " WHERE fk_parent_line IN "; + $sql.= " (SELECT rowid FROM ".MAIN_DB_PREFIX."mrp_production as line_parent"; + $sql.= " WHERE fk_mo=".((int) $this->id).")"; + + $resql = $this->db->query($sql); + + if ($resql) { + if ($this->db->num_rows($resql) > 0) { + while ($obj = $this->db->fetch_object($resql)) { + $MoChild = new Mo($this->db); + $res = $MoChild->fetch($obj->rowid); + if ($res > 0) $TMoChilds[$MoChild->id] = $MoChild; + else $error++; + } + } + } else { + $error++; + } + + if ($error) { + return -1; + } else { + return $TMoChilds; + } + } + + /** + * Function used to return childs of Mo + * + * @return object Mo if OK, -1 if KO, 0 if not exist + */ + public function getMoParent() + { + + $MoParent = new Mo($this->db); + $error = 0; + + $sql = "SELECT lineparent.fk_mo as id_moparent FROM ".MAIN_DB_PREFIX."mrp_mo as mo"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."mrp_production lineparent ON mo.fk_parent_line = lineparent.rowid"; + $sql.= " WHERE mo.rowid = ".((int) $this->id); + + $resql = $this->db->query($sql); + + if ($resql) { + if ($this->db->num_rows($resql) > 0) { + $obj = $this->db->fetch_object($resql); + $res = $MoParent->fetch($obj->id_moparent); + if ($res < 0) $error++; + } else { + return 0; + } + } else { + $error++; + } + + if ($error) { + return -1; + } else { + return $MoParent; + } + } } /** @@ -1671,7 +1762,7 @@ class MoLine extends CommonObjectLine 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); diff --git a/htdocs/mrp/mo_card.php b/htdocs/mrp/mo_card.php index 2a8fa13be52..70aebccad16 100644 --- a/htdocs/mrp/mo_card.php +++ b/htdocs/mrp/mo_card.php @@ -31,6 +31,8 @@ require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php'; require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp_mo.lib.php'; require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php'; +require_once DOL_DOCUMENT_ROOT.'/bom/lib/bom.lib.php'; + // Load translation files required by the page $langs->loadLangs(array("mrp", "other")); @@ -44,6 +46,7 @@ $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'); // Initialize technical objects @@ -128,9 +131,41 @@ if (empty($reshook)) { if ($cancel && !empty($backtopageforcancel)) { $backtopage = $backtopageforcancel; } - $triggermodname = 'MRP_MO_MODIFY'; // Name of trigger action code to execute when we modify record + //Create MO with Childs + if ($action == 'add' && empty($id) && !empty($TBomLineId)) { + $noback = 0; + 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('DESC', 'rowid', '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'; + + $res = $object->add_object_linked('mo', $mo_parent->id); + } + + header("Location: ".dol_buildpath('/mrp/mo_list.php', 1)); + exit; + } + // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; @@ -240,10 +275,12 @@ if ($action == 'create') { print dol_get_fiche_end(); + print mrpCollapseBomManagement(); + ?>