30require
'../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
37$langs->loadLangs(array(
'admin',
'products'));
44$action =
GETPOST(
'action',
'aZ09');
45$oldvatrate =
GETPOST(
'oldvatrate',
'alpha');
46$newvatrate =
GETPOST(
'newvatrate',
'alpha');
55if ($action ==
'convert') {
58 if ($oldvatrate == $newvatrate) {
59 $langs->load(
"errors");
60 setEventMessages($langs->trans(
"ErrorNewValueCantMatchOldValue"),
null,
'errors');
65 $country_id = $mysoc->country_id;
67 $nbrecordsmodified = 0;
74 $vat_src_code_old =
'';
75 if (preg_match(
'/\((.*)\)/', $oldvatrate, $reg)) {
76 $vat_src_code_old = $reg[1];
77 $oldvatrateclean = preg_replace(
'/\s*\(.*\)/',
'', $oldvatrate);
79 $oldvatrateclean = $oldvatrate;
83 $vat_src_code_new =
'';
84 if (preg_match(
'/\((.*)\)/', $newvatrate, $reg)) {
85 $vat_src_code_new = $reg[1];
86 $newvatrateclean = preg_replace(
'/\s*\(.*\)/',
'', $newvatrate);
88 $newvatrateclean = $newvatrate;
92 if ($country_id == $mysoc->country_id) {
93 $sql =
'SELECT rowid';
94 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product';
95 $sql .=
' WHERE entity IN ('.getEntity(
'product').
')';
96 $sql .=
" AND tva_tx = '".$db->escape($oldvatrateclean).
"'";
97 if ($vat_src_code_old) {
98 $sql .=
" AND default_vat_code = '".$db->escape($vat_src_code_old).
"'";
100 $sql .=
" AND default_vat_code = IS NULL";
103 $resql = $db->query($sql);
105 $num = $db->num_rows($resql);
109 $obj = $db->fetch_object($resql);
111 $objectstatic =
new Product($db);
112 $ret = $objectstatic->fetch($obj->rowid);
116 $updatelevel1 =
false;
119 $listofmulti = array_reverse($objectstatic->multiprices,
true);
120 foreach ($listofmulti as $level => $multiprices) {
121 $price_base_type = $objectstatic->multiprices_base_type[$level];
122 if (empty($price_base_type)) {
126 if ($price_base_type ==
'TTC') {
127 $newprice =
price2num($objectstatic->multiprices_ttc[$level],
'MU');
128 $newminprice = $objectstatic->multiprices_min_ttc[$level];
130 $newprice =
price2num($objectstatic->multiprices[$level],
'MU');
131 $newminprice = $objectstatic->multiprices_min[$level];
133 if ($newminprice > $newprice) {
134 $newminprice = $newprice;
137 $newvat = str_replace(
'*',
'', $newvatrate);
139 $newnpr = $objectstatic->multiprices_recuperableonly[$level];
140 $newdefaultvatcode = $vat_src_code_new;
144 $retm = $objectstatic->updatePrice($newprice, $price_base_type, $user, $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode);
150 if ($newlevel == 1) {
151 $updatelevel1 =
true;
156 $price_base_type = $objectstatic->price_base_type;
157 if ($price_base_type ==
'TTC') {
158 $newprice =
price2num($objectstatic->price_ttc,
'MU');
159 $newminprice = $objectstatic->price_min_ttc;
161 $newprice =
price2num($objectstatic->price,
'MU');
162 $newminprice = $objectstatic->price_min;
164 if ($newminprice > $newprice) {
165 $newminprice = $newprice;
167 $newvat = str_replace(
'*',
'', $newvatrate);
169 $newnpr = $objectstatic->tva_npr;
170 $newdefaultvatcode = $vat_src_code_new;
172 if (!empty($price_base_type) && !$updatelevel1) {
174 $ret = $objectstatic->updatePrice($newprice, $price_base_type, $user, $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode);
177 if ($ret < 0 || $retm < 0) {
180 $nbrecordsmodified++;
183 unset($objectstatic);
195 $sql =
'SELECT pfp.rowid, pfp.fk_soc, pfp.price as price, pfp.quantity as qty, pfp.fk_availability, pfp.ref_fourn';
196 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price as pfp, '.MAIN_DB_PREFIX.
'societe as s';
197 $sql .=
' WHERE pfp.fk_soc = s.rowid AND pfp.entity IN ('.getEntity(
'product').
')';
198 $sql .=
" AND tva_tx = '".$db->escape($oldvatrate).
"'";
199 if ($vat_src_code_old) {
200 $sql .=
" AND default_vat_code = '".$db->escape($vat_src_code_old).
"'";
202 $sql .=
" AND default_vat_code = IS NULL";
204 $sql .=
" AND s.fk_pays = ".((int) $country_id);
206 $resql = $db->query($sql);
208 $num = $db->num_rows($resql);
212 $obj = $db->fetch_object($resql);
215 $ret = $objectstatic2->fetch_product_fournisseur_price($obj->rowid);
219 $updatelevel1 =
false;
221 $price_base_type =
'HT';
230 $newprice =
price2num($obj->price,
'MU');
234 $newvat = str_replace(
'*',
'', $newvatrate);
238 $newdefaultvatcode = $vat_src_code_new;
240 $newpercent = $objectstatic2->fourn_remise_percent;
241 $newdeliverydelay = $objectstatic2->delivery_time_days;
242 $newsupplierreputation = $objectstatic2->supplier_reputation;
245 if (!empty($price_base_type) && !$updatelevel1) {
247 $fourn->id = $obj->fk_soc;
248 $ret = $objectstatic2->update_buyprice($obj->qty, $newprice, $user, $price_base_type, $fourn, $obj->fk_availability, $obj->ref_fourn, $newvat,
'', $newpercent, 0, $newnpr, $newdeliverydelay, $newsupplierreputation, $localtaxes_type, $newdefaultvatcode);
251 if ($ret < 0 || $retm < 0) {
254 $nbrecordsmodified++;
257 unset($objectstatic2);
267 $parameters = array(
'oldvatrate' => $oldvatrate,
'newvatrate' => $newvatrate);
268 $reshook = $hookmanager->executeHooks(
'hookAfterVatUpdate', $parameters);
284 if ($nbrecordsmodified > 0) {
285 setEventMessages($langs->trans(
"RecordsModified", $nbrecordsmodified),
null,
'mesgs');
299$form =
new Form($db);
301$title = $langs->trans(
'ProductVatMassChange');
303llxHeader(
'', $title,
'',
'', 0, 0,
'',
'',
'',
'mod-product page-admin_product_tools');
307print $langs->trans(
"ProductVatMassChangeDesc").
'<br><br>';
309if (empty($mysoc->country_code)) {
310 $langs->load(
"errors");
311 $warnpicto =
img_error($langs->trans(
"WarningMandatorySetupNotComplete"));
312 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/company.php?mainmenu=home">'.$warnpicto.
' '.$langs->trans(
"WarningMandatorySetupNotComplete").
'</a>';
314 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'">';
315 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
316 print
'<input type="hidden" name="action" value="convert" />';
318 print
'<table class="noborder centpercent">';
319 print
'<tr class="liste_titre">';
320 print
'<td>'.$langs->trans(
"Parameters").
'</td>'.
"\n";
321 print
'<td class="right" width="60">'.$langs->trans(
"Value").
'</td>'.
"\n";
325 print
'<tr class="oddeven">'.
"\n";
326 print
'<td>'.$langs->trans(
"OldVATRates").
'</td>'.
"\n";
327 print
'<td width="60" class="right">'.
"\n";
328 print $form->load_tva(
'oldvatrate', $oldvatrate, $mysoc,
null, 0, 0,
'',
false, 1);
333 print
'<tr class="oddeven">'.
"\n";
334 print
'<td>'.$langs->trans(
"NewVATRates").
'</td>'.
"\n";
335 print
'<td width="60" class="right">'.
"\n";
336 print $form->load_tva(
'newvatrate', $newvatrate, $mysoc,
null, 0, 0,
'',
false, 1);
356 print
'<div class="center">';
357 print
'<input type="submit" id="convert_vatrate" name="convert_vatrate" value="'.$langs->trans(
"MassConvert").
'" class="button" />';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage suppliers.
Class to manage predefined suppliers products.
Class to manage products or services.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
img_error($titlealt='default')
Show error logo.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.