Qual: Clean and uniformize code

This commit is contained in:
Laurent Destailleur 2013-11-13 23:35:33 +01:00
parent cf3d6d410c
commit 2e5320a532
2 changed files with 254 additions and 239 deletions

View File

@ -39,9 +39,9 @@ if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($ob
<input type="hidden" name="id" value="<?php echo $this->id; ?>"> <input type="hidden" name="id" value="<?php echo $this->id; ?>">
<tr class="liste_titre nodrag nodrop"> <tr class="liste_titre nodrag nodrop">
<td <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>>
<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>><div <div id="add"></div>
id="add"></div> <span class="hideonsmartphone"><?php echo $langs->trans('AddNewLine').' - ' ?></span><?php echo $langs->trans("FreeZone"); ?> <span class="hideonsmartphone"><?php echo $langs->trans('AddNewLine').' - ' ?></span><?php echo $langs->trans("FreeZone"); ?>
</td> </td>
<td align="right"><?php echo $langs->trans('VAT'); ?></td> <td align="right"><?php echo $langs->trans('VAT'); ?></td>
<td align="right"><?php echo $langs->trans('PriceUHT'); ?></td> <td align="right"><?php echo $langs->trans('PriceUHT'); ?></td>
@ -83,36 +83,36 @@ if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($ob
</tr> </tr>
<tr <?php echo $bcnd[$var]; ?>> <tr <?php echo $bcnd[$var]; ?>>
<?php <?php
if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
$coldisplay=2; } $coldisplay=2; }
else { else {
$coldisplay=0; } $coldisplay=0; }
?> ?>
<td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>> <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>>
<?php <?php
echo '<span>'; echo '<span>';
echo $form->select_type_of_lines(isset($_POST["type"])?$_POST["type"]:-1,'type',1); echo $form->select_type_of_lines(isset($_POST["type"])?$_POST["type"]:-1,'type',1);
echo '</span>'; echo '</span>';
if (is_object($hookmanager)) if (is_object($hookmanager))
{ {
$parameters=array(); $parameters=array('fk_parent_line'=>GETPOST('fk_parent_line','int'));
$reshook=$hookmanager->executeHooks('formCreateProductOptions',$parameters,$object,$action); $reshook=$hookmanager->executeHooks('formCreateProductOptions',$parameters,$object,$action);
} }
if ((! empty($conf->product->enabled) && ! empty($conf->service->enabled)) || (empty($conf->product->enabled) && empty($conf->service->enabled))) echo '<br>'; if ((! empty($conf->product->enabled) && ! empty($conf->service->enabled)) || (empty($conf->product->enabled) && empty($conf->service->enabled))) echo '<br>';
// Editor wysiwyg // Editor wysiwyg
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$nbrows=ROWS_2; $nbrows=ROWS_2;
$enabled=(! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0); $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; if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
$doleditor=new DolEditor('dp_desc',GETPOST('dp_desc'),'',100,'dolibarr_details','',false,true,$enabled,$nbrows,70); $doleditor=new DolEditor('dp_desc',GETPOST('dp_desc'),'',100,'dolibarr_details','',false,true,$enabled,$nbrows,70);
$doleditor->Create(); $doleditor->Create();
?> ?>
</td> </td>
<td align="right"><?php <td align="right"><?php
@ -120,8 +120,7 @@ if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($ob
else echo $form->load_tva('tva_tx', (isset($_POST["tva_tx"])?$_POST["tva_tx"]:-1), $seller, $buyer); else echo $form->load_tva('tva_tx', (isset($_POST["tva_tx"])?$_POST["tva_tx"]:-1), $seller, $buyer);
?> ?>
</td> </td>
<td align="right"><input type="text" size="5" name="price_ht" class="flat" value="<?php echo (isset($_POST["price_ht"])?$_POST["price_ht"]:''); ?>"> <td align="right"><input type="text" size="5" name="price_ht" class="flat" value="<?php echo (isset($_POST["price_ht"])?$_POST["price_ht"]:''); ?>"></td>
</td>
<td align="right"><input type="text" size="2" name="qty" class="flat" value="<?php echo (isset($_POST["qty"])?$_POST["qty"]:1); ?>"></td> <td align="right"><input type="text" size="2" name="qty" class="flat" value="<?php echo (isset($_POST["qty"])?$_POST["qty"]:1); ?>"></td>
<td align="right" class="nowrap"><input type="text" size="1" class="flat" value="<?php echo (isset($_POST["remise_percent"])?$_POST["remise_percent"]:$buyer->remise_client); ?>" name="remise_percent"><span class="hideonsmartphone">%</span></td> <td align="right" class="nowrap"><input type="text" size="1" class="flat" value="<?php echo (isset($_POST["remise_percent"])?$_POST["remise_percent"]:$buyer->remise_client); ?>" name="remise_percent"><span class="hideonsmartphone">%</span></td>
<?php <?php
@ -129,8 +128,8 @@ if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($ob
if (! empty($usemargins)) if (! empty($usemargins))
{ {
?> ?>
<td align="right"><input type="text" size="5" name="buying_price" class="flat" <td align="right">
value="<?php echo (isset($_POST["buying_price"])?$_POST["buying_price"]:''); ?>"> <input type="text" size="5" name="buying_price" class="flat" value="<?php echo (isset($_POST["buying_price"])?$_POST["buying_price"]:''); ?>">
</td> </td>
<?php <?php
if ($user->rights->margins->creer) if ($user->rights->margins->creer)
@ -155,21 +154,25 @@ if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($ob
} }
} }
?> ?>
<td align="center" valign="middle" colspan="<?php echo $colspan; ?>"><input type="submit" class="button" value="<?php echo $langs->trans('Add'); ?>" name="addline"></td> <td align="center" valign="middle" colspan="<?php echo $colspan; ?>">
<?php <input type="submit" class="button" value="<?php echo $langs->trans('Add'); ?>" name="addline_libre">
//Line extrafield </td>
if (!empty($extrafieldsline)) { <?php
if ($this->table_element_line=='commandedet') { //Line extrafield
$newline = new OrderLine($this->db); if (!empty($extrafieldsline)) {
}elseif ($this->table_element_line=='propaldet') { if ($this->table_element_line=='commandedet') {
$newline = new PropaleLigne($this->db); $newline = new OrderLine($this->db);
}elseif ($this->table_element_line=='facturedet') {
$newline = new FactureLigne($this->db);
}
if (is_object($newline)) {
print $newline->showOptionals($extrafieldsline,'edit',array('style'=>$bcnd[$var],'colspan'=>$coldisplay+8));
}
} }
elseif ($this->table_element_line=='propaldet') {
$newline = new PropaleLigne($this->db);
}
elseif ($this->table_element_line=='facturedet') {
$newline = new FactureLigne($this->db);
}
if (is_object($newline)) {
print $newline->showOptionals($extrafieldsline,'edit',array('style'=>$bcnd[$var],'colspan'=>$coldisplay+8));
}
}
?> ?>
</tr> </tr>
@ -182,13 +185,14 @@ if (! empty($conf->service->enabled) && $dateSelector)
if (! empty($usemargins)) if (! empty($usemargins))
{ {
$colspan++; // For the buying price $colspan++; // For the buying price
if($conf->global->DISPLAY_MARGIN_RATES) $colspan++; if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
if($conf->global->DISPLAY_MARK_RATES) $colspan++; if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
} }
?> ?>
<tr <?php echo $bcnd[$var]; ?>> <tr <?php echo $bcnd[$var]; ?>>
<td colspan="<?php echo $colspan; ?>"><?php <td colspan="<?php echo $colspan; ?>">
<?php
if (! empty($object->element) && $object->element == 'contrat') if (! empty($object->element) && $object->element == 'contrat')
{ {
print $langs->trans("DateStartPlanned").' '; print $langs->trans("DateStartPlanned").' ';
@ -212,101 +216,108 @@ if (! empty($conf->service->enabled) && $dateSelector)
</form> </form>
<?php if ($conf->margin->enabled && $user->rights->margins->creer)
{
?>
<script type="text/javascript">
var npRate = null;
<?php <?php
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { ?> if (! empty($usemargins) && $user->rights->margins->creer)
npRate = "np_marginRate";
<?php }
elseif (! empty($conf->global->DISPLAY_MARK_RATES)) { ?>
npRate = "np_markRate";
<?php }
?>
$("form#addproduct").submit(function(e) {
if (npRate) return checkFreeLine(e, npRate);
else return true;
});
if (npRate == 'np_marginRate') {
$("input[name='np_marginRate']:first").blur(function(e) {
return checkFreeLine(e, npRate);
});
}
else {
if (npRate == 'np_markRate') {
$("input[name='np_markRate']:first").blur(function(e) {
return checkFreeLine(e, npRate);
});
}
}
function checkFreeLine(e, npRate)
{ {
var buying_price = $("input[name='buying_price']:first"); ?>
var remise = $("input[name='remise_percent']:first"); <script type="text/javascript">
var rate = $("input[name='"+npRate+"']:first"); jQuery(document).ready(function() {
if (rate.val() == '') var npRate = null;
return true; <?php
if (! $.isNumeric(rate.val().replace(',','.'))) if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
{ npRate = "np_marginRate";
alert('<?php echo $langs->trans("rateMustBeNumeric"); ?>'); <?php }
e.stopPropagation(); elseif (! empty($conf->global->DISPLAY_MARK_RATES)) { ?>
setTimeout(function () { rate.focus() }, 50); npRate = "np_markRate";
return false; <?php }
} ?>
if (npRate == "np_markRate" && rate.val() >= 100)
{
alert('<?php echo $langs->trans("markRateShouldBeLesserThan100"); ?>');
e.stopPropagation();
setTimeout(function () { rate.focus() }, 50);
return false;
}
var np_price = 0; $("form#addproduct").submit(function(e) {
if (remise.val().replace(',','.') != 100) if (npRate) return checkFreeLine(e, npRate);
{ else return true;
if (npRate == "np_marginRate") });
np_price = ((buying_price.val().replace(',','.') * (1 + rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100)); if (npRate == 'np_marginRate') {
else { $("input[name='np_marginRate']:first").blur(function(e) {
if (npRate == "np_markRate") return checkFreeLine(e, npRate);
np_price = ((buying_price.val().replace(',','.') / (1 - rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100)); });
} }
else {
if (npRate == 'np_markRate') {
$("input[name='np_markRate']:first").blur(function(e) {
return checkFreeLine(e, npRate);
});
}
}
});
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;
if (! $.isNumeric(rate.val().replace(',','.')))
{
alert('<?php echo $langs->trans("rateMustBeNumeric"); ?>');
e.stopPropagation();
setTimeout(function () { rate.focus() }, 50);
return false;
}
if (npRate == "np_markRate" && rate.val() >= 100)
{
alert('<?php echo $langs->trans("markRateShouldBeLesserThan100"); ?>');
e.stopPropagation();
setTimeout(function () { rate.focus() }, 50);
return false;
}
var np_price = 0;
if (remise.val().replace(',','.') != 100)
{
if (npRate == "np_marginRate")
np_price = ((buying_price.val().replace(',','.') * (1 + rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100));
else {
if (npRate == "np_markRate")
np_price = ((buying_price.val().replace(',','.') / (1 - rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100));
}
}
$("input[name='price_ht']:first").val(formatFloat(np_price));
return true;
} }
$("input[name='price_ht']:first").val(formatFloat(np_price));
return true; function roundFloat(num) {
var main_max_dec_shown = <?php echo $conf->global->MAIN_MAX_DECIMALS_SHOWN; ?>;
var main_rounding = <?php echo min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?>;
var amount = num.toString().replace(',','.'); // should be useless
var nbdec = 0;
var rounding = main_rounding;
var pos = amount.indexOf('.');
var decpart = '';
if (pos >= 0)
decpart = amount.substr(pos+1).replace('/0+$/i',''); // Supprime les 0 de fin de partie decimale
nbdec = decpart.length;
if (nbdec > rounding)
rounding = nbdec;
// Si on depasse max
if (rounding > main_max_dec_shown)
{
rounding = main_max_dec_shown;
}
//amount = parseFloat(amount) + (1 / Math.pow(100, rounding)); // to avoid floating-point errors
return parseFloat(amount).toFixed(rounding);
}
function formatFloat(num) {
return roundFloat(num).replace('.', ',');
}
</script>
<?php
} }
function roundFloat(num) { ?>
var main_max_dec_shown = <?php echo $conf->global->MAIN_MAX_DECIMALS_SHOWN; ?>;
var main_rounding = <?php echo min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?>;
var amount = num.toString().replace(',','.'); // should be useless
var nbdec = 0;
var rounding = main_rounding;
var pos = amount.indexOf('.');
var decpart = '';
if (pos >= 0)
decpart = amount.substr(pos+1).replace('/0+$/i',''); // Supprime les 0 de fin de partie decimale
nbdec = decpart.length;
if (nbdec > rounding)
rounding = nbdec;
// Si on depasse max
if (rounding > main_max_dec_shown)
{
rounding = main_max_dec_shown;
}
//amount = parseFloat(amount) + (1 / Math.pow(100, rounding)); // to avoid floating-point errors
return parseFloat(amount).toFixed(rounding);
}
function formatFloat(num) {
return roundFloat(num).replace('.', ',');
}
</script>
<?php } ?>
<!-- END PHP TEMPLATE freeproductline_create.tpl.php --> <!-- END PHP TEMPLATE freeproductline_create.tpl.php -->

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com> /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2010-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr> * Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* *
@ -17,7 +17,6 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*
* Need to have following variables defined: * Need to have following variables defined:
* $conf * $conf
* $langs * $langs
@ -39,15 +38,6 @@ if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($ob
<input type="hidden" name="mode" value="predefined"> <input type="hidden" name="mode" value="predefined">
<input type="hidden" name="id" value="<?php echo $this->id; ?>"> <input type="hidden" name="id" value="<?php echo $this->id; ?>">
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#idprod').change(function() {
if (jQuery('#idprod').val() > 0) jQuery('#np_desc').focus();
});
});
</script>
<tr class="liste_titre nodrag nodrop"> <tr class="liste_titre nodrag nodrop">
<td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="4"' : ' colspan="3"'); ?>> <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="4"' : ' colspan="3"'); ?>>
<?php <?php
@ -59,50 +49,59 @@ jQuery(document).ready(function() {
</td> </td>
<td align="right"><?php echo $langs->trans('Qty'); ?></td> <td align="right"><?php echo $langs->trans('Qty'); ?></td>
<td align="right"><?php echo $langs->trans('ReductionShort'); ?></td> <td align="right"><?php echo $langs->trans('ReductionShort'); ?></td>
<?php
$colspan = 4;
if (! empty($usemargins))
{
?>
<td align="right">
<?php <?php
if ($conf->global->MARGIN_TYPE == "1") $colspan = 4;
echo $langs->trans('BuyingPrice'); if (! empty($usemargins))
else
echo $langs->trans('CostPrice');
if ($user->rights->margins->creer)
{ {
if(! empty($conf->global->DISPLAY_MARGIN_RATES)) ?>
<td align="right">
<?php
if ($conf->global->MARGIN_TYPE == "1")
echo $langs->trans('BuyingPrice');
else
echo $langs->trans('CostPrice');
?>
</td>
<?php
if ($user->rights->margins->creer)
{ {
echo '<td align="right">'.$langs->trans('MarginRate').'</td>'; if(! empty($conf->global->DISPLAY_MARGIN_RATES))
{
echo '<td align="right">'.$langs->trans('MarginRate').'</td>';
}
if(! empty($conf->global->DISPLAY_MARK_RATES))
{
echo '<td align="right">'.$langs->trans('MarkRate').'</td>';
}
} }
if(! empty($conf->global->DISPLAY_MARK_RATES)) else
{ {
echo '<td align="right">'.$langs->trans('MarkRate').'</td>'; if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
} }
} }
else
{
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++;
if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++;
}
?> ?>
</td>
<?php
}
?>
<td colspan="<?php echo $colspan; ?>">&nbsp;</td> <td colspan="<?php echo $colspan; ?>">&nbsp;</td>
</tr> </tr>
<tr <?php echo $bcnd[$var]; ?>> <tr <?php echo $bcnd[$var]; ?>>
<?php <?php
if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
$coldisplay=4; } $coldisplay=4; }
else { else {
$coldisplay=3; } $coldisplay=3; }
?> ?>
<td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="4"' : ' colspan="3"'); ?>> <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="4"' : ' colspan="3"'); ?>>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#idprod').change(function() {
if (jQuery('#idprod').val() > 0) jQuery('#np_desc').focus();
});
});
</script>
<?php <?php
echo '<span>'; echo '<span>';
@ -128,8 +127,9 @@ else {
$doleditor->Create(); $doleditor->Create();
?> ?>
</td> </td>
<td align="right"><input type="hidden" name="price_ht"><input type="text" size="2" name="qty" class="flat" value="1"></td> <td align="right"><input type="hidden" name="price_ht"><input type="text" size="2" name="qty" class="flat" value="1"></td>
<td align="right" nowrap><input type="text" size="1" class="flat" name="remise_percent" value="<?php echo $buyer->remise_percent; ?>"><span class="hideonsmartphone">%</span></td> <td align="right" class="nowrap"><input type="text" size="1" class="flat" name="remise_percent" value="<?php echo $buyer->remise_percent; ?>"><span class="hideonsmartphone">%</span></td>
<?php <?php
$colspan = 4; $colspan = 4;
if (! empty($usemargins)) if (! empty($usemargins))
@ -163,14 +163,15 @@ else {
} }
?> ?>
<td align="center" valign="middle" colspan="<?php echo $colspan; ?>"> <td align="center" valign="middle" colspan="<?php echo $colspan; ?>">
<input type="submit" class="button" value="<?php echo $langs->trans("Add"); ?>" name="addline"> <input type="submit" class="button" value="<?php echo $langs->trans('Add'); ?>" name="addline_predefined">
</td> </td>
<?php <?php
//Line extrafield //Line extrafield
if (!empty($extrafieldsline)) { if (!empty($extrafieldsline)) {
if ($this->table_element_line=='commandedet') { if ($this->table_element_line=='commandedet') {
$newline = new OrderLine($this->db); $newline = new OrderLine($this->db);
}elseif ($this->table_element_line=='propaldet') { }
elseif ($this->table_element_line=='propaldet') {
$newline = new PropaleLigne($this->db); $newline = new PropaleLigne($this->db);
} }
elseif ($this->table_element_line=='facturedet') { elseif ($this->table_element_line=='facturedet') {
@ -209,9 +210,9 @@ if (! empty($conf->service->enabled) && $dateSelector)
else else
{ {
echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' ';
echo $form->select_date('','date_start_predef',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,"addpredefinedproduct"); echo $form->select_date('','date_start_predef',empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?0:1,empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?0:1,1,"addpredefinedproduct");
echo ' '.$langs->trans('to').' '; echo ' '.$langs->trans('to').' ';
echo $form->select_date('','date_end_predef',$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,"addpredefinedproduct"); echo $form->select_date('','date_end_predef',empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?0:1,empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?0:1,1,"addpredefinedproduct");
} }
?> ?>
</td> </td>
@ -223,40 +224,39 @@ if (! empty($conf->service->enabled) && $dateSelector)
</form> </form>
<?php <?php
if (! empty($usemargins)) if (! empty($usemargins) && $user->rights->margins->creer)
{ {
?> ?>
<script type="text/javascript"> <script type="text/javascript">
<?php
if ($user->rights->margins->creer)
{
?>
var npRate = null;
<?php
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
npRate = "np_marginRate";
<?php }
elseif (! empty($conf->global->DISPLAY_MARK_RATES)) { ?>
npRate = "np_markRate";
<?php }
?>
$("form#addpredefinedproduct").submit(function(e) { jQuery(document).ready(function() {
if (npRate) return checkLine(e, npRate); var npRate = null;
else return true; <?php
}); if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
if (npRate == 'np_marginRate') { npRate = "np_marginRate";
$("input[name='np_marginRate']:last").blur(function(e) { <?php }
return checkLine(e, npRate); elseif (! empty($conf->global->DISPLAY_MARK_RATES)) { ?>
npRate = "np_markRate";
<?php }
?>
$("form#addpredefinedproduct").submit(function(e) {
if (npRate) return checkLine(e, npRate);
else return true;
}); });
} if (npRate == 'np_marginRate') {
else { $("input[name='np_marginRate']:last").blur(function(e) {
if (npRate == 'np_markRate') {
$("input[name='np_markRate']:last").blur(function(e) {
return checkLine(e, npRate); return checkLine(e, npRate);
}); });
} }
} else {
if (npRate == 'np_markRate') {
$("input[name='np_markRate']:last").blur(function(e) {
return checkLine(e, npRate);
});
}
}
});
function checkLine(e, npRate) function checkLine(e, npRate)
{ {
@ -295,6 +295,7 @@ if (! empty($usemargins))
return true; return true;
} }
function roundFloat(num) { function roundFloat(num) {
var main_max_dec_shown = <?php echo $conf->global->MAIN_MAX_DECIMALS_SHOWN; ?>; var main_max_dec_shown = <?php echo $conf->global->MAIN_MAX_DECIMALS_SHOWN; ?>;
var main_rounding = <?php echo min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?>; var main_rounding = <?php echo min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?>;
@ -321,40 +322,43 @@ if (! empty($usemargins))
function formatFloat(num) { function formatFloat(num) {
return roundFloat(num).replace('.', ','); return roundFloat(num).replace('.', ',');
} }
<?php
} jQuery(document).ready(function() {
?> $("#idprod").change(function()
$("#idprod").change(function() { {
$("#fournprice options").remove(); $("#fournprice options").remove();
$("#fournprice").hide(); $("#fournprice").hide();
$("#buying_price").val("").show(); $("#buying_price").val("").show();
$.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': $(this).val()}, function(data) { $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', { 'idprod': $(this).val() }, function(data) {
if (data && data.length > 0) { if (data && data.length > 0)
var options = ''; {
var i = 0; var options = '';
$(data).each(function() { var i = 0;
i++; $(data).each(function() {
options += '<option value="'+this.id+'" price="'+this.price+'"'; i++;
if (i == 1) { options += '<option value="'+this.id+'" price="'+this.price+'"';
options += ' selected'; if (i == 1) {
$("#buying_price").val(this.price); options += ' selected';
} $("#buying_price").val(this.price);
options += '>'+this.label+'</option>'; }
}); options += '>'+this.label+'</option>';
options += '<option value=""><?php echo $langs->trans("InputPrice"); ?></option>'; });
$("#buying_price").hide(); options += '<option value=""><?php echo $langs->trans("InputPrice"); ?></option>';
$("#fournprice").html(options).show(); $("#buying_price").hide();
$("#fournprice").change(function() { $("#fournprice").html(options).show();
var selval = $(this).find('option:selected').attr("price"); $("#fournprice").change(function() {
if (selval) var selval = $(this).find('option:selected').attr("price");
$("#buying_price").val(selval).hide(); if (selval)
else $("#buying_price").val(selval).hide();
$('#buying_price').show(); else
}); $('#buying_price').show();
} });
}, }
'json'); },
'json');
});
}); });
</script> </script>
<?php <?php
} }