private void BaseButton_ConfirmRefund_Click(object sender, EventArgs e) { try { if (originalRetailCostume == null) { GlobalMessageBox.Show("请选择销售单!"); return; } if (!string.IsNullOrEmpty(this.originalRetailCostume.RetailOrder.RefundOrderID)) { GlobalMessageBox.Show("该销售单号已经退过货,不能再次退货!"); return; } if (this.originalRetailCostume.RetailOrder.IsCancel) { GlobalMessageBox.Show("该销售单号已被冲单!"); return; } if (this.guideComboBox1.SelectedIndex == 0) { GlobalMessageBox.Show("该笔单的导购员不能为空!"); return; } string id = IDHelper.GetID(OrderPrefix.RefundOrder, GlobalCache.GetShop(shopID).AutoCode); //if (this.currentRetailCostume.RetailOrder.ShopID != shopID || this.currentRetailCostume.RetailOrder.EmOnline) //{ // GlobalMessageBox.Show("该商品不是在本店销售的,不能退货!"); // return; //} bool isNoHasGuidFlag = false; if (this.currentRetailCostume.RetailDetailList != null && this.currentRetailCostume.RetailDetailList.Count > 0) { foreach (RetailDetail detail in this.currentRetailCostume.RetailDetailList) { if (detail.GuideID == null || detail.GuideID == "") { isNoHasGuidFlag = true; break; } } } if (isNoHasGuidFlag) { GlobalMessageBox.Show("导购员不能为空,请检查列表里所有款号的导购员!"); return; } #region 创建RefundCostume对象 string selectShopid = ValidateUtil.CheckEmptyValue(this.skinComboBoxShopID.SelectedValue); List <Guide> guideList = CommonGlobalCache.GuideList.FindAll(t => t.State == 0 && t.ShopID == selectShopid); this.GuideName.DataSource = guideList; this.GuideName.DisplayMember = "Name"; this.GuideName.ValueMember = "ID"; RefundCostume costume = new RefundCostume() { RefundOrder = null, RefundDetailList = new List <RetailDetail>() }; int totalCount = 0; decimal totalPrice = 0; decimal totalCost = 0; foreach (RetailDetail detail in this.currentRetailCostume.RetailDetailList) { if (detail.IsRefund && detail.RefundCount > 0) { totalCount += detail.RefundCount; totalPrice += detail.RefundCount * detail.Price; totalCost += detail.RefundCount * detail.CostPrice; costume.RefundDetailList.Add(this.RetailDetailToRefundDetail(detail, id)); } } List <String> costumeIds = new List <string>(); foreach (var item in costume.RefundDetailList) { if (!costumeIds.Contains(item.CostumeID)) { costumeIds.Add(item.CostumeID); } } if (costumeIds != null && costumeIds.Count > 0) { //判断是否又禁用的商品,并提示返回 InteractResult interactResult = GlobalCache.ServerProxy.IsCostumeValid(costumeIds); if (interactResult.ExeResult == ExeResult.Error) { GlobalMessageBox.Show(interactResult.Msg); return; } } RetailOrder refundOrder = new RetailOrder() { ID = id, IsRefundOrder = true, OriginOrderID = this.currentRetailCostume.RetailOrder.ID, // GuideID = this.currentRetailCostume.RetailOrder.GuideID, // OperateGuideID = this.currentRetailCostume.RetailOrder.GuideID, GuideID = (string)this.guideComboBox1.SelectedValue, ShopID = shopID, MemeberID = this.currentRetailCostume.RetailOrder.MemeberID, SalesPromotionID = this.currentRetailCostume.RetailOrder.SalesPromotionID, PromotionText = this.currentRetailCostume.RetailOrder.PromotionText, EntryUserID = CommonGlobalCache.CurrentUserID, // TotalMoneyReceived = this.currentRetailCostume.RetailOrder.TotalMoneyReceived, // TotalMoneyReceivedActual = this.currentRetailCostume.RetailOrder.TotalMoneyReceivedActual, MoneyBankCard = 0, MoneyWeiXin = 0, MoneyAlipay = 0, MoneyOther = 0, SmallMoneyRemoved = 0, MoneyChange = 0, TotalCount = totalCount * -1, TotalCost = totalCost * -1, TotalPrice = totalPrice * -1, MoneyDiscounted = -totalCount == this.originalRetailCostume.RetailOrder.TotalCount ? this.originalRetailCostume.RetailOrder.MoneyDiscounted * -1 : 0,//若是全部退款,折扣金额为原始折扣金额,否则为0 Remarks = this.skinTextBox_RefundReason.SkinTxt.Text.Trim(), CreateTime = dateTimePicker_Start.Value, EntryTime = DateTime.Now, IsNotPay = this.currentRetailCostume.RetailOrder.IsNotPay, }; costume.RefundOrder = refundOrder; #endregion decimal sourceTotalMoneyReceived = this.currentRetailCostume.RetailOrder.TotalMoneyReceived; #region 根据活动获取退款的金额,并赋值给RefundCostume decimal originalDonate = 0; if (this.originalRetailCostume.RetailOrder.MoneyVipCard != 0) { originalDonate = this.originalRetailCostume.RetailOrder.MoneyVipCardDonate / this.originalRetailCostume.RetailOrder.MoneyVipCard; } //应该退还的金额 decimal moneyBuyByTicket = CalGiftTicket(costume); SettlementMoney settlementMoney = new SettlementMoney(balanceRound); RefundMoney refundMoney = settlementMoney.GetRefundMoney(this.originalRetailCostume, costume, moneyBuyByTicket, GlobalCache.GetSalesPromotionFromAll(this.originalRetailCostume.RetailOrder.SalesPromotionID), GlobalCache.CurrentShop.MinDiscount); costume.RefundOrder.MoneyCash = refundMoney.RefundCash * -1; costume.RefundOrder.MoneyCash2 = costume.RefundOrder.MoneyCash; costume.RefundOrder.MoneyIntegration = refundMoney.RefundIntegration * -1; costume.RefundOrder.MoneyVipCard = refundMoney.RefundStoredCard * -1; costume.RefundOrder.MoneyVipCardMain = refundMoney.RefundStoredCard * (1 - originalDonate) * -1; costume.RefundOrder.MoneyVipCardDonate = refundMoney.RefundStoredCard * originalDonate * -1; //costume.RefundOrder.MoneyBuyByTicket = moneyBuyByTicket; costume.RefundOrder.RetailMoneyDeductedByTicket = originalRetailCostume.RetailOrder.MoneyDeductedByTicket; costume.RefundOrder.MoneyDeductedByTicket = moneyBuyByTicket; //总计=现金+积分+VIP卡+优惠券 //这笔单的应收金额 - (不退的那几件以原价* 数量 -满减金额) - (退的那几件)优惠券 costume.RefundOrder.TotalMoneyReceived = costume.RefundOrder.MoneyCash + costume.RefundOrder.MoneyIntegration + costume.RefundOrder.MoneyVipCard; costume.RefundOrder.TotalMoneyReceivedActual = costume.RefundOrder.MoneyCash + costume.RefundOrder.MoneyVipCardMain; costume.RefundOrder.Benefit = costume.RefundOrder.TotalMoneyReceivedActual - costume.RefundOrder.TotalCost; ////平摊 #endregion if (Math.Abs(costume.RefundOrder.TotalCount) < 1) { GlobalMessageBox.Show("退货数量不能小于1"); return; } //foreach (RetailDetail detail in costume.RefundDetailList) //{ // if (detail.IsRefund && detail.RefundCount > 0) // { // detail.SinglePrice = detail.SumMoney / detail.BuyCount * -1; // } //} ConfirmRefundForm confirmRefundForm = new ConfirmRefundForm(costume, shopID, this.dataGridView1, sourceTotalMoneyReceived, 1); DialogResult result = confirmRefundForm.ShowDialog(); if (result == DialogResult.Cancel) { return; } this.ResetForm(); } catch (Exception ee) { GlobalUtil.ShowError(ee); } }