Beispiel #1
0
        private async Task <HttpResponseMessage> SendMessage(SapCreditNoteModel creditNote, string sapSystem, string uriString, HttpMethod method)
        {
            var message = new HttpRequestMessage()
            {
                RequestUri = new Uri(uriString),
                Method     = method
            };

            if (creditNote != null)
            {
                message.Content = new StringContent(JsonConvert.SerializeObject(creditNote,
                                                                                new JsonSerializerSettings
                {
                    NullValueHandling    = NullValueHandling.Ignore,
                    DefaultValueHandling = DefaultValueHandling.Ignore
                }),
                                                    Encoding.UTF8,
                                                    "application/json");
            }

            var sapTaskHandler = _sapServiceSettingsFactory.CreateHandler(sapSystem);
            var cookies        = await sapTaskHandler.StartSession();

            message.Headers.Add("Cookie", cookies.B1Session);
            message.Headers.Add("Cookie", cookies.RouteId);

            var client = _httpClientFactory.CreateClient();

            return(await client.SendAsync(message));
        }
        public SapCreditNoteModel MapToSapCreditNote(SapSaleOrderInvoiceResponse sapSaleOrderInvoiceResponse, CreditNoteRequest creditNoteRequest)
        {
            var sapCreditNoteModel = new SapCreditNoteModel
            {
                NumAtCard            = sapSaleOrderInvoiceResponse.NumAtCard ?? "",
                U_DPL_RECURRING_SERV = sapSaleOrderInvoiceResponse.U_DPL_RECURRING_SERV,
                U_DPL_CARD_HOLDER    = sapSaleOrderInvoiceResponse.U_DPL_CARD_HOLDER,
                U_DPL_CARD_NUMBER    = sapSaleOrderInvoiceResponse.U_DPL_CARD_NUMBER,
                U_DPL_CARD_TYPE      = sapSaleOrderInvoiceResponse.U_DPL_CARD_TYPE,
                U_DPL_CARD_ERROR_COD = creditNoteRequest.CardErrorCode,
                U_DPL_CARD_ERROR_DET = creditNoteRequest.CardErrorDetail,
                U_DPL_CN_ID          = creditNoteRequest.CreditNoteId,
                DocumentLines        = new List <SapCreditNoteDocumentLineModel>(),
                DocDate           = _dateTimeProvider.GetDateByTimezoneId(_dateTimeProvider.UtcNow, _timezoneConfig.InvoicesTimeZone).ToString("yyyy-MM-dd"),
                DocDueDate        = _dateTimeProvider.GetDateByTimezoneId(_dateTimeProvider.UtcNow, _timezoneConfig.InvoicesTimeZone).ToString("yyyy-MM-dd"),
                TaxDate           = _dateTimeProvider.GetDateByTimezoneId(_dateTimeProvider.UtcNow, _timezoneConfig.InvoicesTimeZone).ToString("yyyy-MM-dd"),
                CreditNoteId      = creditNoteRequest.CreditNoteId,
                CardCode          = sapSaleOrderInvoiceResponse.CardCode,
                TransferReference = creditNoteRequest.TransferReference
            };

            var balance   = creditNoteRequest.Amount;
            var isPartial = sapSaleOrderInvoiceResponse.DocTotal > Convert.ToDecimal(creditNoteRequest.Amount);

            foreach (SapDocumentLineResponse line in sapSaleOrderInvoiceResponse.DocumentLines)
            {
                if (balance == 0)
                {
                    break;
                }

                var amount = (line.UnitPrice > balance) ? balance : line.UnitPrice;
                SapCreditNoteDocumentLineModel creditNoteLine = new SapCreditNoteDocumentLineModel
                {
                    BaseEntry    = (creditNoteRequest.Type == (int)CreditNoteEnum.NoRefund) ? sapSaleOrderInvoiceResponse.DocEntry : (int?)null,
                    BaseLine     = (creditNoteRequest.Type == (int)CreditNoteEnum.NoRefund) ? line.LineNum : (int?)null,
                    BaseType     = (creditNoteRequest.Type == (int)CreditNoteEnum.NoRefund) ? _invoiceType : (int?)null,
                    CostingCode  = line.CostingCode,
                    CostingCode2 = line.CostingCode2,
                    CostingCode3 = line.CostingCode3,
                    CostingCode4 = line.CostingCode4,
                    Currency     = line.Currency,
                    FreeText     = isPartial ? $"Partial refund - Invoice: {sapSaleOrderInvoiceResponse.DocNum}." : $"Cancel invoice: {sapSaleOrderInvoiceResponse.DocNum}.",
                    ItemCode     = line.ItemCode,
                    Quantity     = line.Quantity,
                    TaxCode      = line.TaxCode,
                    UnitPrice    = amount,
                    ReturnReason = string.IsNullOrEmpty(creditNoteRequest.Reason) ? -1 :
                                   _creditNoteReason.TryGetValue(creditNoteRequest.Reason, out var outReason) ? outReason : -1
                };

                sapCreditNoteModel.DocumentLines.Add(creditNoteLine);

                balance -= amount;
            }

            return(sapCreditNoteModel);
        }
        public SapCreditNoteModel MapToSapCreditNote(CancelCreditNoteRequest cancelCreditNoteRequest)
        {
            var sapCreditNoteModel = new SapCreditNoteModel
            {
                U_DPL_CN_ID     = cancelCreditNoteRequest.CreditNoteId,
                BillingSystemId = cancelCreditNoteRequest.BillingSystemId
            };

            return(sapCreditNoteModel);
        }
        public SapCreditNoteModel MapToSapCreditNote(CreditNoteRequest creditNoteRequest)
        {
            var sapCreditNoteModel = new SapCreditNoteModel
            {
                BillingSystemId      = creditNoteRequest.BillingSystemId,
                CreditNoteId         = creditNoteRequest.InvoiceId,
                U_DPL_CARD_ERROR_COD = creditNoteRequest.CardErrorCode,
                U_DPL_CARD_ERROR_DET = creditNoteRequest.CardErrorDetail,
                TransactionApproved  = creditNoteRequest.TransactionApproved,
                TransferReference    = creditNoteRequest.TransferReference
            };

            return(sapCreditNoteModel);
        }