码迷,mamicode.com
首页 > 其他好文 > 详细

财务金额大小写转换

时间:2019-12-31 14:37:16      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:_id   break   new   etc   else   clu   处理   bre   股份   

//==========================财务流程,货币小写转换为大写========【开始】===============================================
//对应数据库【LR_Form_SchemeInfo】的F_Id
//二位数组定义:["表单名称/编号","小写金额标识","大写金额标识"]
//表单名称:对应【表单设计】中的名称,而非流程
/*
var needTransForm = new Array(   
    ["21.费用报销流程(股份)", "报销金额(元)","报销金额大写"],
    ["22.差旅费报销流程(股份)", "费用总额(元)","总费用(大写)"],
    ["23.支出单办理流程(股份)", "支出金额(元)", "支出金额大写"],
    ["24.借款单(股份)", "借款金额(元)", "借款金额大写"],
    ["25.通讯费报销流程(股份)", "报销金额(元)", "报销金额大写"],
    ["26.客户极速退款流程(股份)", "支出金额(元)", "支出金额大写"],
    ["27.客户极速退款流程(科技)", "支出金额(元)", "支出金额大写"],
    ["28.客户常规退款流程(股份)", "支出金额(元)", "支出金额大写"],
    ["29.客户常规退款流程(科技)", "支出金额(元)", "支出金额大写"]
);
**/
var flag_CurrencyTransformation = "CWBD_CurrencyTransformation";
var smallControl;//小写控件
var bigControl;//大写控件
var CurrencyTransformationFromSamllToBig = {

    //是否包含
    IsInclude: function (formName) {
        var lstResult = CommonMethod.GetSettingByCode(flag_CurrencyTransformation);
        if (!lstResult)
            return null;

        var targetItem;//选中的目标数据
        for (var i = 0; i < lstResult.length; i++) {
            if (lstResult[i].Item1 == formName) {
                targetItem = lstResult[i];
                break;
            }
        }

        return targetItem;
        /*
        for (var i = 0; i<needTransForm.length;i++) {
            if (needTransForm[i][0] == formName) {
                currSamllControlFlagIndex = i;
                break;
            }
        }
        return currSamllControlFlagIndex > -1;
        */
    },

    //执行
    Excute: function (formName) {
        smallControl = null;
        bigControl = null;

        //根据表单名称,获取表单对应的配置信息
        var targetItem = CurrencyTransformationFromSamllToBig.IsInclude(formName);
        if (!targetItem)
            return;

        if ((!targetItem.Item2) || (!targetItem.Item3)) {
            console.log(targetItem.Item1 + ",缺少Item2或Item3的配置。(Item2配置小写控件,Item3配置大写控件)");
            return;
        }

        //找到小写金额和大写控件,并改变控件ID
        smallControl = CommonMethod.FindControl(targetItem.Item2, 1);
        bigControl = CommonMethod.FindControl(targetItem.Item3, 1);

        if (smallControl && bigControl) {
            //改变ID
            // $(smallControl).attr("id", "smallCurrency");
            // $(bigControl).attr("id", "bigCurrency");

            $(smallControl).attr("oninput", "CurrencyTransformationFromSamllToBig.CurrencyTransformation()")
        }
        else {
            console.log("没有寻找到小写控件或大写控件。请检查表单和多维字典中对表单的配置。");
        }

        //console.log($(‘#smallCurrency‘).val());
    },

    //货币转换:由小写转换为大写
    CurrencyTransformation: function () {
        var smallVal = $(smallControl).val();
        var bigVal = CurrencyTransformationFromSamllToBig.smalltoBIG(smallVal);

        CommonMethod.SetControlVal($(bigControl), bigVal)
    },

    /** 数字金额大写转换(可以处理整数,小数,负数) */
    smalltoBIG: function (n) {
        var fraction = [‘角‘, ‘分‘];
        var digit = [‘零‘, ‘壹‘, ‘贰‘, ‘叁‘, ‘肆‘, ‘伍‘, ‘陆‘, ‘柒‘, ‘捌‘, ‘玖‘];
        var unit = [[‘元‘, ‘万‘, ‘亿‘], [‘‘, ‘拾‘, ‘佰‘, ‘仟‘]];
        var head = n < 0 ? ‘欠‘ : ‘‘;
        n = Math.abs(n);

        var s = ‘‘;

        for (var i = 0; i < fraction.length; i++) {
            s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, ‘‘);
        }
        s = s || ‘整‘;
        n = Math.floor(n);

        for (var i = 0; i < unit[0].length && n > 0; i++) {
            var p = ‘‘;
            for (var j = 0; j < unit[1].length && n > 0; j++) {
                p = digit[n % 10] + unit[1][j] + p;
                n = Math.floor(n / 10);
            }
            s = p.replace(/(零.)*零$/, ‘‘).replace(/^$/, ‘零‘) + unit[0][i] + s;
        }
        return head + s.replace(/(零.)*零元/, ‘元‘).replace(/(零.)+/g, ‘零‘).replace(/^整$/, ‘零元整‘);
    }
}
//==========================财务流程,货币小写转换为大写=========【结束】==============================================

  

财务金额大小写转换

标签:_id   break   new   etc   else   clu   处理   bre   股份   

原文地址:https://www.cnblogs.com/qiupiaohujie/p/12124048.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!