<?php

function getGeneralStatus($so_id){
	global $db;
	$soStatus = getSOData($so_id, "status");
	
	
	if($soStatus == 1){
		return getWAOverallStatusFromSOID($so_id);
	}elseif($soStatus == 2){
		$eta = getSAData($so_id, "eta");
		$etd = getSAData($so_id, "etd");
		$release_date = getSAData($so_id, "release_date");
		$loading_date = getSAData($so_id, "loading_date");
		$today = date("Y-m-d");
		if($today >= $loading_date && $today < $etd && $release_date == null){
			return "Container Loading";
		}elseif($today >= $etd && $today < $eta && $release_date == null){
			return "ETD";
		}elseif($today >= $eta && $release_date == null){
			return "ETA";
		}elseif($today >= $release_date && $release_date <> null){
			return "Custom Clearance";
		}else{
			return "Warehouse Received";
		}		
	}elseif($soStatus == 3){
		$today = date("Y-m-d");
		$daDeliveryDate = getDAData($so_id, "status");
		$daStatus = getDAData($so_id, "status");
		if($daStatus == 1){
			return "Delivery Request Sent";
		}elseif($daStatus == 2){
			return "Delivery Request Accepted";
		}elseif($daStatus == 3){
			return "Delivery Request Completed";
		}elseif($daStatus == 4){
			return "Order Completed";
		}elseif($daStatus == 5){
			return "Delivery Request Rejected";
		}
	}else{
		return "Order Created";
	}
}