Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW More option for elephant numbering rule #30273

Merged
merged 4 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion htdocs/core/modules/societe/mod_codeclient_elephant.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* Copyright (C) 2011 Juanjo Menent <[email protected]>
* Copyright (C) 2013-2018 Philippe Grand <[email protected]>
* Copyright (C) 2020-2024 Frédéric France <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024 Eric Seigne <[email protected]>
*
* 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
Expand Down Expand Up @@ -93,6 +94,8 @@
$texte .= '<input type="hidden" name="action" value="setModuleOptions">';
$texte .= '<input type="hidden" name="param1" value="COMPANY_ELEPHANT_MASK_CUSTOMER">';
$texte .= '<input type="hidden" name="param2" value="COMPANY_ELEPHANT_MASK_SUPPLIER">';
$texte .= '<input type="hidden" name="param3" value="COMPANY_ELEPHANT_DATE_START">';
$texte .= '<input type="hidden" name="param4" value="COMPANY_ELEPHANT_DATE_START_ENABLE">';
$texte .= '<table class="nobordernopadding" width="100%">';

$tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("ThirdParty"), $langs->transnoentities("ThirdParty"));
Expand All @@ -114,6 +117,33 @@
$texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="value2" value="'.getDolGlobalString('COMPANY_ELEPHANT_MASK_SUPPLIER').'"'.$disabled.'>', $tooltip, 1, 1).'</td>';
$texte .= '</tr>';

// Date of switch to that numberring model

Check failure on line 120 in htdocs/core/modules/societe/mod_codeclient_elephant.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

numberring ==> numbering
$datedb = getDolGlobalString('COMPANY_ELEPHANT_DATE_START');
// After save, default dolibarr store data like displayed : 20/05/2024 and we need a timestamp -> override data
if (!empty($datedb)) {
if (!is_numeric($datedb) && GETPOSTISSET('value3')) {
if (GETPOST('value4') == 1) {
$dateinput = GETPOSTDATE('value3');
$res = dolibarr_set_const($this->db, 'COMPANY_ELEPHANT_DATE_START', $dateinput, 'chaine', 0, '', $conf->entity);
} else {
$res = dolibarr_set_const($this->db, 'COMPANY_ELEPHANT_DATE_START', '', 'chaine', 0, '', $conf->entity);
}
} else {
$dateinput = $datedb;
}
}
if (empty($dateinput)) {
$dateinput = dol_now();
}
$texte .= '<tr><td>'.$langs->trans("DateStartThatModel").' ('.$langs->trans("DateStartThatModelHelp").'):</td>';
$texte .= '<td class="" style="flex-direction: row;display: flex;">';
$texte .= '<input type="checkbox" onclick="let d=document.getElementById(\'elephantchoosedate\'); if(this.checked){d.style.cssText = \'display: block;\'}else{{d.style.cssText = \'display: none;\'}}" name="value4" value="1" style="float: left;"/>';
$texte .= '<div style="display: none;" id="elephantchoosedate" class="right">';
$texte .= $form->selectDate($dateinput, 'value3', 0, 0, 1, '', 1, 1, $disabled);

Check warning on line 142 in htdocs/core/modules/societe/mod_codeclient_elephant.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

mod_codeclient_elephant.php: PhanTypeMismatchArgumentProbablyReal: Argument 9 ($disabled) is $disabled of type ' disabled'|'' but \Form::selectDate() takes int (no real type) defined at htdocs/core/class/html.form.class.php:6963 (the inferred real argument type has nothing in common with the parameter's phpdoc type)
Copy link
Contributor

@frederic34 frederic34 Jul 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it better like this :
$selectdisabled = ((!empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? 1 : 0);
$texte .= $form->selectDate($dateinput, 'value3', 0, 0, 1, '', 1, 1, $selectdisabled);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frederic34 ... i really can't see that your code could do the same thing as mine ?

my objective is:

  • add a checkbox and if user check it, then display the input field, uncheck that checkbox, hide the text input field
  • on submit we could get value if checkbox is checked or no and then delete / update value

that is an elegant way to handle situation where people want to "remove" data: with classic input field if the field is empty on POST dolibarr do not "delete" / "set to empty" value (i think, that was the situation last time i check)...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$disabled returns a string but selectDate wait for an int

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to do
$disabled ? 1 : 0

$texte .= '</div>';
$texte .= '</td>';
$texte .= '</tr>';

$texte .= '</table>';
$texte .= '</form>';

Expand Down Expand Up @@ -271,6 +301,9 @@
$result = 0;
$code = strtoupper(trim($code));

if (getDolGlobalString('COMPANY_ELEPHANT_DATE_START_ENABLE') == 1 && $soc->date_creation < getDolGlobalString('COMPANY_ELEPHANT_DATE_START')) {
return -5;
}
if (empty($code) && $this->code_null && !getDolGlobalString('MAIN_COMPANY_CODE_ALWAYS_REQUIRED')) {
$result = 0;
} elseif (empty($code) && (!$this->code_null || getDolGlobalString('MAIN_COMPANY_CODE_ALWAYS_REQUIRED'))) {
Expand Down
2 changes: 2 additions & 0 deletions htdocs/langs/en_US/admin.lang
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ GenericMaskCodes4b=<u>Example on third party created on 2023-01-31:</u><br>
GenericMaskCodes4c=<u>Example on product created on 2023-01-31:</u><br>
GenericMaskCodes5=<b>ABC{yy}{mm}-{000000}</b> will give <b>ABC2301-000099</b><br><b>{0000+100@1}-ZZZ/{dd}/XXX</b> will give <b>0199-ZZZ/31/XXX</b><br><b>IN{yy}{mm}-{0000}-{t}</b> will give <b>IN2301-0099-A</b> if the type of company is 'Responsable Inscripto' with code for type that is 'A_RI'
GenericNumRefModelDesc=Returns a customizable number according to a defined mask.
DateStartThatModel=Do not check customer numbers created before
DateStartThatModelHelp=You can disable elephant number check for customers created before a date (used for migration from an other erp for example). Let that field empty to check all customers numbers.
ServerAvailableOnIPOrPort=Server is available at address <b>%s</b> on port <b>%s</b>
ServerNotAvailableOnIPOrPort=Server is not available at address <b>%s</b> on port <b>%s</b>
DoTestServerAvailability=Test server connectivity
Expand Down
Loading