0) { $stmt = db()->prepare("SELECT * FROM shipments WHERE id = :id"); $stmt->execute([':id' => $shipmentId]); $shipment = $stmt->fetch(); } $errors = []; $flash = get_flash(); $userRole = $_SESSION['user_role'] ?? ''; $isAdmin = $userRole === 'admin'; $isShipper = $userRole === 'shipper'; $isTruckOwner = $userRole === 'truck_owner'; // Platform Fee Configuration $settings = get_settings(); $platformFeePercentage = (float)($settings['platform_charge_percentage'] ?? 0) / 100; // Handle POST actions if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; if ($action === 'submit_offer') { $offerOwner = trim($_POST['offer_owner'] ?? ''); $offerPrice = trim($_POST['offer_price'] ?? ''); if ($offerOwner === '' || $offerPrice === '') { $errors[] = t('error_required'); } elseif (!is_numeric($offerPrice)) { $errors[] = t('error_invalid'); } else { $stmt = db()->prepare( "UPDATE shipments SET offer_owner = :offer_owner, offer_price = :offer_price, status = 'offered' WHERE id = :id" ); $stmt->execute([ ':offer_owner' => $offerOwner, ':offer_price' => $offerPrice, ':id' => $shipmentId, ]); set_flash('success', t('success_offer')); header('Location: ' . url_with_lang('shipment_detail.php', ['id' => $shipmentId])); exit; } } elseif ($action === 'accept_offer' && $isShipper) { if ($shipment && $shipment['status'] === 'offered' && $shipment['offer_price'] > 0) { $offerPrice = (float)$shipment['offer_price']; $platformFee = $offerPrice * $platformFeePercentage; $totalPrice = $offerPrice + $platformFee; $stmt = db()->prepare( "UPDATE shipments SET status = 'confirmed', payment_status = 'paid', platform_fee = :fee, total_price = :total WHERE id = :id" ); $stmt->execute([ ':fee' => $platformFee, ':total' => $totalPrice, ':id' => $shipmentId ]); set_flash('success', t('Payment successful. Shipment confirmed!')); header('Location: ' . url_with_lang('shipment_detail.php', ['id' => $shipmentId])); exit; } } } render_header(t('shipment_detail')); ?>

Back to Shipments Back to Dashboard

#

:

Payment Complete
Total Paid: $ (Includes $ platform fee)

Accept Offer

0): ?>
Payment Breakdown
Truck Offer $
Platform Fee (%) $

Total $

Secure payment via

Waiting for truck owners to submit offers.

Offer Accepted

This shipment has been confirmed and paid for.

This shipment is already confirmed/processed.