public void SaveInfo()
    {
        bool newPay = false;
        if (PaymentInfo == null)
        {
            PaymentInfo = new SaleOrderPayment()
              {
                  CreatedDate = DateTime.Now,
                  PaymentDate = DateTime.Now,
                  UserName = UserHelper.Username,
                  PaymentType = OrderPaymentType.FromDealer,
              };
            newPay = true;
        }
        PaymentInfo.Amount = long.Parse(txtAmount.Text);
        PaymentInfo.Description = txtComment.Text.Trim();
        PaymentInfo.LastEditDate = DateTime.Now;
        PaymentInfo.VoucherNumber = txtVoucher.Text.Trim().ToUpper();

        PaymentInfo.FromBank = dlFromBank.SelectedValue;
        PaymentInfo.FromAccount = dlFromAcc.Text;
        PaymentInfo.FromAccountHolder = txtFromAcc.Text;
        PaymentInfo.ToBank = dlToBank.SelectedValue;
        PaymentInfo.ToAccount = dlToAcc.Text;
        PaymentInfo.ToAccountHolder = txtToAcc.Text;

        if (newPay) OrderBonus.AddPayment(PaymentInfo, OrderId);
    }
Esempio n. 2
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (!IsValid)
         return;
     long tmp;
     int count = 0;
     foreach (GridViewRow r in gv.Rows)
     {
         count++;
         var usingAmount = long.TryParse(((TextBox)r.Cells[4].FindControl("txtUsingAmount")).Text, out tmp) ? tmp : 0;
         if (usingAmount > 0)
         {
             var paymentId = long.TryParse(r.Cells[0].Text, out tmp) ? tmp : 0;
             var orgPayment = OrderBonusDAO.GetOrderPayment(paymentId);
             var newPayment = new SaleOrderPayment
             {
                 Amount = (decimal)usingAmount,
                 CreatedDate = DateTime.Now,
                 DealerCode = orgPayment.DealerCode,
                 PaymentDate = orgPayment.PaymentDate,
                 PaymentType = OrderPaymentType.RemainingPayment,
                 ToBank = orgPayment.ToBank,
                 UserName = VDMS.Helper.UserHelper.Username,
                 VoucherNumber = orgPayment.VoucherNumber + " used",
                 Description = "Use remaining money",
                 OriginalSaleOrderPaymentId = orgPayment.OrderPaymentId,
             };
             OrderBonus.AddPayment(newPayment, OrderId);
         }
     }
     ClosePopup("updated()");
 }
Esempio n. 3
0
        public static void AddPayment(SaleOrderPayment PaymentInfo, long oid)
        {
            PaymentInfo.Id = Guid.NewGuid();
            PaymentInfo.SessionId = HttpContext.Current.Session.SessionID;
            if (oid > 0) PaymentInfo.OrderHeaderId = oid;

            var o = EditingItems.FirstOrDefault(p => p.FromBank == PaymentInfo.FromBank && p.FromAccount == PaymentInfo.FromAccount && p.VoucherNumber == PaymentInfo.VoucherNumber);
            if (o != null) EditingItems.Remove(o);
            EditingItems.Add(PaymentInfo);
        }
Esempio n. 4
0
        public static bool ReConsign(DateTime from, DateTime to, string dCode)
        {
            var found = false;
            var q = new PaymentManager().QueryOrderPayments(-1, -1, null, dCode, from, to, OrderPaymentType.BankImport);
            foreach (var item in q)
            {
                found = true;

                var total = item.OrderHeader.TotalAmount;
                item.OrderHeader.SubTotal = total;
                foreach (var pm in item.SaleOrderPayments)
                {
                    if (pm.PaymentType == OrderPaymentType.BankImport)
                        pm.PaymentType = OrderPaymentType.BankConfirmed;
                    if (pm.PaymentType == OrderPaymentType.RemainingPayment)
                        pm.PaymentType = OrderPaymentType.RemainingPaymentComfirmed;
                    item.OrderHeader.PaymentAmount += (long)pm.Amount;
                }
                var remain = item.OrderHeader.PaymentAmount + item.OrderHeader.BonusAmount - total;

                if (remain > 0)
                {
                    item.OrderHeader.PaymentAmount = total - item.OrderHeader.BonusAmount > 0 ? total - item.OrderHeader.BonusAmount : 0;
                    var lastPm = item.SaleOrderPayments.OrderByDescending(p => p.PaymentDate).FirstOrDefault();
                    var pm = new SaleOrderPayment()
                    {
                        Amount = remain,
                        CreatedDate = DateTime.Now,
                        Description = "Auto Re-consign",
                        LastEditDate = DateTime.Now,
                        OrderHeaderId = item.OrderHeader.OrderHeaderId,
                        PaymentDate = DateTime.Now,
                        PaymentType = OrderPaymentType.ConsignRemain,
                        ToAccount = lastPm.ToAccount,
                        ToAccountHolder = lastPm.ToAccountHolder,
                        ToBank = lastPm.ToBank,
                        UserName = UserHelper.Username,
                        VoucherNumber = string.Format("OrderNo: {0}", item.OrderHeader.OrderNumber),
                    };
                    DC.SaleOrderPayments.InsertOnSubmit(pm);
                }
            }
            DC.SubmitChanges();
            return found;
        }
Esempio n. 5
0
        public static bool LoadExcelData(Stream excel, string bCode)
        {
            var result = false;
            var setting = VDMS.VDMSSetting.CurrentSetting.BankPaymentSettings.SingleOrDefault(s => s.BankCode == bCode);
            if (setting == null) return false;

            //try
            {
                ExcelDataReader spreadsheet = new ExcelDataReader(excel);

                var am = setting.Amount;
                var sr = setting.StartRow;
                var cm = setting.Comment;
                var vn = setting.OrderId;
                var pd = setting.PaymentDate;
                var tn = setting.TransactionNumber;
                var dc = setting.DealerCode;
                var dn = setting.DealerName;
                if (am < 1 || sr < 1 || cm < 1 || vn < 1 || pd < 1 || tn < 1 || dc < 1 || dn < 1)
                    throw new Exception(string.Format("Wrong excel format for: {0}", bCode));

                var rows = spreadsheet.WorkbookData.Tables[0].AsEnumerable();
                int i = 0;
                var query = from r in rows
                            select new
                            {
                                Amount = r.Field<string>(am - 1),
                                Comment = r.Field<string>(cm - 1),
                                OrderNumber = r.Field<string>(vn - 1),
                                PaymentDate = r.Field<string>(pd - 1),
                                TransactionNumber = r.Field<string>(tn - 1),
                                DealerCode = r.Field<string>(dc - 1),
                                DealerName = r.Field<string>(dn - 1),
                                Index = ++i,
                            };
                var data = query.Skip(sr - 1).TakeWhile(p => !string.IsNullOrEmpty(p.TransactionNumber));

                List<SaleOrderPayment> items = new List<SaleOrderPayment>();

                foreach (var item in data)
                {

                    try
                    {
                        DateTime d = DataFormat.DateFromExcel(item.PaymentDate, setting.DateFormat);
                        ImportPayment(item.OrderNumber.Trim(), bCode, item.DealerCode, item.DealerName, item.TransactionNumber, item.Comment, d, long.Parse(item.Amount)).Index = item.Index;
                    }
                    catch
                    {
                        result = false;
                        var p = new SaleOrderPayment() { Error = Resources.Message.DataFormatWrong };
                        ImportPayment(p);
                    };
                }

                result = true;
            }
            //catch
            //{
            //    result = false;
            //}

            return result;
        }
Esempio n. 6
0
        public static void ImportPayment(SaleOrderPayment p)
        {
            p.Id = Guid.NewGuid();
            p.SessionId = HttpContext.Current.Session.SessionID;

            ImportingItems.Add(p);
        }
Esempio n. 7
0
        public static SaleOrderPayment ImportPayment(string orderno, string bankCode, string dCode, string dName, string trans, string content, DateTime pDate, long amount)
        {
            SaleOrderPayment p = null;
            long oid;
            OrderHeader o;
            if (long.TryParse(orderno, out oid))
                o = OrderDAO.GetOrder(oid);
            else
                o = OrderDAO.GetOrder(orderno);

            p = new SaleOrderPayment()
            {
                Id = Guid.NewGuid(),
                Amount = amount,
                OrderNumber = o.OrderNumber,
                CreatedDate = DateTime.Now,
                DealerCode = dCode,
                DealerName = dName,
                Description = content,
                LastEditDate = DateTime.Now,
                OrderHeaderId = o.OrderHeaderId,
                PaymentDate = pDate,
                PaymentType = OrderPaymentType.BankImport,
                SessionId = HttpContext.Current.Session.SessionID,
                ToBank = bankCode,
                UserName = UserHelper.Username,
                VoucherNumber = trans,
            };
            // check for existing data
            if (DC.SaleOrderPayments.Any(op => op.ToBank == bankCode && op.VoucherNumber == trans))
            {
                p.Error = p.Error + " " + string.Format(Errors.DataExistInDatabase, bankCode, trans);
            }

            ImportingItems.Add(p);

            if (o == null) p.Error = p.Error + " " + Errors.NotExistVDMSOrderNumber;
            else if (o.DealerCode != dCode) p.Error = p.Error + " " + string.Format(Errors.WrongActualDealerCode, o.DealerCode);
            else if (o.DatabaseCode != UserHelper.DatabaseCode || (o.AreaCode != UserHelper.AreaCode && UserHelper.Profile.Position == VDMS.II.Entity.PositionType.Employee && !UserHelper.IsSysAdmin)) p.Error = p.Error + " " + string.Format(Errors.NotExistDealerCode, o.DealerCode);

            return p;
        }
Esempio n. 8
0
 public static void DeleteImportingPayment(SaleOrderPayment item)
 {
     if (item != null)
     {
         if (item.OrderPaymentId > 0) item.Deleted = true;
         else ImportingItems.RemoveAll(p => p.Id == item.Id);
     }
 }
Esempio n. 9
0
 public static void DeleteEditingItem(SaleOrderPayment Item)
 {
     if (Item.OrderHeaderId > 0)
         Item.Deleted = true;
     else
         EditingItems.RemoveAll(p => p.Id == Item.Id);
 }
 private void detach_SaleOrderPayments(SaleOrderPayment entity)
 {
     this.SendPropertyChanging("SaleOrderPayments");
     entity.OrderHeader = null;
 }