Housekeeping on InboundInvoices; added OrgSeqId
This commit is contained in:
@@ -5,8 +5,8 @@ namespace Swarmops.Basic.Types.Financial
|
||||
{
|
||||
public class BasicInboundInvoice : IHasIdentity
|
||||
{
|
||||
public BasicInboundInvoice (int inboundInvoiceId, int organizationId, DateTime createdDateTime,
|
||||
DateTime dueDate, Int64 amountCents, Int64 vatCents, int budgetId, string supplier, string
|
||||
public BasicInboundInvoice (int inboundInvoiceId, int organizationId, int organizationSequenceId,
|
||||
DateTime createdDateTime, DateTime dueDate, Int64 amountCents, Int64 vatCents, int budgetId, string supplier, string
|
||||
payToAccount, string ocr, string invoiceReference, bool attested, bool open,
|
||||
DateTime closedDateTime, int closedByPersonId)
|
||||
{
|
||||
@@ -28,7 +28,8 @@ namespace Swarmops.Basic.Types.Financial
|
||||
}
|
||||
|
||||
public BasicInboundInvoice (BasicInboundInvoice original)
|
||||
: this (original.InboundInvoiceId, original.OrganizationId, original.CreatedDateTime,
|
||||
: this (original.InboundInvoiceId, original.OrganizationId, original.OrganizationSequenceId,
|
||||
original.CreatedDateTime,
|
||||
original.DueDate, original.AmountCents, original.VatCents, original.BudgetId,
|
||||
original.Supplier, original.PayToAccount, original.Ocr, original.InvoiceReference,
|
||||
original.Attested, original.Open, original.ClosedDateTime, original.ClosedByPersonId)
|
||||
@@ -38,6 +39,7 @@ namespace Swarmops.Basic.Types.Financial
|
||||
|
||||
public int InboundInvoiceId { get; private set; }
|
||||
public DateTime CreatedDateTime { get; private set; }
|
||||
public int OrganizationSequenceId { get; protected set; }
|
||||
public DateTime DueDate { get; protected set; }
|
||||
public int BudgetId { get; protected set; }
|
||||
public bool Attested { get; protected set; }
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Swarmops.Database
|
||||
/// </summary>
|
||||
public static int DbVersionExpected
|
||||
{
|
||||
get { return 39; }
|
||||
get { return 41; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Swarmops.Database
|
||||
" InboundInvoiceId,OrganizationId,CreatedDateTime,CreatedByPersonId,DueDate," +
|
||||
"AmountCents,BudgetId,Attested,Open,Supplier," +
|
||||
"PayToAccount,Ocr,InvoiceReference,ClosedDateTime,ClosedByPersonId, " +
|
||||
"VatCents " +
|
||||
"VatCents, OrganizationSequenceId " +
|
||||
"FROM InboundInvoices ";
|
||||
|
||||
private BasicInboundInvoice ReadInboundInvoiceFromDataReader (DbDataReader reader)
|
||||
@@ -38,8 +38,9 @@ namespace Swarmops.Database
|
||||
DateTime closedDateTime = reader.GetDateTime (13);
|
||||
int closedByPersonId = reader.GetInt32 (14);
|
||||
Int64 vatCents = reader.GetInt64(15);
|
||||
int organizationSequenceId = reader.GetInt32(16);
|
||||
|
||||
return new BasicInboundInvoice (inboundInvoiceId, organizationId, createdDateTime, dueDate,
|
||||
return new BasicInboundInvoice (inboundInvoiceId, organizationId, organizationSequenceId, createdDateTime, dueDate,
|
||||
amountCents, vatCents, budgetId, supplier, payToAccount, ocr, invoiceReference,
|
||||
attested, open, closedDateTime, closedByPersonId);
|
||||
}
|
||||
@@ -106,32 +107,6 @@ namespace Swarmops.Database
|
||||
|
||||
#region Creation and manipulation - stored procedures
|
||||
|
||||
/* -- UNUSED
|
||||
public int CreateInboundInvoice(int organizationId, DateTime dueDate, int budgetId,
|
||||
string supplier, string payToAccount, string ocr, string invoiceReference, double amount, int createdByPersonId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("CreateInboundInvoice", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "organizationId", organizationId);
|
||||
AddParameterWithName(command, "createdDateTime", DateTime.Now);
|
||||
AddParameterWithName(command, "dueDate", dueDate);
|
||||
AddParameterWithName(command, "budgetId", budgetId);
|
||||
AddParameterWithName(command, "supplier", supplier);
|
||||
AddParameterWithName(command, "payToAccount", payToAccount);
|
||||
AddParameterWithName(command, "ocr", ocr);
|
||||
AddParameterWithName(command, "invoiceReference", invoiceReference);
|
||||
AddParameterWithName(command, "amount", amount);
|
||||
AddParameterWithName(command, "createdByPersonId", createdByPersonId);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
public int CreateInboundInvoice (int organizationId, DateTime dueDate, int budgetId, string supplier,
|
||||
string payToAccount, string ocr, string invoiceReference, Int64 amountCents, int createdByPersonId)
|
||||
@@ -140,7 +115,7 @@ namespace Swarmops.Database
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand ("CreateInboundInvoicePrecise", connection);
|
||||
DbCommand command = GetDbCommand ("CreateInboundInvoice", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName (command, "organizationId", organizationId);
|
||||
@@ -159,17 +134,33 @@ namespace Swarmops.Database
|
||||
}
|
||||
|
||||
|
||||
public void SetInboundInvoiceOpen (int inboundInvoiceId, bool open)
|
||||
public int SetInboundInvoiceSequence(int inboundInvoiceId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand ("SetInboundInvoiceOpen", connection);
|
||||
DbCommand command = GetDbCommand("SetInboundInvoiceOrganizationSequenceId", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName (command, "inboundInvoiceId", inboundInvoiceId);
|
||||
AddParameterWithName (command, "open", open);
|
||||
AddParameterWithName(command, "inboundInvoiceId", inboundInvoiceId);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetInboundInvoiceOpen(int inboundInvoiceId, bool open)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetInboundInvoiceOpen", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "inboundInvoiceId", inboundInvoiceId);
|
||||
AddParameterWithName(command, "open", open);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
@@ -37,4 +37,5 @@
|
||||
0037 - Added Suppliers, ExternalContacts tables; no procs for them yet [RF]
|
||||
0038 - VAT Report tables and functions [RF]
|
||||
0039 - VatReport.Guid added [RF]
|
||||
0040 - Document.HiresStatus added [RF]
|
||||
0040 - Document.HiresStatus added [RF]
|
||||
0041 - InboundInvoice housekeeping; added OrgSeqId [RF]
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
ALTER TABLE `InboundInvoices`
|
||||
DROP COLUMN `Amount`,
|
||||
ADD COLUMN `OrganizationSequenceId` INT NOT NULL DEFAULT 0 AFTER `OrganizationId`,
|
||||
ADD INDEX `Index_SequenceId` (`OrganizationSequenceId` ASC)
|
||||
|
||||
|
||||
#
|
||||
|
||||
DROP PROCEDURE IF EXISTS `CreateInboundInvoice`
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
DROP PROCEDURE IF EXISTS `CreateInboundInvoicePrecise`
|
||||
|
||||
|
||||
#
|
||||
|
||||
CREATE PROCEDURE `CreateInboundInvoice`(
|
||||
organizationId INTEGER,
|
||||
createdDateTime DATETIME,
|
||||
dueDate DATETIME,
|
||||
budgetId INTEGER,
|
||||
supplier VARCHAR(64),
|
||||
payToAccount VARCHAR(64),
|
||||
ocr VARCHAR(64),
|
||||
invoiceReference VARCHAR(64),
|
||||
amountCents BIGINT,
|
||||
createdByPersonId INTEGER
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE newIdentity INTEGER;
|
||||
DECLARE sequenceNumber INTEGER;
|
||||
|
||||
INSERT INTO InboundInvoices
|
||||
(OrganizationId, CreatedDateTime, DueDate, BudgetId, Supplier, Attested, Open, PayToAccount, Ocr,
|
||||
InvoiceReference, ClosedDateTime, AmountCents, CreatedByPersonId, ClosedByPersonId)
|
||||
VALUES
|
||||
(organizationId, createdDateTime, dueDate, budgetId, supplier, 0, 1, payToAccount, ocr,
|
||||
invoiceReference, createdDateTime, amountCents, createdByPersonId, 0);
|
||||
|
||||
SELECT LAST_INSERT_ID() INTO newIdentity;
|
||||
|
||||
SELECT COUNT(*) FROM InboundInvoices WHERE
|
||||
InboundInvoices.OrganizationId = organizationId AND
|
||||
InboundInvoices.InboundInvoiceId <= newIdentity INTO sequenceNumber;
|
||||
|
||||
UPDATE InboundInvoices
|
||||
SET InboundInvoices.OrganizationSequenceId = sequenceNumber
|
||||
WHERE InboundInvoices.InboundInvoiceId = newIdentity;
|
||||
|
||||
SELECT newIdentity AS Identity;
|
||||
|
||||
END
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
CREATE PROCEDURE `SetInboundInvoiceOrganizationSequenceId`(
|
||||
IN inboundInvoiceId INTEGER
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE organizationId INTEGER;
|
||||
DECLARE sequenceNumber INTEGER;
|
||||
|
||||
SELECT InboundInvoices.OrganizationId
|
||||
FROM InboundInvoices
|
||||
WHERE InboundInvoices.InboundInvoiceId = inboundInvoiceId
|
||||
INTO organizationId;
|
||||
|
||||
SELECT COUNT(*)
|
||||
FROM InboundInvoices
|
||||
WHERE InboundInvoices.OrganizationId=organizationId
|
||||
AND InboundInvoices.InboundInvoicesId <= inboundInvoiceId
|
||||
INTO sequenceNumber;
|
||||
|
||||
UPDATE InboundInvoices SET OrganizationSequenceId = sequenceNumber
|
||||
WHERE InboundInvoices.InboundInvoiceId = inboundInvoiceId;
|
||||
|
||||
SELECT sequenceNumber AS OrganizationSequenceId;
|
||||
|
||||
END
|
||||
@@ -46,6 +46,22 @@ namespace Swarmops.Logic.Financial
|
||||
}
|
||||
|
||||
|
||||
public int OrganizationSequenceId
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.OrganizationSequenceId == 0)
|
||||
{
|
||||
SwarmDb db = SwarmDb.GetDatabaseForWriting();
|
||||
base.OrganizationSequenceId = db.SetInboundInvoiceSequence(this.Identity);
|
||||
return base.OrganizationSequenceId;
|
||||
}
|
||||
|
||||
return base.OrganizationSequenceId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public decimal Amount
|
||||
{
|
||||
get { return base.AmountCents/100.0m; }
|
||||
|
||||
@@ -63,7 +63,7 @@ public partial class Pages_v5_Finance_Json_ListInvoicesInbound : DataV5Base
|
||||
//"<img id=\\\"IconDenied{5}\\\" class=\\\"LocalIconDenied LocalNew\\\" baseid=\\\"{5}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
|
||||
//"<img id=\\\"IconUndo{5}\\\" class=\\\"LocalIconUndo LocalNew\\\" baseid=\\\"{5}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
|
||||
"</span>\"",
|
||||
"#" + invoice.Identity.ToString("N0"),
|
||||
"#" + invoice.OrganizationSequenceId.ToString("N0"),
|
||||
|
||||
JsonSanitize(invoice.DueDate.ToString(invoice.DueDate < dueDateFormatBreakDate ? "yyyy-MMM" : "MMM-dd")),
|
||||
JsonSanitize(invoice.Supplier),
|
||||
|
||||
Reference in New Issue
Block a user