'That expense no longer exists.']); exit; } $expense_id = intval($row['expense_id']); $client_id = intval($row['expense_client_id']); $can_edit = lookupUserPermission('module_financial') >= 2; $can_delete = lookupUserPermission('module_financial') >= 3; $is_transfer = !empty($row['transfer_id']); $amount = floatval($row['expense_amount']); $currency = (string) $row['expense_currency_code']; $receipt_kind = $row['expense_receipt'] && expenseReceiptPath($row['expense_receipt']) !== '' ? expenseReceiptKind($row['expense_receipt']) : ''; $receipt_missing = $row['expense_receipt'] && $receipt_kind === '' && expenseReceiptPath($row['expense_receipt']) === ''; $receipt_url = "expense_receipt.php?expense_id=$expense_id"; // Refunds against it, and the stock it paid for $refunds = []; $sql = mysqli_query($mysqli, "SELECT expense_id, expense_date, expense_amount, expense_description FROM expenses WHERE expense_refund_of_id = $expense_id ORDER BY expense_date ASC, expense_id ASC"); while ($refund = mysqli_fetch_assoc($sql)) { $refunds[] = $refund; } $stock = []; $sql = mysqli_query($mysqli, "SELECT stock_qty, stock_unit_cost, stock_created_at, product_id, product_name FROM product_stock JOIN products ON product_id = stock_product_id WHERE stock_expense_id = $expense_id ORDER BY stock_id ASC"); while ($move = mysqli_fetch_assoc($sql)) { $stock[] = $move; } ob_start(); ?>