userfunction.js
资源名称:OA.rar [点击查看]
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:9k
源码类别:
OA系统
开发平台:
Java
- /*用户自定义函数文件 2002.07.11
- */
- /*科目取数函数
- 科目取数函数共有11个参数:1)科目编码,2)年份,3)月份,4)期初/本期借方/本期贷方/期末,
- 5)已记帐/未记帐,6)金额/外币/数量,7)第一个辅助核算名称,8)第一个辅助核算编码,
- 9)第二个辅助核算名称,10)第二个辅助核算编码,11)帐套路径
- 所有参数的数据类型为字符型,即数据的两边得加上双引号。其中第2,3二个参数可为空,
- 为空时表示取当前默认的年份和月份的数据。也可以用年-1,月-1来表示上一年,上一月。
- 月份这个参数支持这种格式:1,3,5-7,这表示取1,2,5,6,7这5个月的数据,
- 如果月份这个参数为:1-则表示取1到当前月的数据。 当前年份和当前月份是指选项窗中设置的年月。
- 第7,8,9,10四个参数可以省略。第11为取指定帐套路径的数据,可省略 例如:取101科目的1998年10月的期初: KM("101","1998","10","期初","已记帐","金额") 例如:取102科目的上年从年初到当前月的包括未记帐的累计借方发生额: KM("102","年-1","1-","本期借方","未记帐","金额")
- */
- function KM(fstrAccountName,sYear,sMonth,sInit,sAmount,sRegister,
- sAnalysisName1,sAnalysisName2,sPath){
- var sSql=""
- var sField=""
- var sInitField="" //计算期初的字段
- var sWhere=""
- var dblRet=0
- switch (sAmount){
- case "金额" :
- sField="fcurAmount"
- sInitField="fcurInit"
- break
- case "外币" :
- sField="fcurForeignAmount"
- sInitField="fcurForeign"
- break
- case "数量" :
- sField="fdblQuantity"
- sInitField="fdblQuantity"
- break
- default:
- sField="fcurAmount"
- sInitField="fcurInit"
- break
- }
- if(sInit!="本期借方" && sInit!="本期贷方" && sInit!="期初" && sInit!="期末" )
- sInit="本期借方"
- if(sInit=="本期借方") {
- //SQL Server 库
- //sField="sum(case fblnDirection when 1 then "+sField+" else 0 end)"
- //Access 库
- sField="sum(iif(fblnDirection ,"+sField+" , 0 ))"
- }
- if(sInit=="本期贷方") {
- //SQL Server 库
- //sField="sum(case fblnDirection when 0 then "+sField+" else 0 end)"
- //Access 库
- sField="sum(iif( fblnDirection , 0 , "+sField+" ))"
- }
- if(sRegister=="已记帐"){
- sWhere=" and fstrRegisterDesc!='' "
- }
- if(sAnalysisName1!=""){
- sWhere+=" and fstrAnalysisName1='"+sAnalysisName1+"' "
- if(sAnalysisName2!=""){
- sWhere+=" and fstrAnalysisName2='"+sAnalysisName2+"' "
- }
- }
- var arr=KmDateAct(sYear,sMonth)
- if(sInit=="期初" || sInit=="期末"){
- var sSqlInit="Select "+sInitField+" From Account Where fstrAccountName='"+fstrAccountName+"'"
- if(sInit=="期初"){
- sSql="Select "+sField+" From Voucher Inner Join VoucherDetail On Voucher.flngVoucherID=VoucherDetail.flngVoucherID "
- +" Where fstrAccountName='"+fstrAccountName+"' "+arr[1]+sWhere
- }
- else {
- sSql="Select "+sField+" From Voucher Inner Join VoucherDetail On Voucher.flngVoucherID=VoucherDetail.flngVoucherID "
- +" Where fstrAccountName='"+fstrAccountName+"' "+arr[2]+sWhere
- }
- var sXml=fc_select(sSqlInit,1,2)
- if(sXml=="<root></root>"){
- var dblRet1=0
- }
- else {
- var oXml=new ActiveXObject("Microsoft.XMLDOM")
- oXml.async="false";
- oXml.loadXML(sXml)
- var dblRet1=parseFloat(oXml.documentElement.childNodes(0).childNodes(0).text)
- if(isNaN(dblRet1)) dblRet1=0
- }
- sXml=fc_select(sSql,1,2)
- if(sXml=="<root></root>"){
- var dblRet=0
- }
- else {
- oXml.loadXML(sXml)
- dblRet=parseFloat(oXml.documentElement.childNodes(0).childNodes(0).text)
- if(isNaN(dblRet)) dblRet=0
- }
- dblRet+=dblRet1
- }
- else { //本期借方,本期贷方
- sSql="Select "+sField+" From Voucher Inner Join VoucherDetail On Voucher.flngVoucherID=VoucherDetail.flngVoucherID "
- +" Where fstrAccountName like '"+fstrAccountName+"%' "+arr[0]+sWhere
- var sXml=fc_select(sSql,1,2)
- var oXml=new ActiveXObject("Microsoft.XMLDOM")
- oXml.async="false";
- oXml.loadXML(sXml)
- dblRet=parseFloat(oXml.documentElement.childNodes(0).childNodes(0).text)
- if(isNaN(dblRet)) dblRet=0
- //sdfasd
- }
- return dblRet
- }
- /**
- //显示科目取数函数向导
- **/
- function ShowKMGuide() {
- if(txtMyGrid.style.display=="none") return
- var arySend=t.getAttribute("formula")
- if(arySend==null)arySend=""
- var strReturn=window.showModalDialog("dsnwizard.htm",arySend,"status:no;dialogHeight:350px;dialogWidth:520px;dialogTop:100;dialogLeft:150px")
- if (isSpace(strReturn)==false && typeof strReturn!="undefined"){
- txtMyGrid.value ="="+strReturn
- grid.curTD.innerText=txtMyGrid.value
- }
- }
- /**
- //科目取数函数的日期处理
- //sYear为处理前的年字符串,sPeriod为处理前的月字符串,返回一个数组,含3个日期SQL,
- //(供期初,期末时区分用)
- **/
- function KmDateAct(sYear,sPeriod) {
- var MonthSql="" //本期借方贷方用
- var MonthSql1="" //期初用
- var MonthSql2="" //期末用
- var mlngYear=0
- var mlngPeriod=0
- var pYear=2002 //全局年份
- var pPeriod=1 //全局月份
- //计算全局年份,全局月份
- var sXml=t.getAttribute("userdata")
- if(sXml==null)sXml=""
- sXml=unescape(sXml)
- if(sXml!=""){
- var oXml=new ActiveXObject("Microsoft.XMLDOM")
- oXml.async ="false";
- oXml.loadXML(sXml)
- pYear =parseInt(oXml.documentElement.childNodes(3).text)
- pPeriod =parseInt(oXml.documentElement.childNodes(4).text)
- }
- //--------------------------------
- var bFind=false
- //处理年
- if(sYear.substring(0,1)=="年") {
- if(sYear.length==1){
- mlngYear=pYear
- }
- else {
- var tmpYear=parseInt(sYear.substring(2,sYear.length-1))
- if(sYear.substring(1,2)=="-")
- mlngYear=pYear-tmpYear
- else
- mlngYear=pYear+tmpYear
- }
- }
- else {
- if(sYear=="")
- mlngYear=pYear
- else
- mlngYear=parseInt(sYear)
- }
- //处理月
- if(sPeriod.substring(0,1)=="月") {
- if(sPeriod.length==1){
- mlngPeriod=pPeriod
- }
- else {
- var tmpPeriod=parseInt(sPeriod.substring(2,sPeriod.length-1))
- if(sPeriod.substring(1,2)=="-")
- mlngPeriod=pPeriod-tmpPeriod
- else
- mlngPeriod=pPeriod+tmpPeriod
- }
- }
- else {
- if(sPeriod==""){
- mlngPeriod=pPeriod
- }
- else {
- //同时处理多个月份
- if(sPeriod.indexOf("-")<0 && sPeriod.indexOf(",")<0 && sPeriod.length<=2){
- mlngPeriod=parseInt(sPeriod)
- }
- else {
- if(sPeriod.substring(sPeriod.length-1,sPeriod.length)=="-")
- sPeriod=sPeriod+pPeriod
- var arr=PrintArray(sPeriod)
- bFind=true
- }
- }
- }
- if(bFind){
- MonthSql = " AND fintYear= " +mlngYear+ " AND ( "
- for(var i = 0;i< arr.length;i++ )
- MonthSql += " fintPeriod= " +arr[i] + " OR "
- //去掉尾部的OR
- MonthSql = Left(MonthSql, MonthSql.length - 4) + " ) "
- }
- else {
- MonthSql = " AND fintYear= " +mlngYear+ " AND fintPeriod = " +mlngPeriod
- }
- MonthSql1 = " AND (fintYear<" +mlngYear+" OR (fintYear="+mlngYear+" AND fintPeriod<" +mlngPeriod+")) "
- MonthSql2 = " AND (fintYear<" +mlngYear+" OR (fintYear="+mlngYear+" AND fintPeriod<=" +mlngPeriod+")) "
- var arrRet=new Array()
- arrRet[0]=MonthSql
- arrRet[1]=MonthSql1
- arrRet[2]=MonthSql2
- return arrRet
- }
- /**
- //在数据库中保存表格数据的示例用的自定义函数
- **/
- function SaveCustomerTest() {
- //此函数实现将损益表中特写单元格中的数据保存到Customer表中
- var sCustomer=GETCELL(4,3)
- var sAnalysis1= GETCELL(6,5)
- var sAnalysis2= GETCELL(7,5)
- var sSql="insert into Customer (fstrCustomerName,fstrCustomerDesc,fstrAnalysisName1,fstrAnalysisName2) values ("
- +"'"+sCustomer+"','"+sCustomer+"','"+sAnalysis1+"','"+sAnalysis2+"'"+ ")"
- var sR=fc_insert(sSql)
- if(isSpace(sR)){
- alert("保存成功!")
- }
- else{
- alert(sR)
- }
- }
- /**
- *如要实现保存后的报表模版只有打印和打印预览两个功能按钮,可用下面此函数
- **/
- function SaveUserReport1(){
- var s1=""
- s1+="<root>"
- s1+="<button><value>打印预览</value><click>PreviewReport()</click></button>"
- s1+="<button><value>打印</value><click>PrintReport()</click></button>"
- s1+="</root>"
- t.setAttribute("buttonxml",s1)
- SaveUserReport()
- }
- /**
- //在数据库中保存表格数据的示例用的自定义函数
- **/
- function test_insert() {
- var orderid=GETCELL(1,2)
- var s1= GETCELL(2,2)
- var sSql="insert into Orders (OrderID,CustomerID) values ("
- +"'"+orderid+"','"+s1+"'"+ ")"
- var sR=fc_insert(sSql)
- if(isSpace(sR)){
- alert("保存成功!")
- }
- else{
- alert(sR)
- }
- }
- /**
- //在数据库中保存表格数据的示例用的自定义函数
- **/
- function test_save() {
- var orderid=GETCELL(1,2)
- var s1= GETCELL(2,2)
- var sSql="Update Orders Set Customerid='"+s1+ "' Where OrderID='"+orderid+"'"
- var sR=fc_insert(sSql)
- if(isSpace(sR)){
- alert("保存成功!")
- }
- else{
- alert(sR)
- }
- }
- /**
- //在数据库中保存表格数据的示例用的自定义函数
- **/
- function test_del() {
- var orderid=GETCELL(1,2)
- var s1= GETCELL(2,2)
- var sSql="Delete Orders Where OrderID='"+orderid+"'"
- var sR=fc_insert(sSql)
- if(isSpace(sR)){
- alert("保存成功!")
- }
- else{
- alert(sR)
- }
- }