diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index 651fa556e8a..efb589ac8b9 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -56,7 +56,7 @@ if (GETPOST('cancel', 'alpha') && !empty($backtopage)) exit; } -if ($action == 'confirm_split' && GETPOST("confirm") == 'yes') +if ($action == 'confirm_split' && GETPOST("confirm", "alpha") == 'yes') { //if ($user->rights->societe->creer) //if ($user->rights->facture->creer) @@ -122,6 +122,8 @@ if ($action == 'confirm_split' && GETPOST("confirm") == 'yes') $newdiscount2->datec = $discount->datec; $newdiscount1->tva_tx = $discount->tva_tx; $newdiscount2->tva_tx = $discount->tva_tx; + $newdiscount1->vat_src_code = $discount->vat_src_code; + $newdiscount2->vat_src_code = $discount->vat_src_code; $newdiscount1->amount_ttc = $amount_ttc_1; $newdiscount2->amount_ttc = price2num($discount->amount_ttc - $newdiscount1->amount_ttc); $newdiscount1->amount_ht = price2num($newdiscount1->amount_ttc / (1 + $newdiscount1->tva_tx / 100), 'MT'); @@ -154,12 +156,12 @@ if ($action == 'setremise' && $user->rights->societe->creer) //if ($user->rights->societe->creer) //if ($user->rights->facture->creer) - $amount_ht = GETPOST('amount_ht'); + $amount_ht = price2num(GETPOST('amount_ht', 'alpha')); $desc = GETPOST('desc', 'alpha'); $tva_tx = GETPOST('tva_tx', 'alpha'); $discount_type = !empty($_POST['discount_type']) ?GETPOST('discount_type', 'alpha') : 0; - if (price2num($amount_ht) > 0) + if ($amount_ht > 0) { $error = 0; if (empty($desc)) @@ -196,7 +198,7 @@ if ($action == 'setremise' && $user->rights->societe->creer) } else { - setEventMessages($langs->trans("ErrorFieldFormat", $langs->transnoentitiesnoconv("NewGlobalDiscount")), null, 'errors'); + setEventMessages($langs->trans("ErrorFieldFormat", $langs->transnoentitiesnoconv("AmountHT")), null, 'errors'); } } @@ -375,10 +377,10 @@ if ($socid > 0) print ' '.$langs->trans("Currency".$conf->currency).''; print ''.$langs->trans("VAT").''; print ''; - print $form->load_tva('tva_tx', GETPOST('tva_tx'), $mysoc, $object); + print $form->load_tva('tva_tx', GETPOSTISSET('tva_tx') ? GETPOST('tva_tx', 'alpha') : 0, $mysoc, $object, 0, 0, '', 0, 1); print ''; print ''.$langs->trans("NoteReason").''; - print ''; + print ''; print ""; @@ -409,7 +411,7 @@ if ($socid > 0) /* - * List remises fixes client restant en cours (= liees a aucune facture ni ligne de facture) + * List not consumed available credits (= linked to no invoice and no invoice line) */ print load_fiche_titre($langs->trans("DiscountStillRemaining")); @@ -421,7 +423,8 @@ if ($socid > 0) print load_fiche_titre($langs->trans("CustomerDiscounts"), '', ''); } - $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,"; + $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,"; + $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,"; $sql .= " rc.datec as dc, rc.description,"; $sql .= " rc.fk_facture_source,"; $sql .= " u.login, u.rowid as user_id,"; @@ -510,7 +513,7 @@ if ($socid > 0) { print ''.price($obj->multicurrency_amount_ht).''; } - print ''.vatrate($obj->tva_tx, true).''; + print ''.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).''; print ''.price($obj->amount_ttc).''; if (!empty($conf->multicurrency->enabled)) { @@ -577,7 +580,8 @@ if ($socid > 0) /* * Liste remises fixes fournisseur restant en cours (= liees a aucune facture ni ligne de facture) */ - $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,"; + $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,"; + $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,"; $sql .= " rc.datec as dc, rc.description,"; $sql .= " rc.fk_invoice_supplier_source,"; $sql .= " u.login, u.rowid as user_id,"; @@ -666,7 +670,7 @@ if ($socid > 0) { print ''.price($obj->multicurrency_amount_ht).''; } - print ''.vatrate($obj->tva_tx, true).''; + print ''.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).''; print ''.price($obj->amount_ttc).''; if (!empty($conf->multicurrency->enabled)) { @@ -744,7 +748,8 @@ if ($socid > 0) } // Discount linked to invoice lines - $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,"; + $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,"; + $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,"; $sql .= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture_source,"; $sql .= " u.login, u.rowid as user_id,"; $sql .= " f.rowid as invoiceid, f.ref,"; @@ -762,7 +767,7 @@ if ($socid > 0) $sql .= " ORDER BY dc DESC"; //$sql.= " UNION "; // Discount linked to invoices - $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,"; + $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,"; $sql2 .= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture,"; $sql2 .= " rc.fk_facture_source,"; $sql2 .= " u.login, u.rowid as user_id,"; @@ -881,7 +886,7 @@ if ($socid > 0) { print ''.price($obj->multicurrency_amount_ht).''; } - print ''.vatrate($obj->tva_tx, true).''; + print ''.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).''; print ''.price($obj->amount_ttc).''; if (!empty($conf->multicurrency->enabled)) { @@ -920,7 +925,8 @@ if ($socid > 0) } // Discount linked to invoice lines - $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,"; + $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,"; + $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,"; $sql .= " rc.datec as dc, rc.description, rc.fk_invoice_supplier_line, rc.fk_invoice_supplier,"; $sql .= " rc.fk_invoice_supplier_source,"; $sql .= " u.login, u.rowid as user_id,"; @@ -939,7 +945,7 @@ if ($socid > 0) $sql .= " ORDER BY dc DESC"; //$sql.= " UNION "; // Discount linked to invoices - $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,"; + $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,"; $sql2 .= " rc.datec as dc, rc.description, rc.fk_invoice_supplier_line, rc.fk_invoice_supplier,"; $sql2 .= " rc.fk_invoice_supplier_source,"; $sql2 .= " u.login, u.rowid as user_id,"; @@ -1057,7 +1063,7 @@ if ($socid > 0) { print ''.price($obj->multicurrency_amount_ht).''; } - print ''.vatrate($obj->tva_tx, true).''; + print ''.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).''; print ''.price($obj->amount_ttc).''; if (!empty($conf->multicurrency->enabled)) { diff --git a/htdocs/core/class/discount.class.php b/htdocs/core/class/discount.class.php index c3707b18972..bf85699a9fe 100644 --- a/htdocs/core/class/discount.class.php +++ b/htdocs/core/class/discount.class.php @@ -62,6 +62,7 @@ class DiscountAbsolute public $multicurrency_amount_ttc; // Vat rate public $tva_tx; + public $vat_src_code; /** * @var int User ID Id utilisateur qui accorde la remise @@ -133,7 +134,7 @@ class DiscountAbsolute $sql = "SELECT sr.rowid, sr.fk_soc, sr.discount_type,"; $sql.= " sr.fk_user,"; - $sql.= " sr.amount_ht, sr.amount_tva, sr.amount_ttc, sr.tva_tx,"; + $sql.= " sr.amount_ht, sr.amount_tva, sr.amount_ttc, sr.tva_tx, sr.vat_src_code,"; $sql.= " sr.multicurrency_amount_ht, sr.multicurrency_amount_tva, sr.multicurrency_amount_ttc,"; $sql.= " sr.fk_facture_line, sr.fk_facture, sr.fk_facture_source, sr.fk_invoice_supplier_line, sr.fk_invoice_supplier, sr.fk_invoice_supplier_source, sr.description,"; $sql.= " sr.datec,"; @@ -168,6 +169,8 @@ class DiscountAbsolute $this->multicurrency_amount_ttc = $obj->multicurrency_amount_ttc; $this->tva_tx = $obj->tva_tx; + $this->vat_src_code = $obj->vat_src_code; + $this->fk_user = $obj->fk_user; $this->fk_facture_line = $obj->fk_facture_line; $this->fk_facture = $obj->fk_facture; @@ -244,12 +247,12 @@ class DiscountAbsolute // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except"; $sql .= " (entity, datec, fk_soc, discount_type, fk_user, description,"; - $sql .= " amount_ht, amount_tva, amount_ttc, tva_tx,"; + $sql .= " amount_ht, amount_tva, amount_ttc, tva_tx, vat_src_code,"; $sql .= " multicurrency_amount_ht, multicurrency_amount_tva, multicurrency_amount_ttc,"; $sql .= " fk_facture_source, fk_invoice_supplier_source"; $sql .= ")"; $sql .= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec != '' ? $this->datec : dol_now())."', ".$this->fk_soc.", ".(empty($this->discount_type) ? 0 : intval($this->discount_type)).", ".$userid.", '".$this->db->escape($this->description)."',"; - $sql .= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.","; + $sql .= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.", '".$this->db->escape($this->vat_src_code)."',"; $sql .= " ".$this->multicurrency_amount_ht.", ".$this->multicurrency_amount_tva.", ".$this->multicurrency_amount_ttc.", "; $sql .= " ".($this->fk_facture_source ? "'".$this->db->escape($this->fk_facture_source)."'" : "null").","; $sql .= " ".($this->fk_invoice_supplier_source ? "'".$this->db->escape($this->fk_invoice_supplier_source)."'" : "null"); diff --git a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql index f5c4dee3f15..892c2a94f5f 100644 --- a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql +++ b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql @@ -200,3 +200,6 @@ ALTER TABLE llx_entrepot ADD COLUMN phone varchar(20) DEFAULT NULL; ALTER TABLE llx_accounting_account ADD COLUMN reconcilable tinyint DEFAULT 0 NOT NULL after active; ALTER TABLE llx_categorie MODIFY type integer NOT NULL DEFAULT 1; + +ALTER TABLE llx_societe_remise_except ADD COLUMN vat_src_code varchar(10) DEFAULT ''; + diff --git a/htdocs/install/mysql/tables/llx_societe_remise_except.sql b/htdocs/install/mysql/tables/llx_societe_remise_except.sql index 50cbfae51c1..63762f8ad32 100644 --- a/htdocs/install/mysql/tables/llx_societe_remise_except.sql +++ b/htdocs/install/mysql/tables/llx_societe_remise_except.sql @@ -30,6 +30,7 @@ create table llx_societe_remise_except amount_tva double(24,8) DEFAULT 0 NOT NULL, amount_ttc double(24,8) DEFAULT 0 NOT NULL, tva_tx double(6,3) DEFAULT 0 NOT NULL, + vat_src_code varchar(10) DEFAULT '', -- Vat code used as source of vat fields. Not strict foreign key here. fk_user integer NOT NULL, fk_facture_line integer, fk_facture integer, diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index e61c98e3267..e6e9e42aa75 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1987,11 +1987,11 @@ class Societe extends CommonObject * @param float $remise Amount of discount * @param User $user User adding discount * @param string $desc Reason of discount - * @param float $tva_tx VAT rate + * @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 + * @return int <0 if KO, id of discount record if OK */ - public function set_remise_except($remise, User $user, $desc, $tva_tx = 0, $discount_type = 0) + public function set_remise_except($remise, User $user, $desc, $vatrate = '', $discount_type = 0) { // phpcs:enable global $langs; @@ -2012,8 +2012,17 @@ class Societe extends CommonObject return -2; } - if ($this->id) + if ($this->id > 0) { + // Clean vat code + $reg = array(); + $vat_src_code = ''; + if (preg_match('/\((.*)\)/', $vatrate, $reg)) + { + $vat_src_code = $reg[1]; + $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. + } + require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; $discount = new DiscountAbsolute($this->db); @@ -2022,10 +2031,12 @@ 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 * $tva_tx / 100, '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($tva_tx, 'MT'); + $discount->tva_tx = price2num($vatrate, 'MT'); + $discount->vat_src_code = $vat_src_code; + $discount->description = $desc; $result = $discount->create($user);