public DTO.EditFormData GetData(int userId, int id, int clientID, int factoryID, string season, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.EditFormData data = new DTO.EditFormData(); data.Data = new DTO.FactoryProformaInvoice(); data.DeliveryTerms = new List <Support.DTO.DeliveryTerm>(); data.PaymentTerms = new List <Support.DTO.PaymentTerm>(); data.Data.FactoryProformaInvoiceDetails = new List <DTO.FactoryProformaInvoiceDetail>(); //try to get data try { // check permission if (id <= 0 && fwFactory.CheckFactoryPermission(userId, factoryID) == 0) { throw new Exception("Current user don't have access permission for the selected factory data"); } if (id > 0 && fwFactory.CheckFactoryProformaInvoicePermission(userId, id) == 0) { throw new Exception("Current user don't have access permission for the selected proforma invoice data"); } using (FactoryProformaInvoice2MngEntities context = CreateContext()) { if (id <= 0) { data.Data.Season = season; data.Data.InvoiceDate = DateTime.Now.ToString("dd/MM/yyyy"); data.Data.ClientID = clientID; data.Data.FactoryID = factoryID; data.Data.ClientUD = supportFactory.GetClient().FirstOrDefault(o => o.ClientID == clientID).ClientUD; data.Data.FactoryUD = supportFactory.GetFactory().FirstOrDefault(o => o.FactoryID == factoryID).FactoryUD; } else { data.Data = converter.DB2DTO_FactoryProformaInvoice(context.FactoryProformaInvoice2Mng_FactoryProformaInvoice_View.Include("FactoryProformaInvoice2Mng_FactoryProformaInvoiceDetail_View").FirstOrDefault(o => o.FactoryProformaInvoiceID == id)); } } data.DeliveryTerms = supportFactory.GetDeliveryTerm(); data.PaymentTerms = supportFactory.GetPaymentTerm(); } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; } return(data); }
public DTO.DataContainer GetDataContainer(int id, int offerID, string orderType, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; Support.DAL.DataFactory support_factory = new Support.DAL.DataFactory(); try { using (SaleOrderMngEntities context = CreateContext()) { DTO.DataContainer dtoItem = new DTO.DataContainer(); if (id > 0) { SaleOrderMng_SaleOrder_View dbItem; dbItem = context.SaleOrderMng_SaleOrder_View .Include("SaleOrderMng_SaleOrderDetail_View.SaleOrderMng_SaleOrderDetailExtend_View") .Include("SaleOrderMng_SaleOrderExtend_View") .Include("SaleOrderMng_SaleOrderDetailSparepart_View") .Include("SaleOrderMng_SaleOrderProductReturn_View") .Include("SaleOrderMng_SaleOrderSparepartReturn_View") .Include("SaleOrderMng_WarehouseImport_View") .FirstOrDefault(o => o.SaleOrderID == id); DTO.SaleOrder SaleOrderDTOItem = converter.DB2DTO_SaleOrder(dbItem); dtoItem.SaleOrderData = SaleOrderDTOItem; } else { SaleOrderMng_Offer_View dbOffer = context.SaleOrderMng_Offer_View //.Include("SaleOrderMng_OfferLine_View") //.Include("SaleOrderMng_OfferLineSparepart_View") .FirstOrDefault(o => o.OfferID == offerID); // remove in-approrpiated items if (!String.IsNullOrEmpty(orderType) && (orderType == "WAREHOUSE" || orderType == "FACTORY")) { if (orderType == "WAREHOUSE") { // remove factory item dbOffer.SaleOrderMng_OTC_View.Where(o => o.OfferSeasonTypeID == 2 || o.OfferSeasonTypeID == 3).ToList().ForEach(o => dbOffer.SaleOrderMng_OTC_View.Remove(o)); //dbOffer.SaleOrderMng_OTCSparepart_View.Where(o => o.OfferSeasonTypeID == 4 || o.OfferSeasonTypeID == 5).ToList().ForEach(o => dbOffer.SaleOrderMng_OTCSparepart_View.Remove(o)); } else { //remove warehouse item dbOffer.SaleOrderMng_OTC_View.Where(o => o.OfferSeasonTypeID == 1 || o.OfferSeasonTypeID == null).ToList().ForEach(o => dbOffer.SaleOrderMng_OTC_View.Remove(o)); dbOffer.SaleOrderMng_OTCSparepart_View.Where(o => o.OfferSeasonTypeID == 1 || o.OfferSeasonTypeID == null).ToList().ForEach(o => dbOffer.SaleOrderMng_OTCSparepart_View.Remove(o)); } } else { dbOffer.SaleOrderMng_OTC_View.Clear(); dbOffer.SaleOrderMng_OTCSparepart_View.Clear(); orderType = null; } dbOffer.SaleOrderMng_OTC_View.Where(o => !o.Quantity.HasValue || o.Quantity == 0).ToList().ForEach(o => dbOffer.SaleOrderMng_OTC_View.Remove(o)); dbOffer.SaleOrderMng_OTCSparepart_View.Where(o => !o.Quantity.HasValue || o.Quantity == 0).ToList().ForEach(o => dbOffer.SaleOrderMng_OTCSparepart_View.Remove(o)); dtoItem.SaleOrderData = new DTO.SaleOrder(); dtoItem.SaleOrderData.SaleOrderExtends = new List <DTO.SaleOrderExtend>(); dtoItem.SaleOrderData.SaleOrderDetails = new List <DTO.SaleOrderDetail>(); dtoItem.SaleOrderData.SaleOrderDetailSpareparts = new List <DTO.SaleOrderDetailSparepart>(); dtoItem.SaleOrderData.SaleOrderProductReturns = new List <DTO.SaleOrderProductReturn>(); dtoItem.SaleOrderData.SaleOrderSparepartReturns = new List <DTO.SaleOrderSparepartReturn>(); //SET INIT VALUE dtoItem.SaleOrderData.OfferID = offerID; dtoItem.SaleOrderData.OfferUD = dbOffer.OfferUD; dtoItem.SaleOrderData.Season = dbOffer.Season; dtoItem.SaleOrderData.TrackingStatusNM = Library.Helper.TEXT_STATUS_CREATED; dtoItem.SaleOrderData.PaymentTermID = dbOffer.PaymentTermID; dtoItem.SaleOrderData.DeliveryTermID = dbOffer.DeliveryTermID; dtoItem.SaleOrderData.PaymentTypeNM = dbOffer.PaymentTypeNM; dtoItem.SaleOrderData.DeliveryTypeNM = dbOffer.DeliveryTypeNM; //dtoItem.SaleOrderData.Season = Library.Helper.GetCurrentSeason(); dtoItem.SaleOrderData.Conditions = "ALL PRICES INCLUDE 2% DAMAGE RISK"; dtoItem.SaleOrderData.Currency = dbOffer.Currency; dtoItem.SaleOrderData.VATPercent = dbOffer.VAT; dtoItem.SaleOrderData.IsViewDeliveryDateOnPrintout = true; dtoItem.SaleOrderData.IsViewLDSOnPrintout = true; dtoItem.SaleOrderData.IsViewQuantityContOnPrintout = true; dtoItem.SaleOrderData.OrderType = orderType; int i = -1; foreach (SaleOrderMng_OTC_View lineItem in dbOffer.SaleOrderMng_OTC_View.OrderBy(o => o.RowIndex)) { DTO.SaleOrderDetail dtoDetail = new DTO.SaleOrderDetail(); dtoDetail.SaleOrderDetailID = i; dtoDetail.OfferLineID = lineItem.OfferLineID; dtoDetail.ArticleCode = lineItem.ArticleCode; dtoDetail.Description = lineItem.Description; //dtoDetail.OrderQnt = lineItem.Quantity; dtoDetail.UnitPrice = lineItem.FinalPrice; dtoDetail.ProductID = lineItem.ProductID; dtoDetail.Quantity = lineItem.Quantity; //offer quantity dtoDetail.PhysicalQnt = lineItem.PhysicalQnt; dtoDetail.OnSeaQnt = lineItem.OnSeaQnt; dtoDetail.TobeShippedQnt = lineItem.TobeShippedQnt; dtoDetail.ReservationQnt = lineItem.ReservationQnt; dtoDetail.FTSQnt = lineItem.FTSQnt; dtoDetail.ProductStatusID = 1; dtoDetail.ClientArticleCode = lineItem.ClientArticleCode; dtoDetail.ClientArticleName = lineItem.ClientArticleName; dtoDetail.ClientOrderNumber = lineItem.ClientOrderNumber; dtoDetail.ClientEANCode = lineItem.ClientEANCode; // themy dtoDetail.OfferItemTypeID = lineItem.OfferItemTypeID; dtoDetail.OfferItemTypeNM = lineItem.OfferItemTypeNM; dtoDetail.ApproverName = lineItem.ApproverName; dtoDetail.ApprovedDate = lineItem.ApprovedDate.HasValue ? lineItem.ApprovedDate.Value.ToString("dd/MM/yyyy HH:mm") : null; dtoDetail.PlaningPurchasingPrice = lineItem.PlaningPurchasingPrice; dtoDetail.PlaningPurchasingPriceFactoryID = lineItem.PlaningPurchasingPriceFactoryID; dtoDetail.PlaningPurchasingPriceSourceID = lineItem.PlaningPurchasingPriceSourceID; dtoDetail.IsPlaningPurchasingPriceSelected = lineItem.IsPlaningPurchasingPriceSelected; dtoDetail.PlaningPurchasingPriceSelectedBy = lineItem.PlaningPurchasingPriceSelectedBy; dtoDetail.PlaningPurchasingPriceSelectedDate = lineItem.PlaningPurchasingPriceSelectedDate.HasValue ? lineItem.PlaningPurchasingPriceSelectedDate.Value.ToString("dd/MM/yyyy HH:mm") : null; dtoDetail.PlaningPurchasingPriceSourceNM = lineItem.PlaningPurchasingPriceSourceNM; dtoDetail.PlanningPriceSelectorName = lineItem.PlanningPriceSelectorName; dtoDetail.UnitPrice = lineItem.OfferSalePrice; dtoDetail.SaleOrderDetailExtends = new List <DTO.SaleOrderDetailExtend>(); dtoItem.SaleOrderData.SaleOrderDetails.Add(dtoDetail); i = i - 1; } i = -1; foreach (var item in dbOffer.SaleOrderMng_OTCSparepart_View.OrderBy(o => o.RowIndex)) { DTO.SaleOrderDetailSparepart dtoSparepart = new DTO.SaleOrderDetailSparepart(); dtoSparepart.SaleOrderDetailSparepartID = i; dtoSparepart.OfferLineSparepartID = item.OfferLineSparepartID; dtoSparepart.ArticleCode = item.ArticleCode; dtoSparepart.Description = item.Description; //dtoSparepart.OrderQnt = item.Quantity; dtoSparepart.UnitPrice = item.UnitPrice; dtoSparepart.ProductStatusID = 1; dtoSparepart.ClientArticleCode = item.ClientArticleCode; dtoSparepart.ClientArticleName = item.ClientArticleName; dtoSparepart.ClientEANCode = item.ClientEANCode; dtoItem.SaleOrderData.SaleOrderDetailSpareparts.Add(dtoSparepart); i = i - 1; } } //get support data dtoItem.DeliveryTerms = support_factory.GetDeliveryTerm().ToList(); dtoItem.PaymentTerms = support_factory.GetPaymentTerm().ToList(); dtoItem.Seasons = support_factory.GetSeason().ToList(); dtoItem.OrderTypes = GetOrderType().ToList(); dtoItem.ProductStatuses = GetProductStatus().ToList(); dtoItem.CostTypes = GetCostTypes().ToList(); dtoItem.PaymentStatuses = GetPaymentStatus().ToList(); dtoItem.VATPercents = GetVATPercent().ToList(); dtoItem.ReportTemplates = support_factory.GetReportTemplate().ToList(); // Get defautl report template if (dtoItem.SaleOrderData.DefaultPiReport == null) { var defaultRpt = dtoItem.ReportTemplates.FirstOrDefault(x => x.ReportType == "PI" && x.IsDefault == true).ReportTemplateNM; dtoItem.SaleOrderData.DefaultPiReport = defaultRpt; } return(dtoItem); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { notification.DetailMessage.Add(ex.InnerException.Message); } return(new DTO.DataContainer()); } }