Example #1
0
        public ActionResult <RetInfo> AutoSendInventary830(bool Force = false, string Idusr = "")
        {
            DateTime StartTime = DateTime.Now;

            try
            {
                if (((DateTime.Now.DayOfWeek == DayOfWeek.Friday ||
                      DateTime.Now.DayOfWeek == DayOfWeek.Saturday ||
                      DateTime.Now.DayOfWeek == DayOfWeek.Sunday
                      ) &&
                     DateTime.Now.Hour > 18) ||
                    Force
                    )
                {
                    string DateLastRep = LastRep();
                    if (string.IsNullOrEmpty(DateLastRep))
                    {
                        EdiRepSent EdiSent = new EdiRepSent()
                        {
                            Tipo   = "830",
                            Fecha  = DateTime.Now.ToString(ApplicationSettings.DateTimeFormat),
                            Log    = "Procesando reporte",
                            Code   = "0",
                            EdiStr = "",
                            HashId = EdiBase.GetHashId()
                        };
                        DbO.EdiRepSent.Add(EdiSent);
                        DbO.SaveChanges();
                        LearRep830 LearRep830O = new LearRep830(ref DbO, ref WmsDb);
                        string     EdiStr      = LearRep830O.AutoSendInventary830(ref EdiSent);
                        SendEdiFtp(EdiStr, "830 de inventario");
                        return(new RetInfo()
                        {
                            CodError = 0,
                            Mensaje = "ok",
                            ResponseTimeSeconds = (DateTime.Now - StartTime).TotalSeconds
                        });
                    }
                    else
                    {
                        DateTime LastDateRep = DateLastRep.ToDateEsp();
                        if ((DateTime.Now - LastDateRep).TotalDays > 4)
                        {
                            int CodUsr =
                                (from U in WmsDb.Usrsystem
                                 where U.Idusr == Idusr
                                 select U.Codusr).Fod();
                            EdiRepSent EdiSent = new EdiRepSent()
                            {
                                Tipo   = "830",
                                Fecha  = DateTime.Now.ToString(ApplicationSettings.DateTimeFormat),
                                Log    = "Procesando reporte",
                                Code   = "0",
                                EdiStr = "",
                                HashId = EdiBase.GetHashId(),
                                CodUsr = CodUsr
                            };
                            DbO.EdiRepSent.Add(EdiSent);
                            DbO.SaveChanges();
                            LearRep830 LearRep830O = new LearRep830(ref DbO, ref WmsDb);
                            string     EdiStr      = LearRep830O.AutoSendInventary830(ref EdiSent);
                            SendEdiFtp(EdiStr, "830 de inventario");
                            return(new RetInfo()
                            {
                                CodError = 0,
                                Mensaje = "ok",
                                ResponseTimeSeconds = (DateTime.Now - StartTime).TotalSeconds
                            });
                        }
                    }
                }
                return(new RetInfo()
                {
                    CodError = 0,
                    Mensaje = "ok",
                    ResponseTimeSeconds = (DateTime.Now - StartTime).TotalSeconds
                });
            }
            catch (Exception e1)
            {
                return(new RetInfo()
                {
                    CodError = -1,
                    Mensaje = e1.ToString(),
                    ResponseTimeSeconds = (DateTime.Now - StartTime).TotalSeconds
                });
            }
        }
Example #2
0
        public string AutoSendInventary830(ref EdiRepSent EdiSent)
        {
            string            ThisDate = DateTime.Now.ToString(ApplicationSettings.ToDateTimeFormat);
            string            ThisTime = DateTime.Now.ToString(ApplicationSettings.ToTimeFormat);
            int               ControlNumber = 1, NSeg = 0;
            IEnumerable <int> IeMaxRep =
                (from Rs in DbO.EdiRepSent
                 where Rs.Tipo == "830"
                 select Convert.ToInt32(Rs.Code));

            if (IeMaxRep.Count() > 0)
            {
                ControlNumber = IeMaxRep.Max() + 1;
            }
            ISAO = new ISA830(EdiBase.SegmentTerminator)
            {
                AuthorizationInformationQualifier = "00",
                AuthorizationInformation          = "          ",
                SecurityInformationQualifier      = "00",
                SecurityInformation            = "          ",
                InterchangeSenderIdQualifier   = "ZZ",
                InterchangeSenderId            = "GLC503         ",
                InterchangeReceiverIdQualifier = "ZZ",
                InterchangeReceiverId          = "ICN3660        ",
                InterchangeDate = ThisDate,
                InterchangeTime = ThisTime,
                InterchangeControlStandardsId = "U",
                InterchangeControlVersion     = "00204",
                AcknowledgmentRequested       = "0",
                UsageIndicator           = "P",
                InterchangeControlNumber = $"{ControlNumber.ToString("D9")}"
            };
            NSeg++;
            GS830 Gs = new GS830(EdiBase.SegmentTerminator)
            {
                FunctionalIdCode        = "PS",
                ApplicationSenderCode   = "GLC503",
                ApplicationReceiverCode = "ICN3660",
                GsDate = ThisDate,
                GsTime = ThisTime,
                ResponsibleAgencyCode = "X",
                Version            = "002040",
                GroupControlNumber = $"{ControlNumber.ToString("D4")}"
            };

            NSeg++;
            //Gs.Parent = ISAO;
            //ISAO.Childs.Add(Gs);
            ISAO.AddParentChild(Gs);
            ST830 St = new ST830(EdiBase.SegmentTerminator)
            {
                IdCode        = "830",
                ControlNumber = $"{ControlNumber.ToString("D4")}"
            };

            NSeg++;
            ISAO.AddParentChild(St);
            BFR830 Bfr = new BFR830(EdiBase.SegmentTerminator)
            {
                TransactionSetPurposeCode = "00",
                ForecastOrderNumber       = "",
                ReleaseNumber             = "0000",
                ForecastTypeQualifier     = "ZZ",
                ForecastQuantityQualifier = "A",
                ForecastHorizonStart      = ThisDate,
                ForecastHorizonEnd        = ThisDate,
                ForecastGenerationDate    = ThisDate,
                ForecastUpdatedDate       = "",
                ContractNumber            = "",
                PurchaseOrderNumber       = ""
            };

            NSeg++;
            St.AddParentChild(Bfr);
            IEnumerable <FE830DataAux>      IeExistencias     = ManualDB.SP_GetExistencias(ref DbO, 618);
            IEnumerable <LearEquivalencias> learEquivalencias = DbO.LearEquivalencias;

            foreach (FE830DataAux Producto in IeExistencias)
            {
                IEnumerable <LearEquivalencias> Exists = learEquivalencias.Where(E => E.CodProducto == Producto.CodProducto ||
                                                                                 E.CodProducto + "-" == Producto.CodProducto);
                if (Exists.Count() == 0)
                {
                    continue;
                }
                LIN830 Lin = new LIN830(EdiBase.SegmentTerminator)
                {
                    AssignedIdentification = "",
                    ProductIdQualifier     = "BP",
                    ProductId                  = Producto.CodProducto,
                    ProductRefIdQualifier      = "",
                    ProductRefId               = "",
                    ProductPurchaseIdQualifier = "",
                    ProductPurchaseId          = "",
                };
                NSeg++;
                St.AddParentChild(Lin);
                UIT830 Uit = new UIT830(EdiBase.SegmentTerminator)
                {
                    UnitOfMeasure = "FT"
                };
                NSeg++;
                Lin.AddParentChild(Uit);
                PRS830 Prs = new PRS830(EdiBase.SegmentTerminator)
                {
                    StatusCode = "9"
                };
                NSeg++;
                Lin.AddParentChild(Prs);
                N1830 N1 = new N1830(EdiBase.SegmentTerminator)
                {
                    OrganizationId  = "ST",
                    Name            = "GLC HONDURAS",
                    IdCodeQualifier = "92",
                    IdCode          = "GLC503"
                };
                NSeg++;
                Lin.AddParentChild(N1);
                N4830 N4 = new N4830(EdiBase.SegmentTerminator)
                {
                    LocationQualifier = "WH",
                    LocationId        = "GLC503"
                };
                NSeg++;
                Lin.AddParentChild(N4);
                SDP830 Sdp = new SDP830(EdiBase.SegmentTerminator)
                {
                    CalendarPatternCode = "Z",
                    PatternTimeCode     = "Z"
                };
                NSeg++;
                Lin.AddParentChild(Sdp);
                FST830 Fst = new FST830(EdiBase.SegmentTerminator)
                {
                    Quantity                = Math.Round(Convert.ToDecimal(Producto.Existencia), 0).ToString(),
                    ForecastQualifier       = "Z",
                    ForecastTimingQualifier = "Z",
                    FstDate = ThisDate
                }; // Solo el monto actual
                NSeg++;
                Sdp.AddParentChild(Fst);
            }
            CTT830 Ctt = new CTT830(EdiBase.SegmentTerminator)
            {
                TotalLineItems = IeExistencias.Count().ToString(),
                HashTotal      = ""
            };

            ISAO.AddParentChild(Ctt);
            SE830 Se = new SE830(EdiBase.SegmentTerminator)
            {
                NumIncludedSegments         = NSeg.ToString(),
                TransactionSetControlNumber = $"{ControlNumber.ToString("D4")}"
            };

            ISAO.AddParentChild(Se);
            GE830 Ge = new GE830(EdiBase.SegmentTerminator)
            {
                NumTransactionSetsIncluded = "1",
                GroupControl = $"{ControlNumber.ToString("D4")}"
            };

            ISAO.AddParentChild(Ge);
            IEA830 Iea = new IEA830(EdiBase.SegmentTerminator)
            {
                NumIncludedGroups        = "1",
                InterchangeControlNumber = $"{ControlNumber.ToString("D9")}"
            };

            ISAO.AddParentChild(Iea);
            string ActualEdiStr = ISAO.Ts();

            EdiSent.Log    = "Reporte enviado";
            EdiSent.Code   = ControlNumber.ToString();
            EdiSent.EdiStr = ActualEdiStr;
            EdiBase E1 = new EdiBase(EdiBase.SegmentTerminator)
            {
                HashId = EdiSent.HashId
            };

            ISAO.Parent = E1;
            ISAO.SaveAll830(ref DbO);
            DbO.EdiRepSent.Update(EdiSent);
            LearPureEdi Pe = new LearPureEdi()
            {
                EdiStr        = ActualEdiStr,
                HashId        = E1.HashId,
                Fingreso      = DateTime.Now.ToString(ApplicationSettings.DateTimeFormat),
                Fprocesado    = DateTime.Now.ToString(ApplicationSettings.DateTimeFormat),
                Reprocesar    = false,
                NombreArchivo = "Inventario",
                Log           = $"{NSeg} segmentos analizados, procesados y guardados",
                CheckSeg      = NSeg,
                Shp           = false,
                InOut         = "O"
            };

            DbO.LearPureEdi.Add(Pe);
            DbO.SaveChanges();
            return(EdiSent.EdiStr);
        }