Ejemplo n.º 1
0
        private string CheckForStockInLocation(DocumentLine line, Label sourceLocation)
        {
            Node storedNode = WType.GetNode(new Node {
                NodeID = NodeType.Stored
            });

            //Toma las etiquetas No printed del sourceLocation
            //Obtiene los labels que va a mover

            if (!Rules.ValidateBinStatus(sourceLocation.Bin, false))
            {
                return("Bin affected: " + sourceLocation.Bin.BinCode + " is currently " + sourceLocation.Bin.Status.Name);
            }

            //Label sourceLabel = new Label { Bin = sourceLocation, LabelType = new DocumentType { DocTypeID = LabelType.BinLocation } };

            IList <Label> labelList = GetQuantityOfLabels(sourceLocation, line);

            if (labelList.Sum(f => f.BaseCurrQty) < line.Quantity * line.Unit.BaseAmount)
            {
                return("No quantity available in the bin " + sourceLocation.Name + " for product " + line.Product.Name + ".\n");
            }


            return("");
        }
Ejemplo n.º 2
0
        private void UpdateReceivedOnNode()
        {
            //Obtiene los Nodetrace que sean de nodo 4 y que tengan labels en nodo 2, y con documento de posteo existente
            try
            {
                IList <Label> labelList = Factory.DaoNodeTrace().Select(
                    new NodeTrace
                {
                    Label = new Label {
                        Node = new Node {
                            NodeID = NodeType.Received
                        }
                    },
                    PostingDocument = new Document {
                        DocID = 1
                    },
                    Node = new Node {
                        NodeID = NodeType.Stored
                    }
                }).Select(f => f.Label).ToList();

                Node stored = WType.GetNode(new Node {
                    NodeID = NodeType.Stored
                });

                //Actualizando los lables encontrados
                foreach (Label lbl in labelList)
                {
                    lbl.Node   = stored;
                    lbl.Notes += " (2)";
                    Factory.DaoLabel().Update(lbl);
                }
            }
            catch { }
        }
        public Label EmptyUniqueTrackLabel(Product product, string labelCode, string user)
        {
            //Chequear que no exista un labelcode igual para el mismo producto. En estado Activo.
            try
            {
                Label lbl = Factory.DaoLabel().Select(new Label
                {
                    LabelCode = labelCode.Trim(),
                    Product   = product,
                    Node      = new Node {
                        NodeID = NodeType.Stored
                    },
                    Status = new Status {
                        StatusID = EntityStatus.Active
                    }
                }).First();

                lbl.CurrQty   = 0;
                lbl.LabelCode = "VOID_" + DateTime.Now.ToString("YMdHms") + lbl.LabelCode;
                lbl.ModDate   = DateTime.Now;
                lbl.Node      = WType.GetNode(new Node {
                    NodeID = NodeType.Voided
                });
                lbl.Status = WType.GetStatus(new Status {
                    StatusID = EntityStatus.Inactive
                });

                Factory.DaoLabel().Update(lbl);
                return(lbl);
            }
            catch
            {
                throw new Exception("Track # [" + labelCode + "] does not exists or is inactive.");
            }
        }
Ejemplo n.º 4
0
        public void UnPickUniqueLabel(Document document, Label label, SysUser picker)
        {
            Node storedNode = WType.GetNode(new Node {
                NodeID = NodeType.Stored
            });
            Status status = WType.GetStatus(new Status {
                StatusID = EntityStatus.Active
            });

            IList <NodeTrace> nodeList = Factory.DaoNodeTrace().Select(
                new NodeTrace {
                Document = document, Label = label, Node = label.Node
            });

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

            ReverseNodeTrace(nodeList, picker.UserName, storedNode, label.LastBin, status);
        }
Ejemplo n.º 5
0
        //Process the lines to Print - OBSOLETE
        public String GetReplacedTemplate(IList <DocumentBalance> printList, LabelTemplate template, string printLot, UserByRol userByRol)
        {
            Factory.IsTransactional = true;

            string result = "";
            Node   node   = WType.GetNode(new Node {
                NodeID = NodeType.PreLabeled
            });
            Bin bin = WType.GetBin(new Bin {
                BinCode = DefaultBin.MAIN, Location = userByRol.Location
            });



            try
            {
                foreach (DocumentBalance printLine in printList)
                {
                    result += ProcessPrintingLine(printLine, template, printLot, node, bin, userByRol);

                    if (template.PrintEmptyLabel == true)
                    {
                        result += template.Empty;
                    }
                }

                Factory.Commit();
            }
            catch (Exception ex)
            {
                Factory.Rollback();
                ExceptionMngr.WriteEvent("GetReplacedTemplate:", ListValues.EventType.Fatal, ex, null, ListValues.ErrorCategory.ErpConnection);
                throw new Exception(WriteLog.GetTechMessage(ex));
            }

            return(result);
        }
Ejemplo n.º 6
0
        //Mueve cantidades de un package a otro
        public void MoveQtyBetweenPackages(DocumentPackage curPack, DocumentPackage newPack,
                                           Product product, double qty)
        {
            Factory.IsTransactional = true;

            Unit baseUnit = product.BaseUnit;

            try
            {
                DocumentLine line = new DocumentLine
                {
                    Quantity  = qty,
                    Product   = product,
                    Unit      = baseUnit,
                    CreatedBy = newPack.CreatedBy
                };

                #region remove from OLD package
                //#########################################################################
                //Remover la cantidad del paquete origen
                //Saca las cantidades para es BIN y de ese producto.
                IList <Label> labelList = GetPackageLabels(curPack.PackLabel, line);

                Label sourceLabel = null;

                if (labelList.Sum(f => f.BaseCurrQty) < line.Quantity * line.Unit.BaseAmount)
                {
                    Factory.Rollback();
                    throw new Exception("No quantity available for the transaction.");
                }


                //Recorre los labels hasta que termine el saldo y se salga.
                double qtyBalance = line.Quantity * line.Unit.BaseAmount;
                double curQty;
                foreach (Label label in labelList)
                {
                    if (qtyBalance <= 0)
                    {
                        break;
                    }

                    label.CurrQty  = label.BaseCurrQty;
                    label.StartQty = label.BaseStartQty;
                    label.Unit     = baseUnit;

                    //Cantidad a Disminuir
                    curQty = qtyBalance > label.CurrQty ? label.CurrQty : qtyBalance;

                    qtyBalance -= curQty;

                    label.CurrQty   -= curQty;
                    label.ModDate    = DateTime.Now;
                    label.ModifiedBy = line.CreatedBy;
                    Factory.DaoLabel().Update(label);
                    sourceLabel = label;
                }

                #endregion

                #region add to NEW package
                //#########################################################################
                //Adicionar la cantidad al paquete destino
                Label  tmpLabel   = null;
                Status statusLock = WType.GetStatus(new Status {
                    StatusID = EntityStatus.Locked
                });                                                                                 //Active

                DocumentType lblType = new DocumentType {
                    DocTypeID = LabelType.ProductLabel
                };
                //DocumentTypeSequence initSequence = DocMngr.GetNextDocSequence(curPack.Document.Company, lblType); //Funcion para obtener siguiente Label


                //Salvar con el nuevo status
                tmpLabel = new Label();

                //To Send
                Node node = WType.GetNode(new Node {
                    NodeID = NodeType.Released
                });
                tmpLabel.Node = curPack.PackLabel.Node;

                tmpLabel.Bin       = curPack.PackLabel.Bin;
                tmpLabel.CurrQty   = line.Quantity;
                tmpLabel.Product   = line.Product;
                tmpLabel.StartQty  = line.Quantity;
                tmpLabel.Unit      = line.Product.BaseUnit;
                tmpLabel.CreatedBy = line.CreatedBy;

                tmpLabel.Status    = statusLock;
                tmpLabel.LabelType = lblType;
                tmpLabel.LabelCode = ""; // initSequence.NumSequence.ToString() + GetRandomHex(line.CreatedBy, initSequence.NumSequence);

                tmpLabel.Printed          = false;
                tmpLabel.CreationDate     = DateTime.Now;
                tmpLabel.IsLogistic       = false;
                tmpLabel.ShippingDocument = curPack.Document;
                tmpLabel.LabelSource      = sourceLabel;

                tmpLabel.FatherLabel = newPack.PackLabel;
                tmpLabel             = Factory.DaoLabel().Save(tmpLabel);


                #endregion

                Factory.Commit();
            }
            catch  {
                Factory.Rollback();
                throw;
            }
        }
        //Obtiene la info del stock del ERP y actualiza el inventario
        //Detallado o global dejando todo en MAIN
        public void UpdateWMSStockFromERP(Company company, bool detailed)
        {
            if (company == null)
            {
                ExceptionMngr.WriteEvent("GetStockComparation Company " + company.Name, ListValues.EventType.Fatal, null, null, ListValues.ErrorCategory.Business);
                return;
            }
            SetConnectMngr(company);


            //bool detailed = true; //indica si obtiene el stock a nivel de BIN
            ProductStock data;
            Node         storedNode = WType.GetNode(new Node {
                NodeID = NodeType.Stored
            });
            IList <ProductStock> erpStock;


            IList <Location> locationList = Factory.DaoLocation().Select(new Location {
                Company = company
            });

            Console.WriteLine("Locations: " + locationList.Count.ToString());

            foreach (Location location in locationList)
            {
                if (location.LocationID == 107 || location.LocationID == 103)
                {
                    continue;
                }

                try
                {
                    data = new ProductStock {
                        Bin = new Bin {
                            Location = location
                        }
                    };
                    erpStock = ErpFactory.Documents().GetErpStock(data, detailed);

                    if (erpStock == null || erpStock.Count == 0)
                    {
                        continue;
                    }


                    Console.WriteLine("Location: " + location.Name + " => " + erpStock.Count + " records");
                    //Console.ReadKey();

                    foreach (ProductStock ps in erpStock.Where(f => f.Stock > 0))
                    {
                        try
                        {
                            UpdateStock(ps, storedNode, "Stock Update From ERP");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("UpdateStock: " + ex.Message);
                        }
                    }
                }
                catch (Exception ex)
                { Console.WriteLine("GetErpStock: " + ex.Message); }
            }
        }
        //Permite reversar un documento PR que fue posteado en el ERP,
        //solo se reversa si en el ERP no lo ha posteado
        public void ReversePurchaseReceipt(Document data)
        {
            Factory.IsTransactional = true;

            //if (data.Company.ErpConnection == null)
            //    throw new Exception("Please setup Erp Connection.");

            //SetConnectMngr(data.Company);

            Node recNode = new Node {
                NodeID = NodeType.Received
            };
            Node storedNode = new Node {
                NodeID = NodeType.Stored
            };

            try
            {
                //Update document status to Cancelled
                Status cancelled = WType.GetStatus(new Status {
                    StatusID = DocStatus.Cancelled
                });
                Status inactive = WType.GetStatus(new Status {
                    StatusID = EntityStatus.Inactive
                });


                //Cross Dock 7 - Marzo - 09
                ReverseCrossDockProcess(data);

                data.DocStatus = cancelled;
                Factory.DaoDocument().Update(data);

                //Pasa las lineas del documento a Cancelled
                IList <DocumentLine> docLines = Factory.DaoDocumentLine().Select(new DocumentLine {
                    Document = data
                });

                foreach (DocumentLine dl in docLines)
                {
                    dl.LineStatus = cancelled;
                    Factory.DaoDocumentLine().Update(dl);
                }

                //update NodeTrace
                NodeTrace qNodeTrace = new NodeTrace {
                    PostingDocument = data
                };

                //Busca todo los registros de ese documento y los reversa
                IList <NodeTrace> nodeTraceList = Factory.DaoNodeTrace().Select(qNodeTrace);

                Node voidNode = WType.GetNode(new Node {
                    NodeID = NodeType.Voided
                });

                Label curLabel;

                foreach (NodeTrace trace in nodeTraceList)
                {
                    //Crear un trace que tenga la transaccion del posting eliminado en el nodo void
                    //Registra el movimiento del nodo
                    if (trace.Node.NodeID == NodeType.Stored)
                    {
                        trace.Node       = voidNode;
                        trace.Status     = inactive;
                        trace.ModDate    = DateTime.Now;
                        trace.ModifiedBy = data.ModifiedBy;
                        trace.Comment    = "Stored: " + trace.PostingDocument.DocNumber + " Reversed";
                        Factory.DaoNodeTrace().Update(trace);

                        /*
                         * SaveNodeTrace(
                         *  new NodeTrace
                         *  {
                         *      Node = voidNode,
                         *      Document = trace.Document,
                         *      Label = trace.Label,
                         *      Quantity = trace.Quantity,
                         *      IsDebit = trace.IsDebit,
                         *      CreatedBy = trace.CreatedBy,
                         *      PostingDocument = trace.PostingDocument,
                         *      PostingUserName = trace.PostingUserName,
                         *      Status = inactive,
                         *      Comment = "Receipt " + trace.PostingDocument.DocNumber + " Reversed",
                         *      ModDate = DateTime.Now,
                         *      ModifiedBy = data.ModifiedBy,
                         *      PostingDate = trace.PostingDate,
                         *  });
                         */
                    }

                    //Reversa el trace original para poderlo postear nuevamente
                    if (trace.Node.NodeID == NodeType.Received)
                    {
                        trace.DocumentLine    = null;
                        trace.PostingDate     = null;
                        trace.PostingDocument = null;
                        trace.PostingUserName = null;
                        trace.ModifiedBy      = data.ModifiedBy;
                        trace.ModDate         = DateTime.Now;

                        Factory.DaoNodeTrace().Update(trace);


                        //Reverse labels to node trace received
                        curLabel      = trace.Label;
                        curLabel.Node = recNode;

                        try { curLabel.Notes += "Receipt " + trace.PostingDocument.DocNumber + " Reversed"; }
                        catch { }

                        curLabel.ModDate    = DateTime.Now;
                        curLabel.ModifiedBy = data.ModifiedBy;

                        Factory.DaoLabel().Update(curLabel);
                    }
                }

                Factory.Commit();
            }
            catch (Exception ex)
            {
                Factory.Rollback();
                ExceptionMngr.WriteEvent("ReversePurchaseReceipt #" + data.DocNumber, ListValues.EventType.Fatal, ex, null, ListValues.ErrorCategory.Persistence);
                throw;
                //return;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Piquea un producto a una orden teneindo en cuanta las tracking options.
        /// </summary>
        /// <param name="label"></param>
        /// <param name="qtyToPick"></param>
        /// <param name="node"></param>
        /// <param name="picker"></param>
        public Label PickProductWithTrack(Document document, Label label, double qtyToPick, Node destNode, SysUser picker,
                                          Label packLabel)
        {
            //Debe piquear de producto suelto, teniendo en cuanta el Track del Label.
            Factory.IsTransactional = true;

            Node storedNode = WType.GetNode(new Node {
                NodeID = NodeType.Stored
            });

            Status status = WType.GetStatus(new Status {
                StatusID = EntityStatus.Active
            });
            Status locked = WType.GetStatus(new Status {
                StatusID = EntityStatus.Locked
            });
            //DocumentType labelType = WType.GetLabelType(new DocumentType { DocTypeID = LabelType.ProductLabel });

            Bin destBin = Rules.GetBinForNode(destNode, document.Location);


            try
            {
                //Valida si el docuemnto no es nulo
                Rules.ValidateDocument(document, true);

                Rules.ValidateBinStatus(label.Bin, true);


                //Valida si el producto esta en ese documento
                DocumentLine docLine = new DocumentLine
                {
                    Document   = document,
                    Product    = label.Product,
                    LineStatus = new Status {
                        StatusID = DocStatus.New
                    },
                    Unit      = label.Unit,
                    Quantity  = qtyToPick,
                    CreatedBy = picker.UserName
                };


                if (document.DocType.DocTypeID != SDocType.PickTicket)
                {
                    Rules.ValidateProductInDocument(docLine, true);

                    //Valida si hay saldo pendiente por procesar
                    Rules.ValidateBalanceQuantityInDocument(docLine, destNode, true, false);
                }


                //Evaluacion de tipo de source, Bin or Label
                DateTime recDate = DateTime.Now;
                //if (Rules.ValidateIsBinLabel(sourceLocation, false))
                //{
                IList <Label> tranLabel = DecreaseQtyFromBin(label, docLine, "Picking Source Track", true, storedNode);
                try
                {
                    recDate = (DateTime)tranLabel.Where(f => f.ReceivingDate != null).OrderBy(f => f.ReceivingDate).First().ReceivingDate;
                }
                catch { recDate = DateTime.Now; }
                //}

                //    //SI el ajustes es sobre un Label
                //else if (Rules.ValidateIsProductLabel(sourceLocation, false))
                //{
                //    DecreaseQtyFromLabel(sourceLocation, line, "Picking Source", true, storedNode);
                //    try { recDate = (sourceLocation.ReceivingDate == null) ? DateTime.Now : (DateTime)sourceLocation.ReceivingDate; }
                //    catch { recDate = DateTime.Now; }
                //}


                //Creando el package para ingresar la mercancia.
                if (packLabel == null)
                {
                    packLabel = new Label {
                        LabelID = -1
                    }
                }
                ;

                document.Location = label.Bin.Location;  //Revalidando que el location sea correcto
                try
                {
                    packLabel = GetPackageLabel(packLabel, document, picker).PackLabel;
                }
                catch (Exception ex)
                {
                    Factory.Rollback();
                    throw new Exception("Package label could not be created.\n" + ex.Message);
                }


                //Increasing the Record of Product on Dest Bin.
                //Oct 09 /2009 Se adiciona el track option.
                Label pickedLabel = IncreaseQtyIntoBin(docLine, destNode, destBin, "Picking Dest Track", true,
                                                       recDate, label.TrackOptions, label);

                pickedLabel.FatherLabel      = packLabel;
                pickedLabel.Status           = locked;
                pickedLabel.ShippingDocument = document;
                Factory.DaoLabel().Update(pickedLabel);

                Factory.Commit();
                return(pickedLabel);
            }
            catch (Exception ex)
            {
                Factory.Rollback();
                ExceptionMngr.WriteEvent("PickProductWithTrack:", ListValues.EventType.Fatal, ex, null, ListValues.ErrorCategory.Business);
                throw new Exception(WriteLog.GetTechMessage(ex));
            }
        }
Ejemplo n.º 10
0
        public void PickCrossDockProduct(Document purchase, IList <DocumentBalance> crossDockBalance, SysUser picker)
        {
            Factory.IsTransactional = true;

            Node storedNode = WType.GetNode(new Node {
                NodeID = NodeType.Stored
            });
            Node node = WType.GetNode(new Node {
                NodeID = NodeType.Picked
            });
            Status status = WType.GetStatus(new Status {
                StatusID = EntityStatus.Active
            });
            DocumentType labelType = WType.GetLabelType(new DocumentType {
                DocTypeID = LabelType.ProductLabel
            });

            Bin pickingBin = WType.GetBin(new Bin {
                Location = purchase.Location, BinCode = DefaultBin.PICKING
            });

            Dictionary <Document, Label> packageLabel = new Dictionary <Document, Label>();
            Status locked = WType.GetStatus(new Status {
                StatusID = EntityStatus.Locked
            });


            try
            {
                //Solo toma las lineas de sales y deja quietas las del docuemnto de purchasing
                foreach (DocumentBalance line in crossDockBalance.Where(f => f.Document.DocType.DocClass.DocClassID == SDocClass.Shipping))
                {
                    //Valida si el documento no es nulo
                    Rules.ValidateDocument(line.Document, true);


                    if (line.Document.DocType.DocTypeID != SDocType.PickTicket)
                    {
                        //Valida si el producto esta en ese documento
                        DocumentLine docLine = new DocumentLine
                        {
                            Document   = line.Document,
                            Product    = line.Product,
                            LineStatus = new Status {
                                StatusID = DocStatus.New
                            },
                            Unit     = line.Unit,
                            Quantity = line.QtyProcessed //Quatity processed que es la que hace el cruce con el CrossDock
                        };

                        Rules.ValidateProductInDocument(docLine, true);

                        //Valida si hay saldo pendiente por procesar
                        try { Rules.ValidateBalanceQuantityInDocument(docLine, node, true, true); }
                        catch { continue; }
                    }

                    //Toma el producto del nodetrace
                    //Obtiene los labels que va a mover
                    NodeTrace sourceTrace = new NodeTrace
                    {
                        Document = purchase,
                        //Dec 7/09 no se puede forzar a que sea la misma unidad del balance //Unit = line.Unit,
                        Label = new Label {
                            Product = line.Product, Node = storedNode, Status = status
                        },
                        Status = status,
                        Node   = storedNode
                    };

                    //Obtiene las transacciones del node trace para ese documento especifico de Purchase.
                    IList <Label> labelList = Factory.DaoNodeTrace().Select(sourceTrace).Select(f => f.Label)
                                              //.Take(int.Parse(line.QtyProcessed.ToString()))
                                              .ToList();


                    if (labelList.Sum(f => f.CurrQty * f.Unit.BaseAmount) < line.QtyProcessed * line.Unit.BaseAmount)
                    {
                        Factory.Rollback();
                        throw new Exception("No quantity available in the purchase document " + purchase.DocNumber
                                            + " for product " + line.Product.FullDesc + ".\nQty Available: " + labelList.Sum(f => f.CurrQty * f.Unit.BaseAmount).ToString()
                                            + " Qty Requested: " + (line.QtyProcessed * line.Unit.BaseAmount).ToString() + " in Doc# " + line.Document.DocNumber);
                    }


                    //Package Label para el Despacho
                    if (!packageLabel.ContainsKey(line.Document))
                    {
                        packageLabel.Add(line.Document, GetPackageLabel(new Label {
                            LabelID = -1
                        }, line.Document, picker).PackLabel);
                    }


                    //Debe piquear la cantidad necesaria para suplir el SO con los labels
                    //recibidos.

                    double crQtyBal = line.QtyProcessed * line.Unit.BaseAmount; //LLevada  a la unidad basica

                    foreach (Label curLabel in labelList)
                    {
                        if (crQtyBal <= 0)
                        {
                            break;
                        }

                        //Si el Qty del label menor que lo pendiente mando todo el label
                        if (curLabel.CurrQty * curLabel.Unit.BaseAmount <= crQtyBal)
                        {
                            //Si el destino es logitico lo hace su padre, si no es producto suelto en BIN
                            curLabel.ModifiedBy = purchase.ModifiedBy;
                            curLabel.Node       = node;
                            curLabel.LastBin    = curLabel.Bin;
                            curLabel.Bin        = pickingBin;
                            curLabel.ModDate    = DateTime.Now;

                            curLabel.FatherLabel = null;
                            curLabel.FatherLabel = packageLabel[line.Document];
                            curLabel.Status      = locked;

                            SaveNodeTrace(new NodeTrace
                            {
                                Node      = node,
                                Label     = curLabel,
                                Quantity  = curLabel.CurrQty,
                                Bin       = pickingBin,
                                IsDebit   = false,
                                CreatedBy = purchase.ModifiedBy,
                                Document  = line.Document,
                                // 07 Marzo 2009
                                // En el comenttario se pone el # del PO de cross dock,
                                // este dato sirve en caso de reversion del crossdock process
                                Comment = purchase.DocNumber
                            });


                            curLabel.ShippingDocument = line.Document;
                            Factory.DaoLabel().Update(curLabel);
                            crQtyBal -= curLabel.CurrQty * curLabel.Unit.BaseAmount;
                        }

                        //Si no: disminuyo el Qty del label y hago un Increase
                        else
                        {
                            //Si el destino es logitico lo hace su padre, si no es producto suelto en BIN
                            curLabel.ModifiedBy = purchase.ModifiedBy;
                            curLabel.ModDate    = DateTime.Now;
                            curLabel.CurrQty   -= crQtyBal;
                            Factory.DaoLabel().Update(curLabel);

                            //Increase The Pick Node

                            Node pickNode = WType.GetNode(new Node {
                                NodeID = NodeType.Picked
                            });

                            DocumentLine crdLine = new DocumentLine {
                                Document  = line.Document,
                                Product   = line.Product,
                                Quantity  = crQtyBal,
                                CreatedBy = purchase.ModifiedBy
                            };

                            Label pickedLabel = IncreaseQtyIntoBin(crdLine, pickNode, Rules.GetBinForNode(pickNode, purchase.Location),
                                                                   "Picking Dest", true, DateTime.Now, null, curLabel);

                            pickedLabel.FatherLabel      = packageLabel[line.Document];
                            pickedLabel.Status           = locked;
                            pickedLabel.ShippingDocument = line.Document;

                            Factory.DaoLabel().Update(pickedLabel);

                            //Factory.Commit();
                        }
                    }



                    /*
                     * //Acutualiza la ubicacion Nuevo Bin
                     * foreach (Label curLabel in labelList)
                     * {
                     *  //Si el destino es logitico lo hace su padre, si no es producto suelto en BIN
                     *  curLabel.ModifiedBy = purchase.ModifiedBy;
                     *  curLabel.Node = node;
                     *  curLabel.LastBin = curLabel.Bin;
                     *  curLabel.Bin = pickingBin;
                     *
                     *  SaveNodeTrace(new NodeTrace
                     *  {
                     *      Node = node,
                     *      Label = curLabel,
                     *      Quantity = curLabel.CurrQty,
                     *      Bin = pickingBin,
                     *      IsDebit = false,
                     *      CreatedBy = purchase.ModifiedBy,
                     *      Document = line.Document,
                     *      // 07 Marzo 2009
                     *      // En el comenttario se pone el # del PO de cross dock,
                     *      // este dato sirve en caso de reversion del crossdock process
                     *      Comment = purchase.DocNumber
                     *  });
                     *
                     *  curLabel.FatherLabel = null;
                     *  Factory.DaoLabel().Update(curLabel);
                     * }
                     */
                }

                Factory.Commit();


                //Actualiza el estado de los documentos de shiiping a CrossDock
                foreach (Document doc in crossDockBalance.Where(f => f.Document.DocType.DocClass.DocClassID == SDocClass.Shipping).Select(f => f.Document).Distinct())
                {
                    doc.CrossDocking = true;
                    Factory.DaoDocument().Update(doc);
                }

                Factory.Commit();
            }
            catch (Exception ex)
            {
                Factory.Rollback();
                ExceptionMngr.WriteEvent("PickCrossDockProduct:", ListValues.EventType.Fatal, ex, null, ListValues.ErrorCategory.Business);
                throw new Exception(WriteLog.GetTechMessage(ex));
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Recolecta= producto, sin etiqueta (recibo manual) toma de los labels virtuales para cada unidad basica de producto
        /// </summary>
        /// <param name="line"></param>
        /// <param name="sourceLocation"></param>
        /// <param name="node"></param>
        /// <param name="packageLabel"></param>
        /// <param name="picker"></param>
        public void PickProduct(DocumentLine line, Label sourceLocation, Node destNode, Label packageLabel, SysUser picker, Bin destBin)
        {
            Factory.IsTransactional = true;

            Node storedNode = WType.GetNode(new Node {
                NodeID = NodeType.Stored
            });

            Status status = WType.GetStatus(new Status {
                StatusID = EntityStatus.Active
            });
            Status locked = WType.GetStatus(new Status {
                StatusID = EntityStatus.Locked
            });
            DocumentType labelType = WType.GetLabelType(new DocumentType {
                DocTypeID = LabelType.ProductLabel
            });

            if (destBin == null)
            {
                destBin = Rules.GetBinForNode(destNode, sourceLocation.Bin.Location);
            }


            try
            {
                //Valida si el docuemnto no es nulo
                Rules.ValidateDocument(line.Document, true);

                Rules.ValidateBinStatus(sourceLocation.Bin, true);

                //Validar si las locations son iguales
                Rules.ValidatePickLocation(line.Document.Location, sourceLocation.Bin.Location, true);


                if (sourceLocation.LabelType.DocTypeID == LabelType.ProductLabel)
                {
                    //Valida que este activo
                    Rules.ValidateActiveStatus(sourceLocation.Status, true);

                    //Validar que no este vod
                    Rules.ValidateVoided(sourceLocation.Node, true);
                }



                if (line.Document.DocType.DocTypeID != SDocType.PickTicket)
                {
                    //Valida si el producto esta en ese documento
                    DocumentLine docLine = new DocumentLine
                    {
                        Document   = line.Document,
                        Product    = line.Product,
                        LineStatus = new Status {
                            StatusID = DocStatus.New
                        },
                        Unit      = line.Unit,
                        Quantity  = line.Quantity,
                        CreatedBy = picker.UserName
                    };

                    Rules.ValidateProductInDocument(docLine, true);

                    //Valida si hay saldo pendiente por procesar
                    Rules.ValidateBalanceQuantityInDocument(docLine, destNode, true, false);
                }


                //Evaluacion de tipo de source, Bin or Label
                DateTime recDate = DateTime.Now;
                if (Rules.ValidateIsBinLabel(sourceLocation, false))
                {
                    IList <Label> tranLabel = DecreaseQtyFromBin(sourceLocation, line, "Picking Source Product", true, storedNode);
                    try
                    {
                        recDate = (DateTime)tranLabel.Where(f => f.ReceivingDate != null).OrderBy(f => f.ReceivingDate).First().ReceivingDate;
                    }
                    catch { recDate = DateTime.Now; }
                }

                //SI el ajustes es sobre un Label
                else if (Rules.ValidateIsProductLabel(sourceLocation, false))
                {
                    DecreaseQtyFromLabel(sourceLocation, line, "Picking Source Product", true, storedNode, true);
                    try { recDate = (sourceLocation.ReceivingDate == null) ? DateTime.Now : (DateTime)sourceLocation.ReceivingDate; }
                    catch { recDate = DateTime.Now; }
                }


                //Creando el package para ingresar la mercancia.
                if (packageLabel != null)
                {
                    line.Document.Location = sourceLocation.Bin.Location;  //Revalidando que el location sea correcto

                    try { packageLabel = GetPackageLabel(packageLabel, line.Document, picker).PackLabel; }
                    catch (Exception ex)
                    {
                        Factory.Rollback();
                        throw new Exception("Package label could not be created.\n" + ex.Message);
                    }
                }


                //Increasing the Record of Product on Dest Bin.
                Label pickedLabel = IncreaseQtyIntoBin(line, destNode, destBin, "Picking Dest Product", true, recDate, null, sourceLocation);
                pickedLabel.FatherLabel      = packageLabel;
                pickedLabel.Status           = locked;
                pickedLabel.ShippingDocument = line.Document;
                Factory.DaoLabel().Update(pickedLabel);

                Factory.Commit();
            }
            catch (Exception ex)
            {
                Factory.Rollback();
                ExceptionMngr.WriteEvent("PickProduct:", ListValues.EventType.Fatal, ex, null, ListValues.ErrorCategory.Business);
                throw new Exception(WriteLog.GetTechMessage(ex));
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Crea a new label package for a specific document, this package will contain product picked for the order.
        /// </summary>
        /// <param name="line"></param>
        /// <param name="picker"></param>
        /// <returns></returns>
        public DocumentPackage CreateNewPackage(Document document, SysUser picker, bool isOpen,
                                                DocumentPackage parent, string packageType)
        {
            Factory.IsTransactional = true;

            Node node = WType.GetNode(new Node {
                NodeID = NodeType.Picked
            });
            Status status = WType.GetStatus(new Status {
                StatusID = EntityStatus.Active
            });
            DocumentType labelType = WType.GetLabelType(new DocumentType {
                DocTypeID = LabelType.CustomerLabel
            });
            Unit logisticUnit = WType.GetUnit(new Unit {
                Company = document.Company, Name = WmsSetupValues.CustomUnit
            });
            Bin destLocation = WType.GetBin(new Bin {
                Location = document.Location, BinCode = DefaultBin.PICKING
            });

            int sequence = Factory.DaoDocumentPackage().Select(new DocumentPackage
            {
                Document = document,
                //PostingDocument = new Document {DocID = -1 }
            }).Count + 1;

            //Generate new logistig labels located in MAIN
            //Labels shouldbe activated the next transaction
            try
            {
                //Funcion para obtener siguiente Label
                //DocumentTypeSequence initSequence = GetNextDocSequence(document.Company, labelType);

                Label packLabel = new Label();
                packLabel.Node             = node;
                packLabel.Bin              = destLocation;
                packLabel.CreatedBy        = picker.UserName;
                packLabel.Status           = status;
                packLabel.LabelType        = labelType;
                packLabel.CreationDate     = DateTime.Now;
                packLabel.Printed          = false;
                packLabel.Unit             = logisticUnit;
                packLabel.IsLogistic       = true;
                packLabel.LabelCode        = ""; // initSequence.NumSequence.ToString() + GetRandomHex(picker.UserName, initSequence.NumSequence);
                packLabel.Notes            = "Package label for Document # " + document.DocNumber;
                packLabel.ShippingDocument = document;

                //Added on 14/ENE/09
                if (parent != null && parent.PackLabel != null && parent.PackLabel.LabelID != 0)
                {
                    try { packLabel.FatherLabel = parent.PackLabel; }
                    catch { }
                }



                //Creado el document Package Asociado al Label
                DocumentPackage docPack = new DocumentPackage
                {
                    Document     = document,
                    CreatedBy    = picker.UserName,
                    CreationDate = DateTime.Now,
                    IsClosed     = !isOpen,
                    PackLabel    = packLabel,
                    Picker       = picker,
                    StartTime    = DateTime.Now,
                    EndTime      = DateTime.Now,
                    Sequence     = (short)sequence,
                    Dimension    = "",
                    ShipToName   = document.Customer.Name,
                    //Added on 14/ENE/09
                    ParentPackage = (parent != null && parent.PackID != 0) ? parent : null,
                    PackageType   = packageType
                };

                //Address Line for package 16/oct/09

                DocumentAddress ShipTo_address = null;
                try
                {
                    ShipTo_address = Factory.DaoDocumentAddress().Select(
                        new DocumentAddress
                    {
                        Document    = document,
                        AddressType = AddressType.Shipping
                    })
                                     .Where(f => f.DocumentLine == null).First();

                    docPack.AddressLine1 = ShipTo_address.AddressLine1 + " " + ShipTo_address.AddressLine2;
                    docPack.AddressLine2 = ShipTo_address.City + ", " + ShipTo_address.State + " " + ShipTo_address.ZipCode;
                    docPack.AddressLine3 = ShipTo_address.Country;
                }
                catch { }

                packLabel.DocumentPackages = new List <DocumentPackage> {
                    docPack
                };
                packLabel           = Factory.DaoLabel().Save(packLabel);
                packLabel.LabelCode = packLabel.LabelID.ToString();

                //Registra el movimiento del nodo

                SaveNodeTrace(
                    new NodeTrace
                {
                    Node      = node,
                    Document  = document,
                    Label     = packLabel,
                    Quantity  = packLabel.CurrQty,
                    IsDebit   = false,
                    CreatedBy = picker.UserName
                }
                    );

                //initSequence.NumSequence;
                //Factory.DaoDocumentTypeSequence().Update(initSequence);
                Factory.Commit();


                //actualizando el documento
                try
                {
                    if (string.IsNullOrEmpty(document.UserDef3))
                    {
                        //document.UserDef3 = picker.UserName;
                        Factory.DaoDocument().Update(document);
                    }
                }
                catch { }

                return(docPack);
            }
            catch { throw; }
        }