Metallzuschlag v1.1 - Kupferzuschlag-Berechnung + Notierungsverlauf
- Sonepar Metal Note API: CU/AL Tageswerte + Monatsdurchschnitte - Dashboard mit Chart.js Verlaufsdiagramm (30/90/365 Tage) - Trigger: Kupfergehalt (kg/km) = Aderanzahl × Querschnitt × 8,89 - Trigger: Kupferzuschlag (€/m) auf Einkaufspreisen berechnen - CU-Logik: Lieferant-eigener Wert oder aktuellster aus History - Cronjobs: Wöchentlicher API-Abruf + Kupferzuschlag-Neuberechnung - Extrafields: Lieferantenkarte (CU/AL/Datum/Quelle), Produkt (Aderanzahl/Querschnitt/Kupfergehalt) - Admin-Seite mit API-URL, Auto-Fetch, Lieferantenübersicht - Mehrsprachig (de_DE, en_US) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
8729b5fdb7
17 changed files with 2673 additions and 0 deletions
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
modulebuilder.txt
|
||||
build/
|
||||
test/
|
||||
*.eml
|
||||
.env
|
||||
credentials*
|
||||
621
COPYING
Executable file
621
COPYING
Executable file
|
|
@ -0,0 +1,621 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
28
ChangeLog.md
Executable file
28
ChangeLog.md
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
# Changelog - Metallzuschlag Modul
|
||||
|
||||
## 1.1 (2026-02-19)
|
||||
|
||||
### Neu
|
||||
- Kupfergehalt-Berechnung: Trigger auf Produkt-Speicherung (Aderanzahl x Querschnitt x 8,89)
|
||||
- Kupferzuschlag-Berechnung auf Einkaufspreisen (EUR/m = Kupfergehalt x CU-Notiz / 100.000)
|
||||
- CU-Notiz-Logik: Lieferanten-eigener Wert oder aktuellster aus History
|
||||
- Cronjob: Woechentliche Neuberechnung aller Kupferzuschlaege
|
||||
- Dashboard: Notierungsverlauf-Diagramm (Chart.js) mit Zeitraumauswahl (30/90/365 Tage)
|
||||
- Produkt-Extrafields: Aderanzahl (int), Querschnitt (double), Kupfergehalt (double)
|
||||
|
||||
### Geaendert
|
||||
- Modul-Deskriptor: Trigger aktiviert, zweiter Cronjob registriert
|
||||
- API-Klasse: getChartData(), recalcAllKupferzuschlag(), getCUForSupplier()
|
||||
- Sprachdateien: Neue Uebersetzungen fuer Chart, Extrafields
|
||||
|
||||
## 1.0 (2026-02-19)
|
||||
|
||||
### Erstversion
|
||||
- Sonepar Metal Note API Anbindung (Tageswerte + Monatsdurchschnitt)
|
||||
- DB-Tabelle llx_metallzuschlag_history fuer Notierungsverlauf
|
||||
- Dashboard mit aktuellen CU/AL-Werten und Verlaufstabelle
|
||||
- Lieferanten-Extrafields (metallzuschlag_cu, _al, _date, _source)
|
||||
- Automatische Aktualisierung der Lieferanten-Extrafields beim API-Abruf
|
||||
- Cronjob fuer woechentlichen Abruf
|
||||
- Admin-Seite: API-URL, Auto-Fetch, Lieferantenuebersicht
|
||||
- Mehrsprachig (de_DE, en_US)
|
||||
67
README.md
Executable file
67
README.md
Executable file
|
|
@ -0,0 +1,67 @@
|
|||
# Metallzuschlag - Dolibarr Modul
|
||||
|
||||
Metallnotierungen (Kupfer/Aluminium) von Sonepar abrufen, verwalten und automatisch auf Einkaufspreise anwenden.
|
||||
|
||||
## Funktionen
|
||||
|
||||
- **Metallnotierungen abrufen**: Tageswerte und Monatsdurchschnitte (CU/AL) von der Sonepar Metal Note API
|
||||
- **Dashboard**: Aktuelle Notierungen, Verlaufsdiagramm (Chart.js) und Historie
|
||||
- **Kupfergehalt berechnen**: Automatisch aus Aderanzahl x Querschnitt x 8,89 kg/(km*mm2) beim Speichern von Produkten
|
||||
- **Kupferzuschlag berechnen**: EUR/m auf Einkaufspreisen = Kupfergehalt x CU-Notiz / 100.000
|
||||
- **Lieferanten-Zuschlaege**: CU/AL-Werte pro Lieferant (automatisch oder manuell)
|
||||
- **Cronjobs**: Woechentlicher API-Abruf + Neuberechnung aller Kupferzuschlaege
|
||||
|
||||
## Datenquellen
|
||||
|
||||
- **Sonepar Metal Note API** (oeffentlich, ohne Authentifizierung)
|
||||
- Tageswert: `https://www.sonepar.de/api/content/metalnote/day?date=YYYYMMDD`
|
||||
- Monatsdurchschnitt: `https://www.sonepar.de/api/content/metalnote/previousmonth?date=YYYYMM01`
|
||||
|
||||
## Extrafields
|
||||
|
||||
### Auf Lieferantenkarten (thirdparty)
|
||||
- `metallzuschlag_cu` - Kupferzuschlag (EUR/100kg)
|
||||
- `metallzuschlag_al` - Aluminiumzuschlag (EUR/100kg)
|
||||
- `metallzuschlag_date` - Datum der letzten Aktualisierung
|
||||
- `metallzuschlag_source` - Quelle (sonepar, kluxen, manuell)
|
||||
|
||||
### Auf Produkten
|
||||
- `aderanzahl` - Anzahl Kupfer-Adern
|
||||
- `querschnitt` - Leiterquerschnitt in mm2
|
||||
- `kupfergehalt` - Berechnetes Kupfergewicht in kg/km (automatisch per Trigger)
|
||||
|
||||
### Auf Einkaufspreisen (product_fournisseur_price)
|
||||
- `kupferzuschlag` - Berechneter Kupferzuschlag in EUR/m (automatisch per Trigger + Cronjob)
|
||||
|
||||
## Berechnung
|
||||
|
||||
```
|
||||
Kupfergehalt (kg/km) = Aderanzahl x Querschnitt (mm2) x 8,89
|
||||
Kupferzuschlag (EUR/m) = Kupfergehalt (kg/km) x CU-Notiz (EUR/100kg) / 100.000
|
||||
```
|
||||
|
||||
Beispiel: NYM-J 3x1,5mm2 bei CU = 1.092,10 EUR/100kg
|
||||
- Kupfergehalt = 3 x 1,5 x 8,89 = 40,005 kg/km
|
||||
- Kupferzuschlag = 40,005 x 1.092,10 / 100.000 = 0,4369 EUR/m
|
||||
|
||||
## CU-Notiz Logik
|
||||
|
||||
1. Lieferant hat eigenen Wert (metallzuschlag_cu auf Lieferantenkarte) -> diesen verwenden
|
||||
2. Kein eigener Wert -> aktuellsten aus der Metallzuschlag-Historie
|
||||
|
||||
## Installation
|
||||
|
||||
1. Modul in `/custom/metallzuschlag/` ablegen
|
||||
2. In Dolibarr unter Einrichtung > Module aktivieren
|
||||
3. Einstellungen unter Metallzuschlag > Einrichtung konfigurieren
|
||||
4. "Jetzt abrufen" auf dem Dashboard klicken
|
||||
|
||||
## Voraussetzungen
|
||||
|
||||
- Dolibarr >= 19.0
|
||||
- PHP >= 7.1
|
||||
- cURL-Erweiterung (fuer API-Abruf)
|
||||
|
||||
## Lizenz
|
||||
|
||||
GPLv3 oder (nach Wahl) jede spaetere Version. Siehe COPYING.
|
||||
118
admin/about.php
Executable file
118
admin/about.php
Executable file
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
||||
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file metallzuschlag/admin/about.php
|
||||
* \ingroup metallzuschlag
|
||||
* \brief About page of module Metallzuschlag.
|
||||
*/
|
||||
|
||||
// Load Dolibarr environment
|
||||
$res = 0;
|
||||
// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
|
||||
if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
|
||||
$res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
|
||||
}
|
||||
// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
|
||||
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
|
||||
$tmp2 = realpath(__FILE__);
|
||||
$i = strlen($tmp) - 1;
|
||||
$j = strlen($tmp2) - 1;
|
||||
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
|
||||
$i--;
|
||||
$j--;
|
||||
}
|
||||
if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
|
||||
$res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
|
||||
}
|
||||
if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
|
||||
$res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
|
||||
}
|
||||
// Try main.inc.php using relative path
|
||||
if (!$res && file_exists("../../main.inc.php")) {
|
||||
$res = @include "../../main.inc.php";
|
||||
}
|
||||
if (!$res && file_exists("../../../main.inc.php")) {
|
||||
$res = @include "../../../main.inc.php";
|
||||
}
|
||||
if (!$res) {
|
||||
die("Include of main fails");
|
||||
}
|
||||
|
||||
// Libraries
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
||||
require_once '../lib/metallzuschlag.lib.php';
|
||||
|
||||
/**
|
||||
* @var Conf $conf
|
||||
* @var DoliDB $db
|
||||
* @var HookManager $hookmanager
|
||||
* @var Translate $langs
|
||||
* @var User $user
|
||||
*/
|
||||
|
||||
// Translations
|
||||
$langs->loadLangs(array("errors", "admin", "metallzuschlag@metallzuschlag"));
|
||||
|
||||
// Access control
|
||||
if (!$user->admin) {
|
||||
accessforbidden();
|
||||
}
|
||||
|
||||
// Parameters
|
||||
$action = GETPOST('action', 'aZ09');
|
||||
$backtopage = GETPOST('backtopage', 'alpha');
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
// None
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
$help_url = '';
|
||||
$title = "MetallzuschlagSetup";
|
||||
|
||||
llxHeader('', $langs->trans($title), $help_url, '', 0, 0, '', '', '', 'mod-metallzuschlag page-admin_about');
|
||||
|
||||
// Subheader
|
||||
$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
|
||||
|
||||
print load_fiche_titre($langs->trans($title), $linkback, 'title_setup');
|
||||
|
||||
// Configuration header
|
||||
$head = metallzuschlagAdminPrepareHead();
|
||||
print dol_get_fiche_head($head, 'about', $langs->trans($title), 0, 'metallzuschlag@metallzuschlag');
|
||||
|
||||
dol_include_once('/metallzuschlag/core/modules/modMetallzuschlag.class.php');
|
||||
$tmpmodule = new modMetallzuschlag($db);
|
||||
print $tmpmodule->getDescLong();
|
||||
|
||||
// Page end
|
||||
print dol_get_fiche_end();
|
||||
llxFooter();
|
||||
$db->close();
|
||||
177
admin/setup.php
Executable file
177
admin/setup.php
Executable file
|
|
@ -0,0 +1,177 @@
|
|||
<?php
|
||||
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file metallzuschlag/admin/setup.php
|
||||
* \ingroup metallzuschlag
|
||||
* \brief Metallzuschlag Konfigurationsseite
|
||||
*/
|
||||
|
||||
// Dolibarr Umgebung laden
|
||||
$res = 0;
|
||||
if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
|
||||
$res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
|
||||
}
|
||||
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
|
||||
$tmp2 = realpath(__FILE__);
|
||||
$i = strlen($tmp) - 1;
|
||||
$j = strlen($tmp2) - 1;
|
||||
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
|
||||
$i--;
|
||||
$j--;
|
||||
}
|
||||
if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
|
||||
$res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
|
||||
}
|
||||
if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
|
||||
$res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
|
||||
}
|
||||
if (!$res && file_exists("../../main.inc.php")) {
|
||||
$res = @include "../../main.inc.php";
|
||||
}
|
||||
if (!$res && file_exists("../../../main.inc.php")) {
|
||||
$res = @include "../../../main.inc.php";
|
||||
}
|
||||
if (!$res) {
|
||||
die("Include of main fails");
|
||||
}
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
|
||||
require_once '../lib/metallzuschlag.lib.php';
|
||||
|
||||
/**
|
||||
* @var Conf $conf
|
||||
* @var DoliDB $db
|
||||
* @var HookManager $hookmanager
|
||||
* @var Translate $langs
|
||||
* @var User $user
|
||||
*/
|
||||
|
||||
$langs->loadLangs(array("admin", "metallzuschlag@metallzuschlag"));
|
||||
|
||||
// Zugriffskontrolle
|
||||
if (!$user->admin) {
|
||||
accessforbidden();
|
||||
}
|
||||
|
||||
$action = GETPOST('action', 'aZ09');
|
||||
$backtopage = GETPOST('backtopage', 'alpha');
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($action == 'update' && !empty($user->admin)) {
|
||||
$apiUrl = GETPOST('METALLZUSCHLAG_API_URL', 'alpha');
|
||||
$autoFetch = GETPOSTINT('METALLZUSCHLAG_AUTO_FETCH');
|
||||
|
||||
dolibarr_set_const($db, 'METALLZUSCHLAG_API_URL', trim($apiUrl), 'chaine', 0, '', $conf->entity);
|
||||
dolibarr_set_const($db, 'METALLZUSCHLAG_AUTO_FETCH', $autoFetch, 'chaine', 0, '', $conf->entity);
|
||||
|
||||
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
|
||||
$action = '';
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
$title = "MetallzuschlagSetup";
|
||||
llxHeader('', $langs->trans($title), '', '', 0, 0, '', '', '', 'mod-metallzuschlag page-admin');
|
||||
|
||||
$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
|
||||
print load_fiche_titre($langs->trans($title), $linkback, 'title_setup');
|
||||
|
||||
$head = metallzuschlagAdminPrepareHead();
|
||||
print dol_get_fiche_head($head, 'settings', $langs->trans($title), -1, 'fa-coins');
|
||||
|
||||
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="update">';
|
||||
|
||||
print '<table class="noborder centpercent">';
|
||||
|
||||
// API Basis-URL
|
||||
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("MetallzuschlagApiUrl").'</td></tr>';
|
||||
print '<tr class="oddeven">';
|
||||
print '<td class="titlefield">'.$langs->trans("MetallzuschlagApiUrl");
|
||||
print ' '.$form->textwithpicto('', $langs->trans("MetallzuschlagApiUrlHelp"));
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print '<input type="text" class="flat minwidth500" name="METALLZUSCHLAG_API_URL" value="'.dol_escape_htmltag(getDolGlobalString('METALLZUSCHLAG_API_URL', 'https://www.sonepar.de/api/content/metalnote')).'">';
|
||||
print '</td></tr>';
|
||||
|
||||
// Automatischer Abruf
|
||||
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("MetallzuschlagAutoFetch").'</td></tr>';
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$langs->trans("MetallzuschlagAutoFetch");
|
||||
print ' '.$form->textwithpicto('', $langs->trans("MetallzuschlagAutoFetchHelp"));
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print $form->selectyesno('METALLZUSCHLAG_AUTO_FETCH', getDolGlobalInt('METALLZUSCHLAG_AUTO_FETCH', 1), 1);
|
||||
print '</td></tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"></div>';
|
||||
print '</form>';
|
||||
|
||||
// Lieferanten mit Metallzuschlag-Quelle anzeigen
|
||||
print '<br>';
|
||||
print load_fiche_titre($langs->trans("MetallzuschlagSuppliers"), '', '');
|
||||
|
||||
$sql = "SELECT s.rowid, s.nom as name, se.metallzuschlag_source, se.metallzuschlag_cu, se.metallzuschlag_al, se.metallzuschlag_date";
|
||||
$sql .= " FROM ".$db->prefix()."societe as s";
|
||||
$sql .= " INNER JOIN ".$db->prefix()."societe_extrafields as se ON se.fk_object = s.rowid";
|
||||
$sql .= " WHERE se.metallzuschlag_source IS NOT NULL AND se.metallzuschlag_source != ''";
|
||||
$sql .= " ORDER BY s.nom ASC";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
|
||||
print '<table class="noborder centpercent">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Company").'</td>';
|
||||
print '<td>'.$langs->trans("MetallzuschlagSource").'</td>';
|
||||
print '<td class="right">'.$langs->trans("MetallzuschlagCUShort").'</td>';
|
||||
print '<td class="right">'.$langs->trans("MetallzuschlagALShort").'</td>';
|
||||
print '<td class="right">'.$langs->trans("MetallzuschlagDate").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
if ($num > 0) {
|
||||
while ($obj = $db->fetch_object($resql)) {
|
||||
print '<tr class="oddeven">';
|
||||
print '<td><a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$obj->rowid.'">'.dol_escape_htmltag($obj->name).'</a></td>';
|
||||
print '<td>'.dol_escape_htmltag($obj->metallzuschlag_source).'</td>';
|
||||
print '<td class="right">'.(!empty($obj->metallzuschlag_cu) ? price($obj->metallzuschlag_cu, 0, '', 1, -1, 2).' €/100kg' : '-').'</td>';
|
||||
print '<td class="right">'.(!empty($obj->metallzuschlag_al) ? price($obj->metallzuschlag_al, 0, '', 1, -1, 2).' €/100kg' : '-').'</td>';
|
||||
print '<td class="right">'.(!empty($obj->metallzuschlag_date) ? dol_print_date($db->jdate($obj->metallzuschlag_date), 'day') : '-').'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
} else {
|
||||
print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("MetallzuschlagNoSuppliers").'</td></tr>';
|
||||
}
|
||||
print '</table>';
|
||||
} else {
|
||||
// Tabelle existiert evtl. noch nicht
|
||||
print '<div class="opacitymedium">'.$langs->trans("MetallzuschlagNoSuppliers").'</div>';
|
||||
}
|
||||
|
||||
print '<br><div class="opacitymedium">';
|
||||
print $langs->trans("MetallzuschlagSupplierMappingHelp");
|
||||
print '</div>';
|
||||
|
||||
print dol_get_fiche_end();
|
||||
|
||||
llxFooter();
|
||||
$db->close();
|
||||
491
class/metallzuschlagapi.class.php
Normal file
491
class/metallzuschlagapi.class.php
Normal file
|
|
@ -0,0 +1,491 @@
|
|||
<?php
|
||||
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file metallzuschlag/class/metallzuschlagapi.class.php
|
||||
* \ingroup metallzuschlag
|
||||
* \brief API-Client fuer Metallnotierungen + Cronjob-Methode
|
||||
*/
|
||||
|
||||
/**
|
||||
* Klasse fuer Metallnotiz-API-Abfragen und Cronjob
|
||||
*/
|
||||
class MetallzuschlagApi
|
||||
{
|
||||
/** @var DoliDB */
|
||||
public $db;
|
||||
/** @var string */
|
||||
public $error = '';
|
||||
/** @var string[] */
|
||||
public $errors = array();
|
||||
/** @var string */
|
||||
public $output = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cronjob-Methode: Metallnotierungen abrufen und speichern
|
||||
*
|
||||
* @return int 0 bei Erfolg, -1 bei Fehler
|
||||
*/
|
||||
public function fetchMetalNotes()
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
$langs->load('metallzuschlag@metallzuschlag');
|
||||
|
||||
dol_syslog("MetallzuschlagApi::fetchMetalNotes - Start", LOG_INFO);
|
||||
|
||||
$baseUrl = getDolGlobalString('METALLZUSCHLAG_API_URL', 'https://www.sonepar.de/api/content/metalnote');
|
||||
$today = date('Ymd');
|
||||
$firstOfMonth = date('Ym01');
|
||||
|
||||
$results = array();
|
||||
$hasError = false;
|
||||
|
||||
// Tageswerte abrufen
|
||||
$dayData = $this->callApi($baseUrl.'/day?date='.$today);
|
||||
if ($dayData !== false && !empty($dayData['data'])) {
|
||||
foreach ($dayData['data'] as $entry) {
|
||||
$metal = $entry['nes'];
|
||||
$value = (float)$entry['nku'];
|
||||
$date = $entry['ndt'];
|
||||
|
||||
$res = $this->saveNotation($date, $metal, $value, null, 'sonepar');
|
||||
if ($res < 0) {
|
||||
$hasError = true;
|
||||
} else {
|
||||
$results[] = $metal.': '.$value.' EUR/100kg ('.$date.')';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->output .= "Tageswerte: Keine Daten erhalten\n";
|
||||
$hasError = true;
|
||||
}
|
||||
|
||||
// Monatsdurchschnitt Vormonat abrufen
|
||||
$monthData = $this->callApi($baseUrl.'/previousmonth?date='.$firstOfMonth);
|
||||
if ($monthData !== false && !empty($monthData['data'])) {
|
||||
foreach ($monthData['data'] as $entry) {
|
||||
$metal = $entry['nes'];
|
||||
$avgValue = (float)$entry['nku'];
|
||||
|
||||
// Monatsdurchschnitt auf den heutigen Tageseintrag aktualisieren
|
||||
$this->updateMonthAvg(date('Y-m-d'), $metal, $avgValue, 'sonepar');
|
||||
$results[] = $metal.' Ø Vormonat: '.$avgValue.' EUR/100kg';
|
||||
}
|
||||
}
|
||||
|
||||
// Lieferanten-Extrafields aktualisieren
|
||||
$updatedSuppliers = $this->updateSupplierExtrafields($dayData);
|
||||
if ($updatedSuppliers > 0) {
|
||||
$results[] = $updatedSuppliers.' Lieferant(en) aktualisiert';
|
||||
}
|
||||
|
||||
if (!empty($results)) {
|
||||
$this->output = implode("\n", $results);
|
||||
}
|
||||
|
||||
dol_syslog("MetallzuschlagApi::fetchMetalNotes - Fertig: ".implode(', ', $results), LOG_INFO);
|
||||
|
||||
return $hasError ? -1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* API-Aufruf durchfuehren
|
||||
*
|
||||
* @param string $url URL zum Abrufen
|
||||
* @return array|false Dekodierte JSON-Antwort oder false bei Fehler
|
||||
*/
|
||||
public function callApi($url)
|
||||
{
|
||||
dol_syslog("MetallzuschlagApi::callApi - URL: ".$url, LOG_DEBUG);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Accept: application/json',
|
||||
'User-Agent: Dolibarr-Metallzuschlag/1.0',
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curlError = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($response === false || !empty($curlError)) {
|
||||
$this->error = 'cURL-Fehler: '.$curlError;
|
||||
dol_syslog("MetallzuschlagApi::callApi - ".$this->error, LOG_ERR);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($httpCode !== 200) {
|
||||
$this->error = 'HTTP '.$httpCode.' von '.$url;
|
||||
dol_syslog("MetallzuschlagApi::callApi - ".$this->error, LOG_ERR);
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = json_decode($response, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$this->error = 'JSON-Parse-Fehler: '.json_last_error_msg();
|
||||
dol_syslog("MetallzuschlagApi::callApi - ".$this->error, LOG_ERR);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($data['status']) || $data['status']['statuscode'] != 200) {
|
||||
$this->error = 'API-Fehler: Status '.($data['status']['statuscode'] ?? 'unbekannt');
|
||||
dol_syslog("MetallzuschlagApi::callApi - ".$this->error, LOG_ERR);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notierung in DB speichern (INSERT oder UPDATE bei Duplikat)
|
||||
*
|
||||
* @param string $date Datum (Y-m-d)
|
||||
* @param string $metal Metall-Kuerzel (CU/AL)
|
||||
* @param float $value Wert in EUR/100kg
|
||||
* @param float|null $avg Monatsdurchschnitt (optional)
|
||||
* @param string $source Quelle
|
||||
* @return int 1 bei Erfolg, -1 bei Fehler
|
||||
*/
|
||||
public function saveNotation($date, $metal, $value, $avg = null, $source = 'sonepar')
|
||||
{
|
||||
$sql = "INSERT INTO ".$this->db->prefix()."metallzuschlag_history";
|
||||
$sql .= " (date_notiz, metal, value, value_month_avg, source)";
|
||||
$sql .= " VALUES ('".$this->db->escape($date)."',";
|
||||
$sql .= " '".$this->db->escape($metal)."',";
|
||||
$sql .= " ".((float)$value).",";
|
||||
$sql .= " ".($avg !== null ? ((float)$avg) : "NULL").",";
|
||||
$sql .= " '".$this->db->escape($source)."')";
|
||||
$sql .= " ON DUPLICATE KEY UPDATE value = ".((float)$value);
|
||||
if ($avg !== null) {
|
||||
$sql .= ", value_month_avg = ".((float)$avg);
|
||||
}
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if (!$result) {
|
||||
$this->error = 'DB-Fehler: '.$this->db->lasterror();
|
||||
dol_syslog("MetallzuschlagApi::saveNotation - ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Monatsdurchschnitt auf bestehenden Eintrag aktualisieren
|
||||
*
|
||||
* @param string $date Datum
|
||||
* @param string $metal Metall
|
||||
* @param float $avg Durchschnittswert
|
||||
* @param string $source Quelle
|
||||
* @return int
|
||||
*/
|
||||
public function updateMonthAvg($date, $metal, $avg, $source = 'sonepar')
|
||||
{
|
||||
$sql = "UPDATE ".$this->db->prefix()."metallzuschlag_history";
|
||||
$sql .= " SET value_month_avg = ".((float)$avg);
|
||||
$sql .= " WHERE date_notiz = '".$this->db->escape($date)."'";
|
||||
$sql .= " AND metal = '".$this->db->escape($metal)."'";
|
||||
$sql .= " AND source = '".$this->db->escape($source)."'";
|
||||
|
||||
return $this->db->query($sql) ? 1 : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lieferanten-Extrafields mit aktuellen Werten aktualisieren
|
||||
*
|
||||
* @param array|false $dayData Tageswerte von der API
|
||||
* @return int Anzahl aktualisierter Lieferanten
|
||||
*/
|
||||
public function updateSupplierExtrafields($dayData)
|
||||
{
|
||||
if ($dayData === false || empty($dayData['data'])) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Werte aus API-Antwort extrahieren
|
||||
$values = array();
|
||||
foreach ($dayData['data'] as $entry) {
|
||||
$values[$entry['nes']] = (float)$entry['nku'];
|
||||
}
|
||||
|
||||
$cuValue = isset($values['CU']) ? $values['CU'] : null;
|
||||
$alValue = isset($values['AL']) ? $values['AL'] : null;
|
||||
$today = date('Y-m-d');
|
||||
|
||||
// Alle Lieferanten mit metallzuschlag_source != '' finden
|
||||
$sql = "SELECT fk_object, metallzuschlag_source";
|
||||
$sql .= " FROM ".$this->db->prefix()."societe_extrafields";
|
||||
$sql .= " WHERE metallzuschlag_source IS NOT NULL";
|
||||
$sql .= " AND metallzuschlag_source != ''";
|
||||
$sql .= " AND metallzuschlag_source != 'manuell'";
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
$sets = array();
|
||||
if ($cuValue !== null) {
|
||||
$sets[] = "metallzuschlag_cu = ".$cuValue;
|
||||
}
|
||||
if ($alValue !== null) {
|
||||
$sets[] = "metallzuschlag_al = ".$alValue;
|
||||
}
|
||||
$sets[] = "metallzuschlag_date = '".$this->db->escape($today)."'";
|
||||
|
||||
if (!empty($sets)) {
|
||||
$sqlUpdate = "UPDATE ".$this->db->prefix()."societe_extrafields";
|
||||
$sqlUpdate .= " SET ".implode(", ", $sets);
|
||||
$sqlUpdate .= " WHERE fk_object = ".((int)$obj->fk_object);
|
||||
|
||||
if ($this->db->query($sqlUpdate)) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktuelle Notierung aus DB holen
|
||||
*
|
||||
* @param string $metal Metall (CU/AL)
|
||||
* @param string $source Quelle
|
||||
* @return object|null Objekt mit value, value_month_avg, date_notiz oder null
|
||||
*/
|
||||
public function getLatest($metal = 'CU', $source = 'sonepar')
|
||||
{
|
||||
$sql = "SELECT date_notiz, metal, value, value_month_avg, source";
|
||||
$sql .= " FROM ".$this->db->prefix()."metallzuschlag_history";
|
||||
$sql .= " WHERE metal = '".$this->db->escape($metal)."'";
|
||||
$sql .= " AND source = '".$this->db->escape($source)."'";
|
||||
$sql .= " ORDER BY date_notiz DESC LIMIT 1";
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql && $this->db->num_rows($resql) > 0) {
|
||||
return $this->db->fetch_object($resql);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Historie aus DB holen
|
||||
*
|
||||
* @param string $source Quelle
|
||||
* @param int $limit Anzahl Eintraege
|
||||
* @return array Array von Objekten
|
||||
*/
|
||||
public function getHistory($source = 'sonepar', $limit = 30)
|
||||
{
|
||||
$results = array();
|
||||
|
||||
$sql = "SELECT date_notiz, metal, value, value_month_avg, source";
|
||||
$sql .= " FROM ".$this->db->prefix()."metallzuschlag_history";
|
||||
$sql .= " WHERE source = '".$this->db->escape($source)."'";
|
||||
$sql .= " ORDER BY date_notiz DESC, metal ASC";
|
||||
$sql .= " LIMIT ".((int)$limit);
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
$results[] = $obj;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cronjob: Kupferzuschlag auf allen Einkaufspreisen neu berechnen
|
||||
*
|
||||
* Fuer alle Produkte mit Kupfergehalt > 0 werden die Einkaufspreise aktualisiert.
|
||||
* CU-Notiz: Lieferant-eigener Wert (metallzuschlag_cu) oder aktuellster aus History.
|
||||
*
|
||||
* @return int 0 bei Erfolg, -1 bei Fehler
|
||||
*/
|
||||
public function recalcAllKupferzuschlag()
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$langs->load('metallzuschlag@metallzuschlag');
|
||||
|
||||
dol_syslog("MetallzuschlagApi::recalcAllKupferzuschlag - Start", LOG_INFO);
|
||||
|
||||
// Aktuellste CU-Notiz als Fallback
|
||||
$fallbackCU = 0;
|
||||
$latestCU = $this->getLatest('CU');
|
||||
if ($latestCU) {
|
||||
$fallbackCU = (float) $latestCU->value;
|
||||
}
|
||||
|
||||
if ($fallbackCU <= 0) {
|
||||
$this->error = 'Keine CU-Notierung vorhanden';
|
||||
dol_syslog("MetallzuschlagApi::recalcAllKupferzuschlag - ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Alle Produkte mit kupfergehalt > 0
|
||||
$sql = "SELECT pe.fk_object, pe.kupfergehalt";
|
||||
$sql .= " FROM ".$this->db->prefix()."product_extrafields pe";
|
||||
$sql .= " WHERE pe.kupfergehalt IS NOT NULL AND pe.kupfergehalt > 0";
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) {
|
||||
$this->error = 'DB-Fehler: '.$this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
|
||||
$productCount = 0;
|
||||
$priceCount = 0;
|
||||
|
||||
while ($product = $this->db->fetch_object($resql)) {
|
||||
$kupfergehalt = (float) $product->kupfergehalt;
|
||||
$productId = (int) $product->fk_object;
|
||||
|
||||
// Alle Einkaufspreise dieses Produkts
|
||||
$sqlPrices = "SELECT pf.rowid, pf.fk_soc";
|
||||
$sqlPrices .= " FROM ".$this->db->prefix()."product_fournisseur_price pf";
|
||||
$sqlPrices .= " WHERE pf.fk_product = ".$productId;
|
||||
|
||||
$resPrices = $this->db->query($sqlPrices);
|
||||
if (!$resPrices) {
|
||||
continue;
|
||||
}
|
||||
|
||||
while ($price = $this->db->fetch_object($resPrices)) {
|
||||
// CU-Notiz des Lieferanten oder Fallback
|
||||
$cuNotiz = $this->getCUForSupplier((int) $price->fk_soc, $fallbackCU);
|
||||
|
||||
if ($cuNotiz <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Kupferzuschlag EUR/m = Kupfergehalt (kg/km) × CU (EUR/100kg) / 100.000
|
||||
$kupferzuschlag = $kupfergehalt * $cuNotiz / 100000;
|
||||
|
||||
// UPDATE oder INSERT
|
||||
$sqlUpd = "UPDATE ".$this->db->prefix()."product_fournisseur_price_extrafields";
|
||||
$sqlUpd .= " SET kupferzuschlag = ".((float) $kupferzuschlag);
|
||||
$sqlUpd .= " WHERE fk_object = ".((int) $price->rowid);
|
||||
|
||||
$resUpd = $this->db->query($sqlUpd);
|
||||
if ($resUpd && $this->db->affected_rows($resUpd) > 0) {
|
||||
$priceCount++;
|
||||
} else {
|
||||
$sqlIns = "INSERT INTO ".$this->db->prefix()."product_fournisseur_price_extrafields";
|
||||
$sqlIns .= " (fk_object, kupferzuschlag) VALUES (".((int) $price->rowid).", ".((float) $kupferzuschlag).")";
|
||||
if ($this->db->query($sqlIns)) {
|
||||
$priceCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$productCount++;
|
||||
}
|
||||
|
||||
$this->output = $productCount.' Produkte, '.$priceCount.' Einkaufspreise aktualisiert (CU: '.$fallbackCU.' EUR/100kg)';
|
||||
dol_syslog("MetallzuschlagApi::recalcAllKupferzuschlag - ".$this->output, LOG_INFO);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* CU-Notiz fuer einen Lieferanten ermitteln
|
||||
*
|
||||
* @param int $socId Lieferanten-ID
|
||||
* @param float $fallbackCU Fallback-Wert aus History
|
||||
* @return float CU-Notiz in EUR/100kg
|
||||
*/
|
||||
public function getCUForSupplier($socId, $fallbackCU)
|
||||
{
|
||||
$sql = "SELECT metallzuschlag_cu";
|
||||
$sql .= " FROM ".$this->db->prefix()."societe_extrafields";
|
||||
$sql .= " WHERE fk_object = ".((int) $socId);
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql && $this->db->num_rows($resql) > 0) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if (!empty($obj->metallzuschlag_cu) && (float) $obj->metallzuschlag_cu > 0) {
|
||||
return (float) $obj->metallzuschlag_cu;
|
||||
}
|
||||
}
|
||||
|
||||
return $fallbackCU;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verlaufsdaten fuer Chart aufbereiten
|
||||
*
|
||||
* @param int $days Zeitraum in Tagen
|
||||
* @param string $source Quelle
|
||||
* @return array Array mit 'labels', 'cu', 'al' fuer Chart.js
|
||||
*/
|
||||
public function getChartData($days = 90, $source = 'sonepar')
|
||||
{
|
||||
$result = array(
|
||||
'labels' => array(),
|
||||
'cu' => array(),
|
||||
'al' => array(),
|
||||
);
|
||||
|
||||
$dateFrom = date('Y-m-d', strtotime('-'.$days.' days'));
|
||||
|
||||
// Alle Daten im Zeitraum holen, nach Datum sortiert
|
||||
$sql = "SELECT date_notiz, metal, value";
|
||||
$sql .= " FROM ".$this->db->prefix()."metallzuschlag_history";
|
||||
$sql .= " WHERE source = '".$this->db->escape($source)."'";
|
||||
$sql .= " AND date_notiz >= '".$this->db->escape($dateFrom)."'";
|
||||
$sql .= " ORDER BY date_notiz ASC, metal ASC";
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Daten nach Datum gruppieren
|
||||
$byDate = array();
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
$date = $obj->date_notiz;
|
||||
if (!isset($byDate[$date])) {
|
||||
$byDate[$date] = array('CU' => null, 'AL' => null);
|
||||
}
|
||||
$byDate[$date][$obj->metal] = (float) $obj->value;
|
||||
}
|
||||
|
||||
foreach ($byDate as $date => $values) {
|
||||
$result['labels'][] = $date;
|
||||
$result['cu'][] = $values['CU'];
|
||||
$result['al'][] = $values['AL'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
335
core/modules/modMetallzuschlag.class.php
Executable file
335
core/modules/modMetallzuschlag.class.php
Executable file
|
|
@ -0,0 +1,335 @@
|
|||
<?php
|
||||
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \defgroup metallzuschlag Module Metallzuschlag
|
||||
* \brief Metallnotierungen (Kupfer/Aluminium) von Großhändlern abrufen und verwalten
|
||||
*
|
||||
* \file htdocs/metallzuschlag/core/modules/modMetallzuschlag.class.php
|
||||
* \ingroup metallzuschlag
|
||||
*/
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
|
||||
|
||||
/**
|
||||
* Modul-Deskriptor fuer Metallzuschlag
|
||||
*/
|
||||
class modMetallzuschlag extends DolibarrModules
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
$this->db = $db;
|
||||
|
||||
$this->numero = 500027;
|
||||
$this->rights_class = 'metallzuschlag';
|
||||
$this->family = "products";
|
||||
$this->module_position = '90';
|
||||
$this->name = preg_replace('/^mod/i', '', get_class($this));
|
||||
$this->description = "MetallzuschlagDescription";
|
||||
$this->descriptionlong = "MetallzuschlagDescriptionLong";
|
||||
$this->editor_name = 'Alles Watt laeuft';
|
||||
$this->editor_url = '';
|
||||
$this->version = '1.0';
|
||||
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
|
||||
$this->picto = 'fa-coins';
|
||||
|
||||
$this->module_parts = array(
|
||||
'triggers' => 1,
|
||||
'login' => 0,
|
||||
'substitutions' => 0,
|
||||
'menus' => 0,
|
||||
'tpl' => 0,
|
||||
'barcode' => 0,
|
||||
'models' => 0,
|
||||
'printing' => 0,
|
||||
'theme' => 0,
|
||||
'css' => array(),
|
||||
'js' => array(),
|
||||
'hooks' => array(),
|
||||
'moduleforexternal' => 0,
|
||||
'websitetemplates' => 0,
|
||||
'captcha' => 0
|
||||
);
|
||||
|
||||
$this->dirs = array("/metallzuschlag/temp");
|
||||
$this->config_page_url = array("setup.php@metallzuschlag");
|
||||
|
||||
// Abhaengigkeiten
|
||||
$this->hidden = getDolGlobalInt('MODULE_METALLZUSCHLAG_DISABLED');
|
||||
$this->depends = array();
|
||||
$this->requiredby = array();
|
||||
$this->conflictwith = array();
|
||||
|
||||
$this->langfiles = array("metallzuschlag@metallzuschlag");
|
||||
|
||||
$this->phpmin = array(7, 1);
|
||||
$this->need_dolibarr_version = array(19, -3);
|
||||
$this->need_javascript_ajax = 0;
|
||||
|
||||
$this->warnings_activation = array();
|
||||
$this->warnings_activation_ext = array();
|
||||
|
||||
// Konstanten
|
||||
$this->const = array(
|
||||
0 => array('METALLZUSCHLAG_API_URL', 'chaine', 'https://www.sonepar.de/api/content/metalnote', 'Basis-URL fuer Metallnotiz-API', 1),
|
||||
1 => array('METALLZUSCHLAG_AUTO_FETCH', 'chaine', '1', 'Automatischer Abruf aktiviert', 1),
|
||||
);
|
||||
|
||||
if (!isModEnabled("metallzuschlag")) {
|
||||
$conf->metallzuschlag = new stdClass();
|
||||
$conf->metallzuschlag->enabled = 0;
|
||||
}
|
||||
|
||||
// Tabs
|
||||
$this->tabs = array();
|
||||
|
||||
// Dictionaries
|
||||
$this->dictionaries = array();
|
||||
|
||||
// Widgets
|
||||
$this->boxes = array();
|
||||
|
||||
// Cronjobs
|
||||
$this->cronjobs = array(
|
||||
// Metallnotierungen woechentlich abrufen
|
||||
0 => array(
|
||||
'label' => 'MetallzuschlagFetch',
|
||||
'jobtype' => 'method',
|
||||
'class' => '/metallzuschlag/class/metallzuschlagapi.class.php',
|
||||
'objectname' => 'MetallzuschlagApi',
|
||||
'method' => 'fetchMetalNotes',
|
||||
'parameters' => '',
|
||||
'comment' => 'Metallnotierungen (CU/AL) von Sonepar abrufen und in DB speichern',
|
||||
'frequency' => 1,
|
||||
'unitfrequency' => 604800,
|
||||
'status' => 0,
|
||||
'test' => 'isModEnabled("metallzuschlag") && getDolGlobalInt("METALLZUSCHLAG_AUTO_FETCH")',
|
||||
'priority' => 50,
|
||||
),
|
||||
// Kupferzuschlag auf allen Einkaufspreisen woechentlich neu berechnen
|
||||
1 => array(
|
||||
'label' => 'MetallzuschlagRecalcKupferzuschlag',
|
||||
'jobtype' => 'method',
|
||||
'class' => '/metallzuschlag/class/metallzuschlagapi.class.php',
|
||||
'objectname' => 'MetallzuschlagApi',
|
||||
'method' => 'recalcAllKupferzuschlag',
|
||||
'parameters' => '',
|
||||
'comment' => 'Kupferzuschlag (EUR/m) auf allen Einkaufspreisen mit Kupfergehalt neu berechnen',
|
||||
'frequency' => 1,
|
||||
'unitfrequency' => 604800,
|
||||
'status' => 0,
|
||||
'test' => 'isModEnabled("metallzuschlag")',
|
||||
'priority' => 60,
|
||||
),
|
||||
);
|
||||
|
||||
// Berechtigungen
|
||||
$this->rights = array();
|
||||
$r = 0;
|
||||
|
||||
$this->rights[$r][0] = $this->numero.'01';
|
||||
$this->rights[$r][1] = 'MetallzuschlagPermRead';
|
||||
$this->rights[$r][4] = 'read';
|
||||
$this->rights[$r][5] = '';
|
||||
$r++;
|
||||
|
||||
$this->rights[$r][0] = $this->numero.'02';
|
||||
$this->rights[$r][1] = 'MetallzuschlagPermConfig';
|
||||
$this->rights[$r][4] = 'config';
|
||||
$this->rights[$r][5] = '';
|
||||
$r++;
|
||||
|
||||
// Hauptmenue
|
||||
$this->menu = array();
|
||||
$r = 0;
|
||||
|
||||
$this->menu[$r++] = array(
|
||||
'fk_menu' => '',
|
||||
'type' => 'top',
|
||||
'titre' => 'ModuleMetallzuschlagName',
|
||||
'prefix' => img_picto('', $this->picto, 'class="pictofixedwidth valignmiddle"'),
|
||||
'mainmenu' => 'metallzuschlag',
|
||||
'leftmenu' => '',
|
||||
'url' => '/metallzuschlag/metallzuschlagindex.php',
|
||||
'langs' => 'metallzuschlag@metallzuschlag',
|
||||
'position' => 1000 + $r,
|
||||
'enabled' => 'isModEnabled("metallzuschlag")',
|
||||
'perms' => '$user->hasRight("metallzuschlag", "read")',
|
||||
'target' => '',
|
||||
'user' => 2,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modul aktivieren: Tabellen + Extrafields erstellen
|
||||
*
|
||||
* @param string $options Optionen
|
||||
* @return int 1 wenn OK, -1 bei Fehler
|
||||
*/
|
||||
public function init($options = '')
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
$result = $this->_load_tables('/metallzuschlag/sql/');
|
||||
if ($result < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Extrafields auf Lieferantenkarte (thirdparty) erstellen
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
||||
$extrafields = new ExtraFields($this->db);
|
||||
|
||||
// Separator
|
||||
$extrafields->addExtraField(
|
||||
'metallzuschlag_sep',
|
||||
'MetallzuschlagSeparator',
|
||||
'separator',
|
||||
200, 0,
|
||||
'thirdparty',
|
||||
0, 0, '', array('options' => array(1 => 1)),
|
||||
1, '', 1, 0, '', '',
|
||||
'metallzuschlag@metallzuschlag',
|
||||
'isModEnabled("metallzuschlag")'
|
||||
);
|
||||
|
||||
// Kupferzuschlag
|
||||
// Signatur: $attrname, $label, $type, $pos, $size, $elementtype,
|
||||
// $unique, $required, $default_value, $param,
|
||||
// $alwayseditable, $perms, $list, $help, $computed, $entity, $langfile, $enabled
|
||||
$extrafields->addExtraField(
|
||||
'metallzuschlag_cu',
|
||||
'MetallzuschlagCU',
|
||||
'price',
|
||||
201, '24,8',
|
||||
'thirdparty',
|
||||
0, 0, '', '',
|
||||
1, '', 1, 'MetallzuschlagCUHelp',
|
||||
'', '',
|
||||
'metallzuschlag@metallzuschlag',
|
||||
'isModEnabled("metallzuschlag")'
|
||||
);
|
||||
|
||||
// Aluminiumzuschlag
|
||||
$extrafields->addExtraField(
|
||||
'metallzuschlag_al',
|
||||
'MetallzuschlagAL',
|
||||
'price',
|
||||
202, '24,8',
|
||||
'thirdparty',
|
||||
0, 0, '', '',
|
||||
1, '', 1, 'MetallzuschlagALHelp',
|
||||
'', '',
|
||||
'metallzuschlag@metallzuschlag',
|
||||
'isModEnabled("metallzuschlag")'
|
||||
);
|
||||
|
||||
// Datum der letzten Aktualisierung
|
||||
$extrafields->addExtraField(
|
||||
'metallzuschlag_date',
|
||||
'MetallzuschlagDate',
|
||||
'date',
|
||||
203, 0,
|
||||
'thirdparty',
|
||||
0, 0, '', '',
|
||||
1, '', 1, '',
|
||||
'', '',
|
||||
'metallzuschlag@metallzuschlag',
|
||||
'isModEnabled("metallzuschlag")'
|
||||
);
|
||||
|
||||
// Quelle
|
||||
$extrafields->addExtraField(
|
||||
'metallzuschlag_source',
|
||||
'MetallzuschlagSource',
|
||||
'select',
|
||||
204, 0,
|
||||
'thirdparty',
|
||||
0, 0, '',
|
||||
array('options' => array('sonepar' => 'Sonepar', 'kluxen' => 'Kluxen', 'manuell' => 'Manuell')),
|
||||
1, '', 1, '',
|
||||
'', '',
|
||||
'metallzuschlag@metallzuschlag',
|
||||
'isModEnabled("metallzuschlag")'
|
||||
);
|
||||
|
||||
// Extrafields auf Produkten fuer Kupferberechnung
|
||||
// Aderanzahl
|
||||
$extrafields->addExtraField(
|
||||
'aderanzahl',
|
||||
'Aderanzahl',
|
||||
'int',
|
||||
126, 11,
|
||||
'product',
|
||||
0, 0, '', '',
|
||||
1, '', 1, 'AderanzahlHelp',
|
||||
'', '',
|
||||
'metallzuschlag@metallzuschlag',
|
||||
'isModEnabled("metallzuschlag")'
|
||||
);
|
||||
|
||||
// Querschnitt (mm²)
|
||||
$extrafields->addExtraField(
|
||||
'querschnitt',
|
||||
'Querschnitt',
|
||||
'double',
|
||||
127, '10,2',
|
||||
'product',
|
||||
0, 0, '', '',
|
||||
1, '', 1, 'QuerschnittHelp',
|
||||
'', '',
|
||||
'metallzuschlag@metallzuschlag',
|
||||
'isModEnabled("metallzuschlag")'
|
||||
);
|
||||
|
||||
// Kupfergehalt (kg/km) - wird per Trigger berechnet
|
||||
$extrafields->addExtraField(
|
||||
'kupfergehalt',
|
||||
'Kupfergehalt',
|
||||
'double',
|
||||
128, '24,8',
|
||||
'product',
|
||||
0, 0, '', '',
|
||||
1, '', 1, 'KupfergehaltHelp',
|
||||
'', '',
|
||||
'metallzuschlag@metallzuschlag',
|
||||
'isModEnabled("metallzuschlag")'
|
||||
);
|
||||
|
||||
$this->remove($options);
|
||||
|
||||
$sql = array();
|
||||
return $this->_init($sql, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modul deaktivieren
|
||||
*
|
||||
* @param string $options Optionen
|
||||
* @return int 1 wenn OK, -1 bei Fehler
|
||||
*/
|
||||
public function remove($options = '')
|
||||
{
|
||||
$sql = array();
|
||||
return $this->_remove($sql, $options);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,235 @@
|
|||
<?php
|
||||
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file core/triggers/interface_99_modMetallzuschlag_MetallzuschlagTriggers.class.php
|
||||
* \ingroup metallzuschlag
|
||||
* \brief Trigger: Kupfergehalt + Kupferzuschlag berechnen
|
||||
*/
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
|
||||
|
||||
/**
|
||||
* Trigger fuer automatische Kupfergehalt- und Kupferzuschlag-Berechnung
|
||||
*/
|
||||
class InterfaceMetallzuschlagTriggers extends DolibarrTriggers
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->name = preg_replace('/^Interface/i', '', get_class($this));
|
||||
$this->family = 'products';
|
||||
$this->description = "Berechnet Kupfergehalt und Kupferzuschlag auf Einkaufspreisen";
|
||||
$this->version = '1.1';
|
||||
$this->picto = 'fa-coins';
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger-Funktion
|
||||
*
|
||||
* @param string $action Trigger-Aktion
|
||||
* @param Object $object Betroffenes Objekt
|
||||
* @param User $user Ausloesender User
|
||||
* @param Translate $langs Sprach-Objekt
|
||||
* @param Conf $conf Konfiguration
|
||||
* @return int 0 = OK, <0 = Fehler
|
||||
*/
|
||||
public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
|
||||
{
|
||||
if (!isModEnabled('metallzuschlag')) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Produkt erstellt oder geaendert → Kupfergehalt + Kupferzuschlag berechnen
|
||||
if ($action === 'PRODUCT_CREATE' || $action === 'PRODUCT_MODIFY') {
|
||||
$kupfergehalt = $this->calculateKupfergehalt($object);
|
||||
if ($kupfergehalt > 0) {
|
||||
$this->updateKupferzuschlagForProduct($object->id, $kupfergehalt);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Berechnet Kupfergehalt aus Aderanzahl und Querschnitt
|
||||
*
|
||||
* Formel: kupfergehalt (kg/km) = aderanzahl × querschnitt (mm²) × 8,89
|
||||
*
|
||||
* @param Product $object Produkt-Objekt
|
||||
* @return float Berechneter Kupfergehalt (0 wenn nicht berechenbar)
|
||||
*/
|
||||
private function calculateKupfergehalt($object)
|
||||
{
|
||||
if (empty($object->array_options)) {
|
||||
$object->fetch_optionals();
|
||||
}
|
||||
|
||||
$aderanzahl = !empty($object->array_options['options_aderanzahl']) ? (int) $object->array_options['options_aderanzahl'] : 0;
|
||||
$querschnitt = !empty($object->array_options['options_querschnitt']) ? (float) $object->array_options['options_querschnitt'] : 0;
|
||||
|
||||
if ($aderanzahl <= 0 || $querschnitt <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Kupfergewicht: Aderanzahl × Querschnitt (mm²) × 8,89 kg/(km·mm²)
|
||||
$kupfergehalt = $aderanzahl * $querschnitt * 8.89;
|
||||
|
||||
// In Produkt-Extrafield speichern
|
||||
$currentValue = !empty($object->array_options['options_kupfergehalt']) ? (float) $object->array_options['options_kupfergehalt'] : 0;
|
||||
|
||||
if (round($currentValue, 4) !== round($kupfergehalt, 4)) {
|
||||
$sql = "UPDATE ".$this->db->prefix()."product_extrafields";
|
||||
$sql .= " SET kupfergehalt = ".((float) $kupfergehalt);
|
||||
$sql .= " WHERE fk_object = ".((int) $object->id);
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql && $this->db->affected_rows($resql) == 0) {
|
||||
$sql2 = "INSERT INTO ".$this->db->prefix()."product_extrafields";
|
||||
$sql2 .= " (fk_object, kupfergehalt) VALUES (".((int) $object->id).", ".((float) $kupfergehalt).")";
|
||||
$this->db->query($sql2);
|
||||
}
|
||||
|
||||
dol_syslog("Metallzuschlag: Kupfergehalt Produkt #".$object->id.": ".$aderanzahl." × ".$querschnitt." × 8,89 = ".round($kupfergehalt, 4)." kg/km", LOG_INFO);
|
||||
}
|
||||
|
||||
return $kupfergehalt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kupferzuschlag auf allen Einkaufspreisen eines Produkts berechnen
|
||||
*
|
||||
* Logik fuer CU-Notiz:
|
||||
* 1. Lieferant hat eigenen Metallzuschlag (metallzuschlag_cu) → diesen nehmen
|
||||
* 2. Sonst: aktuellsten verfuegbaren Wert aus metallzuschlag_history
|
||||
*
|
||||
* Formel: kupferzuschlag (EUR/m) = kupfergehalt (kg/km) × CU-Notiz (EUR/100kg) / 100.000
|
||||
*
|
||||
* @param int $productId Produkt-ID
|
||||
* @param float $kupfergehalt Kupfergehalt in kg/km
|
||||
* @return int Anzahl aktualisierter Einkaufspreise
|
||||
*/
|
||||
private function updateKupferzuschlagForProduct($productId, $kupfergehalt)
|
||||
{
|
||||
// Alle Einkaufspreise des Produkts holen
|
||||
$sql = "SELECT pf.rowid, pf.fk_soc";
|
||||
$sql .= " FROM ".$this->db->prefix()."product_fournisseur_price pf";
|
||||
$sql .= " WHERE pf.fk_product = ".((int) $productId);
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Aktuellste CU-Notiz aus History als Fallback vorhalten
|
||||
$fallbackCU = $this->getLatestCUFromHistory();
|
||||
|
||||
$count = 0;
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
// CU-Notiz fuer diesen Lieferanten bestimmen
|
||||
$cuNotiz = $this->getCUForSupplier((int) $obj->fk_soc, $fallbackCU);
|
||||
|
||||
if ($cuNotiz <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Kupferzuschlag EUR/m = Kupfergehalt (kg/km) × CU (EUR/100kg) / 100.000
|
||||
$kupferzuschlag = $kupfergehalt * $cuNotiz / 100000;
|
||||
|
||||
// In Einkaufspreis-Extrafield schreiben
|
||||
if ($this->saveKupferzuschlag((int) $obj->rowid, $kupferzuschlag)) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($count > 0) {
|
||||
dol_syslog("Metallzuschlag: Kupferzuschlag fuer ".$count." Einkaufspreise von Produkt #".$productId." aktualisiert", LOG_INFO);
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* CU-Notiz fuer einen Lieferanten ermitteln
|
||||
*
|
||||
* @param int $socId Lieferanten-ID
|
||||
* @param float $fallbackCU Fallback-Wert aus History
|
||||
* @return float CU-Notiz in EUR/100kg
|
||||
*/
|
||||
private function getCUForSupplier($socId, $fallbackCU)
|
||||
{
|
||||
// Lieferant hat eigenen Wert?
|
||||
$sql = "SELECT metallzuschlag_cu, metallzuschlag_source";
|
||||
$sql .= " FROM ".$this->db->prefix()."societe_extrafields";
|
||||
$sql .= " WHERE fk_object = ".((int) $socId);
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql && $this->db->num_rows($resql) > 0) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if (!empty($obj->metallzuschlag_cu) && (float) $obj->metallzuschlag_cu > 0) {
|
||||
return (float) $obj->metallzuschlag_cu;
|
||||
}
|
||||
}
|
||||
|
||||
// Kein eigener Wert → Fallback
|
||||
return $fallbackCU;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktuellste CU-Notiz aus der History-Tabelle holen
|
||||
*
|
||||
* @return float CU-Notiz in EUR/100kg (0 wenn nichts vorhanden)
|
||||
*/
|
||||
private function getLatestCUFromHistory()
|
||||
{
|
||||
$sql = "SELECT value FROM ".$this->db->prefix()."metallzuschlag_history";
|
||||
$sql .= " WHERE metal = 'CU'";
|
||||
$sql .= " ORDER BY date_notiz DESC LIMIT 1";
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql && $this->db->num_rows($resql) > 0) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
return (float) $obj->value;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kupferzuschlag in Einkaufspreis-Extrafield speichern
|
||||
*
|
||||
* @param int $priceId Einkaufspreis-ID (rowid)
|
||||
* @param float $kupferzuschlag Wert in EUR/m
|
||||
* @return bool true wenn gespeichert
|
||||
*/
|
||||
private function saveKupferzuschlag($priceId, $kupferzuschlag)
|
||||
{
|
||||
// UPDATE versuchen
|
||||
$sql = "UPDATE ".$this->db->prefix()."product_fournisseur_price_extrafields";
|
||||
$sql .= " SET kupferzuschlag = ".((float) $kupferzuschlag);
|
||||
$sql .= " WHERE fk_object = ".((int) $priceId);
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql && $this->db->affected_rows($resql) > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Zeile existiert nicht → INSERT
|
||||
$sql2 = "INSERT INTO ".$this->db->prefix()."product_fournisseur_price_extrafields";
|
||||
$sql2 .= " (fk_object, kupferzuschlag) VALUES (".((int) $priceId).", ".((float) $kupferzuschlag).")";
|
||||
|
||||
return (bool) $this->db->query($sql2);
|
||||
}
|
||||
}
|
||||
14
img/README.md
Executable file
14
img/README.md
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
Directory for module image files
|
||||
--------------------------------
|
||||
|
||||
You can put here the .png files of your module:
|
||||
|
||||
|
||||
If the picto of your module is an image (property $picto has been set to 'metallzuschlag.png@metallzuschlag', you can put into this
|
||||
directory a .png file called *object_metallzuschlag.png* (16x16 or 32x32 pixels)
|
||||
|
||||
|
||||
If the picto of an object is an image (property $picto of the object.class.php has been set to 'myobject.png@metallzuschlag', then you can put into this
|
||||
directory a .png file called *object_myobject.png* (16x16 or 32x32 pixels)
|
||||
|
||||
82
langs/de_DE/metallzuschlag.lang
Normal file
82
langs/de_DE/metallzuschlag.lang
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
# Copyright (C) 2026 Eduard Wisch
|
||||
#
|
||||
# Metallzuschlag Modul - Deutsche Sprachdatei
|
||||
#
|
||||
|
||||
# Modul
|
||||
ModuleMetallzuschlagName = Metallzuschlag
|
||||
ModuleMetallzuschlagDesc = Metallnotierungen (Kupfer/Aluminium) von Großhändlern abrufen
|
||||
MetallzuschlagDescription = Metallnotierungen von Großhändlern abrufen und verwalten
|
||||
MetallzuschlagDescriptionLong = Ruft aktuelle Metallzuschläge (Kupfer, Aluminium) von Großhändler-APIs ab und stellt sie zentral in Dolibarr bereit. Unterstützt automatische Aktualisierung per Cronjob.
|
||||
|
||||
# Berechtigungen
|
||||
MetallzuschlagPermRead = Metallzuschläge ansehen
|
||||
MetallzuschlagPermConfig = Metallzuschlag konfigurieren
|
||||
|
||||
# Bereiche
|
||||
MetallzuschlagArea = Metallzuschlag
|
||||
MetallzuschlagSetup = Metallzuschlag Einrichtung
|
||||
MetallzuschlagSetupPage = Metallzuschlag Konfiguration
|
||||
MetallzuschlagAbout = Über Metallzuschlag
|
||||
|
||||
# Dashboard
|
||||
MetallzuschlagDashboard = Metallzuschlag Übersicht
|
||||
MetallzuschlagCurrentValues = Aktuelle Notierungen
|
||||
MetallzuschlagHistory = Verlauf
|
||||
MetallzuschlagNoData = Noch keine Daten vorhanden. Bitte zuerst Notierungen abrufen.
|
||||
MetallzuschlagFetchNow = Jetzt abrufen
|
||||
MetallzuschlagFetchSuccess = Metallnotierungen erfolgreich abgerufen
|
||||
MetallzuschlagFetchError = Fehler beim Abruf der Metallnotierungen
|
||||
MetallzuschlagLastUpdate = Letzte Aktualisierung
|
||||
|
||||
# Metalle
|
||||
MetallzuschlagCU = Kupferzuschlag (€/100kg)
|
||||
MetallzuschlagAL = Aluminiumzuschlag (€/100kg)
|
||||
MetallzuschlagCUHelp = Aktueller Kupferzuschlag in EUR pro 100kg (DEL-Notiz)
|
||||
MetallzuschlagALHelp = Aktueller Aluminiumzuschlag in EUR pro 100kg
|
||||
MetallzuschlagCUShort = Kupfer (CU)
|
||||
MetallzuschlagALShort = Aluminium (AL)
|
||||
|
||||
# Extrafields
|
||||
MetallzuschlagSeparator = Metallzuschlag
|
||||
MetallzuschlagDate = Notierung vom
|
||||
MetallzuschlagSource = Quelle
|
||||
MetallzuschlagSourceHelp = Quelle der Metallnotierung
|
||||
|
||||
# Tabelle
|
||||
MetallzuschlagDate = Datum
|
||||
MetallzuschlagMetal = Metall
|
||||
MetallzuschlagValue = Tageswert
|
||||
MetallzuschlagMonthAvg = Ø Vormonat
|
||||
MetallzuschlagSourceCol = Quelle
|
||||
MetallzuschlagUnit = €/100kg
|
||||
|
||||
# Setup
|
||||
MetallzuschlagApiUrl = API Basis-URL
|
||||
MetallzuschlagApiUrlHelp = Basis-URL der Metallnotiz-API (z.B. Sonepar)
|
||||
MetallzuschlagAutoFetch = Automatischer Abruf
|
||||
MetallzuschlagAutoFetchHelp = Metallnotierungen automatisch per Cronjob abrufen
|
||||
MetallzuschlagSupplierMapping = Lieferanten-Zuordnung
|
||||
MetallzuschlagSupplierMappingHelp = Welche Lieferanten sollen automatisch aktualisiert werden
|
||||
|
||||
# Lieferanten
|
||||
MetallzuschlagSuppliers = Lieferanten mit Metallzuschlag
|
||||
MetallzuschlagNoSuppliers = Keine Lieferanten mit Metallzuschlag-Quelle konfiguriert
|
||||
MetallzuschlagUpdatedSuppliers = %s Lieferant(en) aktualisiert
|
||||
|
||||
# Produkt-Extrafields
|
||||
Aderanzahl = Aderanzahl
|
||||
AderanzahlHelp = Anzahl der Kupfer-Adern im Kabel
|
||||
Querschnitt = Querschnitt (mm²)
|
||||
QuerschnittHelp = Leiterquerschnitt in mm²
|
||||
Kupfergehalt = Kupfergehalt (kg/km)
|
||||
KupfergehaltHelp = Kupfergewicht in kg pro km Kabel (Aderanzahl × Querschnitt × 8,89)
|
||||
MetallzuschlagKupfergehaltCalc = Kupfergehalt wird automatisch berechnet: Aderanzahl × Querschnitt × 8,89 kg/(km·mm²)
|
||||
|
||||
# Diagramm
|
||||
MetallzuschlagChart = Notierungsverlauf
|
||||
MetallzuschlagChartCU = Kupfer (CU) €/100kg
|
||||
MetallzuschlagChartAL = Aluminium (AL) €/100kg
|
||||
MetallzuschlagLast30Days = Letzte 30 Tage
|
||||
MetallzuschlagLast90Days = Letzte 90 Tage
|
||||
MetallzuschlagLast365Days = Letzte 365 Tage
|
||||
81
langs/en_US/metallzuschlag.lang
Executable file
81
langs/en_US/metallzuschlag.lang
Executable file
|
|
@ -0,0 +1,81 @@
|
|||
# Copyright (C) 2026 Eduard Wisch
|
||||
#
|
||||
# Metallzuschlag Module - English language file
|
||||
#
|
||||
|
||||
# Module
|
||||
ModuleMetallzuschlagName = Metal Surcharge
|
||||
ModuleMetallzuschlagDesc = Fetch metal surcharges (copper/aluminum) from wholesalers
|
||||
MetallzuschlagDescription = Fetch and manage metal surcharges from wholesalers
|
||||
MetallzuschlagDescriptionLong = Fetches current metal surcharges (copper, aluminum) from wholesaler APIs and provides them centrally in Dolibarr. Supports automatic updates via cron job.
|
||||
|
||||
# Permissions
|
||||
MetallzuschlagPermRead = View metal surcharges
|
||||
MetallzuschlagPermConfig = Configure metal surcharges
|
||||
|
||||
# Areas
|
||||
MetallzuschlagArea = Metal Surcharge
|
||||
MetallzuschlagSetup = Metal Surcharge Setup
|
||||
MetallzuschlagSetupPage = Metal Surcharge Configuration
|
||||
MetallzuschlagAbout = About Metal Surcharge
|
||||
|
||||
# Dashboard
|
||||
MetallzuschlagDashboard = Metal Surcharge Overview
|
||||
MetallzuschlagCurrentValues = Current Rates
|
||||
MetallzuschlagHistory = History
|
||||
MetallzuschlagNoData = No data available yet. Please fetch rates first.
|
||||
MetallzuschlagFetchNow = Fetch now
|
||||
MetallzuschlagFetchSuccess = Metal rates fetched successfully
|
||||
MetallzuschlagFetchError = Error fetching metal rates
|
||||
MetallzuschlagLastUpdate = Last update
|
||||
|
||||
# Metals
|
||||
MetallzuschlagCU = Copper surcharge (€/100kg)
|
||||
MetallzuschlagAL = Aluminum surcharge (€/100kg)
|
||||
MetallzuschlagCUHelp = Current copper surcharge in EUR per 100kg (DEL notation)
|
||||
MetallzuschlagALHelp = Current aluminum surcharge in EUR per 100kg
|
||||
MetallzuschlagCUShort = Copper (CU)
|
||||
MetallzuschlagALShort = Aluminum (AL)
|
||||
|
||||
# Extrafields
|
||||
MetallzuschlagSeparator = Metal Surcharge
|
||||
MetallzuschlagDate = Rate date
|
||||
MetallzuschlagSource = Source
|
||||
MetallzuschlagSourceHelp = Source of the metal rate
|
||||
|
||||
# Table
|
||||
MetallzuschlagMetal = Metal
|
||||
MetallzuschlagValue = Daily rate
|
||||
MetallzuschlagMonthAvg = Avg. prev. month
|
||||
MetallzuschlagSourceCol = Source
|
||||
MetallzuschlagUnit = €/100kg
|
||||
|
||||
# Setup
|
||||
MetallzuschlagApiUrl = API Base URL
|
||||
MetallzuschlagApiUrlHelp = Base URL for the metal rate API (e.g. Sonepar)
|
||||
MetallzuschlagAutoFetch = Automatic fetch
|
||||
MetallzuschlagAutoFetchHelp = Automatically fetch metal rates via cron job
|
||||
MetallzuschlagSupplierMapping = Supplier mapping
|
||||
MetallzuschlagSupplierMappingHelp = Which suppliers should be updated automatically
|
||||
|
||||
# Suppliers
|
||||
MetallzuschlagSuppliers = Suppliers with metal surcharge
|
||||
MetallzuschlagNoSuppliers = No suppliers configured with metal surcharge source
|
||||
MetallzuschlagUpdatedSuppliers = %s supplier(s) updated
|
||||
|
||||
# Product extrafields
|
||||
Aderanzahl = Number of conductors
|
||||
AderanzahlHelp = Number of copper conductors in the cable
|
||||
Querschnitt = Cross-section (mm²)
|
||||
QuerschnittHelp = Conductor cross-section in mm²
|
||||
Kupfergehalt = Copper content (kg/km)
|
||||
KupfergehaltHelp = Copper weight in kg per km cable (conductors × cross-section × 8.89)
|
||||
MetallzuschlagKupfergehaltCalc = Copper content is calculated automatically: conductors × cross-section × 8.89 kg/(km·mm²)
|
||||
|
||||
# Chart
|
||||
MetallzuschlagChart = Rate history chart
|
||||
MetallzuschlagChartCU = Copper (CU) €/100kg
|
||||
MetallzuschlagChartAL = Aluminum (AL) €/100kg
|
||||
MetallzuschlagLast30Days = Last 30 days
|
||||
MetallzuschlagLast90Days = Last 90 days
|
||||
MetallzuschlagLast365Days = Last 365 days
|
||||
73
lib/metallzuschlag.lib.php
Executable file
73
lib/metallzuschlag.lib.php
Executable file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file metallzuschlag/lib/metallzuschlag.lib.php
|
||||
* \ingroup metallzuschlag
|
||||
* \brief Hilfsfunktionen fuer Metallzuschlag-Modul
|
||||
*/
|
||||
|
||||
/**
|
||||
* Admin-Navigation vorbereiten
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function metallzuschlagAdminPrepareHead()
|
||||
{
|
||||
global $langs, $conf;
|
||||
|
||||
$langs->load("metallzuschlag@metallzuschlag");
|
||||
|
||||
$h = 0;
|
||||
$head = array();
|
||||
|
||||
$head[$h][0] = dol_buildpath("/metallzuschlag/admin/setup.php", 1);
|
||||
$head[$h][1] = $langs->trans("Settings");
|
||||
$head[$h][2] = 'settings';
|
||||
$h++;
|
||||
|
||||
$head[$h][0] = dol_buildpath("/metallzuschlag/admin/about.php", 1);
|
||||
$head[$h][1] = $langs->trans("About");
|
||||
$head[$h][2] = 'about';
|
||||
$h++;
|
||||
|
||||
complete_head_from_modules($conf, $langs, null, $head, $h, 'metallzuschlag@metallzuschlag');
|
||||
complete_head_from_modules($conf, $langs, null, $head, $h, 'metallzuschlag@metallzuschlag', 'remove');
|
||||
|
||||
return $head;
|
||||
}
|
||||
|
||||
/**
|
||||
* Metallname fuer Anzeige
|
||||
*
|
||||
* @param string $metal Metall-Kuerzel (CU/AL)
|
||||
* @return string Anzeigename
|
||||
*/
|
||||
function metallzuschlagGetMetalLabel($metal)
|
||||
{
|
||||
$labels = array(
|
||||
'CU' => 'Kupfer (CU)',
|
||||
'AL' => 'Aluminium (AL)',
|
||||
);
|
||||
return isset($labels[$metal]) ? $labels[$metal] : $metal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wert als Preis formatieren
|
||||
*
|
||||
* @param float $value Wert
|
||||
* @return string Formatierter Preis mit Einheit
|
||||
*/
|
||||
function metallzuschlagFormatPrice($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return '-';
|
||||
}
|
||||
return price($value, 0, '', 1, -1, 2).' €/100kg';
|
||||
}
|
||||
320
metallzuschlagindex.php
Executable file
320
metallzuschlagindex.php
Executable file
|
|
@ -0,0 +1,320 @@
|
|||
<?php
|
||||
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file metallzuschlag/metallzuschlagindex.php
|
||||
* \ingroup metallzuschlag
|
||||
* \brief Metallzuschlag Dashboard - Aktuelle Notierungen und Verlauf
|
||||
*/
|
||||
|
||||
// Dolibarr Umgebung laden
|
||||
$res = 0;
|
||||
if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
|
||||
$res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
|
||||
}
|
||||
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
|
||||
$tmp2 = realpath(__FILE__);
|
||||
$i = strlen($tmp) - 1;
|
||||
$j = strlen($tmp2) - 1;
|
||||
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
|
||||
$i--;
|
||||
$j--;
|
||||
}
|
||||
if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
|
||||
$res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
|
||||
}
|
||||
if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
|
||||
$res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
|
||||
}
|
||||
if (!$res && file_exists("../main.inc.php")) {
|
||||
$res = @include "../main.inc.php";
|
||||
}
|
||||
if (!$res && file_exists("../../main.inc.php")) {
|
||||
$res = @include "../../main.inc.php";
|
||||
}
|
||||
if (!$res && file_exists("../../../main.inc.php")) {
|
||||
$res = @include "../../../main.inc.php";
|
||||
}
|
||||
if (!$res) {
|
||||
die("Include of main fails");
|
||||
}
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
|
||||
require_once './class/metallzuschlagapi.class.php';
|
||||
require_once './lib/metallzuschlag.lib.php';
|
||||
|
||||
/**
|
||||
* @var Conf $conf
|
||||
* @var DoliDB $db
|
||||
* @var HookManager $hookmanager
|
||||
* @var Translate $langs
|
||||
* @var User $user
|
||||
*/
|
||||
|
||||
$langs->loadLangs(array("metallzuschlag@metallzuschlag"));
|
||||
|
||||
$action = GETPOST('action', 'aZ09');
|
||||
|
||||
// Zugriffskontrolle
|
||||
if (!$user->hasRight('metallzuschlag', 'read')) {
|
||||
accessforbidden();
|
||||
}
|
||||
|
||||
$api = new MetallzuschlagApi($db);
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
// Manueller Abruf
|
||||
if ($action == 'fetch' && $user->hasRight('metallzuschlag', 'config')) {
|
||||
if (!verifCond(GETPOST('token', 'alpha') == newToken())) {
|
||||
accessforbidden('Bad CSRF token');
|
||||
}
|
||||
|
||||
$result = $api->fetchMetalNotes();
|
||||
if ($result >= 0) {
|
||||
setEventMessages($langs->trans("MetallzuschlagFetchSuccess"), null, 'mesgs');
|
||||
if (!empty($api->output)) {
|
||||
setEventMessages($api->output, null, 'mesgs');
|
||||
}
|
||||
} else {
|
||||
setEventMessages($langs->trans("MetallzuschlagFetchError"), null, 'errors');
|
||||
if (!empty($api->error)) {
|
||||
setEventMessages($api->error, null, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
header("Location: ".$_SERVER["PHP_SELF"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
llxHeader("", $langs->trans("MetallzuschlagDashboard"), '', '', 0, 0, '', '', '', 'mod-metallzuschlag page-index');
|
||||
|
||||
print load_fiche_titre($langs->trans("MetallzuschlagDashboard"), '', 'fa-coins');
|
||||
|
||||
// Aktuelle Werte abrufen
|
||||
$latestCU = $api->getLatest('CU');
|
||||
$latestAL = $api->getLatest('AL');
|
||||
|
||||
// Info-Panels: Aktuelle Notierungen
|
||||
print '<div class="fichecenter">';
|
||||
|
||||
if ($latestCU || $latestAL) {
|
||||
print '<div class="fichethirdleft">';
|
||||
|
||||
// Kupfer
|
||||
print '<div class="info-box">';
|
||||
print '<div class="info-box-icon bg-infobox-action">';
|
||||
print img_picto('', 'fa-coins', 'class="fa-2x"');
|
||||
print '</div>';
|
||||
print '<div class="info-box-content">';
|
||||
print '<span class="info-box-title">'.$langs->trans("MetallzuschlagCUShort").'</span><br>';
|
||||
if ($latestCU) {
|
||||
print '<span class="info-box-number">'.price($latestCU->value, 0, '', 1, -1, 2).' <small>€/100kg</small></span><br>';
|
||||
if (!empty($latestCU->value_month_avg)) {
|
||||
print '<span class="opacitymedium">'.$langs->trans("MetallzuschlagMonthAvg").': '.price($latestCU->value_month_avg, 0, '', 1, -1, 2).' €/100kg</span><br>';
|
||||
}
|
||||
print '<span class="opacitymedium">'.dol_print_date($db->jdate($latestCU->date_notiz), 'day').'</span>';
|
||||
} else {
|
||||
print '<span class="opacitymedium">-</span>';
|
||||
}
|
||||
print '</div>';
|
||||
print '</div>';
|
||||
|
||||
print '</div>';
|
||||
print '<div class="fichethirdleft">';
|
||||
|
||||
// Aluminium
|
||||
print '<div class="info-box">';
|
||||
print '<div class="info-box-icon bg-infobox-project">';
|
||||
print img_picto('', 'fa-coins', 'class="fa-2x"');
|
||||
print '</div>';
|
||||
print '<div class="info-box-content">';
|
||||
print '<span class="info-box-title">'.$langs->trans("MetallzuschlagALShort").'</span><br>';
|
||||
if ($latestAL) {
|
||||
print '<span class="info-box-number">'.price($latestAL->value, 0, '', 1, -1, 2).' <small>€/100kg</small></span><br>';
|
||||
if (!empty($latestAL->value_month_avg)) {
|
||||
print '<span class="opacitymedium">'.$langs->trans("MetallzuschlagMonthAvg").': '.price($latestAL->value_month_avg, 0, '', 1, -1, 2).' €/100kg</span><br>';
|
||||
}
|
||||
print '<span class="opacitymedium">'.dol_print_date($db->jdate($latestAL->date_notiz), 'day').'</span>';
|
||||
} else {
|
||||
print '<span class="opacitymedium">-</span>';
|
||||
}
|
||||
print '</div>';
|
||||
print '</div>';
|
||||
|
||||
print '</div>';
|
||||
print '<div class="fichethirdleft">';
|
||||
|
||||
// Button: Jetzt abrufen
|
||||
if ($user->hasRight('metallzuschlag', 'config')) {
|
||||
print '<div class="info-box">';
|
||||
print '<div class="info-box-content" style="padding: 15px;">';
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=fetch&token='.newToken().'">';
|
||||
print img_picto('', 'fa-sync', 'class="paddingright"');
|
||||
print $langs->trans("MetallzuschlagFetchNow");
|
||||
print '</a>';
|
||||
if ($latestCU) {
|
||||
print '<br><br><span class="opacitymedium">'.$langs->trans("MetallzuschlagLastUpdate").': '.dol_print_date($db->jdate($latestCU->date_notiz), 'day').'</span>';
|
||||
}
|
||||
print '</div>';
|
||||
print '</div>';
|
||||
}
|
||||
|
||||
print '</div>';
|
||||
} else {
|
||||
// Keine Daten vorhanden
|
||||
print '<div class="opacitymedium">'.$langs->trans("MetallzuschlagNoData").'</div>';
|
||||
print '<br>';
|
||||
if ($user->hasRight('metallzuschlag', 'config')) {
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=fetch&token='.newToken().'">';
|
||||
print img_picto('', 'fa-sync', 'class="paddingright"');
|
||||
print $langs->trans("MetallzuschlagFetchNow");
|
||||
print '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
print '</div>';
|
||||
print '<div class="clearboth"></div>';
|
||||
|
||||
// Diagramm: Notierungsverlauf
|
||||
$chartDays = GETPOSTINT('chart_days') ?: 90;
|
||||
$chartData = $api->getChartData($chartDays);
|
||||
|
||||
if (!empty($chartData['labels'])) {
|
||||
print '<br>';
|
||||
|
||||
// Zeitraum-Auswahl
|
||||
$chartButtons = '';
|
||||
foreach (array(30, 90, 365) as $d) {
|
||||
$active = ($chartDays == $d) ? ' butActionActive' : '';
|
||||
$label = $langs->trans('MetallzuschlagLast'.$d.'Days');
|
||||
$chartButtons .= '<a class="butAction'.$active.' small" href="'.$_SERVER["PHP_SELF"].'?chart_days='.$d.'">'.$label.'</a> ';
|
||||
}
|
||||
|
||||
print load_fiche_titre($langs->trans("MetallzuschlagChart"), $chartButtons, '');
|
||||
|
||||
print '<div style="max-width: 100%; height: 400px;">';
|
||||
print '<canvas id="metallzuschlagChart"></canvas>';
|
||||
print '</div>';
|
||||
|
||||
// Chart.js-Daten vorbereiten
|
||||
$jsLabels = json_encode($chartData['labels']);
|
||||
$jsCU = json_encode($chartData['cu']);
|
||||
$jsAL = json_encode($chartData['al']);
|
||||
$labelCU = $langs->trans("MetallzuschlagChartCU");
|
||||
$labelAL = $langs->trans("MetallzuschlagChartAL");
|
||||
|
||||
print '<script src="'.DOL_URL_ROOT.'/includes/nnnick/chartjs/dist/chart.min.js"></script>';
|
||||
print '<script>';
|
||||
print 'document.addEventListener("DOMContentLoaded", function() {';
|
||||
print ' var ctx = document.getElementById("metallzuschlagChart").getContext("2d");';
|
||||
print ' new Chart(ctx, {';
|
||||
print ' type: "line",';
|
||||
print ' data: {';
|
||||
print ' labels: '.$jsLabels.',';
|
||||
print ' datasets: [{';
|
||||
print ' label: "'.dol_escape_js($labelCU).'",';
|
||||
print ' data: '.$jsCU.',';
|
||||
print ' borderColor: "#b87333",'; // Kupferfarbe
|
||||
print ' backgroundColor: "rgba(184, 115, 51, 0.1)",';
|
||||
print ' borderWidth: 2,';
|
||||
print ' fill: true,';
|
||||
print ' tension: 0.3,';
|
||||
print ' spanGaps: true,';
|
||||
print ' yAxisID: "yCU"';
|
||||
print ' }, {';
|
||||
print ' label: "'.dol_escape_js($labelAL).'",';
|
||||
print ' data: '.$jsAL.',';
|
||||
print ' borderColor: "#a8a9ad",'; // Aluminiumfarbe
|
||||
print ' backgroundColor: "rgba(168, 169, 173, 0.1)",';
|
||||
print ' borderWidth: 2,';
|
||||
print ' fill: true,';
|
||||
print ' tension: 0.3,';
|
||||
print ' spanGaps: true,';
|
||||
print ' yAxisID: "yAL"';
|
||||
print ' }]';
|
||||
print ' },';
|
||||
print ' options: {';
|
||||
print ' responsive: true,';
|
||||
print ' maintainAspectRatio: false,';
|
||||
print ' interaction: { mode: "index", intersect: false },';
|
||||
print ' plugins: {';
|
||||
print ' tooltip: {';
|
||||
print ' callbacks: {';
|
||||
print ' label: function(ctx) {';
|
||||
print ' return ctx.dataset.label + ": " + (ctx.parsed.y !== null ? ctx.parsed.y.toFixed(2) : "-") + " €/100kg";';
|
||||
print ' }';
|
||||
print ' }';
|
||||
print ' }';
|
||||
print ' },';
|
||||
print ' scales: {';
|
||||
print ' x: {';
|
||||
print ' ticks: { maxTicksLimit: 12 }';
|
||||
print ' },';
|
||||
print ' yCU: {';
|
||||
print ' type: "linear",';
|
||||
print ' position: "left",';
|
||||
print ' title: { display: true, text: "'.dol_escape_js($labelCU).'" },';
|
||||
print ' ticks: { callback: function(v) { return v.toFixed(0) + " €"; } }';
|
||||
print ' },';
|
||||
print ' yAL: {';
|
||||
print ' type: "linear",';
|
||||
print ' position: "right",';
|
||||
print ' title: { display: true, text: "'.dol_escape_js($labelAL).'" },';
|
||||
print ' ticks: { callback: function(v) { return v.toFixed(0) + " €"; } },';
|
||||
print ' grid: { drawOnChartArea: false }';
|
||||
print ' }';
|
||||
print ' }';
|
||||
print ' }';
|
||||
print ' });';
|
||||
print '});';
|
||||
print '</script>';
|
||||
}
|
||||
|
||||
// Verlaufstabelle
|
||||
print '<br>';
|
||||
print load_fiche_titre($langs->trans("MetallzuschlagHistory"), '', '');
|
||||
|
||||
$history = $api->getHistory('sonepar', 60);
|
||||
|
||||
if (!empty($history)) {
|
||||
print '<table class="noborder centpercent">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("MetallzuschlagDate").'</td>';
|
||||
print '<td>'.$langs->trans("MetallzuschlagMetal").'</td>';
|
||||
print '<td class="right">'.$langs->trans("MetallzuschlagValue").'</td>';
|
||||
print '<td class="right">'.$langs->trans("MetallzuschlagMonthAvg").'</td>';
|
||||
print '<td>'.$langs->trans("MetallzuschlagSourceCol").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
foreach ($history as $row) {
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.dol_print_date($db->jdate($row->date_notiz), 'day').'</td>';
|
||||
print '<td>'.metallzuschlagGetMetalLabel($row->metal).'</td>';
|
||||
print '<td class="right">'.price($row->value, 0, '', 1, -1, 2).' €/100kg</td>';
|
||||
print '<td class="right">'.(!empty($row->value_month_avg) ? price($row->value_month_avg, 0, '', 1, -1, 2).' €/100kg' : '-').'</td>';
|
||||
print '<td>'.dol_escape_htmltag($row->source).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
} else {
|
||||
print '<div class="opacitymedium">'.$langs->trans("MetallzuschlagNoData").'</div>';
|
||||
}
|
||||
|
||||
llxFooter();
|
||||
$db->close();
|
||||
3
sql/dolibarr_allversions.sql
Executable file
3
sql/dolibarr_allversions.sql
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
--
|
||||
-- Script run when an upgrade of Dolibarr is done. Whatever is the Dolibarr version.
|
||||
--
|
||||
8
sql/llx_metallzuschlag_history.key.sql
Normal file
8
sql/llx_metallzuschlag_history.key.sql
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
-- Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
||||
--
|
||||
-- Indizes fuer Metallzuschlag-Historie
|
||||
--
|
||||
|
||||
ALTER TABLE llx_metallzuschlag_history ADD UNIQUE INDEX uk_metallzuschlag_history (date_notiz, metal, source);
|
||||
ALTER TABLE llx_metallzuschlag_history ADD INDEX idx_metallzuschlag_history_date (date_notiz);
|
||||
ALTER TABLE llx_metallzuschlag_history ADD INDEX idx_metallzuschlag_history_metal (metal);
|
||||
14
sql/llx_metallzuschlag_history.sql
Normal file
14
sql/llx_metallzuschlag_history.sql
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
-- Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
||||
--
|
||||
-- Metallzuschlag-Historie: Tägliche Metallnotierungen von externen Quellen
|
||||
--
|
||||
|
||||
CREATE TABLE llx_metallzuschlag_history (
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
date_notiz date NOT NULL,
|
||||
metal varchar(4) NOT NULL,
|
||||
value double(24,8) NOT NULL,
|
||||
value_month_avg double(24,8) DEFAULT NULL,
|
||||
source varchar(32) DEFAULT 'sonepar' NOT NULL,
|
||||
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=innodb;
|
||||
Loading…
Reference in a new issue