CommandeFournisseur::addline rounds the line quantity to the next packaging
multiple but never enforces pfp.quantity (the supplier minimum purchase
quantity). A line with packaging=3 and qty_min=15 could therefore be saved
at qty=6 (only multiple of packaging) - the user-facing scenario from
#38783 with the table of expected vs actual values.
Two small changes:
1. htdocs/product/class/product.class.php get_buyprice() already maintains
$prod_supplier->fourn_qty for the dynamic-price code path at lines 2622
and 2691 but never propagates the same value to $this->fourn_qty (which
is the public property documented as MOQ at line 738). Assign $this->fourn_qty
in both branches of get_buyprice so callers can read it after the call.
2. htdocs/fourn/class/fournisseur.commande.class.php addline now applies a
second rounding pass against $prod->fourn_qty after the packaging multiple
step. If qty is still below qty_min, round qty_min up to the next packaging
multiple - the smallest qty that satisfies both constraints simultaneously.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
When PRODUCT_USE_CUSTOMER_PACKAGING / PRODUCT_USE_SUPPLIER_PACKAGING are
enabled, the four order line methods (Commande::addline, Commande::updateline,
CommandeFournisseur::addline, CommandeFournisseur::updateline) recompute the
quantity to the next packaging multiple. Reporter audited the four code paths
and listed six divergences between them; the customer addline at
htdocs/commande/class/commande.class.php:1720 is the reference and the rest
were re-aligned on it:
- Bug 1: supplier addline did not call setEventMessages() when qty < packaging,
so the user was silently corrected (htdocs/fourn/class/fournisseur.commande.class.php:2153).
- Bug 2: supplier addline used a raw float multiplication; switch to price2num('MS').
- Bug 3: supplier updateline used 'fmod() > 0' which is vulnerable to float
noise (fmod(3.0, 1.5) can yield 4.44e-16); switch to price2num((float) ..., 'MS').
- Bug 4: supplier updateline missed the qty < packaging notification.
- Bug 5: both updateline paths missed abs() in coeff = intval(qty / packaging) + 1,
which broke rounding for negative qty; the addline paths already do abs().
- Bug 6: supplier path used setEventMessages('mesgs') (green/info); the user
feedback is a corrected input, semantically a warning. Switch to 'warnings'
to match the customer path.
No behavior change for callers passing positive, valid quantities; the diff
only affects edge cases (negative qty, qty just under packaging, float-fmod
noise) and the message channel.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
htdocs/modulebuilder/index.php:1859 ran strtolower() on the raw form value
$proptype before storing it back into the object's field definition. That
lower-cased composite types like
'integer:Societe:societe/class/societe.class.php:1:(...__SHARED_ENTITIES__...)'
into 'integer:societe:...:(...__shared_entities__...)'. Two breakages from
that single transform:
1. PHP class names are case-sensitive on case-sensitive filesystems; 'societe'
then fails to instantiate where 'Societe' worked.
2. Substitution tokens such as __SHARED_ENTITIES__ are matched verbatim by
the entity filter; once lower-cased they no longer match.
Only lowercase truly atomic types ('Integer' -> 'integer', 'TEXT' -> 'text').
For anything containing ':' or '_' (composite spec, substitution token) keep
the user-typed casing.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
htdocs/product/inventory/inventory.php:264 wrote into llx_product_perentity
under MAIN_PRODUCT_PERENTITY_SHARED, but Product::fetch at line 2995-2997
of htdocs/product/class/product.class.php only reads pmp from that table when
both MULTICOMPANY_PRODUCT_SHARING_ENABLED and MULTICOMPANY_PMP_PER_ENTITY_ENABLED
are set. MAIN_PRODUCT_PERENTITY_SHARED is the accountancy-codes flag; using
it to gate the pmp write meant inventory wrote a value that fetch would
silently ignore (and overwriting whatever was there before).
Align the inventory write with the fetch read so the two stay in sync.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
htdocs/projet/element.php:1075 unconditionally negates total_ht / total_ttc for
commande_fournisseur and supplier_proposal rows. A few lines below at 1095 the
margin block also negates when $margin === 'minus'.
The default 'order_supplier' entry in $listofreferent ships without a margin
key, so users opt it into the profit calculation via
PROJECT_ELEMENTS_FOR_MINUS_MARGIN=order_supplier. The PROJECT_ELEMENTS_FOR_MINUS_MARGIN
loop at line 819 then sets $margin='minus' for that key, and both negations
fire on the same value - the supplier total flows into balance_ht as a positive
amount instead of being subtracted, which matches the symptom in the screenshot.
Skip the line-level negation when the margin block will take care of it.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
The 'tiers_fournisseur' and 'contact_fournisseur' SQL templates in
htdocs/datapolicy/class/datapolicycron.class.php tested NOT EXISTS against
llx_facture (sales invoices) when the gate must be on llx_facture_fourn
(purchase invoices). A pure supplier (fournisseur=1, client=0) with an
active purchase history but no sales would pass the filter and get
anonymized as if it had no activity, losing the data that was the whole
reason it was kept in the dictionary.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
htdocs/admin/dict.php:2402 guards the edit-form rendering with
'$rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code)'. PHP empty(0)
returns true, so the ternary falls back to $obj->code for any row whose
rowid is 0 - the comparison becomes '0' == 'ST_NEVER' and the form
never renders. ST_NEVER in llx_c_stcomm is inserted with id = 0 and is
therefore stuck non-editable for label, picto, etc.
Switch the guard to isset() so rowid = 0 is treated as a real rowid.
The same fallback exists at line 2415 for the name attribute of the
hidden div; apply the same change for consistency.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
Per eldy review: use price() to render the prefilled qty in locale format
so GETPOSTFLOAT('MS') on submit (which calls price2num option=2) parses
it back correctly instead of misreading '1.234' as 1234 when '.' is the
locale thousand separator.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
KnowledgeRecord::delete only ran the SQL DELETE chain through
deleteCommon() and never touched the filesystem. Uploaded attachments
under documents/knowledgemanagement/knowledgerecord/<ref>/ stayed on
disk forever, growing the documents directory whenever an article was
removed.
After deleteCommon succeeds, remove the matching directory with
dol_delete_dir_recursive(), matching the pattern Project::delete and
Expedition::delete already use.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
The fetch loop reused a single $tmpobj declared before the loop and
reset only $tmpobj->id before each fetch. Object classes whose fetch()
does not clear every property left stale data from previous rows, and
the shallow 'clone $tmpobj' kept nested object references (thirdparty,
extrafields, ...) pointing at the last fetched row.
Instantiate a fresh $tmpobj per row and append it directly so each
returned entry is fully independent.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
When SERVICE_ARE_ECOMMERCE_200238EC is enabled the accountancy code
chosen by getTaxesFromId() depends on the buyer country. The cache key
in sellsjournal.php was only tax rate plus vat_src_code, so two
invoices for buyers in different countries that happened to share the
same rate hit the same cache slot and the second invoice reused the
first buyer's accountancy code.
Add buyer country (s.fk_pays) to the cache key when this constant is
on. When it is off the lookup does not depend on the buyer so the
behaviour stays unchanged.
Diagnosis and patch direction from the reporter.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
In htdocs/compta/facture/card.php, the 'setabsolutediscount' action has
two branches: remise_id (line 657+) and remise_id_for_payment (line 683+).
The first branch already guards setPaid behind a STATUS_VALIDATED check
(line 675), but the second branch calls setPaid directly whenever the
new remain_to_pay reaches zero.
When a user applies a 100% deposit-converted-to-discount on a still-draft
invoice via that second branch, setPaid runs on a PROV-ref invoice. The
invoice then sits in status paid with a temporary reference and never gets
its real ref assigned because validateion is skipped.
Mirror the guard from the remise_id branch so we only mark the invoice
as paid when it has actually been validated.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
The form-rendering path runs $db->query($sql) only when $ext != 'csv'
(line 381-386). When the user clicks the 'Download CSV' link, $ext is
'csv', so $resql is never assigned. The check immediately after at
line 387 then sees empty($resql) and triggers dol_print_error($db);
exit, which surfaces as HTTP 500 and a CSV with only headers.
Move $db->query($sql) out of the if/else and run it in both branches.
For the csv branch we still want to skip the plimit so the export is
not paginated; that part stays inside the if. Reported in #37582.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
The user/ldap.php attribute viewer calls $ldap->getAttribute($dn, $search)
where $search is built from the user identifier alone, e.g. (uid=jdoe).
getAttribute() then forwards that filter to ldap_search() unchanged.
The admin-configured LDAP_FILTER_CONNECTION ($this->filter) was applied
only by getRecords() with activefilter=1, not by getAttribute(). As a
result, if a local Dolibarr user is renamed to a uid that matches an
LDAP entry sitting outside the configured search filter scope, the
attribute lookup still returns that entry's data.
AND the configured filter with the caller-supplied filter when present,
unless the caller has already built a conjunctive filter starting with
(&(. The conservative regex avoids double-wrapping when getAttribute is
later called by getRecords() with an already-AND-composed filter.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
TakePOS supplement handling needs the rowid of the previously selected
line so the new line can be attached as a child via fk_parent_line.
htdocs/takepos/invoice.php:837 reads $selectedline = GETPOSTINT('selectedline')
and SELECTs FROM facturedet WHERE rowid = $selectedline to find the
parent.
When the JS in htdocs/takepos/index.php:590 dropped the selectedline
query parameter (regression since 19.x), GETPOSTINT returns 0, the
parent lookup matches no row, fk_parent_line stays null and the
supplement is added as a regular standalone line.
Restore the &selectedline= parameter to the AJAX URL.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
dol_add_file_process() calls implode(',', getExecutableContent()) inline
to build the default value of the MAIN_FILE_EXTENSION_UPLOAD_RESTRICTION
constant. The helper getExecutableContent() lives in core/lib/functions.lib.php
and was added in 22.0.0. On installs where the deploy left a newer
files.lib.php sitting next to an older functions.lib.php (partial upgrade,
mixed deploy), the upload path throws Fatal Error 'Call to undefined function
getExecutableContent()' at files.lib.php:2078.
Guard the call with function_exists() and fall back to a static copy of
the current executable-extension list. The fallback matches the function
exactly so the security check is preserved; once functions.lib.php is
upgraded the function-based branch takes over again.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
htdocs/admin/security.php:75 stores DATABASE_PWD_ENCRYPTED with entity 0
(see the comment 'DATABASE_PWD_ENCRYPTED is a setup into conf file, so
always shared for everybody'). htdocs/install/step5.php was instead
writing it with $conf->entity (= 1 on a first install), so the flag
landed in llx_const for entity 1 only. Any later created entity then
defaulted to no password encryption until an admin manually flipped the
setting in admin/security.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
htdocs/contrat/card.php builds the source-class path from $element/$subelement
parsed out of GETPOST('origin'). When a contract is created from a recurring
invoice, origin = 'facturerec' (or facture_fourn_rec), so the include path
becomes /facturerec/class/facturerec.class.php while the real file is
htdocs/compta/facture/class/facture-rec.class.php. dol_include_once silently
logs the missing file, the source object is never instantiated, the contract
is created without source lines and the link to the original invoice template
breaks.
Add the same compatibility branches for facturerec / facture_fourn_rec as
exist for facture / invoice. Because the file name now contains a hyphen,
ucfirst($subelement) would yield 'Facture-rec' (not a valid PHP identifier),
so the branches also pin $classname explicitly to FactureRec / FactureFournisseurRec
and the existing fallback only runs when no branch set it.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
In admin/extrafields the create page renders the Help tooltip row right
after Totalizable, before the Css rows. The edit page renders it after
all Css rows, so jumping from create to edit visually moves the field
without any meaningful reason.
Move the <tr class="help"> row in admin_extrafields_edit.tpl.php to the
same position as in admin_extrafields_add.tpl.php (after Totalizable,
before Css edit). Pure markup ordering, no logic change.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
The fixed-target branch of Notify::send built the PDF path as
"$dir_output/$ref/$ref.pdf" while $dir_output already includes the
get_exdir(...) ref subdirectory. The double ref segment made
dol_is_file always fail and the PDF was never attached when a
notification was routed to a fixed email address. The matching block
just above for user/group targets has always used the correct
"$dir_output/$ref.pdf" form.
Drop the extra ref segment so both branches produce the same path.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
Dictionary entry creation in admin/dict.php computes $newid = MAX(rowid)+1
in PHP and INSERTs with that rowid explicitly. On PostgreSQL the matching
serial sequence (<table>_rowid_seq) is never told about the manually
chosen value, so the next auto-increment insert (the next dictionary
entry, or any other code path that pulls from the same sequence) hits a
duplicate-key error mis-reported to the user as
'already existing record'.
Bump the sequence with setval(pg_get_serial_sequence(...), GREATEST(MAX,1))
right after a successful forced-rowid INSERT, gated on $db->type == 'pgsql'
so MySQL/MariaDB behaviour is unchanged.
Diagnosis by @hregis (#36510).
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
#33434 was meant to allow positive lines on a credit note when both
FACTURE_ENABLE_NEGATIVE_LINES and INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN
were enabled (so that origin-negative lines moved as positive into the
credit note could be re-edited without being forced back to negative).
The actual gate was '!A && !B', which disables the abs forcing whenever
either flag is set. Sites that enable only FACTURE_ENABLE_NEGATIVE_LINES
now see credit note totals flip to positive after editing any line.
Use '!(A && B)' instead so the relaxation only kicks in when both flags
are set, matching the intent and the symmetric addline() path which
always forces -abs on credit notes.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
The constants MAIN_LIST_ALLOW_PUBLIC_NOTES / MAIN_LIST_ALLOW_PRIVATE_NOTES
were renamed to MAIN_LIST_HIDE_PUBLIC_NOTES / MAIN_LIST_HIDE_PRIVATE_NOTES
in the 16.0.0 to 17.0.0 migration, but four sites still referenced the
old names (expedition/list.php lines 160-161, commande/list_det.php lines
232-233). With the constants only present under their new names the
expression !getDolGlobalString('MAIN_LIST_ALLOW_*') always returns true,
so the note columns showed up regardless of admin intent and disagreed
with the other lists (`contrat`, `commande/list.php`, `fourn/commande`,
`fourn/facture`, ...) which already use the HIDE names.
Switch both files to the HIDE constants so the four legacy sites match
the rest of the codebase and respect the same admin flag.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
Product::delete() and Product::hasVariants() queried
llx_product_attribute_combination unconditionally, even when the
variants module was disabled. On PostgreSQL the table only ever exists
when the variants module has been activated (it lives in the suffixed
-variants.sql files loaded via _load_tables()), so deleting a freshly
created product on a fresh install fatals with
'relation llx_product_attribute_combination does not exist'.
Wrap the delete-time block in isModEnabled('variants') (matching the
existing gate in update on line 1802) and short-circuit hasVariants()
when the module is off, mirroring the existing guard in isVariant().
MySQL is unaffected because the table is created in the same path.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
The tasks segment block in doc_generic_project_odt already swallowed
the missing-segment exception by checking the trace function name
('setSegment'), letting templates omit the [!-- BEGIN tasks --] pair
without fatal-ing. The projectfiles and projectcontacts catch blocks
right below did not have that check, so a template missing either
segment caused a 500 even though the surrounding code clearly meant to
treat all three the same way.
Apply the same trace-function check to both catch blocks. Behaviour on
templates that include the segments is unchanged; templates that omit
them now generate without the fatal.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
ExtraFields::getOptionalsFromPost() had no dedicated handler for the
pricecy (price with currency) type, so the path used by line-level
extrafields fell through to the generic else and only read the amount
field. The companion options_<key>currency_id input was dropped and the
saved value was a bare number, which the renderer then treated as the
default currency.
Add a pricecy case that concatenates amount and currency_id into the
amount:currency string the rest of the code already expects.
The legacy setOptionalsFromPost() path had the symmetric problem from
a different angle: its pricecy branch was guarded by
in_array($key_type, array('pricecy', 'double')), where 'double' is dead
code because the previous elseif already matches it. Drop 'double' so
the type list reflects the real intent.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
setListDependencies() bound a change handler on every select option[parent]
on the page, including line-item extrafield selects that already get
their own handler from setListDependencies_extra() (built by
CommonObject::getJSListDependancies()).
When both handlers bind to the same select, showOptions() flips child
options with prop('disabled') while showOptions_extra() rebuilds them
with clone/remove/append. The two races leave the child options
permanently greyed out the first time the parent changes during a line
edit. Users have to clear and save the line, then re-edit, to recover.
Skip elements inside the extrafield_lines_area_* containers so only
setListDependencies_extra() drives line cascades. Header-level
extrafields keep going through the original path.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
The proposal-to-order create path relies on the order in which
Propal::fetch_lines() returns its rows. The query only sorted by
d.rang, so two lines sharing a rang (legacy data, manual edits, or
batch imports) came back in MySQL's internal heap order, and the
order built from them ended up with lines permuted versus the
proposal.
Add d.rowid as a tie-breaker, matching the stable pattern used by
Expedition::fetch_lines (ORDER BY rang ASC, rowid ASC). Behaviour
on data with unique rangs is unchanged.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
* Fix#38697 catch per-email exceptions in EmailCollector
The foreach over richarrayofemail in EmailCollector::doCollectOneCollector
had no per-iteration exception guard. On PHP 8, mysqli throws on query
errors, so a single poison email - a duplicate UNIQUE INSERT, an invalid
date, etc. - aborted the whole run mid-loop. datelastresult was never
updated, the processing flag stayed set and every remaining email was
skipped, leaving the collector stuck until cleared manually.
Wrap the body in try { ... } catch (Throwable $e) so a failing email is
rolled back, logged and the loop continues. The rest of the batch
completes and the collector lock is released.
Signed-off-by: Dolicraft <contact@dolicraft.com>
* Fix#38697 reindent foreach body wrapped in try
The previous commit wrapped the per-email loop body in try/catch but did
not bump the inner indentation, so pre-commit/phpcs flagged ~1.6k tab
count mismatches. Add the missing inner tab on the wrapped range.
Signed-off-by: Dolicraft <contact@dolicraft.com>
* Fix#38697 update codespell ignore tab count after reindent
The two existing udate (IMAP overview field) entries were ignored with
five tabs of indent. The previous reindent commit added one more tab
inside the wrapped try block, so the ignore lines no longer match the
source lines. Re-add the missing tab on the two ignore entries.
Signed-off-by: Dolicraft <contact@dolicraft.com>
---------
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
ActionComm::create()'s INSERT and ActionComm::update()'s UPDATE both
omitted the fk_task column, so the value posted via /agendaevents or
the manual create-event form was silently dropped. The fetch() SELECT
was also missing the column, so even if it had been written it would
not have been loaded back.
Add fk_task to all three SQL statements and assign it from the row in
fetch(), matching the existing pattern for fk_user_action / fk_contact.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
The delete-icon link on bankentries_list.php stripped 'action=reconcile'
from $param but left a stray trailing '&' (and the same string can be
re-emitted by other includes), so the final URL ended up with two
action= query params (action=delete and action=reconcile). PHP picks
the last one, the page silently switches to the reconcile path and the
delete confirm dialog never opens.
Widen the preg_replace to consume the surrounding & as well, and also
clean up the confirm_deleteonreconcile form.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
compta/paiement/document.php and fourn/paiement/document.php expose
$hookmanager via the @var docblock but never call initHooks, so the
include of core/actions_linkedfiles.inc.php and the rest of the page
can't run any custom-module hook context.
Add an initHooks() right after loadLangs, mirroring the pattern used
by commande/document.php (orderdocument, globalcard). Use
paymentdocument / paymentsupplierdocument for the two pages.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
PrintIPP just calls $ipp->setData($fileprint) and never tells CUPS what
the file actually is, so the job arrives as application/octet-stream
and CUPS treats ODT/PDF/PS as raw bytes - the ASCII garbage symptom
the reporter sees.
Map the file extension to a MIME and call $ipp->setMimeMediaType()
when the extension is recognised. Unknown extensions fall through to
the existing default, so the change is non-breaking.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
When $arraydefaultmessage->email_from is set but $arraydefaultmessage->id
is empty, FormMail built a 'from_template_' option key with no trailing
id, and the same string was passed as the preselected value of the
fromtype select. The downstream parser in core/actions_sendmails.inc.php
matches /from_template_(\d+)/ which requires at least one digit, so the
match failed and the from address fell back through the else branch.
Guard the option emission and the selected-value computation against
empty $arraydefaultmessage->id so the malformed key is never produced.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
isStringVarMatching() wraps the input regex with '/^' and '/' before
preg_match, but callers (custom modules, older code, dol_eval rules
that accept both '(aaa|bbb)' and '/^(aaa|bbb)/') sometimes already
pass the full regex with delimiters. The double wrap produces
'/^/^(aaa|bbb)//' which trips preg_match with 'Unknown modifier ^'
on every page load.
Strip a leading '/' (optionally followed by '^') and any trailing
'$?/' plus PCRE flags before reusing the pattern, so both bare and
already-delimited forms work the same way.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
When a paid deposit invoice is auto-converted into a discount, the per-rate
buckets in Paiement::create were keyed on tva_tx alone. Lines that shared a
rate but had distinct vat_src_code values were merged into one bucket, and
the generated discount was always created with an empty vat_src_code.
A later 'Apply discount' on the standard invoice therefore inserts a line
without the source VAT code, while the deposit lines keep it. The PDF then
shows two VAT lines for the same rate (one with the code, one without).
Bucket by tva_tx + vat_src_code instead, parse both back when looping the
buckets, and assign vat_src_code on the generated discount before create().
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
The various-payments section of compta/resultat/clientfourn.php fetches
two rows from the GROUP BY p.sens query (debit, credit). When one of the
two sens has no payment in the period the corresponding fetch_object()
returns null, but the subsequent print statements still dereferenced
$obj->amount outside the isset() guard used for the totals.
Capture the amount into a local that defaults to 0 when the row is
absent, and print from that local. Behaviour is unchanged when both rows
are present, the warning disappears in the missing-row case, and the
debit/credit value printed in that case is now 0 instead of an undefined
read.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
The signed-PDF builder branched only when the bank PDF model is exactly
'sepamandate' and left $sourcefile empty in every other case. The
downstream dol_is_file($sourcefile) check then failed silently, the
signed PDF was never built, and the public download link kept pointing
at the unsigned original.
Add an else fallback that takes the last generated main document path
and derives the signed name by appending _signed-<date> before the
extension, so non-default bank PDF models (eg. 'ban') produce a signed
copy too.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
draw_chart() built tmpykey by indexing array_of_ykeys[$i + 1] without
checking the key existed first, and the y_<i> fallback used
$valarray[$i + 1] the same way. Both fire PHP 8.2 'Undefined array key'
warnings when a $this->data row is shorter than the longest one (custom
modules sometimes feed sparse rows).
Resolve ykey via isset() before exploding, and add a ?? null fallback on
the value lookup so both warnings stop without changing the value
returned in the well-formed case.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
* Fix#38358 guard cache_availability lookup in form_availability
When form_availability() is called with a non-zero $selected that is
not a known c_availability rowid (e.g. -1 from a row whose fk_availability
was left at the legacy 'not set' sentinel), the direct array access
emits two PHP warnings on PHP 8+:
- Undefined array key -1
- Trying to access array offset on value of type null
Check isset() before printing the label and fall back to nbsp like the
$selected==0 branch already does.
Signed-off-by: Dolicraft <contact@dolicraft.com>
* Fix#38358 also drop excess args on two dolPrintHTMLForAttribute calls
phpstan flags two pre-existing 6-arg calls in the same file once any
edit forces a re-check. dolPrintHTMLForAttribute() takes 1-3 args, so
the extra '', 0, 1 are dropped. The default $escapeonlyhtmltags=0 and
$allowothertags=array() match the intent of the original calls.
Signed-off-by: Dolicraft <contact@dolicraft.com>
---------
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
When the 'by' column is hidden in the project timespent list, the form does
not emit a userid_line input. The updateline handler then read
GETPOSTINT('userid_line') as 0 and overwrote timespent_fk_user. The downstream
'in_array($object->timespent_fk_user, $childids)' guard with fk_user=0
blocked the update and the user saw a confusing 'Field User is required' for
the unchanged user assignment.
Only overwrite timespent_fk_user when the form actually posted userid_line,
mirroring the date column fix from #34511.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
The shared confirm_delete branch at htdocs/core/actions_addupdatedelete.inc.php:468
fired on action=confirm_delete with permission, but never checked the
$confirm value. Every other confirm_* branch in the same file checks
$confirm == 'yes'. As a result, a card.php using the standard
$form->formconfirm() flow without the ajax handler would delete the
object when the user clicks 'No' on the confirmation dialog.
Align with the rest of the file by requiring $confirm == 'yes'.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
ExpenseReport::hasDelay() compares the validation date to (now -
warning_delay). When MAIN_DELAY_EXPENSEREPORTS (or its 'to pay' twin)
is not configured, $conf->expensereport->approve->warning_delay is 0,
so the test becomes "date_valid < now" and every validated report
older than a moment is flagged as late.
Treat warning_delay <= 0 as 'no delay configured' and return false in
that case, so an unconfigured threshold no longer marks the whole list
as overdue.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
llx_actioncomm has no fk_user_done column - it was migrated to
fk_user_action by the 3.5 -> 3.6 schema change. The 2023 introduction
of the upcoming-events box (commit e0ef2870a4) added a third predicate
'a.fk_user_done = $user->id' to the visibility WHERE clause, which
fails with 'Unknown column' on both MySQL and PostgreSQL (PG just
surfaces it visibly).
Drop the extra OR. fk_user_action already covers the 'owner of action'
case, which is what fk_user_done used to mean before the column rename.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
Task::create()'s INSERT statement omitted the rang column. Project clone
flows go through Task::createFromClone -> Task::create with the rang
copied from the source task, but because the INSERT never wrote it the
new tasks always ended up with rang=0 (the column default) and the
duplicated project lost the drag/drop ordering.
Include rang in the INSERT, mirroring the update() statement at line 692
that already does '($this->rang ?: 0)'.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
The customer-side line picker preselects the product's default measuring
unit when a product is chosen, via /product/ajax/products.php returning
fk_unit and a small jQuery snippet in objectline_create.tpl.php (added
for issue #34610). The supplier-side line picker, which uses
/fourn/ajax/getSupplierPrices.php and a separate $.post callback,
never received fk_unit on the wire, so the #units dropdown was always
left at its default and the reporter's products with a configured unit
showed the wrong unit on save.
Three coordinated edits:
- list_product_fournisseur_price() now selects p.fk_unit alongside the
other product columns and assigns it on the returned ProductFournisseur
instance as $prodfourn->fk_unit.
- getSupplierPrices.php exposes $productSupplier->fk_unit on each row
of the JSON response so the client can read it.
- objectline_create.tpl.php (the supplier callback after the
fournprice_predef rebuild) walks the response, picks the first
non-pmp/non-costprice row's fk_unit (all rows for one product carry
the same fk_unit), and sets #units to that value when
PRODUCT_USE_UNITS is on. Mirrors the customer-side logic already
in place for issue #34610.
Same code path on develop.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>
The existing guard at line 1531 of Product::update re-clones $this->oldcopy
with native=1 (which preserves methods) when oldcopy is null or has no
id, but does not catch the case where a caller assigned a stdClass via
dol_clone($obj, 2). dol_clone with native=2 copies the scalar properties
of $srcobject onto a fresh stdClass, including $obj->id, so
empty($this->oldcopy->id) is false. Execution then reaches
$this->oldcopy->hasbatch() at line 1716 and fatals with
'Call to undefined method stdClass::hasbatch()'.
Add a third branch to the guard: re-clone whenever oldcopy is not an
instance of Product. The native=1 reclone restores the proper Product
type and the hasbatch() / isEmpty() calls below work as intended.
Reproduced on PHP 8.2 in Docker: assigned oldcopy = dol_clone($obj, 2)
(stdClass) then called update(), vanilla path fatals on
stdClass::hasbatch(), patched path returns 1 cleanly.
Signed-off-by: Dolicraft <contact@dolicraft.com>
Co-authored-by: Dolicraft <contact@dolicraft.com>