private void btnGenerate_Click(object sender, EventArgs e) { var customer = (Customer)cboCustomer.SelectedItem; var invoiceCode = (string)cboInvoice.SelectedItem; if (IsValid == false) { MessageBox.Show(AllErrors.ErrorMessageString(), Constants.ALERTMESSAGEHEADER); return; } var request = new CreditNoteRequest { CreditNote = new CreditNote { TransactionDate = dtCosting.Value, Amount = Convert.ToDecimal(txtAmount.Text), CustomerCode = customer.CustomersCode, IsActive = true, Description = txtDescription.Text, InvoiceNo = invoiceCode } }; var response = _transactionService.CreateCreditNote(request); if (false == response.IsValid) { MessageBox.Show(response.AllErrors.ErrorMessageString(), Constants.ALERTMESSAGEHEADER); return; } ShowCreditNoteReport(request.CreditNote.Id); }
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); }
public void CreateCreditNotes_ShouldBeThrowsAnException_WhenInvoiceIdIsNotValid() { var creditNote = new CreditNoteRequest { Amount = 100, BillingSystemId = 2, ClientId = 1, InvoiceId = 0, Type = 1 }; var loggerMock = new Mock <ILogger <BillingController> >(); var billingServiceMock = new Mock <IBillingService>(); billingServiceMock.Setup(x => x.CreateCreditNote(It.IsAny <CreditNoteRequest>())).ThrowsAsync(new ArgumentException("Value can not be null", "InvoiceId")); var controller = new BillingController(loggerMock.Object, billingServiceMock.Object); // Act var ex = Assert.ThrowsAsync <ArgumentException>(() => controller.CreateCreditNote(creditNote)); // Assert Assert.Equal("Value can not be null (Parameter 'InvoiceId')", ex.Result.Message); }
public async Task CreateCreditNotes_ShouldBeHttpStatusCodeOk_WhenRequestIsValid() { var creditNote = new CreditNoteRequest { Amount = 100, BillingSystemId = 2, ClientId = 1, InvoiceId = 1, Type = 1 }; var loggerMock = new Mock <ILogger <BillingController> >(); var billingServiceMock = new Mock <IBillingService>(); billingServiceMock.Setup(x => x.CreateCreditNote(It.IsAny <CreditNoteRequest>())) .Returns(Task.CompletedTask); var controller = new BillingController(loggerMock.Object, billingServiceMock.Object); // Act var response = await controller.CreateCreditNote(creditNote); // Assert Assert.IsType <OkObjectResult>(response); Assert.Equal("Successfully", ((ObjectResult)response).Value); }
public async Task CreateCreditNote(CreditNoteRequest creditNotesRequest) { try { var sapSystem = SapSystemHelper.GetSapSystemByBillingSystem(creditNotesRequest.BillingSystemId); var validator = GetValidator(sapSystem); validator.ValidateCreditNoteRequest(creditNotesRequest); _queuingService.AddToTaskQueue( new SapTask { CreditNoteRequest = creditNotesRequest, TaskType = SapTaskEnum.CreateCreditNote } ); } catch (Exception e) { _logger.LogError($"Failed at generating create credit note request for user: {creditNotesRequest.ClientId}.", e); await _slackService.SendNotification($"Failed at generating create credit note request for user: {creditNotesRequest.ClientId}. Error: {e.Message}"); } }
private void dgvJewel_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } var row = dgvCreditNote[e.ColumnIndex, e.RowIndex]; var id = row.Tag; if (row.Value.ToString() == "View") { ShowCreditNoteReport((int)id); } else if (row.Value.ToString() == "Done Payment" || row.Value.ToString() == "Undo Payment") { var crn = _transactionService.GetCreditNotes().Single(x => x.Id == (int)id); crn.IsActive = !crn.IsActive; var request = new CreditNoteRequest { CreditNote = crn }; _transactionService.CreateCreditNote(request); BindDataGrid(crn.CustomerCode); } }
public async Task BillingService_ShouldBeNotAddOneTaskInQueue_WhenCreateCreditNotesHasOneElementWithInvalidClientId() { var timeZoneConfigurations = new TimeZoneConfigurations { InvoicesTimeZone = TimeZoneHelper.GetTimeZoneByOperativeSystem("Argentina Standard Time") }; var billingMappers = new List <IBillingMapper> { new BillingForArMapper(Mock.Of <ISapBillingItemsService>(), Mock.Of <IDateTimeProvider>(), timeZoneConfigurations), new BillingForUsMapper(Mock.Of <ISapBillingItemsService>(), Mock.Of <IDateTimeProvider>(), timeZoneConfigurations) }; var slackServiceMock = new Mock <ISlackService>(); slackServiceMock.Setup(x => x.SendNotification(It.IsAny <string>())).Returns(Task.CompletedTask); var queuingServiceMock = new Mock <IQueuingService>(); var billingService = new BillingService(queuingServiceMock.Object, Mock.Of <IDateTimeProvider>(), Mock.Of <ILogger <BillingService> >(), slackServiceMock.Object, billingMappers, null, Mock.Of <ISapServiceSettingsFactory>()); var creditNote = new CreditNoteRequest { Amount = 100, BillingSystemId = 2, ClientId = 0, InvoiceId = 1, Type = 1 }; await billingService.CreateCreditNote(creditNote); queuingServiceMock.Verify(x => x.AddToTaskQueue(It.IsAny <SapTask>()), Times.Never); slackServiceMock.Verify(x => x.SendNotification(It.IsAny <string>()), Times.Once); }
public async Task BillingService_ShouldBeAddOneTaskInQueue_WhenCreateCreditNotesHasOneValidElement() { var billingValidations = new List <IBillingValidation> { new BillingForArValidation(Mock.Of <ILogger <BillingForArValidation> >()), new BillingForUsValidation(Mock.Of <ILogger <BillingForUsValidation> >()) }; var timeZoneConfigurations = new TimeZoneConfigurations { InvoicesTimeZone = TimeZoneHelper.GetTimeZoneByOperativeSystem("Argentina Standard Time") }; var billingMappers = new List <IBillingMapper> { new BillingForArMapper(Mock.Of <ISapBillingItemsService>(), Mock.Of <IDateTimeProvider>(), timeZoneConfigurations), new BillingForUsMapper(Mock.Of <ISapBillingItemsService>(), Mock.Of <IDateTimeProvider>(), timeZoneConfigurations) }; var queuingServiceMock = new Mock <IQueuingService>(); var billingService = new BillingService(queuingServiceMock.Object, Mock.Of <IDateTimeProvider>(), Mock.Of <ILogger <BillingService> >(), Mock.Of <ISlackService>(), billingMappers, billingValidations, Mock.Of <ISapServiceSettingsFactory>()); var creditNote = new CreditNoteRequest { Amount = 100, BillingSystemId = 2, ClientId = 1, InvoiceId = 1, Type = 1 }; await billingService.CreateCreditNote(creditNote); queuingServiceMock.Verify(x => x.AddToTaskQueue(It.IsAny <SapTask>()), Times.Once); }
public Task CreateCreditNote(CreditNoteRequest creditNotesRequest) { return(Task.CompletedTask); }
public CreditNoteResponse CreditNote(CreditNoteRequest request) { return(WrapResponse <CreditNoteResponse, CreditNoteResponseBody>(new ServiceExecutionDelegator <CreditNoteResponseBody, CreditNoteRequestBody>() .ResolveRequest(request.Request, (request.Request.Platform ?? ConfigurationManager.AppSettings["DefaultPlatform"]), ApiServiceName.CreditNote))); }
public SapCreditNoteModel MapToSapCreditNote(SapSaleOrderInvoiceResponse sapSaleOrderInvoiceResponse, CreditNoteRequest creditNoteRequest) { var sapCreditNoteModel = new SapCreditNoteModel { NumAtCard = sapSaleOrderInvoiceResponse.NumAtCard ?? "", 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, DiscountPercent = (int)line.DiscountPercent, FreeText = isPartial ? $"Partial refund - Invoice: {sapSaleOrderInvoiceResponse.DocNum}." : $"Cancel invoice: {sapSaleOrderInvoiceResponse.DocNum}.", ItemCode = line.ItemCode, Quantity = line.Quantity, TaxCode = line.TaxCode, UnitPrice = amount, ReturnReason = -1 }; sapCreditNoteModel.DocumentLines.Add(creditNoteLine); balance -= amount; } return(sapCreditNoteModel); }