メインコンテンツへスキップ
この例のスクリプトは、Document Set Definitionで定義されたdocument setsにdocumentsをアセンブルするために使用します。Document Set Definitionには、借り手のフォームという名前のセクションと、以下のDocument Definitionsへの参照が含まれています。
  • パスポート
  • 保証人の書類
  • 共同借入人の書類
  • 雇用主の参照情報
借り手のフォームセクションには、以下のfieldsが含まれます:
  • 共同借入人の氏名
  • 借入額
document setに含めるドキュメントは、Loan sum fieldの値によって決まります。scriptには、setに含めるドキュメントを決定する2つの閾値があります。
  1. 融資額が最初のしきい値を下回る場合、ドキュメントセットに必要なのはパスポートだけです。
  2. ローン金額が1つ目のしきい値より大きく、2つ目のしきい値より小さい場合、ドキュメントセットにはパスポートと雇用主の在職証明書を含める必要があります。
  3. 融資額が2番目のしきい値を超える場合、ドキュメントセットにはパスポート、在職証明書、保証人の書類を含める必要があります。
また、Co-borrower’s name fieldに値が含まれている場合、document setには共同借り手のdocumentsが含まれている必要があります。以下のスクリプトは、このロジックを使用してドキュメントセットを組み立てます。
using System.Collections.Generic;
int creditSum = 0;
bool creditSumFound = false;
string cocreditor = "";
int formCount = 0;
string formName = "Borrower's form";
// document set で使用される Document Definitions
int referenceFromWorkCount = 0;
string referenceFromWorkName = "Employer reference";
int guaranteeDocsCount = 0;
string guaranteeDocsName = "Guarantor's documents";
int cocreditorDocsCount = 0;
string cocreditorDocsName = "Co-borrower's documents";
int passportCount = 0;
string passportName = "Passport";
foreach( IBatchItem item in BatchItems ) {
// フォームを検索してローンの合計を算出する
    if (item.Type == TBatchItemType.BIT_Page)
    {
if (item.AsPage.SectionName != formName)
            AssemblingErrors.AddCustomError("次のセクションを含めることはできません: " + item.AsPage.SectionName, 1);
else
        {
cocreditor = item.AsPage.Document.IndexedItemValue("Borrower's name").ToString();
            string creditSumText = item.AsPage.Document.IndexedItemValue("Loan sum").ToString();
if (!int.TryParse(creditSumText, out creditSum))
                AssemblingErrors.AddCustomError("ローン金額が認識されませんでした: " + creditSumText, 1);
else 
                creditSumFound = true;
            formCount++;
        }
    }
// セット内のドキュメント数をカウントする
    else if (item.Type == TBatchItemType.BIT_Document) {
if (item.AsDocument.TemplateName == referenceFromWorkName)
            referenceFromWorkCount++;
else if (item.AsDocument.TemplateName == guaranteeDocsName)
            guaranteeDocsCount++;
else if (item.AsDocument.TemplateName == passportName)
            passportCount++;
else if (item.AsDocument.TemplateName == cocreditorDocsName)
            cocreditorDocsCount++;
else
            AssemblingErrors.AddCustomError("ドキュメントセットにはドキュメントを含めることができません " + item.AsDocument.TemplateName, 1);
    }
}
// セット内のセクション数とドキュメント数を確認する
if (formCount > 1)
    AssemblingErrors.AddCustomError("There are too many documents of the type: " + formName, formCount);
else if (formCount < 1)
    AssemblingErrors.AddCustomError("次のドキュメントが不足しています: " + formName, 1);
if (passportCount > 1)
    AssemblingErrors.AddCustomError("このタイプのドキュメントが多すぎます: " + passportName, passportCount);
else if (passportCount < 1)
    AssemblingErrors.AddCustomError("次の書類が不足しています: " + passportName, 1);
// フォームに共同借入人名が存在する場合、ドキュメントセットに共同借入人が含まれているかを確認する
if (cocreditor != "" && cocreditorDocsCount < 1)
    AssemblingErrors.AddCustomError("Missing the following documents: " + cocreditorDocsName, 1);
else if (cocreditor != "" && cocreditorDocsCount > 1)
    AssemblingErrors.AddCustomError("このタイプのドキュメントが多すぎます: " + cocreditorDocsName, cocreditorDocsCount);
else if (cocreditor == "" && cocreditorDocsCount > 0)
    AssemblingErrors.AddCustomError("このタイプのドキュメントが多すぎます: " + cocreditorDocsName, cocreditorDocsCount);
// ローン金額がいずれかの閾値を超えたため、document setに必要なすべてのDocumentが含まれているかどうかを確認する
if (creditSumFound)
{
if (creditSum > 50000) // 雇用主の照会が必要
    {
if (referenceFromWorkCount > 1)
            AssemblingErrors.AddCustomError("次のタイプのドキュメントが多すぎます: " + referenceFromWorkName, referenceFromWorkCount);
else if (referenceFromWorkCount < 1)
            AssemblingErrors.AddCustomError("次のドキュメントが見つかりません: " + referenceFromWorkName, 1);
    }
if (creditSum > 500000) // 保証人の書類が必要
    {
if (guaranteeDocsCount > 1)
            AssemblingErrors.AddCustomError("次のタイプのドキュメントが多すぎます: " + guaranteeDocsName, guaranteeDocsCount);
else if (guaranteeDocsCount < 1)
AssemblingErrors.AddCustomError("次のドキュメントが不足しています: " + guaranteeDocsName, 1);
    }
}
この例のスクリプトは、Identification Documents の Document Set Definition を使用します。この Document Set Definition には、次の Document Definitions への参照が含まれています。
  • Passport
  • Driver’s license
このスクリプトで生成される document set には、これらの種類のドキュメントをそれぞれ1つまで含めることができ、かつ少なくとも1つは含まれている必要があります。以下のスクリプトは、このロジックを使用して document set をアセンブリします。
using System.Collections.Generic;
using System;
string docSetName = "Identification Documents";
int pagesCnt = 0;
// set に含めることができるドキュメントの種類のリスト
List<string> allowed = new List<string> {"Passport", "Driver's license"};
// set 内の各種類のドキュメント数の上限
List<int> allowedCount = new List<int>{1,1};
// set 内で検出されたドキュメント数
List<int> foundCount = new List<int>{0,0};
// set 内のドキュメント数とページ数をカウントする
foreach (IBatchItem item in BatchItems) {
if (item.Type == TBatchItemType.BIT_Document) {
if (item.AsDocument.TemplateName == docSetName)
AssemblingErrors.AddCustomError("Cannot contain a nested set", 1);
else if (allowed.Contains(item.AsDocument.TemplateName)) {
int i = allowed.IndexOf(item.AsDocument.TemplateName);
foundCount[i]++;
}
}
else if (item.Type == TBatchItemType.BIT_Page) pagesCnt++;
}
// ドキュメント数とページ数をチェックする
if (foundCount[0] + foundCount[1] == 0)
AssemblingErrors.AddCustomError("At least one identification document is required", 1);
for (int i = 0; i < allowed.Count; i++) {
if (foundCount[i] > allowedCount[i])
AssemblingErrors.AddCustomError("Maximum number of documents: " + allowed[i] + ": " + allowedCount[i]);
}
if (pagesCnt > 0) AssemblingErrors.AddCustomError("The document set cannot contain pages that do not belong to a document", pagesCnt);