<?php
class ModelToolBooking extends Model {
	public function prepareData($array_products) {
		
		$this->load->model('catalog/product');

		foreach ($array_products as $product_id => $dates) {
			$product_info = $this->model_catalog_product->getProduct($product_id);
			if (!empty($product_info)) {
				$count = $this->model_catalog_product->getBooking($product_id);
				foreach ($count as $key => $value) {
					
				}

				$tmp = array_reduce($count, function($carry, $item){
					$carry[$item['days']] = $item['total'];
					return $carry;
				}, []);

				foreach ($dates as $day) {
					$res['apartamets'][] = [
						'room_id' => [
							'booking' => $product_info['upc'],
							'hotel24' => $product_info['ean']
						],
					'date'         => $day,
					'room_to_sell' => $product_info['quantity']-(isset($tmp[$day]) ? $tmp[$day] : 0), 
					'price'        => (int)$product_info['price'],
					'tariff'       => $product_info['mpn']
					];
				}
			}
			
		}
		return $res;

	}
}