Exemplo n.º 1
0
 //Constructor
 public Control()
 {
     Factory = new DaoFactory();
     DocMngr = new DocumentMngr();
     LabelMngr = new LabelMngr();
     TranMngr = new TransactionMngr();
     ErpMngr = new ErpDataMngr();
     RptMngr = new ReportMngr();
     BasicMngr = new BasicMngr();
     MsgMngr = new MessageMngr();
     WType = new WmsTypes();
 }
Exemplo n.º 2
0
        //Crea un ajuste de INventario Cuando un Return Contiene Kits
        private void CreateKitAssemblyComponentsAdjustment(Document prDocument, bool ErpConnected)
        {
            Factory.IsTransactional = true;
            TransactionMngr tranMngr = new TransactionMngr();

            //Leer las lineas del Recibo que sean Kits
            IList<DocumentLine> kitLines = Factory.DaoDocumentLine().Select(new DocumentLine { Document = prDocument });

            kitLines = kitLines.Where(f => f.Product.Kit != null && f.Product.Kit.Count > 0 &&
                f.Product.Kit[0].ProductFormula != null && f.Product.Kit[0].ProductFormula.Count > 0).ToList();

            if (kitLines == null || kitLines.Count == 0)
                return;

            try
            {
                //Armar el Header del Ajuste
                Document curDocument = new Document
                {
                    DocType = new DocumentType { DocTypeID = SDocType.InventoryAdjustment },
                    DocConcept = prDocument.DocConcept,
                    CreatedBy = prDocument.CreatedBy,
                    Location = prDocument.Location,
                    Company = prDocument.Company,
                    IsFromErp = false,
                    CrossDocking = false,
                    Comment = "Automatic Adjustment for " + prDocument.CustPONumber,
                    Date1 = DateTime.Now
                };
                DocMngr.CreateNewDocument(curDocument, false);

                //Return  Location
                Label sourceBinLocaton = GetBinLabel(DefaultBin.RETURN, prDocument.Location);
                DocumentLine adjKit = null;
                DocumentLine adjComponent = null;

                //Armar las lineas de los ajuste
                int count = 1;
                foreach (DocumentLine dl in kitLines)
                {
                    //Lineas de Ajuste Negativo
                    adjKit = new DocumentLine
                    {
                        Product = dl.Product,
                        Unit = dl.Product.BaseUnit,
                        Quantity = dl.Quantity,
                        CreatedBy = dl.CreatedBy,
                        LineStatus = dl.LineStatus,
                        IsDebit = true,
                        UnitBaseFactor = dl.Product.BaseUnit.BaseAmount,
                        Document = curDocument,
                        Location = curDocument.Location,
                        LineNumber = count++
                    };

                    adjKit = tranMngr.SaveAdjustmentTransaction(adjKit, sourceBinLocaton, false);

                    if (adjComponent.Note != "Adjust OK.")
                        throw new Exception(adjComponent.Note);



                    //Lineas de Ajuste Positivo

                    if (dl.Product.Kit != null && dl.Product.Kit.Count > 0 &&
                         dl.Product.Kit[0].ProductFormula != null && dl.Product.Kit[0].ProductFormula.Count > 0)
                    {


                        foreach (KitAssemblyFormula formula in dl.Product.Kit[0].ProductFormula)
                        {
                            //Lineas de Ajuste Positivo
                            adjComponent = new DocumentLine
                            {
                                Product = formula.Component,
                                Unit = formula.Component.BaseUnit,
                                Quantity = dl.Quantity * formula.FormulaQty,
                                CreatedBy = dl.CreatedBy,
                                LineStatus = dl.LineStatus,
                                IsDebit = false,
                                UnitBaseFactor = formula.Component.BaseUnit.BaseAmount,
                                Document = curDocument,
                                Location = curDocument.Location,
                                LineNumber = count++
                            };

                            adjComponent = tranMngr.SaveAdjustmentTransaction(adjComponent, sourceBinLocaton, false);

                            if (adjComponent.Note != "Adjust OK.")
                                throw new Exception(adjComponent.Note);

                        }
                    }
                }

                //MAndar el ajuste al ERP. Si hay conexion con el ERP.
                if (ErpConnected)
                    CreateInventoryAdjustment(curDocument,false);

                Factory.Commit();

            }
            catch (Exception ex) {                 
                Factory.Rollback();
                ExceptionMngr.WriteEvent("CreateKitAssemblyComponentsAdjustment", ListValues.EventType.Fatal, ex, null, ListValues.ErrorCategory.Business);

            }

        }