:green_heart: Fix model structure.

:green_heart: Fix model structure.

[ {
      "Archive" : "S1002Q54",
      "Section" : "四半期連結貸借対照表",
      "Hypercube" : "Balance sheet",
      "SectionURI" : "http://disclosure.edinet-fsa.go.jp/role/jppfs/rol_QuarterlyConsolidatedBalanceSheet",
      "HypercubeName" : "jppfs-cor:BalanceSheetTable",
      "ModelStructure" : [ {
        "Name" : "jppfs-cor:QuarterlyConsolidatedBalanceSheetHeading",
        "Label" : "四半期連結貸借対照表",
        "Kind" : "Abstract",
        "Depth" : 1,
        "Children" : [ {
          "Name" : "jppfs-cor:BalanceSheetTable",
          "Label" : "連結貸借対照表",
          "Order" : 1,
          "Kind" : "Hypercube",
          "Depth" : 2,
          "Children" : [ {
            "Name" : "jppfs-cor:ConsolidatedOrNonConsolidatedAxis",
            "Label" : "連結個別",
            "Order" : 1,
            "Kind" : "Dimension",
            "Depth" : 3,
            "Children" : [ {
              "Name" : "jppfs-cor:ConsolidatedMember",
              "Label" : "連結",
              "Order" : 1,
              "Kind" : "Member",
              "Depth" : 4
            } ]
          } ]
        }, {
          "Name" : "jppfs-cor:BalanceSheetLineItems",
          "Label" : "連結貸借対照表",
          "Order" : 2,
          "Kind" : "LineItems",
          "Depth" : 2,
          "Children" : [ {
            "Name" : "jppfs-cor:AssetsAbstract",
            "Label" : "資産の部",
            "Order" : 1,
            "Kind" : "Abstract",
            "Depth" : 3,
            "Children" : [ {
              "Name" : "jppfs-cor:CurrentAssetsAbstract",
              "Label" : "流動資産",
              "Order" : 1,
              "Kind" : "Abstract",
              "Depth" : 4,
              "Children" : [ {
                "Name" : "jppfs-cor:CashAndDeposits",
                "Label" : "現金及び預金",
                "Order" : 1,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "debit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:NotesAndAccountsReceivableTrade",
                "Label" : "受取手形及び売掛金",
                "Order" : 2,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "debit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:Inventories",
                "Label" : "たな卸資産",
                "Order" : 3,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "debit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:OtherCA",
                "Label" : "その他",
                "Order" : 4,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "debit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:AllowanceForDoubtfulAccountsCA",
                "Label" : "貸倒引当金",
                "Order" : 5,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "debit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:CurrentAssets",
                "Label" : "流動資産合計",
                "Order" : 6,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "debit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              } ]
            }, {
              "Name" : "jppfs-cor:NoncurrentAssetsAbstract",
              "Label" : "固定資産",
              "Order" : 2,
              "Kind" : "Abstract",
              "Depth" : 4,
              "Children" : [ {
                "Name" : "jppfs-cor:PropertyPlantAndEquipmentAbstract",
                "Label" : "有形固定資産",
                "Order" : 1,
                "Kind" : "Abstract",
                "Depth" : 5,
                "Children" : [ {
                  "Name" : "jppfs-cor:BuildingsAndStructuresNet",
                  "Label" : "建物及び構築物（純額）",
                  "Order" : 1,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:MachineryEquipmentAndVehiclesNet",
                  "Label" : "機械装置及び運搬具（純額）",
                  "Order" : 2,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:OtherNetPPE",
                  "Label" : "その他（純額）",
                  "Order" : 3,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:PropertyPlantAndEquipment",
                  "Label" : "有形固定資産合計",
                  "Order" : 4,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                } ]
              }, {
                "Name" : "jppfs-cor:IntangibleAssets",
                "Label" : "無形固定資産",
                "Order" : 2,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "debit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:InvestmentsAndOtherAssetsAbstract",
                "Label" : "投資その他の資産",
                "Order" : 3,
                "Kind" : "Abstract",
                "Depth" : 5,
                "Children" : [ {
                  "Name" : "jppfs-cor:InvestmentSecurities",
                  "Label" : "投資有価証券",
                  "Order" : 1,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:NetDefinedBenefitAsset",
                  "Label" : "退職給付に係る資産",
                  "Order" : 2,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:OtherIOA",
                  "Label" : "その他",
                  "Order" : 3,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:AllowanceForDoubtfulAccountsIOAByGroup",
                  "Label" : "貸倒引当金",
                  "Order" : 4,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:InvestmentsAndOtherAssets",
                  "Label" : "投資その他の資産合計",
                  "Order" : 5,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                } ]
              }, {
                "Name" : "jppfs-cor:NoncurrentAssets",
                "Label" : "固定資産合計",
                "Order" : 4,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "debit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              } ]
            }, {
              "Name" : "jppfs-cor:Assets",
              "Label" : "資産合計",
              "Order" : 3,
              "Kind" : "Concept",
              "Depth" : 4,
              "IsNillable" : true,
              "IsAbstract" : false,
              "PeriodType" : "instant",
              "Balance" : "debit",
              "SubstitutionGroup" : "xbrli:item",
              "DataType" : "xbrli:monetaryItemType",
              "BaseType" : "xbrli:monetary",
              "ClosestSchemaBuiltinType" : "xs:decimal",
              "IsTextBlock" : false
            } ]
          }, {
            "Name" : "jppfs-cor:LiabilitiesAbstract",
            "Label" : "負債の部",
            "Order" : 2,
            "Kind" : "Abstract",
            "Depth" : 3,
            "Children" : [ {
              "Name" : "jppfs-cor:CurrentLiabilitiesAbstract",
              "Label" : "流動負債",
              "Order" : 1,
              "Kind" : "Abstract",
              "Depth" : 4,
              "Children" : [ {
                "Name" : "jppfs-cor:NotesAndAccountsPayableTrade",
                "Label" : "支払手形及び買掛金",
                "Order" : 1,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:ShortTermLoansPayable",
                "Label" : "短期借入金",
                "Order" : 2,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:CommercialPapersLiabilities",
                "Label" : "コマーシャル・ペーパー",
                "Order" : 3,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:CurrentPortionOfBonds",
                "Label" : "1年内償還予定の社債",
                "Order" : 4,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:IncomeTaxesPayable",
                "Label" : "未払法人税等",
                "Order" : 5,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:ProvisionCL",
                "Label" : "引当金",
                "Order" : 6,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:OtherCL",
                "Label" : "その他",
                "Order" : 7,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:CurrentLiabilities",
                "Label" : "流動負債合計",
                "Order" : 8,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              } ]
            }, {
              "Name" : "jppfs-cor:NoncurrentLiabilitiesAbstract",
              "Label" : "固定負債",
              "Order" : 2,
              "Kind" : "Abstract",
              "Depth" : 4,
              "Children" : [ {
                "Name" : "jppfs-cor:BondsPayable",
                "Label" : "社債",
                "Order" : 1,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:LongTermLoansPayable",
                "Label" : "長期借入金",
                "Order" : 2,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:ProvisionNCL",
                "Label" : "引当金",
                "Order" : 3,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:NetDefinedBenefitLiability",
                "Label" : "退職給付に係る負債",
                "Order" : 4,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:OtherNCL",
                "Label" : "その他",
                "Order" : 5,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:NoncurrentLiabilities",
                "Label" : "固定負債合計",
                "Order" : 6,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              } ]
            }, {
              "Name" : "jppfs-cor:Liabilities",
              "Label" : "負債合計",
              "Order" : 3,
              "Kind" : "Concept",
              "Depth" : 4,
              "IsNillable" : true,
              "IsAbstract" : false,
              "PeriodType" : "instant",
              "Balance" : "credit",
              "SubstitutionGroup" : "xbrli:item",
              "DataType" : "xbrli:monetaryItemType",
              "BaseType" : "xbrli:monetary",
              "ClosestSchemaBuiltinType" : "xs:decimal",
              "IsTextBlock" : false
            } ]
          }, {
            "Name" : "jppfs-cor:NetAssetsAbstract",
            "Label" : "純資産の部",
            "Order" : 3,
            "Kind" : "Abstract",
            "Depth" : 3,
            "Children" : [ {
              "Name" : "jppfs-cor:ShareholdersEquityAbstract",
              "Label" : "株主資本",
              "Order" : 1,
              "Kind" : "Abstract",
              "Depth" : 4,
              "Children" : [ {
                "Name" : "jppfs-cor:CapitalStock",
                "Label" : "資本金",
                "Order" : 1,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:CapitalSurplus",
                "Label" : "資本剰余金",
                "Order" : 2,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:RetainedEarnings",
                "Label" : "利益剰余金",
                "Order" : 3,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:TreasuryStock",
                "Label" : "自己株式",
                "Order" : 4,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:ShareholdersEquity",
                "Label" : "株主資本合計",
                "Order" : 5,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              } ]
            }, {
              "Name" : "jppfs-cor:ValuationAndTranslationAdjustmentsAbstract",
              "Label" : "その他の包括利益累計額",
              "Order" : 2,
              "Kind" : "Abstract",
              "Depth" : 4,
              "Children" : [ {
                "Name" : "jppfs-cor:ValuationDifferenceOnAvailableForSaleSecurities",
                "Label" : "その他有価証券評価差額金",
                "Order" : 1,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:DeferredGainsOrLossesOnHedges",
                "Label" : "繰延ヘッジ損益",
                "Order" : 2,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:RevaluationReserveForLand",
                "Label" : "土地再評価差額金",
                "Order" : 3,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:ForeignCurrencyTranslationAdjustment",
                "Label" : "為替換算調整勘定",
                "Order" : 4,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:RemeasurementsOfDefinedBenefitPlans",
                "Label" : "退職給付に係る調整累計額",
                "Order" : 5,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:ValuationAndTranslationAdjustments",
                "Label" : "その他の包括利益累計額合計",
                "Order" : 6,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              } ]
            }, {
              "Name" : "jppfs-cor:MinorityInterests",
              "Label" : "少数株主持分",
              "Order" : 3,
              "Kind" : "Concept",
              "Depth" : 4,
              "IsNillable" : true,
              "IsAbstract" : false,
              "PeriodType" : "instant",
              "Balance" : "credit",
              "SubstitutionGroup" : "xbrli:item",
              "DataType" : "xbrli:monetaryItemType",
              "BaseType" : "xbrli:monetary",
              "ClosestSchemaBuiltinType" : "xs:decimal",
              "IsTextBlock" : false
            }, {
              "Name" : "jppfs-cor:NetAssets",
              "Label" : "純資産合計",
              "Order" : 4,
              "Kind" : "Concept",
              "Depth" : 4,
              "IsNillable" : true,
              "IsAbstract" : false,
              "PeriodType" : "instant",
              "Balance" : "credit",
              "SubstitutionGroup" : "xbrli:item",
              "DataType" : "xbrli:monetaryItemType",
              "BaseType" : "xbrli:monetary",
              "ClosestSchemaBuiltinType" : "xs:decimal",
              "IsTextBlock" : false
            } ]
          }, {
            "Name" : "jppfs-cor:LiabilitiesAndNetAssets",
            "Label" : "負債純資産合計",
            "Order" : 4,
            "Kind" : "Concept",
            "Depth" : 3,
            "IsNillable" : true,
            "IsAbstract" : false,
            "PeriodType" : "instant",
            "Balance" : "credit",
            "SubstitutionGroup" : "xbrli:item",
            "DataType" : "xbrli:monetaryItemType",
            "BaseType" : "xbrli:monetary",
            "ClosestSchemaBuiltinType" : "xs:decimal",
            "IsTextBlock" : false
          } ]
        } ]
      } ]
    } ],
    "actual" : [ {
      "Archive" : "S1002Q54",
      "Section" : "四半期連結貸借対照表",
      "Hypercube" : "Balance sheet",
      "SectionURI" : "http://disclosure.edinet-fsa.go.jp/role/jppfs/rol_QuarterlyConsolidatedBalanceSheet",
      "HypercubeName" : "jppfs-cor:BalanceSheetTable",
      "ModelStructure" : [ {
        "Name" : "jppfs-cor:QuarterlyConsolidatedBalanceSheetHeading",
        "Label" : "四半期連結貸借対照表",
        "Kind" : "Abstract",
        "Depth" : 1,
        "Children" : [ {
          "Name" : "jppfs-cor:BalanceSheetTable",
          "Label" : "連結貸借対照表",
          "Order" : 1,
          "Kind" : "Hypercube",
          "Depth" : 2,
          "Children" : [ {
            "Name" : "jppfs-cor:ConsolidatedOrNonConsolidatedAxis",
            "Label" : "連結個別",
            "Order" : 1,
            "Kind" : "Dimension",
            "Depth" : 3,
            "Children" : [ {
              "Name" : "jppfs-cor:ConsolidatedMember",
              "Label" : "連結",
              "Order" : 1,
              "Kind" : "Member",
              "Depth" : 4
            } ]
          }, {
            "Name" : "jppfs-cor:BalanceSheetLineItems",
            "Label" : "連結貸借対照表",
            "Order" : 2,
            "Kind" : "LineItems",
            "Depth" : 3,
            "Children" : [ {
              "Name" : "jppfs-cor:AssetsAbstract",
              "Label" : "資産の部",
              "Order" : 1,
              "Kind" : "Abstract",
              "Depth" : 4,
              "Children" : [ {
                "Name" : "jppfs-cor:CurrentAssetsAbstract",
                "Label" : "流動資産",
                "Order" : 1,
                "Kind" : "Abstract",
                "Depth" : 5,
                "Children" : [ {
                  "Name" : "jppfs-cor:CashAndDeposits",
                  "Label" : "現金及び預金",
                  "Order" : 1,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:NotesAndAccountsReceivableTrade",
                  "Label" : "受取手形及び売掛金",
                  "Order" : 2,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:Inventories",
                  "Label" : "たな卸資産",
                  "Order" : 3,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:OtherCA",
                  "Label" : "その他",
                  "Order" : 4,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:AllowanceForDoubtfulAccountsCA",
                  "Label" : "貸倒引当金",
                  "Order" : 5,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:CurrentAssets",
                  "Label" : "流動資産合計",
                  "Order" : 6,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                } ]
              }, {
                "Name" : "jppfs-cor:NoncurrentAssetsAbstract",
                "Label" : "固定資産",
                "Order" : 2,
                "Kind" : "Abstract",
                "Depth" : 5,
                "Children" : [ {
                  "Name" : "jppfs-cor:PropertyPlantAndEquipmentAbstract",
                  "Label" : "有形固定資産",
                  "Order" : 1,
                  "Kind" : "Abstract",
                  "Depth" : 6,
                  "Children" : [ {
                    "Name" : "jppfs-cor:BuildingsAndStructuresNet",
                    "Label" : "建物及び構築物（純額）",
                    "Order" : 1,
                    "Kind" : "Concept",
                    "Depth" : 7,
                    "IsNillable" : true,
                    "IsAbstract" : false,
                    "PeriodType" : "instant",
                    "Balance" : "debit",
                    "SubstitutionGroup" : "xbrli:item",
                    "DataType" : "xbrli:monetaryItemType",
                    "BaseType" : "xbrli:monetary",
                    "ClosestSchemaBuiltinType" : "xs:decimal",
                    "IsTextBlock" : false
                  }, {
                    "Name" : "jppfs-cor:MachineryEquipmentAndVehiclesNet",
                    "Label" : "機械装置及び運搬具（純額）",
                    "Order" : 2,
                    "Kind" : "Concept",
                    "Depth" : 7,
                    "IsNillable" : true,
                    "IsAbstract" : false,
                    "PeriodType" : "instant",
                    "Balance" : "debit",
                    "SubstitutionGroup" : "xbrli:item",
                    "DataType" : "xbrli:monetaryItemType",
                    "BaseType" : "xbrli:monetary",
                    "ClosestSchemaBuiltinType" : "xs:decimal",
                    "IsTextBlock" : false
                  }, {
                    "Name" : "jppfs-cor:OtherNetPPE",
                    "Label" : "その他（純額）",
                    "Order" : 3,
                    "Kind" : "Concept",
                    "Depth" : 7,
                    "IsNillable" : true,
                    "IsAbstract" : false,
                    "PeriodType" : "instant",
                    "Balance" : "debit",
                    "SubstitutionGroup" : "xbrli:item",
                    "DataType" : "xbrli:monetaryItemType",
                    "BaseType" : "xbrli:monetary",
                    "ClosestSchemaBuiltinType" : "xs:decimal",
                    "IsTextBlock" : false
                  }, {
                    "Name" : "jppfs-cor:PropertyPlantAndEquipment",
                    "Label" : "有形固定資産合計",
                    "Order" : 4,
                    "Kind" : "Concept",
                    "Depth" : 7,
                    "IsNillable" : true,
                    "IsAbstract" : false,
                    "PeriodType" : "instant",
                    "Balance" : "debit",
                    "SubstitutionGroup" : "xbrli:item",
                    "DataType" : "xbrli:monetaryItemType",
                    "BaseType" : "xbrli:monetary",
                    "ClosestSchemaBuiltinType" : "xs:decimal",
                    "IsTextBlock" : false
                  } ]
                }, {
                  "Name" : "jppfs-cor:IntangibleAssets",
                  "Label" : "無形固定資産",
                  "Order" : 2,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:InvestmentsAndOtherAssetsAbstract",
                  "Label" : "投資その他の資産",
                  "Order" : 3,
                  "Kind" : "Abstract",
                  "Depth" : 6,
                  "Children" : [ {
                    "Name" : "jppfs-cor:InvestmentSecurities",
                    "Label" : "投資有価証券",
                    "Order" : 1,
                    "Kind" : "Concept",
                    "Depth" : 7,
                    "IsNillable" : true,
                    "IsAbstract" : false,
                    "PeriodType" : "instant",
                    "Balance" : "debit",
                    "SubstitutionGroup" : "xbrli:item",
                    "DataType" : "xbrli:monetaryItemType",
                    "BaseType" : "xbrli:monetary",
                    "ClosestSchemaBuiltinType" : "xs:decimal",
                    "IsTextBlock" : false
                  }, {
                    "Name" : "jppfs-cor:NetDefinedBenefitAsset",
                    "Label" : "退職給付に係る資産",
                    "Order" : 2,
                    "Kind" : "Concept",
                    "Depth" : 7,
                    "IsNillable" : true,
                    "IsAbstract" : false,
                    "PeriodType" : "instant",
                    "Balance" : "debit",
                    "SubstitutionGroup" : "xbrli:item",
                    "DataType" : "xbrli:monetaryItemType",
                    "BaseType" : "xbrli:monetary",
                    "ClosestSchemaBuiltinType" : "xs:decimal",
                    "IsTextBlock" : false
                  }, {
                    "Name" : "jppfs-cor:OtherIOA",
                    "Label" : "その他",
                    "Order" : 3,
                    "Kind" : "Concept",
                    "Depth" : 7,
                    "IsNillable" : true,
                    "IsAbstract" : false,
                    "PeriodType" : "instant",
                    "Balance" : "debit",
                    "SubstitutionGroup" : "xbrli:item",
                    "DataType" : "xbrli:monetaryItemType",
                    "BaseType" : "xbrli:monetary",
                    "ClosestSchemaBuiltinType" : "xs:decimal",
                    "IsTextBlock" : false
                  }, {
                    "Name" : "jppfs-cor:AllowanceForDoubtfulAccountsIOAByGroup",
                    "Label" : "貸倒引当金",
                    "Order" : 4,
                    "Kind" : "Concept",
                    "Depth" : 7,
                    "IsNillable" : true,
                    "IsAbstract" : false,
                    "PeriodType" : "instant",
                    "Balance" : "debit",
                    "SubstitutionGroup" : "xbrli:item",
                    "DataType" : "xbrli:monetaryItemType",
                    "BaseType" : "xbrli:monetary",
                    "ClosestSchemaBuiltinType" : "xs:decimal",
                    "IsTextBlock" : false
                  }, {
                    "Name" : "jppfs-cor:InvestmentsAndOtherAssets",
                    "Label" : "投資その他の資産合計",
                    "Order" : 5,
                    "Kind" : "Concept",
                    "Depth" : 7,
                    "IsNillable" : true,
                    "IsAbstract" : false,
                    "PeriodType" : "instant",
                    "Balance" : "debit",
                    "SubstitutionGroup" : "xbrli:item",
                    "DataType" : "xbrli:monetaryItemType",
                    "BaseType" : "xbrli:monetary",
                    "ClosestSchemaBuiltinType" : "xs:decimal",
                    "IsTextBlock" : false
                  } ]
                }, {
                  "Name" : "jppfs-cor:NoncurrentAssets",
                  "Label" : "固定資産合計",
                  "Order" : 4,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "debit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                } ]
              }, {
                "Name" : "jppfs-cor:Assets",
                "Label" : "資産合計",
                "Order" : 3,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "debit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              } ]
            }, {
              "Name" : "jppfs-cor:LiabilitiesAbstract",
              "Label" : "負債の部",
              "Order" : 2,
              "Kind" : "Abstract",
              "Depth" : 4,
              "Children" : [ {
                "Name" : "jppfs-cor:CurrentLiabilitiesAbstract",
                "Label" : "流動負債",
                "Order" : 1,
                "Kind" : "Abstract",
                "Depth" : 5,
                "Children" : [ {
                  "Name" : "jppfs-cor:NotesAndAccountsPayableTrade",
                  "Label" : "支払手形及び買掛金",
                  "Order" : 1,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:ShortTermLoansPayable",
                  "Label" : "短期借入金",
                  "Order" : 2,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:CommercialPapersLiabilities",
                  "Label" : "コマーシャル・ペーパー",
                  "Order" : 3,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:CurrentPortionOfBonds",
                  "Label" : "1年内償還予定の社債",
                  "Order" : 4,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:IncomeTaxesPayable",
                  "Label" : "未払法人税等",
                  "Order" : 5,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:ProvisionCL",
                  "Label" : "引当金",
                  "Order" : 6,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:OtherCL",
                  "Label" : "その他",
                  "Order" : 7,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:CurrentLiabilities",
                  "Label" : "流動負債合計",
                  "Order" : 8,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                } ]
              }, {
                "Name" : "jppfs-cor:NoncurrentLiabilitiesAbstract",
                "Label" : "固定負債",
                "Order" : 2,
                "Kind" : "Abstract",
                "Depth" : 5,
                "Children" : [ {
                  "Name" : "jppfs-cor:BondsPayable",
                  "Label" : "社債",
                  "Order" : 1,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:LongTermLoansPayable",
                  "Label" : "長期借入金",
                  "Order" : 2,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:ProvisionNCL",
                  "Label" : "引当金",
                  "Order" : 3,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:NetDefinedBenefitLiability",
                  "Label" : "退職給付に係る負債",
                  "Order" : 4,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:OtherNCL",
                  "Label" : "その他",
                  "Order" : 5,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:NoncurrentLiabilities",
                  "Label" : "固定負債合計",
                  "Order" : 6,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                } ]
              }, {
                "Name" : "jppfs-cor:Liabilities",
                "Label" : "負債合計",
                "Order" : 3,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              } ]
            }, {
              "Name" : "jppfs-cor:NetAssetsAbstract",
              "Label" : "純資産の部",
              "Order" : 3,
              "Kind" : "Abstract",
              "Depth" : 4,
              "Children" : [ {
                "Name" : "jppfs-cor:ShareholdersEquityAbstract",
                "Label" : "株主資本",
                "Order" : 1,
                "Kind" : "Abstract",
                "Depth" : 5,
                "Children" : [ {
                  "Name" : "jppfs-cor:CapitalStock",
                  "Label" : "資本金",
                  "Order" : 1,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:CapitalSurplus",
                  "Label" : "資本剰余金",
                  "Order" : 2,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:RetainedEarnings",
                  "Label" : "利益剰余金",
                  "Order" : 3,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:TreasuryStock",
                  "Label" : "自己株式",
                  "Order" : 4,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:ShareholdersEquity",
                  "Label" : "株主資本合計",
                  "Order" : 5,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                } ]
              }, {
                "Name" : "jppfs-cor:ValuationAndTranslationAdjustmentsAbstract",
                "Label" : "その他の包括利益累計額",
                "Order" : 2,
                "Kind" : "Abstract",
                "Depth" : 5,
                "Children" : [ {
                  "Name" : "jppfs-cor:ValuationDifferenceOnAvailableForSaleSecurities",
                  "Label" : "その他有価証券評価差額金",
                  "Order" : 1,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:DeferredGainsOrLossesOnHedges",
                  "Label" : "繰延ヘッジ損益",
                  "Order" : 2,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:RevaluationReserveForLand",
                  "Label" : "土地再評価差額金",
                  "Order" : 3,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:ForeignCurrencyTranslationAdjustment",
                  "Label" : "為替換算調整勘定",
                  "Order" : 4,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:RemeasurementsOfDefinedBenefitPlans",
                  "Label" : "退職給付に係る調整累計額",
                  "Order" : 5,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                }, {
                  "Name" : "jppfs-cor:ValuationAndTranslationAdjustments",
                  "Label" : "その他の包括利益累計額合計",
                  "Order" : 6,
                  "Kind" : "Concept",
                  "Depth" : 6,
                  "IsNillable" : true,
                  "IsAbstract" : false,
                  "PeriodType" : "instant",
                  "Balance" : "credit",
                  "SubstitutionGroup" : "xbrli:item",
                  "DataType" : "xbrli:monetaryItemType",
                  "BaseType" : "xbrli:monetary",
                  "ClosestSchemaBuiltinType" : "xs:decimal",
                  "IsTextBlock" : false
                } ]
              }, {
                "Name" : "jppfs-cor:MinorityInterests",
                "Label" : "少数株主持分",
                "Order" : 3,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              }, {
                "Name" : "jppfs-cor:NetAssets",
                "Label" : "純資産合計",
                "Order" : 4,
                "Kind" : "Concept",
                "Depth" : 5,
                "IsNillable" : true,
                "IsAbstract" : false,
                "PeriodType" : "instant",
                "Balance" : "credit",
                "SubstitutionGroup" : "xbrli:item",
                "DataType" : "xbrli:monetaryItemType",
                "BaseType" : "xbrli:monetary",
                "ClosestSchemaBuiltinType" : "xs:decimal",
                "IsTextBlock" : false
              } ]
            }, {
              "Name" : "jppfs-cor:LiabilitiesAndNetAssets",
              "Label" : "負債純資産合計",
              "Order" : 4,
              "Kind" : "Concept",
              "Depth" : 4,
              "IsNillable" : true,
              "IsAbstract" : false,
              "PeriodType" : "instant",
              "Balance" : "credit",
              "SubstitutionGroup" : "xbrli:item",
              "DataType" : "xbrli:monetaryItemType",
              "BaseType" : "xbrli:monetary",
              "ClosestSchemaBuiltinType" : "xs:decimal",
              "IsTextBlock" : false
            } ]
          } ]
        } ]
      } ]
    } ]

機械装置及び運搬具（純額）

その他有価証券評価差額金

退職給付に係る調整累計額

その他の包括利益累計額合計


fix bug related to returning duplicate facts in case of amended filings

import module namespace companies = "http://xbrl.io/modules/bizql/profiles/sec/companies";
import module namespace archives = "http://xbrl.io/modules/bizql/archives";
import module namespace sec-fiscal = "http://xbrl.io/modules/bizql/profiles/sec/fiscal/core";
import module namespace facts = "http://xbrl.io/modules/bizql/facts";

import module namespace hypercubes = "http://xbrl.io/modules/bizql/hypercubes";
import module namespace response = "http://www.28msec.com/modules/http-response";
import module namespace request = "http://www.28msec.com/modules/http-request";
import module namespace session = "http://apps.28.io/session";
import module namespace csv = "http://zorba.io/modules/json-csv";

declare function local:to-csv($o as object*) as string?
{
    if (exists($o)) (: bug in csv:serialize :)
    then
    string-join(
        csv:serialize(
            for $o in $o
            let $a := $o.Aspects
            return {|
                for $k in keys($a)
                return { $k : $a.$k },
                { "Value" : $o.Value },
                if (exists($o."Unit"))
                then { "Unit" :  $o."Unit" }
                else (),
                if (exists($o.Decimals))
                then { "Decimals" : $o.Decimals }
                else(),
                { "EntityRegistrantName" : $o.EntityRegistrantName },
                if (exists($o.ReportedConcept))
                then { "ReportedConcept" : $o.ReportedConcept }
                else ()
            |},
            { serialize-null-as : "" }
        )
    )
    else ()
};

declare function local:to-xml($o as object*) as node()*
{
    (session:comment("xml", {
        NumFacts: count($o),
        TotalNumFacts: session:num-facts(),
        TotalNumArchives: session:num-archives(),
        TotalNumEntities: session:num-entities()
    }),
    <FactTable NetworkIdentifier="http://bizql.io/facts"
            TableName="xbrl:Facts">{
        for $o in $o
        let $a := $o.Aspects
        return
            <Fact>{
                <Aspects>{
                    for $k in keys($a)
                    return
                        <Aspect>
                            <Name>{$k}</Name>
                            <Value>{$a.$k}</Value>
                        </Aspect>
                }</Aspects>,
                <Value>{$o.Value}</Value>,
                <Type>{$o.Type}</Type>,
                if (exists($o.Unit))
                then <Unit>{$o.Unit}</Unit>
                else(),
                if (exists($o.Decimals))
                then <Decimals>{$o.Decimals}</Decimals>
                else (),
                <EntityRegistrantName>{$o.EntityRegistrantName}</EntityRegistrantName>,
                if (exists($o.ReportedConcept))
                then <ReportedConcept>{$o."ReportedConcept"}</ReportedConcept>
                else ()
            }</Fact>
    }</FactTable>)
};

declare function local:facts(
    $archives as object*,
    $concepts as string*,
    $dimensions as object* ,
    $map as string?,
    $rules as string?) as object*
{
    let $aspects :=
        {|
            { "xbrl:Concept" : $concepts },
            (: This is because of a bug that will be fixed later (hypercube members do not get considered) :)
            for $d in values($dimensions)
            let $members := descendant-objects(values($d)).Name
            where exists($members)
            return { $d.Name: [ $members ] }
        |}
    let $hypercube := copy $h := hypercubes:dimensionless-hypercube()
                      modify (
                          insert json (
                            if (values($dimensions).Name = "dei:LegalEntityAxis")
                            then { "dei:LegalEntityAxis" : values($dimensions)[$$.Name eq "dei:LegalEntityAxis"] }
                            else
                            {|
                                "dei:LegalEntityAxis" ! {
                                $$ : {
                                        Name : $$,
                                        Default : "sec:DefaultLegalEntity",
                                        Domains: {
                                            "sec:DefaultLegalEntity" : {
                                                Name: "sec:DefaultLegalEntity"
                                            }
                                        }
                                    }
                                }
                            |})
                          into $h.Aspects,
                          for $d in $dimensions[not values($$).Name = "dei:LegalEntityAxis"]
                          return insert json $d into $h.Aspects
                      )
                      return $h
    let $options :=
            {|
                if (exists($map))
                then { "concept-maps" : $map }
                else (),
                if (exists($rules))
                then { "Rules" : $rules }
                else (),
                { Hypercube : $hypercube }
            |}
    return
    for $fact in
        for $f in facts:facts-for-archives-and-aspects($archives, $aspects, $options)
        where exists($f.Profiles.SEC.Fiscal.Year)
        group by $f.Profiles.SEC.Fiscal.Year,
                 $f.Profiles.SEC.Fiscal.Period,
                 $f.Aspects."xbrl:Concept"
        let $latest-accepted := max(distinct-values($f.Profiles.SEC.Accepted))
        return if (empty($latest-accepted))
               then $f
               else $f[$$.Profiles.SEC.Accepted eq $latest-accepted]
    return {|
        { Aspects : {|
            for $a in keys($fact.Aspects)
            where $a ne "xbrl:Unit"
            return { $a : $fact.Aspects.$a },
            { "bizql:FiscalPeriod" : $fact.Profiles.SEC.Fiscal.Period },
            { "bizql:FiscalYear" : $fact.Profiles.SEC.Fiscal.Year }
        |} },
        { Type: $fact.Type },
        if (exists($fact.Aspects."xbrl:Unit"))
        then { Unit: $fact.Aspects."xbrl:Unit" }
        else  (),
        if (exists($fact.Decimals))
        then { Decimals: $fact.Decimals }
        else (),
        { Value: $fact.Value },
        { "EntityRegistrantName" : companies:companies($fact.Aspects."xbrl:Entity").Profiles.SEC.CompanyName},
        if (exists($map) and ($fact."xbrl28:Type" eq "xbrl28:concept-maps"))
        then { "ReportedConcept" : $fact.AuditTrails[][$$.Type eq "xbrl28:concept-maps"].Data.OriginalConcept[1] }
        else ()
    |}
};

declare function local:filings(
    $ciks as string*,
    $tags as string*,
    $tickers as string*,
    $sics as string*,
    $fp as string*,
    $fy as string*) as object*
{
    let $entities := (
        companies:companies($ciks),
        companies:companies-for-tags($tags),
        companies:companies-for-tickers($tickers),
        companies:companies-for-SIC($sics)
    )
    for $entity in $entities
    for $fy in distinct-values(
                for $fy in $fy
                return
                    switch ($fy)
                    case "LATEST" return
                        for $p in $fp
                        return
                            if ($p eq "FY")
                            then sec-fiscal:latest-reported-fiscal-period($entity, "10-K").year
                            else sec-fiscal:latest-reported-fiscal-period($entity, "10-Q").year
                        case "ALL" return  $sec-fiscal:ALL_FISCAL_YEARS
                    default return $fy
                )
    for $fp in $fp
    return sec-fiscal:filings-for-entities-and-fiscal-periods-and-years($entity, $fp, $fy cast as integer)
};

let $format      := lower-case(request:param-values("format")[1])

(: choose
    1. entities (using ciks, tags, tickers, sics), FY, and FP ) or
    2. accession numbers
:)
let $ciks        := distinct-values(companies:eid(request:param-values("cik")))
let $tags        := distinct-values(request:param-values("tag") ! upper-case($$))
let $tickers     := distinct-values(request:param-values("ticker"))
let $sics        := distinct-values(request:param-values("sic"))
let $fiscalYears := distinct-values(
                        for $y in request:param-values("fiscalYear", "LATEST")
                        return
                            if ($y eq "LATEST" or $y eq "ALL")
                            then $y
                            else if ($y castable as integer)
                            then $y
                            else ()
                    )
let $fiscalPeriods := distinct-values(let $fp := request:param-values("fiscalPeriod", "FY")
                      return
                        if (($fp ! lower-case($$)) = "all")
                        then $sec-fiscal:ALL_FISCAL_PERIODS
                        else $fp)
let $aids := request:param-values("aid")
let $dimensions :=  for $p in request:param-names()
                    where contains($p, ":")
                    group by $dimension-name := if (ends-with(lower-case($p), ":default"))
                                                then
                                                    if (ends-with(lower-case($p), "::default"))
                                                    then substring-before($p, "::default")
                                                    else substring-before($p, ":default")
                                                else $p
                    let $default := ($p = $dimension-name || "::default") or ($p = $dimension-name || ":default")
                    let $all := (request:param-values($dimension-name) ! upper-case($$)) = "ALL"
                    return
                    {
                       $dimension-name : {|
                            { Name : $dimension-name },
                            if ($default)
                            then { Default :
                                (request:param-values($dimension-name || "::default"),
                                 request:param-values($dimension-name || ":default"))[1] }
                            else (),
                            if ($all)
                            then ()
                            else {
                                Domains : {
                                    "sec:ImplicitDomain" : {
                                        Name: "sec:ImplicitDomain",
                                        Members: {|
                                            (request:param-values($dimension-name)) ! { $$ : { Name: $$ } }
                                        |}
                                    }
                                }
                            }
                        |}
                    }
let $concepts := request:param-values("concept")
let $map      := request:param-values("map")[1]
let $rules      := request:param-values("rules")[1]
return
  if (empty($concepts))
  then {
    response:status-code(400);
    session:error("concept: missing parameter", $format)
  } else
    let $archives := (
                        local:filings($ciks, $tags, $tickers, $sics, $fiscalPeriods, $fiscalYears),
                        archives:archives($aids)
                     )
    let $entities     := companies:companies($archives.Entity)
    return switch(true)
      case empty($archives) return {
        response:status-code(400);
        session:error("entities or archives not found (valid parameters: cik, ticker, tag, sic, aid)", $format)
      }
      case not (session:only-dow30($entities) or session:valid()) return {
        response:status-code(401);
        session:error("accessing facts of an entity that is not in the DOW30", $format)
      }
      default return
        let $facts := local:facts($archives, $concepts, $dimensions, $map, $rules)
        return
            switch ($format)
            case "xml" return {
                response:serialization-parameters({"omit-xml-declaration" : false, indent : true });
                local:to-xml($facts)
            }
            case "text" case "csv" return {
                response:content-type("text/csv");
                response:header("Content-Disposition", "attachment; filename=facts.csv");
                local:to-csv($facts)
            }
            case "excel" return {
                response:content-type("application/vnd.ms-excel");
                response:header("Content-Disposition", "attachment; filename=fact.csv");
                local:to-csv($facts)
            }
            default return {
                response:content-type("application/json");
                response:serialization-parameters({"indent" : true});
                {|
                    { NetworkIdentifier : "http://bizql.io/facts" },
                    { TableName : "xbrl:Facts" },
                    { FactTable : [ $facts ] },
                    session:comment("json", {
                            NumFacts: count($facts),
                            TotalNumFacts: session:num-facts(),
                            TotalNumArchives: session:num-archives(),
                            TotalNumEntities: session:num-entities()
                        })
                |}
            }

import module namespace companies = "http://xbrl.io/modules/bizql/profiles/sec/companies";
import module namespace archives = "http://xbrl.io/modules/bizql/archives";
import module namespace sec-fiscal = "http://xbrl.io/modules/bizql/profiles/sec/fiscal/core";
import module namespace facts = "http://xbrl.io/modules/bizql/facts";

import module namespace hypercubes = "http://xbrl.io/modules/bizql/hypercubes";
import module namespace response = "http://www.28msec.com/modules/http-response";
import module namespace request = "http://www.28msec.com/modules/http-request";
import module namespace session = "http://apps.28.io/session";
import module namespace csv = "http://zorba.io/modules/json-csv";

declare function local:to-csv($o as object*) as string?
{
    if (exists($o)) (: bug in csv:serialize :)
    then
    string-join(
        csv:serialize(
            for $o in $o
            let $a := $o.Aspects
            return {|
                for $k in keys($a)
                return { $k : $a.$k },
                { "Value" : $o.Value },
                if (exists($o."Unit"))
                then { "Unit" :  $o."Unit" }
                else (),
                if (exists($o.Decimals))
                then { "Decimals" : $o.Decimals }
                else(),
                { "EntityRegistrantName" : $o.EntityRegistrantName },
                if (exists($o.ReportedConcept))
                then { "ReportedConcept" : $o.ReportedConcept }
                else ()
            |},
            { serialize-null-as : "" }
        )
    )
    else ()
};

declare function local:to-xml($o as object*) as node()*
{
    (session:comment("xml", {
        NumFacts: count($o),
        TotalNumFacts: session:num-facts(),
        TotalNumArchives: session:num-archives(),
        TotalNumEntities: session:num-entities()
    }),
    <FactTable NetworkIdentifier="http://bizql.io/facts"
            TableName="xbrl:Facts">{
        for $o in $o
        let $a := $o.Aspects
        return
            <Fact>{
                <Aspects>{
                    for $k in keys($a)
                    return
                        <Aspect>
                            <Name>{$k}</Name>
                            <Value>{$a.$k}</Value>
                        </Aspect>
                }</Aspects>,
                <Value>{$o.Value}</Value>,
                <Type>{$o.Type}</Type>,
                if (exists($o.Unit))
                then <Unit>{$o.Unit}</Unit>
                else(),
                if (exists($o.Decimals))
                then <Decimals>{$o.Decimals}</Decimals>
                else (),
                <EntityRegistrantName>{$o.EntityRegistrantName}</EntityRegistrantName>,
                if (exists($o.ReportedConcept))
                then <ReportedConcept>{$o."ReportedConcept"}</ReportedConcept>
                else ()
            }</Fact>
    }</FactTable>)
};

declare function local:facts(
    $archives as object*,
    $concepts as string*,
    $dimensions as object* ,
    $map as string?,
    $rules as string?) as object*
{
    let $aspects :=
        {|
            { "xbrl:Concept" : $concepts },
            (: This is because of a bug that will be fixed later (hypercube members do not get considered) :)
            for $d in values($dimensions)
            let $members := descendant-objects(values($d)).Name
            where exists($members)
            return { $d.Name: [ $members ] }
        |}
    let $hypercube := copy $h := hypercubes:dimensionless-hypercube()
                      modify (
                          insert json (
                            if (values($dimensions).Name = "dei:LegalEntityAxis")
                            then { "dei:LegalEntityAxis" : values($dimensions)[$$.Name eq "dei:LegalEntityAxis"] }
                            else
                            {|
                                "dei:LegalEntityAxis" ! {
                                $$ : {
                                        Name : $$,
                                        Default : "sec:DefaultLegalEntity",
                                        Domains: {
                                            "sec:DefaultLegalEntity" : {
                                                Name: "sec:DefaultLegalEntity"
                                            }
                                        }
                                    }
                                }
                            |})
                          into $h.Aspects,
                          for $d in $dimensions[not values($$).Name = "dei:LegalEntityAxis"]
                          return insert json $d into $h.Aspects
                      )
                      return $h
    let $options :=
            {|
                if (exists($map))
                then { "concept-maps" : $map }
                else (),
                if (exists($rules))
                then { "Rules" : $rules }
                else (),
                { Hypercube : $hypercube }
            |}
    return
    for $fact in
        for $f in facts:facts-for-archives-and-aspects($archives, $aspects, $options)
        where exists($f.Profiles.SEC.Fiscal.Year)
        group by $f.Profiles.SEC.Fiscal.Year,
                 $f.Profiles.SEC.Fiscal.Period,
                 $f.Aspects."xbrl:Concept"
        let $latest-accepted := max(distinct-values($f.Profiles.SEC.Fiscal.Acceptance))
        return if (empty($latest-accepted))
               then $f
               else $f[$$.Profiles.SEC.Fiscal.Acceptance eq $latest-accepted]
    return {|
        { Aspects : {|
            for $a in keys($fact.Aspects)
            where $a ne "xbrl:Unit"
            return { $a : $fact.Aspects.$a },
            { "bizql:FiscalPeriod" : $fact.Profiles.SEC.Fiscal.Period },
            { "bizql:FiscalYear" : $fact.Profiles.SEC.Fiscal.Year }
        |} },
        { Type: $fact.Type },
        if (exists($fact.Aspects."xbrl:Unit"))
        then { Unit: $fact.Aspects."xbrl:Unit" }
        else  (),
        if (exists($fact.Decimals))
        then { Decimals: $fact.Decimals }
        else (),
        { Value: $fact.Value },
        { "EntityRegistrantName" : companies:companies($fact.Aspects."xbrl:Entity").Profiles.SEC.CompanyName},
        if (exists($map) and ($fact."xbrl28:Type" eq "xbrl28:concept-maps"))
        then { "ReportedConcept" : $fact.AuditTrails[][$$.Type eq "xbrl28:concept-maps"].Data.OriginalConcept[1] }
        else ()
    |}
};

declare function local:filings(
    $ciks as string*,
    $tags as string*,
    $tickers as string*,
    $sics as string*,
    $fp as string*,
    $fy as string*) as object*
{
    let $entities := (
        companies:companies($ciks),
        companies:companies-for-tags($tags),
        companies:companies-for-tickers($tickers),
        companies:companies-for-SIC($sics)
    )
    for $entity in $entities
    for $fy in distinct-values(
                for $fy in $fy
                return
                    switch ($fy)
                    case "LATEST" return
                        for $p in $fp
                        return
                            if ($p eq "FY")
                            then sec-fiscal:latest-reported-fiscal-period($entity, "10-K").year
                            else sec-fiscal:latest-reported-fiscal-period($entity, "10-Q").year
                        case "ALL" return  $sec-fiscal:ALL_FISCAL_YEARS
                    default return $fy
                )
    for $fp in $fp
    return sec-fiscal:filings-for-entities-and-fiscal-periods-and-years($entity, $fp, $fy cast as integer)
};

let $format      := lower-case(request:param-values("format")[1])

(: choose
    1. entities (using ciks, tags, tickers, sics), FY, and FP ) or
    2. accession numbers
:)
let $ciks        := distinct-values(companies:eid(request:param-values("cik")))
let $tags        := distinct-values(request:param-values("tag") ! upper-case($$))
let $tickers     := distinct-values(request:param-values("ticker"))
let $sics        := distinct-values(request:param-values("sic"))
let $fiscalYears := distinct-values(
                        for $y in request:param-values("fiscalYear", "LATEST")
                        return
                            if ($y eq "LATEST" or $y eq "ALL")
                            then $y
                            else if ($y castable as integer)
                            then $y
                            else ()
                    )
let $fiscalPeriods := distinct-values(let $fp := request:param-values("fiscalPeriod", "FY")
                      return
                        if (($fp ! lower-case($$)) = "all")
                        then $sec-fiscal:ALL_FISCAL_PERIODS
                        else $fp)
let $aids := request:param-values("aid")
let $dimensions :=  for $p in request:param-names()
                    where contains($p, ":")
                    group by $dimension-name := if (ends-with(lower-case($p), ":default"))
                                                then
                                                    if (ends-with(lower-case($p), "::default"))
                                                    then substring-before($p, "::default")
                                                    else substring-before($p, ":default")
                                                else $p
                    let $default := ($p = $dimension-name || "::default") or ($p = $dimension-name || ":default")
                    let $all := (request:param-values($dimension-name) ! upper-case($$)) = "ALL"
                    return
                    {
                       $dimension-name : {|
                            { Name : $dimension-name },
                            if ($default)
                            then { Default :
                                (request:param-values($dimension-name || "::default"),
                                 request:param-values($dimension-name || ":default"))[1] }
                            else (),
                            if ($all)
                            then ()
                            else {
                                Domains : {
                                    "sec:ImplicitDomain" : {
                                        Name: "sec:ImplicitDomain",
                                        Members: {|
                                            (request:param-values($dimension-name)) ! { $$ : { Name: $$ } }
                                        |}
                                    }
                                }
                            }
                        |}
                    }
let $concepts := request:param-values("concept")
let $map      := request:param-values("map")[1]
let $rules      := request:param-values("rules")[1]
return
  if (empty($concepts))
  then {
    response:status-code(400);
    session:error("concept: missing parameter", $format)
  } else
    let $archives := (
                        local:filings($ciks, $tags, $tickers, $sics, $fiscalPeriods, $fiscalYears),
                        archives:archives($aids)
                     )
    let $entities     := companies:companies($archives.Entity)
    return switch(true)
      case empty($archives) return {
        response:status-code(400);
        session:error("entities or archives not found (valid parameters: cik, ticker, tag, sic, aid)", $format)
      }
      case not (session:only-dow30($entities) or session:valid()) return {
        response:status-code(401);
        session:error("accessing facts of an entity that is not in the DOW30", $format)
      }
      default return
        let $facts := local:facts($archives, $concepts, $dimensions, $map, $rules)
        return
            switch ($format)
            case "xml" return {
                response:serialization-parameters({"omit-xml-declaration" : false, indent : true });
                local:to-xml($facts)
            }
            case "text" case "csv" return {
                response:content-type("text/csv");
                response:header("Content-Disposition", "attachment; filename=facts.csv");
                local:to-csv($facts)
            }
            case "excel" return {
                response:content-type("application/vnd.ms-excel");
                response:header("Content-Disposition", "attachment; filename=fact.csv");
                local:to-csv($facts)
            }
            default return {
                response:content-type("application/json");
                response:serialization-parameters({"indent" : true});
                {|
                    { NetworkIdentifier : "http://bizql.io/facts" },
                    { TableName : "xbrl:Facts" },
                    { FactTable : [ $facts ] },
                    session:comment("json", {
                            NumFacts: count($facts),
                            TotalNumFacts: session:num-facts(),
                            TotalNumArchives: session:num-archives(),
                            TotalNumEntities: session:num-entities()
                        })
                |}
            }