public async Task <IActionResult> GenerateInvoice([FromRoute] Guid organizationId, [FromQuery] Guid projectId, [FromBody] InvoiceInput input) { var invoice = await _invoiceService.CreateInvoice(_accountManager, input); return(Ok(invoice)); }
public async Task <IActionResult> Create(InvoiceInput input) { var userId = await this.userService.GetUserIdByIdNumber(input.IdNumber); await this.invoiceService.CreateAsync(input, userId); await publisher.Publish(new CreatedInvoiceMessage { UserId = userId, Amount = input.Amount }); return(Ok("Invoice is generated")); }
private void submitButton_Click(object sender, EventArgs e) { if (ClientNameInput.Text.Length < 1) { MessageBox.Show("You must enter a Client Name.", "Invalid Name", MessageBoxButtons.OK, MessageBoxIcon.Error); ClientNameInput.Focus(); } else if (InvoiceInput.Text.Length < 1) { MessageBox.Show("You must enter an Invoice value.", "Invalid Name", MessageBoxButtons.OK, MessageBoxIcon.Error); InvoiceInput.Focus(); } else if (!int.TryParse(InvoiceInput.Text.ToString(), out addInvoice)) { MessageBox.Show("You must enter an Invoice value is not a valid.", "Invalid Name", MessageBoxButtons.OK, MessageBoxIcon.Error); InvoiceInput.Focus(); } else { using (var context = new MyDbContext()) { var newInvoice = new Invoice { date = dateTimePicker1.Value, client = ClientNameInput.Text, invoice_amount = Int32.Parse(InvoiceInput.Text) }; context.Invoice.Add(newInvoice); context.SaveChanges(); this.invoicesTableAdapter.Fill(this.invoiceDataSet.Invoices); } } }
// EditPaymentDetails FAINvoice edit with all parementer (Invoiceid). public Object Invoice([FromBody] InvoiceInput ii) { string ServerDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); InvoiceFinalOpt ifo = new InvoiceFinalOpt(); try { cnn.Close(); cnn.Open(); SqlCommand command = cnn.CreateCommand(); SqlTransaction transaction; // Start a local transaction. transaction = cnn.BeginTransaction("SampleTransaction"); // Must assign both transaction object and connection // to Command object for a pending local transaction command.Connection = cnn; command.Transaction = transaction; //InvoiceID command.CommandText = "update FAInvoice set FAPaymentModes='" + ii.FAPaymentModes + "',PayableAmount='" + ii.PayableAmount + "',AmountDue='" + ii.DueAmount + "',GymFees='" + ii.GymFee + "',TrainerFees='" + ii.PersonalTrainerFee + "',IGSTableAmount='" + ii.IGSTableAmount + "',IGST='" + ii.IGST + "',CGST='" + ii.CGST + "',SGST='" + ii.SGST + "',DueDate='" + ii.DueDate + "',FinalAmount='" + ii.FinalAmount + "',FAPaymentModes2='" + ii.FAPaymentModes2 + "',PayableAmount2='" + ii.PayableAmount2 + "',DiscountAmount='" + ii.DiscountAmount + "',WriteOFF='" + ii.WriteOFF + "',Wallet='" + ii.Wallet + "',PaymentDate='" + ii.PaymentDate + "',SlotPrice='" + ii.SlotPrice + "',PlanCost='',DuePaidAmount='" + ii.DuePaidAmount + "' where InvoiceID ='" + ii.Invoice + "' "; command.ExecuteNonQuery(); transaction.Commit(); cnn.Close(); } catch (Exception ece) { } finally { cnn.Close(); ifo.status = "Success"; } string sJSONResponse = JsonConvert.SerializeObject(ifo); return(sJSONResponse); }
public async Task CreateAsync(InvoiceInput input, Guid userId) { var client = await this.db.Clients.FirstOrDefaultAsync(c => c.ClientName == input.Name); if (client == null) { client = new Client { UserId = userId, ClientName = input.Name, NationalIdentityNumber = input.IdNumber }; } var invoice = new Invoice { Date = DateTime.Now, Amount = input.Amount, Client = client }; await this.db.AddAsync(invoice); await this.db.SaveChangesAsync(); }
private async Task <InvoiceResult> Create(InvoiceInput input, Guid organizationId) { _logger.LogInformation(GetLogMessage("{organizationId} with options {@input}"), organizationId, input); var retVal = new InvoiceResult() { ProjectId = input.ProjectId }; var project = await _projectService .Repository.Queryable() .Include(x => x.CustomerAccount) .ThenInclude(x => x.PaymentTerm) .Include(x => x.Contracts) .ThenInclude(x => x.InvoiceItems) .Include(x => x.BuyerOrganization) .ThenInclude(x => x.OrganizationBuyerAccount) .Include(x => x.ProviderOrganization) .Include(x => x.Contracts) .ThenInclude(x => x.TimeEntries) .Include(x => x.Contracts) .ThenInclude(x => x.Contractor) .ThenInclude(x => x.Person) .Include(x => x.ProviderOrganization) .ThenInclude(x => x.Organization) .Include(x => x.Contracts) .ThenInclude(x => x.ProviderOrganization) .ThenInclude(x => x.Organization) .Where(x => x.Id == input.ProjectId && x.ProjectManagerOrganizationId == organizationId) .FirstAsync(); if (project == null) { throw new ApplicationException("Project Not Found. Id : " + input.ProjectId + " Organization Id : " + organizationId); } if (project.BuyerOrganization.OrganizationBuyerAccount == null) { _logger.LogInformation(GetLogMessage("No buyer account found, creating...")); var result = await _buyerAccountService.PushCustomer(project.CustomerOrganizationId, project.CustomerId); if (result > 0) { _logger.LogDebug(GetLogMessage("{0} records updated in database"), result); return(await Create(input, organizationId)); } retVal.ErrorMessage = "Unable to establish buyer account for customer"; return(retVal); } List <Contract> contracts; // this could be filtered by active, etc if (input.IncludeAllContracts) { contracts = project.Contracts.ToList(); } else { contracts = project .Contracts .Where(x => input.ContractIds.Contains(x.Id)) .ToList(); } _logger.LogDebug(GetLogMessage("Contracts Found: {contracts}"), contracts.Count); _logger.LogDebug(GetLogMessage("Buyer Account: {buyerAcct}"), project .BuyerOrganization.OrganizationBuyerAccount.BuyerAccountId); var options = new InvoiceCreateOptions() { Customer = project.BuyerOrganization.OrganizationBuyerAccount.BuyerAccountId, AutoAdvance = false, CollectionMethod = "send_invoice", //DaysUntilDue = project.CustomerAccount.PaymentTerm.NetValue > 0 ? project.CustomerAccount.PaymentTerm.NetValue : 1, //Footer = project.Proposal.AgreementText, DueDate = DateTime.Today.AddDays(project.CustomerAccount.PaymentTerm.NetValue > 0 ? project.CustomerAccount.PaymentTerm.NetValue : 1), CustomFields = new List <InvoiceCustomFieldOptions>() { new InvoiceCustomFieldOptions() { Name = "Project Name", Value = project.Name }, new InvoiceCustomFieldOptions() { Name = "Provider Company", Value = project.ProviderOrganization.Organization.Name } }, Metadata = new Dictionary <string, string>() { { "proj_id", project.Id.ToString() } } }; var itemsCreated = 0; var itemsUpdated = 0; foreach (var c in contracts) { _logger.LogInformation(GetLogMessage("Contract Id: {0}"), c.Id); var timeEntries = c.TimeEntries .Where(x => x.Status == TimeStatus.Approved && x.InvoiceItemId == null) .ToList(); _logger.LogDebug(GetLogMessage("{entries} Approved Entries Found"), timeEntries.Count); var totalHours = timeEntries.Sum(x => x.TotalHours); if (totalHours > 0) { var totalCustomerAmount = timeEntries.Sum(x => x.TotalCustomerAmount); var ancientEntry = c.TimeEntries.Min(x => x.StartDate); var latterDayEntry = c.TimeEntries.Max(x => x.EndDate); var hours = totalHours.ToString("F"); _logger.LogDebug(GetLogMessage("Hours: {0}"), hours); _logger.LogDebug(GetLogMessage("Amount {amount:C}"), totalCustomerAmount); var description = $@"{hours} Hours Worked by {c.Contractor.Person.DisplayName} [{c.ProviderOrganization.Organization.Name}]"; var hasInvoiceItems = c.InvoiceItems.Any(x => x.InvoiceId == null); if (hasInvoiceItems) { var invoiceItems = c.InvoiceItems.Where(x => x.InvoiceId == null); _logger.LogDebug(GetLogMessage("Contract has invoice items : {0}"), invoiceItems.Count()); foreach (var item in invoiceItems) { _logger.LogDebug(GetLogMessage("Invoice Item Id : {0}"), item.Id); var stripeItem = _invoiceItemService.Update(item.Id, new InvoiceItemUpdateOptions() { Description = description, Amount = Convert.ToInt64(totalCustomerAmount * 100m) }); if (stripeItem != null) { _logger.LogDebug(GetLogMessage("Item Updated in Stripe. Stripe Item Id : {0}"), stripeItem.Id); itemsUpdated++; } else { _logger.LogDebug(GetLogMessage("Item Update Failed in Stripe")); } } } else { _logger.LogDebug(GetLogMessage("Contract doesn't have invoice items. Creating New Invoice Item")); var invoiceItemOptions = new InvoiceItemCreateOptions() { Period = new InvoiceItemPeriodOptions() { Start = ancientEntry.DateTime, End = latterDayEntry.DateTime }, Customer = project.BuyerOrganization.OrganizationBuyerAccount.BuyerAccountId, Amount = Convert.ToInt64(totalCustomerAmount * 100), Currency = "usd", Description = description, Metadata = new Dictionary <string, string>() { { "contract-id", c.Id.ToString() } } }; _logger.LogInformation(GetLogMessage("options: {0}"), invoiceItemOptions); var invoiceItem = _invoiceItemService.Create(invoiceItemOptions); _logger.LogDebug(GetLogMessage("Invoice Item: {0}"), invoiceItem); var invoiceItemResult = await InvoiceItemCreated(invoiceItem); _logger.LogDebug(GetLogMessage("Invoice Item Result: {@result}"), invoiceItemResult); if (invoiceItemResult.Succeeded) { itemsCreated++; } } if (itemsUpdated + itemsCreated > 0) { c.ObjectState = ObjectState.Modified; } } else { _logger.LogDebug(GetLogMessage("no billable time for {contract}"), c.Id); } } var entriesUpdated = _timeEntries.Commit(); _logger.LogDebug(GetLogMessage("Entries Updated: {entriesUpdated}"), entriesUpdated); if (entriesUpdated == 0) { _logger.LogWarning(GetLogMessage("No Entities were updated")); } _logger.LogInformation(GetLogMessage("options: {@Options}"), options); var invoice = _invoiceService.Create(options); if (invoice != null) { var stripeResult = await InvoiceCreated(invoice, input.RefNo); _logger.LogDebug(GetLogMessage("Stripe Result: {@result}"), stripeResult); if (stripeResult.Succeeded) { retVal.Succeeded = true; retVal.InvoiceId = invoice.Id; } } else { _logger.LogDebug(GetLogMessage("Unable to create invoice")); } if (retVal.Succeeded) { await Task.Run(() => new InvoiceCreatedEvent() { InvoiceId = invoice.Id }); } return(retVal); }
public Task <InvoiceResult> CreateInvoice(IOrganizationAccountManager am, InvoiceInput input) { _logger.LogInformation(GetLogMessage("Creating invoice as account manager")); return(Create(input, am.OrganizationId)); }
public Task <InvoiceResult> CreateInvoice(IProviderAgencyOwner agencyOwner, InvoiceInput input) { _logger.LogInformation(GetLogMessage("Creating invoice as agency owner")); return(Create(input, agencyOwner.OrganizationId)); }
public async Task <IActionResult> CreateInvoice([FromRoute] Guid organizationId, [FromBody] InvoiceInput input) { var invoice = await _invoiceService.CreateInvoice(_agencyOwner, input); return(Ok(invoice)); }