Merge pull request #20098 from atm-lena/NEW_OF_Child

Create MO Child
This commit is contained in:
Laurent Destailleur
2022-05-24 22:00:19 +02:00
committed by GitHub
10 changed files with 377 additions and 90 deletions

View File

@@ -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 '</div>';
print "</form>\n";
?>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
// When clicking on collapse
$(".collapse_bom").click(function() {
console.log("We click on collapse");
var id_bom_line = $(this).attr('id').replace('collapse-', '');
console.log($(this).html().indexOf('folder-open'));
if($(this).html().indexOf('folder-open') <= 0) {
$('[parentid="'+ id_bom_line +'"]').show();
$(this).html('<?php echo dol_escape_js(img_picto('', 'folder-open')); ?>');
}
else {
$('[parentid="'+ id_bom_line +'"]').hide();
$(this).html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
}
return false;
});
// To Show all the sub bom lines
$("#show_all").click(function() {
console.log("We click on show all");
$("[class^=sub_bom_lines]").show();
$("[class^=collapse_bom]").html('<?php echo dol_escape_js(img_picto('', 'folder-open')); ?>');
return false;
});
// To Hide all the sub bom lines
$("#hide_all").click(function() {
console.log("We click on hide all");
$("[class^=sub_bom_lines]").hide();
$("[class^=collapse_bom]").html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
return false;
});
});
</script>
<?php
print mrpCollapseBomManagement();
}

View File

@@ -136,3 +136,55 @@ function bomPrepareHead($object)
return $head;
}
/**
* Manage collapse bom display
*
* @return void
*/
function mrpCollapseBomManagement()
{
?>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
// When clicking on collapse
$(".collapse_bom").click(function() {
console.log("We click on collapse");
var id_bom_line = $(this).attr('id').replace('collapse-', '');
console.log($(this).html().indexOf('folder-open'));
if($(this).html().indexOf('folder-open') <= 0) {
$('[parentid="'+ id_bom_line +'"]').show();
$(this).html('<?php echo dol_escape_js(img_picto('', 'folder-open')); ?>');
}
else {
$('[parentid="'+ id_bom_line +'"]').hide();
$(this).html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
}
return false;
});
// To Show all the sub bom lines
$("#show_all").click(function() {
console.log("We click on show all");
$("[class^=sub_bom_lines]").show();
$("[class^=collapse_bom]").html('<?php echo dol_escape_js(img_picto('', 'folder-open')); ?>');
return false;
});
// To Hide all the sub bom lines
$("#hide_all").click(function() {
console.log("We click on hide all");
$("[class^=sub_bom_lines]").hide();
$("[class^=collapse_bom]").html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
return false;
});
});
</script>
<?php
}

View File

@@ -28,6 +28,7 @@
// $permissiontodelete must be defined
// $backurlforlist must be defined
// $backtopage may be defined
// $noback may be defined
// $triggermodname may be defined
if (!empty($permissionedit) && empty($permissiontoadd)) {
@@ -137,8 +138,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
@@ -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');

View File

@@ -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 '<!-- showLinkedObjectBlock -->';
print load_fiche_titre($langs->trans('RelatedObjects'), $morehtmlright, '', 0, 0, 'showlinkedobjectblock');
print load_fiche_titre($langs->trans($title), $morehtmlright, '', 0, 0, 'showlinkedobjectblock');
print '<div class="div-table-responsive-no-min">';
@@ -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)) {

View File

@@ -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
MoChildGenerate=Generate Child Mo
ParentMo=MO Parent
MOChild=MO Child

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,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").'<br>' : '');
print '<tr class="liste_titre">';
// Product or sub-bom
print '<td class="linecoldescription">'.$langs->trans('Description');
if (!empty($conf->global->BOM_SUB_BOM)) {
print ' &nbsp; <a id="show_all" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a>&nbsp;&nbsp;';
print '<a id="hide_all" href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a>&nbsp;';
}
print '</td>';
print '<td>'.$langs->trans('Ref').'</td>';
print '<td class="right">'.$langs->trans('Qty');
if ($this->bom->bomtype == 0) {
@@ -1392,9 +1408,9 @@ class Mo extends CommonObject
print '<td class="center">'.$form->textwithpicto($langs->trans("VirtualStock"), $langs->trans("VirtualStockDesc")).'</td>';
print '<td class="center">'.$langs->trans('QtyFrozen').'</td>';
print '<td class="center">'.$langs->trans('DisableStockChange').'</td>';
//print '<td class="right">'.$langs->trans('Efficiency').'</td>';
print '<td class="center">'.$langs->trans('MoChildGenerate').'</td>';
//print '<td class="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
print '<td class="center"></td>';
// print '<td class="center"></td>';
print '</tr>';
$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);

View File

@@ -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();
?>
<script>
$(document).ready(function () {
jQuery('#fk_bom').change(function() {
jQuery('#fk_bom').change(function() {
console.log('We change value of BOM with BOM of id '+jQuery('#fk_bom').val());
if (jQuery('#fk_bom').val() > 0)
{
@@ -486,6 +523,15 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">'."\n";
//Mo Parent
$mo_parent = $object->getMoParent();
if (is_object($mo_parent)) {
print '<tr class="field_fk_mo_parent">';
print '<td class="titlefield fieldname_fk_mo_parent">' . $langs->trans('ParentMo') . '</td>';
print '<td class="valuefield fieldname_fk_mo_parent">' .$mo_parent->getNomUrl(1).'</td>';
print '</tr>';
}
// Common attributes
$keyforbreak = 'fk_warehouse';
unset($object->fields['fk_project']);
@@ -685,7 +731,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// Show links to link elements
$linktoelem = $form->showLinkToObjectBlock($object, null, array('mo'));
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, false, 'MOChild');
print '</div><div class="fichehalfright">';

View File

@@ -118,6 +118,17 @@ foreach ($object->fields as $key => $val) {
'help'=> isset($val['help']) ? $val['help'] : ''
);
}
if ($key == 'fk_parent_line') {
$visible = (int) dol_eval($val['visible'], 1);
$arrayfields['t.'.$key] = array(
'label'=>$val['label'],
'checked'=>(($visible < 0) ? 0 : 1),
'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1)),
'position'=>$val['position'],
'help'=> isset($val['help']) ? $val['help'] : ''
);
}
}
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
@@ -219,6 +230,8 @@ $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
if (isset($extrafields->attributes[$object->table_element]['label']) && 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)";
}
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."mrp_production lineparent ON t.fk_parent_line = lineparent.rowid";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."mrp_mo moparent ON lineparent.fk_mo = moparent.rowid";
// Add table from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
@@ -228,11 +241,16 @@ if ($object->ismultientitymanaged == 1) {
} else {
$sql .= " WHERE 1 = 1";
}
foreach ($search as $key => $val) {
if (array_key_exists($key, $object->fields)) {
if ($key == 'status' && $search[$key] == -1) {
continue;
}
if ($key == 'fk_parent_line') {
$sql .= natural_search('moparent.ref', $search[$key], 0);
continue;
}
$mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
@@ -439,6 +457,8 @@ foreach ($object->fields as $key => $val) {
$cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
if ($key == 'status') {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif ($key == 'fk_parent_line') {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif (in_array($val['type'], array('timestamp'))) {
@@ -448,6 +468,11 @@ foreach ($object->fields as $key => $val) {
}
if (!empty($arrayfields['t.'.$key]['checked'])) {
print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
if ($key == 'fk_parent_line') {
print '<input type="text" class="flat maxwidth75" name="search_fk_parent_line">';
print '</td>';
continue;
}
if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
} elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
@@ -487,6 +512,8 @@ foreach ($object->fields as $key => $val) {
$cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
if ($key == 'status') {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif ($key == 'fk_parent_line') {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif (in_array($val['type'], array('timestamp'))) {
@@ -543,6 +570,9 @@ while ($i < ($limit ? min($num, $limit) : $num)) {
} elseif ($key == 'status') {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
}
elseif ($key == 'fk_parent_line') {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
}
if (in_array($val['type'], array('timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
@@ -558,6 +588,9 @@ while ($i < ($limit ? min($num, $limit) : $num)) {
print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
if ($key == 'status') {
print $object->getLibStatut(5);
} elseif ($key == 'fk_parent_line') {
$moparent = $object->getMoParent();
if (is_object($moparent)) print $moparent->getNomUrl(1);
} elseif ($key == 'rowid') {
print $object->showOutputField($val, $key, $object->id, '');
} else {

View File

@@ -31,21 +31,23 @@ global $noMoreLinkedObjectBlockAfter;
$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 '<tr class="'.$trclass.'" >';
echo '<td class="linkedcol-element" >'.$langs->trans("ManufacturingOrder");
if (!empty($showImportButton) && $conf->global->MAIN_ENABLE_IMPORT_LINKED_OBJECT_LINES) {
@@ -55,26 +57,14 @@ foreach ($linkedObjectBlock as $key => $objectlink) {
echo '<td class="linkedcol-name nowraponall" >'.$objectlink->getNomUrl(1).'</td>';
echo '<td class="linkedcol-ref" align="center">';
$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 '</td>';
echo '<td class="linkedcol-date" align="center">'.dol_print_date($objectlink->date_creation, 'day').'</td>';
echo '<td class="linkedcol-amount right">';
if ($user->rights->commande->lire) {
$total = $total + $objectlink->total_ht;
echo price($objectlink->total_ht);
}
echo '</td>';
echo '<td class="linkedcol-amount right">-</td>';
echo '<td class="linkedcol-statut right">'.$objectlink->getLibStatut(3).'</td>';
echo '<td class="linkedcol-action right">';
// For now, shipments must stay linked to order, so link is not deletable
if ($object->element != 'shipping') {
echo '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=dellink&token='.newToken().'&dellinkid='.$key.'">'.img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink').'</a>';
}
echo '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=dellink&token='.newToken().'&dellinkid='.$key.'">'.img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink').'</a>';
echo '</td>';
echo "</tr>\n";
}

View File

@@ -22,6 +22,8 @@ if (empty($conf) || !is_object($conf)) {
exit;
}
global $db;
if (!is_object($form)) {
$form = new Form($db);
}
@@ -32,12 +34,31 @@ $qtytoconsumeforline = $this->tpl['qty'] / ( ! empty($this->tpl['efficiency']) ?
}*/
$qtytoconsumeforline = price2num($qtytoconsumeforline, 'MS');
$tmpproduct = new Product($db);
$tmpproduct->fetch($line->fk_product);
$tmpbom = new BOM($db);
$res = $tmpbom->fetch($line->fk_bom_child);
?>
<!-- BEGIN PHP TEMPLATE originproductline.tpl.php -->
<?php
print '<tr class="oddeven'.(empty($this->tpl['strike']) ? '' : ' strikefordisabled').'">';
print '<td>'.$this->tpl['label'].'</td>';
print '<td>';
if ($res) {
print $tmpproduct->getNomUrl(1);
if ($tmpbom->id) {
print ' ' . $langs->trans("or") . ' ';
print $tmpbom->getNomUrl(1);
print ' <a class="collapse_bom" id="collapse-' . $line->id . '" href="#">';
print (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT) ? img_picto('', 'folder') : img_picto('', 'folder-open'));
}
print '</a>';
} else {
print $this->tpl['label'];
}
print '</td>';
//print '<td>'.$this->tpl['label'].'</td>';
print '<td class="right">'.$this->tpl['qty'].(($this->tpl['efficiency'] > 0 && $this->tpl['efficiency'] < 1) ? ' / '.$form->textwithpicto($this->tpl['efficiency'], $langs->trans("ValueOfMeansLoss")).' = '.$qtytoconsumeforline : '').'</td>';
print '<td class="center">'.(empty($this->tpl['stock']) ? 0 : price2num($this->tpl['stock'], 'MS'));
if ($this->tpl['seuil_stock_alerte'] != '' && ($this->tpl['stock'] < $this->tpl['seuil_stock_alerte'])) {
@@ -60,6 +81,92 @@ if (!empty($selectedLines) && !in_array($this->tpl['id'], $selectedLines)) {
print '<td class="center">';
//print '<input id="cb'.$this->tpl['id'].'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$this->tpl['id'].'"'.($selected?' checked="checked"':'').'>';
print '</td>';
if ($tmpbom->id) {
print '<td class="center">';
print '<input type="checkbox" name="bomlineid[]" value="' . $line->id . '">';
print '</td>';
} else {
print '<td class="center">&nbsp;</td>';
}
print '</tr>'."\n";
// Select of all the sub-BOM lines
$sql = 'SELECT rowid, fk_bom_child, fk_product, qty FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl';
$sql.= ' WHERE fk_bom ='. (int) $tmpbom->id;
$resql = $db->query($sql);
if ($resql) {
// Loop on all the sub-BOM lines if they exist
while ($obj = $db->fetch_object($resql)) {
$sub_bom_product = new Product($db);
$sub_bom_product->fetch($obj->fk_product);
$sub_bom_product->load_stock();
$sub_bom = new BOM($db);
$sub_bom->fetch($obj->fk_bom_child);
$sub_bom_line = new BOMLine($db);
$sub_bom_line->fetch($obj->rowid);
//If hidden conf is set, we show directly all the sub-BOM lines
if (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT)) {
print '<tr style="display:none" class="sub_bom_lines" parentid="'.$line->id.'">';
} else {
print '<tr class="sub_bom_lines" parentid="'.$line->id.'">';
}
// Product OR BOM
print '<td style="padding-left: 5%" id="sub_bom_product_'.$sub_bom_line->id.'">';
if (!empty($obj->fk_bom_child)) {
print $sub_bom_product->getNomUrl(1);
print ' '.$langs->trans('or').' ';
print $sub_bom->getNomUrl(1);
} else {
print $sub_bom_product->getNomUrl(1);
print '</td>';
}
// Qty
if ($sub_bom_line->qty_frozen > 0) {
print '<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.'">'.price($sub_bom_line->qty, 0, '', 0, 0).'</td>';
} else {
print '<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.'">'.price($sub_bom_line->qty * $line->qty, 0, '', 0, 0).'</td>';
}
// Stock réel
if ($sub_bom_product->stock_reel > 0) {
print '<td class="linecolstockreel nowrap center" id="sub_bom_stock_reel_'.$sub_bom_product->stock_reel.'">'.$sub_bom_product->stock_reel.'</td>';
} else {
print '<td class="linecolstockreel nowrap center" id="sub_bom_stock_reel_'.$sub_bom_product->stock_reel.'">&nbsp;</td>';
}
// Stock virtuel
if ($sub_bom_product->stock_theorique > 0) {
print '<td class="linecolstocktheorique nowrap center" id="sub_bom_stock_theorique_'.$sub_bom_product->stock_theorique.'">'.$sub_bom_product->stock_theorique.'</td>';
} else {
print '<td class="linecolstocktheorique nowrap center" id="sub_bom_stock_theorique_'.$sub_bom_product->stock_theorique.'">&nbsp;</td>';
}
// Frozen qty
if ($sub_bom_line->qty_frozen > 0) {
print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->qty_frozen.'">'.$langs->trans('Yes').'</td>';
} else {
print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->qty_frozen.'">&nbsp;</td>';
}
// Disable stock change
if ($sub_bom_line->disable_stock_change > 0) {
print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">'.yn($sub_bom_line->disable_stock_change).'</td>';
} else {
print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">&nbsp;</td>';
}
print '<td></td>';
print '<td></td>';
}
}
?>
<!-- END PHP TEMPLATE originproductline.tpl.php -->