29require
'../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
36$langs->loadLangs(array(
'admin',
'products'));
43$action =
GETPOST(
'action',
'aZ09');
44$oldvatrate =
GETPOST(
'oldvatrate',
'alpha');
45$newvatrate =
GETPOST(
'newvatrate',
'alpha');
54if ($action ==
'convert') {
57 if ($oldvatrate == $newvatrate) {
58 $langs->load(
"errors");
59 setEventMessages($langs->trans(
"ErrorNewValueCantMatchOldValue"),
null,
'errors');
64 $country_id = $mysoc->country_id;
66 $nbrecordsmodified = 0;
71 $vat_src_code_old =
'';
72 if (preg_match(
'/\((.*)\)/', $oldvatrate, $reg)) {
73 $vat_src_code_old = $reg[1];
74 $oldvatrateclean = preg_replace(
'/\s*\(.*\)/',
'', $oldvatrate);
76 $oldvatrateclean = $oldvatrate;
80 $vat_src_code_new =
'';
81 if (preg_match(
'/\((.*)\)/', $newvatrate, $reg)) {
82 $vat_src_code_new = $reg[1];
83 $newvatrateclean = preg_replace(
'/\s*\(.*\)/',
'', $newvatrate);
85 $newvatrateclean = $newvatrate;
89 if ($country_id == $mysoc->country_id) {
90 $sql =
'SELECT rowid';
91 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product';
92 $sql .=
' WHERE entity IN ('.getEntity(
'product').
')';
93 $sql .=
" AND tva_tx = '".$db->escape($oldvatrateclean).
"'";
94 if ($vat_src_code_old) {
95 $sql .=
" AND default_vat_code = '".$db->escape($vat_src_code_old).
"'";
97 " AND default_vat_code = IS NULL";
100 $resql = $db->query($sql);
102 $num = $db->num_rows($resql);
106 $obj = $db->fetch_object($resql);
108 $objectstatic =
new Product($db);
109 $ret = $objectstatic->fetch($obj->rowid);
113 $updatelevel1 =
false;
116 $listofmulti = array_reverse($objectstatic->multiprices,
true);
117 foreach ($listofmulti as $level => $multiprices) {
118 $price_base_type = $objectstatic->multiprices_base_type[$level];
119 if (empty($price_base_type)) {
123 if ($price_base_type ==
'TTC') {
124 $newprice =
price2num($objectstatic->multiprices_ttc[$level],
'MU');
125 $newminprice = $objectstatic->multiprices_min_ttc[$level];
127 $newprice =
price2num($objectstatic->multiprices[$level],
'MU');
128 $newminprice = $objectstatic->multiprices_min[$level];
130 if ($newminprice > $newprice) {
131 $newminprice = $newprice;
134 $newvat = str_replace(
'*',
'', $newvatrate);
136 $newnpr = $objectstatic->multiprices_recuperableonly[$level];
137 $newdefaultvatcode = $vat_src_code_new;
141 $retm = $objectstatic->updatePrice($newprice, $price_base_type, $user, $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode);
147 if ($newlevel == 1) {
148 $updatelevel1 =
true;
153 $price_base_type = $objectstatic->price_base_type;
154 if ($price_base_type ==
'TTC') {
155 $newprice =
price2num($objectstatic->price_ttc,
'MU');
156 $newminprice = $objectstatic->price_min_ttc;
158 $newprice =
price2num($objectstatic->price,
'MU');
159 $newminprice = $objectstatic->price_min;
161 if ($newminprice > $newprice) {
162 $newminprice = $newprice;
164 $newvat = str_replace(
'*',
'', $newvatrate);
166 $newnpr = $objectstatic->tva_npr;
167 $newdefaultvatcode = $vat_src_code_new;
169 if (!empty($price_base_type) && !$updatelevel1) {
171 $ret = $objectstatic->updatePrice($newprice, $price_base_type, $user, $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode);
174 if ($ret < 0 || $retm < 0) {
177 $nbrecordsmodified++;
180 unset($objectstatic);
192 $sql =
'SELECT pfp.rowid, pfp.fk_soc, pfp.price as price, pfp.quantity as qty, pfp.fk_availability, pfp.ref_fourn';
193 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price as pfp, '.MAIN_DB_PREFIX.
'societe as s';
194 $sql .=
' WHERE pfp.fk_soc = s.rowid AND pfp.entity IN ('.getEntity(
'product').
')';
195 $sql .=
" AND tva_tx = '".$db->escape($oldvatrate).
"'";
196 if ($vat_src_code_old) {
197 $sql .=
" AND default_vat_code = '".$db->escape($vat_src_code_old).
"'";
199 " AND default_vat_code = IS NULL";
201 $sql .=
" AND s.fk_pays = ".((int) $country_id);
203 $resql = $db->query($sql);
205 $num = $db->num_rows($resql);
209 $obj = $db->fetch_object($resql);
212 $ret = $objectstatic2->fetch_product_fournisseur_price($obj->rowid);
216 $updatelevel1 =
false;
218 $price_base_type =
'HT';
227 $newprice =
price2num($obj->price,
'MU');
231 $newvat = str_replace(
'*',
'', $newvatrate);
235 $newdefaultvatcode = $vat_src_code_new;
237 $newpercent = $objectstatic2->fourn_remise_percent;
238 $newdeliverydelay = $objectstatic2->delivery_time_days;
239 $newsupplierreputation = $objectstatic2->supplier_reputation;
242 if (!empty($price_base_type) && !$updatelevel1) {
244 $fourn->id = $obj->fk_soc;
245 $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);
248 if ($ret < 0 || $retm < 0) {
251 $nbrecordsmodified++;
254 unset($objectstatic2);
270 if ($nbrecordsmodified > 0) {
271 setEventMessages($langs->trans(
"RecordsModified", $nbrecordsmodified),
null,
'mesgs');
285$form =
new Form($db);
287$title = $langs->trans(
'ProductVatMassChange');
293print $langs->trans(
"ProductVatMassChangeDesc").
'<br><br>';
295if (empty($mysoc->country_code)) {
296 $langs->load(
"errors");
297 $warnpicto =
img_error($langs->trans(
"WarningMandatorySetupNotComplete"));
298 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/company.php?mainmenu=home">'.$warnpicto.
' '.$langs->trans(
"WarningMandatorySetupNotComplete").
'</a>';
300 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'">';
301 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
302 print
'<input type="hidden" name="action" value="convert" />';
304 print
'<table class="noborder centpercent">';
305 print
'<tr class="liste_titre">';
306 print
'<td>'.$langs->trans(
"Parameters").
'</td>'.
"\n";
307 print
'<td class="right" width="60">'.$langs->trans(
"Value").
'</td>'.
"\n";
311 print
'<tr class="oddeven">'.
"\n";
312 print
'<td>'.$langs->trans(
"OldVATRates").
'</td>'.
"\n";
313 print
'<td width="60" class="right">'.
"\n";
314 print $form->load_tva(
'oldvatrate', $oldvatrate, $mysoc,
null, 0, 0,
'',
false, 1);
319 print
'<tr class="oddeven">'.
"\n";
320 print
'<td>'.$langs->trans(
"NewVATRates").
'</td>'.
"\n";
321 print
'<td width="60" class="right">'.
"\n";
322 print $form->load_tva(
'newvatrate', $newvatrate, $mysoc,
null, 0, 0,
'',
false, 1);
342 print
'<div class="center">';
343 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($titre, $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 '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.