1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-29 15:24:51 -05:00

api settings for our address

This commit is contained in:
Kyle Spearrin 2017-10-25 10:59:30 -04:00
parent e7b565d007
commit 461be7a14f
6 changed files with 40 additions and 19 deletions

9
src/Api/ApiSettings.cs Normal file
View File

@ -0,0 +1,9 @@
namespace Bit.Api
{
public class ApiSettings
{
public string OurAddress1 { get; set; }
public string OurAddress2 { get; set; }
public string OurAddress3 { get; set; }
}
}

View File

@ -16,6 +16,7 @@ using jsreport.AspNetCore;
using jsreport.Types; using jsreport.Types;
using Bit.Api.Models; using Bit.Api.Models;
using Stripe; using Stripe;
using Microsoft.Extensions.Options;
namespace Bit.Api.Controllers namespace Bit.Api.Controllers
{ {
@ -29,6 +30,7 @@ namespace Bit.Api.Controllers
private readonly IUserService _userService; private readonly IUserService _userService;
private readonly CurrentContext _currentContext; private readonly CurrentContext _currentContext;
private readonly GlobalSettings _globalSettings; private readonly GlobalSettings _globalSettings;
private readonly ApiSettings _apiSettings;
private readonly UserManager<User> _userManager; private readonly UserManager<User> _userManager;
public OrganizationsController( public OrganizationsController(
@ -38,6 +40,7 @@ namespace Bit.Api.Controllers
IUserService userService, IUserService userService,
CurrentContext currentContext, CurrentContext currentContext,
GlobalSettings globalSettings, GlobalSettings globalSettings,
IOptions<ApiSettings> apiSettings,
UserManager<User> userManager) UserManager<User> userManager)
{ {
_organizationRepository = organizationRepository; _organizationRepository = organizationRepository;
@ -47,6 +50,7 @@ namespace Bit.Api.Controllers
_currentContext = currentContext; _currentContext = currentContext;
_userManager = userManager; _userManager = userManager;
_globalSettings = globalSettings; _globalSettings = globalSettings;
_apiSettings = apiSettings.Value;
} }
[HttpGet("{id}")] [HttpGet("{id}")]
@ -123,8 +127,10 @@ namespace Bit.Api.Controllers
throw new NotFoundException(); throw new NotFoundException();
} }
var model = new InvoiceModel(organization, invoice); var model = new InvoiceModel(organization, invoice, _apiSettings);
HttpContext.JsReportFeature().Recipe(Recipe.PhantomPdf); HttpContext.JsReportFeature().Recipe(Recipe.PhantomPdf)
.OnAfterRender((r) => HttpContext.Response.Headers["Content-Disposition"] =
$"attachment; filename=\"bitwarden_{model.InvoiceNumber}.pdf\"");
return View("Invoice", model); return View("Invoice", model);
} }
catch(StripeException) catch(StripeException)

View File

@ -7,19 +7,19 @@ namespace Bit.Api.Models
{ {
public class InvoiceModel public class InvoiceModel
{ {
public InvoiceModel(Organization organization, StripeInvoice invoice) public InvoiceModel(Organization organization, StripeInvoice invoice, ApiSettings apiSettings)
{ {
// TODO: address OurAddress1 = apiSettings.OurAddress1;
OurAddress1 = "567 Green St"; OurAddress2 = apiSettings.OurAddress2;
OurAddress2 = "Jacksonville, FL 32256"; OurAddress3 = apiSettings.OurAddress3;
OurAddress3 = "United States";
CustomerName = organization.BusinessName ?? "--"; CustomerName = organization.BusinessName ?? "--";
// TODO: address and vat // TODO: address and vat
CustomerAddress1 = "123 Any St"; CustomerAddress1 = "123 Any St";
CustomerAddress2 = "New York, NY 10001"; CustomerAddress2 = "New York, NY 10001";
CustomerAddress3 = "United States"; CustomerAddress3 = "United States";
CustomerVatNumber = "PT 123456789"; CustomerAddress4 = null;
CustomerVatNumber = "PT123456789";
InvoiceDate = invoice.Date?.ToLongDateString(); InvoiceDate = invoice.Date?.ToLongDateString();
InvoiceDueDate = invoice.DueDate?.ToLongDateString(); InvoiceDueDate = invoice.DueDate?.ToLongDateString();
@ -43,6 +43,7 @@ namespace Bit.Api.Models
public string CustomerAddress1 { get; set; } public string CustomerAddress1 { get; set; }
public string CustomerAddress2 { get; set; } public string CustomerAddress2 { get; set; }
public string CustomerAddress3 { get; set; } public string CustomerAddress3 { get; set; }
public string CustomerAddress4 { get; set; }
public IEnumerable<Item> Items { get; set; } public IEnumerable<Item> Items { get; set; }
public string SubtotalAmount { get; set; } public string SubtotalAmount { get; set; }
public string VatTotalAmount { get; set; } public string VatTotalAmount { get; set; }
@ -54,13 +55,11 @@ namespace Bit.Api.Models
{ {
public Item(StripeInvoiceLineItem item) public Item(StripeInvoiceLineItem item)
{ {
Quantity = item.Quantity?.ToString() ?? "-";
Amount = (item.Amount / 100).ToString("F"); Amount = (item.Amount / 100).ToString("F");
Description = item.Description ?? "--"; Description = item.Description ?? "--";
} }
public string Description { get; set; } public string Description { get; set; }
public string Quantity { get; set; }
public string Amount { get; set; } public string Amount { get; set; }
} }
} }

View File

@ -44,6 +44,7 @@ namespace Bit.Api
// Settings // Settings
var globalSettings = services.AddGlobalSettingsServices(Configuration); var globalSettings = services.AddGlobalSettingsServices(Configuration);
services.Configure<ApiSettings>(Configuration.GetSection("apiSettings"));
if(!globalSettings.SelfHosted) if(!globalSettings.SelfHosted)
{ {
services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimitOptions")); services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimitOptions"));
@ -145,8 +146,7 @@ namespace Bit.Api
// PDF generation // PDF generation
if(!globalSettings.SelfHosted) if(!globalSettings.SelfHosted)
{ {
services services.AddJsReport(new jsreport.Local.LocalReporting()
.AddJsReport(new jsreport.Local.LocalReporting()
.UseBinary(jsreport.Binary.JsReportBinary.GetBinary()) .UseBinary(jsreport.Binary.JsReportBinary.GetBinary())
.AsUtility() .AsUtility()
.Create()); .Create());

View File

@ -78,10 +78,6 @@
<h2>To</h2> <h2>To</h2>
<p> <p>
<b>@Model.CustomerName</b><br /> <b>@Model.CustomerName</b><br />
@if(Model.UsesVat)
{
@:VAT @Model.CustomerVatNumber<br />
}
@if(!string.IsNullOrWhiteSpace(Model.CustomerAddress1)) @if(!string.IsNullOrWhiteSpace(Model.CustomerAddress1))
{ {
@Model.CustomerAddress1<br /> @Model.CustomerAddress1<br />
@ -92,9 +88,17 @@
} }
@if(!string.IsNullOrWhiteSpace(Model.CustomerAddress3)) @if(!string.IsNullOrWhiteSpace(Model.CustomerAddress3))
{ {
@Model.CustomerAddress3 @Model.CustomerAddress3<br />
}
@if(!string.IsNullOrWhiteSpace(Model.CustomerAddress4))
{
@Model.CustomerAddress4
} }
</p> </p>
@if(Model.UsesVat)
{
<p>VAT @Model.CustomerVatNumber</p>
}
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -104,7 +108,6 @@
<thead> <thead>
<tr> <tr>
<th>Description</th> <th>Description</th>
<th class="right" style="width: 100px;">Qty</th>
@if(Model.UsesVat) @if(Model.UsesVat)
{ {
<th class="right" style="width: 100px;">VAT %</th> <th class="right" style="width: 100px;">VAT %</th>
@ -118,7 +121,6 @@
{ {
<tr> <tr>
<td>@item.Description</td> <td>@item.Description</td>
<td class="right">@item.Quantity</td>
@if(Model.UsesVat) @if(Model.UsesVat)
{ {
<td class="right">0</td> <td class="right">0</td>

View File

@ -52,6 +52,11 @@
"privateKey": "SECRET" "privateKey": "SECRET"
} }
}, },
"apiSettings": {
"ourAddress1": "123 Green St.",
"ourAddress2": "New York, NY 10001",
"ourAddress3": "United States"
},
"IpRateLimitOptions": { "IpRateLimitOptions": {
"EnableEndpointRateLimiting": true, "EnableEndpointRateLimiting": true,
"StackBlockedRequests": false, "StackBlockedRequests": false,