From 61bf731d17367bd44b6d936c3ea2596f9dea9c53 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 30 Apr 2019 18:11:35 +0200 Subject: [PATCH] FIX Balance of td --- htdocs/core/class/commonobject.class.php | 2 +- htdocs/core/lib/pdf.lib.php | 5 +- htdocs/core/lib/price.lib.php | 24 ++--- htdocs/core/tpl/objectline_create.tpl.php | 101 ++++++++-------------- htdocs/core/tpl/objectline_edit.tpl.php | 6 +- htdocs/core/tpl/objectline_view.tpl.php | 9 +- htdocs/langs/en_US/main.lang | 1 + 7 files changed, 66 insertions(+), 82 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 8b20479a154..454936d2998 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3966,7 +3966,7 @@ abstract class CommonObject // Fields for situation invoice if ($this->situation_cycle_ref) { print '' . $langs->trans('Progress') . ''; - //print '' . $langs->trans('TotalHT100') . ''; + print '' . $langs->trans('TotalHT100Short') . ''; } if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id)) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 134cf7c8e5e..cc40fcb9272 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1954,6 +1954,7 @@ function pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails = 0) $total_ht = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_total_ht : $object->lines[$i]->total_ht); if ($object->lines[$i]->situation_percent > 0) { + // TODO Remove this. The total should be saved correctly in database instead of being modified here. $prev_progress = 0; $progress = 1; if (method_exists($object->lines[$i], 'get_prev_progress')) @@ -1964,7 +1965,9 @@ function pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails = 0) $result.=price($sign * ($total_ht/($object->lines[$i]->situation_percent/100)) * $progress, 0, $outputlangs); } else - $result.=price($sign * $total_ht, 0, $outputlangs); + { + $result.=price($sign * $total_ht, 0, $outputlangs); + } } } return $result; diff --git a/htdocs/core/lib/price.lib.php b/htdocs/core/lib/price.lib.php index 9d3aa99f306..a649d9d225e 100644 --- a/htdocs/core/lib/price.lib.php +++ b/htdocs/core/lib/price.lib.php @@ -39,7 +39,7 @@ * @param int $qty Quantity * @param float $pu Unit price (HT or TTC selon price_base_type) * @param float $remise_percent_ligne Discount for line - * @param float $txtva 0=do not apply standard tax, Vat rate=apply + * @param float $txtva 0=do not apply VAT tax, VAT rate=apply (this is VAT rate only without text code, we don't need text code because we alreaydy have all tax info into $localtaxes_array) * @param float $uselocaltax1_rate 0=do not use this localtax, >0=apply and get value from localtaxes_array (or database if empty), -1=autodetect according to seller if we must apply, get value from localtaxes_array (or database if empty). Try to always use -1. * @param float $uselocaltax2_rate 0=do not use this localtax, >0=apply and get value from localtaxes_array (or database if empty), -1=autodetect according to seller if we must apply, get value from localtaxes_array (or database if empty). Try to always use -1. * @param float $remise_percent_global 0 @@ -82,7 +82,7 @@ * 25=multicurrency_total_tax1 for total_ht * 26=multicurrency_total_tax2 for total_ht */ -function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller = '', $localtaxes_array = '', $progress = 100, $multicurrency_tx = 1, $pu_devise = 0) +function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller = '', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_devise=0) { global $conf,$mysoc,$db; @@ -131,13 +131,14 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt $localtax2_type = $localtaxes_array[2]; $localtax2_rate = $localtaxes_array[3]; } - else // deprecated method. values and type for localtaxes must be provided by caller and loaded with getLocalTaxesFromRate + else // deprecated method. values and type for localtaxes must be provided by caller and loaded with getLocalTaxesFromRate using the full vat rate (including text code) { - $sql = "SELECT taux, localtax1, localtax2, localtax1_type, localtax2_type"; + dol_syslog("Price.lib::calcul_price_total search vat information using old deprecated method", LOG_WARNING); + + $sql = "SELECT taux, localtax1, localtax2, localtax1_type, localtax2_type"; $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as cv"; $sql.= " WHERE cv.taux = ".$txtva; $sql.= " AND cv.fk_pays = ".$countryid; - dol_syslog("Price.lib::calcul_price_total search vat information using old deprecated method", LOG_WARNING); $resql = $db->query($sql); if ($resql) { @@ -187,9 +188,9 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt //If input unit price is 'HT', we need to have the totals with main VAT for a correct calculation if ($price_base_type != 'TTC') { - $tot_sans_remise_wt = price2num($tot_sans_remise * (1 + ($txtva / 100)), 'MU'); - $tot_avec_remise_wt = price2num($tot_avec_remise * (1 + ($txtva / 100)), 'MU'); - $pu_wt = price2num($pu * (1 + ($txtva / 100)), 'MU'); + $tot_sans_remise_wt = price2num($tot_sans_remise * (1 + ($txtva / 100)),'MU'); + $tot_avec_remise_wt = price2num($tot_avec_remise * (1 + ($txtva / 100)),'MU'); + $pu_wt = price2num($pu * (1 + ($txtva / 100)),'MU'); } else { @@ -291,9 +292,9 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt //If input unit price is 'TTC', we need to have the totals without main VAT for a correct calculation if ($price_base_type == 'TTC') { - $tot_sans_remise= price2num($tot_sans_remise / (1 + ($txtva / 100)), 'MU'); - $tot_avec_remise= price2num($tot_avec_remise / (1 + ($txtva / 100)), 'MU'); - $pu = price2num($pu / (1 + ($txtva / 100)), 'MU'); + $tot_sans_remise= price2num($tot_sans_remise / (1 + ($txtva / 100)),'MU'); + $tot_avec_remise= price2num($tot_avec_remise / (1 + ($txtva / 100)),'MU'); + $pu = price2num($pu / (1 + ($txtva / 100)),'MU'); } $apply_tax = false; @@ -410,3 +411,4 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt return $result; } + diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 93140c02ef0..04911584809 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -134,7 +134,7 @@ if ($nolinesbefore) { // Fields for situation invoice if ($this->situation_cycle_ref) { print '' . $langs->trans('Progress') . ''; - //print ''; + print ''; } if (! empty($usemargins)) { @@ -163,18 +163,18 @@ if ($nolinesbefore) { ?> global->MAIN_VIEW_LINE_NUMBER)) { - $coldisplay=2; + $coldisplay++; ?> + } + $coldisplay++; + ?> global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; $toolbarname='dolibarr_details'; if (! empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) $toolbarname='dolibarr_notes'; - $doleditor=new DolEditor('dp_desc', GETPOST('dp_desc'), '', (empty($conf->global->MAIN_DOLEDITOR_HEIGHT)?100:$conf->global->MAIN_DOLEDITOR_HEIGHT), $toolbarname, '', false, true, $enabled, $nbrows, '98%'); + $doleditor=new DolEditor('dp_desc', GETPOST('dp_desc', 'none'), '', (empty($conf->global->MAIN_DOLEDITOR_HEIGHT)?100:$conf->global->MAIN_DOLEDITOR_HEIGHT), $toolbarname, '', false, true, $enabled, $nbrows, '98%'); $doleditor->Create(); // Show autofill date for recurring invoices @@ -355,52 +355,71 @@ else { if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines { ?> + $coldisplay++; "> tva_assuj == "0") echo ''.vatrate(0, true); else echo $form->load_tva('tva_tx', (isset($_POST["tva_tx"])?GETPOST("tva_tx", 'alpha', 2):-1), $seller, $buyer, 0, 0, '', false, 1); ?> - + + "> - multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { ?> + multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { + $coldisplay++; + ?> "> - + "> - + "> global->PRODUCT_USE_UNITS) { + $coldisplay++; print ''; print $form->selectUnits($line->fk_unit, "units"); print ''; } $remise_percent = $buyer->remise_percent; - if($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') { + if($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') + { $remise_percent = $seller->remise_supplier_percent; } + + $coldisplay++; ?> ">% situation_cycle_ref) { $coldisplay++; print '%'; + $coldisplay++; + print ''; } + if (! empty($usemargins)) { if (!empty($user->rights->margins->creer)) { + $coldisplay++; ?> @@ -411,7 +430,6 @@ else { "> rights->margins->creer) @@ -427,12 +445,9 @@ else { $coldisplay++; } } - else - { - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $coldisplay++; - if (! empty($conf->global->DISPLAY_MARK_RATES)) $coldisplay++; - } } + + $coldisplay+=$colspan; ?> @@ -441,62 +456,18 @@ else { showOptionals($extrafieldsline, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay+8), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1); + print $objectline->showOptionals($extrafieldsline, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1); } ?> service->enabled) || ($object->element == 'contrat')) && $dateSelector && GETPOST('type') != '0') // We show date field if required { - $colspan = 6; - - if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines - { - $colspan++; - } - if ($this->situation_cycle_ref) { - $colspan++; - } - // We add 1 if col total ttc - if (!empty($inputalsopricewithtax)) { - $colspan++; - } - if ($conf->global->PRODUCT_USE_UNITS) { - $colspan++; - } - 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', - 'supplier_proposal', - 'facture', - 'facturerec', - 'invoice', - 'commande', - 'order', - 'order_supplier', - 'invoice_supplier' - ))) { - $colspan++; - } - } - - if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) $colspan+=2; - - if (! empty($usemargins)) - { - if (!empty($user->rights->margins->creer)) $colspan++; // For the buying price - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++; - if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++; - } ?> > global->MAIN_VIEW_LINE_NUMBER)) { print ''; } ?> - + situation_cycle_ref) { $coldisplay++; - print '%'; + print '%'; + $coldisplay++; + print ''; } if (! empty($usemargins)) { @@ -270,7 +272,7 @@ if (!empty($extrafieldsline)) global->MAIN_VIEW_LINE_NUMBER)) { ?> - trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?> + trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?> global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE:''); print $form->selectDate($line->date_start, 'date_start', $hourmin, $hourmin, $line->date_start?0:1, "updateline", 1, 0); diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index ba52a4a63c5..09bedf2ec53 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -237,17 +237,22 @@ $domData .= ' data-product_type="'.$line->product_type.'"';   global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); + // Fields for situation invoices if ($this->situation_cycle_ref) { + include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; $coldisplay++; print '' . $line->situation_percent . '%'; - //print '' . $line->situation_percent . ''; + $coldisplay++; + $locataxes_array = getLocalTaxesFromRate($line->tva.($line->vat_src_code ? ' ('.$line->vat_src_code.')' : ''), 0, ($senderissupplier?$mysoc:$object->thirdparty), ($senderissupplier?$object->thirdparty:$mysoc)); + $tmp = calcul_price_total($line->qty, $line->pu, $line->remise_percent, $line->txtva, -1, -1, 0, 'HT', $line->info_bits, $line->type, ($senderissupplier?$object->thirdparty:$mysoc), $locataxes_array, 100, $object->multicurrency_tx, $line->multicurrency_subprice); + print '' . price($tmp[0]) . ''; } if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id)) { - $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); ?> rights->margins->creer)) { ?> diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index c739f8d5624..3aec931714b 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -371,6 +371,7 @@ Percentage=Percentage Total=Total SubTotal=Subtotal TotalHTShort=Total (excl.) +TotalHT100Short=Total 100%% (excl.) TotalHTShortCurrency=Total (excl. in currency) TotalTTCShort=Total (inc. tax) TotalHT=Total (excl. tax)