<?php require dirname(__DIR__).'/app/core.php';csrf();$id=(int)($_POST['shipment_id']??0);$tracking=trim($_POST['tracking_number']??'');if(!$tracking)exit('Tracking required');$s=$pdo->prepare('SELECT * FROM shipments WHERE id=?');$s->execute([$id]);$x=$s->fetch()?:exit('Not found');$location=$x['shipment_type']==='GmbH Recalibration'?'GmbH':'Shipping';try{$pdo->beginTransaction();$pdo->prepare("UPDATE shipments SET shipping_status='Shipped',tracking_number=?,shipped_at=?,shipped_by=?,record_updated_by=? WHERE id=?")->execute([$tracking,now_utc(),$_SESSION['user'],$_SESSION['user'],$id]);$pdo->prepare('UPDATE afguards SET current_location=?,record_updated_by=? WHERE id=?')->execute([$location,$_SESSION['user'],$x['afguard_id']]);if($x['shipment_type']==='GmbH Recalibration')$pdo->prepare("UPDATE recertification_workflows SET workflow_status='Sent to GmbH',record_updated_by=? WHERE id=?")->execute([$_SESSION['user'],$x['workflow_id']]);$pdo->commit();flash('Shipment marked shipped.');}catch(Throwable $e){if($pdo->inTransaction())$pdo->rollBack();flash($e->getMessage(),'error');}go('shipping.php');