* Fix#39020 avoid duplicate MO when BOM has a sub-BOM
When generating child MOs from a BOM with a sub-BOM line, the lookup of
the parent MO consume line used a substring filter
(origin_id LIKE '%id%') that was not scoped to the parent MO. It could
match an unrelated mrp_production row or none at all. When it matched
none, the child MO was still created from the leftover parent POST data,
producing a second MO identical to the parent instead of a real child.
Scope the lookup to the parent MO with an exact match on origin_id and
origin_type via customsql, and skip the iteration when no matching
consume line is found so no duplicate parent MO can be created.
Signed-off-by: Dolicraft <contact@dolicraft.com>
* Fix#39020 use exact-match filter keys instead of customsql per review
Add exact-match handling for fk_mo, origin_id and origin_type in
MoLine::fetchAll and call it with those keys instead of a customsql
clause, so the lookup stays valid on 18.0/19.0 where customsql would be
the only alternative to the buggy LIKE. The universal-search filter form
is handled separately on 20.0 and later.
Signed-off-by: Dolicraft <contact@dolicraft.com>
---------
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
When MAIN_STORE_COMPUTED_EXTRAFIELDS is enabled, insertExtraFields() and
updateExtraField() evaluated the computed formula without setting the global
$objectoffield to the current object, so formulas relying on
$objectoffield->array_options returned a wrong value (often 0) when stored,
unlike fetch_optionals() which already sets it.
The list template also always recomputed computed extrafields, but the raw
row available in a list has no object context, giving wrong display and wrong
totals. When MAIN_STORE_COMPUTED_EXTRAFIELDS is enabled the value stored in
database is now used instead.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
pdf_crabe and pdf_sponge recompute the per-VAT-rate total for situation
invoice lines using a ratio based on (situation_percent - prev_progress),
assuming facturedet.total_ht/total_tva/situation_percent are still stored
as cumulative values (INVOICE_USE_SITUATION=1, the legacy behavior).
Once an instance is converted to store situation invoice lines as delta
values (INVOICE_USE_SITUATION=2), this ratio is applied a second time on
top of an amount that is already a delta, producing a wrong (sometimes
negative) VAT total on the generated PDF while Total HT/TTC stay correct.
CommonObject::update_price() already guards its equivalent cumulative-to-
delta computation with `getDolGlobalInt('INVOICE_USE_SITUATION') != 2`;
this adds the same guard to both PDF models so they skip the ratio and
use the stored (already delta) total_tva directly once INVOICE_USE_SITUATION=2.
The selector $("[name='type'") was missing its closing bracket, so
the change handler that auto-selects the PDF model per invoice type
(INVOICE_USE_DEFAULT_DOCUMENT) never bound to the type radios.
Also trigger change on #model after .val() so the select2 widget
refreshes its displayed label, not just the underlying select value.
Typo $elementype vs $elementtype: extrafields were fetched for socpeople
but read under the stale key societe, so the contact extrafields section
rendered empty.
The payout.paid IPN handler recorded the bank transfer line with an empty
num_chq (a "// TODO Store the po ref from $event->data" placeholder). The
Stripe payout id is available as $event->data->object->id, so store it as
the transfer reference. This makes auto-recorded payouts traceable and
reconcilable against Stripe.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
In compta/resultat/result.php and clientfourn.php the account number was cast to
(int) before being passed to AccountancyCategory::getSumDebitCredit(), which
compares it as a string (t.numero_compte = '...'). (int) '0510' -> 510 -> '510'
never matches the stored '0510' (numero_compte and account_number are varchar(32),
so leading zeros are significant). Accounts whose code starts with 0 were therefore
silently excluded from the current-year and per-month totals of a personalized
account group, while the previous-year column was already correct because it passes
a string array.
The (int) cast had no functional purpose: it was added to silence a phan notice in
"Qual: Fix phan notices" (#33484). Remove it and pass the raw string, and widen the
getSumDebitCredit() @param to string|int|array<?string> so the string argument is
accepted by static analysis and the cast is not reintroduced. Numeric codes are
unaffected (the callee already casts the scalar with (string)).
In a January that starts with week 52 or 53 of the previous year (for
example January 2022), getFirstDayOfEachWeek() wrongly shifted week 01
to the next year, and the $year++ inside the loop then also corrupted
all the following weeks of the month: every first day returned was the
one of the next year (02, 09, 16, 23, 30 instead of 03, 10, 17, 24, 31
for January 2022). getLastDayOfEachWeek() had no year handling at all,
so the trailing/leading weeks of the other year were resolved in the
wrong year too.
This made the per-month time spent view (projet/activity/permonth.php)
display wrong week date ranges, link to the wrong week and compute the
weekly holiday overlap on wrong date ranges for such months.
Co-authored-by: Claude <noreply@anthropic.com>
When creating a credit note "with same lines" from a situation invoice,
the code always subtracts the previous situation invoice's line values
before inverting the sign, assuming lines are stored cumulative
(INVOICE_USE_SITUATION = 1, legacy mode).
In progressive mode (INVOICE_USE_SITUATION = 2), each situation invoice
line already stores its own delta amount and percent, so this extra
subtraction credits the wrong amount and percent (e.g. 60% / 1272
instead of the correct 20% / 424 on a real cycle).
Skip the subtraction in progressive mode so the credit note reuses the
source line's own delta values, as expected.
* FIX#37826 country_code must be an ISO code, not a label
On a proposal/order, the 2nd+ line got VAT 0% with the error "no vat rates
defined for country 'France'/'Suisse'". Root cause: the seller country_code
held a translated country label instead of the ISO code, so the
"c.code IN (...)" lookup in Form::load_cache_vatrates() matched nothing.
- Societe::setMysoc(): the canonical MAIN_INFO_SOCIETE_COUNTRY is
"id:code:label"; a legacy "id:label" value put the label into
country_code. Only treat the full 3-token form as "id:code:label" and
otherwise rebuild code/label from the authoritative country id.
- Form::load_tva(): defensively recover the seller ISO code from its
country id when country_code is not a known c_country code, so a bad
value can never silently force the VAT rate to 0%.
Signed-off-by: Jam Balaya <jambalaya.pyoncafe@outlook.jp>
* FIX#37826 avoid useless SQL per page: recover country ISO code from id only when code is not a 2-char ISO code
---------
Signed-off-by: Jam Balaya <jambalaya.pyoncafe@outlook.jp>
The day loop of num_public_holiday() advanced with
dol_time_plus_duree($timestampStart, 1, 'd'). On 21.0 and 22.0 that
function only forces UTC when MAIN_DATE_IN_MEMORY_ARE_GMT is set, so by
default it adds a wall-clock day in the server timezone. When the range
crosses a DST boundary (last Sunday of March in Europe), the GMT
timestamp advances by only 23 hours, the same GMT day is evaluated
twice, one day is counted as holiday twice and the working day after
the boundary is never examined.
For a leave request from Sat 28/03/2026 to Mon 30/03/2026 with a server
in Europe/Paris: 3 days between, 3 holidays counted (Sunday twice),
0 working days instead of 1.
Advance by exactly 86400 seconds instead. Inputs of this function are
GMT dates (enforced by the modulo check at the top of the function), so
a GMT day is always exactly 86400 seconds, in every timezone and conf.
This matches the behaviour that 23.0 and develop get by default since
dol_time_plus_duree() switched to UTC by default there.
Signed-off-by: Gregory Aliot <greg.aliot@gmail.com>
Co-authored-by: Gregory Aliot <greg.aliot@gmail.com>
* fix: accounting export reexport date not updated and fiscal year filter incorrectly applied on reexport
* Update date_export only if it is empty or ACCOUNTING_REEXPORT is active
---------
Co-authored-by: Zakaria Boushaba <z.boushaba@vold.africa>
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
* FIX: Margin calculation on situation invoices uses cumulative percent instead of delta, causing inflated amounts across all margin views
* Fix
* use the 'as' between table name and alias name
---------
Co-authored-by: Zakaria Boushaba <z.boushaba@vold.africa>
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
* FIX Mass reverse of stock movements bypasses the MAIN_LIMIT_FOR_MASS_ACTIONS limit
The confirm_reverse handler did not check the error raised by the
generic mass action limit control (TooManyRecordForMassAction), so
selecting more records than the limit still executed the reverse
after the error message was displayed. The reverse was also triggered
when relaunching a search while the confirmation form was open,
because the protection only reset $massaction, not $action.
* FIX phan: initialize $error at the start of the confirm_reverse handler
The new !$error guard lets phan narrow $error to falsy types inside
the block, so the $error++ in the query-error branch was reported as
PhanTypeInvalidUnaryOperandIncOrDec. Initialize $error to 0 at the
start of the handler (and drop the redundant init inside the loop
setup where present).
* FIX coding rule: comment on the $action test that only cancels the pending action
CodingPhpTest requires a permission check or an explicit comment on
every test of $action in the Actions section.
---------
Co-authored-by: Nicolas Zaou <nz@anatoleconseil.com>
htdocs/fourn/paiement/document.php called
restrictedArea($user, $object->element, $object->id, 'paiementfourn', '')
before $object was instantiated (the 'Load object' block sat after the
security check), so the permission check ran on an undefined $object (null
element / null id) and PHPStan level 10 flagged 'Variable $object might not
be defined'.
The sibling pages fourn/paiement/card.php and info.php instantiate the
PaiementFourn object before the same restrictedArea() call. Move the object
load ahead of the security check so the check runs against the real object.
In htdocs/comm/action/index.php the month and week views call
print_actions_filter(..., $actioncode, $usergroupids, ...) with
$usergroupids (array<int>, built at the top from the comma-separated
$usergroup), but the day view passed the raw $usergroup string instead.
print_actions_filter() forwards this to select_dolgroups() which expects an
array, so a multi-group filter (e.g. '3,5') is not preselected in the day view.
Pass $usergroupids to match the two sibling calls.
PHPStan level 10 flagged: Parameter #16 $usergroupid of function
print_actions_filter expects array<int>, string given.
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
htdocs/paypal/lib/paypal.lib.php passed a boolean to CURLOPT_SSL_VERIFYHOST:
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, ($ssl_verifypeer ? true : false));
CURLOPT_SSL_VERIFYHOST expects 0, 1 or 2 (not a bool). 'true' is cast to int 1,
which only checks that a Common Name is present, not that it matches the host
(value 1 is also deprecated / a no-op on some libcurl builds) - weakening TLS
host verification on PayPal API calls. Use 2 (full host check) / 0.
PHPStan level 10 flagged: Parameter #3 $value of function curl_setopt expects
0|2, bool given.
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>