Skip to content

Commit

Permalink
Merge pull request Dolibarr#25871 from DoliGreece/sonikf-patch-fetch-…
Browse files Browse the repository at this point in the history
…vat-details

 NEW: Retrieve vat details from the Greek Ministry of Finance GSIS SOAP web service and autocomplete third party fields
  • Loading branch information
eldy authored Oct 2, 2023
2 parents e8f5f32 + da92e4b commit 46bc9de
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 9 deletions.
44 changes: 44 additions & 0 deletions htdocs/admin/company.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Copyright (C) 2011-2017 Philippe Grand <[email protected]>
* Copyright (C) 2015 Alexandre Spangaro <[email protected]>
* Copyright (C) 2017 Rui Strecht <[email protected]>
* 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
Expand Down Expand Up @@ -233,6 +234,14 @@
dolibarr_set_const($db, "MAIN_INFO_LOCALTAX_CALC2", GETPOST("clt2", 'aZ09'), 'chaine', 0, '', $conf->entity);
}

// Credentials for AADE webservices, applicable only for Greece
if ($mysoc->country_code == 'GR') {
dolibarr_set_const($db, "MYDATA_AADE_USER", GETPOST("MYDATA_AADE_USER", 'alpha'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MYDATA_AADE_KEY", GETPOST("MYDATA_AADE_KEY", 'alpha'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "AADE_WEBSERVICE_USER", GETPOST("AADE_WEBSERVICE_USER", 'alpha'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "AADE_WEBSERVICE_KEY", GETPOST("AADE_WEBSERVICE_KEY", 'alpha'), 'chaine', 0, '', $conf->entity);
}

// Remove constant MAIN_INFO_SOCIETE_SETUP_TODO_WARNING
dolibarr_del_const($db, "MAIN_INFO_SOCIETE_SETUP_TODO_WARNING", $conf->entity);

Expand Down Expand Up @@ -847,6 +856,41 @@

print "</table>";

// AADE webservices credentials, applicable only for Greece
if ($mysoc->country_code == 'GR') {
print load_fiche_titre($langs->trans("AADEWebserviceCredentials"), '', '');
print '<table class="noborder centpercent editmode">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("AccountParameter").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print '<td></td>';
print "</tr>\n";

print '<tr class="oddeven"><td>';
print '<span class="titlefield fieldrequired">'.$langs->trans("MYDATA_AADE_USER").'</span></td><td>';
print '<input class="minwidth300" type="text" name="MYDATA_AADE_USER" value="'.getDolGlobalString('MYDATA_AADE_USER').'"';
print '</td><td></td></tr>';

print '<tr class="oddeven"><td>';
print '<span class="titlefield fieldrequired">'.$langs->trans("MYDATA_AADE_KEY").'</span></td><td>';
print '<input class="minwidth300" type="text" name="MYDATA_AADE_KEY="'.getDolGlobalString('MYDATA_AADE_KEY').'"';
print '</td><td></td></tr>';

print '<tr class="oddeven"><td>';
print '<span class="titlefield fieldrequired">'.$langs->trans("AADE_WEBSERVICE_USER").'</span></td><td>';
print '<input class="minwidth300" type="text" name="AADE_WEBSERVICE_USER" value="'.getDolGlobalString('AADE_WEBSERVICE_USER').'"';
print '</td><td></td></tr>';

print '<tr class="oddeven"><td>';
print '<span class="titlefield fieldrequired">'.$langs->trans("AADE_WEBSERVICE_KEY").'</span></td><td>';
print '<input class="minwidth300" type="text" name="AADE_WEBSERVICE_KEY" value="'.getDolGlobalString('AADE_WEBSERVICE_KEY').'"';
print '</td><td></td></tr>';

print '<br>';

print "</table>";
}

print $form->buttonsSaveCancel("Save", '');

print '</form>';
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/en_US/companies.lang
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,4 @@ ShowSocialNetworks=Show social networks
HideSocialNetworks=Hide social networks
ExternalSystemID=External system ID
IDOfPaymentInAnExternalSystem=ID of the payment mode into an external system (like Stripe, Paypal, ...)
AADEWebserviceCredentials=AADE Webservice Credentials
81 changes: 72 additions & 9 deletions htdocs/societe/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* Copyright (C) 2018 Nicolas ZABOURI <[email protected]>
* Copyright (C) 2018 Ferran Marcet <[email protected]>
* Copyright (C) 2018-2022 Frédéric France <[email protected]>
* Copyright (C) 2022-2023 George Gkantinas <[email protected]>
* 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
Expand Down Expand Up @@ -63,6 +65,12 @@
require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
}

if ($mysoc->country_code == 'GR') {
$u = getDolGlobalString('AADE_WEBSERVICE_USER');
$p = getDolGlobalString('AADE_WEBSERVICE_KEY');
$myafm = getDolGlobalString('MAIN_INFO_TVAINTRA');
}


// Load translation files required by the page

Expand Down Expand Up @@ -385,13 +393,13 @@
}

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');
Expand Down Expand Up @@ -895,7 +903,7 @@
break;
}
}
// Gestion du logo de la société
// Company logo management


// Update linked member
Expand Down Expand Up @@ -1187,7 +1195,7 @@

$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) {
Expand Down Expand Up @@ -1728,7 +1736,11 @@ function formatCustomerSelection (selection) {
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' && !empty($u)) {
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";
Expand Down Expand Up @@ -1957,7 +1969,7 @@ function formatCustomerSelection (selection) {
}
}
$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();
}
Expand All @@ -1973,7 +1985,7 @@ function formatCustomerSelection (selection) {
}
}
$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();
}
Expand Down Expand Up @@ -2500,7 +2512,11 @@ function init_check_no_email(input) {
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' && !empty($u)) {
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";
Expand Down Expand Up @@ -2968,7 +2984,11 @@ function init_check_no_email(input) {
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' && !empty($u)) {
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";
Expand Down Expand Up @@ -3339,3 +3359,46 @@ function init_check_no_email(input) {
// 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: { afm }, // Set request parameters
success: function(data) {
var obj = 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
$("#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>
64 changes: 64 additions & 0 deletions htdocs/societe/checkvat/checkVatGr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/* Copyright (C) 2016 Spiros Ioannou
* Copyright (C) 2017 Marios Kaintatzis
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
* \file htdocs/societe/checkvat/checkVatGr.php
* \ingroup societe
* \brief Request VAT details from the Greek Ministry of Finance GSIS SOAP web service
*/

require "../../main.inc.php";

$username = getDolGlobalString('AADE_WEBSERVICE_USER'); // Get username from request
$password = getDolGlobalString('AADE_WEBSERVICE_KEY'); // Get password from request
$myafm = getDolGlobalString('MAIN_INFO_TVAINTRA'); // Get Vat from request
$afm = GETPOST('afm'); // Get client Vat from request

// Make call to check VAT for Greek client
$result = checkVATGR($username, $password, $myafm, $afm);

top_httphead('application/json');
echo json_encode($result); // Encode the result as JSON and output

/**
* Request VAT details
* @param string $username Company AADE username
* @param string $password Company AADE password
* @param string $AFMcalledfor Company vat number
* @param string $AFMcalledby Client vat number
* @return string
*/
function checkVATGR($username, $password, $AFMcalledfor, $AFMcalledby = '')
{
$client = new SoapClient("https://www1.gsis.gr/webtax2/wsgsis/RgWsPublic/RgWsPublicPort?WSDL", array('trace' => true));
$authHeader = new stdClass();
$authHeader->UsernameToken = new stdClass();
$authHeader->UsernameToken->Username = "$username";
$authHeader->UsernameToken->Password = "$password";
$Headers[] = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', $authHeader, true);
$client->__setSoapHeaders($Headers);
$result = $client->rgWsPublicAfmMethod(
array(
'afmCalledBy' => "$AFMcalledby",
'afmCalledFor' => "$AFMcalledfor",
)
);

return $result;
}

0 comments on commit 46bc9de

Please sign in to comment.