noalyss Version-9
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();
35 return;
36}
37$vatnr = strtoupper($vatnr);
38$country = substr($vatnr, 0, 2);
39$vatnr = preg_replace("/[[:^digit:]]/", '', $vatnr);
40$array = array(
41 "countryCode" => $country,
42 "vatNumber" => $vatnr,
43 "requesterMemberStateCode" => "",
44 "requesterNumber" => "",
45 "traderName" => "",
46 "traderStreet" => "",
47 "traderPostalCode" => "",
48 "traderCity" => "",
49 "traderCompanyType" => ""
50);
51
52$curl = curl_init(VATCHECK_URL . "/check-vat-number");
53curl_setopt($curl, CURLOPT_HTTPHEADER, array(
54 "Content-Type: application/json",
55 "accept: application/json"
56 )
57);
58curl_setopt($curl, CURLOPT_POST, true);
59curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
60curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($array));
61$json = curl_exec($curl);
62curl_close($curl);
63if (empty($json)) {
64 $obj = new stdClass;
65 $obj->status = 'NOK';
66 $obj->html=_('Erreur');
67 echo json_response($obj);
68 return;
69}
70
71
72$obj = json_decode($json);
73if (isset ($obj->actionSucceed) && $obj->actionSucceed == false)
74{
75 $obj = new stdClass;
76 $obj->status = 'NOK';
77 $obj->html=_('Erreur');
78 echo json_response($obj);
79 return;
80}
81
82if ($obj->valid == true) {
83 $obj->status = 'OK';
84 $obj->vat = $country . $vatnr;
85 $obj->name = str_replace("\n", ' ', $obj->name ?? "");
86 $obj->address = str_replace("\n", ' ', $obj->address ?? "");
87
88 $obj->html = <<<EOF
89{$obj->name} {$obj->address}
90EOF;
91
92} else {
93 $obj->status = 'NOK';
94 $obj->html=_('non valide');
95}
96
98?>
catch(\Exception $e) $vatnr
_("actif, passif,charge,...")
const VATCHECK_URL(!defined("DEFAULT_SERVER_VIDEO_CONF"))
Definition constant.php:373
json_response($p_answer)
Send header and json object.