Clean code

This commit is contained in:
Laurent Destailleur 2022-08-26 17:57:17 +02:00
parent af69270a0e
commit bfb01ae928
5 changed files with 62 additions and 26 deletions

View File

@ -899,6 +899,7 @@ if (empty($reshook)) {
$price_ht_devise = '';
$price_ttc = '';
$price_ttc_devise = '';
if (GETPOST('price_ht') !== '') {
$price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
}
@ -1319,7 +1320,7 @@ if (empty($reshook)) {
$buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
//$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
$date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
$date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
@ -1403,7 +1404,14 @@ if (empty($reshook)) {
$qty = price2num(GETPOST('qty', 'alpha'), 'MS');
$result = $object->updateline(GETPOST('lineid', 'int'), $pu_ht, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $description, 'HT', $info_bits, $special_code, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $type, $date_start, $date_end, $array_options, GETPOST("units"), $pu_ht_devise);
$pu = $pu_ht;
$price_base_type = 'HT';
if (empty($pu) && ! empty($pu_ttc)) {
$pu = $pu_ttc;
$price_base_type = 'TTC';
}
$result = $object->updateline(GETPOST('lineid', 'int'), $pu, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $description, $price_base_type, $info_bits, $special_code, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $type, $date_start, $date_end, $array_options, GETPOST("units"), $pu_ht_devise);
if ($result >= 0) {
$db->commit();
@ -2717,7 +2725,7 @@ if ($action == 'create') {
* Lines
*/
// Show object lines
// Get object lines
$result = $object->getLinesArray();
// Add products/services form
@ -2725,7 +2733,7 @@ if ($action == 'create') {
global $inputalsopricewithtax;
$inputalsopricewithtax = 1;
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">
<input type="hidden" name="token" value="' . newToken().'">
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
<input type="hidden" name="mode" value="">

View File

@ -932,9 +932,6 @@ class Propal extends CommonObject
$this->line->date_start = $date_start;
$this->line->date_end = $date_end;
// TODO deprecated
$this->line->price = $price;
if (is_array($array_options) && count($array_options) > 0) {
// We replace values in this->line->array_options only for entries defined into $array_options
foreach ($array_options as $key => $value) {

View File

@ -1058,12 +1058,14 @@ if (empty($reshook)) {
$description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml'));
$vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx', 'alpha') : 0);
$vat_rate = str_replace('*', '', $vat_rate);
$pu_ht = price2num(GETPOST('price_ht'), '', 2);
$pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
//$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
$qty = price2num(GETPOST('qty'), 'MS');
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
$qty = price2num(GETPOST('qty', 'alpha'), 'MS');
// Define info_bits
$info_bits = 0;
@ -1158,7 +1160,15 @@ if (empty($reshook)) {
}
}
}
$result = $object->updateline(GETPOST('lineid', 'int'), $description, $pu_ht, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $info_bits, $date_start, $date_end, $type, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options, GETPOST('units'), $pu_ht_devise);
$price_base_type = 'HT';
$pu = $pu_ht;
if (empty($pu) && ! empty($pu_ttc)) {
$pu = $pu_ttc;
$price_base_type = 'TTC';
}
$result = $object->updateline(GETPOST('lineid', 'int'), $description, $pu, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $price_base_type, $info_bits, $date_start, $date_end, $type, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options, GETPOST('units'), $pu_ht_devise);
if ($result >= 0) {
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
@ -2701,9 +2711,16 @@ if ($action == 'create' && $usercancreate) {
/*
* Lines
*/
// Get object lines
$result = $object->getLinesArray();
print '<form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
// Add products/services form
//$forceall = 1;
global $inputalsopricewithtax;
$inputalsopricewithtax = 1;
print '<form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">
<input type="hidden" name="token" value="' . newToken().'">
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
<input type="hidden" name="mode" value="">

View File

@ -2068,7 +2068,7 @@ if (empty($reshook)) {
$error++;
}
if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && (($price_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $price_ht == '') && (($price_ht_devise < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $price_ht_devise == '') && $price_ttc === '' && $price_ttc_devise === '' && $object->type != Facture::TYPE_CREDIT_NOTE) { // Unit price can be 0 but not ''
if ($price_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
if (($price_ht < 0 || $price_ttc < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
$langs->load("errors");
if ($object->type == $object::TYPE_DEPOSIT) {
// Using negative lines on deposit lead to headach and blocking problems when you want to consume them.
@ -2405,12 +2405,14 @@ if (empty($reshook)) {
$description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml') ? GETPOST('product_desc', 'restricthtml') : GETPOST('desc', 'restricthtml'));
$vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
$vat_rate = str_replace('*', '', $vat_rate);
$pu_ht = price2num(GETPOST('price_ht'), '', 2);
$pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
//$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
$qty = GETPOST('qty');
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
$qty = price2num(GETPOST('qty', 'alpha'), 'MS');
// Define info_bits
$info_bits = 0;
@ -2519,8 +2521,8 @@ if (empty($reshook)) {
setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors');
$error++;
}
if ((empty($productid) && (($pu_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $pu_ht == '') && $pu_ht_devise == '') && $object->type != Facture::TYPE_CREDIT_NOTE) { // Unit price can be 0 but not ''
if ($pu_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
if (empty($productid) && (($pu_ht < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $pu_ht == '') && (($pu_ht_devise < 0 && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) || $pu_ht_devise == '') && $pu_ttc === '' && $pu_ttc_devise === '' && $object->type != Facture::TYPE_CREDIT_NOTE) { // Unit price can be 0 but not ''
if (($pu_ht < 0 || $pu_ttc < 0) && empty($conf->global->FACTURE_ENABLE_NEGATIVE_LINES)) {
$langs->load("errors");
if ($object->type == $object::TYPE_DEPOSIT) {
// Using negative lines on deposit lead to headach and blocking problems when you want to consume them.
@ -2548,10 +2550,17 @@ if (empty($reshook)) {
}
}
$price_base_type = 'HT';
$pu = $pu_ht;
if (empty($pu) && ! empty($pu_ttc)) {
$pu = $pu_ttc;
$price_base_type = 'TTC';
}
$result = $object->updateline(
GETPOST('lineid', 'int'),
$description,
$pu_ht,
$pu,
$qty,
$remise_percent,
$date_start,
@ -2559,7 +2568,7 @@ if (empty($reshook)) {
$vat_rate,
$localtax1_rate,
$localtax2_rate,
'HT',
$price_base_type,
$info_bits,
$type,
GETPOST('fk_parent_line', 'int'),
@ -5342,10 +5351,15 @@ if ($action == 'create') {
include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
}
// Lines
// Get object lines
$result = $object->getLinesArray();
// Show global modifiers
// Add products/services form
//$forceall = 1;
global $inputalsopricewithtax;
$inputalsopricewithtax = 1;
// Show global modifiers for situation invoices
if (!empty($conf->global->INVOICE_USE_SITUATION)) {
if ($object->situation_cycle_ref && $object->statut == 0) {
print '<!-- Area to change globally the situation percent -->'."\n";
@ -5387,7 +5401,7 @@ if ($action == 'create') {
}
}
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">
<input type="hidden" name="token" value="' . newToken().'">
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
<input type="hidden" name="mode" value="">

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2010-2020 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010-2022 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
@ -325,8 +325,8 @@ $coldisplay++;
<!-- colspan for this td because it replace total_ht+3 td for buttons+... -->
<td class="center valignmiddle" colspan="<?php echo $colspan; ?>"><?php $coldisplay += $colspan; ?>
<input type="submit" class="button buttongen marginbottomonly button-save" id="savelinebutton marginbottomonly" name="save" value="<?php echo $langs->trans("Save"); ?>"><br>
<input type="submit" class="button buttongen marginbottomonly button-cancel" id="cancellinebutton" name="cancel" value="<?php echo $langs->trans("Cancel"); ?>">
<input type="submit" class="reposition button buttongen marginbottomonly button-save" id="savelinebutton marginbottomonly" name="save" value="<?php echo $langs->trans("Save"); ?>"><br>
<input type="submit" class="reposition button buttongen marginbottomonly button-cancel" id="cancellinebutton" name="cancel" value="<?php echo $langs->trans("Cancel"); ?>">
</td>
</tr>