Exemplo n.º 1
0
        public void DeletePurchaseOrder(tbl_PurchaseOrderHeader _Header, List <tbl_PurchaseOrderDetails> _Details)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                try
                {
                    var rch = (from x in context.tbl_PurchaseOrderHeader.ToList()
                               where x.TransID == _Header.TransID
                               select x).FirstOrDefault();

                    context.DeleteObject(rch);

                    foreach (var item in context.tbl_PurchaseOrderDetails
                             .Where
                             (
                                 x => x.Trans_TransactionHeader == rch.TransID
                             ).ToList())
                    {
                        context.DeleteObject(item);
                    }
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 2
0
        public static tbl_PurchaseOrderHeader MapToModel(PurchaseOrderHeaderViewModel objectToBeMapped, int parentID)
        {
            var purchHeader     = objectToBeMapped;
            var purchHeaderTemp = new tbl_PurchaseOrderHeader
            {
                CreationDate = purchHeader.CreationDate,
                RecieveDate  = purchHeader.DocDate,
                Vendor       = purchHeader.VendorCode,
                WareHouseID  = purchHeader.WarHouseCode,
                IsPosted     = purchHeader.IsPosted,
                PurchaseID   = purchHeader.PurchId
            };

            if (purchHeader.TransID != null)
            {
                purchHeaderTemp.TransID = (int)purchHeader.TransID;
            }
            purchHeaderTemp.RFQTransID = parentID;
            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.º 3
0
 public void AddPurchaseOrder(tbl_PurchaseOrderHeader _Header, List <tbl_PurchaseOrderDetails> _Details)
 {
     using (var context = new WorkFlowManagerDBEntities())
     {
         try
         {
             context.tbl_PurchaseOrderHeader.AddObject(_Header);
             foreach (var item in _Details)
             {
                 context.tbl_PurchaseOrderDetails.AddObject(item);
             }
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
Exemplo n.º 4
0
        public void UpdatePurchaseOrder(tbl_PurchaseOrderHeader _Header, List <tbl_PurchaseOrderDetails> _Details)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                tbl_PurchaseOrderHeader rch;
                try
                {
                    rch = (from x in context.tbl_PurchaseOrderHeader.ToList()
                           where x.TransID == _Header.TransID
                           select x).FirstOrDefault();

                    rch.RecieveDate  = _Header.RecieveDate;
                    rch.DelivaryDate = _Header.DelivaryDate;
                    rch.Vendor       = _Header.Vendor;

                    foreach (var item in context.RouteCardDetails
                             .Where
                             (
                                 x => x.Trans_TransactionHeader == rch.TransID
                             ).ToList())
                    {
                        context.DeleteObject(item);
                    }

                    foreach (var item in _Details)
                    {
                        context.tbl_PurchaseOrderDetails.AddObject(item);
                    }
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 5
0
        private void PostPoToAx(tbl_PurchaseOrderHeader paramHeaderObjToPost)
        {
            var context         = new WorkFlowManagerDBEntities();
            var headerObjToPost =
                context.tbl_PurchaseOrderHeader.Include("tbl_PurchaseOrderDetails.tbl_PurchaseOrderSizeDetails")
                .FirstOrDefault(x => x.TransID == paramHeaderObjToPost.TransID);

            var axapta = new Axapta();

            var credential = new NetworkCredential("bcproxy", "around1");

            try
            {
                axapta.LogonAs("ahmed.gamal", "ccasual.loc", credential, "ccr", null, null, null);
            }
            catch (Exception)
            {
                throw new Exception("There was a problem logging to ax");
            }
            try
            {
                axapta.TTSBegin();
                var inventDimTable       = axapta.CreateAxaptaRecord("InventDim");
                var inventColorTable     = axapta.CreateAxaptaRecord("InventColor");
                var inventDimCombination = axapta.CreateAxaptaRecord("InventDimCombination");

                var axaptaRecord = axapta.CreateAxaptaRecord("PurchTable");
                axaptaRecord.Clear();
                axaptaRecord.InitValue();
                var purchId = headerObjToPost.PurchaseID;
                axaptaRecord.set_Field("PurchId", purchId);

                var header =
                    axapta.CallStaticRecordMethod("VendTable", "find", headerObjToPost.Vendor) as AxaptaRecord;
                axaptaRecord.Call("initFromVendTable", header);

                axaptaRecord.Insert();
                context.tbl_PurchaseOrderDetails.MergeOption = MergeOption.NoTracking;
                context.V_Warehouse.MergeOption = MergeOption.NoTracking;
                var detailHeadersFull = headerObjToPost.tbl_PurchaseOrderDetails;

                foreach (var ditem in detailHeadersFull)
                {
                    foreach (var sdItem in ditem.tbl_PurchaseOrderSizeDetails)
                    {
                        var itemId = ditem.StyleCode;

                        axaptaRecord = axapta.CreateAxaptaRecord("PurchLine");
                        axaptaRecord.Clear();
                        axaptaRecord.InitValue();

                        inventDimTable.Clear();
                        inventDimTable.set_Field("InventLocationId", headerObjToPost.WareHouseID);

                        var warehouse =
                            context.V_Warehouse.SingleOrDefault(
                                x => x.DataAreaID == "ccr" && x.WarehouseID == headerObjToPost.WareHouseID);
                        if (warehouse !=
                            null)
                        {
                            inventDimTable.set_Field("InventSiteId", warehouse.SiteId);
                        }

                        inventColorTable.set_Field("ItemID", ditem.StyleCode);
                        inventColorTable.set_Field("InventColorId", ditem.Color);
                        var clr =
                            (bool)
                            axapta.CallStaticRecordMethod("InventColor", "checkExist", ditem.StyleCode, ditem.Color);
                        if (!clr)
                        {
                            inventColorTable.Insert();
                        }
                        else
                        {
                            inventColorTable.Clear();
                        }

                        try
                        {
                            inventDimCombination.set_Field("ItemID", ditem.StyleCode);
                            inventDimCombination.set_Field("InventSizeId", sdItem.Size);
                            inventDimCombination.set_Field("InventColorId", ditem.Color);
                            inventDimCombination.Insert();
                        }
                        catch
                        {
                        }

                        inventDimTable.set_Field("InventColorId", ditem.Color);
                        inventDimTable.set_Field("InventSizeId", sdItem.Size);

                        inventDimTable =
                            axapta.CallStaticRecordMethod("InventDim", "findOrCreate", inventDimTable) as
                            AxaptaRecord;

                        var tempx = inventDimTable.get_Field("inventDimId").ToString();
                        axaptaRecord.set_Field("InventDimId", tempx);

                        if (ditem.DelivaryDate != null)
                        {
                            axaptaRecord.set_Field("DeliveryDate", ditem.DelivaryDate);
                        }

                        axaptaRecord.set_Field("ItemId", itemId);
                        axaptaRecord.set_Field("purchId", purchId);
                        axaptaRecord.set_Field("PurchUnit", "Pcs");
                        axaptaRecord.set_Field("QtyOrdered", Convert.ToDecimal(sdItem.Qty.ToString()));
                        axaptaRecord.set_Field("PurchPrice", Convert.ToDecimal(ditem.PurchasePrice));
                        axaptaRecord.set_Field("PurchQty", Convert.ToDecimal(sdItem.Qty.ToString()));
                        axaptaRecord.set_Field("LineAmount",
                                               Convert.ToDecimal((sdItem.Qty * ditem.PurchasePrice).ToString()));

                        axaptaRecord.Call("createLine", true, true, false, true, true, false);
                    }

                    //TO DO: Add Posting TO Retail Plus Logic Here!

                    //-////////////////////////////////////////////
                    var retailContext = new ccnewEntities();
                    //var retailPoHeader = new TblPOHeader
                    //{
                    //    Code = headerObjToPost.PurchaseID,
                    //    tblstore = headerObjToPost.WareHouseID,
                    //     tblseason = headerObjToPost.tbl_RFQHeader.SeasonCode,

                    //};
                    var retailPoMainDetail = new TblPOMainDetail();
                    var retailPoDetail     = new TblPODetail();

                    axapta.TTSCommit();
                    headerObjToPost.IsPosted = true;
                    context.SaveChanges();
                }
            }
            catch (Exception)
            {
                axapta.TTSAbort();
                throw;
            }
            finally
            {
                axapta.Logoff();
                axapta.Dispose();
            }
        }
Exemplo n.º 6
0
        public static tbl_RFQHeader MapToModel(RFQViewModel objectToBemapped, bool isFullObjectMapper)
        {
            var temp = new tbl_RFQHeader
            {
                BrandCode    = objectToBemapped.BrandCode,
                SeasonCode   = objectToBemapped.SeasonCode,
                SupplierCode = objectToBemapped.SupplierID
            };

            if (objectToBemapped.TransID != null)
            {
                temp.TransID = (int)objectToBemapped.TransID;
            }
            temp.DocNumber     = objectToBemapped.DocNum ?? " ";
            temp.tbl_RFQDetail = new ObservableCollection <tbl_RFQDetail>();
            foreach (var item in objectToBemapped.RFQHeaderList)
            {
                var stemp = new tbl_RFQDetail
                {
                    DelivaryDate     = item.DelivaryDate,
                    Descreption      = item.Desc,
                    Image            = item.HeaderImage,
                    IsSampleAttached = item.IsSampleAttached,
                    MainFabricDesc   = item.MainFabDesc
                };
                if (item.MainHeaderTransID != null)
                {
                    stemp.MainHeaderTransID = item.MainHeaderTransID;
                }
                stemp.Notes         = item.Notes;
                stemp.Qty           = item.Qty;
                stemp.StyleCode     = item.Style;
                stemp.SubFabricDesc = item.SubFabDesc;

                if (item.SubHeaderSerial != null)
                {
                    stemp.SubHeaderID = (int)item.SubHeaderSerial;
                }
                stemp.tbl_RFQDetailService = new ObservableCollection <tbl_RFQDetailService>();
                foreach (var sItem in item.HeaderServices)
                {
                    var hsTemp = new tbl_RFQDetailService {
                        Image = sItem.Image
                    };

                    if (sItem.Iserial != null)
                    {
                        hsTemp.Iserial = (int)sItem.Iserial;
                    }

                    hsTemp.Notes = sItem.Notes;
                    if (sItem.ServiceCode != null)
                    {
                        hsTemp.ServiceCode = sItem.ServiceCode;
                    }

                    if (sItem.ParentID != null)
                    {
                        hsTemp.SupHeaderID = sItem.ParentID;
                    }

                    stemp.tbl_RFQDetailService.Add(hsTemp);
                }
                stemp.tbl_RFQDetailItem = new ObservableCollection <tbl_RFQDetailItem>();
                foreach (var iItems in item.HeaderItems)
                {
                    var iTemp = new tbl_RFQDetailItem();
                    iTemp.ItemCode      = iItems.SelectedRFQItem.Code;
                    iTemp.Description   = iItems.Description;
                    iTemp.Image         = iItems.Image;
                    iTemp.Size          = iItems.SelectedRFQItem.Size;
                    iTemp.Configuration = iItems.SelectedRFQItem.Config;
                    iTemp.Batch         = iItems.SelectedRFQItem.Batch;
                    iTemp.Name          = iItems.SelectedRFQItem.Name;
                    iTemp.Source        = iItems.SelectedRFQItem.ItemGroup;
                    if (iItems.Iserial != null)
                    {
                        iTemp.Iserial = (int)iItems.Iserial;
                    }

                    iTemp.ItemCode = iItems.ItemCode;
                    if (iItems.ParentID != null)
                    {
                        iTemp.SupHeaderID = iItems.ParentID;
                    }

                    stemp.tbl_RFQDetailItem.Add(iTemp);
                }
                stemp.tbl_RFQFollowup = new ObservableCollection <tbl_RFQFollowup>();
                foreach (var fItem in item.FollowUpList)
                {
                    var fTemp = new tbl_RFQFollowup
                    {
                        ActualDelivaryDate = fItem.ActualDelivaryDate,
                        EstDelivaryDate    = fItem.EstimatedDelivaryDate,
                        FollowupType       = 1
                    };

                    if (fItem.Iserial != null)
                    {
                        fTemp.Iserial = (int)fItem.Iserial;
                    }

                    fTemp.Notes     = fItem.Notes;
                    fTemp.SizeCode  = fItem.SizeCode;
                    fTemp.StatusID  = fItem.StatusID;
                    fTemp.StyleCode = fItem.Style;
                    if (fItem.ParentID != null)
                    {
                        fTemp.SubHeaderID = fItem.ParentID;
                    }

                    stemp.tbl_RFQFollowup.Add(fTemp);
                }
                foreach (var fcItem in item.CostFollowUpList)
                {
                    var fcTemp = new tbl_RFQFollowup
                    {
                        ActualDelivaryDate = fcItem.ActualDelivaryDate,
                        Cost            = fcItem.Cost,
                        EstDelivaryDate = fcItem.EstimatedDelivaryDate,
                        FollowupType    = 0,
                        Currency        = fcItem.Currency,
                        ExchangeRate    = fcItem.ExchangeRate,
                        LocalCost       = fcItem.LocalCost,
                        DCost           = fcItem.AdditionalCost,
                        ColorCode       = fcItem.StyleColor
                    };

                    if (fcItem.Iserial != null)
                    {
                        fcTemp.Iserial = (int)fcItem.Iserial;
                    }

                    fcTemp.Notes     = fcItem.Notes;
                    fcTemp.StatusID  = fcItem.Status;
                    fcTemp.StyleCode = fcItem.Style;
                    if (fcItem.ParentID != null)
                    {
                        fcTemp.SubHeaderID = fcItem.ParentID;
                    }

                    fcTemp.tbl_RFQ_AdditionalCost = fcItem.AdditionalCostList;
                    stemp.tbl_RFQFollowup.Add(fcTemp);
                }

                temp.tbl_RFQDetail.Add(stemp);
            }
            temp.tbl_PurchaseOrderHeader = new ObservableCollection <tbl_PurchaseOrderHeader>();
            foreach (var purchHeader in objectToBemapped.PurchHeaders)
            {
                var purchHeaderTemp = new tbl_PurchaseOrderHeader
                {
                    CreationDate             = purchHeader.CreationDate,
                    RecieveDate              = purchHeader.DocDate,
                    Vendor                   = purchHeader.VendorCode,
                    WareHouseID              = purchHeader.WarHouseCode,
                    PurchaseID               = purchHeader.PurchId,
                    tbl_PurchaseOrderDetails = new ObservableCollection <tbl_PurchaseOrderDetails>()
                };
                foreach (var detail in purchHeader.PurchaseOrderDetails)
                {
                    var detail1   = detail;
                    var purchline = new tbl_PurchaseOrderDetails
                    {
                        Color         = detail1.StyleColor ?? "",
                        PurchasePrice = detail1.Price,
                        StyleCode     = detail1.StyleHeader,
                        DelivaryDate  = detail1.DelivaryDate
                    };
                    purchline.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))
                    })
                        );
                    purchline.tbl_PurchaseOrder_AdditionalCost =
                        new ObservableCollection <tbl_PurchaseOrder_AdditionalCost>
                            (detail.AdditionalCostList);
                    purchHeaderTemp.tbl_PurchaseOrderDetails
                    .Add
                    (
                        purchline
                    );
                }
                temp.tbl_PurchaseOrderHeader.Add(purchHeaderTemp);
            }
            return(temp);
        }