Exemple #1
0
        public Document ConfirmCountingTaskDocument(Document countTask, IList <CountTaskBalance> taskList, string user)
        {
            Bin NoCountBin = null;

            try { NoCountBin = Factory.DaoBin().Select(new Bin {
                    BinCode = DefaultBin.NOCOUNT, Location = countTask.Location
                }).First(); }
            catch
            {
                NoCountBin = Factory.DaoBin().Save(new Bin
                {
                    Location = countTask.Location,
                    BinCode  = DefaultBin.NOCOUNT,
                    Status   = new Status {
                        StatusID = EntityStatus.Active
                    },
                    Rank         = 0,
                    CreatedBy    = WmsSetupValues.SystemUser,
                    CreationDate = DateTime.Now,
                    IsArea       = true,
                    IsFromErp    = false,
                    LevelCode    = ""
                });
            }

            /* Recibe el balance de conteo y ejecuta los ajuste necesarios
             *
             * LABELS
             * 1. Envia los labels Printed que NO fueron reportados a NOCOUNT (label != null && conuted = 0)
             * 2. Los Labels encontrados son ajustados si hay diferencia  (label != null && Difference != 0)
             *  2a. A los labels encontrados se les ajusta el BIN y el status
             *
             */

            Status posted = Factory.DaoStatus().Select(new Status {
                StatusID = DocStatus.Posted
            }).First();
            Status active = Factory.DaoStatus().Select(new Status {
                StatusID = EntityStatus.Active
            }).First();
            Status inActive = Factory.DaoStatus().Select(new Status {
                StatusID = EntityStatus.Inactive
            }).First();


            // CAA [2010/07/13]  Se activan los bines usados
            if (countTask.Notes == "0")
            {
                IList <BinByTask> binList = Factory.DaoBinByTask().Select(new BinByTask {
                    TaskDocument = countTask
                });
                foreach (BinByTask bin in binList)
                {
                    try
                    {
                        bin.Bin.Status  = active;
                        bin.Bin.Comment = "";
                        Factory.DaoBin().Update(bin.Bin);
                    }
                    catch { }
                }
            }
            else if (countTask.Notes == "1")
            {
                IList <BinByTaskExecution> binListE = Factory.DaoBinByTaskExecution().Select(
                    new BinByTaskExecution {
                    BinTask = new BinByTask {
                        TaskDocument = countTask
                    }
                });

                foreach (BinByTaskExecution bin in binListE)
                {
                    try
                    {
                        bin.Bin.Status  = active;
                        bin.Bin.Comment = "";
                        Factory.DaoBin().Update(bin.Bin);
                    }
                    catch { }
                }
            }


            IList <Document> negativeDocs = new List <Document>();
            DocumentLine     addLine;
            Document         postiveAdj  = null;
            Document         negativeAdj = null;
            int positiveLine             = 1;

            //Ajustes Positivos en un solo documento
            if (taskList.Any(f => f.Difference > 0))
            {
                //Crear Ajustes de inventario positivos en un solo ajuste.
                postiveAdj = new Document
                {
                    DocType = new DocumentType {
                        DocTypeID = SDocType.InventoryAdjustment
                    },
                    CreatedBy    = user,
                    Location     = countTask.Location,
                    Company      = countTask.Company,
                    IsFromErp    = false,
                    CrossDocking = false,
                    Comment      = "CountTask Posting (Postitive Adj) " + countTask.DocNumber + ", " + user,
                    Date1        = DateTime.Now,
                    CustPONumber = countTask.DocNumber,
                    Notes        = WmsSetupValues.Counting_Bach
                };

                postiveAdj = DocMngr.CreateNewDocument(postiveAdj, false);
            }


            //Casetype
            //3. Label Contado (esperado y no Esperado)
            //4. Label Esperado no Contado Se meuve a No Count


            List <CountTaskBalance> labelsTotal, productTotal;

            try
            {
                try { labelsTotal = taskList.Where(f => f.Label != null && f.Label.LabelID > 0).ToList(); }
                catch { labelsTotal = new List <CountTaskBalance>(); }

                //LABELS
                foreach (CountTaskBalance r in labelsTotal.Where(f => f.CaseType == 4 || f.CaseType == 5 || f.CaseType == 6))
                {
                    //Label Counted - Expected
                    if ((r.CaseType == 4 || r.CaseType == 5) && r.Mark == true)
                    {
                        UpdateLabelData(r.Label, r.Bin, countTask.DocNumber, active, user);
                    }

                    //Label no counted expected
                    if (r.CaseType == 6 && r.Mark == true)
                    {
                        UpdateLabelData(r.Label, NoCountBin, countTask.DocNumber, inActive, user);
                    }


                    //Hacer el ajuste de inventario si el label tiene diferencias.
                    if (r.Difference > 0 && r.Mark == true)
                    {
                        positiveLine = UpdatePositiveAdj(countTask, r, user, postiveAdj, positiveLine);
                    }

                    else if (r.Difference < 0 && r.Mark == true)
                    {
                        negativeAdj = UpdateNegativeAdj(countTask, r, user);
                        if (negativeAdj != null)
                        {
                            negativeDocs.Add(negativeAdj);
                        }
                    }
                }


                /* PRODUCTO
                 * 1. Ajusta las diferencias de producto en el mismo BIN (Positivo/Negativo) (Label == null && Expected > 0 && counted > 0)
                 * 2. Aumenta el producto Encontrado (Ajuste Positivo) (Label == null && Expected == 0)
                 * 3. Disminuir el producto no encotrado pero esperado en el bin (Label = null && Expected > 0 && counted ==0)
                 */

                //Casetype
                //1. Producto Suelto en el BIN (contado o no Contado)
                //2. Producto No esperado ajuste positivo

                try { productTotal = taskList.Where(f => f.CaseType == 1 || f.CaseType == 2 || f.CaseType == 3).ToList(); }
                catch { productTotal = new List <CountTaskBalance>(); }


                foreach (CountTaskBalance r in productTotal.Where(f => f.Mark == true))
                {
                    if (r.Difference > 0) //r.QtyExpected == 0 &&
                    {
                        positiveLine = UpdatePositiveAdj(countTask, r, user, postiveAdj, positiveLine);
                    }

                    else if (r.Difference < 0) //r.QtyExpected > 0 && r.QtyCount == 0 &&
                    {
                        negativeAdj = UpdateNegativeAdj(countTask, r, user);
                        if (negativeAdj != null)
                        {
                            negativeDocs.Add(negativeAdj);
                        }
                    }
                }

                //Factory.Commit();
                Factory.IsTransactional = true;


                //Enviando Ajustes Positivos Al ERP
                if (postiveAdj != null)
                {
                    try { ErpMngr.CreateInventoryAdjustment(postiveAdj, true); }
                    catch { }
                }

                //Enviando Ajustes Negativos Al ERP
                if (negativeDocs.Count > 0)
                {
                    foreach (Document negAdj in negativeDocs)
                    {
                        try { ErpMngr.CreateInventoryAdjustment(negAdj, true); }
                        catch (Exception ex)
                        {
                            try
                            {
                                addLine = Factory.DaoDocumentLine().Select(new DocumentLine {
                                    Document = negAdj
                                }).First();
                                addLine.Note = WriteLog.GetTechMessage(ex).Substring(0, 255);
                                Factory.DaoDocumentLine().Update(addLine);
                            }
                            catch { }
                        }
                    }
                }


                //Factory.IsTransactional = true;


                Status cancell = Factory.DaoStatus().Select(new Status {
                    StatusID = DocStatus.Cancelled
                }).First();

                //Cancel the BinExecution Completed Or New
                //Lista de Tareas Ejecutadas.
                //Poner las tareas en status completed.
                IList <BinByTask>          executionList = taskList.Select(f => f.BinByTask).Distinct().ToList();
                IList <BinByTaskExecution> exeChilds;
                foreach (BinByTask btExe in executionList)
                {
                    btExe.Status     = posted;
                    btExe.ModDate    = DateTime.Now;
                    btExe.ModifiedBy = user;
                    Factory.DaoBinByTask().Update(btExe);

                    //Actualizando los Hijos
                    exeChilds = Factory.DaoBinByTaskExecution().Select(new BinByTaskExecution {
                        BinTask = new BinByTask {
                            RowID = btExe.RowID
                        }
                    });
                    foreach (BinByTaskExecution ch in exeChilds)
                    {
                        ch.Status     = posted;
                        ch.ModDate    = DateTime.Now;
                        ch.ModifiedBy = user;
                        Factory.DaoBinByTaskExecution().Update(ch);
                    }
                }

                //Factory.Commit();

                countTask.DocStatus  = posted;
                countTask.ModDate    = DateTime.Now;
                countTask.ModifiedBy = user;
                countTask.Date2      = DateTime.Now; //Confirmation Date
                Factory.DaoDocument().Update(countTask);


                Factory.Commit();



                return(countTask);
            }
            catch (Exception ex)
            {
                Factory.Rollback();

                ExceptionMngr.WriteEvent("ConfirmCountingTaskDocument: " + countTask.DocNumber, ListValues.EventType.Error, ex, null, ListValues.ErrorCategory.ErpPosting);
                throw;
            }
        }
Exemple #2
0
        public Document ProcessNoCount(List <ProductStock> listNoCount, string username, bool erp)
        {
            //Para el listado enviado
            //1. Pasar los labels de esos productos en NOCOUNT a Printed = false & Status = active
            //2. hacer Ajustes Negativos BIN NOCOUNT por las cantidades

            // CAA [2010/06/10]
            // Nueva opción para enviar o nó, al ERP
            string erpText = "OnlyWms";

            if (erp)
            {
                erpText = "SentToErp";
            }

            //Crear Ajustes de inventario positivos en un solo ajuste.
            Document negativeAdj = new Document
            {
                DocType = new DocumentType {
                    DocTypeID = SDocType.InventoryAdjustment
                },
                CreatedBy    = username,
                Location     = listNoCount[0].Bin.Location,
                Company      = listNoCount[0].Product.Company,
                IsFromErp    = false,
                CrossDocking = false,
                Comment      = "CountTask Posting (NOCOUT Adj)" + username,
                Date1        = DateTime.Now,
                CustPONumber = "NOCOUNT Adjustment",
                Notes        = WmsSetupValues.Counting_Bach,
                Reference    = erpText
            };

            negativeAdj = DocMngr.CreateNewDocument(negativeAdj, false);


            Status active = Factory.DaoStatus().Select(new Status {
                StatusID = EntityStatus.Active
            }).First();

            Node storedNode = Factory.DaoNode().Select(new Node {
                NodeID = NodeType.Stored
            }).First();

            IList <Label> affectedLabels;
            int           adjLine = 1;

            foreach (ProductStock ps in listNoCount)
            {
                affectedLabels = Factory.DaoLabel().Select(new Label
                {
                    Product   = ps.Product,
                    Bin       = ps.Bin,
                    LabelType = new DocumentType {
                        DocTypeID = LabelType.ProductLabel
                    }
                });

                foreach (Label lbl in affectedLabels)
                {
                    lbl.Status  = active;
                    lbl.Printed = false;
                    lbl.Node    = storedNode;
                    Factory.DaoLabel().Update(lbl);
                }

                //Crear la Negative Lines.
                adjLine = CreateNoCountAdjLines(ps, username, negativeAdj, adjLine);
            }


            ErpMngr.CreateInventoryAdjustment(negativeAdj, true);
            return(negativeAdj);
        }