diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index ed77c0e8a56..3600e9a8322 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -2335,10 +2335,10 @@ if (empty($reshook)) } } - $result = $object->updateline(GETPOST('lineid'), $description, $pu_ht, $qty, GETPOST('remise_percent'), + $result = $object->updateline(GETPOST('lineid', 'int'), $description, $pu_ht, $qty, price2num(GETPOST('remise_percent', 'alpha')), $date_start, $date_end, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $info_bits, $type, - GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options, GETPOST('progress'), - $_POST['units'], $pu_ht_devise); + GETPOST('fk_parent_line', 'int'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options, price2num(GETPOST('progress', 'alpha')), + GETPOST('units', 'alpha'), $pu_ht_devise); if ($result >= 0) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { @@ -4420,44 +4420,50 @@ if ($action == 'create') print '
'; print '
'; + print ''."\n"; print ''; + $sign = 1; + if (!empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE_SCREEN) && $object->type == $object::TYPE_CREDIT_NOTE) { + $sign = -1; // We invert sign for output + } + if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) { // Multicurrency Amount HT print ''; - print ''; + print ''; print ''; // Multicurrency Amount VAT print ''; - print ''; + print ''; print ''; // Multicurrency Amount TTC print ''; - print ''; + print ''; print ''; } // Amount print ''; - print ''; + print ''; // Vat - print ''; + print ''; print ''; // Amount Local Taxes if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) // Localtax1 { print ''; - print ''; + print ''; } if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) // Localtax2 { print ''; - print ''; + print ''; } // Revenue stamp @@ -4515,13 +4521,11 @@ if ($action == 'create') } // Total with tax - print ''; + print ''; print '
'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).''.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).''.price($sign * $object->multicurrency_total_ht, '', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).''.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).''.price($sign * $object->multicurrency_total_tva, '', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).''.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).''.price($sign * $object->multicurrency_total_ttc, '', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$langs->trans('AmountHT').''.price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency).'
'.price($sign * $object->total_ht, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->trans('AmountVAT').''.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->trans('AmountVAT').''.price($sign * $object->total_tva, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'
'.price($sign * $object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'
'.price($sign * $object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->trans('AmountTTC').''.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->trans('AmountTTC').''.price($sign * $object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).'
'; - $sign = 1; - if ($object->type == Facture::TYPE_CREDIT_NOTE) $sign = - 1; $nbrows = 8; $nbcols = 3; if (!empty($conf->projet->enabled)) @@ -4664,6 +4668,8 @@ if ($action == 'create') print ''; } + $sign = 1; + if ($object->type == $object::TYPE_CREDIT_NOTE) $sign = -1; // List of payments already done diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 5110b1194e5..268aaf2ad87 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3351,7 +3351,7 @@ class Facture extends CommonInvoice $this->line->localtax2_type = $localtaxes_type[2]; $this->line->remise_percent = $remise_percent; - $this->line->subprice = ($this->type == 2 ?-abs($pu_ht) : $pu_ht); // For credit note, unit price always negative, always positive otherwise + $this->line->subprice = ($this->type == self::TYPE_CREDIT_NOTE ?-abs($pu_ht) : $pu_ht); // For credit note, unit price always negative, always positive otherwise $this->line->date_start = $date_start; $this->line->date_end = $date_end; $this->line->total_ht = (($this->type == self::TYPE_CREDIT_NOTE || $qty < 0) ?-abs($total_ht) : $total_ht); // For credit note and if qty is negative, total is negative @@ -3371,10 +3371,10 @@ class Facture extends CommonInvoice $this->line->pa_ht = $pa_ht; // Multicurrency - $this->line->multicurrency_subprice = $pu_ht_devise; - $this->line->multicurrency_total_ht = $multicurrency_total_ht; - $this->line->multicurrency_total_tva = $multicurrency_total_tva; - $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; + $this->line->multicurrency_subprice = ($this->type == self::TYPE_CREDIT_NOTE ?-abs($pu_ht_devise) : $pu_ht_devise); // For credit note, unit price always negative, always positive otherwise + $this->line->multicurrency_total_ht = (($this->type == self::TYPE_CREDIT_NOTE || $qty < 0) ?-abs($multicurrency_total_ht) : $multicurrency_total_ht); // For credit note and if qty is negative, total is negative + $this->line->multicurrency_total_tva = (($this->type == self::TYPE_CREDIT_NOTE || $qty < 0) ?-abs($multicurrency_total_tva) : $multicurrency_total_tva); + $this->line->multicurrency_total_ttc = (($this->type == self::TYPE_CREDIT_NOTE || $qty < 0) ?-abs($multicurrency_total_ttc) : $multicurrency_total_ttc); if (is_array($array_options) && count($array_options) > 0) { // We replace values in this->line->array_options only for entries defined into $array_options diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index 742a7862100..1b131a4b8df 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -63,8 +63,13 @@ $domData .= ' data-id="'.$line->id.'"'; $domData .= ' data-qty="'.$line->qty.'"'; $domData .= ' data-product_type="'.$line->product_type.'"'; +$sign = 1; +if (!empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE_SCREEN) && $object->type == $object::TYPE_CREDIT_NOTE) { + $sign = -1; +} -$coldisplay = 0; ?> +$coldisplay = 0; +?> > global->MAIN_VIEW_LINE_NUMBER)) { ?> @@ -197,14 +202,14 @@ print vatrate($positiverates.($line->vat_src_code ? ' ('.$line->vat_src_code.')' //print vatrate($line->tva_tx.($line->vat_src_code?(' ('.$line->vat_src_code.')'):''), '%', $line->info_bits); ?> - subprice); ?> + subprice); ?> multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { ?> - multicurrency_subprice); ?> + multicurrency_subprice); ?> - pu_ttc) ?price($line->pu_ttc) : price($line->subprice)); ?> + pu_ttc) ? price($sign * $line->pu_ttc) : price($sign * $line->subprice)); ?> @@ -247,7 +252,7 @@ if ($this->situation_cycle_ref) $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]).''; + print ''.price($sign * $tmp[0]).''; } if ($usemargins && !empty($conf->margin->enabled) && empty($user->socid)) @@ -262,6 +267,7 @@ if ($usemargins && !empty($conf->margin->enabled) && empty($user->socid)) marque_tx, 'MT')).'%'; ?> special_code == 3) { ?> trans('Option'); ?> special_code == 3) { ?> print ''; } - print price($line->total_ht); + print price($sign * $line->total_ht); if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { print ''; } print ''; if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { - print ''.price($line->multicurrency_total_ht).''; + print ''.price($sign * $line->multicurrency_total_ht).''; $coldisplay++; } } if ($outputalsopricetotalwithtax) { - print ''.price($line->total_ttc).''; + print ''.price($sign * $line->total_ttc).''; $coldisplay++; }