2012-08-23 13:45:51 +02:00
< ? php
2012-12-30 15:13:49 +01:00
/* Copyright ( C ) 2010 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2012-08-23 13:45:51 +02:00
* Copyright ( C ) 2010 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2012 Christophe Battarel < christophe . battarel @ altairis . fr >
2013-06-10 16:05:41 +02:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
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
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*
*
* Need to have following variables defined :
* $conf
* $langs
* $dateSelector
* $this ( invoice , order , ... )
* $line defined
*/
?>
<!-- BEGIN PHP TEMPLATE objectline_edit . tpl . php -->
2013-11-17 23:25:25 +01:00
< ? php
2014-03-07 11:58:30 +01:00
$coldisplay =- 1 ; // We remove first td
?>
2012-08-23 13:45:51 +02:00
< tr < ? php echo $bc [ $var ]; ?> >
2014-03-07 11:58:30 +01:00
< td < ? php echo ( ! empty ( $conf -> global -> MAIN_VIEW_LINE_NUMBER ) ? ' colspan="2"' : '' ); ?> ><?php $coldisplay+=(! empty($conf->global->MAIN_VIEW_LINE_NUMBER))?2:1; ?>
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 ; ?> " >
< input type = " hidden " id = " product_id " name = " productid " value = " <?php echo (! empty( $line->fk_product )? $line->fk_product :0); ?> " />
2013-12-16 00:07:50 +01:00
< input type = " hidden " id = " special_code " name = " special_code " value = " <?php echo $line->special_code ; ?> " >
2012-08-23 13:45:51 +02:00
2012-09-07 10:03:25 +02:00
< ? php
if ( $conf -> global -> MAIN_FEATURES_LEVEL > 1 )
{
if ( $line -> fk_product > 0 )
{
echo $text . ' - ' ;
}
else
{
echo $form -> select_type_of_lines ( $line -> product_type , 'type' , 1 , 1 );
}
2012-10-22 19:30:49 +02:00
?>
2012-08-27 19:11:44 +02:00
2012-09-07 10:03:25 +02:00
< input id = " product_label " name = " product_label " size = " 40 " value = " <?php echo $label ; ?> " < ? php echo $placeholder . (( ! empty ( $line -> fk_product ) && empty ( $line -> label )) ? ' disabled="disabled"' : '' ); ?> >
< input type = " hidden " id = " origin_label_cache " name = " origin_label_cache " value = " <?php echo $line->product_label ; ?> " />
< span id = " update_label_area " class = " hideobject " >< input type = " checkbox " id = " update_label_checkbox " name = " update_label " value = " 1 " />
< ? php echo $form -> textwithtooltip ( $langs -> trans ( 'UpdateOriginalProductLabel' ), $langs -> trans ( 'HelpUpdateOriginalProductLabel' ), 1 , 0 , '' , '' , 3 ); ?>
</ span >
< span id = " price_base_type " class = " hideobject " ></ span >
2012-08-23 13:45:51 +02:00
2012-09-08 00:58:14 +02:00
< br >
2012-09-07 18:16:05 +02:00
< ? php } else if ( $line -> fk_product > 0 ) { ?>
2012-08-23 13:45:51 +02:00
2012-09-07 10:03:25 +02:00
< a href = " <?php echo DOL_URL_ROOT.'/product/fiche.php?id='. $line->fk_product ; ?> " >
< ? php
if ( $line -> product_type == 1 ) echo img_object ( $langs -> trans ( 'ShowService' ), 'service' );
else print img_object ( $langs -> trans ( 'ShowProduct' ), 'product' );
echo ' ' . $line -> ref ;
?>
</ a >
< ? php
echo ' - ' . nl2br ( $line -> product_label );
?>
2012-08-27 19:11:44 +02:00
2012-09-08 00:58:14 +02:00
< br >
2012-09-07 18:16:05 +02:00
2012-09-08 00:58:14 +02:00
< ? php } ?>
2012-08-23 13:45:51 +02:00
< ? php
if ( is_object ( $hookmanager ))
{
$fk_parent_line = ( GETPOST ( 'fk_parent_line' ) ? GETPOST ( 'fk_parent_line' ) : $line -> fk_parent_line );
$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 );
}
// editeur wysiwyg
2012-09-07 18:16:05 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2012-08-23 13:45:51 +02:00
$nbrows = ROWS_2 ;
if ( ! empty ( $conf -> global -> MAIN_INPUT_DESC_HEIGHT )) $nbrows = $conf -> global -> MAIN_INPUT_DESC_HEIGHT ;
2012-09-07 18:16:05 +02:00
$enable = ( isset ( $conf -> global -> FCKEDITOR_ENABLE_DETAILS ) ? $conf -> global -> FCKEDITOR_ENABLE_DETAILS : 0 );
$doleditor = new DolEditor ( 'product_desc' , $line -> description , '' , 164 , 'dolibarr_details' , '' , false , true , $enable , $nbrows , 70 );
2012-08-23 13:45:51 +02:00
$doleditor -> Create ();
?>
</ td >
2013-06-10 16:05:41 +02:00
< td align = " right " >< ? php $coldisplay ++ ; ?> <?php echo $form->load_tva('tva_tx',$line->tva_tx,$seller,$buyer,0,$line->info_bits,$line->product_type); ?></td>
2012-08-23 13:45:51 +02:00
2013-06-10 16:05:41 +02:00
< td align = " right " >< ? php $coldisplay ++ ; ?> <input type="text" class="flat" size="8" id="price_ht" name="price_ht" value="<?php echo price($line->subprice,0,'',0); ?>"></td>
2012-08-27 19:11:44 +02:00
< ? php if ( $conf -> global -> MAIN_FEATURES_LEVEL > 1 ) { ?>
2013-06-10 16:05:41 +02:00
< td align = " right " >< ? php $coldisplay ++ ; ?> <input type="text" class="flat" size="8" id="price_ttc" name="price_ttc" value="<?php echo price($pu_ttc,0,'',0); ?>"></td>
2012-08-27 19:11:44 +02:00
< ? php } ?>
2012-08-23 13:45:51 +02:00
2013-06-10 16:05:41 +02:00
< td align = " right " >< ? php $coldisplay ++ ; ?>
2012-10-06 23:13:46 +02:00
< ? php if (( $line -> info_bits & 2 ) != 2 ) {
// I comment this because it shows info even when not required
// 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;"')." ";
?>
2012-08-25 03:28:30 +02:00
< input size = " 3 " type = " text " class = " flat " name = " qty " value = " <?php echo $line->qty ; ?> " >
2012-08-23 13:45:51 +02:00
< ? php } else { ?>
& nbsp ;
< ? php } ?>
</ td >
2013-06-10 16:05:41 +02:00
< td align = " right " nowrap >< ? php $coldisplay ++ ; ?>
2012-08-23 13:45:51 +02:00
< ? php if (( $line -> info_bits & 2 ) != 2 ) { ?>
< input size = " 1 " type = " text " class = " flat " name = " remise_percent " value = " <?php echo $line->remise_percent ; ?> " >%
< ? php } else { ?>
& nbsp ;
< ? php } ?>
</ td >
< ? php if ( ! empty ( $conf -> margin -> enabled )) { ?>
2013-08-22 11:39:55 +02:00
< td align = " right " >< ? php $coldisplay ++ ; ?>
< select id = " fournprice " name = " fournprice " class = " hideobject " ></ select >
< input type = " text " size = " 5 " id = " buying_price " name = " buying_price " class = " hideobject " value = " <?php echo price( $line->pa_ht ,0,'',0); ?> " >
</ td >
< ? php if ( $user -> rights -> margins -> creer ) {
if ( ! empty ( $conf -> global -> DISPLAY_MARGIN_RATES ))
{
2014-03-07 11:58:30 +01:00
$margin_rate = ( isset ( $_POST [ " np_marginRate " ]) ? $_POST [ " np_marginRate " ] : (( $line -> pa_ht == 0 ) ? '' : price ( $line -> marge_tx )));
2013-09-24 17:49:56 +02:00
// if credit note, dont allow to modify margin
if ( $line -> subprice < 0 )
2013-12-01 19:39:21 +01:00
echo '<td align="right" class="nowrap">' . $margin_rate . '<span class="hideonsmartphone">%</span></td>' ;
2013-09-24 17:49:56 +02:00
else
2014-03-07 11:58:30 +01:00
echo '<td align="right" class="nowrap"><input type="text" size="2" name="np_marginRate" value="' . $margin_rate . '"><span class="hideonsmartphone">%</span></td>' ;
2013-08-22 11:39:55 +02:00
$coldisplay ++ ;
}
2013-08-22 11:45:27 +02:00
elseif ( ! empty ( $conf -> global -> DISPLAY_MARK_RATES ))
2013-08-22 11:39:55 +02:00
{
2014-03-07 11:58:30 +01:00
$mark_rate = ( isset ( $_POST [ " np_markRate " ]) ? $_POST [ " np_markRate " ] : price ( $line -> marque_tx ));
2013-09-24 17:49:56 +02:00
// if credit note, dont allow to modify margin
if ( $line -> subprice < 0 )
2013-12-01 19:39:21 +01:00
echo '<td align="right" class="nowrap">' . $mark_rate . '<span class="hideonsmartphone">%</span></td>' ;
2013-09-24 17:49:56 +02:00
else
2014-03-07 11:58:30 +01:00
echo '<td align="right" class="nowrap"><input type="text" size="2" name="np_markRate" value="' . $mark_rate . '"><span class="hideonsmartphone">%</span></td>' ;
2013-08-22 11:39:55 +02:00
$coldisplay ++ ;
}
}
} ?>
2012-08-23 13:45:51 +02:00
2014-03-07 11:58:30 +01:00
<!-- colspan = 4 for this td because it replace total_ht + 3 td for buttons -->
< td align = " center " colspan = " 4 " valign = " middle " >< ? php $coldisplay += 4 ; ?>
2012-08-23 13:45:51 +02:00
< input type = " submit " class = " button " id = " savelinebutton " name = " save " value = " <?php echo $langs->trans ( " Save " ); ?> " >< br >
< input type = " submit " class = " button " id = " cancellinebutton " name = " cancel " value = " <?php echo $langs->trans ( " Cancel " ); ?> " >
</ td >
2013-06-10 16:05:41 +02:00
< ? php
//Line extrafield
if ( ! empty ( $extrafieldsline )) {
print $line -> showOptionals ( $extrafieldsline , 'edit' , array ( 'style' => $bc [ $var ], 'colspan' => $coldisplay ));
}
?>
2012-08-23 13:45:51 +02:00
</ tr >
2012-09-19 12:02:06 +02:00
< ? php if ( ! empty ( $conf -> service -> enabled ) && $line -> product_type == 1 && $dateSelector ) { ?>
2012-08-23 13:45:51 +02:00
< tr id = " service_duration_area " < ? php echo $bc [ $var ]; ?> >
< td colspan = " 11 " >< ? php echo $langs -> trans ( 'ServiceLimitedDuration' ) . ' ' . $langs -> trans ( 'From' ) . ' ' ; ?>
< ? php
2012-09-07 11:40:59 +02:00
$hourmin = ( isset ( $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE ) ? $conf -> global -> MAIN_USE_HOURMIN_IN_DATE_RANGE : '' );
echo $form -> select_date ( $line -> date_start , 'date_start' , $hourmin , $hourmin , $line -> date_start ? 0 : 1 , " updateligne " );
2012-08-23 13:45:51 +02:00
echo ' ' . $langs -> trans ( 'to' ) . ' ' ;
2012-09-07 11:40:59 +02:00
echo $form -> select_date ( $line -> date_end , 'date_end' , $hourmin , $hourmin , $line -> date_end ? 0 : 1 , " updateligne " );
2012-08-23 13:45:51 +02:00
?>
</ td >
</ tr >
< ? php } ?>
< script type = " text/javascript " >
2013-11-17 23:25:25 +01:00
< ? php
if ( $conf -> global -> MAIN_FEATURES_LEVEL > 1 ) // TODO A virer
{
?>
jQuery ( document ) . ready ( function () {
2012-08-27 19:11:44 +02:00
2012-08-23 13:45:51 +02:00
if ( $ ( '#product_type' ) . val () == 0 ) {
$ ( '#service_duration_area' ) . hide ();
} else if ( $ ( '#product_type' ) . val () == 1 ) {
$ ( '#service_duration_area' ) . show ();
}
if ( $ ( '#product_label' ) . attr ( 'disabled' )) {
$ ( '#update_label_area' ) . show ();
}
$ ( '#update_label_checkbox' ) . change ( function () {
if ( $ ( this ) . attr ( 'checked' )) {
$ ( '#product_label' ) . removeAttr ( 'disabled' ) . focus ();
} else {
2012-08-25 03:28:30 +02:00
$ ( '#product_label' )
. attr ( 'disabled' , 'disabled' )
. val ( $ ( '#origin_label_cache' ) . val ());
2012-08-23 13:45:51 +02:00
}
});
$ ( '#select_type' ) . change ( function () {
var type = $ ( this ) . val ();
if ( type >= 0 ) {
if ( type == 0 ) {
$ ( '#service_duration_area' ) . hide ();
$ ( '#date_start' ) . val ( '' ) . trigger ( 'change' );
$ ( '#date_end' ) . val ( '' ) . trigger ( 'change' );
} else if ( type == 1 ) {
$ ( '#service_duration_area' ) . show ();
}
2012-08-28 16:11:40 +02:00
var addline = false ;
if ( $ ( '#price_ht' ) . val () . length > 0 ) {
if ( $ ( '#product_id' ) . val () == 0 ) {
if ( typeof CKEDITOR == 'object' && typeof CKEDITOR . instances != 'undefined' && CKEDITOR . instances [ 'product_desc' ] != 'undefined' ) {
var content = CKEDITOR . instances [ 'product_desc' ] . getData ();
} else {
var content = $ ( '#product_desc' ) . val ();
}
if ( content . length > 0 ) {
addline = true ;
}
} else {
addline = true ;
}
}
if ( addline ) {
2012-08-23 13:45:51 +02:00
$ ( '#savelinebutton' ) . removeAttr ( 'disabled' );
} else {
$ ( '#savelinebutton' ) . attr ( 'disabled' , 'disabled' );
}
} else {
$ ( '#savelinebutton' ) . attr ( 'disabled' , 'disabled' );
$ ( '#service_duration_area' ) . hide ();
$ ( '#date_start' ) . val ( '' ) . trigger ( 'change' );
$ ( '#date_end' ) . val ( '' ) . trigger ( 'change' );
}
});
2012-08-25 03:28:30 +02:00
$ ( '#price_ht' ) . focusin ( function () {
2012-08-28 16:11:40 +02:00
$ ( '#price_base_type' ) . val ( 'HT' );
2012-08-25 03:28:30 +02:00
});
2012-08-28 16:11:40 +02:00
$ ( '#price_ht' ) . bind ( 'change keyup input' , function () {
if ( $ ( '#price_base_type' ) . val () == 'HT' ) {
update_price ( 'price_ht' , 'price_ttc' );
2012-08-23 13:45:51 +02:00
}
});
2012-08-25 03:28:30 +02:00
$ ( '#price_ttc' ) . focusin ( function () {
2012-08-28 16:11:40 +02:00
$ ( '#price_base_type' ) . val ( 'TTC' );
2012-08-25 03:28:30 +02:00
});
2012-08-28 16:11:40 +02:00
$ ( '#price_ttc' ) . bind ( 'change keyup input' , function () {
if ( $ ( '#price_base_type' ) . val () == 'TTC' ) {
update_price ( 'price_ttc' , 'price_ht' );
}
});
if ( $ ( '#tva_tx' ) . val () == 0 ) {
$ ( '#price_ttc' ) . attr ( 'disabled' , 'disabled' );
}
$ ( '#tva_tx' ) . change ( function () {
if ( $ ( this ) . val () == 0 ) {
$ ( '#price_ttc' ) . attr ( 'disabled' , 'disabled' );
$ ( '#price_ttc' ) . val ( '' );
} else {
$ ( '#price_ttc' ) . removeAttr ( 'disabled' );
if ( $ ( '#price_base_type' ) . val () == 'HT' ) {
update_price ( 'price_ht' , 'price_ttc' );
} else if ( $ ( '#price_base_type' ) . val () == 'TTC' ) {
update_price ( 'price_ttc' , 'price_ht' );
}
}
});
2013-11-17 23:25:25 +01:00
// update_price
function update_price ( input , output )
{
2012-08-28 16:11:40 +02:00
$ . post ( '<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php' , {
'amount' : $ ( '#' + input ) . val (),
'output' : output ,
'tva_tx' : $ ( '#tva_tx' ) . val ()
},
function ( data ) {
var addline = false ;
if ( typeof data [ output ] != 'undefined' ) {
// Hide price_ttc if no vat
if ( $ ( '#tva_tx' ) . val () > 0 || ( $ ( '#tva_tx' ) . val () == 0 && output == 'price_ht' )) {
$ ( '#' + output ) . val ( data [ output ]);
}
if ( $ ( '#product_id' ) . val () == 0 && $ ( '#select_type' ) . val () >= 0 ) {
if ( typeof CKEDITOR == 'object' && typeof CKEDITOR . instances != 'undefined' && CKEDITOR . instances [ 'product_desc' ] != 'undefined' ) {
var content = CKEDITOR . instances [ 'product_desc' ] . getData ();
2012-08-23 13:45:51 +02:00
} else {
2012-08-28 16:11:40 +02:00
var content = $ ( '#product_desc' ) . val ();
}
if ( content . length > 0 ) {
addline = true ;
2012-08-23 13:45:51 +02:00
}
} else {
2012-08-28 16:11:40 +02:00
addline = true ;
2012-08-23 13:45:51 +02:00
}
2012-08-28 16:11:40 +02:00
} else {
$ ( '#' + input ) . val ( '' );
$ ( '#' + output ) . val ( '' );
}
if ( addline ) {
$ ( '#savelinebutton' ) . removeAttr ( 'disabled' );
} else {
$ ( '#savelinebutton' ) . attr ( 'disabled' , 'disabled' );
}
}, 'json' );
}
2012-08-23 13:45:51 +02:00
2012-08-28 16:11:40 +02:00
// Check if decription is not empty for free line
< ? php if ( ! empty ( $conf -> fckeditor -> enabled ) && ! empty ( $conf -> global -> FCKEDITOR_ENABLE_DETAILS )) { ?>
CKEDITOR . on ( 'instanceReady' , function () {
CKEDITOR . instances [ 'product_desc' ] . on ( 'key' , function () {
var addline = false ;
if ( $ ( '#product_id' ) . val () == 0 && $ ( '#select_type' ) . val () >= 0 && $ ( '#price_ht' ) . val () . length > 0 ) {
var content = CKEDITOR . instances [ 'product_desc' ] . getData ();
if ( content . length > 0 ) {
addline = true ;
2012-08-25 03:28:30 +02:00
}
2012-08-28 16:11:40 +02:00
} else if ( $ ( '#product_id' ) . val () > 0 && $ ( '#price_ht' ) . val () . length > 0 ) {
addline = true ;
}
if ( addline ) {
$ ( '#savelinebutton' ) . removeAttr ( 'disabled' );
} else {
$ ( '#savelinebutton' ) . attr ( 'disabled' , 'disabled' );
}
});
});
< ? php } else { ?>
$ ( '#product_desc' ) . onDelayedKeyup ({
'handler' : function () {
var addline = false ;
if ( $ ( '#product_id' ) . val () == 0 && $ ( '#select_type' ) . val () >= 0 && $ ( '#price_ht' ) . val () . length > 0 ) {
var content = $ ( '#product_desc' ) . val ();
if ( content . length > 0 ) {
addline = true ;
2012-08-25 03:28:30 +02:00
}
2012-08-28 16:11:40 +02:00
} else if ( $ ( '#product_id' ) . val () > 0 && $ ( '#price_ht' ) . val () . length > 0 ) {
addline = true ;
}
if ( addline ) {
$ ( '#savelinebutton' ) . removeAttr ( 'disabled' );
} else {
$ ( '#savelinebutton' ) . attr ( 'disabled' , 'disabled' );
}
2012-08-25 03:28:30 +02:00
}
2012-08-23 13:45:51 +02:00
});
2012-08-27 19:11:44 +02:00
< ? php } ?>
2012-08-23 13:45:51 +02:00
2013-11-17 23:25:25 +01:00
});
2012-08-28 16:11:40 +02:00
2013-11-17 23:25:25 +01:00
< ? php } // End MAIN_LEVEL_FEATURES > 1 ?>
< ? php
if ( ! empty ( $conf -> margin -> enabled ))
{
?>
jQuery ( document ) . ready ( function ()
{
2014-03-07 11:58:30 +01:00
/* Add rule to clear margin when we change price_ht or buying_price, so when we change sell or buy price, margin will be recalculated after submitting form */
jQuery ( " #price_ht " ) . keyup ( function () {
jQuery ( " input[name='np_marginRate']:first " ) . val ( '' );
jQuery ( " input[name='np_markRate']:first " ) . val ( '' );
});
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 */
2013-11-17 23:25:25 +01:00
$ . post ( '<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php' , { 'idprod' : < ? php echo $line -> fk_product ? $line -> fk_product : 0 ; ?> }, function(data) {
2012-09-19 12:02:06 +02: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' );
2013-08-22 11:39:55 +02:00
2014-03-07 11:58:30 +01:00
/* Add rules to reset price_ht from margin info */
2013-11-17 23:25:25 +01:00
< ? php
if ( ! empty ( $conf -> global -> DISPLAY_MARGIN_RATES ))
{
?>
$ ( '#savelinebutton' ) . click ( function ( e ) {
return checkEditLine ( e , " marginRate " );
});
$ ( " input[name='np_marginRate']:first " ) . blur ( function ( e ) {
return checkEditLine ( e , " marginRate " );
});
< ? php
}
if ( ! empty ( $conf -> global -> DISPLAY_MARK_RATES ))
{
?>
$ ( '#savelinebutton' ) . click ( function ( e ) {
return checkEditLine ( e , " markRate " );
});
$ ( " input[name='np_markRate']:first " ) . blur ( function ( e ) {
return checkEditLine ( e , " markRate " );
});
< ? php
}
?>
2013-08-22 11:39:55 +02:00
});
2014-03-07 11:58:30 +01:00
/* If margin rate field empty, do nothing. */
/* Force content of price_ht to 0 or if a discount is set recalculate it from margin rate */
2013-11-17 23:25:25 +01:00
function checkEditLine ( e , npRate )
2013-08-22 11:39:55 +02:00
{
2013-11-17 23:25:25 +01:00
var buying_price = $ ( " input[name='buying_price']:first " );
var remise = $ ( " input[name='remise_percent']:first " );
2013-08-22 11:39:55 +02:00
2013-11-17 23:25:25 +01:00
var rate = $ ( " input[name=' " + npRate + " ']:first " );
2014-03-07 11:58:30 +01:00
if ( rate . val () == '' ) return true ;
2013-11-17 23:25:25 +01:00
if ( ! $ . isNumeric ( rate . val () . replace ( ',' , '.' )))
{
alert ( '<?php echo $langs->trans("rateMustBeNumeric"); ?>' );
e . stopPropagation ();
setTimeout ( function () { rate . focus () }, 50 );
return false ;
}
if ( npRate == " markRate " && rate . val () >= 100 )
{
alert ( '<?php echo $langs->trans("markRateShouldBeLesserThan100"); ?>' );
e . stopPropagation ();
setTimeout ( function () { rate . focus () }, 50 );
return false ;
}
var price = 0 ;
2014-02-16 19:42:43 +01:00
remisejs = price2numjs ( remise . val ());
if ( remisejs != 100 )
2013-11-17 23:25:25 +01:00
{
2014-02-16 19:26:41 +01:00
bpjs = price2numjs ( buying_price . val ());
ratejs = price2numjs ( rate . val ());
2013-11-17 23:25:25 +01:00
if ( npRate == " marginRate " )
2014-02-16 19:26:41 +01:00
price = (( bpjs * ( 1 + ratejs / 100 )) / ( 1 - remisejs / 100 ));
else if ( npRate == " markRate " )
price = (( bpjs / ( 1 - ratejs / 100 )) / ( 1 - remisejs / 100 ));
2013-08-22 11:39:55 +02:00
}
2014-02-16 19:26:41 +01:00
$ ( " input[name='price_ht']:first " ) . val ( price ); // TODO Must use a function like php price to have here a formated value
2013-11-17 23:25:25 +01:00
return true ;
2013-08-22 11:39:55 +02:00
}
2014-02-16 19:26:41 +01:00
/* Function similar to price2num in PHP */
function price2numjs ( num )
{
< ? php
$dec = ',' ; $thousand = ' ' ;
if ( $langs -> transnoentitiesnoconv ( " SeparatorDecimal " ) != " SeparatorDecimal " ) $dec = $langs -> transnoentitiesnoconv ( " SeparatorDecimal " );
if ( $langs -> transnoentitiesnoconv ( " SeparatorThousand " ) != " SeparatorThousand " ) $thousand = $langs -> transnoentitiesnoconv ( " SeparatorThousand " );
if ( $thousand == 'None' ) $thousand = '' ;
print " var dec=' " . $dec . " '; var thousand=' " . $thousand . " '; \n " ;
?>
2013-11-17 23:25:25 +01:00
var main_max_dec_shown = < ? php echo $conf -> global -> MAIN_MAX_DECIMALS_SHOWN ; ?> ;
2014-02-16 19:26:41 +01:00
var main_rounding_unit = < ? php echo $conf -> global -> MAIN_MAX_DECIMALS_UNIT ; ?> ;
var main_rounding_tot = < ? php echo $conf -> global -> MAIN_MAX_DECIMALS_TOT ; ?> ;
var amount = num . toString ();
2013-11-17 23:25:25 +01:00
2014-02-16 19:26:41 +01:00
// rounding for unit price
var rounding = main_rounding_unit ;
var pos = amount . indexOf ( dec );
2013-11-17 23:25:25 +01:00
var decpart = '' ;
2014-02-16 19:26:41 +01:00
if ( pos >= 0 ) decpart = amount . substr ( pos + 1 ) . replace ( '/0+$/i' , '' ); // Supprime les 0 de fin de partie decimale
var nbdec = decpart . length ;
if ( nbdec > rounding ) rounding = nbdec ;
// If rounding higher than max shown
if ( rounding > main_max_dec_shown ) rounding = main_max_dec_shown ;
if ( thousand != ',' && thousand != '.' ) amount = amount . replace ( ',' , '.' );
amount = amount . replace ( ' ' , '' ); // To avoid spaces
amount = amount . replace ( thousand , '' ); // Replace of thousand before replace of dec to avoid pb if thousand is .
amount = amount . replace ( dec , '.' );
2013-11-17 23:25:25 +01:00
return parseFloat ( amount ) . toFixed ( rounding );
}
2013-08-22 11:39:55 +02:00
2013-11-17 23:25:25 +01:00
< ? php
2013-08-22 11:39:55 +02:00
}
2013-11-17 23:25:25 +01: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 -->