/// <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); }
/// <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 <TWOEntity> GetDados(bool isnew) { var transacoes = new List <TWOEntity>(); principal.GravaAudit("MyRecordSet ini"); using (var conn = new MyRecordSet()) { //if (isnew) // TODO @BFAGUNDES - conn.DoQuery("SELECT * FROM [dbo].[Sage_Transaction_WO] WITH (NOLOCK) WHERE [TransactionType] = 40 AND ReadBySAP <> 'Y' AND (OWOR_DocNum IS NULL OR OWOR_DocNum < 1) ORDER BY AddDate"); //else //conn.DoQuery("SELECT TOP 500 * FROM [dbo].[Sage_Transaction_WO] WITH (NOLOCK) WHERE [TransactionType] = 40 AND OWOR_DocNum > 0 ORDER BY ReadBySAP DESC"); while (conn.HasNext()) { var trans = new TWOEntity(); try { trans.TransType = conn.GetFieldValue("TransactionType").ToInt(); trans.ReadBySAP = conn.GetFieldValue("ReadBySAP").ToChar(); trans.OWOR_U_ORDER_JOMAR = conn.GetFieldValue("OWOR_ORDER_JOMAR").ToString(); trans.OWOR_DocNum = conn.GetFieldValue("OWOR_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(); trans.OWOR_Project = conn.GetFieldValue("OWOR_Project").ToString(); trans.OWOR_Remarks = String.Format("ID {0} - Transação 40. {1}", trans.Id, conn.GetFieldValue("OWOR_Remarks").ToString()); if (MyQuery.Exist("OITT", trans.OITM_ItemCode, "Code")) { if ((Program.contador % 2) == 0) { transacoes.Add(trans); } else { transacoes.Add(trans); } } else { principal.GravaAudit("Não existe estrutura de produto cadastrado para ItemCode \"{0}\".", trans.OITM_ItemCode); 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("Erro empacotar ID " + trans.Id.ToString() + " " + ex.Message.ToString()); } } principal.GravaAudit("Termino While"); } return(transacoes); }
/// <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> /// Cria ou atualiza a estrutura de produto, baseada na tabela ProductTree. /// </summary> private bool ProductTree(string itemCode) { var prodTree = ProductTreeDAO.GetDados(itemCode); if (prodTree == null) { principal.GravaAudit(this.GetType().ToString() + " Não existe nenhuma estrutura para ItemCode {0} na tabela [ProductTree] " + itemCode.ToString()); return(true); } var oOITT = (SAPbobsCOM.ProductTrees)SAPConnection.DI.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductTrees); bool is_update; if (MyQuery.Exist("OITT", itemCode, "Code")) { is_update = true; if (!oOITT.GetByKey(itemCode)) { throw new LogException(this.GetType() , System.Diagnostics.EventLogEntryType.Error , Properties.LogMessage.ProductTree_e0021_1 , itemCode); } } else { is_update = false; oOITT.TreeCode = prodTree.OITT_Code; } oOITT.PriceList = prodTree.OITT_PriceList; oOITT.Project = prodTree.OITT_Project; oOITT.Quantity = prodTree.OITT_Quantity; oOITT.TreeType = prodTree.OITT_TreeTypeBo; oOITT.Warehouse = prodTree.OITT_ToWH; foreach (var line in prodTree.Lines) { oOITT.Items.ItemCode = line.ITT1_Code; oOITT.Items.ItemType = line.ITT1_TypeBo; oOITT.Items.Quantity = line.ITT1_Quantity; oOITT.Items.Warehouse = line.ITT1_WareHouse; oOITT.Items.IssueMethod = line.ITT1_IssuedMthdBo; oOITT.Items.PriceList = prodTree.OITT_PriceList; oOITT.Items.Price = line.ITT1_Price; oOITT.Items.Comment = line.ITT1_Comment; oOITT.Items.Add(); } if (is_update) { if (oOITT.Update() != 0) { prodTree.ReadBySAP = 'E'; ProductTreeDAO.UpdateStatus(prodTree); throw new SAPException("OITT" , Properties.LogMessage.ProductTree_e0022_2, "atualização", itemCode); return(false); } } else { if (oOITT.Add() != 0) { prodTree.ReadBySAP = 'E'; ProductTreeDAO.UpdateStatus(prodTree); throw new SAPException("OITT" , Properties.LogMessage.ProductTree_e0022_2, "cadastro", itemCode); return(false); } } prodTree.ReadBySAP = 'Y'; ProductTreeDAO.UpdateStatus(prodTree); prodTree = null; return(true); }
/// <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="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); }