32require
'../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
48$langs->loadLangs(array(
'admin',
'products'));
55$action =
GETPOST(
'action',
'aZ09');
56$oldvatrate =
GETPOST(
'oldvatrate',
'alpha');
57$newvatrate =
GETPOST(
'newvatrate',
'alpha');
60$hookmanager->initHooks(array(
'productvatadmin'));
66if ($action ==
'convert') {
69 if ($oldvatrate == $newvatrate) {
70 $langs->load(
"errors");
71 setEventMessages($langs->trans(
"ErrorNewValueCantMatchOldValue"),
null,
'errors');
76 $country_id =
$mysoc->country_id;
78 $nbrecordsmodified = 0;
85 $vat_src_code_old =
'';
86 if (preg_match(
'/\((.*)\)/', $oldvatrate, $reg)) {
87 $vat_src_code_old = $reg[1];
88 $oldvatrateclean = preg_replace(
'/\s*\(.*\)/',
'', $oldvatrate);
90 $oldvatrateclean = $oldvatrate;
94 $vat_src_code_new =
'';
95 if (preg_match(
'/\((.*)\)/', $newvatrate, $reg)) {
96 $vat_src_code_new = $reg[1];
97 $newvatrateclean = preg_replace(
'/\s*\(.*\)/',
'', $newvatrate);
99 $newvatrateclean = $newvatrate;
103 if ($country_id ==
$mysoc->country_id) {
104 $sql =
'SELECT rowid';
105 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product';
106 $sql .=
' WHERE entity IN ('.getEntity(
'product').
')';
107 $sql .=
" AND tva_tx = '".$db->escape($oldvatrateclean).
"'";
108 if ($vat_src_code_old) {
109 $sql .=
" AND default_vat_code = '".$db->escape($vat_src_code_old).
"'";
111 $sql .=
" AND (default_vat_code IS NULL OR default_vat_code = '')";
114 $resql =
$db->query($sql);
116 $num =
$db->num_rows($resql);
120 $obj =
$db->fetch_object($resql);
123 $ret = $objectstatic->fetch($obj->rowid);
127 $updatelevel1 =
false;
130 $listofmulti = array_reverse($objectstatic->multiprices,
true);
131 foreach ($listofmulti as $level => $multiprices) {
132 $price_base_type = $objectstatic->multiprices_base_type[$level];
133 if (empty($price_base_type)) {
137 if ($price_base_type ==
'TTC') {
138 $newprice =
price2num($objectstatic->multiprices_ttc[$level],
'MU');
139 $newminprice = $objectstatic->multiprices_min_ttc[$level];
141 $newprice =
price2num($objectstatic->multiprices[$level],
'MU');
142 $newminprice = $objectstatic->multiprices_min[$level];
144 if ($newminprice > $newprice) {
145 $newminprice = $newprice;
148 $newvat = str_replace(
'*',
'', $newvatrate);
150 $newnpr = $objectstatic->multiprices_recuperableonly[$level];
151 $newdefaultvatcode = $vat_src_code_new;
155 $retm = $objectstatic->updatePrice((
float) $newprice, $price_base_type, $user, (
float) $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode);
161 if ($newlevel == 1) {
162 $updatelevel1 =
true;
167 $price_base_type = $objectstatic->price_base_type;
168 if ($price_base_type ==
'TTC') {
169 $newprice =
price2num($objectstatic->price_ttc,
'MU');
170 $newminprice = $objectstatic->price_min_ttc;
172 $newprice =
price2num($objectstatic->price,
'MU');
173 $newminprice = $objectstatic->price_min;
175 if ($newminprice > $newprice) {
176 $newminprice = $newprice;
178 $newvat = str_replace(
'*',
'', $newvatrate);
180 $newnpr = $objectstatic->tva_npr;
181 $newdefaultvatcode = $vat_src_code_new;
183 if (!empty($price_base_type) && !$updatelevel1) {
185 $ret = $objectstatic->updatePrice((
float) $newprice, $price_base_type, $user, (
float) $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode);
188 if ($ret < 0 || $retm < 0) {
191 $nbrecordsmodified++;
194 unset($objectstatic);
205 $sweepwhere =
" AND tva_tx = '".$db->escape($oldvatrateclean).
"'";
206 if ($vat_src_code_old) {
207 $sweepwhere .=
" AND default_vat_code = '".$db->escape($vat_src_code_old).
"'";
209 $sweepwhere .=
" AND (default_vat_code IS NULL OR default_vat_code = '')";
211 $db->query(
"UPDATE ".MAIN_DB_PREFIX.
"product SET tva_tx = '".
$db->escape($newvatrateclean).
"', default_vat_code = '".
$db->escape($vat_src_code_new).
"' WHERE entity IN (".
getEntity(
'product').
")".$sweepwhere);
212 $db->query(
"UPDATE ".MAIN_DB_PREFIX.
"product_price SET tva_tx = '".
$db->escape($newvatrateclean).
"', default_vat_code = '".
$db->escape($vat_src_code_new).
"' WHERE 1 = 1".$sweepwhere);
218 $sql =
'SELECT pfp.rowid, pfp.fk_soc, pfp.price as price, pfp.quantity as qty, pfp.fk_availability, pfp.ref_fourn';
219 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price as pfp, '.MAIN_DB_PREFIX.
'societe as s';
220 $sql .=
' WHERE pfp.fk_soc = s.rowid AND pfp.entity IN ('.getEntity(
'product').
')';
221 $sql .=
" AND tva_tx = '".$db->escape($oldvatrate).
"'";
222 if ($vat_src_code_old) {
223 $sql .=
" AND default_vat_code = '".$db->escape($vat_src_code_old).
"'";
225 $sql .=
" AND (default_vat_code IS NULL OR default_vat_code = '')";
227 $sql .=
" AND s.fk_pays = ".((int) $country_id);
229 $resql =
$db->query($sql);
231 $num =
$db->num_rows($resql);
235 $obj =
$db->fetch_object($resql);
238 $ret = $objectstatic2->fetch_product_fournisseur_price($obj->rowid);
242 $updatelevel1 =
false;
244 $price_base_type =
'HT';
253 $newprice =
price2num($obj->price,
'MU');
257 $newvat = str_replace(
'*',
'', $newvatrate);
261 $newdefaultvatcode = $vat_src_code_new;
263 $newpercent = $objectstatic2->fourn_remise_percent;
264 $newdeliverydelay = $objectstatic2->delivery_time_days;
265 $newsupplierreputation = $objectstatic2->supplier_reputation;
268 if (!empty($price_base_type) && !$updatelevel1) {
270 $fourn->id = $obj->fk_soc;
271 $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);
274 if ($ret < 0 || $retm < 0) {
277 $nbrecordsmodified++;
280 unset($objectstatic2);
290 $parameters = array(
'oldvatrate' => $oldvatrate,
'newvatrate' => $newvatrate);
291 $reshook = $hookmanager->executeHooks(
'hookAfterVatUpdate', $parameters);
307 if ($nbrecordsmodified > 0) {
308 setEventMessages($langs->trans(
"RecordsModified", $nbrecordsmodified),
null,
'mesgs');
324$title = $langs->trans(
'ProductVatMassChange');
326llxHeader(
'', $title,
'',
'', 0, 0,
'',
'',
'',
'mod-product page-admin_product_tools');
330print $langs->trans(
"ProductVatMassChangeDesc").
'<br><br>';
332if (empty(
$mysoc->country_code)) {
333 $langs->load(
"errors");
334 $warnpicto =
img_error($langs->trans(
"WarningMandatorySetupNotComplete"));
335 print
'<br><a href="'.DOL_URL_ROOT.
'/admin/company.php?mainmenu=home">'.$warnpicto.
' '.$langs->trans(
"WarningMandatorySetupNotComplete").
'</a>';
337 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'">';
338 print
'<input type="hidden" name="token" value="'.newToken().
'" />';
339 print
'<input type="hidden" name="action" value="convert" />';
341 print
'<table class="noborder centpercent">';
342 print
'<tr class="liste_titre">';
343 print
'<td>'.$langs->trans(
"Parameters").
'</td>'.
"\n";
344 print
'<td class="right" width="60">'.$langs->trans(
"Value").
'</td>'.
"\n";
348 print
'<tr class="oddeven">'.
"\n";
349 print
'<td>'.$langs->trans(
"OldVATRates").
'</td>'.
"\n";
350 print
'<td width="60" class="right">'.
"\n";
353 print
'<select class="flat" name="oldvatrate" id="oldvatrate">';
354 $sqloldvat =
"SELECT tva_tx, default_vat_code, COUNT(*) as nb FROM ".MAIN_DB_PREFIX.
"product";
355 $sqloldvat .=
" WHERE entity IN (".getEntity(
'product').
") AND tva_tx IS NOT NULL";
356 $sqloldvat .=
" GROUP BY tva_tx, default_vat_code ORDER BY tva_tx DESC, default_vat_code";
357 $resqloldvat =
$db->query($sqloldvat);
358 while ($resqloldvat && $objoldvat =
$db->fetch_object($resqloldvat)) {
359 $rateclean =
price2num($objoldvat->tva_tx);
360 $hascode = !empty($objoldvat->default_vat_code);
361 $optval = $rateclean.($hascode ?
' ('.$objoldvat->default_vat_code.
')' :
'');
362 $optlbl =
vatrate($rateclean,
true).($hascode ?
' ('.$objoldvat->default_vat_code.
')' :
' ('.$langs->trans(
"WithoutVATCode").
')').
' ('.$objoldvat->nb.
')';
363 print
'<option value="'.dol_escape_htmltag($optval).
'"'.((
string) $oldvatrate === (
string) $optval ?
' selected' :
'').
'>'.$optlbl.
'</option>';
370 print
'<tr class="oddeven">'.
"\n";
371 print
'<td>'.$langs->trans(
"NewVATRates").
'</td>'.
"\n";
372 print
'<td width="60" class="right">'.
"\n";
373 print $form->load_tva(
'newvatrate', $newvatrate,
$mysoc,
null, 0, 0,
'',
false, 1);
393 print
'<div class="center">';
394 print
'<input type="submit" id="convert_vatrate" name="convert_vatrate" value="'.$langs->trans(
"MassConvert").
'" class="button" />';
404 jQuery("#convert_vatrate").closest("form").on("submit", function() {
405 dolBlockUI("'.dol_escape_js($langs->transnoentities(
"MassConvertInProgress")).
'");
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.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.