Skip to content

ERP Sync — Diagrams

Visual overview of how the Zwerfkei platform synchronises data with Microsoft Dynamics Navision / Business Central.

Current vs. target

The diagrams below reflect the current (legacy) integration in Zwerfkei Old. The target architecture will use the Business Central REST API instead of SOAP. See Legacy Integration for full documentation.


System overview

High-level view of the two sync directions and where they sit in the platform.

graph TD
    subgraph ZwerfkeiOld["Zwerfkei Old (CodeIgniter)"]
        App["Application"]
        DB[("MySQL\nk3_* tables")]
        Queue[("k3_synchronization\nOutbound queue")]
    end

    subgraph Cron["Cron jobs"]
        CronIn["k3retail_webservices\nevery minute"]
        CronOut["k3retail_sync\nevery 5 min"]
    end

    subgraph NAV["Microsoft Dynamics Navision 2018"]
        Buffer["Sync Buffer\n(GetSyncBuffer)"]
        SOAP_LS["LS Retail WSDL\nProducts · Prices · Stock · Discounts"]
        SOAP_Kei["Kei WSDL\nMembers · Transactions · Purchases"]
    end

    CronIn -->|"1. Poll buffer"| Buffer
    Buffer -->|"2. Changed record list"| CronIn
    CronIn -->|"3. Get full record"| SOAP_LS
    SOAP_LS -->|"4. Record data"| CronIn
    CronIn -->|"5. Upsert"| DB

    App -->|"Queue pending record"| Queue
    CronOut -->|"Read pending"| Queue
    CronOut -->|"SubmitOrder / SetMemberAccount / etc."| SOAP_LS
    CronOut -->|"Member operations"| SOAP_Kei
    SOAP_LS -->|"nav_id + confirmation"| CronOut
    CronOut -->|"Mark status = ok"| Queue

Inbound buffer flow

How Navision pushes changes to the website via the polling buffer.

sequenceDiagram
    participant OS as OS Cron (every min)
    participant PHP as k3retail_webservices
    participant NAV as Navision Sync Buffer
    participant GetOp as Navision Get* SOAP
    participant DB as MySQL (k3_* tables)

    OS->>PHP: Trigger (every minute)
    loop ~50 seconds inner loop
        PHP->>NAV: GetSyncBuffer
        NAV-->>PHP: [{TableNo, RecordId, ChangeType}, ...]
        loop For each changed record
            PHP->>GetOp: GetProduct / GetSalesPrice / GetItemAvailability / etc.
            GetOp-->>PHP: Full record data
            PHP->>DB: Upsert k3_* table
        end
        PHP->>PHP: Sleep 2 seconds
    end

Outbound queue flow

How website-initiated changes (orders, customers) are sent to Navision.

sequenceDiagram
    participant App as Application (PHP)
    participant Queue as k3_synchronization table
    participant Cron as k3retail_sync (every 5 min)
    participant Lock as DB Lock (k3_sync)
    participant NAV as Navision SOAP

    App->>Queue: INSERT (model, reference, action, status=pending)

    Note over Cron,Lock: Cron fires every 5 minutes
    Cron->>Lock: GET_LOCK('k3_sync', 1)
    Lock-->>Cron: Lock acquired

    loop For each pending record
        Cron->>NAV: SubmitOrder / SetMemberAccount / SubmitPeriodicDiscount
        alt Success
            NAV-->>Cron: nav_id + confirmation
            Cron->>Queue: UPDATE status=ok, nav_id=..., date_ok=now()
        else Failure (up to 10 retries)
            NAV-->>Cron: SOAP fault
            Cron->>Queue: UPDATE retry_count++
        end
    end

    Cron->>Lock: RELEASE_LOCK('k3_sync')

Data flow by entity

Which entities flow in which direction and how frequently.

graph LR
    subgraph NAV_In["NAV → Web (inbound)"]
        P["Products & Variants\ncontinuous"]
        PR["Prices & Discounts\ncontinuous"]
        ST["Stock / Availability\ncontinuous"]
        OS["Order Status\ncontinuous"]
        TX["POS Transactions\nhourly"]
        PO["Purchase Orders\nscheduled"]
        MP["Member Points\nscheduled"]
        LE["Value Entries\nnightly"]
    end

    subgraph NAV_Out["Web → NAV (outbound)"]
        OR["Orders\nqueue · 5 min"]
        CU["Customers\nqueue · 5 min"]
        PD["Periodic Discounts\nqueue · 5 min"]
        SC["Stock Corrections\nmanual"]
    end

    P --> DB[("Zwerfkei DB")]
    PR --> DB
    ST --> DB
    OS --> DB
    TX --> DB
    PO --> DB
    MP --> DB
    LE --> DB

    DB --> OR
    DB --> CU
    DB --> PD
    DB --> SC

Legacy Integration Sync Triggers & Cron Methods K3 Data Models Full Architecture Diagram