Exemplo n.º 1
0
        private Document UpdateNegativeAdj(Document countTask, CountTaskBalance r, string user)
        {
            Label targetLabel;

            if (r.Label != null)
            {
                targetLabel = r.Label;
            }
            else
            {
                targetLabel = Factory.DaoLabel().Select(new Label {
                    Bin = new Bin {
                        BinID = r.Bin.BinID
                    }, LabelType = new DocumentType {
                        DocTypeID = LabelType.BinLocation
                    }
                }).First();
            }


            //Creando la linea del Ajuste
            DocumentLine addLine = new DocumentLine
            {
                Product      = r.Product,
                Quantity     = Math.Abs(r.Difference), //Math.Abs(binTask.QtyDiff),
                QtyAllocated = r.QtyExpected,
                ModifiedBy   = user,
                CreationDate = DateTime.Now,
                CreatedBy    = user,
                ModDate      = DateTime.Now,
                Unit         = r.Product.BaseUnit,
                LineStatus   = new Status {
                    StatusID = DocStatus.New
                },
                IsDebit        = true, //r.Difference < 0 ? true : false,
                UnitBaseFactor = r.Product.BaseUnit.BaseAmount,
                //BinAffected = r.Bin.BinCode + ((r.Label != null) ? " " + r.Label.LabelCode : ""),
                BinAffected = targetLabel.LabelCode,
                Location    = countTask.Location,
                Note        = r.Bin.BinCode,
                Date1       = DateTime.Now
            };

            //Crear Ajustes de inventario positivos en un solo ajuste.
            Document negativeAdj = new Document
            {
                DocType = new DocumentType {
                    DocTypeID = SDocType.InventoryAdjustment
                },
                CreatedBy    = user,
                Location     = countTask.Location,
                Company      = countTask.Company,
                IsFromErp    = false,
                CrossDocking = false,
                Comment      = "CountTask Posting (Negative Adj) " + countTask.DocNumber + ", " + user,
                Date1        = DateTime.Now,
                CustPONumber = countTask.DocNumber,
                Notes        = WmsSetupValues.Counting_Bach
            };

            negativeAdj        = DocMngr.CreateNewDocument(negativeAdj, false);
            addLine.Document   = negativeAdj;
            addLine.LineNumber = 1;
            addLine            = SaveAdjustmentTransaction(addLine, targetLabel, false);

            if (addLine.Note == "Adjust OK.")
            {
                return(negativeAdj);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
0
        public void CreateScheduledCount()
        {
            DocumentType docType = new DocumentType {
                DocClass = new DocumentClass {
                    DocClassID = SDocClass.Task
                }
            };

            docType.DocTypeID = SDocType.CountTask;

            // search for the Scheduled counts...
            IList <CountSchedule> list = Factory.DaoCountSchedule().Select(new CountSchedule {
                NextDateRun = DateTime.Today, IsDone = false
            });

            foreach (CountSchedule sch in list)
            {
                Document document = new Document
                {
                    Comment      = "Scheduled Counting : " + sch.Title,
                    DocType      = docType,
                    CrossDocking = false,
                    IsFromErp    = false,
                    Location     = sch.Location,
                    Company      = sch.Location.Company,
                    Date1        = DateTime.Today,
                    CreationDate = DateTime.Now,
                    CreatedBy    = WmsSetupValues.SystemUser,
                    Notes        = sch.CountOption.ToString()
                };
                document = DocMngr.CreateNewDocument(document, true);

                // parametros para ejecutar el query
                DataSet paramsQuery = BasicMngr.GetDataSet(sch.Parameters);

                // ejecuta el query q trae los productos/bines
                DataSet dataSet = Factory.DaoIqReport().GetReportObject(sch.Query, paramsQuery);


                bool useProduct = true;

                if (sch.CountOption == 0) //Only BIN
                {
                    useProduct = false;
                }

                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    //  siempre deben enviar los alias "producto" "binCode" en el reporte !!!
                    Product prod = null;
                    try
                    {
                        if (!string.IsNullOrEmpty(row["Product"].ToString()) && useProduct)
                        {
                            prod = Factory.DaoProduct().Select(new Product {
                                ProductCode = row["Product"].ToString()
                            }, 0)[0];
                        }
                    }
                    catch { }

                    Bin bin = null;
                    try
                    {
                        if (!string.IsNullOrEmpty(row["BinCode"].ToString()))
                        {
                            bin = Factory.DaoBin().Select(new Bin {
                                BinCode = row["BinCode"].ToString()
                            })[0];
                        }
                    }
                    catch { }

                    //Crea el BinTask x prod/bin
                    BinByTask binByTask = new BinByTask
                    {
                        CreatedBy    = WmsSetupValues.SystemUser,
                        CreationDate = DateTime.Now,
                        Bin          = bin,
                        Product      = prod,
                        TaskDocument = document,
                        Status       = new Status {
                            StatusID = DocStatus.New
                        }
                    };

                    try
                    {
                        Factory.DaoBinByTask().Save(binByTask);
                    }
                    catch (Exception e)
                    {
                        continue;
                    }
                }

                // programamos sgte fecha de conteo (si no se pasa de la fecha final)
                if (sch.NextDateRun.Value.AddDays(double.Parse(sch.RepeatEach.ToString())) <= sch.Finish.Value)
                {
                    sch.NextDateRun = sch.NextDateRun.Value.AddDays(double.Parse(sch.RepeatEach.ToString()));
                }

                else  // ya finaliza el conteo repetitivo
                {
                    sch.IsDone = true;
                }

                sch.ModDate    = DateTime.Now;
                sch.ModifiedBy = WmsSetupValues.SystemUser;

                Factory.DaoCountSchedule().Update(sch);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        //Hecho para maxiforce, manejo de Caterpillar MAY/12/2010
        public void ConfirmPicking(Document document, string user)
        {
            //Revisar que el ajuste no se ha enviado antes.
            if (document.Reference == "CAT")
            {
                throw new Exception("This document was confirmed before.");
            }

            //Revisar la order y detectar si tiene componentes o kits de caterpillar en su balance.
            IList <DocumentBalance> list = Factory.DaoDocumentBalance().PostingBalance( //PostingBalance
                new DocumentBalance
            {
                Document = document,
                Node     = new Node {
                    NodeID = NodeType.Picked
                },
                Location = document.Location
            });

            if (list == null || list.Count == 0)
            {
                return;
            }

            Product parentKit;
            IList <DocumentLine> adjLines = new List <DocumentLine>();
            DocumentLine         addLine;
            int lineSeq = 1;

            IList <DocumentLine> docLines = Factory.DaoDocumentLine().Select(new DocumentLine {
                Note     = "1",
                Document = new Document {
                    DocID = document.DocID
                }
            });

            foreach (DocumentBalance r in list)
            {
                //revisa que ese producto este manejado como componente Notes = "1" en las lineas.
                //if (!docLines.Any(f => f.Product.ProductID == r.Product.ProductID && f.AccountItem == ExplodeKit.Caterpillar.ToString()))
                if (!docLines.Any(f => f.Product.ProductID == r.Product.ProductID && f.AccountItem == ExplodeKit.Caterpillar.ToString()))
                {
                    continue;
                }


                try
                {
                    //revisa si es un componente caterpillar
                    parentKit = Factory.DaoKitAssemblyFormula().Select(
                        new KitAssemblyFormula {
                        Component = r.Product
                    })
                                .Select(f => f.KitAssembly.Product).Where(f => f.Category.ExplodeKit == ExplodeKit.Caterpillar)
                                .First();


                    foreach (DocumentLine zLine in docLines.Where(f => f.Product.ProductID == r.Product.ProductID && f.AccountItem == ExplodeKit.Caterpillar.ToString()))
                    {
                        //Creando la linea del Ajuste Negativo COMPONENTE
                        adjLines.Add(new DocumentLine
                        {
                            Product      = r.Product,
                            Quantity     = zLine.Quantity - zLine.QtyCancel - zLine.QtyBackOrder, //r.QtyPending,
                            CreationDate = DateTime.Now,
                            CreatedBy    = user,
                            Unit         = r.Product.BaseUnit,
                            LineStatus   = new Status {
                                StatusID = DocStatus.New
                            },
                            IsDebit        = true,
                            UnitBaseFactor = r.Product.BaseUnit.BaseAmount,
                            Location       = document.Location,
                            Date1          = DateTime.Now,
                            LineNumber     = lineSeq++
                        });


                        //Creando la linea del Ajuste POsitivo KIT
                        adjLines.Add(new DocumentLine
                        {
                            Product      = parentKit,
                            Quantity     = zLine.Quantity - zLine.QtyCancel - zLine.QtyBackOrder, //r.QtyPending,
                            CreationDate = DateTime.Now,
                            CreatedBy    = user,
                            Unit         = parentKit.BaseUnit,
                            LineStatus   = new Status {
                                StatusID = DocStatus.New
                            },
                            IsDebit        = false,
                            UnitBaseFactor = parentKit.BaseUnit.BaseAmount,
                            Location       = document.Location,
                            Date1          = DateTime.Now,
                            LineNumber     = lineSeq++
                        });
                    }
                }
                catch { continue; }
            }


            if (adjLines.Count == 0)
            {
                return;
            }


            Factory.IsTransactional = true;

            try
            {
                //Crear Ajustes de inventario positivos en un solo ajuste.
                Document adjustment = new Document
                {
                    DocType = new DocumentType {
                        DocTypeID = SDocType.InventoryAdjustment
                    },
                    CreatedBy    = user,
                    Location     = document.Location,
                    Company      = document.Company,
                    IsFromErp    = false,
                    CrossDocking = false,
                    Comment      = "Caterpillar Replace " + document.DocNumber + ", " + user,
                    Date1        = DateTime.Now,
                    CustPONumber = document.DocNumber,
                    Notes        = (string.IsNullOrEmpty(document.Location.ErpCode) ? "" : document.Location.ErpCode) + " CAT REPLACE"
                };

                adjustment = DocMngr.CreateNewDocument(adjustment, false);

                foreach (DocumentLine l in adjLines)
                {
                    l.Document = adjustment;
                    adjustment.DocumentLines.Add(l);
                }

                Factory.DaoDocument().Update(adjustment);

                (new ErpDataMngr()).CreateInventoryAdjustment(adjustment, false);


                Factory.Commit();


                //Actualiza un dato en el documento qu eindica que ya el ajuste se envio
                Document doc = Factory.DaoDocument().Select(new Document {
                    DocID = document.DocID
                }).First();
                doc.Reference = "CAT";
                Factory.DaoDocument().Update(doc);
            }
            catch (Exception ex)
            {
                Factory.Rollback();
                ExceptionMngr.WriteEvent("ConfirmPicking:", ListValues.EventType.Fatal, ex, null, ListValues.ErrorCategory.Business);
                throw new Exception(WriteLog.GetTechMessage(ex));
            }
        }