/
summary.html
232 lines (194 loc) · 7.55 KB
/
summary.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>福润堂 日结</title>
<link rel="stylesheet" href="css/app.css">
<link rel="stylesheet" href="css/bootstrap.css">
<script type="text/javascript" src="lib/angular.js"></script>
<script type="text/javascript" src="js/FRT_cashier.js"></script>
<style type="text/css">
input.ng-invalid.ng-dirty, input.ng-invalid.ng-invalid {
background-color: yellow;
}
</style>
</head>
<body ng-app="inputApp" ng-controller="Ctrl">
<h1 style="">福润堂</h1>
<h2>日结</h2>
<br>
<input type="button" value=" 第一步:装入数据 " ng-click="go_detail()" />
<input type="button" value=" 第二步:计算汇总 " ng-click="go_summary()" />
<input type="button" value=" 打印汇总 " ng-click="go_print2()" />
<div id="id_summary">
<h2>Summary</h2>
<h3>总价:{{total}}</h3>
<h3>VIP卡支付:{{VIPCard_sum}}</h3>
<h3>现金支付:{{Cash_sum}}</h3>
<table border="1" width="500">
<tr class='txt_center'><td></td><td>药名</td><td>用量</td><td>小计</td></tr>
<tr ng-repeat="obj in summary">
<td> {{$index+1}} </td>
<td>{{obj.medicine_name}}</td>
<td class='txt_right'>{{obj.count}}</td>
<td class='txt_right'>{{obj.price}}</td>
</tr>
</table>
</div>
<br><br>
<h2>By Doctor</h2>
<table border="1" width="500">
<tr class='txt_center'><td></td><td>医生姓名</td><td>合计</td></tr>
<tr ng-repeat="obj in sum_by_doctor">
<td> {{$index+1}} </td>
<td>{{obj.doctor_name}}</td>
<td class='txt_right'>{{obj.sum}}</td>
</tr>
</table>
</div>
<br><br>
<h2>Detail</h2>
<div ng-repeat="recipe in allRecipe">
<table border="1" width="500">
<tr>
<td colspan="3">
序号:{{$index+1}}
姓名: {{recipe.case.patient_name}}
性别: {{recipe.case.sex}}<br>
门诊号:{{recipe.case.case_no}}
金额:{{recipe.case.sumprice}}
付款方式:{{recipe.case.pay_type}}
</td></tr>
<tr><td></td><td>药名</td><td>用量</td></tr>
<tr ng-repeat="obj in recipe.case.recipe">
<td> {{$index+1}} </td>
<td>{{obj.medicine_name}}</td>
<td>{{obj.count}}</td>
</tr>
</table>
<br>
</div>
<script type="text/javascript">
var serverUrl = "http://192.168.1.2:8080";
var inputApp = angular.module('inputApp', []);
function Ctrl($scope, $http) {
$scope.dummy = "will";
$scope.allRecipeFiles = [];
$scope.allRecipe = [];
$scope.detail = [];
$scope.summary = [];
$scope.total = 0;
$scope.VIPCard_sum = 0;
$scope.Cash_sum = 0;
$scope.sum_by_doctor = [];
// 读所有处方文件, 取出内容,放入数组。
$scope.go_detail = function(){
// 读入所有 处方文件名 把 文件名 放在数组中
$http.get( serverUrl + '/getAllRecipe' )
.success(function(data) {
if( data.flag ){
if(data.flag==='error'){
$scope.msg = data.msg;
}else{
$scope.msg = "Undefine Error.";
}
}else{
console.log(data);
$scope.allRecipe = data;
$scope.detail = [];
console.log(data);
// 读入所有 处方 文件内容。
for(var i=0; i<$scope.allRecipe.length; i++ ){
var Recipe_json = $scope.allRecipe[i];
console.log(Recipe_json.case.recipe);
items = Recipe_json.case.recipe;
for( var j=0; j<items.length; j++ ){
var temp_obj = {};
temp_obj.medicine_name = items[j].medicine_name;
temp_obj.count = items[j].count;
temp_obj.price = items[j].price;
// 药品内容 放入数组中
$scope.detail.push(temp_obj);
}
}
}
})
.error(function(data, status, headers, config) {
console.log(data);
$scope.msg = "Front end Error.";
});
};
$scope.go_summary = function(){
// 计算前,清空保存结果的数组
$scope.summary = [];
// 计算每种药物的用量和销售金额的 小计
var temp_obj_count = _.groupBy($scope.detail, function(obj){ return obj.medicine_name; });
var all_count = _.values(temp_obj_count);
for(i=0;i<all_count.length;i++){
var obj2 = all_count[i];
var sum = _.reduce(obj2, function(memo, num){ return memo + num.count; }, 0);
//console.log(JSON.stringify(obj2));
var obj3 = {};
obj3.medicine_name = obj2[0].medicine_name;
obj3.count = sum;
obj3.price = (sum * obj2[0].price).toFixed(2) ;
$scope.summary.push(obj3);
}
// 计算 VIP卡 和 现金 的总计
var paytype_group = _.groupBy($scope.allRecipe, function(obj){ return obj.case.pay_type; });
var vipcard_pay = _.reduce(paytype_group.vip_card, function(memo, num){ return memo + parseFloat(num.case.sumprice); }, 0);
var cash_pay = _.reduce(paytype_group.cash, function(memo, num){ return memo + parseFloat(num.case.sumprice); }, 0);
console.log(paytype_group);
$scope.VIPCard_sum = vipcard_pay.toFixed(2);
$scope.Cash_sum = cash_pay.toFixed(2);
// 计算每个医生的总计
var doctor_group = _.groupBy($scope.allRecipe, function(obj){ return obj.case.doctor_name; });
var all_doctor_names = _.keys(doctor_group);
for( var i=0; i< all_doctor_names.length; i++){
var temp_name = all_doctor_names[i];
var temp_sum = 0;
var doctor_sum = {};
for( var j=0; j< $scope.allRecipe.length; j++){
var temp_recipe = $scope.allRecipe[j];
if( temp_name === temp_recipe.case.doctor_name ){
console.log(temp_recipe.case.sumprice);
temp_sum = temp_sum + parseFloat(temp_recipe.case.sumprice);
}
doctor_sum.doctor_name = temp_name;
doctor_sum.sum = temp_sum.toFixed(2);
}
$scope.sum_by_doctor.push(doctor_sum);
}
// 计算所有药物销售金额的 总计
$scope.total = (parseFloat(vipcard_pay) + parseFloat(cash_pay)).toFixed(2);
};
$scope.go_print2 = function(){
var obj = document.getElementById('id_summary');
//打开一个新窗口newWindow
var newWindow=window.open("打印窗口","w_print_summary");
//要打印的div的内容
var docStr = "<link rel='stylesheet' href='css/bootstrap.css'><link rel='stylesheet' href='css/app.css'>" + obj.innerHTML ;
//打印内容写入newWindow文档
newWindow.document.write(docStr);
//关闭文档
newWindow.document.close();
setTimeout(function(){
//调用打印机
newWindow.print();
//关闭newWindow页面
newWindow.close();
}, 1000);
};
}
debug_flag = 0;
var login_flag = window.prompt("请输入密码");
if( "frtabc" === login_flag ){
console.log("密码正确");
}else{
console.log("密码错误");
window.location.href = "cashier.html";
}
</script>
</body>
</html>