Example #1
0
        protected void Button6_Click(object sender, EventArgs e)
        {
            Product  prod      = ControllerManager.Product.GetProductInfo("59539502");
            DateTime endDate   = Config.CurrentDate;
            DateTime startDate = Config.CurrentDate.AddDays(-7);

            IList <PartnerNet.Domain.TransactionHistoryWeekly> translist = new List <PartnerNet.Domain.TransactionHistoryWeekly>();

            //aca va un for por cada producto de la lista de productos
            {
                PartnerNet.Domain.TransactionHistoryWeekly transax = new TransactionHistoryWeekly();

                IList <Transactions>  trans = ControllerManager.Transactions.GetTransaction(startDate, endDate, prod);
                IList <PurchaseOrder> pol   = ControllerManager.PurchaseOrder.FilterByWeek(startDate, endDate);

                int purchases      = 0;
                int sales          = 0;
                int purchaseorders = 0;
                int stock          = 0;

                stock = prod.StockQ;

                foreach (Transactions transaction in trans)
                {
                    if (transaction.Quantity > 0)
                    {
                        purchases = purchases + transaction.Quantity;
                    }
                    else if (transaction.Quantity < 0)
                    {
                        sales = sales + (-transaction.Quantity);
                    }
                }
                foreach (PurchaseOrder po in pol)
                {
                    PurchaseOrderItem poi = ControllerManager.PurchaseOrderItem.GetPurchaseOrderInfo(prod, po);
                    if (poi != null)
                    {
                        purchaseorders = purchaseorders + poi.Quantity;
                    }
                }

                transax.ProductID      = PartnerNet.Business.ControllerManager.Product.GetProductInfo(prod.Id);
                transax.Purchase       = purchases;
                transax.Sale           = sales;
                transax.PurchaseOrders = purchaseorders;
                transax.Stock          = stock;
                transax.Year           = Config.CurrentDate.Year;
                transax.Week           = Config.CurrentWeek;
                //borrar esta propiedad!!!
                transax.ProductCode = prod.Id;

                translist.Add(transax);
            }

            GridView1.DataSource = translist;
            GridView1.DataBind();
        }
Example #2
0
        private void LoadInformation(int id)
        {
            Product prod = ControllerManager.Product.GetById(id);

            TransactionHistoryWeekly tran = ControllerManager.TransactionHistoryWeekly.GetIndividualInfo(prod.Id, Config.CurrentWeek, Config.CurrentDate.Year);

            Grundfos.ScalaConnector.Product  prodscala = Grundfos.ScalaConnector.ControllerManager.Product.GetProductInfo(prod.ProductCode);
            IList <TransactionHistoryWeekly> sales     = ControllerManager.TransactionHistoryWeekly.GetSalesTotal(prod, Config.CurrentWeek, Config.CurrentDate.Year);
            IList <ProductStatisticWeekly>   fullstats = ControllerManager.ProductStatisticWeekly.GetProductFullInfo(prod.Id);

            //seguridad por si no existen registros PERO DEBEN EXISTIR AUNQUE SEA EN 0!!!!!!!!
            if (tran == null)
            {
                tran = new TransactionHistoryWeekly();
            }
            //termina la seguridad
            Label25.Text = id.ToString();
            Label2.Text  = prodscala.PurchasePrice.ToString("#,##0.00");
            Label4.Text  = "% " + prodscala.OverCost.ToString();
            Label6.Text  = "U$S " + prodscala.SalePrice.ToString("#,##0.00");
            Label27.Text = "$ " + prodscala.StandardCost.ToString("#,##0.000");
            Label9.Text  = sales[3].Sale.ToString();
            Label11.Text = sales[2].Sale.ToString();
            Label13.Text = sales[1].Sale.ToString();
            Label15.Text = sales[0].Sale.ToString();
            Label18.Text = fullstats[4].Sale.ToString();
            Label20.Text = fullstats[3].Sale.ToString();
            Label22.Text = fullstats[2].Sale.ToString();
            Label24.Text = fullstats[0].Sale.ToString();
            if (prodscala.PurchaseCurrency == "00")
            {
                Label2.Text = "$ " + prodscala.PurchasePrice.ToString("#,##0.00");
            }
            else if (prodscala.PurchaseCurrency == "01")
            {
                Label2.Text = "U$S " + prodscala.PurchasePrice.ToString("#,##0.00");
            }
            else if (prodscala.PurchaseCurrency == "02")
            {
                Label2.Text = "€ " + prodscala.PurchasePrice.ToString("#,##0.00");
            }


            IList <BreakDown> despiece = ControllerManager.BreakDown.GetBreakDown(prod);

            if (despiece.Count > 1)
            {
                ImageButton2.Visible = true;
            }
        }
Example #3
0
        public void GetTransactionHistory(IList <Grundfos.ScalaConnector.Product> prodlist, DateTime startDate, DateTime endDate)
        {
            foreach (Grundfos.ScalaConnector.Product prod in prodlist)
            {
                PartnerNet.Domain.TransactionHistoryWeekly transax = new TransactionHistoryWeekly();

                IList <Grundfos.ScalaConnector.Transactions>  trans = Grundfos.ScalaConnector.ControllerManager.Transactions.GetTransaction(DateTime.Today.Year, endDate, startDate, prod);
                IList <Grundfos.ScalaConnector.PurchaseOrder> pol   = Grundfos.ScalaConnector.ControllerManager.PurchaseOrder.FilterByWeek(DateTime.Today.Year, endDate, startDate);

                int purchases      = 0;
                int sales          = 0;
                int purchaseorders = 0;
                int stock          = 0;

                stock = prod.StockQ;

                foreach (Grundfos.ScalaConnector.Transactions transaction in trans)
                {
                    if (transaction.Quantity > 0)
                    {
                        purchases = purchases + transaction.Quantity;
                    }
                    else if (transaction.Quantity < 0)
                    {
                        sales = sales + (-transaction.Quantity);
                    }
                }
                foreach (Grundfos.ScalaConnector.PurchaseOrder po in pol)
                {
                    Grundfos.ScalaConnector.PurchaseOrderItem poi = Grundfos.ScalaConnector.ControllerManager.PurchaseOrderItem.GetPurchaseOrderInfo(prod, po);
                    if (poi != null)
                    {
                        purchaseorders = purchaseorders + poi.Quantity;
                    }
                }

                transax.ProductID      = ControllerManager.Product.GetProductInfo(prod.Id);
                transax.Purchase       = purchases;
                transax.Sale           = sales;
                transax.PurchaseOrders = purchaseorders;
                transax.Stock          = stock;
                transax.Year           = DateTime.Today.Year;
                transax.Week           = Thread.CurrentThread.CurrentCulture.Calendar.GetWeekOfYear(DateTime.Today, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday);
                //borrar esta propiedad!!!
                transax.ProductCode = prod.Id;

                this.Save(transax);
            }
        }
Example #4
0
        private void LoadInformation(int id)
        {
            Product prod = ControllerManager.Product.GetById(id);

            TransactionHistoryWeekly tran = ControllerManager.TransactionHistoryWeekly.GetIndividualInfo(prod.Id, Config.CurrentWeek, Config.CurrentDate.Year);

            Grundfos.ScalaConnector.Product  prodscala = Grundfos.ScalaConnector.ControllerManager.Product.GetProductInfo(prod.ProductCode);
            IList <TransactionHistoryWeekly> sales     = ControllerManager.TransactionHistoryWeekly.GetSalesTotal(prod, Config.CurrentWeek, Config.CurrentDate.Year);
            IList <ProductStatisticWeekly>   fullstats = ControllerManager.ProductStatisticWeekly.GetProductFullInfo(prod.Id);

            //seguridad por si no existen registros PERO DEBEN EXISTIR AUNQUE SEA EN 0!!!!!!!!
            if (tran == null)
            {
                tran = new TransactionHistoryWeekly();
            }
            //termina la seguridad
            Label25.Text = id.ToString();
            Label2.Text  = prodscala.PurchasePrice.ToString();
            Label4.Text  = prodscala.OverCost.ToString();
            Label6.Text  = prodscala.SalePrice.ToString();
            Label9.Text  = sales[3].Sale.ToString();
            Label11.Text = sales[2].Sale.ToString();
            Label13.Text = sales[1].Sale.ToString();
            Label15.Text = sales[0].Sale.ToString();
            if (fullstats.Count > 5)
            {
                Label18.Text = fullstats[4].Sale.ToString();
            }
            if (fullstats.Count > 4)
            {
                Label20.Text = fullstats[3].Sale.ToString();
            }
            if (fullstats.Count > 3)
            {
                Label22.Text = fullstats[2].Sale.ToString();
            }
            if (fullstats.Count > 2)
            {
                Label24.Text = fullstats[0].Sale.ToString();
            }
        }
Example #5
0
        protected void btnImprimirLP_Click(object sender, ImageClickEventArgs e)
        {
            IList <Product> selectedproduct = new List <Product>();

            foreach (RepeaterItem rep in repItems.Items)
            {
                if (((CheckBox)rep.FindControl("chkGuardar")).Checked)
                {
                    Product prod = ControllerManager.Product.GetProductInfo(((Label)rep.FindControl("lblCodigo")).Text);
                    selectedproduct.Add(prod);
                }
            }
            if (selectedproduct.Count > 0)
            {
                DataSet   objDataSet  = new DataSet();
                DataTable objProdList = new DataTable("rptProdList");

                objProdList.Columns.Add("Codigo");
                objProdList.Columns.Add("Descripcion");
                objProdList.Columns.Add("Proveedor");
                objProdList.Columns.Add("Stock");
                objProdList.Columns.Add("NivelRep");
                objProdList.Columns.Add("ModuloComp");
                objProdList.Columns.Add("PromVentas");
                objProdList.Columns.Add("LeadTime");
                objProdList.Columns.Add("Safety");

                objProdList.Columns.Add("PrecioCompra");
                objProdList.Columns.Add("SobreCostos");
                objProdList.Columns.Add("PrecioVenta");
                objProdList.Columns.Add("VentaAnual");
                objProdList.Columns.Add("VentaSemestral");
                objProdList.Columns.Add("VentaTrimestral");
                objProdList.Columns.Add("VentaMensual");
                objProdList.Columns.Add("PromedioAnual");
                objProdList.Columns.Add("PromedioSemestral");
                objProdList.Columns.Add("PromedioTrimestral");
                objProdList.Columns.Add("PromedioMensual");

                foreach (Product prod in selectedproduct)
                {
                    int cuenta;
                    ProductInformation               prodinfo  = ControllerManager.Product.GetProductInformation(prod.ProductCode, "N/A", 0, 0, 0, 0, out cuenta, chbViejos.Checked)[0];
                    TransactionHistoryWeekly         tran      = ControllerManager.TransactionHistoryWeekly.GetIndividualInfo(prod.Id, Config.CurrentWeek, Config.CurrentDate.Year);
                    Grundfos.ScalaConnector.Product  prodscala = Grundfos.ScalaConnector.ControllerManager.Product.GetProductInfo(prod.ProductCode);
                    IList <TransactionHistoryWeekly> sales     = ControllerManager.TransactionHistoryWeekly.GetSalesTotal(prod, Config.CurrentWeek, Config.CurrentDate.Year);
                    IList <ProductStatisticWeekly>   fullstats = ControllerManager.ProductStatisticWeekly.GetProductFullInfo(prod.Id);

                    DataRow myRow;
                    myRow     = objProdList.NewRow();
                    myRow[0]  = prodinfo.ProductCode;
                    myRow[1]  = prodinfo.Description;
                    myRow[2]  = prodinfo.Provider;
                    myRow[3]  = prodinfo.Stock;
                    myRow[4]  = prodinfo.RepositionLevel;
                    myRow[5]  = prodinfo.RepositionPoint;
                    myRow[6]  = prodinfo.Saleaverage;
                    myRow[7]  = prodinfo.LeadTime;
                    myRow[8]  = prodinfo.Safety;
                    myRow[9]  = prodscala.PurchasePrice;
                    myRow[10] = prodscala.OverCost;
                    myRow[11] = prodscala.SalePrice;
                    myRow[12] = sales[3].Sale;
                    myRow[13] = sales[2].Sale;
                    myRow[14] = sales[1].Sale;
                    myRow[15] = sales[0].Sale;
                    myRow[16] = fullstats[4].Sale;
                    myRow[17] = fullstats[3].Sale;
                    myRow[18] = fullstats[2].Sale;
                    myRow[19] = fullstats[0].Sale;

                    objProdList.Rows.Add(myRow);
                }
                objDataSet.Tables.Add(objProdList);

                //objDataSet.Relations.Add("PO_POI", objDataSet.Tables["rptPO"].Columns["Codigo"], objDataSet.Tables["rptPOI"].Columns["CodOC"]);

                //objDataSet.WriteXmlSchema("c:/esquemaprod.xsd");
                //objDataSet.WriteXml("c:/dataset.xml");
                Session["dsListProductos"] = objDataSet;
                Response.Redirect("/product-list/report.aspx");
            }

            else
            {
                lblErrorProducto.Visible = true;
            }
        }
Example #6
0
        public bool Execute(out string errors)
        {
            errors = "";

            try
            {
                #region Check if needs to be executed

                if (Config.CurrentDate.DayOfWeek ==
                    (DayOfWeek)Convert.ToInt32(ConfigurationManager.AppSettings["ExecuteDayOfWeek"]) &&
                    DateTime.Now.Hour >= Convert.ToInt32(ConfigurationManager.AppSettings["ExecuteHour"]))
                {
                    //Review if the forecast is executing in the log
                    //If not start the process, otherwise returns true with no errors.
                    if (ControllerManager.Log.IsExecuting(Name, ExecutionStatus.Start))
                    {
                        return(true);
                    }
                    else
                    {
                        ControllerManager.Log.Add(Name, ExecutionStatus.Start, string.Empty);
                    }
                }
                else
                {
                    return(true);
                }

                #endregion



                DateTime endDate   = Config.CurrentDate;
                DateTime startDate = endDate.AddDays(-7);

                #region Provider Refresh
                IList <Grundfos.ScalaConnector.Provider> proveedoresScala = Grundfos.ScalaConnector.ControllerManager.Provider.GetProviderList();
                List <PartnerNet.Domain.Provider>        proveedores      = ControllerManager.Provider.GetFullProviderList();
                try
                {
                    foreach (Grundfos.ScalaConnector.Provider provider in proveedoresScala)
                    {
                        bool updated = false;
                        PartnerNet.Domain.Provider prov = null;
                        prov = proveedores.Find(delegate(PartnerNet.Domain.Provider record)
                        {
                            if (record.ProviderCode != provider.Id)
                            {
                                return(false);
                            }
                            return(true);
                        });

                        if (prov != null)
                        {
                            prov.Name        = provider.Name;
                            prov.CountryCode = provider.CountryCode;
                            updated          = true;
                        }

                        if (updated == false)
                        {
                            PartnerNet.Domain.Provider nuevo = new PartnerNet.Domain.Provider();
                            nuevo.Name         = provider.Name;
                            nuevo.ProviderCode = provider.Id;
                            //cambiar y resubir
                            nuevo.CountryCode = provider.CountryCode;
                            ControllerManager.Provider.SaveOrUpdate(nuevo);
                            updated = true;
                        }
                    }
                    ControllerManager.Log.Add(Name, ExecutionStatus.Running, "Provider refresh successfully");
                }
                catch (Exception ex)
                {
                    errors = ex.ToString();

                    try
                    {
                        string process = "Provider Refresh";
                        ControllerManager.Log.Add(Name, ExecutionStatus.Running, process + ": " + errors);
                        SendErrorEmail(process, errors);
                    }
                    catch
                    {
                    }

                    return(false);
                }
                #endregion

                #region Product Refresh
                IList <Grundfos.ScalaConnector.Product> productosScala = Grundfos.ScalaConnector.ControllerManager.Product.GetProductList();
                List <PartnerNet.Domain.Product>        productos      = ControllerManager.Product.GetFullProductList();
                try
                {
                    foreach (Grundfos.ScalaConnector.Product product in productosScala)
                    {
                        PartnerNet.Domain.Product producto = productos.Find(delegate(PartnerNet.Domain.Product record)
                        {
                            if (record.ProductCode != product.Id)
                            {
                                return(false);
                            }
                            return(true);
                        });

                        if (producto == null)
                        {
                            producto             = new PartnerNet.Domain.Product();
                            producto.ProductCode = product.Id;
                            producto.Safety      = 6;
                        }

                        producto.Description = product.Description;
                        producto.Group       = product.Group;
                        producto.LeadTime    = product.Detail[0].Leadtime;
                        producto.CountryCode = product.CountryCode;
                        if (producto.RepositionLevel != product.Detail[0].RepPoint)
                        {
                            producto.RepositionLevel = product.Detail[0].RepPoint;
                            //ProductRepositionLevelHistory prlh = new ProductRepositionLevelHistory();
                            //prlh.Product = producto;
                            //prlh.RepositionLevel = producto.RepositionLevel;
                            //ControllerManager.Product.GenericSave(prlh);
                        }
                        producto.RepositionPoint    = product.Detail[0].PurchaseMod;
                        producto.AlternativeProduct = product.AlternativeProduct;
                        producto.AlternativeDate    = product.AlternativeDate;
                        PartnerNet.Domain.Provider provtemp = proveedores.Find(delegate(PartnerNet.Domain.Provider record)
                        {
                            if (record.ProviderCode != product.Provider.Id)
                            {
                                return(false);
                            }
                            return(true);
                        });
                        if (provtemp != null)
                        {
                            producto.Provider = provtemp;
                        }
                        else if (provtemp == null)
                        {
                            producto.Provider = proveedores.Find(delegate(PartnerNet.Domain.Provider record)
                            {
                                if (record.ProviderCode != "999999")
                                {
                                    return(false);
                                }
                                return(true);
                            });
                        }
                        foreach (ProductDetail productDetail in product.Detail)
                        {
                            if (productDetail.RepPoint == 0)
                            {
                                producto.ScalaRep0 = true;
                            }
                        }

                        ControllerManager.Product.Save(producto);
                    }
                    ControllerManager.Log.Add(Name, ExecutionStatus.Running, "Product refresh successfully");
                }
                catch (Exception ex)
                {
                    errors = ex.ToString();

                    try
                    {
                        string process = "Product Refresh";
                        ControllerManager.Log.Add(Name, ExecutionStatus.Running, process + ": " + errors);
                        SendErrorEmail(process, errors);
                    }
                    catch
                    {
                    }

                    return(false);
                }
                #endregion

                #region Generate History

                #region Limpieza de datos procesador de esta semana (si los hubiera)

                ControllerManager.TransactionHistoryWeekly.CleanData(Config.CurrentWeek, Config.CurrentDate.Year);

                #endregion

                IList <Product> prodlist = Grundfos.ScalaConnector.ControllerManager.Product.GetProductList();
                List <PartnerNet.Domain.Product> productlist = ControllerManager.Product.GetProductListAlt();
                try
                {
                    List <Transactions>      transcomp = Grundfos.ScalaConnector.ControllerManager.Transactions.GetTransaction(startDate, endDate, 0);
                    List <Transactions>      transvent = Grundfos.ScalaConnector.ControllerManager.Transactions.GetTransaction(startDate, endDate, 1);
                    List <PurchaseOrderItem> poil      = Grundfos.ScalaConnector.ControllerManager.PurchaseOrderItem.GetWeeklyTransaction(startDate, endDate);

                    foreach (Product prod in prodlist)
                    {
                        PartnerNet.Domain.Product producto = null;
                        producto = productlist.Find(delegate(PartnerNet.Domain.Product record)
                        {
                            if (record.ProductCode != prod.Id)
                            {
                                return(false);
                            }
                            return(true);
                        });

                        if (producto != null)
                        {
                            #region Generate TransactionHistoryWeekly

                            TransactionHistoryWeekly transax = new TransactionHistoryWeekly();

                            int stock          = 0;
                            int purchases      = 0;
                            int sales          = 0;
                            int purchaseorders = 0;

                            stock = prod.StockQ;

                            Transactions subList = null;

                            subList = transcomp.Find(delegate(Transactions record)
                            {
                                if (record.Product != prod)
                                {
                                    return(false);
                                }
                                return(true);
                            });

                            if (subList != null)
                            {
                                purchases = subList.Quantity;
                            }

                            subList = transvent.Find(delegate(Transactions record)
                            {
                                if (record.Product != prod)
                                {
                                    return(false);
                                }
                                return(true);
                            });
                            if (subList != null)
                            {
                                sales = -subList.Quantity;
                            }

                            PurchaseOrderItem subList2 = null;
                            subList2 = poil.Find(delegate(PurchaseOrderItem record)
                            {
                                if (record.Product != prod)
                                {
                                    return(false);
                                }
                                return(true);
                            });

                            if (subList2 != null)
                            {
                                purchaseorders = subList2.QuantityOrdered;
                            }


                            transax.ProductID      = producto;
                            transax.Purchase       = purchases;
                            transax.Sale           = sales;
                            transax.PurchaseOrders = purchaseorders;
                            transax.Stock          = stock;
                            transax.Year           = endDate.Year;
                            transax.Week           =
                                Thread.CurrentThread.CurrentCulture.Calendar.GetWeekOfYear(endDate,
                                                                                           CalendarWeekRule.
                                                                                           FirstFourDayWeek,
                                                                                           DayOfWeek.Sunday);
                            transax.ProductCode = prod.Id;

                            ControllerManager.TransactionHistoryWeekly.Save(transax);

                            #endregion
                        }
                    }

                    ControllerManager.TransactionHistoryWeekly.Copy();

                    ControllerManager.Log.Add(Name, ExecutionStatus.Running, "Weekly history created successfully");
                }
                catch (Exception ex)
                {
                    errors = ex.ToString();

                    try
                    {
                        string process = "Weekly History";
                        ControllerManager.Log.Add(Name, ExecutionStatus.Running, process + ": " + errors);
                        SendErrorEmail(process, errors);
                    }
                    catch
                    {
                    }

                    return(false);
                }
                #endregion

                #region Generate Weekly Statitics
                try
                {
                    ControllerManager.TransactionHistoryWeekly.CalculateFullStatistic(Config.CurrentWeek,
                                                                                      Config.CurrentDate.Year);

                    ControllerManager.Log.Add(Name, ExecutionStatus.Running, "Weekly statistics created successfully");
                }
                catch (Exception ex)
                {
                    errors = ex.ToString();

                    try
                    {
                        string process = "Weekly Statistics";
                        ControllerManager.Log.Add(Name, ExecutionStatus.Running, process + ": " + errors);
                        SendErrorEmail(process, errors);
                    }
                    catch
                    {
                    }

                    return(false);
                }
                #endregion

                if (Config.CurrentDate.Day <= 7)
                {
                    #region Limpieza de datos procesador de este mes (si los hubiera)

                    ControllerManager.TransactionHistoryMonthly.CleanData(Config.CurrentDate.Month, Config.CurrentDate.Year);

                    #endregion

                    #region Generate Monthly History
                    try
                    {
                        DateTime endDateM   = GetLastDayOfMonth(Config.CurrentDate.AddMonths(-1));
                        DateTime startDateM = GetFirstDayOfMonth(Config.CurrentDate.AddMonths(-1));

                        List <Transactions>      transcompm = Grundfos.ScalaConnector.ControllerManager.Transactions.GetTransaction(startDateM, endDateM, 0);
                        List <Transactions>      transventm = Grundfos.ScalaConnector.ControllerManager.Transactions.GetTransaction(startDateM, endDateM, 1);
                        List <PurchaseOrderItem> poilm      = Grundfos.ScalaConnector.ControllerManager.PurchaseOrderItem.GetWeeklyTransaction(startDateM, endDateM);

                        foreach (Product prod in prodlist)
                        {
                            PartnerNet.Domain.Product producto = null;
                            producto = productlist.Find(delegate(PartnerNet.Domain.Product record)
                            {
                                if (record.ProductCode != prod.Id)
                                {
                                    return(false);
                                }
                                return(true);
                            });

                            if (producto != null)
                            {
                                #region Generate TransactionHistoryMonthly

                                TransactionHistoryMonthly transax = new TransactionHistoryMonthly();

                                int stock          = 0;
                                int purchases      = 0;
                                int sales          = 0;
                                int purchaseorders = 0;

                                stock = prod.StockQ;

                                Transactions subList = null;

                                subList = transcompm.Find(delegate(Transactions record)
                                {
                                    if (record.Product != prod)
                                    {
                                        return(false);
                                    }
                                    return(true);
                                });

                                if (subList != null)
                                {
                                    purchases = subList.Quantity;
                                }

                                subList = transventm.Find(delegate(Transactions record)
                                {
                                    if (record.Product != prod)
                                    {
                                        return(false);
                                    }
                                    return(true);
                                });
                                if (subList != null)
                                {
                                    sales = -subList.Quantity;
                                }

                                PurchaseOrderItem subList2 = null;
                                subList2 = poilm.Find(delegate(PurchaseOrderItem record)
                                {
                                    if (record.Product != prod)
                                    {
                                        return(false);
                                    }
                                    return(true);
                                });

                                if (subList2 != null)
                                {
                                    purchaseorders = subList2.QuantityOrdered;
                                }


                                transax.ProductID      = producto;
                                transax.Purchase       = purchases;
                                transax.Sale           = sales;
                                transax.PurchaseOrders = purchaseorders;
                                transax.Stock          = stock;
                                transax.Year           = endDateM.Year;
                                transax.Month          =
                                    Thread.CurrentThread.CurrentCulture.Calendar.GetMonth(endDateM);
                                transax.ProductCode = prod.Id;

                                ControllerManager.TransactionHistoryMonthly.Save(transax);

                                #endregion
                            }
                        }

                        ControllerManager.Log.Add(Name, ExecutionStatus.Running, "Montly history created successfully");
                    }
                    catch (Exception ex)
                    {
                        errors = ex.ToString();

                        try
                        {
                            string process = "Monthly History";
                            ControllerManager.Log.Add(Name, ExecutionStatus.Running, process + ": " + errors);
                            SendErrorEmail(process, errors);
                        }
                        catch
                        {
                        }

                        return(false);
                    }

                    #endregion

                    #region Generate Monthly Statitics

                    //try
                    //{
                    //    ControllerManager.TransactionHistoryMonthly.CalculateFullStatistic(Config.CurrentDate.Month - 1, Config.CurrentDate.Year);

                    //    ControllerManager.Log.Add(Name, ExecutionStatus.Running, "Monthly statistics created successfully");
                    //}
                    //catch (Exception ex)
                    //{
                    //    errors = ex.ToString();

                    //    try
                    //    {
                    //        string process = "Monthly Statistics";
                    //        ControllerManager.Log.Add(Name, ExecutionStatus.Running, process + ": " + errors);
                    //        SendErrorEmail(process, errors);
                    //    }
                    //    catch
                    //    {
                    //    }

                    //    return false;
                    //}

                    #endregion
                }


                #region Generate Forecast

                try
                {
                    IList <PartnerNet.Domain.Product> tempprodlist = new List <PartnerNet.Domain.Product>();
                    ControllerManager.Forecast.CalculateFullForecast(Config.CurrentWeek, Config.CurrentDate.Year, tempprodlist, true);

                    ControllerManager.Log.Add(Name, ExecutionStatus.Running, "Forecast created successfully");
                }
                catch (Exception ex)
                {
                    errors = ex.ToString();

                    try
                    {
                        string process = "Forecast";
                        ControllerManager.Log.Add(Name, ExecutionStatus.Running, process + ": " + errors);
                        SendErrorEmail(process, errors);
                    }
                    catch
                    {
                    }

                    return(false);
                }
                #endregion

                #region Generate Purchase Orders

                #region Limpieza de datos procesador de esta semana (si los hubiera)

                ControllerManager.PurchaseOrder.CleanData(Config.CurrentDate);

                #endregion

                try
                {
                    ControllerManager.PurchaseOrder.GenerateFullPO(Config.CurrentWeek, Config.CurrentDate.Year, PurchaseOrderType.Forecast);

                    ControllerManager.Log.Add(Name, ExecutionStatus.Running, "Purchase orders created successfully");
                }
                catch (Exception ex)
                {
                    errors = ex.ToString();

                    try
                    {
                        string process = "Purchase Orders";
                        ControllerManager.Log.Add(Name, ExecutionStatus.Running, process + ": " + errors);
                        SendErrorEmail(process, errors);
                    }
                    catch
                    {
                    }

                    return(false);
                }
                #endregion

                #region Proceso de Forecast a Productos Faltantes
                //List<string> prodlistfalt = PartnerNet.Business.ControllerManager.Product.GetLeftProductList();
                //List<PartnerNet.Domain.Product> prodlisttemp = PartnerNet.Business.ControllerManager.Product.GetFullProductList();
                //List<string> leftproducts = new List<string>();

                //foreach (PartnerNet.Domain.Product product in prodlisttemp)
                //{
                //    string temp = prodlistfalt.Find(delegate(string record)
                //                                                          {
                //                                                              if (record == product.ProductCode)
                //                                                              {
                //                                                                  return true;
                //                                                              }
                //                                                              return false;
                //                                                          });

                //    if (temp == null)
                //    {
                //        leftproducts.Add(product.ProductCode);
                //    }
                //}



                //foreach (string product in leftproducts)
                //{
                //    PartnerNet.Domain.Product producto = PartnerNet.Business.ControllerManager.Product.GetProductInfo(product);
                //    PartnerNet.Business.ControllerManager.Forecast.CalculateIndividualForecast(Config.CurrentWeek, Config.CurrentDate.Year, producto);
                //}
                #endregion

                ControllerManager.Log.Add(Name, ExecutionStatus.Finished, "Process finished successfully");
            }
            catch (Exception ex)
            {
                errors = ex.ToString();

                try
                {
                    string process = "Proceso de Forecast";
                    ControllerManager.Log.Add(Name, ExecutionStatus.Running, process + ": " + errors);
                    SendErrorEmail(process, errors);
                }
                catch
                {
                }

                return(false);
            }

            return(true);
        }
Example #7
0
        public void CalculateFullForecast(int week, int year, IList <Product> productlist, bool clean)
        {
            int prodcont = 0;

            if (productlist.Count < 1)
            {
                productlist = ControllerManager.Product.GetProductList();
            }

            List <TransactionHistoryWeekly> fullhistory    = ControllerManager.TransactionHistoryWeekly.GetInfo(week, year, 20);
            List <ProductStatisticWeekly>   fullstatistics = ControllerManager.ProductStatisticWeekly.GetStatistics();
            List <PurchaseOrderItem>        fullpoil       = Grundfos.ScalaConnector.ControllerManager.PurchaseOrderItem.GetFullArrivalPO(Config.CurrentDate);

            if (clean)
            {
                IQuery q = NHibernateSession.GetNamedQuery("sp_forecast_clean");
                q.SetInt32("Week", week);
                q.SetInt32("Year", year);
                q.UniqueResult();
            }
            foreach (Product p in productlist)
            {
                prodcont++;
                List <TransactionHistoryWeekly> history = fullhistory.FindAll(delegate(TransactionHistoryWeekly record)
                {
                    if (record.ProductID != p)
                    {
                        return(false);
                    }
                    return(true);
                });

                ProductStatisticWeekly statistics = fullstatistics.Find(delegate(ProductStatisticWeekly record)
                {
                    if (record.Product != p)
                    {
                        return(false);
                    }
                    return(true);
                });

                List <PurchaseOrderItem> poil = fullpoil.FindAll(delegate(PurchaseOrderItem record)
                {
                    if (record.Product.Id == p.ProductCode)
                    {
                        return(true);
                    }
                    return(false);
                });

                if (history.Count < 20)
                {
                    List <TransactionHistoryWeekly> temphistory = new List <TransactionHistoryWeekly>();

                    int initialweek = 0;
                    int initialyear = 0;
                    if (week < 20)
                    {
                        initialweek = week - 20 + 54;
                        initialyear = year - 1;
                    }
                    else
                    {
                        initialweek = week - 20;
                    }
                    for (int cont = 1; cont <= 20; cont++)
                    {
                        TransactionHistoryWeekly tempTHW = history.Find(delegate(TransactionHistoryWeekly record)
                        {
                            if ((record.Week == initialweek) &&
                                (record.Year == initialyear))
                            {
                                return(true);
                            }
                            return(false);
                        });
                        if (tempTHW == null)
                        {
                            tempTHW                = new TransactionHistoryWeekly(0, p);
                            tempTHW.Week           = initialweek;
                            tempTHW.Year           = initialyear;
                            tempTHW.Stock          = 0;
                            tempTHW.PurchaseOrders = 0;
                            tempTHW.Purchase       = 0;
                            tempTHW.Sale           = 0;
                        }


                        temphistory.Add(tempTHW);

                        if (initialweek < 53)
                        {
                            initialweek++;
                        }
                        else
                        {
                            initialweek = 1;
                            initialyear++;
                        }
                    }
                    CalculateForecast(p, week, year, temphistory, statistics, poil);
                }
                else
                {
                    CalculateForecast(p, week, year, history, statistics, poil);
                }

                if (Convert.ToDouble(prodcont) % 1000 == 0)
                {
                    NHibernateSession.Flush();
                    ControllerManager.Log.Add("Forecast Processor", ExecutionStatus.Running, "Forecast: " + prodcont + " productos procesados");
                }
            }

            NHibernateSession.Flush();
            ControllerManager.Log.Add("Forecast Processor", ExecutionStatus.Running, "Forecast: " + prodcont + " productos procesados");
        }
Example #8
0
        public void CalculateForecast(Product prod, int week, int year, List <TransactionHistoryWeekly> history,
                                      ProductStatisticWeekly statistics, List <PurchaseOrderItem> poil)
        {
            //VARIABLES
            int cont        = 0;
            int cont2       = 0;
            int cont3       = 0;
            int todaysale   = 0;
            int processedOn = 0;

            //CREACION DE COLECCION DE OBJETOS
            IList <Forecast> lista = new List <Forecast>();

            //INICIO DE CARGA DE TRANSACCIONES PASADAS (10)
            for (cont3 = 19; cont3 >= 0; cont3--)
            {
                Forecast past = new Forecast();
                past.Product = prod;
                if (week - cont3 > 0)
                {
                    past.Week = week - cont3;
                    past.Year = year;
                }
                else
                {
                    past.Week = 53 + (week - cont3);
                    past.Year = year - 1;
                }
                past.Stock             = 0;
                past.Purchase          = 0;
                past.Sale              = 0;
                past.FinalStock        = 0;
                past.Safety            = 0;
                past.SafetyCoEf        = 0;
                past.QuantitySuggested = 0;
                past.ProcessedOn       = 0;

                TransactionHistoryWeekly THWpast = history.Find(delegate(TransactionHistoryWeekly record)
                {
                    if ((record.Year == past.Year) &&
                        (record.Week == past.Week))
                    {
                        return(true);
                    }
                    return(false);
                });
                if (THWpast != null)
                {
                    past.FinalStock = THWpast.Stock;
                    past.Purchase   = THWpast.Purchase;
                    past.Sale       = THWpast.Sale;
                }

                past.Stock = past.FinalStock + past.Sale - past.Purchase;

                lista.Add(past);
            }

            //PROCESO DE CALCULO DEL FUTURO (18)
            int saleaverage = statistics.Sale;
            int safety      = statistics.Sale * prod.Safety;

            for (cont = 1; cont <= 53; cont++)
            {
                int stock             = 0;
                int purchase          = 0;
                int finalStock        = 0;
                int quantitySuggested = 0;

                //if (cont <= prod.LeadTime)
                {
                    //int tempweek = week;
                    //int tempyear = year;
                    //if (53 - prod.LeadTime + cont + week < 54)
                    //{
                    //    tempweek = 53 - prod.LeadTime + cont + week;
                    //    tempyear = year - 1;
                    //}
                    //else if (prod.LeadTime - cont > 0)
                    //{
                    //    tempweek = prod.LeadTime - cont;
                    //}
                    //TransactionHistoryWeekly THWfut = history.Find(delegate(TransactionHistoryWeekly record)
                    //                                                   {
                    //                                                       if ((record.Week == tempweek) &&
                    //                                                           (record.Year == tempyear))
                    //                                                       {
                    //                                                           return true;
                    //                                                       }
                    //                                                       return false;
                    //                                                   });
                    int tempdays = 0;
                    if (cont == 1)
                    {
                        tempdays = 1;
                    }
                    else
                    {
                        tempdays = 1 + (7 * (cont - 1));
                    }
                    DateTime startDate = Config.CurrentDate.AddDays(tempdays);
                    DateTime endDate   = startDate.AddDays(7);

                    List <Grundfos.ScalaConnector.PurchaseOrderItem> poilist = poil.FindAll(delegate(Grundfos.ScalaConnector.PurchaseOrderItem record)
                    {
                        if ((record.ArrivalDate >= startDate) && (record.ArrivalDate <= endDate))
                        {
                            return(true);
                        }
                        return(false);
                    });
                    if (poilist.Count == 0)
                    {
                        purchase = 0;
                    }
                    else
                    {
                        foreach (PurchaseOrderItem item in poilist)
                        {
                            purchase = purchase + item.QuantityOrdered;
                        }
                    }
                }

                stock      = lista[18 + cont].FinalStock;
                finalStock = stock + purchase - saleaverage;

                Forecast info = new Forecast();

                info.Product = prod;
                if (week + cont <= 53)
                {
                    info.Week = week + cont;
                    info.Year = year;
                }
                else
                {
                    info.Week = week + cont - 53;
                    info.Year = year + 1;
                }

                if (cont > prod.LeadTime && finalStock < safety)
                {
                    double modulequantity    = 1;
                    int    purchasesuggested = 0;
                    if (prod.RepositionPoint > 0)
                    {
                        modulequantity    = (Convert.ToDouble(safety) - Convert.ToDouble(finalStock)) / Convert.ToDouble(prod.RepositionPoint);
                        purchasesuggested = Convert.ToInt32(Math.Ceiling(modulequantity));
                    }

                    if (prod.LeadTime > 0)
                    {
                        lista[cont - prod.LeadTime + 19].QuantitySuggested = purchasesuggested * prod.RepositionPoint;
                    }
                    else
                    {
                        lista[cont - prod.LeadTime + 18].QuantitySuggested = purchasesuggested * prod.RepositionPoint;
                    }
                    purchase   = purchasesuggested * prod.RepositionPoint + purchase;
                    finalStock = stock + purchase - saleaverage;
                }

                info.Stock             = stock;
                info.Purchase          = purchase;
                info.Sale              = saleaverage;
                info.FinalStock        = finalStock;
                info.Safety            = safety;
                info.SafetyCoEf        = prod.Safety;
                info.QuantitySuggested = quantitySuggested;
                info.ProcessedOn       = processedOn;

                lista.Add(info);
            }
            for (cont = 20; cont < 73; cont++)
            {
                Forecast forecast = lista[cont];
                Save(forecast);
            }
        }
Example #9
0
        protected void Button5_Click(object sender, EventArgs e)
        {
            //Seccion de Carga de datos historicos
            //DateTime endDate = Config.CurrentDate;
            DateTime endDate   = Calendar1.SelectedDate;
            DateTime startDate = endDate.AddDays(-7);

            IList <Grundfos.ScalaConnector.Product> prodlist =
                Grundfos.ScalaConnector.ControllerManager.Product.GetProductList(
                    ControllerManager.Product.GetProductList());
            IList <Grundfos.ScalaConnector.Transactions> trans =
                Grundfos.ScalaConnector.ControllerManager.Transactions.GetTransaction(startDate, endDate);
            IList <Grundfos.ScalaConnector.PurchaseOrderItem> poil =
                Grundfos.ScalaConnector.ControllerManager.PurchaseOrderItem.GetWeeklyTransaction(startDate, endDate);


            foreach (Grundfos.ScalaConnector.Product prod in prodlist)
            {
                if (ControllerManager.Product.GetProductInfo(prod.Id) != null)
                {
                    PartnerNet.Domain.TransactionHistoryWeekly transax = new TransactionHistoryWeekly();

                    int stock          = 0;
                    int purchases      = 0;
                    int sales          = 0;
                    int purchaseorders = 0;

                    stock = prod.StockQ;

                    foreach (Grundfos.ScalaConnector.Transactions transaction in trans)
                    {
                        if (transaction.Product == prod)
                        {
                            if (transaction.Quantity > 0)
                            {
                                purchases = purchases + transaction.Quantity;
                            }
                            else if (transaction.Quantity < 0)
                            {
                                sales = sales + (-transaction.Quantity);
                            }
                        }
                    }

                    foreach (Grundfos.ScalaConnector.PurchaseOrderItem poi in poil)
                    {
                        if (poi.Product == prod)
                        {
                            purchaseorders = poi.Quantity;
                        }
                    }

                    transax.ProductID      = ControllerManager.Product.GetProductInfo(prod.Id);
                    transax.Purchase       = purchases;
                    transax.Sale           = sales;
                    transax.PurchaseOrders = purchaseorders;
                    transax.Stock          = stock;
                    transax.Year           = endDate.Year;
                    transax.Week           = Thread.CurrentThread.CurrentCulture.Calendar.GetWeekOfYear(endDate, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday);
                    //borrar esta propiedad!!!
                    transax.ProductCode = prod.Id;

                    ControllerManager.TransactionHistoryWeekly.Save(transax);
                }
            }
        }