Beispiel #1
0
        public void DeletePayment(string id, SqlConnection con, SqlTransaction trans)
        {
            var ps = new PaymentRecordService();

            var payment = ps.GetById(id);

            var source = GetById(payment.MoneySourceId);
            var amount = Convert.ToSingle(payment.Amount);

            if (payment.Type.Equals("Income", StringComparison.CurrentCultureIgnoreCase) ||
                payment.Type.Equals("Order-Payment", StringComparison.CurrentCultureIgnoreCase))
            {
                amount = -amount;
            }

            if (payment.Unit.Equals("VND"))
            {
                source.BalanceVND += amount;
            }
            else
            {
                source.BalanceUSD += amount;
            }

            if (con != null && trans != null)
            {
                ps.Delete(id, con, trans);

                _adapter.Update(source, con, trans);
            }
            else
            {
                SqlHelper.StartTransaction(ConfigManager.ConnectionString, (connection, transaction) =>
                {
                    ps.Delete(id, connection, transaction);

                    _adapter.Update(source, con, trans);
                });
            }
        }
Beispiel #2
0
        public static void Delete(string id)
        {
            var ms = new MoneySourceService();
            var ps = new PaymentRecordService();

            SqlHelper.StartTransaction(ConfigManager.ConnectionString, (connection, transaction) =>
            {
                var order = GetById(id);

                var msDict = new Dictionary <string, MoneySource>();
                var pmList = new List <PaymentRecord>();
                pmList.AddRange(order.Discounts);
                pmList.AddRange(order.Payments);
                foreach (var item in pmList)
                {
                    if (!msDict.ContainsKey(item.MoneySourceId))
                    {
                        msDict.Add(item.MoneySourceId, ms.GetById(item.MoneySourceId));
                    }
                }

                foreach (var item in pmList)
                {
                    ReverseSource(msDict[item.MoneySourceId], item);
                    ps.Delete(item.Id, connection, transaction);
                }

                foreach (var source in msDict.Values)
                {
                    ms.Update(source, connection, transaction);
                }

                SqlHelper.ExecuteCommand(connection, transaction, CommandType.StoredProcedure, SP_ORDER_DELETE,
                                         new[]
                {
                    new SqlParameter("@id", id),
                });
            });
        }
Beispiel #3
0
        private static void UpdatePaymentForOrder(BookingOrder order, BookingOrder originalOrder, SqlConnection connection, SqlTransaction transaction)
        {
            var ms = new MoneySourceService();
            var ps = new PaymentRecordService();

            var msDict = new Dictionary <string, MoneySource>();

            foreach (var discount in order.Discounts)
            {
                if (!msDict.ContainsKey(discount.MoneySourceId))
                {
                    msDict.Add(discount.MoneySourceId, ms.GetById(discount.MoneySourceId));
                }
            }
            foreach (var payment in order.Payments)
            {
                if (!msDict.ContainsKey(payment.MoneySourceId))
                {
                    msDict.Add(payment.MoneySourceId, ms.GetById(payment.MoneySourceId));
                }
            }
            foreach (var discount in originalOrder.Discounts.Where(d => !order.Discounts.Exists(d1 => d1.Id == d.Id)))
            {
                if (!msDict.ContainsKey(discount.MoneySourceId))
                {
                    msDict.Add(discount.MoneySourceId, ms.GetById(discount.MoneySourceId));
                }
            }
            foreach (var payment in originalOrder.Payments.Where(p => !order.Payments.Exists(p1 => p1.Id == p.Id)))
            {
                if (!msDict.ContainsKey(payment.MoneySourceId))
                {
                    msDict.Add(payment.MoneySourceId, ms.GetById(payment.MoneySourceId));
                }
            }

            foreach (var discount in order.Discounts)
            {
                if (discount.Id.StartsWith("discount-"))
                {
                    var id = IdHelper.Generate();
                    discount.Id      = "d-" + id;
                    discount.Date    = DateTime.Now;
                    discount.OrderId = order.Id;
                    ps.Insert(discount, connection, transaction);
                    UpdateSource(msDict[discount.MoneySourceId], discount);
                }
                else
                {
                    ps.Update(discount, connection, transaction);
                    var source  = msDict[discount.MoneySourceId];
                    var oldItem = ps.GetById(discount.Id);
                    ReverseSource(source, oldItem);
                    UpdateSource(source, discount);
                }
            }
            foreach (var discount in originalOrder.Discounts.Where(d => !order.Discounts.Exists(d1 => d1.Id == d.Id)))
            {
                var source = msDict[discount.MoneySourceId];
                ReverseSource(source, discount);
                ps.Delete(discount.Id, connection, transaction);
            }

            // update payment
            foreach (var payment in order.Payments)
            {
                if (payment.Id.StartsWith("payment-"))
                {
                    var id = IdHelper.Generate();
                    payment.Id      = "p-" + id;
                    payment.Date    = DateTime.Now;
                    payment.OrderId = order.Id;
                    ps.Insert(payment, connection, transaction);
                    UpdateSource(msDict[payment.MoneySourceId], payment);
                }
                else
                {
                    ps.Update(payment, connection, transaction);
                    var source  = msDict[payment.MoneySourceId];
                    var oldItem = ps.GetById(payment.Id);
                    ReverseSource(source, oldItem);
                    UpdateSource(source, payment);
                }
            }
            foreach (var payment in originalOrder.Payments.Where(p => !order.Payments.Exists(p1 => p1.Id == p.Id)))
            {
                var source = msDict[payment.MoneySourceId];
                ReverseSource(source, payment);
                ps.Delete(payment.Id, connection, transaction);
            }

            foreach (var source in msDict.Values)
            {
                ms.Update(source, connection, transaction);
            }
        }