Skip to content

Instantly share code, notes, and snippets.

@brian56
Created October 22, 2025 03:04
Show Gist options
  • Select an option

  • Save brian56/b28636ac30b465613ea5edc925c43976 to your computer and use it in GitHub Desktop.

Select an option

Save brian56/b28636ac30b465613ea5edc925c43976 to your computer and use it in GitHub Desktop.
5. Tính ngược từ giá trị hợp đồng: xảy ra khi KH thay đổi HTTT sau khoảng thời gian quy định
graph TD
    subgraph "Điều chỉnh từ Giá trị HĐ (reverse)<br/>"
        direction TB

        %% === INPUT CONTEXTS ===
        subgraph Inputs["Context Inputs"]
            A1["grand_total<br/>Giá trị HĐ hiện tại (Grand Total)"]
            A2["discount_input<br/>Chiết khấu thêm"]
            A3["taxable_area<br/>DT tính thuế (m²)"]
            A4["land_unit_value<br/>Đơn giá đất/m²"]
            A5["tax_rate<br/>VAT (%)"]
            A6["maintenance_rate<br/>Tỷ lệ phí bảo trì (%)"]
        end

        %% === STEPS ===
        subgraph Steps["MathJS Computation Steps"]
            B1["land_value = taxable_area * land_unit_value"]
            B2["new_grand_total = grand_total - (discount_input ? discount_input : 0)"]
            B3["base_price_raw = ( new_grand_total + (tax_rate / 100) * land_value ) / ( 1 + (tax_rate / 100) + (maintenance_rate / 100) )"]
            B4["vat = (base_price_raw - land_value) * (tax_rate / 100)"]
            B5["maintenance_fee = base_price_raw * (maintenance_rate / 100)"]
            B6["grand_total_calc_raw = base_price_raw + vat + maintenance_fee"]
            B7["balancing_delta = new_grand_total - grand_total_calc_raw"]
            B8["base_price = base_price_raw + balancing_delta"]
            B9["grand_total = base_price + vat + maintenance_fee"]
        end

        %% === DEPENDENCIES ===
        A3 --> B1
        A4 --> B1

        A1 --> B2
        A2 --> B2

        B1 --> B3
        B2 --> B3
        A5 --> B3
        A6 --> B3

        B3 --> B4
        B1 --> B4
        A5 --> B4

        B3 --> B5
        A6 --> B5

        B3 --> B6
        B4 --> B6
        B5 --> B6

        B2 --> B7
        B6 --> B7

        B3 --> B8
        B7 --> B8

        B8 --> B9
        B4 --> B9
        B5 --> B9

        %% === OUTPUT ===
        subgraph Output["Final Result"]
            Z1["💰 grand_total<br/>Tổng giá trị HĐ (kết quả)"]
        end

        B9 --> Z1
    end
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment