> For the complete documentation index, see [llms.txt](https://docs.coreway.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coreway.com/yoov-work/zh-hk/salary-management/custom-formula.md).

# 自定義公式

### 遲到、早退、缺勤、加班 <a href="#late-early-leave-absent-overtime" id="late-early-leave-absent-overtime"></a>

遲到及早退時間可以使用同一個時間單位混合計算，例如：遲到/早退每月累計3 次 , 且遲到/早退時長在15分鐘內不扣款?

```
SUM(FORDATE(#计薪週期-開始日期#,#计薪週期-結束日期#,IF(AND(#出勤.遲到次數#+#出勤.早退次數#≤3,#出勤.遲到分钟數#+#出勤.早退分钟數#≤15),0,100)))
```

加班錢是當月工資/該月天數/當天工時，可以如何自訂義?

```
SUM(FORDATE(#计薪週期-開始日期#,#计薪週期-結束日期#,#固定工資#/#月計薪天數#/IF(#班次.工作時長#=0,8,#班次.工作時長#)*#出勤.加班時長#))
```

上班超過10小時及23:50後下班,滿足兩項條件有$70?

```
SUM(FORDATE(#计薪週期-開始日期#, #计薪週期-結束日期#, IF(AND(出勤.工作時長>10,SUM(FORSHIFT(班次.上下班次數,IF(HOUR(IFNA(出勤.下班打卡時間, 0))*100+MINUTE(IFNA(出勤.下班打卡時間,0))>2350,1,0)))>0),70,0)))
```

缺勤: 上月固定工資/上月天數\*上月缺勤天數

```
HISTORYSALARY(#固定工资#, 1, #固定工资#)/HISTORYATTENDANCE(EDATE(#计薪周期-开始日期#,-1),EOMONTH(#计薪周期-开始日期#,-1),#该月天数#)*HISTORYATTENDANCE(EDATE(#计薪周期-开始日期#,-1),EOMONTH(#计薪周期-开始日期#,-1),#缺勤天数#)
```

加班是按班次下班時間和下班打卡時間計薪\
18:00 之前 是時薪 x 1\
18:00 - 00:00 是時薪 x 1.5\
00:00 - 08:00 是時薪 x 2, 請問需要怎樣設定?\
例如員工A班次下班時間是17:00, 加班到01:00\
計算 = 1 x 時薪 x 1 (18:00 之前) + 6 x 時薪 x 1.5 (18:00 - 00:00) + 1 x 時薪 x 2 (00:00 - 08:00)

```
SUM(FORDATE(#計薪周期-開始日期#, #計薪周期-結束日期#, SUM(FORSHIFT(#班次.上下班次數#, IF(#班次循環變量# = #班次.上下班次數#, IFERROR(QUOTIENT(MAX(MIN(DATEDIF(#循環變量#, #出勤.下班打卡時間#, 'D') * 24 * 60 + HOUR(#出勤.下班打卡時間#) * 60 + MINUTE(#出勤.下班打卡時間#), 1080) - MIN(DATEDIF(#循環變量#, #班次.下班時間#, 'D') * 24 * 60 + HOUR(#班次.下班時間#) * 60 + MINUTE(#班次.下班時間#), 1080), 0), 30)*0.5 * 1 + QUOTIENT(MAX(MIN(DATEDIF(#循環變量#, #出勤.下班打卡時間#, 'D') * 24 * 60 + HOUR(#出勤.下班打卡時間#) * 60 + MINUTE(#出勤.下班打卡時間#), 1440) - MIN(MAX(DATEDIF(#循環變量#, #班次.下班時間#, 'D') * 24 * 60 + HOUR(#班次.下班時間#) * 60 + MINUTE(#班次.下班時間#), 1080), 1440), 0), 30) *0.5* 1.5 + QUOTIENT(MAX(MIN(DATEDIF(#循環變量#, #出勤.下班打卡時間#, 'D') * 24 * 60 + HOUR(#出勤.下班打卡時間#) * 60 + MINUTE(#出勤.下班打卡時間#), 1920) - MIN(MAX(DATEDIF(#循環變量#, #班次.下班時間#, 'D') * 24 * 60 + HOUR(#班次.下班時間#) * 60 + MINUTE(#班次.下班時間#), 1440), 1920), 0), 30)*0.5 * 2 , 0), 0)))))
```

### 勤工獎 <a href="#attendance-bonus" id="attendance-bonus"></a>

勤工獎: 當月上班95小時以上+ 遲到少於15mins才有$500

```
IF(AND(#總工作時長#>95, SUM(FORDATE(#計薪周期-開始日期#, #計薪周期-結束日期#, #出勤.遲到分鐘數#))<15), 500, 0)
```

### 津貼 <a href="#allowance" id="allowance"></a>

當上班日子是星期日的班次A才有津貼

```
100*SUM(FORDATE(#計薪周期-開始日期#, #計薪周期-結束日期#, IF(AND(#班次#=#春节班次#, WEEKDAY(#循環變量#) ≥5), 1, 0)))
```

只限農曆新年3日,不是所有公眾/法定假期，上班就會有固定工資/當月天數\*2

```
SUM(FORDATE(#計薪周期-開始日期#, #計薪周期-結束日期#, IF(AND(#班次.工作時長# > 0, OR(ISHOLIDAY(#法定假日.農曆年初一#, #循環變量#), ISHOLIDAY(#法定假日.農曆年初二#, #循環變量#), ISHOLIDAY(#法定假日.農曆年初三#, #循環變量#))), #固定工資#/#該月天數#*2, 0)))
```

津貼: 按上月工作地點A\*次數, 一次100元

```
SUM(FORDATE(EDATE(#计薪周期-开始日期#, -1), EOMONTH(#计薪周期-开始日期#, -1), SUM(FORSHIFT(#班次.上下班次数#, IF(#班次.工作地点#=#总部#, 1, 0)))))*100
```

### 其他 <a href="#others" id="others"></a>

入職滿6個月有9千元新人獎,如何設置?

```
IF(DATEDIF(#入職日期#,#計薪週期-結束日期#,'M')=6,9000,0)
```

員工沒有遲到就正常按照第一個月600，第二個600，第三個月有遲到就 0，沒有遲到就1200，第四個月從頭開始計 600

```
MAX(SUM(FORARRAY([1, 2], IF(HISTORYSALARY(#額外勤工獎#, #循環變量#, 0) = 600 , 1, 0))), 1) * IF(SUM(FORDATE(#計薪周期-開始日期#, #計薪周期-結束日期#, #出勤.遲到次數#)) > 0 , 0, 600)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.coreway.com/yoov-work/zh-hk/salary-management/custom-formula.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
