100) { http_response_code(400); $return_arr['success'] = "False"; $return_arr['message'] = 'items is a list of up to 100 lines - each a product_id, or a name and price.'; echo json_encode($return_arr); exit(); } $lines = []; foreach (array_values($items) as $i => $item) { $line = billingLineFromApi($item, $client_id, $error, "items[$i]"); if (!$line) { http_response_code(400); $return_arr['success'] = "False"; $return_arr['message'] = $error; echo json_encode($return_arr); exit(); } if (array_key_exists('frequency', $item)) { $line['frequency'] = (string) $item['frequency']; } $lines[] = $line; } $date = isset($quote_set['quote_date']) ? trim($quote_set['quote_date'], "'") : date('Y-m-d'); $expire = isset($quote_set['quote_expire']) ? trim($quote_set['quote_expire'], "'") : date('Y-m-d', strtotime("$date +30 days")); $scope = $quote_set['quote_scope'] ?? "''"; $category_id = intval($quote_set['quote_category_id'] ?? 0); $discount = floatval($quote_set['quote_discount_amount'] ?? 0); $note = $quote_set['quote_note'] ?? "''"; // Atomically increment and get the new quote number $quote_number = billingNextNumber('quote'); $prefix = escapeSql($config_quote_prefix); $currency = escapeSql($session_company_currency); $url_key = randomString(32); $insert_sql = mysqli_query($mysqli, "INSERT INTO quotes SET quote_prefix = '$prefix', quote_number = $quote_number, quote_scope = $scope, quote_date = '$date', quote_expire = '$expire', quote_discount_amount = $discount, quote_amount = " . (0 - $discount) . ", quote_note = $note, quote_currency_code = '$currency', quote_category_id = $category_id, quote_status = 'Draft', quote_url_key = '$url_key', quote_client_id = $client_id"); if ($insert_sql) { $quote_id = mysqli_insert_id($mysqli); $insert_id = $quote_id; logHistory('Draft', "Quote created via API ($api_key_name)", 0, $quote_id); foreach ($lines as $line) { billingItemSave('quote', $quote_id, $line, 0, $error); } billingRecalc('quote', $quote_id); $quote = billingRow('quote', $quote_id, false); $reference = billingNumber('quote', $quote); $return_arr['quote_reference'] = $reference; $return_arr['amount'] = (float) $quote['quote_amount']; $return_arr['url'] = billingGuestUrl('quote', $quote); $reference = escapeSql($reference); logAudit("Quote", "Create", "Created quote $reference via API ($api_key_name)", $client_id, $quote_id); logAudit("API", "Success", "Created quote $reference via API ($api_key_name)", $client_id); triggerCustomAction('quote_create', $quote_id); } } // Output require_once '../create_output.php';