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';
46$langs->loadLangs(array(
'admin',
'products'));
53$action =
GETPOST(
'action',
'aZ09');
54$oldvatrate =
GETPOST(
'oldvatrate',
'alpha');
55$newvatrate =
GETPOST(
'newvatrate',
'alpha');
64if ($action ==
'convert') {
67 if ($oldvatrate == $newvatrate) {
68 $langs->load(
"errors");
69 setEventMessages($langs->trans(
"ErrorNewValueCantMatchOldValue"),
null,
'errors');
74 $country_id = $mysoc->country_id;
76 $nbrecordsmodified = 0;
83 $vat_src_code_old =
'';
84 if (preg_match(
'/\((.*)\)/', $oldvatrate, $reg)) {
85 $vat_src_code_old = $reg[1];
86 $oldvatrateclean = preg_replace(
'/\s*\(.*\)/',
'', $oldvatrate);
88 $oldvatrateclean = $oldvatrate;
92 $vat_src_code_new =
'';
93 if (preg_match(
'/\((.*)\)/', $newvatrate, $reg)) {
94 $vat_src_code_new = $reg[1];
95 $newvatrateclean = preg_replace(
'/\s*\(.*\)/',
'', $newvatrate);
97 $newvatrateclean = $newvatrate;
101 if ($country_id == $mysoc->country_id) {
102 $sql =
'SELECT rowid';
103 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product';
104 $sql .=
' WHERE entity IN ('.getEntity(
'product').
')';
105 $sql .=
" AND tva_tx = '".$db->escape($oldvatrateclean).
"'";
106 if ($vat_src_code_old) {
107 $sql .=
" AND default_vat_code = '".$db->escape($vat_src_code_old).
"'";
109 $sql .=
" AND default_vat_code = IS NULL";
112 $resql = $db->query($sql);
114 $num = $db->num_rows($resql);
118 $obj = $db->fetch_object($resql);
120 $objectstatic =
new Product($db);
121 $ret = $objectstatic->fetch($obj->rowid);
125 $updatelevel1 =
false;
128 $listofmulti = array_reverse($objectstatic->multiprices,
true);
129 foreach ($listofmulti as $level => $multiprices) {
130 $price_base_type = $objectstatic->multiprices_base_type[$level];
131 if (empty($price_base_type)) {
135 if ($price_base_type ==
'TTC') {
136 $newprice =
price2num($objectstatic->multiprices_ttc[$level],
'MU');
137 $newminprice = $objectstatic->multiprices_min_ttc[$level];
139 $newprice =
price2num($objectstatic->multiprices[$level],
'MU');
140 $newminprice = $objectstatic->multiprices_min[$level];
142 if ($newminprice > $newprice) {
143 $newminprice = $newprice;
146 $newvat = str_replace(
'*',
'', $newvatrate);
148 $newnpr = $objectstatic->multiprices_recuperableonly[$level];
149 $newdefaultvatcode = $vat_src_code_new;
153 $retm = $objectstatic->updatePrice($newprice, $price_base_type, $user, $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode);
159 if ($newlevel == 1) {
160 $updatelevel1 =
true;
165 $price_base_type = $objectstatic->price_base_type;
166 if ($price_base_type ==
'TTC') {
167 $newprice =
price2num($objectstatic->price_ttc,
'MU');
168 $newminprice = $objectstatic->price_min_ttc;
170 $newprice =
price2num($objectstatic->price,
'MU');
171 $newminprice = $objectstatic->price_min;
173 if ($newminprice > $newprice) {
174 $newminprice = $newprice;
176 $newvat = str_replace(
'*',
'', $newvatrate);
178 $newnpr = $objectstatic->tva_npr;
179 $newdefaultvatcode = $vat_src_code_new;
181 if (!empty($price_base_type) && !$updatelevel1) {
183 $ret = $objectstatic->updatePrice($newprice, $price_base_type, $user, $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode);
186 if ($ret < 0 || $retm < 0) {
189 $nbrecordsmodified++;
192 unset($objectstatic);
204 $sql =
'SELECT pfp.rowid, pfp.fk_soc, pfp.price as price, pfp.quantity as qty, pfp.fk_availability, pfp.ref_fourn';
205 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price as pfp, '.MAIN_DB_PREFIX.
'societe as s';
206 $sql .=
' WHERE pfp.fk_soc = s.rowid AND pfp.entity IN ('.getEntity(
'product').
')';
207 $sql .=
" AND tva_tx = '".$db->escape($oldvatrate).
"'";
208 if ($vat_src_code_old) {
209 $sql .=
" AND default_vat_code = '".$db->escape($vat_src_code_old).
"'";
211 $sql .=
" AND default_vat_code = IS NULL";
213 $sql .=
" AND s.fk_pays = ".((int) $country_id);
215 $resql = $db->query($sql);
217 $num = $db->num_rows($resql);
221 $obj = $db->fetch_object($resql);
224 $ret = $objectstatic2->fetch_product_fournisseur_price($obj->rowid);
228 $updatelevel1 =
false;
230 $price_base_type =
'HT';
239 $newprice =
price2num($obj->price,
'MU');
243 $newvat = str_replace(
'*',
'', $newvatrate);
247 $newdefaultvatcode = $vat_src_code_new;
249 $newpercent = $objectstatic2->fourn_remise_percent;
250 $newdeliverydelay = $objectstatic2->delivery_time_days;
251 $newsupplierreputation = $objectstatic2->supplier_reputation;
254 if (!empty($price_base_type) && !$updatelevel1) {
256 $fourn->id = $obj->fk_soc;
257 $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);
260 if ($ret < 0 || $retm < 0) {
263 $nbrecordsmodified++;
266 unset($objectstatic2);
276 $parameters = array(
'oldvatrate' => $oldvatrate,
'newvatrate' => $newvatrate);
277 $reshook = $hookmanager->executeHooks(
'hookAfterVatUpdate', $parameters);
293 if ($nbrecordsmodified > 0) {
294 setEventMessages($langs->trans(
"RecordsModified", $nbrecordsmodified),
null,
'mesgs');
308$form =
new Form($db);
310$title = $langs->trans(
'ProductVatMassChange');
312llxHeader(
'', $title,
'',
'', 0, 0,
'',
'',
'',
'mod-product page-admin_product_tools');
316print $langs->trans(
"ProductVatMassChangeDesc").
'<br><br>';
318if (empty($mysoc->country_code)) {
319 $langs->load(
"errors");
320 $warnpicto =
img_error($langs->trans(
"WarningMandatorySetupNotComplete"));
321 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/company.php?mainmenu=home">'.$warnpicto.
' '.$langs->trans(
"WarningMandatorySetupNotComplete").
'</a>';
323 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'">';
324 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
325 print
'<input type="hidden" name="action" value="convert" />';
327 print
'<table class="noborder centpercent">';
328 print
'<tr class="liste_titre">';
329 print
'<td>'.$langs->trans(
"Parameters").
'</td>'.
"\n";
330 print
'<td class="right" width="60">'.$langs->trans(
"Value").
'</td>'.
"\n";
334 print
'<tr class="oddeven">'.
"\n";
335 print
'<td>'.$langs->trans(
"OldVATRates").
'</td>'.
"\n";
336 print
'<td width="60" class="right">'.
"\n";
337 print $form->load_tva(
'oldvatrate', $oldvatrate, $mysoc,
null, 0, 0,
'',
false, 1);
342 print
'<tr class="oddeven">'.
"\n";
343 print
'<td>'.$langs->trans(
"NewVATRates").
'</td>'.
"\n";
344 print
'<td width="60" class="right">'.
"\n";
345 print $form->load_tva(
'newvatrate', $newvatrate, $mysoc,
null, 0, 0,
'',
false, 1);
365 print
'<div class="center">';
366 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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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.