mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-08 18:48:22 +01:00
Change fk_unit service lines management
This commit is contained in:
@@ -53,6 +53,7 @@ if (!defined('NOBROWSERNOTIF')) {
|
||||
|
||||
include_once '../../main.inc.php'; // Load $user and permissions
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
|
||||
|
||||
|
||||
$action = GETPOST('action', 'aZ09');
|
||||
@@ -69,10 +70,9 @@ if ($action == 'getDurationUnitByProduct') {
|
||||
$product = new Product($db);
|
||||
$res = $product->fetch($idproduct);
|
||||
|
||||
if ($res > 0) {
|
||||
$return = $product->duration_unit;
|
||||
}
|
||||
$cUnit = new CUnits($db);
|
||||
$fk_unit = $cUnit->getUnitFromCode($product->duration_unit, 'short_label','time');
|
||||
|
||||
echo json_encode($return);
|
||||
echo json_encode($fk_unit);
|
||||
exit();
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ if (empty($reshook)) {
|
||||
$qty_frozen = price2num(GETPOST('qty_frozen', 'alpha'), 'MS');
|
||||
$disable_stock_change = GETPOST('disable_stock_change', 'int');
|
||||
$efficiency = price2num(GETPOST('efficiency', 'alpha'));
|
||||
$duration_unit = GETPOST('duration_unit', 'alphanohtml');
|
||||
$fk_unit = GETPOST('fk_unit', 'alphanohtml');
|
||||
if ($qty == '') {
|
||||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
|
||||
$error++;
|
||||
@@ -191,7 +191,7 @@ if (empty($reshook)) {
|
||||
$bomline->qty_frozen = (int) $qty_frozen;
|
||||
$bomline->disable_stock_change = (int) $disable_stock_change;
|
||||
$bomline->efficiency = $efficiency;
|
||||
$bomline->duration_unit = $duration_unit;
|
||||
$bomline->fk_unit = $fk_unit;
|
||||
|
||||
// Rang to use
|
||||
$rangmax = $object->line_max(0);
|
||||
@@ -227,7 +227,7 @@ if (empty($reshook)) {
|
||||
$qty_frozen = price2num(GETPOST('qty_frozen', 'alpha'), 'MS');
|
||||
$disable_stock_change = GETPOST('disable_stock_change', 'int');
|
||||
$efficiency = price2num(GETPOST('efficiency', 'alpha'));
|
||||
$duration_unit = GETPOST('duration_unit', 'alphanohtml');
|
||||
$fk_unit = GETPOST('fk_unit', 'alphanohtml');
|
||||
|
||||
if ($qty == '') {
|
||||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
|
||||
@@ -240,7 +240,9 @@ if (empty($reshook)) {
|
||||
$bomline->qty_frozen = (int) $qty_frozen;
|
||||
$bomline->disable_stock_change = (int) $disable_stock_change;
|
||||
$bomline->efficiency = $efficiency;
|
||||
$bomline->duration_unit = $duration_unit;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
|
||||
$bomline->fk_unit = $fk_unit;
|
||||
|
||||
$result = $bomline->update($user);
|
||||
if ($result <= 0) {
|
||||
|
||||
@@ -1128,7 +1128,8 @@ class BOM extends CommonObject
|
||||
}
|
||||
} else {
|
||||
//Convert qty to hour
|
||||
$qty = convertDurationtoHour($line->qty, $line->duration_unit);
|
||||
$unit = measuringUnitString($line->fk_unit);
|
||||
$qty = convertDurationtoHour($line->qty, $unit);
|
||||
|
||||
if ($conf->workstation->enabled) {
|
||||
if ($tmpproduct->fk_default_workstation) {
|
||||
@@ -1293,7 +1294,7 @@ class BOMLine extends CommonObjectLine
|
||||
'qty_frozen' => array('type'=>'smallint', 'label'=>'QuantityFrozen', 'enabled'=>1, 'visible'=>1, 'default'=>0, 'position'=>105, 'css'=>'maxwidth50imp', 'help'=>'QuantityConsumedInvariable'),
|
||||
'disable_stock_change' => array('type'=>'smallint', 'label'=>'DisableStockChange', 'enabled'=>1, 'visible'=>1, 'default'=>0, 'position'=>108, 'css'=>'maxwidth50imp', 'help'=>'DisableStockChangeHelp'),
|
||||
'efficiency' => array('type'=>'double(24,8)', 'label'=>'ManufacturingEfficiency', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'position'=>110, 'notnull'=>1, 'css'=>'maxwidth50imp', 'help'=>'ValueOfEfficiencyConsumedMeans'),
|
||||
'duration_unit' => array('type'=>'varchar(6)', 'label'=>'Unit', 'enabled'=>1, 'visible'=>1, 'position'=>120, 'notnull'=>-1,),
|
||||
'fk_unit' => array('type'=>'integer', 'label'=>'Unit', 'enabled'=>1, 'visible'=>1, 'position'=>120, 'notnull'=>-1,),
|
||||
'position' => array('type'=>'integer', 'label'=>'Rank', 'enabled'=>1, 'visible'=>0, 'default'=>0, 'position'=>200, 'notnull'=>1,),
|
||||
'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000, 'notnull'=>-1,),
|
||||
);
|
||||
|
||||
@@ -160,8 +160,11 @@ if ($filtertype != 1) {
|
||||
print '</td>';
|
||||
} else {
|
||||
$coldisplay++;
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
|
||||
$cUnit = new CUnits($this->db);
|
||||
$fk_unit_default = $cUnit->getUnitFromCode('h', 'short_label','time');
|
||||
print '<td class="bordertop nobottom nowrap linecolunit right">';
|
||||
print $formproduct->selectMeasuringUnits("duration_unit", "time", 'h', 0, 1);
|
||||
print $formproduct->selectMeasuringUnits("fk_unit", "time", $fk_unit_default, 0, 0);
|
||||
print '</td>';
|
||||
|
||||
$coldisplay++;
|
||||
@@ -213,6 +216,7 @@ jQuery(document).ready(function() {
|
||||
<?php if ($filtertype == 1) { ?>
|
||||
$('#idprodservice').change(function(){
|
||||
var idproduct = $(this).val();
|
||||
|
||||
$.ajax({
|
||||
url : "<?php echo dol_buildpath('/bom/ajax/ajax.php', 1); ?>"
|
||||
,type: 'POST'
|
||||
@@ -221,8 +225,10 @@ jQuery(document).ready(function() {
|
||||
,'idproduct' : idproduct
|
||||
}
|
||||
}).done(function(data) {
|
||||
|
||||
console.log(data);
|
||||
var data = JSON.parse(data);
|
||||
$('#duration_unit').val(data).change();;
|
||||
$("#fk_unit").val(data).change();
|
||||
});
|
||||
});
|
||||
<?php } ?>
|
||||
|
||||
@@ -141,7 +141,7 @@ if ($filtertype != 1) {
|
||||
|
||||
$coldisplay++;
|
||||
print '<td class="nobottom nowrap linecolunit right">';
|
||||
print $formproduct->selectMeasuringUnits("duration_unit", "time", ($line->duration_unit) ? $line->duration_unit : '', 0, 1);
|
||||
print $formproduct->selectMeasuringUnits("fk_unit", "time", ($line->fk_unit) ? $line->fk_unit : '', 0, 0);
|
||||
print '</td>';
|
||||
|
||||
$coldisplay++;
|
||||
|
||||
@@ -132,16 +132,14 @@ if ($filtertype != 1) {
|
||||
//Unité
|
||||
print '<td class="linecolunit nowrap right">';
|
||||
$coldisplay++;
|
||||
if ($line->qty > 1) {
|
||||
$dur = array("s"=>$langs->trans("Seconds"), "i"=>$langs->trans("Minutes"), "h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years"));
|
||||
} elseif ($tmpproduct->duration_value > 0) {
|
||||
$dur = array("s"=>$langs->trans("Second"), "i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year"));
|
||||
}
|
||||
if (!empty($line->duration_unit)) {
|
||||
print (isset($dur[$line->duration_unit]) ? " ".$langs->trans($dur[$line->duration_unit])." " : '');
|
||||
} else {
|
||||
print (!empty($tmpproduct->duration_unit) && isset($dur[$tmpproduct->duration_unit]) ? " " . $langs->trans($dur[$tmpproduct->duration_unit]) . " " : '');
|
||||
|
||||
if (!empty($line->fk_unit)) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
|
||||
$unit = new CUnits($this->db);
|
||||
$unit->fetch($line->fk_unit);
|
||||
print (isset($unit->label) ? " ".$langs->trans(ucwords($unit->label))." " : '');
|
||||
}
|
||||
|
||||
print '</td>';
|
||||
|
||||
//Poste de travail
|
||||
|
||||
@@ -420,15 +420,16 @@ class CUnits // extends CommonObject
|
||||
* Get unit from code
|
||||
* @param string $code code of unit
|
||||
* @param string $mode 0= id , short_label=Use short label as value, code=use code
|
||||
* @param string $unit_type weight,size,surface,volume,qty,time...
|
||||
* @return int <0 if KO, Id of code if OK
|
||||
*/
|
||||
public function getUnitFromCode($code, $mode = 'code')
|
||||
public function getUnitFromCode($code, $mode = 'code', $unit_type='')
|
||||
{
|
||||
|
||||
if ($mode == 'short_label') {
|
||||
return dol_getIdFromCode($this->db, $code, 'c_units', 'short_label', 'rowid');
|
||||
return dol_getIdFromCode($this->db, $code, 'c_units', 'short_label', 'rowid',0, ' AND unit_type = "'.$unit_type.'"');
|
||||
} elseif ($mode == 'code') {
|
||||
return dol_getIdFromCode($this->db, $code, 'c_units', 'code', 'rowid');
|
||||
return dol_getIdFromCode($this->db, $code, 'c_units', 'code', 'rowid',0, ' AND unit_type = "'. $unit_type .'"');
|
||||
}
|
||||
|
||||
return $code;
|
||||
|
||||
@@ -8504,10 +8504,11 @@ function dol_osencode($str)
|
||||
* @param string $fieldkey Field to search the key into
|
||||
* @param string $fieldid Field to get
|
||||
* @param int $entityfilter Filter by entity
|
||||
* @param string $filters Filter on other fields
|
||||
* @return int <0 if KO, Id of code if OK
|
||||
* @see $langs->getLabelFromKey
|
||||
*/
|
||||
function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid = 'id', $entityfilter = 0)
|
||||
function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid = 'id', $entityfilter = 0, $filters = array())
|
||||
{
|
||||
global $cache_codes;
|
||||
|
||||
@@ -8529,6 +8530,9 @@ function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid =
|
||||
if (!empty($entityfilter)) {
|
||||
$sql .= " AND entity IN (".getEntity($tablename).")";
|
||||
}
|
||||
if ($filters) {
|
||||
$sql .= $filters;
|
||||
}
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
|
||||
@@ -57,4 +57,4 @@ ALTER TABLE llx_facture_fourn ADD COLUMN close_missing_amount double(24, 8) afte
|
||||
ALTER TABLE llx_adherent_type ADD COLUMN caneditamount integer DEFAULT 0 AFTER amount;
|
||||
|
||||
ALTER TABLE llx_product ADD COLUMN fk_default_workstation integer DEFAULT NULL;
|
||||
ALTER TABLE llx_bom_bomline ADD COLUMN duration_unit varchar(6) DEFAULT NULL;
|
||||
ALTER TABLE llx_bom_bomline ADD COLUMN fk_unit integer DEFAULT NULL;
|
||||
|
||||
@@ -25,7 +25,7 @@ CREATE TABLE llx_bom_bomline(
|
||||
qty_frozen smallint DEFAULT 0,
|
||||
disable_stock_change smallint DEFAULT 0,
|
||||
efficiency double(24,8) NOT NULL DEFAULT 1,
|
||||
duration_unit varchar(6) NULL,
|
||||
fk_unit integer NULL,
|
||||
position integer NOT NULL DEFAULT 0
|
||||
-- END MODULEBUILDER FIELDS
|
||||
) ENGINE=innodb;
|
||||
|
||||
Reference in New Issue
Block a user