© 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.

SIMS 7 - Dinner Money Coding

Background

Dinner Money (DM) has been designed to allow a Bursar to make errors without significant consequences rather than to enforce rigorous financial disciplines; the outcome is no less rigorous within DM but a more traditional finance package design would be far easier to interface with from the perspective of an external system. 

DM was not written with external payment systems in mind.  As such interfacing with an e-payment system will require careful thought and the reasons are discussed below.  

The document intends to be open and straightforward about the current DM interfaces as to how they work and some of the thinking behind them.  The research for the training session and associated sample code was a voyage of discovery about what we couldn’t do and the understanding of why this was the case. 

Why is it awkward to integrate with Dinner Money?

Historical Editing

Scenario 1:         “Dinner money charges were increased on 1/9, all the parents were informed and pupils are bringing in the right money; however the new charges were not updated in dinner money until 2 weeks in to term.”

Scenario 2:         “Fred’s free school meal eligibility changed, notification arrived 2 weeks after the effective date of the change.” 

It is possible to change data historically.  In which case information previously exported to external systems may be wrong.  DM does not currently have row versioning; as such at best an external system would need to export all of the meals taken, costs and payments.  The nearest API is the report described below but this comes with a health warning about the volumes of data that it may generate.

Traditional finance systems would not have allowed retrospective change and forced the use of journals and other devices to correct errors made.

Balances are recalculated when needed

 If you run DM reports or other processes in SIMS .Net, DM will kick off a recalculation of balances. This needs to be done by a user who has access to modify data because there may be invalid entries within the database where say free school meal entitlement has been modified.  In these cases DM pops up a list of issues for the DM user to address. In some cases, the update may fail because of error conditions and the DM user interface will in some circumstances allow the user to correct the fault.  One example of this might be a student is marked as having taken a Christmas meal in June; typically, this would be corrected to a standard meal before the use can proceed to the requested task.  During the preparation of this document, the training data has a student that had had a meal taken at a time where they were not in a year group, the error was shown on entry to DM interfaces and it did not allow the user past this error until it was resolved.  Whilst an unusual error, it would have prevented the recalculation of balances.

Unless the error list is ‘terminal’ such as the missing year group, the list is a use once and the errors are not available after the call.  It is therefore not viewed as desirable that an external system should force a balance recalculation before say importing payments because the import process would likely be an unattended process and hence offer no opportunity to interact with the user.  Even if the process was interactive, it would potentially require the partner to implement a significant chunk of DM logic to replicate what DM does when problems occur.  This logic is part of the UI layer which is not available to partners.

The consequence of this is that balances are correct as of the last recalculation, unfortunately there are no interfaces that tell when this was or allow a test update to occur.  Whilst it is unusual within SIMS, in effect parts of DM are indirectly tied to the UI.

When a payment is made, the payments totals for a student are updated.  This at least means that when an external system pays in £10, the ‘current balance’ is in effect also adjusted (via the payment total).

Conclusion

Dinner money isn't the easiest system to integrate with because of the features above but there are examples of Technical Integrators who have achieved this successfully. 

Payments

Split Payments

There is no such thing in DM as payments for an individual.  A payment includes a set of splits and a special case is a single split for one person.

The code below shows how a payment is processed:

private static void processDemoPayment3(DMp.EditStudentPayments editProcess)
{
    string reff = Guid.NewGuid().ToString().Substring(0, 8);
    // paul Andrews is 1884
    int Paul = 1884;
    int Jordan = 2087;
    double total = 17.99;
    double jordans = 8.33;
    // Jordan Acton is 2087
    
    int financialTransactionID = -1;
    DMe.PersonPayment personPayment = new DMe.PersonPayment();
    personPayment.Person.Surname = "Transaction: " + financialTransactionID;  // Used for identification on excEPTion below, if needed
    personPayment.FinancialTransactionIDAttribute.Value = financialTransactionID--;
    personPayment.TransactionDate = DateTime.Now.AddDays(-1);
    personPayment.TransactionAmount = Convert.ToDouble(total);
    personPayment.ExternalRef = "B"+reff;
    personPayment.ExternalID = Guid.NewGuid().ToString();
    personPayment.PaymentType = DMe.Cache.PaymentTypeExternal;
    personPayment.Reference = reff;
    personPayment.PayerName = "joint Dad";
    personPayment.Notes = "Test";
    personPayment.Status = DMe.StatusEnum.New;

    int displayOrder = 1;
    DMe.TransactionLine transactionLine = new DMe.TransactionLine(DMe.DiscriminatorEnum.Student, InformationDomainEnum.DinnerMoneyBasicFinancial);
    transactionLine.FinancialTransactionIDAttribute.Value = personPayment.FinancialTransactionID;
    transactionLine.PersonIDAttribute.Value = Paul;
    transactionLine.Surname = ".";  // Field must contain anything/something as it has a min length of 1, but is not used for our purpose!
    transactionLine.LineAmount = total-jordans;
    transactionLine.DisplayOrder = displayOrder++;
    transactionLine.Status = DMe.StatusEnum.New;

    personPayment.TransactionLines.Add(transactionLine);

    DMe.TransactionLine transactionLine2 = new DMe.TransactionLine(DMe.DiscriminatorEnum.Student, InformationDomainEnum.DinnerMoneyBasicFinancial);
    transactionLine2.FinancialTransactionIDAttribute.Value = personPayment.FinancialTransactionID;
    transactionLine2.PersonIDAttribute.Value = Jordan;
    transactionLine2.Surname = ".";  // Field must contain anything/something as it has a min length of 1, but is not used for our purpose!
    transactionLine2.LineAmount = jordans;
    transactionLine2.DisplayOrder = displayOrder++;
    transactionLine2.Status = DMe.StatusEnum.New;

    personPayment.TransactionLines.Add(transactionLine2);

    if (!personPayment.Valid())
    {
        ValidationErrors.Record(string.Format("PersonPayment not Valid {0}", personPayment.ValidationErrors.Item(0)));
        return;
    }

    editProcess.Payments.Add(personPayment);
}

 

Potential issues

The sample code preparation failed on a number of occasions the line highlighted above is the key one to aid debugging.  Look at the validation error in the debugger. (Or improve the details captured by the line).  The errors seen included:

  1. The transaction value does not match the sum of the splits.
  2. Cannot enter future transactions – Note this failed for Datetime.Now!
  3. External references may be at most 10 characters.

A stranger error also occurred.  The original sample code set the external and internal references to hard coded values.  Whilst it was happy to add the values on the first run, trying to add them again failed hence the code gets the references as bits of Guids; Clearly partner systems would need to ensure that their references were unique and compatible.

Saving the payments

public static bool MakeStudentPayments()
{
    // Populate the DM cache
    DMp.Cache.Populate();
    // We need a status for a pseudo call to the browse...
    DMe.StudentStatus statusNone;
    statusNone = new DMe.StudentStatus();
    statusNone.StudentStatusIDAttribute.Value = -1;
    statusNone.Code = Cache.WildcardNone;
    statusNone.Description = DMe.Cache.NoneText;

    bool paymentsMade = false;
    // Set up an edit payment for students - MUST be of type external.  Supported from Spring 2012 onwards.
    DMp.EditStudentPayments editProcess = new DMp.EditStudentPayments(DateTime.Today, DMe.Cache.PaymentTypeExternal);
    // Load required DM data
    editProcess.LoadArgsOnly(new DMe.SelectStudentsEventArgs(Cache.WildcardAny, Cache.WildcardAny, false, statusNone,
        editProcess.TierNone, editProcess.YearGroupNone, editProcess.RegistrationGroupNone, editProcess.HouseNone, DateTime.Today));
    // Process the payment
    processDemoPayment1(editProcess);
    paymentsMade = editProcess.Save(DMe.SaveModeEnum.SaveAndConfirm);
    processDemoPayment3(editProcess);
    paymentsMade = editProcess.Save(DMe.SaveModeEnum.SaveAndConfirm);
    processDemoPayment2(editProcess);
    // Save the payments - force the payments
    paymentsMade = editProcess.Save(DMe.SaveModeEnum.SaveAndConfirm);
    if (!paymentsMade)
    {
        // get the ValidationErrors from (personPayment.ValidationErrors);
    }

    return paymentsMade;
}

 

Please note that the example shows one save per transaction.    When the code is amended to try to save multiple transactions it refused to save.

Outcome

In effect we create a new payment with a set of splits.  If I pass in the transaction date as 10/07/2012 and an amount of £10 then the payment history it will show the following.

These payments must be of type ‘External’ or they should be rejected (No guarantees of that).  If they are not rejected, it will potentially break the banking returns.

Getting the Current Balance

This uses a report, the detailed information is shown below.  Typically when the report is shown in SIMS, it will re-calculate the balances as was stated above.  It is plausible that the balances may be ‘aged’ if the DM manager (Bursar) does not run the financial reports on a regular basis.

The report has its limitations and we would recommend that it is executed on a per student basis as is the default within DM.  Executing the report for a say ‘All pupils’ in a large school for a large time period may take a significant time or possibly fail.

The key XML in the report is:
 

<Students>  
  <Student externalID="3E3DC1AF-CAB6-4A16-9931-86756BF1C901" sourceOnly="false" baseGroupCode="" name="Paul Andrews" yearGroup=" 4" regGroup="4SL" openingBalance="33.60" mealsTotal="1.60" transactionsTotal="107.39" />
</Students>

 

Where the ‘current balance’ is the sum of the opening balance + transaction total less meals taken.

 

private decimal dmBalance(StringBuilder sb)
{        
    // add some wrapper xml elements
    sb.Insert(0, "<Root>");
    sb.AppendLine("</Root>");
            
    XDocument repDoc = XDocument.Parse(sb.ToString());

    // get the 3 amount values to do the math 
    var Student = repDoc.Descendants("Students")
                        .Select(x => x.Element("Student"))
                        .ToList();

    decimal openBalance = Convert.ToDecimal(Student[0].Attribute("openingBalance").Value);
    decimal mealsTotal = Convert.ToDecimal(Student[0].Attribute("mealsTotal").Value);
    decimal transactionsTotal = Convert.ToDecimal(Student[0].Attribute("transactionsTotal").Value);

    decimal currentBalance = openBalance - mealsTotal + transactionsTotal;            

    return currentBalance;        
} 

 

Running the report in code

Take care when deciding how much data to request. Getting data for all pupils in a single call on my test system timed out on a 16GB i7 Microsoft Surface but did complete on a more powerful i7 with 32GB RAM.  School servers vary in performance and as such it is critical that the report below is suitably constrained to work for all customers.

public decimal GetStudentStatement(int personID, DateTime start_Date, DateTime end_Date, string outputPath)
{
    decimal currentBalance = 0;
            
    List<DMe.StudentEmployeeSummary> selectedPersons = new List<DMe.StudentEmployeeSummary>();
    DMe.StudentEmployeeSummary personDMe = new DMe.StudentEmployeeSummary(DMe.DiscriminatorEnum.Student);
    personDMe.PersonIDAttribute.Value = personID;
    selectedPersons.Add(personDMe);

    //params for Load are DateTime startDate, DateTime endDate, SIMS.Entities.DinnerMoney.BaseGroupType baseGrouptype, <AbstractGroupLookup>basegroups, <StudentEmployeeSummary>persons  
    DMp.ViewStudentDetailedStatementOfAccountReport viewStudSOA 
= new DMp.ViewStudentDetailedStatementOfAccountReport();
    viewStudSOA.Load(start_Date, 
end_Date.AddHours(23).AddMinutes(59),
DMe.Cache.BaseGroupTypeIndividuals, 
new List<DMe.AbstractGroupLookup>().AsReadOnly(), selectedPersons.AsReadOnly());

    SIMS.XMLServices.IXmlReport xmlrep = viewStudSOA as SIMS.XMLServices.IXmlReport;

    if (xmlrep == null)
    {  return 0;  // Error – do some feedback!  Probably a programming one…
    }
            
    StringBuilder sb = new StringBuilder();
    try
    {
        xmlrep.GenerateXml(new XmlTextWriter(new StringWriter(sb)));

        StreamWriter output = new StreamWriter(outputPath);
        output.WriteLine(sb.ToString());
        output.Close();

        // derive balance
        currentBalance = dmBalance(sb);
    }
    catch (System.Exception e)
    {   // Do something with the error
    }
    return currentBalance;
}

 

 

 

 

 

The report also includes activities for the specified period.  A sample of a full report is included below.

 

<Root>
  <Configuration>
    <School leaNumber="823" schoolNumber="2999" schoolName="WATERS EDGE PRIMARY SCHOOL" />
    <Report printDateTime="2022-03-22T16:48:08.397" loginName="GROSG" fullName="Mrs Gillian Grosvenor" applicationVersion="1.0" />
    <DateRange startDate="2021-09-01" endDate="2021-10-01" />
    <BaseGroupType code="" description="Individuals" />
    <BaseGroups />
    <MealTypes>
      <MealType code="SM" description="School Meal" />
    </MealTypes>
    <Weeks>
      <Week weekNumber="1" startDate="2021-09-01" endDate="2021-09-05" />
      <Week weekNumber="2" startDate="2021-09-06" endDate="2021-09-12" />
      <Week weekNumber="3" startDate="2021-09-13" endDate="2021-09-19" />
      <Week weekNumber="4" startDate="2021-09-20" endDate="2021-09-26" />
      <Week weekNumber="5" startDate="2021-09-27" endDate="2021-10-01" />
    </Weeks>
    <DaysOfWeek>
      <DayOfWeek dow="2" code="Mon" description="Monday" />
      <DayOfWeek dow="3" code="Tue" description="Tuesday" />
      <DayOfWeek dow="4" code="Wed" description="Wednesday" />
      <DayOfWeek dow="5" code="Thu" description="Thursday" />
      <DayOfWeek dow="6" code="Fri" description="Friday" />
    </DaysOfWeek>
    <Texts students="Pupils" yearGroup="Year Group" regGroup="Class" />
  </Configuration>
  <Students>
    <Student externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" sourceOnly="false" baseGroupCode="" name="Shaquib Abhra" yearGroup="3" regGroup="3TO" openingBalance="0.00" mealsTotal="42.00" transactionsTotal="42.00" />
  </Students>
  <StudentMeals>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-06" dayNum="2" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="2" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-07" dayNum="3" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="2" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-08" dayNum="4" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="2" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-09" dayNum="5" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="2" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-10" dayNum="6" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="2" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-13" dayNum="2" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="3" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-14" dayNum="3" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="3" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-15" dayNum="4" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="3" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-16" dayNum="5" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="3" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-17" dayNum="6" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="3" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-20" dayNum="2" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="4" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-21" dayNum="3" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="4" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-22" dayNum="4" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="4" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-23" dayNum="5" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="4" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-24" dayNum="6" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="4" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-27" dayNum="2" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="5" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-28" dayNum="3" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="5" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-29" dayNum="4" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="5" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-09-30" dayNum="5" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="5" />
    </StudentMeal>
    <StudentMeal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" date="2021-10-01" dayNum="6" cost="2.10" fsm="false" universal="false" actualCost="2.10">
      <MealType code="SM" description="School Meal" />
      <Week number="5" />
    </StudentMeal>
  </StudentMeals>
  <StudentMealTotals>
    <StudentMealTotal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" total="10.50">
      <Week number="2" />
    </StudentMealTotal>
    <StudentMealTotal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" total="10.50">
      <Week number="3" />
    </StudentMealTotal>
    <StudentMealTotal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" total="10.50">
      <Week number="4" />
    </StudentMealTotal>
    <StudentMealTotal externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" total="10.50">
      <Week number="5" />
    </StudentMealTotal>
  </StudentMealTotals>
  <StudentTransactions>
    <StudentTransaction externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" sourceExternalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" transactionNumber="53122" transactionAmount="10.50" transactionDate="2021-09-27" transactionExternalID="E44F2062-EEAE-493F-A330-B1694BB01803" bankingNumber="440" bankingDate="2021-09-27T00:00:00" lineAmount="10.50">
      <TransactionType code="P" description="Payment" />
      <ExtendedTransactionType code="C" description="Cash" />
    </StudentTransaction>
    <StudentTransaction externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" sourceExternalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" transactionNumber="52996" transactionAmount="10.50" transactionDate="2021-09-21" transactionExternalID="76B9050F-CA64-4C7E-9ECB-5B8825F8AD23" bankingNumber="439" bankingDate="2021-09-21T00:00:00" lineAmount="10.50">
      <TransactionType code="P" description="Payment" />
      <ExtendedTransactionType code="C" description="Cash" />
    </StudentTransaction>
    <StudentTransaction externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" sourceExternalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" transactionNumber="52871" transactionAmount="10.50" transactionDate="2021-09-14" transactionExternalID="AB81B713-8ADC-41E6-8D6F-61D0398580C3" bankingNumber="438" bankingDate="2021-09-14T00:00:00" lineAmount="10.50">
      <TransactionType code="P" description="Payment" />
      <ExtendedTransactionType code="C" description="Cash" />
    </StudentTransaction>
    <StudentTransaction externalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" sourceExternalID="E2FCD6CC-3C3A-4BC6-A791-9FA1DD137DF1" transactionNumber="52738" transactionAmount="10.50" transactionDate="2021-09-07" transactionExternalID="2839BF77-9519-4A26-BE85-6FC3B606B6A8" bankingNumber="437" bankingDate="2021-09-07T00:00:00" lineAmount="10.50">
      <TransactionType code="P" description="Payment" />
      <ExtendedTransactionType code="C" description="Cash" />
    </StudentTransaction>
  </StudentTransactions>
</Root>

 

Permissions

The Bursar has full access to DM.  The APIs are likely to need most if not all of the permissions below.

Dinner Money 7 Permissions