Beispiel #1
0
        public static bool saveSalesContractDetail(
            SalesContract salescontract_requests,
            int ResponseGenID)
        {
            Stockdbf     stockdbf     = new Stockdbf();
            StockDetails stockDetails = new StockDetails();
            bool         flag         = false;

            try
            {
                using (CustomERPEntities customErpEntities = new CustomERPEntities())
                {
                    if (salescontract_requests.SalescontractDetails != null)
                    {
                        if (salescontract_requests.SalescontractDetails.Count > 0)
                        {
                            foreach (SalesContractDetails salescontractDetail1 in salescontract_requests.SalescontractDetails)
                            {
                                SalesContractDetails salescontractDetail = salescontractDetail1;
                                salescontractDetail.SalesID = ResponseGenID;
                                SalesContractDetails salesContractDetails = customErpEntities.SalesContractDetails.Where <SalesContractDetails>((Expression <Func <SalesContractDetails, bool> >)(iv => iv.IDNUMBER == salescontractDetail.IDNUMBER && iv.SalesID == ResponseGenID)).SingleOrDefault <SalesContractDetails>();
                                if (salesContractDetails == null)
                                {
                                    customErpEntities.SalesContractDetails.Add(salescontractDetail);
                                    customErpEntities.SaveChanges();
                                }
                                else
                                {
                                    salesContractDetails.Price       = salescontractDetail.Price;
                                    salesContractDetails.Qty         = salescontractDetail.Qty;
                                    salesContractDetails.TotalAmount = salescontractDetail.TotalAmount;
                                    salesContractDetails.CompanyID   = salescontractDetail.CompanyID;
                                    salesContractDetails.UnitID      = salescontractDetail.UnitID;
                                    customErpEntities.SaveChanges();
                                }
                            }
                        }
                        flag = true;
                    }
                    flag = true;
                }
            }
            catch (Exception ex)
            {
                flag = false;
            }
            return(flag);
        }
Beispiel #2
0
        public static bool saveStocks(Sales sales_requests, int ResponseGenID)
        {
            Stockdbf     stockdbf = new Stockdbf();
            StockDetails entity   = new StockDetails();
            bool         flag     = false;

            try
            {
                using (CustomERPEntities customErpEntities = new CustomERPEntities())
                {
                    if (sales_requests.SalesDetails != null)
                    {
                        if (sales_requests.SalesDetails.Count > 0)
                        {
                            foreach (SalesDetails salesDetail1 in sales_requests.SalesDetails)
                            {
                                SalesDetails salesDetail = salesDetail1;
                                salesDetail.SalesID = ResponseGenID;
                                SalesDetails salesDetails = customErpEntities.SalesDetails.Where <SalesDetails>((Expression <Func <SalesDetails, bool> >)(iv => iv.IDNUMBER == salesDetail.IDNUMBER && iv.SalesID == ResponseGenID)).SingleOrDefault <SalesDetails>();
                                if (salesDetails == null)
                                {
                                    customErpEntities.SalesDetails.Add(salesDetail);
                                    customErpEntities.SaveChanges();
                                    if (customErpEntities.Stockdbf.FirstOrDefault <Stockdbf>((Expression <Func <Stockdbf, bool> >)(x => x.ItemID == salesDetail.ItemID && x.ItemVarientID == salesDetail.ItemVarientID)) != null)
                                    {
                                        stockdbf.StockQty -= salesDetail.Qty;
                                        customErpEntities.SaveChanges();
                                        entity.CompanyID     = new int?(1);
                                        entity.StockID       = stockdbf.IDNUMBER;
                                        entity.ItemID        = salesDetail.ItemID;
                                        entity.ItemVarientID = salesDetail.IDNUMBER;
                                        entity.StockQty      = salesDetail.Qty;
                                        entity.StockRate     = salesDetail.Price;
                                        entity.TranCode      = "D";
                                        entity.TranBook      = "SLS";
                                        entity.TranNo        = sales_requests.SONO;
                                        entity.CreatedBy     = new int?(1);
                                        entity.CreatedDate   = new DateTime?(DateTime.Now);
                                        customErpEntities.StockDetails.Add(entity);
                                        customErpEntities.SaveChanges();
                                    }
                                    flag = true;
                                }
                                else
                                {
                                    salesDetails.Price       = salesDetail.Price;
                                    salesDetails.Qty         = salesDetail.Qty;
                                    salesDetails.TotalAmount = salesDetail.TotalAmount;
                                    salesDetails.CompanyID   = salesDetail.CompanyID;
                                    salesDetails.UnitID      = salesDetail.UnitID;
                                    customErpEntities.SaveChanges();
                                    if (customErpEntities.Stockdbf.FirstOrDefault <Stockdbf>((Expression <Func <Stockdbf, bool> >)(x => x.ItemID == salesDetail.ItemID && x.ItemVarientID == salesDetail.ItemVarientID)) != null)
                                    {
                                        stockdbf.StockQty -= salesDetails.Qty;
                                        customErpEntities.SaveChanges();
                                        entity.CompanyID     = new int?(1);
                                        entity.StockID       = stockdbf.IDNUMBER;
                                        entity.ItemID        = salesDetails.ItemID;
                                        entity.ItemVarientID = salesDetails.IDNUMBER;
                                        entity.StockQty      = salesDetails.Qty;
                                        entity.StockRate     = salesDetails.Price;
                                        entity.TranCode      = "D";
                                        entity.TranBook      = "SLS";
                                        entity.TranNo        = sales_requests.SONO;
                                        entity.CreatedBy     = new int?(1);
                                        entity.CreatedDate   = new DateTime?(DateTime.Now);
                                        customErpEntities.StockDetails.Add(entity);
                                        customErpEntities.SaveChanges();
                                    }
                                    flag = true;
                                }
                            }
                        }
                        flag = true;
                    }
                    flag = true;
                }
            }
            catch (Exception ex)
            {
                flag = false;
            }
            return(flag);
        }
Beispiel #3
0
        public static bool saveStocks(Purchase purchase_requests, int ResponseGenID)
        {
            Stockdbf     stockdbf = new Stockdbf();
            StockDetails entity   = new StockDetails();
            bool         flag     = false;

            try
            {
                using (CustomERPEntities customErpEntities = new CustomERPEntities())
                {
                    if (purchase_requests.PurchaseDetails != null)
                    {
                        if (purchase_requests.PurchaseDetails.Count > 0)
                        {
                            foreach (PurchaseDetails purchaseDetail1 in purchase_requests.PurchaseDetails)
                            {
                                PurchaseDetails purchaseDetail = purchaseDetail1;
                                purchaseDetail.PurchaseID = ResponseGenID;
                                PurchaseDetails purchaseDetails = customErpEntities.PurchaseDetails.Where <PurchaseDetails>((Expression <Func <PurchaseDetails, bool> >)(iv => iv.IDNUMBER == purchaseDetail.IDNUMBER && iv.PurchaseID == ResponseGenID)).SingleOrDefault <PurchaseDetails>();
                                if (purchaseDetails == null)
                                {
                                    customErpEntities.PurchaseDetails.Add(purchaseDetail);
                                    customErpEntities.SaveChanges();
                                    if (customErpEntities.Stockdbf.FirstOrDefault <Stockdbf>((Expression <Func <Stockdbf, bool> >)(x => x.ItemID == purchaseDetail.ItemID && x.ItemVarientID == purchaseDetail.ItemVarientID)) != null)
                                    {
                                        stockdbf.StockQty += purchaseDetail.Qty;
                                        customErpEntities.SaveChanges();
                                        entity.CompanyID     = new int?(1);
                                        entity.StockID       = stockdbf.IDNUMBER;
                                        entity.ItemID        = purchaseDetail.ItemID;
                                        entity.ItemVarientID = purchaseDetail.IDNUMBER;
                                        entity.StockQty      = purchaseDetail.Qty;
                                        entity.StockRate     = purchaseDetail.Price;
                                        entity.TranCode      = "C";
                                        entity.TranBook      = "PUR";
                                        entity.TranNo        = purchase_requests.PONo;
                                        entity.CreatedBy     = new int?(1);
                                        entity.CreatedDate   = new DateTime?(DateTime.Now);
                                        customErpEntities.StockDetails.Add(entity);
                                        customErpEntities.SaveChanges();
                                    }
                                    flag = true;
                                }
                                else
                                {
                                    purchaseDetails.Price       = purchaseDetail.Price;
                                    purchaseDetails.Qty         = purchaseDetail.Qty;
                                    purchaseDetails.TotalAmount = purchaseDetail.TotalAmount;
                                    purchaseDetails.CompanyID   = purchaseDetail.CompanyID;
                                    purchaseDetails.UnitID      = purchaseDetail.UnitID;
                                    customErpEntities.SaveChanges();
                                    if (customErpEntities.Stockdbf.FirstOrDefault <Stockdbf>((Expression <Func <Stockdbf, bool> >)(x => x.ItemID == purchaseDetail.ItemID && x.ItemVarientID == purchaseDetail.ItemVarientID)) != null)
                                    {
                                        stockdbf.StockQty += purchaseDetails.Qty;
                                        customErpEntities.SaveChanges();
                                        entity.CompanyID     = new int?(1);
                                        entity.StockID       = stockdbf.IDNUMBER;
                                        entity.ItemID        = purchaseDetails.ItemID;
                                        entity.ItemVarientID = purchaseDetails.IDNUMBER;
                                        entity.StockQty      = purchaseDetails.Qty;
                                        entity.StockRate     = purchaseDetails.Price;
                                        entity.TranCode      = "C";
                                        entity.TranBook      = "PUR";
                                        entity.TranNo        = purchase_requests.PONo;
                                        entity.CreatedBy     = new int?(1);
                                        entity.CreatedDate   = new DateTime?(DateTime.Now);
                                        customErpEntities.StockDetails.Add(entity);
                                        customErpEntities.SaveChanges();
                                    }
                                    flag = true;
                                }
                            }
                        }
                        flag = true;
                    }
                    flag = true;
                }
            }
            catch (Exception ex)
            {
                flag = false;
            }
            return(flag);
        }
        public static bool saveStocks(Item product_requests, int ResponseGenID)
        {
            Stockdbf     entity1      = new Stockdbf();
            StockDetails entity2      = new StockDetails();
            ItemVarient  itemVarient1 = new ItemVarient();
            bool         flag         = false;

            try
            {
                using (CustomERPEntities customErpEntities = new CustomERPEntities())
                {
                    if (product_requests.ItemVarients != null)
                    {
                        if (product_requests.ItemVarients.Count > 0)
                        {
                            foreach (ItemVarient itemVarient2 in product_requests.ItemVarients)
                            {
                                ItemVarient responseGenID = itemVarient2;
                                responseGenID.ItemID      = ResponseGenID;
                                responseGenID.CreatedBy   = new int?(1);
                                responseGenID.CreatedDate = new DateTime?(DateTime.Now);
                                responseGenID.UpdateBy    = new int?(1);
                                responseGenID.UpdatedDate = new DateTime?(DateTime.Now);
                                ItemVarient warehouseID = customErpEntities.ItemVarient.Where <ItemVarient>((Expression <Func <ItemVarient, bool> >)(iv => iv.IDNUMBER == responseGenID.IDNUMBER && iv.ItemID == ResponseGenID)).SingleOrDefault <ItemVarient>();
                                if (warehouseID == null)
                                {
                                    warehouseID             = responseGenID;
                                    entity1.StockQty        = responseGenID.Inventory;
                                    warehouseID.WarehouseID = responseGenID.WarehouseID;
                                    customErpEntities.ItemVarient.Add(warehouseID);
                                    customErpEntities.SaveChanges();
                                    if (customErpEntities.Stockdbf.Where <Stockdbf>((Expression <Func <Stockdbf, bool> >)(st => st.ItemID == responseGenID.ItemID && st.ItemVarientID == responseGenID.IDNUMBER)).FirstOrDefault <Stockdbf>() != null)
                                    {
                                        entity1.StockQty = responseGenID.Inventory;
                                        customErpEntities.SaveChanges();
                                        entity2.StockQty  = responseGenID.Inventory;
                                        entity2.StockRate = warehouseID.Cost;
                                        entity2.TranNo    = product_requests.ItemName;
                                        customErpEntities.SaveChanges();
                                    }
                                    else
                                    {
                                        entity1.CompanyID     = new int?(1);
                                        entity1.ItemID        = responseGenID.ItemID;
                                        entity1.ItemVarientID = responseGenID.IDNUMBER;
                                        entity1.StockQty      = warehouseID.Inventory;
                                        customErpEntities.Stockdbf.Add(entity1);
                                        customErpEntities.SaveChanges();
                                        entity2.CompanyID     = new int?(1);
                                        entity2.StockID       = entity1.IDNUMBER;
                                        entity2.ItemID        = responseGenID.ItemID;
                                        entity2.ItemVarientID = responseGenID.IDNUMBER;
                                        entity2.StockQty      = responseGenID.Inventory;
                                        entity2.StockRate     = responseGenID.Cost;
                                        entity2.TranCode      = "C";
                                        entity2.TranBook      = "OP";
                                        entity2.TranNo        = product_requests.ItemName;
                                        entity2.CreatedBy     = new int?(1);
                                        entity2.CreatedDate   = new DateTime?(DateTime.Now);
                                        customErpEntities.StockDetails.Add(entity2);
                                        customErpEntities.SaveChanges();
                                    }
                                    flag = true;
                                }
                                else
                                {
                                    warehouseID.Color       = responseGenID.Color;
                                    warehouseID.Size        = responseGenID.Size;
                                    warehouseID.Inventory   = responseGenID.Inventory;
                                    warehouseID.WarehouseID = responseGenID.WarehouseID;
                                    warehouseID.Cost        = responseGenID.Cost;
                                    warehouseID.SKU         = responseGenID.SKU;
                                    warehouseID.UPC         = responseGenID.UPC;
                                    customErpEntities.SaveChanges();
                                    if (customErpEntities.Stockdbf.FirstOrDefault <Stockdbf>((Expression <Func <Stockdbf, bool> >)(x => x.ItemID == warehouseID.ItemID && x.ItemVarientID == warehouseID.IDNUMBER)) != null)
                                    {
                                        entity1.StockQty = warehouseID.Inventory;
                                        customErpEntities.SaveChanges();
                                        entity2.StockQty  = responseGenID.Inventory;
                                        entity2.StockRate = warehouseID.Cost;
                                        entity2.TranNo    = product_requests.ItemName;
                                        customErpEntities.SaveChanges();
                                    }
                                    else
                                    {
                                        entity1.CompanyID     = new int?(1);
                                        entity1.ItemID        = warehouseID.ItemID;
                                        entity1.ItemVarientID = warehouseID.IDNUMBER;
                                        entity1.StockQty      = warehouseID.Inventory;
                                        customErpEntities.Stockdbf.Add(entity1);
                                        customErpEntities.SaveChanges();
                                        entity2.CompanyID     = new int?(1);
                                        entity2.StockID       = entity1.IDNUMBER;
                                        entity2.ItemID        = warehouseID.ItemID;
                                        entity2.ItemVarientID = warehouseID.IDNUMBER;
                                        entity2.StockQty      = warehouseID.Inventory;
                                        entity2.StockRate     = warehouseID.Cost;
                                        entity2.TranCode      = "C";
                                        entity2.TranBook      = "OP";
                                        entity2.TranNo        = product_requests.ItemName;
                                        entity2.CreatedBy     = new int?(1);
                                        entity2.CreatedDate   = new DateTime?(DateTime.Now);
                                        customErpEntities.StockDetails.Add(entity2);
                                        customErpEntities.SaveChanges();
                                    }
                                    flag = true;
                                }
                            }
                        }
                        flag = true;
                    }
                    flag = true;
                }
            }
            catch (Exception ex)
            {
                flag = false;
            }
            return(flag);
        }