[2026-03-31 04:23:09] [INFO] ===========================================
[2026-03-31 04:23:09] [INFO] Quotations Processor Log
[2026-03-31 04:23:09] [INFO] Record ID: f1746972-3828-4fc2-9d34-3735072bc4f1
[2026-03-31 04:23:09] [INFO] Table: quotations
[2026-03-31 04:23:09] [INFO] Timestamp: 2026-03-31 04:23:09
[2026-03-31 04:23:09] [INFO] ===========================================
[2026-03-31 04:23:09] [INFO] ========== START: processQuotationSubmission ==========
[2026-03-31 04:23:09] [INFO] Function called for record ID: f1746972-3828-4fc2-9d34-3735072bc4f1
[2026-03-31 04:23:09] [DEBUG] Form data received: {"table":"quotations","tenant_id":"019b9c9c-9d60-79d0-3ec5-849b68cdb9da"}
[2026-03-31 04:23:09] [INFO] Detected table: quotations (Type: proforma)
[2026-03-31 04:23:09] [DEBUG] ID field: quotation_id, Number field: quotation_number
[2026-03-31 04:23:09] [DEBUG] STEP 1: Fetching quotation data from database
[2026-03-31 04:23:09] [DEBUG] QueryBuilder instance created
[2026-03-31 04:23:09] [DEBUG] Database query executed for quotation_id: f1746972-3828-4fc2-9d34-3735072bc4f1
[2026-03-31 04:23:09] [DEBUG] Quotation found successfully
[2026-03-31 04:23:09] [INFO] quotation_type from record overrides invoiceType: proforma
[2026-03-31 04:23:09] [DEBUG] Using org_id: 019b9c9c-9d60-79d0-3ec5-849b68cdb9da
[2026-03-31 04:23:09] [INFO] Fetched quotation data: {"quotation_id":"f1746972-3828-4fc2-9d34-3735072bc4f1","quotation_number":"00002","date":"2026-03-31","customer_id":"019bb59b-f3bc-7091-b426-1ed577d19144","org_id":"019b9c9c-9d60-79d0-3ec5-849b68cdb9da","client_id":null,"line_items":"[{\"quantity\": \"4\", \"vat_rate\": \"VIP\", \"line_total\": \"348.64\", \"product_id\": \"000019ba-60c9-793a-2e57-55ac82f7d61e\", \"unit_price\": \"87.16\", \"vat_amount\": \"38.74\", \"description\": \"Rooster sp\", \"line_subtotal\": \"348.64\"}, {\"quantity\": \"3\", \"vat_rate\": \"VIP\", \"line_total\": \"447.75\", \"product_id\": \"000019ba-6096-762a-ac9a-5f26483b400a\", \"unit_price\": \"149.25\", \"vat_amount\": \"49.75\", \"description\": \"Rooster 18\", \"line_subtotal\": \"447.75\"}, {\"quantity\": \"3\", \"vat_rate\": \"VIP\", \"line_total\": \"456.36\", \"product_id\": \"000019ba-607e-7972-f446-529bc618ace3\", \"unit_price\": \"152.12\", \"vat_amount\": \"50.71\", \"description\": \"Rooster 16\", \"line_subtotal\": \"456.36\"}, {\"quantity\": \"2\", \"vat_rate\": \"VIP\", \"line_total\": \"280.2\", \"product_id\": \"000019ba-5fc8-73a1-c75e-d8f02babd138\", \"unit_price\": \"140.10\", \"vat_amount\": \"31.13\", \"description\": \"Rooster 12\", \"line_subtotal\": \"280.2\"}, {\"quantity\": \"20\", \"vat_rate\": \"VIP\", \"line_total\": \"359\", \"product_id\": \"000019bb-e755-7bba-a955-6ad4d7bb7dd3\", \"unit_price\": \"17.95\", \"vat_amount\": \"39.89\", \"description\": \"lamb neck X1kg\", \"line_subtotal\": \"359\"}]","note":null,"terms":null,"validity_days":30,"status":"expired","total_amount":"0.00","tax_amount":"0.00","template_id":null,"sent_at":null,"expires_at":"2026-03-31","accepted_at":null,"rejected_at":null,"rejection_reason":null,"converted_invoice_id":null,"created_by":null,"updated_by":null,"isdeleted":false,"updatedat":"2026-03-31 04:23:09.50883+00","taxcore_submission_id":null,"taxcore_submission_id_fk":null,"taxcore_receipt_data":null,"taxcore_submitted_at":null,"taxcore_verification_url":null,"taxcore_qr_code":null,"journal_entry_id":null,"converted_to_invoice_id":null,"po_number":null,"notes_additional":null,"payment_terms_details":null,"quotation_type":"proforma"}
[2026-03-31 04:23:09] [DEBUG] STEP 2: Parsing line_items JSON
[2026-03-31 04:23:09] [DEBUG] Parsed 5 line items
[2026-03-31 04:23:09] [DEBUG] Line items: [{"quantity":"4","vat_rate":"VIP","line_total":"348.64","product_id":"000019ba-60c9-793a-2e57-55ac82f7d61e","unit_price":"87.16","vat_amount":"38.74","description":"Rooster sp","line_subtotal":"348.64"},{"quantity":"3","vat_rate":"VIP","line_total":"447.75","product_id":"000019ba-6096-762a-ac9a-5f26483b400a","unit_price":"149.25","vat_amount":"49.75","description":"Rooster 18","line_subtotal":"447.75"},{"quantity":"3","vat_rate":"VIP","line_total":"456.36","product_id":"000019ba-607e-7972-f446-529bc618ace3","unit_price":"152.12","vat_amount":"50.71","description":"Rooster 16","line_subtotal":"456.36"},{"quantity":"2","vat_rate":"VIP","line_total":"280.2","product_id":"000019ba-5fc8-73a1-c75e-d8f02babd138","unit_price":"140.10","vat_amount":"31.13","description":"Rooster 12","line_subtotal":"280.2"},{"quantity":"20","vat_rate":"VIP","line_total":"359","product_id":"000019bb-e755-7bba-a955-6ad4d7bb7dd3","unit_price":"17.95","vat_amount":"39.89","description":"lamb neck X1kg","line_subtotal":"359"}]
[2026-03-31 04:23:09] [DEBUG] STEP 3: Preparing items for TaxCore
[2026-03-31 04:23:09] [DEBUG] Processing line item: 0 -> {"quantity":"4","vat_rate":"VIP","line_total":"348.64","product_id":"000019ba-60c9-793a-2e57-55ac82f7d61e","unit_price":"87.16","vat_amount":"38.74","description":"Rooster sp","line_subtotal":"348.64"}
[2026-03-31 04:23:09] [DEBUG] Calculated - Quantity: 4, UnitPrice: 87.16, TotalAmount: 348.64
[2026-03-31 04:23:09] [DEBUG] Processing line item: 1 -> {"quantity":"3","vat_rate":"VIP","line_total":"447.75","product_id":"000019ba-6096-762a-ac9a-5f26483b400a","unit_price":"149.25","vat_amount":"49.75","description":"Rooster 18","line_subtotal":"447.75"}
[2026-03-31 04:23:09] [DEBUG] Calculated - Quantity: 3, UnitPrice: 149.25, TotalAmount: 447.75
[2026-03-31 04:23:09] [DEBUG] Processing line item: 2 -> {"quantity":"3","vat_rate":"VIP","line_total":"456.36","product_id":"000019ba-607e-7972-f446-529bc618ace3","unit_price":"152.12","vat_amount":"50.71","description":"Rooster 16","line_subtotal":"456.36"}
[2026-03-31 04:23:09] [DEBUG] Calculated - Quantity: 3, UnitPrice: 152.12, TotalAmount: 456.36
[2026-03-31 04:23:09] [DEBUG] Processing line item: 3 -> {"quantity":"2","vat_rate":"VIP","line_total":"280.2","product_id":"000019ba-5fc8-73a1-c75e-d8f02babd138","unit_price":"140.10","vat_amount":"31.13","description":"Rooster 12","line_subtotal":"280.2"}
[2026-03-31 04:23:09] [DEBUG] Calculated - Quantity: 2, UnitPrice: 140.1, TotalAmount: 280.2
[2026-03-31 04:23:09] [DEBUG] Processing line item: 4 -> {"quantity":"20","vat_rate":"VIP","line_total":"359","product_id":"000019bb-e755-7bba-a955-6ad4d7bb7dd3","unit_price":"17.95","vat_amount":"39.89","description":"lamb neck X1kg","line_subtotal":"359"}
[2026-03-31 04:23:09] [DEBUG] Calculated - Quantity: 20, UnitPrice: 17.95, TotalAmount: 359
[2026-03-31 04:23:09] [DEBUG] Prepared 5 items for TaxCore
[2026-03-31 04:23:09] [INFO] TaxCore items: [{"name":"Rooster sp","quantity":4,"unitPrice":"87.16","totalAmount":"348.64","Labels":["G"]},{"name":"Rooster 18","quantity":3,"unitPrice":"149.25","totalAmount":"447.75","Labels":["G"]},{"name":"Rooster 16","quantity":3,"unitPrice":"152.12","totalAmount":"456.36","Labels":["G"]},{"name":"Rooster 12","quantity":2,"unitPrice":"140.10","totalAmount":"280.20","Labels":["G"]},{"name":"lamb neck X1kg","quantity":20,"unitPrice":"17.95","totalAmount":"359.00","Labels":["G"]}]
[2026-03-31 04:23:09] [DEBUG] STEP 4: Preparing payment method as Credit
[2026-03-31 04:23:09] [INFO] Payment prepared (Credit): [{"paymentType":"0","amount":0}]
[2026-03-31 04:23:09] [DEBUG] STEP 5: Fetching cashier information
[2026-03-31 04:23:09] [DEBUG] User ID from formData: 019b9c9c-9d60-79d0-3ec5-849b68cdb9da
[2026-03-31 04:23:09] [DEBUG] Querying users table for user_id: 019b9c9c-9d60-79d0-3ec5-849b68cdb9da
[2026-03-31 04:23:09] [INFO] Cashier name found: System
[2026-03-31 04:23:09] [DEBUG] STEP 6: Building TaxCore payload
[2026-03-31 04:23:09] [DEBUG] Base payload created with type=proforma
[2026-03-31 04:23:09] [DEBUG] STEP 7: Adding customer/buyer information
[2026-03-31 04:23:09] [DEBUG] Customer ID found: 019bb59b-f3bc-7091-b426-1ed577d19144
[2026-03-31 04:23:09] [DEBUG] Customer found: {"name":"Keyasi Convenient","tin":null}
[2026-03-31 04:23:09] [INFO] TaxCore payload prepared: {
    "items": [
        {
            "name": "Rooster sp",
            "quantity": 4,
            "unitPrice": "87.16",
            "totalAmount": "348.64",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Rooster 18",
            "quantity": 3,
            "unitPrice": "149.25",
            "totalAmount": "447.75",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Rooster 16",
            "quantity": 3,
            "unitPrice": "152.12",
            "totalAmount": "456.36",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Rooster 12",
            "quantity": 2,
            "unitPrice": "140.10",
            "totalAmount": "280.20",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "lamb neck X1kg",
            "quantity": 20,
            "unitPrice": "17.95",
            "totalAmount": "359.00",
            "Labels": [
                "G"
            ]
        }
    ],
    "payment": [
        {
            "paymentType": "0",
            "amount": 0
        }
    ],
    "Cashier": "System",
    "type": "proforma",
    "invoiceNumber": "00002",
    "Buyer": {
        "Name": "Keyasi Convenient"
    }
}
[2026-03-31 04:23:09] [DEBUG] STEP 8: Creating Journal Entry in Finance module
[2026-03-31 04:23:09] [INFO] --- createJournalEntry: Starting ---
[2026-03-31 04:23:09] [INFO] Is Cancelled/Refund: NO
[2026-03-31 04:23:09] [DEBUG] Calculated totals - Subtotal: 1891.95, Tax: 236.49375, Total: 2128.44375
[2026-03-31 04:23:09] [DEBUG] Looking for customer-specific AR account for: Keyasi Convenient
[2026-03-31 04:23:09] [INFO] Found customer-specific AR account: 1300-098 - AR - Keyasi Convenient
[2026-03-31 04:23:09] [DEBUG] Found GL accounts - Revenue: 4000, Tax: 2410, Receivables: 1300-098 (AR - Keyasi Convenient)
[2026-03-31 04:23:09] [DEBUG] Journal entry header prepared: {"id":"8ad6ff50-23df-44d3-ac86-16b924f33d73","entry_date":"2026-03-31","description":"Quotation 00002","reference":"00002","source_module":"quotations","source_id":"f1746972-3828-4fc2-9d34-3735072bc4f1","total_debits":2128.44375,"total_credits":2128.44375,"status":"posted","is_balanced":true,"created_by":null,"org_id":null,"posted_at":"2026-03-31 04:23:09","posted_by":null}
[2026-03-31 04:23:09] [INFO] Journal entry header created: 8ad6ff50-23df-44d3-ac86-16b924f33d73
[2026-03-31 04:23:09] [DEBUG] Prepared 3 journal lines
[2026-03-31 04:23:09] [ERROR] ERROR creating journal entry: SQL Error: SQLSTATE[23502]: Not null violation: 7 ERROR:  null value in column "org_id" of relation "gl_account_balances" violates not-null constraint
DETAIL:  Failing row contains (019bb59c-7d1f-7080-8861-3d1f3aa0262c, null, 2128.44, 0.00, 2128.44, 2026-03-31 04:23:09.575561+00, 2026-03-31, 1, 2026-03-31 04:23:09.575561+00, 2026-03-31 04:23:09.575561+00, 019d4221-920b-78f1-ac82-7d7d0d71d81e).
CONTEXT:  SQL statement "INSERT INTO gl_account_balances (
        account_id,
        org_id,
        total_debits,
        total_credits,
        current_balance,
        last_updated,
        last_entry_date,
        transaction_count,
        updated_at
    ) VALUES (
        v_account_id,
        v_org_id,
        v_total_debits,
        v_total_credits,
        v_new_balance,
        CURRENT_TIMESTAMP,
        v_last_entry_date,
        v_transaction_count,
        CURRENT_TIMESTAMP
    )
    ON CONFLICT (account_id, org_id) DO UPDATE SET
        total_debits = EXCLUDED.total_debits,
        total_credits = EXCLUDED.total_credits,
        current_balance = EXCLUDED.current_balance,
        last_updated = EXCLUDED.last_updated,
        last_entry_date = EXCLUDED.last_entry_date,
        transaction_count = EXCLUDED.transaction_count,
        updated_at = EXCLUDED.updated_at"
PL/pgSQL function update_account_balance() line 49 at SQL statement | Query: INSERT INTO "gl_journal_lines" ("id", "journal_entry_id", "account_id", "memo", "debit", "credit", "org_id") VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id
[2026-03-31 04:23:09] [ERROR] Stack trace: #0 /var/www/POS/api/utils/DB.php(231): Core\DB->runQuery()
#1 /var/www/POS/api/utils/QueryBuilder.php(466): Core\DB->insert()
#2 /var/www/POS/api/services/QuotationsProcessor.php(720): Core\QueryBuilder->insert()
#3 /var/www/POS/api/services/QuotationsProcessor.php(301): App\Services\QuotationsProcessor::createJournalEntry()
#4 [internal function]: App\Services\QuotationsProcessor::processQuotationSubmission()
#5 /var/www/POS/api/services/workflow_steps/CustomFunctionStep.php(121): call_user_func_array()
#6 /var/www/POS/api/services/WorkflowEngine.php(507): App\Services\WorkflowSteps\CustomFunctionStep->execute()
#7 /var/www/POS/api/services/WorkflowEngine.php(766): App\Services\WorkflowEngine->executeStep()
#8 /var/www/POS/api/services/WorkflowEngine.php(143): App\Services\WorkflowEngine->runSteps()
#9 /var/www/POS/api/services/WorkflowEngine.php(176): App\Services\WorkflowEngine->handleEvent()
#10 /var/www/POS/api/services/WorkflowEngine.php(188): App\Services\WorkflowEngine->emit()
#11 /var/www/POS/api/controllers/GenericController.php(373): App\Services\WorkflowEngine::trigger()
#12 /var/www/POS/api/controllers/SyncController.php(202): App\Controllers\GenericController->processWorkflowEvents()
#13 /var/www/POS/api/controllers/SyncController.php(214): App\Controllers\GenericController@anonymous->exec()
#14 /var/www/POS/api/controllers/SyncController.php(1308): App\Controllers\SyncController->triggerWorkflow()
#15 /var/www/POS/api/router.php(226): App\Controllers\SyncController->push()
#16 /var/www/POS/api/index.php(32): require_once('...')
#17 {main}
[2026-03-31 04:23:09] [WARN] WARNING: Journal entry creation failed: SQL Error: SQLSTATE[23502]: Not null violation: 7 ERROR:  null value in column "org_id" of relation "gl_account_balances" violates not-null constraint
DETAIL:  Failing row contains (019bb59c-7d1f-7080-8861-3d1f3aa0262c, null, 2128.44, 0.00, 2128.44, 2026-03-31 04:23:09.575561+00, 2026-03-31, 1, 2026-03-31 04:23:09.575561+00, 2026-03-31 04:23:09.575561+00, 019d4221-920b-78f1-ac82-7d7d0d71d81e).
CONTEXT:  SQL statement "INSERT INTO gl_account_balances (
        account_id,
        org_id,
        total_debits,
        total_credits,
        current_balance,
        last_updated,
        last_entry_date,
        transaction_count,
        updated_at
    ) VALUES (
        v_account_id,
        v_org_id,
        v_total_debits,
        v_total_credits,
        v_new_balance,
        CURRENT_TIMESTAMP,
        v_last_entry_date,
        v_transaction_count,
        CURRENT_TIMESTAMP
    )
    ON CONFLICT (account_id, org_id) DO UPDATE SET
        total_debits = EXCLUDED.total_debits,
        total_credits = EXCLUDED.total_credits,
        current_balance = EXCLUDED.current_balance,
        last_updated = EXCLUDED.last_updated,
        last_entry_date = EXCLUDED.last_entry_date,
        transaction_count = EXCLUDED.transaction_count,
        updated_at = EXCLUDED.updated_at"
PL/pgSQL function update_account_balance() line 49 at SQL statement | Query: INSERT INTO "gl_journal_lines" ("id", "journal_entry_id", "account_id", "memo", "debit", "credit", "org_id") VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id
[2026-03-31 04:23:09] [DEBUG] STEP 9: Checking if TaxCore integration is enabled
[2026-03-31 04:23:09] [DEBUG] Checking TaxCore integration status for org_id: 019b9c9c-9d60-79d0-3ec5-849b68cdb9da (table: quotations)
[2026-03-31 04:23:09] [INFO] TIN found, TaxCore could be enabled but no explicit setting - defaulting to false for safety
[2026-03-31 04:23:09] [INFO] No TaxCore configuration found for org_id: 019b9c9c-9d60-79d0-3ec5-849b68cdb9da, defaulting to disabled
[2026-03-31 04:23:09] [INFO] TaxCore integration enabled: NO
[2026-03-31 04:23:09] [INFO] TaxCore integration is disabled - skipping TaxCore submission
[2026-03-31 04:23:09] [INFO] TaxCore call completed successfully
[2026-03-31 04:23:09] [INFO] TaxCore response: {
    "skipped": true,
    "reason": "TaxCore integration disabled for this organization",
    "invoiceNumber": null
}
[2026-03-31 04:23:09] [DEBUG] STEP 10: Updating quotations record with TaxCore and Journal Entry details
[2026-03-31 04:23:09] [DEBUG] Update data prepared: {"quotation_id":"f1746972-3828-4fc2-9d34-3735072bc4f1"}
[2026-03-31 04:23:09] [INFO] Quotations record updated successfully
[2026-03-31 04:23:09] [INFO] Skipping sales_receipts insert - TaxCore disabled or submission failed
[2026-03-31 04:23:09] [DEBUG] STEP 12: Saving audit file to storage
[2026-03-31 04:23:09] [DEBUG] Storage file path: /var/www/POS/storage/quotations/quotation_f1746972-3828-4fc2-9d34-3735072bc4f1_2026-03-31_04-23-09.json
[2026-03-31 04:23:09] [INFO] Audit file saved successfully to: /var/www/POS/storage/quotations/quotation_f1746972-3828-4fc2-9d34-3735072bc4f1_2026-03-31_04-23-09.json
[2026-03-31 04:23:09] [DEBUG] STEP 13: Preparing final result
[2026-03-31 04:23:09] [INFO] ========== SUCCESS: Process completed ==========
[2026-03-31 04:23:09] [INFO] Final result: {"success":true,"message":"Quotations processed successfully (TaxCore disabled)","record_id":"f1746972-3828-4fc2-9d34-3735072bc4f1","table":"quotations","invoice_type":"proforma","taxcore_enabled":false,"journal_entry_id":null,"journal_entry_number":null,"taxcore_invoice_number":null,"taxcore_verification_url":null,"taxcore_skipped":true,"processed_at":"2026-03-31 04:23:09","saved_to":"\/var\/www\/POS\/storage\/quotations\/quotation_f1746972-3828-4fc2-9d34-3735072bc4f1_2026-03-31_04-23-09.json","log_file":"\/var\/www\/POS\/storage\/quotations\/logs\/quotation_f1746972-3828-4fc2-9d34-3735072bc4f1_2026-03-31_04-23-09.log"}
[2026-03-31 04:23:09] [INFO] ===========================================
[2026-03-31 04:23:09] [INFO] Quotations Processor Log
[2026-03-31 04:23:09] [INFO] Record ID: f1746972-3828-4fc2-9d34-3735072bc4f1
[2026-03-31 04:23:09] [INFO] Table: quotations
[2026-03-31 04:23:09] [INFO] Timestamp: 2026-03-31 04:23:09
[2026-03-31 04:23:09] [INFO] ===========================================
[2026-03-31 04:23:09] [INFO] ========== START: processQuotationSubmission ==========
[2026-03-31 04:23:09] [INFO] Function called for record ID: f1746972-3828-4fc2-9d34-3735072bc4f1
[2026-03-31 04:23:09] [DEBUG] Form data received: {"table":"quotations","tenant_id":"019b9c9c-9d60-79d0-3ec5-849b68cdb9da"}
[2026-03-31 04:23:09] [INFO] Detected table: quotations (Type: proforma)
[2026-03-31 04:23:09] [DEBUG] ID field: quotation_id, Number field: quotation_number
[2026-03-31 04:23:09] [DEBUG] STEP 1: Fetching quotation data from database
[2026-03-31 04:23:09] [DEBUG] QueryBuilder instance created
[2026-03-31 04:23:09] [DEBUG] Database query executed for quotation_id: f1746972-3828-4fc2-9d34-3735072bc4f1
[2026-03-31 04:23:09] [DEBUG] Quotation found successfully
[2026-03-31 04:23:09] [INFO] quotation_type from record overrides invoiceType: proforma
[2026-03-31 04:23:09] [DEBUG] Using org_id: 019b9c9c-9d60-79d0-3ec5-849b68cdb9da
[2026-03-31 04:23:09] [INFO] Fetched quotation data: {"quotation_id":"f1746972-3828-4fc2-9d34-3735072bc4f1","quotation_number":"00002","date":"2026-03-31","customer_id":"019bb59b-f3bc-7091-b426-1ed577d19144","org_id":"019b9c9c-9d60-79d0-3ec5-849b68cdb9da","client_id":null,"line_items":"[{\"quantity\": \"4\", \"vat_rate\": \"VIP\", \"line_total\": \"348.64\", \"product_id\": \"000019ba-60c9-793a-2e57-55ac82f7d61e\", \"unit_price\": \"87.16\", \"vat_amount\": \"38.74\", \"description\": \"Rooster sp\", \"line_subtotal\": \"348.64\"}, {\"quantity\": \"3\", \"vat_rate\": \"VIP\", \"line_total\": \"447.75\", \"product_id\": \"000019ba-6096-762a-ac9a-5f26483b400a\", \"unit_price\": \"149.25\", \"vat_amount\": \"49.75\", \"description\": \"Rooster 18\", \"line_subtotal\": \"447.75\"}, {\"quantity\": \"3\", \"vat_rate\": \"VIP\", \"line_total\": \"456.36\", \"product_id\": \"000019ba-607e-7972-f446-529bc618ace3\", \"unit_price\": \"152.12\", \"vat_amount\": \"50.71\", \"description\": \"Rooster 16\", \"line_subtotal\": \"456.36\"}, {\"quantity\": \"2\", \"vat_rate\": \"VIP\", \"line_total\": \"280.2\", \"product_id\": \"000019ba-5fc8-73a1-c75e-d8f02babd138\", \"unit_price\": \"140.10\", \"vat_amount\": \"31.13\", \"description\": \"Rooster 12\", \"line_subtotal\": \"280.2\"}, {\"quantity\": \"20\", \"vat_rate\": \"VIP\", \"line_total\": \"359\", \"product_id\": \"000019bb-e755-7bba-a955-6ad4d7bb7dd3\", \"unit_price\": \"17.95\", \"vat_amount\": \"39.89\", \"description\": \"lamb neck X1kg\", \"line_subtotal\": \"359\"}]","note":null,"terms":null,"validity_days":30,"status":"expired","total_amount":"0.00","tax_amount":"0.00","template_id":null,"sent_at":null,"expires_at":"2026-03-31","accepted_at":null,"rejected_at":null,"rejection_reason":null,"converted_invoice_id":null,"created_by":null,"updated_by":null,"isdeleted":false,"updatedat":"2026-03-31 04:23:09.581917+00","taxcore_submission_id":null,"taxcore_submission_id_fk":null,"taxcore_receipt_data":null,"taxcore_submitted_at":null,"taxcore_verification_url":null,"taxcore_qr_code":null,"journal_entry_id":null,"converted_to_invoice_id":null,"po_number":null,"notes_additional":null,"payment_terms_details":null,"quotation_type":"proforma"}
[2026-03-31 04:23:09] [DEBUG] STEP 2: Parsing line_items JSON
[2026-03-31 04:23:09] [DEBUG] Parsed 5 line items
[2026-03-31 04:23:09] [DEBUG] Line items: [{"quantity":"4","vat_rate":"VIP","line_total":"348.64","product_id":"000019ba-60c9-793a-2e57-55ac82f7d61e","unit_price":"87.16","vat_amount":"38.74","description":"Rooster sp","line_subtotal":"348.64"},{"quantity":"3","vat_rate":"VIP","line_total":"447.75","product_id":"000019ba-6096-762a-ac9a-5f26483b400a","unit_price":"149.25","vat_amount":"49.75","description":"Rooster 18","line_subtotal":"447.75"},{"quantity":"3","vat_rate":"VIP","line_total":"456.36","product_id":"000019ba-607e-7972-f446-529bc618ace3","unit_price":"152.12","vat_amount":"50.71","description":"Rooster 16","line_subtotal":"456.36"},{"quantity":"2","vat_rate":"VIP","line_total":"280.2","product_id":"000019ba-5fc8-73a1-c75e-d8f02babd138","unit_price":"140.10","vat_amount":"31.13","description":"Rooster 12","line_subtotal":"280.2"},{"quantity":"20","vat_rate":"VIP","line_total":"359","product_id":"000019bb-e755-7bba-a955-6ad4d7bb7dd3","unit_price":"17.95","vat_amount":"39.89","description":"lamb neck X1kg","line_subtotal":"359"}]
[2026-03-31 04:23:09] [DEBUG] STEP 3: Preparing items for TaxCore
[2026-03-31 04:23:09] [DEBUG] Processing line item: 0 -> {"quantity":"4","vat_rate":"VIP","line_total":"348.64","product_id":"000019ba-60c9-793a-2e57-55ac82f7d61e","unit_price":"87.16","vat_amount":"38.74","description":"Rooster sp","line_subtotal":"348.64"}
[2026-03-31 04:23:09] [DEBUG] Calculated - Quantity: 4, UnitPrice: 87.16, TotalAmount: 348.64
[2026-03-31 04:23:09] [DEBUG] Processing line item: 1 -> {"quantity":"3","vat_rate":"VIP","line_total":"447.75","product_id":"000019ba-6096-762a-ac9a-5f26483b400a","unit_price":"149.25","vat_amount":"49.75","description":"Rooster 18","line_subtotal":"447.75"}
[2026-03-31 04:23:09] [DEBUG] Calculated - Quantity: 3, UnitPrice: 149.25, TotalAmount: 447.75
[2026-03-31 04:23:09] [DEBUG] Processing line item: 2 -> {"quantity":"3","vat_rate":"VIP","line_total":"456.36","product_id":"000019ba-607e-7972-f446-529bc618ace3","unit_price":"152.12","vat_amount":"50.71","description":"Rooster 16","line_subtotal":"456.36"}
[2026-03-31 04:23:09] [DEBUG] Calculated - Quantity: 3, UnitPrice: 152.12, TotalAmount: 456.36
[2026-03-31 04:23:09] [DEBUG] Processing line item: 3 -> {"quantity":"2","vat_rate":"VIP","line_total":"280.2","product_id":"000019ba-5fc8-73a1-c75e-d8f02babd138","unit_price":"140.10","vat_amount":"31.13","description":"Rooster 12","line_subtotal":"280.2"}
[2026-03-31 04:23:09] [DEBUG] Calculated - Quantity: 2, UnitPrice: 140.1, TotalAmount: 280.2
[2026-03-31 04:23:09] [DEBUG] Processing line item: 4 -> {"quantity":"20","vat_rate":"VIP","line_total":"359","product_id":"000019bb-e755-7bba-a955-6ad4d7bb7dd3","unit_price":"17.95","vat_amount":"39.89","description":"lamb neck X1kg","line_subtotal":"359"}
[2026-03-31 04:23:09] [DEBUG] Calculated - Quantity: 20, UnitPrice: 17.95, TotalAmount: 359
[2026-03-31 04:23:09] [DEBUG] Prepared 5 items for TaxCore
[2026-03-31 04:23:09] [INFO] TaxCore items: [{"name":"Rooster sp","quantity":4,"unitPrice":"87.16","totalAmount":"348.64","Labels":["G"]},{"name":"Rooster 18","quantity":3,"unitPrice":"149.25","totalAmount":"447.75","Labels":["G"]},{"name":"Rooster 16","quantity":3,"unitPrice":"152.12","totalAmount":"456.36","Labels":["G"]},{"name":"Rooster 12","quantity":2,"unitPrice":"140.10","totalAmount":"280.20","Labels":["G"]},{"name":"lamb neck X1kg","quantity":20,"unitPrice":"17.95","totalAmount":"359.00","Labels":["G"]}]
[2026-03-31 04:23:09] [DEBUG] STEP 4: Preparing payment method as Credit
[2026-03-31 04:23:09] [INFO] Payment prepared (Credit): [{"paymentType":"0","amount":0}]
[2026-03-31 04:23:09] [DEBUG] STEP 5: Fetching cashier information
[2026-03-31 04:23:09] [DEBUG] User ID from formData: 019b9c9c-9d60-79d0-3ec5-849b68cdb9da
[2026-03-31 04:23:09] [DEBUG] Querying users table for user_id: 019b9c9c-9d60-79d0-3ec5-849b68cdb9da
[2026-03-31 04:23:09] [INFO] Cashier name found: System
[2026-03-31 04:23:09] [DEBUG] STEP 6: Building TaxCore payload
[2026-03-31 04:23:09] [DEBUG] Base payload created with type=proforma
[2026-03-31 04:23:09] [DEBUG] STEP 7: Adding customer/buyer information
[2026-03-31 04:23:09] [DEBUG] Customer ID found: 019bb59b-f3bc-7091-b426-1ed577d19144
[2026-03-31 04:23:09] [DEBUG] Customer found: {"name":"Keyasi Convenient","tin":null}
[2026-03-31 04:23:09] [INFO] TaxCore payload prepared: {
    "items": [
        {
            "name": "Rooster sp",
            "quantity": 4,
            "unitPrice": "87.16",
            "totalAmount": "348.64",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Rooster 18",
            "quantity": 3,
            "unitPrice": "149.25",
            "totalAmount": "447.75",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Rooster 16",
            "quantity": 3,
            "unitPrice": "152.12",
            "totalAmount": "456.36",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Rooster 12",
            "quantity": 2,
            "unitPrice": "140.10",
            "totalAmount": "280.20",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "lamb neck X1kg",
            "quantity": 20,
            "unitPrice": "17.95",
            "totalAmount": "359.00",
            "Labels": [
                "G"
            ]
        }
    ],
    "payment": [
        {
            "paymentType": "0",
            "amount": 0
        }
    ],
    "Cashier": "System",
    "type": "proforma",
    "invoiceNumber": "00002",
    "Buyer": {
        "Name": "Keyasi Convenient"
    }
}
[2026-03-31 04:23:09] [DEBUG] STEP 8: Creating Journal Entry in Finance module
[2026-03-31 04:23:09] [INFO] --- createJournalEntry: Starting ---
[2026-03-31 04:23:09] [INFO] Is Cancelled/Refund: NO
[2026-03-31 04:23:09] [DEBUG] Calculated totals - Subtotal: 1891.95, Tax: 236.49375, Total: 2128.44375
[2026-03-31 04:23:09] [DEBUG] Looking for customer-specific AR account for: Keyasi Convenient
[2026-03-31 04:23:09] [INFO] Found customer-specific AR account: 1300-098 - AR - Keyasi Convenient
[2026-03-31 04:23:09] [DEBUG] Found GL accounts - Revenue: 4000, Tax: 2410, Receivables: 1300-098 (AR - Keyasi Convenient)
[2026-03-31 04:23:09] [DEBUG] Journal entry header prepared: {"id":"5d1e8879-9dae-4f67-ba73-6089bee214ad","entry_date":"2026-03-31","description":"Quotation 00002","reference":"00002","source_module":"quotations","source_id":"f1746972-3828-4fc2-9d34-3735072bc4f1","total_debits":2128.44375,"total_credits":2128.44375,"status":"posted","is_balanced":true,"created_by":null,"org_id":null,"posted_at":"2026-03-31 04:23:09","posted_by":null}
[2026-03-31 04:23:09] [ERROR] ERROR creating journal entry: SQL Error: SQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint "idx_journal_entries_unique_source"
DETAIL:  Key (source_module, source_id)=(quotations, f1746972-3828-4fc2-9d34-3735072bc4f1) already exists. | Query: INSERT INTO "gl_journal_entries" ("id", "entry_date", "description", "reference", "source_module", "source_id", "total_debits", "total_credits", "status", "is_balanced", "created_by", "org_id", "posted_at", "posted_by", "branch_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id
[2026-03-31 04:23:09] [ERROR] Stack trace: #0 /var/www/POS/api/utils/DB.php(231): Core\DB->runQuery()
#1 /var/www/POS/api/utils/QueryBuilder.php(466): Core\DB->insert()
#2 /var/www/POS/api/services/QuotationsProcessor.php(640): Core\QueryBuilder->insert()
#3 /var/www/POS/api/services/QuotationsProcessor.php(301): App\Services\QuotationsProcessor::createJournalEntry()
#4 [internal function]: App\Services\QuotationsProcessor::processQuotationSubmission()
#5 /var/www/POS/api/services/workflow_steps/CustomFunctionStep.php(121): call_user_func_array()
#6 /var/www/POS/api/services/WorkflowEngine.php(507): App\Services\WorkflowSteps\CustomFunctionStep->execute()
#7 /var/www/POS/api/services/WorkflowEngine.php(766): App\Services\WorkflowEngine->executeStep()
#8 /var/www/POS/api/services/WorkflowEngine.php(143): App\Services\WorkflowEngine->runSteps()
#9 /var/www/POS/api/services/WorkflowEngine.php(176): App\Services\WorkflowEngine->handleEvent()
#10 /var/www/POS/api/services/WorkflowEngine.php(188): App\Services\WorkflowEngine->emit()
#11 /var/www/POS/api/controllers/GenericController.php(373): App\Services\WorkflowEngine::trigger()
#12 /var/www/POS/api/controllers/SyncController.php(202): App\Controllers\GenericController->processWorkflowEvents()
#13 /var/www/POS/api/controllers/SyncController.php(214): App\Controllers\GenericController@anonymous->exec()
#14 /var/www/POS/api/controllers/SyncController.php(1308): App\Controllers\SyncController->triggerWorkflow()
#15 /var/www/POS/api/router.php(226): App\Controllers\SyncController->push()
#16 /var/www/POS/api/index.php(32): require_once('...')
#17 {main}
[2026-03-31 04:23:09] [WARN] WARNING: Journal entry creation failed: SQL Error: SQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint "idx_journal_entries_unique_source"
DETAIL:  Key (source_module, source_id)=(quotations, f1746972-3828-4fc2-9d34-3735072bc4f1) already exists. | Query: INSERT INTO "gl_journal_entries" ("id", "entry_date", "description", "reference", "source_module", "source_id", "total_debits", "total_credits", "status", "is_balanced", "created_by", "org_id", "posted_at", "posted_by", "branch_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id
[2026-03-31 04:23:09] [DEBUG] STEP 9: Checking if TaxCore integration is enabled
[2026-03-31 04:23:09] [DEBUG] Checking TaxCore integration status for org_id: 019b9c9c-9d60-79d0-3ec5-849b68cdb9da (table: quotations)
[2026-03-31 04:23:09] [INFO] TIN found, TaxCore could be enabled but no explicit setting - defaulting to false for safety
[2026-03-31 04:23:09] [INFO] No TaxCore configuration found for org_id: 019b9c9c-9d60-79d0-3ec5-849b68cdb9da, defaulting to disabled
[2026-03-31 04:23:09] [INFO] TaxCore integration enabled: NO
[2026-03-31 04:23:09] [INFO] TaxCore integration is disabled - skipping TaxCore submission
[2026-03-31 04:23:09] [INFO] TaxCore call completed successfully
[2026-03-31 04:23:09] [INFO] TaxCore response: {
    "skipped": true,
    "reason": "TaxCore integration disabled for this organization",
    "invoiceNumber": null
}
[2026-03-31 04:23:09] [DEBUG] STEP 10: Updating quotations record with TaxCore and Journal Entry details
[2026-03-31 04:23:09] [DEBUG] Update data prepared: {"quotation_id":"f1746972-3828-4fc2-9d34-3735072bc4f1"}
[2026-03-31 04:23:09] [INFO] Quotations record updated successfully
[2026-03-31 04:23:09] [INFO] Skipping sales_receipts insert - TaxCore disabled or submission failed
[2026-03-31 04:23:09] [DEBUG] STEP 12: Saving audit file to storage
[2026-03-31 04:23:09] [DEBUG] Storage file path: /var/www/POS/storage/quotations/quotation_f1746972-3828-4fc2-9d34-3735072bc4f1_2026-03-31_04-23-09.json
[2026-03-31 04:23:09] [INFO] Audit file saved successfully to: /var/www/POS/storage/quotations/quotation_f1746972-3828-4fc2-9d34-3735072bc4f1_2026-03-31_04-23-09.json
[2026-03-31 04:23:09] [DEBUG] STEP 13: Preparing final result
[2026-03-31 04:23:09] [INFO] ========== SUCCESS: Process completed ==========
[2026-03-31 04:23:09] [INFO] Final result: {"success":true,"message":"Quotations processed successfully (TaxCore disabled)","record_id":"f1746972-3828-4fc2-9d34-3735072bc4f1","table":"quotations","invoice_type":"proforma","taxcore_enabled":false,"journal_entry_id":null,"journal_entry_number":null,"taxcore_invoice_number":null,"taxcore_verification_url":null,"taxcore_skipped":true,"processed_at":"2026-03-31 04:23:09","saved_to":"\/var\/www\/POS\/storage\/quotations\/quotation_f1746972-3828-4fc2-9d34-3735072bc4f1_2026-03-31_04-23-09.json","log_file":"\/var\/www\/POS\/storage\/quotations\/logs\/quotation_f1746972-3828-4fc2-9d34-3735072bc4f1_2026-03-31_04-23-09.log"}
