2
0
forked from Wavyzz/dolibarr

Compare commits

...

7 Commits
21.0.2 ... 16.0

Author SHA1 Message Date
ldestailleur
bd2aba1a2f Merge branch '15.0' of git@github.com:Dolibarr/dolibarr.git into 16.0 2025-09-25 11:54:59 +02:00
ldestailleur
a4601686a6 Merge branch '14.0' of git@github.com:Dolibarr/dolibarr.git into 15.0 2025-09-25 11:54:18 +02:00
lvessiller-opendsi
bcf6d6a7a2 FIX api orders : forward database error on failure (backpot commit d9e81cb) (#35478) 2025-09-25 11:47:51 +02:00
lvessiller-opendsi
e818bf732d FIX extra field list depend on parent list when editing a card (#35165) 2025-09-01 19:55:00 +02:00
Maxime Kohlhaas
b3a2257638 Fix : contract line activation error when duration not defined (#34813)
* Fix : contract line activation error when duration not defined

* Fix of fix

* Update card.php

---------

Co-authored-by: x <x@x.x>
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-08-06 21:22:47 +02:00
VIAL-GOUTEYRON Quentin
154a25f8cb Enhance working days calculation to incorporate half-day adjustments and optimize public holiday checks (#34552)
* "Enhance working days calculation to incorporate half-day adjustments and optimize public holiday checks"

* "Add test cases for num_open_day() to validate half-day and weekend boundary scenarios"

* "Update DateLibTest to include Saturday and Sunday as non-working days in test setup"
2025-07-31 22:59:29 +02:00
Maxime Kohlhaas
6a88d31675 Fix : missing langs load on comm card file (#34812)
Co-authored-by: x <x@x.x>
2025-07-26 14:57:23 +02:00
6 changed files with 68 additions and 11 deletions

View File

@@ -64,7 +64,7 @@ if (!empty($conf->ficheinter->enabled)) {
}
// Load translation files required by the page
$langs->loadLangs(array('companies', 'banks'));
$langs->loadLangs(array('companies', 'banks', 'commercial'));
if (!empty($conf->contrat->enabled)) {
$langs->load("contracts");

View File

@@ -1182,7 +1182,7 @@ class Commande extends CommonOrder
}
}
} else {
dol_print_error($this->db);
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
}

View File

@@ -1886,7 +1886,9 @@ if ($action == 'create') {
if ($objp->fk_product > 0) {
$product = new Product($db);
$product->fetch($objp->fk_product);
$dateactend = dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
if (!empty($product->duration_value) && !empty($product->duration_unit)) {
$dateactend = dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
}
}
}

View File

@@ -8305,7 +8305,7 @@ abstract class CommonObject
$("#"+child_list).hide();
//Show mother lists
} else if ($("#"+parent_list).val() != 0){
$("#"+parent_list).show();
showOptions'.$type.'(child_list, parent_list, orig_select[child_list]);
}
//Show the child list if the parent list value is selected
$("select[name=\""+parent_list+"\"]").click(function() {

View File

@@ -997,16 +997,35 @@ function num_open_day($timestampStart, $timestampEnd, $inhour = 0, $lastday = 0,
return 'ErrorBadParameter_num_open_day';
}
//print 'num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday;
if ($timestampStart < $timestampEnd) {
$numdays = num_between_day($timestampStart, $timestampEnd, $lastday);
// --- 1. Calculate Gross Working Days ---
// Gross working days = total days in range - non-working days (weekends & public holidays).
$nbOpenDay = num_between_day($timestampStart, $timestampEnd, $lastday) - num_public_holiday($timestampStart, $timestampEnd, $country_code, $lastday);
$numholidays = num_public_holiday($timestampStart, $timestampEnd, $country_code, $lastday);
$nbOpenDay = ($numdays - $numholidays);
if ($inhour == 1 && $nbOpenDay <= 3) {
$nbOpenDay = ($nbOpenDay * 24);
// --- 2. Apply Contextual Half-Day Deductions ---
$halfday = (int) $halfday; // Ensure $halfday is an integer for reliable comparisons.
// Check if start/end days are working days just ONCE to optimize performance
// by avoiding redundant calls to the potentially slow num_public_holiday() function.
$isStartDayWorking = (num_public_holiday($timestampStart, $timestampStart, $country_code, 1) == 0);
$isEndDayWorking = (num_public_holiday($timestampEnd, $timestampEnd, $country_code, 1) == 0);
// Deduct 0.5 if the leave starts in the afternoon of a working day.
if (($halfday == -1 || $halfday == 2) && $isStartDayWorking) {
$nbOpenDay -= 0.5;
}
return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday));
// Deduct 0.5 if the leave ends in the morning of a different, working day.
if (($halfday == 1 || $halfday == 2) && date('Y-m-d', $timestampStart) != date('Y-m-d', $timestampEnd) && $isEndDayWorking) {
$nbOpenDay -= 0.5;
}
// --- 3. Return Final Value ---
if ($inhour == 1) {
return $nbOpenDay * 24;
}
return $nbOpenDay;
} elseif ($timestampStart == $timestampEnd) {
$numholidays = 0;
if ($lastday) {

View File

@@ -303,6 +303,42 @@ class DateLibTest extends PHPUnit\Framework\TestCase
$result=num_open_day($date1, $date2, 'XX', 1);
print __METHOD__." result=".$result."\n";
$this->assertEquals(3, $result, 'NumOpenDay for XX when saturday + sunday are working days'); // 3 opened day, 0 closes (even if country unknown)
// Define specific dates for these tests
$date_friday_4 = dol_mktime(0, 0, 0, 1, 4, 2013, 'gmt'); // Friday
$date_saturday_5 = dol_mktime(0, 0, 0, 1, 5, 2013, 'gmt'); // Saturday
$date_monday_7 = dol_mktime(0, 0, 0, 1, 7, 2013, 'gmt'); // Monday
$date_friday_11 = dol_mktime(0, 0, 0, 1, 11, 2013, 'gmt'); // Following Friday
// Case 1: Weekend Boundary (Friday morning -> Saturday morning)
// Expected: 1 day. No half-day deduction for end date on a non-working day.
// $starthalfday = 'morning', $endhalfday = 'morning' -> $halfday = 1
$conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY = 1;
$conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY = 1;
$result = num_open_day($date_friday_4, $date_saturday_5, 0, 1, 1, 'FR');
print __METHOD__." result=".$result."\n";
$this->assertEquals(1, $result, 'Case 1: Friday morning to Saturday morning should be 1 day');
// Case 2: Full week with half-day (Friday morning -> Following Friday morning)
// Expected: 5.5 days.
// $starthalfday = 'morning', $endhalfday = 'morning' -> $halfday = 1
$result = num_open_day($date_friday_4, $date_friday_11, 0, 1, 1, 'FR');
print __METHOD__." result=".$result."\n";
$this->assertEquals(5.5, $result, 'Case 2: Friday morning to next Friday morning should be 5.5 days');
// Case 3: Single Half-Day (Monday afternoon)
// Expected: 0.5 days.
// $starthalfday = 'afternoon' -> $halfday = -1
$result = num_open_day($date_monday_7, $date_monday_7, 0, 1, -1, 'FR');
print __METHOD__." result=".$result."\n";
$this->assertEquals(0.5, $result, 'Case 3: A single Monday afternoon should be 0.5 days');
// Case 4: Standard Leave (Monday morning -> Friday evening)
// Expected: 5 days.
// $starthalfday = 'morning', $endhalfday = 'evening' -> $halfday = 0
$result = num_open_day($date_monday_7, $date_friday_11, 0, 1, 0, 'FR');
print __METHOD__." result=".$result."\n";
$this->assertEquals(5, $result, 'Case 4: Monday morning to Friday evening should be 5 days');
}
/**