'That expense no longer exists.']); exit; } $expense_id = intval($row['expense_id']); $cleared = reconcileLock('expense', $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']) || !empty($row['reimbursement_out_id']); $is_payback = !empty($row['reimbursement_out_id']); $paid_by = intval($row['expense_paid_by']); $to_reimburse = $paid_by && !$row['expense_reimbursement_id'] && floatval($row['expense_amount']) > 0; $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"; // Mileage - the trips in their own vehicle this pays for (functions/trips.php) [$mileage_trips, $mileage_miles] = tripTotalsFor('trip_expense_id', $expense_id); // Billing it on to the client $can_sales = lookupUserPermission('module_sales'); $billed_on = intval($row['expense_invoice_id']); $cost = round($amount - floatval($row['refunded_amount']), 2); $billable = !$billed_on && intval($row['expense_billable']) && $client_id && $amount > 0 && !$is_transfer; $bill_price = expenseBillPrice($cost, $row['expense_markup']); $can_unbill = $billed_on && $can_edit && expenseCanUnbill($row['invoice_status']); // 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(); ?>