add countries to shipments
This commit is contained in:
parent
29654f3470
commit
2d3486ba46
20
api/get_cities.php
Normal file
20
api/get_cities.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../includes/app.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$countryId = isset($_GET['country_id']) ? (int)$_GET['country_id'] : 0;
|
||||
|
||||
if ($countryId <= 0) {
|
||||
echo json_encode([]);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = db()->prepare("SELECT id, name_en, name_ar FROM cities WHERE country_id = ? ORDER BY name_en ASC");
|
||||
$stmt->execute([$countryId]);
|
||||
$cities = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
echo json_encode($cities);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['error' => $e->getMessage()]);
|
||||
}
|
||||
@ -22,7 +22,8 @@ $isShipper = $userRole === 'shipper';
|
||||
$isTruckOwner = $userRole === 'truck_owner';
|
||||
|
||||
// Platform Fee Configuration
|
||||
const PLATFORM_FEE_PERCENTAGE = 0.05; // 5%
|
||||
$settings = get_settings();
|
||||
$platformFeePercentage = (float)($settings['platform_charge_percentage'] ?? 0) / 100;
|
||||
|
||||
// Handle POST actions
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
@ -52,7 +53,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
} elseif ($action === 'accept_offer' && $isShipper) {
|
||||
if ($shipment && $shipment['status'] === 'offered' && $shipment['offer_price'] > 0) {
|
||||
$offerPrice = (float)$shipment['offer_price'];
|
||||
$platformFee = $offerPrice * PLATFORM_FEE_PERCENTAGE;
|
||||
$platformFee = $offerPrice * $platformFeePercentage;
|
||||
$totalPrice = $offerPrice + $platformFee;
|
||||
|
||||
$stmt = db()->prepare(
|
||||
@ -186,7 +187,7 @@ render_header(t('shipment_detail'));
|
||||
<?php if ($shipment['status'] === 'offered' && $shipment['offer_price'] > 0): ?>
|
||||
<?php
|
||||
$offerPrice = (float)$shipment['offer_price'];
|
||||
$fee = $offerPrice * PLATFORM_FEE_PERCENTAGE;
|
||||
$fee = $offerPrice * $platformFeePercentage;
|
||||
$total = $offerPrice + $fee;
|
||||
?>
|
||||
<div class="card bg-light border-0 mb-4">
|
||||
@ -197,7 +198,7 @@ render_header(t('shipment_detail'));
|
||||
<span class="fw-medium">$<?= number_format($offerPrice, 2) ?></span>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between mb-3">
|
||||
<span class="text-muted">Platform Fee (5%)</span>
|
||||
<span class="text-muted">Platform Fee (<?= e($platformFeePercentage * 100) ?>%)</span>
|
||||
<span class="fw-medium">$<?= number_format($fee, 2) ?></span>
|
||||
</div>
|
||||
<hr>
|
||||
|
||||
@ -96,6 +96,12 @@ try {
|
||||
}
|
||||
} catch (Throwable $e) {}
|
||||
|
||||
// Fetch countries for dropdowns
|
||||
$countries = [];
|
||||
try {
|
||||
$countries = db()->query("SELECT * FROM countries ORDER BY name_en ASC")->fetchAll();
|
||||
} catch (Throwable $e) {}
|
||||
|
||||
render_header(t('shipper_dashboard'), 'shipper');
|
||||
$flash = get_flash();
|
||||
?>
|
||||
@ -155,13 +161,38 @@ $flash = get_flash();
|
||||
</div>
|
||||
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label text-muted small fw-bold">Origin Country</label>
|
||||
<select class="form-select" id="origin_country" required>
|
||||
<option value="">Select Country</option>
|
||||
<?php foreach ($countries as $country): ?>
|
||||
<option value="<?= e($country['id']) ?>"><?= e($country['name_en']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label text-muted small fw-bold"><?= e(t('origin')) ?></label>
|
||||
<input class="form-control" name="origin_city" required>
|
||||
<select class="form-select" name="origin_city" id="origin_city" disabled required>
|
||||
<option value="">Select City</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label text-muted small fw-bold">Destination Country</label>
|
||||
<select class="form-select" id="destination_country" required>
|
||||
<option value="">Select Country</option>
|
||||
<?php foreach ($countries as $country): ?>
|
||||
<option value="<?= e($country['id']) ?>"><?= e($country['name_en']) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label text-muted small fw-bold"><?= e(t('destination')) ?></label>
|
||||
<input class="form-control" name="destination_city" required>
|
||||
<select class="form-select" name="destination_city" id="destination_city" disabled required>
|
||||
<option value="">Select City</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -255,4 +286,44 @@ $flash = get_flash();
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
function setupCityLoader(countrySelectId, citySelectId) {
|
||||
const countrySelect = document.getElementById(countrySelectId);
|
||||
const citySelect = document.getElementById(citySelectId);
|
||||
|
||||
countrySelect.addEventListener('change', function() {
|
||||
const countryId = this.value;
|
||||
citySelect.innerHTML = '<option value="">Loading...</option>';
|
||||
citySelect.disabled = true;
|
||||
|
||||
if (countryId) {
|
||||
fetch('api/get_cities.php?country_id=' + countryId)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
citySelect.innerHTML = '<option value="">Select City</option>';
|
||||
data.forEach(city => {
|
||||
const option = document.createElement('option');
|
||||
option.value = city.name_en; // Using name as value for DB compatibility
|
||||
option.textContent = city.name_en;
|
||||
citySelect.appendChild(option);
|
||||
});
|
||||
citySelect.disabled = false;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching cities:', error);
|
||||
citySelect.innerHTML = '<option value="">Error loading cities</option>';
|
||||
});
|
||||
} else {
|
||||
citySelect.innerHTML = '<option value="">Select City</option>';
|
||||
citySelect.disabled = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setupCityLoader('origin_country', 'origin_city');
|
||||
setupCityLoader('destination_country', 'destination_city');
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php render_footer(); ?>
|
||||
Loading…
x
Reference in New Issue
Block a user