diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index b28af96527e..fe8c630fc10 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -53,6 +53,9 @@ if ($user->socid > 0) { } $result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0); +$permissiontocreate = ($user->rights->societe->creer || $user->rights->facture->creer); + + /* * Actions @@ -63,7 +66,7 @@ if (GETPOST('cancel', 'alpha') && !empty($backtopage)) { exit; } -if ($action == 'confirm_split' && GETPOST("confirm", "alpha") == 'yes' && ($user->rights->societe->creer || $user->rights->facture->creer)) { +if ($action == 'confirm_split' && GETPOST("confirm", "alpha") == 'yes' && $permissiontocreate) { //if ($user->rights->societe->creer) //if ($user->rights->facture->creer) @@ -154,16 +157,17 @@ if ($action == 'confirm_split' && GETPOST("confirm", "alpha") == 'yes' && ($user } } -if ($action == 'setremise' && ($user->rights->societe->creer || $user->rights->facture->creer)) { +if ($action == 'setremise' && $permissiontocreate) { //if ($user->rights->societe->creer) //if ($user->rights->facture->creer) - $amount_ht = price2num(GETPOST('amount_ht', 'alpha')); + $amount = price2num(GETPOST('amount', 'alpha'), '', 2); $desc = GETPOST('desc', 'alpha'); $tva_tx = GETPOST('tva_tx', 'alpha'); $discount_type = GETPOSTISSET('discount_type') ? GETPOST('discount_type', 'alpha') : 0; + $price_base_type = GETPOST('price_base_type', 'alpha'); - if ($amount_ht > 0) { + if ($amount > 0) { $error = 0; if (empty($desc)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ReasonDiscount")), null, 'errors'); @@ -173,14 +177,14 @@ if ($action == 'setremise' && ($user->rights->societe->creer || $user->rights->f if (!$error) { $soc = new Societe($db); $soc->fetch($id); - $discountid = $soc->set_remise_except($amount_ht, $user, $desc, $tva_tx, $discount_type); + $discountid = $soc->set_remise_except($amount, $user, $desc, $tva_tx, $discount_type, $price_base_type); if ($discountid > 0) { if (!empty($backtopage)) { - header("Location: ".$backtopage.'&discountid='.$discountid); + header("Location: ".$backtopage.'&discountid='.((int) $discountid)); exit; } else { - header("Location: remx.php?id=".$id); + header("Location: remx.php?id=".((int) $id)); exit; } } else { @@ -193,7 +197,7 @@ if ($action == 'setremise' && ($user->rights->societe->creer || $user->rights->f } } -if (GETPOST('action', 'aZ09') == 'confirm_remove' && GETPOST("confirm") == 'yes' && ($user->rights->societe->creer || $user->rights->facture->creer)) { +if (GETPOST('action', 'aZ09') == 'confirm_remove' && GETPOST("confirm") == 'yes' && $permissiontocreate) { //if ($user->rights->societe->creer) //if ($user->rights->facture->creer) @@ -231,9 +235,8 @@ if ($socid > 0) { $isCustomer = $object->client == 1 || $object->client == 3; $isSupplier = $object->fournisseur == 1; - /* - * Display tabs - */ + // Display tabs + $head = societe_prepare_head($object); print '
'; @@ -262,6 +265,7 @@ if ($socid > 0) { } + print '
'; print ''; if ($isCustomer) { // Calcul avoirs client en cours @@ -324,9 +328,10 @@ if ($socid > 0) { } print '
'; - print '
'; + print ''; // close fichecenter + print dol_get_fiche_end(); @@ -346,6 +351,8 @@ if ($socid > 0) { print dol_get_fiche_head(); + + print '
'; print ''; if ($isCustomer && $isSupplier) { print ''; @@ -353,9 +360,19 @@ if ($socid > 0) { print '   '; print ''; } - print ''; - print ''; + print ''; + + // Price base (HT / TTC) + print ''; + print ''; + + // VAT print ''; print ''; print "
'.$langs->trans('DiscountType').'
'.$langs->trans("AmountHT").''; + + // Amount + print '
'.$langs->trans("Amount").''; print ' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("PriceBase").''; + print $form->selectPriceBaseType(GETPOST("price_base_type"), "price_base_type"); + print '
'.$langs->trans("VAT").''; print $form->load_tva('tva_tx', GETPOSTISSET('tva_tx') ? GETPOST('tva_tx', 'alpha') : 0, $mysoc, $object, 0, 0, '', 0, 1); @@ -364,6 +381,7 @@ if ($socid > 0) { print '
"; + print '
'; print dol_get_fiche_end(); } diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index c01f83401cf..66f7cb6ee79 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -2268,14 +2268,15 @@ class Societe extends CommonObject /** * Add a discount for third party * - * @param float $remise Amount of discount - * @param User $user User adding discount - * @param string $desc Reason of discount - * @param string $vatrate VAT rate (may contain the vat code too). Exemple: '1.23', '1.23 (ABC)', ... - * @param int $discount_type 0 => customer discount, 1 => supplier discount - * @return int <0 if KO, id of discount record if OK + * @param float $remise Amount of discount + * @param User $user User adding discount + * @param string $desc Reason of discount + * @param string $vatrate VAT rate (may contain the vat code too). Exemple: '1.23', '1.23 (ABC)', ... + * @param int $discount_type 0 => customer discount, 1 => supplier discount + * @param string $price_base_type Price base type 'HT' or 'TTC' + * @return int <0 if KO, id of discount record if OK */ - public function set_remise_except($remise, User $user, $desc, $vatrate = '', $discount_type = 0) + public function set_remise_except($remise, User $user, $desc, $vatrate = '', $discount_type = 0, $price_base_type = 'HT') { // phpcs:enable global $langs; @@ -2310,9 +2311,15 @@ class Societe extends CommonObject $discount->discount_type = $discount_type; - $discount->amount_ht = $discount->multicurrency_amount_ht = price2num($remise, 'MT'); - $discount->amount_tva = $discount->multicurrency_amount_tva = price2num($remise * $vatrate / 100, 'MT'); - $discount->amount_ttc = $discount->multicurrency_amount_ttc = price2num($discount->amount_ht + $discount->amount_tva, 'MT'); + if ($price_base_type == 'TTC') { + $discount->amount_ttc = $discount->multicurrency_amount_ttc = price2num($remise, 'MT'); + $discount->amount_ht = $discount->multicurrency_amount_ht = price2num($remise / (1 + $vatrate / 100), 'MT'); + $discount->amount_tva = $discount->multicurrency_amount_tva = price2num($discount->amount_ttc - $discount->amount_ht, 'MT'); + } else { + $discount->amount_ht = $discount->multicurrency_amount_ht = price2num($remise, 'MT'); + $discount->amount_tva = $discount->multicurrency_amount_tva = price2num($remise * $vatrate / 100, 'MT'); + $discount->amount_ttc = $discount->multicurrency_amount_ttc = price2num($discount->amount_ht + $discount->amount_tva, 'MT'); + } $discount->tva_tx = price2num($vatrate); $discount->vat_src_code = $vat_src_code;