kts-component-invoice-operate 3.2.20 → 3.2.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -65,6 +65,8 @@ export default class GoodsListState {
65
65
  isVisibleDrawer: boolean;
66
66
  /** 是否可以合并明细 */
67
67
  isMergeDetails: boolean;
68
+ /** 是否可以合并折扣 */
69
+ isMergeDiscount: boolean;
68
70
  /** 正在 添加商品对照 的货物 */
69
71
  addComparisonIndex?: string;
70
72
  }
@@ -0,0 +1,2 @@
1
+ import { InvoiceControllerState } from '..';
2
+ export default function mergeDiscount(state: InvoiceControllerState): Promise<void>;
@@ -24,6 +24,8 @@ export default class InvoiceController extends InvoiceControllerForm {
24
24
  addGood: (option?: any) => Promise<any>;
25
25
  /** 全单合并明细 */
26
26
  mergeDetails: (option?: any) => Promise<any>;
27
+ /** 全单合并折扣 */
28
+ mergeDiscount: (option?: any) => Promise<any>;
27
29
  /** 给一组货物添加折扣行 */
28
30
  addGoodDiscount: (option?: import("./fns/addGoodDiscount").IOptions | undefined) => Promise<any>;
29
31
  /** 给一组货物添加折扣行 */
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ /** 全单合并折扣 */
3
+ export default function useMergeDiscount(): {
4
+ /** 按钮 */
5
+ button: JSX.Element;
6
+ };
package/dist/index.esm.js CHANGED
@@ -1016,6 +1016,7 @@ var GoodsListState = /*#__PURE__*/_createClass(function GoodsListState() {
1016
1016
  this.productComparison = new ProductComparison();
1017
1017
  this.isVisibleDrawer = false;
1018
1018
  this.isMergeDetails = false;
1019
+ this.isMergeDiscount = false;
1019
1020
  this.addComparisonIndex = void 0;
1020
1021
  });
1021
1022
 
@@ -2028,6 +2029,62 @@ function findMaxIndex(arr) {
2028
2029
  return maxIndex;
2029
2030
  }
2030
2031
 
2032
+ function mergeDiscount(_x) {
2033
+ return _mergeDiscount.apply(this, arguments);
2034
+ }
2035
+
2036
+ function _mergeDiscount() {
2037
+ _mergeDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(state) {
2038
+ var goodsList, i, good, sum, zk;
2039
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2040
+ while (1) {
2041
+ switch (_context.prev = _context.next) {
2042
+ case 0:
2043
+ if (!(state.goodsListState.goodsList.length <= 1 || state.goodsListState.editGood)) {
2044
+ _context.next = 2;
2045
+ break;
2046
+ }
2047
+
2048
+ return _context.abrupt("return");
2049
+
2050
+ case 2:
2051
+ goodsList = state.goodsListState.goodsList.slice();
2052
+
2053
+ for (i = 0; i < goodsList.length; i++) {
2054
+ good = goodsList[i];
2055
+
2056
+ if (good.lineAttribute * 1 === LineAttributeType$1.被折扣行) {
2057
+ sum = _objectSpread2(_objectSpread2({}, good), {}, {
2058
+ $index: idGenerator(),
2059
+ lineAttribute: LineAttributeType$1.正常,
2060
+ discountGroup: undefined
2061
+ });
2062
+ zk = goodsList[i + 1];
2063
+ sum.lineAmountExcludeTax = chain$1(bignumber(good.lineAmountExcludeTax)).subtract(bignumber(Math.abs(zk.lineAmountExcludeTax || 0))).done().toNumber();
2064
+ sum.lineAmountIncludeTax = chain$1(bignumber(good.lineAmountIncludeTax)).subtract(bignumber(Math.abs(zk.lineAmountIncludeTax || 0))).done().toNumber();
2065
+ sum.quantity = good.quantity;
2066
+
2067
+ if (sum.quantity) {
2068
+ sum.priceExcludeTax = chain$1(bignumber(good.lineAmountExcludeTax)).divide(bignumber(good.quantity)).done().toNumber();
2069
+ sum.priceIncludeTax = chain$1(bignumber(good.lineAmountIncludeTax)).divide(bignumber(good.quantity)).done().toNumber();
2070
+ }
2071
+
2072
+ goodsList.splice(i, 2, sum);
2073
+ }
2074
+ }
2075
+
2076
+ state.goodsListState.goodsList = goodsList;
2077
+
2078
+ case 5:
2079
+ case "end":
2080
+ return _context.stop();
2081
+ }
2082
+ }
2083
+ }, _callee);
2084
+ }));
2085
+ return _mergeDiscount.apply(this, arguments);
2086
+ }
2087
+
2031
2088
  var InvoiceController = /*#__PURE__*/function (_InvoiceControllerFor) {
2032
2089
  _inherits(InvoiceController, _InvoiceControllerFor);
2033
2090
 
@@ -2049,6 +2106,7 @@ var InvoiceController = /*#__PURE__*/function (_InvoiceControllerFor) {
2049
2106
  _this.delGood = _this.pipeline(delGood);
2050
2107
  _this.addGood = _this.pipeline(addGood);
2051
2108
  _this.mergeDetails = _this.pipeline(mergeDetails);
2109
+ _this.mergeDiscount = _this.pipeline(mergeDiscount);
2052
2110
  _this.addGoodDiscount = _this.pipeline(addGoodDiscount);
2053
2111
  _this.addGoodDiscountV2 = _this.pipeline(addGoodDiscountV2);
2054
2112
  _this.getGoodsList = void 0;
@@ -10216,12 +10274,100 @@ function ItemNameInput(props) {
10216
10274
  };
10217
10275
  }(), [autoComplete.onItemNameSearch]);
10218
10276
  var onChangeAutoComplete = React.useCallback(function (itemName) {
10219
- var _controller$state$goo;
10220
-
10221
- var good = options.filter(function (e) {
10277
+ // const good = options.filter(e=>e.itemName === itemName)[0];
10278
+ // good && controller.state.goodsListState.form?.setFieldsValue(removeNullUndefined(good));
10279
+ var record = options.filter(function (e) {
10222
10280
  return e.itemName === itemName;
10223
10281
  })[0];
10224
- good && ((_controller$state$goo = controller.state.goodsListState.form) === null || _controller$state$goo === void 0 ? void 0 : _controller$state$goo.setFieldsValue(removeNullUndefined(good)));
10282
+ debugger;
10283
+ if (!record) return;
10284
+ controller.run( /*#__PURE__*/function () {
10285
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(s) {
10286
+ var between, editGood;
10287
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
10288
+ while (1) {
10289
+ switch (_context2.prev = _context2.next) {
10290
+ case 0:
10291
+ Object.keys(record).filter(function (e) {
10292
+ return !record[e] && record[e] !== 0;
10293
+ }).forEach(function (e) {
10294
+ delete record[e];
10295
+ }); // 没用 被编辑的货物 和 form 就退出
10296
+
10297
+ if (!(!s.goodsListState.editGood || !s.goodsListState.form)) {
10298
+ _context2.next = 3;
10299
+ break;
10300
+ }
10301
+
10302
+ return _context2.abrupt("return");
10303
+
10304
+ case 3:
10305
+ // 导入时清空之前输入的值,使用导入的单价和税率(参考税局系统)
10306
+ record.quantity = undefined;
10307
+ record.lineAmountExcludeTax = undefined;
10308
+ record.lineAmountIncludeTax = undefined; // 中间数据
10309
+
10310
+ between = _objectSpread2({}, record);
10311
+ between.itemName = record.itemName;
10312
+ between.itemNameOther = record.itemName; // 设置编辑货物
10313
+
10314
+ editGood = s.goodsListState.editGood = _objectSpread2(_objectSpread2({}, s.goodsListState.editGood), between);
10315
+
10316
+ if (editGood.taxRate) {
10317
+ editGood.taxRate = dutyFree(controller, editGood.taxRate, s.goodsListState.form, editGood);
10318
+ }
10319
+
10320
+ if ("".concat(editGood.priceIncludeTax) === '0') {
10321
+ editGood.priceIncludeTax = undefined;
10322
+ editGood.priceExcludeTax = undefined;
10323
+ } else {
10324
+ editGood.priceExcludeTax = getPriceExcludeTax(editGood, record, s.calculatingDigits);
10325
+ }
10326
+
10327
+ if (editGood.quantity && editGood.priceIncludeTax) {
10328
+ editGood.lineAmountIncludeTax = countAmountIncludeTax(editGood.quantity, editGood.priceIncludeTax, s.calculatingDigits);
10329
+ } // 导入FORM里
10330
+
10331
+
10332
+ if (s.goodsListState.isMyShow) {
10333
+ s.goodsListState.form.setFieldsValue(_objectSpread2(_objectSpread2({}, editGood), {}, {
10334
+ itemName: editGood.itemNameSelf,
10335
+ itemModelName: editGood.itemModelNameSelf
10336
+ }));
10337
+ } else {
10338
+ s.goodsListState.form.setFieldsValue(_objectSpread2({}, editGood));
10339
+ }
10340
+
10341
+ s.goodsListState.importGoods.isVisibleDrawer = false;
10342
+
10343
+ if (!s.goodsListState.isTaxIncluded) {
10344
+ _context2.next = 20;
10345
+ break;
10346
+ }
10347
+
10348
+ _context2.next = 18;
10349
+ return updateUnitPriceExcludingTax(controller, s.goodsListState.form, record);
10350
+
10351
+ case 18:
10352
+ _context2.next = 22;
10353
+ break;
10354
+
10355
+ case 20:
10356
+ _context2.next = 22;
10357
+ return updateUnitPriceTax(controller, s.goodsListState.form, record);
10358
+
10359
+ case 22:
10360
+ case "end":
10361
+ return _context2.stop();
10362
+ }
10363
+ }
10364
+ }, _callee2);
10365
+ }));
10366
+
10367
+ return function (_x2) {
10368
+ return _ref2.apply(this, arguments);
10369
+ };
10370
+ }());
10225
10371
  }, [options, controller]);
10226
10372
  return React.createElement("div", {
10227
10373
  className: 'kts-invoice-operate-goods-list-itemName-input'
@@ -10246,19 +10392,23 @@ function ItemNameInput(props) {
10246
10392
  value: props.value,
10247
10393
  onChange: onChange
10248
10394
  })));
10249
- }
10395
+ } // function removeNullUndefined(obj: Record<string, any>): Record<string, any> {
10396
+ // const filteredObj: Record<string, any> = {};
10397
+ // for (const key in obj) {
10398
+ // if (obj[key] !== null && obj[key] !== undefined) {
10399
+ // filteredObj[key] = obj[key];
10400
+ // }
10401
+ // }
10402
+ // return filteredObj;
10403
+ // }
10250
10404
 
10251
- function removeNullUndefined(obj) {
10252
- var filteredObj = {};
10405
+ /** 货物单价,不含税 */
10253
10406
 
10254
- for (var key in obj) {
10255
- if (obj[key] !== null && obj[key] !== undefined) {
10256
- filteredObj[key] = obj[key];
10257
- }
10258
- }
10407
+ var getPriceExcludeTax = function getPriceExcludeTax(s, record, calculatingDigits) {
10408
+ if (!s.taxRate && s.taxRate !== 0 || !record.priceIncludeTax && record.priceIncludeTax !== 0) return; // 单价(含税)/(1+税率) = 单价(不含税)
10259
10409
 
10260
- return filteredObj;
10261
- }
10410
+ return format15(evaluate("".concat(record.priceIncludeTax, " / (1+").concat(s.taxRate, "/100)")), calculatingDigits);
10411
+ };
10262
10412
 
10263
10413
  /** 拆分全称加简称 */
10264
10414
  var getSN = function getSN(value) {
@@ -12406,7 +12556,7 @@ function useMergeDetails() {
12406
12556
  }
12407
12557
  }
12408
12558
  }, _callee);
12409
- })), []);
12559
+ })), [controller]);
12410
12560
  var button = React.useMemo(function () {
12411
12561
  if (!isMergeDetails) return React.createElement(React.Fragment, null);
12412
12562
  return React.createElement(Button, {
@@ -12420,6 +12570,52 @@ function useMergeDetails() {
12420
12570
  };
12421
12571
  }
12422
12572
 
12573
+ /** 全单合并折扣 */
12574
+
12575
+ function useMergeDiscount() {
12576
+ var controller = Invoice.useInvoiceController();
12577
+ var goodsList = controller.useMemo(function (s) {
12578
+ return s.goodsListState.goodsList;
12579
+ }, []);
12580
+ var isMergeDiscount = controller.useMemo(function (s) {
12581
+ return s.goodsListState.isMergeDiscount;
12582
+ }, []);
12583
+ var onClick = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
12584
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
12585
+ while (1) {
12586
+ switch (_context.prev = _context.next) {
12587
+ case 0:
12588
+ _context.next = 2;
12589
+ return controller.saveEditGood();
12590
+
12591
+ case 2:
12592
+ _context.next = 4;
12593
+ return controller.wait();
12594
+
12595
+ case 4:
12596
+ _context.next = 6;
12597
+ return controller.mergeDiscount();
12598
+
12599
+ case 6:
12600
+ case "end":
12601
+ return _context.stop();
12602
+ }
12603
+ }
12604
+ }, _callee);
12605
+ })), [controller]);
12606
+ var button = React.useMemo(function () {
12607
+ if (!isMergeDiscount) return React.createElement(React.Fragment, null);
12608
+ return React.createElement(Button, {
12609
+ onClick: onClick,
12610
+ disabled: goodsList.length <= 1
12611
+ }, "\u5408\u5E76\u6298\u6263");
12612
+ }, [goodsList.length]);
12613
+ return {
12614
+ /** 按钮 */
12615
+ button: button
12616
+ };
12617
+ }
12618
+
12423
12619
  var GoodsList = /*#__PURE__*/function (_React$Component) {
12424
12620
  _inherits(GoodsList, _React$Component);
12425
12621
 
@@ -12479,6 +12675,9 @@ var Main = decorator(Form.create())(function (props) {
12479
12675
  /** 全单合并明细 */
12480
12676
 
12481
12677
  var mergeDetails = useMergeDetails();
12678
+ /** 全单合并折扣 */
12679
+
12680
+ var mergeDiscount = useMergeDiscount();
12482
12681
  /** 清空自动赋码缓存 */
12483
12682
 
12484
12683
  React.useEffect(function () {
@@ -12636,7 +12835,7 @@ var Main = decorator(Form.create())(function (props) {
12636
12835
  className: "kts-invoice-operate-goods-list-able"
12637
12836
  }, React.createElement("div", {
12638
12837
  className: "kts-invoice-operate-goods-list-able-list"
12639
- }, React.createElement(AddRowButton, null), endowCodeButton.button, delRowButton.button, mergeDetails.button, addDiscountRowButton.drawer, React.createElement(Search, null)), React.createElement("div", {
12838
+ }, React.createElement(AddRowButton, null), endowCodeButton.button, delRowButton.button, mergeDetails.button, mergeDiscount.button, addDiscountRowButton.drawer, React.createElement(Search, null)), React.createElement("div", {
12640
12839
  className: "kts-invoice-operate-goods-list-able-extend"
12641
12840
  }, props.menuExpansion, React.createElement(DescribeSwitch, null), React.createElement(TaxIncludedSwitch, null))), React.createElement("div", {
12642
12841
  className: classnames('kts-invoice-operate-goods-list-table', {
@@ -19650,7 +19849,7 @@ var DrawerBody$2 = function DrawerBody() {
19650
19849
  editGood.priceIncludeTax = undefined;
19651
19850
  editGood.priceExcludeTax = undefined;
19652
19851
  } else {
19653
- editGood.priceExcludeTax = getPriceExcludeTax(editGood, record, s.calculatingDigits);
19852
+ editGood.priceExcludeTax = getPriceExcludeTax$1(editGood, record, s.calculatingDigits);
19654
19853
  }
19655
19854
 
19656
19855
  if (editGood.quantity && editGood.priceIncludeTax) {
@@ -19712,7 +19911,7 @@ var DrawerBody$2 = function DrawerBody() {
19712
19911
  /** 货物单价,不含税 */
19713
19912
 
19714
19913
 
19715
- var getPriceExcludeTax = function getPriceExcludeTax(s, record, calculatingDigits) {
19914
+ var getPriceExcludeTax$1 = function getPriceExcludeTax(s, record, calculatingDigits) {
19716
19915
  if (!s.taxRate && s.taxRate !== 0 || !record.priceIncludeTax && record.priceIncludeTax !== 0) return; // 单价(含税)/(1+税率) = 单价(不含税)
19717
19916
 
19718
19917
  return format15(evaluate("".concat(record.priceIncludeTax, " / (1+").concat(s.taxRate, "/100)")), calculatingDigits);
package/dist/index.js CHANGED
@@ -1026,6 +1026,7 @@ var GoodsListState = /*#__PURE__*/_createClass(function GoodsListState() {
1026
1026
  this.productComparison = new ProductComparison();
1027
1027
  this.isVisibleDrawer = false;
1028
1028
  this.isMergeDetails = false;
1029
+ this.isMergeDiscount = false;
1029
1030
  this.addComparisonIndex = void 0;
1030
1031
  });
1031
1032
 
@@ -2038,6 +2039,62 @@ function findMaxIndex(arr) {
2038
2039
  return maxIndex;
2039
2040
  }
2040
2041
 
2042
+ function mergeDiscount(_x) {
2043
+ return _mergeDiscount.apply(this, arguments);
2044
+ }
2045
+
2046
+ function _mergeDiscount() {
2047
+ _mergeDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(state) {
2048
+ var goodsList, i, good, sum, zk;
2049
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2050
+ while (1) {
2051
+ switch (_context.prev = _context.next) {
2052
+ case 0:
2053
+ if (!(state.goodsListState.goodsList.length <= 1 || state.goodsListState.editGood)) {
2054
+ _context.next = 2;
2055
+ break;
2056
+ }
2057
+
2058
+ return _context.abrupt("return");
2059
+
2060
+ case 2:
2061
+ goodsList = state.goodsListState.goodsList.slice();
2062
+
2063
+ for (i = 0; i < goodsList.length; i++) {
2064
+ good = goodsList[i];
2065
+
2066
+ if (good.lineAttribute * 1 === LineAttributeType$1.被折扣行) {
2067
+ sum = _objectSpread2(_objectSpread2({}, good), {}, {
2068
+ $index: idGenerator(),
2069
+ lineAttribute: LineAttributeType$1.正常,
2070
+ discountGroup: undefined
2071
+ });
2072
+ zk = goodsList[i + 1];
2073
+ sum.lineAmountExcludeTax = mathjs.chain(mathjs.bignumber(good.lineAmountExcludeTax)).subtract(mathjs.bignumber(Math.abs(zk.lineAmountExcludeTax || 0))).done().toNumber();
2074
+ sum.lineAmountIncludeTax = mathjs.chain(mathjs.bignumber(good.lineAmountIncludeTax)).subtract(mathjs.bignumber(Math.abs(zk.lineAmountIncludeTax || 0))).done().toNumber();
2075
+ sum.quantity = good.quantity;
2076
+
2077
+ if (sum.quantity) {
2078
+ sum.priceExcludeTax = mathjs.chain(mathjs.bignumber(good.lineAmountExcludeTax)).divide(mathjs.bignumber(good.quantity)).done().toNumber();
2079
+ sum.priceIncludeTax = mathjs.chain(mathjs.bignumber(good.lineAmountIncludeTax)).divide(mathjs.bignumber(good.quantity)).done().toNumber();
2080
+ }
2081
+
2082
+ goodsList.splice(i, 2, sum);
2083
+ }
2084
+ }
2085
+
2086
+ state.goodsListState.goodsList = goodsList;
2087
+
2088
+ case 5:
2089
+ case "end":
2090
+ return _context.stop();
2091
+ }
2092
+ }
2093
+ }, _callee);
2094
+ }));
2095
+ return _mergeDiscount.apply(this, arguments);
2096
+ }
2097
+
2041
2098
  var InvoiceController = /*#__PURE__*/function (_InvoiceControllerFor) {
2042
2099
  _inherits(InvoiceController, _InvoiceControllerFor);
2043
2100
 
@@ -2059,6 +2116,7 @@ var InvoiceController = /*#__PURE__*/function (_InvoiceControllerFor) {
2059
2116
  _this.delGood = _this.pipeline(delGood);
2060
2117
  _this.addGood = _this.pipeline(addGood);
2061
2118
  _this.mergeDetails = _this.pipeline(mergeDetails);
2119
+ _this.mergeDiscount = _this.pipeline(mergeDiscount);
2062
2120
  _this.addGoodDiscount = _this.pipeline(addGoodDiscount);
2063
2121
  _this.addGoodDiscountV2 = _this.pipeline(addGoodDiscountV2);
2064
2122
  _this.getGoodsList = void 0;
@@ -10226,12 +10284,100 @@ function ItemNameInput(props) {
10226
10284
  };
10227
10285
  }(), [autoComplete.onItemNameSearch]);
10228
10286
  var onChangeAutoComplete = React__default['default'].useCallback(function (itemName) {
10229
- var _controller$state$goo;
10230
-
10231
- var good = options.filter(function (e) {
10287
+ // const good = options.filter(e=>e.itemName === itemName)[0];
10288
+ // good && controller.state.goodsListState.form?.setFieldsValue(removeNullUndefined(good));
10289
+ var record = options.filter(function (e) {
10232
10290
  return e.itemName === itemName;
10233
10291
  })[0];
10234
- good && ((_controller$state$goo = controller.state.goodsListState.form) === null || _controller$state$goo === void 0 ? void 0 : _controller$state$goo.setFieldsValue(removeNullUndefined(good)));
10292
+ debugger;
10293
+ if (!record) return;
10294
+ controller.run( /*#__PURE__*/function () {
10295
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(s) {
10296
+ var between, editGood;
10297
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
10298
+ while (1) {
10299
+ switch (_context2.prev = _context2.next) {
10300
+ case 0:
10301
+ Object.keys(record).filter(function (e) {
10302
+ return !record[e] && record[e] !== 0;
10303
+ }).forEach(function (e) {
10304
+ delete record[e];
10305
+ }); // 没用 被编辑的货物 和 form 就退出
10306
+
10307
+ if (!(!s.goodsListState.editGood || !s.goodsListState.form)) {
10308
+ _context2.next = 3;
10309
+ break;
10310
+ }
10311
+
10312
+ return _context2.abrupt("return");
10313
+
10314
+ case 3:
10315
+ // 导入时清空之前输入的值,使用导入的单价和税率(参考税局系统)
10316
+ record.quantity = undefined;
10317
+ record.lineAmountExcludeTax = undefined;
10318
+ record.lineAmountIncludeTax = undefined; // 中间数据
10319
+
10320
+ between = _objectSpread2({}, record);
10321
+ between.itemName = record.itemName;
10322
+ between.itemNameOther = record.itemName; // 设置编辑货物
10323
+
10324
+ editGood = s.goodsListState.editGood = _objectSpread2(_objectSpread2({}, s.goodsListState.editGood), between);
10325
+
10326
+ if (editGood.taxRate) {
10327
+ editGood.taxRate = dutyFree(controller, editGood.taxRate, s.goodsListState.form, editGood);
10328
+ }
10329
+
10330
+ if ("".concat(editGood.priceIncludeTax) === '0') {
10331
+ editGood.priceIncludeTax = undefined;
10332
+ editGood.priceExcludeTax = undefined;
10333
+ } else {
10334
+ editGood.priceExcludeTax = getPriceExcludeTax(editGood, record, s.calculatingDigits);
10335
+ }
10336
+
10337
+ if (editGood.quantity && editGood.priceIncludeTax) {
10338
+ editGood.lineAmountIncludeTax = countAmountIncludeTax(editGood.quantity, editGood.priceIncludeTax, s.calculatingDigits);
10339
+ } // 导入FORM里
10340
+
10341
+
10342
+ if (s.goodsListState.isMyShow) {
10343
+ s.goodsListState.form.setFieldsValue(_objectSpread2(_objectSpread2({}, editGood), {}, {
10344
+ itemName: editGood.itemNameSelf,
10345
+ itemModelName: editGood.itemModelNameSelf
10346
+ }));
10347
+ } else {
10348
+ s.goodsListState.form.setFieldsValue(_objectSpread2({}, editGood));
10349
+ }
10350
+
10351
+ s.goodsListState.importGoods.isVisibleDrawer = false;
10352
+
10353
+ if (!s.goodsListState.isTaxIncluded) {
10354
+ _context2.next = 20;
10355
+ break;
10356
+ }
10357
+
10358
+ _context2.next = 18;
10359
+ return updateUnitPriceExcludingTax(controller, s.goodsListState.form, record);
10360
+
10361
+ case 18:
10362
+ _context2.next = 22;
10363
+ break;
10364
+
10365
+ case 20:
10366
+ _context2.next = 22;
10367
+ return updateUnitPriceTax(controller, s.goodsListState.form, record);
10368
+
10369
+ case 22:
10370
+ case "end":
10371
+ return _context2.stop();
10372
+ }
10373
+ }
10374
+ }, _callee2);
10375
+ }));
10376
+
10377
+ return function (_x2) {
10378
+ return _ref2.apply(this, arguments);
10379
+ };
10380
+ }());
10235
10381
  }, [options, controller]);
10236
10382
  return React__default['default'].createElement("div", {
10237
10383
  className: 'kts-invoice-operate-goods-list-itemName-input'
@@ -10256,19 +10402,23 @@ function ItemNameInput(props) {
10256
10402
  value: props.value,
10257
10403
  onChange: onChange
10258
10404
  })));
10259
- }
10405
+ } // function removeNullUndefined(obj: Record<string, any>): Record<string, any> {
10406
+ // const filteredObj: Record<string, any> = {};
10407
+ // for (const key in obj) {
10408
+ // if (obj[key] !== null && obj[key] !== undefined) {
10409
+ // filteredObj[key] = obj[key];
10410
+ // }
10411
+ // }
10412
+ // return filteredObj;
10413
+ // }
10260
10414
 
10261
- function removeNullUndefined(obj) {
10262
- var filteredObj = {};
10415
+ /** 货物单价,不含税 */
10263
10416
 
10264
- for (var key in obj) {
10265
- if (obj[key] !== null && obj[key] !== undefined) {
10266
- filteredObj[key] = obj[key];
10267
- }
10268
- }
10417
+ var getPriceExcludeTax = function getPriceExcludeTax(s, record, calculatingDigits) {
10418
+ if (!s.taxRate && s.taxRate !== 0 || !record.priceIncludeTax && record.priceIncludeTax !== 0) return; // 单价(含税)/(1+税率) = 单价(不含税)
10269
10419
 
10270
- return filteredObj;
10271
- }
10420
+ return format15(evaluate("".concat(record.priceIncludeTax, " / (1+").concat(s.taxRate, "/100)")), calculatingDigits);
10421
+ };
10272
10422
 
10273
10423
  /** 拆分全称加简称 */
10274
10424
  var getSN = function getSN(value) {
@@ -12416,7 +12566,7 @@ function useMergeDetails() {
12416
12566
  }
12417
12567
  }
12418
12568
  }, _callee);
12419
- })), []);
12569
+ })), [controller]);
12420
12570
  var button = React__default['default'].useMemo(function () {
12421
12571
  if (!isMergeDetails) return React__default['default'].createElement(React__default['default'].Fragment, null);
12422
12572
  return React__default['default'].createElement(ktsComponentsAntdX3.Button, {
@@ -12430,6 +12580,52 @@ function useMergeDetails() {
12430
12580
  };
12431
12581
  }
12432
12582
 
12583
+ /** 全单合并折扣 */
12584
+
12585
+ function useMergeDiscount() {
12586
+ var controller = Invoice.useInvoiceController();
12587
+ var goodsList = controller.useMemo(function (s) {
12588
+ return s.goodsListState.goodsList;
12589
+ }, []);
12590
+ var isMergeDiscount = controller.useMemo(function (s) {
12591
+ return s.goodsListState.isMergeDiscount;
12592
+ }, []);
12593
+ var onClick = React__default['default'].useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
12594
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
12595
+ while (1) {
12596
+ switch (_context.prev = _context.next) {
12597
+ case 0:
12598
+ _context.next = 2;
12599
+ return controller.saveEditGood();
12600
+
12601
+ case 2:
12602
+ _context.next = 4;
12603
+ return controller.wait();
12604
+
12605
+ case 4:
12606
+ _context.next = 6;
12607
+ return controller.mergeDiscount();
12608
+
12609
+ case 6:
12610
+ case "end":
12611
+ return _context.stop();
12612
+ }
12613
+ }
12614
+ }, _callee);
12615
+ })), [controller]);
12616
+ var button = React__default['default'].useMemo(function () {
12617
+ if (!isMergeDiscount) return React__default['default'].createElement(React__default['default'].Fragment, null);
12618
+ return React__default['default'].createElement(ktsComponentsAntdX3.Button, {
12619
+ onClick: onClick,
12620
+ disabled: goodsList.length <= 1
12621
+ }, "\u5408\u5E76\u6298\u6263");
12622
+ }, [goodsList.length]);
12623
+ return {
12624
+ /** 按钮 */
12625
+ button: button
12626
+ };
12627
+ }
12628
+
12433
12629
  var GoodsList = /*#__PURE__*/function (_React$Component) {
12434
12630
  _inherits(GoodsList, _React$Component);
12435
12631
 
@@ -12489,6 +12685,9 @@ var Main = GreyReactBox.decorator(ktsComponentsAntdX3.Form.create())(function (p
12489
12685
  /** 全单合并明细 */
12490
12686
 
12491
12687
  var mergeDetails = useMergeDetails();
12688
+ /** 全单合并折扣 */
12689
+
12690
+ var mergeDiscount = useMergeDiscount();
12492
12691
  /** 清空自动赋码缓存 */
12493
12692
 
12494
12693
  React__default['default'].useEffect(function () {
@@ -12646,7 +12845,7 @@ var Main = GreyReactBox.decorator(ktsComponentsAntdX3.Form.create())(function (p
12646
12845
  className: "kts-invoice-operate-goods-list-able"
12647
12846
  }, React__default['default'].createElement("div", {
12648
12847
  className: "kts-invoice-operate-goods-list-able-list"
12649
- }, React__default['default'].createElement(AddRowButton, null), endowCodeButton.button, delRowButton.button, mergeDetails.button, addDiscountRowButton.drawer, React__default['default'].createElement(Search, null)), React__default['default'].createElement("div", {
12848
+ }, React__default['default'].createElement(AddRowButton, null), endowCodeButton.button, delRowButton.button, mergeDetails.button, mergeDiscount.button, addDiscountRowButton.drawer, React__default['default'].createElement(Search, null)), React__default['default'].createElement("div", {
12650
12849
  className: "kts-invoice-operate-goods-list-able-extend"
12651
12850
  }, props.menuExpansion, React__default['default'].createElement(DescribeSwitch, null), React__default['default'].createElement(TaxIncludedSwitch, null))), React__default['default'].createElement("div", {
12652
12851
  className: classnames__default['default']('kts-invoice-operate-goods-list-table', {
@@ -19660,7 +19859,7 @@ var DrawerBody$2 = function DrawerBody() {
19660
19859
  editGood.priceIncludeTax = undefined;
19661
19860
  editGood.priceExcludeTax = undefined;
19662
19861
  } else {
19663
- editGood.priceExcludeTax = getPriceExcludeTax(editGood, record, s.calculatingDigits);
19862
+ editGood.priceExcludeTax = getPriceExcludeTax$1(editGood, record, s.calculatingDigits);
19664
19863
  }
19665
19864
 
19666
19865
  if (editGood.quantity && editGood.priceIncludeTax) {
@@ -19722,7 +19921,7 @@ var DrawerBody$2 = function DrawerBody() {
19722
19921
  /** 货物单价,不含税 */
19723
19922
 
19724
19923
 
19725
- var getPriceExcludeTax = function getPriceExcludeTax(s, record, calculatingDigits) {
19924
+ var getPriceExcludeTax$1 = function getPriceExcludeTax(s, record, calculatingDigits) {
19726
19925
  if (!s.taxRate && s.taxRate !== 0 || !record.priceIncludeTax && record.priceIncludeTax !== 0) return; // 单价(含税)/(1+税率) = 单价(不含税)
19727
19926
 
19728
19927
  return format15(evaluate("".concat(record.priceIncludeTax, " / (1+").concat(s.taxRate, "/100)")), calculatingDigits);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kts-component-invoice-operate",
3
- "version": "3.2.20",
3
+ "version": "3.2.23",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",
@@ -92,6 +92,9 @@ export default class GoodsListState {
92
92
  /** 是否可以合并明细 */
93
93
  isMergeDetails = false;
94
94
 
95
+ /** 是否可以合并折扣 */
96
+ isMergeDiscount = false;
97
+
95
98
  /** 正在 添加商品对照 的货物 */
96
99
  addComparisonIndex?: string;
97
100
  }
@@ -0,0 +1,29 @@
1
+
2
+
3
+ import { IGood, InvoiceControllerState, LineAttributeType } from '..';
4
+ import { chain, bignumber } from 'mathjs';
5
+ import idGenerator from '../../tools/idGenerator';
6
+
7
+ export default async function mergeDiscount(state: InvoiceControllerState) {
8
+ if (state.goodsListState.goodsList.length <= 1 || state.goodsListState.editGood) return;
9
+
10
+ const goodsList = state.goodsListState.goodsList.slice();
11
+ for (let i = 0; i < goodsList.length; i++) {
12
+ const good = goodsList[i];
13
+ if (good.lineAttribute * 1 === LineAttributeType.被折扣行) {
14
+ const sum: IGood = { ...good, $index: idGenerator(), lineAttribute: LineAttributeType.正常, discountGroup: undefined };
15
+ const zk = goodsList[i + 1];
16
+
17
+ sum.lineAmountExcludeTax = chain(bignumber(good.lineAmountExcludeTax)).subtract(bignumber(Math.abs(zk.lineAmountExcludeTax || 0))).done().toNumber();
18
+ sum.lineAmountIncludeTax = chain(bignumber(good.lineAmountIncludeTax)).subtract(bignumber(Math.abs(zk.lineAmountIncludeTax || 0))).done().toNumber();
19
+ sum.quantity = good.quantity;
20
+ if (sum.quantity) {
21
+ sum.priceExcludeTax = chain(bignumber(good.lineAmountExcludeTax)).divide(bignumber(good.quantity)).done().toNumber();
22
+ sum.priceIncludeTax = chain(bignumber(good.lineAmountIncludeTax)).divide(bignumber(good.quantity)).done().toNumber();
23
+ }
24
+
25
+ goodsList.splice(i, 2, sum);
26
+ }
27
+ }
28
+ state.goodsListState.goodsList = goodsList;
29
+ }
@@ -12,6 +12,7 @@ import addGood from './fns/addGood';
12
12
  import saveEditGood from './fns/saveEditGood';
13
13
  import getGoodsSearch from './fns/getGoodsSearch';
14
14
  import mergeDetails from './fns/mergeDetails';
15
+ import mergeDiscount from './fns/mergeDiscount';
15
16
 
16
17
  export { default as InvoiceControllerState } from './InvoiceControllerState';
17
18
  export { default as IGood } from './InvoiceControllerState/GoodsListState/IGood';
@@ -52,6 +53,9 @@ export default class InvoiceController extends InvoiceControllerForm {
52
53
  /** 全单合并明细 */
53
54
  mergeDetails = this.pipeline<any>(mergeDetails);
54
55
 
56
+ /** 全单合并折扣 */
57
+ mergeDiscount = this.pipeline<any>(mergeDiscount);
58
+
55
59
  /** 给一组货物添加折扣行 */
56
60
  addGoodDiscount = this.pipeline(addGoodDiscount);
57
61
 
@@ -2,8 +2,11 @@
2
2
  import { Input } from 'kts-components-antd-x3';
3
3
  import React, { ChangeEvent } from 'react';
4
4
  import { AutoComplete } from 'kts-xui';
5
+ import { countAmountIncludeTax } from '../../../../../../../tools/calculate'
5
6
  import { IGood, Invoice } from '../../../../../../../..';
6
7
  import './index.less';
8
+ import { dutyFree, format15, updateUnitPriceExcludingTax, updateUnitPriceTax } from '../../autoFillFn';
9
+ import evaluate from '../../../../../../../tools/evaluate';
7
10
 
8
11
  export default function ItemNameInput(props: { onChange?: (e: ChangeEvent<HTMLInputElement>) => void, value?: string, shorthand?: string }) {
9
12
 
@@ -30,8 +33,64 @@ export default function ItemNameInput(props: { onChange?: (e: ChangeEvent<HTMLIn
30
33
  }, [autoComplete.onItemNameSearch])
31
34
 
32
35
  const onChangeAutoComplete = React.useCallback(itemName => {
33
- const good = options.filter(e=>e.itemName === itemName)[0];
34
- good && controller.state.goodsListState.form?.setFieldsValue(removeNullUndefined(good));
36
+ // const good = options.filter(e=>e.itemName === itemName)[0];
37
+ // good && controller.state.goodsListState.form?.setFieldsValue(removeNullUndefined(good));
38
+
39
+ const record = options.filter(e => e.itemName === itemName)[0] as any;
40
+ debugger;
41
+ if (!record) return;
42
+ controller.run(async s => {
43
+ Object.keys(record).filter(e => !record[e] && record[e] !== 0).forEach(e => { delete record[e] });
44
+
45
+ // 没用 被编辑的货物 和 form 就退出
46
+ if (!s.goodsListState.editGood || !s.goodsListState.form) return;
47
+
48
+ // 导入时清空之前输入的值,使用导入的单价和税率(参考税局系统)
49
+ record.quantity = undefined;
50
+ record.lineAmountExcludeTax = undefined;
51
+ record.lineAmountIncludeTax = undefined;
52
+
53
+ // 中间数据
54
+ const between = { ...record };
55
+ between.itemName = record.itemName;
56
+ between.itemNameOther = record.itemName;
57
+
58
+ // 设置编辑货物
59
+ const editGood: IGood = s.goodsListState.editGood = { ...s.goodsListState.editGood, ...between };
60
+
61
+ if (editGood.taxRate) {
62
+ editGood.taxRate = dutyFree(controller, editGood.taxRate, s.goodsListState.form, editGood)
63
+ }
64
+
65
+ if (`${editGood.priceIncludeTax}` === '0') {
66
+ editGood.priceIncludeTax = undefined;
67
+ editGood.priceExcludeTax = undefined;
68
+ } else {
69
+ editGood.priceExcludeTax = getPriceExcludeTax(editGood, record, s.calculatingDigits) as number;
70
+ }
71
+
72
+ if (editGood.quantity && editGood.priceIncludeTax) {
73
+ editGood.lineAmountIncludeTax = countAmountIncludeTax(editGood.quantity, editGood.priceIncludeTax, s.calculatingDigits);
74
+ }
75
+
76
+ // 导入FORM里
77
+ if (s.goodsListState.isMyShow) {
78
+ s.goodsListState.form.setFieldsValue({
79
+ ...editGood,
80
+ itemName: editGood.itemNameSelf,
81
+ itemModelName: editGood.itemModelNameSelf,
82
+ });
83
+ } else {
84
+ s.goodsListState.form.setFieldsValue({
85
+ ...editGood,
86
+ });
87
+ }
88
+
89
+ s.goodsListState.importGoods.isVisibleDrawer = false;
90
+ s.goodsListState.isTaxIncluded
91
+ ? await updateUnitPriceExcludingTax(controller, s.goodsListState.form, record)
92
+ : await updateUnitPriceTax(controller, s.goodsListState.form, record)
93
+ })
35
94
  }, [options, controller])
36
95
 
37
96
  return (
@@ -45,14 +104,22 @@ export default function ItemNameInput(props: { onChange?: (e: ChangeEvent<HTMLIn
45
104
  }
46
105
 
47
106
 
48
- function removeNullUndefined(obj: Record<string, any>): Record<string, any> {
49
- const filteredObj: Record<string, any> = {};
50
-
51
- for (const key in obj) {
52
- if (obj[key] !== null && obj[key] !== undefined) {
53
- filteredObj[key] = obj[key];
54
- }
55
- }
56
-
57
- return filteredObj;
58
- }
107
+ // function removeNullUndefined(obj: Record<string, any>): Record<string, any> {
108
+ // const filteredObj: Record<string, any> = {};
109
+
110
+ // for (const key in obj) {
111
+ // if (obj[key] !== null && obj[key] !== undefined) {
112
+ // filteredObj[key] = obj[key];
113
+ // }
114
+ // }
115
+
116
+ // return filteredObj;
117
+ // }
118
+
119
+ /** 货物单价,不含税 */
120
+ const getPriceExcludeTax = (s: IGood, record: any, calculatingDigits?: number) => {
121
+ if ((!s.taxRate && s.taxRate !== 0) || (!record.priceIncludeTax && record.priceIncludeTax !== 0)) return;
122
+
123
+ // 单价(含税)/(1+税率) = 单价(不含税)
124
+ return format15(evaluate(`${record.priceIncludeTax} / (1+${s.taxRate}/100)`), calculatingDigits);
125
+ };
@@ -28,6 +28,7 @@ import useEndowCodeButton from './ui/BulkMenu/hooks/useEndowCodeButton';
28
28
  import useDelRowButton from './ui/BulkMenu/hooks/useDelRowButton';
29
29
  import useAddDiscountRowButton from './ui/BulkMenu/hooks/useAddDiscountRowButton';
30
30
  import useMergeDetails from './ui/BulkMenu/hooks/useMergeDetails';
31
+ import useMergeDiscount from './ui/BulkMenu/hooks/useMergeDiscount';
31
32
 
32
33
  export interface IGoodsListProps {
33
34
  /** 扩展部分 */
@@ -87,6 +88,9 @@ const Main = decorator<IGoodsListProps, FormComponentProps & IGoodsListProps>(Fo
87
88
  /** 全单合并明细 */
88
89
  const mergeDetails = useMergeDetails()
89
90
 
91
+ /** 全单合并折扣 */
92
+ const mergeDiscount = useMergeDiscount()
93
+
90
94
  /** 清空自动赋码缓存 */
91
95
  React.useEffect(() => {
92
96
  controller.run(async s => { s.goodsListState.endowCode.cache = {} });
@@ -139,6 +143,9 @@ const Main = decorator<IGoodsListProps, FormComponentProps & IGoodsListProps>(Fo
139
143
  {/* 全单合并明细 */}
140
144
  {mergeDetails.button}
141
145
 
146
+ {/* 全单合并折扣 */}
147
+ {mergeDiscount.button}
148
+
142
149
  {/* 添加折扣行 */}
143
150
  {addDiscountRowButton.drawer}
144
151
 
@@ -16,7 +16,7 @@ export default function useMergeDetails() {
16
16
  await controller.saveEditGood();
17
17
  await controller.wait();
18
18
  await controller.mergeDetails();
19
- }, [])
19
+ }, [controller])
20
20
 
21
21
  const button = React.useMemo(() => {
22
22
  if (!isMergeDetails) return <></>;
@@ -0,0 +1,37 @@
1
+
2
+ import React from "react"
3
+ import { Button } from "kts-components-antd-x3"
4
+ import Invoice from '../../../../../../..'
5
+
6
+ /** 全单合并折扣 */
7
+ export default function useMergeDiscount() {
8
+
9
+ const controller = Invoice.useInvoiceController();
10
+
11
+ const goodsList = controller.useMemo(s => s.goodsListState.goodsList, []);
12
+
13
+ const isMergeDiscount = controller.useMemo(s => s.goodsListState.isMergeDiscount, []);
14
+
15
+ const onClick = React.useCallback(async () => {
16
+ await controller.saveEditGood();
17
+ await controller.wait();
18
+ await controller.mergeDiscount();
19
+ }, [controller])
20
+
21
+ const button = React.useMemo(() => {
22
+ if (!isMergeDiscount) return <></>;
23
+ return (
24
+ <Button
25
+ onClick={onClick}
26
+ disabled={goodsList.length <= 1}
27
+ >
28
+ 合并折扣
29
+ </Button>
30
+ )
31
+ }, [goodsList.length])
32
+
33
+ return {
34
+ /** 按钮 */
35
+ button,
36
+ }
37
+ }