© 2018 Capita Business Services Ltd. All rights reserved.

Capita Education Software Solutions is a trading name of Capita Business Services Ltd. Our Registered office is 30 Berners Street, London, W1T 3LR and our registered number is 02299747. Further information about Capita plc can be found in our legal statement.

Local - Fees Import Transactions

This could be used either for importing payments from an online ePayment provider or possibly uploading charges from say squash court booking.

Code Sample can be obtained from Local - SIMS 7 Fees Example Code | ESS Portal (sims-partners.com)

Fees Batch EntryThe principle is that we are using the SIMS APIs to automate the screen.

Each connection from the external system will create a batch of transactions which may or may not be of the same type.  Each batch needs a description and it would be sensible for it to be unique e.g. Payment import 22 May 21 at 09:14:02.  

Additional DLLs referenced

  • Fees7Entities.Dll
  • Fees7Processes.Dll

A SIMS login is required before these calls can be made typically with a fees manager permission level.

Constructor

public TPAFessProcessTransactionDetails(string _BatchDescription, string _ImportFileName)
{
            ImportFileName = _ImportFileName;
            BatchDescription = _BatchDescription;
}

File example (TSV)

PupilReference PayerReference     Amount     AdmissionNumber
AARC0744     AARO4740     100 004740
AARL0745     AARO4740     50 004741   
AARS0746     AARO4740     25 004742

Please note that all amounts must be >0

Record format: <Payer><Tab><Pupil><Tab><Amount><CR><LF>

The simplest way to get the references and map these to other identifiers is via the automation of command reporter which is shown in other examples.

Set up a batch for import

Reference should really be related to the set of payments and be the basis of a conversation between the school and the payment provider in the case of any dispute. 

public void Go()
{ 
            this.hostedProcess = new FeesTransactionBatchDetail();
            this.hostedProcess.AddNew();
            this.hostedProcess.TransactionBatch.SetBatchLine(this.hostedProcess.GetNewBatchLine());
            this.hostedProcess.TransactionBatch.DescriptionAttribute.Value = BatchDescription;

Due date is likely to be the date of the import and we need to flag that this is a new batch.

this.hostedProcess.CurrentEnterBy = new SIMS.Entities.FeesBatchEnterBy { Code = "5", Description = "Import Transaction Batch", ID = 4 };
            this.hostedProcess.TransactionBatch.BatchLine.TransactionTypeAttribute.Value
                = SIMS.Entities.FeesCache.GetTransactionTypeSummarys().ItemByString("Online Payment");

            this.hostedProcess.TransactionBatch.BatchLine.TransactionReferenceAttribute.Value
                = SIMS.Entities.FeesCache.GetTransactionTypeSummarys().ItemByString("Online Payment").ToString();

            //For Transaction Type "Online Payment" Base Transaction Type is Credit (check tables sims.fees_transaction_type, sims.fees_transaction_base_type)
            this.hostedProcess.TransactionBatch.BatchLine.TransactionBaseTypeAttribute.Value = "CREDIT";

Transaction type is likely to be Online Payment for payment imports, other types will need a little research.

We use the file import method because it is much simpler.  This does however mean that we create a temporary file in order to achieve this.  There is no easy work around for this.

//Need to pass the GL code or look this up
            // alternatively a GL Description could be passed and use ItemByDescription
            this.hostedProcess.TransactionBatch.BatchLine.GLAccountAttribute.Value =
                SIMS.Entities.FeesCache.GetGeneralLedgers().ItemByCode("110-1202-01");

GL Account should default to an appropriate value when transaction type is set.  There is a link in the configuration for transaction types which can give a default but is not mandatory.  Training data does not have a default for online payments.  The 'GetGeneralLedgers()' call can also be used to match on a description rather than the ledger code and TIs are advised to consult their customers to agree how this might work best for them.

importTransactionsData();

The file can now be imported in to the batch

private void importTransactionsData()
{
            importData = new DataSet();
            //need to pass file name
            importProcess.ImportTextFileName = ImportFileName;
            if (importProcess.ImportTextFileName.Trim().Length > 0)
            {
                importProcess.ReadTextFile(true);
                importData = importProcess.GetValidTransactionData();
            }

            this.hostedProcess.GenerateBatchLinesforImportedData(this.importData);
            this.updateTransactionBatchDetails();
            this.addTransaction();
            this.saveDetails();
}
 private void updateTransactionBatchDetails()
        {
            this.hostedProcess.TransactionBatch.TotalAmount = 0;
            DoubleAttribute vatAmt = new DoubleAttribute(InformationDomainEnum.None);
            DoubleAttribute amt = new DoubleAttribute(InformationDomainEnum.None);

            foreach (FeesTransactionBatchLine line in this.hostedProcess.TransactionBatch.BatchLines.Value)
            {
                amt.Value += (line.TransactionBaseTypeAttribute.Value == "DEBIT" ? 1 : -1) * line.AmountAttribute.Value;
                vatAmt.Value += (line.TransactionBaseTypeAttribute.Value == "DEBIT" ? 1 : -1) * line.VatAmountAttribute.Value;
            }
            this.hostedProcess.TransactionBatch.TotalAmount = (amt.Value + vatAmt.Value);
            this.hostedProcess.TransactionBatch.TotalEntries = this.hostedProcess.TransactionBatch.BatchLines.Value.Count;
        }
private void addTransaction()
        {
            if (this.hostedProcess.TransactionBatch.BatchLine == null)
            {
                return;
            }
            // preserve old values to be set again for new batch line
            DateAttribute dt = new DateAttribute(InformationDomainEnum.None);
            dt = this.hostedProcess.TransactionBatch.BatchLine.TransactionDateAttribute;
            EntityAttribute transType = new EntityAttribute(InformationDomainEnum.None);
            transType = this.hostedProcess.TransactionBatch.BatchLine.TransactionTypeAttribute;
            StringAttribute oldTransactionReferenceAttribute = new StringAttribute(false, InformationDomainEnum.None);
            oldTransactionReferenceAttribute.Value = this.hostedProcess.TransactionBatch.BatchLine.TransactionReferenceAttribute.Value;
            FeesGeneralLedger glAccount = new FeesGeneralLedger();
            glAccount = this.hostedProcess.TransactionBatch.BatchLine.GLAccount;

            this.hostedProcess.TransactionBatch.SetBatchLine(this.hostedProcess.GetNewBatchLine());
            // assign old values back to controls
            this.hostedProcess.TransactionBatch.BatchLine.TransactionDateAttribute.Value = dt.Value;
            this.hostedProcess.TransactionBatch.BatchLine.TransactionTypeAttribute.Value = transType.Value;
            this.oldTransactionType.Value = transType.Value;
            if (this.hostedProcess.TransactionBatch.BatchLine.TransactionBaseTypeAttribute.IsNull
                && !this.hostedProcess.TransactionBatch.BatchLine.TransactionTypeAttribute.IsNull)
            {
                this.hostedProcess.TransactionBatch.BatchLine.TransactionBaseTypeAttribute.Value = ((FeesTransactionTypeSummary)this.hostedProcess.TransactionBatch.BatchLine.TransactionTypeAttribute.Value).CreditAttribute.Value.Code;
            }
            this.hostedProcess.TransactionBatch.BatchLine.TransactionReferenceAttribute.Value = oldTransactionReferenceAttribute.Value;
            this.hostedProcess.TransactionBatch.BatchLine.GLAccount = new FeesGeneralLedger();
            if (this.hostedProcess.TransactionBatch.BatchLine.GLAccount != null && glAccount != null)
            {
                this.hostedProcess.TransactionBatch.BatchLine.GLAccount.Assign(glAccount);
            }
            this.hostedProcess.TransactionBatch.CurrentAllocations = new SIMS.Entities.FeesTransactions(InformationDomainEnum.None);
        }
        private bool saveDetails()
        {
            bool saved = false;
            try
            {
                if (this.hostedProcess.Valid())
                {
                    saved = this.hostedProcess.Save();
                }
                else if (this.hostedProcess.validationErrors.Count > 0)
                {
                    SIMS.Entities.ValidationError thisError = this.hostedProcess.validationErrors.Item(0);
                    // TI needs to do something with the error
                    //SIMS.Processes.Cache.StatusMessage(thisError.Message, UserMessageEventEnum.Error);
                }

            }
            catch (Exception ex)
            {
                // TI needs to do something with the error
            }

            return saved;
        }

 

public class Program
    {
        private static string Server = ".";
        private static string Database = "Duchy2021";
        private static string User = "Fees";
        private static string Password = "Pa$$w0rd";

        static void Main(string[] args)
        {
            string file = Path.Combine(Environment.CurrentDirectory, "CMS - Fees Data Export v1.RptDef");
            SIMSInterface.SIMSDllResolution.AddSIMSDllResolution();
            DoTheRest();
         }
        static void DoTheRest()
        {
            // Login to SIMS
            if (SIMSInterface.LoginHelper.SIMSlogin(Server, Database, User, Password))
            {
                // Create a class to post a fees batch
                // takes a unique batch name and the file to import from
                // unfortunately a file in the format 
                // Payee Ref<tab>Bill Payer Ref<tab>Amount<tab>Admission Number
                // is required for the import.
                SIMSInterface.TPAFessProcessTransactionDetails feesPost =
                    new SIMSInterface.TPAFessProcessTransactionDetails("Unique Batch Name", @"c:\temp\FeesImport.txt");
                // Then invoke the import
                feesPost.Go();
            }
        }

 See getting started and sample code for guidance.