ledger.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const itemsPre = 'id_';
  10. class baseTree {
  11. /**
  12. * 构造函数
  13. */
  14. constructor (ctx, setting) {
  15. this.ctx = ctx;
  16. // 无索引
  17. this.datas = [];
  18. // 以key为索引
  19. this.items = {};
  20. // 以排序为索引
  21. this.nodes = [];
  22. // 根节点
  23. this.children = [];
  24. // 树设置
  25. this.setting = setting;
  26. }
  27. clear() {
  28. // 无索引
  29. this.datas = [];
  30. // 以key为索引
  31. this.items = {};
  32. // 以排序为索引
  33. this.nodes = [];
  34. // 根节点
  35. this.children = [];
  36. }
  37. /**
  38. * 根据id获取树结构节点数据
  39. * @param {Number} id
  40. * @returns {Object}
  41. */
  42. getItems (id) {
  43. return this.items[itemsPre + id];
  44. };
  45. /**
  46. * 查找node的parent
  47. * @param {Object} node
  48. * @returns {Object}
  49. */
  50. getParent (node) {
  51. return this.getItems(node[this.setting.pid]);
  52. };
  53. /**
  54. * 查询node的已下载子节点
  55. * @param {Object} node
  56. * @returns {Array}
  57. */
  58. getChildren (node) {
  59. const setting = this.setting;
  60. const pid = node ? node[setting.id] : setting.rootId;
  61. const children = this.datas.filter(function (x) {
  62. return x[setting.pid] === pid;
  63. });
  64. children.sort(function (a, b) {
  65. return a.order - b.order;
  66. });
  67. return children;
  68. };
  69. /**
  70. * 获取节点的 index
  71. * @param node
  72. * @returns {number}
  73. */
  74. getNodeSerialNo(node) {
  75. return this.nodes.indexOf(node);
  76. }
  77. /**
  78. * 树结构根据显示排序
  79. */
  80. sortTreeNode (isResort) {
  81. const self = this;
  82. const addSortNodes = function (nodes) {
  83. if (!nodes) { return }
  84. for (let i = 0; i < nodes.length; i++) {
  85. self.nodes.push(nodes[i]);
  86. nodes[i].index = self.nodes.length - 1;
  87. if (!isResort) {
  88. nodes[i].children = self.getChildren(nodes[i]);
  89. } else {
  90. nodes[i].children.sort(function (a, b) {
  91. return a.order - b.order;
  92. })
  93. }
  94. addSortNodes(nodes[i].children);
  95. }
  96. };
  97. this.nodes = [];
  98. if (!isResort) {
  99. this.children = this.getChildren();
  100. } else {
  101. this.children.sort(function (a, b) {
  102. return a.order - b.order;
  103. })
  104. }
  105. addSortNodes(this.children);
  106. }
  107. /**
  108. * 加载数据(初始化), 并给数据添加部分树结构必须数据
  109. * @param datas
  110. */
  111. loadDatas (datas) {
  112. // 清空旧数据
  113. this.items = {};
  114. this.nodes = [];
  115. this.datas = [];
  116. this.children = [];
  117. // 加载全部数据
  118. datas.sort(function (a, b) {
  119. return a.level - b.level;
  120. });
  121. for (const data of datas) {
  122. const keyName = itemsPre + data[this.setting.id];
  123. if (!this.items[keyName]) {
  124. const item = JSON.parse(JSON.stringify(data));
  125. item.children = [];
  126. item.expanded = true;
  127. item.visible = true;
  128. this.items[keyName] = item;
  129. this.datas.push(item);
  130. if (item[this.setting.pid] === this.setting.rootId) {
  131. this.children.push(item);
  132. } else {
  133. const parent = this.getParent(item);
  134. if (parent) {
  135. parent.children.push(item);
  136. }
  137. }
  138. }
  139. }
  140. this.children.sort(function (a, b) {
  141. return a.order - b.order;
  142. });
  143. this.sortTreeNode(true);
  144. }
  145. /**
  146. * 递归方式 查询node的已下载的全部后代 (兼容full_path不存在的情况)
  147. * @param node
  148. * @returns {*}
  149. * @private
  150. */
  151. _recursiveGetPosterity (node) {
  152. let posterity = node.children;
  153. for (const c of node.children) {
  154. posterity = posterity.concat(this._recursiveGetPosterity(c));
  155. }
  156. return posterity;
  157. };
  158. /**
  159. * 查询node的已下载的全部后代
  160. * @param {Object} node
  161. * @returns {Array}
  162. */
  163. getPosterity (node) {
  164. const self = this;
  165. let posterity;
  166. if (node.full_path !== '') {
  167. const reg = new RegExp('^' + node.full_path + '-');
  168. posterity = this.datas.filter(function (x) {
  169. return reg.test(x.full_path);
  170. });
  171. } else {
  172. posterity = this._recursiveGetPosterity(node);
  173. }
  174. posterity.sort(function (x, y) {
  175. return self.getNodeSerialNo(x) - self.getNodeSerialNo(y);
  176. });
  177. return posterity;
  178. };
  179. /**
  180. * 根据 字段名称 获取数据
  181. * @param fields
  182. * @returns {Array}
  183. */
  184. getDatas (fields) {
  185. const datas = [];
  186. for (const node of this.nodes) {
  187. if (node.b_code && node.b_code !== '') node.chapter = this.ctx.helper.getChapterCode(node.b_code);
  188. node.is_leaf = !node.children || node.children.length === 0;
  189. const data = {};
  190. for (const field of fields) {
  191. data[field] = node[field];
  192. }
  193. datas.push(data);
  194. }
  195. return datas;
  196. }
  197. /**
  198. * 排除 某些字段 获取数据
  199. * @param fields
  200. * @returns {Array}
  201. */
  202. getDatasWithout (fields, filter) {
  203. const datas = [];
  204. for (const node of this.nodes) {
  205. if (filter && filter(node)) {
  206. continue;
  207. }
  208. if (node.b_code && node.b_code !== '') node.chapter = this.ctx.helper.getChapterCode(node.b_code);
  209. node.is_leaf = !node.children || node.children.length === 0;
  210. const data = {};
  211. for (const field in node) {
  212. if (fields.indexOf(field) === -1) {
  213. data[field] = node[field];
  214. }
  215. }
  216. datas.push(data);
  217. }
  218. return datas;
  219. }
  220. /**
  221. * 获取默认数据 剔除一些树结构需要的缓存数据
  222. * @returns {Array}
  223. */
  224. getDefaultDatas(filter) {
  225. return this.getDatasWithout(['expanded', 'visible', 'children', 'index'], filter);
  226. }
  227. _mapTreeNode () {
  228. let map = {}, maxLevel = 0;
  229. for (const node of this.nodes) {
  230. let levelArr = map[node.level];
  231. if (!levelArr) {
  232. levelArr = [];
  233. map[node.level] = levelArr;
  234. }
  235. if (node.level > maxLevel) {
  236. maxLevel = node.level;
  237. }
  238. levelArr.push(node);
  239. }
  240. return [maxLevel, map];
  241. }
  242. _calculateNode (node, fun) {
  243. const self = this;
  244. if (node.children && node.children.length > 0) {
  245. const gather = node.children.reduce(function (rst, x) {
  246. const result = {};
  247. for (const cf of self.setting.calcFields) {
  248. result[cf] = self.ctx.helper.add(rst[cf], x[cf]);
  249. }
  250. return result;
  251. });
  252. // 汇总子项
  253. for (const cf of this.setting.calcFields) {
  254. if (gather[cf]) {
  255. node[cf] = gather[cf];
  256. } else {
  257. node[cf] = null;
  258. }
  259. }
  260. }
  261. // 自身运算
  262. if (fun) {
  263. fun(node);
  264. } else if (this.setting.calc) {
  265. this.setting.calc(node, this.ctx.helper);
  266. }
  267. }
  268. calculateAll(fun) {
  269. const [maxLevel, levelMap] = this._mapTreeNode();
  270. for (let i = maxLevel; i >= 0; i--) {
  271. const levelNodes = levelMap[i];
  272. if (levelNodes && levelNodes.length > 0) {
  273. for (const node of levelNodes) {
  274. this._calculateNode(node, fun);
  275. }
  276. }
  277. }
  278. }
  279. }
  280. class billsTree extends baseTree {
  281. /**
  282. * 检查节点是否是最底层项目节
  283. * @param node
  284. * @returns {boolean}
  285. */
  286. isLeafXmj(node) {
  287. if (node.b_code && node.b_code !== '') {
  288. return false;
  289. }
  290. for (const child of node.children) {
  291. if (!child.b_code || child.b_code === '') {
  292. return false;
  293. }
  294. }
  295. return true;
  296. }
  297. /**
  298. * 查询最底层项目节(本身或父项)
  299. * @param {Object} node - 查询节点
  300. * @returns {Object}
  301. */
  302. getLeafXmjParent(node) {
  303. let parent = node;
  304. while (parent) {
  305. if (this.isLeafXmj(parent)) {
  306. return parent;
  307. } else {
  308. parent = this.getParent(parent);
  309. }
  310. }
  311. return null;
  312. }
  313. }
  314. class filterTree extends baseTree {
  315. addData(data, fields) {
  316. const item = {};
  317. for (const prop in data) {
  318. if (fields.indexOf(prop) >= 0) {
  319. item[prop] = data[prop];
  320. }
  321. }
  322. const keyName = itemsPre + item[this.setting.id];
  323. if (!this.items[keyName]) {
  324. item.children = [];
  325. item.is_leaf = true;
  326. item.expanded = true;
  327. item.visible = true;
  328. this.items[keyName] = item;
  329. this.datas.push(item);
  330. if (item[this.setting.pid] === this.setting.rootId) {
  331. this.children.push(item);
  332. } else {
  333. const parent = this.getParent(item);
  334. if (parent) {
  335. parent.is_leaf = false;
  336. parent.children.push(item);
  337. }
  338. }
  339. } else {
  340. return this.items[keyName];
  341. }
  342. return item;
  343. }
  344. }
  345. class filterGatherTree extends baseTree {
  346. clearDatas() {
  347. this.items = {};
  348. this.nodes = [];
  349. this.datas = [];
  350. this.children = [];
  351. }
  352. get newId() {
  353. if (!this._maxId) {
  354. this._maxId = 0;
  355. }
  356. this._maxId++;
  357. return this._maxId;
  358. }
  359. addNode(data, parent) {
  360. data[this.setting.pid] = parent ? parent[this.setting.id] : this.setting.rootId;
  361. let item = this.ctx.helper._.find(this.items, data);
  362. if (item) return item;
  363. item = data;
  364. item.drawing_code = [];
  365. item.memo = [];
  366. item.postil = [];
  367. item[this.setting.id] = this.newId;
  368. const keyName = itemsPre + item[this.setting.id];
  369. item.children = [];
  370. item.is_leaf = true;
  371. item.expanded = true;
  372. item.visible = true;
  373. this.items[keyName] = item;
  374. this.datas.push(item);
  375. if (parent) {
  376. item[this.setting.fullPath] = parent[this.setting.fullPath] + '-' + item[this.setting.id];
  377. item[this.setting.level] = parent[this.setting.level] + 1;
  378. item[this.setting.order] = parent.children.length + 1;
  379. parent.is_leaf = false;
  380. parent.children.push(item);
  381. } else {
  382. item[this.setting.fullPath] = '' + item[this.setting.id];
  383. item[this.setting.level] = 1;
  384. item[this.setting.order] = this.children.length + 1;
  385. this.children.push(item);
  386. }
  387. return item;
  388. }
  389. generateSortNodes() {
  390. const self = this;
  391. const addSortNode = function (node) {
  392. self.nodes.push(node);
  393. for (const c of node.children) {
  394. addSortNode(c);
  395. }
  396. };
  397. this.nodes = [];
  398. for (const n of this.children) {
  399. addSortNode(n);
  400. }
  401. }
  402. sortTreeNodeCustom(fun) {
  403. const sortNodes = function (nodes) {
  404. nodes.sort(fun);
  405. for (const [i, node] of nodes.entries()) {
  406. node.order = i + 1;
  407. }
  408. for (const node of nodes) {
  409. if (node.children && node.children.length > 1) {
  410. sortNodes(node.children);
  411. }
  412. }
  413. };
  414. this.nodes = [];
  415. this.children = this.getChildren(null);
  416. sortNodes(this.children);
  417. this.generateSortNodes();
  418. }
  419. }
  420. class gatherTree extends baseTree {
  421. constructor(ctx, setting) {
  422. super(ctx, setting);
  423. this._newId = 1;
  424. }
  425. get newId() {
  426. return this._newId++;
  427. }
  428. loadGatherNode(node, parent, loadFun) {
  429. const siblings = parent ? parent.children : this.children;
  430. let cur = siblings.find(function (x) {
  431. return node.b_code
  432. ? x.b_code === node.b_code && x.name === node.name && x.unit === node.unit && x.unit_price === node.unit_price
  433. : x.code === node.code && x.name === node.name;
  434. });
  435. if (!cur) {
  436. const id = this.newId;
  437. cur = {
  438. id: id,
  439. pid: parent ? parent.id : this.setting.rootId,
  440. full_path: parent ? parent.full_path + '-' + id : '' + id,
  441. level: parent ? parent.level + 1 : 1,
  442. order: siblings.length + 1,
  443. children: [],
  444. code: node.code, b_code: node.b_code, name: node.name,
  445. unit: node.unit, unit_price: node.unit_price,
  446. };
  447. siblings.push(cur);
  448. this.datas.push(cur);
  449. }
  450. loadFun(cur, node);
  451. for (const c of node.children) {
  452. this.loadGatherNode(c, cur, loadFun);
  453. }
  454. }
  455. generateSortNodes() {
  456. const self = this;
  457. const addSortNode = function (node) {
  458. self.nodes.push(node);
  459. for (const c of node.children) {
  460. addSortNode(c);
  461. }
  462. };
  463. this.nodes = [];
  464. for (const n of this.children) {
  465. addSortNode(n);
  466. }
  467. }
  468. loadGatherTree(sourceTree, loadFun) {
  469. for (const c of sourceTree.children) {
  470. this.loadGatherNode(c, null, loadFun);
  471. }
  472. // todo load Pos Data;
  473. }
  474. calculateSum() {
  475. if (this.setting.calcSum) {
  476. for (const d of this.datas) {
  477. this.setting.calcSum(d, this.count);
  478. }
  479. }
  480. }
  481. }
  482. class pos {
  483. /**
  484. * 构造函数
  485. * @param {id|Number, masterId|Number} setting
  486. */
  487. constructor (setting) {
  488. // 无索引
  489. this.datas = [];
  490. // 以key为索引
  491. this.items = {};
  492. // 以分类id为索引的有序
  493. this.ledgerPos = {};
  494. // pos设置
  495. this.setting = setting;
  496. }
  497. /**
  498. * 加载部位明细数据
  499. * @param datas
  500. */
  501. loadDatas(datas) {
  502. this.datas = datas;
  503. this.items = {};
  504. this.ledgerPos = {};
  505. for (const data of this.datas) {
  506. const key = itemsPre + data[this.setting.id];
  507. this.items[key] = data;
  508. const masterKey = itemsPre + data[this.setting.ledgerId];
  509. if (!this.ledgerPos[masterKey]) {
  510. this.ledgerPos[masterKey] = [];
  511. }
  512. this.ledgerPos[masterKey].push(data);
  513. }
  514. for (const prop in this.ledgerPos) {
  515. this.resortLedgerPos(this.ledgerPos[prop]);
  516. }
  517. }
  518. getLedgerPos(mid) {
  519. return this.ledgerPos[itemsPre + mid];
  520. }
  521. resortLedgerPos(ledgerPos) {
  522. if (ledgerPos instanceof Array) {
  523. ledgerPos.sort(function (a, b) {
  524. return a.porder - b.porder;
  525. })
  526. }
  527. }
  528. /**
  529. * 计算全部
  530. */
  531. calculateAll(fun) {
  532. const calcFun = fun ? fun : this.setting.calc;
  533. if (!calcFun) return;
  534. for (const pos of this.datas) {
  535. calcFun(pos);
  536. }
  537. }
  538. getDatas () {
  539. return this.datas;
  540. }
  541. }
  542. class checkData {
  543. constructor(ctx) {
  544. this.ctx = ctx;
  545. this.checkBills = new billsTree(ctx, { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1 });
  546. this.checkPos = new pos({ id: 'id', ledgerId: 'lid' });
  547. }
  548. _check3f(data, limit, ratio) {
  549. if (limit === 0) {
  550. if (data.contract_tp || data.pre_contract_tp) return 1; // 违规
  551. }
  552. if (limit === 1) {
  553. if (ratio === 0) {
  554. if (!data.contract_tp && !data.pre_contract_tp) return 2; // 漏计
  555. } else {
  556. const tp = this.ctx.helper.mul(data.total_price, this.ctx.helper.div(ratio, 100, 4), this.ctx.tender.info.decimal.tp);
  557. const checkTp = this.ctx.helper.add(data.contract_tp, data.pre_contract_tp);
  558. if (tp > checkTp) return 1; // 违规
  559. if (tp < checkTp) return 2; // 漏计
  560. }
  561. }
  562. return 0; // 合法
  563. }
  564. _check3fQty(data, limit, ratio, unit) {
  565. if (limit === 0) {
  566. if (data.contract_qty || data.qc_qty || data.pre_contract_qty || data.pre_qc_qty) return 1; // 违规
  567. }
  568. if (limit === 1) {
  569. if (!ratio || ratio === 0) {
  570. if (!data.contract_qty && !data.qc_qty && !data.pre_contract_qty && !data.pre_qc_qty) return 2; // 漏计
  571. } else {
  572. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, unit);
  573. const checkQty = this.ctx.helper.mul(data.quantity, this.ctx.helper.div(ratio, 100, 4), precision.value);
  574. const qty = this.ctx.helper.add(data.contract_qty, data.pre_contract_qty);
  575. if (qty > checkQty) return 1; // 违规
  576. if (qty < checkQty) return 2; // 漏计
  577. }
  578. }
  579. return 0; // 合法
  580. }
  581. _getRatio(type, status) {
  582. if (type === 'gxby') return null;
  583. const gs = this.ctx.session.sessionProject.dagl_status.find(x => { return x.value === status });
  584. return gs ? gs.ratio : null;
  585. }
  586. _getValid = function (type, status, limit) {
  587. if (limit) {
  588. const statusConst = type === 'gxby' ? this.ctx.session.sessionProject.gxby_status : this.ctx.session.sessionProject.dagl_status;
  589. const sc = statusConst.find(x => { return x.value === status; });
  590. return sc ? (sc.limit ? 1 : 0) : 0;
  591. } else {
  592. return -1;
  593. }
  594. };
  595. _checkLeafBills3fLimit(checkType, bills, result, checkInfo) {
  596. const over = [], lost = [];
  597. const posRange = this.checkPos.getLedgerPos(bills.id);
  598. if (posRange && posRange.length > 0) {
  599. for (const p of posRange) {
  600. const posCheckInfo = this.ctx.helper._.assign({}, checkInfo);
  601. for (const ct of checkType) {
  602. if (p[ct + '_limit'] > 0) {
  603. posCheckInfo[ct + '_limit'] = p[ct + '_limit'];
  604. }
  605. }
  606. for (const ct of checkType) {
  607. const checkResult = this._check3fQty(p, this._getValid(ct, p[ct + '_status'], posCheckInfo[ct + '_limit']), this._getRatio(ct, p[ct+'_status']), bills.unit);
  608. if (checkResult === 1) {
  609. if (over.indexOf(ct) === -1) over.push(ct);
  610. }
  611. if (checkResult === 2) {
  612. if (lost.indexOf(ct) === -1) lost.push(ct);
  613. }
  614. }
  615. }
  616. } else {
  617. for (const ct of checkType) {
  618. const checkResult = bills.is_tp
  619. ? this._check3f(bills, this._getValid(ct, bills[ct + '_status'], checkInfo[ct + '_limit']), this._getRatio(ct, bills[ct+'_status']))
  620. : this._check3fQty(bills, this._getValid(ct, bills[ct + '_status'], checkInfo[ct + '_limit']), this._getRatio(ct, bills[ct+'_status']), bills.unit);
  621. if (checkResult === 1) {
  622. if (over.indexOf(ct) === -1) over.push(ct);
  623. }
  624. if (checkResult === 2) {
  625. if (lost.indexOf(ct) === -1) lost.push(ct);
  626. }
  627. }
  628. }
  629. if (over.length + lost.length > 0) {
  630. for (const o of over) {
  631. result.error.push({
  632. ledger_id: bills.ledger_id,
  633. b_code: bills.b_code,
  634. name: bills.name,
  635. errorType: 's2b_over_' + o,
  636. });
  637. }
  638. for (const l of lost) {
  639. result.error.push({
  640. ledger_id: bills.ledger_id,
  641. b_code: bills.b_code,
  642. name: bills.name,
  643. errorType: 's2b_lost_' + l,
  644. });
  645. }
  646. result.source.bills.push(bills);
  647. if (posRange && posRange.length > 0) result.source.pos.push(...posRange);
  648. }
  649. }
  650. _recursiveCheckBills3fLimit(checkType, bills, result, parentCheckInfo) {
  651. const checkInfo = this.ctx.helper._.assign({}, parentCheckInfo);
  652. for (const ct of checkType) {
  653. if (bills[ct + '_limit'] > 0) {
  654. checkInfo[ct + '_limit'] = bills[ct + '_limit'];
  655. }
  656. }
  657. if (bills.children && bills.children.length > 0) {
  658. for (const c of bills.children) {
  659. this._recursiveCheckBills3fLimit(checkType, c, result, checkInfo);
  660. }
  661. } else {
  662. this._checkLeafBills3fLimit(checkType, bills, result, checkInfo);
  663. }
  664. }
  665. loadData(bills, pos) {
  666. this.checkBills.loadDatas(bills);
  667. this.checkPos.loadDatas(pos);
  668. }
  669. checkSibling() {
  670. const error = [];
  671. for (const node of this.checkBills.nodes) {
  672. if (!node.children || node.children.length === 0) continue;
  673. let hasXmj, hasGcl;
  674. for (const child of node.children) {
  675. if (child.b_code) hasXmj = true;
  676. if (!child.b_code) hasGcl = true;
  677. }
  678. if (hasXmj && hasGcl) error.push({
  679. ledger_id: node.ledger_id,
  680. b_code: node.b_code,
  681. name: node.name,
  682. errorType: 'sibling',
  683. });
  684. }
  685. return error;
  686. }
  687. checkSameCode() {
  688. const error = [];
  689. let xmj = this.checkBills.nodes.filter(x => { return /^((GD*)|G)?[0-9]+/.test(x.code); });
  690. let check = null;
  691. while (xmj.length > 0) {
  692. [check, xmj] = this.ctx.helper._.partition(xmj, x => { return x.code === xmj[0].code; });
  693. if (check.length > 1) {
  694. for (const c of check) {
  695. error.push({
  696. ledger_id: c.ledger_id,
  697. b_code: c.b_code,
  698. name: c.name,
  699. errorType: 'same_code',
  700. })
  701. }
  702. }
  703. }
  704. return error;
  705. }
  706. check3fLimit(tender) {
  707. const result = {
  708. error: [],
  709. source: {bills: [], pos: []},
  710. };
  711. const check = [];
  712. if (tender.s2b_gxby_limit) check.push('gxby');
  713. if (tender.s2b_dagl_limit) check.push('dagl');
  714. if (check.length === 0) return result;
  715. for (const b of this.checkBills.children) {
  716. this._recursiveCheckBills3fLimit(check, b, result, {});
  717. }
  718. return result;
  719. }
  720. }
  721. module.exports = {
  722. billsTree,
  723. pos,
  724. filterTree,
  725. filterGatherTree,
  726. gatherTree,
  727. checkData,
  728. };