(function () {
var appId = $.context.getCurrentApplicationId();
var doc = $.context.getCurrentDocument();
var position = doc.getElementByName("申请人职位").getValue();
var subDocs = doc.getElementByName("明细").getSubDocuments();
var costCenter = doc.getElementByName("所属成本中心").getValue();
var tripCity = doc.getElementByName("出差城市").getValue();
var day = doc.getElementByName("实际出差天数").getIntValue();
//遍历子表单数据
for (var i = 0; i < subDocs.size(); i++) {
var subDoc = subDocs.get(i);
var subject = subDoc.getElementByName("科目_复制").getValue();
var category = subDoc.getElementByName("预算大类复制").getValue();
var count = subDoc.getElementByName("单价").getDoubleValue();
if (subject != "研发费用-差旅费住宿" && subject != "管理费用-差旅费住宿" && subject != "销售费用-差旅费-住宿") {
//表单名称
var formName = "职位单次报销限制";
//控件值键对
var conditionMap = new Packages.java.util.HashMap();
conditionMap.put("职位名称", position);
conditionMap.put("科目名称_复制", subject);
var limits = $.form.getDocumentsByCondition(appId, formName, conditionMap);
if (limits != null && limits.size() > 0) {
for (var k = 0; k < limits.size(); k++) {
var limit = limits.get(k);
var amount = limit.getElementByName("单次最高报销金额").getDoubleValue();
if (amount < count) {
var message = $.validate.create();
message.addError(subject + "222超额,请调整发票金额");
return message;
}
}
}
} else {
if (tripCity == "1") {
if (day * 500 < count) {
var message = $.validate.create();
message.addError(subject + "超额,请调整发票金额");
return message;
}
}
if (tripCity == "2") {
if (day * 300 < count) {
var message = $.validate.create();
message.addError(subject + "超额,请调整发票金额");
return message;
}
}
}
//表单名称
var formNametwo = "预算明细";
//控件值键对
var filedMap = new Packages.java.util.HashMap();
filedMap.put("成本中心名称", costCenter);
filedMap.put("预算大类名称", category);
var budgets = $.form.getDocumentsByCondition(appId, formNametwo, filedMap);
if (budgets != null && budgets.size() > 0) {
for (var j = 0; j < budgets.size(); j++) {
var budget = budgets.get(j);
var availableBudget = budget.getElementByName("可用预算").getDoubleValue();
if (availableBudget < count) {
var message = $.validate.create();
message.addError(category + "可用金额不足,请去申请预算后填写");
return message;
}
}
}
}
var appId = $.context.getCurrentApplicationId();
var doc = $.context.getCurrentDocument();
//var departmentId = doc.getElementByName("申请人部门").getValue();
var time = doc.getElementByName("单据日期").getValue();
var center = doc.getElementByName("所属成本中心").getValue();
var centerCode = doc.getElementByName("成本中心编码").getValue();
var subDocuments = doc.getElementByName("明细").getSubDocuments();
//var departmentManagers = $.contact.listDepartmentManagersByDepartmentId(departmentId);
var timestamp = time;
//获取日期对象
var dateObject1 = $.date.timestampToDate(timestamp);
//日期格式
var format = "MM-dd";
//获取日期字符串
var dateStr = $.date.dateToString(dateObject1, format);
for (var i = 0; i < subDocuments.size(); i++) {
var subDocument = subDocuments.get(i);
var budget = subDocument.getElementByName("预算大类复制").getValue();
//表单名称
var formName = "预算明细";
//控件值键对
var conditionMap = new Packages.java.util.HashMap();
conditionMap.put("预算大类名称", budget);
conditionMap.put("成本中心名称", center);
// conditionMap.put("成本中心编码",centerCode);
var aggregates = $.form.getDocumentsByCondition(appId, formName, conditionMap);
for (var j = 0; j < aggregates.size(); j++) {
var aggregate = aggregates.get(j);
var available = aggregate.getElementByName("已使用预算").getIntValue();
var one = aggregate.getElementByName("第一季度").getIntValue();
var two = aggregate.getElementByName("第二季度").getIntValue();
var three = aggregate.getElementByName("第三季度").getIntValue();
var four = aggregate.getElementByName("第四季度").getIntValue();
var a = one + two;
var b = one + two + three;
var c = one + two + three + four;
if ("01-01" <= dateStr <= "03-31") {
if (available > one) {
//站内信标题
var subject = "站内信的标题";
//站内信正文
var context = "第一季度预算已使用完毕";
//接收用户id集合
var receiveUserIds = $.context.getCurrentUserId();
//发送站内信
$.message.sendGeneralStationMessage(subject, context, receiveUserIds);
}
if (available > a) {
//站内信标题
var subject = "站内信的标题";
//站内信正文
var context = "第二季度预算已使用完毕";
//接收用户id集合
var receiveUserIds = $.context.getCurrentUserId();
//发送站内信
$.message.sendGeneralStationMessage(subject, context, receiveUserIds);
}
if (available > b) {
//站内信标题
var subject = "站内信的标题";
//站内信正文
var context = "第三季度预算已使用完毕";
//接收用户id集合
var receiveUserIds = $.context.getCurrentUserId();
//发送站内信
$.message.sendGeneralStationMessage(subject, context, receiveUserIds);
}
if (available > c) {
//站内信标题
var subject = "站内信的标题";
//站内信正文
var context = "第四季度预算已使用完毕";
//接收用户id集合
var receiveUserIds = $.context.getCurrentUserId();
//发送站内信
$.message.sendGeneralStationMessage(subject, context, receiveUserIds);
}
}
if ("04-01" <= dateStr <= "06-30") {
if (available > a) {
//站内信标题
var subject = "站内信的标题";
//站内信正文
var context = "第二季度预算已使用完毕";
//接收用户id集合
var receiveUserIds = $.context.getCurrentUserId();
//发送站内信
$.message.sendGeneralStationMessage(subject, context, receiveUserIds);
}
if (available > b) {
//站内信标题
var subject = "站内信的标题";
//站内信正文
var context = "第三季度预算已使用完毕";
//接收用户id集合
var receiveUserIds = $.context.getCurrentUserId();
//发送站内信
$.message.sendGeneralStationMessage(subject, context, receiveUserIds);
}
if (available > c) {
//站内信标题
var subject = "站内信的标题";
//站内信正文
var context = "第四季度预算已使用完毕";
//接收用户id集合
var receiveUserIds = $.context.getCurrentUserId();
//发送站内信
$.message.sendGeneralStationMessage(subject, context, receiveUserIds);
}
}
if ("07-01" <= dateStr <= "09-30") {
if (available > b) {
//站内信标题
var subject = "站内信的标题";
//站内信正文
var context = "第三季度预算已使用完毕";
//接收用户id集合
var receiveUserIds = $.context.getCurrentUserId();
//发送站内信
$.message.sendGeneralStationMessage(subject, context, receiveUserIds);
}
if (available > c) {
//站内信标题
var subject = "站内信的标题";
//站内信正文
var context = "第四季度预算已使用完毕";
//接收用户id集合
var receiveUserIds = $.context.getCurrentUserId();
//发送站内信
$.message.sendGeneralStationMessage(subject, context, receiveUserIds);
}
}
if ("10-01" <= dateStr <= "12-31") {
if (available > c) {
//站内信标题
var subject = "站内信的标题";
//站内信正文
var context = "第四季度预算已使用完毕";
//接收用户id集合
var receiveUserIds = $.context.getCurrentUserId();
//发送站内信
$.message.sendGeneralStationMessage(subject, context, receiveUserIds);
}
}
}
}
})()
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!