[2026-03-29 21:30:50] [INFO] ===========================================
[2026-03-29 21:30:50] [INFO] Quotations Processor Log
[2026-03-29 21:30:50] [INFO] Record ID: dbeb5ecc-00d4-4b5c-8933-cbe145718dfd
[2026-03-29 21:30:50] [INFO] Table: quotations
[2026-03-29 21:30:50] [INFO] Timestamp: 2026-03-29 21:30:50
[2026-03-29 21:30:50] [INFO] ===========================================
[2026-03-29 21:30:50] [INFO] ========== START: processQuotationSubmission ==========
[2026-03-29 21:30:50] [INFO] Function called for record ID: dbeb5ecc-00d4-4b5c-8933-cbe145718dfd
[2026-03-29 21:30:50] [DEBUG] Form data received: {"table":"quotations","tenant_id":"019bafe2-05ad-7b4a-c449-ebcb1b933597"}
[2026-03-29 21:30:50] [INFO] Detected table: quotations (Type: proforma)
[2026-03-29 21:30:50] [DEBUG] ID field: quotation_id, Number field: quotation_number
[2026-03-29 21:30:50] [DEBUG] STEP 1: Fetching quotation data from database
[2026-03-29 21:30:50] [DEBUG] QueryBuilder instance created
[2026-03-29 21:30:50] [DEBUG] Database query executed for quotation_id: dbeb5ecc-00d4-4b5c-8933-cbe145718dfd
[2026-03-29 21:30:50] [DEBUG] Quotation found successfully
[2026-03-29 21:30:50] [INFO] quotation_type from record overrides invoiceType: proforma
[2026-03-29 21:30:50] [DEBUG] Using org_id: 019bafe2-05ad-7b4a-c449-ebcb1b933597
[2026-03-29 21:30:50] [INFO] Fetched quotation data: {"quotation_id":"dbeb5ecc-00d4-4b5c-8933-cbe145718dfd","quotation_number":"00056","date":"2026-03-30","customer_id":"019bd483-6577-7a66-9ac3-652ee8c6e1e9","org_id":"019bafe2-05ad-7b4a-c449-ebcb1b933597","client_id":null,"line_items":"[{\"quantity\": \"15.1\", \"vat_rate\": \"12.5\", \"line_total\": \"721.97\", \"product_id\": \"019be940-6ff7-7437-8e1b-41c1f7089219\", \"unit_price\": \"42.50\", \"vat_amount\": \"80.22\", \"description\": \"Walu Fillets\", \"line_subtotal\": \"641.75\"}, {\"quantity\": \"10.1\", \"vat_rate\": \"12.5\", \"line_total\": \"357.92\", \"product_id\": \"019bedb2-e0b3-7f78-9754-137b11823e91\", \"unit_price\": \"31.50\", \"vat_amount\": \"39.77\", \"description\": \"Tuna Fillets\", \"line_subtotal\": \"318.15\"}, {\"quantity\": \"10.3\", \"vat_rate\": \"12.5\", \"line_total\": \"492.47\", \"product_id\": \"019bedb5-d4a9-7f24-9675-32d1a6308c43\", \"unit_price\": \"42.50\", \"vat_amount\": \"54.72\", \"description\": \"Mahimahi Fillets\", \"line_subtotal\": \"437.75\"}, {\"quantity\": \"10.2\", \"vat_rate\": \"12.5\", \"line_total\": \"476.21\", \"product_id\": \"019c8784-b5e3-7ce0-a28f-9c375ac62530\", \"unit_price\": \"41.50\", \"vat_amount\": \"52.91\", \"description\": \"Snapper Fillets\", \"line_subtotal\": \"423.3\"}, {\"quantity\": \"10.5\", \"vat_rate\": \"12.5\", \"line_total\": \"502.03\", \"product_id\": \"019be94e-d15c-75f8-ba90-bcd687829c19\", \"unit_price\": \"42.50\", \"vat_amount\": \"55.78\", \"description\": \"Opakapaka Fillets\", \"line_subtotal\": \"446.25\"}, {\"quantity\": \"10.6\", \"vat_rate\": \"12.5\", \"line_total\": \"375.64\", \"product_id\": \"019be93d-696a-7adb-973a-9e97172fe156\", \"unit_price\": \"31.50\", \"vat_amount\": \"41.74\", \"description\": \"Marlin Fillets \", \"line_subtotal\": \"333.9\"}]","note":null,"terms":null,"validity_days":30,"status":"draft","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-29 21:30:50.558091+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":"PO 13761","notes_additional":null,"payment_terms_details":null,"quotation_type":"proforma"}
[2026-03-29 21:30:50] [DEBUG] STEP 2: Parsing line_items JSON
[2026-03-29 21:30:50] [DEBUG] Parsed 6 line items
[2026-03-29 21:30:50] [DEBUG] Line items: [{"quantity":"15.1","vat_rate":"12.5","line_total":"721.97","product_id":"019be940-6ff7-7437-8e1b-41c1f7089219","unit_price":"42.50","vat_amount":"80.22","description":"Walu Fillets","line_subtotal":"641.75"},{"quantity":"10.1","vat_rate":"12.5","line_total":"357.92","product_id":"019bedb2-e0b3-7f78-9754-137b11823e91","unit_price":"31.50","vat_amount":"39.77","description":"Tuna Fillets","line_subtotal":"318.15"},{"quantity":"10.3","vat_rate":"12.5","line_total":"492.47","product_id":"019bedb5-d4a9-7f24-9675-32d1a6308c43","unit_price":"42.50","vat_amount":"54.72","description":"Mahimahi Fillets","line_subtotal":"437.75"},{"quantity":"10.2","vat_rate":"12.5","line_total":"476.21","product_id":"019c8784-b5e3-7ce0-a28f-9c375ac62530","unit_price":"41.50","vat_amount":"52.91","description":"Snapper Fillets","line_subtotal":"423.3"},{"quantity":"10.5","vat_rate":"12.5","line_total":"502.03","product_id":"019be94e-d15c-75f8-ba90-bcd687829c19","unit_price":"42.50","vat_amount":"55.78","description":"Opakapaka Fillets","line_subtotal":"446.25"},{"quantity":"10.6","vat_rate":"12.5","line_total":"375.64","product_id":"019be93d-696a-7adb-973a-9e97172fe156","unit_price":"31.50","vat_amount":"41.74","description":"Marlin Fillets ","line_subtotal":"333.9"}]
[2026-03-29 21:30:50] [DEBUG] STEP 3: Preparing items for TaxCore
[2026-03-29 21:30:50] [DEBUG] Processing line item: 0 -> {"quantity":"15.1","vat_rate":"12.5","line_total":"721.97","product_id":"019be940-6ff7-7437-8e1b-41c1f7089219","unit_price":"42.50","vat_amount":"80.22","description":"Walu Fillets","line_subtotal":"641.75"}
[2026-03-29 21:30:50] [DEBUG] Calculated - Quantity: 15.1, UnitPrice: 42.5, TotalAmount: 641.75
[2026-03-29 21:30:50] [DEBUG] Processing line item: 1 -> {"quantity":"10.1","vat_rate":"12.5","line_total":"357.92","product_id":"019bedb2-e0b3-7f78-9754-137b11823e91","unit_price":"31.50","vat_amount":"39.77","description":"Tuna Fillets","line_subtotal":"318.15"}
[2026-03-29 21:30:50] [DEBUG] Calculated - Quantity: 10.1, UnitPrice: 31.5, TotalAmount: 318.15
[2026-03-29 21:30:50] [DEBUG] Processing line item: 2 -> {"quantity":"10.3","vat_rate":"12.5","line_total":"492.47","product_id":"019bedb5-d4a9-7f24-9675-32d1a6308c43","unit_price":"42.50","vat_amount":"54.72","description":"Mahimahi Fillets","line_subtotal":"437.75"}
[2026-03-29 21:30:50] [DEBUG] Calculated - Quantity: 10.3, UnitPrice: 42.5, TotalAmount: 437.75
[2026-03-29 21:30:50] [DEBUG] Processing line item: 3 -> {"quantity":"10.2","vat_rate":"12.5","line_total":"476.21","product_id":"019c8784-b5e3-7ce0-a28f-9c375ac62530","unit_price":"41.50","vat_amount":"52.91","description":"Snapper Fillets","line_subtotal":"423.3"}
[2026-03-29 21:30:50] [DEBUG] Calculated - Quantity: 10.2, UnitPrice: 41.5, TotalAmount: 423.3
[2026-03-29 21:30:50] [DEBUG] Processing line item: 4 -> {"quantity":"10.5","vat_rate":"12.5","line_total":"502.03","product_id":"019be94e-d15c-75f8-ba90-bcd687829c19","unit_price":"42.50","vat_amount":"55.78","description":"Opakapaka Fillets","line_subtotal":"446.25"}
[2026-03-29 21:30:50] [DEBUG] Calculated - Quantity: 10.5, UnitPrice: 42.5, TotalAmount: 446.25
[2026-03-29 21:30:50] [DEBUG] Processing line item: 5 -> {"quantity":"10.6","vat_rate":"12.5","line_total":"375.64","product_id":"019be93d-696a-7adb-973a-9e97172fe156","unit_price":"31.50","vat_amount":"41.74","description":"Marlin Fillets ","line_subtotal":"333.9"}
[2026-03-29 21:30:50] [DEBUG] Calculated - Quantity: 10.6, UnitPrice: 31.5, TotalAmount: 333.9
[2026-03-29 21:30:50] [DEBUG] Prepared 6 items for TaxCore
[2026-03-29 21:30:50] [INFO] TaxCore items: [{"name":"Walu Fillets","quantity":15.1,"unitPrice":"42.50","totalAmount":"641.75","Labels":["G"]},{"name":"Tuna Fillets","quantity":10.1,"unitPrice":"31.50","totalAmount":"318.15","Labels":["G"]},{"name":"Mahimahi Fillets","quantity":10.3,"unitPrice":"42.50","totalAmount":"437.75","Labels":["G"]},{"name":"Snapper Fillets","quantity":10.2,"unitPrice":"41.50","totalAmount":"423.30","Labels":["G"]},{"name":"Opakapaka Fillets","quantity":10.5,"unitPrice":"42.50","totalAmount":"446.25","Labels":["G"]},{"name":"Marlin Fillets ","quantity":10.6,"unitPrice":"31.50","totalAmount":"333.90","Labels":["G"]}]
[2026-03-29 21:30:50] [DEBUG] STEP 4: Preparing payment method as Credit
[2026-03-29 21:30:50] [INFO] Payment prepared (Credit): [{"paymentType":"0","amount":0}]
[2026-03-29 21:30:50] [DEBUG] STEP 5: Fetching cashier information
[2026-03-29 21:30:50] [DEBUG] User ID from formData: 019bafe2-05ad-7b4a-c449-ebcb1b933597
[2026-03-29 21:30:50] [DEBUG] Querying users table for user_id: 019bafe2-05ad-7b4a-c449-ebcb1b933597
[2026-03-29 21:30:50] [INFO] Cashier name found: System
[2026-03-29 21:30:50] [DEBUG] STEP 6: Building TaxCore payload
[2026-03-29 21:30:50] [DEBUG] Base payload created with type=proforma
[2026-03-29 21:30:50] [DEBUG] STEP 7: Adding customer/buyer information
[2026-03-29 21:30:50] [DEBUG] Customer ID found: 019bd483-6577-7a66-9ac3-652ee8c6e1e9
[2026-03-29 21:30:50] [DEBUG] Customer found: {"name":"Vomo Fiji Island Resort","tin":"00"}
[2026-03-29 21:30:50] [INFO] Buyer TIN added: 00
[2026-03-29 21:30:50] [INFO] TaxCore payload prepared: {
    "items": [
        {
            "name": "Walu Fillets",
            "quantity": 15.1,
            "unitPrice": "42.50",
            "totalAmount": "641.75",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Tuna Fillets",
            "quantity": 10.1,
            "unitPrice": "31.50",
            "totalAmount": "318.15",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Mahimahi Fillets",
            "quantity": 10.3,
            "unitPrice": "42.50",
            "totalAmount": "437.75",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Snapper Fillets",
            "quantity": 10.2,
            "unitPrice": "41.50",
            "totalAmount": "423.30",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Opakapaka Fillets",
            "quantity": 10.5,
            "unitPrice": "42.50",
            "totalAmount": "446.25",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Marlin Fillets ",
            "quantity": 10.6,
            "unitPrice": "31.50",
            "totalAmount": "333.90",
            "Labels": [
                "G"
            ]
        }
    ],
    "payment": [
        {
            "paymentType": "0",
            "amount": 0
        }
    ],
    "Cashier": "System",
    "type": "proforma",
    "invoiceNumber": "00056",
    "Buyer": {
        "Name": "Vomo Fiji Island Resort"
    },
    "buyerId": "00"
}
[2026-03-29 21:30:50] [DEBUG] STEP 8: Creating Journal Entry in Finance module
[2026-03-29 21:30:50] [INFO] --- createJournalEntry: Starting ---
[2026-03-29 21:30:50] [INFO] Is Cancelled/Refund: NO
[2026-03-29 21:30:50] [DEBUG] Calculated totals - Subtotal: 2601.1, Tax: 325.1375, Total: 2926.2375
[2026-03-29 21:30:50] [DEBUG] Looking for customer-specific AR account for: Vomo Fiji Island Resort
[2026-03-29 21:30:50] [INFO] Found customer-specific AR account: 1300-010 - AR - Vomo Fiji Island Resort
[2026-03-29 21:30:50] [DEBUG] Found GL accounts - Revenue: 4000, Tax: 2410, Receivables: 1300-010 (AR - Vomo Fiji Island Resort)
[2026-03-29 21:30:50] [DEBUG] Journal entry header prepared: {"id":"582005fd-d8bc-4926-94d1-ed08dbcd0b7b","entry_date":"2026-03-30","description":"Quotation 00056","reference":"00056","source_module":"quotations","source_id":"dbeb5ecc-00d4-4b5c-8933-cbe145718dfd","total_debits":2926.2374999999997,"total_credits":2926.2374999999997,"status":"posted","is_balanced":true,"created_by":null,"org_id":null,"posted_at":"2026-03-29 21:30:50","posted_by":null}
[2026-03-29 21:30:50] [INFO] Journal entry header created: 582005fd-d8bc-4926-94d1-ed08dbcd0b7b
[2026-03-29 21:30:50] [DEBUG] Prepared 3 journal lines
[2026-03-29 21:30:50] [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 (019bd483-6581-7007-9aaf-65b190a56c4c, null, 2926.24, 0.00, 2926.24, 2026-03-29 21:30:50.601721+00, 2026-03-30, 1, 2026-03-29 21:30:50.601721+00, 2026-03-29 21:30:50.601721+00, 019d3b81-b96b-77e8-9b9a-5c789267434d).
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-29 21:30:50] [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-29 21:30:50] [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 (019bd483-6581-7007-9aaf-65b190a56c4c, null, 2926.24, 0.00, 2926.24, 2026-03-29 21:30:50.601721+00, 2026-03-30, 1, 2026-03-29 21:30:50.601721+00, 2026-03-29 21:30:50.601721+00, 019d3b81-b96b-77e8-9b9a-5c789267434d).
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-29 21:30:50] [DEBUG] STEP 9: Checking if TaxCore integration is enabled
[2026-03-29 21:30:50] [DEBUG] Checking TaxCore integration status for org_id: 019bafe2-05ad-7b4a-c449-ebcb1b933597 (table: quotations)
[2026-03-29 21:30:50] [INFO] TIN found, TaxCore could be enabled but no explicit setting - defaulting to false for safety
[2026-03-29 21:30:50] [INFO] No TaxCore configuration found for org_id: 019bafe2-05ad-7b4a-c449-ebcb1b933597, defaulting to disabled
[2026-03-29 21:30:50] [INFO] TaxCore integration enabled: NO
[2026-03-29 21:30:50] [INFO] TaxCore integration is disabled - skipping TaxCore submission
[2026-03-29 21:30:50] [INFO] TaxCore call completed successfully
[2026-03-29 21:30:50] [INFO] TaxCore response: {
    "skipped": true,
    "reason": "TaxCore integration disabled for this organization",
    "invoiceNumber": null
}
[2026-03-29 21:30:50] [DEBUG] STEP 10: Updating quotations record with TaxCore and Journal Entry details
[2026-03-29 21:30:50] [DEBUG] Update data prepared: {"quotation_id":"dbeb5ecc-00d4-4b5c-8933-cbe145718dfd"}
[2026-03-29 21:30:50] [INFO] Quotations record updated successfully
[2026-03-29 21:30:50] [INFO] Skipping sales_receipts insert - TaxCore disabled or submission failed
[2026-03-29 21:30:50] [DEBUG] STEP 12: Saving audit file to storage
[2026-03-29 21:30:50] [DEBUG] Storage file path: /var/www/POS/storage/quotations/quotation_dbeb5ecc-00d4-4b5c-8933-cbe145718dfd_2026-03-29_21-30-50.json
[2026-03-29 21:30:50] [INFO] Audit file saved successfully to: /var/www/POS/storage/quotations/quotation_dbeb5ecc-00d4-4b5c-8933-cbe145718dfd_2026-03-29_21-30-50.json
[2026-03-29 21:30:50] [DEBUG] STEP 13: Preparing final result
[2026-03-29 21:30:50] [INFO] ========== SUCCESS: Process completed ==========
[2026-03-29 21:30:50] [INFO] Final result: {"success":true,"message":"Quotations processed successfully (TaxCore disabled)","record_id":"dbeb5ecc-00d4-4b5c-8933-cbe145718dfd","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-29 21:30:50","saved_to":"\/var\/www\/POS\/storage\/quotations\/quotation_dbeb5ecc-00d4-4b5c-8933-cbe145718dfd_2026-03-29_21-30-50.json","log_file":"\/var\/www\/POS\/storage\/quotations\/logs\/quotation_dbeb5ecc-00d4-4b5c-8933-cbe145718dfd_2026-03-29_21-30-50.log"}
[2026-03-29 21:30:50] [INFO] ===========================================
[2026-03-29 21:30:50] [INFO] Quotations Processor Log
[2026-03-29 21:30:50] [INFO] Record ID: dbeb5ecc-00d4-4b5c-8933-cbe145718dfd
[2026-03-29 21:30:50] [INFO] Table: quotations
[2026-03-29 21:30:50] [INFO] Timestamp: 2026-03-29 21:30:50
[2026-03-29 21:30:50] [INFO] ===========================================
[2026-03-29 21:30:50] [INFO] ========== START: processQuotationSubmission ==========
[2026-03-29 21:30:50] [INFO] Function called for record ID: dbeb5ecc-00d4-4b5c-8933-cbe145718dfd
[2026-03-29 21:30:50] [DEBUG] Form data received: {"table":"quotations","tenant_id":"019bafe2-05ad-7b4a-c449-ebcb1b933597"}
[2026-03-29 21:30:50] [INFO] Detected table: quotations (Type: proforma)
[2026-03-29 21:30:50] [DEBUG] ID field: quotation_id, Number field: quotation_number
[2026-03-29 21:30:50] [DEBUG] STEP 1: Fetching quotation data from database
[2026-03-29 21:30:50] [DEBUG] QueryBuilder instance created
[2026-03-29 21:30:50] [DEBUG] Database query executed for quotation_id: dbeb5ecc-00d4-4b5c-8933-cbe145718dfd
[2026-03-29 21:30:50] [DEBUG] Quotation found successfully
[2026-03-29 21:30:50] [INFO] quotation_type from record overrides invoiceType: proforma
[2026-03-29 21:30:50] [DEBUG] Using org_id: 019bafe2-05ad-7b4a-c449-ebcb1b933597
[2026-03-29 21:30:50] [INFO] Fetched quotation data: {"quotation_id":"dbeb5ecc-00d4-4b5c-8933-cbe145718dfd","quotation_number":"00056","date":"2026-03-30","customer_id":"019bd483-6577-7a66-9ac3-652ee8c6e1e9","org_id":"019bafe2-05ad-7b4a-c449-ebcb1b933597","client_id":null,"line_items":"[{\"quantity\": \"15.1\", \"vat_rate\": \"12.5\", \"line_total\": \"721.97\", \"product_id\": \"019be940-6ff7-7437-8e1b-41c1f7089219\", \"unit_price\": \"42.50\", \"vat_amount\": \"80.22\", \"description\": \"Walu Fillets\", \"line_subtotal\": \"641.75\"}, {\"quantity\": \"10.1\", \"vat_rate\": \"12.5\", \"line_total\": \"357.92\", \"product_id\": \"019bedb2-e0b3-7f78-9754-137b11823e91\", \"unit_price\": \"31.50\", \"vat_amount\": \"39.77\", \"description\": \"Tuna Fillets\", \"line_subtotal\": \"318.15\"}, {\"quantity\": \"10.3\", \"vat_rate\": \"12.5\", \"line_total\": \"492.47\", \"product_id\": \"019bedb5-d4a9-7f24-9675-32d1a6308c43\", \"unit_price\": \"42.50\", \"vat_amount\": \"54.72\", \"description\": \"Mahimahi Fillets\", \"line_subtotal\": \"437.75\"}, {\"quantity\": \"10.2\", \"vat_rate\": \"12.5\", \"line_total\": \"476.21\", \"product_id\": \"019c8784-b5e3-7ce0-a28f-9c375ac62530\", \"unit_price\": \"41.50\", \"vat_amount\": \"52.91\", \"description\": \"Snapper Fillets\", \"line_subtotal\": \"423.3\"}, {\"quantity\": \"10.5\", \"vat_rate\": \"12.5\", \"line_total\": \"502.03\", \"product_id\": \"019be94e-d15c-75f8-ba90-bcd687829c19\", \"unit_price\": \"42.50\", \"vat_amount\": \"55.78\", \"description\": \"Opakapaka Fillets\", \"line_subtotal\": \"446.25\"}, {\"quantity\": \"10.6\", \"vat_rate\": \"12.5\", \"line_total\": \"375.64\", \"product_id\": \"019be93d-696a-7adb-973a-9e97172fe156\", \"unit_price\": \"31.50\", \"vat_amount\": \"41.74\", \"description\": \"Marlin Fillets \", \"line_subtotal\": \"333.9\"}]","note":null,"terms":null,"validity_days":30,"status":"draft","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-29 21:30:50.605857+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":"PO 13761","notes_additional":null,"payment_terms_details":null,"quotation_type":"proforma"}
[2026-03-29 21:30:50] [DEBUG] STEP 2: Parsing line_items JSON
[2026-03-29 21:30:50] [DEBUG] Parsed 6 line items
[2026-03-29 21:30:50] [DEBUG] Line items: [{"quantity":"15.1","vat_rate":"12.5","line_total":"721.97","product_id":"019be940-6ff7-7437-8e1b-41c1f7089219","unit_price":"42.50","vat_amount":"80.22","description":"Walu Fillets","line_subtotal":"641.75"},{"quantity":"10.1","vat_rate":"12.5","line_total":"357.92","product_id":"019bedb2-e0b3-7f78-9754-137b11823e91","unit_price":"31.50","vat_amount":"39.77","description":"Tuna Fillets","line_subtotal":"318.15"},{"quantity":"10.3","vat_rate":"12.5","line_total":"492.47","product_id":"019bedb5-d4a9-7f24-9675-32d1a6308c43","unit_price":"42.50","vat_amount":"54.72","description":"Mahimahi Fillets","line_subtotal":"437.75"},{"quantity":"10.2","vat_rate":"12.5","line_total":"476.21","product_id":"019c8784-b5e3-7ce0-a28f-9c375ac62530","unit_price":"41.50","vat_amount":"52.91","description":"Snapper Fillets","line_subtotal":"423.3"},{"quantity":"10.5","vat_rate":"12.5","line_total":"502.03","product_id":"019be94e-d15c-75f8-ba90-bcd687829c19","unit_price":"42.50","vat_amount":"55.78","description":"Opakapaka Fillets","line_subtotal":"446.25"},{"quantity":"10.6","vat_rate":"12.5","line_total":"375.64","product_id":"019be93d-696a-7adb-973a-9e97172fe156","unit_price":"31.50","vat_amount":"41.74","description":"Marlin Fillets ","line_subtotal":"333.9"}]
[2026-03-29 21:30:50] [DEBUG] STEP 3: Preparing items for TaxCore
[2026-03-29 21:30:50] [DEBUG] Processing line item: 0 -> {"quantity":"15.1","vat_rate":"12.5","line_total":"721.97","product_id":"019be940-6ff7-7437-8e1b-41c1f7089219","unit_price":"42.50","vat_amount":"80.22","description":"Walu Fillets","line_subtotal":"641.75"}
[2026-03-29 21:30:50] [DEBUG] Calculated - Quantity: 15.1, UnitPrice: 42.5, TotalAmount: 641.75
[2026-03-29 21:30:50] [DEBUG] Processing line item: 1 -> {"quantity":"10.1","vat_rate":"12.5","line_total":"357.92","product_id":"019bedb2-e0b3-7f78-9754-137b11823e91","unit_price":"31.50","vat_amount":"39.77","description":"Tuna Fillets","line_subtotal":"318.15"}
[2026-03-29 21:30:50] [DEBUG] Calculated - Quantity: 10.1, UnitPrice: 31.5, TotalAmount: 318.15
[2026-03-29 21:30:50] [DEBUG] Processing line item: 2 -> {"quantity":"10.3","vat_rate":"12.5","line_total":"492.47","product_id":"019bedb5-d4a9-7f24-9675-32d1a6308c43","unit_price":"42.50","vat_amount":"54.72","description":"Mahimahi Fillets","line_subtotal":"437.75"}
[2026-03-29 21:30:50] [DEBUG] Calculated - Quantity: 10.3, UnitPrice: 42.5, TotalAmount: 437.75
[2026-03-29 21:30:50] [DEBUG] Processing line item: 3 -> {"quantity":"10.2","vat_rate":"12.5","line_total":"476.21","product_id":"019c8784-b5e3-7ce0-a28f-9c375ac62530","unit_price":"41.50","vat_amount":"52.91","description":"Snapper Fillets","line_subtotal":"423.3"}
[2026-03-29 21:30:50] [DEBUG] Calculated - Quantity: 10.2, UnitPrice: 41.5, TotalAmount: 423.3
[2026-03-29 21:30:50] [DEBUG] Processing line item: 4 -> {"quantity":"10.5","vat_rate":"12.5","line_total":"502.03","product_id":"019be94e-d15c-75f8-ba90-bcd687829c19","unit_price":"42.50","vat_amount":"55.78","description":"Opakapaka Fillets","line_subtotal":"446.25"}
[2026-03-29 21:30:50] [DEBUG] Calculated - Quantity: 10.5, UnitPrice: 42.5, TotalAmount: 446.25
[2026-03-29 21:30:50] [DEBUG] Processing line item: 5 -> {"quantity":"10.6","vat_rate":"12.5","line_total":"375.64","product_id":"019be93d-696a-7adb-973a-9e97172fe156","unit_price":"31.50","vat_amount":"41.74","description":"Marlin Fillets ","line_subtotal":"333.9"}
[2026-03-29 21:30:50] [DEBUG] Calculated - Quantity: 10.6, UnitPrice: 31.5, TotalAmount: 333.9
[2026-03-29 21:30:50] [DEBUG] Prepared 6 items for TaxCore
[2026-03-29 21:30:50] [INFO] TaxCore items: [{"name":"Walu Fillets","quantity":15.1,"unitPrice":"42.50","totalAmount":"641.75","Labels":["G"]},{"name":"Tuna Fillets","quantity":10.1,"unitPrice":"31.50","totalAmount":"318.15","Labels":["G"]},{"name":"Mahimahi Fillets","quantity":10.3,"unitPrice":"42.50","totalAmount":"437.75","Labels":["G"]},{"name":"Snapper Fillets","quantity":10.2,"unitPrice":"41.50","totalAmount":"423.30","Labels":["G"]},{"name":"Opakapaka Fillets","quantity":10.5,"unitPrice":"42.50","totalAmount":"446.25","Labels":["G"]},{"name":"Marlin Fillets ","quantity":10.6,"unitPrice":"31.50","totalAmount":"333.90","Labels":["G"]}]
[2026-03-29 21:30:50] [DEBUG] STEP 4: Preparing payment method as Credit
[2026-03-29 21:30:50] [INFO] Payment prepared (Credit): [{"paymentType":"0","amount":0}]
[2026-03-29 21:30:50] [DEBUG] STEP 5: Fetching cashier information
[2026-03-29 21:30:50] [DEBUG] User ID from formData: 019bafe2-05ad-7b4a-c449-ebcb1b933597
[2026-03-29 21:30:50] [DEBUG] Querying users table for user_id: 019bafe2-05ad-7b4a-c449-ebcb1b933597
[2026-03-29 21:30:50] [INFO] Cashier name found: System
[2026-03-29 21:30:50] [DEBUG] STEP 6: Building TaxCore payload
[2026-03-29 21:30:50] [DEBUG] Base payload created with type=proforma
[2026-03-29 21:30:50] [DEBUG] STEP 7: Adding customer/buyer information
[2026-03-29 21:30:50] [DEBUG] Customer ID found: 019bd483-6577-7a66-9ac3-652ee8c6e1e9
[2026-03-29 21:30:50] [DEBUG] Customer found: {"name":"Vomo Fiji Island Resort","tin":"00"}
[2026-03-29 21:30:50] [INFO] Buyer TIN added: 00
[2026-03-29 21:30:50] [INFO] TaxCore payload prepared: {
    "items": [
        {
            "name": "Walu Fillets",
            "quantity": 15.1,
            "unitPrice": "42.50",
            "totalAmount": "641.75",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Tuna Fillets",
            "quantity": 10.1,
            "unitPrice": "31.50",
            "totalAmount": "318.15",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Mahimahi Fillets",
            "quantity": 10.3,
            "unitPrice": "42.50",
            "totalAmount": "437.75",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Snapper Fillets",
            "quantity": 10.2,
            "unitPrice": "41.50",
            "totalAmount": "423.30",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Opakapaka Fillets",
            "quantity": 10.5,
            "unitPrice": "42.50",
            "totalAmount": "446.25",
            "Labels": [
                "G"
            ]
        },
        {
            "name": "Marlin Fillets ",
            "quantity": 10.6,
            "unitPrice": "31.50",
            "totalAmount": "333.90",
            "Labels": [
                "G"
            ]
        }
    ],
    "payment": [
        {
            "paymentType": "0",
            "amount": 0
        }
    ],
    "Cashier": "System",
    "type": "proforma",
    "invoiceNumber": "00056",
    "Buyer": {
        "Name": "Vomo Fiji Island Resort"
    },
    "buyerId": "00"
}
[2026-03-29 21:30:50] [DEBUG] STEP 8: Creating Journal Entry in Finance module
[2026-03-29 21:30:50] [INFO] --- createJournalEntry: Starting ---
[2026-03-29 21:30:50] [INFO] Is Cancelled/Refund: NO
[2026-03-29 21:30:50] [DEBUG] Calculated totals - Subtotal: 2601.1, Tax: 325.1375, Total: 2926.2375
[2026-03-29 21:30:50] [DEBUG] Looking for customer-specific AR account for: Vomo Fiji Island Resort
[2026-03-29 21:30:50] [INFO] Found customer-specific AR account: 1300-010 - AR - Vomo Fiji Island Resort
[2026-03-29 21:30:50] [DEBUG] Found GL accounts - Revenue: 4000, Tax: 2410, Receivables: 1300-010 (AR - Vomo Fiji Island Resort)
[2026-03-29 21:30:50] [DEBUG] Journal entry header prepared: {"id":"96b4e948-646c-4d2c-8d28-91a124e9f963","entry_date":"2026-03-30","description":"Quotation 00056","reference":"00056","source_module":"quotations","source_id":"dbeb5ecc-00d4-4b5c-8933-cbe145718dfd","total_debits":2926.2374999999997,"total_credits":2926.2374999999997,"status":"posted","is_balanced":true,"created_by":null,"org_id":null,"posted_at":"2026-03-29 21:30:50","posted_by":null}
[2026-03-29 21:30:50] [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, dbeb5ecc-00d4-4b5c-8933-cbe145718dfd) 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-29 21:30:50] [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-29 21:30:50] [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, dbeb5ecc-00d4-4b5c-8933-cbe145718dfd) 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-29 21:30:50] [DEBUG] STEP 9: Checking if TaxCore integration is enabled
[2026-03-29 21:30:50] [DEBUG] Checking TaxCore integration status for org_id: 019bafe2-05ad-7b4a-c449-ebcb1b933597 (table: quotations)
[2026-03-29 21:30:50] [INFO] TIN found, TaxCore could be enabled but no explicit setting - defaulting to false for safety
[2026-03-29 21:30:50] [INFO] No TaxCore configuration found for org_id: 019bafe2-05ad-7b4a-c449-ebcb1b933597, defaulting to disabled
[2026-03-29 21:30:50] [INFO] TaxCore integration enabled: NO
[2026-03-29 21:30:50] [INFO] TaxCore integration is disabled - skipping TaxCore submission
[2026-03-29 21:30:50] [INFO] TaxCore call completed successfully
[2026-03-29 21:30:50] [INFO] TaxCore response: {
    "skipped": true,
    "reason": "TaxCore integration disabled for this organization",
    "invoiceNumber": null
}
[2026-03-29 21:30:50] [DEBUG] STEP 10: Updating quotations record with TaxCore and Journal Entry details
[2026-03-29 21:30:50] [DEBUG] Update data prepared: {"quotation_id":"dbeb5ecc-00d4-4b5c-8933-cbe145718dfd"}
[2026-03-29 21:30:50] [INFO] Quotations record updated successfully
[2026-03-29 21:30:50] [INFO] Skipping sales_receipts insert - TaxCore disabled or submission failed
[2026-03-29 21:30:50] [DEBUG] STEP 12: Saving audit file to storage
[2026-03-29 21:30:50] [DEBUG] Storage file path: /var/www/POS/storage/quotations/quotation_dbeb5ecc-00d4-4b5c-8933-cbe145718dfd_2026-03-29_21-30-50.json
[2026-03-29 21:30:50] [INFO] Audit file saved successfully to: /var/www/POS/storage/quotations/quotation_dbeb5ecc-00d4-4b5c-8933-cbe145718dfd_2026-03-29_21-30-50.json
[2026-03-29 21:30:50] [DEBUG] STEP 13: Preparing final result
[2026-03-29 21:30:50] [INFO] ========== SUCCESS: Process completed ==========
[2026-03-29 21:30:50] [INFO] Final result: {"success":true,"message":"Quotations processed successfully (TaxCore disabled)","record_id":"dbeb5ecc-00d4-4b5c-8933-cbe145718dfd","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-29 21:30:50","saved_to":"\/var\/www\/POS\/storage\/quotations\/quotation_dbeb5ecc-00d4-4b5c-8933-cbe145718dfd_2026-03-29_21-30-50.json","log_file":"\/var\/www\/POS\/storage\/quotations\/logs\/quotation_dbeb5ecc-00d4-4b5c-8933-cbe145718dfd_2026-03-29_21-30-50.log"}
