Retrieve vat details from the Greek Ministry of Finance GSIS SOAP web service and autocomplete third party fields

This commit is contained in:
sonikf 2023-09-12 00:44:22 +03:00 committed by GitHub
parent 689f4b63ea
commit ee09db0e55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,8 @@
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es.com>
* Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2022-2023 George Gkantinas <info@geowv.eu>
* Copyright (C) 2023 Nick Fragoulis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -63,6 +65,12 @@ if (isModEnabled('eventorganization')) {
require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
}
if ($mysoc->country_code == 'GR') {
$u = $conf->global->AADE_WEBSERVICE_USER;
$p = $conf->global->AADE_WEBSERVICE_KEY;
$myafm = $mysoc->tva_intra;
}
// Load translation files required by the page
@ -385,13 +393,13 @@ if (empty($reshook)) {
}
if ($action == 'set_localtax1') {
//obtidre selected del combobox
//get selected from combobox
$value = GETPOST('lt1');
$object->fetch($socid);
$res = $object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
}
if ($action == 'set_localtax2') {
//obtidre selected del combobox
//get selected from combobox
$value = GETPOST('lt2');
$object->fetch($socid);
$res = $object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
@ -895,7 +903,7 @@ if (empty($reshook)) {
break;
}
}
// Gestion du logo de la société
// Company logo management
// Update linked member
@ -1187,7 +1195,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
$object->logo = (isset($_FILES['photo']) ?dol_sanitizeFileName($_FILES['photo']['name']) : '');
// Gestion du logo de la société
// Company logo management
$dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos";
$file_OK = (isset($_FILES['photo']) ?is_uploaded_file($_FILES['photo']['tmp_name']) : false);
if ($file_OK) {
@ -1728,8 +1736,11 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print "\n";
print '<script type="text/javascript">';
print "function CheckVAT(a) {\n";
print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
print "}\n";
if ($mysoc->country_code == 'GR' && $object->country_code == 'GR') {
print "GRVAT(a,'{$u}','{$p}','{$myafm}');\n";
}
else { print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
}print "}\n";
print '</script>';
print "\n";
$s .= '<a href="#" class="hideonsmartphone" onclick="CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
@ -1957,7 +1968,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
}
}
$modCodeClient = new $module($db);
// We verified if the tag prefix is used
// We check if the prefix tag is used
if ($modCodeClient->code_auto) {
$prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed();
}
@ -1973,7 +1984,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
}
}
$modCodeFournisseur = new $module($db);
// On verifie si la balise prefix est utilisee
// We check if the prefix tag is used
if ($modCodeFournisseur->code_auto) {
$prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed();
}
@ -2500,7 +2511,11 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print "\n";
print '<script type="text/javascript">';
print "function CheckVAT(a) {\n";
print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
if ($mysoc->country_code == 'GR' && $object->country_code == 'GR') {
print "GRVAT(a,'{$u}','{$p}','{$myafm}');\n";
}
else { print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
}
print "}\n";
print '</script>';
print "\n";
@ -2968,7 +2983,11 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print "\n";
print '<script type="text/javascript">';
print "function CheckVAT(a) {\n";
print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
if ($mysoc->country_code == 'GR' && $object->country_code == 'GR') {
print "GRVAT(a,'{$u}','{$p}','{$myafm}');\n";
}
else { print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
}
print "}\n";
print '</script>';
print "\n";
@ -3339,3 +3358,47 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
// End of page
llxFooter();
$db->close();
?>
<script>
// Function to retrieve VAT details from the Greek Ministry of Finance GSIS SOAP web service
function GRVAT(a, u, p, myafm) {
var afm = a.replace(/\D/g, ""); // Remove non-digit characters from 'a'
$.ajax({
type: "GET",
url: "/societe/checkvat/checkVatGr.php",
data: { u: u, p: p, myafm: myafm, afm: afm }, // Set request parameters
success: function(data) {
var obj = JSON.parse(data); // Parse response data as JSON
// Update form fields based on retrieved data
if (obj.RgWsPublicBasicRt_out.afm === null) {
alert(obj.pErrorRec_out.errorDescr); // Display error message if AFM is null
} else {
$("#name").val(obj.RgWsPublicBasicRt_out.onomasia); // Set 'name' field value
$("#address").val(obj.RgWsPublicBasicRt_out.postalAddress + " " + obj.RgWsPublicBasicRt_out.postalAddressNo); // Set 'address' field value
$("#zipcode").val(obj.RgWsPublicBasicRt_out.postalZipCode); // Set 'zipcode' field value
$("#town").val(obj.RgWsPublicBasicRt_out.postalAreaDescription); // Set 'town' field value
$("#idprof2").val(obj.RgWsPublicBasicRt_out.doyDescr); // Set 'idprof2' field value
$("#name_alias_input").val(obj.RgWsPublicBasicRt_out.commerTitle); // Set 'name_alias' field value
if (obj.arrayOfRgWsPublicFirmActRt_out.RgWsPublicFirmActRtUser) {
var firmActUser = obj.arrayOfRgWsPublicFirmActRt_out.RgWsPublicFirmActRtUser;
if (Array.isArray(firmActUser)) {
var primaryFirmAct = firmActUser.find(item => item.firmActKindDescr === "ΚΥΡΙΑ"); // Find primary client activity
if (primaryFirmAct) {
$("#idprof1").val(primaryFirmAct.firmActDescr); // Set 'idprof1' field value
}
} else {
$("#idprof1").val(firmActUser.firmActDescr); // Set 'idprof1' field value
}
}
}
}
});
}
</script>