forked from Wavyzz/dolibarr
NEW : Select for BOM workable + JS to fill it according to the product selected
This commit is contained in:
@@ -570,6 +570,31 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
|
||||
print '</table>';
|
||||
}
|
||||
?>
|
||||
<script>
|
||||
let select_product_val;
|
||||
let current_bom_id = <?php echo $object->id?>;
|
||||
$('#idprod').on('change', function () {
|
||||
select_product_val = $('#idprod').select2().val();
|
||||
$.ajax({
|
||||
url: 'script/interface.php'
|
||||
, method: 'POST'
|
||||
, dataType: 'text'
|
||||
, data: {
|
||||
action: 'select_BOM'
|
||||
, select_product_val: ""+select_product_val
|
||||
, current_bom_id: current_bom_id
|
||||
}
|
||||
}).done(function (data) {
|
||||
let options = JSON.parse(data)
|
||||
for (let key in options) {
|
||||
let opt = new Option(options[key], key);
|
||||
$('#bom_select').append(opt)
|
||||
}
|
||||
})
|
||||
})
|
||||
</script>
|
||||
<?php
|
||||
print '</div>';
|
||||
|
||||
print "</form>\n";
|
||||
|
||||
29
htdocs/bom/script/interface.php
Normal file
29
htdocs/bom/script/interface.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
require '../../main.inc.php';
|
||||
|
||||
$action = GETPOST('action', 'alphanohtml');
|
||||
$select_product_val = GETPOST('select_product_val', 'alphanohtml');
|
||||
$current_bom_id = GETPOST('current_bom_id', 'alphanohtml');
|
||||
|
||||
global $db;
|
||||
|
||||
switch ($action){
|
||||
case 'select_BOM':
|
||||
//Selection of nomenclatures corresponding to the selected product
|
||||
$sql = 'SELECT b.rowid, b.ref, b.label, b.fk_product, p.label AS product_label FROM '.MAIN_DB_PREFIX.'bom_bom AS b ';
|
||||
$sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'product AS p ON b.fk_product=p.rowid';
|
||||
$sql.= ' WHERE fk_product='.$select_product_val.' AND b.rowid!='.$current_bom_id;
|
||||
$resql = $db->query($sql);
|
||||
if ($resql && $db->num_rows($resql) > 0) {
|
||||
$options = array();
|
||||
$cpt=0;
|
||||
while ($obj = $db->fetch_object($resql)){
|
||||
|
||||
$options[$obj->rowid] = $obj->ref.' - '.$obj->label;
|
||||
$cpt++;
|
||||
}
|
||||
print json_encode($options);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -107,6 +107,10 @@ if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
|
||||
|
||||
echo '</span>';
|
||||
}
|
||||
$coldisplay++;
|
||||
print '<td class="bordertop nobottom linecolbom">';
|
||||
print '<select id="bom_select" name="bom_select"><options value="-1"></options></select>';
|
||||
print '</td>';
|
||||
|
||||
$coldisplay++;
|
||||
print '<td class="bordertop nobottom linecolqty right"><input type="text" size="2" name="qty" id="qty" class="flat right" value="'.(GETPOSTISSET("qty") ? GETPOST("qty", 'alpha', 2) : 1).'">';
|
||||
|
||||
@@ -52,6 +52,9 @@ if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
|
||||
// Description
|
||||
print '<td class="linecoldescription">'.$langs->trans('Description').'</td>';
|
||||
|
||||
// Linked BOM
|
||||
print '<td class="linecolBOM">'.$langs->trans('BOM').'</td>';
|
||||
|
||||
// Qty
|
||||
print '<td class="linecolqty right">'.$form->textwithpicto($langs->trans('Qty'), $langs->trans("QtyRequiredIfNoLoss")).'</td>';
|
||||
|
||||
|
||||
@@ -83,6 +83,8 @@ $tmpproduct->fetch($line->fk_product);
|
||||
print $tmpproduct->getNomUrl(1);
|
||||
print ' - '.$tmpproduct->label;
|
||||
print '</td>';
|
||||
|
||||
print '<td id="bom_id"></td>';
|
||||
print '<td class="linecolqty nowrap right">';
|
||||
$coldisplay++;
|
||||
echo price($line->qty, 0, '', 0, 0); // Yes, it is a quantity, not a price, but we just want the formating role of function price
|
||||
|
||||
@@ -101,3 +101,4 @@ HumanMachine=Human / Machine
|
||||
WorkstationArea=Workstation area
|
||||
Machines=Machines
|
||||
THMEstimatedHelp=This rate makes it possible to define a forecast cost of the item
|
||||
BOM=Nomenclature
|
||||
|
||||
@@ -101,3 +101,4 @@ HumanMachine=Humain/machine
|
||||
WorkstationArea=Espace Poste de travail
|
||||
Machines=Machines
|
||||
THMEstimatedHelp=Ce taux permet de définir un coût prévisionnel de l'article
|
||||
BOM=Nomenclature
|
||||
|
||||
Reference in New Issue
Block a user