noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
ajax_check_vatnumber.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19// Copyright Author Dany De Bontridder danydb@aevalys.eu 13/05/24
20/*!
21 * \file
22 * \brief check the VAT Number with VIES,
23 * \see ivatnumber.class.php
24 */
25
26if (!defined('ALLOWED')) die('Appel direct ne sont pas permis');
27
28$http = new \HttpInput();
29
30try {
31 $vatnr = $http->get("vatnr");
32 $p_domid = $http->get("p_domid");
33} catch (\Exception $e) {
34 echo $e->getMessage();
36 return;
37}
38$vatnr = str_replace([" ",".","-"],"",strtoupper($vatnr??""));
39$country = substr($vatnr, 0, 2);
40$vatnr = preg_replace("/[[:^digit:]]/", '', $vatnr);
41$array = array(
42 "countryCode" => $country,
43 "vatNumber" => $vatnr,
44 "requesterMemberStateCode" => "",
45 "requesterNumber" => "",
46 "traderName" => "",
47 "traderStreet" => "",
48 "traderPostalCode" => "",
49 "traderCity" => "",
50 "traderCompanyType" => ""
51);
52
53$curl = curl_init(VATCHECK_URL . "/check-vat-number");
54curl_setopt($curl, CURLOPT_HTTPHEADER, array(
55 "Content-Type: application/json",
56 "accept: application/json"
57 )
58);
59curl_setopt($curl, CURLOPT_POST, true);
60curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
61curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($array));
62$json = curl_exec($curl);
63curl_close($curl);
64if (empty($json)) {
65 $obj = new stdClass;
66 $obj->status = 'NOK';
67 $obj->html=_('Erreur');
68 echo json_response($obj);
69 return;
70}
71
72
73$obj = json_decode($json);
74if (isset ($obj->actionSucceed) && $obj->actionSucceed == false)
75{
76 $obj = new stdClass;
77 $obj->status = 'NOK';
78 $obj->html=_('Erreur');
79 echo json_response($obj);
80 return;
81}
82
83if ($obj->valid == true) {
84 $obj->status = 'OK';
85 $obj->vat = $country . $vatnr;
86 $obj->name = str_replace("\n", ' ', $obj->name ?? "");
87 $obj->address = str_replace("\n", ' ', $obj->address ?? "");
88
89 $obj->html = <<<EOF
90{$obj->name} {$obj->address}
91EOF;
92
93} else {
94 $obj->status = 'NOK';
95 $obj->html=_('non valide');
96}
97
99?>
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
catch(Exception $e) $obj
catch(\Exception $e) $vatnr
_("actif, passif,charge,...")
const VATCHECK_URL(!defined("DEFAULT_SERVER_VIDEO_CONF"))
Definition constant.php:390
json_response($p_answer)
Send header and json object.