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

Enhancement - Calendario laboral - Añadir nuevo tipo: Anulado #425

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3244,6 +3244,7 @@
$app_list_strings['stic_work_calendar_types_list']['sick'] = 'Baixa';
$app_list_strings['stic_work_calendar_types_list']['leave'] = 'Permís/Excedència';
$app_list_strings['stic_work_calendar_types_list']['other'] = 'Altres';
$app_list_strings['stic_work_calendar_types_list']['canceled'] = 'Anul·lat';

// Diari: Tipus
$app_list_strings['stic_journal_types_list'][''] = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3243,6 +3243,7 @@
$app_list_strings['stic_work_calendar_types_list']['sick'] = 'Sick';
$app_list_strings['stic_work_calendar_types_list']['leave'] = 'Leave';
$app_list_strings['stic_work_calendar_types_list']['other'] = 'Other';
$app_list_strings['stic_work_calendar_types_list']['canceled'] = 'Canceled';

// Journal: Type
$app_list_strings['stic_journal_types_list'][''] = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3244,6 +3244,7 @@
$app_list_strings['stic_work_calendar_types_list']['sick'] = 'Baja';
$app_list_strings['stic_work_calendar_types_list']['leave'] = 'Permiso/Excedencia';
$app_list_strings['stic_work_calendar_types_list']['other'] = 'Otros';
$app_list_strings['stic_work_calendar_types_list']['canceled'] = 'Anulado';

// Diario: Tipo de diario
$app_list_strings['stic_journal_types_list'][''] = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3245,6 +3245,7 @@
$app_list_strings['stic_work_calendar_types_list']['sick'] = 'Baixa';
$app_list_strings['stic_work_calendar_types_list']['leave'] = 'Permiso/Excedencia';
$app_list_strings['stic_work_calendar_types_list']['other'] = 'Outros';
$app_list_strings['stic_work_calendar_types_list']['canceled'] = 'Anulado';

// Diario: Tipo de diario
$app_list_strings['stic_journal_types_list'][''] = '';
Expand Down
6 changes: 6 additions & 0 deletions custom/modules/Calendar/CalendarActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ public static function get_activities(
$act = new CustomCalendarActivity($focusBean);

if (!empty($act)) {
// STIC-Custom 20241004 MHP - Exclude cancelled work calendar records from displaying them in the Activity Calendar
// https://github.com/SinergiaTIC/SinergiaCRM/pull/425
if ($act->sugar_bean->module_dir === 'stic_Work_Calendar' && $act->sugar_bean->type == 'canceled' ) {
continue;
}
// END STIC-Custom
$act_list[] = $act;
}
}
Expand Down
6 changes: 6 additions & 0 deletions modules/iCals/iCal.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ protected function createSugarIcal(&$user_bean, &$start_date_time, &$end_date_ti
foreach ($acts_arr as $act) {
$event = $act->sugar_bean;
if (!$hide_calls || ($hide_calls && $event->object_name != "Call")) {
// STIC-Custom 20241004 MHP - Exclude canceled work calendar records from synchronization
// https://github.com/SinergiaTIC/SinergiaCRM/pull/425
if ($event->module_dir == "stic_Work_Calendar" && $event->type == 'canceled'){
continue;
}
// END STIC-Custom
$ical_array[] = array("BEGIN", "VEVENT");
// STIC-Custom 20220315 AAM - Encoding the activity name to UTF8 in order to display special characters
// $ical_array[] = array("SUMMARY", $event->name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function prepareSQL(stic_Validation_Actions $actionBean, $proposedSQL)
JOIN users_cstm as swcu ON swc.assigned_user_id = swcu.id_c
WHERE DATE(CONVERT_TZ(swc.start_date, '+00:00', '" . $tzone ."')) BETWEEN DATE(DATE_SUB(CONVERT_TZ(UTC_TIMESTAMP(), '+00:00', '" . $tzone ."'), INTERVAL 7 DAY)) AND DATE(DATE_SUB(CONVERT_TZ(UTC_TIMESTAMP(), '+00:00', '" . $tzone ."'), INTERVAL 1 DAY))
AND swc.type = 'working'
AND swc.type != 'canceled'
AND swc.deleted = 0
GROUP BY swc.assigned_user_id) AS wc
ON tt.assigned_user_id = wc.assigned_user_id
Expand All @@ -80,11 +81,13 @@ public function prepareSQL(stic_Validation_Actions $actionBean, $proposedSQL)
FROM stic_work_calendar swc
JOIN users_cstm as swcu ON swc.assigned_user_id = swcu.id_c
WHERE DATE(CONVERT_TZ(swc.start_date, '+00:00', '" . $tzone ."')) BETWEEN DATE(DATE_SUB(CONVERT_TZ(UTC_TIMESTAMP(), '+00:00', '" . $tzone ."'), INTERVAL 7 DAY)) AND DATE(DATE_SUB(CONVERT_TZ(UTC_TIMESTAMP(), '+00:00', '" . $tzone ."'), INTERVAL 1 DAY))
AND swc.type = 'working'
AND swc.type = 'working'
AND swc.type != 'canceled'
AND swc.deleted = 0
GROUP BY swc.assigned_user_id) AS wc
ON tt.assigned_user_id = wc.assigned_user_id;";

$GLOBALS['log']->error('Line ' . __LINE__ . ': ' . __METHOD__ . ': SQL: ' . $sql);
return $sql;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function prepareSQL(stic_Validation_Actions $actionBean, $proposedSQL)
FROM stic_work_calendar
WHERE DATE(CONVERT_TZ(start_date, '+00:00', '" . $tzone ."')) = DATE(DATE_SUB(CONVERT_TZ(UTC_TIMESTAMP(), '+00:00', '" . $tzone ."'), INTERVAL 1 DAY))
AND type = 'working'
AND type != 'canceled'
AND deleted = 0
ORDER BY assigned_user_id;";

Expand Down
21 changes: 16 additions & 5 deletions modules/stic_Work_Calendar/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,28 @@ function manageAllDayView()

type.addEventListener("change", function()
{
if (!allDayTypes.includes(document.getElementById("type").value))
var typeValue = document.getElementById("type").value;
if (!allDayTypes.includes(typeValue))
{
if (allDayTypes.includes(previousType)) { // Set the previous values if the previous type was not type: all day

if (typeValue == 'canceled')
{
$("#start_date_hours").val('00');
$("#start_date_minutes").val('00');
$("#end_date_hours").val('00');
$("#end_date_minutes").val('00');
} else {
$("#start_date_hours").val(previousStartDateHours);
$("#start_date_minutes").val(previousStartDateMinutes);
$("#end_date_hours").val(previousEndDateHours);
$("#end_date_minutes").val(previousEndDateMinutes);
$("#start_date_hours").change();
$("#start_date_minutes").change();
$("#end_date_hours").change();
$("#end_date_minutes").change();
}

$("#start_date_hours").change();
$("#start_date_minutes").change();
$("#end_date_hours").change();
$("#end_date_minutes").change();

// Show the start time and the end_date section
$("#start_date_time_section").parent().show();
Expand Down
92 changes: 48 additions & 44 deletions modules/stic_Work_Calendar/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,61 +35,65 @@ class stic_Work_CalendarUtils
*/
public static function existsRecordsWithIncompatibleType($id, $startDate, $endDate, $type, $assignedUserId)
{
require_once 'modules/stic_Work_Calendar/stic_Work_Calendar.php';
if ($type != 'canceled') {
require_once 'modules/stic_Work_Calendar/stic_Work_Calendar.php';

// Check if there is already a non-work record that takes up the entire day, in that case, it is not posible to create the record
global $db, $current_user;
$tzone = $current_user->getPreference('timezone') ?? $sugar_config['default_timezone'] ?? date_default_timezone_get();
// Check if there is already a non-work record that takes up the entire day, in that case, it is not posible to create the record
global $db, $current_user;
$tzone = $current_user->getPreference('timezone') ?? $sugar_config['default_timezone'] ?? date_default_timezone_get();

$query = "SELECT * FROM stic_work_calendar
WHERE deleted = 0
AND id != '". $id . "'
AND assigned_user_id = '" . $assignedUserId . "'
AND type IN ('" . implode("', '", stic_Work_Calendar::ALL_DAY_TYPES) . "')
AND DATE(CONVERT_TZ(start_date, '+00:00', '" . $tzone ."')) = DATE(CONVERT_TZ('" . $startDate . "', '+00:00', '" . $tzone ."'))";
$query = "SELECT * FROM stic_work_calendar
WHERE deleted = 0
AND type != 'canceled'
AND id != '". $id . "'
AND assigned_user_id = '" . $assignedUserId . "'
AND type IN ('" . implode("', '", stic_Work_Calendar::ALL_DAY_TYPES) . "')
AND DATE(CONVERT_TZ(start_date, '+00:00', '" . $tzone ."')) = DATE(CONVERT_TZ('" . $startDate . "', '+00:00', '" . $tzone ."'))";

$GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": " . $query);
$result = $db->query($query);
$GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": " . $query);
$result = $db->query($query);

if (!is_null($result) && $result->num_rows > 0) {
return false;
} else {
if (in_array($type, stic_Work_Calendar::ALL_DAY_TYPES)) {
// Checks if exist a record that does not occupy the entire day, in that case, since the record to be created is an all-day record, it is not possible to create the record.
$query = "SELECT * FROM stic_work_calendar
WHERE deleted = 0
AND id != '". $id . "'
AND assigned_user_id = '" . $assignedUserId . "'
AND type NOT IN ('" . implode("', '", stic_Work_Calendar::ALL_DAY_TYPES) . "')
AND DATE(CONVERT_TZ(start_date, '+00:00', '" . $tzone ."')) = DATE(CONVERT_TZ('" . $startDate . "', '+00:00', '" . $tzone ."'))";
if (!is_null($result) && $result->num_rows > 0) {
return false;
} else {
if (in_array($type, stic_Work_Calendar::ALL_DAY_TYPES)) {
// Checks if exist a record that does not occupy the entire day, in that case, since the record to be created is an all-day record, it is not possible to create the record.
$query = "SELECT * FROM stic_work_calendar
WHERE deleted = 0
AND id != '". $id . "'
AND assigned_user_id = '" . $assignedUserId . "'
AND type != 'canceled'
AND type NOT IN ('" . implode("', '", stic_Work_Calendar::ALL_DAY_TYPES) . "')
AND DATE(CONVERT_TZ(start_date, '+00:00', '" . $tzone ."')) = DATE(CONVERT_TZ('" . $startDate . "', '+00:00', '" . $tzone ."'))";

$GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": " . $query);
$result = $db->query($query);
$GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": " . $query);
$result = $db->query($query);

if (!is_null($result) && $result->num_rows > 0) {
return false;
if (!is_null($result) && $result->num_rows > 0) {
return false;
} else {
return true;
}
} else {
return true;
}
} else {
// Checks if exist a record that does not occupy the entire day, in that case, since the record to be created is an all-day record, it is not possible to create the record.
$query = "SELECT * FROM stic_work_calendar
WHERE deleted = 0
AND id != '". $id . "'
AND assigned_user_id = '" . $assignedUserId . "'
AND type NOT IN ('" . implode("', '", stic_Work_Calendar::ALL_DAY_TYPES) . "')
AND TIMESTAMPDIFF(SECOND, start_date, '" . $endDate . "') > 0
AND TIMESTAMPDIFF(SECOND, '" . $startDate . "',end_date) > 0";
$GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": " . $query);
$result = $db->query($query);
// Checks if exist a record that does not occupy the entire day, in that case, since the record to be created is an all-day record, it is not possible to create the record.
$query = "SELECT * FROM stic_work_calendar
WHERE deleted = 0
AND id != '". $id . "'
AND assigned_user_id = '" . $assignedUserId . "'
AND type != 'canceled'
AND type NOT IN ('" . implode("', '", stic_Work_Calendar::ALL_DAY_TYPES) . "')
AND TIMESTAMPDIFF(SECOND, start_date, '" . $endDate . "') > 0
AND TIMESTAMPDIFF(SECOND, '" . $startDate . "',end_date) > 0";
$GLOBALS['log']->debug('Line ' . __LINE__ . ': ' . __METHOD__ . ": " . $query);
$result = $db->query($query);

if (!is_null($result) && $result->num_rows > 0) {
return false;
} else {
return true;
if (!is_null($result) && $result->num_rows > 0) {
return false;
}
}
}
}
return true;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion modules/stic_Work_Calendar/stic_Work_Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function save($check_notify = true)
}

/**
* Checks if the given user has a work calendar record between the previous 24 hours and now, in UTC.
* Checks if the given user has an uncancelled calendar record between the previous 24 hours and now, in UTC
* @param userId User Identificator
* @return void
*/
Expand All @@ -137,6 +137,7 @@ public static function existAtLeastOneRecordFromYesterday($userId)
$query = "SELECT count(id) as count
FROM stic_work_calendar
WHERE deleted = 0
AND type != 'canceled'
AND start_date BETWEEN DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 DAY) AND UTC_TIMESTAMP()
AND assigned_user_id = '" . $userId . "';";

Expand Down
Loading