This example will show how to integrate Capitex Företagslån in a simple loan application process.

  • Fill in data from an application form into the case client side 

  • Do a pre calculation in the application form to show the user a loan indicator

  • Store the credit case in Capitex Företagslån and link the Case ID to the loan process system

  • Generate a first preliminar Credit PM and store it in the loan process system

  • The user of the loan process opens the credit case in Capitex Företagslån and change some data.

  • The user of the loan process updates the loan process system manually after the data has been changed in Capitex Företagslån

Use case not covered in this example:

  • A direct link from the loan process system to a specific credit case in Capitex Företagslån GUI

  • Automatic update of data in the loan process after a user change the case in Capitex Företagslån GUI

Techniques used in this example

  • Javascript client calls to perform calculations

  • Javascript JSON server calls to import data

  • JSON serverside calls to store a credit case

  • Java serverside webservice calls to perform calculations

  • Java serverside webservice calls to fetch a credit case

  • Java serverside webservice calls to generate PDF document

Sequence diagram

Loan application form

Fill in data from an application form into the case data model client side 

window.creditCase = {
  "datatype": "capitex.companycalc.dto.CompanyCalcInput",
  "Companies": [
    {
      "datatype": "capitex.companycalc.dto.Company",
      "AppliedLoans": [
        {
          "datatype": "capitex.companycalc.dto.InstallmentLoan",
          "Amortization": {
            "datatype": "capitex.companycalc.dto.amort.AmortizationStraight",
            "PaymentSchedule": "MONTHLY"
          },
          "LoanAmount": {
            "datatype": "capitex.companycalc.dto.CurrencyValuePair",
            "Currency": "SEK",
            "Amount": 200000
          },
          "InterestRate": {
            "datatype": "capitex.companycalc.dto.Rate",
            "RateProc": 3
          },
          "LoanCapitalDistribution": [
            {
              "datatype": "capitex.companycalc.dto.LoanPlaceAndAmount",
              "LoanPlace": "Cash",
              "AmountProc": 100
            }
          ],
          "Status": "New",
          "LoanID": "DDD5D4FE-8485-4E8B-AF82-2D755E0A2D19",
          "CreditAvailableFromDate": {
            "datatype": "capitex.companycalc.dto.Date",
            "Year": 2020,
            "Month": 11
          },
          "LoanTermMonths": 12
        }
      ],
      "Securities": {
        "datatype": "capitex.companycalc.dto.collaterals.Collateralrights",
        "Collateralrights": [
          {
            "datatype": "capitex.companycalc.dto.collaterals.CompanyMortgageSweden",
            "IdentificationNumber": "1234567890",
            "TransferFromActualCompany": true,
            "Mortgages": [
              {
                "datatype": "capitex.companycalc.dto.collaterals.CollateralValuePartWithPriority",
                "MortgageLienPriority": 200000,
                "IsSecondaryCollateral": true,
                "MortgageStatus": "Existing",
                "Value": 200000,
                "ID": "1D72DC37-D63B-4A5C-B2E0-8DC45DC4EAA1"
              }
            ],
            "CollateralCurrency": "SEK",
            "CollateralType": "General",
            "ID": "77667D9D-76ED-4E65-932E-E6F3A61DB8DE"
          }
        ]
      },
      "CompanyInformation": {
        "datatype": "capitex.companycalc.dto.CompanyInformation",
        "RegisteredCountry": "Sverige",
        "OrgNo": "1234567890"
      },
      "MainCurrency": "SEK",
      "FutureHints": {
        "datatype": "capitex.companycalc.dto.FutureHints",
        "FutureHintsForOneFiscalYear": [
          {
            "datatype": "capitex.companycalc.dto.FutureHintsForOneFiscalYear",
            "Revenue": 2000000,
            "IncomeAfterFinancialItems": 900000
          },{
            "datatype": "capitex.companycalc.dto.FutureHintsForOneFiscalYear"
          },{
            "datatype": "capitex.companycalc.dto.FutureHintsForOneFiscalYear"
          }
        ]
      },
      "ID": "911D1522-E78F-4CCF-9DAA-F503DD9AAD25"
    }
  ],
  "CalculationYear": 2020,
  "CalculationMonth": 10,
  "ActualDate": {
    "datatype": "capitex.companycalc.dto.DateWithDay",
    "Day": 14,
    "Year": 2020,
    "Month": 10
  },
  "CalcInformation": {
    "datatype": "capitex.companycalc.dto.CalcInformation",
    "CalcName": "Application form 123456-7890",
    "UserName": "public",
    "UserPhone": "072 987 6543",
    "CreatedDateTime": "2020-10-14",
    "Status": "InProgress"
  },
  "MainCurrency": "SEK"
};

Import data from UC, using JSON/REST call

This call can be done from javascript as below only if you host Capitex Företagslån on the same host as the application form. Otherwise you have to provide your own serverside logic at your own host that acts like a proxy for the call to the server where Capitex Företagslån is installed.

$.ajax(
  {url: 'https://host/context/services/companycalc/Applicationsservice?json=1&method=ImportCompany&data={"OrgNo":"1234567890","Sourcename":"capitex.companycalc.services.imp.uc.ImportCompany"}',
   success: function(importdata){
       updateCreditCaseAfterImportDone(importdata);
   }
  });

Handle the result from the import and merge the data into the credit case

function updateCreditCaseAfterImportDone(importdata) {
    var performImportInput = { 
       "datatype": "capitex.companycalc.dto.imp.PerformImportInput",
       "InputData": window.creditCase,
       "ImportData": JSON.parse(importdata),
       "ImportType": "AUTO";
    };
    var caseAfterImportAsJsonString = window.companycalc_engine_performImport(JSON.stringify(performImportInput));
    window.creditCase = JSON.parse(caseAfterImportAsJsonString);
    calculateAndUpdateLoanIndicator();
}

Calculate the credit case and update a loan indicator

function calculateAndUpdateLoanIndicator() {
    var calculatedResults = JSON.parse(window.companycalc_engine_doActiveCompanyCalculation(JSON.stringify(window.creditCase)));
    //The repayment capacity as a value between 0 - 100. 0 - 25 is red, 25 - 50 is yellow, 50 - 100 is green.
    updateLoanIndicatorGauge(calculatedResults.CalculatedScoring.RepaymentCapacityScore);
    //The maximum loan amount for new loans to stay in the green and yellow level in the RepaymentCapacityScore.
    updateInfoText("Ditt företag kan preliminärt låna upp till " + calculatedResults.CalculatedScoring.MaximumLoanamount + " kr.");  
}

Send in the credit case to the server when the user submit the form

You send the credit case JSON to your own server logic and after that your server logic will handle the rest of the initial process of the loan application.  The code below is example of server code using RES/JSON functions in Capitex Företagslån

public void initApplicationProcess(String caseInputJsonString) throws HttpException,IOException  {
    HttpClient httpClient = HttpClients.createDefault();
    PostMethod postMethod = new PostMethod("https://host/context/services/companycalc/Applicationsservice?json=1&method=SaveCalculation");
    postMethod.addParameter("data", caseInputJsonString);
    httpClient.executeMethod(postMethod);
    boolean statusOK = false;
    String caseID = null;
    if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
        JSONObject resp = JSONParser.parser(postMethod.getResponseBodyAsString());
        statusOK = resp.get("ok");
        caseID = resp.get("information");
    }
    if(statusOK) {
        //Store the ID of the credit case in the process system.
        storeCaseIDInProcessSystem(caseID);
        updateProcessSystemAfterCaseChange(caseID);
    } else {
        //Dump the credit case, log error and inform the customer of a problem.
        handleError(CASE_STORAGE_ERROR, caseInputJsonString);
    }   
}

Generate Credit PM and update the process system with calculated results

This should be done every time you store a credit case or when you use Capitex Företagslån GUI to update a credit case. The code below is example of server code using Java Webservice client.

public void updateProcessSystemAfterCaseChange(String caseID) {
    ApplicationserviceImplSEI app = new ApplicationserviceImpl().getApplicationserviceImplSEIPort();
    ((BindingProvider) app).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://host/context/services/companycalc/Applicationsservice");
    ((BindingProvider) app).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, USERNAME);
    ((BindingProvider) app).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, PASSWORD);
 
    //Now we can use strong typed java objects when we interact with Capitex Företagslån
    Id id = new Id();
    id.ID = caseID;
    CompanyCalcInput creditCase = app.FetchCalculation(id);
    CompanyCalcOutput calculatedResults = app.doActiveCompanyCalculation(creditCase);
 
    //Here you can extract all important input or calculated data that you want to be accesable directly in the loan process system.
 
    //The repayment capacity as a value between 0 - 100. 0 - 25 is red, 25 - 50 is yellow, 50 - 100 is green.
    updateLoanIndicatorGaugeInProcessSystem(caseID, calculatedResults.CalculatedScoring.RepaymentCapacityScore);
 
    //The maximum loan amount for new loans to stay in the green and yellow level in the RepaymentCapacityScore.
    updateMaxLoanInfoInProcessSystem(caseID, calculatedResults.CalculatedScoring.MaximumLoanamount);
 
    //Recreate the Credit PM
    CreateDocument createDocumentInput = new CreateDocument();
    createDocumentInput.InputData = creditCase;   
    createDocumentInput.Printouts = new Printout[] {new CreditPMPrintout()};
    createDocumentInput.DocumentFormat = "PDF";
    CreateDocumentResult documentResults = app.CreateDocument(createDocumentInput); 
 
    //Store the PDF byte-array in the loan process system so you can view the Credit PM directly in the loan process system.
    updateCreditPMPDFInProcessSystem(caseID, documentResults.Document);
}

The user of the loan process opens the credit case in Capitex Företagslån and change some data.

Just start Capitex Företagslån GUI standalone and use the fetch dialog to open the credit case just as you open any case you create directly in Capitex Företagslån. Enter the "username" that is used for the public application form and click "Sök".

The user of the loan process updates the loan process system manually after the data has been changed in Capitex Företagslån

Just start Capitex Företagslån GUI standalone and use the fetch dialog to open the credit case just as you open any case you create directly in Capitex Företagslån. Enter the "username" that is used for the public application form and click "Sök".

In this example there is no signal sent from Capitex Företagslån to the loan process system when a calculation is sent so the user have to manually trigger the update in the loan process system by pressing a button:

public void onUpdateClick(Event e) {
    updateProcessSystemAfterCaseChange(this.loanProcessCase.idOfConnectedCalculation);
}