Work on inbound invoices
This commit is contained in:
@@ -360,4 +360,15 @@
|
||||
<data name="Global_ImageSpecification" xml:space="preserve">
|
||||
<value>Image {0} of {1}</value>
|
||||
</data>
|
||||
<data name="Financial_DueDate" xml:space="preserve">
|
||||
<value>Due Date</value>
|
||||
<comment>For invoices and similar</comment>
|
||||
</data>
|
||||
<data name="Financial_Supplier" xml:space="preserve">
|
||||
<value>Supplier</value>
|
||||
</data>
|
||||
<data name="Global_CurrentLanguageName_Native" xml:space="preserve">
|
||||
<value>English (US)</value>
|
||||
<comment>Replace with THIS language, EXPRESSED IN this language. Examples: "Español", "Français", "Svenska", etc.</comment>
|
||||
</data>
|
||||
</root>
|
||||
@@ -190,6 +190,45 @@
|
||||
<value>Salary #{0} for {1} was DE-attested. It will not be paid out unless attested again.</value>
|
||||
<comment>When somebody undoes a previous attestation.</comment>
|
||||
</data>
|
||||
<data name="CreateInboundInvoice_Amount" xml:space="preserve">
|
||||
<value>Invoice amount (in {0})</value>
|
||||
<comment>{0} is the organization's main currency.</comment>
|
||||
</data>
|
||||
<data name="CreateInboundInvoice_Description" xml:space="preserve">
|
||||
<value>Description</value>
|
||||
<comment>Free-text description of invoice</comment>
|
||||
</data>
|
||||
<data name="CreateInboundInvoice_HeaderInvoiceImage" xml:space="preserve">
|
||||
<value>Invoice Image</value>
|
||||
</data>
|
||||
<data name="CreateInboundInvoice_HeaderPaymentDetails" xml:space="preserve">
|
||||
<value>Payment Details</value>
|
||||
<comment>Displayed as header over supplier's account details</comment>
|
||||
</data>
|
||||
<data name="CreateInboundInvoice_Info" xml:space="preserve">
|
||||
<value>This is where you file invoices received at your organization ("Accounts Payable"). Enter the supplier name, amount, due date, the invoice reference, and upload an image of the received invoice. Also, select a budget. The budget owner needs to attest, as usual. (Future roadmapped expansions to this mechanism include purchase orders and supplier lists.)</value>
|
||||
</data>
|
||||
<data name="CreateInboundInvoice_PageTitle" xml:space="preserve">
|
||||
<value>Received Inbound Invoice</value>
|
||||
</data>
|
||||
<data name="CreateInboundInvoice_Reference" xml:space="preserve">
|
||||
<value>Invoice reference</value>
|
||||
</data>
|
||||
<data name="CreateInboundInvoice_ReferenceAutomaticOcr" xml:space="preserve">
|
||||
<value>OCR / Automatic</value>
|
||||
<comment>Some invoices come with OCR numbers printed on them for automatic processing.</comment>
|
||||
</data>
|
||||
<data name="CreateInboundInvoice_ReferenceManual" xml:space="preserve">
|
||||
<value>Manual</value>
|
||||
<comment>Other invoices come without automated processing and a manual </comment>
|
||||
</data>
|
||||
<data name="CreateInboundInvoice_SupplierAccount" xml:space="preserve">
|
||||
<value>Account</value>
|
||||
<comment>Free text input, intended to convey everything needed to get the money right</comment>
|
||||
</data>
|
||||
<data name="CreateInboundInvoice_UploadInvoiceImage" xml:space="preserve">
|
||||
<value>Upload image file</value>
|
||||
</data>
|
||||
<data name="FileExpenseClaim_Amount" xml:space="preserve">
|
||||
<value>Expense claim amount (in {0})</value>
|
||||
<comment>{0} is the currency.</comment>
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Swarmops.Controls.Base
|
||||
}
|
||||
|
||||
public string GuidString;
|
||||
public UploadFilter Filter;
|
||||
public UploadFilter Filter { get; set; }
|
||||
|
||||
|
||||
public enum UploadFilter
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 757 B |
Binary file not shown.
|
After Width: | Height: | Size: 2.7 KiB |
@@ -165,7 +165,7 @@
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Validate Receipts" NavigateUrl="~/Pages/v5/Financial/ValidateReceipts.aspx" ImageUrl="~/Images/PageIcons/iconshock-invoice-greentick-16px.png" Permission="Economy:Write" UserLevel="2" GlobalResourceKey="Menu5_Financial_ValidateReceipts" />
|
||||
<telerik:RadMenuItem runat="server" IsSeparator="true" UserLevel="2" />
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Send Invoice" Permission="Economy:Write" UserLevel="2" GlobalResourceKey="Menu5_Financial_SendInvoice" />
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Received Invoice" Permission="Economy:Write" UserLevel="2" GlobalResourceKey="Menu5_Financial_ReceivedInvoice" />
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Received Invoice" Permission="Economy:Write" UserLevel="2" NavigateUrl="~/Pages/v5/Financial/CreateInboundInvoice.aspx" ImageUrl="~/Images/PageIcons/iconshock-invoice-16px.png" GlobalResourceKey="Menu5_Financial_ReceivedInvoice" />
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Gigs Assistant" Permission="All" UserLevel="3" GlobalResourceKey="Menu5_Financial_GigsAssistant" />
|
||||
<telerik:RadMenuItem runat="server" IsSeparator="true" UserLevel="3" />
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ List" Permission="Economy:Read" UserLevel="3" GlobalResourceKey="Menu5_Financial_List">
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="CreateInboundInvoice.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Financial.CreateInboundInvoice" %>
|
||||
<%@ Register src="~/Controls/v5/Base/FileUpload.ascx" tagname="FileUpload" tagprefix="Swarmops5" %>
|
||||
<%@ Register TagPrefix="Swarmops5" TagName="ExternalScripts" Src="~/Controls/v5/UI/ExternalScripts.ascx" %>
|
||||
<%@ Register TagPrefix="Swarmops5" TagName="ComboBudgets" Src="~/Controls/v5/Financial/ComboBudgets.ascx" %>
|
||||
|
||||
<asp:Content ID="Content4" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
|
||||
<Swarmops5:ExternalScripts ID="ExternalScripts1" Package="easyui" Control="tree" runat="server" />
|
||||
<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
|
||||
<script src="/Scripts/jquery.fileupload/jquery.iframe-transport.js" type="text/javascript" language="javascript"></script>
|
||||
<!-- The basic File Upload plugin -->
|
||||
<script src="/Scripts/jquery.fileupload/jquery.fileupload.js" type="text/javascript" language="javascript"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/Style/v5-easyui-elements.css">
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
<asp:Repeater ID="RepeaterTagDropScript" runat="server"><ItemTemplate>
|
||||
$('#DropTags<%# Eval("TagSetId") %>').combotree({
|
||||
animate: true,
|
||||
height: 30
|
||||
});
|
||||
|
||||
|
||||
$('#SpanDropTags<%# Eval("TagSetId") %> span.combo input.combo-text').click(function () {
|
||||
$('#SpanDropTags<%# Eval("TagSetId") %> span.combo span span.combo-arrow').click();
|
||||
});
|
||||
</ItemTemplate></asp:Repeater>
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function validateFields() {
|
||||
var isValid = true;
|
||||
|
||||
isValid = validateTextField('#<%=this.TextAccount.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorBankAccount" />") && isValid;
|
||||
|
||||
if ($('#<%=this.ComboBudgets.ClientID %>_DropBudgets').combotree('tree').tree('getSelected') == null) {
|
||||
isValid = false;
|
||||
$('#<%=this.ComboBudgets.ClientID %>_SpanBudgets').addClass("entryError");
|
||||
alertify.error("<asp:Literal runat="server" ID="LiteralErrorBudget" />");
|
||||
}
|
||||
|
||||
<asp:Repeater ID="RepeaterErrorCheckTags" runat="server"><ItemTemplate>
|
||||
if ($('#DropTags<%# Eval("TagSetId") %>').combotree('tree').tree('getSelected') == null) {
|
||||
isValid = false;
|
||||
$('#SpanDropTags<%# Eval("TagSetId") %>').addClass("entryError");
|
||||
alertify.error('<%=Resources.Pages.Financial.FileExpenseClaim_ValidationError_MissingTag.Replace("'", "''") %>');
|
||||
}
|
||||
</ItemTemplate></asp:Repeater>
|
||||
|
||||
isValid = validateTextField('#<%=this.TextPurpose.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorPurpose" />") && isValid;
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/Automation/FieldValidation.asmx/IsAmountValid",
|
||||
data: "{'amount': '" + escape($('#<%=this.TextAmount.ClientID %>').val()) + "'}",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
async: false, // blocks until function returns - race conditions otherwise
|
||||
success: function (msg) {
|
||||
if (msg.d != true) {
|
||||
isValid = false;
|
||||
$('#TextAmount').addClass("entryError");
|
||||
alertify.error("<asp:Literal runat="server" ID="LiteralErrorAmount" />");
|
||||
$('#<%=this.TextAmount.ClientID %>').focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/Automation/FieldValidation.asmx/AreDocumentsUploaded",
|
||||
data: "{'guidString': '<%=this.FileUpload.GuidString %>'}",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
async: false, // blocks until function returns - race conditions otherwise
|
||||
success: function (msg) {
|
||||
if (msg.d != true) {
|
||||
isValid = false;
|
||||
$('#TextAmount').addClass("entryError");
|
||||
alertify.error("<asp:Literal runat="server" ID="LiteralErrorDocuments" />");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
function validateTextField (fieldId, message) {
|
||||
if ($(fieldId).val().length == 0) {
|
||||
alertify.error(message);
|
||||
$(fieldId).addClass("entryError");
|
||||
$(fieldId).focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
</script>
|
||||
</asp:Content>
|
||||
|
||||
|
||||
<asp:Content ID="Content5" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
|
||||
<asp:HiddenField ID="HiddenTagSetIdentifiers" runat="server"/>
|
||||
<div class="entryFields">
|
||||
<asp:TextBox runat="server" ID="TextSupplier" />​<br/>
|
||||
<asp:TextBox runat="server" ID="TextAmount" CssClass="alignRight" />​<br/>
|
||||
<asp:TextBox runat="server" ID="TextPurpose" />​<br/>
|
||||
<asp:TextBox runat="server" ID="TextDueDate" />​<br/>
|
||||
<Swarmops5:ComboBudgets ID="ComboBudgets" runat="server" /> <br/>
|
||||
<asp:Repeater ID="RepeaterTagDrop" runat="server"><ItemTemplate><span id="SpanDropTags<%# Eval("TagSetId") %>"><select class="easyui-combotree" url="/Automation/Json-TransactionTagsTree.aspx?TagSetId=<%# Eval("TagSetId") %>" name="DropTags<%# Eval("TagSetId") %>" id="DropTags<%# Eval("TagSetId") %>" animate="true" style="width:300px"></select></span> <br/></ItemTemplate></asp:Repeater>
|
||||
|
||||
<br/><!-- placeholder for label-side H2 -->
|
||||
|
||||
<!-- file upload begins here -->
|
||||
|
||||
<Swarmops5:FileUpload ID="FileUpload" runat="server" Filter="ImagesOrPdf"/>
|
||||
|
||||
<!-- file upload ends -->
|
||||
|
||||
<br/><!-- placeholder for label-side H2 -->
|
||||
<asp:TextBox runat="server" ID="TextAccount" /> <br/>
|
||||
<asp:TextBox runat="server" ID="TextReference" />​<br/>
|
||||
<asp:Button ID="ButtonCreate" runat="server" CssClass="buttonAccentColor NoInputFocus" OnClientClick="return validateFields();" OnClick="ButtonCreate_Click" Text="Create"/>
|
||||
</div>
|
||||
<div class="entryLabels">
|
||||
<asp:Label runat="server" ID="LabelSupplier" /><br/>
|
||||
<asp:Label runat="server" ID="LabelAmount" /><br/>
|
||||
<asp:Label runat="server" ID="LabelPurpose" /><br/>
|
||||
<asp:Label runat="server" ID="LabelDueDate" /><br/>
|
||||
<asp:Label runat="server" ID="LabelBudget" /><br/>
|
||||
<asp:Repeater ID="RepeaterTagLabels" runat="server"><ItemTemplate><%# Eval("TagSetLocalizedName") %><br/></ItemTemplate></asp:Repeater>
|
||||
<h2><asp:Label runat="server" ID="LabelHeaderImageFiles" /></h2>
|
||||
<asp:Label runat="server" ID="LabelImageFiles" /><br/>
|
||||
<h2><asp:Label runat="server" ID="LabelHeaderBankDetails" /></h2>
|
||||
<asp:Label runat="server" ID="LabelAccount" /><br/>
|
||||
<asp:Label runat="server" ID="LabelReference" /><br/>
|
||||
</div>
|
||||
<div style="clear:both"></div>
|
||||
</asp:Content>
|
||||
|
||||
|
||||
|
||||
<asp:Content ID="Content6" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
|
||||
</asp:Content>
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using Swarmops.Logic.Financial;
|
||||
using Swarmops.Logic.Support;
|
||||
|
||||
namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
{
|
||||
public partial class CreateInboundInvoice : PageV5Base
|
||||
{
|
||||
protected void Page_Init(object sender, EventArgs e)
|
||||
{
|
||||
string tagSetIdsString = Request["ctl00$PlaceHolderMain$HiddenTagSetIdentifiers"];
|
||||
|
||||
// Find our tag ids, either from previously hidden var or load from org
|
||||
|
||||
if (String.IsNullOrEmpty(tagSetIdsString))
|
||||
{
|
||||
_tagSetIds = FinancialTransactionTagSets.ForOrganization(this.CurrentOrganization).Identities;
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] tagSetIdStrings = tagSetIdsString.Split(',');
|
||||
_tagSetIds = new int[tagSetIdStrings.Length];
|
||||
|
||||
for (int index = 0; index < tagSetIdStrings.Length; index++)
|
||||
{
|
||||
_tagSetIds[index] = Int32.Parse(tagSetIdStrings[index]);
|
||||
}
|
||||
}
|
||||
|
||||
// Construct data source
|
||||
|
||||
List<TagSetDataSourceItem> dataSource = new List<TagSetDataSourceItem>();
|
||||
|
||||
foreach (int tagSetId in _tagSetIds)
|
||||
{
|
||||
TagSetDataSourceItem item = new TagSetDataSourceItem()
|
||||
{
|
||||
TagSetId = tagSetId,
|
||||
TagSetLocalizedName =
|
||||
FinancialTransactionTagSetType.GetLocalizedName(
|
||||
FinancialTransactionTagSet.FromIdentity(tagSetId).
|
||||
FinancialTransactionTagSetTypeId)
|
||||
};
|
||||
dataSource.Add(item);
|
||||
}
|
||||
|
||||
// Bind data
|
||||
|
||||
this.RepeaterTagLabels.DataSource = dataSource;
|
||||
this.RepeaterTagDrop.DataSource = dataSource;
|
||||
this.RepeaterTagDropScript.DataSource = dataSource;
|
||||
this.RepeaterErrorCheckTags.DataSource = dataSource;
|
||||
|
||||
this.RepeaterTagLabels.DataBind();
|
||||
this.RepeaterTagDrop.DataBind();
|
||||
this.RepeaterTagDropScript.DataBind();
|
||||
this.RepeaterErrorCheckTags.DataBind();
|
||||
|
||||
// Write set list back to hidden variable
|
||||
|
||||
List<string> tagSetIdStringList = new List<string>();
|
||||
|
||||
foreach (int tagSetId in _tagSetIds)
|
||||
{
|
||||
tagSetIdStringList.Add(tagSetId.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
this.HiddenTagSetIdentifiers.Value = String.Join(",", tagSetIdStringList.ToArray());
|
||||
}
|
||||
|
||||
private int[] _tagSetIds;
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!this.CurrentOrganization.IsEconomyEnabled)
|
||||
{
|
||||
Response.Redirect("/Pages/v5/Financial/EconomyNotEnabled.aspx", true);
|
||||
return;
|
||||
}
|
||||
|
||||
this.PageTitle = Resources.Pages.Financial.CreateInboundInvoice_PageTitle;
|
||||
this.PageIcon = "iconshock-invoice";
|
||||
this.InfoBoxLiteral = Resources.Pages.Financial.CreateInboundInvoice_Info;
|
||||
|
||||
if (!Page.IsPostBack)
|
||||
{
|
||||
// Prime bank details
|
||||
|
||||
this.TextAmount.Text = 0.ToString("N2");
|
||||
this.TextSupplier.Focus();
|
||||
this.TextDueDate.Text = DateTime.Today.AddDays(30).ToShortDateString(); // Use current culture
|
||||
|
||||
Localize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Localize()
|
||||
{
|
||||
this.LabelSupplier.Text = Resources.Global.Financial_Supplier;
|
||||
this.LabelDueDate.Text = Resources.Global.Financial_DueDate;
|
||||
this.LabelAmount.Text = string.Format(Resources.Pages.Financial.CreateInboundInvoice_Amount,
|
||||
CurrentOrganization.Currency.Code);
|
||||
this.LabelPurpose.Text = Resources.Pages.Financial.CreateInboundInvoice_Description;
|
||||
this.LabelBudget.Text = Resources.Global.Financial_Budget;
|
||||
this.LabelHeaderBankDetails.Text = Resources.Pages.Financial.CreateInboundInvoice_HeaderPaymentDetails;
|
||||
this.LabelHeaderImageFiles.Text = Resources.Pages.Financial.CreateInboundInvoice_HeaderInvoiceImage;
|
||||
this.LabelImageFiles.Text = Resources.Pages.Financial.CreateInboundInvoice_UploadInvoiceImage;
|
||||
this.LabelReference.Text = Resources.Pages.Financial.CreateInboundInvoice_Reference;
|
||||
this.LabelAccount.Text = Resources.Pages.Financial.CreateInboundInvoice_SupplierAccount;
|
||||
|
||||
this.LiteralErrorAmount.Text = Resources.Pages.Financial.FileExpenseClaim_ValidationError_Amount; // TODO: Validation errors
|
||||
this.LiteralErrorPurpose.Text = Resources.Pages.Financial.FileExpenseClaim_ValidationError_Purpose;
|
||||
this.LiteralErrorBudget.Text = Resources.Pages.Financial.RequestCashAdvance_ValidationError_Budget;
|
||||
this.LiteralErrorBankAccount.Text = Resources.Pages.Financial.RequestCashAdvance_ValidationError_BankAccount;
|
||||
this.LiteralErrorDocuments.Text = Resources.Pages.Financial.FileExpenseClaim_ValidationError_Documents;
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void ButtonCreate_Click(object sender, EventArgs e) // TODO
|
||||
{
|
||||
// The data has been validated client-side already. We'll throw unfriendly exceptions if invalid data is passed here.
|
||||
// People who choose to disable JavaScript and then submit bad input almost deserve to be hurt.
|
||||
|
||||
double amount = Double.Parse(this.TextAmount.Text, NumberStyles.Number);
|
||||
// parses in current culture - intentional
|
||||
Int64 amountCents = (Int64) amount*100;
|
||||
|
||||
string description = this.TextPurpose.Text;
|
||||
|
||||
DateTime dueDate = DateTime.Parse(this.TextDueDate.Text);
|
||||
|
||||
|
||||
FinancialAccount budget = FinancialAccount.FromIdentity(Int32.Parse(this.Request.Form["DropBudgets"]));
|
||||
|
||||
// sanity check
|
||||
|
||||
if (budget.Organization.Identity != CurrentOrganization.Identity)
|
||||
{
|
||||
throw new InvalidOperationException("Budget-organization mismatch; won't file expense claim");
|
||||
}
|
||||
|
||||
|
||||
// Get documents; check that documents have been uploaded
|
||||
|
||||
Documents documents = Documents.RecentFromDescription (this.FileUpload.GuidString);
|
||||
|
||||
if (documents.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException("No documents uploaded");
|
||||
}
|
||||
|
||||
InboundInvoice invoice = InboundInvoice.Create(CurrentOrganization, dueDate, amountCents, budget,
|
||||
this.TextSupplier.Text, this.TextAccount.Text, string.Empty,
|
||||
this.TextReference.Text, CurrentUser);
|
||||
|
||||
foreach (int tagSetId in _tagSetIds)
|
||||
{
|
||||
string selectedTagString =
|
||||
this.Request.Form["DropTags" + tagSetId.ToString(CultureInfo.InvariantCulture)];
|
||||
|
||||
if (!String.IsNullOrEmpty(selectedTagString))
|
||||
{
|
||||
int selectedTagType = Int32.Parse(selectedTagString);
|
||||
invoice.FinancialTransaction.CreateTag(FinancialTransactionTagType.FromIdentity(selectedTagType), CurrentUser);
|
||||
}
|
||||
}
|
||||
|
||||
documents.SetForeignObjectForAll(invoice);
|
||||
|
||||
// TODO: Clear fields, show success message, return to blank fields
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected class TagSetDataSourceItem
|
||||
{
|
||||
public int TagSetId { get; set; }
|
||||
public string TagSetLocalizedName { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user