예제 #1
0
 public ST830(UInt16 _RepType, string _SegmentTerminator, string _ControlNumber = "000000001") : base(_SegmentTerminator)
 {
     RepType = _RepType;
     InitOrden();
     switch (_RepType)
     {
     case 0:
         IdCode        = "830";
         ControlNumber = _ControlNumber;
         StTrailerO    = new SE830(SegmentTerminator);
         break;
     }
 }
예제 #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);
        }
예제 #3
0
        public string Parse()
        {
            string Ident = "";

            ListLIN.Clear();
            ListSDP.Clear();
            ListSHP.Clear();
            ISAO = new ISA830(EdiBase.SegmentTerminator);
            GSO  = new GS830(EdiBase.SegmentTerminator);
            STO  = new ST830(EdiBase.SegmentTerminator);
            string EdiStr = string.Empty;

            for (int Nr = 0; Nr < EdiFile.Count; Nr++)
            {
                EdiStr = EdiFile[Nr];
                Ident  = EdiStr.IndexOf(EdiBase.ElementTerminator) > 0 ? EdiStr.Substring(0, EdiStr.IndexOf(EdiBase.ElementTerminator)) : string.Empty;
                if (Ident != string.Empty)
                {
                    switch (Ident)
                    {
                    case ISA830.Init:
                        if (!ISAO.Parse(EdiStr))
                        {
                            return(ParseMenError1(ISA830.Self, Nr, ISAO.Coli));
                        }
                        break;

                    case GS830.Init:
                        if (string.IsNullOrEmpty(ISAO.EdiStr))
                        {
                            return(ParseMenError2(GS830.Self, ISA830.Self, Nr));
                        }
                        if (!GSO.Parse(EdiStr))
                        {
                            return(ParseMenError1(GS830.Self, Nr, GSO.Coli));
                        }
                        GSO.Parent = ISAO;
                        ISAO.Childs.Add(GSO);
                        break;

                    case ST830.Init:
                        if (string.IsNullOrEmpty(GSO.EdiStr))
                        {
                            return(ParseMenError2(ST830.Self, GS830.Self, Nr));
                        }
                        if (!STO.Parse(EdiStr))
                        {
                            return(ParseMenError1(ST830.Self, Nr, STO.Coli));
                        }
                        STO.Parent = ISAO;
                        ISAO.Childs.Add(STO);
                        break;

                    case BFR830.Init:
                        if (string.IsNullOrEmpty(STO.EdiStr))
                        {
                            return(ParseMenError2(BFR830.Self, ST830.Self, Nr));
                        }
                        BFR830 BFRnp = new BFR830(EdiBase.SegmentTerminator);
                        if (!BFRnp.Parse(EdiStr))
                        {
                            return(ParseMenError1(BFR830.Self, Nr, BFRnp.Coli));
                        }
                        BFRnp.Parent = STO;
                        STO.Childs.Add(BFRnp);
                        break;

                    case NTE830.Init:
                        if (ListLIN.Count == 0)
                        {
                            if (string.IsNullOrEmpty(STO.EdiStr))
                            {
                                return(ParseMenError2(NTE830.Self, ST830.Self, Nr));
                            }
                            NTE830 NTEnp = new NTE830(EdiBase.SegmentTerminator);
                            if (!NTEnp.Parse(EdiStr))
                            {
                                return(ParseMenError1(NTE830.Self, Nr, NTEnp.Coli));
                            }
                            NTEnp.Parent = STO;
                            STO.Childs.Add(NTEnp);
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(ListLIN.LastOrDefault().EdiStr))
                            {
                                return(ParseMenError2(NTE830.Self, LIN830.Self, Nr));
                            }
                            NTE830 NTEnp = new NTE830(EdiBase.SegmentTerminator);
                            if (!NTEnp.Parse(EdiStr))
                            {
                                return(ParseMenError1(NTE830.Self, Nr, NTEnp.Coli));
                            }
                            NTEnp.Parent = ListLIN.LastOrDefault();
                            ListLIN.AddLastChild(NTEnp);
                        }
                        break;

                    case N1830.Init:
                        if (ListLIN.Count == 0)
                        {
                            if (string.IsNullOrEmpty(STO.EdiStr))
                            {
                                return(ParseMenError2(N1830.Self, ST830.Self, Nr));
                            }
                            N1830 N1np = new N1830(EdiBase.SegmentTerminator);
                            if (!N1np.Parse(EdiStr))
                            {
                                return(ParseMenError1(N1830.Self, Nr, N1np.Coli));
                            }
                            N1np.Parent = STO;
                            STO.Childs.Add(N1np);
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(ListLIN.LastOrDefault().EdiStr))
                            {
                                return(ParseMenError2(N1830.Self, LIN830.Self, Nr));
                            }
                            N1830 N1np = new N1830(EdiBase.SegmentTerminator);
                            if (!N1np.Parse(EdiStr))
                            {
                                return(ParseMenError1(N1830.Self, Nr, N1np.Coli));
                            }
                            N1np.Parent = ListLIN.LastOrDefault();
                            ListLIN.AddLastChild(N1np);
                        }
                        break;

                    case N4830.Init:
                        if (ListLIN.Count == 0)
                        {
                            if (string.IsNullOrEmpty(STO.EdiStr))
                            {
                                return(ParseMenError2(N4830.Self, ST830.Self, Nr));
                            }
                            N4830 N4np = new N4830(EdiBase.SegmentTerminator);
                            if (!N4np.Parse(EdiStr))
                            {
                                return(ParseMenError1(N4830.Self, Nr, N4np.Coli));
                            }
                            N4np.Parent = STO;
                            STO.Childs.Add(N4np);
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(ListLIN.LastOrDefault().EdiStr))
                            {
                                return(ParseMenError2(N4830.Self, LIN830.Self, Nr));
                            }
                            N4830 N4np = new N4830(EdiBase.SegmentTerminator);
                            if (!N4np.Parse(EdiStr))
                            {
                                return(ParseMenError1(N4830.Self, Nr, N4np.Coli));
                            }
                            N4np.Parent = ListLIN.LastOrDefault();
                            ListLIN.AddLastChild(N4np);
                        }
                        break;

                    case LIN830.Init:
                        if (string.IsNullOrEmpty(STO.EdiStr))
                        {
                            return(ParseMenError2(LIN830.Self, ST830.Self, Nr));
                        }
                        LIN830 LINnp = new LIN830(EdiBase.SegmentTerminator);
                        if (!LINnp.Parse(EdiStr))
                        {
                            return(ParseMenError1(LIN830.Self, Nr, LINnp.Coli));
                        }
                        LINnp.Parent = STO;
                        STO.Childs.Add(LINnp);
                        ListLIN.Add(LINnp);
                        break;

                    case UIT830.Init:
                        if (ListLIN.Count == 0)
                        {
                            return(ParseMenError2(UIT830.Self, LIN830.Self, Nr));
                        }
                        UIT830 UITnp = new UIT830(EdiBase.SegmentTerminator);
                        if (!UITnp.Parse(EdiStr))
                        {
                            return(ParseMenError1(UIT830.Self, Nr, UITnp.Coli));
                        }
                        UITnp.Parent = ListLIN.LastOrDefault();
                        ListLIN.AddLastChild(UITnp);
                        break;

                    case PRS830.Init:
                        if (ListLIN.Count == 0)
                        {
                            return(ParseMenError2(PRS830.Self, LIN830.Self, Nr));
                        }
                        PRS830 PRSnp = new PRS830(EdiBase.SegmentTerminator);
                        if (!PRSnp.Parse(EdiStr))
                        {
                            return(ParseMenError1(PRS830.Self, Nr, PRSnp.Coli));
                        }
                        PRSnp.Parent = ListLIN.LastOrDefault();
                        ListLIN.AddLastChild(PRSnp);
                        break;

                    case SDP830.Init:
                        if (ListLIN.Count == 0)
                        {
                            return(ParseMenError2(SDP830.Self, LIN830.Self, Nr));
                        }
                        SDP830 SDPnp = new SDP830(EdiBase.SegmentTerminator);
                        if (!SDPnp.Parse(EdiStr))
                        {
                            return(ParseMenError1(SDP830.Self, Nr, SDPnp.Coli));
                        }
                        SDPnp.Parent = ListLIN.LastOrDefault();
                        ListLIN.AddLastChild(SDPnp);
                        ListSDP.Add(SDPnp);
                        break;

                    case FST830.Init:
                        if (ListLIN.Count == 0)
                        {
                            return(ParseMenError2(FST830.Self, LIN830.Self, Nr));
                        }
                        FST830 FSTnp = new FST830(EdiBase.SegmentTerminator);
                        if (!FSTnp.Parse(EdiStr))
                        {
                            return(ParseMenError1(FST830.Self, Nr, FSTnp.Coli));
                        }
                        FSTnp.RealQty = "0";
                        if (ListSDP.Count == 0)
                        {
                            FSTnp.Parent = ListLIN.LastOrDefault();
                            ListLIN.AddLastChild(FSTnp);
                        }
                        else
                        {
                            FSTnp.Parent = ListSDP.LastOrDefault();
                            ListSDP.AddLastChild(FSTnp);
                        }
                        break;

                    case ATH830.Init:
                        if (ListLIN.Count == 0)
                        {
                            return(ParseMenError2(ATH830.Self, LIN830.Self, Nr));
                        }
                        ATH830 ATHnp = new ATH830(EdiBase.SegmentTerminator);
                        if (!ATHnp.Parse(EdiStr))
                        {
                            return(ParseMenError1(ATH830.Self, Nr, ATHnp.Coli));
                        }
                        ATHnp.Parent = ListLIN.LastOrDefault();
                        ListLIN.AddLastChild(ATHnp);
                        break;

                    case SHP830.Init:
                        if (ListLIN.Count == 0)
                        {
                            return(ParseMenError2(SHP830.Self, LIN830.Self, Nr));
                        }
                        SHP830 SHPnp = new SHP830(EdiBase.SegmentTerminator);
                        if (!SHPnp.Parse(EdiStr))
                        {
                            return(ParseMenError1(SHP830.Self, Nr, SHPnp.Coli));
                        }
                        SHPnp.Parent = ListLIN.LastOrDefault();
                        ListLIN.AddLastChild(SHPnp);
                        ListSHP.Add(SHPnp);
                        break;

                    case REF830.Init:
                        if (ListLIN.Count == 0)
                        {
                            return(ParseMenError2(REF830.Self, LIN830.Self, Nr));
                        }
                        REF830 REFnp = new REF830(EdiBase.SegmentTerminator);
                        if (!REFnp.Parse(EdiStr))
                        {
                            return(ParseMenError1(REF830.Self, Nr, REFnp.Coli));
                        }
                        if (ListSHP.Count == 0)
                        {
                            REFnp.Parent = ListLIN.LastOrDefault();
                            ListLIN.AddLastChild(REFnp);
                        }
                        else
                        {
                            REFnp.Parent = ListSHP.LastOrDefault();
                            ListSHP.AddLastChild(REFnp);
                        }
                        break;

                    case CTT830.Init:
                        if (string.IsNullOrEmpty(ISAO.EdiStr))
                        {
                            return(ParseMenError2(CTT830.Self, ISA830.Self, Nr));
                        }
                        CTT830 CTTnp = new CTT830(EdiBase.SegmentTerminator);
                        if (!CTTnp.Parse(EdiStr))
                        {
                            return(ParseMenError1(CTT830.Self, Nr, CTTnp.Coli));
                        }
                        CTTnp.Parent = ISAO;
                        ISAO.Childs.Add(CTTnp);
                        break;

                    case SE830.Init:
                        if (string.IsNullOrEmpty(ISAO.EdiStr))
                        {
                            return(ParseMenError2(SE830.Self, ISA830.Self, Nr));
                        }
                        SE830 SEnp = new SE830(EdiBase.SegmentTerminator);
                        if (!SEnp.Parse(EdiStr))
                        {
                            return(ParseMenError1(SE830.Self, Nr, SEnp.Coli));
                        }
                        SEnp.Parent = ISAO;
                        ISAO.Childs.Add(SEnp);
                        break;

                    case GE830.Init:
                        if (string.IsNullOrEmpty(ISAO.EdiStr))
                        {
                            return(ParseMenError2(GE830.Self, ISA830.Self, Nr));
                        }
                        GE830 GEnp = new GE830(EdiBase.SegmentTerminator);
                        if (!GEnp.Parse(EdiStr))
                        {
                            return(ParseMenError1(GE830.Self, Nr, GEnp.Coli));
                        }
                        GEnp.Parent = ISAO;
                        ISAO.Childs.Add(GEnp);
                        break;

                    case IEA830.Init:
                        if (string.IsNullOrEmpty(ISAO.EdiStr))
                        {
                            return(ParseMenError2(IEA830.Self, ISA830.Self, Nr));
                        }
                        IEA830 IEAnp = new IEA830(EdiBase.SegmentTerminator);
                        if (!IEAnp.Parse(EdiStr))
                        {
                            return(ParseMenError1(IEA830.Self, Nr, IEAnp.Coli));
                        }
                        IEAnp.Parent = ISAO;
                        ISAO.Childs.Add(IEAnp);
                        break;

                    default:
                        return(ParseMenError2("(desconocido)", EdiStr, Nr));
                    }
                }
            }
            return(string.Empty);
        }