Skip to content

Developer notes

app/addons/kv_vendor_commission_invoices/
addon.xml settings, e-mail template, document template, 3 tables, 2 privileges
init.php / func.php hooks, document type service, settings handlers, licence helpers
controllers/backend/kv_commission_invoices.php list, view, generate, billing, print, pdf, export,
issue/paid/void/credit/lines, vendor page, cron
controllers/backend/kv_vendor_commission_invoices_license.php "Check now" and licence cron
schemas/documents/types.post.php registers the document type kv_vci_invoice
schemas/documents/kv_vci_invoice.php template variables i (invoice), s (seller), b (bill to)
schemas/menu/*.post.php admin menu (Vendors) and vendor panel menu
schemas/permissions/*.post.php privileges, vendor modes, cron as trusted controller
Tygh/Addons/KvVendorCommissionInvoices/
Sources.php what core accounting recorded and what is still to invoice (reconciliation)
Documents.php generation, refresh, adjustments, totals, issue + numbering, paid, void, credit notes, list
Engine.php periodic run, pseudo-cron, run lock
Period.php weekly (ISO), monthly, quarterly periods and labels
Billing.php vendor billing details, tax treatment, bill-to snapshot
Config.php settings, seller snapshot
View.php escaped display data of a document (template variables, e-mail)
Output.php HTML (core document template), print page, PDF (core pdf_documents)
Document/Type.php, Document/Context.php, ServiceProvider.php core document type
Notifier.php e-mail on issue
Exporter.php CSV of documents and lines
Money.php primary currency, minor units, half-up rounding, tax
StorageData.php run marks (files instead of storage_data while the full page cache is on)
License/, Upgrade/ licence client, self-healing upgrades
design/backend/templates/addons/kv_vendor_commission_invoices/ views, components, settings info, licence UI
design/backend/css/addons/kv_vendor_commission_invoices/ styles.less, license.less
var/langs/en/addons/kv_vendor_commission_invoices.po

The add-on reads ?:vendor_payouts and never recalculates a commission.

Line type Source rows Amount
Commission (C) Every row with marketplace_profit <> 0 whose order is in a status with “calculate for payouts” (core getPayoutOrderStatuses(), hook get_order_payout_statuses included) or that has no order marketplace_profit (refund rows are negative)
Plan fee (F) payout_type = payout, plan_id > 0, order_id = 0, approval C or P, exclude_from_balance = N (what core deducts from the vendor balance) payout_amount
Adjustment (A) Entered by the administrator as entered

This is the rule core uses for the administrator’s income (vendor_plans vendor_payouts_get_income handler: SUM(marketplace_profit)), so the commission on the invoices always equals core accounting. Every add-on that writes marketplace_profit (vendor_categories_fee, kv_vendor_commission_rules, kv_vendor_coupons funding) is followed automatically. Collected vendor taxes (commission_amount - marketplace_profit with “collect taxes from vendors”) are not commission and are not invoiced.

Each transaction is invoiced once (reconciliation). For a vendor and a cut-off time, Sources::pending() compares, per core row, the amount core says now with the sum of the lines already carrying that source_payout_id in documents that are not void (drafts included, so two drafts never take the same row). Only the difference becomes a line. Rows that disappeared from core (deleted, or no longer a commission/fee row) are reversed. Rows outside the window (before Invoice transactions from) are never touched. A void document or a full credit note frees its rows, which the next document takes again.

Totals. Line amounts are core decimal(12,2) values summed in integer cents. Tax = taxable cents × rate (rate × 1000 as an integer) / 100000, rounded half away from zero to the decimals of the primary currency. Total = net + tax. Withheld = commission + plan fees + charged adjustments (+ tax when it is charged to the balance); due = total − withheld (manual settlement: withheld = 0). Documents store their currency code and decimals.

Core rows the add-on writes (only on issue, only with withheld settlement): a completed payout row per charged adjustment (positive = charge, negative = credit) and, with Deduct the tax from the vendor balance, one for the tax. plan_id stays 0, so they are never read back as plan fees. Void sets them to approval D (declined).

Documents::issue() takes GET_LOCK('<prefix>_seq'), reads MAX(seq_no) of the sequence key (I or C, plus the year when yearly), uses max(first number setting, max + 1), and moves the draft to issued with one conditional UPDATE ... WHERE status = 'D'. UNIQUE(seq_key, seq_no) guards the database. Drafts never hold numbers; issued documents are never deleted; void keeps the number.

  • Automatic run: GET_LOCK('<prefix>_run'); each completed period is processed once (kv_vci_done_until mark = <type>:<period key>).
  • One invoice per vendor and period: period_lock (company|period, UNIQUE, NULL after void) on documents created by generation, INSERT IGNORE.
  • Generation, refresh, credit notes and void run under GET_LOCK('<prefix>_gen'), so two of them never take the same core row.
Table Purpose
kv_vci_documents Documents: type (I/C), vendor, status (D/I/P/V), sequence key + number, period, period lock, credit-for link, currency, net, taxable, tax rate/amount/treatment/label/note, total, withheld, due, core tax row, seller and bill-to snapshots (JSON), notes, source (A/M), dates, payment reference, void reason
kv_vci_lines Lines: type (C/F/A), core source_payout_id, order, transaction date, description, order amount, rate, amount, taxable, charge to balance, core row written on issue
kv_vci_billing Billing details per vendor, tax treatment (‘’ = default) and rate (-1 = default)
Hook Use
before_dispatch Pseudo-cron in the admin and vendor panel (GET, not AJAX, at most every 30 min)
delete_company Removes the billing details (documents stay)
template_document_get_name Name of the document template in Design > Documents

Signatures are identical in 4.17.2 and 4.21.2. The document type uses the core document API (Tygh\Template\Document\*, service template.document.kv_vci_invoice.type), unchanged between 4.17 and 4.21. The default template is valid for Twig 2.14 and 3.11. CS-Cart renders document templates without auto-escaping, so View HTML-escapes every value.

php admin.php --dispatch=kv_commission_invoices.cron
php admin.php --dispatch=kv_vendor_commission_invoices_license.check

Multi-Vendor only (core_edition), depends on vendor_plans. No storefront templates and no storefront writes: the 4.21 full page cache is not affected. Vendor panel modes: vendor, print, pdf, billing, update_billing, always limited to runtime.company_id and never showing drafts.