Example #1
0
        private bool ModifyForOrder(List <OrderPayoff> orderPayoffList, decimal paymentMoney, decimal needChangePay)
        {
            //填充Order
            Order order = new Order();

            order.OrderID         = m_SalesOrder.order.OrderID;
            order.TotalSellPrice  = m_TotalPrice;
            order.ActualSellPrice = m_ActualPayMoney;
            order.DiscountPrice   = m_Discount;
            order.CutOffPrice     = m_CutOff;
            order.ServiceFee      = m_ServiceFee;
            order.PaymentMoney    = paymentMoney;
            order.NeedChangePay   = needChangePay;
            order.EmployeeID      = ConstantValuePool.CurrentEmployee.EmployeeID;
            //填充OrderDetails\OrderDiscount
            List <OrderDetails>  orderDetailsList  = new List <OrderDetails>();
            List <OrderDiscount> orderDiscountList = new List <OrderDiscount>();

            for (int i = 0; i < dgvGoodsOrder.RowCount; i++)
            {
                Discount itemDiscount = dgvGoodsOrder.Rows[i].Cells["GoodsDiscount"].Tag as Discount;
                if (itemDiscount != null)
                {
                    decimal itemDiscountPrice = Convert.ToDecimal(dgvGoodsOrder.Rows[i].Cells["GoodsDiscount"].Value);

                    OrderDetails orderDetails = CopyExtension.Clone <OrderDetails>(m_SalesOrder.orderDetailsList[i]);
                    orderDetails.TotalDiscount = itemDiscountPrice;
                    orderDetailsList.Add(orderDetails);
                    //OrderDiscount
                    OrderDiscount orderDiscount = new OrderDiscount();
                    orderDiscount.OrderDiscountID = Guid.NewGuid();
                    orderDiscount.OrderID         = m_SalesOrder.order.OrderID;
                    orderDiscount.OrderDetailsID  = orderDetails.OrderDetailsID;
                    orderDiscount.DiscountID      = itemDiscount.DiscountID;
                    orderDiscount.DiscountName    = itemDiscount.DiscountName;
                    orderDiscount.DiscountType    = itemDiscount.DiscountType;
                    orderDiscount.DiscountRate    = itemDiscount.DiscountRate;
                    orderDiscount.OffFixPay       = itemDiscount.OffFixPay;
                    orderDiscount.OffPay          = Math.Abs(itemDiscountPrice);
                    orderDiscount.EmployeeID      = ConstantValuePool.CurrentEmployee.EmployeeID;
                    orderDiscountList.Add(orderDiscount);
                }
            }
            ModifiedPaidOrder modifiedPaidOrder = new ModifiedPaidOrder();

            modifiedPaidOrder.order             = order;
            modifiedPaidOrder.orderDetailsList  = orderDetailsList;
            modifiedPaidOrder.orderDiscountList = orderDiscountList;
            modifiedPaidOrder.orderPayoffList   = orderPayoffList;
            return(ModifyOrderService.GetInstance().ModifyForOrder(modifiedPaidOrder));
        }
Example #2
0
        private void btnCheckOut_Click(object sender, EventArgs e)
        {
            decimal refundAmount     = decimal.Parse(txtRefundAmount.Text);
            decimal realReturnAmount = 0;

            if (!string.IsNullOrEmpty(txtRealReturnAmount.Text))
            {
                realReturnAmount = decimal.Parse(txtRealReturnAmount.Text);
            }
            if (refundAmount == realReturnAmount)
            {
                //判断支付方式是否正确
                bool IsPayoffWayRight = true;
                IList <OrderPayoff> _orderPayoffList = new List <OrderPayoff>();
                foreach (KeyValuePair <string, OrderPayoff> item in dic)
                {
                    if (item.Value.Quantity > 0)
                    {
                        _orderPayoffList.Add(item.Value);
                    }
                }
                foreach (OrderPayoff orderPayoff in _orderPayoffList)
                {
                    bool        IsContains = false;
                    OrderPayoff temp       = null;
                    foreach (OrderPayoff item in m_SalesOrder.orderPayoffList)
                    {
                        if (item.PayoffID.Equals(orderPayoff.PayoffID))
                        {
                            IsContains = true;
                            temp       = item;
                            break;
                        }
                    }
                    if (IsContains)
                    {
                        decimal tempAmount = temp.AsPay * temp.Quantity - temp.NeedChangePay;
                        decimal payAmount  = orderPayoff.AsPay * orderPayoff.Quantity - orderPayoff.NeedChangePay;
                        if (tempAmount < payAmount)
                        {
                            IsPayoffWayRight = false;
                            break;
                        }
                    }
                    else
                    {
                        IsPayoffWayRight = false;
                        break;
                    }
                }
                if (IsPayoffWayRight)
                {
                    IList <OrderPayoff> orderPayoffList = new List <OrderPayoff>();
                    foreach (OrderPayoff item in m_SalesOrder.orderPayoffList)
                    {
                        bool IsContains = false;
                        foreach (OrderPayoff orderPayoff in _orderPayoffList)
                        {
                            if (item.PayoffID.Equals(orderPayoff.PayoffID))
                            {
                                decimal remainQty = ((item.AsPay * item.Quantity - item.NeedChangePay) - (orderPayoff.AsPay * orderPayoff.Quantity - orderPayoff.NeedChangePay)) / orderPayoff.AsPay;
                                if (remainQty > 0)
                                {
                                    OrderPayoff temp = new OrderPayoff();
                                    temp.OrderPayoffID = Guid.NewGuid();
                                    temp.OrderID       = m_SalesOrder.order.OrderID;
                                    temp.PayoffID      = item.PayoffID;
                                    temp.PayoffName    = item.PayoffName;
                                    temp.PayoffType    = item.PayoffType;
                                    temp.AsPay         = item.AsPay;
                                    temp.Quantity      = remainQty;
                                    temp.NeedChangePay = 0;
                                    temp.CardNo        = item.CardNo;
                                    temp.EmployeeID    = ConstantValuePool.CurrentEmployee.EmployeeID;
                                    orderPayoffList.Add(temp);
                                }
                                IsContains = true;
                                break;
                            }
                        }
                        if (!IsContains)
                        {
                            OrderPayoff temp = CopyExtension.Clone <OrderPayoff>(item);
                            temp.OrderID       = m_SalesOrder.order.OrderID;
                            temp.OrderPayoffID = Guid.NewGuid();
                            temp.EmployeeID    = ConstantValuePool.CurrentEmployee.EmployeeID;
                            orderPayoffList.Add(temp);
                        }
                    }
                    List <DeletedOrderDetails> deletedOrderDetailsList = new List <DeletedOrderDetails>();
                    for (int i = 0; i < dgvGoodsOrder.RowCount; i++)
                    {
                        OrderDetails tempOrderDetails  = dgvGoodsOrder.Rows[i].Cells["OrderDetailsID"].Tag as OrderDetails;
                        decimal      tempGoodsNum      = Convert.ToDecimal(dgvGoodsOrder.Rows[i].Cells["GoodsNum"].Value);
                        decimal      tempGoodsDiscount = Convert.ToDecimal(dgvGoodsOrder.Rows[i].Cells["GoodsDiscount"].Value);
                        decimal      tempDeletedNum    = Convert.ToDecimal(dgvGoodsOrder.Rows[i].Cells["DelFlag"].Value);
                        if (Math.Abs(tempDeletedNum) > 0)
                        {
                            decimal             remainQty    = tempGoodsNum - Math.Abs(tempDeletedNum);
                            DeletedOrderDetails orderDetails = new DeletedOrderDetails();
                            orderDetails.OrderDetailsID    = tempOrderDetails.OrderDetailsID;
                            orderDetails.DeletedQuantity   = tempDeletedNum;
                            orderDetails.RemainQuantity    = remainQty;
                            orderDetails.OffPay            = Math.Round(-tempGoodsDiscount / tempGoodsNum * remainQty, 4);
                            orderDetails.AuthorisedManager = ConstantValuePool.CurrentEmployee.EmployeeID;
                            orderDetails.CancelEmployeeNo  = ConstantValuePool.CurrentEmployee.EmployeeNo;
                            orderDetails.CancelReasonName  = dgvGoodsOrder.Rows[i].Cells["DelReasonName"].Value.ToString();;
                            deletedOrderDetailsList.Add(orderDetails);
                        }
                    }
                    //构造DeletedPaidOrder对象
                    decimal paymentMoney = 0;
                    foreach (OrderPayoff item in orderPayoffList)
                    {
                        paymentMoney += item.AsPay * item.Quantity;
                    }
                    Order order = new Order();
                    order.OrderID         = m_SalesOrder.order.OrderID;
                    order.TotalSellPrice  = m_TotalPrice;
                    order.ActualSellPrice = m_ActualPayMoney;
                    order.DiscountPrice   = m_Discount;
                    order.CutOffPrice     = m_CutOff;
                    order.ServiceFee      = m_ServiceFee;
                    order.PaymentMoney    = paymentMoney;
                    order.NeedChangePay   = 0;
                    order.EmployeeID      = ConstantValuePool.CurrentEmployee.EmployeeID;
                    DeletedPaidOrder deletedPaidOrder = new DeletedPaidOrder();
                    deletedPaidOrder.order = order;
                    deletedPaidOrder.deletedOrderDetailsList = deletedOrderDetailsList;
                    deletedPaidOrder.orderPayoffList         = orderPayoffList;
                    if (DeletedOrderService.GetInstance().DeletePaidSingleOrder(deletedPaidOrder))
                    {
                        m_IsChanged = true;
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("单品删除失败,请重新操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("退款支付方式不属于原结账支付方式,请重新支付!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("应退金额与实退金额不一致,请重新支付!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }