From 0f4b1e1d7a54d4cbcb0f1ada271a3045a92bcaae Mon Sep 17 00:00:00 2001 From: atm-lena Date: Tue, 15 Feb 2022 11:46:30 +0100 Subject: [PATCH] WIP --- htdocs/core/class/html.form.class.php | 8 +- htdocs/langs/fr_FR/mrp.lang | 1 + htdocs/mrp/class/mo.class.php | 161 ++++++++++------------- htdocs/mrp/mo_card.php | 18 ++- htdocs/mrp/tpl/linkedobjectblock.tpl.php | 36 ++--- 5 files changed, 104 insertions(+), 120 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 3375e9f7cc4..3d2c4572779 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -8406,11 +8406,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)) { @@ -8447,6 +8442,7 @@ class Form } $res = @include dol_buildpath($reldir.'/'.$tplname.'.tpl.php'); + if ($res) { $nboftypesoutput++; break; @@ -8508,6 +8504,7 @@ class Form unset($tmpproject); } + $possiblelinks = array( 'propal'=>array('enabled'=>$conf->propal->enabled, 'perms'=>1, 'label'=>'LinkToProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".$this->db->prefix()."societe as s, ".$this->db->prefix()."propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$this->db->sanitize($listofidcompanytoscan).') AND t.entity IN ('.getEntity('propal').')'), 'order'=>array('enabled'=>$conf->commande->enabled, 'perms'=>1, 'label'=>'LinkToOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".$this->db->prefix()."societe as s, ".$this->db->prefix()."commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$this->db->sanitize($listofidcompanytoscan).') AND t.entity IN ('.getEntity('commande').')'), @@ -8574,6 +8571,7 @@ class Form $sql = $possiblelink['sql']; $resqllist = $this->db->query($sql); + if ($resqllist) { $num = $this->db->num_rows($resqllist); $i = 0; diff --git a/htdocs/langs/fr_FR/mrp.lang b/htdocs/langs/fr_FR/mrp.lang index 1820abd2ccd..a337cb68d9d 100644 --- a/htdocs/langs/fr_FR/mrp.lang +++ b/htdocs/langs/fr_FR/mrp.lang @@ -107,3 +107,4 @@ THMEstimatedHelp=Ce taux permet de définir un coût prévisionnel de l'article BOM=Nomenclature CollapseBOMHelp=You can define the default display of the details of the nomenclature in the configuration of the BOM module MOAndLines=Ordres de fabrication et lignes +MOParent=Ordre de fabrication parent diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index c02a19d9d66..f35e8589431 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -1427,6 +1427,79 @@ 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; + } + } } /** @@ -1667,92 +1740,4 @@ 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).' '.$langs->trans("ManufacturingOrder").''; - if (isset($moparent->status)) { - $label .= ' '.$moparent->getLibStatut(5); - } - $label .= '
'; - $label .= ''.$langs->trans('Ref').': '.$moparent->ref; - if (isset($moparent->label)) { - $label .= '
'.$langs->trans('Label').': '.$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 = ''; - $linkend = ''; - - $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; - } } diff --git a/htdocs/mrp/mo_card.php b/htdocs/mrp/mo_card.php index d405e7fe341..cabc3163ca7 100644 --- a/htdocs/mrp/mo_card.php +++ b/htdocs/mrp/mo_card.php @@ -131,13 +131,12 @@ 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'; @@ -163,6 +162,7 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; + $res = $object->add_object_linked('mo', $mo_parent->id); } $noback = 0; @@ -174,8 +174,6 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; - - // Actions when linking object each other include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; @@ -463,6 +461,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($ref == 'PROV') { $object->fetch_product(); $numref = $object->getNextNumRef($object->fk_product); + } else { $numref = $object->ref; } @@ -567,6 +566,15 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print '
'; print ''."\n"; + //Mo Parent + $mo_parent = $object->getMoParent(); + if(is_object($mo_parent)) { + print ''; + print ''; + print ''; + print ''; + } + // Common attributes $keyforbreak = 'fk_warehouse'; unset($object->fields['fk_project']); @@ -765,7 +773,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print $formfile->showdocuments('mrp:mo', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $mysoc->default_lang); // Show links to link elements - $linktoelem = $form->showLinkToObjectBlock($object, null, array('mo')); + $linktoelem = $form->showLinkToObjectBlock($object,'', array('mo')); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); diff --git a/htdocs/mrp/tpl/linkedobjectblock.tpl.php b/htdocs/mrp/tpl/linkedobjectblock.tpl.php index 5dbe583fd21..494f22e4e8f 100644 --- a/htdocs/mrp/tpl/linkedobjectblock.tpl.php +++ b/htdocs/mrp/tpl/linkedobjectblock.tpl.php @@ -29,23 +29,27 @@ print "\n"; global $user, $db; global $noMoreLinkedObjectBlockAfter; +//var_dump($object); exit; $langs = $GLOBALS['langs']; $linkedObjectBlock = $GLOBALS['linkedObjectBlock']; +$object = $GLOBALS['object']; // Load translation files required by the page $langs->load("bom"); -$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date', 'desc', 0, 0, 1); - $total = 0; $ilink = 0; -foreach ($linkedObjectBlock as $key => $objectlink) { + +$mo_static = new Mo($db); +$res = $mo_static->fetch($object->id); +$TMoChilds = $mo_static->getMoChilds(); + +foreach ($TMoChilds as $key => $objectlink) { + $ilink++; - $product_static = new Product($db); + $trclass = 'oddeven'; - if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) { - $trclass .= ' liste_sub_total'; - } + echo ''; echo ''; echo ''; echo ''; - echo ''; + echo ''; echo ''; echo ''; echo "\n"; }
' . $langs->trans('MOParent') . '' .$mo_parent->getNomUrl(1).'
'.$langs->trans("ManufacturingOrder"); if (!empty($showImportButton) && $conf->global->MAIN_ENABLE_IMPORT_LINKED_OBJECT_LINES) { @@ -55,26 +59,14 @@ foreach ($linkedObjectBlock as $key => $objectlink) { echo ''.$objectlink->getNomUrl(1).''; - $result = $product_static->fetch($objectlink->fk_product); - if ($result < 0) { - setEventMessage($product_static->error, 'errors'); - } elseif ($result > 0) { - $product_static->getNomUrl(1); - } +// $result = $product_static->fetch($objectlink->fk_product); print ''.dol_print_date($objectlink->date_creation, 'day').''; - if ($user->rights->commande->lire) { - $total = $total + $objectlink->total_ht; - echo price($objectlink->total_ht); - } - echo '-'.$objectlink->getLibStatut(3).''; // For now, shipments must stay linked to order, so link is not deletable - if ($object->element != 'shipping') { - echo ''.img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink').''; - } + echo ''.img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink').''; echo '