コード例 #1
0
        //
        // GET: /Planejamento/Create
        public ActionResult Create()
        {
            Planejamento planejamento = new Planejamento();

            ViewBag.CodigoItem = new SelectList(db.Material, "Id", "Codigo");
            ViewBag.Status = new SelectList(db.StatusPlanejamento, "Id", "Nome", db.StatusPlanejamento.Single(s => s.Sigla == "P").Id);

            planejamento.DataInicio = 0;

            return View(planejamento);
        }
コード例 #2
0
        public ActionResult Create(Planejamento planejamento)
        {
            if (ModelState.IsValid)
            {
                db.Planejamento.AddObject(planejamento);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CodigoItem = new SelectList(db.Material, "Id", "Codigo", planejamento.CodigoItem);
            ViewBag.Status = new SelectList(db.StatusPlanejamento, "Id", "Nome", planejamento.Status);
            return View(planejamento);
        }
コード例 #3
0
        public ActionResult Index(int? Material, int Quantidade, int Data)
        {
            if (!Material.HasValue)
            {
                return null;
            }

            Material material = db.Material.Single(m => m.Id == Material);

            for (int Ordem = 0; Ordem <= db.DependenciaMaterial.Max(m => m.Ordem); Ordem++)
            {
                // se for o Material "raiz", o sistema só deve gerar o planejamento de liberação

                if (Ordem == 0)
                {
                    Estoque estoque = db.Estoque.Single(e => e.IdMaterial == material.Id);

                    int QtdeSobra = estoque.Quantidade - Quantidade;
                    if (QtdeSobra < material.EstoqueMinimo)
                    {
                        int TotalFalta = material.EstoqueMinimo - QtdeSobra;

                        int Multiplicador = int.Parse(Math.Ceiling((double)TotalFalta / (double)material.LoteReposicao).ToString());

                        Planejamento planejamento = new Planejamento()
                        {
                            CodigoOrdem = material.Codigo + "_" + (Data - material.LeadTime).ToString(),
                            CodigoItem = material.Id,
                            DataPrevistaTermino = Data,
                            DataInicio = Data - material.LeadTime,
                            QuantidadeOrdem = material.LoteReposicao * Multiplicador,
                            Status = db.StatusPlanejamento.Single(s => s.Sigla == "P").Id
                        };

                        Movimentacao movimentacao = new Movimentacao()
                        {
                            IdItem = material.Id,
                            IdTipoTransacao = db.TipoTransacao.Single(t => t.Sigla == "SA").Id,
                            QuantidadeMovimentada = Quantidade,
                            Data = Data
                        };

                        db.Planejamento.AddObject(planejamento);
                        db.Movimentacao.AddObject(movimentacao);

                        db.SaveChanges();
                    }
                }
                else
                {
                    List<DependenciaMaterial> listDependencia =
                        db.DependenciaMaterial.Where(d => d.Ordem == Ordem).ToList();

                    foreach (DependenciaMaterial dependencia in listDependencia)
                    {
                        material = db.Material.Single(m => m.Id == dependencia.IdMaterialFilho);
                        Estoque estoque = db.Estoque.Single(e => e.IdMaterial == material.Id);

                        // para cada material filho, pegar os planejamentos do material pai

                        List<Planejamento> listPlanejamento =
                            db.Planejamento.Where(p => p.Material.Id == dependencia.IdMaterialPai).ToList();

                        foreach (Planejamento planejamentoPai in listPlanejamento)
                        {
                            int NecessidadeBruta = planejamentoPai.QuantidadeOrdem * Convert.ToInt32(dependencia.Quantidade);

                            int QtdeSobra = estoque.Quantidade - NecessidadeBruta;
                            if (QtdeSobra < material.EstoqueMinimo)
                            {
                                int TotalFalta = material.EstoqueMinimo - QtdeSobra;

                                int Multiplicador = int.Parse(Math.Ceiling((double)TotalFalta / (double)material.LoteReposicao).ToString());

                                Planejamento planejamentoFilho = new Planejamento()
                                {
                                    CodigoOrdem = material.Codigo + "_" + (planejamentoPai.DataInicio - material.LeadTime).ToString(),
                                    CodigoItem = material.Id,
                                    DataPrevistaTermino = planejamentoPai.DataInicio,
                                    DataInicio = planejamentoPai.DataInicio - material.LeadTime,
                                    QuantidadeOrdem = material.LoteReposicao * Multiplicador,
                                    Status = db.StatusPlanejamento.Single(s => s.Sigla == "P").Id
                                };

                                Movimentacao movimentacao = new Movimentacao()
                                {
                                    IdItem = material.Id,
                                    IdTipoTransacao = db.TipoTransacao.Single(t => t.Sigla == "SA").Id,
                                    QuantidadeMovimentada = NecessidadeBruta,
                                    Data = planejamentoFilho.DataPrevistaTermino.Value
                                };

                                db.Planejamento.AddObject(planejamentoFilho);
                                db.SaveChanges();

                                db.Movimentacao.AddObject(movimentacao);
                                db.SaveChanges();
                            }
                        }
                    }
                }
            }

            /*
            Planejamento planejamentoAnterior = new Planejamento()
            {
                QuantidadeOrdem = Quantidade,
                DataInicio = Data
            };

            int Multiplicador = 1;

            if (Ordem > 0)
            {
                List<DependenciaMaterial> dependencia =
                    db.DependenciaMaterial.Where(d => d.IdMaterialFilho == material.Id).ToList<DependenciaMaterial>();
            }

            Estoque estoque = db.Estoque.Single(e => e.IdMaterial == material.Id);

            Planejamento planejamentoNovo = new Planejamento()
            {
                QuantidadeOrdem = planejamentoAnterior.QuantidadeOrdem,
                DataPrevistaTermino = planejamentoAnterior.DataInicio,
                DataInicio = planejamentoAnterior.DataInicio - material.LeadTime,
                CodigoItem = material.Id
            };
            */

            var materiais = from M in db.Material
                            join D in db.DependenciaMaterial on M.Id equals D.IdMaterialFilho
                            where D.Ordem == 0
                            orderby M.Codigo
                            select M;

            ViewBag.Material = new SelectList(materiais, "Id", "Codigo");

            ViewBag.Mensagem = "Processamento efetuado com sucesso!";

            return View();
        }
コード例 #4
0
 public ActionResult Edit(Planejamento planejamento)
 {
     if (ModelState.IsValid)
     {
         db.Planejamento.Attach(planejamento);
         db.ObjectStateManager.ChangeObjectState(planejamento, EntityState.Modified);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.CodigoItem = new SelectList(db.Material, "Id", "Codigo", planejamento.CodigoItem);
     ViewBag.Status = new SelectList(db.StatusPlanejamento, "Id", "Nome", planejamento.Status);
     return View(planejamento);
 }
コード例 #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Planejamento EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPlanejamento(Planejamento planejamento)
 {
     base.AddObject("Planejamento", planejamento);
 }
コード例 #6
0
 /// <summary>
 /// Create a new Planejamento object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="codigoOrdem">Initial value of the CodigoOrdem property.</param>
 /// <param name="quantidadeOrdem">Initial value of the QuantidadeOrdem property.</param>
 /// <param name="dataInicio">Initial value of the DataInicio property.</param>
 /// <param name="codigoItem">Initial value of the CodigoItem property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 public static Planejamento CreatePlanejamento(global::System.Int32 id, global::System.String codigoOrdem, global::System.Int32 quantidadeOrdem, global::System.Int32 dataInicio, global::System.Int32 codigoItem, global::System.Int32 status)
 {
     Planejamento planejamento = new Planejamento();
     planejamento.Id = id;
     planejamento.CodigoOrdem = codigoOrdem;
     planejamento.QuantidadeOrdem = quantidadeOrdem;
     planejamento.DataInicio = dataInicio;
     planejamento.CodigoItem = codigoItem;
     planejamento.Status = status;
     return planejamento;
 }