|
|
本帖最后由 purple 于 2012-12-17 10:18 编辑
函数格式:
getCustomerSales(customerno, startDate, isLastYear, quarter)
函数说明:
Customerno : 客户号
startDate : 日期,根据此日期获取财务年
isLastYear : 是否上年
quarter : 季度,1/2/3/4
示例:
实现getCustomerSales(customerno, startDate, isLastYear, quarter)函数的应用- function getCustomerSales(customerno, startDate, isLastYear, quarter) {
- var year = "";
- var strDate = "";
- var iyear = 0; //var startDate = getItemValueAsDate("startdate");
- if (startDate != null) {
- strDate = format(startDate, "yyyy-MM-dd");
- }
- var sql = "select * from TLK_CALENDAR where '" + strDate + "' between ITEM_FROM and ITEM_TO";
- var cal = findBySQL(sql);
- year = cal.getItemValueAsString("year");
- if (year != null && year.length() > 3) {
- iyear = parseInt(year.substring(2, year.length()));
- if (isLastYear) iyear = iyear - 1;
- }
- var syear = "FY" + iyear;
- var sqlQuarter = "";
- if (quarter) {
- sqlQuarter = " and item_quarter=" + quarter;
- } //var customerno = getItemValue("customerno");
- var countSql = "select SUM(item_sales) from tlk_customersales where ITEM_customerno='" + customerno + "'"
- + " and ITEM_SALESSTARTDATE >= (select MIN(item_from) from TLK_CALENDAR where ITEM_YEAR='" + syear + "'" + sqlQuarter + ")"
- + " and ITEM_SALEENDDATE <= (select MAX(item_to) from TLK_CALENDAR where ITEM_YEAR='" + syear + "'" + sqlQuarter + ")";
- var value = sumBySQL(countSql);
- return value;
- }
复制代码 调用- #include " businesslib";
- getCustomerSales("customerno", "startDate", "isLastYear", "quarter");
复制代码 |
|