2014-05-05 14:30:08 +02:00
< ? php
/* Copyright ( C ) 2010 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2014-05-05 17:59:43 +02:00
* Copyright ( C ) 2010 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
2014-05-05 14:30:08 +02:00
* Copyright ( C ) 2012 - 2013 Christophe Battarel < christophe . battarel @ altairis . fr >
2014-11-14 16:43:49 +01:00
* Copyright ( C ) 2012 Cédric Salvador < csalvador @ gpcsolutions . fr >
2015-01-27 12:53:02 +01:00
* Copyright ( C ) 2014 Florian Henry < florian . henry @ open - concept . pro >
2014-11-14 16:43:49 +01:00
* Copyright ( C ) 2014 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2016-07-23 16:37:21 +02:00
* Copyright ( C ) 2015 - 2016 Marcos García < marcosgdf @ gmail . com >
2014-05-05 14:30:08 +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
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*
* Need to have following variables defined :
2014-05-06 18:31:39 +02:00
* $object ( invoice , order , ... )
2014-05-05 14:30:08 +02:00
* $conf
* $langs
* $dateSelector
2014-05-05 17:59:43 +02:00
* $forceall ( 0 by default , 1 for supplier invoices / orders )
2017-08-23 15:02:38 +02:00
* $senderissupplier ( 0 by default , 1 or 2 for supplier invoices / orders )
2014-05-06 18:31:39 +02:00
* $inputalsopricewithtax ( 0 by default , 1 to also show column with unit price including tax )
2014-05-05 14:30:08 +02:00
*/
2017-12-21 13:32:16 +01:00
// Protection to avoid direct call of template
if ( empty ( $object ) || ! is_object ( $object ))
{
print " Error, template page can't be called as URL " ;
exit ;
}
2014-05-05 17:59:43 +02:00
2014-05-05 14:30:08 +02:00
$usemargins = 0 ;
2016-04-12 11:35:39 +02:00
if ( ! empty ( $conf -> margin -> enabled ) && ! empty ( $object -> element ) && in_array ( $object -> element , array ( 'facture' , 'propal' , 'commande' )))
2015-11-15 18:23:42 +01:00
{
$usemargins = 1 ;
}
2014-05-06 18:31:39 +02:00
2017-09-11 01:20:15 +02:00
if ( ! isset ( $dateSelector )) global $dateSelector ; // Take global var only if not already defined into function calling (for example formAddObjectLine)
global $forceall , $forcetoshowtitlelines , $senderissupplier , $inputalsopricewithtax ;
2016-09-14 19:48:57 +02:00
if ( ! isset ( $dateSelector )) $dateSelector = 1 ; // For backward compatibility
elseif ( empty ( $dateSelector )) $dateSelector = 0 ;
2014-05-05 17:59:43 +02:00
if ( empty ( $forceall )) $forceall = 0 ;
if ( empty ( $senderissupplier )) $senderissupplier = 0 ;
2014-05-06 18:31:39 +02:00
if ( empty ( $inputalsopricewithtax )) $inputalsopricewithtax = 0 ;
// Define colspan for button Add
$colspan = 3 ; // Col total ht + col edit + col delete
2017-12-22 10:56:52 +01:00
if ( in_array ( $object -> element , array ( 'propal' , 'commande' , 'order' , 'facture' , 'facturerec' , 'invoice' , 'supplier_proposal' , 'order_supplier' , 'invoice_supplier' ))) $colspan ++ ; // With this, there is a column move button
2015-03-06 18:51:55 +01:00
//print $object->element;
2018-03-20 10:10:21 +01:00
// Lines for extrafield
$objectline = null ;
if ( ! empty ( $extrafieldsline ))
{
if ( $this -> table_element_line == 'commandedet' ) {
$objectline = new OrderLine ( $this -> db );
}
elseif ( $this -> table_element_line == 'propaldet' ) {
$objectline = new PropaleLigne ( $this -> db );
}
elseif ( $this -> table_element_line == 'supplier_proposaldet' ) {
$objectline = new SupplierProposalLine ( $this -> db );
}
elseif ( $this -> table_element_line == 'facturedet' ) {
$objectline = new FactureLigne ( $this -> db );
}
elseif ( $this -> table_element_line == 'contratdet' ) {
$objectline = new ContratLigne ( $this -> db );
}
elseif ( $this -> table_element_line == 'commande_fournisseurdet' ) {
$objectline = new CommandeFournisseurLigne ( $this -> db );
}
elseif ( $this -> table_element_line == 'facture_fourn_det' ) {
$objectline = new SupplierInvoiceLine ( $this -> db );
}
elseif ( $this -> table_element_line == 'facturedet_rec' ) {
$objectline = new FactureLigneRec ( $this -> db );
}
}
2014-05-05 14:30:08 +02:00
?>
<!-- BEGIN PHP TEMPLATE objectline_create . tpl . php -->
2017-06-23 11:20:29 +02:00
< ? php
2017-03-03 13:14:59 +01:00
$nolinesbefore = ( count ( $this -> lines ) == 0 || $forcetoshowtitlelines );
2016-07-28 15:29:46 +02:00
if ( $nolinesbefore ) {
?>
2017-04-12 12:13:38 +02:00
< tr class = " liste_titre<?php echo (( $nolinesbefore || $object->element =='contrat')?'':' liste_titre_add_') ?> nodrag nodrop " >
2017-04-07 14:18:04 +02:00
< ? php if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) { ?>
< td class = " linecolnum " align = " center " ></ td >
< ? php } ?>
< td class = " linecoldescription minwidth500imp " >
2014-05-05 14:30:08 +02:00
< div id = " add " ></ div >< span class = " hideonsmartphone " >< ? php echo $langs -> trans ( 'AddNewLine' ); ?> </span><?php // echo $langs->trans("FreeZone"); ?>
</ td >
2017-11-12 15:30:21 +01:00
< ? php
if ( $object -> element == 'supplier_proposal' || $object -> element == 'order_supplier' || $object -> element == 'invoice_supplier' ) // We must have same test in printObjectLines
{
?>
2018-01-12 14:03:03 +01:00
< td class = " linecolrefsupplier " align = " right " >< span id = " title_fourn_ref " >< ? php echo $langs -> trans ( 'SupplierRef' ); ?> </span></td>
2015-02-02 17:50:33 +01:00
< ? php } ?>
2015-10-20 16:08:25 +02:00
< td class = " linecolvat " align = " right " >< span id = " title_vat " >< ? php echo $langs -> trans ( 'VAT' ); ?> </span></td>
< td class = " linecoluht " align = " right " >< span id = " title_up_ht " >< ? php echo $langs -> trans ( 'PriceUHT' ); ?> </span></td>
2018-05-02 11:30:35 +02:00
< ? php if ( ! empty ( $conf -> multicurrency -> enabled ) && $this -> multicurrency_code != $conf -> currency ) { $colspan ++ ; ?>
2016-01-18 19:45:27 +01:00
< td class = " linecoluht_currency " align = " right " >< span id = " title_up_ht_currency " >< ? php echo $langs -> trans ( 'PriceUHTCurrency' ); ?> </span></td>
< ? php } ?>
2014-05-05 17:59:43 +02:00
< ? php if ( ! empty ( $inputalsopricewithtax )) { ?>
2015-10-20 16:08:25 +02:00
< td class = " linecoluttc " align = " right " >< span id = " title_up_ttc " >< ? php echo $langs -> trans ( 'PriceUTTC' ); ?> </span></td>
2014-05-05 17:59:43 +02:00
< ? php } ?>
2015-10-20 16:08:25 +02:00
< td class = " linecolqty " align = " right " >< ? php echo $langs -> trans ( 'Qty' ); ?> </td>
2015-02-26 14:15:33 +01:00
< ? php
if ( $conf -> global -> PRODUCT_USE_UNITS )
{
2015-10-20 16:08:25 +02:00
print '<td class="linecoluseunit" align="left">' ;
2015-02-26 14:15:33 +01:00
print '<span id="title_units">' ;
print $langs -> trans ( 'Unit' );
print '</span></td>' ;
}
?>
2015-10-20 16:08:25 +02:00
< td class = " linecoldiscount " align = " right " >< ? php echo $langs -> trans ( 'ReductionShort' ); ?> </td>
2014-05-05 14:30:08 +02:00
< ? php
2014-11-14 16:43:49 +01:00
if ( $this -> situation_cycle_ref ) {
2015-10-20 16:08:25 +02:00
print '<td class="linecolcycleref" align="right">' . $langs -> trans ( 'Progress' ) . '</td>' ;
2014-11-14 16:43:49 +01:00
}
2014-05-05 14:30:08 +02:00
if ( ! empty ( $usemargins ))
{
2016-12-15 12:01:46 +01:00
if ( ! empty ( $user -> rights -> margins -> creer )) {
2014-05-05 14:30:08 +02:00
?>
2015-10-20 16:08:25 +02:00
< td align = " right " class = " margininfos linecolmargin1 " >
2014-05-05 14:30:08 +02:00
< ? php
2016-12-15 12:01:46 +01:00
}
else $colspan ++ ;
2016-12-24 21:39:40 +01:00
2014-05-05 14:30:08 +02:00
if ( $conf -> global -> MARGIN_TYPE == " 1 " )
echo $langs -> trans ( 'BuyingPrice' );
else
echo $langs -> trans ( 'CostPrice' );
?>
</ td >
< ? php
2015-10-20 16:08:25 +02:00
if ( $user -> rights -> margins -> creer && ! empty ( $conf -> global -> DISPLAY_MARGIN_RATES )) echo '<td align="right" class="margininfos linecolmargin2"><span class="np_marginRate">' . $langs -> trans ( 'MarginRate' ) . '</span></td>' ;
if ( $user -> rights -> margins -> creer && ! empty ( $conf -> global -> DISPLAY_MARK_RATES )) echo '<td align="right" class="margininfos linecolmargin2"><span class="np_markRate">' . $langs -> trans ( 'MarkRate' ) . '</span></td>' ;
2014-05-05 14:30:08 +02:00
}
?>
2015-10-20 16:08:25 +02:00
< td class = " linecoledit " colspan = " <?php echo $colspan ; ?> " >& nbsp ; </ td >
2014-05-05 14:30:08 +02:00
</ tr >
2016-09-06 21:06:33 +02:00
< ? php
2016-07-28 15:29:46 +02:00
}
?>
2017-04-12 12:13:38 +02:00
< tr class = " pair nodrag nodrop nohoverpair<?php echo ( $nolinesbefore || $object->element =='contrat')?'':' liste_titre_create'; ?> " >
2014-05-05 14:30:08 +02:00
< ? php
if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) {
2017-04-07 14:18:04 +02:00
$coldisplay = 2 ;
?>
2018-03-01 02:37:18 +01:00
< td class = " nobottom linecolnum " align = " center " width = " 5 " ></ td >
2017-06-23 11:20:29 +02:00
< ? php
2017-04-07 14:18:04 +02:00
}
2014-05-05 14:30:08 +02:00
else {
2017-06-23 11:20:29 +02:00
$coldisplay = 0 ;
2017-04-07 14:18:04 +02:00
}
2014-05-05 14:30:08 +02:00
?>
2017-04-07 14:18:04 +02:00
< td class = " nobottom linecoldescription minwidth500imp " >
2014-05-05 14:30:08 +02:00
< ? php
2018-03-01 02:37:18 +01:00
2018-01-14 17:13:42 +01:00
$freelines = false ;
2018-02-03 17:00:47 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FREE_LINES ))
2014-05-06 18:31:39 +02:00
{
2018-01-14 17:13:42 +01:00
$freelines = true ;
$forceall = 1 ; // We always force all type for free lines (module product or service means we use predefined product or service)
if ( $object -> element == 'contrat' )
2014-11-28 02:05:40 +01:00
{
2018-01-14 17:13:42 +01:00
if ( empty ( $conf -> product -> enabled ) && empty ( $conf -> service -> enabled ) && empty ( $conf -> global -> CONTRACT_SUPPORT_PRODUCTS )) $forceall =- 1 ; // With contract, by default, no choice at all, except if CONTRACT_SUPPORT_PRODUCTS is set
else $forceall = 0 ;
}
2018-03-01 02:37:18 +01:00
2018-01-14 17:13:42 +01:00
// Free line
echo '<span class="prod_entry_mode_free">' ;
// Show radio free line
if ( $forceall >= 0 && ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled )))
{
echo '<label for="prod_entry_mode_free">' ;
echo '<input type="radio" class="prod_entry_mode_free" name="prod_entry_mode" id="prod_entry_mode_free" value="free"' ;
//echo (GETPOST('prod_entry_mode')=='free' ? ' checked' : ((empty($forceall) && (empty($conf->product->enabled) || empty($conf->service->enabled)))?' checked':'') );
echo ( GETPOST ( 'prod_entry_mode' ) == 'free' ? ' checked' : '' );
echo '> ' ;
// Show type selector
echo $langs -> trans ( " FreeLineOfType " );
echo '</label>' ;
2014-11-28 02:05:40 +01:00
echo ' ' ;
}
2018-01-14 17:13:42 +01:00
else
{
echo '<input type="hidden" id="prod_entry_mode_free" name="prod_entry_mode" value="free">' ;
// Show type selector
if ( $forceall >= 0 )
{
if ( empty ( $conf -> product -> enabled ) || empty ( $conf -> service -> enabled )) echo $langs -> trans ( " Type " );
else echo $langs -> trans ( " FreeLineOfType " );
echo ' ' ;
}
}
2018-03-01 02:37:18 +01:00
2018-01-14 17:13:42 +01:00
echo $form -> select_type_of_lines ( isset ( $_POST [ " type " ]) ? GETPOST ( " type " , 'alpha' , 2 ) :- 1 , 'type' , 1 , 1 , $forceall );
2018-03-01 02:37:18 +01:00
2018-01-14 17:13:42 +01:00
echo '</span>' ;
2014-07-19 22:05:35 +02:00
}
2014-05-05 17:59:43 +02:00
// Predefined product/service
2014-05-05 14:30:08 +02:00
if ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled ))
{
2018-01-14 17:13:42 +01:00
if ( $forceall >= 0 && $freelines ) echo '<br>' ;
2015-10-11 13:26:22 +02:00
echo '<span class="prod_entry_mode_predef">' ;
2014-07-10 17:36:39 +02:00
echo '<label for="prod_entry_mode_predef">' ;
2015-10-11 13:26:22 +02:00
echo '<input type="radio" class="prod_entry_mode_predef" name="prod_entry_mode" id="prod_entry_mode_predef" value="predef"' . ( GETPOST ( 'prod_entry_mode' ) == 'predef' ? ' checked' : '' ) . '> ' ;
2014-05-05 17:59:43 +02:00
if ( empty ( $senderissupplier ))
{
2014-05-05 18:30:07 +02:00
if ( ! empty ( $conf -> product -> enabled ) && empty ( $conf -> service -> enabled )) echo $langs -> trans ( 'PredefinedProductsToSell' );
else if ( empty ( $conf -> product -> enabled ) && ! empty ( $conf -> service -> enabled )) echo $langs -> trans ( 'PredefinedServicesToSell' );
else echo $langs -> trans ( 'PredefinedProductsAndServicesToSell' );
2014-05-05 17:59:43 +02:00
}
else
{
if ( ! empty ( $conf -> product -> enabled ) && empty ( $conf -> service -> enabled )) echo $langs -> trans ( 'PredefinedProductsToPurchase' );
else if ( empty ( $conf -> product -> enabled ) && ! empty ( $conf -> service -> enabled )) echo $langs -> trans ( 'PredefinedServicesToPurchase' );
else echo $langs -> trans ( 'PredefinedProductsAndServicesToPurchase' );
}
2014-07-10 17:36:39 +02:00
echo '</label>' ;
2014-05-05 14:30:08 +02:00
echo ' ' ;
$filtertype = '' ;
if ( ! empty ( $object -> element ) && $object -> element == 'contrat' && empty ( $conf -> global -> CONTRACT_SUPPORT_PRODUCTS )) $filtertype = '1' ;
2014-05-05 17:59:43 +02:00
if ( empty ( $senderissupplier ))
{
2017-12-22 10:56:52 +01:00
if ( ! empty ( $conf -> global -> ENTREPOT_EXTRA_STATUS ))
2016-11-30 13:03:17 +01:00
{
2016-12-02 12:22:09 +01:00
// hide products in closed warehouse, but show products for internal transfer
2018-01-13 16:09:05 +01:00
$form -> select_produits ( GETPOST ( 'idprod' ), 'idprod' , $filtertype , $conf -> product -> limit_size , $buyer -> price_level , 1 , 2 , '' , 1 , array (), $buyer -> id , '1' , 0 , 'maxwidth300' , 0 , 'warehouseopen,warehouseinternal' , GETPOST ( 'combinations' , 'array' ));
2016-11-30 13:03:17 +01:00
}
else
{
2018-01-13 16:09:05 +01:00
$form -> select_produits ( GETPOST ( 'idprod' ), 'idprod' , $filtertype , $conf -> product -> limit_size , $buyer -> price_level , 1 , 2 , '' , 1 , array (), $buyer -> id , '1' , 0 , 'maxwidth300' , 0 , '' , GETPOST ( 'combinations' , 'array' ));
2016-11-30 13:03:17 +01:00
}
2014-05-05 17:59:43 +02:00
}
else
{
2017-08-23 15:02:38 +02:00
// $senderissupplier=2 is same than 1 but disable test on minimum qty and disable autofill qty with minimum
2016-09-11 16:05:38 +02:00
if ( $senderissupplier != 2 )
{
$ajaxoptions = array (
'update' => array ( 'qty' => 'qty' , 'remise_percent' => 'discount' , 'idprod' => 'idprod' ), // html id tags that will be edited with which ajax json response key
2017-08-23 15:02:38 +02:00
'option_disabled' => 'idthatdoesnotexists' , // html id to disable once select is done
'warning' => $langs -> trans ( " NoPriceDefinedForThisSupplier " ) // translation of an error saved into var 'warning' (for exemple shown we select a disabled option into combo)
2016-09-11 16:05:38 +02:00
);
$alsoproductwithnosupplierprice = 0 ;
}
2016-11-06 15:01:40 +01:00
else
2016-09-11 16:05:38 +02:00
{
$ajaxoptions = array ();
$alsoproductwithnosupplierprice = 1 ;
}
2017-08-23 15:02:38 +02:00
2016-09-11 16:05:38 +02:00
$form -> select_produits_fournisseurs ( $object -> socid , GETPOST ( 'idprodfournprice' ), 'idprodfournprice' , '' , '' , $ajaxoptions , 1 , $alsoproductwithnosupplierprice );
2014-05-05 17:59:43 +02:00
}
2017-12-22 10:56:52 +01:00
echo '<input type="hidden" name="pbq" id="pbq" value="">' ;
2014-05-05 14:30:08 +02:00
echo '</span>' ;
}
2014-05-05 17:59:43 +02:00
if ( is_object ( $hookmanager ) && empty ( $senderissupplier ))
2014-05-05 14:30:08 +02:00
{
$parameters = array ( 'fk_parent_line' => GETPOST ( 'fk_parent_line' , 'int' ));
$reshook = $hookmanager -> executeHooks ( 'formCreateProductOptions' , $parameters , $object , $action );
2016-04-12 11:35:39 +02:00
if ( ! empty ( $hookmanager -> resPrint )) {
print $hookmanager -> resPrint ;
}
2014-05-05 14:30:08 +02:00
}
2014-05-05 17:59:43 +02:00
if ( is_object ( $hookmanager ) && ! empty ( $senderissupplier ))
{
$parameters = array ( 'htmlname' => 'addproduct' );
$reshook = $hookmanager -> executeHooks ( 'formCreateProductSupplierOptions' , $parameters , $object , $action );
2016-04-12 11:35:39 +02:00
if ( ! empty ( $hookmanager -> resPrint )) {
print $hookmanager -> resPrint ;
}
2014-05-05 17:59:43 +02:00
}
2014-05-05 14:30:08 +02:00
2016-07-23 16:37:21 +02:00
if ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled )) {
2017-02-08 12:37:38 +01:00
if ( ! empty ( $conf -> variants -> enabled )) {
2016-07-23 16:37:21 +02:00
echo '<div id="attributes_box"></div>' ;
}
echo '<br>' ;
}
2014-05-05 14:30:08 +02:00
// Editor wysiwyg
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
$nbrows = ROWS_2 ;
$enabled = ( ! empty ( $conf -> global -> FCKEDITOR_ENABLE_DETAILS ) ? $conf -> global -> FCKEDITOR_ENABLE_DETAILS : 0 );
if ( ! empty ( $conf -> global -> MAIN_INPUT_DESC_HEIGHT )) $nbrows = $conf -> global -> MAIN_INPUT_DESC_HEIGHT ;
2015-03-13 15:20:08 +01:00
$toolbarname = 'dolibarr_details' ;
if ( ! empty ( $conf -> global -> FCKEDITOR_ENABLE_DETAILS_FULL )) $toolbarname = 'dolibarr_notes' ;
$doleditor = new DolEditor ( 'dp_desc' , GETPOST ( 'dp_desc' ), '' , 100 , $toolbarname , '' , false , true , $enabled , $nbrows , '98%' );
2014-05-05 14:30:08 +02:00
$doleditor -> Create ();
2018-03-12 12:27:40 +01:00
// Show autofill date for recuring invoices
if ( ! empty ( $conf -> service -> enabled ) && $object -> element == 'facturerec' )
{
echo '<div class="divlinefordates"><br>' ;
echo $langs -> trans ( 'AutoFillDateFrom' ) . ' ' ;
echo $form -> selectyesno ( 'date_start_fill' , $line -> date_start_fill , 1 );
echo ' - ' ;
echo $langs -> trans ( 'AutoFillDateTo' ) . ' ' ;
echo $form -> selectyesno ( 'date_end_fill' , $line -> date_end_fill , 1 );
echo '</div>' ;
}
2014-05-05 14:30:08 +02:00
?>
</ td >
2015-04-27 02:33:44 +02:00
2017-11-12 16:06:08 +01:00
< ? php
if ( $object -> element == 'supplier_proposal' || $object -> element == 'order_supplier' || $object -> element == 'invoice_supplier' ) // We must have same test in printObjectLines
{
?>
2018-01-12 14:09:51 +01:00
< td class = " nobottom linecolresupplier " >< input id = " fourn_ref " name = " fourn_ref " class = " flat maxwidth75 " value = " <?php echo (isset( $_POST["fourn_ref"] )?GETPOST( " fourn_ref " ,'alpha',2):''); ?> " ></ td >
2015-02-02 17:50:33 +01:00
< ? php } ?>
2015-04-27 02:33:44 +02:00
2015-10-20 16:08:25 +02:00
< td class = " nobottom linecolvat " align = " right " >< ? php
2015-06-14 17:11:36 +02:00
if ( $seller -> tva_assuj == " 0 " ) echo '<input type="hidden" name="tva_tx" id="tva_tx" value="0">' . vatrate ( 0 , true );
2016-12-18 01:44:26 +01:00
else echo $form -> load_tva ( 'tva_tx' , ( isset ( $_POST [ " tva_tx " ]) ? GETPOST ( " tva_tx " , 'alpha' , 2 ) :- 1 ), $seller , $buyer , 0 , 0 , '' , false , 1 );
2014-05-05 14:30:08 +02:00
?>
</ td >
2015-10-20 16:08:25 +02:00
< td class = " nobottom linecoluht " align = " right " >
2017-03-14 21:02:26 +01:00
< input type = " text " size = " 5 " name = " price_ht " id = " price_ht " class = " flat right " value = " <?php echo (isset( $_POST["price_ht"] )?GETPOST( " price_ht " ,'alpha',2):''); ?> " >
2014-05-05 14:30:08 +02:00
</ td >
2017-06-23 11:20:29 +02:00
2018-05-02 11:30:35 +02:00
< ? php if ( ! empty ( $conf -> multicurrency -> enabled ) && $this -> multicurrency_code != $conf -> currency ) { $colspan ++ ; ?>
2016-01-18 19:45:27 +01:00
< td class = " nobottom linecoluht_currency " align = " right " >
2017-03-14 21:02:26 +01:00
< input type = " text " size = " 5 " name = " multicurrency_price_ht " id = " multicurrency_price_ht " class = " flat right " value = " <?php echo (isset( $_POST["multicurrency_price_ht"] )?GETPOST( " multicurrency_price_ht " ,'alpha',2):''); ?> " >
2016-01-18 19:45:27 +01:00
</ td >
< ? php } ?>
2017-06-23 11:20:29 +02:00
2014-05-05 17:59:43 +02:00
< ? php if ( ! empty ( $inputalsopricewithtax )) { ?>
2015-10-20 16:08:25 +02:00
< td class = " nobottom linecoluttc " align = " right " >
2016-12-18 01:44:26 +01:00
< input type = " text " size = " 5 " name = " price_ttc " id = " price_ttc " class = " flat " value = " <?php echo (isset( $_POST["price_ttc"] )?GETPOST( " price_ttc " ,'alpha',2):''); ?> " >
2014-05-05 17:59:43 +02:00
</ td >
< ? php } ?>
2017-03-14 21:02:26 +01:00
< td class = " nobottom linecolqty " align = " right " >< input type = " text " size = " 2 " name = " qty " id = " qty " class = " flat right " value = " <?php echo (isset( $_POST["qty"] )?GETPOST( " qty " ,'alpha',2):1); ?> " >
2014-05-05 14:30:08 +02:00
</ td >
2015-02-26 14:15:33 +01:00
< ? php
if ( $conf -> global -> PRODUCT_USE_UNITS )
{
2015-10-20 16:08:25 +02:00
print '<td class="nobottom linecoluseunit" align="left">' ;
2015-04-21 15:49:58 +02:00
print $form -> selectUnits ( $line -> fk_unit , " units " );
2015-02-26 14:15:33 +01:00
print '</td>' ;
}
2018-02-27 16:30:39 +01:00
$remise_percent = $buyer -> remise_percent ;
if ( $object -> element == 'supplier_proposal' || $object -> element == 'order_supplier' || $object -> element == 'invoice_supplier' ) {
$remise_percent = $seller -> remise_supplier_percent ;
}
2015-02-26 14:15:33 +01:00
?>
2018-02-27 16:30:39 +01:00
< td class = " nobottom nowrap linecoldiscount " align = " right " >< input type = " text " size = " 1 " name = " remise_percent " id = " remise_percent " class = " flat right " value = " <?php echo (isset( $_POST["remise_percent"] )?GETPOST( " remise_percent " ,'alpha',2): $remise_percent ); ?> " >< span class = " hideonsmartphone " >%</ span ></ td >
2014-05-05 14:30:08 +02:00
< ? php
2014-11-14 16:43:49 +01:00
if ( $this -> situation_cycle_ref ) {
$coldisplay ++ ;
2017-03-14 21:02:26 +01:00
print '<td class="nobottom nowrap" align="right"><input class="falt right" type="text" size="1" value="0" name="progress">%</td>' ;
2014-11-14 16:43:49 +01:00
}
2014-05-05 14:30:08 +02:00
if ( ! empty ( $usemargins ))
{
2016-12-15 12:01:46 +01:00
if ( ! empty ( $user -> rights -> margins -> creer )) {
2014-05-05 14:30:08 +02:00
?>
2015-10-20 16:08:25 +02:00
< td align = " right " class = " nobottom margininfos linecolmargin " >
2014-05-05 14:30:08 +02:00
<!-- For predef product -->
< ? php if ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled )) { ?>
2017-09-24 01:36:20 +02:00
< select id = " fournprice_predef " name = " fournprice_predef " class = " flat " style = " display: none; " ></ select >
2014-05-05 14:30:08 +02:00
< ? php } ?>
<!-- For free product -->
2017-03-14 21:02:26 +01:00
< input type = " text " size = " 5 " id = " buying_price " name = " buying_price " class = " flat right " value = " <?php echo (isset( $_POST["buying_price"] )?GETPOST( " buying_price " ,'alpha',2):''); ?> " >
2014-05-05 14:30:08 +02:00
</ td >
< ? php
2014-05-06 18:31:39 +02:00
$coldisplay ++ ;
2016-12-15 12:01:46 +01:00
}
2016-12-24 21:39:40 +01:00
2014-05-05 14:30:08 +02:00
if ( $user -> rights -> margins -> creer )
{
2014-05-06 18:31:39 +02:00
if ( ! empty ( $conf -> global -> DISPLAY_MARGIN_RATES ))
{
2017-03-14 21:02:26 +01:00
echo '<td align="right" class="nobottom nowrap margininfos"><input class="flat right" type="text" size="2" id="np_marginRate" name="np_marginRate" value="' . ( isset ( $_POST [ " np_marginRate " ]) ? GETPOST ( " np_marginRate " , 'alpha' , 2 ) : '' ) . '"><span class="np_marginRate hideonsmartphone">%</span></td>' ;
2014-05-05 14:30:08 +02:00
$coldisplay ++ ;
}
2014-05-06 18:31:39 +02:00
if ( ! empty ( $conf -> global -> DISPLAY_MARK_RATES ))
{
2017-03-14 21:02:26 +01:00
echo '<td align="right" class="nobottom nowrap margininfos"><input class="flat right" type="text" size="2" id="np_markRate" name="np_markRate" value="' . ( isset ( $_POST [ " np_markRate " ]) ? GETPOST ( " np_markRate " , 'alpha' , 2 ) : '' ) . '"><span class="np_markRate hideonsmartphone">%</span></td>' ;
2014-05-05 14:30:08 +02:00
$coldisplay ++ ;
}
}
else
{
2014-05-06 18:31:39 +02:00
if ( ! empty ( $conf -> global -> DISPLAY_MARGIN_RATES )) $coldisplay ++ ;
if ( ! empty ( $conf -> global -> DISPLAY_MARK_RATES )) $coldisplay ++ ;
2014-05-05 14:30:08 +02:00
}
}
?>
2015-10-20 16:08:25 +02:00
< td class = " nobottom linecoledit " align = " center " valign = " middle " colspan = " <?php echo $colspan ; ?> " >
2014-05-05 14:30:08 +02:00
< input type = " submit " class = " button " value = " <?php echo $langs->trans ('Add'); ?> " name = " addline " id = " addline " >
</ td >
</ tr >
2018-03-20 10:10:21 +01:00
< ? php
if ( is_object ( $objectline )) {
print $objectline -> showOptionals ( $extrafieldsline , 'edit' , array ( 'style' => $bcnd [ $var ], 'colspan' => $coldisplay + 8 ), '' , '' , empty ( $conf -> global -> MAIN_EXTRAFIELDS_IN_ONE_TD ) ? 0 : 1 );
}
?>
2014-05-05 14:30:08 +02:00
< ? php
2015-03-06 14:36:22 +01:00
if (( ! empty ( $conf -> service -> enabled ) || ( $object -> element == 'contrat' )) && $dateSelector && GETPOST ( 'type' ) != '0' ) // We show date field if required
2014-05-05 14:30:08 +02:00
{
2015-11-07 14:29:38 +01:00
$colspan = 6 ;
2018-03-01 02:37:18 +01:00
if ( $object -> element == 'supplier_proposal' || $object -> element == 'order_supplier' || $object -> element == 'invoice_supplier' ) // We must have same test in printObjectLines
{
$colspan ++ ;
}
2015-11-07 14:29:38 +01:00
if ( $this -> situation_cycle_ref ) {
$colspan ++ ;
}
// We add 1 if col total ttc
if ( ! empty ( $inputalsopricewithtax )) {
$colspan ++ ;
}
2015-02-26 14:15:33 +01:00
if ( $conf -> global -> PRODUCT_USE_UNITS ) {
$colspan ++ ;
}
2015-11-07 14:29:38 +01:00
if ( count ( $object -> lines )) {
//There will be an edit and a delete button
$colspan += 2 ;
// With this, there is a column move button ONLY if lines > 1
if ( in_array ( $object -> element , array (
'propal' ,
2015-11-15 18:23:42 +01:00
'supplier_proposal' ,
2015-11-07 14:29:38 +01:00
'facture' ,
2016-04-24 18:55:19 +02:00
'facturerec' ,
2015-11-07 14:29:38 +01:00
'invoice' ,
'commande' ,
'order' ,
'order_supplier' ,
'invoice_supplier'
))) {
$colspan ++ ;
}
}
2014-05-05 14:30:08 +02:00
2018-05-02 11:30:35 +02:00
if ( ! empty ( $conf -> multicurrency -> enabled ) && $this -> multicurrency_code != $conf -> currency ) $colspan += 2 ;
2016-01-18 19:45:27 +01:00
2014-05-05 14:30:08 +02:00
if ( ! empty ( $usemargins ))
{
2016-12-15 12:01:46 +01:00
if ( ! empty ( $user -> rights -> margins -> creer )) $colspan ++ ; // For the buying price
2014-05-05 14:30:08 +02:00
if ( ! empty ( $conf -> global -> DISPLAY_MARGIN_RATES )) $colspan ++ ;
if ( ! empty ( $conf -> global -> DISPLAY_MARK_RATES )) $colspan ++ ;
}
2014-05-05 17:59:43 +02:00
?>
2014-05-05 14:30:08 +02:00
2014-05-05 17:59:43 +02:00
< tr id = " trlinefordates " < ? php echo $bcnd [ $var ]; ?> >
2018-02-01 00:49:12 +01:00
< ? php if ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER )) { print '<td></td>' ; } ?>
2014-05-05 14:30:08 +02:00
< td colspan = " <?php echo $colspan ; ?> " >
< ? php
2014-05-05 17:59:43 +02:00
$date_start = dol_mktime ( GETPOST ( 'date_starthour' ), GETPOST ( 'date_startmin' ), 0 , GETPOST ( 'date_startmonth' ), GETPOST ( 'date_startday' ), GETPOST ( 'date_startyear' ));
$date_end = dol_mktime ( GETPOST ( 'date_starthour' ), GETPOST ( 'date_startmin' ), 0 , GETPOST ( 'date_endmonth' ), GETPOST ( 'date_endday' ), GETPOST ( 'date_endyear' ));
2014-05-05 14:30:08 +02:00
if ( ! empty ( $object -> element ) && $object -> element == 'contrat' )
{
print $langs -> trans ( " DateStartPlanned " ) . ' ' ;
2016-03-25 15:53:44 +01:00
$form -> select_date ( $date_start , " date_start " , $usehm , $usehm , 1 , " addproduct " );
2014-05-05 14:30:08 +02:00
print ' ' . $langs -> trans ( " DateEndPlanned " ) . ' ' ;
2016-03-25 15:53:44 +01:00
$form -> select_date ( $date_end , " date_end " , $usehm , $usehm , 1 , " addproduct " );
2014-05-05 14:30:08 +02:00
}
else
{
echo $langs -> trans ( 'ServiceLimitedDuration' ) . ' ' . $langs -> trans ( 'From' ) . ' ' ;
2016-03-25 15:53:44 +01:00
echo $form -> select_date ( $date_start , 'date_start' , empty ( $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE ) ? 0 : 1 , empty ( $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE ) ? 0 : 1 , 1 , " addproduct " , 1 , 0 , 1 );
2014-05-05 14:30:08 +02:00
echo ' ' . $langs -> trans ( 'to' ) . ' ' ;
2016-03-25 15:53:44 +01:00
echo $form -> select_date ( $date_end , 'date_end' , empty ( $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE ) ? 0 : 1 , empty ( $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE ) ? 0 : 1 , 1 , " addproduct " , 1 , 0 , 1 );
2016-03-04 00:50:47 +01:00
};
2016-03-03 16:11:42 +01:00
print '<script type="text/javascript">' ;
if ( ! $date_start ) {
2016-03-04 00:50:47 +01:00
if ( isset ( $conf -> global -> MAIN_DEFAULT_DATE_START_HOUR )) {
2016-03-03 16:11:42 +01:00
print 'jQuery("#date_starthour").val("' . $conf -> global -> MAIN_DEFAULT_DATE_START_HOUR . '");' ;
}
2016-03-04 00:50:47 +01:00
if ( isset ( $conf -> global -> MAIN_DEFAULT_DATE_START_MIN )) {
2016-03-03 16:11:42 +01:00
print 'jQuery("#date_startmin").val("' . $conf -> global -> MAIN_DEFAULT_DATE_START_MIN . '");' ;
}
}
if ( ! $date_end ) {
2016-03-04 00:50:47 +01:00
if ( isset ( $conf -> global -> MAIN_DEFAULT_DATE_END_HOUR )) {
2016-03-03 16:11:42 +01:00
print 'jQuery("#date_endhour").val("' . $conf -> global -> MAIN_DEFAULT_DATE_END_HOUR . '");' ;
}
2016-03-04 00:50:47 +01:00
if ( isset ( $conf -> global -> MAIN_DEFAULT_DATE_END_MIN )) {
2016-03-03 16:11:42 +01:00
print 'jQuery("#date_endmin").val("' . $conf -> global -> MAIN_DEFAULT_DATE_END_MIN . '");' ;
}
}
print '</script>'
2014-05-05 14:30:08 +02:00
?>
</ td >
2014-05-05 17:59:43 +02:00
</ tr >
2014-05-05 14:30:08 +02:00
< ? php
}
2014-05-05 17:59:43 +02:00
?>
2014-05-05 14:30:08 +02:00
2014-05-05 17:59:43 +02:00
< script type = " text/javascript " >
2014-05-05 14:30:08 +02:00
2014-05-05 17:59:43 +02:00
< ? php
2014-05-05 14:30:08 +02:00
if ( ! empty ( $usemargins ) && $user -> rights -> margins -> creer )
{
?>
/* Some js test when we click on button "Add" */
jQuery ( document ) . ready ( function () {
< ? php
if ( ! empty ( $conf -> global -> DISPLAY_MARGIN_RATES )) { ?>
$ ( " input[name='np_marginRate']:first " ) . blur ( function ( e ) {
return checkFreeLine ( e , " np_marginRate " );
});
< ? php
}
if ( ! empty ( $conf -> global -> DISPLAY_MARK_RATES )) { ?>
$ ( " input[name='np_markRate']:first " ) . blur ( function ( e ) {
return checkFreeLine ( e , " np_markRate " );
});
< ? php
}
?>
});
/* 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 ;
2014-05-10 20:10:59 +02:00
2014-05-05 14:30:08 +02:00
if ( ! $ . isNumeric ( rate . val () . replace ( ',' , '.' )))
{
alert ( '<?php echo dol_escape_js($langs->trans("rateMustBeNumeric")); ?>' );
e . stopPropagation ();
setTimeout ( function () { rate . focus () }, 50 );
return false ;
}
if ( npRate == " np_markRate " && rate . val () >= 100 )
{
alert ( '<?php echo dol_escape_js($langs->trans("markRateShouldBeLesserThan100")); ?>' );
e . stopPropagation ();
setTimeout ( function () { rate . focus () }, 50 );
return false ;
}
var price = 0 ;
remisejs = price2numjs ( remise . val ());
2014-05-10 20:10:59 +02:00
if ( remisejs != 100 ) // If a discount not 100 or no discount
2014-05-05 14:30:08 +02:00
{
2014-05-10 20:10:59 +02:00
if ( remisejs == '' ) remisejs = 0 ;
2014-05-05 14:30:08 +02:00
bpjs = price2numjs ( buying_price . val ());
ratejs = price2numjs ( rate . val ());
2014-05-10 20:10:59 +02:00
if ( npRate == " np_marginRate " )
2014-05-05 14:30:08 +02:00
price = (( bpjs * ( 1 + ratejs / 100 )) / ( 1 - remisejs / 100 ));
2014-05-10 20:10:59 +02:00
else if ( npRate == " np_markRate " )
2014-05-05 14:30:08 +02:00
price = (( bpjs / ( 1 - ratejs / 100 )) / ( 1 - remisejs / 100 ));
}
$ ( " input[name='price_ht']:first " ) . val ( price ); // TODO Must use a function like php price to have here a formated value
return true ;
}
< ? php
}
?>
/* JQuery for product free or predefined select */
jQuery ( document ) . ready ( function () {
$ ( " #prod_entry_mode_free " ) . on ( " click " , function () {
setforfree ();
});
$ ( " #select_type " ) . change ( function ()
{
setforfree ();
2016-04-12 11:35:39 +02:00
if ( jQuery ( '#select_type' ) . val () >= 0 )
2015-11-21 13:42:01 +01:00
{
/* focus work on a standard textarea but not if field was replaced with CKEDITOR */
jQuery ( '#dp_desc' ) . focus ();
/* focus if CKEDITOR */
2015-12-11 18:28:55 +01:00
if ( typeof CKEDITOR == " object " && typeof CKEDITOR . instances != " undefined " )
2015-11-21 13:42:01 +01:00
{
var editor = CKEDITOR . instances [ 'dp_desc' ];
if ( editor ) { editor . focus (); }
}
}
2018-03-12 12:27:40 +01:00
console . log ( " Hide/show date according to product type " );
if ( jQuery ( '#select_type' ) . val () == '0' )
{
jQuery ( '#trlinefordates' ) . hide ();
jQuery ( '.divlinefordates' ) . hide ();
}
else
{
jQuery ( '#trlinefordates' ) . show ();
jQuery ( '.divlinefordates' ) . show ();
}
2014-05-05 14:30:08 +02:00
});
$ ( " #prod_entry_mode_predef " ) . on ( " click " , function () {
2015-11-05 01:05:17 +01:00
console . log ( " click prod_entry_mode_predef " );
2014-05-05 14:30:08 +02:00
setforpredef ();
2014-05-05 17:59:43 +02:00
jQuery ( '#trlinefordates' ) . show ();
2014-05-05 14:30:08 +02:00
});
2018-03-01 02:37:18 +01:00
2018-01-14 17:13:42 +01:00
< ? php
if ( ! $freelines ) { ?>
$ ( " #prod_entry_mode_predef " ) . click ();
< ? php
}
?>
2015-01-13 15:38:59 +01:00
2016-04-08 21:50:48 +02:00
/* When changing predefined product, we reload list of supplier prices required for margin combo */
2014-05-05 17:59:43 +02:00
$ ( " #idprod, #idprodfournprice " ) . change ( function ()
2014-05-05 14:30:08 +02:00
{
2016-04-08 21:50:48 +02:00
console . log ( " #idprod, #idprodfournprice change triggered " );
2016-07-23 16:37:21 +02:00
2016-04-08 21:50:48 +02:00
setforpredef (); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva
2016-07-23 16:37:21 +02:00
2014-05-05 17:59:43 +02:00
jQuery ( '#trlinefordates' ) . show ();
2014-05-05 14:30:08 +02:00
2015-01-13 15:38:59 +01:00
< ? php
if ( ! empty ( $usemargins ) && $user -> rights -> margins -> creer )
{
$langs -> load ( 'stocks' );
?>
2014-05-05 14:30:08 +02:00
2016-04-08 21:50:48 +02:00
/* Code for margin */
$ ( " #fournprice_predef " ) . find ( " option " ) . remove ();
$ ( " #fournprice_predef " ) . hide ();
$ ( " #buying_price " ) . val ( " " ) . show ();
/* Call post to load content of combo list fournprice_predef */
$ . post ( '<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php?bestpricefirst=1' , { 'idprod' : $ ( this ) . val () }, function ( data ) {
if ( data && data . length > 0 )
{
var options = '' ;
var defaultkey = '' ;
var defaultprice = '' ;
var bestpricefound = 0 ;
2016-07-23 16:37:21 +02:00
2016-04-08 21:50:48 +02:00
var bestpriceid = 0 ; var bestpricevalue = 0 ;
var pmppriceid = 0 ; var pmppricevalue = 0 ;
var costpriceid = 0 ; var costpricevalue = 0 ;
2016-07-23 16:37:21 +02:00
2016-04-08 21:50:48 +02:00
/* setup of margin calculation */
2016-07-23 16:37:21 +02:00
var defaultbuyprice = ' < ? php
2016-04-08 21:50:48 +02:00
if ( isset ( $conf -> global -> MARGIN_TYPE ))
{
if ( $conf -> global -> MARGIN_TYPE == '1' ) print 'bestsupplierprice' ;
if ( $conf -> global -> MARGIN_TYPE == 'pmp' ) print 'pmp' ;
if ( $conf -> global -> MARGIN_TYPE == 'costprice' ) print 'costprice' ;
} ?> ';
console . log ( " we will set the field for margin. defaultbuyprice= " + defaultbuyprice );
2016-07-23 16:37:21 +02:00
2016-04-08 21:50:48 +02:00
var i = 0 ;
$ ( data ) . each ( function () {
if ( this . id != 'pmpprice' && this . id != 'costprice' )
{
i ++ ;
this . price = parseFloat ( this . price ); // to fix when this.price >0
// If margin is calculated on best supplier price, we set it by defaut (but only if value is not 0)
//console.log("id="+this.id+"-price="+this.price+"-"+(this.price > 0));
if ( bestpricefound == 0 && this . price > 0 ) { defaultkey = this . id ; defaultprice = this . price ; bestpriceid = this . id ; bestpricevalue = this . price ; bestpricefound = 1 ; } // bestpricefound is used to take the first price > 0
}
if ( this . id == 'pmpprice' )
{
// If margin is calculated on PMP, we set it by defaut (but only if value is not 0)
//console.log("id="+this.id+"-price="+this.price);
if ( 'pmp' == defaultbuyprice || 'costprice' == defaultbuyprice )
{
2016-07-23 16:37:21 +02:00
if ( this . price > 0 ) {
2016-04-08 21:50:48 +02:00
defaultkey = this . id ; defaultprice = this . price ; pmppriceid = this . id ; pmppricevalue = this . price ;
//console.log("pmppricevalue="+pmppricevalue);
}
}
}
if ( this . id == 'costprice' )
{
// If margin is calculated on Cost price, we set it by defaut (but only if value is not 0)
//console.log("id="+this.id+"-price="+this.price+"-pmppricevalue="+pmppricevalue);
if ( 'costprice' == defaultbuyprice )
{
if ( this . price > 0 ) { defaultkey = this . id ; defaultprice = this . price ; costpriceid = this . id ; costpricevalue = this . price ; }
else if ( pmppricevalue > 0 ) { defaultkey = pmppriceid ; defaultprice = pmppricevalue ; }
}
}
options += '<option value="' + this . id + '" price="' + this . price + '">' + this . label + '</option>' ;
});
options += '<option value="inputprice" price="' + defaultprice + '"><?php echo $langs->trans("InputPrice"); ?></option>' ;
2016-07-23 16:37:21 +02:00
2016-04-08 21:50:48 +02:00
console . log ( " finally selected defaultkey= " + defaultkey + " defaultprice= " + defaultprice );
2016-07-23 16:37:21 +02:00
2016-04-08 21:50:48 +02:00
$ ( " #fournprice_predef " ) . html ( options ) . show ();
if ( defaultkey != '' )
{
$ ( " #fournprice_predef " ) . val ( defaultkey );
}
2016-07-23 16:37:21 +02:00
2016-04-08 21:50:48 +02:00
/* At loading, no product are yet selected, so we hide field of buying_price */
$ ( " #buying_price " ) . hide ();
2016-07-23 16:37:21 +02:00
2016-04-08 21:50:48 +02:00
/* Define default price at loading */
var defaultprice = $ ( " #fournprice_predef " ) . find ( 'option:selected' ) . attr ( " price " );
$ ( " #buying_price " ) . val ( defaultprice );
2016-07-23 16:37:21 +02:00
2016-04-08 21:50:48 +02:00
$ ( " #fournprice_predef " ) . change ( function () {
console . log ( " change on fournprice_predef " );
/* Hide field buying_price according to choice into list (if 'inputprice' or not) */
var linevalue = $ ( this ) . find ( 'option:selected' ) . val ();
var pricevalue = $ ( this ) . find ( 'option:selected' ) . attr ( " price " );
if ( linevalue != 'inputprice' && linevalue != 'pmpprice' ) {
$ ( " #buying_price " ) . val ( pricevalue ) . hide (); /* We set value then hide field */
}
if ( linevalue == 'inputprice' ) {
$ ( '#buying_price' ) . show ();
}
if ( linevalue == 'pmpprice' ) {
$ ( " #buying_price " ) . val ( pricevalue );
$ ( '#buying_price' ) . hide ();
}
});
}
},
'json' );
< ? php
}
?>
2014-05-05 17:59:43 +02:00
2017-12-22 10:56:52 +01:00
/* To process customer price per quantity */
2018-03-01 12:31:33 +01:00
var pbq = parseInt ( $ ( 'option:selected' , this ) . attr ( 'data-pbq' ));
var pbqqty = parseFloat ( $ ( 'option:selected' , this ) . attr ( 'data-pbqqty' ));
var pbqpercent = parseFloat ( $ ( 'option:selected' , this ) . attr ( 'data-pbqpercent' ));
if (( jQuery ( '#idprod' ) . val () > 0 || jQuery ( '#idprodfournprice' ) . val ()) && typeof pbq !== " undefined " )
2017-12-22 10:56:52 +01:00
{
console . log ( " We choose a price by quanty price_by_qty id = " + pbq + " price_by_qty qty = " + pbqqty + " price_by_qty percent = " + pbqpercent );
jQuery ( " #pbq " ) . val ( pbq );
if ( jQuery ( " #qty " ) . val () < pbqqty )
{
jQuery ( " #qty " ) . val ( pbqqty );
}
if ( jQuery ( " #remise_percent " ) . val () < pbqpercent )
{
jQuery ( " #remise_percent " ) . val ( pbqpercent );
}
}
else
{
jQuery ( " #pbq " ) . val ( '' );
}
2014-05-05 17:59:43 +02:00
/* To set focus */
2016-04-12 11:35:39 +02:00
if ( jQuery ( '#idprod' ) . val () > 0 || jQuery ( '#idprodfournprice' ) . val () > 0 )
2015-11-21 13:42:01 +01:00
{
/* focus work on a standard textarea but not if field was replaced with CKEDITOR */
jQuery ( '#dp_desc' ) . focus ();
/* focus if CKEDITOR */
2015-12-11 18:28:55 +01:00
if ( typeof CKEDITOR == " object " && typeof CKEDITOR . instances != " undefined " )
2015-11-21 13:42:01 +01:00
{
var editor = CKEDITOR . instances [ 'dp_desc' ];
if ( editor ) { editor . focus (); }
}
}
2014-05-05 14:30:08 +02:00
});
2015-03-06 14:36:22 +01:00
< ? php if ( GETPOST ( 'prod_entry_mode' ) == 'predef' ) { // When we submit with a predef product and it fails we must start with predef ?>
setforpredef ();
< ? php } ?>
2014-05-05 14:30:08 +02:00
});
/* Function to set fields from choice */
function setforfree () {
2016-04-08 21:50:48 +02:00
console . log ( " Call setforfree. We show most fields " );
2014-05-05 14:30:08 +02:00
jQuery ( " #search_idprod " ) . val ( '' );
jQuery ( " #idprod " ) . val ( '' );
2014-06-09 14:58:58 +02:00
jQuery ( " #idprodfournprice " ) . val ( '0' ); // Set cursor on not selected product
2014-05-05 17:59:43 +02:00
jQuery ( " #search_idprodfournprice " ) . val ( '' );
2016-07-23 16:37:21 +02:00
jQuery ( " #prod_entry_mode_free " ) . prop ( 'checked' , true ) . change ();
jQuery ( " #prod_entry_mode_predef " ) . prop ( 'checked' , false ) . change ();
2014-05-05 14:30:08 +02:00
jQuery ( " #price_ht " ) . show ();
2016-12-11 10:48:49 +01:00
jQuery ( " #multicurrency_price_ht " ) . show ();
2014-05-06 18:31:39 +02:00
jQuery ( " #price_ttc " ) . show (); // May no exists
2017-11-12 15:30:21 +01:00
jQuery ( " #fourn_ref " ) . show ();
2014-05-05 14:30:08 +02:00
jQuery ( " #tva_tx " ) . show ();
jQuery ( " #buying_price " ) . val ( '' ) . show ();
jQuery ( " #fournprice_predef " ) . hide ();
jQuery ( " #title_vat " ) . show ();
jQuery ( " #title_up_ht " ) . show ();
2017-03-04 21:02:27 +01:00
jQuery ( " #title_up_ht_currency " ) . show ();
2014-05-05 17:59:43 +02:00
jQuery ( " #title_up_ttc " ) . show ();
2017-03-04 21:02:27 +01:00
jQuery ( " #title_up_ttc_currency " ) . show ();
2014-05-10 20:10:59 +02:00
jQuery ( " #np_marginRate " ) . show (); // May no exists
jQuery ( " #np_markRate " ) . show (); // May no exists
jQuery ( " .np_marginRate " ) . show (); // May no exists
jQuery ( " .np_markRate " ) . show (); // May no exists
2015-02-26 14:15:33 +01:00
jQuery ( " #units, #title_units " ) . show ();
2014-05-05 14:30:08 +02:00
}
function setforpredef () {
2018-03-12 12:27:40 +01:00
console . log ( " Call setforpredef. We hide some fields and show dates " );
2014-05-05 14:30:08 +02:00
jQuery ( " #select_type " ) . val ( - 1 );
2017-06-23 11:20:29 +02:00
2016-07-23 16:37:21 +02:00
jQuery ( " #prod_entry_mode_free " ) . prop ( 'checked' , false ) . change ();
jQuery ( " #prod_entry_mode_predef " ) . prop ( 'checked' , true ) . change ();
2017-06-19 18:07:43 +02:00
jQuery ( " #price_ht " ) . val ( '' ) . hide ();
2016-12-11 10:48:49 +01:00
jQuery ( " #multicurrency_price_ht " ) . hide ();
2014-05-06 18:31:39 +02:00
jQuery ( " #price_ttc " ) . hide (); // May no exists
2017-11-12 15:30:21 +01:00
jQuery ( " #fourn_ref " ) . hide ();
2014-05-05 14:30:08 +02:00
jQuery ( " #tva_tx " ) . hide ();
jQuery ( " #buying_price " ) . show ();
jQuery ( " #title_vat " ) . hide ();
2016-06-29 10:05:05 +02:00
jQuery ( " #title_up_ht " ) . hide ();
2017-03-04 21:02:27 +01:00
jQuery ( " #title_up_ht_currency " ) . hide ();
2014-05-05 17:59:43 +02:00
jQuery ( " #title_up_ttc " ) . hide ();
2017-03-04 21:02:27 +01:00
jQuery ( " #title_up_ttc_currency " ) . hide ();
2014-05-10 20:10:59 +02:00
jQuery ( " #np_marginRate " ) . hide (); // May no exists
jQuery ( " #np_markRate " ) . hide (); // May no exists
jQuery ( " .np_marginRate " ) . hide (); // May no exists
jQuery ( " .np_markRate " ) . hide (); // May no exists
2015-02-26 14:15:33 +01:00
jQuery ( " #units, #title_units " ) . hide ();
2018-03-12 12:27:40 +01:00
jQuery ( '#trlinefordates' ) . show ();
jQuery ( '.divlinefordates' ) . show ();
2014-05-05 14:30:08 +02:00
}
</ script >
<!-- END PHP TEMPLATE objectline_create . tpl . php -->