From fb3ee26e1d334a2aec7fb8f9accad4d354b852ca Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sat, 28 Dec 2013 12:36:05 +0000 Subject: [PATCH] Work on inbound invoices --- Site5/App_GlobalResources/Global.resx | 11 + .../App_GlobalResources/Pages.Financial.resx | 39 ++++ Site5/Controls/v5/Base/FileUpload.ascx.cs | 2 +- .../PageIcons/iconshock-invoice-16px.png | Bin 0 -> 757 bytes .../PageIcons/iconshock-invoice-40px.png | Bin 0 -> 2763 bytes Site5/Master-v5.master | 2 +- .../v5/Financial/CreateInboundInvoice.aspx | 151 ++++++++++++++ .../v5/Financial/CreateInboundInvoice.aspx.cs | 189 ++++++++++++++++++ 8 files changed, 392 insertions(+), 2 deletions(-) create mode 100644 Site5/Images/PageIcons/iconshock-invoice-16px.png create mode 100644 Site5/Images/PageIcons/iconshock-invoice-40px.png create mode 100644 Site5/Pages/v5/Financial/CreateInboundInvoice.aspx create mode 100644 Site5/Pages/v5/Financial/CreateInboundInvoice.aspx.cs diff --git a/Site5/App_GlobalResources/Global.resx b/Site5/App_GlobalResources/Global.resx index 01e71c64..36a778ce 100644 --- a/Site5/App_GlobalResources/Global.resx +++ b/Site5/App_GlobalResources/Global.resx @@ -360,4 +360,15 @@ Image {0} of {1} + + Due Date + For invoices and similar + + + Supplier + + + English (US) + Replace with THIS language, EXPRESSED IN this language. Examples: "Español", "Français", "Svenska", etc. + \ No newline at end of file diff --git a/Site5/App_GlobalResources/Pages.Financial.resx b/Site5/App_GlobalResources/Pages.Financial.resx index 84d20b57..4051d403 100644 --- a/Site5/App_GlobalResources/Pages.Financial.resx +++ b/Site5/App_GlobalResources/Pages.Financial.resx @@ -190,6 +190,45 @@ Salary #{0} for {1} was DE-attested. It will not be paid out unless attested again. When somebody undoes a previous attestation. + + Invoice amount (in {0}) + {0} is the organization's main currency. + + + Description + Free-text description of invoice + + + Invoice Image + + + Payment Details + Displayed as header over supplier's account details + + + 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.) + + + Received Inbound Invoice + + + Invoice reference + + + OCR / Automatic + Some invoices come with OCR numbers printed on them for automatic processing. + + + Manual + Other invoices come without automated processing and a manual + + + Account + Free text input, intended to convey everything needed to get the money right + + + Upload image file + Expense claim amount (in {0}) {0} is the currency. diff --git a/Site5/Controls/v5/Base/FileUpload.ascx.cs b/Site5/Controls/v5/Base/FileUpload.ascx.cs index 011cf332..8ec00c0d 100644 --- a/Site5/Controls/v5/Base/FileUpload.ascx.cs +++ b/Site5/Controls/v5/Base/FileUpload.ascx.cs @@ -29,7 +29,7 @@ namespace Swarmops.Controls.Base } public string GuidString; - public UploadFilter Filter; + public UploadFilter Filter { get; set; } public enum UploadFilter diff --git a/Site5/Images/PageIcons/iconshock-invoice-16px.png b/Site5/Images/PageIcons/iconshock-invoice-16px.png new file mode 100644 index 0000000000000000000000000000000000000000..052a801e0a259fc4fea7d53caae9ca30ac8227da GIT binary patch literal 757 zcmVE<)rDJEiYrA|Qt&TO z>dFf4g^FFcRuDz7i;9bCYh!Giq?t~q$z(E*%)^BUjV7Mmg?oRTb1#?RknTT!?H%Zh z-()D+GE8&l`*u!x`R?=n>azzD8i*V&9xZE;OwxopfcrY_@5ry46ip3%Nv=WB1#N_rj(FO9EDM-U@iL-*}MqD z&>K6bs0v9X`$$hQj%+RqjZ(n5NKfmZnsz_u+Ci?hEA?{wXK{Se8XuDMOO> zzzY!wktkqWF#Q~apbw^Lpe|r}{sw}qC(JiB1$vW73=NNf=XtzZdI7Ppi^)?1FsfBz zST<=GA-9#eCkY%$w8sDt9LTaea_&4ib2bHrVNfcowpOWFb)P91=838lTf<%bso}xF z>(i5$rZ0>Rg~Fi_Ln$GYGFbciO_`m$I;G2nRRHCGzVR<-;Xu5re{?uC(9?Tj?DWb0 n@i*^3N=u86Zvj{VpaH-yH8%=1Y6kZJ00000NkvXXu0mjfDgZ-z literal 0 HcmV?d00001 diff --git a/Site5/Images/PageIcons/iconshock-invoice-40px.png b/Site5/Images/PageIcons/iconshock-invoice-40px.png new file mode 100644 index 0000000000000000000000000000000000000000..51e6b5fa9a68254651195d89237bf55fcd4beab9 GIT binary patch literal 2763 zcmV;+3N-bJP)#sy8;f*&>_WY%b!yNTN1NmMz;OkCT~9;4v^51VIuYNRS)? zB$-2i00|O6x#Tjp0J&srV1NWUBsmOZ#LHNgXCzzJYKxLgQxZ3EZL&8u#jb94*LyDq zQi?sWCv?;WJk+7ytM}pif8X~O!T<5RdiEzgSjy0sXbCAT%(?7lZR*O@Hg|rizplSP zaPI7%(1=IurPE)(@n*1VU-ZADK|5S_s|%$qcQL!Mxs=)1TAI&quFU5)mlxl@u|)RG z?XMdD{j;zCzX9(F;6MEPd+`&)J-I_YDe9i2F6GXgj1BZ?A%sv;_PW*W-r}S353(DNxH&a9 zd2ea$7*K5pK(|`+dG#8qDa7UZIRcJNGSNG!P4N9d<(-7p>*Ew|X0Nb9# z@AqSvCR!;3Ff%<(Fc`!%O#I-T&$fBx z$O-O0xX;4M5`|)hj~5q-rjm3I4>L463R>gU>l6wFr00=cUnd%k(wv*1r*iAL9*>jEe1W;-1D-|~|wlr&N8T9Vo9lt{;6z19IPh$v!NF;)7+sx0-u)MNN zsZwF9Rz>+NYHRB>rT3#B57v#$L5&ay+S(I3(Vi5KC#hDeR9tswQURH@4C`wdlvLP` z!)Q89|G*HQ=doET5e$WpQlgZ?Q@W7=wIO#jBczm%LmJ0%a2yA%H9`ntu@?6C_U(v5 z2-ep!T>Qlas@qj+)op&`w|<+)7JkBHgGy|fhQZal6YOhiBW(K#IetR6Lu(>|&$dB> z(h8;2lgV4#60|2%7^cbXTc6^29=6Yi{suX-CxAi-Z5jfk;_lSv+<$P7?$I$)U7aky z{|=q04kD&SGTzG2@F>A>2=8$zJr5xza(9{Zq@?UtlqXdKW5$zy5LC-$MpK;}?;Ri< zZsPv*eKs-~aB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km@n^o9n47pVc3YJgJ#bJMhM}dDLTmjcuu@8Td;3sI5ex)rYHC6V zfoYomd&?)plLJ$=QrU2ed%K%4f8Dpr%Cv8)P`i8i&I9%H3l{6`!hQQdv?g{b}J3@Tw5m9?7}uCKvo zK=a+vlSBXU*83wJZLLEiV|9UVidws@d7)kc4RKR(CN^|}Wr@vCxpEQ$Gt56S0p zwQ_c)AJ_s)yRG((0cxdOV0*V;t}uCZ6}Y}^n9UPcf4R>x%y{SM;r>+L$cs&W>(pSX zHT=w>VU8X>hHX1qN-4g047Dtai9vB%Jv4ehxa5&8UsVV;MpI%?Sf9>KwmUF8)UnL002ovPDHLkV1g{qIu8H< literal 0 HcmV?d00001 diff --git a/Site5/Master-v5.master b/Site5/Master-v5.master index 4cd22e12..1f12967b 100644 --- a/Site5/Master-v5.master +++ b/Site5/Master-v5.master @@ -165,7 +165,7 @@ - + diff --git a/Site5/Pages/v5/Financial/CreateInboundInvoice.aspx b/Site5/Pages/v5/Financial/CreateInboundInvoice.aspx new file mode 100644 index 00000000..79123e35 --- /dev/null +++ b/Site5/Pages/v5/Financial/CreateInboundInvoice.aspx @@ -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" %> + + + + + + + + + + + + + + + +
+ ​
+ ​
+ ​
+ ​
+  
+ "> 
+ +  
+ + + + + + + +  
+  
+ ​
+ +
+ +
+
+ + + + + + diff --git a/Site5/Pages/v5/Financial/CreateInboundInvoice.aspx.cs b/Site5/Pages/v5/Financial/CreateInboundInvoice.aspx.cs new file mode 100644 index 00000000..e02a4d24 --- /dev/null +++ b/Site5/Pages/v5/Financial/CreateInboundInvoice.aspx.cs @@ -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 dataSource = new List(); + + 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 tagSetIdStringList = new List(); + + 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; } + } + } +} \ No newline at end of file