private static Result <SalesOrder> CreateSalesOrder(
            WineMsSalesOrderTransactionDocument salesOrderTransactionDocument) =>
        ExceptionWrapper
        .Wrap(
            () =>
        {
            var customer = new Customer(salesOrderTransactionDocument.CustomerAccountCode);

            var salesOrder = (SalesOrder)
                             new SalesOrder {
                Customer        = customer,
                DeliveryDate    = salesOrderTransactionDocument.TransactionDate,
                Description     = "Tax Invoice",
                DiscountPercent = (double)salesOrderTransactionDocument.DocumentDiscountPercentage,
                DueDate         = salesOrderTransactionDocument.TransactionDate,
                InvoiceDate     = salesOrderTransactionDocument.TransactionDate,
                OrderDate       = salesOrderTransactionDocument.TransactionDate,
                OrderNo         = salesOrderTransactionDocument.DocumentNumber
            }
            .SetDeliveryAddress(customer)
            .SetPostalAddress(customer)
            .SetMessageLines(salesOrderTransactionDocument)
            .SetTaxMode(customer)
            .SetExchangeRate(customer, salesOrderTransactionDocument.ExchangeRate)
            ;

            return(Result.Ok(salesOrder));
        });
        private static Result <CreditNote> CreateCreditNote(
            WineMsCreditNoteTransactionDocument creditNoteTransactionDocument) =>
        ExceptionWrapper
        .Wrap(
            () =>
        {
            var customer = new Customer(creditNoteTransactionDocument.CustomerAccountCode);

            var creditNote = (CreditNote)
                             new CreditNote {
                Customer        = customer,
                DeliveryDate    = creditNoteTransactionDocument.TransactionDate,
                Description     = "Credit Note",
                DiscountPercent = (double)creditNoteTransactionDocument.DocumentDiscountPercentage,
                DueDate         = creditNoteTransactionDocument.TransactionDate,
                InvoiceDate     = creditNoteTransactionDocument.TransactionDate,
                OrderDate       = creditNoteTransactionDocument.TransactionDate,
                OrderNo         = creditNoteTransactionDocument.DocumentNumber
            }
            .SetDeliveryAddress(customer)
            .SetPostalAddress(customer)
            .SetMessageLines(creditNoteTransactionDocument)
            .SetTaxMode(customer)
            .SetExchangeRate(customer, creditNoteTransactionDocument.ExchangeRate)
            ;

            return(Result.Ok(creditNote));
        });
Example #3
0
 private static Result <PurchaseOrder> CreatePurchaseOrder(
     WineMsPurchaseOrderTransactionDocument salesOrderTransactionDocument) =>
 ExceptionWrapper
 .Wrap(
     () => Result.Ok(
         new PurchaseOrder {
     Supplier     = new Supplier(salesOrderTransactionDocument.SupplierAccountCode),
     DeliveryDate = salesOrderTransactionDocument.TransactionDate,
     DueDate      = salesOrderTransactionDocument.TransactionDate,
     OrderDate    = salesOrderTransactionDocument.TransactionDate,
     OrderNo      = salesOrderTransactionDocument.DocumentNumber,
     TaxMode      = TaxMode.Exclusive
 }));
Example #4
0
        private static Result <OrderBase> AddOrderLines(
            this OrderBase order,
            WineMsOrderTransactionDocument salesOrderTransactionDocument,
            OrderTransactionType orderTransactionType) =>
        WineMsTransactionDocumentFunctions
        .ForEachTransactionDocumentLine(
            transactionLine =>
            ExceptionWrapper
            .Wrap(
                () =>
        {
            var isGeneralLedgerLine = IsGeneralLedgerLine(transactionLine);
            var orderLine           = NewOrderDetail(order);

            if (isGeneralLedgerLine)
            {
                SetGeneralLedgerAccount(orderLine, transactionLine);
            }
            else
            {
                SetInventoryItem(orderLine, transactionLine);
            }

            orderLine.Quantity  = (double)transactionLine.Quantity;
            orderLine.ToProcess = orderLine.Quantity;
            SetUnitSellingPrice(orderLine, transactionLine);

            if (transactionLine.TaxTypeId > 0)
            {
                var result = GetOrderLineTaxType(transactionLine);
                if (result.IsFailure)
                {
                    return(Result.Fail(result.Error));
                }
                orderLine.TaxType = result.Value;
            }

            orderLine.DiscountPercent = (double)transactionLine.LineDiscountPercentage;
            orderLine.Description     = transactionLine.Description1;

            if (!transactionLine.ItemNote.IsNullOrWhiteSpace())
            {
                orderLine.Note = transactionLine.ItemNote;
            }

            SetUserDefinedFields(orderTransactionType, orderLine, transactionLine);

            return(Result.Ok());
        }),
            salesOrderTransactionDocument.TransactionLines)
        .OnSuccess(() => order);
Example #5
0
 public static Result <WineMsPurchaseOrderTransactionDocument> ProcessTransaction(
     WineMsPurchaseOrderTransactionDocument wineMsSalesOrderTransactionDocument) =>
 CreatePurchaseOrder(wineMsSalesOrderTransactionDocument)
 .OnSuccess(
     order => order.AddPurchaseOrderLines(wineMsSalesOrderTransactionDocument))
 .OnSuccess(
     order => ExceptionWrapper
     .Wrap(
         () =>
 {
     order.Save();
     wineMsSalesOrderTransactionDocument.IntegrationDocumentNumber = order.OrderNo;
     return(Result.Ok(wineMsSalesOrderTransactionDocument));
 }));
 public static Result <WineMsCreditNoteTransactionDocument> ProcessTransaction(
     WineMsCreditNoteTransactionDocument wineMsCreditNoteTransactionDocument) =>
 CreateCreditNote(wineMsCreditNoteTransactionDocument)
 .OnSuccess(
     creditNote => creditNote.AddSalesOrderLines(wineMsCreditNoteTransactionDocument))
 .OnSuccess(
     creditNote => ExceptionWrapper
     .Wrap(
         () =>
 {
     creditNote.Save();
     wineMsCreditNoteTransactionDocument.IntegrationDocumentNumber = creditNote.OrderNo;
     return(Result.Ok(wineMsCreditNoteTransactionDocument));
 }));