Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Registra o documento no SBO.
        /// </summary>
        /// <param name="oPedido">Entidade</param>
        /// <exception cref="SAPException">Retorno o erro do SAP em log</exception>
        public void Add(MyLibs.v2.sbo.DI.Documents.Entity.DocumentsEntity oPedido)
        {
            var oDocument = SAPConnection.GetDocument(Table);

            // Header
            oDocument.CardCode   = oPedido.CardCode;
            oDocument.CardName   = oPedido.CardName;
            oDocument.NumAtCard  = oPedido.NumAtCard;
            oDocument.DocDate    = oPedido.DocDate;
            oDocument.DocDueDate = oPedido.DocDueDate;
            oDocument.TaxDate    = oPedido.TaxDate;
            oDocument.Series     = oPedido.Series;

            if (SAPConnection.IsMultiBranchs())
            {
                oDocument.BPL_IDAssignedToInvoice = oPedido.BplId;
            }

            // Lines
            foreach (var line in oPedido.Lines)
            {
                oDocument.Lines.ItemCode        = line.ItemCode;
                oDocument.Lines.Quantity        = line.Quantity;
                oDocument.Lines.DiscountPercent = line.DiscPrcnt;

                if (line.LineNum >= 0)
                {
                    oDocument.Lines.BaseLine  = line.LineNum;
                    oDocument.Lines.BaseType  = (int)oPedido.ObjType;
                    oDocument.Lines.BaseEntry = oPedido.DocNum;
                }

                oDocument.Lines.Add();
            }

            // Footer
            oDocument.DiscountPercent = oPedido.DiscPrcnt;
            oDocument.Comments        = oPedido.Comments;

            if (oDocument.Add() != 0)
            {
                throw new MyLibs.v2.sbo.Register.SAPException(this.GetType(), "0 - Erro ao adicionar um PV");
            }
            else
            {
                oPedido.DocNum = SAPConnection.GetNewKey();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Criação de uma nova Ordem de Produção com os
        /// componentes da estrutura do produto.
        /// </summary>
        /// <param name="tnwo"></param>
        private void OWORWithProductTreeDefault(TWOEntity two)
        {
            try
            {
                var oOWOR = (SAPbobsCOM.ProductionOrders)SAPConnection.DI.GetBusinessObject(BoObjectTypes.oProductionOrders);
                oOWOR.ItemNo = two.OITM_ItemCode;
                oOWOR.ProductionOrderType = two.OWOR_TypeBo;
                oOWOR.Warehouse           = two.OWOR_WareHouse;
                oOWOR.PostingDate         = two.OWOR_PostDate;
                oOWOR.DueDate             = two.OWOR_DueDate;
                if (two.OWOR_OriginNum > 0)
                {
                    oOWOR.ProductionOrderOriginEntry = two.OWOR_OriginNum;
                }
                oOWOR.ProductionOrderStatus = two.OWOR_StatusBo;
                oOWOR.Project         = two.OWOR_Project;
                oOWOR.PlannedQuantity = two.OWOR_PlannedQty < 0 ? -two.OWOR_PlannedQty : two.OWOR_PlannedQty;
                oOWOR.UserFields.Fields.Item("U_ORDER_JOMAR").Value = two.OWOR_U_ORDER_JOMAR;
                oOWOR.Remarks = two.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(two.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 * (two.OWOR_PlannedQty < 0 ? -two.OWOR_PlannedQty : two.OWOR_PlannedQty);
                                oOWOR.Lines.BaseQuantity    = oOITT.Items.Quantity;
                                oOWOR.Lines.Warehouse       = "PP";//oOITT.Items.Warehouse;
                                oOWOR.Lines.UserFields.Fields.Item("U_Line_Jomar").Value = two.OWOR_U_ORDER_JOMAR;
                                oOWOR.Lines.Add();
                            }
                            else
                            {
                                Log.Register("Transação - WO"
                                             , System.Diagnostics.EventLogEntryType.Information
                                             , "Estrutura de Produto {0} : Recurso '{1}' removido da desmontagem."
                                             , two.OITM_ItemCode
                                             , oOITT.Items.ItemCode);
                            }
                        }
                    }
                    else
                    {
                        Log.Register("Transação " + (int)two.TransType
                                     , System.Diagnostics.EventLogEntryType.Information
                                     , "Estrutura de Produto {0} não localizado."
                                     , two.OITM_ItemCode);
                    }
                }

                #region Itens - Não será mais utilizado
                //var t38lista = T38DAO.GetForOWOR(int.Parse(tnwo.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)
                {
                    two.ReadBySAP = 'E';
                    two.MSG_SAP   = SAPConnection.DI.GetLastErrorDescription().Replace("'", "\"");
                    TWODAO.UpdateStatus(two);

                    Log.Register("Transação " + (int)two.TransType, System.Diagnostics.EventLogEntryType.Error
                                 , "ID {0} - {1}", two.Id, two.MSG_SAP);
                    if (SAPConnection.DI.InTransaction)
                    {
                        SAPConnection.DI.EndTransaction(BoWfTransOpt.wf_RollBack);
                    }
                }
                else
                {
                    two.OWOR_DocNum = SAPConnection.GetNewKey();
                    two.ReadBySAP   = 'Y';
                    two.MSG_SAP     = "SUCESSO - Ordem de Produção criado. Número da Ordem: " + SAPConnection.GetNewKey();
                    TWODAO.UpdateStatus(two);

                    // @BFAGUNDES - alterando o Status como 'Liberado'
                    two.OWOR_Status = 'R'; // Release
                    AlterOWORStatus(two);
                }
            }
            catch (Exception ex)
            {
                Log.Register("Transação WO-WO"
                             , System.Diagnostics.EventLogEntryType.Error
                             , "Erro Adicionar OP na ID {0}. {1}"
                             , two.Id
                             , ex.Message);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Criação de uma nova Ordem de Produção com os
        /// componentes da estrutura do produto.
        /// </summary>
        /// <param name="tnwo"></param>
        private void OWORWithProductTreeDefault(TWOEntity two)
        {
            try
            {
                principal.GravaAudit("Inicio AddOP");
                var oOWOR = (SAPbobsCOM.ProductionOrders)SAPConnection.DI.GetBusinessObject(BoObjectTypes.oProductionOrders);
                oOWOR.ItemNo = two.OITM_ItemCode;
                oOWOR.ProductionOrderType = two.OWOR_TypeBo;
                oOWOR.Warehouse           = two.OWOR_WareHouse;
                oOWOR.PostingDate         = two.OWOR_PostDate;
                oOWOR.DueDate             = two.OWOR_DueDate;
                if (two.OWOR_OriginNum > 0)
                {
                    oOWOR.ProductionOrderOriginEntry = two.OWOR_OriginNum;
                }
                oOWOR.ProductionOrderStatus = BoProductionOrderStatusEnum.boposPlanned;
                oOWOR.Project         = two.OWOR_Project;
                oOWOR.PlannedQuantity = two.OWOR_PlannedQty < 0 ? -two.OWOR_PlannedQty : two.OWOR_PlannedQty;
                oOWOR.UserFields.Fields.Item("U_ORDER_JOMAR").Value = two.OWOR_U_ORDER_JOMAR;
                oOWOR.Remarks = two.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(two.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 * (two.OWOR_PlannedQty < 0 ? -two.OWOR_PlannedQty : two.OWOR_PlannedQty);
                                oOWOR.Lines.BaseQuantity    = oOITT.Items.Quantity;
                                oOWOR.Lines.Warehouse       = "PP";//oOITT.Items.Warehouse;
                                oOWOR.Lines.UserFields.Fields.Item("U_Line_Jomar").Value = two.OWOR_U_ORDER_JOMAR;
                                oOWOR.Lines.Add();
                            }
                        }
                    }
                }

                if (oOWOR.Add() != 0)
                {
                    two.ReadBySAP = 'E';
                    two.MSG_SAP   = SAPConnection.DI.GetLastErrorDescription().Replace("'", "\"");
                    principal.GravaAudit(two.MSG_SAP);
                    TWODAO.UpdateStatus(two);

                    if (SAPConnection.DI.InTransaction)
                    {
                        SAPConnection.DI.EndTransaction(BoWfTransOpt.wf_RollBack);
                    }
                }
                else
                {
                    two.OWOR_DocNum = SAPConnection.GetNewKey();
                    two.ReadBySAP   = 'Y';
                    two.MSG_SAP     = "SUCESSO - Ordem de Produção criado. Número da Ordem: " + SAPConnection.GetNewKey();
                    principal.GravaAudit(two.MSG_SAP);
                    TWODAO.UpdateStatusReleased(two, oOWOR);
                    TWODAO.UpdateLineOP(two, oOWOR);
                    TWODAO.UpdateStatus(two);

                    // @BFAGUNDES - alterando o Status como 'Liberado'
                    two.OWOR_Status = 'R'; // Release
                    AlterOWORStatus(two);
                }
                principal.GravaAudit("Termino AddOP");
            }
            catch (Exception ex)
            {
                principal.GravaAudit(ex.Message.ToString());
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Cria um esboço de Nota Fiscal.
        /// </summary>
        /// <param name="t32"></param>
        private void NewOINV(T32Entity t32)
        {
            var oODRF = SAPConnection.GetDocument(SAPConnection.DocsEnum.ODRF);

            oODRF.DocObjectCode = BoObjectTypes.oInvoices;
            oODRF.CardCode      = t32.JOMAR_CardCode;
            //oODRF.NumAtCard = t32.ORDR_NumAtCard;
            oODRF.HandWritten             = BoYesNoEnum.tNO;
            oODRF.BPL_IDAssignedToInvoice = t32.ORDR_BplId;

            //oODRF.Reference1 = t32.JOMAR_OrderNum.ToString();
            oODRF.DocDate    = DateTime.Now;
            oODRF.DocDueDate = DateTime.Now;
            oODRF.TaxDate    = DateTime.Now;

            foreach (var line in t32.Lines)
            {
                oODRF.Lines.ItemCode      = line.OITM_ItemCode;
                oODRF.Lines.Quantity      = line.RDR1_Quantity;
                oODRF.Lines.WarehouseCode = line.RDR1_WhsCode;
                oODRF.Lines.BaseType      = 17;
                oODRF.Lines.BaseEntry     = t32.ORDR_DocEntry;//rs.GetFieldValue("DocNum").ToInt();
                oODRF.Lines.BaseLine      = line.RDR1_LineNum;
                oODRF.Lines.Add();
            }
            //using (var rs = new MyRecordSet())
            //{
            //    rs.DoQuery(Properties.Querys.ItensAberto_RDR1_1, t32.ORDR_DocEntry);
            //    while (rs.HasNext())
            //    {
            //        ////////////////////////////////////
            //        oODRF.Lines.ItemCode = rs.GetFieldValue("ItemCode").ToString();
            //        oODRF.Lines.Quantity = rs.GetFieldValue("diff").ToDouble() < rs.GetFieldValue("Quantity").ToDouble() ;
            //        //oODRF.Lines.Price = rs.GetFieldValue("Price").ToDouble();
            //        //oODRF.Lines.WarehouseCode = rs.GetFieldValue("WhsCode").ToString();
            //        oODRF.Lines.BaseType = rs.GetFieldValue("ObjType").ToInt();
            //        oODRF.Lines.BaseEntry = t32.ORDR_DocEntry;//rs.GetFieldValue("DocNum").ToInt();
            //        oODRF.Lines.BaseLine = rs.GetFieldValue("LineNum").ToInt();
            //        oODRF.Lines.Add();
            //    }
            //}

            oODRF.SalesPersonCode = t32.JOMAR_OIM;

            if (oODRF.Add() != 0)
            {
                t32.ReadBySAP = 'E';
                t32.MSG_SAP   = SAPConnection.DI.GetLastErrorDescription();

                foreach (var line in t32.Lines)
                {
                    line.ReadBySAP = 'E';

                    using (var rs = new MyRecordSet())
                    {
                        rs.DoQuery("SELECT TrgetEntry FROM RDR1 WHERE TargetType = '13' AND LineNum = '{0}' AND DocEntry = '{1}'", line.Jomar_LineNum, t32.ORDR_DocEntry);
                        if (rs.HasNext())
                        {
                            line.OINV_DocEntry = rs.GetFieldValue("TrgetEntry").ToInt();
                            line.ReadBySAP     = 'Y';
                        }
                        else
                        {
                            line.OINV_DocEntry = 0;
                        }
                    }

                    line.OINV_DocEntry = 0;
                    line.MSG_SAP       = SAPConnection.DI.GetLastErrorDescription();
                }

                T32DAO.UpdateStatus(t32, true);

                if (SAPConnection.DI.InTransaction)
                {
                    SAPConnection.DI.EndTransaction(BoWfTransOpt.wf_RollBack);
                }
            }
            else
            {
                var oinv = SAPConnection.GetNewKey();
                var msg  = "SUCESSO - Nota Fiscal Criada com sucesso.";
                foreach (var line in t32.Lines)
                {
                    line.ReadBySAP     = 'Y';
                    line.OINV_DocEntry = oinv;
                    line.MSG_SAP       = msg;
                }

                T32DAO.UpdateStatus(t32, true);
            }
        }