p2p/migration_dev_to_studio.sql

406 lines
79 KiB
PL/PgSQL

-- ============================================================
-- P2P Invoice System — Full Migration: Dev → Studio
-- Org 20, App 20
-- Generated from dev DB (studio-v2-pg)
-- ============================================================
BEGIN;
-- 1. Users
INSERT INTO usersystem.tbl_users (id, name, email, password) VALUES (29100, 'Priya AI Finance (P2P Demo)', 'org20_priya.p2p@company.com', 'priya123') ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_users (id, name, email, password) VALUES (29101, 'Vendor Portal User', 'org20_vendor@abcsupplies.com', 'vendor123') ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_users (id, name, email, password) VALUES (29102, 'Rajesh Sharma (Warehouse)', 'org20_rajesh.warehouse@company.com', 'rajesh123') ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_users (id, name, email, password) VALUES (29103, 'Meera Patel (Procurement)', 'org20_meera.procurement@company.com', 'meera123') ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_users (id, name, email, password) VALUES (29104, 'Anita Desai (Accounts Payable)', 'org20_anita.ap@company.com', 'anita123') ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_users (id, name, email, password) VALUES (29105, 'Vikram Singh (Finance Manager)', 'org20_vikram.finance@company.com', 'vikram123') ON CONFLICT (id) DO NOTHING;
-- Org users
INSERT INTO usersystem.tbl_org_users (id, user_id, org_id) VALUES (20027, 29100, 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_org_users (id, user_id, org_id) VALUES (20028, 29101, 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_org_users (id, user_id, org_id) VALUES (20029, 29102, 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_org_users (id, user_id, org_id) VALUES (20030, 29103, 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_org_users (id, user_id, org_id) VALUES (20031, 29104, 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_org_users (id, user_id, org_id) VALUES (20032, 29105, 20) ON CONFLICT (id) DO NOTHING;
-- Roles
INSERT INTO usersystem.tbl_roles (id, name, org_id) VALUES (29100, 'p2p_ai_finance', 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_roles (id, name, org_id) VALUES (29101, 'p2p_vendor', 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_roles (id, name, org_id) VALUES (29102, 'p2p_warehouse', 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_roles (id, name, org_id) VALUES (29103, 'p2p_procurement', 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_roles (id, name, org_id) VALUES (29104, 'p2p_ap_team', 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_roles (id, name, org_id) VALUES (29105, 'p2p_finance_reviewer', 20) ON CONFLICT (id) DO NOTHING;
-- User roles
INSERT INTO usersystem.tbl_user_roles (user_id, role_id, org_id) VALUES (29100, 29100, 20) ON CONFLICT DO NOTHING;
INSERT INTO usersystem.tbl_user_roles (user_id, role_id, org_id) VALUES (29101, 29101, 20) ON CONFLICT DO NOTHING;
INSERT INTO usersystem.tbl_user_roles (user_id, role_id, org_id) VALUES (29102, 29102, 20) ON CONFLICT DO NOTHING;
INSERT INTO usersystem.tbl_user_roles (user_id, role_id, org_id) VALUES (29103, 29103, 20) ON CONFLICT DO NOTHING;
INSERT INTO usersystem.tbl_user_roles (user_id, role_id, org_id) VALUES (29104, 29104, 20) ON CONFLICT DO NOTHING;
INSERT INTO usersystem.tbl_user_roles (user_id, role_id, org_id) VALUES (29105, 29105, 20) ON CONFLICT DO NOTHING;
-- User groups
-- User app assignments
INSERT INTO usersystem.tbl_org_user_apps (id, org_user_id, app_id, org_id) VALUES (20129, 20027, 20, 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_org_user_apps (id, org_user_id, app_id, org_id) VALUES (20130, 20028, 20, 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_org_user_apps (id, org_user_id, app_id, org_id) VALUES (20131, 20029, 20, 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_org_user_apps (id, org_user_id, app_id, org_id) VALUES (20132, 20030, 20, 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_org_user_apps (id, org_user_id, app_id, org_id) VALUES (20133, 20031, 20, 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO usersystem.tbl_org_user_apps (id, org_user_id, app_id, org_id) VALUES (20134, 20032, 20, 20) ON CONFLICT (id) DO NOTHING;
-- 2. App
INSERT INTO tbl_apps (id, name, org_id, description) VALUES (20, 'P2P Invoice System', 20, 'AI-powered invoice validation with department clarification and finance approval') ON CONFLICT (id) DO NOTHING;
-- Workflow config
INSERT INTO tbl_appconfig_workflows (id, workflow_uid, version, app_id, content) VALUES (20109, 'wf_p2p_invoice_demo', '1', 20, '{"name": "P2P Invoice Validation", "states": [{"uid": "p2p-state-awaiting-clarification", "name": "Awaiting Clarification", "type": "STANDARD", "allowed_activities": ["p2p-act-provide-clarification"]}, {"uid": "p2p-state-invoice-submitted", "name": "Invoice Submitted", "type": "STANDARD", "allowed_activities": ["p2p-act-request-clarification", "p2p-act-submit-recommendation"]}, {"uid": "p2p-state-ai-analysis", "name": "AI Analysis", "type": "STANDARD", "allowed_activities": ["p2p-act-request-clarification", "p2p-act-submit-recommendation"]}, {"uid": "p2p-state-finance-review", "name": "Finance Review", "type": "STANDARD", "allowed_activities": ["p2p-act-approve-payment", "p2p-act-reject-payment", "p2p-act-hold-payment"]}, {"uid": "p2p-state-approved", "name": "Approved", "type": "END", "allowed_activities": []}, {"uid": "p2p-state-rejected", "name": "Rejected", "type": "END", "allowed_activities": []}, {"uid": "p2p-state-on-hold", "name": "On Hold", "type": "END", "allowed_activities": []}], "version": 1, "sg_rules": [], "activities": [{"uid": "p2p-act-submit-invoice", "name": "Submit Invoice", "type": "INIT", "ai_confidence_threshold": 0.5}, {"uid": "p2p-act-request-clarification", "name": "Request Clarification", "type": "NORMAL", "ai_confidence_threshold": 0.5}, {"uid": "p2p-act-submit-recommendation", "name": "Submit Recommendation", "type": "NORMAL", "ai_confidence_threshold": 0.5}, {"uid": "p2p-act-provide-clarification", "name": "Provide Clarification", "type": "NORMAL", "ai_confidence_threshold": 0.5}, {"uid": "p2p-act-approve-payment", "name": "Approve Payment", "type": "NORMAL", "ai_confidence_threshold": 0.5}, {"uid": "p2p-act-reject-payment", "name": "Reject Payment", "type": "NORMAL", "ai_confidence_threshold": 0.5}, {"uid": "p2p-act-hold-payment", "name": "Hold Payment", "type": "NORMAL", "ai_confidence_threshold": 0.5}], "stage_gates": [], "transitions": [{"to_state_id": "p2p-state-invoice-submitted", "from_state_id": "", "by_activity_id": "p2p-act-submit-invoice", "transition_type": "INIT_TO_STATE"}, {"to_state_id": "p2p-state-awaiting-clarification", "from_state_id": "p2p-state-invoice-submitted", "by_activity_id": "p2p-act-request-clarification", "transition_type": "TO_STATE"}, {"to_state_id": "p2p-state-finance-review", "from_state_id": "p2p-state-invoice-submitted", "by_activity_id": "p2p-act-submit-recommendation", "transition_type": "TO_STATE"}, {"to_state_id": "p2p-state-awaiting-clarification", "from_state_id": "p2p-state-ai-analysis", "by_activity_id": "p2p-act-request-clarification", "transition_type": "TO_STATE"}, {"to_state_id": "p2p-state-finance-review", "from_state_id": "p2p-state-ai-analysis", "by_activity_id": "p2p-act-submit-recommendation", "transition_type": "TO_STATE"}, {"to_state_id": "p2p-state-ai-analysis", "from_state_id": "p2p-state-awaiting-clarification", "by_activity_id": "p2p-act-provide-clarification", "transition_type": "TO_STATE"}, {"to_state_id": "p2p-state-approved", "from_state_id": "p2p-state-finance-review", "by_activity_id": "p2p-act-approve-payment", "transition_type": "TO_STATE"}, {"to_state_id": "p2p-state-rejected", "from_state_id": "p2p-state-finance-review", "by_activity_id": "p2p-act-reject-payment", "transition_type": "TO_STATE"}, {"to_state_id": "p2p-state-on-hold", "from_state_id": "p2p-state-finance-review", "by_activity_id": "p2p-act-hold-payment", "transition_type": "TO_STATE"}], "workflow_id": "wf_p2p_invoice_demo", "activity_prefills": [], "activity_triggers": [{"nodes": [{"id": "a0a0a0a0-0000-4000-8000-000000093011", "name": "Start", "type": "start", "edges": [{"target": "a0a0a0a0-0000-4000-8000-000000093012", "source_handle": "output"}], "config": {}, "ui_config": null}, {"id": "a0a0a0a0-0000-4000-8000-000000093012", "name": "AI Employee", "type": "aiEmployee", "edges": [{"target": "a0a0a0a0-0000-4000-8000-000000093013", "source_handle": "output"}], "config": {"ai_user_id": "29100"}, "ui_config": null}, {"id": "a0a0a0a0-0000-4000-8000-000000093013", "name": "Complete", "type": "response", "edges": [], "config": {"message": "AI Employee task dispatched", "success": true, "status_code": 200}, "ui_config": null}], "trigger_uid": "trigger_p2p_submit", "activity_uid": "p2p-act-submit-invoice", "trigger_config": {}}, {"nodes": [{"id": "a0a0a0a0-0000-4000-8000-000000093041", "name": "Start", "type": "start", "edges": [{"target": "a0a0a0a0-0000-4000-8000-000000093042", "source_handle": "output"}], "config": {}, "ui_config": null}, {"id": "a0a0a0a0-0000-4000-8000-000000093042", "name": "AI Employee", "type": "aiEmployee", "edges": [{"target": "a0a0a0a0-0000-4000-8000-000000093043", "source_handle": "output"}], "config": {"ai_user_id": "29100"}, "ui_config": null}, {"id": "a0a0a0a0-0000-4000-8000-000000093043", "name": "Complete", "type": "response", "edges": [], "config": {"message": "AI Employee task dispatched", "success": true, "status_code": 200}, "ui_config": null}], "trigger_uid": "trigger_p2p_clarify", "activity_uid": "p2p-act-provide-clarification", "trigger_config": {}}], "activity_data_fields": [{"data_fields": [{"id": "vendor_id", "uid": "p2p-field-9401", "name": "Vendor ID", "type": "local", "data_type": "text", "mandatory": true}, {"id": "vendor_name", "uid": "p2p-field-9402", "name": "Vendor Name", "type": "local", "data_type": "text", "mandatory": true}, {"id": "invoice_number", "uid": "p2p-field-9403", "name": "Invoice Number", "type": "local", "data_type": "text", "mandatory": true}, {"id": "invoice_date", "uid": "p2p-field-9404", "name": "Invoice Date", "type": "local", "data_type": "date", "mandatory": true}, {"id": "po_number", "uid": "p2p-field-9405", "name": "PO Number", "type": "local", "data_type": "text", "mandatory": true}, {"id": "currency", "uid": "p2p-field-9406", "name": "Currency", "type": "local", "data_type": "text", "mandatory": false}, {"id": "total_amount", "uid": "p2p-field-9407", "name": "Total Amount", "type": "local", "data_type": "number", "mandatory": true}, {"id": "tax_amount", "uid": "p2p-field-9408", "name": "Tax Amount", "type": "local", "data_type": "number", "mandatory": false}, {"id": "payment_terms", "uid": "p2p-field-9409", "name": "Payment Terms", "type": "local", "data_type": "text", "mandatory": false}, {"id": "notes", "uid": "p2p-field-9410", "name": "Notes", "type": "local", "data_type": "text", "mandatory": false}], "activity_uid": "p2p-act-submit-invoice", "activity_name": "Submit Invoice"}, {"data_fields": [{"id": "target_department", "uid": "p2p-field-9411", "name": "Target Department", "type": "local", "data_type": "text", "mandatory": true}, {"id": "clarification_question", "uid": "p2p-field-9412", "name": "Question", "type": "local", "data_type": "text", "mandatory": true}, {"id": "clarification_context", "uid": "p2p-field-9413", "name": "Context", "type": "local", "data_type": "text", "mandatory": false}, {"id": "analysis_so_far", "uid": "p2p-field-9414", "name": "Analysis So Far", "type": "local", "data_type": "text", "mandatory": false}], "activity_uid": "p2p-act-request-clarification", "activity_name": "Request Clarification"}, {"data_fields": [{"id": "response_text", "uid": "p2p-field-9415", "name": "Response", "type": "local", "data_type": "text", "mandatory": true}, {"id": "confirmed_quantity", "uid": "p2p-field-9416", "name": "Confirmed Quantity", "type": "local", "data_type": "number", "mandatory": false}, {"id": "response_notes", "uid": "p2p-field-9417", "name": "Additional Notes", "type": "local", "data_type": "text", "mandatory": false}], "activity_uid": "p2p-act-provide-clarification", "activity_name": "Provide Clarification"}, {"data_fields": [{"id": "recommendation", "uid": "p2p-field-9418", "name": "Recommendation", "type": "local", "data_type": "text", "mandatory": true}, {"id": "recommended_amount", "uid": "p2p-field-9419", "name": "Recommended Payment Amount", "type": "local", "data_type": "number", "mandatory": false}, {"id": "match_summary", "uid": "p2p-field-9420", "name": "Match Summary", "type": "local", "data_type": "text", "mandatory": false}, {"id": "ai_reasoning", "uid": "p2p-field-9421", "name": "AI Reasoning", "type": "local", "data_type": "text", "mandatory": false}, {"id": "ai_confidence", "uid": "p2p-field-9422", "name": "AI Confidence", "type": "local", "data_type": "number", "mandatory": false}], "activity_uid": "p2p-act-submit-recommendation", "activity_name": "Submit Recommendation"}, {"data_fields": [{"id": "approved_amount", "uid": "p2p-field-9423", "name": "Approved Amount", "type": "local", "data_type": "number", "mandatory": true}, {"id": "reviewer_notes", "uid": "p2p-field-9424", "name": "Reviewer Notes", "type": "local", "data_type": "text", "mandatory": false}], "activity_uid": "p2p-act-approve-payment", "activity_name": "Approve Payment"}, {"data_fields": [{"id": "rejection_reason", "uid": "p2p-field-9425", "name": "Rejection Reason", "type": "local", "data_type": "text", "mandatory": true}, {"id": "reviewer_notes", "uid": "p2p-field-9426", "name": "Reviewer Notes", "type": "local", "data_type": "text", "mandatory": false}], "activity_uid": "p2p-act-reject-payment", "activity_name": "Reject Payment"}, {"data_fields": [{"id": "hold_reason", "uid": "p2p-field-9427", "name": "Hold Reason", "type": "local", "data_type": "text", "mandatory": true}, {"id": "reviewer_notes", "uid": "p2p-field-9428", "name": "Reviewer Notes", "type": "local", "data_type": "text", "mandatory": false}], "activity_uid": "p2p-act-hold-payment", "activity_name": "Hold Payment"}], "activity_permissions": [], "workflow_data_fields": null}'::jsonb) ON CONFLICT (id) DO UPDATE SET content = EXCLUDED.content;
-- Record views
INSERT INTO tbl_appconfig_recordview (id, rv_uid, rv_description, workflow_uid, app_id, config) VALUES (20034, 'p2p-rv-all-invoices', 'All invoice instances across all states', 'wf_p2p_invoice_demo', 20, '{"fields": [{"type": "system-global", "data_type": "text", "field_key": "instance_id", "field_uid": "", "is_filter": false, "is_search": false, "activity_id": "SYSTEM", "output_label": "Instance ID"}, {"type": "system-global", "data_type": "text", "field_key": "current_state_name", "field_uid": "", "is_filter": true, "is_search": false, "activity_id": "SYSTEM", "output_label": "Current State"}, {"type": "local", "data_type": "text", "field_key": "vendor_name", "field_uid": "p2p-field-9401", "is_filter": true, "is_search": true, "activity_id": "p2p-act-submit-invoice", "output_label": "Vendor"}, {"type": "local", "data_type": "text", "field_key": "invoice_number", "field_uid": "p2p-field-9403", "is_filter": false, "is_search": true, "activity_id": "p2p-act-submit-invoice", "output_label": "Invoice #"}, {"type": "local", "data_type": "text", "field_key": "po_number", "field_uid": "p2p-field-9405", "is_filter": false, "is_search": true, "activity_id": "p2p-act-submit-invoice", "output_label": "PO #"}, {"type": "local", "data_type": "number", "field_key": "total_amount", "field_uid": "p2p-field-9407", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Amount"}, {"type": "system-global", "data_type": "datetime", "field_key": "created_at", "field_uid": "", "is_filter": false, "is_search": false, "activity_id": "SYSTEM", "output_label": "Created"}]}'::jsonb) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_recordview (id, rv_uid, rv_description, workflow_uid, app_id, config) VALUES (20035, 'p2p-rv-pending-clarifications', 'Invoices awaiting department clarification', 'wf_p2p_invoice_demo', 20, '{"fields": [{"type": "system-global", "data_type": "text", "field_key": "instance_id", "field_uid": "", "is_filter": false, "is_search": false, "activity_id": "SYSTEM", "output_label": "Instance ID"}, {"type": "local", "data_type": "text", "field_key": "vendor_name", "field_uid": "p2p-field-9402", "is_filter": false, "is_search": true, "activity_id": "p2p-act-submit-invoice", "output_label": "Vendor"}, {"type": "local", "data_type": "text", "field_key": "invoice_number", "field_uid": "p2p-field-9403", "is_filter": false, "is_search": true, "activity_id": "p2p-act-submit-invoice", "output_label": "Invoice #"}, {"type": "local", "data_type": "number", "field_key": "total_amount", "field_uid": "p2p-field-9407", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Amount"}, {"type": "local", "data_type": "text", "field_key": "target_department", "field_uid": "p2p-field-9411", "is_filter": true, "is_search": false, "activity_id": "p2p-act-request-clarification", "output_label": "Department"}, {"type": "system-global", "data_type": "datetime", "field_key": "created_at", "field_uid": "", "is_filter": false, "is_search": false, "activity_id": "SYSTEM", "output_label": "Created"}], "prefilters": {"logic": "AND", "conditions": [{"value": "Awaiting Clarification", "operator": "equals", "data_type": "text", "field_key": "current_state_name"}]}}'::jsonb) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_recordview (id, rv_uid, rv_description, workflow_uid, app_id, config) VALUES (20037, 'p2p-rv-vendor-invoices', 'Vendor''s submitted invoices with status tracking', 'wf_p2p_invoice_demo', 20, '{"fields": [{"type": "system-global", "data_type": "text", "field_key": "instance_id", "field_uid": "", "is_filter": false, "is_search": false, "activity_id": "SYSTEM", "output_label": "Instance ID"}, {"type": "system-global", "data_type": "text", "field_key": "current_state_name", "field_uid": "", "is_filter": true, "is_search": false, "activity_id": "SYSTEM", "output_label": "Status"}, {"type": "local", "data_type": "text", "field_key": "invoice_number", "field_uid": "p2p-field-9403", "is_filter": false, "is_search": true, "activity_id": "p2p-act-submit-invoice", "output_label": "Invoice #"}, {"type": "local", "data_type": "text", "field_key": "po_number", "field_uid": "p2p-field-9405", "is_filter": false, "is_search": true, "activity_id": "p2p-act-submit-invoice", "output_label": "PO #"}, {"type": "local", "data_type": "number", "field_key": "total_amount", "field_uid": "p2p-field-9407", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Amount"}, {"type": "system-global", "data_type": "datetime", "field_key": "created_at", "field_uid": "", "is_filter": false, "is_search": false, "activity_id": "SYSTEM", "output_label": "Submitted"}]}'::jsonb) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_recordview (id, rv_uid, rv_description, workflow_uid, app_id, config) VALUES (20036, 'p2p-rv-finance-review-queue', 'Invoices ready for finance review with AI recommendations', 'wf_p2p_invoice_demo', 20, '{"fields": [{"type": "local", "data_type": "number", "field_key": "recommended_amount", "field_uid": "p2p-field-9419", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-recommendation", "output_label": "Recommended Amt"}, {"type": "system-global", "data_type": "datetime", "field_key": "created_at", "field_uid": "", "is_filter": false, "is_search": false, "activity_id": "SYSTEM", "output_label": "Created"}, {"type": "system-global", "data_type": "text", "field_key": "instance_id", "field_uid": "", "is_filter": false, "is_search": false, "activity_id": "SYSTEM", "output_label": "Instance ID"}, {"type": "local", "data_type": "text", "field_key": "vendor_name", "field_uid": "p2p-field-9402", "is_filter": false, "is_search": true, "activity_id": "p2p-act-submit-invoice", "output_label": "Vendor"}, {"type": "local", "data_type": "text", "field_key": "invoice_number", "field_uid": "p2p-field-9403", "is_filter": false, "is_search": true, "activity_id": "p2p-act-submit-invoice", "output_label": "Invoice #"}, {"type": "local", "data_type": "number", "field_key": "total_amount", "field_uid": "p2p-field-9407", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Amount"}, {"type": "local", "data_type": "text", "field_key": "recommendation", "field_uid": "p2p-field-9418", "is_filter": true, "is_search": false, "activity_id": "p2p-act-submit-recommendation", "output_label": "AI Recommendation"}], "prefilters": {"logic": "AND", "conditions": [{"value": "Finance Review", "operator": "equals", "data_type": "text", "field_key": "current_state_name"}]}}'::jsonb) ON CONFLICT (id) DO NOTHING;
-- Detail views
INSERT INTO tbl_appconfig_detailview (id, dv_uid, dv_description, workflow_uid, app_id, config) VALUES (20014, 'p2p-dv-clarification-detail', 'AI question and context for department response', 'wf_p2p_invoice_demo', 20, '{"fields": [{"type": "system-global", "data_type": "text", "field_key": "instance_id", "field_uid": "", "is_filter": false, "is_search": false, "activity_id": "SYSTEM", "output_label": "Instance ID"}, {"type": "local", "data_type": "text", "field_key": "vendor_name", "field_uid": "p2p-field-9402", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Vendor"}, {"type": "local", "data_type": "text", "field_key": "invoice_number", "field_uid": "p2p-field-9403", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Invoice #"}, {"type": "local", "data_type": "text", "field_key": "po_number", "field_uid": "p2p-field-9405", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "PO #"}, {"type": "local", "data_type": "number", "field_key": "total_amount", "field_uid": "p2p-field-9407", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Amount"}, {"type": "local", "data_type": "text", "field_key": "target_department", "field_uid": "p2p-field-9411", "is_filter": false, "is_search": false, "activity_id": "p2p-act-request-clarification", "output_label": "Target Department"}, {"type": "local", "data_type": "text", "field_key": "clarification_question", "field_uid": "p2p-field-9412", "is_filter": false, "is_search": false, "activity_id": "p2p-act-request-clarification", "output_label": "AI Question"}, {"type": "local", "data_type": "text", "field_key": "clarification_context", "field_uid": "p2p-field-9413", "is_filter": false, "is_search": false, "activity_id": "p2p-act-request-clarification", "output_label": "Context"}, {"type": "local", "data_type": "text", "field_key": "analysis_so_far", "field_uid": "p2p-field-9414", "is_filter": false, "is_search": false, "activity_id": "p2p-act-request-clarification", "output_label": "Analysis So Far"}]}'::jsonb) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_detailview (id, dv_uid, dv_description, workflow_uid, app_id, config) VALUES (20015, 'p2p-dv-finance-review-detail', 'AI recommendation with full decision trail for finance reviewer', 'wf_p2p_invoice_demo', 20, '{"fields": [{"type": "system-global", "data_type": "text", "field_key": "instance_id", "field_uid": "", "is_filter": false, "is_search": false, "activity_id": "SYSTEM", "output_label": "Instance ID"}, {"type": "system-global", "data_type": "text", "field_key": "current_state_name", "field_uid": "", "is_filter": false, "is_search": false, "activity_id": "SYSTEM", "output_label": "Status"}, {"type": "local", "data_type": "text", "field_key": "vendor_name", "field_uid": "p2p-field-9402", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Vendor"}, {"type": "local", "data_type": "text", "field_key": "invoice_number", "field_uid": "p2p-field-9403", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Invoice #"}, {"type": "local", "data_type": "text", "field_key": "po_number", "field_uid": "p2p-field-9405", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "PO #"}, {"type": "local", "data_type": "number", "field_key": "total_amount", "field_uid": "p2p-field-9407", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Invoice Amount"}, {"type": "local", "data_type": "number", "field_key": "tax_amount", "field_uid": "p2p-field-9408", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Tax"}, {"type": "local", "data_type": "text", "field_key": "recommendation", "field_uid": "p2p-field-9418", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-recommendation", "output_label": "AI Recommendation"}, {"type": "local", "data_type": "number", "field_key": "recommended_amount", "field_uid": "p2p-field-9419", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-recommendation", "output_label": "Recommended Amount"}, {"type": "local", "data_type": "text", "field_key": "match_summary", "field_uid": "p2p-field-9420", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-recommendation", "output_label": "Match Summary"}, {"type": "local", "data_type": "text", "field_key": "ai_reasoning", "field_uid": "p2p-field-9421", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-recommendation", "output_label": "AI Reasoning"}, {"type": "local", "data_type": "number", "field_key": "ai_confidence", "field_uid": "p2p-field-9422", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-recommendation", "output_label": "AI Confidence"}]}'::jsonb) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_detailview (id, dv_uid, dv_description, workflow_uid, app_id, config) VALUES (20013, 'p2p-dv-invoice-detail', 'Full invoice detail with AI analysis trail', 'wf_p2p_invoice_demo', 20, '{"fields": [{"type": "system-global", "data_type": "text", "field_key": "instance_id", "field_uid": "", "is_filter": false, "is_search": false, "activity_id": "SYSTEM", "output_label": "Instance ID"}, {"type": "system-global", "data_type": "text", "field_key": "current_state_name", "field_uid": "", "is_filter": false, "is_search": false, "activity_id": "SYSTEM", "output_label": "Status"}, {"type": "system-global", "data_type": "datetime", "field_key": "created_at", "field_uid": "", "is_filter": false, "is_search": false, "activity_id": "SYSTEM", "output_label": "Created"}, {"type": "local", "data_type": "text", "field_key": "vendor_id", "field_uid": "p2p-field-9401", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Vendor ID"}, {"type": "local", "data_type": "text", "field_key": "vendor_name", "field_uid": "p2p-field-9402", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Vendor Name"}, {"type": "local", "data_type": "text", "field_key": "invoice_number", "field_uid": "p2p-field-9403", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Invoice Number"}, {"type": "local", "data_type": "date", "field_key": "invoice_date", "field_uid": "p2p-field-9404", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Invoice Date"}, {"type": "local", "data_type": "text", "field_key": "po_number", "field_uid": "p2p-field-9405", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "PO Number"}, {"type": "local", "data_type": "number", "field_key": "total_amount", "field_uid": "p2p-field-9407", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Total Amount"}, {"type": "local", "data_type": "number", "field_key": "tax_amount", "field_uid": "p2p-field-9408", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Tax Amount"}, {"type": "local", "data_type": "text", "field_key": "payment_terms", "field_uid": "p2p-field-9409", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Payment Terms"}, {"type": "local", "data_type": "text", "field_key": "notes", "field_uid": "p2p-field-9410", "is_filter": false, "is_search": false, "activity_id": "p2p-act-submit-invoice", "output_label": "Vendor Notes"}]}'::jsonb) ON CONFLICT (id) DO NOTHING;
-- Screens
INSERT INTO tbl_appconfig_screens (id, source_screen_id, app_id, screen_name, device, description, layout, permissions) VALUES (20010, 29631, 20, 'P2P - My Invoices', 'desktop', 'P2P - My Invoices', '[{"type": "element", "style": {"marginBottom": "16px"}, "config": {"icon": "add", "name": "+ Submit New Invoice", "type": "button", "params": {"workflow_id": "wf_p2p_invoice_demo", "activity_id_init": "p2p-act-submit-invoice"}, "action_end": [{"type": "refresh_page"}], "job_template": "start_state_machine"}, "classes": ["z-btn-primary"]}, {"type": "element", "style": {"width": "100%"}, "config": {"type": "recordsview", "view_id": "29601"}}]'::jsonb, NULL) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_screens (id, source_screen_id, app_id, screen_name, device, description, layout, permissions) VALUES (20011, 29632, 20, 'P2P - Pending Clarifications', 'desktop', 'P2P - Pending Clarifications', '[{"type": "element", "style": {"width": "100%"}, "config": {"type": "recordsview", "view_id": "29602"}}]'::jsonb, NULL) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_screens (id, source_screen_id, app_id, screen_name, device, description, layout, permissions) VALUES (20013, 29634, 20, 'P2P - All Invoices', 'desktop', 'P2P - All Invoices', '[{"type": "element", "style": {"width": "100%"}, "config": {"type": "recordsview", "view_id": "29604"}}]'::jsonb, NULL) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_screens (id, source_screen_id, app_id, screen_name, device, description, layout, permissions) VALUES (20025, 29641, 20, 'P2P - Invoice Detail', 'desktop', 'P2P - Invoice Detail', '[{"type": "element", "style": {"width": "100%", "padding": "16px"}, "config": {"type": "detailsview", "view_id": "29611"}}]'::jsonb, NULL) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_screens (id, source_screen_id, app_id, screen_name, device, description, layout, permissions) VALUES (20026, 29642, 20, 'P2P - Clarification Detail', 'desktop', 'P2P - Clarification Detail', '[{"type": "element", "style": {"width": "100%", "padding": "16px"}, "config": {"type": "detailsview", "view_id": "29612"}}]'::jsonb, NULL) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_screens (id, source_screen_id, app_id, screen_name, device, description, layout, permissions) VALUES (20027, 29643, 20, 'P2P - Finance Review Detail', 'desktop', 'P2P - Finance Review Detail', '[{"type": "element", "style": {"width": "100%", "padding": "16px"}, "config": {"type": "detailsview", "view_id": "29613"}}]'::jsonb, NULL) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_screens (id, source_screen_id, app_id, screen_name, device, description, layout, permissions) VALUES (20012, 29633, 20, 'P2P - Finance Review', 'desktop', 'P2P - Finance Review', '[{"type": "element", "style": {"width": "100%"}, "config": {"type": "recordsview", "view_id": "29603"}}]'::jsonb, NULL) ON CONFLICT (id) DO NOTHING;
-- RV Screens
INSERT INTO tbl_appconfig_rv_screens (id, source_screen_id, app_id, screen_name, device, description, layout, rv_template_id) VALUES (20001, 29601, 20, 'Vendor - My Invoices', 'desktop', 'Vendor - My Invoices', '[{"type": "element", "style": {}, "config": {"type": "rv_table", "columns": [{"id": "current_state_name", "display": "Status", "key_name": "current_state_name", "data_type": "text"}, {"id": "invoice_number", "display": "Invoice #", "key_name": "invoice_number", "data_type": "text"}, {"id": "po_number", "display": "PO #", "key_name": "po_number", "data_type": "text"}, {"id": "total_amount", "display": "Amount", "key_name": "total_amount", "data_type": "number"}, {"id": "created_at", "display": "Submitted", "key_name": "created_at", "data_type": "datetime"}], "view_id": "29601", "on_row_click": {"screen_id": "29641", "job_template": "navigate_to_screen"}}}]'::jsonb, 29504) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_rv_screens (id, source_screen_id, app_id, screen_name, device, description, layout, rv_template_id) VALUES (20003, 29603, 20, 'Finance - Review Queue', 'desktop', 'Finance - Review Queue', '[{"type": "element", "style": {}, "config": {"type": "rv_table", "columns": [{"id": "vendor_name", "display": "Vendor", "key_name": "vendor_name", "data_type": "text"}, {"id": "invoice_number", "display": "Invoice #", "key_name": "invoice_number", "data_type": "text"}, {"id": "total_amount", "display": "Amount", "key_name": "total_amount", "data_type": "number"}, {"id": "recommendation", "display": "AI Recommendation", "key_name": "recommendation", "data_type": "text"}, {"id": "recommended_amount", "display": "Recommended Amt", "key_name": "recommended_amount", "data_type": "number"}, {"id": "created_at", "display": "Created", "key_name": "created_at", "data_type": "datetime"}], "view_id": "29603", "on_row_click": {"screen_id": "29643", "job_template": "navigate_to_screen"}}}]'::jsonb, 29503) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_rv_screens (id, source_screen_id, app_id, screen_name, device, description, layout, rv_template_id) VALUES (20004, 29604, 20, 'Admin - All Invoices', 'desktop', 'Admin - All Invoices', '[{"type": "element", "style": {}, "config": {"type": "rv_table", "columns": [{"id": "current_state_name", "display": "Status", "key_name": "current_state_name", "data_type": "text"}, {"id": "vendor_name", "display": "Vendor", "key_name": "vendor_name", "data_type": "text"}, {"id": "invoice_number", "display": "Invoice #", "key_name": "invoice_number", "data_type": "text"}, {"id": "po_number", "display": "PO #", "key_name": "po_number", "data_type": "text"}, {"id": "total_amount", "display": "Amount", "key_name": "total_amount", "data_type": "number"}, {"id": "created_at", "display": "Created", "key_name": "created_at", "data_type": "datetime"}], "view_id": "29604", "on_row_click": {"screen_id": "29641", "job_template": "navigate_to_screen"}}}]'::jsonb, 29501) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_rv_screens (id, source_screen_id, app_id, screen_name, device, description, layout, rv_template_id) VALUES (20002, 29602, 20, 'Department - Pending Clarifications', 'desktop', 'Department - Pending Clarifications', '[{"type": "element", "style": {}, "config": {"type": "rv_table", "columns": [{"id": "vendor_name", "display": "Vendor", "key_name": "vendor_name", "data_type": "text"}, {"id": "invoice_number", "display": "Invoice #", "key_name": "invoice_number", "data_type": "text"}, {"id": "total_amount", "display": "Amount", "key_name": "total_amount", "data_type": "number"}, {"id": "target_department", "display": "Department", "key_name": "target_department", "data_type": "text"}, {"id": "created_at", "display": "Created", "key_name": "created_at", "data_type": "datetime"}], "view_id": "29602", "on_row_click": {"screen_id": "29642", "job_template": "navigate_to_screen"}}}]'::jsonb, 29502) ON CONFLICT (id) DO NOTHING;
-- DV Screens
INSERT INTO tbl_appconfig_dv_screens (id, source_screen_id, app_id, screen_name, device, description, layout, dv_template_id) VALUES (20005, 29612, 20, 'Clarification Detail View', 'desktop', 'Clarification Detail View', '[{"type": "element", "style": {"fontSize": "16px", "marginTop": "20px", "fontWeight": "700", "borderBottom": "1px solid #e2e8f0", "marginBottom": "8px", "paddingBottom": "6px"}, "config": {"name": "Invoice Summary", "type": "label"}, "classes": []}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Vendor", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Vendor", "keyName": "vendor_name"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Invoice Number", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Invoice #", "keyName": "invoice_number"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "PO Number", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "PO #", "keyName": "po_number"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Amount", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Amount", "keyName": "total_amount"}}}, {"type": "element", "style": {"fontSize": "16px", "marginTop": "20px", "fontWeight": "700", "borderBottom": "1px solid #e2e8f0", "marginBottom": "8px", "paddingBottom": "6px"}, "config": {"name": "AI Clarification Request", "type": "label"}, "classes": []}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Target Department", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Department", "keyName": "target_department"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Question from AI", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Question", "keyName": "clarification_question"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Context", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Context", "keyName": "clarification_context"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Analysis So Far", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Analysis", "keyName": "analysis_so_far"}}}, {"type": "element", "style": {"marginTop": "20px"}, "config": {"icon": "reply", "name": "Respond to Clarification", "type": "button", "params": {"activity_id": "p2p-act-provide-clarification", "workflow_id": "wf_p2p_invoice_demo"}, "action_end": [{"type": "refresh_page"}], "job_template": "perform_activity"}, "classes": ["z-btn-primary"]}]'::jsonb, 29512) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_dv_screens (id, source_screen_id, app_id, screen_name, device, description, layout, dv_template_id) VALUES (20004, 29611, 20, 'Invoice Detail View', 'desktop', 'Invoice Detail View', '[{"type": "element", "style": {"fontSize": "16px", "marginTop": "20px", "fontWeight": "700", "borderBottom": "1px solid #e2e8f0", "marginBottom": "8px", "paddingBottom": "6px"}, "config": {"name": "Invoice Details", "type": "label"}, "classes": []}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Status", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Status", "keyName": "current_state_name"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Vendor", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Vendor", "keyName": "vendor_name"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Invoice Number", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Invoice #", "keyName": "invoice_number"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Invoice Date", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Date", "keyName": "invoice_date"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "PO Number", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "PO #", "keyName": "po_number"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Total Amount", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Amount", "keyName": "total_amount"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Tax Amount", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Tax", "keyName": "tax_amount"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Payment Terms", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Terms", "keyName": "payment_terms"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Vendor Notes", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Notes", "keyName": "notes"}}}]'::jsonb, 29511) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_dv_screens (id, source_screen_id, app_id, screen_name, device, description, layout, dv_template_id) VALUES (20006, 29613, 20, 'Finance Review Detail View', 'desktop', 'Finance Review Detail View', '[{"type": "element", "style": {"fontSize": "16px", "marginTop": "20px", "fontWeight": "700", "borderBottom": "1px solid #e2e8f0", "marginBottom": "8px", "paddingBottom": "6px"}, "config": {"name": "Invoice Details", "type": "label"}, "classes": []}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Status", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Status", "keyName": "current_state_name"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Vendor", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Vendor", "keyName": "vendor_name"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Invoice Number", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Invoice #", "keyName": "invoice_number"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "PO Number", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "PO #", "keyName": "po_number"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Invoice Amount", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Amount", "keyName": "total_amount"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Tax", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Tax", "keyName": "tax_amount"}}}, {"type": "element", "style": {"fontSize": "16px", "marginTop": "20px", "fontWeight": "700", "borderBottom": "1px solid #e2e8f0", "marginBottom": "8px", "paddingBottom": "6px"}, "config": {"name": "AI Recommendation", "type": "label"}, "classes": []}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Recommendation", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Recommendation", "keyName": "recommendation"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Recommended Amount", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Amount", "keyName": "recommended_amount"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "Match Summary", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Match Summary", "keyName": "match_summary"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "AI Reasoning", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Reasoning", "keyName": "ai_reasoning"}}}, {"type": "element", "style": {"color": "#64748b", "fontSize": "13px", "marginTop": "12px", "fontWeight": "600"}, "config": {"name": "AI Confidence", "type": "label"}, "classes": []}, {"type": "element", "style": {"marginBottom": "4px"}, "config": {"type": "field", "field": {"label": "Confidence", "keyName": "ai_confidence"}}}, {"type": "element", "style": {"display": "inline-block", "marginTop": "20px", "marginRight": "8px"}, "config": {"icon": "check_circle", "name": "Approve Payment", "type": "button", "params": {"activity_id": "p2p-act-approve-payment", "workflow_id": "wf_p2p_invoice_demo"}, "action_end": [{"type": "refresh_page"}], "job_template": "perform_activity"}, "classes": ["z-btn-primary"]}, {"type": "element", "style": {"display": "inline-block", "marginTop": "20px", "marginRight": "8px"}, "config": {"icon": "cancel", "name": "Reject Payment", "type": "button", "params": {"activity_id": "p2p-act-reject-payment", "workflow_id": "wf_p2p_invoice_demo"}, "action_end": [{"type": "refresh_page"}], "job_template": "perform_activity"}, "classes": ["z-btn-outline"]}, {"type": "element", "style": {"display": "inline-block", "marginTop": "20px"}, "config": {"icon": "pause_circle", "name": "Hold Payment", "type": "button", "params": {"activity_id": "p2p-act-hold-payment", "workflow_id": "wf_p2p_invoice_demo"}, "action_end": [{"type": "refresh_page"}], "job_template": "perform_activity"}, "classes": ["z-btn-outline"]}]'::jsonb, 29513) ON CONFLICT (id) DO NOTHING;
-- Form Screens
INSERT INTO tbl_appconfig_form_screens (id, source_form_id, activity_uid, device_type, layout, grid_config, app_id) VALUES (20136, 20094, 'p2p-act-submit-invoice', 'desktop', '[]'::jsonb, '[{"h": 1, "i": "p2p-field-9401", "w": 6, "x": 0, "y": 0}, {"h": 1, "i": "p2p-field-9402", "w": 6, "x": 6, "y": 0}, {"h": 1, "i": "p2p-field-9403", "w": 6, "x": 0, "y": 1}, {"h": 1, "i": "p2p-field-9404", "w": 6, "x": 6, "y": 1}, {"h": 1, "i": "p2p-field-9405", "w": 6, "x": 0, "y": 2}, {"h": 1, "i": "p2p-field-9406", "w": 6, "x": 6, "y": 2}, {"h": 1, "i": "p2p-field-9407", "w": 6, "x": 0, "y": 3}, {"h": 1, "i": "p2p-field-9408", "w": 6, "x": 6, "y": 3}, {"h": 1, "i": "p2p-field-9409", "w": 6, "x": 0, "y": 4}, {"h": 1, "i": "p2p-field-9410", "w": 6, "x": 6, "y": 4}]'::jsonb, 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_form_screens (id, source_form_id, activity_uid, device_type, layout, grid_config, app_id) VALUES (20137, 20095, 'p2p-act-provide-clarification', 'desktop', '[]'::jsonb, '[{"h": 1, "i": "p2p-field-9415", "w": 12, "x": 0, "y": 0}, {"h": 1, "i": "p2p-field-9416", "w": 12, "x": 0, "y": 1}, {"h": 1, "i": "p2p-field-9417", "w": 12, "x": 0, "y": 2}]'::jsonb, 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_form_screens (id, source_form_id, activity_uid, device_type, layout, grid_config, app_id) VALUES (20138, 20096, 'p2p-act-approve-payment', 'desktop', '[]'::jsonb, '[{"h": 1, "i": "p2p-field-9423", "w": 6, "x": 0, "y": 0}, {"h": 1, "i": "p2p-field-9424", "w": 6, "x": 6, "y": 0}]'::jsonb, 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_form_screens (id, source_form_id, activity_uid, device_type, layout, grid_config, app_id) VALUES (20139, 20097, 'p2p-act-reject-payment', 'desktop', '[]'::jsonb, '[{"h": 1, "i": "p2p-field-9425", "w": 12, "x": 0, "y": 0}, {"h": 1, "i": "p2p-field-9426", "w": 12, "x": 0, "y": 1}]'::jsonb, 20) ON CONFLICT (id) DO NOTHING;
INSERT INTO tbl_appconfig_form_screens (id, source_form_id, activity_uid, device_type, layout, grid_config, app_id) VALUES (20140, 20098, 'p2p-act-hold-payment', 'desktop', '[]'::jsonb, '[{"h": 1, "i": "p2p-field-9427", "w": 12, "x": 0, "y": 0}, {"h": 1, "i": "p2p-field-9428", "w": 12, "x": 0, "y": 1}]'::jsonb, 20) ON CONFLICT (id) DO NOTHING;
-- Header Config
INSERT INTO tbl_appconfig_header_config (id, app_id, device_type, config) VALUES (20001, 20, 'desktop', '{"slots": {"left": ["logo", "nav"], "right": ["profile"], "center": []}, "layout": {"type": "classic", "height": "56px", "position": "sticky", "full_width": true}, "components": {"nav": {"items": [{"id": "nav_vendor", "icon": "receipt_long", "type": "screen", "label": "My Invoices", "screen_id": 29631}, {"id": "nav_clarifications", "icon": "help_outline", "type": "screen", "label": "Pending Clarifications", "screen_id": 29632}, {"id": "nav_finance", "icon": "account_balance", "type": "screen", "label": "Finance Review", "screen_id": 29633}, {"id": "nav_all", "icon": "list_alt", "type": "screen", "label": "All Invoices", "screen_id": 29634}]}, "logo": {"text": "P2P Invoice System", "display_type": "text"}, "profile": {"shape": "circle", "show_name": true}}}'::jsonb) ON CONFLICT (id) DO NOTHING;
-- 3. Workflow design
INSERT INTO workflow.tbl_workflows (id, uid, app_id, name, description) VALUES (29100, 'wf_p2p_invoice_demo', 20, 'P2P Invoice Validation', 'AI-powered invoice validation with department clarification and finance approval') ON CONFLICT (id) DO NOTHING;
-- Workflow versions
-- States
INSERT INTO workflow.tbl_wf_states (id, uid, version_id, name, description, type) VALUES (29203, 'p2p-state-awaiting-clarification', 29100, 'Awaiting Clarification', '', 'STANDARD') ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_states (id, uid, version_id, name, description, type) VALUES (20057, 'p2p-state-invoice-submitted', 29100, 'Invoice Submitted', '', 'STANDARD') ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_states (id, uid, version_id, name, description, type) VALUES (20058, 'p2p-state-ai-analysis', 29100, 'AI Analysis', '', 'STANDARD') ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_states (id, uid, version_id, name, description, type) VALUES (20059, 'p2p-state-finance-review', 29100, 'Finance Review', '', 'STANDARD') ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_states (id, uid, version_id, name, description, type) VALUES (20060, 'p2p-state-approved', 29100, 'Approved', '', 'END') ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_states (id, uid, version_id, name, description, type) VALUES (20061, 'p2p-state-rejected', 29100, 'Rejected', '', 'END') ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_states (id, uid, version_id, name, description, type) VALUES (20062, 'p2p-state-on-hold', 29100, 'On Hold', '', 'END') ON CONFLICT (id) DO NOTHING;
-- Activities
INSERT INTO workflow.tbl_wf_activities (id, activity_uid, workflow_version_id, name, type) VALUES (20070, 'p2p-act-submit-invoice', 29100, 'Submit Invoice', 'INIT') ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_activities (id, activity_uid, workflow_version_id, name, type) VALUES (20071, 'p2p-act-request-clarification', 29100, 'Request Clarification', 'NORMAL') ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_activities (id, activity_uid, workflow_version_id, name, type) VALUES (20072, 'p2p-act-submit-recommendation', 29100, 'Submit Recommendation', 'NORMAL') ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_activities (id, activity_uid, workflow_version_id, name, type) VALUES (20073, 'p2p-act-provide-clarification', 29100, 'Provide Clarification', 'NORMAL') ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_activities (id, activity_uid, workflow_version_id, name, type) VALUES (20074, 'p2p-act-approve-payment', 29100, 'Approve Payment', 'NORMAL') ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_activities (id, activity_uid, workflow_version_id, name, type) VALUES (20075, 'p2p-act-reject-payment', 29100, 'Reject Payment', 'NORMAL') ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_activities (id, activity_uid, workflow_version_id, name, type) VALUES (20076, 'p2p-act-hold-payment', 29100, 'Hold Payment', 'NORMAL') ON CONFLICT (id) DO NOTHING;
-- Activity fields
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9401', 'vendor_id', 20070, 'Vendor ID', 'local', 'text', true) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9402', 'vendor_name', 20070, 'Vendor Name', 'local', 'text', true) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9403', 'invoice_number', 20070, 'Invoice Number', 'local', 'text', true) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9404', 'invoice_date', 20070, 'Invoice Date', 'local', 'date', true) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9405', 'po_number', 20070, 'PO Number', 'local', 'text', true) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9406', 'currency', 20070, 'Currency', 'local', 'text', false) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9407', 'total_amount', 20070, 'Total Amount', 'local', 'number', true) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9408', 'tax_amount', 20070, 'Tax Amount', 'local', 'number', false) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9409', 'payment_terms', 20070, 'Payment Terms', 'local', 'text', false) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9410', 'notes', 20070, 'Notes', 'local', 'text', false) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9411', 'target_department', 20071, 'Target Department', 'local', 'text', true) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9412', 'clarification_question', 20071, 'Question', 'local', 'text', true) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9413', 'clarification_context', 20071, 'Context', 'local', 'text', false) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9414', 'analysis_so_far', 20071, 'Analysis So Far', 'local', 'text', false) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9415', 'response_text', 20073, 'Response', 'local', 'text', true) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9416', 'confirmed_quantity', 20073, 'Confirmed Quantity', 'local', 'number', false) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9417', 'response_notes', 20073, 'Additional Notes', 'local', 'text', false) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9418', 'recommendation', 20072, 'Recommendation', 'local', 'text', true) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9419', 'recommended_amount', 20072, 'Recommended Payment Amount', 'local', 'number', false) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9420', 'match_summary', 20072, 'Match Summary', 'local', 'text', false) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9421', 'ai_reasoning', 20072, 'AI Reasoning', 'local', 'text', false) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9422', 'ai_confidence', 20072, 'AI Confidence', 'local', 'number', false) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9423', 'approved_amount', 20074, 'Approved Amount', 'local', 'number', true) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9424', 'reviewer_notes', 20074, 'Reviewer Notes', 'local', 'text', false) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9425', 'rejection_reason', 20075, 'Rejection Reason', 'local', 'text', true) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9426', 'reviewer_notes', 20075, 'Reviewer Notes', 'local', 'text', false) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9427', 'hold_reason', 20076, 'Hold Reason', 'local', 'text', true) ON CONFLICT DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_fields (uid, field_s_id, activity_id, name, field_type, data_type, is_mandatory) VALUES ('p2p-field-9428', 'reviewer_notes', 20076, 'Reviewer Notes', 'local', 'text', false) ON CONFLICT DO NOTHING;
-- Activity triggers
INSERT INTO workflow.tbl_wf_activity_triggers (id, activity_id, trigger_uid, trigger_config) VALUES (67, 20070, 'trigger_p2p_submit', '{}'::jsonb) ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_triggers (id, activity_id, trigger_uid, trigger_config) VALUES (68, 20073, 'trigger_p2p_clarify', '{}'::jsonb) ON CONFLICT (id) DO NOTHING;
-- Activity trigger nodes
INSERT INTO workflow.tbl_wf_activity_trigger_nodes (id, trigger_id, name, type, config, edges, ui_config) VALUES ('a0a0a0a0-0000-4000-8000-000000093011', 67, 'Start', 'start', '{}'::jsonb, '[{"target": "a0a0a0a0-0000-4000-8000-000000093012", "source_handle": "output"}]'::jsonb, NULL) ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_trigger_nodes (id, trigger_id, name, type, config, edges, ui_config) VALUES ('a0a0a0a0-0000-4000-8000-000000093012', 67, 'AI Employee', 'aiEmployee', '{"ai_user_id": "29100"}'::jsonb, '[{"target": "a0a0a0a0-0000-4000-8000-000000093013", "source_handle": "output"}]'::jsonb, NULL) ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_trigger_nodes (id, trigger_id, name, type, config, edges, ui_config) VALUES ('a0a0a0a0-0000-4000-8000-000000093013', 67, 'Complete', 'response', '{"message": "AI Employee task dispatched", "success": true, "status_code": 200}'::jsonb, '[]'::jsonb, NULL) ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_trigger_nodes (id, trigger_id, name, type, config, edges, ui_config) VALUES ('a0a0a0a0-0000-4000-8000-000000093041', 68, 'Start', 'start', '{}'::jsonb, '[{"target": "a0a0a0a0-0000-4000-8000-000000093042", "source_handle": "output"}]'::jsonb, NULL) ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_trigger_nodes (id, trigger_id, name, type, config, edges, ui_config) VALUES ('a0a0a0a0-0000-4000-8000-000000093042', 68, 'AI Employee', 'aiEmployee', '{"ai_user_id": "29100"}'::jsonb, '[{"target": "a0a0a0a0-0000-4000-8000-000000093043", "source_handle": "output"}]'::jsonb, NULL) ON CONFLICT (id) DO NOTHING;
INSERT INTO workflow.tbl_wf_activity_trigger_nodes (id, trigger_id, name, type, config, edges, ui_config) VALUES ('a0a0a0a0-0000-4000-8000-000000093043', 68, 'Complete', 'response', '{"message": "AI Employee task dispatched", "success": true, "status_code": 200}'::jsonb, '[]'::jsonb, NULL) ON CONFLICT (id) DO NOTHING;
-- Activity permissions
-- 4. AI Employee
INSERT INTO aiemployee.tbl_ai_employees (id, user_id, org_id, name, model, autonomy_level, config, status) VALUES (20, '29100', '20', 'Priya AI Finance (P2P Demo)', 'claude-sonnet-4-5-20250929', 'semi_autonomous', '{"mcp_servers": [], "rate_limits": {"max_tasks_per_day": 500, "max_tasks_per_hour": 100, "confidence_threshold": 0.5, "max_tasks_per_minute": 10, "max_llm_calls_per_task": 12}, "available_tools": {"agentic_tools": ["29110", "29111", "29112", "29113"], "autonomous_agents": []}, "monthly_budget_usd": 200, "max_concurrent_tasks": 3}'::jsonb, 'active') ON CONFLICT (id) DO NOTHING;
-- AI Employee appconfig
INSERT INTO aiemployee.tbl_appconfig_ai_employees (id, user_id, org_id, name, model, autonomy_level, config, status, email, password) VALUES (20038, '29100', '20', 'Priya AI Finance (P2P Demo)', 'claude-sonnet-4-5-20250929', 'semi_autonomous', '{"mcp_servers": [], "rate_limits": {"max_tasks_per_day": 500, "max_tasks_per_hour": 100, "confidence_threshold": 0.5, "max_tasks_per_minute": 10, "max_llm_calls_per_task": 12}, "available_tools": {"agentic_tools": ["29110", "29111", "29112", "29113"], "autonomous_agents": []}, "monthly_budget_usd": 200, "max_concurrent_tasks": 3}'::jsonb, 'active', '', '') ON CONFLICT (id) DO NOTHING;
-- AI Employee registry
INSERT INTO aiemployee.tbl_ai_employee_registry (ai_user_id, service_url, status) VALUES ('29100', 'http://localhost:8090', 'running') ON CONFLICT (ai_user_id) DO NOTHING;
-- 5. Agentic tools
-- 6. DB Connection
INSERT INTO tbl_org_db_connections (id, org_id, name, type, host, port, "user", password, database_name, ssl_mode) VALUES (5, 20, 'P2P Azure DB', 'postgres', 'studio-v2-pg.postgres.database.azure.com', 5432, 'studiov2pgadmin', 'YmzkpmVprw0Fsn8s0cvR', 'sm', 'require') ON CONFLICT (id) DO NOTHING;
-- ============================================================
-- 7. P2P DEMO DATA (p2p_demo schema)
-- ============================================================
CREATE SCHEMA IF NOT EXISTS p2p_demo;
CREATE TABLE p2p_demo.contract_line_items (
id integer NOT NULL,
contract_id text,
product_code text NOT NULL,
description text,
unit_price numeric(12,2) NOT NULL,
currency text DEFAULT 'INR'::text
);
ALTER TABLE p2p_demo.contract_line_items OWNER TO postgres;
--
-- Name: contract_line_items_id_seq; Type: SEQUENCE; Schema: p2p_demo; Owner: postgres
--
CREATE SEQUENCE p2p_demo.contract_line_items_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE p2p_demo.contract_line_items_id_seq OWNER TO postgres;
--
-- Name: contract_line_items_id_seq; Type: SEQUENCE OWNED BY; Schema: p2p_demo; Owner: postgres
--
ALTER SEQUENCE p2p_demo.contract_line_items_id_seq OWNED BY p2p_demo.contract_line_items.id;
--
-- Name: contracts; Type: TABLE; Schema: p2p_demo; Owner: postgres
--
CREATE TABLE p2p_demo.contracts (
contract_id text NOT NULL,
vendor_id text NOT NULL,
vendor_name text NOT NULL,
effective_date date,
expiry_date date,
status text DEFAULT 'active'::text,
payment_terms text,
price_tolerance_pct numeric(5,2) DEFAULT 2.0,
quantity_tolerance_pct numeric(5,2) DEFAULT 5.0,
created_at timestamp without time zone DEFAULT now()
);
ALTER TABLE p2p_demo.contracts OWNER TO postgres;
--
-- Name: goods_receipts; Type: TABLE; Schema: p2p_demo; Owner: postgres
--
CREATE TABLE p2p_demo.goods_receipts (
gr_number text NOT NULL,
po_number text NOT NULL,
vendor_id text NOT NULL,
receipt_date date,
received_by text,
notes text,
created_at timestamp without time zone DEFAULT now()
);
ALTER TABLE p2p_demo.goods_receipts OWNER TO postgres;
--
-- Name: gr_line_items; Type: TABLE; Schema: p2p_demo; Owner: postgres
--
CREATE TABLE p2p_demo.gr_line_items (
id integer NOT NULL,
gr_number text,
product_code text NOT NULL,
quantity_received integer NOT NULL,
condition text DEFAULT 'good'::text
);
ALTER TABLE p2p_demo.gr_line_items OWNER TO postgres;
--
-- Name: gr_line_items_id_seq; Type: SEQUENCE; Schema: p2p_demo; Owner: postgres
--
CREATE SEQUENCE p2p_demo.gr_line_items_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE p2p_demo.gr_line_items_id_seq OWNER TO postgres;
--
-- Name: gr_line_items_id_seq; Type: SEQUENCE OWNED BY; Schema: p2p_demo; Owner: postgres
--
ALTER SEQUENCE p2p_demo.gr_line_items_id_seq OWNED BY p2p_demo.gr_line_items.id;
--
-- Name: payments; Type: TABLE; Schema: p2p_demo; Owner: postgres
--
CREATE TABLE p2p_demo.payments (
payment_id text NOT NULL,
invoice_number text,
po_number text,
vendor_id text NOT NULL,
amount numeric(14,2) NOT NULL,
payment_date date,
status text DEFAULT 'completed'::text,
created_at timestamp without time zone DEFAULT now()
);
ALTER TABLE p2p_demo.payments OWNER TO postgres;
--
-- Name: po_line_items; Type: TABLE; Schema: p2p_demo; Owner: postgres
--
CREATE TABLE p2p_demo.po_line_items (
id integer NOT NULL,
po_number text,
product_code text NOT NULL,
description text,
quantity integer NOT NULL,
unit_price numeric(12,2) NOT NULL
);
ALTER TABLE p2p_demo.po_line_items OWNER TO postgres;
--
-- Name: po_line_items_id_seq; Type: SEQUENCE; Schema: p2p_demo; Owner: postgres
--
CREATE SEQUENCE p2p_demo.po_line_items_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE p2p_demo.po_line_items_id_seq OWNER TO postgres;
--
-- Name: po_line_items_id_seq; Type: SEQUENCE OWNED BY; Schema: p2p_demo; Owner: postgres
--
ALTER SEQUENCE p2p_demo.po_line_items_id_seq OWNED BY p2p_demo.po_line_items.id;
--
-- Name: purchase_orders; Type: TABLE; Schema: p2p_demo; Owner: postgres
--
CREATE TABLE p2p_demo.purchase_orders (
po_number text NOT NULL,
vendor_id text NOT NULL,
vendor_name text NOT NULL,
contract_id text,
order_date date,
expected_delivery date,
status text DEFAULT 'open'::text,
total_amount numeric(14,2),
created_at timestamp without time zone DEFAULT now()
);
ALTER TABLE p2p_demo.purchase_orders OWNER TO postgres;
--
-- Name: tbl_messages; Type: TABLE; Schema: pipeline_ai; Owner: postgres
--
CREATE TABLE pipeline_ai.tbl_messages (
id bigint NOT NULL,
session_id bigint,
role text,
content text,
metadata jsonb DEFAULT '{}'::jsonb,
created_at timestamp with time zone
);
ALTER TABLE pipeline_ai.tbl_messages OWNER TO postgres;
--
COMMIT;
-- User agent assignments
-- Activity permissions
-- Agentic tools
INSERT INTO agents.tbl_agentic_tools (id, org_id, group_id, name, description, flow_config, status, icon) VALUES (29112, 20, 20, 'fetch_contract', 'Fetch contract details by contract_id or vendor_id. Returns contract terms, pricing, tolerances. Use parameter: contract_id (preferred) or vendor_id.', E'{"edges": [{"id": "e1", "type": "custom", "source": "trigger-1", "target": "db-query-1", "sourceHandle": "output", "targetHandle": "input"}, {"id": "e2", "type": "custom", "source": "db-query-1", "target": "success-1", "sourceHandle": "output", "targetHandle": "input"}], "nodes": [{"id": "trigger-1", "data": {"label": "Input", "config": {"path": "/", "method": "POST"}}, "type": "webhookTrigger", "position": {"x": 100, "y": 50}}, {"id": "db-query-1", "data": {"label": "Query p2p_demo", "config": {"query": "SELECT json_build_object(\\\\n\\\\t\\\\t\\\\t\\\\t''contract_id'', c.contract_id,\\\\n\\\\t\\\\t\\\\t\\\\t''vendor_id'', c.vendor_id,\\\\n\\\\t\\\\t\\\\t\\\\t''vendor_name'', c.vendor_name,\\\\n\\\\t\\\\t\\\\t\\\\t''effective_date'', c.effective_date,\\\\n\\\\t\\\\t\\\\t\\\\t''expiry_date'', c.expiry_date,\\\\n\\\\t\\\\t\\\\t\\\\t''status'', c.status,\\\\n\\\\t\\\\t\\\\t\\\\t''payment_terms'', c.payment_terms,\\\\n\\\\t\\\\t\\\\t\\\\t''price_tolerance_pct'', c.price_tolerance_pct,\\\\n\\\\t\\\\t\\\\t\\\\t''quantity_tolerance_pct'', c.quantity_tolerance_pct,\\\\n\\\\t\\\\t\\\\t\\\\t''line_items'', COALESCE((\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tSELECT json_agg(json_build_object(\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''product_code'', cli.product_code,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''description'', cli.description,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''unit_price'', cli.unit_price,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''currency'', cli.currency\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t))\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tFROM p2p_demo.contract_line_items cli WHERE cli.contract_id = c.contract_id\\\\n\\\\t\\\\t\\\\t\\\\t), ''[]''::json)\\\\n\\\\t\\\\t\\\\t) AS result\\\\n\\\\t\\\\t\\\\tFROM p2p_demo.contracts c\\\\n\\\\t\\\\t\\\\tWHERE c.contract_id = ''{{contract_id}}''\\\\n\\\\t\\\\t\\\\t OR c.vendor_id = ''{{vendor_id}}''\\\\n\\\\t\\\\t\\\\tLIMIT 1", "db_type": "postgresql", "operation": "raw", "connection": "{{env.DATABASE_URL}}", "result_limit": 50, "output_variable": "result"}}, "type": "databaseQuery", "position": {"x": 100, "y": 200}}, {"id": "success-1", "data": {"label": "Output", "config": {"output_field": "result"}}, "type": "success", "position": {"x": 100, "y": 350}}]}'::jsonb, 'active', '') ON CONFLICT (id) DO NOTHING;
INSERT INTO agents.tbl_agentic_tools (id, org_id, group_id, name, description, flow_config, status, icon) VALUES (29110, 20, 20, 'fetch_purchase_order', 'Fetch purchase order details by PO number. Returns PO header (vendor, status, total, dates) and line items (product, quantity, unit price). Use parameter: po_number.', E'{"edges": [{"id": "e1", "type": "custom", "source": "trigger-1", "target": "db-query-1", "sourceHandle": "output", "targetHandle": "input"}, {"id": "e2", "type": "custom", "source": "db-query-1", "target": "success-1", "sourceHandle": "output", "targetHandle": "input"}], "nodes": [{"id": "trigger-1", "data": {"label": "Input", "config": {"path": "/", "method": "POST"}}, "type": "webhookTrigger", "position": {"x": 100, "y": 50}}, {"id": "db-query-1", "data": {"label": "Query p2p_demo", "config": {"query": "SELECT json_build_object(\\\\n\\\\t\\\\t\\\\t\\\\t''po_number'', po.po_number,\\\\n\\\\t\\\\t\\\\t\\\\t''vendor_id'', po.vendor_id,\\\\n\\\\t\\\\t\\\\t\\\\t''vendor_name'', po.vendor_name,\\\\n\\\\t\\\\t\\\\t\\\\t''contract_id'', po.contract_id,\\\\n\\\\t\\\\t\\\\t\\\\t''order_date'', po.order_date,\\\\n\\\\t\\\\t\\\\t\\\\t''expected_delivery'', po.expected_delivery,\\\\n\\\\t\\\\t\\\\t\\\\t''status'', po.status,\\\\n\\\\t\\\\t\\\\t\\\\t''total_amount'', po.total_amount,\\\\n\\\\t\\\\t\\\\t\\\\t''line_items'', COALESCE((\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tSELECT json_agg(json_build_object(\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''product_code'', li.product_code,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''description'', li.description,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''quantity'', li.quantity,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''unit_price'', li.unit_price\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t))\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tFROM p2p_demo.po_line_items li WHERE li.po_number = po.po_number\\\\n\\\\t\\\\t\\\\t\\\\t), ''[]''::json)\\\\n\\\\t\\\\t\\\\t) AS result\\\\n\\\\t\\\\t\\\\tFROM p2p_demo.purchase_orders po\\\\n\\\\t\\\\t\\\\tWHERE po.po_number = ''{{po_number}}''", "db_type": "postgresql", "operation": "raw", "connection": "{{env.DATABASE_URL}}", "result_limit": 50, "output_variable": "result"}}, "type": "databaseQuery", "position": {"x": 100, "y": 200}}, {"id": "success-1", "data": {"label": "Output", "config": {"output_field": "result"}}, "type": "success", "position": {"x": 100, "y": 350}}]}'::jsonb, 'active', '') ON CONFLICT (id) DO NOTHING;
INSERT INTO agents.tbl_agentic_tools (id, org_id, group_id, name, description, flow_config, status, icon) VALUES (29111, 20, 20, 'fetch_goods_receipt', 'Fetch goods receipt records for a PO number. Returns all delivery records with received quantities, dates, and notes. Use parameter: po_number.', E'{"edges": [{"id": "e1", "type": "custom", "source": "trigger-1", "target": "db-query-1", "sourceHandle": "output", "targetHandle": "input"}, {"id": "e2", "type": "custom", "source": "db-query-1", "target": "success-1", "sourceHandle": "output", "targetHandle": "input"}], "nodes": [{"id": "trigger-1", "data": {"label": "Input", "config": {"path": "/", "method": "POST"}}, "type": "webhookTrigger", "position": {"x": 100, "y": 50}}, {"id": "db-query-1", "data": {"label": "Query p2p_demo", "config": {"query": "SELECT json_build_object(\\\\n\\\\t\\\\t\\\\t\\\\t''po_number'', ''{{po_number}}'',\\\\n\\\\t\\\\t\\\\t\\\\t''receipts'', COALESCE((\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tSELECT json_agg(json_build_object(\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''gr_number'', gr.gr_number,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''receipt_date'', gr.receipt_date,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''received_by'', gr.received_by,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''notes'', gr.notes,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''line_items'', COALESCE((\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t\\\\tSELECT json_agg(json_build_object(\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''product_code'', gli.product_code,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''quantity_received'', gli.quantity_received,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''condition'', gli.condition\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t))\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t\\\\tFROM p2p_demo.gr_line_items gli WHERE gli.gr_number = gr.gr_number\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t), ''[]''::json)\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t))\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tFROM p2p_demo.goods_receipts gr WHERE gr.po_number = ''{{po_number}}''\\\\n\\\\t\\\\t\\\\t\\\\t), ''[]''::json),\\\\n\\\\t\\\\t\\\\t\\\\t''total_received'', COALESCE((\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tSELECT SUM(gli.quantity_received)\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tFROM p2p_demo.goods_receipts gr\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tJOIN p2p_demo.gr_line_items gli ON gli.gr_number = gr.gr_number\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tWHERE gr.po_number = ''{{po_number}}''\\\\n\\\\t\\\\t\\\\t\\\\t), 0)\\\\n\\\\t\\\\t\\\\t) AS result", "db_type": "postgresql", "operation": "raw", "connection": "{{env.DATABASE_URL}}", "result_limit": 50, "output_variable": "result"}}, "type": "databaseQuery", "position": {"x": 100, "y": 200}}, {"id": "success-1", "data": {"label": "Output", "config": {"output_field": "result"}}, "type": "success", "position": {"x": 100, "y": 350}}]}'::jsonb, 'active', '') ON CONFLICT (id) DO NOTHING;
INSERT INTO agents.tbl_agentic_tools (id, org_id, group_id, name, description, flow_config, status, icon) VALUES (29113, 20, 20, 'fetch_payment_history', 'Fetch payment history for a PO number or vendor. Returns all payments made, total paid amount. Use parameter: po_number (preferred) or vendor_id.', E'{"edges": [{"id": "e1", "type": "custom", "source": "trigger-1", "target": "db-query-1", "sourceHandle": "output", "targetHandle": "input"}, {"id": "e2", "type": "custom", "source": "db-query-1", "target": "success-1", "sourceHandle": "output", "targetHandle": "input"}], "nodes": [{"id": "trigger-1", "data": {"label": "Input", "config": {"path": "/", "method": "POST"}}, "type": "webhookTrigger", "position": {"x": 100, "y": 50}}, {"id": "db-query-1", "data": {"label": "Query p2p_demo", "config": {"query": "SELECT json_build_object(\\\\n\\\\t\\\\t\\\\t\\\\t''payments'', COALESCE((\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tSELECT json_agg(json_build_object(\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''payment_id'', p.payment_id,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''invoice_number'', p.invoice_number,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''po_number'', p.po_number,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''amount'', p.amount,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''payment_date'', p.payment_date,\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t\\\\t''status'', p.status\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t))\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tFROM p2p_demo.payments p\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tWHERE p.po_number = ''{{po_number}}'' OR p.vendor_id = ''{{vendor_id}}''\\\\n\\\\t\\\\t\\\\t\\\\t), ''[]''::json),\\\\n\\\\t\\\\t\\\\t\\\\t''total_paid'', COALESCE((\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tSELECT SUM(p.amount)\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tFROM p2p_demo.payments p\\\\n\\\\t\\\\t\\\\t\\\\t\\\\tWHERE (p.po_number = ''{{po_number}}'' OR p.vendor_id = ''{{vendor_id}}'')\\\\n\\\\t\\\\t\\\\t\\\\t\\\\t AND p.status = ''completed''\\\\n\\\\t\\\\t\\\\t\\\\t), 0)\\\\n\\\\t\\\\t\\\\t) AS result", "db_type": "postgresql", "operation": "raw", "connection": "{{env.DATABASE_URL}}", "result_limit": 50, "output_variable": "result"}}, "type": "databaseQuery", "position": {"x": 100, "y": 200}}, {"id": "success-1", "data": {"label": "Output", "config": {"output_field": "result"}}, "type": "success", "position": {"x": 100, "y": 350}}]}'::jsonb, 'active', '') ON CONFLICT (id) DO NOTHING;
-- ============================================================
-- 7. P2P DEMO DATA (p2p_demo schema)
-- ============================================================
-- Import from: /Users/bhanuprakash/Downloads/sm_db.sql
-- Extract p2p_demo tables/data separately using:
-- grep -A lines for p2p_demo CREATE TABLE and COPY statements
COMMIT;