Beispiel #1
0
/**
 * Remove holidays
 *
 * @since 0.1
 *
 * @return \stdClass
 */
function erp_hr_delete_holidays($holidays_id)
{
    if (is_array($holidays_id)) {
        foreach ($holidays_id as $key => $holiday_id) {
            do_action('erp_hr_leave_holiday_delete', $holiday_id);
        }
        \WeDevs\ERP\HRM\Models\Leave_Holiday::destroy($holidays_id);
    } else {
        do_action('erp_hr_leave_holiday_delete', $holidays_id);
        return \WeDevs\ERP\HRM\Models\Leave_Holiday::find($holidays_id)->delete();
    }
}
Beispiel #2
0
 /**
  * Add log when edit holiday
  *
  * @since 0.1
  *
  * @param  integer $holiday_id
  * @param  array $fields
  *
  * @return void
  */
 public function update_holiday($holiday_id, $fields)
 {
     if (!$holiday_id) {
         return;
     }
     $old_holiday = \WeDevs\ERP\HRM\Models\Leave_Holiday::find($holiday_id)->toArray();
     unset($old_holiday['created_at'], $old_holiday['updated_at']);
     $old_holiday['start'] = erp_format_date($old_holiday['start'], 'Y-m-d');
     $old_holiday['end'] = erp_format_date($old_holiday['end'], 'Y-m-d');
     $fields['start'] = erp_format_date($fields['start'], 'Y-m-d');
     $fields['end'] = erp_format_date($fields['end'], 'Y-m-d');
     $changes = $this->get_array_diff($fields, $old_holiday, true);
     if (empty($changes['old_val']) && empty($changes['new_val'])) {
         $message = false;
     } else {
         array_walk($changes, function (&$key) {
             if (isset($key['start'])) {
                 $key['start_date'] = erp_format_date($key['start']);
                 unset($key['start']);
             }
             if (isset($key['end'])) {
                 $key['end_date'] = erp_format_date($key['end']);
                 unset($key['end']);
             }
         });
         $message = sprintf('<strong>%s</strong> holiday has been edited', $old_holiday['title']);
     }
     if ($message) {
         erp_log()->add(['sub_component' => 'leave', 'message' => $message, 'created_by' => get_current_user_id(), 'changetype' => 'edit', 'old_value' => $changes['old_val'] ? base64_encode(maybe_serialize($changes['old_val'])) : '', 'new_value' => $changes['new_val'] ? base64_encode(maybe_serialize($changes['new_val'])) : '']);
     }
 }