diff --git a/includes/app.php b/includes/app.php index b93ee41..3fddf14 100644 --- a/includes/app.php +++ b/includes/app.php @@ -79,7 +79,7 @@ $translations = [ 'status_in_transit' => 'In transit', 'status_delivered' => 'Delivered', 'footer_note' => 'This is the initial MVP slice. Payments are not yet connected.', -'marketing_title_1' => 'For Shippers', 'marketing_desc_1' => 'Find the right truck for your cargo quickly and securely. Post your load and get offers instantly.', 'marketing_title_2' => 'For Truck Owners', 'marketing_desc_2' => 'Maximize your earnings and eliminate empty miles. Browse available shipments and offer your rate.', 'motivation_phrase' => 'Empowering the logistics of tomorrow.', 'why_choose_us' => 'Why Choose CargoLink?', 'feature_1_title' => 'Fast Matching', 'feature_1_desc' => 'Connect with available trucks or shipments in minutes.', 'feature_2_title' => 'Secure Payments', 'feature_2_desc' => 'Your transactions are protected with security.', 'feature_3_title' => 'Verified Users', 'feature_3_desc' => 'We verify all truck owners to ensure peace of mind.', +'marketing_title_1' => 'For Shippers', 'marketing_desc_1' => 'Find the right truck for your cargo quickly and securely. Post your load and get offers instantly.', 'marketing_title_2' => 'For Truck Owners', 'marketing_desc_2' => 'Maximize your earnings and eliminate empty miles. Browse available shipments and offer your rate.', 'motivation_phrase' => 'Empowering the logistics of tomorrow.', 'why_choose_us' => 'لماذا تختار كارجو لينك؟', 'feature_1_title' => 'Fast Matching', 'feature_1_desc' => 'Connect with available trucks or shipments in minutes.', 'feature_2_title' => 'Secure Payments', 'feature_2_desc' => 'Your transactions are protected with security.', 'feature_3_title' => 'Verified Users', 'feature_3_desc' => 'We verify all truck owners to ensure peace of mind.', ], 'ar' => [ 'app_name' => 'CargoLink', @@ -202,6 +202,10 @@ SQL; try { db()->exec("ALTER TABLE users ADD COLUMN status ENUM('pending','active','rejected') NOT NULL DEFAULT 'active'"); } catch (Exception $e) {} try { db()->exec("ALTER TABLE users ADD COLUMN profile_picture VARCHAR(255) NULL AFTER full_name"); } catch (Exception $e) {} + // Payment fields for shipments + try { db()->exec("ALTER TABLE shipments ADD COLUMN platform_fee DECIMAL(10,2) DEFAULT 0.00 AFTER offer_price"); } catch (Exception $e) {} + try { db()->exec("ALTER TABLE shipments ADD COLUMN total_price DECIMAL(10,2) DEFAULT 0.00 AFTER platform_fee"); } catch (Exception $e) {} + try { db()->exec("ALTER TABLE shipments ADD COLUMN payment_status ENUM('unpaid', 'paid') DEFAULT 'unpaid' AFTER status"); } catch (Exception $e) {} db()->exec( "CREATE TABLE IF NOT EXISTS users ( diff --git a/shipment_detail.php b/shipment_detail.php index f865f5b..bc04268 100644 --- a/shipment_detail.php +++ b/shipment_detail.php @@ -15,32 +15,67 @@ if ($shipmentId > 0) { } $errors = []; -if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['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; +$flash = get_flash(); +$userRole = $_SESSION['user_role'] ?? ''; +$isAdmin = $userRole === 'admin'; +$isShipper = $userRole === 'shipper'; +$isTruckOwner = $userRole === 'truck_owner'; + +// Platform Fee Configuration +const PLATFORM_FEE_PERCENTAGE = 0.05; // 5% + +// 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 * PLATFORM_FEE_PERCENTAGE; + $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; + } } } -$flash = get_flash(); -$isAdmin = ($_SESSION['user_role'] ?? '') === 'admin'; - render_header(t('shipment_detail')); ?> @@ -50,6 +85,8 @@ render_header(t('shipment_detail'));
Back to Shipments + + Back to Dashboard @@ -107,6 +144,17 @@ render_header(t('shipment_detail'));
+ +
+
+ +
+ Payment Complete
+ Total Paid: $ (Includes $ platform fee) +
+
+
+
@@ -116,34 +164,104 @@ render_header(t('shipment_detail')); Edit Shipment + +
+ +
-
-

- -
- - -
- -
- -
- - -
-
- - -
- -
-
+ + +
+

Accept Offer

+ +
+ + + 0): ?> + +
+
+
Payment Breakdown
+
+ Truck Offer + $ +
+
+ Platform Fee (5%) + $ +
+
+
+ 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. +
+ +
+