|
@@ -60,20 +60,34 @@
|
|
};
|
|
};
|
|
const LedgerChecker = function (setting) {
|
|
const LedgerChecker = function (setting) {
|
|
const ledger = setting.ledgerTree, ledgerPos = setting.ledgerPos, decimal = setting.decimal;
|
|
const ledger = setting.ledgerTree, ledgerPos = setting.ledgerPos, decimal = setting.decimal;
|
|
|
|
+ const checkOption = setting.checkOption;
|
|
|
|
+
|
|
|
|
+ const showCheckPart = function (obj, show) {
|
|
|
|
+ if (show) {
|
|
|
|
+ obj.show();
|
|
|
|
+ } else {
|
|
|
|
+ obj.hide();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
const initWaitingModal = function () {
|
|
const initWaitingModal = function () {
|
|
$('.card', '#ledger-check-modal').removeClass('border-success');
|
|
$('.card', '#ledger-check-modal').removeClass('border-success');
|
|
$('[name=check-status]', '#ledger-check-modal').removeClass('text-success').addClass('text-muted').html('待检查');
|
|
$('[name=check-status]', '#ledger-check-modal').removeClass('text-success').addClass('text-muted').html('待检查');
|
|
|
|
+ showCheckPart($('#check-sibling'), checkOption.sibling.enable);
|
|
|
|
+ showCheckPart($('#check-empty-code'), checkOption.empty_code.enable);
|
|
|
|
+ showCheckPart($('#check-calc'), checkOption.calc.enable);
|
|
|
|
+ showCheckPart($('#check-zero'), checkOption.zero.enable);
|
|
|
|
+ showCheckPart($('#check-tp'), checkOption.tp.enable);
|
|
$('#ledger-check-begin').show();
|
|
$('#ledger-check-begin').show();
|
|
$('#ledger-check-waiting').hide();
|
|
$('#ledger-check-waiting').hide();
|
|
$('#ledger-check-hint').removeClass('text-warning').addClass('text-success').html('检查完成,现在您可以查看结果。').hide();
|
|
$('#ledger-check-hint').removeClass('text-warning').addClass('text-success').html('检查完成,现在您可以查看结果。').hide();
|
|
$('#ledger-check-show').hide();
|
|
$('#ledger-check-show').hide();
|
|
}
|
|
}
|
|
|
|
|
|
- const doSomeCheck = function (selector, checkFun) {
|
|
|
|
|
|
+ const doSomeCheck = function (selector, checkFun, option) {
|
|
const checkStatus = $('[name=check-status]', selector);
|
|
const checkStatus = $('[name=check-status]', selector);
|
|
checkStatus.html('<i class="fa fa-spinner fa-spin"></i>');
|
|
checkStatus.html('<i class="fa fa-spinner fa-spin"></i>');
|
|
- const result = checkFun(ledger);
|
|
|
|
|
|
+ const result = checkFun(ledger, option);
|
|
checkStatus.removeClass('text-muted').addClass('text-success').html('<i class="fa fa-check"></i>');
|
|
checkStatus.removeClass('text-muted').addClass('text-success').html('<i class="fa fa-check"></i>');
|
|
$(selector).addClass('border-success');
|
|
$(selector).addClass('border-success');
|
|
return result;
|
|
return result;
|
|
@@ -110,7 +124,7 @@
|
|
}
|
|
}
|
|
return error;
|
|
return error;
|
|
},
|
|
},
|
|
- checkCalc: function (ledgerTree) {
|
|
|
|
|
|
+ checkCalc: function (ledgerTree, option) {
|
|
const error = [];
|
|
const error = [];
|
|
for (const node of ledgerTree.nodes) {
|
|
for (const node of ledgerTree.nodes) {
|
|
if (node.children && node.children.length > 0) continue;
|
|
if (node.children && node.children.length > 0) continue;
|
|
@@ -118,19 +132,15 @@
|
|
const nodePos = ledgerPos.getLedgerPos(node.id);
|
|
const nodePos = ledgerPos.getLedgerPos(node.id);
|
|
if (!nodePos || nodePos.length === 0) continue;
|
|
if (!nodePos || nodePos.length === 0) continue;
|
|
|
|
|
|
- const checkData = {
|
|
|
|
- sgfh_qty: node.sgfh_qty || 0, qtcl_qty: node.qtcl_qty || 0, sjcl_qty: node.sjcl_qty || 0,
|
|
|
|
- quantity: node.quantity || 0
|
|
|
|
- };
|
|
|
|
- const calcData = {
|
|
|
|
- sgfh_qty: 0, qtcl_qty: 0, sjcl_qty: 0,
|
|
|
|
- quantity: 0
|
|
|
|
- };
|
|
|
|
|
|
+ const checkData = {}, calcData = {};
|
|
|
|
+ for (const f of option.fields) {
|
|
|
|
+ checkData[f] = node[f] || 0;
|
|
|
|
+ calcData[f] = 0;
|
|
|
|
+ }
|
|
for (const np of nodePos) {
|
|
for (const np of nodePos) {
|
|
- calcData.sgfh_qty = ZhCalc.add(calcData.sgfh_qty, np.sgfh_qty) || 0;
|
|
|
|
- calcData.qtcl_qty = ZhCalc.add(calcData.qtcl_qty, np.qtcl_qty) || 0;
|
|
|
|
- calcData.sjcl_qty = ZhCalc.add(calcData.sjcl_qty, np.sjcl_qty) || 0;
|
|
|
|
- calcData.quantity = ZhCalc.add(calcData.quantity, np.quantity) || 0;
|
|
|
|
|
|
+ for (const f of option.fields) {
|
|
|
|
+ calcData[f] = ZhCalc.add(calcData[f], np[f]) || 0;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if (!_.isMatch(checkData, calcData)) error.push(node);
|
|
if (!_.isMatch(checkData, calcData)) error.push(node);
|
|
}
|
|
}
|
|
@@ -148,22 +158,17 @@
|
|
}
|
|
}
|
|
return error;
|
|
return error;
|
|
},
|
|
},
|
|
- checkTp: function (ledgerTree) {
|
|
|
|
|
|
+ checkTp: function (ledgerTree, option) {
|
|
const error = [];
|
|
const error = [];
|
|
for (const node of ledgerTree.nodes) {
|
|
for (const node of ledgerTree.nodes) {
|
|
if (node.children && node.children.length > 0) continue;
|
|
if (node.children && node.children.length > 0) continue;
|
|
|
|
+ if (option.filter && option.filter(node)) continue;
|
|
|
|
|
|
- const checkData = {
|
|
|
|
- sgfh_tp: node.sgfh_tp || 0, qtcl_tp: node.qtcl_tp || 0, sjcl_tp: node.sjcl_tp || 0,
|
|
|
|
- total_price: node.total_price || 0, deal_tp: node.deal_tp || 0,
|
|
|
|
- };
|
|
|
|
- const calcData = {
|
|
|
|
- sgfh_tp: ZhCalc.mul(node.unit_price, node.sgfh_qty, decimal.tp) || 0,
|
|
|
|
- qtcl_tp: ZhCalc.mul(node.unit_price, node.qtcl_qty, decimal.tp) || 0,
|
|
|
|
- sjcl_tp: ZhCalc.mul(node.unit_price, node.sjcl_qty, decimal.tp) || 0,
|
|
|
|
- total_price: ZhCalc.mul(node.unit_price, node.quantity, decimal.tp) || 0,
|
|
|
|
- deal_tp: ZhCalc.mul(node.unit_price, node.deal_qty, decimal.tp) || 0,
|
|
|
|
- };
|
|
|
|
|
|
+ const checkData = {}, calcData = {};
|
|
|
|
+ for (const f of option.fields) {
|
|
|
|
+ checkData[f.tp] = node[f.tp] || 0;
|
|
|
|
+ calcData[f.tp] = ZhCalc.mul(node.unit_price, node[f.qty], decimal.tp) || 0;
|
|
|
|
+ }
|
|
if (!_.isMatch(checkData, calcData)) error.push(node);
|
|
if (!_.isMatch(checkData, calcData)) error.push(node);
|
|
}
|
|
}
|
|
return error;
|
|
return error;
|
|
@@ -190,16 +195,26 @@
|
|
check_time: new Date(),
|
|
check_time: new Date(),
|
|
warning_data: [],
|
|
warning_data: [],
|
|
}
|
|
}
|
|
- const sibling = doSomeCheck('#check-sibling', ledgerCheckUtil.checkSibling) || [];
|
|
|
|
- assignWarningData(sibling, ledgerCheckType.sibling.value, checkData.warning_data);
|
|
|
|
- const empty_code = doSomeCheck('#check-empty-code', ledgerCheckUtil.checkCodeEmpty) || [];
|
|
|
|
- assignWarningData(empty_code, ledgerCheckType.empty_code.value, checkData.warning_data);
|
|
|
|
- const calc = doSomeCheck('#check-calc', ledgerCheckUtil.checkCalc) || [];
|
|
|
|
- assignWarningData(calc, ledgerCheckType.calc.value, checkData.warning_data);
|
|
|
|
- const zero = doSomeCheck('#check-zero', ledgerCheckUtil.checkZero) || [];
|
|
|
|
- assignWarningData(zero, ledgerCheckType.zero.value, checkData.warning_data);
|
|
|
|
- const tp = doSomeCheck('#check-tp', ledgerCheckUtil.checkTp) || [];
|
|
|
|
- assignWarningData(tp, ledgerCheckType.tp.value, checkData.warning_data);
|
|
|
|
|
|
+ if (checkOption.sibling.enable) {
|
|
|
|
+ const sibling = doSomeCheck('#check-sibling', ledgerCheckUtil.checkSibling, checkOption.sibling) || [];
|
|
|
|
+ assignWarningData(sibling, ledgerCheckType.sibling.value, checkData.warning_data);
|
|
|
|
+ }
|
|
|
|
+ if (checkOption.empty_code.enable) {
|
|
|
|
+ const empty_code = doSomeCheck('#check-empty-code', ledgerCheckUtil.checkCodeEmpty, checkOption.empty_code) || [];
|
|
|
|
+ assignWarningData(empty_code, ledgerCheckType.empty_code.value, checkData.warning_data);
|
|
|
|
+ }
|
|
|
|
+ if (checkOption.calc.enable) {
|
|
|
|
+ const calc = doSomeCheck('#check-calc', ledgerCheckUtil.checkCalc, checkOption.calc) || [];
|
|
|
|
+ assignWarningData(calc, ledgerCheckType.calc.value, checkData.warning_data);
|
|
|
|
+ }
|
|
|
|
+ if (checkOption.zero.enable) {
|
|
|
|
+ const zero = doSomeCheck('#check-zero', ledgerCheckUtil.checkZero, checkOption.zero) || [];
|
|
|
|
+ assignWarningData(zero, ledgerCheckType.zero.value, checkData.warning_data);
|
|
|
|
+ }
|
|
|
|
+ if (checkOption.tp.enable) {
|
|
|
|
+ const tp = doSomeCheck('#check-tp', ledgerCheckUtil.checkTp, checkOption.tp) || [];
|
|
|
|
+ assignWarningData(tp, ledgerCheckType.tp.value, checkData.warning_data);
|
|
|
|
+ }
|
|
|
|
|
|
$('#ledger-check-waiting').hide();
|
|
$('#ledger-check-waiting').hide();
|
|
setting.checkList.clearCheckData();
|
|
setting.checkList.clearCheckData();
|