//@ sourceURL=drug_in_out_count.js
var LODOP; //声明为全局变量
var groupYk = window.localStorage["groupYk"];
$(function () {
if (groupYk == null) {
return errorMesageSimaple('药库参数未设置,请在发药参数设置中设置');
}
init_daterangepicker();
setTimeout(function () {
getLodop();
}, 800);
$("#kind_table").hide();
$("#class_sum_table").hide();
$(".selectpicker").selectpicker({
dropuAuto: false
});
//初始化页面上面的按钮事件
$("#btn_search").click(function (t) {
$('.sjh').remove();
getRecordData();
});
$('#btn_clean').click(function () {
cleanParams();
});
$("#btn_daily").click(function (t) {
print();
});
$("#btn_excel").click(function (t) {
let statisticalMethod = $("#statisticalMethod").val();
let id = "";
if (statisticalMethod === "0") {
id = 'sum_table';
} else if (statisticalMethod === "2") {
id = 'class_sum_table';
} else {
id = 'kind_table';
}
$("#" + id).table2excel({
exclude: ".exclHide",
filename: $("#" + id + " .title").html() + "(" + getRePortRangeArr()[0].substring(0, getRePortRangeArr()[0].indexOf(" ") + 1) + ").xls"
})
});
$("#statisticalMethod").change(function (t, d, e) {
let statisticalMethod = $("#statisticalMethod").val();
if (statisticalMethod === "0") {
$("#sum_table").show();
$("#kind_table").hide();
$("#class_sum_table").hide();
}else if (statisticalMethod === "2") {
$("#sum_table").hide();
$("#kind_table").hide();
$("#class_sum_table").show();
} else {
$("#kind_table").show();
$("#sum_table").hide();
$("#class_sum_table").hide();
}
$(".dateRange").html($('#reportrange span').html());
$(".printDate").html(format(new Date(), "yyyy-MM-dd HH:mm"));
});
});
/**
* 获取汇总药品统计报表
*/
function getRecordData() {
let statisticalMethod = $('#statisticalMethod').val();
let data = {
'beginDate': getRePortRangeArr()[0],
'endDate': getRePortRangeArr()[1],
'flag': statisticalMethod,
'groupNo': groupYk,
};
$('#YWaitDialog').css('top', $('.xtd').offset().top);
$('#YWaitDialog').show();
$(".dateRange").html($('#reportrange span').html());
$(".groupName").html(getGroupName(groupYk));
$(".printDate").html(format(new Date(), "yyyy-MM-dd HH:mm"));
$.ajax({
type: "POST",
url: '/thmz/getDrugMoneyCount',
contentType: "application/json;charset=UTF-8",
dataType: "json",
headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
data: JSON.stringify(data),
success: function (res) {
$('#YWaitDialog').hide();
if (res == '401' || res == 401) {
window.location.href = '/thmz/login/view'
return;
}
if (res.code == 0) {
let html = '';
let totalInMoneyBuy = 0;
let totalInMoneyRet = 0;
let totalOutMoneyRet = 0;
for (var i = 0; i < res.data.length; i++) {
let data = res.data[i];
let inMoneyBuy = isEmpty(data.inMoneyBuy)?0:keepTwoDecimal(data.inMoneyBuy);
let inMoneyRet = isEmpty(data.inMoneyRet)?0:keepTwoDecimal(data.inMoneyRet);
let outMoneyRet = isEmpty(data.outMoneyRet)?0:keepTwoDecimal(data.outMoneyRet);
if (statisticalMethod == 0) {
html += '
';
html += '| ' + (i + 1) + ' | ';
html += '' + data.countDate + ' | ';
html += '' + inMoneyBuy + ' | ';
html += '' + inMoneyRet + ' | ';
html += '' + outMoneyRet + ' | ';
html += '
';
totalInMoneyBuy += inMoneyBuy;
totalInMoneyRet += inMoneyRet;
totalOutMoneyRet += outMoneyRet;
}else if (statisticalMethod == 2) {
let inMoneyBuy = isEmpty(data.inMoneyBuy)?0:keepTwoDecimal(data.inMoneyBuy);
let inMoneyRet = isEmpty(data.inMoneyRet)?0:keepTwoDecimal(data.inMoneyRet);
let outMoneyRet = isEmpty(data.outMoneyRet)?0:keepTwoDecimal(data.outMoneyRet);
html += '';
html += '| ' + data.kindName + ' | ';
html += '' + inMoneyBuy + ' | ';
html += '' + inMoneyRet + ' | ';
html += '' + outMoneyRet + ' | ';
html += '
';
totalInMoneyBuy += inMoneyBuy;
totalInMoneyRet += inMoneyRet;
totalOutMoneyRet += outMoneyRet
} else {
let inMoneyBuy = isEmpty(data.inMoneyBuy)?0:keepTwoDecimal(data.inMoneyBuy);
let inMoneyRet = isEmpty(data.inMoneyRet)?0:keepTwoDecimal(data.inMoneyRet);
html += '';
html += '| ' + data.name + ' | ';
html += '' + inMoneyBuy + ' | ';
html += '' + inMoneyRet + ' | ';
totalInMoneyRet += inMoneyBuy;
totalOutMoneyRet += inMoneyRet
}
}
if (statisticalMethod == 0 || statisticalMethod == 2) {
html += '
';
html += '| 总计: | ';
html += '' + keepTwoDecimal(totalInMoneyBuy) + ' | ';
html += '' + keepTwoDecimal(totalInMoneyRet) + ' | ';
html += '' + keepTwoDecimal(totalOutMoneyRet) + ' | ';
html += '
';
}else{
html += '';
html += '| 总计: | ';
html += '' + keepTwoDecimal(totalInMoneyRet) + ' | ';
html += '' + keepTwoDecimal(totalOutMoneyRet) + ' | ';
html += '
';
}
if (statisticalMethod == 0) {
$("#sum_table").append(html);
}else if (statisticalMethod == 2) {
$("#class_sum_table").append(html);
}else {
$("#kind_table").append(html);
}
} else if (res.code == -1) {
new PNotify({
title: '错误提示',
text: res.message,
type: 'error',
hide: true,
styling: 'bootstrap3'
});
}
}
});
}
/**
* 获取时间选择器的时间数组
* @returns {string[]}
*/
function getRePortRangeArr() {
var rePortRange = $('#reportrange span').html();
var rePortRangeArr = rePortRange.split(" - ");
return rePortRangeArr;
}
/**
* 清空查询条件
*/
function cleanParams() {
$("#statisticalMethod").val(0);
$('#statisticalMethod').selectpicker('refresh');
$('#reportrange span').html(moment().subtract(1, 'days').format("YYYY-MM-DD") + ' - ' + moment().subtract(1, 'days').format("YYYY-MM-DD"));
$('#sum_table').show();
$('#kind_table').hide();
$('#class_sum_table').hide();
$('.sjh').remove();
}
/**
* 打印报表
*/
function print() {
setDefaultPrint();
LODOP = getLodop();
LODOP.PRINT_INITA(6, 0, "210mm", "297mm", "药品出入库统计表");
LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
//设置默认打印机
LODOP.SET_PRINTER_INDEX(defaultPrintIndex);
LODOP.SET_PRINT_STYLE("FontSize", 10); //字体大小
LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
//设置默认打印机
LODOP.SET_PRINTER_INDEX(defaultPrintIndex);
LODOP.ADD_PRINT_TEXT('285mm', '100mm', '40mm', '40mm', '第#页/共&页');
LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
var strStyle = "";
LODOP.ADD_PRINT_HTM("2mm", "4mm", "RightMargin:4mm", "BottomMargin:15mm", strStyle + document.getElementById("report_table_1").innerHTML);
LODOP.PRINT();
//LODOP.PREVIEW();
}