js 做账单处理

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
    <%@include file="/webpage/inc/inc.jsp"%>
        <!doctype html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>账单打印</title>
        </head>
         <body style="margin: 0;padding: 0;" ng-app="myApp" ng-controller="myCtrl">
        <div style="width: 950px;margin: 5px auto;padding: 10px 0px;border-bottom: 1px solid #eee;" id="headBox">
                    <span style="color:#32c5d2">Ι  </span>收据打印
                    <a onclick="_back()" style="color: #FFF;background-color: #32c5d2;border-color: #32c5d2;border: none;cursor: pointer;margin:0 10px;padding: 5px 10px;font-size: 12px;line-height: 1.5;float: right;">返回账单列表</a>
                    <a href="javascript:printData()" target="_self" style="color: #FFF;background-color: #32c5d2;border-color: #32c5d2;border: none;;cursor: pointer;text-decoration: none;padding: 5px 10px;font-size: 12px;line-height: 1.5;margin-left: 20px;">打印</a>
        </div>
            <div id="divPrint" style="width: 960px;margin:0 auto;">
            <div id="div1"></div>
            <div id="div2">
                <table width="100%" border="" cellspacing="0">
                    <thead>
                      <tr style="height: 40px;text-align: center;font-size: 30px;">
                        <td colspan="14">收&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;据</td>
                      </tr>
                      <tr>
                        <td style="text-align: center;width: 300px;"><span class="time_year">2017</span>年<span class="time_month">12</span>月<span class="time_day">11</span>日</td>
                        <td colspan="12" style="padding-left: 10px;">交款单位<span class="customer" style="padding: 0 12px;"></span></td>
                        <td style="padding-left: 10px;">NO:<span class="code"></td>
                      </tr>

                      <tr>
                        <td rowspan="2" style="text-align: center;">名称</td>
                        <td rowspan="2" style="text-align: center;width:50px;">单位</td>
                        <td rowspan="2" style="text-align: center;width:50px;">数量</td>
                        <td rowspan="2" style="text-align: center;width:50px;">单价</td>
                        <td colspan="9" style="text-align: center;">金额</td>
                        <td rowspan="2" style="text-align: center;">备注</td>
                      </tr>
                      <tr>
                        <td style="width: 30px;text-align: center;">佰</td>
                        <td style="width: 30px;text-align: center;">拾</td>
                        <td style="width: 30px;text-align: center;">万</td>
                        <td style="width: 30px;text-align: center;">千</td>
                        <td style="width: 30px;text-align: center;">百</td>
                        <td style="width: 30px;text-align: center;">十</td>
                        <td style="width: 30px;text-align: center;">元</td>
                        <td style="width: 30px;text-align: center;">角</td>
                        <td style="width: 30px;text-align: center;">分</td>
                        </tr>
                    </thead>
                    <tbody id="tbodyList">
                        <!-- <tr class="t_money_tr_0">
                            <td class="td_name_0" style="text-align: center;">{{items.name}}</td>
                            <td style="text-align: center;">&nbsp;</td>
                            <td style="text-align: center;">&nbsp;</td>
                            <td style="text-align: center;">&nbsp;</td>
                            <td class="hunbit_0" style="text-align: center;">&nbsp;</td>
                            <td class="debit_0" style="text-align: center;">&nbsp;</td>
                            <td class="myriabit_0" style="text-align: center;">&nbsp;</td>
                            <td class="kilbit_0" style="text-align: center;">&nbsp;</td>
                            <td class="hunders_0" style="text-align: center;">&nbsp;</td>
                            <td class="decade_0" style="text-align: center;">&nbsp;</td>
                            <td class="unit_0" style="text-align: center;">&nbsp;</td>
                            <td class="unitone_0" style="text-align: center;">&nbsp;</td>
                            <td class="unittwo_0" style="text-align: center;">&nbsp;</td>
                            <td class="td_remark_0" style="text-align: center;">&nbsp;</td>
                        </tr> -->
                    </tbody>
                    <tfoot>
                        <tr>
                            <td>合计人民币(大写)</td>
                            <td colspan="13"><span class="money_num_text">
                            <i class="num_text_hunbit" style="font-style: normal;margin: 0 12px;display: inline-block;width: 12px;">X</i>佰<i class="num_text_debit" style="font-style: normal;margin: 0 12px;display: inline-block;width: 12px;">X</i>拾<i class="num_text_myriabit" style="font-style: normal;margin: 0 12px;display: inline-block;width: 12px;">X</i>万<i class="num_text_kilbit" style="font-style: normal;margin: 0 12px;display: inline-block;width: 12px;">X</i>仟<i class="num_text_hunders" style="font-style: normal;margin: 0 12px;display: inline-block;width: 12px;">X</i>佰<i class="num_text_decade" style="font-style: normal;margin: 0 12px;display: inline-block;width: 12px;">X</i>拾<i class="num_text_unit" style="font-style: normal;margin: 0 12px;display: inline-block;width: 12px;">X</i>元<i class="num_text_unitone
" style="font-style: normal;margin: 0 12px;display: inline-block;width: 12px;">零</i>角<i class="num_text_unittwo" style="font-style: normal;margin: 0 12px;display: inline-block;width: 12px;">零</i>分<b>¥</b><b class="total"></b>
                        </span></td>
                        </tr>
                        <tr>
                            <td>主管</td>
                            <td colspan="6">会计</td>
                            <td colspan="7">收款人</td>
                        </tr>
                        <tr>
                            <td colspan="12" style="text-align: center;"><span> &nbsp;白1&nbsp;(存根)&nbsp;黄&nbsp;(收据)&nbsp;绿&nbsp;(记账)&nbsp;蓝&nbsp;(提货)&nbsp;红&nbsp;(核对)&nbsp;白2&nbsp;(确认) </span></td>
                            <td colspan="2">
                                <span tdata="pageNO" format="#" >
                                    第<font color="#0000FF">#</font>张</span>
                                    <span tdata="pageCount" format="#">
                                    共<font color="#0000FF">##</font>张</span>
                            </td>
                        </tr>
                    </tfoot>
                </table>
                </div>
            </div>
        </body>
        <script src="<%=staticServPath%>/static/assets/global/plugins/jquery.min.js" type="text/javascript"></script>
        <script src="<%=staticServPath%>/static/js/public.js" type="text/javascript"></script>
        <script src="<%=staticServPath%>/static/plug-in/ng/angular.min.js" type="text/javascript"></script>
        <script src="<%=staticServPath%>/static/plug-in/lodop/LodopFuncs.js" type="text/javascript"></script>
        <script>
        var app = angular.module(‘myApp‘, []);
        app.controller(‘myCtrl‘, function($scope, $http) {
            // var $scope = $scope;
            inputId = window.location.href.split(‘?‘)[1].split(‘&‘)[0].split(‘=‘)[1];
            //请求接口
            ajaxJson(‘GET‘, webroot + ‘/bill/printList?ids=‘ + inputId, ‘‘, function(err, rsp) {
                if (rsp.code == 200) {
                    console.log(‘rsp‘,rsp.result);
                    $scope.aa = rsp.result;
                    $scope.data = rsp.result[0];
                    $scope.paymentDate = $scope.data.paymentDate.split(‘-‘);
                    $scope.customer = $scope.data.customer;
                    $scope.code = $scope.data.code;
                    // $scope.total = $scope.data.total;
                    $scope.total = 10000.99;

                    // $scope.items = $scope.data.items;
                     $scope.items = [{
                        money: 10.01,
                        remark: ‘备注1‘,
                        name: ‘01‘
                    }, {
                        money: 1000000.99,
                        remark: ‘备注2‘,
                        name: ‘02‘
                    }, {
                        money: 1000.00,
                        remark: ‘备注3‘,
                        name: ‘03‘
                    }];
                    $scope.$apply();
                    $(‘.time_year‘).text($scope.paymentDate[0]);
                    $(‘.time_month‘).text($scope.paymentDate[1]);
                    $(‘.time_day‘).text($scope.paymentDate[2]);
                    $(‘.customer‘).text($scope.customer);
                    $(‘.code‘).text($scope.code);
                    $(‘.total‘).text($scope.total);

                    //数据行数
                    var itemLen = $scope.items.length;
                    //迭代行数
                    var rowNum = itemLen + (4-itemLen%4) ;
                    //console.log(rowNum);
                    for(var i = 0; i < rowNum; i++){
                        if(i<=itemLen){
                            _addBzRow($scope.items[i]);
                        }else{
                            _addBzRow(null);
                        }
                    }
                    function _addBzRow(obj){
                        var innerHtml ;
                        if(null==obj){
                            innerHtml = ‘<tr class="t_money_tr_">‘+
                            ‘<td class="td_name_0" style="text-align: center;">&nbsp;</td>‘+
                            ‘<td style="text-align: center;">&nbsp;</td>‘+
                            ‘<td style="text-align: center;">&nbsp;</td>‘+
                            ‘<td style="text-align: center;">&nbsp;</td>‘+
                            ‘<td style="text-align: center;">&nbsp;</td>‘+
                            ‘<td style="text-align: center;">&nbsp;</td>‘+
                            ‘<td style="text-align: center;">&nbsp;</td>‘+
                            ‘<td style="text-align: center;">&nbsp;</td>‘+
                            ‘<td style="text-align: center;">&nbsp;</td>‘+
                            ‘<td style="text-align: center;">&nbsp;</td>‘+
                            ‘<td style="text-align: center;">&nbsp;</td>‘+
                            ‘<td style="text-align: center;">&nbsp;</td>‘+
                            ‘<td style="text-align: center;">&nbsp;</td>‘+
                            ‘<td class="td_remark_0" style="text-align: center;">&nbsp;</td>‘+
                            ‘</tr>‘;
                        }else{
                            var mhtml = getMoneyHtml(obj.money) ;
                            innerHtml = ‘<tr class="t_money_tr_">‘+
                                            ‘<td class="td_name_0" style="text-align: center;">‘+obj.name+‘</td>‘+
                                            ‘<td style="text-align: center;">&nbsp;</td>‘+
                                            ‘<td style="text-align: center;">&nbsp;</td>‘+
                                            ‘<td style="text-align: center;">&nbsp;</td>‘+

                                            //---------------
                                            mhtml +
                                            //-------------------------

                                            ‘<td class="td_remark_0" style="text-align: center;">&nbsp;</td>‘+
                                            ‘</tr>‘;
                        }
                        $(‘#tbodyList‘).append(innerHtml);
                    }

                    // function getMoneyHtml(m){
                    //     // 1089.00-->¥1089.00
                    //     var money = m.toString();
                    //     if(money.indexOf(".")==-1){//整数
                    //         money+".00";
                    //     }
                    //     money = "¥" + money ;
                    //     var arr = new Array();
                    //     for(var i = 0;i<money.length;i++){
                    //         var cm = money.charAt(i) ;
                    //         if(cm == ‘.‘){
                    //             continue ;
                    //         }
                    //         arr.push(cm);
                    //     }
                    //     //money=[‘¥‘,‘1‘,‘0‘,‘8‘,‘9‘,‘0‘,‘0‘]
                    //     var mhtml = ‘‘ ;
                    //     var temp = arr.length , j = 0 ;
                    //     for(var i = 9 ; i>0; i--){
                    //         if(temp<i){
                    //             mhtml = mhtml + ‘<td class="hunbit_0" style="text-align: center;">&nbsp;</td>‘ ;
                    //         }else{
                    //             mhtml = mhtml + ‘<td class="hunbit_0" style="text-align: center;">‘ + arr[j] + ‘</td>‘ ;
                    //             j++;
                    //         }
                    //     }
                    //     return mhtml ;
                    // }
                    /*小写金额填入处理*/
                    function getMoneyHtml(m){
                        var m = m.toString();
                        if(m.indexOf(".") == -1){//整数补齐小数位数为00
                            m = m + ".00";
                        }
                        var money = m.split(‘.‘);
                        var money_1 = ‘¥‘+money[0];//整数部分
                        if(Number(money[0]) >= 1000000){ //大于一百万不显示¥
                            var money_1 = money[0];
                        }
                        var money1_arr = money_1.split(‘‘)//转换成数组
                        var mhtml = ‘‘ ;
                        var temp = money1_arr.length , j = 0 ;
                        // 整数部分
                        for(var i = 7;i>0;i--){
                            if(temp < i){
                                mhtml = mhtml + ‘<td class="hunbit_0" style="text-align: center;">&nbsp;</td>‘ ;
                            }else{
                                mhtml = mhtml + ‘<td class="hunbit_0" style="text-align: center;">‘ + money1_arr[j] + ‘</td>‘ ;
                                j++;
                            }
                        }
                        //小数部分
                        if(m.toString().indexOf(".") != -1){
                            var money_2 = money[1];
                            var money2_arr = money_2.split(‘‘);
                            var temp2 = money2_arr.length ;
                            for(var i = 0;i < 2; i++){
                                 mhtml = mhtml + ‘<td class="hunbit_0" style="text-align: center;">‘ + money2_arr[i] + ‘</td>‘ ;
                            }
                        }
                        return mhtml;
                    }

                    //处理大写金额
                    var DNum = {
                        ‘1‘: ‘壹‘,
                        ‘2‘: ‘贰‘,
                        ‘3‘: ‘叁‘,
                        ‘4‘: ‘肆‘,
                        ‘5‘: ‘伍‘,
                        ‘6‘: ‘陆‘,
                        ‘7‘: ‘柒‘,
                        ‘8‘: ‘捌‘,
                        ‘9‘: ‘玖‘,
                        ‘0‘: ‘零‘
                    }
                    //取出各个位数的值
                    var total = $scope.total.toString();
                    var totalArr = total.split(‘.‘);
                    var totalArr1 = totalArr[0];
                    var text_unit = totalArr1[totalArr1.length - 1];
                    var text_decade = totalArr1[totalArr1.length - 2];
                    var text_hunders = totalArr1[totalArr1.length - 3];
                    var text_kilbit = totalArr1[totalArr1.length - 4];
                    var text_myriabit = totalArr1[totalArr1.length - 5];
                    var text_debit = totalArr1[totalArr1.length - 6];
                    var text_hunbit = totalArr1[totalArr1.length - 7];
                    //赋值
                    $(‘.num_text_hunbit‘).text(DNum[text_hunbit]);
                    $(‘.num_text_debit‘).text(DNum[text_debit]);
                    $(‘.num_text_myriabit‘).text(DNum[text_myriabit]);
                    $(‘.num_text_kilbit‘).text(DNum[text_kilbit]);
                    $(‘.num_text_hunders‘).text(DNum[text_hunders]);
                    $(‘.num_text_decade‘).text(DNum[text_decade]);
                    $(‘.num_text_unit‘).text(DNum[text_unit]);
                    if(total.indexOf(".") != -1){
                        var totalArr2 = totalArr[1].split(‘‘);
                        var text_unitone = totalArr2[0];
                        var text_unittwo = totalArr2[1];
                        $(‘.num_text_unitone‘).text(DNum[text_unitone]);
                        $(‘.num_text_unittwo‘).text(DNum[text_unittwo]);
                    }
                } else {
                    console.log(rsp.message);
                }
            });
        });
        //大写金额转换
        function smalltoBIG(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(/^整$/, ‘零元整‘);
        }
        // 打印
        var global_Html = "";
        // function printme() {
        //     global_Html = document.body.innerHTML;
        //     //调用打印接口,记录打印操作
        //     ajaxJson(‘GET‘, webroot + ‘/bill/printLog?ids=‘ + inputId, ‘‘, function(err, rsp){
        //         if (rsp.code == 200) {
        //             document.body.innerHTML = document.getElementById(‘divPrint‘).innerHTML;
        //             window.print();
        //         } else {
        //             console.log(rsp.message);
        //         }
        //     });
        //     window.setTimeout(function() {
        //         document.body.innerHTML = global_Html;
        //     }, 30);
        // }
        // 不请求接口
        function printme() {
            global_Html = document.body.innerHTML;
            document.body.innerHTML = document.getElementById(‘divPrint‘).innerHTML;
            window.print();
            window.setTimeout(function() {
                document.body.innerHTML = global_Html;
            }, 30);
        }
        //返回账单列表
        function _back() {
            var url = webroot + ‘/bill/index‘;
            window.location.href = url;
        }

        //打印
        function printData(){
            var LODOP=getLodop();  

            LODOP.PRINT_INIT("打印账单收据");
            LODOP.SET_PRINT_PAGESIZE(1,"25cm","15cm","LodopCustomPage")
            var strStyle="<style> table,td,th {border-width: 1px;border-style: solid;border-collapse: collapse}</style>"
            LODOP.ADD_PRINT_TABLE(128,"2%","90%","2.5cm", strStyle + document.getElementById("div2").innerHTML);
            LODOP.SET_PRINT_STYLEA(0,"Vorient",1);        

            LODOP.ADD_PRINT_HTM(26,"2%","90%","1cm",document.getElementById("div1").innerHTML);
            LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
            LODOP.SET_PRINT_STYLEA(0,"LinkedItem",1);

            LODOP.PREVIEW();
        };
        </script>

        </html>

原文地址:https://www.cnblogs.com/Byme/p/8578757.html

时间: 2024-10-15 03:03:09

js 做账单处理的相关文章

用js做登录的用户名判定

<script type="text/javascript" language="javascript" src="JS/jquery.js"></script>    <script language="javascript" type="text/javascript">      $(document).ready(function() {            

[3] 用D3.js做一个简单的图表吧!

本人的个人博客为: www.ourd3js.com csdn博客为: blog.csdn.net/lzhlzz 转载请注明出处,谢谢. 前面说了几节,都是对文字进行处理,这一节中将用 D3.js 做一个简单的柱形图. 做柱形图有很多种方法,比如用 HTML 的 div 标签,或用 svg . 推荐用 SVG 来做各种图形.SVG 意为可缩放矢量图形(Scalable Vector Graphics),SVG 使用 XML 格式定义图像,不清楚什么是SVG的朋友请先在 w3cschools 学习下

socket.io+angular.js+express.js做个聊天应用(三)

接着前面博客文章socket.io+angular.js+express.js做个聊天应用(二) 首先开发之前先介绍下bower.它是用来管理前端类库的(详细介绍,安装可看http://blog.csdn.net/edagarli/article/details/26359535) [email protected]:~/projects/nodejs/chattingnode$ bower Usage: bower <command> [<args>] [<options&

django Forgienkey字段 在前台用js做处理

在我做的项目中有个选择省城市的选项,这两个字段的关系是一对多的关系class Province(models.Model): # 省会      name = models.CharField(max_length=30) class City(models.Model): #城市      name = models.CharField(max_length=30)       province = models.ForeignKey(Province) 前台代码:<html><hea

java--css+js做的树形菜单(完整版)

jsp页面: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":"

socket.io+angular.js+express.js做个聊天应用(一)

node,express开发环境等安装假设已经搞好了. [email protected]:~/projects/nodejs$ express -e chattingnode create : chattingnode create : chattingnode/package.json create : chattingnode/app.js create : chattingnode/public create : chattingnode/public/javascripts creat

socket.io+angular.js+express.js做个聊天应用(二)

接着上一篇 我用的开发工具是sublime 打开之前创建的工程. 打开www 修改并添加代码 #!/usr/bin/env node var debug = require('debug')('my-application'); var app = require('../app'); var io=require("socket.io").listen(app.listen(app.get('port'))); app.set('port', process.env.PORT ||

使用Netty4和socket.js做IM客服坐席平台系统架构

本人最近想做一个 使用Netty4和socket.js做IM客服坐席平台,以前没这方面的实际经验.这里自己实现了一套架构,这里记录下,希望有大师看到帮指点指点: 一张图说出我的心生: IM消息数据持久化准备使用mongdb,其他业务数据用mysql

Json数据如果作为配置文件比较难读懂,XML文件作为配置文件有先天的优势,容易读懂和配置,因此不考虑效率时,在页面中宁可用XML文件作为配置文件再用JS做一次转化把XML转成JSON使用

比如如下相对比较复杂的XML <myobjects> <!--object 1--> <myobject> <id>yourID_1</id> <name>your name</name> <description> <![CDATA[Merck Biologics Pilot Plant ]]> </description> <locations> <location