tplus-pos
Version:
pos module
167 lines (142 loc) • 7.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SingleRepeatCashProcessBlock = undefined;
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _SplitAmountProcessor = require('../../SplitAmountProcessor');
var _QuantityChangeProcessorBlock = require('../../quantity/QuantityChangeProcessorBlock');
var _UpdateRetailDetailProcessor = require('../UpdateRetailDetailProcessor');
var _MergeDetailsProcessorBlock = require('../../MergeDetailsProcessorBlock');
var _DetailCodeProcessor = require('../../DetailCodeProcessor');
var _cloneDeep2 = require('lodash/cloneDeep');
var _cloneDeep3 = _interopRequireDefault(_cloneDeep2);
var _mobx = require('mobx');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* 单品返现成倍赠送
*
*
*/
var SingleRepeatCashProcessBlock = exports.SingleRepeatCashProcessBlock = function () {
function SingleRepeatCashProcessBlock() {
(0, _classCallCheck3.default)(this, SingleRepeatCashProcessBlock);
}
(0, _createClass3.default)(SingleRepeatCashProcessBlock, null, [{
key: 'execute',
value: function execute(retailDto, promotionDto) {
//按照返现金额倒叙
promotionDto.Details.sort(function (a, b) {
return b.DiscountAmount - a.DiscountAmount;
});
var totalQuantity = promotionDto.RetailDetails.Sum("Quantity");
promotionDto.RetailDetails.forEach(function (item) {
var findIndex = retailDto.RetailDetails.findIndex(function (it) {
return it.Code == item.Code;
});
retailDto.RetailDetails.splice(findIndex, 1);
});
var usedStart = 0;
while (totalQuantity > 0) {
var promotionDetailDto = promotionDto.Details.find(function (it) {
return it.QuantityMeet <= totalQuantity;
});
if (!promotionDetailDto) {
this.FindSalesRetailDetailDTOs(promotionDto, usedStart, totalQuantity, retailDto);
totalQuantity = 0;
break;
}
var mult = parseInt(Math.Divide(totalQuantity, promotionDetailDto.QuantityMeet));
var salesQuantity = Math.Multiply(mult, promotionDetailDto.QuantityMeet);
//需要找出这么多的数量,执行促销返现
var retailDetails = this.FindSalesRetailDetailDTOs(promotionDto, usedStart, salesQuantity, retailDto);
//执行分摊返现
var totalCashBack = Math.Multiply(mult, promotionDetailDto.DiscountAmount);
_SplitAmountProcessor.SplitAmountProcessor.execute(retailDto, retailDetails, totalCashBack, "DetailDiscountAmount", "DiscountAmountChange", false);
retailDetails.forEach(function (detail) {
_UpdateRetailDetailProcessor.UpdateRetailDetailProcessor.execute(detail, promotionDto, false, retailDto.Code);
});
totalQuantity = totalQuantity - salesQuantity;
usedStart = usedStart + salesQuantity;
}
//合并零售单
_MergeDetailsProcessorBlock.MergeDetailsProcessorBlock.execute(retailDto);
_DetailCodeProcessor.DetailCodeProcessor.execute(retailDto);
}
}, {
key: 'FindSalesRetailDetailDTOs',
value: function FindSalesRetailDetailDTOs(promotionDto, usedStart, salesQuantity, retailDto) {
var _this = this;
var startIndex = 0;
var usedQuantity = 0;
var retailDetails = [];
promotionDto.RetailDetails.forEach(function (item) {
startIndex = startIndex + item.Quantity;
if (startIndex <= usedStart) {
return;
}
var detailDto = (0, _cloneDeep3.default)((0, _mobx.toJS)(item));
var quantity = detailDto.Quantity - usedStart;
if (quantity >= salesQuantity - usedQuantity) {
detailDto.Quantity = salesQuantity - usedQuantity;
retailDetails.push(detailDto); //数量都满足,然后跳出循环
if (detailDto.Quantity != item.Quantity) {
_QuantityChangeProcessorBlock.QuantityChangeProcessorBlock.execute(retailDto, detailDto, detailDto.Quantity, { isNotExecRunSingleDiscountProcessBlock: true });
}
retailDto.RetailDetails.push(detailDto);
} else {
var detailUsed = retailDto.RetailDetails.filter(function (c) {
return c.Code == item.Code;
}).Sum("Quantity");
detailDto.Quantity = detailDto.Quantity - detailUsed;
retailDetails.push(detailDto);
if (quantity != item.Quantity) {
_QuantityChangeProcessorBlock.QuantityChangeProcessorBlock.execute(retailDto, detailDto, detailDto.Quantity, { isNotExecRunSingleDiscountProcessBlock: true });
}
retailDto.RetailDetails.push(detailDto);
usedQuantity = usedQuantity + detailDto.Quantity;
}
});
return retailDto.RetailDetails.filter(function (it) {
return retailDetails.some(function (detail) {
return _this.getDetailKey(detail) == _this.getDetailKey(it);
});
});
}
/**
* 获取当前列的key
*
* @param {*} detail
* @returns
*/
}, {
key: 'getDetailKey',
value: function getDetailKey(detail) {
var returnKey = "";
var keyFields = "FreeItem0,FreeItem1,FreeItem2,FreeItem3,FreeItem4,FreeItem5,FreeItem6,FreeItem7,FreeItem8,FreeItem9,Idinventory,Idunit,Idunit2,Batch,ProductionDate,ExpiryDate,Quantity,SerialNumber";
var keyArrays = keyFields.split(",");
for (var index = 0; index < keyArrays.length; index++) {
var value = "";
if (JSON.getCellValue(detail, keyArrays[index])) {
value = JSON.getCellValue(detail, keyArrays[index]);
}
if (value && (keyArrays[index] == 'ProductionDate' || keyArrays[index] == 'ExpiryDate')) {
var date = value;
if (typeof value == "string") {
date = new Date(value);
}
value = date.toLocaleDateString();
}
returnKey = returnKey + "|" + keyArrays[index] + "=" + value;
}
return returnKey;
}
}]);
return SingleRepeatCashProcessBlock;
}(); /**
* 执行成倍返现类型
*/
//# sourceMappingURL=SingleRepeatCashProcessBlock.js.map