Transaction Management
Create or modify transactions
An ID is used to identify entities. Therefore the correct ID to the instance is required, in order to modify (edited or deleted) an instance of a transaction.
There are two types of IDs: integer or GUID (global unique identifier). An Account, Bank etc. requires an integer ID, where Transaction, Posting or
Invoices require a GUID ID.
|
Integers for entities like:
|
|
GUID for entities like:
|
|
|
|
|
|
|
|
etc.
|
|
|
Example Code
Example Code
Create a new transaction
If you intend to create a transaction (new record), the ID has to be set to -1 for integer values or an "empty GUID" for GUID ID’s
(use the Guid.Empty property of .NET GUID class). There are various steps to take in order to create a new transaction:
-
Create a Transaction instance
-
Fill in the property for the created instance (Default property values or an empty (Guid.Empty) will be used, if properties haven't been set)
-
Load account list
-
Create postings
-
Add postings to the transaction
-
Save the transaction
// Load transactions via LoadTransactions()
errorcode = manager.LoadTransactions();
// Add here some logic to handle the error code
// Create a transaction instance
ITransaction transaction = new Transaction();
transaction.NumRangeFID = manager.Defaults.DefSimpleNumRangeFID;
transaction.TransactionTypeFID = (int)TransactionType.Simple;
transaction.DocNum = manager.Defaults.DefSimpleCurrNum;
transaction.DocType = "RR";
DateTime date = DateTime.Today;
transaction.DocDate = new DateTime(date.Year, date.Month, date.Day);
manager.LoadAccounts();
IPosting posting1 = new Posting();
posting1.AccountFID = manager.FindAccountID("1020");
// Create your first posting
posting1.Text = "Test Case Single Transaction Posting #1";
posting1.FreeCode = "SN_1002";
posting1.Amount = paymentAmount;
posting1.FcAmount = paymentAmount;
posting1.ExchangeRate = 1;
posting1.IsDebit = true;
posting1.IsInclusive = false;
// Create your second posting
IPosting posting2 = new Posting();
posting2.AccountFID = manager.FindAccountID("3200");
posting2.Text = "TestCase Single Transaction Posting #2";
posting2.FreeCode = "Free 2";
posting2.Amount = paymentAmount;
posting2.FcAmount = paymentAmount;
posting2.ExchangeRate = 1;
posting2.IsDebit = false;
posting2.IsInclusive = false;
transaction.Postings.Add(posting1);
transaction.Postings.Add(posting2);
// Save the created transaction
errorcode = manager.SaveTransaction(transaction);
// Add error handling here
UNDER CONSTRUCTION
An ID of the transaction is required to update (modify) an instance. The system will insert a new transaction, if an ID is empty (Guid.Empty or -1).
The following example shows how to update the posting text of all transactions:
// Load transactions via LoadTransactions()
manager.LoadTransactions();
for (int i = 0; i < manager.Transactions.Count; i++) {
ITransaction transaction = manager.Transactions[i];
int errorcode = manager.LoadTransaction(transaction);
foreach (IPosting p in tr.Postings) {
p.Text = i + " - " + DateTime.Now + Guid.NewGuid();
}
errorcode = manager.SaveTransaction(tr);
// Add error handling here
}
UNDER CONSTRUCTION
An ID of the transaction is required to delete an instance. The following example depicts the deletion of all transactions in the current client. Postings
themselves need not to be deleted separately, they will be deleted automatically by deleting the transaction.
themselves need not to be deleted separately, they will be deleted automatically by deleting the transaction.
// Load transactions via LoadTransactions()
manager.LoadTransactions();
for (int i = 0; i < manager.Transactions.Count; i++) {
ITransaction transaction = manager.Transactions[i];
int errorcode = manager.DeleteTransaction(transaction);
// Add error handling here
}
UNDER CONSTRUCTION