digraph logic {
  graph [rankdir=TB, fontname="Helvetica", fontsize=13,
         label=<<B>Logic Diagram — samples/demo_customs_surtax</B>>, labelloc=t,
         pad=0.4, nodesep=0.90, ranksep=1.10, bgcolor="white",
         splines=spline]
  node  [fontname="Helvetica", fontsize=11, shape=plaintext]
  edge  [fontname="Helvetica", fontsize=10]

  // ── trigger ─────────────────────────────────────────────────────
  TRIGGER [label=<<TABLE BORDER="2" CELLBORDER="0" CELLPADDING="5" BGCOLOR="#e8f5e9" COLOR="#27ae60"><TR><TD><FONT COLOR="#27ae60"><B>&#9889; SurtaxLineItem inserted</B></FONT></TD></TR></TABLE>>, shape=plaintext]

  // ── schema layer ──────────────────────────────────────────────────
  CountryOrigin [label=<<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" COLOR="#4a6fa5"><TR><TD COLSPAN="3" BGCOLOR="#4a6fa5"><FONT COLOR="white"><B> CountryOrigin </B></FONT></TD></TR><TR><TD PORT="CountryOrigin_surtax_rate_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="CountryOrigin_surtax_rate" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> surtax_rate </FONT></TD><TD PORT="CountryOrigin_surtax_rate_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR></TABLE>>]
  CustomsEntry [label=<<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" COLOR="#4a6fa5"><TR><TD COLSPAN="3" BGCOLOR="#4a6fa5"><FONT COLOR="white"><B> CustomsEntry </B></FONT></TD></TR><TR><TD PORT="CustomsEntry_total_customs_value_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="CustomsEntry_total_customs_value" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> total_customs_value </FONT></TD><TD PORT="CustomsEntry_total_customs_value_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="CustomsEntry_total_duty_amount_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="CustomsEntry_total_duty_amount" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> total_duty_amount </FONT></TD><TD PORT="CustomsEntry_total_duty_amount_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="CustomsEntry_total_surtax_amount_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="CustomsEntry_total_surtax_amount" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> total_surtax_amount </FONT></TD><TD PORT="CustomsEntry_total_surtax_amount_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="CustomsEntry_surtax_applicable_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="CustomsEntry_surtax_applicable" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> surtax_applicable </FONT> <FONT COLOR="#e67e22" POINT-SIZE="9">= 1 if (ship_date is not None...</FONT></TD><TD PORT="CustomsEntry_surtax_applicable_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="CustomsEntry_ship_date_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="CustomsEntry_ship_date" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> ship_date </FONT></TD><TD PORT="CustomsEntry_ship_date_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="CustomsEntry_effective_date_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="CustomsEntry_effective_date" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> effective_date </FONT></TD><TD PORT="CustomsEntry_effective_date_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="CustomsEntry_country_surtax_rate_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="CustomsEntry_country_surtax_rate" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> country_surtax_rate </FONT></TD><TD PORT="CustomsEntry_country_surtax_rate_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="CustomsEntry_duty_paid_value_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="CustomsEntry_duty_paid_value" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> duty_paid_value </FONT> <FONT COLOR="#e67e22" POINT-SIZE="9">= (total_customs_value or 0)
...</FONT></TD><TD PORT="CustomsEntry_duty_paid_value_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="CustomsEntry_sales_tax_amount_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="CustomsEntry_sales_tax_amount" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> sales_tax_amount </FONT> <FONT COLOR="#e67e22" POINT-SIZE="9">= (duty_paid_value or 0) * (p...</FONT></TD><TD PORT="CustomsEntry_sales_tax_amount_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="CustomsEntry_province_tax_rate_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="CustomsEntry_province_tax_rate" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> province_tax_rate </FONT></TD><TD PORT="CustomsEntry_province_tax_rate_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="CustomsEntry_total_tax_due_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="CustomsEntry_total_tax_due" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> total_tax_due </FONT> <FONT COLOR="#e67e22" POINT-SIZE="9">= (total_duty_amount or 0)
  ...</FONT></TD><TD PORT="CustomsEntry_total_tax_due_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="CustomsEntry_program_code_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="CustomsEntry_program_code" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> program_code </FONT></TD><TD PORT="CustomsEntry_program_code_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="CustomsEntry_pc_number_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="CustomsEntry_pc_number" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> pc_number </FONT></TD><TD PORT="CustomsEntry_pc_number_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR></TABLE>>]
  HsCodeRate [label=<<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" COLOR="#4a6fa5"><TR><TD COLSPAN="3" BGCOLOR="#4a6fa5"><FONT COLOR="white"><B> HsCodeRate </B></FONT></TD></TR><TR><TD PORT="HsCodeRate_base_duty_rate_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="HsCodeRate_base_duty_rate" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> base_duty_rate </FONT></TD><TD PORT="HsCodeRate_base_duty_rate_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="HsCodeRate_is_steel_derivative_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="HsCodeRate_is_steel_derivative" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> is_steel_derivative </FONT></TD><TD PORT="HsCodeRate_is_steel_derivative_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR></TABLE>>]
  Province [label=<<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" COLOR="#4a6fa5"><TR><TD COLSPAN="3" BGCOLOR="#4a6fa5"><FONT COLOR="white"><B> Province </B></FONT></TD></TR><TR><TD PORT="Province_tax_rate_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="Province_tax_rate" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> tax_rate </FONT></TD><TD PORT="Province_tax_rate_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR></TABLE>>]
  SurtaxLineItem [label=<<TABLE BORDER="3" CELLBORDER="0" CELLSPACING="0" COLOR="#c0392b"><TR><TD COLSPAN="3" BGCOLOR="#4a6fa5"><FONT COLOR="white"><B> SurtaxLineItem </B></FONT></TD></TR><TR><TD PORT="SurtaxLineItem_customs_value_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="SurtaxLineItem_customs_value" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> customs_value </FONT></TD><TD PORT="SurtaxLineItem_customs_value_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="SurtaxLineItem_base_duty_amount_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="SurtaxLineItem_base_duty_amount" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> base_duty_amount </FONT> <FONT COLOR="#e67e22" POINT-SIZE="9">= (customs_value or 0) * (bas...</FONT></TD><TD PORT="SurtaxLineItem_base_duty_amount_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="SurtaxLineItem_surtax_amount_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="SurtaxLineItem_surtax_amount" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> surtax_amount </FONT> <FONT COLOR="#e67e22" POINT-SIZE="9">= (customs_value or 0) * (cus...</FONT></TD><TD PORT="SurtaxLineItem_surtax_amount_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="SurtaxLineItem_surtax_applicable_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="SurtaxLineItem_surtax_applicable" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> surtax_applicable </FONT> <FONT COLOR="#e67e22" POINT-SIZE="9">= 1 if (customs_entry.surtax_...</FONT></TD><TD PORT="SurtaxLineItem_surtax_applicable_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="SurtaxLineItem_customs_entry_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="SurtaxLineItem_customs_entry" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> customs_entry </FONT></TD><TD PORT="SurtaxLineItem_customs_entry_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="SurtaxLineItem_is_steel_derivative_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="SurtaxLineItem_is_steel_derivative" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> is_steel_derivative </FONT></TD><TD PORT="SurtaxLineItem_is_steel_derivative_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="SurtaxLineItem_base_duty_rate_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="SurtaxLineItem_base_duty_rate" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> base_duty_rate </FONT></TD><TD PORT="SurtaxLineItem_base_duty_rate_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR></TABLE>>]
  SysConfig [label=<<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" COLOR="#4a6fa5"><TR><TD COLSPAN="3" BGCOLOR="#4a6fa5"><FONT COLOR="white"><B> SysConfig </B></FONT></TD></TR><TR><TD PORT="SysConfig_effective_date_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="SysConfig_effective_date" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> effective_date </FONT></TD><TD PORT="SysConfig_effective_date_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="SysConfig_program_code_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="SysConfig_program_code" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> program_code </FONT></TD><TD PORT="SysConfig_program_code_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR><TR><TD PORT="SysConfig_pc_number_w" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD><TD PORT="SysConfig_pc_number" ALIGN="LEFT" BGCOLOR="#dbe4f0" CELLPADDING="3"><FONT COLOR="#1a1a2e"> pc_number </FONT></TD><TD PORT="SysConfig_pc_number_e" WIDTH="6" HEIGHT="18" BGCOLOR="#b8cce8"> </TD></TR></TABLE>>]
  // ── rank groupings ────────────────────────────────────────────────
  { rank=min; SysConfig; HsCodeRate; CountryOrigin; Province }
  { rank=same; CustomsEntry }
  { rank=max; SurtaxLineItem; TRIGGER }

  // ── FK relationships ───────────────────────────────────────────
  CustomsEntry -> CountryOrigin [color="#e0e0e0", style=solid, arrowhead=none, arrowtail=crow, dir=both, penwidth=0.7, constraint=false, weight=1]
  CustomsEntry -> Province [color="#e0e0e0", style=solid, arrowhead=none, arrowtail=crow, dir=both, penwidth=0.7, constraint=false, weight=1]
  CustomsEntry -> SysConfig [color="#e0e0e0", style=solid, arrowhead=none, arrowtail=crow, dir=both, penwidth=0.7, constraint=false, weight=1]
  SurtaxLineItem -> CustomsEntry [color="#e0e0e0", style=solid, arrowhead=none, arrowtail=crow, dir=both, penwidth=0.7, constraint=false, weight=1]
  SurtaxLineItem -> HsCodeRate [color="#e0e0e0", style=solid, arrowhead=none, arrowtail=crow, dir=both, penwidth=0.7, constraint=false, weight=1]

  // ── trigger edge ──────────────────────────────────────────────
  TRIGGER -> SurtaxLineItem [color="#27ae60", style=bold, arrowhead=vee, penwidth=2, weight=10]

  // ── logic edges ────────────────────────────────────────────────────
  SysConfig:SysConfig_effective_date_w -> CustomsEntry:CustomsEntry_effective_date_w [label="1", color="#444444", fontcolor="#444444", arrowhead=vee, penwidth=1.8, weight=8]
  SysConfig:SysConfig_program_code_w -> CustomsEntry:CustomsEntry_program_code_w [label="2", color="#444444", fontcolor="#444444", arrowhead=vee, penwidth=1.8, weight=8]
  SysConfig:SysConfig_pc_number_w -> CustomsEntry:CustomsEntry_pc_number_w [label="3", color="#444444", fontcolor="#444444", arrowhead=vee, penwidth=1.8, weight=8]
  CountryOrigin:CountryOrigin_surtax_rate_w -> CustomsEntry:CustomsEntry_country_surtax_rate_w [label="4", color="#444444", fontcolor="#444444", arrowhead=vee, penwidth=1.8, weight=8]
  Province:Province_tax_rate_w -> CustomsEntry:CustomsEntry_province_tax_rate_w [label="5", color="#444444", fontcolor="#444444", arrowhead=vee, penwidth=1.8, weight=8]
  HsCodeRate:HsCodeRate_base_duty_rate_w -> SurtaxLineItem:SurtaxLineItem_base_duty_rate_w [label="6", color="#444444", fontcolor="#444444", arrowhead=vee, penwidth=1.8, weight=8]
  HsCodeRate:HsCodeRate_is_steel_derivative_w -> SurtaxLineItem:SurtaxLineItem_is_steel_derivative_w [label="7", color="#444444", fontcolor="#444444", arrowhead=vee, penwidth=1.8, weight=8]
  // INTRA:CustomsEntry:country_surtax_rate:surtax_applicable:8:0
  // INTRA:CustomsEntry:total_customs_value:duty_paid_value:9:1
  // INTRA:CustomsEntry:duty_paid_value:sales_tax_amount:10:2
  // INTRA:CustomsEntry:province_tax_rate:sales_tax_amount:10:3
  // INTRA:CustomsEntry:total_duty_amount:total_tax_due:11:4
  // INTRA:SurtaxLineItem:is_steel_derivative:surtax_applicable:12:0
  // INTRA:SurtaxLineItem:base_duty_rate:base_duty_amount:13:1
  // INTRA:SurtaxLineItem:surtax_applicable:surtax_amount:14:2
  // INTRA:SurtaxLineItem:customs_entry:surtax_amount:14:3
  SurtaxLineItem:SurtaxLineItem_customs_value_w -> CustomsEntry:CustomsEntry_total_customs_value_w [label="15", color="#444444", fontcolor="#444444", arrowhead=vee, penwidth=2, style=dashed, weight=8]
  SurtaxLineItem:SurtaxLineItem_base_duty_amount_w -> CustomsEntry:CustomsEntry_total_duty_amount_w [label="16", color="#444444", fontcolor="#444444", arrowhead=vee, penwidth=2, style=dashed, weight=8]
  SurtaxLineItem:SurtaxLineItem_surtax_amount_w -> CustomsEntry:CustomsEntry_total_surtax_amount_w [label="17", color="#444444", fontcolor="#444444", arrowhead=vee, penwidth=2, style=dashed, weight=8]
}