drug_out_statistics.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. //@ sourceURL=drug_out_statistics.js
  2. var LODOP; //声明为全局变量
  3. var groupYk = window.localStorage["groupYk"];
  4. var hospitalName ='沭阳铭和医院'
  5. $(function () {
  6. getAjaxRequst("/thmz/queryHospitalName",{},true,function (res) {
  7. hospitalName = res.data
  8. $('.hospitalName').text(hospitalName)
  9. })
  10. if (groupYk == null) {
  11. return errorMesageSimaple('药库参数未设置,请在发药参数设置中设置');
  12. }
  13. init_daterangepicker();
  14. setTimeout(function () {
  15. getLodop();
  16. }, 800);
  17. $("#money_table").hide();
  18. $(".selectpicker").selectpicker({
  19. dropuAuto: false
  20. });
  21. //初始化页面上面的按钮事件
  22. $("#btn_search").click(function (t) {
  23. $('.sjh').remove();
  24. getRecordData();
  25. });
  26. $('#btn_clean').click(function () {
  27. cleanParams();
  28. });
  29. $("#btn_daily").click(function (t) {
  30. print();
  31. });
  32. $("#btn_excel").click(function (t) {
  33. let statisticalMethod = $("#statisticalMethod").val();
  34. let id = "";
  35. if (statisticalMethod === "0") {
  36. id = 'ck_bs_table';
  37. } else {
  38. id = 'money_table';
  39. }
  40. $("#" + id).table2excel({
  41. exclude: ".exclHide",
  42. filename: $("#" + id + " .title").html() + "(" + getRePortRangeArr()[0] + ").xls"
  43. })
  44. });
  45. $("#statisticalMethod").change(function (t, d, e) {
  46. let statisticalMethod = $("#statisticalMethod").val();
  47. if (statisticalMethod == 0) {
  48. $("#ck_bs_table").show();
  49. $("#money_table").hide();
  50. } else {
  51. $("#money_table").show();
  52. $("#ck_bs_table").hide();
  53. }
  54. $(".dateRange").html($('#reportrange span').html());
  55. $(".printDate").html(format(new Date(), "yyyy-MM-dd HH:mm"));
  56. });
  57. });
  58. /**
  59. * 获取汇总药品统计报表
  60. */
  61. function getRecordData() {
  62. let statisticalMethod = $('#statisticalMethod').val();
  63. if (statisticalMethod == 0) {
  64. url = '/thmz/getDrugOutStatistics';
  65. } else {
  66. url = '/thmz/getDeptDrugMoney';
  67. }
  68. let data = {
  69. 'beginDate': getRePortRangeArr()[0],
  70. 'endDate': getRePortRangeArr()[1],
  71. 'flag': statisticalMethod,
  72. 'groupNo': groupYk
  73. };
  74. $('#YWaitDialog').css('top', $('.xtd').offset().top);
  75. $('#YWaitDialog').show();
  76. $(".dateRange").html($('#reportrange span').html());
  77. $(".groupName").html(getGroupName(groupYk));
  78. $(".printDate").html(format(new Date(), "yyyy-MM-dd HH:mm"));
  79. $.ajax({
  80. type: "POST",
  81. url: url,
  82. contentType: "application/json;charset=UTF-8",
  83. dataType: "json",
  84. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  85. data: JSON.stringify(data),
  86. success: function (res) {
  87. $('#YWaitDialog').hide();
  88. if (res == '401' || res == 401) {
  89. window.location.href = '/thmz/login/view'
  90. return;
  91. }
  92. if (res.code == 0) {
  93. console.log(res);
  94. let html = '';
  95. let totalBuyPriceSum = 0;
  96. let totalPackRetpriceSum = 0;
  97. let totalAmount = 0;
  98. let totalDrawCount = 0;
  99. for (var i = 0; i < res.data.length; i++) {
  100. let data = res.data[i];
  101. if (statisticalMethod == 0) {
  102. let buyPriceSum = isEmpty(data.buyPriceSum) ? 0 : keepTwoDecimal(data.buyPriceSum);
  103. let packRetpriceSum = isEmpty(data.packRetpriceSum) ? 0 : keepTwoDecimal(data.packRetpriceSum);
  104. html += '<tr class="sjh">';
  105. if (i > 0 && i != (res.data.length - 1) && data.deptName === res.data[i - 1].deptName) {
  106. html += '<td class="xtd" style="text-align: center;"></td>';
  107. } else {
  108. html += '<td class="xtd" style="text-align: center;">' + data.deptName + '</td>';
  109. }
  110. html += '<td class="xtd" style="text-align: center;">' + data.kindName + '</td>';
  111. html += '<td class="xtd" style="text-align: center;">' + data.drawCount + '</td>';
  112. html += '<td class="xtd" style="text-align: center;">' + data.amount + '</td>';
  113. html += '<td class="xtd" style="text-align: center;">' + buyPriceSum + '</td>';
  114. html += '<td class="xtd" style="text-align: center;">' + packRetpriceSum + '</td>';
  115. html += '<td class="xtd" style="text-align: center;">' + keepTwoDecimal(packRetpriceSum - buyPriceSum) + '</td>';
  116. html += '</tr>';
  117. totalBuyPriceSum += buyPriceSum;
  118. totalPackRetpriceSum += packRetpriceSum;
  119. totalAmount += data.amount;
  120. totalDrawCount += data.drawCount;
  121. } else {
  122. let totalMoney = isEmpty(data.totalMoney) ? 0 : keepTwoDecimal(data.totalMoney);
  123. totalPackRetpriceSum += totalMoney;
  124. html += '<tr class="sjh">';
  125. if (i > 0 && i != (res.data.length - 1) && data.deptName === res.data[i - 1].deptName) {
  126. html += '<td class="xtd" style="text-align: center;"></td>';
  127. } else {
  128. html += '<td class="xtd" style="text-align: center;">' + data.type + "-" + data.deptName + '</td>';
  129. }
  130. html += '<td class="xtd" style="text-align: center;">' + data.kindName + '</td>';
  131. html += '<td class="xtd" style="text-align: center;">' + totalMoney + '</td>';
  132. for (let j = 0; j < res.typeSumData.length; j++) {
  133. if(res.typeSumData[j].deptCode == data.deptCode && res.typeSumData[j].type == data.type){
  134. html += '<td class="xtd" style="text-align: center;">' + keepTwoDecimal(totalMoney/res.typeSumData[j].totalMoney*100) + '%</td>';
  135. break;
  136. }
  137. }
  138. html += '</tr>';
  139. if (i > 0 && i != (res.data.length - 1) && data.deptName !== res.data[i + 1].deptName) {
  140. html += '<tr class="sjh">';
  141. html += '<td class="xtd" colspan="2" style="text-align: right;font-weight: 700;">科室总额</td>';
  142. html += '<td class="xtd" colspan="2" style="text-align: right;font-weight: 700;">' + keepTwoDecimal(totalPackRetpriceSum) + '</td>';
  143. html += '</tr>';
  144. totalPackRetpriceSum = 0;
  145. }
  146. }
  147. }
  148. if (statisticalMethod == 0) {
  149. html += '<tr class="sjh">';
  150. html += '<td colspan="2" style="text-align: center;font-weight: 700;">合计</td>';
  151. html += '<td style="text-align: right;font-weight: 700;">' + totalDrawCount + '</td>';
  152. html += '<td style="text-align: right;font-weight: 700;">' + keepTwoDecimal(totalAmount) + '</td>';
  153. html += '<td style="text-align: right;font-weight: 700;">' + keepTwoDecimal(totalBuyPriceSum) + '</td>';
  154. html += '<td style="text-align: right;font-weight: 700;">' + keepTwoDecimal(totalPackRetpriceSum) + '</td>';
  155. html += '<td style="text-align: right;font-weight: 700;">' + keepTwoDecimal(totalPackRetpriceSum - totalBuyPriceSum) + '</td>';
  156. html += '</tr>';
  157. }
  158. totalBuyPriceSum = 0;
  159. totalPackRetpriceSum = 0;
  160. for (var i = 0; i < res.sumData.length; i++) {
  161. let sumData = res.sumData[i];
  162. if (i == 0) {
  163. if (statisticalMethod == 0) {
  164. html += '<tr class="sjh">';
  165. html += '<td colspan="7" style="text-align: center;font-weight: 700;">小类汇总</td>';
  166. html += '</tr>';
  167. html += '<tr class="sjh">';
  168. html += '<td style="text-align: center;font-weight: 700;">分类</td>';
  169. html += '<td colspan="2" style="text-align: center;font-weight: 700;">购入金额</td>';
  170. html += '<td colspan="2" style="text-align: center;font-weight: 700;">零售金额</td>';
  171. html += '<td colspan="2" style="text-align: center;font-weight: 700;">差额</td>';
  172. html += '</tr>';
  173. } else {
  174. html += '<tr class="sjh">';
  175. html += '<td colspan="4" style="text-align: center;font-weight: 700;">类别汇总</td>';
  176. html += '</tr>';
  177. html += '<tr class="sjh">';
  178. html += '<td colspan="2" style="text-align: center;font-weight: 700;">药品类别</td>';
  179. html += '<td colspan="2" style="text-align: center;font-weight: 700;">零售金额</td>';
  180. html += '</tr>';
  181. }
  182. }
  183. if (statisticalMethod == 0) {
  184. html += '<tr class="sjh">';
  185. html += '<td style="text-align: center;">' + sumData.kindName + '</td>';
  186. html += '<td colspan="2" style="text-align: center;">' + keepTwoDecimal(sumData.buyPriceSum) + '</td>';
  187. html += '<td colspan="2" style="text-align: center;">' + keepTwoDecimal(sumData.packRetpriceSum) + '</td>';
  188. html += '<td colspan="2" style="text-align: center;">' + keepTwoDecimal(sumData.differencePrice) + '</td>';
  189. html += '</tr>';
  190. } else {
  191. totalPackRetpriceSum += keepTwoDecimal(sumData.totalMoney);
  192. html += '<tr class="sjh">';
  193. html += '<td colspan="2" style="text-align: center;">' + sumData.kindName + '</td>';
  194. html += '<td colspan="2" style="text-align: right;">' + keepTwoDecimal(sumData.totalMoney) + '</td>';
  195. html += '</tr>';
  196. }
  197. }
  198. if (statisticalMethod == 1) {
  199. html += '<tr class="sjh">';
  200. html += '<td colspan="2" style="text-align: center;font-weight: 700;">总计</td>';
  201. html += '<td colspan="2" style="text-align: right;font-weight: 700;">' + keepTwoDecimal(totalPackRetpriceSum) + '</td>';
  202. html += '</tr>';
  203. }
  204. if (!isEmpty(res.hzData)) {
  205. for (var i = 0; i < res.hzData.length; i++) {
  206. let hzData = res.hzData[i];
  207. if (i == 0) {
  208. html += '<tr class="sjh">';
  209. html += '<td colspan="7" style="text-align: center;font-weight: 700;">大类汇总</td>';
  210. html += '</tr>';
  211. html += '<tr class="sjh">';
  212. html += '<td style="text-align: center;font-weight: 700;">分类</td>';
  213. html += '<td colspan="2" style="text-align: center;font-weight: 700;">购入金额</td>';
  214. html += '<td colspan="2" style="text-align: center;font-weight: 700;">零售金额</td>';
  215. html += '<td colspan="2" style="text-align: center;font-weight: 700;">差额</td>';
  216. html += '</tr>';
  217. }
  218. if (hzData.buyPriceSum == 0 && hzData.packRetpriceSum == 0) {
  219. continue;
  220. }
  221. html += '<tr class="sjh">';
  222. html += '<td style="text-align: center;">' + hzData.typeName + '</td>';
  223. html += '<td colspan="2" style="text-align: center;">' + keepTwoDecimal(hzData.buyPriceSum) + '</td>';
  224. html += '<td colspan="2" style="text-align: center;">' + keepTwoDecimal(hzData.packRetpriceSum) + '</td>';
  225. html += '<td colspan="2" style="text-align: center;">' + keepTwoDecimal(hzData.differencePrice) + '</td>';
  226. html += '</tr>';
  227. totalBuyPriceSum += keepTwoDecimal(hzData.buyPriceSum);
  228. totalPackRetpriceSum += keepTwoDecimal(hzData.packRetpriceSum);
  229. }
  230. html += '<tr class="sjh">';
  231. html += '<td style="text-align: center;font-weight: 700;">合计</td>';
  232. html += '<td colspan="2" style="text-align: right;font-weight: 700;">' + keepTwoDecimal(totalBuyPriceSum) + '</td>';
  233. html += '<td colspan="2" style="text-align: right;font-weight: 700;">' + keepTwoDecimal(totalPackRetpriceSum) + '</td>';
  234. html += '<td colspan="2" style="text-align: right;font-weight: 700;">' + keepTwoDecimal(totalPackRetpriceSum - totalBuyPriceSum) + '</td>';
  235. html += '</tr>';
  236. html += '<tr class="sjh">';
  237. html += '<td style="text-align: left;font-weight: 700;border: transparent !important;"><br>入库记账:</td>';
  238. html += '<td colspan="2" style="text-align: left;font-weight: 700;border: transparent !important;"><br>验收人:</td>';
  239. html += '<td colspan="2" style="text-align: left;font-weight: 700;border: transparent !important;;"><br>复核人:</td>';
  240. html += '<td colspan="2" style="text-align: left;font-weight: 700;border: transparent !important;;"><br>药品会计:</td>';
  241. html += '</tr>';
  242. html += '<tr class="sjh">';
  243. html += '<td colspan="7" style="text-align: left;font-weight: 700;border: transparent !important;"><br>科室主任:</td>';
  244. html += '</tr>';
  245. }
  246. if (statisticalMethod == 0) {
  247. $("#ck_bs_table").append(html);
  248. } else {
  249. $("#money_table").append(html);
  250. }
  251. } else if (res.code == -1) {
  252. new PNotify({
  253. title: '错误提示',
  254. text: res.message,
  255. type: 'error',
  256. hide: true,
  257. styling: 'bootstrap3'
  258. });
  259. }
  260. }
  261. });
  262. }
  263. /**
  264. * 清空查询条件
  265. */
  266. function cleanParams() {
  267. $("#statisticalMethod").val(0);
  268. $('#statisticalMethod').selectpicker('refresh');
  269. $('#reportrange span').html(moment().subtract(1, 'days').format("YYYY-MM-DD") + ' - ' + moment().subtract(1, 'days').format("YYYY-MM-DD"));
  270. $('#ck_bs_table').show();
  271. $('#money_table').hide();
  272. $('.sjh').remove();
  273. }
  274. /**
  275. * 打印报表
  276. */
  277. function print() {
  278. setDefaultPrint();
  279. LODOP = getLodop();
  280. LODOP.PRINT_INITA(6, 0, "221mm", "93mm", "药品出入库统计表");
  281. LODOP.SET_PRINT_PAGESIZE(1, "221mm", "93mm", "");
  282. //设置默认打印机
  283. LODOP.SET_PRINTER_INDEX(defaultPrintIndex);
  284. LODOP.SET_PRINT_STYLE("FontSize", 10); //字体大小
  285. LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
  286. var strStyle = "<style>table,td,th {border-width: 1px;" +
  287. "border-style: solid;border-collapse: collapse;table-layout:fixed;word-wrap:break-word;font-size: 14px}</style>";
  288. LODOP.ADD_PRINT_HTM("2mm", "4mm", "RightMargin:4mm", "BottomMargin:15mm", strStyle + document.getElementById("report_table_1").innerHTML);
  289. LODOP.PRINT();
  290. //LODOP.PREVIEW();
  291. }