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);
111 $ret = 0; $retm = 0; $updatelevel1 =
false;
114 $listofmulti = array_reverse($objectstatic->multiprices,
true);
115 foreach ($listofmulti as $level => $multiprices) {
116 $price_base_type = $objectstatic->multiprices_base_type[$level];
117 if (empty($price_base_type)) {
121 if ($price_base_type ==
'TTC') {
122 $newprice =
price2num($objectstatic->multiprices_ttc[$level],
'MU');
123 $newminprice = $objectstatic->multiprices_min_ttc[$level];
125 $newprice =
price2num($objectstatic->multiprices[$level],
'MU');
126 $newminprice = $objectstatic->multiprices_min[$level];
128 if ($newminprice > $newprice) {
129 $newminprice = $newprice;
132 $newvat = str_replace(
'*',
'', $newvatrate);
134 $newnpr = $objectstatic->multiprices_recuperableonly[$level];
135 $newdefaultvatcode = $vat_src_code_new;
139 $retm = $objectstatic->updatePrice($newprice, $price_base_type, $user, $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode);
145 if ($newlevel == 1) {
146 $updatelevel1 =
true;
151 $price_base_type = $objectstatic->price_base_type;
152 if ($price_base_type ==
'TTC') {
153 $newprice =
price2num($objectstatic->price_ttc,
'MU');
154 $newminprice = $objectstatic->price_min_ttc;
156 $newprice =
price2num($objectstatic->price,
'MU');
157 $newminprice = $objectstatic->price_min;
159 if ($newminprice > $newprice) {
160 $newminprice = $newprice;
162 $newvat = str_replace(
'*',
'', $newvatrate);
164 $newnpr = $objectstatic->recuperableonly;
165 $newdefaultvatcode = $vat_src_code_new;
167 if (!empty($price_base_type) && !$updatelevel1) {
169 $ret = $objectstatic->updatePrice($newprice, $price_base_type, $user, $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode);
172 if ($ret < 0 || $retm < 0) {
175 $nbrecordsmodified++;
178 unset($objectstatic);
190 $sql =
'SELECT pfp.rowid, pfp.fk_soc, pfp.price as price, pfp.quantity as qty, pfp.fk_availability, pfp.ref_fourn';
191 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price as pfp, '.MAIN_DB_PREFIX.
'societe as s';
192 $sql .=
' WHERE pfp.fk_soc = s.rowid AND pfp.entity IN ('.getEntity(
'product').
')';
193 $sql .=
" AND tva_tx = '".$db->escape($oldvatrate).
"'";
194 if ($vat_src_code_old) {
195 $sql .=
" AND default_vat_code = '".$db->escape($vat_src_code_old).
"'";
197 " AND default_vat_code = IS NULL";
199 $sql .=
" AND s.fk_pays = ".((int) $country_id);
201 $resql = $db->query($sql);
203 $num = $db->num_rows($resql);
207 $obj = $db->fetch_object($resql);
210 $ret = $objectstatic2->fetch_product_fournisseur_price($obj->rowid);
212 $ret = 0; $retm = 0; $updatelevel1 =
false;
214 $price_base_type =
'HT';
223 $newprice =
price2num($obj->price,
'MU');
227 $newvat = str_replace(
'*',
'', $newvatrate);
231 $newdefaultvatcode = $vat_src_code_new;
233 $newpercent = $objectstatic2->fourn_remise_percent;
234 $newdeliverydelay = $objectstatic2->delivery_time_days;
235 $newsupplierreputation = $objectstatic2->supplier_reputation;
238 if (!empty($price_base_type) && !$updatelevel1) {
240 $fourn->id = $obj->fk_soc;
241 $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);
244 if ($ret < 0 || $retm < 0) {
247 $nbrecordsmodified++;
250 unset($objectstatic2);
266 if ($nbrecordsmodified > 0) {
267 setEventMessages($langs->trans(
"RecordsModified", $nbrecordsmodified),
null,
'mesgs');
281$form =
new Form($db);
283$title = $langs->trans(
'ProductVatMassChange');
289print $langs->trans(
"ProductVatMassChangeDesc").
'<br><br>';
291if (empty($mysoc->country_code)) {
292 $langs->load(
"errors");
293 $warnpicto =
img_error($langs->trans(
"WarningMandatorySetupNotComplete"));
294 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/company.php?mainmenu=home">'.$warnpicto.
' '.$langs->trans(
"WarningMandatorySetupNotComplete").
'</a>';
296 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'">';
297 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
298 print
'<input type="hidden" name="action" value="convert" />';
300 print
'<table class="noborder centpercent">';
301 print
'<tr class="liste_titre">';
302 print
'<td>'.$langs->trans(
"Parameters").
'</td>'.
"\n";
303 print
'<td class="right" width="60">'.$langs->trans(
"Value").
'</td>'.
"\n";
307 print
'<tr class="oddeven">'.
"\n";
308 print
'<td>'.$langs->trans(
"OldVATRates").
'</td>'.
"\n";
309 print
'<td width="60" class="right">'.
"\n";
310 print $form->load_tva(
'oldvatrate', $oldvatrate, $mysoc,
null, 0, 0,
'',
false, 1);
315 print
'<tr class="oddeven">'.
"\n";
316 print
'<td>'.$langs->trans(
"NewVATRates").
'</td>'.
"\n";
317 print
'<td width="60" class="right">'.
"\n";
318 print $form->load_tva(
'newvatrate', $newvatrate, $mysoc,
null, 0, 0,
'',
false, 1);
338 print
'<div class="center">';
339 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.