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 >
*
* 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
*
* Need to have following variables defined :
* $object ( invoice , order , ... )
* $conf
* $langs
* $forceall ( 0 by default , 1 for supplier invoices / orders )
* $element ( used to test $user -> rights -> $element -> creer )
* $permtoedit ( used to replace test $user -> rights -> $element -> creer )
* $inputalsopricewithtax ( 0 by default , 1 to also show column with unit price including tax )
* $object_rights -> creer initialized from = $object -> getRights ()
* $disableedit , $disablemove , $disableremove
*
* $type , $text , $description , $line
*/
// 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 " ;
exit ;
}
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
$domData = ' data-element="' . $line -> element . '"' ;
$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 ;
2019-10-20 11:17:54 +02:00
print " <!-- BEGIN PHP TEMPLATE objectline_view.tpl.php --> \n " ;
print '<tr id="row-' . $line -> id . '" class="drag drop oddeven" ' . $domData . ' >' ;
2019-11-13 19:34:37 +01:00
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) {
print '<td class="linecolnum center">' . ( $i + 1 ) . '</td>' ;
2019-10-20 11:17:54 +02:00
$coldisplay ++ ;
}
print '<td class="linecoldescription minwidth300imp">' ;
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="#">' ;
print ( empty ( $conf -> global -> BOM_SHOW_ALL_BOM_BY_DEFAULT ) ? img_picto ( '' , 'folder' ) : img_picto ( '' , 'folder-open' ));
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
}
2021-10-28 15:05:50 +02:00
print '</td>' ;
2021-08-20 13:37:28 +02:00
2019-10-20 11:17:54 +02:00
print '<td class="linecolqty nowrap right">' ;
$coldisplay ++ ;
2019-11-13 19:34:37 +01:00
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
2019-10-20 11:17:54 +02:00
print '</td>' ;
2019-05-22 20:28:24 +02:00
2021-02-23 17:51:46 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
2019-10-20 11:17:54 +02:00
print '<td class="linecoluseunit nowrap left">' ;
2020-10-12 12:23:47 +02:00
$label = $tmpproduct -> getLabelOfUnit ( 'long' );
2019-10-20 11:17:54 +02:00
if ( $label !== '' ) {
print $langs -> trans ( $label );
2019-05-22 20:28:24 +02:00
}
2019-10-20 11:17:54 +02:00
print '</td>' ;
}
2019-10-27 01:49:31 +02:00
print '<td class="linecolqtyfrozen nowrap right">' ;
$coldisplay ++ ;
echo $line -> qty_frozen ? yn ( $line -> qty_frozen ) : '' ;
print '</td>' ;
print '<td class="linecoldisablestockchange nowrap right">' ;
$coldisplay ++ ;
2020-04-10 10:59:32 +02:00
echo $line -> disable_stock_change ? yn ( $line -> disable_stock_change ) : '' ; // Yes, it is a quantity, not a price, but we just want the formating role of function price
2019-10-27 01:49:31 +02:00
print '</td>' ;
2020-02-28 16:12:42 +01:00
print '<td class="linecolefficiency nowrap right">' ;
$coldisplay ++ ;
echo $line -> efficiency ;
print '</td>' ;
2019-05-22 20:28:24 +02:00
2021-08-25 11:21:54 +02:00
$total_cost = 0 ;
print '<td id="costline_' . $line -> id . '" class="linecolcost nowrap right">' ;
2020-03-24 10:32:31 +01:00
$coldisplay ++ ;
2022-03-24 14:04:03 +01:00
echo '<span class="amount">' . price ( $line -> total_cost ) . '</span>' ;
2020-03-24 10:32:31 +01:00
print '</td>' ;
2020-04-10 10:59:32 +02:00
if ( $this -> status == 0 && ( $object_rights -> 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>' ;
$coldisplay = $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
2022-02-15 10:29:42 +01:00
// From this pont 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' ;
2021-10-19 17:25:51 +02: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
2021-08-25 17:24:03 +02:00
if ( empty ( $conf -> global -> 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>' ;
2022-12-15 15:00:27 +01:00
print '<td class="linecoluseunit nowrap left">' ;
if ( $label !== '' ) print $langs -> trans ( $label );
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 {
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 * $line -> qty , 0 , '' , 0 , 0 ) . '</td>' ;
2022-12-12 11:41:54 +01:00
print '<td class="linecoluseunit nowrap left">' ;
2022-12-19 10:41:39 +01:00
if ( $label !== '' ) print $langs -> trans ( $label );
2022-12-15 15:00:27 +01:00
print '</td>' ;
2022-12-12 11:41:54 +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 ();
2023-01-02 09:48:34 +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 * $line -> qty , 'MT' )) . '</span></td>' ;
2022-02-15 10:29:42 +01:00
$total_cost += $sub_bom -> total_cost * $sub_bom_line -> qty * $line -> qty ;
2022-02-17 10:53:02 +01:00
} elseif ( $sub_bom_product -> cost_price > 0 ) {
2023-01-02 09:48:34 +01:00
print '<td class="linecolcost nowrap right" id="sub_bom_cost_' . $sub_bom_line -> id . '"><span class="amount">' . price ( price2num ( $sub_bom_product -> cost_price * $sub_bom_line -> qty * $line -> qty , 'MT' )) . '</span></td>' ;
2022-02-15 10:29:42 +01:00
$total_cost += $sub_bom_product -> cost_price * $sub_bom_line -> qty * $line -> qty ;
2021-08-26 09:43:50 +02:00
} elseif ( $sub_bom_product -> pmp > 0 ) { // PMP if cost price isn't defined
2023-01-02 09:48:34 +01:00
print '<td class="linecolcost nowrap right" id="sub_bom_cost_' . $sub_bom_line -> id . '"><span class="amount">' . price ( price2num ( $sub_bom_product -> pmp * $sub_bom_line -> qty * $line -> qty , 'MT' )) . '</span></td>' ;
2022-02-15 10:29:42 +01:00
$total_cost .= $sub_bom_product -> pmp * $sub_bom_line -> qty * $line -> qty ;
2021-08-26 09:43:50 +02:00
} else { // Minimum purchase price if cost price and PMP aren't defined
2022-01-26 14:41:36 +01:00
$sql_supplier_price = 'SELECT MIN(price) AS min_price, quantity AS qty FROM ' . MAIN_DB_PREFIX . 'product_fournisseur_price' ;
2021-10-20 10:15:31 +02:00
$sql_supplier_price .= ' WHERE fk_product = ' . ( int ) $sub_bom_product -> id ;
2021-08-25 11:21:54 +02:00
$resql_supplier_price = $object -> db -> query ( $sql_supplier_price );
if ( $resql_supplier_price ) {
$obj = $object -> db -> fetch_object ( $resql_supplier_price );
2022-02-15 10:29:42 +01:00
$line_cost = $obj -> min_price / $obj -> qty * $sub_bom_line -> qty * $line -> qty ;
2022-01-26 14:41:36 +01:00
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>' ;
2022-01-26 14:41:36 +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 16:58:22 +02:00
// Replace of the total_cost value by the sum of all sub-BOM lines total_cost
2022-03-24 14:04:03 +01:00
// TODO Remove this bad practice. We should not replace content of ouput using javascript but value should be good during generation of output.
2021-08-25 11:21:54 +02:00
if ( $total_cost > 0 ) {
$line -> total_cost = price ( $total_cost );
?>
< script >
2022-03-24 14:04:03 +01:00
$ ( '#costline_<?php echo $line->id?>' ) . html ( '<?php echo "<span class=\"amount\">".price($total_cost)."</span>"; ?>' );
2021-08-25 11:21:54 +02:00
</ script >
< ? php
}
2019-05-22 20:28:24 +02:00
//Line extrafield
2021-02-23 17:51:46 +01:00
if ( ! empty ( $extrafields )) {
2021-01-04 20:00:57 +01:00
print $line -> showOptionals ( $extrafields , 'view' , array ( 'style' => 'class="drag drop oddeven"' , 'colspan' => $coldisplay ), '' , '' , 1 , 'line' );
2019-05-22 20:28:24 +02:00
}
2019-10-20 11:17:54 +02:00
print " <!-- END PHP TEMPLATE objectline_view.tpl.php --> \n " ;