Exemplo n.º 1
0
        /// <summary>
        /// Obtem os dados para criar um novo Pedido de Venda e Nota Fiscal (Rascunho).
        /// </summary>
        /// <returns></returns>
        public static List <T32Entity> GetNewORDR()
        {
            var t32list = new List <T32Entity>();

            using (var rs_lines = new MyRecordSet())
            {
                rs_lines.DoQuery("SELECT * FROM [Sage_Transacoes32L1] WITH (NOLOCK)  WHERE ReadBySAP <> 'Y' AND (ORDR_DocEntry <= 0 OR ORDR_DocEntry IS NULL) ORDER BY JOMAR_OrderNum ASC");

                var t32     = new T32Entity();
                var t32line = new T32EntityLine();

                var control = -1;
                while (rs_lines.HasNext())
                {
                    try
                    {
                        if (control == -1)                                              // Controle Inicial
                        {
                            control = rs_lines.GetFieldValue("JOMAR_OrderNum").ToInt(); // Nº da ordem no controle
                        }
                        else if (control != rs_lines.GetFieldValue("JOMAR_OrderNum").ToInt())
                        {
                            t32list.Add(t32);                                           // Guarda o pacote na lista
                            t32     = new T32Entity();                                  // Cria um novo header
                            control = rs_lines.GetFieldValue("JOMAR_OrderNum").ToInt(); // Nº da ordem no controle
                        }

                        #region Linhas
                        t32line = new T32EntityLine();

                        t32line.Id              = rs_lines.GetFieldValue("JOMAR_OrderNum").ToInt();
                        t32line.JOMAR_OrderNum  = rs_lines.GetFieldValue("JOMAR_OrderNum").ToInt();
                        t32line.ReadBySAP       = rs_lines.GetFieldValue("ReadBySAP").ToChar();
                        t32line.Jomar_LineNum   = rs_lines.GetFieldValue("Jomar_LineNum").ToInt();
                        t32line.ORDR_DocEntry   = rs_lines.GetFieldValue("ORDR_DocEntry").ToInt();
                        t32line.OINV_DocEntry   = rs_lines.GetFieldValue("OINV_DocEntry").ToInt();
                        t32line.OITM_CodeBars   = rs_lines.GetFieldValue("OITM_CodeBars").ToString();
                        t32line.RDR1_Quantity   = rs_lines.GetFieldValue("RDR1_Quantity").ToDouble();
                        t32line.RDR1_WhsCode    = rs_lines.GetFieldValue("RDR1_WhsCode").ToString();
                        t32line.JOMAR_Peso      = rs_lines.GetFieldValue("JOMAR_Peso").ToDouble();
                        t32line.SalesOrderIndex = rs_lines.GetFieldValue("SalesOrderIndex").ToInt();
                        t32line.MSG_SAP         = rs_lines.GetFieldValue("MSG_SAP").ToString();
                        #endregion

                        var rs_header = new MyRecordSet();

                        rs_header.DoQuery("SELECT * FROM [Sage_Transacoes32] WITH (NOLOCK) WHERE JOMAR_OrderNum = '{0}'", rs_lines.GetFieldValue("JOMAR_OrderNum").ToInt());
                        {
                            #region Cabeçalho
                            if (t32line.JOMAR_OrderNum != t32.JOMAR_OrderNum)
                            {
                                t32.Id               = rs_lines.GetFieldValue("JOMAR_OrderNum").ToInt();
                                t32.JOMAR_OrderNum   = rs_header.GetFieldValue("JOMAR_OrderNum").ToInt();
                                t32.ReadBySAP        = rs_header.GetFieldValue("ReadBySAP").ToChar();
                                t32.TransactionType  = rs_header.GetFieldValue("TransactionType").ToInt();
                                t32.JOMAR_OIM        = rs_header.GetFieldValue("JOMAR_OIM").ToInt();
                                t32.ORDR_DocEntry    = rs_header.GetFieldValue("ORDR_DocEntry").ToInt();
                                t32.JOMAR_CardCode   = rs_header.GetFieldValue("JOMAR_CardCode").ToString();
                                t32.ORDR_DocDate     = rs_header.GetFieldValue("ORDR_DocDate").ToDate();
                                t32.ORDR_DocDueDate  = rs_header.GetFieldValue("ORDR_DocDueDate").ToDate();
                                t32.ORDR_TaxDate     = rs_header.GetFieldValue("ORDR_TaxDate").ToDate();
                                t32.ORDR_NumAtCard   = rs_header.GetFieldValue("ORDR_NumAtCard").ToString();
                                t32.ORDR_BplId       = rs_header.GetFieldValue("ORDR_BplId").ToInt();
                                t32.ORDR_Comments    = rs_header.GetFieldValue("ORDR_Comments").ToString();
                                t32.SalesHeaderIndex = rs_header.GetFieldValue("SalesHeaderIndex").ToInt();
                                t32.MSG_SAP          = rs_header.GetFieldValue("MSG_SAP").ToString();
                            }
                            #endregion
                        }

                        t32line.ORDR_DocEntry = t32.ORDR_DocEntry;
                    }
                    catch (Exception ex)
                    {
                        principal.GravaAudit(ex.Message.ToString());
                    }

                    t32.Lines.Add(t32line);
                }

                // Pega o ultimo que sobra
                if (rs_lines.CountLines() > 0)
                {
                    t32list.Add(t32);
                }
            }


            return(t32list);
        }