Пример #1
0
        //Càlculo del MRP con las semanas o días definidos
        private async void Calcular()
        {
            foreach (var productoA in ProductoPrincipal.Productos)
            {
                if (productoA.Cantidad == null)
                {
                    productoA.Cantidad = 1.ToString();
                }

                if (productoA.InventarioInicial == null || string.IsNullOrEmpty(productoA.InventarioInicial))
                {
                    productoA.InventarioInicial = 0.ToString();
                }

                else if (ProductoPrincipal.Productos[0].Semanas.All(x => x.ReqBruto == null))
                {
                    await dialogService.ShowMessage("Error", "Al menos un campo con requerimiento bruto debe contener un valor mayor a cero"
                                                    );

                    return;
                }
                else
                {
                    foreach (var list in productoA.Semanas.Where(x => x.ReqBruto == null).ToList())
                    {
                        list.ReqBruto = 0.ToString();
                    }
                    IsVisiblePropiedad = false;
                }
                var difDias = 0;
                difDias = DateSelected.DayOfYear - DateTime.Today.DayOfYear;
                for (int i = 0; i < int.Parse(CantSemanas) + difDias; i++)
                {
                    //calculo primer dia

                    if (productoA.Dependencia != "0")
                    {
                        //Busca el producto con el mismo nombre que la dependencia
                        var libOrden = ProductoPrincipal.Productos.Find(x => x.Nombres == productoA.Dependencia);
                        productoA.Semanas[i].ReqBruto = libOrden.Semanas[i].LibOrden;
                    }
                    if (string.IsNullOrEmpty(productoA.Semanas[i].ReqBruto))
                    {
                        productoA.Semanas[i].ReqBruto = 0.ToString();
                    }
                    productoA.Semanas[i].ReqBruto          = (int.Parse(productoA.Semanas[i].ReqBruto) * int.Parse(productoA.Cantidad)).ToString();
                    productoA.Semanas[i].InventarioInicial = productoA.InventarioInicial;
                    productoA.Semanas[i].ReqNeto           = (int.Parse(productoA.Semanas[i].ReqBruto) - int.Parse(productoA.Semanas[i].InventarioInicial)).ToString();
                    if (int.Parse(productoA.Semanas[i].ReqNeto) <= 0)
                    {
                        productoA.Semanas[i].ReqNeto = 0.ToString();
                    }
                    productoA.Semanas[i].InvFinal = (int.Parse(productoA.Semanas[i].InventarioInicial) - int.Parse(productoA.Semanas[i].ReqBruto)).ToString();


                    if (int.Parse(productoA.Semanas[i].InvFinal) < 0)
                    {
                        //Index para ubicar en la lista el objeto guardado donde se tiene que hacer el pedido

                        Index = i - int.Parse(productoA.TiempoFabricacion);

                        //liberación de la orden
                        productoA.Semanas[Index].LibOrden      = productoA.Semanas[i].ReqNeto;
                        productoA.Semanas[Index].IsVisibleDate = true;
                        if (SemanasDias == false)
                        {
                            //Calculo de la fecha donde se debe realizar el pedido
                            productoA.Semanas[Index].DateSelectedLibOrden = DateSelected.Date.AddDays(Index).ToString().Remove(10);
                        }
                        else
                        {
                            productoA.Semanas[Index].DateSelectedLibOrden = DateSelected.AddDays(Index * 7).ToString().Remove(10);
                        }
                        productoA.Semanas[i].InvFinal = (int.Parse(productoA.Semanas[i].InventarioInicial) + int.Parse(productoA.Semanas[Index].LibOrden) - int.Parse(productoA.Semanas[i].ReqBruto)).ToString();
                    }



                    ProductoPrincipal.Calculo = true;
                }
            }
            foreach (var productoA in ProductoPrincipal.Productos)
            {
                dataService.Delete(productoA);
                dataService.Insert(productoA, true);
            }

            dataService.Update(ProductoPrincipal, true);
            SemanasCollection = new ObservableCollection <SemanasA>(ProductoPrincipal.Productos[0].Semanas);
            IsEnabled         = false;
            VisibleReCalcular = true;
        }
Пример #2
0
        public IList <AlertEntity> GetTable2(params String[] s)
        {
            DateSelected = DateSelected.AddDays(1).AddHours(-1);
            IAsyncResult ar1 = d1.BeginInvoke(null, null);
            IAsyncResult ar2 = d2.BeginInvoke(null, null);
            IAsyncResult ar3 = d3.BeginInvoke(null, null);

            while (!ar1.IsCompleted && !ar2.IsCompleted && !ar3.IsCompleted)
            {
                Thread.Sleep(50);                                                              //wait
            }
            IList <AlertTempEntity> l1 = d1.EndInvoke(ar1);
            IList <AlertTempEntity> l2 = d2.EndInvoke(ar2);
            IList <AlertTempEntity> l3 = d3.EndInvoke(ar3);
            IList <AlertTempEntity> l4 = new List <AlertTempEntity>();



            foreach (AlertTempEntity AmntRes in l3)
            {
                int AmtResCi = l2.Where(p => p.rsTime <= AmntRes.rsTime &&
                                        p.rentLoc == AmntRes.rentLoc && p.crGrp == AmntRes.crGrp).Sum(p => p.Amnt);
                int AmntFea = l1.Where(p => p.rsTime <= AmntRes.rsTime &&
                                       p.rentLoc == AmntRes.rentLoc && p.crGrp == AmntRes.crGrp).Sum(p => p.Amnt);

                if ((AmntFea - AmntRes.Amnt + AmtResCi) < 0)
                {
                    l4.Add(new AlertTempEntity
                    {
                        rsTime  = AmntRes.rsTime,
                        crGrp   = AmntRes.crGrp,
                        rentLoc = AmntRes.rentLoc,
                        Amnt    = AmntFea + AmtResCi - AmntRes.Amnt
                    });
                }
            }
            l4 = l4.OrderBy(d => d.Amnt).ThenBy(d => d.rentLoc).ThenBy(d => d.crGrp).ToList();
            AlertEntity[] ax = _alertsRetQ.GetQueryable(l4).ToArray();

            var lx = new List <AlertEntity>();

            String[] a1 = ax.Where(p => !String.IsNullOrEmpty(p.NextHour)).Select(p => p.NextHour).ToArray();
            String[] a2 = ax.Where(p => !String.IsNullOrEmpty(p.Follow4Hours)).Select(p => p.Follow4Hours).ToArray();
            String[] a3 = ax.Where(p => !String.IsNullOrEmpty(p.RestOfDay)).Select(p => p.RestOfDay).ToArray();
            String[] a4 = ax.Where(p => !String.IsNullOrEmpty(p.Custom)).Select(p => p.Custom).ToArray();

            Boolean b = true;

            Int32[] i = { 0, 0, 0, 0 };
            while (b)
            {
                string s1 = String.Empty, s2 = String.Empty, s3 = String.Empty, s4 = string.Empty;
                b = false;
                if (i[0] < a1.Length)
                {
                    s1 = a1[i[0]++];
                    b  = true;
                }
                if (i[1] < a2.Length)
                {
                    s2 = a2[i[1]++];
                    b  = true;
                }
                if (i[2] < a3.Length)
                {
                    s3 = a3[i[2]++];
                    b  = true;
                }
                if (i[3] < a4.Length)
                {
                    s4 = a4[i[3]++];
                    b  = true;
                }

                if (b)
                {
                    lx.Add(new AlertEntity
                    {
                        NextHour     = s1,
                        Follow4Hours = s2,
                        RestOfDay    = s3,
                        Custom       = s4,
                    });
                }
            }
            return(lx);
        }