Beispiel #1
0
        /// <summary>
        /// Retorna as entidades de transações não lida pelo SAP.
        /// </summary>
        /// <returns></returns>
        public static List <T08Entity> GetForOWOR()
        {
            var transacoes = new List <T08Entity>();

            using (var conn = new ConnSqlServer())
            {
                conn.DoQuery(Properties.Querys.Transacao_n08OWOR_0);
                while (conn.HasNext())
                {
                    var trans = new T08Entity();

                    try
                    {
                        trans.OWOR_Type          = 'D'; // Desmontagem
                        trans.TransType          = conn.GetFieldValue("TransactionType").ToInt();
                        trans.OWOR_U_ORDER_JOMAR = conn.GetFieldValue("OWOR_ORDER_JOMAR").ToString();
                        trans.OITM_CodeBars      = conn.GetFieldValue("OITM_CodeBars").ToString();
                        trans.OWOR_PlannedQty    = conn.GetFieldValue("OWOR_PlannedQty").ToDouble();
                        trans.OWOR_WareHouse     = conn.GetFieldValue("OWOR_WareHouse").ToString();
                        trans.OWOR_PostDate      = DateTime.Now;
                        trans.OWOR_DueDate       = DateTime.Now;
                        trans.GroupID            = conn.GetFieldValue("GroupID").ToInt();
                        trans.GroupUnique        = conn.GetFieldValue("GroupUnique").ToString();
                        trans.OWOR_Remarks       = "Transação -08 GroupID : " + conn.GetFieldValue("GroupID").ToString();

                        principal.GravaAudit("Jomar " + trans.OWOR_U_ORDER_JOMAR.ToString());
                        if (MyQuery.Exist("OITT", trans.OITM_ItemCode, "Code"))
                        {
                            if ((Program.contador % 2) == 0)
                            {
                                if (trans.ReadBySAP != 'E')
                                {
                                    transacoes.Add(trans);
                                }
                            }
                            else
                            {
                                transacoes.Add(trans);
                            }
                        }
                        else
                        {
                            throw new Exception(String.Format("Não existe estrutura de produto cadastrado para ItemCode \"{0}\".", trans.OITM_ItemCode));
                        }
                    }
                    catch (Exception ex)
                    {
                        trans.ReadBySAP = 'E';
                        trans.MSG_SAP   = ex.Message;
                        trans.GroupID   = 0;
                        UpdateStatus(trans);

                        principal.GravaAudit("Transação -8 Erro empacotar : " + ex.Message.ToString());
                    }
                }
            }


            return(transacoes);
        }
Beispiel #2
0
        /// <summary>
        /// Cria saída de Produtos acabados.
        /// </summary>
        /// <param name="t08"></param>
        private void NewOIGE(T08Entity t08)
        {
            try
            {
                var Inventory = SAPConnection.GetDocument(SAPConnection.DocsEnum.OIGE);

                // HEADER
                Inventory.DocDate = t08.OWOR_PostDate;
                //Inventory.TaxDate = tn08.OWOR_PostDate;
                Inventory.BPL_IDAssignedToInvoice = 1;
                //Inventory.Lines.Price = 10;
                Inventory.Lines.ItemCode      = "";// tn08.OITM_ItemCode;
                Inventory.Lines.Quantity      = t08.IGN1_Quantity;
                Inventory.Lines.WarehouseCode = t08.OWOR_WareHouse;
                //Inventory.Lines.UserFields.Fields.Item("U_Lot").Value = t08.IGN1_U_Lot;
                Inventory.Lines.BaseEntry = t08.OWOR_DocNum;
                Inventory.Lines.BaseType  = (int)SAPConnection.DocsEnum.OWOR;
                Inventory.Lines.Add();

                //FOOTER
                Inventory.Comments = t08.OWOR_Remarks;

                int res = Inventory.Add();

                if (res != 0)
                {
                    t08.MSG_SAP   = SAPConnection.DI.GetLastErrorDescription();
                    t08.ReadBySAP = 'E';
                    T08DAO.UpdateStatus(t08);

                    principal.GravaAudit(SAPConnection.DI.GetLastErrorDescription().ToString());
                }
                else
                {
                    var docnum = SAPConnection.DI.GetNewObjectKey();

                    if (int.Parse(docnum) == 0) // Estava dando erro ao recuperar o DocEntry
                    {
                        t08.OIGE_DocNum = int.Parse(docnum);
                    }
                    else
                    {
                        t08.OIGE_DocNum = 999999; // Somente para verificar se houver falha.
                    }
                    t08.ReadBySAP = 'Y';
                    t08.MSG_SAP   = "SUCESSO - Saída do produto efetuada.";
                    T08NegDAO.UpdateStatus(t08);
                }
            }
            catch (Exception ex)
            {
                principal.GravaAudit("Transação " + t08.TransType.ToString() + " " + ex.Message.ToString());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Cria nova Entrada de Produtos acabados.
        /// </summary>
        /// <param name="t08"></param>
        private void NewOIGN(T08Entity t08)
        {
            try
            {
                var Inventory = SAPConnection.GetDocument(SAPConnection.DocsEnum.OIGN);

                // HEADER
                Inventory.DocDate = t08.OWOR_PostDate;
                //Inventory.TaxDate = tn08.OWOR_PostDate;
                Inventory.BPL_IDAssignedToInvoice = 1;
                //Inventory.Lines.Price = 10;
                //Inventory.Lines.ItemCode = tn08.OITM_ItemCode;
                Inventory.Lines.Quantity = t08.IGN1_Quantity;
                principal.GravaAudit(t08.IGN1_WhsCode);
                principal.GravaAudit(t08.OWOR_DocNum.ToString());
                Inventory.Lines.WarehouseCode = t08.IGN1_WhsCode;
                Inventory.Lines.UserFields.Fields.Item("U_Lot").Value = t08.IGN1_U_Lot;
                Inventory.Lines.BaseEntry = t08.OWOR_DocNum;
                Inventory.Lines.BaseType  = (int)SAPConnection.DocsEnum.OWOR;
                Inventory.Lines.Add();

                //FOOTER
                Inventory.Comments = t08.OIGN_Comments;

                int res = Inventory.Add();

                if (res != 0)
                {
                    t08.MSG_SAP   = SAPConnection.DI.GetLastErrorDescription();
                    t08.ReadBySAP = 'E';
                    principal.GravaAudit(t08.MSG_SAP);
                    T08DAO.UpdateStatus(t08);

                    principal.GravaAudit(SAPConnection.DI.GetLastErrorDescription().ToString());
                }
                else
                {
                    var docnum = SAPConnection.DI.GetNewObjectKey();
                    t08.OIGN_DocNum = int.Parse(docnum);
                    t08.ReadBySAP   = 'Y';
                    t08.MSG_SAP     = "SUCESSO - Entrada de produto acabado inserido.";
                    principal.GravaAudit(t08.MSG_SAP);
                    T08DAO.UpdateStatus(t08);
                }
            }
            catch (Exception ex)
            {
                principal.GravaAudit("Transação " + t08.TransType.ToString() + " " + ex.Message);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Atualiza o Status do pedido na tabela de transações 08
 /// </summary>
 /// <param name="t38"></param>
 public static void UpdateStatus(T08Entity t08)
 {
     if (t08.Id == 0)
     {
         T08NegDAO.UpdateStatus(t08);
     }
     else
     {
         using (var rs = new MyRecordSet())
         {
             var sql = "UPDATE [Sage_Transaction08] SET ReadBySAP = '{0}', OWOR_DocNum = '{1}',[MSG_SBO] = '{3}', OIGN_DocNum = '{4}', GroupID = '{5}' WHERE Id = '{2}'";
             rs.DoQuery(sql, t08.ReadBySAP, t08.OWOR_DocNum, t08.Id, t08.MSG_SAP.Replace("'", "''"), t08.OIGN_DocNum, t08.GroupID);
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// Alterar o Status do Pedido.
        /// </summary>
        /// <param name="tn08"></param>
        private void AlterOWORStatus(T08Entity t08)
        {
            try
            {
                var oOWOR = (SAPbobsCOM.ProductionOrders)SAPConnection.DI.GetBusinessObject(BoObjectTypes.oProductionOrders);
                if (!oOWOR.GetByKey(t08.OWOR_DocNum))
                {
                    t08.ReadBySAP   = 'E';
                    t08.MSG_SAP     = String.Format(Properties.LogMessage.Trans08_0034_2, t08.Id, t08.OWOR_DocNum);
                    t08.OWOR_Status = 'P';
                    T08DAO.UpdateStatus(t08);

                    principal.GravaAudit("AlterOWORStatus " + Properties.LogMessage.Trans08_0034_2.ToString() + " " + t08.Id.ToString() + t08.OWOR_DocNum.ToString());

                    return;
                }

                oOWOR.ProductionOrderStatus = t08.OWOR_StatusBo;

                if (oOWOR.Update() != 0)
                {
                    t08.ReadBySAP   = 'E';
                    t08.MSG_SAP     = String.Format(Properties.LogMessage.Trans08_0035_3, t08.Id, t08.OWOR_DocNum, SAPConnection.DI.GetLastErrorDescription());
                    t08.OWOR_Status = 'P';
                    T08DAO.UpdateStatus(t08);


                    principal.GravaAudit("AlterOWORStatus " + t08.MSG_SAP.ToString());
                }
                else
                {
                    t08.ReadBySAP = 'Y';
                    t08.MSG_SAP   = "SUCESSO - Ordem de Produção liberada";
                    T08DAO.UpdateStatus(t08);
                }
            }
            catch (Exception ex)
            {
                principal.GravaAudit("Transação 8 - Erro Atualizar Status OP na ID " + t08.Id.ToString() + " " + ex.Message.ToString());
            }
        }
Beispiel #6
0
        /// <summary>
        /// Atualiza o Status do pedido na tabela de transações 08
        /// </summary>
        /// <param name="t38"></param>
        public static void UpdateStatus(T08Entity t08)
        {
            using (var rs = new MyRecordSet())
            {
                if (t08.Id == 0)
                {
                    var sql = @"
UPDATE   [Sage_Transaction08] 
SET      ReadBySAP = '{0}'
        ,OWOR_DocNum = '{1}'
        ,[MSG_SBO] = '{3}'
        , OIGN_DocNum = '{4}' 
        , GroupID = '{5}'
        , OIGE_DocNum = '{6}' 
WHERE (CAST(TransactionType as nvarchar(100)) 
		+	CAST(OWOR_ORDER_JOMAR as nvarchar(100)) 
		+	CAST(OITM_CodeBars AS nvarchar(20))
		+	CAST(OWOR_DocNum AS nvarchar(20))
		+	OWOR_WareHouse) = '{2}'"            ;
                    rs.DoQuery(sql, t08.ReadBySAP, t08.OWOR_DocNum, t08.GroupUnique, t08.MSG_SAP.Replace("'", "''"), t08.OIGN_DocNum, t08.GroupID, t08.OIGE_DocNum);
                }
                else
                {
                    var sql = @"
UPDATE   [Sage_Transaction08] 
SET      ReadBySAP = '{0}'
        ,OWOR_DocNum = '{1}'
        ,[MSG_SBO] = '{3}'
        , OIGN_DocNum = '{4}' 
        , GroupID = '{5}'
        ,OIGE_DocNum = '{6}' 
WHERE Id = {2}";
                    rs.DoQuery(sql, t08.ReadBySAP, t08.OWOR_DocNum, t08.Id, t08.MSG_SAP.Replace("'", "''"), t08.OIGN_DocNum, t08.GroupID, t08.OIGE_DocNum);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Criação de uma nova Orderm de Produção com os
        /// componente da estrutura do produto.
        /// </summary>
        /// <param name="tn08"></param>
        private void OWORWithProductTreeDefault(T08Entity t08)
        {
            try
            {
                var oOWOR = (SAPbobsCOM.ProductionOrders)SAPConnection.DI.GetBusinessObject(BoObjectTypes.oProductionOrders);
                oOWOR.ItemNo = t08.OITM_ItemCode;
                oOWOR.ProductionOrderType = t08.OWOR_TypeBo;
                oOWOR.Warehouse           = t08.OWOR_WareHouse;
                oOWOR.PostingDate         = t08.OWOR_PostDate;
                oOWOR.DueDate             = t08.OWOR_DueDate;
                if (t08.OWOR_OriginNum > 0)
                {
                    oOWOR.ProductionOrderOriginEntry = t08.OWOR_OriginNum;
                }
                oOWOR.ProductionOrderStatus = t08.OWOR_StatusBo;
                oOWOR.Project         = t08.OWOR_Project;
                oOWOR.PlannedQuantity = t08.OWOR_PlannedQty < 0 ? -t08.OWOR_PlannedQty : t08.OWOR_PlannedQty;
                oOWOR.UserFields.Fields.Item("U_ORDER_JOMAR").Value = t08.OWOR_U_ORDER_JOMAR;
                oOWOR.Remarks = t08.OWOR_Remarks;

                // Desmontagem - Os itens deverão ser informado manualmente.
                if (oOWOR.ProductionOrderType == BoProductionOrderTypeEnum.bopotDisassembly)
                {
                    var oOITT = (SAPbobsCOM.ProductTrees)SAPConnection.DI.GetBusinessObject(BoObjectTypes.oProductTrees);

                    if (oOITT.GetByKey(t08.OITM_ItemCode))
                    {
                        for (int i = 0; i < (oOITT.Items.Count - 1); i++)
                        {
                            oOITT.Items.SetCurrentLine(i);

                            // Desmontagem - Não é permitido inserir recurso.
                            if (oOITT.Items.ItemType == ProductionItemType.pit_Item)
                            {
                                oOWOR.Lines.ItemNo          = oOITT.Items.ItemCode;
                                oOWOR.Lines.ItemType        = oOITT.Items.ItemType;
                                oOWOR.Lines.PlannedQuantity = oOITT.Items.Quantity * (t08.OWOR_PlannedQty < 0 ? -t08.OWOR_PlannedQty : t08.OWOR_PlannedQty);
                                oOWOR.Lines.BaseQuantity    = oOITT.Items.Quantity;
                                oOWOR.Lines.Warehouse       = oOITT.Items.Warehouse;
                                oOWOR.Lines.UserFields.Fields.Item("U_Line_Jomar").Value = t08.OWOR_U_ORDER_JOMAR;
                                oOWOR.Lines.Add();
                            }
                            else
                            {
                                principal.GravaAudit("Transação -8 - Estrutura de Produto {0} : Recurso '{1}' removido da desmontagem." + t08.OITM_ItemCode.ToString() + oOITT.Items.ItemCode.ToString());
                            }
                        }
                    }
                    else
                    {
                        principal.GravaAudit("Transação " + t08.TransType.ToString() + " Estrutura de Produto {0} não localizado." + t08.OITM_ItemCode.ToString());
                    }
                }

                #region Itens - Não será mais utilizado
                //var t38lista = T38DAO.GetForOWOR(int.Parse(tn08.OWOR_U_ORDER_JOMAR));
                //int pos = 0;
                //foreach (var t38 in t38lista)
                //{
                //    if (oODRF.ProductionOrderType != BoProductionOrderTypeEnum.bopotSpecial)
                //        oODRF.ProductionOrderType = BoProductionOrderTypeEnum.bopotSpecial;
                //    var a = oODRF.Lines.Count;
                //    oODRF.Lines.SetCurrentLine(pos++);
                //    oODRF.Lines.ItemNo = t38.OITM_ItemCode;
                //    oODRF.Lines.ItemType = t38.ItemTypeBo;
                //    oODRF.Lines.PlannedQuantity = t38.WOR1_PlannedQty;
                //    oODRF.Lines.BaseQuantity = t38.WOR1_BaseQty;
                //    oODRF.Lines.Warehouse = t38.WOR1_WareHouse;
                //    oODRF.Lines.UserFields.Fields.Item("U_Line_Jomar").Value = t38.JOMAR_LineNum;
                //    oODRF.Lines.Add();
                //}
                #endregion

                if (oOWOR.Add() != 0)
                {
                    t08.ReadBySAP = 'E';
                    t08.GroupID   = 0;
                    t08.MSG_SAP   = SAPConnection.DI.GetLastErrorDescription().Replace("'", "\"");
                    T08DAO.UpdateStatus(t08);

                    principal.GravaAudit("Transação " + t08.TransType.ToString() + " " + t08.Id.ToString(), t08.MSG_SAP.ToString());
                    if (SAPConnection.DI.InTransaction)
                    {
                        SAPConnection.DI.EndTransaction(BoWfTransOpt.wf_RollBack);
                    }
                }
                else
                {
                    t08.OWOR_DocNum = SAPConnection.GetNewKey();
                    t08.ReadBySAP   = 'Y';
                    t08.MSG_SAP     = "SUCESSO - Ordem de Produção criado com o grupo " + t08.GroupID;
                    T08DAO.UpdateStatus(t08);

                    // @BFAGUNDES - alterando o Status como 'Liberado'
                    t08.OWOR_Status = 'R'; // Release
                    AlterOWORStatus(t08);
                }
            }
            catch (Exception ex)
            {
                principal.GravaAudit("Transação 8 - Erro Adicionar OP na ID " + t08.Id.ToString() + " " + ex.Message, ToString());
            }
        }
Beispiel #8
0
        /// <summary>
        /// Retorna as entidades de transações não lida pelo SAP.
        /// </summary>
        /// <param name="isnew">Buscar somente novas entradas?</param>
        /// <returns></returns>
        public static List <T08Entity> GetDados(bool isnew)
        {
            var transacoes = new List <T08Entity>();

            using (var conn = new ConnSqlServer())
            {
                if (isnew) // TODO @BFAGUNDES -
                {
                    conn.DoQuery("SELECT Sage_Transaction08.*, OWOR.DocNum FROM [dbo].[Sage_Transaction08] WITH (NOLOCK) INNER JOIN OWOR ON Sage_Transaction08.OWOR_ORDER_JOMAR = OWOR.U_ORDER_JOMAR WHERE [TransactionType] = 8 AND ReadBySAP <> 'Y' AND (OWOR_DocNum IS NULL OR OWOR_DocNum < 1) ORDER BY AddDate ");
                }
                else
                {
                    conn.DoQuery("SELECT Sage_Transaction08.*, OWOR.DocNum FROM [dbo].[Sage_Transaction08] WITH (NOLOCK) INNER JOIN OWOR ON Sage_Transaction08.OWOR_ORDER_JOMAR = OWOR.U_ORDER_JOMAR WHERE [ReadBySAP] <> 'Y' and [TransactionType] = 8 AND (OIGN_DocNum IS NULL OR OIGN_DocNum < 1) ORDER BY AddDate ");
                }

                while (conn.HasNext())
                {
                    var trans = new T08Entity();

                    try
                    {
                        trans.Id                 = conn.GetFieldValue("Id").ToInt();
                        trans.TransType          = conn.GetFieldValue("TransactionType").ToInt();
                        trans.ReadBySAP          = conn.GetFieldValue("ReadBySAP").ToChar();
                        trans.OWOR_U_ORDER_JOMAR = conn.GetFieldValue("OWOR_ORDER_JOMAR").ToString();
                        //tn08.OWOR_Type = conn.GetFieldValue("OWOR_Type").ToChar();
                        trans.OWOR_DocNum     = conn.GetFieldValue("DocNum").ToInt();
                        trans.OITM_CodeBars   = conn.GetFieldValue("OITM_CodeBars").ToString();
                        trans.OWOR_PlannedQty = conn.GetFieldValue("OWOR_PlannedQty").ToDouble();
                        trans.OWOR_WareHouse  = conn.GetFieldValue("OWOR_WareHouse").ToString();
                        trans.OWOR_PostDate   = conn.GetFieldValue("OWOR_PostDate").ToDate();
                        trans.OWOR_DueDate    = conn.GetFieldValue("OWOR_DueDate").ToDate();
                        //t38.OWOR_OriginNum = conn.GetFieldValue("OWOR_OriginNum").ToInt();
                        //t38.OWOR_CardCode = conn.GetFieldValue("OWOR_CardCode").ToString();
                        trans.OWOR_Project  = conn.GetFieldValue("OWOR_Project").ToString();
                        trans.OIGN_DocNum   = conn.GetFieldValue("OIGN_DocNum").ToInt();
                        trans.IGN1_Quantity = conn.GetFieldValue("IGN1_Quantity").ToDouble();
                        trans.IGN1_U_Lot    = conn.GetFieldValue("IGN1_U_Lot").ToString();
                        trans.IGN1_WhsCode  = conn.GetFieldValue("IGN1_WhsCode").ToString();
                        trans.OWOR_Remarks  = trans.OIGN_Comments = String.Format("ID {0} - Transação 8. {1}", trans.Id, conn.GetFieldValue("OWOR_Remarks").ToString());
                        trans.OIGN_Comments = String.Format("ID {0} - Transação 8. {1}", trans.Id, conn.GetFieldValue("OIGN_Comments").ToString());

                        if (MyQuery.Exist("OITT", trans.OITM_ItemCode, "Code"))
                        {
                            if ((Program.contador % 2) == 0)
                            {
                                //if (trans.ReadBySAP != 'E')
                                transacoes.Add(trans);
                            }
                            else
                            {
                                transacoes.Add(trans);
                            }
                        }
                        else
                        {
                            throw new Exception(String.Format("0 - Não existe estrutura de produto cadastrado para ItemCode \"{0}\".", trans.OITM_ItemCode));
                        }
                    }
                    catch (Exception ex)
                    {
                        trans.ReadBySAP = 'E';
                        trans.MSG_SAP   = ex.Message;

                        UpdateStatus(trans);

                        principal.GravaAudit("Transação 8 " + trans.Id.ToString() + " " + ex.Message);
                    }
                }
            }


            return(transacoes);
        }