2019-05-22 20:28:24 +02:00
< ? php
/* Copyright ( C ) 2010 - 2013 Regis Houssin < regis . houssin @ inodbox . com >
* Copyright ( C ) 2010 - 2011 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2012 - 2013 Christophe Battarel < christophe . battarel @ altairis . fr >
* Copyright ( C ) 2012 Cédric Salvador < csalvador @ gpcsolutions . fr >
* Copyright ( C ) 2012 - 2014 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
* Copyright ( C ) 2017 Juanjo Menent < jmenent @ 2 byte . es >
2025-02-08 18:30:42 +01:00
* Copyright ( C ) 2024 - 2025 MDW < mdeweerd @ users . noreply . github . com >
2024-11-04 23:53:20 +01:00
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2019-05-22 20:28:24 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2019-05-22 20:28:24 +02:00
*
2024-06-30 21:02:50 +02:00
* Need to have the following variables defined :
2019-05-22 20:28:24 +02:00
* $object ( invoice , order , ... )
* $conf
* $langs
* $forceall ( 0 by default , 1 for supplier invoices / orders )
2024-02-09 15:58:49 +01:00
* $element ( used to test $user -> hasRight ( $element , 'creer' ))
* $permtoedit ( used to replace test $user -> hasRight ( $element , 'creer' ))
2019-05-22 20:28:24 +02:00
* $inputalsopricewithtax ( 0 by default , 1 to also show column with unit price including tax )
* $disableedit , $disablemove , $disableremove
*
* $type , $text , $description , $line
*/
2024-03-23 01:11:37 +01:00
/**
2024-11-04 23:53:20 +01:00
* @ var Conf $conf
2024-12-05 18:00:38 +01:00
* @ var CommonObject $this
* @ var CommonObject $object
2024-03-23 01:11:37 +01:00
* @ var CommonObjectLine $line
2024-11-04 23:53:20 +01:00
* @ var Translate $langs
* @ var User $user
*
* @ var int $i
2024-03-23 01:11:37 +01:00
* @ var int $num
2024-12-14 13:05:41 +01:00
* @ var string $action
2024-03-23 01:11:37 +01:00
*/
2024-09-18 03:27:25 +02:00
'
@ phan - var - force CommonObjectLine $line
@ phan - var - force int $num
@ phan - var - force int $i
@ phan - var - force CommonObject $this
@ phan - var - force CommonObject $object
' ;
2023-05-01 17:21:00 +02:00
2022-07-06 13:55:43 +02:00
require_once DOL_DOCUMENT_ROOT . '/workstation/class/workstation.class.php' ;
2019-05-22 20:28:24 +02:00
// Protection to avoid direct call of template
2021-02-23 17:51:46 +01:00
if ( empty ( $object ) || ! is_object ( $object )) {
2019-05-22 20:28:24 +02:00
print " Error, template page can't be called as URL " ;
2024-03-16 23:08:15 +01:00
exit ( 1 );
2019-05-22 20:28:24 +02:00
}
2024-02-21 18:14:29 +01:00
2022-07-06 13:55:43 +02:00
global $filtertype ;
2023-12-04 12:01:45 +01:00
if ( empty ( $filtertype )) {
$filtertype = 0 ;
}
2022-07-06 13:55:43 +02:00
2019-05-22 20:28:24 +02:00
2022-01-25 16:40:28 +01:00
global $forceall , $senderissupplier , $inputalsopricewithtax , $outputalsopricetotalwithtax , $langs ;
2019-05-22 20:28:24 +02:00
2021-02-23 17:51:46 +01:00
if ( empty ( $dateSelector )) {
$dateSelector = 0 ;
}
if ( empty ( $forceall )) {
$forceall = 0 ;
}
if ( empty ( $senderissupplier )) {
$senderissupplier = 0 ;
}
if ( empty ( $inputalsopricewithtax )) {
$inputalsopricewithtax = 0 ;
}
if ( empty ( $outputalsopricetotalwithtax )) {
$outputalsopricetotalwithtax = 0 ;
}
2019-05-22 20:28:24 +02:00
// add html5 elements
2023-12-04 12:01:45 +01:00
if ( $filtertype == 1 ) {
$domData = ' data-element="' . $line -> element . 'service"' ;
} else {
$domData = ' data-element="' . $line -> element . '"' ;
}
2022-09-08 11:40:40 +02:00
2019-05-22 20:28:24 +02:00
$domData .= ' data-id="' . $line -> id . '"' ;
$domData .= ' data-qty="' . $line -> qty . '"' ;
$domData .= ' data-product_type="' . $line -> product_type . '"' ;
2019-06-03 19:29:49 +02:00
// Lines for extrafield
2019-06-03 22:07:34 +02:00
$objectline = new BOMLine ( $object -> db );
2019-05-22 20:28:24 +02:00
2019-11-13 19:34:37 +01:00
$coldisplay = 0 ;
2024-07-17 16:23:24 +02:00
print " <!-- BEGIN PHP TEMPLATE bom/tpl/objectline_view.tpl.php --> \n " ;
2019-10-20 11:17:54 +02:00
print '<tr id="row-' . $line -> id . '" class="drag drop oddeven" ' . $domData . ' >' ;
2023-04-27 14:02:59 +02:00
// Line nb
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_VIEW_LINE_NUMBER' )) {
2019-11-13 19:34:37 +01:00
print '<td class="linecolnum center">' . ( $i + 1 ) . '</td>' ;
2019-10-20 11:17:54 +02:00
$coldisplay ++ ;
}
2023-04-27 14:02:59 +02:00
// Product
2024-07-17 16:23:24 +02:00
print '<td class="linecoldescription bomline minwidth300imp tdoverflowmax300">' ;
2019-10-20 11:17:54 +02:00
print '<div id="line_' . $line -> id . '"></div>' ;
$coldisplay ++ ;
$tmpproduct = new Product ( $object -> db );
$tmpproduct -> fetch ( $line -> fk_product );
2021-08-20 13:37:28 +02:00
$tmpbom = new BOM ( $object -> db );
2021-08-23 14:43:17 +02:00
$res = $tmpbom -> fetch ( $line -> fk_bom_child );
2021-10-28 15:05:50 +02:00
if ( $tmpbom -> id > 0 ) {
2022-01-25 16:40:28 +01:00
print $tmpproduct -> getNomUrl ( 1 );
2022-01-29 00:07:04 +01:00
print ' ' . $langs -> trans ( " or " ) . ' ' ;
2022-01-26 15:15:53 +01:00
print $tmpbom -> getNomUrl ( 1 );
2022-01-29 00:07:04 +01:00
print ' <a class="collapse_bom" id="collapse-' . $line -> id . '" href="#">' ;
2023-12-04 12:01:45 +01:00
print ( ! getDolGlobalString ( 'BOM_SHOW_ALL_BOM_BY_DEFAULT' ) ? img_picto ( '' , 'folder' ) : img_picto ( '' , 'folder-open' ));
2022-01-29 00:07:04 +01:00
print '</a>' ;
2021-08-20 13:37:28 +02:00
} else {
2021-10-28 15:05:50 +02:00
print $tmpproduct -> getNomUrl ( 1 );
print ' - ' . $tmpproduct -> label ;
2021-08-20 13:37:28 +02:00
}
2022-12-05 12:30:26 +01:00
// Line extrafield
if ( ! empty ( $extrafields )) {
$temps = $line -> showOptionals ( $extrafields , 'view' , array (), '' , '' , 1 , 'line' );
if ( ! empty ( $temps )) {
print '<div style="padding-top: 10px" id="extrafield_lines_area_' . $line -> id . '" name="extrafield_lines_area_' . $line -> id . '">' ;
print $temps ;
print '</div>' ;
}
}
2021-10-28 15:05:50 +02:00
print '</td>' ;
2021-08-20 13:37:28 +02:00
2023-04-27 14:02:59 +02:00
// Qty
2019-10-20 11:17:54 +02:00
print '<td class="linecolqty nowrap right">' ;
$coldisplay ++ ;
2024-01-12 20:58:09 +01:00
echo price ( $line -> qty , 0 , '' , 0 , 0 ); // Yes, it is a quantity, not a price, but we just want the formatting role of function price
2019-10-20 11:17:54 +02:00
print '</td>' ;
2019-05-22 20:28:24 +02:00
2024-07-17 16:05:06 +02:00
if ( $filtertype != 1 ) { // Product
2024-06-23 22:10:12 +02:00
if ( getDolGlobalInt ( 'PRODUCT_USE_UNITS' )) { // For product, unit is shown only if option PRODUCT_USE_UNITS is on
print '<td class="linecoluseunit nowrap">' ;
2025-02-08 18:30:42 +01:00
$label = measuringUnitString (( int ) $line -> fk_unit , '' , null , 1 );
2022-07-06 13:55:43 +02:00
if ( $label !== '' ) {
print $langs -> trans ( $label );
}
print '</td>' ;
2019-05-22 20:28:24 +02:00
}
2024-07-17 16:05:06 +02:00
} else { // Service
2024-06-23 22:10:12 +02:00
// Unit // For services, units are always enabled
print '<td class="linecolunit nowrap">' ;
2022-07-06 13:55:43 +02:00
$coldisplay ++ ;
2022-07-20 15:38:37 +02:00
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 );
2023-12-04 12:01:45 +01:00
print ( isset ( $unit -> label ) ? " " . $langs -> trans ( ucwords ( $unit -> label )) . " " : '' );
2022-07-06 15:00:07 +02:00
}
2022-07-20 15:38:37 +02:00
2022-07-06 13:55:43 +02:00
print '</td>' ;
2024-07-17 16:05:06 +02:00
}
if ( $filtertype != 1 || getDolGlobalString ( 'STOCK_SUPPORTS_SERVICES' )) { // Product or stock support for Services is active
2024-06-19 20:48:43 +02:00
// Qty frozen
print '<td class="linecolqtyfrozen nowrap right">' ;
$coldisplay ++ ;
echo $line -> qty_frozen ? yn ( $line -> qty_frozen ) : '' ;
print '</td>' ;
2024-07-17 16:05:06 +02:00
// Disable stock change
print '<td class="linecoldisablestockchange nowrap right">' ;
$coldisplay ++ ;
echo $line -> disable_stock_change ? yn ( $line -> disable_stock_change ) : '' ; // Yes, it is a quantity, not a price, but we just want the formatting role of function price
print '</td>' ;
2019-05-22 20:28:24 +02:00
2024-07-17 16:05:06 +02:00
// Efficiency
print '<td class="linecolefficiency nowrap right">' ;
$coldisplay ++ ;
echo $line -> efficiency ;
print '</td>' ;
}
// Service and workstations are active
if ( $filtertype == 1 && isModEnabled ( 'workstation' )) {
$workstation = new Workstation ( $object -> db );
$res = $workstation -> fetch ( $line -> fk_default_workstation );
print '<td class="linecolworkstation nowrap">' ;
$coldisplay ++ ;
if ( $res > 0 ) {
2024-09-29 22:49:02 +02:00
$unit = new CUnits ( $object -> db );
$fk_defaultUnit = $unit -> getUnitFromCode ( 'h' , 'short_label' , 'time' );
$nbPlannedHour = $unit -> unitConverter ( $line -> qty , $line -> fk_unit , $fk_defaultUnit );
$line -> total_cost = 0 ;
if ( $workstation -> thm_machine_estimated ) {
$line -> total_cost += $nbPlannedHour * $workstation -> thm_machine_estimated ;
2023-12-04 12:01:45 +01:00
}
2024-09-29 22:49:02 +02:00
if ( $workstation -> thm_operator_estimated ) {
$line -> total_cost += $nbPlannedHour * $workstation -> thm_operator_estimated ;
}
2024-07-17 16:05:06 +02:00
echo $workstation -> getNomUrl ( 1 );
2022-07-06 13:55:43 +02:00
}
2024-07-17 16:05:06 +02:00
print '</td>' ;
2022-07-06 13:55:43 +02:00
}
2023-04-27 14:02:59 +02:00
// Cost
2021-08-25 11:21:54 +02:00
$total_cost = 0 ;
2024-09-28 12:22:30 +02:00
2023-01-17 17:22:32 +01:00
$tmpbom -> calculateCosts ();
2021-08-25 11:21:54 +02:00
print '<td id="costline_' . $line -> id . '" class="linecolcost nowrap right">' ;
2020-03-24 10:32:31 +01:00
$coldisplay ++ ;
2023-01-17 20:23:01 +01:00
if ( ! empty ( $line -> fk_bom_child )) {
2024-03-28 01:48:30 +01:00
echo '<span class="amount">' . price ( $tmpbom -> total_cost * ( float ) $line -> qty ) . '</span>' ;
2023-01-17 17:22:32 +01:00
} else {
echo '<span class="amount">' . price ( $line -> total_cost ) . '</span>' ;
}
2020-03-24 10:32:31 +01:00
print '</td>' ;
2024-08-27 06:20:04 +02:00
if ( $this -> status == 0 && $user -> hasRight ( 'bom' , 'write' ) && $action != 'selectlines' ) {
2019-10-21 15:02:06 +02:00
print '<td class="linecoledit center">' ;
$coldisplay ++ ;
2020-10-07 15:01:28 +02:00
if (( $line -> info_bits & 2 ) == 2 || ! empty ( $disableedit )) {
} else {
2021-09-27 12:24:01 +02:00
print '<a class="editfielda reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $this -> id . '&action=editline&token=' . newToken () . '&lineid=' . $line -> id . '">' . img_edit () . '</a>' ;
2020-10-07 15:01:28 +02:00
}
print '</td>' ;
print '<td class="linecoldelete center">' ;
$coldisplay ++ ;
if (( $line -> fk_prev_id == null ) && empty ( $disableremove )) {
//La suppression n'est autorisée que si il n'y a pas de ligne dans une précédente situation
2021-09-18 22:04:41 +02:00
print '<a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $this -> id . '&action=deleteline&token=' . newToken () . '&lineid=' . $line -> id . '">' ;
2020-10-07 15:01:28 +02:00
print img_delete ();
print '</a>' ;
}
print '</td>' ;
2019-05-22 20:28:24 +02:00
2019-10-20 11:17:54 +02:00
if ( $num > 1 && $conf -> browser -> layout != 'phone' && empty ( $disablemove )) {
print '<td class="linecolmove tdlineupdown center">' ;
$coldisplay ++ ;
if ( $i > 0 ) {
2022-03-24 14:04:03 +01:00
print '<a class="lineupdown" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $this -> id . '&action=up&token=' . newToken () . '&rowid=' . $line -> id . '">' ;
2019-10-20 11:17:54 +02:00
echo img_up ( 'default' , 0 , 'imgupforline' );
print '</a>' ;
}
2019-11-13 19:34:37 +01:00
if ( $i < $num - 1 ) {
2022-03-24 14:04:03 +01:00
print '<a class="lineupdown" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $this -> id . '&action=down&token=' . newToken () . '&rowid=' . $line -> id . '">' ;
2019-10-20 11:17:54 +02:00
echo img_down ( 'default' , 0 , 'imgdownforline' );
print '</a>' ;
}
print '</td>' ;
} else {
2019-11-13 19:34:37 +01:00
print '<td ' . (( $conf -> browser -> layout != 'phone' && empty ( $disablemove )) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"' ) . '></td>' ;
2019-10-20 11:17:54 +02:00
$coldisplay ++ ;
}
} else {
2020-10-07 15:01:28 +02:00
print '<td colspan="3"></td>' ;
2024-08-07 02:53:45 +02:00
$coldisplay += 3 ;
2019-10-20 11:17:54 +02:00
}
if ( $action == 'selectlines' ) {
2020-10-07 15:01:28 +02:00
print '<td class="linecolcheck center">' ;
print '<input type="checkbox" class="linecheckbox" name="line_checkbox[' . ( $i + 1 ) . ']" value="' . $line -> id . '" >' ;
print '</td>' ;
2019-10-20 11:17:54 +02:00
}
print '</tr>' ;
2019-05-22 20:28:24 +02:00
2021-08-25 16:58:22 +02:00
// Select of all the sub-BOM lines
2024-01-12 20:58:09 +01:00
// From this point to the end of the file, we only take care of sub-BOM lines
2022-01-25 16:40:28 +01:00
$sql = 'SELECT rowid, fk_bom_child, fk_product, qty FROM ' . MAIN_DB_PREFIX . 'bom_bomline AS bl' ;
2024-03-23 01:11:37 +01:00
$sql .= ' WHERE fk_bom =' . ( int ) $tmpbom -> id ;
2021-08-20 13:37:28 +02:00
$resql = $object -> db -> query ( $sql );
2021-08-25 17:24:03 +02:00
if ( $resql ) {
2021-08-25 16:58:22 +02:00
// Loop on all the sub-BOM lines if they exist
2021-08-25 17:24:03 +02:00
while ( $obj = $object -> db -> fetch_object ( $resql )) {
2021-08-20 13:37:28 +02:00
$sub_bom_product = new Product ( $object -> db );
$sub_bom_product -> fetch ( $obj -> fk_product );
$sub_bom = new BOM ( $object -> db );
2022-02-17 10:53:02 +01:00
if ( ! empty ( $obj -> fk_bom_child )) {
2022-02-15 10:29:42 +01:00
$sub_bom -> fetch ( $obj -> fk_bom_child );
2022-02-17 10:53:02 +01:00
}
2021-08-20 13:37:28 +02:00
$sub_bom_line = new BOMLine ( $object -> db );
$sub_bom_line -> fetch ( $obj -> rowid );
2021-08-25 16:58:22 +02:00
//If hidden conf is set, we show directly all the sub-BOM lines
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( 'BOM_SHOW_ALL_BOM_BY_DEFAULT' )) {
2021-08-23 14:43:17 +02:00
print '<tr style="display:none" class="sub_bom_lines" parentid="' . $line -> id . '">' ;
} else {
print '<tr class="sub_bom_lines" parentid="' . $line -> id . '">' ;
}
2021-08-20 13:37:28 +02:00
2022-01-25 16:40:28 +01:00
// Product OR BOM
print '<td style="padding-left: 5%" id="sub_bom_product_' . $sub_bom_line -> id . '">' ;
2022-01-26 15:15:53 +01:00
if ( ! empty ( $obj -> fk_bom_child )) {
2022-01-25 16:40:28 +01:00
print $sub_bom_product -> getNomUrl ( 1 );
2022-01-26 14:46:45 +01:00
print ' ' . $langs -> trans ( 'or' ) . ' ' ;
2022-01-25 16:40:28 +01:00
print $sub_bom -> getNomUrl ( 1 );
2022-01-26 15:15:53 +01:00
} else {
2022-01-25 16:40:28 +01:00
print $sub_bom_product -> getNomUrl ( 1 );
2022-01-26 15:15:53 +01:00
print '</td>' ;
}
2021-08-25 16:58:22 +02:00
// Qty
2022-12-12 11:41:54 +01:00
$label = $sub_bom_product -> getLabelOfUnit ( 'long' );
2021-08-20 13:37:28 +02:00
if ( $sub_bom_line -> qty_frozen > 0 ) {
2022-01-25 16:40:28 +01:00
print '<td class="linecolqty nowrap right" id="sub_bom_qty_' . $sub_bom_line -> id . '">' . price ( $sub_bom_line -> qty , 0 , '' , 0 , 0 ) . '</td>' ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'PRODUCT_USE_UNITS' )) {
2023-01-26 15:56:04 +01:00
print '<td class="linecoluseunit nowrap left">' ;
2023-12-04 12:01:45 +01:00
if ( $label !== '' ) {
print $langs -> trans ( $label );
}
2023-01-26 15:56:04 +01:00
print '</td>' ;
}
2022-01-25 16:40:28 +01:00
print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_' . $sub_bom_line -> id . '">' . $langs -> trans ( 'Yes' ) . '</td>' ;
2021-08-20 13:37:28 +02:00
} else {
2024-03-28 01:48:30 +01:00
print '<td class="linecolqty nowrap right" id="sub_bom_qty_' . $sub_bom_line -> id . '">' . price ( $sub_bom_line -> qty * ( float ) $line -> qty , 0 , '' , 0 , 0 ) . '</td>' ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'PRODUCT_USE_UNITS' )) {
2023-01-26 15:56:04 +01:00
print '<td class="linecoluseunit nowrap left">' ;
2023-12-04 12:01:45 +01:00
if ( $label !== '' ) {
print $langs -> trans ( $label );
}
2023-01-26 15:56:04 +01:00
print '</td>' ;
}
2021-08-20 13:37:28 +02:00
print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_' . $sub_bom_line -> id . '"> </td>' ;
}
2021-08-25 16:58:22 +02:00
// Disable stock change
2021-08-20 13:37:28 +02:00
if ( $sub_bom_line -> disable_stock_change > 0 ) {
print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_' . $sub_bom_line -> id . '">' . $sub_bom_line -> disable_stock_change . '</td>' ;
} else {
print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_' . $sub_bom_line -> id . '"> </td>' ;
}
2021-08-25 16:58:22 +02:00
// Efficiency
2021-08-20 13:37:28 +02:00
print '<td class="linecolefficiency nowrap right" id="sub_bom_efficiency_' . $sub_bom_line -> id . '">' . $sub_bom_line -> efficiency . '</td>' ;
2021-08-25 16:58:22 +02:00
2022-03-24 14:04:03 +01:00
// Cost
2022-02-17 10:53:02 +01:00
if ( ! empty ( $sub_bom -> id )) {
$sub_bom -> calculateCosts ();
2024-03-28 01:48:30 +01:00
print '<td class="linecolcost nowrap right" id="sub_bom_cost_' . $sub_bom_line -> id . '"><span class="amount">' . price ( price2num ( $sub_bom -> total_cost * $sub_bom_line -> qty * ( float ) $line -> qty , 'MT' )) . '</span></td>' ;
$total_cost += $sub_bom -> total_cost * $sub_bom_line -> qty * ( float ) $line -> qty ;
2023-02-10 14:47:46 +01:00
} elseif ( $sub_bom_product -> type == Product :: TYPE_SERVICE && isModEnabled ( 'workstation' ) && ! empty ( $sub_bom_product -> fk_default_workstation )) {
2023-02-02 17:58:54 +01:00
//Convert qty to hour
2025-02-08 18:30:42 +01:00
$unit = measuringUnitString ( $sub_bom_line -> fk_unit , '' , null , 1 );
2023-02-02 17:58:54 +01:00
$qty = convertDurationtoHour ( $sub_bom_line -> qty , $unit );
$workstation = new Workstation ( $this -> db );
$res = $workstation -> fetch ( $sub_bom_product -> fk_default_workstation );
2023-12-04 12:01:45 +01:00
if ( $res > 0 ) {
2024-02-09 15:58:49 +01:00
$sub_bom_line -> total_cost = ( float ) price2num ( $qty * ( $workstation -> thm_operator_estimated + $workstation -> thm_machine_estimated ), 'MT' );
2023-12-04 12:01:45 +01:00
}
2023-02-02 17:58:54 +01:00
print '<td class="linecolcost nowrap right" id="sub_bom_cost_' . $sub_bom_line -> id . '"><span class="amount">' . price ( price2num ( $sub_bom_line -> total_cost , 'MT' )) . '</span></td>' ;
$this -> total_cost += $line -> total_cost ;
2022-02-17 10:53:02 +01:00
} elseif ( $sub_bom_product -> cost_price > 0 ) {
2023-04-27 14:02:59 +02:00
print '<td class="linecolcost nowrap right" id="sub_bom_cost_' . $sub_bom_line -> id . '">' ;
2024-03-28 01:48:30 +01:00
print '<span class="amount">' . price ( price2num ( $sub_bom_product -> cost_price * $sub_bom_line -> qty * ( float ) $line -> qty , 'MT' )) . '</span></td>' ;
$total_cost += $sub_bom_product -> cost_price * $sub_bom_line -> qty * ( float ) $line -> qty ;
2021-08-26 09:43:50 +02:00
} elseif ( $sub_bom_product -> pmp > 0 ) { // PMP if cost price isn't defined
2023-04-27 14:02:59 +02:00
print '<td class="linecolcost nowrap right" id="sub_bom_cost_' . $sub_bom_line -> id . '">' ;
2024-03-28 01:48:30 +01:00
print '<span class="amount">' . price ( price2num ( $sub_bom_product -> pmp * $sub_bom_line -> qty * ( float ) $line -> qty , 'MT' )) . '</span></td>' ;
$total_cost .= $sub_bom_product -> pmp * $sub_bom_line -> qty * ( float ) $line -> qty ;
2021-08-26 09:43:50 +02:00
} else { // Minimum purchase price if cost price and PMP aren't defined
2024-04-03 03:27:28 +02:00
$sql_supplier_price = " SELECT MIN(price) AS min_price, quantity AS qty FROM " . MAIN_DB_PREFIX . " product_fournisseur_price " ;
$sql_supplier_price .= " WHERE fk_product = " . ( int ) $sub_bom_product -> id ;
$sql_supplier_price .= " GROUP BY quantity ORDER BY quantity ASC " ;
2021-08-25 11:21:54 +02:00
$resql_supplier_price = $object -> db -> query ( $sql_supplier_price );
if ( $resql_supplier_price ) {
2024-04-03 03:27:28 +02:00
$obj = $object -> db -> fetch_object ( $resql_supplier_price ); // Take first value so the ref with the smaller minimum quantity
2023-07-29 15:48:16 +02:00
if ( ! empty ( $obj -> qty ) && ! empty ( $sub_bom_line -> qty ) && ! empty ( $line -> qty )) {
2024-03-28 01:48:30 +01:00
$line_cost = $obj -> min_price / $obj -> qty * $sub_bom_line -> qty * ( float ) $line -> qty ;
2023-07-28 14:41:01 +02:00
} else {
$line_cost = $obj -> min_price ;
}
2022-12-09 17:00:11 +01:00
print '<td class="linecolcost nowrap right" id="sub_bom_cost_' . $sub_bom_line -> id . '"><span class="amount">' . price2num ( $line_cost , 'MT' ) . '</span></td>' ;
2024-03-23 01:11:37 +01:00
$total_cost += $line_cost ;
2021-08-25 11:21:54 +02:00
}
}
2021-08-20 13:37:28 +02:00
print '<td></td>' ;
print '<td></td>' ;
print '<td></td>' ;
}
}
2021-08-25 11:21:54 +02:00
2019-10-20 11:17:54 +02:00
print " <!-- END PHP TEMPLATE objectline_view.tpl.php --> \n " ;