Beispiel #1
0
        public TransactionEntity Create(PaymentEntity payment)
        {
            TransactionEntity transaction = new TransactionEntity();
            bool processingError          = false;

            _DownPayment   = Company.GetBusinessObject(BoObjectTypes.oVendorPayments);
            _PaymentEntity = payment;
            _CreatePaymentHeading();
            _AssignPaymentType();

            foreach (var document in payment.Documents)
            {
                TransactionEntity payTransaction        = null;
                TransactionEntity creditNoteTransaction = null;

                if (document.PayAmount > 0)
                {
                    payTransaction = _PayDocument(payment, document);
                    if (!payTransaction.Success)
                    {
                        transaction.Message = payTransaction.Message;
                        processingError     = true;
                        break;
                    }
                }

                if (document.CreditNote.Amount > 0)
                {
                    creditNoteTransaction = _AddCreditNote(payment, document);
                    if (!creditNoteTransaction.Success)
                    {
                        transaction.Message = creditNoteTransaction.Message;
                        processingError     = true;
                        break;
                    }
                }
            }

            if (!processingError)
            {
                if (_DownPayment.Add() != 0)
                {
                    transaction.Message = ErrorMessage;
                }
                else
                {
                    string newEntityId;
                    Company.GetNewObjectCode(out newEntityId);
                    transaction.Successfull(newEntityId);
                }
            }
            else
            {
                _DownPayment.Cancel();
            }

            Company.Disconnect();

            return(transaction);
        }
Beispiel #2
0
        private TransactionEntity _AddCreditNote(PaymentEntity payment, DocumentEntity document)
        {
            TransactionEntity transaction = new TransactionEntity();

            SAPbobsCOM.Documents creditNote;
            creditNote = Company.GetBusinessObject(BoObjectTypes.oPurchaseCreditNotes);

            try
            {
                creditNote.CardCode    = payment.SupplierCode;
                creditNote.DocDate     = payment.Date;
                creditNote.DocDueDate  = payment.Date;
                creditNote.TaxDate     = payment.Date;
                creditNote.DocCurrency = payment.Currency;
                creditNote.Comments    = document.Comments;
                creditNote.DocType     = BoDocumentTypes.dDocument_Service;

                creditNote.Lines.AccountCode     = document.CreditNote.AccountCode;
                creditNote.Lines.ItemDescription = document.CreditNote.ItemDescription;
                creditNote.Lines.Quantity        = document.CreditNote.Quantity;
                creditNote.Lines.TaxCode         = document.CreditNote.TaxCode;
                creditNote.Lines.Price           = document.CreditNote.Amount;

                if (creditNote.Add() != 0)
                {
                    string template  = "CreditNoteError \n {0} \n {1}";
                    string reference = document.Reference;
                    transaction.Message = string.Format(template, ErrorMessage, reference);
                    creditNote.Cancel();
                }
                else
                {
                    var newCreditNoteId = Company.GetNewObjectKey();
                    creditNote.GetByKey(int.Parse(newCreditNoteId));

                    _DownPayment.Invoices.DocEntry    = int.Parse(newCreditNoteId);
                    _DownPayment.Invoices.InvoiceType = BoRcptInvTypes.it_PurchaseCreditNote;
                    _DownPayment.Invoices.SumApplied  = -1 * document.CreditNote.Amount;
                    _DownPayment.Invoices.Add();
                    transaction.Successfull(newCreditNoteId);
                }
            }
            catch (Exception e)
            {
                string template = "CreditNoteException\n {0} \n {1}";
                transaction.Message = string.Format(template, ErrorMessage, e.Message);
                creditNote.Cancel();
            }

            return(transaction);
        }
Beispiel #3
0
        public TransactionEntity Create(InvoiceEntity invoice, List <ItemEntity> items)
        {
            int               line        = 0;
            string            newEntityId = "";
            TransactionEntity transaction = new TransactionEntity();

            _Invoice           = Company.GetBusinessObject(BoObjectTypes.oInvoices);
            _Invoice.CardCode  = invoice.CustomerCode;
            _Invoice.NumAtCard = invoice.Reference;
            _Invoice.DocDate   = invoice.DocDate;
            _Invoice.TaxDate   = invoice.TaxDate;
            _Invoice.DocType   = BoDocumentTypes.dDocument_Items;
            _Invoice.Comments  = invoice.Comments;

            foreach (ItemEntity item in items)
            {
                _Invoice.Lines.SetCurrentLine(line);
                _Invoice.Lines.ItemCode      = item.ItemCode;
                _Invoice.Lines.WarehouseCode = item.WarehouseCode;
                _Invoice.Lines.Quantity      = item.Quantity;
                _Invoice.Lines.VatGroup      = item.VatGroup;
                _Invoice.Lines.UnitPrice     = item.UnitPrice;
                _Invoice.Lines.LineTotal     = item.LineTotal;
                _Invoice.Lines.TaxCode       = item.TaxCode;
                _Invoice.Lines.BaseType      = (int)BoObjectTypes.oOrders;
                _Invoice.Lines.BaseEntry     = invoice.OrderId;
                _Invoice.Lines.BaseLine      = 0;
            }

            if (_Invoice.Add() != 0)
            {
                transaction.Message = Company.GetLastErrorDescription();
            }
            else
            {
                Company.GetNewObjectCode(out newEntityId);
                transaction.Successfull(newEntityId);
            }

            Company.Disconnect();

            return(transaction);
        }
Beispiel #4
0
        public TransactionEntity Create(OrderEntity order, List <ItemEntity> items)
        {
            int               line        = 0;
            string            newEntityId = "";
            TransactionEntity transaction = new TransactionEntity();

            _Order            = Company.GetBusinessObject(BoObjectTypes.oOrders);
            _Order.CardCode   = order.CustomerCode;
            _Order.DocDueDate = order.OrderDueDate;

            foreach (ItemEntity item in items)
            {
                _Order.Lines.SetCurrentLine(line);
                _Order.Lines.WarehouseCode = item.WarehouseCode;
                _Order.Lines.ItemCode      = item.ItemCode;
                _Order.Lines.Quantity      = item.Quantity;
                _Order.Lines.UnitPrice     = item.UnitPrice;
                _Order.Lines.LineTotal     = item.LineTotal;
                _Order.Lines.TaxCode       = item.TaxCode;
                _Order.Lines.VatGroup      = item.VatGroup;
                _Order.Lines.Add();
                line += 1;
            }

            if (_Order.Add() != 0)
            {
                transaction.Message = Company.GetLastErrorDescription();
            }
            else
            {
                Company.GetNewObjectCode(out newEntityId);
                transaction.Successfull(newEntityId);
            }

            Company.Disconnect();

            return(transaction);
        }