ERP导出(自定义格式表格)R报表开发代码
按照正常流程新建程序,画面修改上传,程序下载修改
导入JAVA包,在global.import下
IMPORT com
IMPORT JAVA java.net.URL
IMPORT JAVA org.apache.poi.ss.util.CellRangeAddress
IMPORT JAVA org.apache.poi.ss.util.RegionUtil
IMPORT JAVA java.io.InputStream
IMPORT JAVA java.io.FileInputStream
IMPORT JAVA java.io.FileOutputStream
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFWorkbook
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFSheet
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFRow
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFCell
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFCellStyle
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFFont
IMPORT JAVA org.apache.poi.ss.usermodel.IndexedColors
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFDataFormat
IMPORT JAVA com.fourjs.fgl.lang.FglDecimal
IMPORT JAVA com.fourjs.fgl.lang.FglDate
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFWorkbook
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFSheet
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFRow
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFCell
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFCellStyle
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFFont
IMPORT JAVA org.apache.poi.ss.usermodel.IndexedColors
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFDataFormat
IMPORT JAVA org.apache.poi.xssf.streaming.SXSSFWorkbook
IMPORT JAVA org.apache.poi.ss.usermodel.CellStyle
IMPORT JAVA org.apache.poi.ss.usermodel.Sheet
IMPORT JAVA org.apache.poi.ss.usermodel.Row
IMPORT JAVA org.apache.poi.ss.usermodel.Cell
IMPORT JAVA org.apache.poi.ss.usermodel.Font
IMPORT JAVA org.apache.poi.ss.usermodel.DataFormat
IMPORT JAVA org.apache.poi.xssf.usermodel.XSSFWorkbook
IMPORT JAVA org.apache.poi.xssf.usermodel.XSSFSheet
IMPORT JAVA org.apache.poi.xssf.usermodel.XSSFRow
IMPORT JAVA org.apache.poi.xssf.usermodel.XSSFCell
IMPORT JAVA org.apache.poi.xssf.usermodel.XSSFCellStyle
IMPORT JAVA org.apache.poi.xssf.usermodel.XSSFFont
IMPORT JAVA org.apache.poi.xssf.usermodel.XSSFDataFormat
在global.variable下添加全局变量
DEFINE g_showmsg STRING
DEFINE l_xlsfile STRING
DEFINE l_xlsname STRING
DEFINE l_target STRING
DEFINE fo FileOutputStream
DEFINE import_file InputStream
DEFINE workbook XSSFWorkbook
DEFINE sheet XSSFSheet
DEFINE row XSSFRow
DEFINE cell XSSFCell
DEFINE cell_xls HSSFCell
DEFINE font1 XSSFFont
DEFINE font2 XSSFFont
DEFINE font3 XSSFFont
DEFINE font4 XSSFFont
DEFINE format1 DataFormat
DEFINE g_num FLOAT
在DIALOG ATTRIBUTES下添加查询栏位逻辑
ON ACTION controlp INFIELD xcag004
#add-point:ON ACTION controlp INFIELD xcag004 name="construct.c.xcag004"
#應用 a08 樣板自動產生(Version:3)
#開窗c段
INITIALIZE g_qryparam.* TO NULL
LET g_qryparam.state = 'c'
LET g_qryparam.reqry = FALSE
CALL q_xcag004() #呼叫開窗
DISPLAY g_qryparam.return1 TO xcag004 #顯示到畫面上
NEXT FIELD xcag004 #返回原欄位
#END add-point
#應用 a01 樣板自動產生(Version:2)
BEFORE FIELD xcag004
#add-point:BEFORE FIELD xcag004 name="construct.b.xcag004"
#END add-point
#應用 a02 樣板自動產生(Version:2)
AFTER FIELD xcag004
#add-point:AFTER FIELD xcag004 name="construct.a.xcag004"
#END add-point
在process下的process.count_progress下添加调用方法逻辑
CALL cxcr600_create_tmp()
CALL cxcr600_export_excel()
写自己的方法,供上面调用
PRIVATE FUNCTION cxcr600_create_tmp()
DROP TABLE cxcr600_tmp;
CREATE TEMP TABLE cxcr600_tmp(
t_xcah020 LIKE xcah_t.xcah020, #bom阶层
t_xcah004 LIKE xcah_t.xcah040, #主件料号
t_xcah004_desc LIKE type_t.chr200, #主件品名
t_xcah004_1_desc LIKE type_t.chr200, #主件规格
t_xcaeud015_sum LIKE xcae_t.xcaeud015, #合计工时
t_xcah031_a_sum LIKE type_t.num20_6, #合计材料费
t_price_ws LIKE type_t.num20_6, #未税单价
t_xcah031_b_sum LIKE type_t.num20_6, #合计人工费
t_xcah031_b_szb LIKE type_t.num20_6, #人工费用占比
t_xcah031_a_szb LIKE type_t.num20_6, #材料费用占比
t_xcah022 LIKE xcah_t.xcah022, #元件料号
t_xcah022_desc LIKE type_t.chr200, #元件品名
t_xcah022_1_desc LIKE type_t.chr200, #元件规格
t_xcaeud015 LIKE xcae_t.xcaeud015, #各阶段标准工时
t_xcaeud016 LIKE xcae_t.xcaeud016, #各阶段标准机时
t_xcah031_b LIKE type_t.num20_6, #各阶段人力费
t_xcah031_a LIKE type_t.num20_6, #各阶段材料费
t_xcah026 LIKE xcah_t.xcah026, #工时占比(各阶段/总)
t_xcah025 LIKE xcah_t.xcah025 #材料占比(各阶段/总)
);
END FUNCTION
PRIVATE FUNCTION cxcr600_ins_tmp(p_imaa001_a)
DEFINE p_imaa001_a LIKE imaa_t.imaa001
DEFINE l_sql STRING
DEFINE l_dex LIKE type_t.num5
DEFINE l_docno DYNAMIC ARRAY OF RECORD
l_xcah020 LIKE xcah_t.xcah020, #bom阶层
l_xcah004 LIKE xcah_t.xcah040, #主件料号
l_xcah004_desc LIKE type_t.chr200, #主件品名
l_xcah004_1_desc LIKE type_t.chr200, #主件规格
l_xcaeud015_sum LIKE xcae_t.xcaeud015, #合计工时
l_xcah031_a_sum LIKE type_t.num20_6, #合计材料费
l_price_ws LIKE type_t.num20_6, #未税单价
l_xcah031_b_sum LIKE type_t.num20_6, #合计人工费
l_xcah031_b_szb LIKE type_t.num20_6, #人工费用占比
l_xcah031_a_szb LIKE type_t.num20_6, #材料费用占比
l_xcah022 LIKE xcah_t.xcah022, #元件料号
l_xcah022_desc LIKE type_t.chr200, #元件品名
l_xcah022_1_desc LIKE type_t.chr200, #元件规格
l_xcaeud015 LIKE xcae_t.xcaeud015, #各阶段标准工时
l_xcaeud016 LIKE xcae_t.xcaeud016, #各阶段标准机时
l_xcah031_b LIKE type_t.num20_6, #各阶段人力费
l_xcah031_a LIKE type_t.num20_6, #各阶段材料费
l_xcah026 LIKE xcah_t.xcah026, #工时占比(各阶段/总)
l_xcah025 LIKE xcah_t.xcah025 #材料占比(各阶段/总)
END RECORD
DEFINE l_num LIKE type_t.num5
LET l_sql = "DELETE FROM cxcr600_tmp "
EXECUTE IMMEDIATE l_sql
#插入数据
LET l_sql = "INSERT INTO cxcr600_tmp
SELECT xcah020,xcag004,a.imaal003,a.imaal004,0,0,0,0,0,0,xcah022,b.imaal003,b.imaal004,0,0,0,0,0,0 FROM xcag_t
LEFT JOIN xcah_t ON xcagent = xcahent AND xcagsite = xcahsite AND xcag001 = xcah001 AND xcag004 = xcah004
LEFT JOIN imaal_t a ON a.imaalent = xcagent AND a.imaal001 = xcag004 AND a.imaal002 = '",g_dlang,"'
LEFT JOIN imaal_t b ON b.imaalent = xcahent AND b.imaal001 = xcah022 AND b.imaal002 = '",g_dlang,"'
WHERE xcagent = ",g_enterprise," AND xcagsite = '",g_site,"' AND xcah004 = '",p_imaa001_a,"'
AND xcag001 = '101' AND xcah023 = 'A'
ORDER BY xcah020 ASC "
DISPLAY l_sql
EXECUTE IMMEDIATE l_sql
LET l_sql = " SELECT * FROM cxcr600_tmp "
PREPARE l_upd_code FROM l_sql
DECLARE l_upd_curs CURSOR FOR l_upd_code
CALL l_docno.clear() #在进入循环之前把二维数组清空
LET l_dex = 1 #初始化
FOREACH l_upd_curs INTO l_docno[l_dex].*
#判断如果不属于A或者B料号,就删除,因为存在C,D料号属于A类型
SELECT COUNT(*) INTO l_num
FROM cxcr600_tmp
WHERE t_xcah022=l_docno[l_dex].l_xcah022
AND (t_xcah022 LIKE 'A%' OR t_xcah022 LIKE 'B%')
IF cl_null(l_num) OR (l_num = 0) THEN
#删除此料号
DELETE FROM cxcr600_tmp
WHERE t_xcah004 = l_docno[l_dex].l_xcah004
AND t_xcah022 = l_docno[l_dex].l_xcah022
END IF
LET l_num = 0
LET l_dex = l_dex + 1
END FOREACH
END FUNCTION
PRIVATE FUNCTION cxcr600_get_data(p_imaa001_a)
DEFINE p_imaa001_a LIKE imaa_t.imaa001
DEFINE l_sql STRING
DEFINE l_dex LIKE type_t.num5 #数组循环变量
DEFINE l_num LIKE type_t.num5 #判断是否夹治具
DEFINE l_num1 LIKE xcah_t.xcah025 #上阶主件底数
DEFINE l_num2 LIKE xcah_t.xcah026 #上阶组成用量
DEFINE l_money_sh LIKE type_t.num20_6 #主件损耗
DEFINE l_docno DYNAMIC ARRAY OF RECORD
l_xcah004 LIKE xcah_t.xcah040, #主件料号
l_xcah004_desc LIKE type_t.chr200, #主件品名
l_xcah004_1_desc LIKE type_t.chr200, #主件规格
l_xcaeud015_sum LIKE xcae_t.xcaeud015, #合计工时
l_xcah031_a_sum LIKE type_t.num20_6, #合计材料费
l_price_ws LIKE type_t.num20_6, #未税单价
l_xcah031_b_sum LIKE type_t.num20_6, #合计人工费
l_xcah031_b_szb LIKE type_t.num20_6, #人工费用占比
l_xcah031_a_szb LIKE type_t.num20_6, #材料费用占比
l_xcah022 LIKE xcah_t.xcah022, #元件料号
l_xcah022_desc LIKE type_t.chr200, #元件品名
l_xcah022_1_desc LIKE type_t.chr200, #元件规格
l_xcaeud015 LIKE xcae_t.xcaeud015, #各阶段标准工时
l_xcaeud016 LIKE xcae_t.xcaeud016, #各阶段标准机时
l_xcah031_b LIKE type_t.num20_6, #各阶段人力费
l_xcah031_a LIKE type_t.num20_6, #各阶段材料费
l_xcah026 LIKE xcah_t.xcah026, #工时占比(各阶段/总)
l_xcah025 LIKE xcah_t.xcah025 #材料占比(各阶段/总)
END RECORD
#======================================页签==============================================================
CALL cxcr600_ins_tmp(p_imaa001_a)
LET l_sql = " SELECT t_xcah004,t_xcah004_desc,t_xcah004_1_desc,t_xcaeud015_sum,t_xcah031_a_sum,
t_price_ws,t_xcah031_b_sum,t_xcah031_b_szb,t_xcah031_a_szb,t_xcah022,t_xcah022_desc,
t_xcah022_1_desc,t_xcaeud015,t_xcaeud016,t_xcah031_b,t_xcah031_a,t_xcah026,t_xcah025
FROM cxcr600_tmp ORDER BY t_xcah020 ASC "
PREPARE l_get_code FROM l_sql
DECLARE l_get_curs CURSOR FOR l_get_code
CALL l_docno.clear() #在进入循环之前把二维数组清空
LET l_dex = 1 #初始化
LET l_money_sh = 0 #初始化损耗
FOREACH l_get_curs INTO l_docno[l_dex].*
#1、标准工时 取阶段料号对应的工时和
SELECT SUM(xcaeud015) INTO l_docno[l_dex].l_xcaeud015 FROM xcae_t
WHERE xcaeent = g_enterprise AND xcaesite = g_site
AND xcaestus = 'Y' AND xcae002 = l_docno[l_dex].l_xcah004
AND xcaeud001 = l_docno[l_dex].l_xcah022
IF cl_null(l_docno[l_dex].l_xcaeud015) THEN
LET l_docno[l_dex].l_xcaeud015 = 0
END IF
#2、标准机时 取阶段料号对应的机时和
SELECT SUM(xcaeud016) INTO l_docno[l_dex].l_xcaeud016 FROM xcae_t
WHERE xcaeent = g_enterprise AND xcaesite = g_site
AND xcaestus = 'Y' AND xcae002 = l_docno[l_dex].l_xcah004
AND xcaeud001 = l_docno[l_dex].l_xcah022
IF cl_null(l_docno[l_dex].l_xcaeud016) THEN
LET l_docno[l_dex].l_xcaeud016 = 0
END IF
#3、人力成本 取阶段料号对应的成本直接人工+间接一、二
SELECT (xcah031b+xcah031d+xcah031e) INTO l_docno[l_dex].l_xcah031_b FROM xcah_t
WHERE xcahent = g_enterprise AND xcahsite = g_site AND xcah001 = '101'
AND xcah004 = l_docno[l_dex].l_xcah004 AND xcah022 = l_docno[l_dex].l_xcah022
#4、材料成本 如果是夹治具,直接去成本材料费;不是的话,取它对应的下阶材料费加上它自身的损耗
#取数判断是否夹治具
SELECT imaaud011 INTO l_num FROM imaa_t
WHERE imaaent = g_enterprise AND imaastus = 'Y'
AND imaa001 = l_docno[l_dex].l_xcah022
SELECT xcah025 INTO l_num1 FROM xcah_t
WHERE xcahent = g_enterprise AND xcahsite = g_site AND xcah001 = '101'
AND xcah004 = l_docno[l_dex].l_xcah004 AND xcah022 = l_docno[l_dex].l_xcah022
SELECT xcah026 INTO l_num2 FROM xcah_t
WHERE xcahent = g_enterprise AND xcahsite = g_site AND xcah001 = '101'
AND xcah004 = l_docno[l_dex].l_xcah004 AND xcah022 = l_docno[l_dex].l_xcah022
#损耗=单位材料*组成用量/主件底数/(1-损耗)-单位材料*组成用量/主件底数 更新到主件中去
SELECT (xcah030a*xcah026/xcah025/(1-xcah027/100)-xcah030a*xcah026/xcah025) INTO l_money_sh FROM xcah_t
WHERE xcahent = g_enterprise AND xcahsite = g_site AND xcah001 = '101'
AND xcah004 = l_docno[l_dex].l_xcah004 AND xcah040 = l_docno[l_dex].l_xcah022
AND xcah023 = 'A' AND xcah022 IN (
SELECT imaa001 FROM imaa_t
WHERE imaaent = g_enterprise AND imaastus = 'Y'
AND (imaaud011 = 0 OR imaaud011 IS NULL)
)
IF cl_null(l_money_sh) THEN
LET l_money_sh = 0
END IF
#判断是否夹治具料号,如果是直接取夹治具材料成本,否则的话取下阶材料和
IF l_num <> 0 THEN
SELECT xcah031a INTO l_docno[l_dex].l_xcah031_a FROM xcah_t
WHERE xcahent = g_enterprise AND xcahsite = g_site AND xcah001 = '101'
AND xcah004 = l_docno[l_dex].l_xcah004 AND xcah022 = l_docno[l_dex].l_xcah022
ELSE
SELECT SUM(xcah031a/l_num1*l_num2) INTO l_docno[l_dex].l_xcah031_a FROM xcah_t
WHERE xcahent = g_enterprise AND xcahsite = g_site AND xcah001 = '101'
AND xcah004 = l_docno[l_dex].l_xcah004 AND xcah023 = 'M' AND xcah040 = l_docno[l_dex].l_xcah022
AND xcah020 IN (
SELECT xcah020+1 FROM xcah_t
WHERE xcahent = g_enterprise AND xcahsite = g_site AND xcah001 = '101'
AND xcah004 = l_docno[l_dex].l_xcah004 AND xcah022 = l_docno[l_dex].l_xcah022
)
#如果下阶无材料,费用为空,另它等于零
IF cl_null(l_docno[l_dex].l_xcah031_a) THEN
LET l_docno[l_dex].l_xcah031_a = 0
END IF
#费用加上它的损耗
LET l_docno[l_dex].l_xcah031_a = l_docno[l_dex].l_xcah031_a+l_money_sh
LET l_money_sh = 0
END IF
IF cl_null(l_docno[l_dex].l_xcah031_a) THEN
LET l_docno[l_dex].l_xcah031_a = 0
END IF
#5、合计人工 取axci006里面主件直接+间接
SELECT (xcag102b+xcag102d+xcag102e) INTO l_docno[l_dex].l_xcah031_b_sum FROM xcag_t
WHERE xcagent = g_enterprise AND xcagsite = g_site
AND xcag001 = '101' AND xcag004 = l_docno[l_dex].l_xcah004
#6、合计材料 直接取axci006主件材料费
SELECT xcag102a INTO l_docno[l_dex].l_xcah031_a_sum FROM xcag_t
WHERE xcagent = g_enterprise AND xcagsite = g_site
AND xcag001 = '101' AND xcag004 = l_docno[l_dex].l_xcah004
#7、合计工时 取axci005里面所有工时和
SELECT SUM(xcaeud015) INTO l_docno[l_dex].l_xcaeud015_sum FROM xcae_t
WHERE xcaeent = g_enterprise AND xcaesite = g_site
AND xcaestus = 'Y' AND xcae002 = l_docno[l_dex].l_xcah004
#8、未税单价
LET l_docno[l_dex].l_price_ws = cxcr600_get_price(l_docno[l_dex].l_xcah004)
#9、主件人工占比
LET l_docno[l_dex].l_xcah031_b_szb = l_docno[l_dex].l_xcah031_b_sum/l_docno[l_dex].l_price_ws
#10、主件材料占比
LET l_docno[l_dex].l_xcah031_a_szb = l_docno[l_dex].l_xcah031_a_sum/l_docno[l_dex].l_price_ws
#11、工时占比
LET l_docno[l_dex].l_xcah026= l_docno[l_dex].l_xcaeud015/l_docno[l_dex].l_xcaeud015_sum
#12、材料占比
LET l_docno[l_dex].l_xcah025 = l_docno[l_dex].l_xcah031_a/l_docno[l_dex].l_xcah031_a_sum
LET l_dex = l_dex + 1
END FOREACH
CALL l_docno.deleteElement(l_docno.getLength())
RETURN l_docno
END FUNCTION
PRIVATE FUNCTION cxcr600_export_excel()
DEFINE style2 XSSFCellStyle
DEFINE style3 XSSFCellStyle
DEFINE style3_5 XSSFCellStyle
DEFINE style4 XSSFCellStyle
DEFINE style4_1 XSSFCellStyle
DEFINE style4_3 XSSFCellStyle
DEFINE style4_3_1 XSSFCellStyle
DEFINE style5 XSSFCellStyle
DEFINE style6 XSSFCellStyle
DEFINE style7 XSSFCellStyle
DEFINE style8 XSSFCellStyle
DEFINE style9 XSSFCellStyle
DEFINE workbook XSSFWorkbook
DEFINE l_str STRING
DEFINE l_cnt LIKE type_t.num10
DEFINE l_i LIKE type_t.num5
DEFINE l_n LIKE type_t.num5
DEFINE l_n2 LIKE type_t.num5
DEFINE l_fileloc STRING
DEFINE l_length LIKE type_t.num10
DEFINE region CellRangeAddress
DEFINE l_m LIKE type_t.num5
DEFINE l_flag LIKE type_t.chr100
DEFINE l_n1 LIKE type_t.num5
DEFINE l_num FLOAT
DEFINE li_font_size LIKE type_t.num5
DEFINE l_time LIKE pmaa_t.pmaacrtdt
DEFINE l_string LIKE type_t.chr200
DEFINE l_dex LIKE type_t.num5
DEFINE l_m_n LIKE type_t.num5
DEFINE l_number FLOAT
DEFINE l_sql STRING
DEFINE l_row LIKE type_t.num10
DEFINE l_row1 LIKE type_t.num10
DEFINE l_sum_days LIKE type_t.num5
DEFINE l_imaa001 LIKE imaa_t.imaa001
DEFINE r_docno DYNAMIC ARRAY OF RECORD
l_xcah004 LIKE xcah_t.xcah040, #主件料号
l_xcah004_desc LIKE type_t.chr200, #主件品名
l_xcah004_1_desc LIKE type_t.chr200, #主件规格
l_xcaeud015_sum LIKE xcae_t.xcaeud015, #合计工时
l_xcah031_a_sum LIKE type_t.num20_6, #合计材料费
l_price_ws LIKE type_t.num20_6, #未税单价
l_xcah031_b_sum LIKE type_t.num20_6, #合计人工费
l_xcah031_b_szb LIKE type_t.num20_6, #人工费用占比
l_xcah031_a_szb LIKE type_t.num20_6, #材料费用占比
l_xcah022 LIKE xcah_t.xcah022, #元件料号
l_xcah022_desc LIKE type_t.chr200, #元件品名
l_xcah022_1_desc LIKE type_t.chr200, #元件规格
l_xcaeud015 LIKE xcae_t.xcaeud015, #各阶段标准工时
l_xcaeud016 LIKE xcae_t.xcaeud016, #各阶段标准机时
l_xcah031_b LIKE type_t.num20_6, #各阶段人力费
l_xcah031_a LIKE type_t.num20_6, #各阶段材料费
l_xcah026 LIKE xcah_t.xcah026, #工时占比(各阶段/总)
l_xcah025 LIKE xcah_t.xcah025 #材料占比(各阶段/总)
END RECORD
DEFINE l_date LIKE type_t.dat
DEFINE l_day LIKE type_t.num5
DEFINE l_field LIKE type_t.chr200
DEFINE l_i_dex LIKE type_t.num10
CALL ui.Interface.frontCall("standard","opendir",["C:", "File Browser"],[g_showmsg])
LET workbook = XSSFWorkbook.create() #创建工作簿
#设定EXCEL单元格式1
LET style2 = workbook.createCellStyle()
CALL style2.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER)
CALL style2.setAlignment(XSSFCellStyle.ALIGN_CENTER)
CALL style2.setBorderBottom(XSSFCellStyle.BORDER_THIN)
CALL style2.setBorderLeft(XSSFCellStyle.BORDER_THIN)
CALL style2.setBorderTop(XSSFCellStyle.BORDER_THIN)
CALL style2.setBorderRight(XSSFCellStyle.BORDER_THIN)
CALL style2.setWrapText(true)
#设定EXCEL单元格式2 包涵背景颜色
LET style3 = workbook.createCellStyle()
#CALL style3.setFillForegroundColor(IndexedColors.LIME.getIndex())
CALL style3.setFillForegroundColor(IndexedColors.WHITE.getIndex())
CALL style3.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND)
CALL