Ejemplo n.º 1
0
        public long SavePurchaseInformation(PurchaseReceive model, int userId)
        {
            long CurrentPurchaseID = 0;

            try
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    #region New_Purchase_Insert
                    using (_context)
                    {
                        Prq_Purchase objPurchase = new Prq_Purchase();
                        //Random r = new Random();

                        //objPurchase.PurchaseNo = r.Next().ToString();
                        objPurchase.PurchaseNo        = DalCommon.GetPreDefineNextCodeByUrl("Purchase/Purchase");
                        objPurchase.SupplierID        = Convert.ToInt16(model.SupplierID);
                        objPurchase.SupplierAddressID = Convert.ToInt16(model.SupplierAddressID);
                        objPurchase.PurchaseCategory  = model.PurchaseCategory;
                        objPurchase.PurchaseType      = model.PurchaseType;
                        objPurchase.PurchaseYear      = model.PurchaseYear;
                        objPurchase.PurchaseDate      = DalCommon.SetDate(model.PurchaseDate);
                        objPurchase.PurchaseNote      = model.PurchaseNote;
                        objPurchase.RecordStatus      = "NCF";
                        objPurchase.SetOn             = DateTime.Now;
                        objPurchase.SetBy             = userId;

                        _context.Prq_Purchase.Add(objPurchase);
                        _context.SaveChanges();

                        CurrentPurchaseID = objPurchase.PurchaseID;

                        if (model.ChallanList != null)
                        {
                            Prq_PurchaseChallan objChallan = new Prq_PurchaseChallan();

                            objChallan.ChallanNo       = model.ChallanList.FirstOrDefault().ChallanNo;
                            objChallan.PurchaseID      = CurrentPurchaseID;
                            objChallan.SourceID        = model.ChallanList.FirstOrDefault().SourceID;
                            objChallan.LocationID      = model.ChallanList.FirstOrDefault().LocationID;
                            objChallan.ReceiveStore    = DalCommon.GetStoreCode(model.ChallanList.FirstOrDefault().ReceiveStore);
                            objChallan.ChallanCategory = model.ChallanList.FirstOrDefault().ChallanCategory;
                            objChallan.ChallanNote     = model.ChallanList.FirstOrDefault().ChallanNote;



                            objChallan.ChallanDate = Convert.ToDateTime(model.ChallanList.FirstOrDefault().ChallanDate);


                            objChallan.RecordStatus = "NCF";
                            objChallan.SetOn        = DateTime.Now;
                            objChallan.SetBy        = userId;

                            _context.Prq_PurchaseChallan.Add(objChallan);
                            _context.SaveChanges();

                            var CurrentChallanNo = objChallan.ChallanID;

                            if (model.ChallanItemList != null)
                            {
                                foreach (var ChallanItem in model.ChallanItemList)
                                {
                                    Prq_PurchaseChallanItem objPurchaseChallanItem = new Prq_PurchaseChallanItem();

                                    objPurchaseChallanItem.ChallanID    = CurrentChallanNo;
                                    objPurchaseChallanItem.ItemCategory = "Leather";
                                    objPurchaseChallanItem.ItemTypeID   = DalCommon.GetItemTypeCode(ChallanItem.ItemTypeID);
                                    objPurchaseChallanItem.ItemSizeID   = DalCommon.GetSizeCode(ChallanItem.ItemSizeID);
                                    objPurchaseChallanItem.Description  = ChallanItem.Description;
                                    objPurchaseChallanItem.UnitID       = DalCommon.GetUnitCode(ChallanItem.UnitID);
                                    objPurchaseChallanItem.ChallanQty   = ChallanItem.ChallanQty;
                                    objPurchaseChallanItem.ReceiveQty   = ChallanItem.ReceiveQty;
                                    objPurchaseChallanItem.Remark       = ChallanItem.Remark;
                                    objPurchaseChallanItem.RecordStatus = "NCF";
                                    objPurchaseChallanItem.SetBy        = userId;
                                    objPurchaseChallanItem.SetOn        = DateTime.Now;

                                    _context.Prq_PurchaseChallanItem.Add(objPurchaseChallanItem);
                                    _context.SaveChanges();
                                }
                            }
                        }
                    }
                    #endregion

                    transaction.Complete();
                }
                return(CurrentPurchaseID);
            }
            catch (Exception e)
            {
                return(CurrentPurchaseID);
            }
        }
        public long Save(PRDYearMonthCrustReqItem model, int userId)
        {
            long CurrentRequisitionItemID = 0;

            try
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    using (_context)
                    {
                        var RequisitionDateInfo = (from r in _context.PRD_YearMonthFinishReqDate.AsEnumerable()
                                                   where r.RequisitionDateID == model.RequisitionDateID
                                                   select r).FirstOrDefault();

                        RequisitionDateInfo.Remark = model.ConfirmNote;
                        _context.SaveChanges();


                        #region Update_Item_Information
                        if (model.ItemList != null)
                        {
                            foreach (var Item in model.ItemList)
                            {
                                #region New_Item_Insertion
                                if (Item.RequisitionItemID == 0)
                                {
                                    PRD_YearMonthFinishReqItem objItem = new PRD_YearMonthFinishReqItem();

                                    objItem.RequisitionDateID    = Item.RequisitionDateID;
                                    objItem.ScheduleItemID       = Item.ScheduleItemID;
                                    objItem.ScheduleProductionNo = Item.ScheduleProductionNo;
                                    //objItem.RequisitionNo = Convert.ToInt32(model.PurchaseID);
                                    objItem.BuyerID      = Item.BuyerID;
                                    objItem.BuyerOrderID = Item.BuyerOrderID;
                                    objItem.ArticleID    = Item.ArticleID;
                                    objItem.ArticleNo    = Item.ArticleNo;

                                    if (Item.ArticleChallanID != 0)
                                    {
                                        objItem.ArticleChallanID = Item.ArticleChallanID;
                                        objItem.ArticleChallanNo = Item.ArticleChallanNo;
                                    }
                                    objItem.AvgSize         = Item.AvgSize;
                                    objItem.AvgSizeUnit     = DalCommon.GetUnitCode(Item.AvgSizeUnitName);
                                    objItem.SelectionRange  = Item.SelectionRange;
                                    objItem.SideDescription = Item.SideDescription;
                                    objItem.Thickness       = Item.Thickness;
                                    objItem.ThicknessUnit   = DalCommon.GetUnitCode(Item.ThicknessUnitName);
                                    objItem.ThicknessAt     = (Item.ThicknessAt == "After Shaving" ? "AFSV" : "AFFN");
                                    objItem.ItemTypeID      = DalCommon.GetItemTypeCode(Item.ItemTypeName);
                                    objItem.LeatherStatusID = DalCommon.GetLeatherStatusCode(Item.LeatherStatusName);
                                    objItem.LeatherTypeID   = DalCommon.GetLeatherTypeCode("Crust");
                                    objItem.Remark          = Item.Remarks;
                                    objItem.SetOn           = DateTime.Now;
                                    objItem.SetBy           = 1;;

                                    _context.PRD_YearMonthFinishReqItem.Add(objItem);
                                    _context.SaveChanges();

                                    CurrentRequisitionItemID = objItem.RequisitionItemID;
                                }
                                #endregion

                                #region Existing_Challan_Update
                                else if (Item.RequisitionItemID != 0)
                                {
                                    var CurrentItem = (from c in _context.PRD_YearMonthFinishReqItem.AsEnumerable()
                                                       where c.RequisitionItemID == Item.RequisitionItemID
                                                       select c).FirstOrDefault();

                                    CurrentItem.RequisitionDateID    = Item.RequisitionDateID;
                                    CurrentItem.ScheduleProductionNo = Item.ScheduleProductionNo;
                                    //CurrentItem.RequisitionNo = Convert.ToInt32(model.PurchaseID);
                                    CurrentItem.BuyerID      = Item.BuyerID;
                                    CurrentItem.BuyerOrderID = Item.BuyerOrderID;
                                    CurrentItem.ArticleID    = Item.ArticleID;
                                    CurrentItem.ArticleNo    = Item.ArticleNo;

                                    if (Item.ArticleChallanID != 0)
                                    {
                                        CurrentItem.ArticleChallanID = Item.ArticleChallanID;
                                        CurrentItem.ArticleChallanNo = Item.ArticleChallanNo;
                                    }

                                    CurrentItem.AvgSize         = Item.AvgSize;
                                    CurrentItem.AvgSizeUnit     = DalCommon.GetUnitCode(Item.AvgSizeUnitName);
                                    CurrentItem.SelectionRange  = Item.SelectionRange;
                                    CurrentItem.SideDescription = Item.SideDescription;
                                    CurrentItem.Thickness       = Item.Thickness.ToString();
                                    CurrentItem.ThicknessUnit   = DalCommon.GetUnitCode(Item.ThicknessUnitName);
                                    CurrentItem.ThicknessAt     = Item.ThicknessAt;
                                    CurrentItem.ItemTypeID      = DalCommon.GetItemTypeCode(Item.ItemTypeName);
                                    CurrentItem.LeatherStatusID = DalCommon.GetLeatherStatusCode(Item.LeatherStatusName);
                                    CurrentItem.LeatherTypeID   = DalCommon.GetLeatherTypeCode("Crust");
                                    CurrentItem.Remark          = Item.Remarks;
                                    _context.SaveChanges();
                                }
                                #endregion
                            }
                        }

                        #endregion

                        #region To_Find_ColorItemID_For_Items_If_Any

                        if (model.ColorList != null)
                        {
                            foreach (var Color in model.ColorList)
                            {
                                if (Color.RequisitionItemID != null && Color.RequisitionItemID != 0)
                                {
                                    CurrentRequisitionItemID = Convert.ToInt64(Color.RequisitionItemID);
                                    break;
                                }
                                else
                                {
                                    if (model.SelectedRequisitionItemID != 0)
                                    {
                                        CurrentRequisitionItemID = model.SelectedRequisitionItemID;
                                    }
                                    break;
                                }
                            }
                        }
                        #endregion

                        #region Update_Color_Item_Information
                        if (model.ColorList != null)
                        {
                            foreach (var Color in model.ColorList)
                            {
                                #region New_Color_Item_Insertion
                                if (Color.ReqItemColorID == 0)
                                {
                                    PRD_YearMonthFinishReqItemColor objColor = new PRD_YearMonthFinishReqItemColor();

                                    objColor.RequisitionItemID = CurrentRequisitionItemID;
                                    objColor.ColorID           = Color.ColorID;
                                    objColor.ArticleColorNo    = Color.ArticleColorNo;
                                    objColor.ColorPcs          = (Color.ColorPCS);
                                    objColor.ColorSide         = (Color.ColorSide);
                                    objColor.ColorArea         = Color.ColorArea;
                                    objColor.AreaUnit          = DalCommon.GetUnitCode(Color.AreaUnitName);
                                    objColor.Remarks           = Color.Remarks;
                                    objColor.SetBy             = 1;;
                                    objColor.SetOn             = DateTime.Now;

                                    _context.PRD_YearMonthFinishReqItemColor.Add(objColor);
                                    _context.SaveChanges();
                                }
                                #endregion

                                #region Update_Existing_Color_Item
                                else if (Color.ReqItemColorID != 0)
                                {
                                    var currentColorItem = (from c in _context.PRD_YearMonthFinishReqItemColor.AsEnumerable()
                                                            where c.ReqItemColorID == Color.ReqItemColorID
                                                            select c).FirstOrDefault();

                                    currentColorItem.RequisitionItemID = CurrentRequisitionItemID;
                                    currentColorItem.ColorID           = Color.ColorID;
                                    currentColorItem.ArticleColorNo    = Color.ArticleColorNo;
                                    currentColorItem.ColorPcs          = (Color.ColorPCS);
                                    currentColorItem.ColorSide         = (Color.ColorSide);
                                    currentColorItem.ColorArea         = Color.ColorArea;
                                    currentColorItem.AreaUnit          = DalCommon.GetUnitCode(Color.AreaUnitName);
                                    currentColorItem.Remarks           = Color.Remarks;
                                    currentColorItem.SetBy             = 1;;
                                    currentColorItem.SetOn             = DateTime.Now;
                                    _context.SaveChanges();
                                }
                                #endregion
                            }
                        }
                        #endregion
                    }
                    transaction.Complete();
                }
                return(CurrentRequisitionItemID);
            }
            catch (Exception e)
            {
                return(0);
            }
        }
Ejemplo n.º 3
0
        public int UpdatePurchaseInformation(PurchaseReceive model, int userId)
        {
            long CurrentChallanNo = 0;

            try
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    using (_context)
                    {
                        #region Purchase_Informaiton_Update
                        var currentPurchase = (from p in _context.Prq_Purchase.AsEnumerable()
                                               where p.PurchaseID == Convert.ToInt64(model.PurchaseID)
                                               select p).FirstOrDefault();

                        if (currentPurchase.RecordStatus != "CNF")
                        {
                            currentPurchase.SupplierID        = Convert.ToInt32(model.SupplierID);
                            currentPurchase.SupplierAddressID = Convert.ToInt32(model.SupplierAddressID);
                            currentPurchase.PurchaseCategory  = model.PurchaseCategory;
                            currentPurchase.PurchaseType      = model.PurchaseType;
                            currentPurchase.PurchaseYear      = model.PurchaseYear;
                            currentPurchase.PurchaseNote      = model.PurchaseNote;
                            currentPurchase.RecordStatus      = "NCF";

                            currentPurchase.PurchaseDate = DalCommon.SetDate(model.PurchaseDate);
                            currentPurchase.SetBy        = userId;
                            currentPurchase.SetOn        = DateTime.Now;
                            _context.SaveChanges();
                        }

                        #endregion

                        #region Update_Challan_Information
                        if (model.ChallanList != null)
                        {
                            foreach (var challan in model.ChallanList)
                            {
                                #region New_Challan_Insertion
                                if (challan.ChallanID == 0)
                                {
                                    Prq_PurchaseChallan objChallan = new Prq_PurchaseChallan();

                                    objChallan.ChallanNo       = challan.ChallanNo;
                                    objChallan.PurchaseID      = Convert.ToInt32(model.PurchaseID);
                                    objChallan.SourceID        = challan.SourceID;
                                    objChallan.LocationID      = challan.LocationID;
                                    objChallan.ReceiveStore    = DalCommon.GetStoreCode(challan.ReceiveStore);
                                    objChallan.ChallanCategory = challan.ChallanCategory;
                                    objChallan.ChallanNote     = challan.ChallanNote;
                                    objChallan.ChallanDate     = Convert.ToDateTime(challan.ChallanDate);
                                    objChallan.RecordStatus    = "NCF";
                                    objChallan.SetOn           = DateTime.Now;
                                    objChallan.SetBy           = userId;;

                                    _context.Prq_PurchaseChallan.Add(objChallan);
                                    _context.SaveChanges();

                                    CurrentChallanNo = objChallan.ChallanID;
                                }
                                #endregion

                                #region Existing_Challan_Update
                                else if (challan.ChallanID != 0 && challan.RecordStatus != "CNF" && challan.RecordStatus != "Confirmed")
                                {
                                    var currentChallan = (from c in _context.Prq_PurchaseChallan.AsEnumerable()
                                                          where c.ChallanID == challan.ChallanID
                                                          select c).FirstOrDefault();

                                    currentChallan.ChallanNo = challan.ChallanNo;
                                    //currentChallan.PurchaseID = Convert.ToInt32(model.PurchaseID);
                                    currentChallan.SourceID        = challan.SourceID;
                                    currentChallan.LocationID      = challan.LocationID;
                                    currentChallan.ReceiveStore    = DalCommon.GetStoreCode(challan.ReceiveStore);
                                    currentChallan.ChallanCategory = challan.ChallanCategory;
                                    currentChallan.ChallanNote     = challan.ChallanNote;

                                    try
                                    {
                                        //var GridChallanDate = Convert.ToDateTime(challan.ChallanDate).Date.ToString("dd/MM/yyyy");
                                        //currentChallan.ChallanDate = DalCommon.SetDate(GridChallanDate);

                                        var GridChallanDate = challan.ChallanDate.Contains("/") ? challan.ChallanDate : Convert.ToDateTime(challan.ChallanDate).ToString("dd/MM/yyyy");
                                        //var GridChallanDate = Convert.ToDateTime(challan.ChallanDate).ToString().Contains("/") ? challan.ChallanDate : Convert.ToDateTime(challan.ChallanDate).ToString("dd/MM/yyyy");
                                        currentChallan.ChallanDate = DalCommon.SetDate(GridChallanDate);
                                    }
                                    catch
                                    {
                                        var GridChallanDate = Convert.ToDateTime(challan.ChallanDate).Date.ToString("dd/MM/yyyy");
                                        currentChallan.ChallanDate = DalCommon.SetDate(GridChallanDate);
                                        //currentChallan.ChallanDate = DalCommon.SetDate(challan.ChallanDate);
                                    }



                                    currentChallan.RecordStatus = "NCF";
                                    currentChallan.SetOn        = DateTime.Now;
                                    currentChallan.SetBy        = userId;

                                    _context.SaveChanges();
                                }
                                #endregion
                            }
                        }

                        #endregion

                        #region To_Find_ChallanID_For_Items_If_Any

                        if (model.ChallanItemList != null)
                        {
                            foreach (var challanItem in model.ChallanItemList)
                            {
                                if (challanItem.ChallanID != 0)
                                {
                                    CurrentChallanNo = challanItem.ChallanID;
                                    break;
                                }
                            }
                        }
                        #endregion

                        #region Update_Challan_Item_Information
                        if (model.ChallanItemList != null)
                        {
                            foreach (var challanItem in model.ChallanItemList)
                            {
                                #region New_Challan_Item_Insertion
                                if (challanItem.ChallanItemID == 0)
                                {
                                    Prq_PurchaseChallanItem objPurchaseChallanItem = new Prq_PurchaseChallanItem();

                                    objPurchaseChallanItem.ChallanID    = CurrentChallanNo;
                                    objPurchaseChallanItem.ItemCategory = "Leather";
                                    objPurchaseChallanItem.ItemTypeID   = DalCommon.GetItemTypeCode(challanItem.ItemTypeID);
                                    objPurchaseChallanItem.ItemSizeID   = DalCommon.GetSizeCode(challanItem.ItemSizeID);
                                    objPurchaseChallanItem.Description  = challanItem.Description;
                                    objPurchaseChallanItem.UnitID       = DalCommon.GetUnitCode(challanItem.UnitID);
                                    objPurchaseChallanItem.ChallanQty   = challanItem.ChallanQty;
                                    objPurchaseChallanItem.ReceiveQty   = challanItem.ReceiveQty;
                                    objPurchaseChallanItem.Remark       = challanItem.Remark;
                                    objPurchaseChallanItem.RecordStatus = "NCF";
                                    objPurchaseChallanItem.SetBy        = userId;;
                                    objPurchaseChallanItem.SetOn        = DateTime.Now;

                                    _context.Prq_PurchaseChallanItem.Add(objPurchaseChallanItem);
                                    _context.SaveChanges();
                                }
                                #endregion

                                #region Update_Existing_Challan_Item
                                else if (challanItem.ChallanItemID != 0 && challanItem.RecordStatus != "CNF" && challanItem.RecordStatus != "Confirmed")
                                {
                                    var currentChallanItem = (from c in _context.Prq_PurchaseChallanItem.AsEnumerable()
                                                              where c.ChallanItemID == challanItem.ChallanItemID
                                                              select c).FirstOrDefault();

                                    currentChallanItem.ItemSizeID  = DalCommon.GetSizeCode(challanItem.ItemSizeID);
                                    currentChallanItem.ItemTypeID  = DalCommon.GetItemTypeCode(challanItem.ItemTypeID);
                                    currentChallanItem.UnitID      = DalCommon.GetUnitCode(challanItem.UnitID);
                                    currentChallanItem.Description = challanItem.Description;
                                    currentChallanItem.ChallanQty  = challanItem.ChallanQty;
                                    currentChallanItem.ReceiveQty  = challanItem.ReceiveQty;
                                    currentChallanItem.Remark      = challanItem.Remark;
                                    _context.SaveChanges();
                                }
                                #endregion
                            }
                        }
                        #endregion
                    }

                    transaction.Complete();
                }
                return(1);
            }
            catch (Exception e)
            {
                return(0);
            }
        }