├── .gitignore
├── .travis.yml
├── LICENSE
├── README.it.org
├── README.org
├── composer.json
├── examples
├── FPR12-lot.php
├── FPR12-many-line-items.php
├── data.php
├── invoice-v1.6.2.php
├── invoice.php
├── send-invoice.php
└── valid-fpa.php
├── src
├── AbstractDocument.php
├── AbstractNotice.php
├── EsitoCommittente.php
└── FatturaElettronica.php
└── tests
├── FatturaElettronicaTest.php
├── files
├── IT01234567890_FPA01.xml
├── IT01234567890_FPA02.xml
├── IT01234567890_FPA03.xml
├── IT01234567890_FPR01.xml
├── IT01234567890_FPR02.xml
└── IT01234567890_FPR03.xml
└── tmpfiles
└── .gitkeep
/.gitignore:
--------------------------------------------------------------------------------
1 | examples/*.xml
2 | tests/tmpfiles/*
3 | !tests/tmpfiles/.gitkeep
4 | vendor/
5 | .idea/
6 | composer.lock
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | sudo: false
4 |
5 | matrix:
6 | fast_finish: true
7 | include:
8 | - php: 7.0
9 | - php: 7.1
10 | - php: 7.2
11 | env: CODE_COVERAGE_ARGS="--coverage-clover ./clover.xml
12 | - php: 7.3
13 |
14 | cache:
15 | directories:
16 | - $HOME/.composer/cache
17 |
18 | install:
19 | - if [ "$CODE_COVERAGE_ARGS" = "" ]; then phpenv config-rm xdebug.ini || true; fi
20 | - composer install --no-interaction --prefer-dist
21 |
22 | script:
23 | - vendor/bin/phpunit $CODE_COVERAGE_ARGS tests/FatturaElettronicaTest.php
24 |
25 | notifications:
26 | email: false
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.it.org:
--------------------------------------------------------------------------------
1 | * Installazione
2 | ** Composer
3 | ~composer require taocomp/php-e-invoice-it~
4 |
5 | ** Manualmente
6 | - Clonare o scaricare il repository
7 | - ~require_once('/path/to/php-e-invoice-it/vendor/autoload.php');~
8 |
9 | * Setup
10 | Se utilizzate ~composer~, avrete già incluso il file ~vendor/autoload.php~ nel vostro codice.
11 |
12 | Se avete clonato/scaricato il repository:
13 | #+BEGIN_SRC
14 | require_once('/path/to/php-e-invoice-it/vendor/autoload.php');
15 | #+END_SRC
16 |
17 | In entrambi i casi, per utilizzare la classe ~FatturaElettronica~:
18 | #+BEGIN_SRC
19 | use Taocomp\Einvoicing\FatturaElettronica;
20 | #+END_SRC
21 |
22 | Per utilizzare la classe ~EsitoCommittente~:
23 | #+BEGIN_SRC
24 | use Taocomp\Einvoicing\EsitoCommittente;
25 | #+END_SRC
26 |
27 | * Nuova fattura/notifica
28 | Fattura FPA:
29 | #+BEGIN_SRC
30 | $invoice = new FatturaElettronica('FPA12');
31 | #+END_SRC
32 |
33 | Fattura FPR:
34 | #+BEGIN_SRC
35 | $invoice = new FatturaElettronica('FPR12');
36 | #+END_SRC
37 |
38 | Notifica EsitoCommittente:
39 | #+BEGIN_SRC
40 | $notice = new EsitoCommittente();
41 | #+END_SRC
42 |
43 | * Caricamento di una fattura/notifica esistente
44 | #+BEGIN_SRC
45 | $invoice = new FatturaElettronica('/path/to/invoice.xml');
46 | #+END_SRC
47 |
48 | Oppure:
49 | #+BEGIN_SRC
50 | $invoice = new FatturaElettronica('FPR12');
51 | $invoice->load('/path/to/invoice.xml');
52 | #+END_SRC
53 |
54 | * Individuare gli elementi
55 | In generale, per individuare gli elementi che si vogliono leggere o modificare all'interno dell'XML sono necessari:
56 | - il nome o path dell'elemento che si vuole leggere o modificare
57 | - (opzionale) un nodo /context/ a cui appartiene l'elemento (stringa o ~\DOMNode~)
58 |
59 | La sintassi da utilizzare è quella XPath, con le seguenti facilitazioni.
60 |
61 | ** Path assoluto
62 | Se il path è assoluto (comincia con ~/~), esso è in realtà relativo al nodo root del documento. Nel caso di una fattura elettronica:
63 | #+BEGIN_SRC
64 | $this->getValue('/FatturaElettronicaHeader/DatiTrasmissione/CodiceDestinatario');
65 | #+END_SRC
66 |
67 | è equivalente a una query effettuata con ~\DOMXPath~ per
68 | #+BEGIN_SRC
69 | /p:FatturaElettronica/FatturaElettronicaHeader/DatiTrasmissione/CodiceDestinatario
70 | #+END_SRC
71 |
72 | Un path assoluto non può avere /context/.
73 |
74 | ** Path relativo
75 | A un path relativo viene sempre anteposto ~//~:
76 |
77 | #+BEGIN_CENTER
78 | "Selects nodes in the document from the current node that match the selection no matter where they are". ([[https://www.w3schools.com/xml/xpath_syntax.asp][XPath Syntax]])
79 | #+END_CENTER
80 |
81 | Se è presente un /context/, viene anteposto ~.//~. Il punto specifica che si intende partire dal nodo /context/.
82 |
83 | È possibile anche specificare predicati XPath, ad esempio
84 | #+BEGIN_SRC
85 | $invoice->getValue('DettaglioLinee[2]/NumeroLinea');
86 | #+END_SRC
87 |
88 | leggerà il valore di ~NumeroLinea~ del secondo blocco ~DettaglioLinee~. La numerazione parte da 1 e non da 0, come da sintassi XPath.
89 |
90 | ** Tag
91 | Se viene fornito solo il nome dell'elemento (non sono presenti ~/~), vengono seguite le stesse regole dei path relativi. Ad esempio per selezionare ~ModalitaPagamento~:
92 |
93 | #+BEGIN_SRC
94 | $invoice->getValue('ModalitaPagamento');
95 | #+END_SRC
96 |
97 | Con un /context/:
98 | #+BEGIN_SRC
99 | $invoice->getValue('NumItem', 'DatiContratto');
100 | #+END_SRC
101 |
102 | * Leggere/modificare i valori
103 | ** ~getValue( string $expr, $context = null )~
104 | Restituisce il valore dell'elemento individuato da ~$expr/$context~, se ~$expr/$context~ restituisce un elemento univoco, altrimenti genera un'eccezione.
105 |
106 | Esempi validi:
107 | #+BEGIN_SRC
108 | $invoice->getValue('ProgressivoInvio');
109 | $invoice->getValue('Sede/Indirizzo', 'CedentePrestatore');
110 | #+END_SRC
111 |
112 | Esempi non validi:
113 | #+BEGIN_SRC
114 | $invoice->getValue('IdPaese');
115 | $invoice->getValue('Sede/Indirizzo', 'FatturaElettronicaHeader');
116 | #+END_SRC
117 |
118 | Come detto, ~$context~ può essere un oggetto ~\DOMNode~.
119 |
120 | ** ~setValue( string $expr, $value, $context = null )~
121 | Setta il valore ~$value~ per l'elemento individuato da ~$expr/$context~, se ~$expr/$context~ restituisce un elemento univoco, altrimenti genera un'eccezione.
122 |
123 | ** ~setValueToAll( string $expr, $value, $context = null )~
124 | Setta il valore ~$value~ per tutti gli elementi individuati da ~$expr/$context~.
125 |
126 | ** ~setValues( $context, array $array )~
127 | Per ogni coppia chiave/valore ~$k/$v~ dell'array, setta il valore ~$v~ per l'elemento individuato da ~$k/$context~, se ~$k/$context~ restituisce un elemento univoco, altrimenti genera un'eccezione.
128 |
129 | Esempio:
130 | #+BEGIN_SRC
131 | $invoice->setValues('CessionarioCommittente', array(
132 | 'CodiceFiscale' => '02313821007',
133 | 'Anagrafica/Denominazione' => 'AMMINISTRAZIONE',
134 | ));
135 | #+END_SRC
136 |
137 | ** ~setValuesToAll( $context, array $array )~
138 | Per ogni coppia chiave/valore ~$k/$v~ dell'array, setta il valore ~$v~ per tutti gli elementi individuati da ~$k/$context~.
139 |
140 | ** ~setValuesFromArray( $context, array $array )~
141 | Dato un array che rispecchia fedelmente una porzione di struttura XML di un certo nodo ~$context~, setta ricorsivamente i rispettivi valori.
142 |
143 | Esempio:
144 | #+BEGIN_SRC
145 | $array = array(
146 | 'DatiAnagraficiVettore' => array(
147 | 'IdFiscaleIVA' => array(
148 | 'IdPaese' => 'IT',
149 | 'IdCodice' => '09876543210'
150 | ),
151 | 'Anagrafica' => array(
152 | 'Denominazione' => 'TRASPORTO SRLS'
153 | ),
154 | 'NumeroLicenzaGuida' => 'AA090909'
155 | ),
156 | 'MezzoTrasporto' => 'Mezzo',
157 | 'CausaleTrasporto' => 'La causale del traporto',
158 | 'NumeroColli' => '1',
159 | 'Descrizione' => 'La descrizione'
160 | );
161 |
162 | $invoice->setValuesFromArray('DatiTrasporto', $array);
163 | #+END_SRC
164 |
165 | * Lotto di fatture
166 | ** ~addBody( int $n = 1 )~
167 | Aggiunge n ~FatturaElettronicaBody~ alla fattura.
168 |
169 | Poiché clona il primo body, verranno clonati anche tutti gli eventuali valori al suo interno.
170 |
171 | ** ~getBody( int $bodyIndex = 1 )~
172 | Restituisce l'oggetto ~\DOMNode~ relativo all'i-esimo body.
173 |
174 | Come da sintassi XPath, l'indice parte da 1.
175 |
176 | ** ~setBodyCount( int $n )~
177 | Setta il numero complessivo di ~FatturaElettronicaBody~.
178 |
179 | Può essere usato alternativamente a ~addBody~.
180 |
181 | Ad esempio per creare un lotto di 5 fatture:
182 | #+BEGIN_SRC
183 | $invoice->setBodyCount(5);
184 | // oppure
185 | $invoice->addBody(4);
186 | #+END_SRC
187 |
188 | * Più linee di dettaglio
189 | ** ~addLineItem( int $n, int $bodyIndex = 1 )~
190 | Aggiunge ~$n~ linee di dettaglio al body ~$bodyIndex~.
191 |
192 | Ad esempio per aggiungere 3 linee di dettaglio al secondo body:
193 | #+BEGIN_SRC
194 | $invoice->addLineItem(3, 2);
195 | #+END_SRC
196 |
197 | ** ~getLineItem( int $i, int $bodyIndex = 1 )~
198 | Restituisce l'oggetto ~\DOMNode~ relativo alla i-esima linea di dettaglio del body ~$bodyIndex~.
199 |
200 | ** ~setLineItemCount( int $n, int $bodyIndex = 1 )~
201 | Setta il numero complessivo di ~DettaglioLinee~ del body ~$bodyIndex~.
202 |
203 | Può essere usato alternativamente a ~addLineItem~.
204 |
205 | * Gestione degli elementi XML
206 | Normalmente non c'è bisogno di utilizzare i seguenti metodi per prendere/aggiungere/rimuovere elementi XML come nodi ~\DOMNode~ perché:
207 | - per leggere/settare i valori degli elementi si possono usare i loro nomi o i path, come stringhe
208 | - per aggiungere elementi ~FatturaElettronicaBody~ (lotto di fatture) si possono usare i metodi ~addBody~, ~getBody~ e ~setBodyCount~
209 | - per aggiungere linee di dettaglio si possono usare i metodi ~addLineItem~, ~getLineItem~ e ~setLineItemCount~
210 |
211 | In ogni caso a volte può servire aggiungere, rimuovere o prendere un determinato elemento della struttura XML. È possibile farlo con i seguenti metodi.
212 |
213 | ** ~addElement( $element, $parent, $beforeRef = null )~
214 | Aggiunge un elemento ~$element~ all'interno del nodo genitore ~$parent~. Viene posizionato prima del nodo fratello ~$beforeRef~, se ~$beforeRef~ non è nullo.
215 |
216 | ** ~addElementsFromArray( $parent, array $array )~
217 | Dato un array che rispecchia fedelmente una porzione di struttura XML di un certo nodo ~parent~, aggiunge ricorsivamente i vari elementi dell'array. Il metodo viene usato nel ~constructor~ per creare l'intera struttura della fattura (e della notifica).
218 |
219 | ** ~getElement( $expr, $context = null )~
220 | Prende un determinato elemento individuato da ~$expr/$context~, se ~$expr/$context~ restituisce un elemento univoco, altrimenti genera un'eccezione.
221 |
222 | ** ~removeElement( $element )~
223 | Rimuove l'elemento ~$element~, se univoco. Altrimenti genera un'eccezione.
224 |
225 | ** ~setElementCount( $expr, int $n, $context = null )~
226 | Imposta la cardinalità di un certo elemento. Ad esempio per avere 3 ~DatiRiepilogo~:
227 | #+BEGIN_SRC
228 | $invoice->setElementCount('DatiRiepilogo', 3);
229 | #+END_SRC
230 |
231 | O nel caso di più bodies:
232 | #+BEGIN_SRC
233 | $body2 = $invoice->getBody(2);
234 | $invoice->setElementCount('DatiRiepilogo', 2, $body2);
235 | #+END_SRC
236 |
237 | Settaggio valori:
238 | #+BEGIN_SRC
239 | $invoice->setValue('DatiRiepilogo[1]/AliquotaIVA', '22.00', $body2);
240 | $invoice->setValue('DatiRiepilogo[2]/AliquotaIVA', '10.00', $body2);
241 | #+END_SRC
242 |
243 | * Altri metodi comuni a fatture e notifiche
244 | ** ~getDOM()~
245 | Restituisce l'oggetto ~\DOMDocument~ relativo alla fattura.
246 |
247 | ** ~normalize()~
248 | Rimuove gli elementi XML vuoti.
249 |
250 | Utilizzato in ~asXML()~ e ~save()~, se non esplicitamente disabilitato.
251 |
252 | In ~FatturaElettronica~ divide l'elemento ~DatiGeneraliDocumento/Causale~ in più elementi se il valore supera i 200 caratteri (chunks da 200 caratteri ciascuno).
253 |
254 | ** ~query( string $expr, $context = null, bool $registerNodeNS = true )~
255 | Restituisce una lista di elementi ~\DOMNodeList~ derivante dalla query ~$expr/$context~.
256 |
257 | * Visualizzazione dell'XML
258 | Per recuperare la fattura come stringa XML:
259 | #+BEGIN_SRC
260 | $invoice->asXML();
261 | #+END_SRC
262 |
263 | Di default gli elementi vuoti vengono eliminati prima di stampare la stringa XML (normalizzazione). Per visualizzarli:
264 | #+BEGIN_SRC
265 | $invoice->asXML(false);
266 | #+END_SRC
267 |
268 | * Validazione della fattura
269 | ~php-e-invoice-it~ utilizza la libreria [[https://github.com/Slamdunk/php-validatore-fattura-elettronica][Slamdunk/php-validatore-fattura-elettronica]] per la validazione. Se avete installato ~php-e-invoice-it~ con composer ve la ritrovate già, altrimenti dovete scaricarla e includerla manualmente se volete validare le fatture.
270 |
271 | Validazione:
272 | #+BEGIN_SRC
273 | $invoice->validate();
274 | #+END_SRC
275 |
276 | * Salvataggio su file
277 | ** Fattura
278 | Quando si salva una fattura, di default il nome del file è dato da:
279 | #+BEGIN_SRC
280 | IdPaese . IdCodice . _ . ProgressivoInvio . .xml
281 | #+END_SRC
282 |
283 | È possibile in ogni caso assegnare un nome arbitrario alla fattura:
284 | #+BEGIN_SRC
285 | $invoice->setFilename('filename');
286 | #+END_SRC
287 |
288 | Per settare una directory di destinazione dove salvare la fattura:
289 | #+BEGIN_SRC
290 | $invoice->setPrefixPath('path/to/dir');
291 | #+END_SRC
292 |
293 | Per settare una directory di destinazione per tutti gli oggetti ~FatturaElettronica~ che verranno creati:
294 | #+BEGIN_SRC
295 | FatturaElettronica::setDefaultPrefixPath('path/to/dir');
296 | #+END_SRC
297 |
298 | Per salvare la fattura:
299 | #+BEGIN_SRC
300 | $invoice->save();
301 | #+END_SRC
302 |
303 | Se è già presente un file con lo stesso nome viene generata un'eccezione. Per sovrascrivere il file:
304 | #+BEGIN_SRC
305 | $overwrite = true;
306 | $invoice->save($overwrite);
307 | #+END_SRC
308 |
309 | Prima di salvare il file, l'XML viene normalizzato (vengono rimossi gli elementi vuoti). Per disabilitare la normalizzazione:
310 | #+BEGIN_SRC
311 | $overwrite = false;
312 | $normalize = false;
313 | $invoice->save($overwrite, $normalize);
314 | #+END_SRC
315 |
316 | Getters:
317 | #+BEGIN_SRC
318 | FatturaElettronica::getDefaultPrefixPath();
319 | $invoice->getFilename();
320 | $invoice->getPrefixPath();
321 | #+END_SRC
322 |
323 | ** Notifica
324 | I metodi visti per le fatture valgono anche per le notifiche.
325 |
326 | Inoltre, per costruire il nome del file notifica a partire da quello di una certa ~$invoice~:
327 | #+BEGIN_SRC
328 | $notice->setFilenameFromInvoice($invoice, '_EC_001');
329 | #+END_SRC
330 |
331 | Per pre-popolare i valori della notifica a partire da quelli di una fattura:
332 | #+BEGIN_SRC
333 | $notice->setValuesFromInvoice($invoice, $bodyIndex);
334 | #+END_SRC
335 |
336 | * Invio al Sistema di Interscambio (SdI)
337 | ** Fatture
338 | #+BEGIN_SRC
339 | use Taocomp\Einvoicing\SdicoopClient\Client;
340 | use Taocomp\Einvoicing\SdicoopClient\FileSdIBase;
341 | use Taocomp\Einvoicing\SdicoopClient\RispostaSdIRiceviFile;
342 |
343 | $invoice = new FatturaElettronica('FPR12');
344 | // ...
345 | // settaggio valori
346 | // ...
347 |
348 | Client::setPrivateKey('/path/to/client.key');
349 | Client::setClientCert('/path/to/client.pem');
350 | Client::setCaCert('/path/to/ca.pem');
351 |
352 | $client = new Client(array(
353 | 'endpoint' => 'https://testservizi.fatturapa.it/ricevi_file',
354 | 'wsdl' => '/path/to/wsdl/SdIRiceviFile_v1.0.wsdl'
355 | ));
356 |
357 | $fileSdI = new FileSdIBase();
358 | $fileSdI->load($invoice);
359 | $response = new RispostaSdIRiceviFile($client->RiceviFile($fileSdI));
360 | #+END_SRC
361 |
362 | ** Notifiche
363 | #+BEGIN_SRC
364 | use Taocomp\Einvoicing\SdicoopClient\Client;
365 | use Taocomp\Einvoicing\SdicoopClient\FileSdI;
366 | use Taocomp\Einvoicing\SdicoopClient\RispostaSdINotificaEsito;
367 |
368 | $notice = new EsitoCommittente();
369 | // ...
370 | // settaggio valori
371 | // ...
372 |
373 | Client::setPrivateKey('/path/to/client.key');
374 | Client::setClientCert('/path/to/client.pem');
375 | Client::setCaCert('/path/to/ca.pem');
376 |
377 | $client = new Client(array(
378 | 'endpoint' => 'https://testservizi.fatturapa.it/ricevi_notifica',
379 | 'wsdl' => __DIR__ . '/../wsdl/SdIRiceviNotifica_v1.0.wsdl'
380 | ));
381 |
382 | $fileSdI = new FileSdI();
383 | $fileSdI->load($notice);
384 | $response = new RispostaSdINotificaEsito($client->NotificaEsito($fileSdI));
385 | #+END_SRC
386 |
--------------------------------------------------------------------------------
/README.org:
--------------------------------------------------------------------------------
1 | #+TITLE: PHP E-invoice It
2 |
3 | A PHP package for managing italian e-invoice and notice XML formats:
4 | - XML management through ~DOMDocument~ and ~DOMXPath~
5 | - full ~FatturaElettronica~ (FatturaPA) XML skeleton
6 | - smart simplified xpath strings for getting/setting values (and for adding/getting/removing elements if needed)
7 | - multiple bodies (invoice lot)
8 | - multiple line items (~DettaglioLinee~)
9 | - multiple generic elements with ~setElementCount()~
10 | - XML normalization: remove empty elements and automatically split ~Causale~ in chunks if > 200 characters
11 | - optional ~FatturaElettronica~ validation thanks to [[https://github.com/Slamdunk/php-validatore-fattura-elettronica][Slamdunk/php-validatore-fattura-elettronica]]
12 |
13 | /(Pacchetto PHP per gestire il formato XML di fatture e notifiche come richiesto dal SdI)./
14 |
15 | /([[file:README.it.org][Qui]] la documentazione aggiornata in italiano)./
16 |
17 | Please refer to
18 | - [[https://github.com/taocomp/php-sdicoop-server][PHP SdICoop - Server]] for implementing web services required by the Italian Exchange System (aka "SdI")
19 | - [[https://github.com/taocomp/php-sdicoop-client][PHP SdICoop - Client]] to connect to SdI web services
20 |
21 | See [[https://forum.italia.it/c/fattura-pa][Forum Italia - Fatturazione Elettronica]] for server configuration, interoperability tests, etc. In particular:
22 | - Apache configuration :: [[https://forum.italia.it/t/accreditamento-sdicoop-configurazione-ssl-su-apache/3314][Accreditamento SDICoop: configurazione SSL su Apache - Fatturazione Elettroni...]]
23 | - Interoperability tests :: [[https://forum.italia.it/t/test-interoperabilita-soluzioni/4370][Test Interoperabilità Soluzioni - Fatturazione Elettronica - Forum Italia]]
24 |
25 | * Quickstart
26 | ** Dependencies
27 | - ~php-xml~
28 | - tested for PHP 7+ +should work on PHP 5.5+ +too+
29 |
30 | ** Installation
31 | *** Composer
32 | ~composer require taocomp/php-e-invoice-it~
33 |
34 | *** Manually
35 | - Clone/download the repository
36 | - ~require_once('/path/to/php-e-invoice-it/vendor/autoload.php');~
37 |
38 | ** Invoice
39 | *** Create a new invoice
40 | Create a new FPA12 invoice:
41 | #+BEGIN_SRC
42 | $invoice = new FatturaElettronica('FPA12');
43 | #+END_SRC
44 |
45 | Create a new FPR12 invoice:
46 | #+BEGIN_SRC
47 | $invoice = new FatturaElettronica('FPR12');
48 | #+END_SRC
49 |
50 | Create a new invoice from file
51 | #+BEGIN_SRC
52 | $invoice = new FatturaElettronica('/path/to/invoice.xml');
53 | #+END_SRC
54 | *** Create a custom template invoice to be used later
55 | #+BEGIN_SRC
56 | $prefixPath = __DIR__ . '/tmpfiles';
57 | $filename = 'my-custom-template.xml';
58 | $invoice = new FatturaElettronica('FPR12');
59 | $invoice->setValue('IdTrasmittente/IdCodice', '00011122233');
60 | $invoice->setValue('IdTrasmittente/IdPaese', 'IT');
61 | $invoice->setFilename($filename);
62 | $invoice->setPrefixPath($prefixPath)->save();
63 | #+END_SRC
64 | *** Invoice lot and line items
65 | Set 3 bodies:
66 | #+BEGIN_SRC
67 | $invoice->addBody(2);
68 | // or
69 | $invoice->setBodyCount(3);
70 | #+END_SRC
71 |
72 | Set 4 line items for second body:
73 | #+BEGIN_SRC
74 | $invoice->addLineItem(3, 2);
75 | // or
76 | $invoice->setLineItemCount(4, 2);
77 | #+END_SRC
78 |
79 | *** Get/Set values
80 | In general, you can get/set values (and add/get/remove elements) by using a tag/path and an optional /context/.
81 |
82 | Please note that:
83 | - an absolute path is relative to the root element: ~/FatturaElettronicaHeader~ means ~/p:FatturaElettronica/FatturaElettronicaHeader~
84 | - tags and relative paths are prefixed with ~(.)//~
85 | - xpath predicates are allowed: ~$invoice->getValue('DettaglioLinee[2]/NumeroLinea');~
86 |
87 | Get a value:
88 | #+BEGIN_SRC
89 | $invoice->getValue('ModalitaPagamento');
90 | #+END_SRC
91 |
92 | Get a value with a /context/:
93 | #+BEGIN_SRC
94 | $invoice->getValue('NumItem', 'DatiContratto');
95 | #+END_SRC
96 |
97 | Invalid queries (they return more than one element):
98 | #+BEGIN_SRC
99 | $invoice->getValue('IdPaese');
100 | $invoice->getValue('Sede/Indirizzo', 'FatturaElettronicaHeader');
101 | #+END_SRC
102 |
103 | Set a value for a specific element:
104 | #+BEGIN_SRC
105 | $invoice->setValue('ProgressivoInvio', 10001);
106 | #+END_SRC
107 |
108 | Set many single values at once:
109 | #+BEGIN_SRC
110 | $invoice->setValues('IdTrasmittente', array(
111 | 'IdCodice' => '09876543210',
112 | 'IdPaese' => 'IT'
113 | ));
114 | #+END_SRC
115 |
116 | #+BEGIN_SRC
117 | $invoice->setValues('CedentePrestatore/Sede', array(
118 | 'Indirizzo' => 'VIA UNIVERSO 1'
119 | ));
120 | #+END_SRC
121 |
122 | #+BEGIN_SRC
123 | $invoice->setValues('CessionarioCommittente', array(
124 | // CessionarioCommittente/DatiAnagrafici/CodiceFiscale
125 | 'DatiAnagrafici/CodiceFiscale' => '01234567890',
126 | // Denominazione, somewhere inside CessionarioCommittente
127 | 'Denominazione' => 'BETA SRL'
128 | ));
129 | #+END_SRC
130 |
131 | #+BEGIN_SRC
132 | // Set values for second body
133 | $body2 = $invoice->getBody(2);
134 | $invoice->setValue('Numero', 44, $body2);
135 | $invoice->setValue('Data', '2018-12-12', $body2);
136 | #+END_SRC
137 |
138 | Set values to multiple elements at once:
139 | #+BEGIN_SRC
140 | $invoice->setValuesToAll('DatiGenerali', array(
141 | // All "RiferimentoNumeroLinea" somewhere inside DatiGenerali
142 | 'RiferimentoNumeroLinea' => 1,
143 | // All "IdDocumento" somewhere inside DatiGenerali
144 | 'IdDocumento' => 4455,
145 | // All "NumItem" somewhere inside DatiGenerali
146 | 'NumItem' => 1
147 | ));
148 | #+END_SRC
149 |
150 | Set values from an assoc array:
151 | #+BEGIN_SRC
152 | $array = array(
153 | 'DatiAnagraficiVettore' => array(
154 | 'IdFiscaleIVA' => array(
155 | 'IdPaese' => 'IT',
156 | 'IdCodice' => '09876543210'
157 | ),
158 | 'Anagrafica' => array(
159 | 'Denominazione' => 'TRASPORTO SRLS'
160 | ),
161 | 'NumeroLicenzaGuida' => 'AA090909'
162 | ),
163 | 'MezzoTrasporto' => 'Mezzo',
164 | 'CausaleTrasporto' => 'La causale del traporto',
165 | 'NumeroColli' => '1',
166 | 'Descrizione' => 'La descrizione'
167 | );
168 |
169 | $invoice->setValuesFromArray('DatiTrasporto', $array);
170 | #+END_SRC
171 |
172 | All but ~setValueToAll~ and ~setValuesToAll~ methods will throw an exception if ~$expr/$context~ don't return just one element.
173 |
174 | *** Set/Unset stylesheet
175 | Set:
176 | #+BEGIN_SRC
177 | $invoice->setStylesheet('/path/to/xsl');
178 | #+END_SRC
179 |
180 | Unset:
181 | #+BEGIN_SRC
182 | $invoice->unsetStylesheet();
183 | #+END_SRC
184 |
185 | *** Validate invoice
186 | You need [[https://github.com/Slamdunk/php-validatore-fattura-elettronica][Slamdunk/php-validatore-fattura-elettronica]]. If you install ~php-e-invoice-it~ via-composer, you got it as dependency; otherwise you must download and require it manually.
187 | #+BEGIN_SRC
188 | $invoice->validate();
189 | #+END_SRC
190 | An exception is thrown (with a message) if the XML is not valid, for example:
191 | #+BEGIN_SRC
192 | DOMDocument::schemaValidateSource(): Element 'DatiTrasmissione': Missing child element(s). Expected is ( CodiceDestinatario ).
193 | #+END_SRC
194 |
195 | *** Save invoice
196 | Set an optional default destination dir for all invoices:
197 | #+BEGIN_SRC
198 | FatturaElettronica::setDefaultPrefixPath('path/to/dir');
199 | #+END_SRC
200 |
201 | Set an optional destination dir for current invoice:
202 | #+BEGIN_SRC
203 | $invoice->setPrefixPath('path/to/another/dir');
204 | #+END_SRC
205 |
206 | Save invoice:
207 | #+BEGIN_SRC
208 | $invoice->save();
209 | #+END_SRC
210 |
211 | Specify a custom filename:
212 | #+BEGIN_SRC
213 | $invoice->setFilename('my-invoice.xml')->save();
214 | #+END_SRC
215 |
216 | *** Send invoice to SdI
217 | Setup a ~\Taocomp\Einvoicing\SdicoopClient\Client~ object (for connecting to webservice SdIRiceviFile):
218 | #+BEGIN_SRC
219 | use \Taocomp\Einvoicing\SdicoopClient\Client;
220 | use \Taocomp\Einvoicing\SdicoopClient\FileSdIBase;
221 | use \Taocomp\Einvoicing\SdicoopClient\RispostaSdIRiceviFile;
222 |
223 | Client::setPrivateKey('/path/to/client.key');
224 | Client::setClientCert('/path/to/client.pem');
225 | Client::setCaCert('/path/to/ca.pem');
226 |
227 | $client = new Client(array(
228 | 'endpoint' => 'https://testservizi.fatturapa.it/ricevi_file',
229 | 'wsdl' => '/path/to/wsdl/SdIRiceviFile_v1.0.wsdl'
230 | ));
231 | #+END_SRC
232 |
233 | Send invoice:
234 | #+BEGIN_SRC
235 | $fileSdI = new FileSdIBase();
236 | $fileSdI->load($invoice);
237 | $response = new RispostaSdIRiceviFile($client->RiceviFile($fileSdI));
238 | #+END_SRC
239 |
240 | ** Notices
241 | *** Create a new notice
242 | NotificaEsitoCommittente:
243 | #+BEGIN_SRC
244 | $notice = new EsitoCommittente();
245 | #+END_SRC
246 |
247 | *** Load a notice from file
248 | *** Set values
249 | #+BEGIN_SRC
250 | // Set some values from invoice, second body:
251 | $notice->setValuesFromInvoice($invoice, 2);
252 |
253 | // Set values
254 | $notice->setValue('IdentificativoSdI', 1234567);
255 | $notice->setValue('Esito', EsitoCommittente::EC01);
256 | #+END_SRC
257 | *** Set/Unset stylesheet
258 | Set:
259 | #+BEGIN_SRC
260 | $notice->setStylesheet('/path/to/xsl');
261 | #+END_SRC
262 |
263 | Unset:
264 | #+BEGIN_SRC
265 | $notice->unsetStylesheet();
266 | #+END_SRC
267 |
268 | *** Save notice
269 | #+BEGIN_SRC
270 | // Set filename from invoice
271 | $notice->setFilenameFromInvoice($invoice, '_EC_001');
272 |
273 | // Save notice
274 | $notice->save();
275 | #+END_SRC
276 |
277 | *** Send notice to SdI
278 | Setup a ~\Taocomp\Einvoicing\SdicoopClient\Client~ object (for connecting to webservice SdIRiceviNotifica):
279 | #+BEGIN_SRC
280 | use \Taocomp\Einvoicing\SdicoopClient\Client;
281 | use \Taocomp\Einvoicing\SdicoopClient\FileSdI;
282 | use \Taocomp\Einvoicing\SdicoopClient\RispostaSdINotificaEsito;
283 |
284 | Client::setPrivateKey('/path/to/client.key');
285 | Client::setClientCert('/path/to/client.pem');
286 | Client::setCaCert('/path/to/ca.pem');
287 |
288 | $client = new Client(array(
289 | 'endpoint' => 'https://testservizi.fatturapa.it/ricevi_notifica',
290 | 'wsdl' => __DIR__ . '/../wsdl/SdIRiceviNotifica_v1.0.wsdl'
291 | ));
292 | #+END_SRC
293 |
294 | Send notice:
295 | #+BEGIN_SRC
296 | $fileSdI = new FileSdI();
297 | $fileSdI->load($notice);
298 | $response = new RispostaSdINotificaEsito($client->NotificaEsito($fileSdI));
299 | #+END_SRC
300 |
301 | * Tests
302 | From inside the project root dir:
303 | ~./vendor/bin/phpunit --testdox tests~
304 |
305 | * Credits
306 | We want to thank all contributors of [[https://forum.italia.it/c/fattura-pa][Forum Italia - Fatturazione Elettronica]] who have shared their snippets and any available info.
307 |
308 | Thanks to @Slamdunk for [[https://github.com/Slamdunk/php-validatore-fattura-elettronica][Slamdunk/php-validatore-fattura-elettronica]]!
309 |
310 | * License
311 | GPLv3.
312 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "taocomp/php-e-invoice-it",
3 | "description": "A PHP package for managing italian e-invoice and notice XML formats",
4 | "require": {
5 | "php": "^7|^8.0",
6 | "slam/php-validatore-fattura-elettronica": ">=v1.2.1-patch20201009.1"
7 | },
8 | "autoload": {
9 | "psr-4": {"Taocomp\\Einvoicing\\": "src/"}
10 | },
11 | "require-dev": {
12 | "phpunit/phpunit": "^7|^8.0"
13 | },
14 | "license": "GPL-3.0-or-later",
15 | "authors": [
16 | {
17 | "name": "Alessandro De Donno",
18 | "email": "e-invoicing@taocomp.com",
19 | "homepage": "https://taocomp.com",
20 | "role": "Developer"
21 | }
22 | ]
23 | }
24 |
--------------------------------------------------------------------------------
/examples/FPR12-lot.php:
--------------------------------------------------------------------------------
1 | setBodyCount(2);
16 |
17 | // 2 "dettaglio linee" for body 1
18 | // 3 "dettaglio linee" for body 2
19 | $lineItemCount = array(2, 3);
20 | $invoice->setLineItemCount($lineItemCount[0], 1);
21 | $invoice->setLineItemCount($lineItemCount[1], 2);
22 |
23 | // Dati Trasmissione
24 | $invoice->setValues('DatiTrasmissione', $DatiTrasmissione);
25 | $invoice->setValue('ProgressivoInvio', '00002');
26 | $invoice->setValue('CodiceDestinatario', '0000000');
27 | $invoice->setValue('PECDestinatario', 'betagamma@pec.it');
28 |
29 | // Cedente Prestatore
30 | $invoice->setValues('CedentePrestatore', $CedentePrestatore);
31 |
32 | // Cessionario Committente
33 | $invoice->setValues('CessionarioCommittente', $CessionarioCommittente);
34 |
35 | // Bodies
36 | $bodies = $invoice->getBodies();
37 | foreach ($bodies as $k => $body) {
38 | // Dati Generali Documento
39 | $invoice->setValues('DatiGeneraliDocumento', $DatiGeneraliDocumento, $body);
40 | $invoice->setValue('DatiGeneraliDocumento/Numero', $k + 100, $body);
41 |
42 | // Dati Ordine Acquisto
43 | $invoice->setValues('DatiOrdineAcquisto', $DatiOrdineAcquisto, $body);
44 |
45 | // Dati Trasporto
46 | $invoice->setValues('DatiTrasporto', $DatiTrasporto, $body);
47 |
48 | // Dettaglio Linee
49 | for ($i = 1; $i <= $lineItemCount[$k]; $i++ ) {
50 | $invoice->setValues("DettaglioLinee[$i]", $DettaglioLinee[$i], $body);
51 | }
52 |
53 | // Dati Riepilogo
54 | $invoice->setValues('DatiRiepilogo', $DatiRiepilogo, $body);
55 |
56 | // Dati Pagamento
57 | $invoice->setValues('DatiPagamento', $DatiPagamento, $body);
58 | }
59 |
60 | // save invoice
61 | $invoice->setPrefixPath(__DIR__)->save(true);
62 |
63 | // show xml
64 | $xml = $invoice->asXML();
65 | header("Content-type: text/xml; charset=utf-8");
66 | echo $xml . PHP_EOL;
67 | }
68 | catch (\Exception $e)
69 | {
70 | echo $e->getMessage() . PHP_EOL;
71 | }
72 |
--------------------------------------------------------------------------------
/examples/FPR12-many-line-items.php:
--------------------------------------------------------------------------------
1 | setLineItemCount($lineItemCount);
17 |
18 | // Dati Trasmissione
19 | $invoice->setValues('DatiTrasmissione', $DatiTrasmissione);
20 | $invoice->setValue('ProgressivoInvio', '00001');
21 | $invoice->setValue('CodiceDestinatario', '0000000');
22 | $invoice->setValue('PECDestinatario', 'betagamma@pec.it');
23 |
24 | // Cedente Prestatore
25 | $invoice->setValues('CedentePrestatore', $CedentePrestatore);
26 |
27 | // Cessionario Committente
28 | $invoice->setValues('CessionarioCommittente', $CessionarioCommittente);
29 |
30 | // Dati Generali Documento
31 | $invoice->setValues('DatiGeneraliDocumento', $DatiGeneraliDocumento);
32 |
33 | // Dati Ordine Acquisto
34 | $invoice->setValues('DatiOrdineAcquisto', $DatiOrdineAcquisto);
35 |
36 | // Dati Trasporto
37 | $invoice->setValues('DatiTrasporto', $DatiTrasporto);
38 |
39 | // Dettaglio Linee
40 | for ($i = 1; $i <= $lineItemCount; $i++ ) {
41 | $invoice->setValues("DettaglioLinee[$i]", $DettaglioLinee[$i]);
42 | }
43 |
44 | // Dati Riepilogo
45 | $invoice->setValues('DatiRiepilogo', $DatiRiepilogo);
46 |
47 | // Dati Pagamento
48 | $invoice->setValues('DatiPagamento', $DatiPagamento);
49 |
50 | // save invoice
51 | $invoice->setPrefixPath(__DIR__)->save(true);
52 |
53 | // show xml
54 | $xml = $invoice->asXML();
55 | header("Content-type: text/xml; charset=utf-8");
56 | echo $xml . PHP_EOL;
57 | }
58 | catch (\Exception $e)
59 | {
60 | echo $e->getMessage() . PHP_EOL;
61 | }
62 |
--------------------------------------------------------------------------------
/examples/data.php:
--------------------------------------------------------------------------------
1 | 'IT',
5 | 'IdCodice' => '02313821007'
6 | );
7 |
8 | $CedentePrestatore = array(
9 | 'IdPaese' => 'IT',
10 | 'IdCodice' => '02313821007',
11 | 'Denominazione' => "SOCIETA' ALPHA SRL",
12 | 'RegimeFiscale' => 'RF01',
13 | 'Sede/Indirizzo' => 'VIALE ROMA 543',
14 | 'Sede/CAP' => '07100',
15 | 'Sede/Comune' => "SASSARI",
16 | 'Sede/Provincia' => 'SS',
17 | 'Sede/Nazione' => 'IT'
18 | );
19 |
20 | $CessionarioCommittente = array(
21 | 'CodiceFiscale' => '02313821007',
22 | 'Anagrafica/Denominazione' => 'BETA GAMMA',
23 | 'Sede/Indirizzo' => 'VIA TORINO 38-B',
24 | 'Sede/CAP' => '00145',
25 | 'Sede/Comune' => "ROMA",
26 | 'Sede/Provincia' => 'RM',
27 | 'Sede/Nazione' => 'IT'
28 | );
29 |
30 | $DatiGeneraliDocumento = array(
31 | 'TipoDocumento' => 'TD01',
32 | 'Divisa' => 'EUR',
33 | 'Data' => '2018-12-12',
34 | 'Numero' => '123',
35 | 'Causale' => 'Causale'
36 | );
37 |
38 | $DatiOrdineAcquisto = array(
39 | 'RiferimentoNumeroLinea' => '1',
40 | 'IdDocumento' => '66685',
41 | 'NumItem' => '1'
42 | );
43 |
44 | $DatiTrasporto = array(
45 | 'IdPaese' => 'IT',
46 | 'IdCodice' => '24681012141',
47 | 'Denominazione' => 'Trasporto spa',
48 | 'DataOraConsegna' => '2012-10-22T16:46:12.000+02:00'
49 | );
50 |
51 | $DettaglioLinee = array();
52 | for ($i = 1; $i < 6; $i++) {
53 | $DettaglioLinee[$i] = array(
54 | 'NumeroLinea' => $i,
55 | 'Descrizione' => "Descrizione $i",
56 | 'Quantita' => '5.00',
57 | 'PrezzoUnitario' => '1.00',
58 | 'PrezzoTotale' => '5.00',
59 | 'AliquotaIVA' => '22.00'
60 | );
61 | }
62 |
63 | $DatiRiepilogo = array(
64 | 'AliquotaIVA' => '22.00',
65 | 'ImponibileImporto' => '25.00',
66 | 'Imposta' => '5.50',
67 | 'EsigibilitaIVA' => 'D'
68 | );
69 |
70 | $DatiPagamento = array(
71 | 'CondizioniPagamento' => 'TP01',
72 | 'ModalitaPagamento' => 'MP01',
73 | 'DataScadenzaPagamento' => '2018-12-31',
74 | 'ImportoPagamento' => '30.50'
75 | );
76 |
--------------------------------------------------------------------------------
/examples/invoice-v1.6.2.php:
--------------------------------------------------------------------------------
1 | setLineItemCount($lineItemCount);
20 |
21 | // Dati Trasmissione
22 | $invoice->setValues('DatiTrasmissione', $DatiTrasmissione);
23 | $invoice->setValue('ProgressivoInvio', '00001');
24 | $invoice->setValue('CodiceDestinatario', '0000000');
25 | $invoice->setValue('PECDestinatario', 'betagamma@pec.it');
26 |
27 | // Cedente Prestatore
28 | $invoice->setValues('CedentePrestatore', $CedentePrestatore);
29 |
30 | // Cessionario Committente
31 | $invoice->setValues('CessionarioCommittente', $CessionarioCommittente);
32 |
33 | // Dati Generali Documento
34 | $invoice->setValues('DatiGeneraliDocumento', $DatiGeneraliDocumento);
35 |
36 | // Dati Ordine Acquisto
37 | $invoice->setValues('DatiOrdineAcquisto', $DatiOrdineAcquisto);
38 |
39 | // Dati Trasporto
40 | $invoice->setValues('DatiTrasporto', $DatiTrasporto);
41 |
42 | // Dettaglio Linee
43 | for ($i = 1; $i <= $lineItemCount; $i++ ) {
44 | $invoice->setValues("DettaglioLinee[$i]", $DettaglioLinee[$i]);
45 | }
46 |
47 | // Dati Riepilogo
48 | $invoice->setValues('DatiRiepilogo', $DatiRiepilogo);
49 |
50 | // Dati Pagamento
51 | $invoice->setValues('DatiPagamento', $DatiPagamento);
52 |
53 | $xml = $invoice->validate()->asXML();
54 | echo $xml . PHP_EOL;
55 | }
56 | catch (\Exception $e)
57 | {
58 | echo $e->getMessage() . PHP_EOL;
59 | }
60 |
--------------------------------------------------------------------------------
/examples/invoice.php:
--------------------------------------------------------------------------------
1 | addBody(2);
17 | $invoice->addLineItem(3, 2);
18 |
19 | // Set single value
20 | $invoice->setValue('ProgressivoInvio', random_int(20000,99999));
21 |
22 | // Set multiple values
23 | $invoice->setValues('IdTrasmittente', array(
24 | 'IdCodice' => '09876543210',
25 | 'IdPaese' => 'IT'
26 | ));
27 | $invoice->setValues('CedentePrestatore', array(
28 | 'IdCodice' => '09876543210',
29 | 'IdPaese' => 'IT',
30 | 'Sede/Indirizzo' => 'VIA UNIVERSO 1'
31 | ));
32 | $invoice->setValues('CessionarioCommittente', array(
33 | // CessionarioCommittente/DatiAnagrafici/CodiceFiscale
34 | 'DatiAnagrafici/CodiceFiscale' => '01234567890',
35 | // Anagrafica/Denominazione, somewhere inside CessionarioCommittente
36 | 'Anagrafica/Denominazione' => 'BETA SRL'
37 | ));
38 |
39 | // Add elements
40 | // $invoice->addElement('PECDestinatario', 'DatiTrasmissione');
41 | // $invoice->setValue('PECDestinatario', 'pec@example.com');
42 |
43 | // Add elements from array
44 | $body = $invoice->getBody();
45 | $datiGeneraliDocumento = $invoice->getElement('DatiGeneraliDocumento', $body);
46 | $invoice->addElementsFromArray($datiGeneraliDocumento, array(
47 | 'DatiRitenuta' => array(
48 | 'TipoRitenuta' => '',
49 | 'ImportoRitenuta' => '23.00',
50 | 'AliquotaRitenuta' => ''
51 | )
52 | ));
53 |
54 | // Set values for second body
55 | $body2 = $invoice->getBody(2);
56 | $invoice->setValue('Numero', 44, $body2);
57 | $invoice->setValue('DatiGeneraliDocumento/Data', '2018-12-12', $body2);
58 |
59 | // Set a big "Causale" in second body
60 | $causale = 'Lorem ipsum dolor sit amet, consectetur adipisci elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
61 | $invoice->setValue('DatiGeneraliDocumento/Causale', $causale, $body2);
62 |
63 | // 2 DatiRiepilogo for second body
64 | $invoice->setElementCount('DatiRiepilogo', 2, $body2);
65 | $invoice->setValue('DatiRiepilogo[1]/AliquotaIVA', '22.00', $body2);
66 | $invoice->setValue('DatiRiepilogo[2]/AliquotaIVA', '10.00', $body2);
67 |
68 | // Save invoice
69 | // $invoice->save();
70 |
71 | // Show XML
72 | $xml = $invoice->asXML();
73 | header("Content-type: text/xml; charset=utf-8");
74 | echo $xml . PHP_EOL;
75 |
76 | // --------------------------------------------------------------
77 | // Notice
78 | // --------------------------------------------------------------
79 |
80 | // Create notice
81 | $notice = new EsitoCommittente();
82 |
83 | // Set some values from invoice, second body
84 | $notice->setValuesFromInvoice($invoice, 2);
85 |
86 | // Set values
87 | $notice->setValue('IdentificativoSdI', 1234567);
88 | $notice->setValue('Esito', EsitoCommittente::EC01);
89 |
90 | // Set filename from invoice
91 | $notice->setFilenameFromInvoice($invoice, '_EC_001');
92 |
93 | // Save notice
94 | // $notice->save();
95 |
96 | // XML
97 | $xml = $notice->asXML();
98 | }
99 | catch (\Exception $e)
100 | {
101 | echo $e->getMessage() . PHP_EOL;
102 | }
103 |
--------------------------------------------------------------------------------
/examples/send-invoice.php:
--------------------------------------------------------------------------------
1 | setValue('ProgressivoInvio', random_int(10000, 99999));
19 | $invoice->setValues('IdTrasmittente', array(
20 | 'IdCodice' => '02313821007',
21 | 'IdPaese' => 'IT'
22 | ));
23 | $invoice->setValues('CedentePrestatore', array(
24 | 'IdCodice' => '02313821007',
25 | 'IdPaese' => 'IT'
26 | ));
27 |
28 | // Setup client
29 | Client::setPrivateKey(CLIENT_DIR . '/assets/key/client.key');
30 | Client::setClientCert(CLIENT_DIR . '/assets/certs/client.pem');
31 | Client::setCaCert(CLIENT_DIR . '/assets/certs/ca.pem');
32 |
33 | $client = new Client(array(
34 | 'endpoint' => 'https://testservizi.fatturapa.it/ricevi_file',
35 | 'wsdl' => CLIENT_DIR . '/assets/wsdl/SdIRiceviFile_v1.0.wsdl'
36 | ));
37 |
38 | // Send invoice
39 | $fileSdI = new FileSdIBase();
40 | $fileSdI->load($invoice);
41 | $response = new RispostaSdIRiceviFile($client->RiceviFile($fileSdI));
42 | }
43 | catch (\Exception $e)
44 | {
45 | echo $e->getMessage() . PHP_EOL;
46 | }
47 |
--------------------------------------------------------------------------------
/examples/valid-fpa.php:
--------------------------------------------------------------------------------
1 | setValue('ProgressivoInvio', 10001);
11 | $invoice->setValue('CodiceDestinatario', '999999');
12 |
13 | $invoice->setValues('IdTrasmittente', array(
14 | 'IdCodice' => '02313821007',
15 | 'IdPaese' => 'IT'
16 | ));
17 | $invoice->setValues('CedentePrestatore', array(
18 | 'IdPaese' => 'IT',
19 | 'IdCodice' => '02313821007',
20 | 'Denominazione' => 'CEDENTE SRL',
21 | 'RegimeFiscale' => 'RF19',
22 | ));
23 | $invoice->setValues('CedentePrestatore/Sede', array(
24 | 'Indirizzo' => 'VIA UNIVERSO 1',
25 | 'CAP' => '20100',
26 | 'Comune' => 'TRENTO',
27 | 'Provincia' => 'TN',
28 | 'Nazione' => 'IT'
29 | ));
30 | $invoice->setValues('CessionarioCommittente', array(
31 | 'CodiceFiscale' => '02313821007',
32 | 'Anagrafica/Denominazione' => 'AMMINISTRAZIONE',
33 | ));
34 | $invoice->setValues('CessionarioCommittente/Sede', array(
35 | 'Indirizzo' => 'VIALE MONDO 99',
36 | 'CAP' => '20100',
37 | 'Comune' => 'TRENTO',
38 | 'Provincia' => 'TN',
39 | 'Nazione' => 'IT'
40 | ));
41 | $invoice->setValues('DatiGeneraliDocumento', array(
42 | 'TipoDocumento' => 'TD01',
43 | 'Divisa' => 'EUR',
44 | 'Data' => '2018-12-12',
45 | 'Numero' => 99999
46 | ));
47 | $invoice->setValuesToAll('DatiGenerali', array(
48 | 'RiferimentoNumeroLinea' => 1,
49 | 'IdDocumento' => 4455,
50 | 'NumItem' => 1
51 | ));
52 | $invoice->setValues('DatiTrasporto', array(
53 | 'IdPaese' => 'IT',
54 | 'IdCodice' => '11223344556',
55 | 'Denominazione' => 'TRASPORTO SRLS',
56 | 'DataOraConsegna' => '2017-01-10T16:46:12.000+02:00'
57 | ));
58 | $invoice->setValues('DatiBeniServizi', array(
59 | 'NumeroLinea' => 1,
60 | 'Descrizione' => 'Description',
61 | 'Quantita' => '10.00',
62 | 'PrezzoUnitario' => '5.00',
63 | 'PrezzoTotale' => '50.00',
64 | 'DettaglioLinee/AliquotaIVA' => '22.00',
65 | 'DatiRiepilogo/AliquotaIVA' => '22.00',
66 | 'ImponibileImporto' => '50.00',
67 | 'Imposta' => '11.00',
68 | 'EsigibilitaIVA' => 'D'
69 | ));
70 | $invoice->setValues('DatiPagamento', array(
71 | 'CondizioniPagamento' => 'TP01',
72 | 'ModalitaPagamento' => 'MP01',
73 | 'DataScadenzaPagamento' => '2018-12-31',
74 | 'ImportoPagamento' => '61.00'
75 | ));
76 |
77 | $invoice->removeElement('DatiDDT');
78 |
79 | $invoice->validate()->save(true);
80 |
81 | // Show XML
82 | $xml = $invoice->asXML();
83 | header("Content-type: text/xml; charset=utf-8");
84 | echo $xml . PHP_EOL;
85 | }
86 | catch (\Exception $e)
87 | {
88 | echo $e->getMessage() . PHP_EOL;
89 | }
90 |
--------------------------------------------------------------------------------
/src/AbstractDocument.php:
--------------------------------------------------------------------------------
1 |
5 | *
6 | * This file is part of php-e-invoice-it.
7 | *
8 | * php-e-invoice-it is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * php-e-invoice-it is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with php-e-invoice-it. If not, see .
20 | */
21 |
22 | namespace Taocomp\Einvoicing;
23 |
24 | abstract class AbstractDocument
25 | {
26 | /**
27 | * DOMDocument object
28 | */
29 | protected $dom = null;
30 |
31 | /**
32 | * Filename
33 | */
34 | protected $filename = null;
35 |
36 | /**
37 | * Optional prefix path where to save this document
38 | */
39 | protected $prefixPath = null;
40 |
41 | /**
42 | * Optional stylesheet href.
43 | *
44 | * If not null, the "xml-stylesheet" element will be prepended before
45 | * the first node.
46 | */
47 | protected $stylesheetHref = null;
48 |
49 | /**
50 | * Constructor
51 | */
52 | public function __construct( $file = null )
53 | {
54 | $this->dom = new \DOMDocument('1.0', 'UTF-8');
55 | $this->dom->formatOutput = true;
56 |
57 | if (null === $file) {
58 | $root = $this->dom->createElementNS(
59 | static::ROOT_NAMESPACE,
60 | static::ROOT_TAG_PREFIX . ':' . static::ROOT_TAG_NAME);
61 | $root->setAttributeNS(
62 | 'http://www.w3.org/2000/xmlns/',
63 | 'xmlns:ds',
64 | 'http://www.w3.org/2000/09/xmldsig#');
65 | $root->setAttributeNS(
66 | 'http://www.w3.org/2000/xmlns/',
67 | 'xmlns:xsi',
68 | 'http://www.w3.org/2001/XMLSchema-instance');
69 | $root->setAttributeNS(
70 | 'http://www.w3.org/2001/XMLSchema-instance',
71 | 'schemaLocation',
72 | static::SCHEMA_LOCATION);
73 |
74 | if (false === is_a($root, '\DOMElement')) {
75 | throw new \Exception('Method createRootElement must return a \DOMElement');
76 | }
77 |
78 | if (false === is_array(static::$templateArray)) {
79 | throw new \Exception('static templateArray must be an array');
80 | }
81 |
82 | $this->addElementsFromArray($root, static::$templateArray);
83 | $this->dom->appendChild($root);
84 | } else if (is_readable($file)) {
85 | $this->load($file);
86 | } else {
87 | throw new \Exception("File '$file' not found or not readable");
88 | }
89 | }
90 |
91 | /**
92 | * Returns document class name
93 | *
94 | * @return string
95 | */
96 | protected function getClassName()
97 | {
98 | $classArray = explode('\\', get_class($this));
99 | return array_pop($classArray);
100 | }
101 |
102 | protected function insertStylesheet()
103 | {
104 | if (empty($this->stylesheetHref)) {
105 | throw new \Exception("Cannot add stylesheet because href is empty or null");
106 | }
107 |
108 | $firstChild = $this->dom->firstChild;
109 |
110 | if ($firstChild->nodeName !== 'xml-stylesheet') {
111 | $fragment = $this->dom->createDocumentFragment();
112 | $fragment->appendXML("stylesheetHref}\"?>");
113 | $this->dom->insertBefore($fragment, $this->dom->documentElement);
114 | } else {
115 | $firstChild->nodeValue = "type=\"text/xsl\" href=\"{$this->stylesheetHref}\"";
116 | }
117 |
118 | return $this;
119 | }
120 |
121 | protected function removeStylesheet()
122 | {
123 | $firstChild = $this->dom->firstChild;
124 |
125 | if ($firstChild->nodeName === 'xml-stylesheet') {
126 | $this->dom->removeChild($firstChild);
127 | }
128 |
129 | return $this;
130 | }
131 |
132 | public function setStylesheet( string $href )
133 | {
134 | $this->stylesheetHref = $href;
135 |
136 | return $this;
137 | }
138 |
139 | public function unsetStylesheet()
140 | {
141 | $this->stylesheetHref = null;
142 |
143 | return $this;
144 | }
145 |
146 | /**
147 | * DOMDOCUMENT, DOMXPATH, XML
148 | ***************************************************************************
149 | */
150 |
151 | /**
152 | * Returns the document as XML
153 | */
154 | public function asXML( bool $normalize = true )
155 | {
156 | if (true === $normalize) {
157 | $this->normalize();
158 | }
159 |
160 | if (false === empty($this->stylesheetHref)) {
161 | $this->insertStylesheet();
162 | } else {
163 | $this->removeStylesheet();
164 | }
165 |
166 | return $this->dom->saveXML(null, LIBXML_NOEMPTYTAG);
167 | }
168 |
169 | /**
170 | * Returns the DOMDocument object
171 | *
172 | * @return \DOMDocument
173 | */
174 | public function getDOM()
175 | {
176 | return $this->dom;
177 | }
178 |
179 | /**
180 | * Removes empty elements
181 | */
182 | public function normalize()
183 | {
184 | // TODO: recursive
185 | for ($i = 0; $i < 4; $i++) {
186 | foreach( $this->query('//*[not(node())]') as $node ) {
187 | $node->parentNode->removeChild($node);
188 | }
189 | }
190 |
191 | return $this;
192 | }
193 |
194 | /**
195 | * Query for elements.
196 | *
197 | * - Absolute paths: omit root element (for example p:FatturaElettronica)
198 | * - Tags are prefixed with "(.)//"
199 | * - Relative paths are prefixed with "(.)//"
200 | *
201 | * $context can be a string or a \DOMNode
202 | *
203 | * @return \DOMNodeList
204 | */
205 | public function query( string $expr, $context = null, bool $registerNodeNS = true )
206 | {
207 | $strpos = strpos($expr, '/');
208 |
209 | if (false === $strpos) {
210 | $expr = "//$expr";
211 |
212 | if (null !== $context) {
213 | $expr = ".$expr";
214 | }
215 | } else if ($strpos === 0) {
216 | // Absolute path cannot have a context
217 | if (null !== $context) {
218 | throw new \Exception("Cannot specify a context with an absolute path ($expr)");
219 | }
220 |
221 | if ($expr === '/') {
222 | $expr = '';
223 | }
224 |
225 | $expr = '/' . static::ROOT_TAG_PREFIX . ':' . static::ROOT_TAG_NAME . $expr;
226 | } else if ($strpos > 1) {
227 | $expr = "//$expr";
228 |
229 | if (null !== $context) {
230 | $expr = ".$expr";
231 | }
232 | }
233 |
234 | if (null !== $context) {
235 | $context = $this->getElement($context);
236 | }
237 |
238 | $xpath = new \DOMXpath($this->dom);
239 | return $xpath->query($expr, $context, $registerNodeNS);
240 | }
241 |
242 | /**
243 | * FILENAME, PATH, LOAD/SAVE FILE
244 | ***************************************************************************
245 | */
246 |
247 | /**
248 | * Get destination dir
249 | */
250 | public static function getDefaultPrefixPath()
251 | {
252 | return static::$defaultPrefixPath;
253 | }
254 |
255 | /**
256 | * Get filename
257 | */
258 | public function getFilename()
259 | {
260 | return $this->filename;
261 | }
262 |
263 | /**
264 | * Set filename
265 | */
266 | public function setFilename( string $filename )
267 | {
268 | $this->filename = $filename;
269 | return $this;
270 | }
271 |
272 | /**
273 | * Set destination dir (common prefix path when saving invoices)
274 | */
275 | public static function setDefaultPrefixPath( string $dir )
276 | {
277 | $dir = realpath($dir);
278 |
279 | if (false === $dir) {
280 | throw new \Exception("Cannot access to '$dir'");
281 | }
282 | if (false === is_writeable($dir)) {
283 | throw new \Exception("Directory '$dir' is not writeable");
284 | }
285 |
286 | static::$defaultPrefixPath = $dir;
287 | }
288 |
289 | /**
290 | * Get prefix path for current object
291 | */
292 | public function getPrefixPath()
293 | {
294 | return $this->prefixPath;
295 | }
296 |
297 | /**
298 | * Load a document from file
299 | */
300 | protected function load( string $filename, int $options = 0 )
301 | {
302 | if (false === $this->dom->load($filename, $options)) {
303 | throw new \Exception("Cannot load file '$filename'");
304 | }
305 |
306 | return $this;
307 | }
308 |
309 | /**
310 | * Save document to file.
311 | * If set, prepend static::$defaultPrefixPath to path.
312 | * Overwrite existing file if $overwrite is true.
313 | */
314 | public function save( bool $overwrite = false, bool $normalize = true )
315 | {
316 | $prefixPath = '.';
317 | if (null !== $this->prefixPath) {
318 | $prefixPath = $this->prefixPath;
319 | } else if (null !== static::$defaultPrefixPath) {
320 | $prefixPath = static::$defaultPrefixPath;
321 | }
322 | $prefixPath = realpath($prefixPath);
323 |
324 | if (false === $prefixPath) {
325 | throw new \Exception("Cannot set a valid prefixPath ('$prefixPath')");
326 | }
327 |
328 | $filename = $this->getFilename();
329 |
330 | if (false === is_string($filename) || empty($filename)) {
331 | throw new \Exception("Filename '$filename' empty or invalid");
332 | }
333 |
334 | $dest = $prefixPath . DIRECTORY_SEPARATOR . $filename;
335 |
336 | $className = $this->getClassName();
337 |
338 | if (file_exists($dest) && false === $overwrite) {
339 | throw new \Exception("$className '$dest' already exists");
340 | }
341 |
342 | if (true === $normalize) {
343 | $this->normalize();
344 | }
345 |
346 | if (false === empty($this->stylesheetHref)) {
347 | $this->insertStylesheet();
348 | } else {
349 | $this->removeStylesheet();
350 | }
351 |
352 | // if (false === $this->dom->save($dest, LIBXML_NOEMPTYTAG)) {
353 | if (false === $this->dom->save($dest)) {
354 | throw new \Exception("Cannot save $className to '$dest'");
355 | }
356 |
357 | return $this;
358 | }
359 |
360 | /**
361 | * Set optional destination dir for current object
362 | */
363 | public function setPrefixPath( string $dir )
364 | {
365 | $dir = realpath($dir);
366 |
367 | if (false === $dir) {
368 | throw new \Exception("Cannot access to '$dir'");
369 | }
370 | if (false === is_writeable($dir)) {
371 | throw new \Exception("Directory '$dir' is not writeable");
372 | }
373 |
374 | $this->prefixPath = $dir;
375 |
376 | return $this;
377 | }
378 |
379 | /**
380 | * ELEMENTS
381 | ***************************************************************************
382 | */
383 |
384 | /**
385 | * Add an element
386 | */
387 | public function addElement( $element, $parent, $beforeRef = null )
388 | {
389 | $parent = $this->getElement($parent);
390 |
391 | if (is_string($element)) {
392 | $element = $this->dom->createElement($element);
393 | } else if (false === $element instanceOf \DOMNode) {
394 | throw new \Exception('Invalid $element parameter');
395 | }
396 |
397 | if (null === $beforeRef) {
398 | $parent->appendChild($element);
399 | } else {
400 | $beforeRef = $this->getElement($beforeRef);
401 | $parent->insertBefore($element, $beforeRef);
402 | }
403 |
404 | return $element;
405 | }
406 |
407 | /**
408 | * Recursively adds elements from array
409 | */
410 | public function addElementsFromArray( $parent, array $array )
411 | {
412 | $parent = $this->getElement($parent);
413 |
414 | foreach ($array as $k => $v) {
415 | if (true === is_array($v)) {
416 | $node = $this->dom->createElement($k);
417 | $this->addElementsFromArray($node, $v);
418 | } else {
419 | $node = $this->dom->createElement($k, $v);
420 | }
421 | $parent->appendChild($node);
422 | }
423 | }
424 |
425 | /**
426 | * Query document for specified element.
427 | *
428 | * Throws an exception if query returns 0 or N>1 elements.
429 | */
430 | public function getElement( $expr, $context = null )
431 | {
432 | if ($expr instanceOf \DOMNode) {
433 | return $expr;
434 | } else if (false === is_string($expr)) {
435 | throw new \Exception('Invalid param $expr');
436 | }
437 |
438 | if (null !== $context) {
439 | $context = $this->getElement($context);
440 | }
441 |
442 | $elements = $this->query($expr, $context);
443 | $count = $elements->length;
444 |
445 | if ($count !== 1) {
446 | $errSuffix = null === $context ? "" : " (context: {$context->nodeName})";
447 | }
448 |
449 | if ($count > 1) {
450 | $nodeValues = 'values:';
451 | foreach ($elements as $element) {
452 | $nodeValues .= " {$element->nodeName}:{$element->nodeValue},";
453 | }
454 | throw new \Exception("Element '$expr' returns $count elements ($nodeValues)$errSuffix");
455 | } else if ($count === 0) {
456 | throw new \Exception("Element not found ($expr)$errSuffix");
457 | }
458 |
459 | return $elements->item(0);
460 | }
461 |
462 | /**
463 | * Remove an element
464 | */
465 | public function removeElement( $element )
466 | {
467 | $element = $this->getElement($element);
468 | $parent = $element->parentNode;
469 | $parent->removeChild($element);
470 |
471 | return $this;
472 | }
473 |
474 | /**
475 | * Set element count
476 | */
477 | public function setElementCount( $expr, int $n, $context = null )
478 | {
479 | $currentList = $this->query($expr, $context);
480 | $currentCount = $currentList->length;
481 |
482 | if (0 === $currentCount) {
483 | throw new \Exception("Cannot find an element with expr/context: $expr/$context");
484 | }
485 |
486 | if ($currentCount === $n) {
487 | return $this;
488 | }
489 |
490 | if ($currentCount > $n) {
491 | $exceeding = $currentCount - $n;
492 |
493 | for ($i = $currentCount; --$i >= $n; ) {
494 | $cur = $currentList->item($i);
495 | $cur->parentNode->removeChild($cur);
496 | }
497 | } else {
498 | $adding = $n - $currentCount;
499 | $element = $currentList->item(0);
500 | $nextSibling = $currentList->item($currentCount - 1);
501 |
502 | for ($i = 0; $i < $adding; $i++ ) {
503 | $this->addElement($element->cloneNode(true), $element->parentNode, $nextSibling);
504 | }
505 | }
506 |
507 | return $this;
508 | }
509 |
510 | /**
511 | * Split an element if its value (as string) is > $splitLen characters.
512 | */
513 | public function splitElement( $element, int $splitLen, $context = null )
514 | {
515 | $element = $this->getElement($element, $context);
516 | $nextSibling = $element->nextSibling;
517 | $value = $this->getValue($element);
518 | $strlen = strlen((string)$value);
519 |
520 | if ($strlen <= $splitLen) {
521 | return $this;
522 | }
523 |
524 | $chunks = str_split($value, $splitLen);
525 | $first = array_shift($chunks);
526 |
527 | $this->setValue($element, $first);
528 |
529 | foreach ($chunks as $chunk) {
530 | $newElement = $this->addElement($element->nodeName, $element->parentNode, $nextSibling);
531 | $newElement->nodeValue = $chunk;
532 | }
533 | }
534 |
535 | /**
536 | * VALUES
537 | ***************************************************************************
538 | */
539 |
540 | /**
541 | * Get value
542 | */
543 | public function getValue( $expr, $context = null )
544 | {
545 | return $this->getElement($expr, $context)->nodeValue;
546 | }
547 |
548 | /**
549 | * Set value for a given element, if the element is unique (by tag or xpath).
550 | * Throws an exception otherwise.
551 | */
552 | public function setValue( $expr, $value, $context = null )
553 | {
554 | $this->getElement($expr, $context)->nodeValue = $value;
555 |
556 | return $this;
557 | }
558 |
559 | /**
560 | * Set same value $value to all elements retrieved through $expr
561 | */
562 | public function setValueToAll( $expr, $value, $context = null )
563 | {
564 | $elements = $this->query($expr, $context);
565 |
566 | foreach ($elements as $element) {
567 | $element->nodeValue = $value;
568 | }
569 |
570 | return $this;
571 | }
572 |
573 | /**
574 | * Set values from an associative array. Keys must return just one element.
575 | * Array keys are relative to $expr/$context.
576 | */
577 | public function setValues( $expr, array $array, $context = null )
578 | {
579 | $element = $this->getElement($expr, $context);
580 |
581 | foreach ($array as $k => $v) {
582 | $this->setValue($k, $v, $element);
583 | }
584 |
585 | return $this;
586 | }
587 |
588 | /**
589 | * Recursively set values from array
590 | */
591 | public function setValuesFromArray( $expr, array $array, $context = null )
592 | {
593 | $parent = $this->getElement($expr, $context);
594 |
595 | foreach ($array as $k => $v) {
596 | if (true === is_array($v)) {
597 | $node = $this->getElement($k, $parent);
598 | $this->setValuesFromArray($node, $v);
599 | } else {
600 | $this->setValue($k, $v, $parent);
601 | }
602 | }
603 | }
604 |
605 | /**
606 | * Set values from an associative array. Keys may return N elements.
607 | * Array keys are relative to $expr/$context.
608 | */
609 | public function setValuesToAll( $expr, array $array, $context = null )
610 | {
611 | $element = $this->getElement($expr, $context);
612 |
613 | foreach ($array as $k => $v) {
614 | $this->setValueToAll($k, $v, $element);
615 | }
616 |
617 | return $this;
618 | }
619 | }
620 |
--------------------------------------------------------------------------------
/src/AbstractNotice.php:
--------------------------------------------------------------------------------
1 |
5 | *
6 | * This file is part of php-e-invoice-it.
7 | *
8 | * php-e-invoice-it is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * php-e-invoice-it is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with php-e-invoice-it. If not, see .
20 | */
21 |
22 | namespace Taocomp\Einvoicing;
23 |
24 | abstract class AbstractNotice extends AbstractDocument
25 | {
26 | /**
27 | * Constants for root notice element
28 | */
29 | const ROOT_TAG_PREFIX = 'types';
30 | const ROOT_NAMESPACE = 'http://www.fatturapa.gov.it/sdi/messaggi/v1.0';
31 | const SCHEMA_LOCATION = 'http://www.fatturapa.gov.it/sdi/messaggi/v1.0 MessaggiTypes_v1.0.xsd ';
32 |
33 | /**
34 | * Default destination dir where to save documents
35 | */
36 | protected static $defaultPrefixPath = null;
37 |
38 | /**
39 | * Constructor
40 | */
41 | public function __construct( $file = null )
42 | {
43 | parent::__construct($file);
44 |
45 | if (null === $file) {
46 | $this->dom->documentElement->setAttribute('versione', '1.0');
47 | }
48 | }
49 |
50 | public function setFilenameFromInvoice( FatturaElettronica $invoice, string $suffix )
51 | {
52 | $filename = basename($invoice->getFilename(), '.xml') . $suffix . '.xml';
53 | return $this->setFilename($filename);
54 | }
55 |
56 | /**
57 | * Populate some notice values from invoice
58 | */
59 | abstract public function setValuesFromInvoice( FatturaElettronica $invoice, $body = 1 );
60 | }
61 |
--------------------------------------------------------------------------------
/src/EsitoCommittente.php:
--------------------------------------------------------------------------------
1 |
5 | *
6 | * This file is part of php-e-invoice-it.
7 | *
8 | * php-e-invoice-it is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * php-e-invoice-it is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with php-e-invoice-it. If not, see .
20 | */
21 |
22 | namespace Taocomp\Einvoicing;
23 |
24 | class EsitoCommittente extends AbstractNotice
25 | {
26 | /**
27 | * Constants for root element ("NotificaEsitoCommittente")
28 | */
29 | const ROOT_TAG_NAME = 'NotificaEsitoCommittente';
30 |
31 | /**
32 | * Constants for "Esito"
33 | */
34 | const EC01 = 'EC01';
35 | const EC02 = 'EC02';
36 |
37 | /**
38 | * Notice elements
39 | */
40 | public static $templateArray = array(
41 | 'IdentificativoSdI' => '',
42 | 'RiferimentoFattura' => array(
43 | 'NumeroFattura' => '',
44 | 'AnnoFattura' => ''
45 | ),
46 | 'Esito' => ''
47 | );
48 |
49 | /**
50 | * Populate notice values from invoice
51 | */
52 | public function setValuesFromInvoice( FatturaElettronica $invoice, $body = 1 )
53 | {
54 | $body = $invoice->getBody($body);
55 | $this->setValue('NumeroFattura', $invoice->getValue(".//DatiGeneraliDocumento/Numero", $body));
56 |
57 | $anno = substr($invoice->getValue('.//DatiGeneraliDocumento/Data', $body), 0, 4);
58 | $this->setValue('AnnoFattura', $anno);
59 |
60 | return $this;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/FatturaElettronica.php:
--------------------------------------------------------------------------------
1 |
5 | *
6 | * This file is part of php-e-invoice-it.
7 | *
8 | * php-e-invoice-it is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * php-e-invoice-it is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with php-e-invoice-it. If not, see .
20 | */
21 |
22 | namespace Taocomp\Einvoicing;
23 |
24 | class FatturaElettronica extends AbstractDocument
25 | {
26 | /**
27 | * Constants for root element ("FatturaElettronica")
28 | */
29 | const ROOT_TAG_PREFIX = 'p';
30 | const ROOT_TAG_NAME = 'FatturaElettronica';
31 | const ROOT_NAMESPACE = 'http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2';
32 | const SCHEMA_LOCATION = 'http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2 '
33 | . 'http://www.fatturapa.gov.it/export/fatturazione/sdi/fatturapa'
34 | . '/v1.2/Schema_del_file_xml_FatturaPA_versione_1.2.xsd';
35 |
36 | /**
37 | * Invoice formats
38 | */
39 | protected static $allowedFormats = array('FPA12', 'FPR12');
40 |
41 | /**
42 | * Default destination dir where to save documents
43 | */
44 | protected static $defaultPrefixPath = null;
45 |
46 | /**
47 | * Invoice elements
48 | */
49 | public static $templateArray = array(
50 | 'FatturaElettronicaHeader' => [
51 | 'DatiTrasmissione' => [
52 | 'IdTrasmittente' => ['IdPaese' => '', 'IdCodice' => ''],
53 | 'ProgressivoInvio' => '',
54 | 'FormatoTrasmissione' => '',
55 | 'CodiceDestinatario' => '',
56 | 'ContattiTrasmittente' => ['Telefono' => '', 'Email' => ''],
57 | 'PECDestinatario' => '',
58 | ],
59 | 'CedentePrestatore' => [
60 | 'DatiAnagrafici' => [
61 | 'IdFiscaleIVA' => [
62 | 'IdPaese' => '',
63 | 'IdCodice' => '',
64 | ],
65 | 'CodiceFiscale' => '',
66 | 'Anagrafica' => [
67 | 'Denominazione' => '',
68 | 'Nome' => '',
69 | 'Cognome' => '',
70 | 'Titolo' => '',
71 | 'CodEORI' => '',
72 | ],
73 | 'AlboProfessionale' => '',
74 | 'ProvinciaAlbo' => '',
75 | 'NumeroIscrizioneAlbo' => '',
76 | 'DataIscrizioneAlbo' => '',
77 | 'RegimeFiscale' => '',
78 | ],
79 | 'Sede' => [
80 | 'Indirizzo' => '',
81 | 'NumeroCivico' => '',
82 | 'CAP' => '',
83 | 'Comune' => '',
84 | 'Provincia' => '',
85 | 'Nazione' => '',
86 | ],
87 | 'StabileOrganizzazione' => [
88 | 'Indirizzo' => '',
89 | 'NumeroCivico' => '',
90 | 'CAP' => '',
91 | 'Comune' => '',
92 | 'Provincia' => '',
93 | 'Nazione' => '',
94 | ],
95 | 'IscrizioneREA' => [
96 | 'Ufficio' => '',
97 | 'NumeroREA' => '',
98 | 'CapitaleSociale' => '',
99 | 'SocioUnico' => '',
100 | 'StatoLiquidazione' => ''
101 | ],
102 | 'Contatti' => [
103 | 'Telefono' => '',
104 | 'Fax' => '',
105 | 'Email' => '',
106 | ],
107 | 'RiferimentoAmministrazione' => '',
108 | ],
109 | // Da valorizzare qualora il cedente/prestatore si avvalga di un
110 | // rappresentante fiscale in Italia, ai sensi del DPR 633 del 1972
111 | // e successive modifiche ed integrazioni.
112 | 'RappresentanteFiscale' => [
113 | 'DatiAnagrafici' => [
114 | 'IdFiscaleIVA' => ['IdPaese' => '', 'IdCodice' => ''],
115 | 'CodiceFiscale' => '',
116 | 'Anagrafica' => [
117 | 'Denominazione' => '',
118 | 'Nome' => '',
119 | 'Cognome' => '',
120 | 'Titolo' => '',
121 | 'CodEORI' => '',
122 | ],
123 | ],
124 | ],
125 | 'CessionarioCommittente' => [
126 | 'DatiAnagrafici' => [
127 | 'IdFiscaleIVA' => [
128 | 'IdPaese' => '',
129 | 'IdCodice' => ''
130 | ],
131 | 'CodiceFiscale' => '',
132 | 'Anagrafica' => [
133 | 'Denominazione' => '',
134 | 'Nome' => '',
135 | 'Cognome' => '',
136 | 'Titolo' => '',
137 | 'CodEORI' => ''
138 | ],
139 | ],
140 | 'Sede' => [
141 | 'Indirizzo' => '',
142 | 'NumeroCivico' => '',
143 | 'CAP' => '',
144 | 'Comune' => '',
145 | 'Provincia' => '',
146 | 'Nazione' => '',
147 | ],
148 | 'StabileOrganizzazione' => [
149 | 'Indirizzo' => '',
150 | 'NumeroCivico' => '',
151 | 'CAP' => '',
152 | 'Comune' => '',
153 | 'Provincia' => '',
154 | 'Nazione' => '',
155 | ],
156 | 'RappresentanteFiscale' => [
157 | 'IdFiscaleIVA' => ['IdPaese' => '', 'IdCodice' => ''],
158 | 'Denominazione' => '',
159 | 'Nome' => '',
160 | 'Cognome' => '',
161 | ],
162 | ],
163 | 'TerzoIntermediarioOSoggettoEmittente' => [
164 | 'DatiAnagrafici' => [
165 | 'IdFiscaleIVA' => ['IdPaese' => '', 'IdCodice' => ''],
166 | 'CodiceFiscale' => '',
167 | 'Anagrafica' => [
168 | 'Denominazione' => '',
169 | 'Nome' => '',
170 | 'Cognome' => '',
171 | 'Titolo' => '',
172 | 'CodEORI' => '',
173 | ]
174 | ],
175 | ],
176 | // Nei casi di documenti emessi da un soggetto diverso dal
177 | // cedente/prestatore va valorizzato l’elemento seguente.
178 | 'SoggettoEmittente' => ''
179 | ],
180 | 'FatturaElettronicaBody' => array(
181 | 'DatiGenerali' => [
182 | 'DatiGeneraliDocumento' => [
183 | // Tipologia del documento oggetto della trasmissione
184 | // (fattura, acconto/anticipo su fattura, acconto/anticipo
185 | // su parcella , nota di credito, nota di debito, parcella).
186 | // TD01 Fattura
187 | // TD02 Acconto/Anticipo su fattura
188 | // TD03 Acconto/Anticipo su parcella
189 | // TD04 Nota di Credito
190 | // TD05 Nota di Debito
191 | // TD06 Parcella
192 | 'TipoDocumento' => '',
193 | 'Divisa' => '',
194 | 'Data' => '',
195 | 'Numero' => '',
196 | 'DatiRitenuta' => [
197 | 'TipoRitenuta' => '',
198 | 'ImportoRitenuta' => '',
199 | 'AliquotaRitenuta' => '',
200 | 'CausalePagamento' => '',
201 | ],
202 | 'DatiBollo' => [
203 | 'BolloVirtuale' => '',
204 | 'ImportoBollo' => '',
205 | ],
206 | 'DatiCassaPrevidenziale' => [
207 | 'TipoCassa' => '',
208 | 'AlCassa' => '',
209 | 'ImportoContributoCassa' => '',
210 | 'ImponibileCassa' => '',
211 | 'AliquotaIVA' => '',
212 | 'Ritenuta' => '',
213 | 'Natura' => '',
214 | 'RiferimentoAmministrazione' => '',
215 | ],
216 | 'ScontoMaggiorazione' => [
217 | 'Tipo' => '',
218 | 'Percentuale' => '',
219 | 'Importo' => ''
220 | ],
221 | 'ImportoTotaleDocumento' => '',
222 | 'Arrotondamento' => '',
223 | 'Causale' => '',
224 | 'Art73' => '',
225 | ],
226 | 'DatiOrdineAcquisto' => [
227 | 'RiferimentoNumeroLinea' => '',
228 | 'IdDocumento' => '',
229 | 'Data' => '',
230 | 'NumItem' => '',
231 | 'CodiceCommessaConvenzione' => '',
232 | 'CodiceCUP' => '',
233 | 'CodiceCIG' => '',
234 | ],
235 | 'DatiContratto' => [
236 | 'RiferimentoNumeroLinea' => '',
237 | 'IdDocumento' => '',
238 | 'Data' => '',
239 | 'NumItem' => '',
240 | 'CodiceCommessaConvenzione' => '',
241 | 'CodiceCUP' => '',
242 | 'CodiceCIG' => '',
243 | ],
244 | 'DatiConvenzione' => [
245 | 'RiferimentoNumeroLinea' => '',
246 | 'IdDocumento' => '',
247 | 'Data' => '',
248 | 'NumItem' => '',
249 | 'CodiceCommessaConvenzione' => '',
250 | 'CodiceCUP' => '',
251 | 'CodiceCIG' => '',
252 | ],
253 | 'DatiRicezione' => [
254 | 'RiferimentoNumeroLinea' => '',
255 | 'IdDocumento' => '',
256 | 'Data' => '',
257 | 'NumItem' => '',
258 | 'CodiceCommessaConvenzione' => '',
259 | 'CodiceCUP' => '',
260 | 'CodiceCIG' => '',
261 | ],
262 | 'DatiFattureCollegate' => [
263 | 'RiferimentoNumeroLinea' => '',
264 | 'IdDocumento' => '',
265 | 'Data' => '',
266 | 'NumItem' => '',
267 | 'CodiceCommessaConvenzione' => '',
268 | 'CodiceCUP' => '',
269 | 'CodiceCIG' => '',
270 | ],
271 | 'DatiSAL' => [
272 | 'RiferimentoFase' => '',
273 | ],
274 | 'DatiDDT' => [
275 | 'NumeroDDT' => '',
276 | 'DataDDT' => '',
277 | 'RiferimentoNumeroLinea' => ''
278 | ],
279 | 'DatiTrasporto' => [
280 | 'DatiAnagraficiVettore' => array(
281 | 'IdFiscaleIVA' => array(
282 | 'IdPaese' => '',
283 | 'IdCodice' => ''
284 | ),
285 | 'CodiceFiscale' => '',
286 | 'Anagrafica' => array(
287 | 'Denominazione' => '',
288 | 'Nome' => '',
289 | 'Cognome' => '',
290 | 'Titolo' => '',
291 | 'CodEORI' => ''
292 | ),
293 | 'NumeroLicenzaGuida' => ''
294 | ),
295 | 'MezzoTrasporto' => '',
296 | 'CausaleTrasporto' => '',
297 | 'NumeroColli' => '',
298 | 'Descrizione' => '',
299 | 'UnitaMisuraPeso' => '',
300 | 'PesoLordo' => '',
301 | 'PesoNetto' => '',
302 | 'DataOraRitiro' => '',
303 | 'DataInizioTrasporto' => '',
304 | 'TipoResa' => '',
305 | 'IndirizzoResa' => array(
306 | 'Indirizzo' => '',
307 | 'NumeroCivico' => '',
308 | 'CAP' => '',
309 | 'Comune' => '',
310 | 'Provincia' => '',
311 | 'Nazione' => ''
312 | ),
313 | 'DataOraConsegna' => '',
314 | ],
315 | 'FatturaPrincipale' => [
316 | 'NumeroFatturaPrincipale' => '',
317 | 'DataFatturaPrincipale' => ''
318 | ],
319 | ],
320 | 'DatiBeniServizi' => [
321 | 'DettaglioLinee' => array(
322 | 'NumeroLinea' => '',
323 | 'TipoCessionePrestazione' => '',
324 | 'CodiceArticolo' => array(
325 | 'CodiceTipo' => '',
326 | 'CodiceValore' => ''
327 | ),
328 | 'Descrizione' => '',
329 | 'Quantita' => '',
330 | 'UnitaMisura' => '',
331 | 'DataInizioPeriodo' => '',
332 | 'DataFinePeriodo' => '',
333 | 'PrezzoUnitario' => '',
334 | 'ScontoMaggiorazione' => array(
335 | 'Tipo' => '',
336 | 'Percentuale' => '',
337 | 'Importo' => ''
338 | ),
339 | 'PrezzoTotale' => '',
340 | 'AliquotaIVA' => '',
341 | 'Ritenuta' => '',
342 | 'Natura' => '',
343 | 'RiferimentoAmministrazione' => '',
344 | 'AltriDatiGestionali' => array(
345 | 'TipoDato' => '',
346 | 'RiferimentoTesto' => '',
347 | 'RiferimentoNumero' => '',
348 | 'RiferimentoData' => ''
349 | )
350 | ),
351 | 'DatiRiepilogo' => array(
352 | 'AliquotaIVA' => '',
353 | 'Natura' => '',
354 | 'SpeseAccessorie' => '',
355 | 'Arrotondamento' => '',
356 | 'ImponibileImporto' => '',
357 | 'Imposta' => '',
358 | // I IVA ad esigibilità immediata
359 | // D IVA ad esigibilità differita
360 | // S scissione dei pagamenti
361 | 'EsigibilitaIVA' => '',
362 | 'RiferimentoNormativo' => ''
363 | )
364 | ],
365 | // Presenti nei casi di cessioni tra paesi membri di mezzi di
366 | // trasporto nuovi. Dati relativi ai veicoli di cui
367 | // all’art. 38, comma 4 del DL 331 del 1993.
368 | 'DatiVeicoli' => [
369 | 'Data' => '',
370 | 'TotalePercorso' => ''
371 | ],
372 | 'DatiPagamento' => [
373 | 'CondizioniPagamento' => '',
374 | 'DettaglioPagamento' => array(
375 | 'Beneficiario' => '',
376 | 'ModalitaPagamento' => '',
377 | 'DataRiferimentoTerminiPagamento' => '',
378 | 'GiorniTerminiPagamento' => '',
379 | 'DataScadenzaPagamento' => '',
380 | 'ImportoPagamento' => '',
381 | 'CodUfficioPostale' => '',
382 | 'CognomeQuietanzante' => '',
383 | 'NomeQuietanzante' => '',
384 | 'CFQuietanzante' => '',
385 | 'TitoloQuietanzante' => '',
386 | 'IstitutoFinanziario' => '',
387 | 'IBAN' => '',
388 | 'ABI' => '',
389 | 'CAB' => '',
390 | 'BIC' => '',
391 | 'ScontoPagamentoAnticipato' => '',
392 | 'DataLimitePagamentoAnticipato' => '',
393 | 'PenalitaPagamentiRitardati' => '',
394 | 'DataDecorrenzaPenale' => '',
395 | 'CodicePagamento' => ''
396 | )
397 | ],
398 | 'Allegati' => [
399 | 'NomeAttachment' => '',
400 | 'AlgoritmoCompressione' => '',
401 | 'FormatoAttachment' => '',
402 | 'DescrizioneAttachment' => '',
403 | 'Attachment' => ''
404 | ]
405 | )
406 | );
407 |
408 | protected $validator = null;
409 |
410 | /**
411 | * Constructor
412 | */
413 | public function __construct( string $arg )
414 | {
415 | $format = strtoupper($arg);
416 |
417 | if (true === in_array($format, self::$allowedFormats)) {
418 | // New invoice
419 | parent::__construct();
420 | $this->dom->documentElement->setAttribute('versione', $format);
421 | $this->setValue('FormatoTrasmissione', $format);
422 | } else {
423 | // Load invoice from file
424 | parent::__construct($arg);
425 | }
426 | }
427 |
428 | /**
429 | * Retrieve invoice filename from current element values
430 | * if $this->filename is not set
431 | */
432 | public function getFilename()
433 | {
434 | if (null !== $this->filename) {
435 | return $this->filename;
436 | }
437 |
438 | $progressivoInvio = $this->getValue('ProgressivoInvio');
439 | $codice = $this->getValue('IdCodice', 'CedentePrestatore');
440 | $paese = $this->getValue('IdPaese', 'CedentePrestatore');
441 |
442 | if (empty($progressivoInvio)) {
443 | throw new \Exception(__FUNCTION__ . ': ProgressivoInvio is empty');
444 | }
445 | if (empty($paese)) {
446 | throw new \Exception(__FUNCTION__ . ': IdPaese is empty');
447 | }
448 | if (empty($codice)) {
449 | throw new \Exception(__FUNCTION__ . ': IdCodice is empty');
450 | }
451 |
452 | return "{$paese}{$codice}_$progressivoInvio.xml";
453 | }
454 |
455 | /**
456 | * Override normalize to check for "Causale" length
457 | */
458 | public function normalize()
459 | {
460 | $bodies = $this->getBodies();
461 | foreach ($bodies as $body) {
462 | // Split "Causale" if needed
463 | $causaleCount = $this->query('DatiGeneraliDocumento/Causale', $body)->length;
464 | if ($causaleCount === 1) {
465 | $this->splitElement('DatiGeneraliDocumento/Causale', 200, $body);
466 | }
467 | }
468 |
469 | return parent::normalize();
470 | }
471 |
472 | public function validate()
473 | {
474 | if (null === $this->validator) {
475 | $this->validator = new \SlamFatturaElettronica\Validator();
476 | }
477 |
478 | $this->validator->assertValidXml($this->asXML());
479 |
480 | return $this;
481 | }
482 |
483 | /**
484 | * BODY
485 | ***************************************************************************
486 | */
487 |
488 | /**
489 | * Add body (invoice lot)
490 | */
491 | public function addBody( int $n = 1 )
492 | {
493 | if ($n < 1) {
494 | return $this;
495 | }
496 |
497 | $body = $this->getBody();
498 |
499 | for ($i = 0; $i < $n; $i++) {
500 | $this->addElement($body->cloneNode(true), '/');
501 | }
502 |
503 | return $this;
504 | }
505 |
506 | /**
507 | * Retrieve all bodies as \DOMNodeList
508 | */
509 | public function getBodies()
510 | {
511 | return $this->query('FatturaElettronicaBody');
512 | }
513 |
514 | /**
515 | * Get body
516 | */
517 | public function getBody( int $bodyIndex = 1 )
518 | {
519 | return $this->getElement("FatturaElettronicaBody[$bodyIndex]");
520 | }
521 |
522 | /**
523 | * Set number of bodies (invoice lot)
524 | */
525 | public function setBodyCount( int $n )
526 | {
527 | return $this->addBody($n - 1);
528 | }
529 |
530 | /**
531 | * LINE ITEMS
532 | ***************************************************************************
533 | */
534 |
535 | /**
536 | * Add line item
537 | */
538 | public function addLineItem( int $n, int $bodyIndex = 1 )
539 | {
540 | if ($n < 1) {
541 | return $this;
542 | }
543 |
544 | if ($bodyIndex < 1) {
545 | throw new \Exception("Invalid body index '$bodyIndex'");
546 | }
547 |
548 | $body = $this->getBody($bodyIndex);
549 | $line = $this->getElement('DettaglioLinee', $body);
550 | $parent = $this->getElement('DatiBeniServizi', $body);
551 | $beforeRef = $this->getElement('DatiRiepilogo', $body);
552 |
553 | for ($i = 0; $i < $n; $i++) {
554 | $this->addElement($line->cloneNode(true), $parent, $beforeRef);
555 | }
556 |
557 | return $this;
558 | }
559 |
560 | /**
561 | * Get line item i
562 | */
563 | public function getLineItem( int $i, int $bodyIndex = 1 )
564 | {
565 | $body = $this->getBody($bodyIndex);
566 | return $this->getElement("DettaglioLinee[$i]", $body);
567 | }
568 |
569 | /**
570 | * Set number of line items
571 | */
572 | public function setLineItemCount( int $n, int $bodyIndex = 1 )
573 | {
574 | return $this->addLineItem($n - 1, $bodyIndex);
575 | }
576 | }
577 |
--------------------------------------------------------------------------------
/tests/FatturaElettronicaTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(FatturaElettronica::class, $invoice);
16 | }
17 |
18 | public function testCan_Create_FPR12()
19 | {
20 | $invoice = new FatturaElettronica('FPR12');
21 |
22 | $this->assertInstanceOf(FatturaElettronica::class, $invoice);
23 | }
24 |
25 | public function testCannotCreateWithInvalidFormat()
26 | {
27 | $this->expectException(\Exception::class);
28 |
29 | $invoice = new FatturaElettronica('BAD');
30 | }
31 |
32 | public function testCanCreateFromFile()
33 | {
34 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA01.xml');
35 |
36 | $this->assertInstanceOf(FatturaElettronica::class, $invoice);
37 | }
38 |
39 | public function testCannotCreateFromNonExistentFile()
40 | {
41 | $this->expectException(\Exception::class);
42 |
43 | $invoice = new FatturaElettronica(__DIR__ . '/files/this-file-does-not-exist.xml');
44 | }
45 |
46 | /**
47 | * DOM object
48 | ***************************************************************************
49 | */
50 | public function testDomIsAValidObject()
51 | {
52 | $invoice = new FatturaElettronica('FPA12');
53 |
54 | $this->assertInstanceOf(\DOMDocument::class, $invoice->getDOM());
55 | }
56 |
57 | /**
58 | * QUERY
59 | ***************************************************************************
60 | */
61 | public function testQueryTagAndNoContext()
62 | {
63 | $tag = 'ProgressivoInvio';
64 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA01.xml');
65 | $list = $invoice->query($tag);
66 |
67 | $this->assertEquals(1, $list->length);
68 | }
69 |
70 | public function testQueryRelativePathAndNoContext()
71 | {
72 | $path = 'DatiGeneraliDocumento/Divisa';
73 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA01.xml');
74 | $list = $invoice->query($path);
75 |
76 | $this->assertEquals(1, $list->length);
77 | }
78 |
79 | public function testQueryAbsolutePathAndNoContext()
80 | {
81 | $path = '/FatturaElettronicaBody/DatiPagamento/CondizioniPagamento';
82 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA01.xml');
83 | $list = $invoice->query($path);
84 |
85 | $this->assertEquals(1, $list->length);
86 | }
87 |
88 | public function testQueryTagWithContext()
89 | {
90 | $tag = 'Imposta';
91 | $context = 'DatiRiepilogo';
92 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA01.xml');
93 | $list = $invoice->query($tag, $context);
94 |
95 | $this->assertEquals(1, $list->length);
96 | }
97 |
98 | public function testQueryRelativePathWithContext()
99 | {
100 | $path = 'Sede/CAP';
101 | $context = 'CedentePrestatore';
102 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA01.xml');
103 | $list = $invoice->query($path, $context);
104 |
105 | $this->assertEquals(1, $list->length);
106 | }
107 |
108 | public function testCannotQueryAbsolutePathWithContext()
109 | {
110 | $this->expectException(\Exception::class);
111 |
112 | $path = '/FatturaElettronicaHeader/DatiTrasmissione/CodiceDestinatario';
113 | $context = 'FatturaElettronicaHeader';
114 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA01.xml');
115 | $list = $invoice->query($path, $context);
116 | }
117 |
118 | public function testQueryPathWithPredicateWithContext()
119 | {
120 | $path = './/DatiPagamento';
121 | $context = 'FatturaElettronicaBody[2]';
122 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA03.xml');
123 | $list = $invoice->query($path, $context);
124 |
125 | $this->assertEquals(1, $list->length);
126 | }
127 |
128 | /**
129 | * Elements
130 | ***************************************************************************
131 | */
132 | public function testGetOneElementByTag()
133 | {
134 | $tag = 'ProgressivoInvio';
135 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA01.xml');
136 | $element = $invoice->getElement($tag);
137 |
138 | $this->assertInstanceOf(\DOMNode::class, $element);
139 | }
140 |
141 | public function testAddElementNoBeforeRef()
142 | {
143 | $invoice = new FatturaElettronica('FPA12');
144 | $invoice->addElement('PECDestinatarioExtra', 'DatiTrasmissione');
145 | $invoice->setValue('PECDestinatarioExtra', 'pec@example.com');
146 | $value = $invoice->getValue('PECDestinatarioExtra');
147 |
148 | $this->assertEquals('pec@example.com', $value);
149 | }
150 |
151 | public function testAddBody()
152 | {
153 | $invoice = new FatturaElettronica('FPR12');
154 | $invoice->addBody(2);
155 | $bodies = $invoice->query('FatturaElettronicaBody');
156 | $count = $bodies->length;
157 |
158 | $this->assertEquals(3, $count);
159 | }
160 |
161 | public function testAddLineItem()
162 | {
163 | $invoice = new FatturaElettronica('FPR12');
164 | $invoice->addBody(2);
165 | $invoice->addLineItem(5, 3);
166 | $count = $invoice->query("/FatturaElettronicaBody[3]//DettaglioLinee")->length;
167 |
168 | $this->assertEquals(6, $count);
169 | }
170 |
171 | public function testSplitElement()
172 | {
173 | $string = 'Lorem ipsum dolor sit amet, consectetur adipisci elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
174 | $invoice = new FatturaElettronica('FPR12');
175 | $invoice->setValue('DatiGeneraliDocumento/Causale', $string);
176 |
177 | // 2 times, it should be idempotent
178 | $invoice->normalize();
179 | $invoice->normalize();
180 |
181 | $causaleCount = $invoice->query('DatiGeneraliDocumento/Causale')->length;
182 | $lastChunk = 'lpa qui officia deserunt mollit anim id est laborum.';
183 |
184 | $this->assertEquals('3 lpa qui officia deserunt mollit anim id est laborum.', "$causaleCount $lastChunk");
185 | }
186 |
187 | public function testSetElementCount()
188 | {
189 | $invoice = new FatturaElettronica('FPR12');
190 | $invoice->setElementCount('ProgressivoInvio', 4);
191 | $invoice->setElementCount('ProgressivoInvio', 3);
192 | $count = $invoice->query('ProgressivoInvio')->length;
193 |
194 | $this->assertEquals(3, $count);
195 | }
196 |
197 | /**
198 | * Values
199 | ***************************************************************************
200 | */
201 | public function testGetValueByTag()
202 | {
203 | $tag = 'ProgressivoInvio';
204 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA01.xml');
205 | $value = $invoice->getValue($tag);
206 |
207 | $this->assertEquals('00001', $value);
208 | }
209 |
210 | public function testGetValueWithContext()
211 | {
212 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA02.xml');
213 | $value = $invoice->getValue('NumItem', 'DatiContratto');
214 |
215 | $this->assertEquals('5', (string)$value);
216 | }
217 |
218 | public function testGetValueByAbsolutePath()
219 | {
220 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA02.xml');
221 | $value = $invoice->getValue('/FatturaElettronicaHeader/DatiTrasmissione/CodiceDestinatario');
222 |
223 | $this->assertEquals('AAAAAA', $value);
224 | }
225 |
226 | public function testGetValueByRelativePath()
227 | {
228 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA02.xml');
229 | $value = $invoice->getValue('DettaglioLinee[2]/NumeroLinea');
230 |
231 | $this->assertEquals('2', (string)$value);
232 | }
233 |
234 | public function testCannotGetAmbiguousValue()
235 | {
236 | $this->expectException(\Exception::class);
237 |
238 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA02.xml');
239 | $value = $invoice->getValue('IdPaese');
240 | }
241 |
242 | public function testCannotGetAmbiguousValue2()
243 | {
244 | $this->expectException(\Exception::class);
245 |
246 | $invoice = new FatturaElettronica(__DIR__ . '/files/IT01234567890_FPA02.xml');
247 | $value = $invoice->getValue('Sede/Indirizzo', 'FatturaElettronicaHeader');
248 | }
249 |
250 | public function testSetOneValueByTagNoContext()
251 | {
252 | $tag = 'ProgressivoInvio';
253 | $invoice = new FatturaElettronica('FPR12');
254 | $invoice->setValue($tag, '54321');
255 | $value = $invoice->getValue($tag);
256 |
257 | $this->assertEquals('54321', $value);
258 | }
259 |
260 | public function testSetValuesByTag()
261 | {
262 | $tag = 'CessionarioCommittente';
263 | $invoice = new FatturaElettronica('FPR12');
264 | $invoice->setValues($tag, array(
265 | // CessionarioCommittente/DatiAnagrafici/CodiceFiscale
266 | 'DatiAnagrafici/CodiceFiscale' => '01234567890',
267 | // Denominazione, somewhere inside CessionarioCommittente
268 | 'Anagrafica/Denominazione' => 'BETA SRL'
269 | ));
270 | $value1 = $invoice->getValue('DatiAnagrafici/CodiceFiscale', $tag);
271 | $value2 = $invoice->getValue('Anagrafica/Denominazione', $tag);
272 |
273 | $this->assertEquals(
274 | array('01234567890', 'BETA SRL'),
275 | array($value1, $value2)
276 | );
277 | }
278 |
279 | public function testSetValueToAllByTagNoContext()
280 | {
281 | $tag = 'Indirizzo';
282 | $invoice = new FatturaElettronica('FPR12');
283 | $invoice->setValueToAll($tag, 'VIA DELLE ROSE');
284 | $value1 = $invoice->getValue('CedentePrestatore/Sede/Indirizzo');
285 | $value2 = $invoice->getValue('CessionarioCommittente/Sede/Indirizzo');
286 |
287 | $this->assertEquals(
288 | array('VIA DELLE ROSE', 'VIA DELLE ROSE'),
289 | array($value1, $value2)
290 | );
291 | }
292 |
293 | public function testSetValuesToAll()
294 | {
295 | $tag = 'FatturaElettronicaBody';
296 | $invoice = new FatturaElettronica('FPR12');
297 | $invoice->setValuesToAll($tag, array(
298 | 'AliquotaIVA' => '22.00',
299 | 'Denominazione' => 'TRASPORTO SPA'
300 | ));
301 | $value1 = $invoice->getValue('DettaglioLinee/AliquotaIVA', $tag);
302 | $value2 = $invoice->getValue('DatiRiepilogo/AliquotaIVA', $tag);
303 | $value3 = $invoice->getValue('Denominazione', $tag);
304 |
305 | $this->assertEquals(
306 | array('22.00', '22.00', 'TRASPORTO SPA'),
307 | array($value1, $value2, $value3)
308 | );
309 | }
310 |
311 | public function testSetValuesToLineItem()
312 | {
313 | $invoice = new FatturaElettronica('FPR12');
314 | $invoice->addLineItem(3);
315 | $invoice->setValue('DettaglioLinee[4]/NumeroLinea', 44);
316 | $value = $invoice->getValue('DettaglioLinee[4]/NumeroLinea');
317 |
318 | $this->assertEquals(44, $value);
319 | }
320 |
321 | public function testSetValuesFromArray()
322 | {
323 | $array = array(
324 | 'DatiAnagraficiVettore' => array(
325 | 'IdFiscaleIVA' => array(
326 | 'IdPaese' => 'IT',
327 | 'IdCodice' => '09876543210'
328 | ),
329 | 'Anagrafica' => array(
330 | 'Denominazione' => 'TRASPORTO SRLS'
331 | ),
332 | 'NumeroLicenzaGuida' => 'AA090909'
333 | ),
334 | 'MezzoTrasporto' => 'Mezzo',
335 | 'CausaleTrasporto' => 'La causale del traporto',
336 | 'NumeroColli' => '1',
337 | 'Descrizione' => 'La descrizione'
338 | );
339 |
340 | $invoice = new FatturaElettronica('FPR12');
341 | $invoice->setValuesFromArray('DatiTrasporto', $array);
342 | $value1 = $invoice->getValue('Denominazione', 'DatiTrasporto');
343 | $value2 = $invoice->getValue('NumeroLicenzaGuida', 'DatiTrasporto');
344 |
345 | $this->assertEquals('TRASPORTO SRLS AA090909', "$value1 $value2");
346 | }
347 |
348 | /**
349 | * Filename
350 | ***************************************************************************
351 | */
352 | public function testGetAValidFilename()
353 | {
354 | $invoice = new FatturaElettronica('FPR12');
355 | $invoice->setValue('ProgressivoInvio', '54321');
356 | $invoice->setValue('IdCodice', '00011122233', 'CedentePrestatore');
357 | $invoice->setValue('IdPaese', 'IT', 'CedentePrestatore');
358 | $filename = $invoice->getFilename();
359 |
360 | $this->assertEquals('IT00011122233_54321.xml', $filename);
361 | }
362 |
363 | public function testSetACustomFilename()
364 | {
365 | $prefixPath = __DIR__ . '/tmpfiles';
366 | $filename = 'my-custom-template.xml';
367 | $invoice = new FatturaElettronica('FPR12');
368 | $invoice->setValue('IdTrasmittente/IdCodice', '00011122233');
369 | $invoice->setValue('IdTrasmittente/IdPaese', 'IT');
370 | $invoice->setFilename($filename);
371 | $invoice->setPrefixPath($prefixPath)->save(true);
372 |
373 | $this->assertFileIsReadable($prefixPath . "/$filename");
374 | }
375 |
376 | /**
377 | * Stylesheet
378 | ***************************************************************************
379 | */
380 | public function testSetStylesheet()
381 | {
382 | $invoice = new FatturaElettronica('FPR12');
383 | $invoice->setStylesheet('fatturaPA_v1.2.1.xsl');
384 | $xml = $invoice->asXML();
385 | $xml = $invoice->asXML();
386 |
387 | $this->assertEquals(
388 | 'type="text/xsl" href="fatturaPA_v1.2.1.xsl"',
389 | $invoice->getDOM()->firstChild->nodeValue);
390 | }
391 |
392 | public function testResetStylesheet()
393 | {
394 | $invoice = new FatturaElettronica('FPR12');
395 | $invoice->setStylesheet('fatturaPA_v1.2.1.xsl');
396 | $xml = $invoice->asXML();
397 | $invoice->unsetStylesheet();
398 | $xml = $invoice->asXML();
399 | $string = '';
400 |
401 | $this->assertFalse(strpos($xml, $string));
402 | }
403 | }
404 |
--------------------------------------------------------------------------------
/tests/files/IT01234567890_FPA01.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 | IT
10 | 01234567890
11 |
12 | 00001
13 | FPA12
14 | AAAAAA
15 |
16 |
17 |
18 |
19 | IT
20 | 01234567890
21 |
22 |
23 | ALPHA SRL
24 |
25 | RF19
26 |
27 |
28 | VIALE ROMA 543
29 | 07100
30 | SASSARI
31 | SS
32 | IT
33 |
34 |
35 |
36 |
37 | 09876543210
38 |
39 | AMMINISTRAZIONE BETA
40 |
41 |
42 |
43 | VIA TORINO 38-B
44 | 00145
45 | ROMA
46 | RM
47 | IT
48 |
49 |
50 |
51 |
52 |
53 |
54 | TD01
55 | EUR
56 | 2017-01-18
57 | 123
58 | LA FATTURA FA RIFERIMENTO AD UNA OPERAZIONE AAAA BBBBBBBBBBBBBBBBBB CCC DDDDDDDDDDDDDDD E FFFFFFFFFFFFFFFFFFFF GGGGGGGGGG HHHHHHH II LLLLLLLLLLLLLLLLL MMM NNNNN OO PPPPPPPPPPP QQQQ RRRR SSSSSSSSSSSSSS
59 | SEGUE DESCRIZIONE CAUSALE NEL CASO IN CUI NON SIANO STATI SUFFICIENTI 200 CARATTERI AAAAAAAAAAA BBBBBBBBBBBBBBBBB
60 |
61 |
62 | 1
63 | 66685
64 | 1
65 | 123abc
66 | 456def
67 |
68 |
69 | 1
70 | 123
71 | 2016-09-01
72 | 5
73 | 123abc
74 | 456def
75 |
76 |
77 | 1
78 | 456
79 | 5
80 | 123abc
81 | 456def
82 |
83 |
84 | 1
85 | 789
86 | 5
87 | 123abc
88 | 456def
89 |
90 |
91 |
92 |
93 | IT
94 | 24681012141
95 |
96 |
97 | Trasporto spa
98 |
99 |
100 | 2017-01-10T16:46:12.000+02:00
101 |
102 |
103 |
104 |
105 | 1
106 | DESCRIZIONE DELLA FORNITURA
107 | 5.00
108 | 1.00
109 | 5.00
110 | 22.00
111 |
112 |
113 | 22.00
114 | 5.00
115 | 1.10
116 | I
117 |
118 |
119 |
120 | TP01
121 |
122 | MP01
123 | 2017-02-18
124 | 6.10
125 |
126 |
127 |
128 |
--------------------------------------------------------------------------------
/tests/files/IT01234567890_FPA02.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 | IT
10 | 01234567890
11 |
12 | 00001
13 | FPA12
14 | AAAAAA
15 |
16 |
17 |
18 |
19 | IT
20 | 01234567890
21 |
22 |
23 | ALPHA SRL
24 |
25 | RF01
26 |
27 |
28 | VIALE ROMA 543
29 | 07100
30 | SASSARI
31 | SS
32 | IT
33 |
34 |
35 |
36 |
37 | 09876543210
38 |
39 | AMMINISTRAZIONE BETA
40 |
41 |
42 |
43 | VIA TORINO 38-B
44 | 00145
45 | ROMA
46 | RM
47 | IT
48 |
49 |
50 |
51 |
52 |
53 |
54 | TD01
55 | EUR
56 | 2017-01-18
57 | 123
58 | LA FATTURA FA RIFERIMENTO AD UNA OPERAZIONE AAAA BBBBBBBBBBBBBBBBBB CCC DDDDDDDDDDDDDDD E FFFFFFFFFFFFFFFFFFFF GGGGGGGGGG HHHHHHH II LLLLLLLLLLLLLLLLL MMM NNNNN OO PPPPPPPPPPP QQQQ RRRR SSSSSSSSSSSSSS
59 | SEGUE DESCRIZIONE CAUSALE NEL CASO IN CUI NON SIANO STATI SUFFICIENTI 200 CARATTERI AAAAAAAAAAA BBBBBBBBBBBBBBBBB
60 |
61 |
62 | 1
63 | 66685
64 | 1
65 | 123abc
66 | 456def
67 |
68 |
69 | 1
70 | 123
71 | 2016-09-01
72 | 5
73 | 123abc
74 | 456def
75 |
76 |
77 | 1
78 | 456
79 | 5
80 | 123abc
81 | 456def
82 |
83 |
84 | 1
85 | 789
86 | 5
87 | 123abc
88 | 456def
89 |
90 |
91 |
92 |
93 | IT
94 | 24681012141
95 |
96 |
97 | Trasporto spa
98 |
99 |
100 | 2017-01-10T16:46:12.000+02:00
101 |
102 |
103 |
104 |
105 | 1
106 | LA DESCRIZIONE DELLA FORNITURA PUO' SUPERARE I CENTO CARATTERI CHE RAPPRESENTAVANO IL PRECEDENTE LIMITE DIMENSIONALE. TALE LIMITE NELLA NUOVA VERSIONE E' STATO PORTATO A MILLE CARATTERI
107 | 5.00
108 | 1.00
109 | 5.00
110 | 22.00
111 |
112 |
113 | 2
114 | FORNITURE VARIE PER UFFICIO
115 | 10.00
116 | 2.00
117 | 20.00
118 | 22.00
119 |
120 |
121 | 22.00
122 | 25.00
123 | 5.50
124 | D
125 |
126 |
127 |
128 | TP01
129 |
130 | MP01
131 | 2017-03-30
132 | 30.50
133 |
134 |
135 |
136 |
--------------------------------------------------------------------------------
/tests/files/IT01234567890_FPA03.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 | IT
10 | 01234567890
11 |
12 | 00001
13 | FPA12
14 | AAAAAA
15 |
16 |
17 |
18 |
19 | IT
20 | 01234567890
21 |
22 |
23 | ALPHA SRL
24 |
25 | RF01
26 |
27 |
28 | VIALE ROMA 543
29 | 07100
30 | SASSARI
31 | SS
32 | IT
33 |
34 |
35 |
36 |
37 | 09876543210
38 |
39 | AMMINISTRAZIONE BETA
40 |
41 |
42 |
43 | VIA TORINO 38-B
44 | 00145
45 | ROMA
46 | RM
47 | IT
48 |
49 |
50 |
51 |
52 |
53 |
54 | TD01
55 | EUR
56 | 2017-01-18
57 | 12
58 | LA FATTURA FA RIFERIMENTO AD UNA OPERAZIONE AAAA BBBBBBBBBBBBBBBBBB CCC DDDDDDDDDDDDDDD E FFFFFFFFFFFFFFFFFFFF GGGGGGGGGG HHHHHHH II LLLLLLLLLLLLLLLLL MMM NNNNN OO PPPPPPPPPPP QQQQ RRRR SSSSSSSSSSSSSS
59 | SEGUE DESCRIZIONE CAUSALE NEL CASO IN CUI NON SIANO STATI SUFFICIENTI 200 CARATTERI AAAAAAAAAAA BBBBBBBBBBBBBBBBB
60 |
61 |
62 | 1
63 | 66685
64 | 1
65 | 123abc
66 | 456def
67 |
68 |
69 | 1
70 | 123
71 | 2012-09-01
72 | 5
73 | 123abc
74 | 456def
75 |
76 |
77 | 1
78 | 456
79 | 5
80 | 123abc
81 | 456def
82 |
83 |
84 | 1
85 | 789
86 | 5
87 | 123abc
88 | 456def
89 |
90 |
91 |
92 |
93 | IT
94 | 24681012141
95 |
96 |
97 | Trasporto spa
98 |
99 |
100 | 2017-01-10T16:46:12.000+02:00
101 |
102 |
103 |
104 |
105 | 1
106 | LA DESCRIZIONE DELLA FORNITURA PUO' SUPERARE I CENTO CARATTERI CHE RAPPRESENTAVANO IL PRECEDENTE LIMITE DIMENSIONALE. TALE LIMITE NELLA NUOVA VERSIONE E' STATO PORTATO A MILLE CARATTERI
107 | 5.00
108 | 1.00
109 | 5.00
110 | 22.00
111 |
112 |
113 | 2
114 | FORNITURE VARIE PER UFFICIO
115 | 10.00
116 | 2.00
117 | 20.00
118 | 22.00
119 |
120 |
121 | 22.00
122 | 25.00
123 | 5.50
124 | I
125 |
126 |
127 |
128 | TP01
129 |
130 | MP01
131 | 2017-02-18
132 | 30.50
133 |
134 |
135 |
136 |
137 |
138 |
139 | TD01
140 | EUR
141 | 2017-01-20
142 | 456
143 | LA FATTURA FA RIFERIMENTO AD UNA OPERAZIONE AAAA BBBBBBBBBBBBBBBBBB CCC DDDDDDDDDDDDDDD E FFFFFFFFFFFFFFFFFFFF GGGGGGGGGG HHHHHHH II LLLLLLLLLLLLLLLLL MMM NNNNN OO PPPPPPPPPPP QQQQ RRRR SSSSSSSSSSSSSS
144 | SEGUE DESCRIZIONE CAUSALE NEL CASO IN CUI NON SIANO STATI SUFFICIENTI 200 CARATTERI AAAAAAAAAAA BBBBBBBBBBBBBBBBB
145 |
146 |
147 | 1
148 | 85666
149 | 1
150 | 123abc
151 | 456def
152 |
153 |
154 | 1
155 | 321
156 | 2016-09-01
157 | 5
158 | 123abc
159 | 456def
160 |
161 |
162 | 1
163 | 654
164 | 5
165 | 123abc
166 | 456def
167 |
168 |
169 | 1
170 | 987
171 | 5
172 | 123abc
173 | 456def
174 |
175 |
176 |
177 |
178 | 1
179 | PRESTAZIONE DEL SEGUENTE SERVIZIO PROFESSIONALE: LA DESCRIZIONE DELLA PRESTAZIONE PUO' SUPERARE I CENTO CARATTERI CHE RAPPRESENTAVANO IL PRECEDENTE LIMITE DIMENSIONALE. TALE LIMITE NELLA NUOVA VERSIONE E' STATO PORTATO A MILLE CARATTERI
180 | 2000.00
181 | 2000.00
182 | 22.00
183 |
184 |
185 | 22.00
186 | 2000.00
187 | 440.00
188 | I
189 |
190 |
191 |
192 | TP01
193 |
194 | MP19
195 | 2017-02-20
196 | 2440.00
197 |
198 |
199 |
200 |
--------------------------------------------------------------------------------
/tests/files/IT01234567890_FPR01.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 | IT
10 | 01234567890
11 |
12 | 00001
13 | FPR12
14 | ABC1234
15 |
16 |
17 |
18 |
19 |
20 | IT
21 | 01234567890
22 |
23 |
24 | SOCIETA' ALPHA SRL
25 |
26 | RF19
27 |
28 |
29 | VIALE ROMA 543
30 | 07100
31 | SASSARI
32 | SS
33 | IT
34 |
35 |
36 |
37 |
38 | 09876543210
39 |
40 | DITTA BETA
41 |
42 |
43 |
44 | VIA TORINO 38-B
45 | 00145
46 | ROMA
47 | RM
48 | IT
49 |
50 |
51 |
52 |
53 |
54 |
55 | TD01
56 | EUR
57 | 2014-12-18
58 | 123
59 | LA FATTURA FA RIFERIMENTO AD UNA OPERAZIONE AAAA BBBBBBBBBBBBBBBBBB CCC DDDDDDDDDDDDDDD E FFFFFFFFFFFFFFFFFFFF GGGGGGGGGG HHHHHHH II LLLLLLLLLLLLLLLLL MMM NNNNN OO PPPPPPPPPPP QQQQ RRRR SSSSSSSSSSSSSS
60 | SEGUE DESCRIZIONE CAUSALE NEL CASO IN CUI NON SIANO STATI SUFFICIENTI 200 CARATTERI AAAAAAAAAAA BBBBBBBBBBBBBBBBB
61 |
62 |
63 | 1
64 | 66685
65 | 1
66 |
67 |
68 | 1
69 | 123
70 | 2012-09-01
71 | 5
72 | 123abc
73 | 456def
74 |
75 |
76 |
77 |
78 | IT
79 | 24681012141
80 |
81 |
82 | Trasporto spa
83 |
84 |
85 | 2012-10-22T16:46:12.000+02:00
86 |
87 |
88 |
89 |
90 | 1
91 | DESCRIZIONE DELLA FORNITURA
92 | 5.00
93 | 1.00
94 | 5.00
95 | 22.00
96 |
97 |
98 | 22.00
99 | 5.00
100 | 1.10
101 | I
102 |
103 |
104 |
105 | TP01
106 |
107 | MP01
108 | 2015-01-30
109 | 6.10
110 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/tests/files/IT01234567890_FPR02.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | IT
7 | 01234567890
8 |
9 | 00001
10 | FPR12
11 | 0000000
12 | betagamma@pec.it
13 |
14 |
15 |
16 |
17 | IT
18 | 01234567890
19 |
20 |
21 | SOCIETA' ALPHA SRL
22 |
23 | RF01
24 |
25 |
26 | VIALE ROMA 543
27 | 07100
28 | SASSARI
29 | SS
30 | IT
31 |
32 |
33 |
34 |
35 | 09876543210
36 |
37 | BETA GAMMA
38 |
39 |
40 |
41 | VIA TORINO 38-B
42 | 00145
43 | ROMA
44 | RM
45 | IT
46 |
47 |
48 |
49 |
50 |
51 |
52 | TD01
53 | EUR
54 | 2014-12-18
55 | 123
56 | LA FATTURA FA RIFERIMENTO AD UNA OPERAZIONE AAAA BBBBBBBBBBBBBBBBBB CCC DDDDDDDDDDDDDDD E FFFFFFFFFFFFFFFFFFFF GGGGGGGGGG HHHHHHH II LLLLLLLLLLLLLLLLL MMM NNNNN OO PPPPPPPPPPP QQQQ RRRR SSSSSSSSSSSSSS
57 | SEGUE DESCRIZIONE CAUSALE NEL CASO IN CUI NON SIANO STATI SUFFICIENTI 200 CARATTERI AAAAAAAAAAA BBBBBBBBBBBBBBBBB
58 |
59 |
60 | 1
61 | 66685
62 | 1
63 |
64 |
65 |
66 |
67 | IT
68 | 24681012141
69 |
70 |
71 | Trasporto spa
72 |
73 |
74 | 2012-10-22T16:46:12.000+02:00
75 |
76 |
77 |
78 |
79 | 1
80 | LA DESCRIZIONE DELLA FORNITURA PUO' SUPERARE I CENTO CARATTERI CHE RAPPRESENTAVANO IL PRECEDENTE LIMITE DIMENSIONALE. TALE LIMITE NELLA NUOVA VERSIONE E' STATO PORTATO A MILLE CARATTERI
81 | 5.00
82 | 1.00
83 | 5.00
84 | 22.00
85 |
86 |
87 | 2
88 | FORNITURE VARIE PER UFFICIO
89 | 10.00
90 | 2.00
91 | 20.00
92 | 22.00
93 |
94 |
95 | 22.00
96 | 25.00
97 | 5.50
98 | D
99 |
100 |
101 |
102 | TP01
103 |
104 | MP01
105 | 2015-01-30
106 | 30.50
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/tests/files/IT01234567890_FPR03.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 | IT
10 | 01234567890
11 |
12 | 00001
13 | FPR12
14 | ABC1234
15 |
16 |
17 |
18 |
19 |
20 | IT
21 | 01234567890
22 |
23 |
24 | SOCIETA' ALPHA SRL
25 |
26 | RF01
27 |
28 |
29 | VIALE ROMA 543
30 | 07100
31 | SASSARI
32 | SS
33 | IT
34 |
35 |
36 |
37 |
38 | 09876543210
39 |
40 | BETA GAMMA
41 |
42 |
43 |
44 | VIA TORINO 38-B
45 | 00145
46 | ROMA
47 | RM
48 | IT
49 |
50 |
51 |
52 |
53 |
54 |
55 | TD01
56 | EUR
57 | 2014-12-18
58 | 123
59 | LA FATTURA FA RIFERIMENTO AD UNA OPERAZIONE AAAA BBBBBBBBBBBBBBBBBB CCC DDDDDDDDDDDDDDD E FFFFFFFFFFFFFFFFFFFF GGGGGGGGGG HHHHHHH II LLLLLLLLLLLLLLLLL MMM NNNNN OO PPPPPPPPPPP QQQQ RRRR SSSSSSSSSSSSSS
60 | SEGUE DESCRIZIONE CAUSALE NEL CASO IN CUI NON SIANO STATI SUFFICIENTI 200 CARATTERI AAAAAAAAAAA BBBBBBBBBBBBBBBBB
61 |
62 |
63 | 1
64 | 66685
65 | 1
66 |
67 |
68 |
69 |
70 | IT
71 | 24681012141
72 |
73 |
74 | Trasporto spa
75 |
76 |
77 | 2012-10-22T16:46:12.000+02:00
78 |
79 |
80 |
81 |
82 | 1
83 | LA DESCRIZIONE DELLA FORNITURA PUO' SUPERARE I CENTO CARATTERI CHE RAPPRESENTAVANO IL PRECEDENTE LIMITE DIMENSIONALE. TALE LIMITE NELLA NUOVA VERSIONE E' STATO PORTATO A MILLE CARATTERI
84 | 5.00
85 | 1.00
86 | 5.00
87 | 22.00
88 |
89 |
90 | 2
91 | FORNITURE VARIE PER UFFICIO
92 | 10.00
93 | 2.00
94 | 20.00
95 | 22.00
96 |
97 |
98 | 22.00
99 | 27.00
100 | 5.95
101 | I
102 |
103 |
104 |
105 | TP01
106 |
107 | MP01
108 | 2015-01-30
109 | 32.95
110 |
111 |
112 |
113 |
114 |
115 |
116 | TD01
117 | EUR
118 | 2014-12-20
119 | 456
120 | LA FATTURA FA RIFERIMENTO AD UNA OPERAZIONE AAAA BBBBBBBBBBBBBBBBBB CCC DDDDDDDDDDDDDDD E FFFFFFFFFFFFFFFFFFFF GGGGGGGGGG HHHHHHH II LLLLLLLLLLLLLLLLL MMM NNNNN OO PPPPPPPPPPP QQQQ RRRR SSSSSSSSSSSSSS
121 | SEGUE DESCRIZIONE CAUSALE NEL CASO IN CUI NON SIANO STATI SUFFICIENTI 200 CARATTERI AAAAAAAAAAA BBBBBBBBBBBBBBBBB
122 |
123 |
124 | 1
125 | 66685
126 | 1
127 |
128 |
129 |
130 |
131 | 1
132 | PRESTAZIONE DEL SEGUENTE SERVIZIO PROFESSIONALE: LA DESCRIZIONE DELLA PRESTAZIONE PUO' SUPERARE I CENTO CARATTERI CHE RAPPRESENTAVANO IL PRECEDENTE LIMITE DIMENSIONALE. TALE LIMITE NELLA NUOVA VERSIONE E' STATO PORTATO A MILLE CARATTERI
133 | 2000.00
134 | 2000.00
135 | 22.00
136 |
137 |
138 | 22.00
139 | 2000.00
140 | 440.00
141 | I
142 |
143 |
144 |
145 | TP01
146 |
147 | MP19
148 | 2015-01-28
149 | 2440.00
150 |
151 |
152 |
153 |
--------------------------------------------------------------------------------
/tests/tmpfiles/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/taocomp/php-e-invoice-it/152590a4766b7522426909f7745edbe23921606b/tests/tmpfiles/.gitkeep
--------------------------------------------------------------------------------