'That document no longer exists.'])); } $client_id = intval($doc['client_id']); enforceClientAccess(); // Using AI is a permission of its own if (!aiCan()) { permissionRefuse(permissionRefusedText('module_ai', 1, 0)); } if (!billingCanEditItems($type, $doc)) { exit(json_encode(['error' => billingNumber($type, $doc) . " can't be changed now - " . ($type === 'quote' ? 'it has been answered or invoiced.' : 'it is paid, cancelled or non-billable.')])); } $t = billingType($type); $c = $t['col']; $number = billingNumber($type, $doc); $currency = (string) $doc["{$c}_currency_code"]; $scope = trim((string) $doc["{$c}_scope"]); $support = lookupUserPermission('module_support') >= 1; $ticket = $support ? aiBillingTicket($type, $doc_id) : null; $rate = contractClientRate($client_id)['rate']; $catalog_count = count(aiBillingCatalog()); $prompt = $scope !== '' ? $scope : ($ticket ? $ticket['ticket_subject'] : ''); $word = $type === 'quote' ? 'quote' : 'invoice'; ob_start(); ?>