2012-08-23 13:45:51 +02:00
< ? php
2023-01-10 05:00:24 +01:00
/* Copyright ( C ) 2010 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2022-08-26 17:57:17 +02:00
* Copyright ( C ) 2010 - 2022 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-08-23 13:45:51 +02:00
* Copyright ( C ) 2012 Christophe Battarel < christophe . battarel @ altairis . fr >
2014-11-14 16:43:49 +01:00
* Copyright ( C ) 2012 Cédric Salvador < csalvador @ gpcsolutions . fr >
* Copyright ( C ) 2012 - 2014 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2013-06-10 16:05:41 +02:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2023-01-10 05:00:24 +01:00
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2022-02-14 04:52:39 +01:00
* Copyright ( C ) 2022 OpenDSI < support @ open - dsi . fr >
2012-08-23 13:45:51 +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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2012-08-23 13:45:51 +02:00
* ( 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 />.
2012-08-23 13:45:51 +02:00
*
* Need to have following variables defined :
2014-05-12 12:53:10 +02:00
* $object ( invoice , order , ... )
2012-08-23 13:45:51 +02:00
* $conf
* $langs
2015-09-06 14:54:25 +02:00
* $seller , $buyer
2012-08-23 13:45:51 +02:00
* $dateSelector
2014-05-12 12:53:10 +02:00
* $forceall ( 0 by default , 1 for supplier invoices / orders )
* $senderissupplier ( 0 by default , 1 for supplier invoices / orders )
* $inputalsopricewithtax ( 0 by default , 1 to also show column with unit price including tax )
2020-09-23 18:45:19 +02:00
* $canchangeproduct ( 0 by default , 1 to allow to change the product if it is a predefined product )
2012-08-23 13:45:51 +02:00
*/
2014-05-12 12:53:10 +02:00
2017-12-21 13:32:16 +01:00
// Protection to avoid direct call of template
2021-02-23 22:03:23 +01:00
if ( empty ( $object ) || ! is_object ( $object )) {
2017-12-21 13:32:16 +01:00
print " Error, template page can't be called as URL " ;
exit ;
}
2014-05-12 12:53:10 +02:00
2020-04-10 10:59:32 +02:00
$usemargins = 0 ;
2022-09-25 22:47:12 +02:00
if ( isModEnabled ( 'margin' ) && ! empty ( $object -> element ) && in_array ( $object -> element , array ( 'facture' , 'facturerec' , 'propal' , 'commande' ))) {
2021-02-23 22:03:23 +01:00
$usemargins = 1 ;
}
2014-05-12 12:53:10 +02:00
2020-09-23 18:45:19 +02:00
global $forceall , $senderissupplier , $inputalsopricewithtax , $canchangeproduct ;
2021-02-23 22:03:23 +01:00
if ( empty ( $dateSelector )) {
$dateSelector = 0 ;
}
if ( empty ( $forceall )) {
$forceall = 0 ;
}
if ( empty ( $senderissupplier )) {
$senderissupplier = 0 ;
}
if ( empty ( $inputalsopricewithtax )) {
$inputalsopricewithtax = 0 ;
}
if ( empty ( $canchangeproduct )) {
$canchangeproduct = 0 ;
}
2014-05-12 12:53:10 +02:00
2019-05-20 14:41:47 +02:00
// Define colspan for the button 'Add'
2020-04-10 10:59:32 +02:00
$colspan = 3 ; // Col total ht + col edit + col delete
2021-02-23 22:03:23 +01:00
if ( ! empty ( $inputalsopricewithtax )) {
$colspan ++ ; // We add 1 if col total ttc
}
2022-02-07 14:34:27 +01:00
if ( in_array ( $object -> element , array ( 'propal' , 'supplier_proposal' , 'facture' , 'facturerec' , 'invoice' , 'commande' , 'order' , 'order_supplier' , 'invoice_supplier' , 'invoice_supplier_rec' ))) {
2021-02-23 22:03:23 +01:00
$colspan ++ ; // With this, there is a column move button
}
2023-02-01 22:42:41 +01:00
if ( isModEnabled ( " multicurrency " ) && $object -> multicurrency_code != $conf -> currency ) {
2021-02-23 22:03:23 +01:00
$colspan += 2 ;
}
2022-08-30 11:44:26 +02:00
if ( isModEnabled ( 'asset' ) && $object -> element == 'invoice_supplier' ) {
2022-02-14 04:52:39 +01:00
$colspan ++ ;
}
2012-08-23 13:45:51 +02:00
2019-10-27 17:01:23 +01:00
print " <!-- BEGIN PHP TEMPLATE objectline_edit.tpl.php --> \n " ;
2013-11-17 23:25:25 +01:00
2020-04-10 10:59:32 +02:00
$coldisplay = 0 ;
2014-03-07 11:58:30 +01:00
?>
2019-04-09 15:46:37 +02:00
< tr class = " oddeven tredited " >
2023-11-27 11:39:32 +01:00
< ? php if ( getDolGlobalString ( 'MAIN_VIEW_LINE_NUMBER' )) { ?>
2023-12-04 12:07:53 +01:00
< td class = " linecolnum center " >< ? php $coldisplay ++ ; ?> <?php echo($i + 1); ?></td>
2019-10-27 17:01:23 +01:00
< ? php }
2019-04-30 16:44:11 +02:00
2019-10-27 17:01:23 +01:00
$coldisplay ++ ;
?>
2022-03-26 09:40:34 +01:00
< td class = " linecoldesc minwidth250onall " >
2013-11-17 23:25:25 +01:00
< div id = " line_<?php echo $line->id ; ?> " ></ div >
< input type = " hidden " name = " lineid " value = " <?php echo $line->id ; ?> " >
< input type = " hidden " id = " product_type " name = " type " value = " <?php echo $line->product_type ; ?> " >
2013-12-16 00:07:50 +01:00
< input type = " hidden " id = " special_code " name = " special_code " value = " <?php echo $line->special_code ; ?> " >
2019-02-05 12:02:49 +01:00
< input type = " hidden " id = " fk_parent_line " name = " fk_parent_line " value = " <?php echo $line->fk_parent_line ; ?> " >
2012-08-23 13:45:51 +02:00
2014-05-12 12:53:10 +02:00
< ? php if ( $line -> fk_product > 0 ) { ?>
2019-02-05 12:02:49 +01:00
< ? php
2020-09-23 18:45:19 +02:00
if ( empty ( $canchangeproduct )) {
2021-02-23 22:03:23 +01:00
if ( $line -> fk_parent_line > 0 ) {
echo img_picto ( '' , 'rightarrow' );
2023-12-04 12:07:53 +01:00
} ?>
2020-09-23 18:45:19 +02:00
< a href = " <?php echo DOL_URL_ROOT.'/product/card.php?id='. $line->fk_product ; ?> " >
< ? php
2021-02-23 22:03:23 +01:00
if ( $line -> product_type == 1 ) {
echo img_object ( $langs -> trans ( 'ShowService' ), 'service' );
} else {
print img_object ( $langs -> trans ( 'ShowProduct' ), 'product' );
}
2023-12-04 12:07:53 +01:00
echo ' ' . $line -> ref ; ?>
2020-09-23 18:45:19 +02:00
</ a >
< ? php
echo ' - ' . nl2br ( $line -> product_label );
print '<input type="hidden" id="product_id" name="productid" value="' . ( ! empty ( $line -> fk_product ) ? $line -> fk_product : 0 ) . '">' ;
} else {
if ( $senderissupplier ) {
2022-12-31 14:01:03 +01:00
$form -> select_produits_fournisseurs ( ! empty ( $line -> fk_product ) ? $line -> fk_product : 0 , 'productid' );
2020-09-23 18:45:19 +02:00
} else {
print $form -> select_produits ( ! empty ( $line -> fk_product ) ? $line -> fk_product : 0 , 'productid' );
}
}
2012-09-07 10:03:25 +02:00
?>
2018-03-12 12:27:40 +01:00
< br >< br >
2012-09-08 00:58:14 +02:00
< ? php } ?>
2012-08-23 13:45:51 +02:00
< ? php
2021-02-23 22:03:23 +01:00
if ( is_object ( $hookmanager )) {
2021-11-23 12:11:27 +01:00
$fk_parent_line = ( GETPOST ( 'fk_parent_line' ) ? GETPOST ( 'fk_parent_line' , 'int' ) : $line -> fk_parent_line );
2020-10-31 14:32:18 +01:00
$parameters = array ( 'line' => $line , 'fk_parent_line' => $fk_parent_line , 'var' => $var , 'dateSelector' => $dateSelector , 'seller' => $seller , 'buyer' => $buyer );
$reshook = $hookmanager -> executeHooks ( 'formEditProductOptions' , $parameters , $this , $action );
2012-08-23 13:45:51 +02:00
}
2021-06-30 12:43:44 +02:00
$situationinvoicelinewithparent = 0 ;
if ( $line -> fk_prev_id != null && in_array ( $object -> element , array ( 'facture' , 'facturedet' ))) {
2024-02-21 18:14:29 +01:00
// @phan-suppress-next-line PhanUndeclaredConstantOfClass
2021-06-30 12:43:44 +02:00
if ( $object -> type == $object :: TYPE_SITUATION ) { // The constant TYPE_SITUATION exists only for object invoice
// Set constant to disallow editing during a situation cycle
$situationinvoicelinewithparent = 1 ;
}
}
2014-11-14 16:43:49 +01:00
// Do not allow editing during a situation cycle
2024-01-13 19:48:20 +01:00
// but in some situations that is required (update legal information for example)
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'INVOICE_SITUATION_CAN_FORCE_UPDATE_DESCRIPTION' )) {
2023-02-20 12:19:34 +01:00
$situationinvoicelinewithparent = 0 ;
}
2021-06-30 12:43:44 +02:00
if ( ! $situationinvoicelinewithparent ) {
2020-01-25 13:05:40 +01:00
// editor wysiwyg
2014-11-14 16:43:49 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2019-11-13 19:35:39 +01:00
$nbrows = ROWS_2 ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MAIN_INPUT_DESC_HEIGHT' )) {
2024-01-05 04:18:53 +01:00
$nbrows = getDolGlobalString ( 'MAIN_INPUT_DESC_HEIGHT' );
2021-02-23 22:03:23 +01:00
}
2019-11-13 19:35:39 +01:00
$enable = ( isset ( $conf -> global -> FCKEDITOR_ENABLE_DETAILS ) ? $conf -> global -> FCKEDITOR_ENABLE_DETAILS : 0 );
$toolbarname = 'dolibarr_details' ;
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'FCKEDITOR_ENABLE_DETAILS_FULL' )) {
2021-02-23 22:03:23 +01:00
$toolbarname = 'dolibarr_notes' ;
}
2023-11-27 11:39:32 +01:00
$doleditor = new DolEditor ( 'product_desc' , GETPOSTISSET ( 'product_desc' ) ? GETPOST ( 'product_desc' , 'restricthtml' ) : $line -> description , '' , ( ! getDolGlobalString ( 'MAIN_DOLEDITOR_HEIGHT' ) ? 164 : $conf -> global -> MAIN_DOLEDITOR_HEIGHT ), $toolbarname , '' , false , true , $enable , $nbrows , '98%' );
2014-11-14 16:43:49 +01:00
$doleditor -> Create ();
} else {
2021-11-23 12:11:27 +01:00
print '<textarea id="product_desc" class="flat" name="product_desc" readonly style="width: 200px; height:80px;">' ;
print GETPOSTISSET ( 'product_desc' ) ? GETPOST ( 'product_desc' , 'restricthtml' ) : $line -> description ;
print '</textarea>' ;
2014-11-14 16:43:49 +01:00
}
2018-03-12 12:27:40 +01:00
2020-12-22 12:52:01 +01:00
//Line extrafield
2021-02-23 22:03:23 +01:00
if ( ! empty ( $extrafields )) {
2021-01-16 14:10:37 +01:00
$temps = $line -> showOptionals ( $extrafields , 'edit' , array ( 'class' => 'tredited' ), '' , '' , 1 , 'line' );
if ( ! empty ( $temps )) {
print '<div style="padding-top: 10px" id="extrafield_lines_area_edit" name="extrafield_lines_area_edit">' ;
2021-01-16 16:06:49 +01:00
print $temps ;
2021-01-16 14:10:37 +01:00
print '</div>' ;
}
2020-12-22 12:52:01 +01:00
}
2024-01-13 19:48:20 +01:00
// Show autofill date for recurring invoices
2022-08-23 20:02:37 +02:00
if ( isModEnabled ( " service " ) && $line -> product_type == 1 && ( $line -> element == 'facturedetrec' || $line -> element == 'invoice_supplier_det_rec' )) {
2022-02-07 14:34:27 +01:00
if ( $line -> element == 'invoice_supplier_det_rec' ) {
$line -> date_start_fill = $line -> date_start ;
$line -> date_end_fill = $line -> date_end ;
}
2018-03-12 12:27:40 +01:00
echo '<br>' ;
echo $langs -> trans ( 'AutoFillDateFrom' ) . ' ' ;
2021-11-23 12:11:27 +01:00
echo $form -> selectyesno ( 'date_start_fill' , GETPOSTISSET ( 'date_start_fill' ) ? GETPOST ( 'date_start_fill' , 'int' ) : $line -> date_start_fill , 1 );
2018-03-12 12:27:40 +01:00
echo ' - ' ;
echo $langs -> trans ( 'AutoFillDateTo' ) . ' ' ;
2021-11-23 12:11:27 +01:00
echo $form -> selectyesno ( 'date_end_fill' , GETPOSTISSET ( 'date_end_fill' ) ? GETPOST ( 'date_end_fill' , 'int' ) : $line -> date_end_fill , 1 );
2018-03-12 12:27:40 +01:00
}
2012-08-23 13:45:51 +02:00
?>
</ td >
2017-11-12 15:30:21 +01:00
< ? php
2022-02-07 14:34:27 +01:00
if ( $object -> element == 'supplier_proposal' || $object -> element == 'order_supplier' || $object -> element == 'invoice_supplier' || $object -> element == 'invoice_supplier_rec' ) { // We must have same test in printObjectLines
2023-12-04 12:07:53 +01:00
$coldisplay ++ ; ?>
2022-11-14 20:47:30 +01:00
< td class = " right linecolrefsupplier " >< input id = " fourn_ref " name = " fourn_ref " class = " flat minwidth50 maxwidth100 maxwidth125onsmartphone " value = " <?php echo GETPOSTISSET('fourn_ref') ? GETPOST('fourn_ref') : ( $line->ref_supplier ? $line->ref_supplier : $line->ref_fourn ); ?> " ></ td >
2019-10-27 17:01:23 +01:00
< ? php
2022-10-25 19:58:53 +02:00
print '<input type="hidden" id="fournprice" name="fournprice" class="" value="' . $line -> fk_fournprice . '">' ;
2017-11-12 15:30:21 +01:00
}
2022-10-25 12:22:43 +02:00
// VAT Rate
2014-11-14 16:43:49 +01:00
$coldisplay ++ ;
2023-01-10 05:00:24 +01:00
if ( $object -> element == 'propal' || $object -> element == 'commande' || $object -> element == 'facture' || $object -> element == 'facturerec' ) {
$type_tva = 1 ;
2023-01-10 05:02:08 +01:00
} elseif ( $object -> element == 'supplier_proposal' || $object -> element == 'order_supplier' || $object -> element == 'invoice_supplier' || $object -> element == 'invoice_supplier_rec' ) {
2023-01-10 05:00:24 +01:00
$type_tva = 2 ;
}
2021-06-30 12:43:44 +02:00
if ( ! $situationinvoicelinewithparent ) {
2022-10-25 12:22:43 +02:00
print '<td class="right">' ;
2023-01-10 05:00:24 +01:00
print $form -> load_tva ( 'tva_tx' , GETPOSTISSET ( 'tva_tx' ) ? GETPOST ( 'tva_tx' , 'alpha' ) : ( $line -> tva_tx . ( $line -> vat_src_code ? ( ' (' . $line -> vat_src_code . ')' ) : '' )), $seller , $buyer , 0 , $line -> info_bits , $line -> product_type , false , 1 , $type_tva );
2022-10-25 12:22:43 +02:00
print '</td>' ;
2014-11-14 16:43:49 +01:00
} else {
2019-11-13 19:35:39 +01:00
print '<td class="right"><input size="1" type="text" class="flat right" name="tva_tx" value="' . price ( $line -> tva_tx ) . '" readonly />%</td>' ;
2014-11-14 16:43:49 +01:00
}
2012-08-23 13:45:51 +02:00
2014-11-14 16:43:49 +01:00
$coldisplay ++ ;
2021-11-23 12:11:27 +01:00
print '<td class="right"><input type="text" class="flat right" size="5" id="price_ht" name="price_ht" value="' . ( GETPOSTISSET ( 'price_ht' ) ? GETPOST ( 'price_ht' , 'alpha' ) : ( isset ( $line -> pu_ht ) ? price ( $line -> pu_ht , 0 , '' , 0 ) : price ( $line -> subprice , 0 , '' , 0 ))) . '"' ;
2021-06-30 12:43:44 +02:00
if ( $situationinvoicelinewithparent ) {
2021-02-23 22:03:23 +01:00
print ' readonly' ;
}
2014-11-14 16:43:49 +01:00
print '></td>' ;
2023-02-01 22:42:41 +01:00
if ( isModEnabled ( " multicurrency " ) && $object -> multicurrency_code != $conf -> currency ) {
2020-10-31 14:32:18 +01:00
$coldisplay ++ ;
2021-11-23 12:11:27 +01:00
print '<td class="right"><input rel="' . $object -> multicurrency_tx . '" type="text" class="flat right" size="5" id="multicurrency_subprice" name="multicurrency_subprice" value="' . ( GETPOSTISSET ( 'multicurrency_subprice' ) ? GETPOST ( 'multicurrency_subprice' , 'alpha' ) : price ( $line -> multicurrency_subprice )) . '" /></td>' ;
2016-01-21 21:54:57 +01:00
}
2023-03-11 19:38:39 +01:00
if ( ! empty ( $inputalsopricewithtax ) && ! getDolGlobalInt ( 'MAIN_NO_INPUT_PRICE_WITH_TAX' )) {
2014-11-14 16:43:49 +01:00
$coldisplay ++ ;
2023-03-11 20:25:27 +01:00
$upinctax = isset ( $line -> pu_ttc ) ? $line -> pu_ttc : null ;
if ( getDolGlobalInt ( 'MAIN_UNIT_PRICE_WITH_TAX_IS_FOR_ALL_TAXES' )) {
$upinctax = price2num ( $line -> total_ttc / $line -> qty , 'MU' );
}
print '<td class="right"><input type="text" class="flat right" size="5" id="price_ttc" name="price_ttc" value="' . ( GETPOSTISSET ( 'price_ttc' ) ? GETPOST ( 'price_ttc' ) : ( isset ( $upinctax ) ? price ( $upinctax , 0 , '' , 0 ) : '' )) . '"' ;
2023-02-20 12:19:34 +01:00
if ( $situationinvoicelinewithparent ) {
2021-02-23 22:03:23 +01:00
print ' readonly' ;
}
2014-11-14 16:43:49 +01:00
print '></td>' ;
2015-02-28 18:10:31 +01:00
}
?>
2019-10-27 17:01:23 +01:00
< td class = " right " >
< ? php $coldisplay ++ ;
if (( $line -> info_bits & 2 ) != 2 ) {
2021-06-30 12:43:44 +02:00
// I comment warning of stock because it shows the info even when it should not.
2012-10-06 23:13:46 +02:00
// for example always visible on invoice but must be visible only if stock module on and stock decrease option is on invoice validation and status is not validated
// must also not be output for most entities (proposal, intervention, ...)
//if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." ";
2021-11-23 12:11:27 +01:00
print '<input size="3" type="text" class="flat right" name="qty" id="qty" value="' . ( GETPOSTISSET ( 'qty' ) ? GETPOST ( 'qty' ) : $line -> qty ) . '"' ;
2021-06-30 12:43:44 +02:00
if ( $situationinvoicelinewithparent ) { // Do not allow editing during a situation cycle
2021-02-23 22:03:23 +01:00
print ' readonly' ;
}
2015-02-28 18:10:31 +01:00
print '>' ;
2014-11-14 16:43:49 +01:00
} else { ?>
2012-08-23 13:45:51 +02:00
& nbsp ;
< ? php } ?>
</ td >
2015-02-26 14:15:33 +01:00
< ? php
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'PRODUCT_USE_UNITS' )) {
2021-01-06 15:15:51 +01:00
$unit_type = false ;
// limit unit select to unit type
2023-11-27 11:39:32 +01:00
if ( ! empty ( $line -> fk_unit ) && ! getDolGlobalString ( 'MAIN_EDIT_LINE_ALLOW_ALL_UNIT_TYPE' )) {
2021-01-07 10:30:11 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/cunits.class.php' ;
2021-01-06 15:15:51 +01:00
$cUnit = new CUnits ( $line -> db );
2021-01-07 10:30:11 +01:00
if ( $cUnit -> fetch ( $line -> fk_unit ) > 0 ) {
if ( ! empty ( $cUnit -> unit_type )) {
2021-01-06 15:15:51 +01:00
$unit_type = $cUnit -> unit_type ;
}
}
}
2020-10-31 14:32:18 +01:00
$coldisplay ++ ;
2019-01-20 23:36:39 +01:00
print '<td class="left">' ;
2021-11-23 12:11:27 +01:00
print $form -> selectUnits ( GETPOSTISSET ( 'units' ) ? GETPOST ( 'units' ) : $line -> fk_unit , " units " , 0 , $unit_type );
2015-02-26 14:15:33 +01:00
print '</td>' ;
}
?>
2022-03-26 09:40:34 +01:00
< td class = " nowraponall right linecoldiscount " >
2022-10-25 12:22:43 +02:00
< ? php
// Discount
$coldisplay ++ ;
2019-10-27 17:01:23 +01:00
if (( $line -> info_bits & 2 ) != 2 ) {
2022-10-25 12:22:43 +02:00
print '<input type="text" class="flat right width40" name="remise_percent" id="remise_percent" value="' . ( GETPOSTISSET ( 'remise_percent' ) ? GETPOST ( 'remise_percent' ) : ( $line -> remise_percent ? $line -> remise_percent : '' )) . '"' ;
2021-06-30 12:43:44 +02:00
if ( $situationinvoicelinewithparent ) {
2021-02-23 22:03:23 +01:00
print ' readonly' ;
}
2022-10-25 12:22:43 +02:00
print '><span class="hideonsmartphone opacitymedium">%</span>' ;
2014-11-14 16:43:49 +01:00
} else { ?>
2012-08-23 13:45:51 +02:00
& nbsp ;
< ? php } ?>
</ td >
2022-10-25 12:22:43 +02:00
2019-10-27 17:01:23 +01:00
< ? php
2022-10-25 12:22:43 +02:00
// Progession for situation invoices
2023-02-01 22:42:41 +01:00
if ( $object -> situation_cycle_ref ) {
2014-11-14 16:43:49 +01:00
$coldisplay ++ ;
2021-11-23 12:11:27 +01:00
print '<td class="nowrap right linecolcycleref"><input class="right" type="text" size="1" value="' . ( GETPOSTISSET ( 'progress' ) ? GETPOST ( 'progress' ) : $line -> situation_percent ) . '" name="progress">%</td>' ;
2019-04-30 18:11:35 +02:00
$coldisplay ++ ;
print '<td></td>' ;
2014-11-14 16:43:49 +01:00
}
2022-10-25 12:22:43 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $usemargins )) {
2023-10-15 15:32:35 +02:00
if ( $user -> hasRight ( 'margins' , 'creer' )) {
2023-12-04 12:07:53 +01:00
$coldisplay ++ ; ?>
2021-02-23 22:03:23 +01:00
< td class = " margininfos right " >
2014-05-12 13:25:36 +02:00
<!-- For predef product -->
2022-08-23 20:02:37 +02:00
< ? php if ( isModEnabled ( " product " ) || isModEnabled ( " service " )) { ?>
2019-10-23 03:50:48 +02:00
< select id = " fournprice_predef " name = " fournprice_predef " class = " flat minwidth75imp right " style = " display: none; " ></ select >
2014-05-12 13:25:36 +02:00
< ? php } ?>
<!-- For free product -->
2023-12-04 12:07:53 +01:00
< input class = " flat maxwidth75 right " type = " text " id = " buying_price " name = " buying_price " class = " hideobject " value = " <?php echo(GETPOSTISSET('buying_price') ? GETPOST('buying_price') : price( $line->pa_ht , 0, '', 0)); ?> " >
2013-08-22 11:39:55 +02:00
</ td >
2023-12-04 12:07:53 +01:00
< ? php
}
2019-04-30 16:44:11 +02:00
2023-10-15 15:32:35 +02:00
if ( $user -> hasRight ( 'margins' , 'creer' )) {
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'DISPLAY_MARGIN_RATES' )) {
2020-11-30 14:47:07 +01:00
$margin_rate = ( GETPOSTISSET ( " np_marginRate " ) ? GETPOST ( " np_marginRate " , " alpha " , 2 ) : (( $line -> pa_ht == 0 ) ? '' : price ( $line -> marge_tx )));
2024-01-13 19:48:20 +01:00
// if credit note, don't allow to modify margin
2021-02-23 22:03:23 +01:00
if ( $line -> subprice < 0 ) {
2022-10-25 12:22:43 +02:00
echo '<td class="right nowrap margininfos">' . $margin_rate . '<span class="opacitymedium hideonsmartphone">%</span></td>' ;
2021-02-23 22:03:23 +01:00
} else {
2022-10-25 12:22:43 +02:00
echo '<td class="right nowrap margininfos"><input class="right maxwidth40" type="text" name="np_marginRate" value="' . $margin_rate . '"><span class="opacitymedium hideonsmartphone">%</span></td>' ;
2021-02-23 22:03:23 +01:00
}
2019-02-03 14:29:45 +01:00
$coldisplay ++ ;
2021-10-17 19:39:56 +02:00
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'DISPLAY_MARK_RATES' )) {
2020-11-30 14:47:07 +01:00
$mark_rate = ( GETPOSTISSET ( " np_markRate " ) ? GETPOST ( " np_markRate " , 'alpha' , 2 ) : price ( $line -> marque_tx ));
2024-01-13 19:48:20 +01:00
// if credit note, don't allow to modify margin
2021-02-23 22:03:23 +01:00
if ( $line -> subprice < 0 ) {
2022-10-25 12:22:43 +02:00
echo '<td class="right nowrap margininfos">' . $mark_rate . '<span class="opacitymedium hideonsmartphone">%</span></td>' ;
2021-02-23 22:03:23 +01:00
} else {
2022-10-25 12:22:43 +02:00
echo '<td class="right nowrap margininfos"><input class="right maxwidth40" type="text" name="np_markRate" value="' . $mark_rate . '"><span class="opacitymedium hideonsmartphone">%</span></td>' ;
2021-02-23 22:03:23 +01:00
}
2019-02-03 14:29:45 +01:00
$coldisplay ++ ;
}
}
2015-02-28 18:10:31 +01:00
}
2019-10-27 17:01:23 +01:00
?>
2012-08-23 13:45:51 +02:00
2019-05-20 14:41:47 +02:00
<!-- colspan for this td because it replace total_ht + 3 td for buttons +... -->
2019-11-13 19:35:39 +01:00
< td class = " center valignmiddle " colspan = " <?php echo $colspan ; ?> " >< ? php $coldisplay += $colspan ; ?>
2022-08-26 17:57:17 +02:00
< input type = " submit " class = " reposition button buttongen marginbottomonly button-save " id = " savelinebutton marginbottomonly " name = " save " value = " <?php echo $langs->trans ( " Save " ); ?> " >< br >
< input type = " submit " class = " reposition button buttongen marginbottomonly button-cancel " id = " cancellinebutton " name = " cancel " value = " <?php echo $langs->trans ( " Cancel " ); ?> " >
2012-08-23 13:45:51 +02:00
</ td >
</ tr >
2022-08-23 20:02:37 +02:00
< ? php if ( isModEnabled ( " service " ) && $line -> product_type == 1 && $dateSelector ) { ?>
2019-04-09 19:23:34 +02:00
< tr id = " service_duration_area " class = " treditedlinefordate " >
2023-11-27 11:39:32 +01:00
< ? php if ( getDolGlobalString ( 'MAIN_VIEW_LINE_NUMBER' )) { ?>
2019-04-30 16:44:11 +02:00
< td class = " linecolnum center " ></ td >
2018-03-12 12:27:40 +01:00
< ? php } ?>
2023-11-27 11:39:32 +01:00
< td colspan = " <?php echo $coldisplay - (!getDolGlobalString('MAIN_VIEW_LINE_NUMBER') ? 0 : 1) ?> " >< ? php echo $langs -> trans ( 'ServiceLimitedDuration' ) . ' ' . $langs -> trans ( 'From' ) . ' ' ; ?>
2012-08-23 13:45:51 +02:00
< ? php
2020-04-10 10:59:32 +02:00
$hourmin = ( isset ( $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE ) ? $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE : '' );
print $form -> selectDate ( $line -> date_start , 'date_start' , $hourmin , $hourmin , $line -> date_start ? 0 : 1 , " updateline " , 1 , 0 );
2018-09-09 11:25:59 +02:00
print ' ' . $langs -> trans ( 'to' ) . ' ' ;
2020-04-10 10:59:32 +02:00
print $form -> selectDate ( $line -> date_end , 'date_end' , $hourmin , $hourmin , $line -> date_end ? 0 : 1 , " updateline " , 1 , 0 );
2020-08-16 22:03:11 +02:00
print '<script>' ;
2016-03-03 16:11:42 +01:00
if ( ! $line -> date_start ) {
2016-03-04 00:50:47 +01:00
if ( isset ( $conf -> global -> MAIN_DEFAULT_DATE_START_HOUR )) {
2023-10-15 15:32:35 +02:00
print 'jQuery("#date_starthour").val("' . getDolGlobalString ( 'MAIN_DEFAULT_DATE_START_HOUR' ) . '");' ;
2016-03-03 16:11:42 +01:00
}
2021-07-20 11:23:35 +02:00
2016-03-04 00:50:47 +01:00
if ( isset ( $conf -> global -> MAIN_DEFAULT_DATE_START_MIN )) {
2023-10-15 15:32:35 +02:00
print 'jQuery("#date_startmin").val("' . getDolGlobalString ( 'MAIN_DEFAULT_DATE_START_MIN' ) . '");' ;
2016-03-03 16:11:42 +01:00
}
2021-07-20 11:23:35 +02:00
$res = $line -> fetch_product ();
2023-12-04 12:07:53 +01:00
if ( $res > 0 ) {
if ( $line -> product -> isMandatoryPeriod () && $line -> product -> isService ()) {
2021-07-20 13:56:30 +02:00
print 'jQuery("#date_start").addClass("error");' ;
2021-07-20 11:23:35 +02:00
}
}
2016-03-03 16:11:42 +01:00
}
if ( ! $line -> date_end ) {
2016-03-04 00:50:47 +01:00
if ( isset ( $conf -> global -> MAIN_DEFAULT_DATE_END_HOUR )) {
2023-10-15 15:32:35 +02:00
print 'jQuery("#date_endhour").val("' . getDolGlobalString ( 'MAIN_DEFAULT_DATE_END_HOUR' ) . '");' ;
2016-03-03 16:11:42 +01:00
}
2016-03-04 00:50:47 +01:00
if ( isset ( $conf -> global -> MAIN_DEFAULT_DATE_END_MIN )) {
2023-10-15 15:32:35 +02:00
print 'jQuery("#date_endmin").val("' . getDolGlobalString ( 'MAIN_DEFAULT_DATE_END_MIN' ) . '");' ;
2016-03-03 16:11:42 +01:00
}
2021-07-20 11:23:35 +02:00
$res = $line -> fetch_product ();
// on doit fetch le product là !!! pour connaître le type
2023-12-04 12:07:53 +01:00
if ( $res > 0 ) {
2021-07-20 11:23:35 +02:00
if ( $line -> product -> isMandatoryperiod () && $line -> product -> isService ()) {
2021-07-20 13:56:30 +02:00
print 'jQuery("#date_end").addClass("error");' ;
2021-07-20 11:23:35 +02:00
}
}
2016-03-03 16:11:42 +01:00
}
print '</script>'
2012-08-23 13:45:51 +02:00
?>
</ td >
</ tr >
2018-03-12 12:27:40 +01:00
< ? php }
?>
2012-08-23 13:45:51 +02:00
2020-08-16 22:03:11 +02:00
< script >
2012-08-23 13:45:51 +02:00
2020-08-14 11:48:53 +02:00
< ? php
2023-10-15 15:32:35 +02:00
if ( ! empty ( $usemargins ) && $user -> hasRight ( 'margins' , 'creer' )) {
2020-10-03 14:48:19 +02:00
?>
2020-08-14 11:48:53 +02:00
/* Some js test when we click on button "Add" */
jQuery ( document ) . ready ( function () {
2020-10-04 23:21:24 +02:00
< ? php
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'DISPLAY_MARGIN_RATES' )) {
2020-10-04 23:21:24 +02:00
?>
2020-10-03 14:48:19 +02:00
$ ( " input[name='np_marginRate']:first " ) . blur ( function ( e ) {
return checkFreeLine ( e , " np_marginRate " );
});
2020-08-14 11:48:53 +02:00
< ? php
2020-10-04 23:21:24 +02:00
}
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'DISPLAY_MARK_RATES' )) {
2020-10-04 23:21:24 +02:00
?>
2020-10-03 14:48:19 +02:00
$ ( " input[name='np_markRate']:first " ) . blur ( function ( e ) {
return checkFreeLine ( e , " np_markRate " );
});
2020-08-14 11:48:53 +02:00
< ? php
2023-12-04 12:07:53 +01:00
} ?>
2020-08-14 11:48:53 +02:00
});
/* TODO This does not work for number with thousand separator that is , */
function checkFreeLine ( e , npRate )
{
var buying_price = $ ( " input[name='buying_price']:first " );
var remise = $ ( " input[name='remise_percent']:first " );
var rate = $ ( " input[name=' " + npRate + " ']:first " );
if ( rate . val () == '' )
return true ;
2020-09-28 17:04:20 +02:00
var ratejs = price2numjs ( rate . val ());
if ( ! $ . isNumeric ( ratejs ))
2020-08-14 11:48:53 +02:00
{
alert ( '<?php echo dol_escape_js($langs->transnoentities("rateMustBeNumeric")); ?>' );
e . stopPropagation ();
setTimeout ( function () { rate . focus () }, 50 );
return false ;
}
if ( npRate == " np_markRate " && rate . val () >= 100 )
{
alert ( '<?php echo dol_escape_js($langs->transnoentities("markRateShouldBeLesserThan100")); ?>' );
e . stopPropagation ();
setTimeout ( function () { rate . focus () }, 50 );
return false ;
}
var price = 0 ;
2023-05-01 15:09:43 +02:00
remisejs = price2numjs ( remise . val ());
2020-08-14 11:48:53 +02:00
2023-05-01 15:09:43 +02:00
if ( remisejs != 100 ) { // If a discount not 100 or no discount
if ( remisejs == '' ) {
remisejs = 0 ;
}
2020-08-14 11:48:53 +02:00
bpjs = price2numjs ( buying_price . val ());
ratejs = price2numjs ( rate . val ());
if ( npRate == " np_marginRate " )
price = (( bpjs * ( 1 + ratejs / 100 )) / ( 1 - remisejs / 100 ));
else if ( npRate == " np_markRate " )
price = (( bpjs / ( 1 - ratejs / 100 )) / ( 1 - remisejs / 100 ));
}
2024-01-13 19:48:20 +01:00
$ ( " input[name='price_ht']:first " ) . val ( price ); // TODO Must use a function like php price to have here a formatted value
2020-08-14 11:48:53 +02:00
return true ;
}
2020-10-03 14:48:19 +02:00
< ? php
2020-08-14 11:48:53 +02:00
}
?>
2016-04-30 14:24:33 +02:00
jQuery ( document ) . ready ( function ()
2013-11-17 23:25:25 +01:00
{
2016-09-21 18:13:27 +02:00
jQuery ( " #price_ht " ) . keyup ( function ( event ) {
// console.log(event.which); // discard event tag and arrows
2016-12-11 10:48:49 +01:00
if ( event . which != 9 && ( event . which < 37 || event . which > 40 ) && jQuery ( " #price_ht " ) . val () != '' ) {
jQuery ( " #price_ttc " ) . val ( '' );
jQuery ( " #multicurrency_subprice " ) . val ( '' );
2017-09-24 01:36:20 +02:00
}
2016-12-11 10:48:49 +01:00
});
2016-09-21 18:13:27 +02:00
jQuery ( " #price_ttc " ) . keyup ( function ( event ) {
// console.log(event.which); // discard event tag and arrows
2016-12-11 10:48:49 +01:00
if ( event . which != 9 && ( event . which < 37 || event . which > 40 ) && jQuery ( " #price_ttc " ) . val () != '' ) {
jQuery ( " #price_ht " ) . val ( '' );
jQuery ( " #multicurrency_subprice " ) . val ( '' );
2017-09-24 01:36:20 +02:00
}
2016-12-11 10:48:49 +01:00
});
jQuery ( " #multicurrency_subprice " ) . keyup ( function ( event ) {
// console.log(event.which); // discard event tag and arrows
if ( event . which != 9 && ( event . which < 37 || event . which > 40 ) && jQuery ( " #price_ttc " ) . val () != '' ) {
jQuery ( " #price_ht " ) . val ( '' );
jQuery ( " #price_ttc " ) . val ( '' );
2017-09-24 01:36:20 +02:00
}
2016-12-11 10:48:49 +01:00
});
2016-04-30 14:24:33 +02:00
2023-02-01 22:42:41 +01:00
< ? php if ( in_array ( $object -> table_element_line , array ( 'propaldet' , 'commandedet' , 'facturedet' ))) { ?>
2021-09-23 13:01:04 +02:00
$ ( " #date_start, #date_end " ) . focusout ( function () {
if ( $ ( this ) . val () == '' && ! $ ( this ) . hasClass ( 'inputmandatory' ) ) {
$ ( this ) . addClass ( 'inputmandatory' );
} else {
$ ( this ) . removeClass ( 'inputmandatory' );
2021-07-20 13:56:30 +02:00
}
});
2021-09-23 13:01:04 +02:00
< ? php
}
2022-09-25 22:47:12 +02:00
if ( isModEnabled ( 'margin' )) {
2020-10-31 14:32:18 +01:00
?>
2015-08-31 13:06:53 +02:00
/* Add rule to clear margin when we change some data, so when we change sell or buy price, margin will be recalculated after submitting form */
2024-01-13 19:48:20 +01:00
jQuery ( " #tva_tx " ) . click ( function () { /* sometimes field is a text, sometimes a combo */
2015-08-31 13:06:53 +02:00
jQuery ( " input[name='np_marginRate']:first " ) . val ( '' );
jQuery ( " input[name='np_markRate']:first " ) . val ( '' );
});
2024-01-13 19:48:20 +01:00
jQuery ( " #tva_tx " ) . keyup ( function () { /* sometimes field is a text, sometimes a combo */
2015-08-31 13:06:53 +02:00
jQuery ( " input[name='np_marginRate']:first " ) . val ( '' );
jQuery ( " input[name='np_markRate']:first " ) . val ( '' );
});
2014-03-07 11:58:30 +01:00
jQuery ( " #price_ht " ) . keyup ( function () {
jQuery ( " input[name='np_marginRate']:first " ) . val ( '' );
jQuery ( " input[name='np_markRate']:first " ) . val ( '' );
2016-02-03 01:32:50 +01:00
});
2016-03-30 16:26:34 +02:00
jQuery ( " #qty " ) . keyup ( function () {
jQuery ( " input[name='np_marginRate']:first " ) . val ( '' );
jQuery ( " input[name='np_markRate']:first " ) . val ( '' );
});
2016-02-03 01:32:50 +01:00
jQuery ( " #remise_percent " ) . keyup ( function () {
jQuery ( " input[name='np_marginRate']:first " ) . val ( '' );
jQuery ( " input[name='np_markRate']:first " ) . val ( '' );
2014-03-07 11:58:30 +01:00
});
jQuery ( " #buying_price " ) . keyup ( function () {
jQuery ( " input[name='np_marginRate']:first " ) . val ( '' );
jQuery ( " input[name='np_markRate']:first " ) . val ( '' );
});
/* Init field buying_price and fournprice */
2020-11-16 14:36:23 +01:00
var token = '<?php echo currentToken(); ?>' ; // For AJAX Call we use old 'token' and not 'newtoken'
$ . post ( '<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php' , { 'idprod' : < ? php echo $line -> fk_product ? $line -> fk_product : 0 ; ?> , 'token': token }, function(data) {
2021-02-23 22:03:23 +01:00
if ( data && data . length > 0 ) {
2012-08-23 13:45:51 +02:00
var options = '' ;
var trouve = false ;
$ ( data ) . each ( function () {
options += '<option value="' + this . id + '" price="' + this . price + '"' ;
< ? php if ( $line -> fk_fournprice > 0 ) { ?>
if ( this . id == < ? php echo $line -> fk_fournprice ; ?> ) {
options += ' selected' ;
$ ( " #buying_price " ) . val ( this . price );
trouve = true ;
}
< ? php } ?>
options += '>' + this . label + '</option>' ;
});
options += '<option value=null' + ( trouve ? '' : ' selected' ) + '><?php echo $langs->trans("InputPrice"); ?></option>' ;
$ ( " #fournprice " ) . html ( options );
if ( trouve ) {
$ ( " #buying_price " ) . hide ();
$ ( " #fournprice " ) . show ();
} else {
$ ( " #buying_price " ) . show ();
}
$ ( " #fournprice " ) . change ( function () {
var selval = $ ( this ) . find ( 'option:selected' ) . attr ( " price " );
if ( selval )
$ ( " #buying_price " ) . val ( selval ) . hide ();
else
$ ( '#buying_price' ) . show ();
});
} else {
$ ( " #fournprice " ) . hide ();
$ ( '#buying_price' ) . show ();
}
2013-11-17 23:25:25 +01:00
}, 'json' );
2021-02-23 22:03:23 +01:00
< ? php
2020-10-31 14:32:18 +01:00
}
?>
2016-04-30 14:24:33 +02:00
});
2013-08-22 11:39:55 +02:00
2012-08-23 13:45:51 +02:00
</ script >
<!-- END PHP TEMPLATE objectline_edit . tpl . php -->