Exemplo n.º 1
0
        public static tbl_PurchaseOrderHeader MapToModel(PurchaseOrderHeaderViewModel objectToBeMapped)
        {
            var purchHeader     = objectToBeMapped;
            var purchHeaderTemp = new tbl_PurchaseOrderHeader();

            purchHeaderTemp.CreationDate = purchHeader.CreationDate;
            purchHeaderTemp.RecieveDate  = purchHeader.DocDate;
            purchHeaderTemp.Vendor       = purchHeader.VendorCode;
            purchHeaderTemp.IsPosted     = purchHeader.IsPosted;
            purchHeaderTemp.WareHouseID  = purchHeader.WarHouseCode;
            if (purchHeader.TransID != null)
            {
                purchHeaderTemp.TransID = (int)purchHeader.TransID;
            }
            purchHeaderTemp.RFQTransID = purchHeader.ParentId;
            purchHeaderTemp.PurchaseID = purchHeader.PurchId;
            purchHeaderTemp.tbl_PurchaseOrderDetails = new ObservableCollection <tbl_PurchaseOrderDetails>();
            foreach (var purchline in
                     from detail in purchHeader.PurchaseOrderDetails
                     let detail1 = detail
                                   select new tbl_PurchaseOrderDetails
            {
                Color = detail1.StyleColor ?? "",
                PurchasePrice = detail1.Price,
                StyleCode = detail1.StyleHeader,
                DelivaryDate = detail1.DelivaryDate,
                tbl_PurchaseOrderSizeDetails = new ObservableCollection <tbl_PurchaseOrderSizeDetails>
                                               (
                    detail.PurchaseOrderSizes
                    .Where(x => x.IsTextBoxEnabled)
                    .Select(sizeDetail => new tbl_PurchaseOrderSizeDetails
                {
                    Size = sizeDetail.SizeCode,
                    Qty =
                        int.Parse(
                            sizeDetail.SizeConsumption.ToString(CultureInfo.InvariantCulture))
                    ,
                    Ratio =
                        double.Parse(
                            sizeDetail.SizeRatio.ToString(CultureInfo.InvariantCulture))
                })
                                               ),
                tbl_PurchaseOrder_AdditionalCost =
                    new ObservableCollection <tbl_PurchaseOrder_AdditionalCost>(detail.AdditionalCostList)
            })
            {
                purchHeaderTemp.tbl_PurchaseOrderDetails
                .Add
                (
                    purchline
                );
            }
            return(purchHeaderTemp);
        }
Exemplo n.º 2
0
        public static _proxy.tbl_PurchaseOrderHeader MapToModelObject(PurchaseOrderHeaderViewModel objectToBeMapped)
        {
            var temp = new _proxy.tbl_PurchaseOrderHeader();

            if (objectToBeMapped.TransID != null)
            {
                temp.TransID = (int)objectToBeMapped.TransID;
            }
            temp.WareHouseID  = objectToBeMapped.WareHouseItem.WarehouseID;
            temp.Vendor       = objectToBeMapped.VendorCode;
            temp.RecieveDate  = objectToBeMapped.DocDate;
            temp.CreationDate = objectToBeMapped.CreationDate;
            temp.DelivaryDate = objectToBeMapped.DelivaryDate;
            return(temp);
        }
Exemplo n.º 3
0
        public static RFQViewModel MapToViewModel(tbl_RFQHeader objectToBeMapped, RFQViewModel objectToBeFilled)
        {
            if (objectToBeFilled == null)
            {
                objectToBeFilled = new RFQViewModel();
            }
            objectToBeFilled.TransID    = objectToBeMapped.TransID;
            objectToBeFilled.BrandCode  = objectToBeMapped.BrandCode;
            objectToBeFilled.BrandProp  = objectToBeFilled.Brands.FirstOrDefault(x => x.Brand_Code == objectToBeFilled.BrandCode);
            objectToBeFilled.SeasonCode = objectToBeMapped.SeasonCode;
            objectToBeFilled.SeasonProp = objectToBeFilled.Seasons.FirstOrDefault(x => x.Code == objectToBeFilled.SeasonCode);

            objectToBeFilled.SupplierID   = objectToBeMapped.SupplierCode;
            objectToBeFilled.SupplierProp = objectToBeFilled.Vendors.FirstOrDefault(x => x.vendor_code == objectToBeFilled.SupplierID);
            objectToBeFilled.DocNum       = objectToBeMapped.DocNumber;

            objectToBeFilled.ObjStatus = new ObjectStatus();

            foreach (var item in objectToBeMapped.tbl_RFQDetail)
            {
                objectToBeFilled.RFQHeaderList.Add(new RFQSubHeader(objectToBeFilled.RFQItems, objectToBeFilled.RFQServices));
                var temp2 = objectToBeFilled.RFQHeaderList[objectToBeFilled.RFQHeaderList.Count - 1];
                temp2.HeaderImage = item.Image;
                if (item.DelivaryDate != null)
                {
                    temp2.DelivaryDate = (DateTime)item.DelivaryDate;
                }
                temp2.Desc              = item.Descreption;
                temp2.IsSampleAttached  = item.IsSampleAttached;
                temp2.MainFabDesc       = item.MainFabricDesc;
                temp2.MainHeaderTransID = objectToBeFilled.TransID;
                temp2.Notes             = item.Notes;
                if (item.Qty != null)
                {
                    temp2.Qty = (int)item.Qty;
                }
                temp2.Style           = item.StyleCode;
                temp2.SubFabDesc      = item.SubFabricDesc;
                temp2.SubHeaderSerial = item.SubHeaderID;
                temp2.ObjStatus       = new ObjectStatus {
                    IsNew = false, IsSavedDBItem = true, IsEmpty = false
                };

                foreach (var itemTemp in item.tbl_RFQDetailItem.Select(iItems => new RFQHeaderItem(temp2.RFQItems)
                {
                    Description = iItems.Description,
                    Image = iItems.Image,
                    Iserial = iItems.Iserial,
                    ItemCode = iItems.ItemCode,
                    ParentID = temp2.SubHeaderSerial,
                    ItemGroup = iItems.Source,
                    Batch = iItems.Batch,
                    Config = iItems.Configuration,
                    Size = iItems.Size,
                    Name = iItems.Name
                }))
                {
                    itemTemp.SelectedRFQItem = new ItemsDto
                    {
                        Code      = itemTemp.ItemCode,
                        Desc      = itemTemp.Description,
                        Image     = itemTemp.Image,
                        ItemGroup = itemTemp.ItemGroup,
                        Size      = itemTemp.Size,
                        Config    = itemTemp.Config,
                        Batch     = itemTemp.Batch,
                        Name      = itemTemp.Name
                    };
                    itemTemp.ObjStatus = new ObjectStatus {
                        IsNew = false, IsSavedDBItem = true, IsEmpty = false
                    };

                    temp2.HeaderItems.Add(itemTemp);
                }

                foreach (var servtemp in item.tbl_RFQDetailService.Select(sItem => new RFQHeaderServices(temp2.RFQServices)
                {
                    Image = sItem.Image,
                    Iserial = sItem.Iserial,
                    Notes = sItem.Notes,
                    ServiceCode = sItem.ServiceCode,
                    ParentID = temp2.SubHeaderSerial
                }))
                {
                    servtemp.SelectedRFQService = servtemp.RFQServices.FirstOrDefault(x => x.Code == servtemp.ServiceCode);
                    servtemp.ObjStatus          = new ObjectStatus {
                        IsNew = false, IsSavedDBItem = true, IsEmpty = false
                    };

                    temp2.HeaderServices.Add(servtemp);
                }

                foreach (var ftemp in item.tbl_RFQFollowup.Where(x => x.FollowupType == 1)
                         .Select(fItem => new RFQFollowUpViewModel
                {
                    ActualDelivaryDate = fItem.ActualDelivaryDate,
                    EstimatedDelivaryDate = fItem.EstDelivaryDate,
                    Notes = fItem.Notes,
                    SizeCode = fItem.SizeCode,
                    StatusID = fItem.StatusID,
                    Style = fItem.StyleCode,
                    ParentID = temp2.SubHeaderSerial,
                    IsApproved = fItem.StatusID == 2,
                    Iserial = fItem.Iserial,
                    ObjStatus = new ObjectStatus {
                        IsNew = false, IsSavedDBItem = true, IsEmpty = false
                    }
                }))
                {
                    temp2.FollowUpList.Add(ftemp);
                }

                foreach (var fctemp in item.tbl_RFQFollowup.Where(x => x.FollowupType == 0)
                         .Select(fcItem => new RFQCostFollowUp
                {
                    ActualDelivaryDate = fcItem.ActualDelivaryDate,
                    Cost = fcItem.Cost,
                    EstimatedDelivaryDate = fcItem.EstDelivaryDate,
                    Notes = fcItem.Notes,
                    Status = fcItem.StatusID,
                    IsApproved = fcItem.StatusID == 2,
                    Style = fcItem.StyleCode,
                    Currency = fcItem.Currency,
                    ExchangeRate = fcItem.ExchangeRate,
                    LocalCost = fcItem.LocalCost,
                    ParentID = temp2.SubHeaderSerial,
                    AdditionalCost = fcItem.DCost,
                    Iserial = fcItem.Iserial,
                    AdditionalCostList = fcItem.tbl_RFQ_AdditionalCost,
                    Parent = temp2,
                    StyleColor = fcItem.ColorCode,
                }))
                {
                    temp2.CostFollowUpList.Add(fctemp);
                }
            }
            foreach (var purchHeader in objectToBeMapped.tbl_PurchaseOrderHeader)
            {
                var purchHeaderTemp = new PurchaseOrderHeaderViewModel
                {
                    CreationDate = (DateTime)purchHeader.CreationDate,
                    TransID      = purchHeader.TransID,
                    DocDate      = purchHeader.RecieveDate,
                    VendorCode   = purchHeader.Vendor,
                    WarHouseCode = purchHeader.WareHouseID,
                    ParentId     = purchHeader.RFQTransID,
                    PurchId      = purchHeader.PurchaseID,
                    IsPosted     = purchHeader.IsPosted,
                    ObjStatus    = new ObjectStatus {
                        IsNew = false, IsSavedDBItem = true
                    }
                };

                #region [ Adding Purch Lines ]

                var detailHeaders = (from tblPurchaseOrderDetails in purchHeader.tbl_PurchaseOrderDetails
                                     let purchasePrice = tblPurchaseOrderDetails.PurchasePrice
                                                         where purchasePrice != null
                                                         let rowTotal = tblPurchaseOrderDetails.tbl_PurchaseOrderSizeDetails.Sum(x => x.Qty)
                                                                        let tmp = tblPurchaseOrderDetails.tbl_PurchaseOrder_AdditionalCost.Sum(x => x.LocalValue)
                                                                                  let addCost = tmp == 0 ? tmp : (tmp / rowTotal)
                                                                                                select new PurchasOrderDetailsViewModel
                {
                    StyleColor = tblPurchaseOrderDetails.Color,
                    Price = (decimal)purchasePrice,
                    StyleHeader = tblPurchaseOrderDetails.StyleCode,
                    DelivaryDate = tblPurchaseOrderDetails.DelivaryDate,
                    ParentTransID = tblPurchaseOrderDetails.Trans_TransactionHeader,
                    ParentRfqSub = objectToBeFilled.RFQHeaderList.FirstOrDefault(x => x.Style == tblPurchaseOrderDetails.StyleCode),
                    Iserial = tblPurchaseOrderDetails.Iserial,
                    RowTotal = rowTotal ?? 0,
                    AdditionalCost = addCost ?? 0,
                    ObjStatus = new ObjectStatus {
                        IsNew = false, IsSavedDBItem = true, IsEmpty = false, IsReadyForSaving = true, IsLoading = true
                    },
                    AdditionalCostList = tblPurchaseOrderDetails.tbl_PurchaseOrder_AdditionalCost
                }).ToList();
                foreach (var detail in purchHeader.tbl_PurchaseOrderDetails)
                {
                    var counter   = 0;
                    var detail1   = detail.tbl_PurchaseOrderSizeDetails;
                    var purchline = detailHeaders.FirstOrDefault(x => x.Iserial == detail.Iserial);
                    foreach (var sizeDetail in detail1)
                    {
                        purchline.PurchaseOrderSizes[counter].SizeCode         = sizeDetail.Size;
                        purchline.PurchaseOrderSizes[counter].SizeConsumption  = (int)sizeDetail.Qty;
                        purchline.PurchaseOrderSizes[counter].IsTextBoxEnabled = true;
                        purchline.PurchaseOrderSizes[counter].Iserial          = sizeDetail.Iserial;
                        purchline.PurchaseOrderSizes[counter].SizeRatio        = (decimal)sizeDetail.Ratio;
                        counter++;
                    }
                }

                detailHeaders.ForEach(x => purchHeaderTemp.PurchaseOrderDetails.Add(x));
                purchHeaderTemp.GrandTotal =
                    int.Parse
                    (
                        purchHeaderTemp
                        .PurchaseOrderDetails
                        .Select
                            (x =>
                            x.PurchaseOrderSizes
                            .Sum(z => z.SizeConsumption)
                            ).Sum().ToString(CultureInfo.InvariantCulture)
                    );

                #endregion [ Adding Purch Lines ]

                purchHeaderTemp.SelectedPurchDetail = purchHeaderTemp.PurchaseOrderDetails.FirstOrDefault();
                detailHeaders.ToList().ForEach(x => x.ObjStatus.IsLoading = false);
                objectToBeFilled.PurchHeaders.Add(purchHeaderTemp);
            }
            if (objectToBeFilled.PurchHeaders != null && objectToBeFilled.PurchHeaders.Any())
            {
                objectToBeFilled.PurchaseHeaderSelectedItem = objectToBeFilled.PurchHeaders[0];
            }

            objectToBeFilled.AllFollowupApproved =
                objectToBeFilled.RFQHeaderList
                .Any(x => (x.FollowupsApproved = x.FollowUpList
                                                 .Any(y => y.IsApproved) && x.CostFollowUpList
                                                 .Any(z => z.IsApproved)));
            objectToBeFilled.FormMode                = ObjectMode.LoadedFromDb;
            objectToBeFilled.ObjStatus.IsNew         = false;
            objectToBeFilled.ObjStatus.IsSavedDBItem = true;
            return(objectToBeFilled);
        }