|
@@ -1148,14 +1148,18 @@ module.exports = {
|
|
|
return request.url.indexOf('/wap/') !== -1;
|
|
|
},
|
|
|
|
|
|
- checkBillsWithPos(bills, pos, fields) {
|
|
|
- const result = {
|
|
|
+ getDefaultCheckResult() {
|
|
|
+ return {
|
|
|
error: [],
|
|
|
source: {
|
|
|
bills: [],
|
|
|
pos: [],
|
|
|
},
|
|
|
};
|
|
|
+ },
|
|
|
+
|
|
|
+ checkBillsWithPos(bills, pos, fields) {
|
|
|
+ const result = this.getDefaultCheckResult();
|
|
|
for (const b of bills) {
|
|
|
const pr = _.remove(pos, { lid: b.id });
|
|
|
const checkData = {},
|
|
@@ -1186,14 +1190,83 @@ module.exports = {
|
|
|
return result;
|
|
|
},
|
|
|
|
|
|
+ checkBillsOverRange(bills, posRange, isTz) {
|
|
|
+ if (isTz && posRange.length > 0) {
|
|
|
+ for (const p of posRange) {
|
|
|
+ const end_contract_qty = this.add(p.pre_contract_qty, p.contract_qty);
|
|
|
+ if (end_contract_qty > p.quantity) return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ const end_qc_qty = this.add(bills.qc_qty, bills.pre_qc_qty);
|
|
|
+ const end_qc_tp = this.add(bills.qc_tp, bills.pre_qc_tp);
|
|
|
+ const end_gather_qty = this.sum([bills.contract_qty, bills.pre_contract_qty, end_qc_qty]);
|
|
|
+ const end_gather_tp = this.sum([bills.contract_tp, bills.pre_contract_tp, end_qc_tp]);
|
|
|
+ if (isTz) {
|
|
|
+ if (end_gather_qty) {
|
|
|
+ return !bills.quantity || Math.abs(end_gather_qty) > Math.abs(this.add(bills.quantity, end_qc_qty));
|
|
|
+ } else if (end_gather_tp) {
|
|
|
+ return !bills.total_price || Math.abs(end_gather_tp) > Math.abs(this.add(bills.total_price, end_qc_tp));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (end_gather_qty) {
|
|
|
+ return !bills.deal_qty || Math.abs(end_gather_qty) > Math.abs(this.add(bills.deal_qty, end_qc_qty));
|
|
|
+ } else if (end_gather_tp) {
|
|
|
+ return !bills.deal_tp || Math.abs(end_gather_tp) > Math.abs(this.add(bills.deal_tp, end_qc_tp));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ checkBillsWithPos2(bills, pos, fields, checkOver, isTz) {
|
|
|
+ const result = this.getDefaultCheckResult(), overResult = this.getDefaultCheckResult();
|
|
|
+ for (const b of bills) {
|
|
|
+ let hasSource = false;
|
|
|
+ const pr = _.remove(pos, { lid: b.id });
|
|
|
+ const checkData = {},
|
|
|
+ calcData = {};
|
|
|
+ if (pr && pr.length > 0) {
|
|
|
+ for (const field of fields) {
|
|
|
+ checkData[field] = b[field] ? b[field] : 0;
|
|
|
+ }
|
|
|
+ for (const p of pr) {
|
|
|
+ for (const field of fields) {
|
|
|
+ calcData[field] = this.add(calcData[field], p[field]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!_.isMatch(checkData, calcData)) {
|
|
|
+ hasSource = true;
|
|
|
+ result.error.push({
|
|
|
+ ledger_id: b.ledger_id,
|
|
|
+ b_code: b.b_code,
|
|
|
+ name: b.name,
|
|
|
+ error: { checkData, calcData },
|
|
|
+ });
|
|
|
+ result.source.bills.push(b);
|
|
|
+ for (const p of pr) {
|
|
|
+ result.source.pos.push(p);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (checkOver && this.checkBillsOverRange(b, pr, isTz)) {
|
|
|
+ overResult.error.push({
|
|
|
+ ledger_id: b.ledger_id,
|
|
|
+ b_code: b.b_code,
|
|
|
+ name: b.name,
|
|
|
+ });
|
|
|
+ if (!hasSource) {
|
|
|
+ overResult.source.bills.push(b);
|
|
|
+ for (const p of pr) {
|
|
|
+ overResult.source.pos.push(p);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return [result, overResult];
|
|
|
+ },
|
|
|
+
|
|
|
checkBillsTp(bills, field, decimal) {
|
|
|
- const result = {
|
|
|
- error: [],
|
|
|
- source: {
|
|
|
- bills: [],
|
|
|
- pos: [],
|
|
|
- },
|
|
|
- };
|
|
|
+ const result = this.getDefaultCheckResult();
|
|
|
for (const b of bills) {
|
|
|
if (!b.check_calc) continue;
|
|
|
|