<?php
	function getWarehouseDelivery(){
		global $db;
		$company_id = $_SESSION['company_id'];
		$db->bind("company_id",$company_id);
		
		$data = $db->query("SELECT * FROM warehouses WHERE company_id = :company_id");
		$html = "<option value=''>Please choose / Create New</option>";
		foreach ($data as $key => $value) {
			$html .= "<option value='".$value['warehouse_id']."'>".$value['name']."</option>";
		}
		return $html;
		
	}
	
	function getDAOrderSelectionCount(){
		global $db;
		$db->bind("company_id", $_SESSION['company_id']);
		$orderselections = $db->query("SELECT * FROM shipping_orders where forwarder_id = :company_id and (so_id in (select so_id from shipment_arrangement_items where 1) and so_id not in (select so_id from delivery_arrangement_items where 1))");
			
		return count($orderselections);
	}
	
	function getDAID($so_id){
		global $db;
		
		$db->bind('so_id', $so_id);
		$data = $db->query("SELECT delivery_arrangement_id FROM delivery_arrangement_items WHERE so_id = :so_id");
		
		return $data[0]['delivery_arrangement_id'];
		
	}
	function getDAData($so_id, $data){
		global $db;
		
		$DAID = getDAID($so_id);
		$db->bind('id', $DAID);
		
		$delivery_arrangements = $db->query("SELECT * FROM delivery_arrangements WHERE id = :id");
		
		return (count($delivery_arrangements) > 0 ? $delivery_arrangements[0][$data] : "");
		
	}
	function getDADataFromDAID($DAID, $data){
		global $db;
		
		$db->bind('id', $DAID);
		
		$delivery_arrangements = $db->query("SELECT * FROM delivery_arrangements WHERE id = :id");
		
		return (count($delivery_arrangements) > 0 ? $delivery_arrangements[0][$data] : "");
		
	}