示例#1
0
        /// <summary>
        /// Cria Pedido de Vendo com item genérico.
        /// </summary>
        /// <param name="t32"></param>
        private void NewORDR(T32Entity t32)
        {
            if (!MyQuery.Exist("OITM", Properties.Settings.Default.ItemCodeDefault, "ItemCode"))
            {
                return;
            }

            var oORDR = SAPConnection.GetDocument(SAPConnection.DocsEnum.ORDR);

            oORDR.CardCode  = t32.JOMAR_CardCode;
            oORDR.NumAtCard = t32.ORDR_NumAtCard;
            oORDR.BPL_IDAssignedToInvoice = t32.ORDR_BplId;

            oORDR.Series      = -1;
            oORDR.HandWritten = BoYesNoEnum.tYES;
            oORDR.DocNum      = t32.JOMAR_OrderNum;
            oORDR.Reference1  = t32.JOMAR_OrderNum.ToString();
            oORDR.DocDate     = t32.ORDR_DocDate < (new DateTime(2016, 1, 1)) ? (new DateTime(2016, 1, 1)) : t32.ORDR_DocDate;
            oORDR.DocDueDate  = DateTime.Now;
            oORDR.TaxDate     = t32.ORDR_TaxDate < (new DateTime(2016, 1, 1)) ? (new DateTime(2016, 1, 1)) : t32.ORDR_TaxDate;

            oORDR.Lines.ItemCode      = Properties.Settings.Default.ItemCodeDefault;
            oORDR.Lines.Quantity      = 1;
            oORDR.Lines.Price         = 0;
            oORDR.Lines.WarehouseCode = "EM";
            oORDR.Lines.Add();

            oORDR.SalesPersonCode = t32.JOMAR_OIM;


            if (oORDR.Add() != 0)
            {
                t32.MSG_SAP       = SAPConnection.DI.GetLastErrorDescription();
                t32.ReadBySAP     = 'E';
                t32.ORDR_DocEntry = MyQuery.GetValue("ORDR", t32.JOMAR_OrderNum, "DocNum", "DocEntry").ToInt();
                t32.ReadBySAP     = t32.ORDR_DocEntry > 0 ? 'Y' : 'E';
                T32DAO.UpdateStatus(t32);

                if (SAPConnection.DI.InTransaction)
                {
                    SAPConnection.DI.EndTransaction(BoWfTransOpt.wf_RollBack);
                }
            }
            else
            {
                t32.ORDR_DocEntry = SAPConnection.GetNewKey();
                t32.ReadBySAP     = 'Y';
                t32.MSG_SAP       = "SUCESSO - Pedido de Venda  criado.";
                T32DAO.UpdateStatus(t32);
            }
        }
        /// <summary>
        /// Retorna as entidades de transações não lida pelo SAP.
        /// </summary>
        /// <param name="itemCode">Código do item</param>
        /// <param name="type">Tipo de transação</param>
        /// <returns></returns>
        public static ProductTreeEntity GetDados(string itemCode)
        {
            var prodTree = new ProductTreeEntity();

            using (var conn = new ConnSqlServer())
            {
                var codeBars = MyQuery.GetValue("OITM", itemCode, "ItemCode", "CodeBars");

                conn.DoQuery("SELECT * FROM [Sage_WorkTree] WITH (NOLOCK) WHERE ReadBySAP <> 'Y' AND  OITM_CodeBars = '{0}'", codeBars);

                //if(conn.)


                while (conn.HasNext())
                {
                    prodTree.Id              = conn.GetFieldValue("Id").ToInt();
                    prodTree.AddDate         = conn.GetFieldValue("AddDate").ToDate();
                    prodTree.TransactionType = conn.GetFieldValue("TransactionType").ToInt();
                    prodTree.ReadBySAP       = conn.GetFieldValue("ReadBySAP").ToChar();

                    prodTree.OITM_CodeBars  = conn.GetFieldValue("OITM_CodeBars").ToString();
                    prodTree.OITT_Code      = conn.GetFieldValue("OITT_Code").ToString();
                    prodTree.OITT_Quantity  = conn.GetFieldValue("OITT_Quantity").ToDouble();
                    prodTree.OITT_ToWH      = conn.GetFieldValue("OITT_ToWH").ToString();
                    prodTree.OITT_PriceList = conn.GetFieldValue("OITT_PriceList").ToInt();
                    prodTree.OITT_Project   = conn.GetFieldValue("OITT_Project").ToString();
                    prodTree.OITT_TreeType  = conn.GetFieldValue("OITT_TreeType").ToChar();

                    using (var connLine = new MyLibs.v2.local.DataBase.ConnSqlServer())
                    {
                        var line = new ProductTreeEntityLine();

                        connLine.DoQuery("SELECT * FROM [ProductTreeLine] WHERE ReadBySAP <> 'Y'");

                        line.ITT1_Type       = connLine.GetFieldValue("ITT1_Type").ToInt();
                        line.OITM_CodeBars   = connLine.GetFieldValue("OITM_CodeBars").ToString();
                        line.ITT1_Code       = connLine.GetFieldValue("ITT1_Code").ToString();
                        line.ITT1_Quantity   = connLine.GetFieldValue("ITT1_Quantity").ToDouble();
                        line.ITT1_WareHouse  = connLine.GetFieldValue("ITT1_WareHouse").ToString();
                        line.ITT1_IssuedMthd = connLine.GetFieldValue("ITT1_IssuedMthd").ToChar();
                        line.ITT1_Comment    = connLine.GetFieldValue("ITT1_Comment").ToString();
                        line.ITT1_Price      = connLine.GetFieldValue("ITT1_Price").ToDouble();

                        prodTree.Lines.Add(line);
                    }
                }
            }
            return(prodTree);
        }
        /// <summary>
        /// Retorna as estruturas dos itens não lidas ou com erro.
        /// </summary>
        /// <returns></returns>
        public static List <WorkTreeEntity> GetDados()
        {
            var ListWorkTree = new List <WorkTreeEntity>();

            using (var rs0 = new ConnSqlServer())
            {
                rs0.DoQuery("SELECT * FROM [Sage_WorkTree] WITH (NOLOCK) WHERE ReadBySAP <> 'Y'");

                while (rs0.HasNext())
                {
                    var wte = new WorkTreeEntity();
                    try
                    {
                        // Documento
                        wte.ID_CodeBars    = rs0.GetFieldValue("ID_CodeBars").ToString();
                        wte.OITT_PriceList = rs0.GetFieldValue("OITT_PriceList").ToInt();
                        wte.OITT_Project   = rs0.GetFieldValue("OITT_Project").ToString();
                        wte.OITT_Quantity  = rs0.GetFieldValue("OITT_Quantity").ToDouble();
                        wte.OITT_ToWH      = rs0.GetFieldValue("OITT_ToWH").ToString();
                        wte.ReadBySAP      = rs0.GetFieldValue("ReadBySAP").ToChar();
                        wte.MSG_SAP        = rs0.GetFieldValue("MSG_SAP").ToString();

                        var rs1 = new ConnSqlServer();
                        rs1.DoQuery("SELECT * FROM [Sage_WorkTreeL1] WITH (NOLOCK) WHERE [ID_CodeBars] = '{0}'", wte.ID_CodeBars);
                        while (rs1.HasNext())
                        {
                            var wtl1e = new WorkTreeL1Entity();
                            // Linha
                            //wtl1e.ITT1_ChildNum = rs_header.GetFieldValue("ITT1_ChildNum").ToInt();
                            wtl1e.ITT1_Quantity = rs1.GetFieldValue("ITT1_Quantity").ToDouble();
                            //wtl1e.ITT1_Type = rs_header.GetFieldValue("ITT1_Type").ToInt();
                            wtl1e.OITM_CodeBars = rs1.GetFieldValue("OITM_CodeBars").ToString();


                            if (!MyQuery.Exist("RSD_IsItemOrResource", wtl1e.OITM_CodeBars, "Referencia"))
                            {
                                throw new Exception("Código de barras não cadastrado " + wtl1e.OITM_CodeBars);
                            }

                            if (MyQuery.GetValue("RSD_IsItemOrResource", wtl1e.OITM_CodeBars, "Referencia", "Tipo").ToChar() == 'I')
                            {
                                if (!MyQuery.GetValue("OITM", wtl1e.ITT1_ItemCode, "ItemCode", "InvntItem").ToBoolean())
                                {
                                    wtl1e.ITT1_IssueMthd = 'B';
                                }
                                else
                                {
                                    wtl1e.ITT1_IssueMthd = rs1.GetFieldValue("ITT1_IssueMthd").ToChar();
                                }
                            }
                            else
                            {
                                wtl1e.ITT1_IssueMthd = rs1.GetFieldValue("ITT1_IssueMthd").ToChar();
                            }

                            wtl1e.ITT1_WareHouse = rs1.GetFieldValue("ITT1_WareHouse").ToString();
                            wtl1e.ITT1_Price     = rs1.GetFieldValue("ITT1_Price").ToDouble();

                            wte.Lines.Add(wtl1e);
                        }

                        ListWorkTree.Add(wte);
                    }
                    catch (Exception ex)
                    {
                        wte.ReadBySAP = 'E';
                        wte.MSG_SAP   = ex.Message;
                        WorkTreeDAO.UpdateStatus(wte);

                        Log.Register("WorkTree", System.Diagnostics.EventLogEntryType.Error
                                     , ex.Message);
                    }
                }
            }
            Log.Register("WorkTree", System.Diagnostics.EventLogEntryType.Information, "0 - Foram criados {0} pacotes", ListWorkTree.Count);

            return(ListWorkTree);
        }
        /// <summary>
        /// Retorna as entidades de transações não lida pelo SAP.
        /// </summary>
        /// <param name="JOMAR_OrderNum">Número de Ordem Jomar (0 todos)</param>
        /// <returns></returns>
        public static List<T38Entity> GetDados(int JOMAR_OrderNum = 0)
        {
            var transacoes = new List<T38Entity>();

            using (var conn = new MyRecordSet())
            {
                if(JOMAR_OrderNum > 0)
                    conn.DoQuery("SELECT * FROM [Sage_Transaction38] WITH (NOLOCK) WHERE TransactionType = '-38' AND [JOMAR_OrderNum] = '{0}' AND (WOR1_DocNum IS NULL OR WOR1_DocNum = 0)", JOMAR_OrderNum);
                else
                    conn.DoQuery("SELECT * FROM [Sage_Transaction38] WITH (NOLOCK) WHERE TransactionType = '-38' AND [ReadBySAP] <> 'Y'");

                principal.GravaAudit("Inicio While - 38");
                while (conn.HasNext())
                {
                    var t38 = new T38Entity();
                    try
                    {
                        t38.Id = conn.GetFieldValue("Id").ToInt();
                        t38.AddDate = conn.GetFieldValue("AddDate").ToDate();
                        t38.TransactionType = conn.GetFieldValue("TransactionType").ToInt();
                        t38.ReadBySAP = conn.GetFieldValue("ReadBySAP").ToChar();
                        t38.JOMAR_OrderNum = conn.GetFieldValue("JOMAR_OrderNum").ToString();
                        t38.WOR1_DocNum = conn.GetFieldValue("WOR1_DocNum").ToInt();
                        t38.To_WareHouse = "PP";
                        t38.From_WareHouse = conn.GetFieldValue("WOR1_WareHouse").ToString();
                        t38.OITM_CodeBars = conn.GetFieldValue("OITM_CodeBars").ToString();
                        t38.JOMAR_LineNum = conn.GetFieldValue("JOMAR_LineNum").ToInt();
                        t38.WOR1_BaseQty = conn.GetFieldValue("WOR1_BaseQty").ToDouble();
                        t38.WOR1_PlannedQty = conn.GetFieldValue("WOR1_PlannedQty").ToDouble();
                        t38.IGE1_Quantity= conn.GetFieldValue("IGE1_Quantity").ToDouble();
                        t38.OWOR_DocNum = MyQuery.GetValue("OWOR", t38.JOMAR_OrderNum, "U_ORDER_JOMAR", "DocNum").ToInt();
                        principal.GravaAudit("- 38 - JOMAR_OrderNum " + t38.JOMAR_OrderNum);

                        if (t38.OWOR_DocNum > 0)
                        {
                            if ((Program.contador % 2) == 0)
                            {
                                if (t38.ReadBySAP != 'E')
                                    transacoes.Add(t38);
                            }
                            else
                            {
                                transacoes.Add(t38);
                            }
                        }  

                    } 
                    catch(Exception ex) {
                        t38.ReadBySAP = 'E';
                        t38.MSG_SAP = ex.Message;

                        UpdateStatus(t38);

                        principal.GravaAudit("Transação 38 Erro empacotar ID " + t38.Id.ToString() + " " + ex.Message.ToString());
                    }    

                }

             return transacoes;
            }
        }
        /// <summary>
        /// Retorna as entidades de transações não lida pelo SAP.
        /// </summary>
        /// <param name="type">Tipo de transação</param>
        /// <returns></returns>
        public static List <Transacoes.Entidade.Documents> GetDados(TransEnum type)
        {
            var oDocEntitys = new List <Transacoes.Entidade.Documents>();

            var conn = new MyLibs.v2.local.DataBase.ConnSqlServer();

            conn.DoQuery(Properties.Querys.Transacoes_1, (int)type);

            var oDocEntity = new Transacoes.Entidade.Documents();
            int bplId      = -1;

            try
            {
                while (conn.HasNext())
                {
                    var error = false;

                    try
                    {
                        if (bplId != conn.GetFieldValue("BplId").ToInt())
                        {
                            bplId                     = conn.GetFieldValue("BplId").ToInt();
                            oDocEntity.BplId          = bplId;
                            oDocEntity.MyValues["Id"] = conn.GetFieldValue("Id");

                            oDocEntity.Comments = conn.GetFieldValue("Comments").ToString();
                            oDocEntity.DocDate  = conn.GetFieldValue("DocDate").ToDate();
                            oDocEntity.GroupNum = conn.GetFieldValue("GroupNum").ToInt();
                            oDocEntity.TaxDate  = conn.GetFieldValue("TaxDate").ToDate();

                            var oDocentryLine = new Transacoes.Entidade.DocumentsEntityLine();

                            oDocentryLine.Quantity = conn.GetFieldValue("Quantity").ToDouble();

                            var codebars = conn.GetFieldValue("OITM_CodeBars").ToString();
                            try
                            {
                                oDocentryLine.ItemCode = MyQuery.GetValue("OITM", codebars, "CodeBars", "ItemCode").ToString();
                            }
                            catch
                            {
                                error = true;
                                principal.GravaAudit("Transação " + type.ToString() + " " + Properties.LogMessage.ERRO_TRANS_28_2.ToString() + " " + codebars.ToString());

                                UpdateStatus(oDocEntity, 'E', String.Format(Properties.LogMessage.ERRO_TRANS_28_2
                                                                            , codebars
                                                                            , oDocEntity.MyValues["Id"]));

                                oDocentryLine.ItemCode = null;
                            }

                            oDocentryLine.UserFields["U_Lot"]     = conn.GetFieldValue("U_Lot").ToString();
                            oDocentryLine.UserFields["U_Quality"] = conn.GetFieldValue("U_Quality").ToString();
                            oDocentryLine.WhsCode = conn.GetFieldValue("WareHouse").ToString();

                            oDocentryLine.MyValues["Id"] = conn.GetFieldValue("Id");

                            oDocEntity.Lines.Add(oDocentryLine);
                        }
                        else
                        {
                            var oDocentryLine = new Transacoes.Entidade.DocumentsEntityLine();

                            oDocentryLine.MyValues["Id"] = conn.GetFieldValue("Id");
                            oDocentryLine.Quantity       = conn.GetFieldValue("Quantity").ToDouble();
                            var codebars = conn.GetFieldValue("OITM_CodeBars").ToString();

                            try
                            {
                                oDocentryLine.ItemCode = MyQuery.GetValue("OITM", codebars, "CodeBars", "ItemCode").ToString();
                            }
                            catch
                            {
                                error = true;
                                principal.GravaAudit("Transação " + type.ToString() + " " + Properties.LogMessage.ERRO_TRANS_28_2.ToString() + " " + codebars.ToString());

                                UpdateStatus(oDocEntity, 'E', String.Format(Properties.LogMessage.ERRO_TRANS_28_2
                                                                            , codebars
                                                                            , oDocEntity.MyValues["Id"].ToInt()));

                                oDocentryLine.ItemCode = null;
                            }

                            oDocentryLine.UserFields["U_Lot"]     = conn.GetFieldValue("U_Lot").ToString();
                            oDocentryLine.UserFields["U_Quality"] = conn.GetFieldValue("U_Quality").ToString();
                            oDocentryLine.WhsCode = conn.GetFieldValue("WareHouse").ToString();

                            oDocEntity.Lines.Add(oDocentryLine);
                        }
                    }catch (Exception ex)
                    {
                        error = true;
                        UpdateStatus(oDocEntity, 'E', ex.Message);
                    }

                    if (!error)
                    {
                        oDocEntitys.Add(oDocEntity);
                    }

                    oDocEntity = new Transacoes.Entidade.Documents();
                }
            }
            catch (Exception ex)
            {
                principal.GravaAudit("Transação " + type.ToString() + " " + ex.Message.ToString());
            }

            return(oDocEntitys);
        }
示例#6
0
        /// <summary>
        /// Retorna as entidades de transações não lida pelo SAP.
        /// </summary>
        /// <param name="JOMAR_OrderNum">Número de Ordem Jomar (0 todos)</param>
        /// <returns></returns>
        public static List <T38Entity> GetDados(int JOMAR_OrderNum = 0)
        {
            var transacoes = new List <T38Entity>();

            using (var conn = new MyRecordSet())
            {
                if (JOMAR_OrderNum > 0)
                {
                    conn.DoQuery("SELECT * FROM [Sage_Transaction38] WITH (NOLOCK) WHERE TransactionType = '38' AND [JOMAR_OrderNum] = '{0}' AND (WOR1_DocNum IS NULL OR WOR1_DocNum = 0)", JOMAR_OrderNum);
                }
                else
                {
                    conn.DoQuery("SELECT * FROM [Sage_Transaction38] T0 WITH (NOLOCK) inner join OITM T1 on T1.CodeBars = T0.oitm_Codebars inner join OWOR T3 on T3.U_ORDER_JOMAR = T0.Jomar_OrderNum inner join WOR1 T2 on T2.DocEntry = T3.DocEntry and T2.itemcode = T1.ItemCode WHERE TransactionType = '38' AND [ReadBySAP] <> 'Y' AND (OIGE_DocNum IS NULL OR OIGE_DocNum = 0) order by T0.Jomar_OrderNum "); //(WOR1_DocNum IS NULL OR WOR1_DocNum = 0) AND
                }
                principal.GravaAudit("Inicio While ");
                while (conn.HasNext())
                {
                    var t38 = new T38Entity();
                    try
                    {
                        principal.GravaAudit(conn.GetFieldValue("JOMAR_OrderNum").ToString());
                        t38.Id              = conn.GetFieldValue("Id").ToInt();
                        t38.AddDate         = conn.GetFieldValue("AddDate").ToDate();
                        t38.Update_CodeBars = conn.GetFieldValue("Update_CodeBars").ToChar();
                        t38.TransactionType = conn.GetFieldValue("TransactionType").ToInt();
                        t38.ReadBySAP       = conn.GetFieldValue("ReadBySAP").ToChar();
                        t38.JOMAR_OrderNum  = conn.GetFieldValue("JOMAR_OrderNum").ToString();
                        t38.WOR1_DocNum     = conn.GetFieldValue("WOR1_DocNum").ToInt();
                        t38.To_WareHouse    = "PP";
                        t38.From_WareHouse  = conn.GetFieldValue("WOR1_WareHouse").ToString();
                        t38.OITM_CodeBars   = conn.GetFieldValue("OITM_CodeBars").ToString();
                        t38.JOMAR_LineNum   = conn.GetFieldValue("JOMAR_LineNum").ToInt();
                        t38.WOR1_BaseQty    = conn.GetFieldValue("WOR1_BaseQty").ToDouble();
                        t38.WOR1_PlannedQty = conn.GetFieldValue("WOR1_PlannedQty").ToDouble();
                        t38.IGE1_Quantity   = conn.GetFieldValue("IGE1_Quantity").ToDouble();
                        t38.OWOR_DocNum     = MyQuery.GetValue("OWOR", t38.JOMAR_OrderNum, "U_ORDER_JOMAR", "DocNum").ToInt();

                        principal.GravaAudit("Existe OPs " + t38.OWOR_DocNum);
                        if ((Program.contador % 2) == 0)
                        {
                            //if (t38.ReadBySAP != 'E')
                            transacoes.Add(t38);
                        }
                        else
                        {
                            transacoes.Add(t38);
                        }
                    }
                    catch (Exception ex) {
                        t38.ReadBySAP = 'E';
                        t38.MSG_SAP   = ex.Message;

                        UpdateStatus(t38);

                        principal.GravaAudit("Transação 38 - " + t38.Id.ToString() + " " + ex.Message.ToString());
                    }
                }

                principal.GravaAudit("Termino While");

                return(transacoes);
            }
        }