Пример #1
0
        /// <summary>
        /// Transação 98 - Ajuste de Estoque.
        /// Se a coluna quantidade for negativa, trata-se de uma saída de mercadoria,
        /// caso contrário será considerada uma entrada.
        /// </summary>
        private void Trans98()
        {
            var transacoes = TransGenericDAO.GetDadosSL(transType);

            if (transacoes.Count == 0)
            {
                principal.GravaAudit("Transação " + transType.ToString() + " " + ROBO.Properties.LogMessage.TRANS_i0002_G1.ToString());
                return;
            }

            foreach (var transacao in transacoes)
            {
                try
                {
                    Documents Inventory = null;

                    if (transacao.Lines[0].Quantity > 0)
                    {
                        Inventory = SAPConnection.GetDocument(SAPConnection.DocsEnum.OIGN); //Entrada
                    }
                    else if (transacao.Lines[0].Quantity < 0)
                    {
                        Inventory = SAPConnection.GetDocument(SAPConnection.DocsEnum.OIGE); // saida
                    }
                    else
                    {
                        TransGenericDAO.UpdateStatus(transacao, 'E', Properties.LogMessage.Trans_0031_0);
                    }

                    if (Inventory != null)
                    {
                        // HEADER
                        Inventory.DocDate = transacao.DocDate;
                        Inventory.TaxDate = transacao.TaxDate;
                        Inventory.BPL_IDAssignedToInvoice = transacao.BplId;

                        // LINES
                        foreach (var line in transacao.Lines)
                        {
                            Inventory.Lines.ItemCode      = line.ItemCode;
                            Inventory.Lines.Quantity      = line.Quantity < 0 ? -line.Quantity : line.Quantity;
                            Inventory.Lines.WarehouseCode = line.WhsCode;
                            Inventory.Lines.Add();
                        }
                        //FOOTER
                        Inventory.Comments = String.Format("ID {0} - Transação {1}. {2}", transacao.MyValues["Id"].ToInt(), (int)transType, transacao.Comments);

                        int res = Inventory.Add();

                        if (res != 0)
                        {
                            var erro = SAPConnection.DI.GetLastErrorDescription();
                            TransGenericDAO.UpdateStatus(transacao, 'E', SAPConnection.DI.GetLastErrorDescription());

                            var array = new List <string>();
                            foreach (var line in transacao.Lines)
                            {
                                array.Add(line.ItemCode);
                            }

                            throw new LogException(this.GetType()
                                                   , System.Diagnostics.EventLogEntryType.Error
                                                   , ROBO.Properties.LogMessage.ERRO_003_4
                                                   , (int)transType
                                                   , transacao.MyValues["Id"]
                                                   , SAPConnection.DI.GetLastErrorDescription()
                                                   , String.Join(", ", array.ToArray()));
                        }
                        else
                        {
                            var docnum = SAPConnection.DI.GetNewObjectKey();
                            transacao.DocNum = int.Parse(docnum);
                            TransGenericDAO.UpdateStatus(transacao);
                        }
                    }
                }
                catch (Exception ex)
                {
                    principal.GravaAudit("Transação " + transType.ToString() + " " + ex.Message.ToString());
                }
            }

            transacoes.Clear();
            transacoes = null;
        }
Пример #2
0
        /// <summary>
        /// Transação 06 - Transferência de localização de Peça (Table OIGN in SBO).
        /// </summary>
        private void Trans06()
        {
            MessageBox.Show("TRans06");
            var transacoes = TransGenericDAO.GetDadosSL(transType);

            foreach (var transacao in transacoes)
            {
                MessageBox.Show("Achou GetDados");
                var Inventory = SAPConnection.GetDocument(SAPConnection.DocsEnum.OIGN);
                // HEADER
                Inventory.DocDate = transacao.DocDate;
                Inventory.TaxDate = transacao.TaxDate;
                Inventory.BPL_IDAssignedToInvoice = transacao.BplId;

                MessageBox.Show("GroupNUM " + Inventory.GroupNumber.ToString());

                // LINES
                foreach (var line in transacao.Lines)
                {
                    Inventory.Lines.ItemCode      = line.ItemCode;
                    Inventory.Lines.Quantity      = line.Quantity;
                    Inventory.Lines.WarehouseCode = line.WhsCode;
                    Inventory.Lines.UserFields.Fields.Item("U_Lot").Value     = line.UserFields["U_Lot"];
                    Inventory.Lines.UserFields.Fields.Item("U_Quality").Value = line.UserFields["U_Quality"];

                    MessageBox.Show("ItemCode " + line.ItemCode.ToString());
                    MessageBox.Show("Quantity " + line.Quantity.ToString());
                    MessageBox.Show("WarehouseCode " + line.WhsCode.ToString());

                    using (var rs = new MyRecordSet())
                    {
                        rs.DoQuery(Properties.Querys.CustoItem_2, line.ItemCode, line.WhsCode);
                        if (rs.HasNext())
                        {
                            MessageBox.Show("Price " + rs.GetFieldValue(0).ToDouble());
                            Inventory.Lines.UnitPrice = rs.GetFieldValue(0).ToDouble();
                        }
                        else
                        {
                            Inventory.Lines.UnitPrice = 0;
                            MessageBox.Show("Price 0");
                        }
                    }

                    Inventory.Lines.Add();
                }

                //FOOTER
                Inventory.Comments = String.Format("ID {0} - Transação {1}. {2}", transacao.MyValues["Id"].ToInt(), (int)transType, transacao.Comments);
                int res = Inventory.Add();

                MessageBox.Show("Add " + res.ToString());
                MessageBox.Show("MSG " + this.GetType().Name.ToString() + SAPConnection.DI.GetLastErrorDescription().ToString());

                if (res != 0)
                {
                    principal.GravaAudit(this.GetType().Name.ToString() + SAPConnection.DI.GetLastErrorDescription().ToString());
                    TransGenericDAO.UpdateStatus(transacao, 'E', SAPConnection.DI.GetLastErrorDescription());
                }
                else
                {
                    transacao.DocNum = int.Parse(MyLibs.v2.sbo.SAPConnection.DI.GetNewObjectKey());
                    TransGenericDAO.UpdateStatus(transacao);
                }
            }

            transacoes.Clear();
            transacoes = null;
        }