31require
'../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
47$langs->loadLangs(array(
'admin',
'products'));
54$action =
GETPOST(
'action',
'aZ09');
55$oldvatrate =
GETPOST(
'oldvatrate',
'alpha');
56$newvatrate =
GETPOST(
'newvatrate',
'alpha');
65if ($action ==
'convert') {
68 if ($oldvatrate == $newvatrate) {
69 $langs->load(
"errors");
70 setEventMessages($langs->trans(
"ErrorNewValueCantMatchOldValue"),
null,
'errors');
75 $country_id =
$mysoc->country_id;
77 $nbrecordsmodified = 0;
84 $vat_src_code_old =
'';
85 if (preg_match(
'/\((.*)\)/', $oldvatrate, $reg)) {
86 $vat_src_code_old = $reg[1];
87 $oldvatrateclean = preg_replace(
'/\s*\(.*\)/',
'', $oldvatrate);
89 $oldvatrateclean = $oldvatrate;
93 $vat_src_code_new =
'';
94 if (preg_match(
'/\((.*)\)/', $newvatrate, $reg)) {
95 $vat_src_code_new = $reg[1];
96 $newvatrateclean = preg_replace(
'/\s*\(.*\)/',
'', $newvatrate);
98 $newvatrateclean = $newvatrate;
102 if ($country_id ==
$mysoc->country_id) {
103 $sql =
'SELECT rowid';
104 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product';
105 $sql .=
' WHERE entity IN ('.getEntity(
'product').
')';
106 $sql .=
" AND tva_tx = '".$db->escape($oldvatrateclean).
"'";
107 if ($vat_src_code_old) {
108 $sql .=
" AND default_vat_code = '".$db->escape($vat_src_code_old).
"'";
110 $sql .=
" AND default_vat_code = IS NULL";
113 $resql = $db->query($sql);
115 $num = $db->num_rows($resql);
119 $obj = $db->fetch_object($resql);
121 $objectstatic =
new Product($db);
122 $ret = $objectstatic->fetch($obj->rowid);
126 $updatelevel1 =
false;
129 $listofmulti = array_reverse($objectstatic->multiprices,
true);
130 foreach ($listofmulti as $level => $multiprices) {
131 $price_base_type = $objectstatic->multiprices_base_type[$level];
132 if (empty($price_base_type)) {
136 if ($price_base_type ==
'TTC') {
137 $newprice =
price2num($objectstatic->multiprices_ttc[$level],
'MU');
138 $newminprice = $objectstatic->multiprices_min_ttc[$level];
140 $newprice =
price2num($objectstatic->multiprices[$level],
'MU');
141 $newminprice = $objectstatic->multiprices_min[$level];
143 if ($newminprice > $newprice) {
144 $newminprice = $newprice;
147 $newvat = str_replace(
'*',
'', $newvatrate);
149 $newnpr = $objectstatic->multiprices_recuperableonly[$level];
150 $newdefaultvatcode = $vat_src_code_new;
154 $retm = $objectstatic->updatePrice((
float) $newprice, $price_base_type, $user, (
float) $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode);
160 if ($newlevel == 1) {
161 $updatelevel1 =
true;
166 $price_base_type = $objectstatic->price_base_type;
167 if ($price_base_type ==
'TTC') {
168 $newprice =
price2num($objectstatic->price_ttc,
'MU');
169 $newminprice = $objectstatic->price_min_ttc;
171 $newprice =
price2num($objectstatic->price,
'MU');
172 $newminprice = $objectstatic->price_min;
174 if ($newminprice > $newprice) {
175 $newminprice = $newprice;
177 $newvat = str_replace(
'*',
'', $newvatrate);
179 $newnpr = $objectstatic->tva_npr;
180 $newdefaultvatcode = $vat_src_code_new;
182 if (!empty($price_base_type) && !$updatelevel1) {
184 $ret = $objectstatic->updatePrice((
float) $newprice, $price_base_type, $user, (
float) $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode);
187 if ($ret < 0 || $retm < 0) {
190 $nbrecordsmodified++;
193 unset($objectstatic);
205 $sql =
'SELECT pfp.rowid, pfp.fk_soc, pfp.price as price, pfp.quantity as qty, pfp.fk_availability, pfp.ref_fourn';
206 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price as pfp, '.MAIN_DB_PREFIX.
'societe as s';
207 $sql .=
' WHERE pfp.fk_soc = s.rowid AND pfp.entity IN ('.getEntity(
'product').
')';
208 $sql .=
" AND tva_tx = '".$db->escape($oldvatrate).
"'";
209 if ($vat_src_code_old) {
210 $sql .=
" AND default_vat_code = '".$db->escape($vat_src_code_old).
"'";
212 $sql .=
" AND default_vat_code = IS NULL";
214 $sql .=
" AND s.fk_pays = ".((int) $country_id);
216 $resql = $db->query($sql);
218 $num = $db->num_rows($resql);
222 $obj = $db->fetch_object($resql);
225 $ret = $objectstatic2->fetch_product_fournisseur_price($obj->rowid);
229 $updatelevel1 =
false;
231 $price_base_type =
'HT';
240 $newprice =
price2num($obj->price,
'MU');
244 $newvat = str_replace(
'*',
'', $newvatrate);
248 $newdefaultvatcode = $vat_src_code_new;
250 $newpercent = $objectstatic2->fourn_remise_percent;
251 $newdeliverydelay = $objectstatic2->delivery_time_days;
252 $newsupplierreputation = $objectstatic2->supplier_reputation;
255 if (!empty($price_base_type) && !$updatelevel1) {
257 $fourn->id = $obj->fk_soc;
258 $ret = $objectstatic2->update_buyprice($obj->qty, (
float) $newprice, $user, $price_base_type, $fourn, $obj->fk_availability, $obj->ref_fourn, (
float) $newvat,
'', $newpercent, 0, $newnpr, $newdeliverydelay, $newsupplierreputation, $localtaxes_type, $newdefaultvatcode);
261 if ($ret < 0 || $retm < 0) {
264 $nbrecordsmodified++;
267 unset($objectstatic2);
277 $parameters = array(
'oldvatrate' => $oldvatrate,
'newvatrate' => $newvatrate);
278 $reshook = $hookmanager->executeHooks(
'hookAfterVatUpdate', $parameters);
294 if ($nbrecordsmodified > 0) {
295 setEventMessages($langs->trans(
"RecordsModified", $nbrecordsmodified),
null,
'mesgs');
309$form =
new Form($db);
311$title = $langs->trans(
'ProductVatMassChange');
313llxHeader(
'', $title,
'',
'', 0, 0,
'',
'',
'',
'mod-product page-admin_product_tools');
317print $langs->trans(
"ProductVatMassChangeDesc").
'<br><br>';
319if (empty(
$mysoc->country_code)) {
320 $langs->load(
"errors");
321 $warnpicto =
img_error($langs->trans(
"WarningMandatorySetupNotComplete"));
322 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/company.php?mainmenu=home">'.$warnpicto.
' '.$langs->trans(
"WarningMandatorySetupNotComplete").
'</a>';
324 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'">';
325 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
326 print
'<input type="hidden" name="action" value="convert" />';
328 print
'<table class="noborder centpercent">';
329 print
'<tr class="liste_titre">';
330 print
'<td>'.$langs->trans(
"Parameters").
'</td>'.
"\n";
331 print
'<td class="right" width="60">'.$langs->trans(
"Value").
'</td>'.
"\n";
335 print
'<tr class="oddeven">'.
"\n";
336 print
'<td>'.$langs->trans(
"OldVATRates").
'</td>'.
"\n";
337 print
'<td width="60" class="right">'.
"\n";
338 print $form->load_tva(
'oldvatrate', $oldvatrate,
$mysoc,
null, 0, 0,
'',
false, 1);
343 print
'<tr class="oddeven">'.
"\n";
344 print
'<td>'.$langs->trans(
"NewVATRates").
'</td>'.
"\n";
345 print
'<td width="60" class="right">'.
"\n";
346 print $form->load_tva(
'newvatrate', $newvatrate,
$mysoc,
null, 0, 0,
'',
false, 1);
366 print
'<div class="center">';
367 print
'<input type="submit" id="convert_vatrate" name="convert_vatrate" value="'.$langs->trans(
"MassConvert").
'" class="button" />';
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.