コード例 #1
0
 public static string SaveReceipt(ReceiptViewModel model)
 {
     if (model.Id > 0)
     {
         return service.Update(getEntityByModel(model));
     }
     else
     {
         return service.Insert(getEntityByModel(model));
     }
 }
コード例 #2
0
        private static Receipt getEntityByModel(ReceiptViewModel model)
        {
            if (model == null) return null;

            Receipt entity = new Receipt();

            if (model.Id == 0)
            {
                entity.CreateBy = AuthenticationHelper.UserId;
                entity.CreateDate = DateTime.Now;
                entity.CompanyId = AuthenticationHelper.CompanyId.Value;
            }
            else
            {
                entity.CreateBy = model.CreateBy;
                entity.CreateDate = model.CreateDate;
                entity.CompanyId = model.CompanyId;
            }

            entity.BankAccountId = model.BankAccountId;
            entity.BankId = model.BankId;
            entity.ConversionRate = model.ConversionRate;
            entity.CurrencyId = model.CurrencyId;
            entity.CustomerId = model.CustomerId;
            entity.CustomerSiteId = model.CustomerSiteId;
            entity.Id = model.Id;
            entity.PeriodId = model.PeriodId;
            entity.ReceiptAmount = model.ReceiptAmount;
            entity.ReceiptDate = model.ReceiptDate;
            entity.ReceiptNumber = model.ReceiptNumber;
            entity.Remarks = model.Remarks;
            entity.SOBId = model.SOBId;
            entity.Status = model.Status;
            entity.UpdateBy = AuthenticationHelper.UserId;
            entity.UpdateDate = DateTime.Now;
            return entity;
        }
コード例 #3
0
 public static ReceiptViewModel GetReceipt(string id)
 {
     ReceiptViewModel receipt = new ReceiptViewModel(service.GetSingle(id, AuthenticationHelper.CompanyId.Value));
     return receipt;
 }
コード例 #4
0
        public ActionResult Create(long periodId, long customerId, long currencyId)
        {
            ReceiptViewModel receipt = new ReceiptViewModel();

            SessionHelper.Calendar = CalendarHelper.GetCalendar(ReceivablePeriodHelper.GetReceivablePeriod(periodId.ToString()).CalendarId.ToString());

            receipt.PeriodId = SessionHelper.Calendar.Id;
            receipt.SOBId = SessionHelper.SOBId;
            receipt.CustomerId = customerId;
            receipt.CurrencyId = currencyId;
            receipt.ConversionRate = 1;
            receipt.ReceiptDate = SessionHelper.Calendar.StartDate;

            SessionHelper.PrecisionLimit = CurrencyHelper.GetCurrency(currencyId.ToString()).Precision;

            if (receipt.CustomerSites == null)
            {
                receipt.CustomerSites = CustomerHelper.GetCustomerSites(receipt.CustomerId).Select(a => new SelectListItem
                {
                    Text = a.SiteName.ToString(),
                    Value = a.Id.ToString()
                }).ToList();
            }
            else
            {
                receipt.CustomerSites = new List<SelectListItem>();
            }

            if (receipt.Banks == null)
            {
                receipt.Banks = BankHelper.GetBankList(receipt.SOBId);
            }
            else
            {
                receipt.Banks = new List<SelectListItem>();
            }
            receipt.BankId = receipt.Banks.Count() > 0 ? Convert.ToInt64(receipt.Banks.FirstOrDefault().Value) : 0;

            if (receipt.BankAccounts == null)
            {
                receipt.BankAccounts = BankHelper.GetBankAccountList(receipt.BankId);
            }
            else
            {
                receipt.BankAccounts = new List<SelectListItem>();
            }

            return View(receipt);
        }
コード例 #5
0
        public ActionResult Create(ReceiptViewModel model)
        {
            if (ModelState.IsValid)
            {
                bool validated = false;
                string result = "";
                model.PeriodId = SessionHelper.Calendar.Id;
                model.CompanyId = AuthenticationHelper.CompanyId.Value;
                //Validation..

                if (model.ReceiptDate >= SessionHelper.Calendar.StartDate && model.ReceiptDate <= SessionHelper.Calendar.EndDate)
                    validated = true;

                if (validated)
                {
                    result = ReceiptHelper.SaveReceipt(model);
                }

                return RedirectToAction("Index");
            }
            return View(model);
        }