noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
Noalyss\XMLDocument\FacturX Class Reference

FacturX French / German Standard for invoicing. More...

+ Inheritance diagram for Noalyss\XMLDocument\FacturX:
+ Collaboration diagram for Noalyss\XMLDocument\FacturX:

Public Member Functions

 build_data ($jr_id)
 transform an operation ($jr_id) into an array, which contains needed information for making an e-invoice
 
 check_company_data ()
 check that mandatory info are saved in the DB
 
 check_customer_data ()
 check that mandatory info are saved in the DB for customer
 
 check_VAT ()
 check that the VAT is using a PEPPOL Code
 
 create_invoice ($operation_id)
 create the invoice in the right format
 
 make_xml ($jr_id)
 create an XML invoice(Factur-X) based on JRN.JR_ID operation @parameter $jr_id (int) operation JRN.JR_ID operation
 
- Public Member Functions inherited from Noalyss\XMLDocument\XMLInvoice
 __construct (\Database $conx)
 $jr_id (int) is JRN.JR_ID
 
 display_error ()
 display_error display a warning with all error
 
 fill_customer ($card_id)
 retrieve data from customer and return it into an array
 
 fill_document ($jr_id)
 retrieve additionnal documents but only PDF , not other files
 
 fill_operation_from_array ($a_array)
 build operation from array key :
 
 fill_supplier ()
 complete $this->data from $g_parameter (global variable) for Noalyss_Folder_Parameter
 
 get_data ()
 return data
 
 get_db_conx ()
 get Database Connexion
 
 load_noalyss_parameter ()
 make an array of parameter_extra where pe_code as key and pe_value as value
 
 set_data ($data)
 returns data
 
 set_db_conx (\Database $cn)
 set Database Connexion
 
 set_pdf_filename ($pdf_filename)
 set the PDF
 

Data Fields

const EXTRA_PARAMETER
 

Protected Attributes

 $pdf_filename
 
- Protected Attributes inherited from Noalyss\XMLDocument\XMLInvoice
 $cn
 Database conx , current folder.
 
 $data
 
 $jr_id
 $data (Array) data retrieve from DB
 

Additional Inherited Members

- Static Public Member Functions inherited from Noalyss\XMLDocument\XMLInvoice
static build_xmlinvoice (\Database $conx)
 thanks MY_INVOICE_FORMAT , create the corresponding object
 

Detailed Description

FacturX French / German Standard for invoicing.

Definition at line 42 of file facturx.class.php.

Member Function Documentation

◆ build_data()

Noalyss\XMLDocument\FacturX::build_data ( $jr_id)

transform an operation ($jr_id) into an array, which contains needed information for making an e-invoice

Parameters
$jr_id(int) operation JRN.JR_ID
Returns
array with all info7

Compute totals VAT and AMOUNT

block cac:LegalMonetaryTotal

Todo
Pour les intracomm , quel taux utilisé ? 0 ou 21%

Reimplemented from Noalyss\XMLDocument\XMLInvoice.

Definition at line 62 of file facturx.class.php.

62 : array {
63 $this->data=parent::build_data($jr_id);
64 return $this->data;
65 }
$jr_id

References Noalyss\XMLDocument\XMLInvoice\$jr_id, and build_data().

Referenced by build_data(), and make_xml().

+ Here is the call graph for this function:

◆ check_company_data()

Noalyss\XMLDocument\FacturX::check_company_data ( )

check that mandatory info are saved in the DB

Parameters
$a_error(array) array of errors, empty if nothing found

Reimplemented from Noalyss\XMLDocument\XMLInvoice.

Definition at line 70 of file facturx.class.php.

71 {
72 $a_error=array();
73 $company = $this->load_noalyss_parameter();
74 foreach (FacturX::EXTRA_PARAMETER as $item) {
75 if (!isset($company[$item]) || trim($company[$item]) == '') {
76 $a_error[]=$item;
77 }
78 }
79 return $a_error;
80 }

References EXTRA_PARAMETER, and Noalyss\XMLDocument\XMLInvoice\load_noalyss_parameter().

+ Here is the call graph for this function:

◆ check_customer_data()

Noalyss\XMLDocument\FacturX::check_customer_data ( )

check that mandatory info are saved in the DB for customer

Reimplemented from Noalyss\XMLDocument\XMLInvoice.

Definition at line 84 of file facturx.class.php.

84 {
85 $a_error=array();
86 $a_needed=[ATTR_DEF_NAME=>'name'
87 ,ATTR_DEF_ADRESS=>'street'
88 ,ATTR_DEF_POSTCODE=>'postalzone'
89 ,ATTR_DEF_CITY=>'city'
90 ,ATTR_DEF_COUNTRY_CODE=>'country'
91 ,ATTR_DEF_NUMTVA=>'customer_vat_id'
92 ];
93
94 foreach ($a_needed as $item=>$value) {
95 if ( $this->data['customer'][$value]=="") {
96 $a_error[]=$value;
97 }
98 }
99
100 return $a_error;
101 }
const ATTR_DEF_ADRESS
Definition constant.php:230
const ATTR_DEF_NUMTVA
Definition constant.php:229
const ATTR_DEF_NAME
Definition constant.php:223
const ATTR_DEF_COUNTRY_CODE
Definition constant.php:255
const ATTR_DEF_POSTCODE
Definition constant.php:231
const ATTR_DEF_CITY
Definition constant.php:236

References $value, ATTR_DEF_ADRESS, ATTR_DEF_CITY, ATTR_DEF_COUNTRY_CODE, ATTR_DEF_NAME, ATTR_DEF_NUMTVA, and ATTR_DEF_POSTCODE.

◆ check_VAT()

Noalyss\XMLDocument\FacturX::check_VAT ( )

check that the VAT is using a PEPPOL Code

Reimplemented from Noalyss\XMLDocument\XMLInvoice.

Definition at line 263 of file facturx.class.php.

264 {
265 return array();
266 }

◆ create_invoice()

Noalyss\XMLDocument\FacturX::create_invoice ( $operation_id)

create the invoice in the right format

Parameters
$operation_id(int) JRN.JR_ID
Returns
string PDF Invoice including the XML

Reimplemented from Noalyss\XMLDocument\XMLInvoice.

Definition at line 235 of file facturx.class.php.

235 {
236 $documentBuilder= $this->make_xml($operation_id);
237
238 $invoice = \horstoeko\zugferd\ZugferdDocumentPdfBuilder::fromPdfFile($documentBuilder, $this->pdf_filename);
239 $invoice->generateDocument();
240 $invoice->saveDocument($this->pdf_filename."-new.pdf");
241 return $invoice->downloadString();
242 }

References $operation_id, and make_xml().

+ Here is the call graph for this function:

◆ make_xml()

Noalyss\XMLDocument\FacturX::make_xml ( $jr_id)

create an XML invoice(Factur-X) based on JRN.JR_ID operation @parameter $jr_id (int) operation JRN.JR_ID operation

Returns
XML String
Note
SIREN or SIRET is mandatory

Reimplemented from Noalyss\XMLDocument\XMLInvoice.

Definition at line 109 of file facturx.class.php.

110 {
111 $this->data = $this->build_data($jr_id);
112 $company = $this->load_noalyss_parameter();
113 // var_dump($this->data);
114 $documentBuilder = ZugferdDocumentBuilder::createNew(ZugferdProfiles::PROFILE_EN16931);
115 $documentBuilder->setDocumentInformation(
116 $this->data['id']
117 ,"380"
118 ,\DateTime::createFromFormat( 'Y-m-d',$this->data["issue_date"])
119 , $this->data['currency']
120 );
121
122 $documentBuilder->addDocumentPaymentTerm(
123 sprintf("IBAN %s",$company['COMPANY_BANK_IBAN'])
124 ,\DateTime::createFromFormat( 'Y-m-d',$this->data["due_date"])
125 , $this->data['info']['communication']
126 );
127 //------------------------------------------------
128 // SELLER
129 //------------------------------------------------
130 $documentBuilder->setDocumentSeller($company['MY_NAME'], );
131 $documentBuilder->addDocumentSellerGlobalId($company['SIREN'], '0009');
132 $documentBuilder->addDocumentSellerTaxNumber($company['MY_TVA']);
133 $documentBuilder->addDocumentSellerVATRegistrationNumber($company['MY_TVA']);
134 $documentBuilder->setDocumentSellerAddress(
135 $company['MY_STREET']
136 , '', ''
137 , $company['MY_POSTCODE']
138 , $company['MY_CITY']
139 ,$company['MY_COUNTRY_CODE']);
140
141 $documentBuilder->setDocumentSellerCommunication(ZugferdElectronicAddressScheme::UNECE3155_EM
142 , $company["INVOICE_EMAIL_COMPANY"]);
143
144 //------------------------------------------------
145 // BUYER
146 //------------------------------------------------
147
148 $documentBuilder->setDocumentBuyer($this->data['customer']['name'], $this->data['customer']['customer_vat_id']);
149 $documentBuilder->setDocumentBuyerAddress(
150 $this->data['customer']['street']
151 , ''
152 , ''
153 , $this->data['customer']['postalzone']
154 , $this->data['customer']['city']
155 , $this->data['customer']['country']
156 );
157// $documentBuilder->setDocumentBuyerContact('H. Meier', 'Einkauf', '+49-333-4444444', '+49-333-5555555', 'hm@kunde.de');
158// $documentBuilder->setDocumentBuyerCommunication(ZugferdElectronicAddressScheme::UNECE3155_EM, 'purchase@kunde.de');
159
160 $documentBuilder->setDocumentBuyerOrderReferencedDocument($this->data['info']['order']);
161
162 //------------------------------------------------
163 // Item & total
164 //------------------------------------------------
165
166 $base=0;$vat=0;
167 $nb=count($this->data['operation']);
168
169 for ($i=0;$i < $nb;$i++) {
170 $documentBuilder->addNewPosition($i+1);
171 $documentBuilder->setDocumentPositionProductDetails($this->data['operation'][$i]['qcode']
172 ,$this->data['operation'][$i]['name']
173 ,$this->data['operation'][$i]['description']
174 );
175 $documentBuilder->setDocumentPositionNetPrice($this->data['operation'][$i]['price']);
176 $documentBuilder->setDocumentPositionQuantity($this->data['operation'][$i]['quantity']
177 ,$this->data['operation'][$i]['code_quantity']
178 );
179 $documentBuilder->addDocumentPositionTax(
180 $this->data['operation'][$i]['vat_code']
181 , ZugferdVatTypeCodes::VALUE_ADDED_TAX
182 , bcmul($this->data['operation'][$i]['vat_rate'],100,2)
183 );
184 $documentBuilder->setDocumentPositionLineSummation($this->data['operation'][$i]['price']);
185
186
187 $base=bcadd($base,$this->data['operation'][$i]['price'],2);
188 $vat=bcadd($vat,$this->data['operation'][$i]['vat'],2);
189 $vat=bcsub($vat,$this->data['operation'][$i]['vat_reversed'],2);
190 }
191 $tt = bcadd($base,$vat,2);
192 //------------------------------------------------
193 // VAT Detail
194 //------------------------------------------------
195 $subTotal=$this->data['subTotalVAT'];
196 $nb_sub=count($subTotal);
197 for ($i=0;$i<$nb_sub;$i++)
198 {
199 $documentBuilder->addDocumentTax(
200 $subTotal[$i]["vat_code"]
201 , ZugferdVatTypeCodes::VALUE_ADDED_TAX
202 ,sprintf("%.2f",$subTotal[$i]['amount'])
203 , sprintf("%.2f",$subTotal[$i]['vat'])
204 , sprintf("%.2f",$subTotal[$i]['percent'])
205 );
206 }
207 //------------------------------------------------
208 // Total summary
209 //------------------------------------------------
210 $documentBuilder->setDocumentSummation(
211 sprintf("%.2f",$this->data['TaxInclusiveAmount'])
212 , sprintf("%.2f",$this->data['PayableAmount'])
213 , sprintf("%.2f",$this->data['TaxExclusiveAmount'])
214 , 0.0
215 , 0.0
216 , sprintf("%.2f",$this->data['LineExtensionAmount'])
217 , sprintf("%.2f",(bcsub($this->data['TaxInclusiveAmount'],
218 $this->data['TaxExclusiveAmount'],
219 2)
220 )
221 )
222 , 0
223 );
224
225
226 return $documentBuilder;
227
228
229 }
$base

References $base, $i, Noalyss\XMLDocument\XMLInvoice\$jr_id, $nb, build_data(), and Noalyss\XMLDocument\XMLInvoice\load_noalyss_parameter().

Referenced by create_invoice().

+ Here is the call graph for this function:

Field Documentation

◆ $pdf_filename

Noalyss\XMLDocument\FacturX::$pdf_filename
protected

Definition at line 60 of file facturx.class.php.

◆ EXTRA_PARAMETER

const Noalyss\XMLDocument\FacturX::EXTRA_PARAMETER
Initial value:
= [
"INVOICE_EMAIL_COMPANY"
, 'INVOICE_CONTACT_NAME'
, 'COMPANY_LEGAL_ENTITY'
, 'COMPANY_LEGAL_REGISTRATION'
, 'COMPANY_BANK_IBAN'
, 'COMPANY_BANK_BIC'
, 'MY_NAME'
, 'MY_STREET'
, 'MY_CITY'
, 'MY_COUNTRY_CODE'
, 'MY_TVA'
,'SIREN'
]

Definition at line 44 of file facturx.class.php.

Referenced by check_company_data().


The documentation for this class was generated from the following file: