NEW: holiday: handle monthly updates with cronjob

This commit is contained in:
Marc de Lima Lucio
2021-06-10 21:53:06 +02:00
parent d4ca6bf42a
commit 1e7df0ba9f
7 changed files with 25 additions and 19 deletions

View File

@@ -135,6 +135,28 @@ class modHoliday extends DolibarrModules
//$r++;
// Cronjobs
$arraydate = dol_getdate(dol_now());
$datestart = dol_mktime(4, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
$this->cronjobs = array(
0 => array(
'label' => 'HolidayBalanceMonthlyUpdate',
'jobtype' => 'method',
'class' => 'holiday/class/holiday.class.php',
'objectname' => 'Holiday',
'method' => 'updateBalance',
'parameters' => '',
'comment' => 'Update holiday balance every month',
'frequency' => 1,
'unitfrequency' => 3600 * 24,
'priority' => 50,
'status' => 1,
'test' => '$conf->holiday->enabled',
'datestart' => $datestart
)
);
// Permissions
$this->rights = array(); // Permission array used by this module
$r = 0;

View File

@@ -227,7 +227,7 @@ class Holiday extends CommonObject
if ($result >= 0) {
$this->db->commit();
return 1;
return 0; // for cronjob use (0 is OK, any other value is an error code)
} else {
$this->db->rollback();
return -1;

View File

@@ -193,10 +193,6 @@ llxHeader('', $langs->trans('CPTitreMenu'));
$typeleaves = $holiday->getTypes(1, 1);
$result = $holiday->updateBalance(); // Create users into table holiday if they don't exists. TODO Remove this whif we use field into table user.
if ($result < 0) {
setEventMessages($holiday->error, $holiday->errors, 'errors');
}
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';

View File

@@ -231,9 +231,6 @@ $formfile = new FormFile($db);
$fuser = new User($db);
$holidaystatic = new Holiday($db);
// Update sold
$result = $object->updateBalance();
$title = $langs->trans('CPTitreMenu');
llxHeader('', $title);

View File

@@ -68,16 +68,6 @@ if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INF
$max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
/*
* Actions
*/
// Update sold
if (!empty($conf->holiday->enabled) && !empty($setupcompanynotcomplete)) {
$holidaystatic = new Holiday($db);
$result = $holidaystatic->updateBalance();
}
/*
* View

View File

@@ -132,3 +132,4 @@ FreeLegalTextOnHolidays=Free text on PDF
WatermarkOnDraftHolidayCards=Watermarks on draft leave requests
HolidaysToApprove=Holidays to approve
NobodyHasPermissionToValidateHolidays=Nobody has permission to validate holidays
HolidayBalanceMonthlyUpdate=Monthly update of holiday balance

View File

@@ -366,6 +366,6 @@ class HolidayTest extends PHPUnit\Framework\TestCase
$localobjecta->updateConfCP('lastUpdate', '20100101120000');
$result = $localobjecta->updateBalance();
$this->assertEquals($result, 1);
$this->assertEquals($result, 0);
}
}