Clean Code
This commit is contained in:
parent
503e2310ea
commit
16415a1c92
@ -17,8 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file htdocs/public/ticket/ajax/ajax.php
|
* \file htdocs/bom/ajax/ajax.php
|
||||||
* \brief Ajax component for Ticket.
|
* \brief Ajax component for BOM.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('NOTOKENRENEWAL')) {
|
if (!defined('NOTOKENRENEWAL')) {
|
||||||
|
|||||||
@ -546,16 +546,16 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
* Lines
|
* Lines
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
if (!empty($object->table_element_line)) {
|
if (!empty($object->table_element_line)) {
|
||||||
|
|
||||||
print load_fiche_titre($langs->trans('BOMProductsList'), '', 'product');
|
//Products
|
||||||
|
$res = $object->fetchLinesbytypeproduct(0);
|
||||||
$res = $object->fetchLinesbytype(0);
|
|
||||||
$object->calculateCosts();
|
$object->calculateCosts();
|
||||||
|
|
||||||
if($res > 0) {
|
if($res > 0) {
|
||||||
|
|
||||||
|
print load_fiche_titre($langs->trans('BOMProductsList'), '', 'product');
|
||||||
|
|
||||||
print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '' : '') . '" method="POST">
|
print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '' : '') . '" method="POST">
|
||||||
<input type="hidden" name="token" value="' . newToken() . '">
|
<input type="hidden" name="token" value="' . newToken() . '">
|
||||||
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
|
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
|
||||||
@ -602,9 +602,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Services
|
||||||
$filtertype = 1;
|
$filtertype = 1;
|
||||||
|
$res = $object->fetchLinesbytypeproduct(1);
|
||||||
$res = $object->fetchLinesbytype(1);
|
|
||||||
$object->calculateCosts();
|
$object->calculateCosts();
|
||||||
|
|
||||||
if($res > 0) {
|
if($res > 0) {
|
||||||
|
|||||||
@ -401,11 +401,13 @@ class BOM extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load object lines in memory from the database
|
* Load object lines in memory from the database by type of product
|
||||||
*
|
*
|
||||||
|
* @param int $typeproduct 0 type product, 1 type service
|
||||||
|
|
||||||
* @return int <0 if KO, 0 if not found, >0 if OK
|
* @return int <0 if KO, 0 if not found, >0 if OK
|
||||||
*/
|
*/
|
||||||
public function fetchLinesbytype($type = 0)
|
public function fetchLinesbytypeproduct($typeproduct = 0)
|
||||||
{
|
{
|
||||||
$this->lines = array();
|
$this->lines = array();
|
||||||
|
|
||||||
@ -421,7 +423,7 @@ class BOM extends CommonObject
|
|||||||
$sql .= " FROM ".$this->db->prefix().$objectline->table_element." as l";
|
$sql .= " FROM ".$this->db->prefix().$objectline->table_element." as l";
|
||||||
$sql .= " LEFT JOIN ".$this->db->prefix()."product as p ON p.rowid = l.fk_product";
|
$sql .= " LEFT JOIN ".$this->db->prefix()."product as p ON p.rowid = l.fk_product";
|
||||||
$sql .= " WHERE l.fk_".$this->db->escape($this->element)." = ".((int) $this->id);
|
$sql .= " WHERE l.fk_".$this->db->escape($this->element)." = ".((int) $this->id);
|
||||||
$sql .= " AND p.fk_product_type = ". $type;
|
$sql .= " AND p.fk_product_type = ". $typeproduct;
|
||||||
if (isset($objectline->fields['position'])) {
|
if (isset($objectline->fields['position'])) {
|
||||||
$sql .= $this->db->order('position', 'ASC');
|
$sql .= $this->db->order('position', 'ASC');
|
||||||
}
|
}
|
||||||
@ -1141,6 +1143,7 @@ class BOM extends CommonObject
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
//Convert qty to hour
|
||||||
if($line->duration_unit == 's') $qty = $line->qty / 3600;
|
if($line->duration_unit == 's') $qty = $line->qty / 3600;
|
||||||
if($line->duration_unit == 'i') $qty = $line->qty / 60;
|
if($line->duration_unit == 'i') $qty = $line->qty / 60;
|
||||||
if($line->duration_unit == 'd') $qty = $line->qty * 24;
|
if($line->duration_unit == 'd') $qty = $line->qty * 24;
|
||||||
@ -1151,9 +1154,13 @@ class BOM extends CommonObject
|
|||||||
if($conf->workstation->enabled){
|
if($conf->workstation->enabled){
|
||||||
if($tmpproduct->fk_default_workstation) {
|
if($tmpproduct->fk_default_workstation) {
|
||||||
$workstation = new Workstation($this->db);
|
$workstation = new Workstation($this->db);
|
||||||
$workstation->fetch($tmpproduct->fk_default_workstation);
|
$res = $workstation->fetch($tmpproduct->fk_default_workstation);
|
||||||
|
|
||||||
$line->total_cost = price2num($qty * $workstation->thm_operator_estimated, 'MT');
|
if($res > 0) $line->total_cost = price2num($qty * $workstation->thm_operator_estimated, 'MT');
|
||||||
|
else {
|
||||||
|
$this->error = $workstation->error;
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$line->total_cost = price2num($qty * $tmpproduct->cost_price, 'MT');
|
$line->total_cost = price2num($qty * $tmpproduct->cost_price, 'MT');
|
||||||
|
|||||||
@ -163,7 +163,7 @@ if($filtertype != 1) {
|
|||||||
} else {
|
} else {
|
||||||
$coldisplay++;
|
$coldisplay++;
|
||||||
print '<td class="bordertop nobottom nowrap linecolunit right">';
|
print '<td class="bordertop nobottom nowrap linecolunit right">';
|
||||||
print $formproduct->selectMeasuringUnits("duration_unit", "time", (GETPOSTISSET('duration_value') ? GETPOST('duration_value', 'alpha') : 'h'), 0, 1);
|
print $formproduct->selectMeasuringUnits("duration_unit", "time", 'h', 0, 1);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
$coldisplay++;
|
$coldisplay++;
|
||||||
@ -196,8 +196,6 @@ jQuery(document).ready(function() {
|
|||||||
/* When changing predefined product, we reload list of supplier prices required for margin combo */
|
/* When changing predefined product, we reload list of supplier prices required for margin combo */
|
||||||
$("#idprod").change(function()
|
$("#idprod").change(function()
|
||||||
{
|
{
|
||||||
console.log("#idprod change triggered");
|
|
||||||
|
|
||||||
/* To set focus */
|
/* To set focus */
|
||||||
if (jQuery('#idprod').val() > 0)
|
if (jQuery('#idprod').val() > 0)
|
||||||
{
|
{
|
||||||
@ -212,11 +210,11 @@ jQuery(document).ready(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//change unit selected if we change service selected
|
||||||
<?php if($filtertype == 1) { ?>
|
<?php if($filtertype == 1) { ?>
|
||||||
$('#idprod:nth-child(2)').change(function(){
|
$('#idprod:nth-child(2)').change(function(){
|
||||||
var idproduct = $(this).val();
|
var idproduct = $(this).val();
|
||||||
|
|
||||||
console.log(idproduct);
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : "<?php echo dol_buildpath('/bom/ajax/ajax.php',1); ?>"
|
url : "<?php echo dol_buildpath('/bom/ajax/ajax.php',1); ?>"
|
||||||
,type: 'POST'
|
,type: 'POST'
|
||||||
|
|||||||
@ -129,32 +129,29 @@ if($filtertype != 1) {
|
|||||||
echo $line->efficiency;
|
echo $line->efficiency;
|
||||||
print '</td>';
|
print '</td>';
|
||||||
} else {
|
} else {
|
||||||
$product = new Product($object->db);
|
|
||||||
$res = $product->fetch($line->fk_product);
|
|
||||||
|
|
||||||
//Unité
|
//Unité
|
||||||
print '<td class="linecolunit nowrap right">';
|
print '<td class="linecolunit nowrap right">';
|
||||||
$coldisplay++;
|
$coldisplay++;
|
||||||
if ($line->qty > 1) {
|
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"));
|
$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 ($product->duration_value > 0) {
|
} 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"));
|
$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)){
|
if(!empty($line->duration_unit)){
|
||||||
print (isset($dur[$line->duration_unit]) ? " ".$langs->trans($dur[$line->duration_unit])." " : '');
|
print (isset($dur[$line->duration_unit]) ? " ".$langs->trans($dur[$line->duration_unit])." " : '');
|
||||||
} else {
|
} else {
|
||||||
print (!empty($product->duration_unit) && isset($dur[$product->duration_unit]) ? " " . $langs->trans($dur[$product->duration_unit]) . " " : '');
|
print (!empty($tmpproduct->duration_unit) && isset($dur[$tmpproduct->duration_unit]) ? " " . $langs->trans($dur[$tmpproduct->duration_unit]) . " " : '');
|
||||||
}
|
}
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
//Poste de travail
|
//Poste de travail
|
||||||
if($conf->workstation->enabled) {
|
if($conf->workstation->enabled) {
|
||||||
$workstation = new Workstation($object->db);
|
$workstation = new Workstation($object->db);
|
||||||
$workstation->fetch($product->fk_default_workstation);
|
$res = $workstation->fetch($tmpproduct->fk_default_workstation);
|
||||||
|
|
||||||
print '<td class="linecolunit nowrap right">';
|
print '<td class="linecolunit nowrap right">';
|
||||||
$coldisplay++;
|
$coldisplay++;
|
||||||
echo $workstation->getNomUrl();
|
if($res > 0) echo $workstation->getNomUrl();
|
||||||
print '</td>';
|
print '</td>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2496,7 +2496,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
|
|||||||
|
|
||||||
if($object->isService() && $conf->workstation->enabled) {
|
if($object->isService() && $conf->workstation->enabled) {
|
||||||
$workstation = new Workstation($db);
|
$workstation = new Workstation($db);
|
||||||
$workstation->fetch($object->fk_default_workstation);
|
$res = $workstation->fetch($object->fk_default_workstation);
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans("DefaultWorkstation").'</td><td>';
|
print '<tr><td>'.$langs->trans("DefaultWorkstation").'</td><td>';
|
||||||
print (!empty($workstation->id) ? $workstation->getNomUrl(1) : '');
|
print (!empty($workstation->id) ? $workstation->getNomUrl(1) : '');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user