adding shipment types
This commit is contained in:
parent
d1d4a0cc48
commit
c1349af904
@ -69,6 +69,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token();
|
||||
// These are now selected from dropdowns, but the value is still the city name
|
||||
$origin_city = trim($_POST['origin_city'] ?? '');
|
||||
$destination_city = trim($_POST['destination_city'] ?? '');
|
||||
$shipment_type = trim($_POST['shipment_type'] ?? 'Dry');
|
||||
$cargo_description = trim($_POST['cargo_description'] ?? '');
|
||||
$weight_tons = (float)($_POST['weight_tons'] ?? 0);
|
||||
$pickup_date = trim($_POST['pickup_date'] ?? '');
|
||||
@ -84,13 +85,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { validate_csrf_token();
|
||||
$updateSql = "
|
||||
UPDATE shipments
|
||||
SET shipper_name = ?, shipper_company = ?, origin_city = ?, destination_city = ?,
|
||||
cargo_description = ?, weight_tons = ?, pickup_date = ?, delivery_date = ?,
|
||||
shipment_type = ?, cargo_description = ?, weight_tons = ?, pickup_date = ?, delivery_date = ?,
|
||||
payment_method = ?, status = ?
|
||||
WHERE id = ?
|
||||
";
|
||||
db()->prepare($updateSql)->execute([
|
||||
$shipper_name, $shipper_company, $origin_city, $destination_city,
|
||||
$cargo_description, $weight_tons, $pickup_date, $delivery_date,
|
||||
$shipment_type, $cargo_description, $weight_tons, $pickup_date, $delivery_date,
|
||||
$payment_method, $status, $id
|
||||
]);
|
||||
$flash = t('shipment_updated_success');
|
||||
@ -251,7 +252,16 @@ if (!$isAjax):
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label"><?= t('shipment_type') ?></label>
|
||||
<select name="shipment_type" class="form-select">
|
||||
<option value="Dry" <?= ($shipment['shipment_type'] ?? 'Dry') === 'Dry' ? 'selected' : '' ?>><?= t('type_dry') ?></option>
|
||||
<option value="Cold" <?= ($shipment['shipment_type'] ?? '') === 'Cold' ? 'selected' : '' ?>><?= t('type_cold') ?></option>
|
||||
<option value="Frozen" <?= ($shipment['shipment_type'] ?? '') === 'Frozen' ? 'selected' : '' ?>><?= t('type_frozen') ?></option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-8">
|
||||
<label class="form-label"><?= t('cargo') ?></label>
|
||||
<input type="text" name="cargo_description" class="form-control" value="<?= e((string)$shipment['cargo_description']) ?>">
|
||||
</div>
|
||||
|
||||
@ -146,6 +146,9 @@ render_header(t('manage_shipments'), 'admin', true);
|
||||
<td>
|
||||
<div><span class="text-muted small"><?= t('from_label') ?></span> <?= e($shipment['origin_city']) ?></div>
|
||||
<div><span class="text-muted small"><?= t('to_label') ?></span> <?= e($shipment['destination_city']) ?></div>
|
||||
<?php if (!empty($shipment['shipment_type'])): ?>
|
||||
<div class="mt-1"><span class="badge bg-light text-secondary border"><?= e(t('type_' . strtolower($shipment['shipment_type']))) ?></span></div>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<div class="small"><span class="text-muted"><?= t('pick_label') ?></span> <?= e($shipment['pickup_date']) ?></div>
|
||||
|
||||
17
db/migrations/add_shipment_type_to_shipments.php
Normal file
17
db/migrations/add_shipment_type_to_shipments.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config.php';
|
||||
$pdo = db();
|
||||
|
||||
try {
|
||||
// Check if column exists
|
||||
$stmt = $pdo->query("SHOW COLUMNS FROM shipments LIKE 'shipment_type'");
|
||||
if ($stmt->fetch()) {
|
||||
echo "Column 'shipment_type' already exists in 'shipments'.\n";
|
||||
} else {
|
||||
$pdo->exec("ALTER TABLE shipments ADD COLUMN shipment_type VARCHAR(50) DEFAULT 'Dry' AFTER cargo_description");
|
||||
echo "Added 'shipment_type' column to 'shipments' table.\n";
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
echo "Error: " . $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
@ -329,6 +329,10 @@ $translations = [
|
||||
'reg_expiry' => 'Reg. Expiry',
|
||||
'ins_expiry' => 'Ins. Expiry',
|
||||
'registration_doc' => 'Registration Doc',
|
||||
'shipment_type' => 'Shipment Type',
|
||||
'type_frozen' => 'Frozen',
|
||||
'type_cold' => 'Cold',
|
||||
'type_dry' => 'Dry',
|
||||
),
|
||||
"ar" => array (
|
||||
'app_name' => 'CargoLink',
|
||||
@ -646,6 +650,10 @@ $translations = [
|
||||
'reg_expiry' => 'انتهاء التسجيل',
|
||||
'ins_expiry' => 'انتهاء التأمين',
|
||||
'registration_doc' => 'وثيقة التسجيل',
|
||||
'shipment_type' => 'نوع الشحنة',
|
||||
'type_frozen' => 'مجمد',
|
||||
'type_cold' => 'مبرد',
|
||||
'type_dry' => 'جاف',
|
||||
)
|
||||
];
|
||||
|
||||
@ -908,4 +916,4 @@ try {
|
||||
if ($tz && in_array($tz, DateTimeZone::listIdentifiers())) {
|
||||
date_default_timezone_set($tz);
|
||||
}
|
||||
} catch (Throwable $e) {}
|
||||
} catch (Throwable $e) {}
|
||||
|
||||
@ -215,6 +215,10 @@ render_header(t('shipment_detail'));
|
||||
<div class="small text-muted"><?= e(t('destination')) ?></div>
|
||||
<div class="fw-semibold"><?= e($shipment['destination_city']) ?></div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="small text-muted"><?= e(t('shipment_type')) ?></div>
|
||||
<div class="fw-semibold"><?= e(t('type_' . strtolower($shipment['shipment_type'] ?? 'dry'))) ?></div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="small text-muted"><?= e(t('cargo')) ?></div>
|
||||
<div class="fw-semibold"><?= e($shipment['cargo_description']) ?></div>
|
||||
|
||||
@ -28,6 +28,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'creat
|
||||
$shipperCompany = trim($_POST['shipper_company'] ?? '');
|
||||
$origin = trim($_POST['origin_city'] ?? '');
|
||||
$destination = trim($_POST['destination_city'] ?? '');
|
||||
$shipmentType = trim($_POST['shipment_type'] ?? 'Dry');
|
||||
$cargo = trim($_POST['cargo_description'] ?? '');
|
||||
$weight = trim($_POST['weight_tons'] ?? '');
|
||||
$pickupDate = trim($_POST['pickup_date'] ?? '');
|
||||
@ -44,8 +45,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'creat
|
||||
$shipperId = isset($_SESSION['user_id']) ? (int)$_SESSION['user_id'] : null;
|
||||
|
||||
$stmt = db()->prepare(
|
||||
"INSERT INTO shipments (shipper_id, shipper_name, shipper_company, origin_city, destination_city, cargo_description, weight_tons, pickup_date, delivery_date, payment_method)
|
||||
VALUES (:shipper_id, :shipper_name, :shipper_company, :origin_city, :destination_city, :cargo_description, :weight_tons, :pickup_date, :delivery_date, :payment_method)"
|
||||
"INSERT INTO shipments (shipper_id, shipper_name, shipper_company, origin_city, destination_city, shipment_type, cargo_description, weight_tons, pickup_date, delivery_date, payment_method)
|
||||
VALUES (:shipper_id, :shipper_name, :shipper_company, :origin_city, :destination_city, :shipment_type, :cargo_description, :weight_tons, :pickup_date, :delivery_date, :payment_method)"
|
||||
);
|
||||
$stmt->execute([
|
||||
':shipper_id' => $shipperId,
|
||||
@ -53,6 +54,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'creat
|
||||
':shipper_company' => $shipperCompany,
|
||||
':origin_city' => $origin,
|
||||
':destination_city' => $destination,
|
||||
':shipment_type' => $shipmentType,
|
||||
':cargo_description' => $cargo,
|
||||
':weight_tons' => $weight,
|
||||
':pickup_date' => $pickupDate,
|
||||
@ -215,6 +217,15 @@ $flash = get_flash();
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label text-muted small fw-bold"><?= e(t('shipment_type')) ?></label>
|
||||
<select class="form-select" name="shipment_type">
|
||||
<option value="Dry"><?= t('type_dry') ?></option>
|
||||
<option value="Cold"><?= t('type_cold') ?></option>
|
||||
<option value="Frozen"><?= t('type_frozen') ?></option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label text-muted small fw-bold"><?= e(t('cargo')) ?></label>
|
||||
<input class="form-control" name="cargo_description" placeholder="<?= e(t('cargo_placeholder') ?? 'e.g. 20 Pallets of Electronics') ?>" required>
|
||||
@ -280,6 +291,11 @@ $flash = get_flash();
|
||||
<span class="fw-medium"><?= e($row['destination_city']) ?></span>
|
||||
</div>
|
||||
<small class="text-muted"><?= e(date('M d', strtotime($row['pickup_date']))) ?></small>
|
||||
<?php if (!empty($row['shipment_type'])): ?>
|
||||
<div class="text-xs text-muted mt-1">
|
||||
<span class="badge bg-light text-secondary border"><?= e(t('type_' . strtolower($row['shipment_type']))) ?></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><span class="badge <?= e($row['status']) ?> rounded-pill px-3 py-2"><?= e(status_label($row['status'])) ?></span></td>
|
||||
<td>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user