28 require
'../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
35 $langs->loadLangs(array(
'admin',
'products'));
40 $action =
GETPOST(
'action',
'aZ09');
41 $oldvatrate =
GETPOST(
'oldvatrate',
'alpha');
42 $newvatrate =
GETPOST(
'newvatrate',
'alpha');
51 if ($action ==
'convert')
55 if ($oldvatrate == $newvatrate)
57 $langs->load(
"errors");
58 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))
74 $vat_src_code_old = $reg[1];
75 $oldvatrateclean = preg_replace(
'/\s*\(.*\)/',
'', $oldvatrate);
76 }
else $oldvatrateclean = $oldvatrate;
79 $vat_src_code_new =
'';
80 if (preg_match(
'/\((.*)\)/', $newvatrate, $reg))
82 $vat_src_code_new = $reg[1];
83 $newvatrateclean = preg_replace(
'/\s*\(.*\)/',
'', $newvatrate);
84 }
else $newvatrateclean = $newvatrate;
87 if ($country_id == $mysoc->country_id)
89 $sql =
'SELECT rowid';
90 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product';
91 $sql .=
' WHERE entity IN ('.getEntity(
'product').
')';
92 $sql .=
" AND tva_tx = '".$db->escape($oldvatrateclean).
"'";
93 if ($vat_src_code_old) $sql .=
" AND default_vat_code = '".$db->escape($vat_src_code_old).
"'";
94 else " AND default_vat_code = IS NULL";
99 $num = $db->num_rows(
$resql);
104 $obj = $db->fetch_object(
$resql);
106 $objectstatic =
new Product($db);
107 $ret = $objectstatic->fetch($obj->rowid);
110 $ret = 0; $retm = 0; $updatelevel1 =
false;
113 $listofmulti = array_reverse($objectstatic->multiprices,
true);
114 foreach ($listofmulti as $level => $multiprices)
116 $price_base_type = $objectstatic->multiprices_base_type[$level];
117 if (empty($price_base_type))
continue;
119 if ($price_base_type ==
'TTC')
121 $newprice =
price2num($objectstatic->multiprices_ttc[$level],
'MU');
122 $newminprice = $objectstatic->multiprices_min_ttc[$level];
124 $newprice =
price2num($objectstatic->multiprices[$level],
'MU');
125 $newminprice = $objectstatic->multiprices_min[$level];
127 if ($newminprice > $newprice) $newminprice = $newprice;
129 $newvat = str_replace(
'*',
'', $newvatrate);
131 $newnpr = $objectstatic->multiprices_recuperableonly[$level];
132 $newdefaultvatcode = $vat_src_code_new;
136 $retm = $objectstatic->updatePrice($newprice, $price_base_type, $user, $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode);
143 if ($newlevel == 1) $updatelevel1 =
true;
147 $price_base_type = $objectstatic->price_base_type;
148 if ($price_base_type ==
'TTC')
150 $newprice =
price2num($objectstatic->price_ttc,
'MU');
151 $newminprice = $objectstatic->price_min_ttc;
153 $newprice =
price2num($objectstatic->price,
'MU');
154 $newminprice = $objectstatic->price_min;
156 if ($newminprice > $newprice) $newminprice = $newprice;
157 $newvat = str_replace(
'*',
'', $newvatrate);
159 $newnpr = $objectstatic->recuperableonly;
160 $newdefaultvatcode = $vat_src_code_new;
162 if (!empty($price_base_type) && !$updatelevel1)
165 $ret = $objectstatic->updatePrice($newprice, $price_base_type, $user, $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode);
168 if ($ret < 0 || $retm < 0) $error++;
169 else $nbrecordsmodified++;
171 unset($objectstatic);
181 $sql =
'SELECT pfp.rowid, pfp.fk_soc, pfp.price as price, pfp.quantity as qty, pfp.fk_availability, pfp.ref_fourn';
182 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_fournisseur_price as pfp, '.MAIN_DB_PREFIX.
'societe as s';
183 $sql .=
' WHERE pfp.fk_soc = s.rowid AND pfp.entity IN ('.getEntity(
'product').
')';
184 $sql .=
" AND tva_tx = '".$db->escape($oldvatrate).
"'";
185 if ($vat_src_code_old) $sql .=
" AND default_vat_code = '".$db->escape($vat_src_code_old).
"'";
186 else " AND default_vat_code = IS NULL";
187 $sql .=
" AND s.fk_pays = ".((int) $country_id);
189 $resql = $db->query($sql);
192 $num = $db->num_rows(
$resql);
197 $obj = $db->fetch_object(
$resql);
200 $ret = $objectstatic2->fetch_product_fournisseur_price($obj->rowid);
203 $ret = 0; $retm = 0; $updatelevel1 =
false;
205 $price_base_type =
'HT';
214 $newprice =
price2num($obj->price,
'MU');
218 $newvat = str_replace(
'*',
'', $newvatrate);
222 $newdefaultvatcode = $vat_src_code_new;
224 $newpercent = $objectstatic2->fourn_remise_percent;
225 $newdeliverydelay = $objectstatic2->delivery_time_days;
226 $newsupplierreputation = $objectstatic2->supplier_reputation;
229 if (!empty($price_base_type) && !$updatelevel1)
232 $fourn->id = $obj->fk_soc;
233 $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);
236 if ($ret < 0 || $retm < 0) $error++;
237 else $nbrecordsmodified++;
239 unset($objectstatic2);
255 if ($nbrecordsmodified > 0)
setEventMessages($langs->trans(
"RecordsModified", $nbrecordsmodified), null,
'mesgs');
267 $form =
new Form($db);
269 $title = $langs->trans(
'ProductVatMassChange');
275 print $langs->trans(
"ProductVatMassChangeDesc").
'<br><br>';
277 if (empty($mysoc->country_code))
279 $langs->load(
"errors");
280 $warnpicto =
img_error($langs->trans(
"WarningMandatorySetupNotComplete"));
281 print '<br><a href="'.DOL_URL_ROOT.
'/admin/company.php?mainmenu=home">'.$warnpicto.
' '.$langs->trans(
"WarningMandatorySetupNotComplete").
'</a>';
283 print '<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'">';
284 print '<input type="hidden" name="token" value="'.newToken().
'" />';
285 print '<input type="hidden" name="action" value="convert" />';
287 print '<table class="noborder centpercent">';
288 print '<tr class="liste_titre">';
289 print '<td>'.$langs->trans(
"Parameters").
'</td>'.
"\n";
290 print '<td class="right" width="60">'.$langs->trans(
"Value").
'</td>'.
"\n";
294 print '<tr class="oddeven">'.
"\n";
295 print '<td>'.$langs->trans(
"OldVATRates").
'</td>'.
"\n";
296 print '<td width="60" class="right">'.
"\n";
297 print $form->load_tva(
'oldvatrate', $oldvatrate, $mysoc, null, 0, 0,
'',
false, 1);
302 print '<tr class="oddeven">'.
"\n";
303 print '<td>'.$langs->trans(
"NewVATRates").
'</td>'.
"\n";
304 print '<td width="60" class="right">'.
"\n";
305 print $form->load_tva(
'newvatrate', $newvatrate, $mysoc, null, 0, 0,
'',
false, 1);
325 print '<div class="center">';
326 print '<input type="submit" id="convert_vatrate" name="convert_vatrate" value="'.$langs->trans(
"MassConvert").
'" class="button" />';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage products or services.
Class to manage suppliers.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
img_error($titlealt= 'default')
Show error logo.
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 '...
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print
Draft customers invoices.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
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.
Class to manage predefined suppliers products.