<?php include_once( "../../../../spider.inc.php" ); ?>
{charset:SJIS-win}
{module:shopping.category.LoadList}
{module:shopping.flag.LoadList}
{module:shopping.product.unit.Load}
{module:shopping.product.unit.LoadOrderItems}
{module:shopping.calendar.Load force}
	{if:IS_ERROR}
		<h2>エラー</h2>
		<ul class="error">
		{foreach:errors error}
			<li>{write:error}</li>
		{/foreach}
	</ul>
	{else}
	{set:maxStock shopping.product.unit.unit_object->getStock(request)}
	{set:maxTotalStock 0}
	{set:totalStock 0}
	{set:totalReserved 0}
	<table class="calendar" style="width:96%;margin:0 auto;">
	<thead>
	<tr>
		<th>日付</th>
	<?php for( $GLOBALS['page.hour']=9; $GLOBALS['page.hour']<19; $GLOBALS['page.hour']++ ) { ?>
		<th style="font-size:x-small;font-weight:100;">{write:sprintf('%02d',page.hour)}:00</th>
	<?php } ?>
	</tr>
	</thead>
	<tbody>
	<?php for( $GLOBALS['page.day']=1; $GLOBALS['page.day']<=$GLOBALS['shopping.calendar.targetMonthDayCount']; $GLOBALS['page.day']++ ) { ?>
	{set:dayOpenTimes shopping.calendar.scheduleHash[sprintf('%02d',page.day)]}
	{set:targetTime strtotime( shopping.calendar.targetYear . '-' . shopping.calendar.targetMonth . '-' . page.day . ' 12:00:00' )}
	{if:page.day>1 && date('w',targetTime)==1}
	</tbody>
	<thead>
	<tr>
		<th>日付</th>
	<?php for( $GLOBALS['page.hour']=9; $GLOBALS['page.hour']<19; $GLOBALS['page.hour']++ ) { ?>
		<th style="font-size:x-small;font-weight:100;">{write:sprintf('%02d',page.hour)}:00</th>
	<?php } ?>
	</tr>
	</thead>
	<tbody>
	{/if}
	<tr>
		<th style="{if:date('w',targetTime)==0}background-color:#fff0f0;{else-if:date('w',targetTime)==6}background-color:#f0f0ff;{/if}">
			{write:page.day}日({write:WEEK_DAY_NAME_ARRAY[date('w',targetTime)]})
		</th>
		<?php for( $GLOBALS['page.hour']=9; $GLOBALS['page.hour']<19; $GLOBALS['page.hour']++ ) { ?>
		{set:targetTime strtotime( shopping.calendar.targetYear . '-' . shopping.calendar.targetMonth . '-' . page.day . ' ' . sprintf('%02d',page.hour) . ':00:00' )}
		{set:isOpen 'false'}{if:is_array(dayOpenTimes)}{foreach:dayOpenTimes openInfo}{if:strtotime(openInfo['start_date'])<=targetTime && strtotime(openInfo['close_date'])>targetTime}{set:isOpen 'true'}{/if}{/foreach}{/if}
		<td style="{if:isOpen=='true'}{else}background-color:#c0c0c0;{/if}font-size:x-small;">
			<input type="hidden" name="page_date[]" value="{write:date('Y-m-d H:i:s',targetTime)}" />
			{if:isOpen=='true'}
			{set:realStock maxStock-shopping.product.unit.orderedCountHash[sprintf('%02d',page.day)][date('Hi',targetTime)]}
			{set:maxTotalStock maxTotalStock+maxStock}
			{set:totalStock totalStock+realStock}
			{set:totalReserved totalReserved+shopping.product.unit.orderedCountHash[sprintf('%02d',page.day)][date('Hi',targetTime)]}
			<div style="font-size:8px;">
				{if:is_array(shopping.product.unit.orderedInfoHash[sprintf('%02d',page.day)][date('Hi',targetTime)])}
				{set:infoHash shopping.product.unit.orderedInfoHash[sprintf('%02d',page.day)][date('Hi',targetTime)]}
				{foreach:infoHash page.row}
					<a href="../../order/detail.php?shpoi={write:page.row['order_id']}" target="_blank">{write:page.row['order_id']}</a><br />
				{/foreach}
				{/if}
			</div>
			<div style="font-size:8px;text-align:right;">
				空{write:realStock}/{write:maxStock}
			</div>
			{else}-{/if}
		</td>
		<?php } ?>
	</tr>
	<?php } ?>
	</tbody>
	</table>
	<div style="width:96%;margin:0 auto;text-align:right;font-size:16px;font-weight:bold;color:#e09040;">
		予約数/予約可能数 = {write:totalReserved}/{write:maxTotalStock}
		&nbsp;&nbsp;
		稼働率={write:round(totalReserved/maxTotalStock * 100,1)}%
	</div>
	{/if}