<?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>{foreach:WEEK_DAY_NAME_ARRAY wkey wday}<th>{write:wday}</th>{/foreach}</tr>
	</thead>
	<tbody>
	<tr>
	<?php for( $num=0; $num<$GLOBALS['shopping.calendar.firstWeekDay']; $num++ ) { ?>
		<td style="height:5em;color:#c0c0c0;background-color:#e0e0e0;"> - </td>
	<?php } ?>
	<?php for( $GLOBALS['page.day']=1; $GLOBALS['page.day']<=$GLOBALS['shopping.calendar.targetMonthDayCount']; $GLOBALS['page.day']++ ) { ?>
		<td style="height:10em;font-size:x-small;<?php if( !array_key_exists(sprintf('%02d',$GLOBALS['page.day']),$GLOBALS['shopping.calendar.scheduleHash']) ) { ?>background-color:#e0e0ef;<?php } ?>;"
			onmouseover="this.orgColor=this.style.backgroundColor;this.style.backgroundColor='#fff0f0'"
			onmouseout="this.style.backgroundColor=this.orgColor;"
		>
			{set:realStock maxStock-shopping.product.unit.orderedCountHash[sprintf('%02d',page.day)]}
			<?php if( !array_key_exists(sprintf('%02d',$GLOBALS['page.day']),$GLOBALS['shopping.calendar.scheduleHash']) ) { ?>
			<?php } else { ?>
			{set:maxTotalStock maxTotalStock+maxStock}
			{set:totalStock totalStock+realStock}
			{set:totalReserved totalReserved+shopping.product.unit.orderedCountHash[sprintf('%02d',page.day)]}
			<?php } ?>
			<?php echo $GLOBALS['page.day']; ?>日
			<div style="font-size:x-small;">
				{if:is_array(shopping.product.unit.orderedInfoHash[sprintf('%02d',page.day)])}
				{set:infoHash shopping.product.unit.orderedInfoHash[sprintf('%02d',page.day)]}
				{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:x-small;text-align:right;">
			<?php if( !array_key_exists(sprintf('%02d',$GLOBALS['page.day']),$GLOBALS['shopping.calendar.scheduleHash']) ) { ?>
				休業
			<?php } else { ?>
				空{write:realStock}/{write:maxStock}
			<?php } ?>
			</div>
		</td>
		<?php $num++; if( $num % 7 == 0 ) { ?></tr><tr><?php } ?>
	<?php } ?>
	<?php for( $GLOBALS['page.day']=1; $GLOBALS['page.day']<7 && $num%7!=0; $GLOBALS['page.day']++ ) { ?>
		<td style="height:5em;color:#c0c0c0;background-color:#e0e0e0;"><?php echo $GLOBALS['page.day']; ?></td>
		<?php $num++; ?>
	<?php } ?>
	</tr>
	</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}