コード例 #1
0
        private static Invoice getEntityByModel(InvoiceModel model)
        {
            if (model == null) return null;
            Invoice entity = new Invoice();

            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.ConversionRate = model.ConversionRate;
            entity.CurrencyId = model.CurrencyId;
            entity.CustomerId = model.CustomerId;
            entity.CustomerSiteId = model.CustomerSiteId;
            entity.Id = model.Id;
            entity.InvoiceDate = model.InvoiceDate;
            entity.InvoiceNo = model.InvoiceNo;
            entity.InvoiceType = model.InvoiceType;
            entity.PeriodId = model.PeriodId;
            entity.Remarks = model.Remarks;
            entity.SOBId = model.SOBId;
            entity.UpdateBy = AuthenticationHelper.UserId;
            entity.UpdateDate = DateTime.Now;

            return entity;
        }
コード例 #2
0
        public ActionResult Create()
        {
            InvoiceModel model = SessionHelper.Invoice;
            if (model == null)
            {
                model = new InvoiceModel
                {
                    CompanyId = AuthenticationHelper.CompanyId.Value,
                    InvoiceDetail = new List<InvoiceDetailModel>(),
                    InvoiceNo = "New",
                    SOBId = SessionHelper.SOBId,
                    ConversionRate = 1
                };
                SessionHelper.Invoice = model;
            }
            model.Currencies = CurrencyHelper.GetCurrencyList(SessionHelper.SOBId);
            //model.Periods = CalendarHelper.GetCalendarsList(SessionHelper.SOBId);
            model.Periods = ReceivablePeriodHelper.GetPeriodList(SessionHelper.SOBId);

            if (model.Currencies != null && model.Currencies.Count() > 0)
            {
                model.CurrencyId = Convert.ToInt64(model.Currencies.FirstOrDefault().Value);
                SessionHelper.PrecisionLimit = CurrencyHelper.GetCurrency(model.CurrencyId.ToString()).Precision;
            }
            if (model.Periods != null && model.Periods.Count() > 0)
            {
                model.PeriodId = Convert.ToInt64(model.Periods.FirstOrDefault().Value);
                //SessionHelper.Calendar = CalendarHelper.GetCalendar(model.PeriodId.ToString());
                SessionHelper.Calendar = CalendarHelper.GetCalendar(ReceivablePeriodHelper.GetReceivablePeriod(model.PeriodId.ToString()).CalendarId.ToString());
                model.InvoiceDate = SessionHelper.Calendar.StartDate;
                
                model.Customers = CustomerHelper.GetCustomersCombo(SessionHelper.Calendar.StartDate, SessionHelper.Calendar.EndDate);
                if (model.Customers != null && model.Customers.Count() > 0)
                {
                    model.CustomerId = Convert.ToInt64(model.Customers.FirstOrDefault().Value);
                    model.CustomerSites = CustomerHelper.GetCustomerSitesCombo(model.CustomerId);
                    if (model.CustomerSites != null && model.CustomerSites.Count() > 0)
                    {
                        model.CustomerSiteId = Convert.ToInt64(model.CustomerSites.FirstOrDefault().Value);
                    }
                }
            }



            return View("Edit", model);
        }
コード例 #3
0
        public static void Update(InvoiceModel invoiceModel)
        {
            Invoice entity = getEntityByModel(invoiceModel);

            string result = string.Empty;
            if (entity.IsValid())
            {
                if (invoiceModel.Id > 0)
                    result = service.Update(entity);
                else
                    result = service.Insert(entity);

                if (!string.IsNullOrEmpty(result))
                {
                    var savedDetail = getInvoiceDetailByInvoiceId(result);
                    if (savedDetail.Count() > invoiceModel.InvoiceDetail.Count())
                    {
                        var tobeDeleted = savedDetail.Take(savedDetail.Count() - invoiceModel.InvoiceDetail.Count());
                        foreach (var item in tobeDeleted)
                        {
                            detailService.Delete(item.Id.ToString(), AuthenticationHelper.CompanyId.Value);
                        }
                        savedDetail = getInvoiceDetailByInvoiceId(result);
                    }

                    foreach (var detail in invoiceModel.InvoiceDetail)
                    {
                        InvoiceDetail detailEntity = getEntityByModel(detail);
                        if (detailEntity.IsValid())
                        {
                            detailEntity.InvoiceId = Convert.ToInt64(result);
                            if (savedDetail.Count() > 0)
                            {
                                detailEntity.Id = savedDetail.FirstOrDefault().Id;
                                savedDetail.Remove(savedDetail.FirstOrDefault(rec => rec.Id == detailEntity.Id));
                                detailService.Update(detailEntity);
                            }
                            else
                                detailService.Insert(detailEntity);
                        }
                    }
                }
            }
        }