Skip to main content

Limit leave days by formula

This case is from Jing, a three-party developer 」

1. Usage scenarios

Many users will use YIDA for attendance management, especially leave management. It is necessary to check the annual leave duration of each employee. Please do not exceed the annual leave duration stipulated by the company, however, there is no restriction when taking sick leave or personal leave or other vacation categories.

2. Implement functions

2.1 Configuration page

(1) employee holiday duration

It is used to record the vacation duration of different types of holidays for employees.

(2) leave application

2.2 configure page functions

Modify the component identifier as needed.

(1) Data Linkage

Configure data linkage to link out the remaining vacation days.

(2) formula editing

Configure formula editing to calculate the duration of leave.

{"text":"DAYS(DATE(​请假结束时间​),DATE(​请假开始时间​))","marks":[{"from":{"line":0,"ch":10,"sticky":null},"to":{"line":0,"ch":18,"sticky":null},"value":"dateField_ksudx6ym","invalid":false},{"from":{"line":0,"ch":25,"sticky":null},"to":{"line":0,"ch":33,"sticky":null},"value":"dateField_ksudx6yk","invalid":false}],"isCmData":true}

(3) configure the pre-submission event on the page

Configure pre-submission events on the page to query the remaining leave days in real time before submission to avoid data errors caused by multiple submissions.

Reference documents:Search form instance details by criteria

The interface configuration is as follows:

Bind the following events:

export function beforeSubmit({ formDataMap }) {
// 注意:目前不支持在这里修改提交数据
return new Promise(resolve => {
this.dataSourceMap.getData.load({
formUuid: 'FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7',
searchFieldJson: JSON.stringify({
employeeField_ksu8iqm5: [this.$('employeeField_ksudx6yc').getValue()[0].value],
dateField_lc48ia6n: [this.$('dateField_lc48iwz8').getValue() - 1, this.$('dateField_lc48iwz8').getValue() + 1],
radioField_lc73huhr: this.$('radioField_ksudx6yi').getValue()
})
}).then(res => {
const { totalCount, data } = res;
if (!totalCount) {
this.utils.toast({
title: '该类型假期定额不足',
type: 'error',
});
resolve(false);
} else {
const { formData } = data[0];
const days = this.$('numberField_ksudx6yo').getValue(); // 请假时长
if (days > formData.numberField_ksu8iqm9) {
this.utils.toast({
title: '该类型假期定额不足,请重新提交',
type: 'error',
});
resolve(false);
} else {
resolve(true);
};
};
}).catch(error => {
this.utils.toast({
title: error.message,
type: 'error',
});
resolve(false);
});
});
}

(4) process configuration Business Association rules

When an employee initiates a leave, the holiday balance is deducted. If the approval is rejected or the initiator cancels it, the deduction amount is released. If the corresponding type of holiday quota is insufficient, the submission is blocked.

{"text":"UPDATE(​员工假期时长表​,AND(EQ(​员工假期时长表.员工姓名​,​请假人​),EQ(​员工假期时长表.年份​,​年份​),EQ(​员工假期时长表.假期类型​,​请假类型​)),\"\",​员工假期时长表.假期时长​,​员工假期时长表.假期时长​-​请假时长​)","marks":[{"from":{"line":0,"ch":7,"sticky":null},"to":{"line":0,"ch":16,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/","invalid":false},{"from":{"line":0,"ch":24,"sticky":null},"to":{"line":0,"ch":38,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/employeeField_ksu8iqm5","invalid":false},{"from":{"line":0,"ch":39,"sticky":null},"to":{"line":0,"ch":44,"sticky":null},"value":"employeeField_ksudx6yc","invalid":false},{"from":{"line":0,"ch":49,"sticky":null},"to":{"line":0,"ch":61,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/dateField_lc48ia6n","invalid":false},{"from":{"line":0,"ch":62,"sticky":null},"to":{"line":0,"ch":66,"sticky":null},"value":"dateField_lc48iwz8","invalid":false},{"from":{"line":0,"ch":71,"sticky":null},"to":{"line":0,"ch":85,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/radioField_lc73huhr","invalid":false},{"from":{"line":0,"ch":86,"sticky":null},"to":{"line":0,"ch":92,"sticky":null},"value":"radioField_ksudx6yi","invalid":false},{"from":{"line":0,"ch":98,"sticky":null},"to":{"line":0,"ch":112,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/numberField_ksu8iqm9","invalid":false},{"from":{"line":0,"ch":113,"sticky":null},"to":{"line":0,"ch":127,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/numberField_ksu8iqm9","invalid":false},{"from":{"line":0,"ch":128,"sticky":null},"to":{"line":0,"ch":134,"sticky":null},"value":"numberField_ksudx6yo","invalid":false}],"isCmData":true}

{"text":"UPDATE(​员工假期时长表​,AND(EQ(​员工假期时长表.员工姓名​,​请假人​),EQ(​员工假期时长表.年份​,​年份​),EQ(​员工假期时长表.假期类型​,​请假类型​)),\"\",​员工假期时长表.假期时长​,​员工假期时长表.假期时长​+​请假时长​)","marks":[{"from":{"line":0,"ch":7,"sticky":null},"to":{"line":0,"ch":16,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/","invalid":false},{"from":{"line":0,"ch":24,"sticky":null},"to":{"line":0,"ch":38,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/employeeField_ksu8iqm5","invalid":false},{"from":{"line":0,"ch":39,"sticky":null},"to":{"line":0,"ch":44,"sticky":null},"value":"employeeField_ksudx6yc","invalid":false},{"from":{"line":0,"ch":49,"sticky":null},"to":{"line":0,"ch":61,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/dateField_lc48ia6n","invalid":false},{"from":{"line":0,"ch":62,"sticky":null},"to":{"line":0,"ch":66,"sticky":null},"value":"dateField_lc48iwz8","invalid":false},{"from":{"line":0,"ch":71,"sticky":null},"to":{"line":0,"ch":85,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/radioField_lc73huhr","invalid":false},{"from":{"line":0,"ch":86,"sticky":null},"to":{"line":0,"ch":92,"sticky":null},"value":"radioField_ksudx6yi","invalid":false},{"from":{"line":0,"ch":98,"sticky":null},"to":{"line":0,"ch":112,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/numberField_ksu8iqm9","invalid":false},{"from":{"line":0,"ch":113,"sticky":null},"to":{"line":0,"ch":127,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/numberField_ksu8iqm9","invalid":false},{"from":{"line":0,"ch":128,"sticky":null},"to":{"line":0,"ch":134,"sticky":null},"value":"numberField_ksudx6yo","invalid":false}],"isCmData":true}

{"text":"OR(ISEMPTY(​剩余假期天数​),GT(​请假时长​,​剩余假期天数​))","marks":[{"from":{"line":0,"ch":11,"sticky":null},"to":{"line":0,"ch":19,"sticky":null},"value":"numberField_ksudx6yg","invalid":false},{"from":{"line":0,"ch":24,"sticky":null},"to":{"line":0,"ch":30,"sticky":null},"value":"numberField_ksudx6yo","invalid":false},{"from":{"line":0,"ch":31,"sticky":null},"to":{"line":0,"ch":39,"sticky":null},"value":"numberField_ksudx6yg","invalid":false}],"isCmData":true}

3. Achieve results

4. Try it online

This doc is generated using machine translation. Any discrepancies or differences created in the translation are not binding and have no legal effect for compliance or enforcement purposes.
Copyright © 2024钉钉(中国)信息技术有限公司和/或其关联公司浙ICP备18037475号-4