<?php
namespace Modules\Orders\MiceProjects;

/**
 * class for mice reports (option from mice project listing)
 */
class MiceReports
{
	/**
	 * it returns an array with information about reservation and services associated with mice project
	 * the information are structured on days
	 * @param int $id
	 */
	public function getRecords($id)
	{
		$project = \Entity\MiceProject::select($id);

		$result['startDate'] = $start =  '9999-99-99';
		$result['endDate'] = $stop = '0000-00-00';

		foreach($project->idOrders as $idOrder){

			// reservation entity
			$order = \Entity\Order::select($idOrder);
			$services = $order->servicesList;

			foreach($services as $idService=>$serviceArr){

				// service entity
				$service = \Entity\Service::select($idService);

				$result['services'][$idService]['serviceName'] 				= $service->serviceName;
				$result['services'][$idService]['category'] 				= $service->category;
				$result['services'][$idService]['startTime'] 				= $service->startDate;
				$result['services'][$idService]['endTime'] 					= $service->endDate;
				$result['services'][$idService]['productName'] 				= $service->productName;
				$result['services'][$idService]['categoryReadable'] 		= $service->categoryReadable;
				$result['services'][$idService]['departureCityId'] 			= $service->departureCityId;
				$result['services'][$idService]['destinationCityId'] 		= $service->destinationCityId;
				$result['services'][$idService]['departureCountryCode'] 	= $service->departureCountryCode;
				$result['services'][$idService]['destinationCountryCode'] 	= $service->destinationCountryCode;
				$result['services'][$idService]['multiplierReadable'] 		= $service->multiplierReadable;
				$result['services'][$idService]['pax'] 						= $service->pax;
				$result['services'][$idService]['idSupplier'] 				= $service->chosenOffer->idSupplier;
				$result['services'][$idService]['idSupplierProduct'] 		= $service->idSupplierProduct;
				$result['services'][$idService]['productTypeCode'] 			= $service->productTypeCode;
				$result['services'][$idService]['productTypeReadable'] 		= $service->productTypeReadable;
				$result['services'][$idService]['serviceSourceReadable'] 	= $service->serviceSourceReadable;
				$result['services'][$idService]['description'] 				= $service->description;

				$start = min($start, $service->startDate);
				$stop = max($stop, $service->endDate);
			}

			$result['startDate'] = $start;
			$result['endDate'] = $stop;
		}

		// make sure we dont end up with invalid dates
		if ($result['startDate']=='9999-99-99') {
			$result['startDate'] = '';
		}
		if ($result['endDate']=='0000-00-00') {
			$result['endDate'] = '';
		}

		return $result;
	}
}