{% extends 'measurement/stats/measurement_stats_base.html' %}
{% load staticfiles %}
{% block extrastyle %}
<style>
	h3 {
		width: 100%;
	}
</style>
{% endblock extrastyle %}
{% block activemenu2 %}class="active"{% endblock activemenu2 %}
{% block content %}
<article>
	<div class="onepage">
		<br style='height:0; line-height:0'>
		<button class="pdfBtn">PDF 저장하기</button>
		<button class="printBtn">인쇄하기</button>
		<h3> 1. 사이즈별 주문현황</h3>
		<table class="table-size-status">
			<colgroup>
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
			</colgroup>
			<caption>[단위:PCS]</caption>
			<tr>
				<th colspan="6"></th>
				<th colspan="8">사이즈</th>
			</tr>
			<tr>
				<th>일자</th>
				<th>유치원명</th>
				<th>연도</th>
				<th>시즌</th>
				<th>품목</th>
				<th>품목명</th>
				<th>90</th>
				<th>100</th>
				<th>110</th>
				<th>120</th>
				<th>130</th>
				<th>140</th>
				<th>150</th>
				<th>합계</th>
			</tr>
			{% if final_set %}
			{% regroup final_set by season as season_list %}
	        {% for season in season_list %}
	        {% regroup season.list by style as style_list %}
	        {% for style in style_list %}
	        {% for set in style.list %}
	        {% if style.grouper == "정복" %}
			<tr class="row-size divide-color-formal">
			{% elif style.grouper == "체육복" %}
			<tr class="row-size divide-color-training">
			{% endif %}
				{% if forloop.first %}
				{% if forloop.parentloop.first %}
				{% if forloop.parentloop.parentloop.first %}
				<td rowspan="{{ final_set|length }}" class="backC_No">{{ order.contract_date|date:"Y-m-d" }}</td>
				<td rowspan="{{ final_set|length }}" class="backC_No">{{ order.kindergarten.name }}</td>
				<td rowspan="{{ final_set|length }}" class="backC_No">{{ order.contract_date|date:"y년" }}</td>
				{% endif %}
				<td rowspan="{{ season.list|length }}" class="seasonGroup backC_No">{{ season.grouper }}</td>
				{% endif %}
				<td rowspan="{{ style.list|length }}">{{ style.grouper }}</td>	
				{% endif %}
				<td>
					{{ set.product.product.product_type.get_name_display }}({% if set.gender == 'boy'%}남아{% elif set.gender == 'girl' %}여아{% endif %})
				</td>
				<td>{{ set.size.size90 }}</td>
				<td>{{ set.size.size100 }}</td>
				<td>{{ set.size.size110 }}</td>
				<td>{{ set.size.size120 }}</td>
				<td>{{ set.size.size130 }}</td>
				<td>{{ set.size.size140 }}</td>
				<td>{{ set.size.size150 }}</td>
				<td>{{ set.product_size_total }}</td>
			</tr>
			{% endfor %}
			{% endfor %}
			{% endfor %}
			{% endif %}
			<tr class="total">
				<td>합계</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				
			</tr>
		</table>
		<h3> 1-2. 사이즈별 주문비율</h3>
		<table class="table-size-status">
			<colgroup>
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
			</colgroup>
			<caption>[단위:%]</caption>
			<tr>
				<th colspan="6"></th>
				<th colspan="8">사이즈</th>
			</tr>
			<tr>
				<th>일자</th>
				<th>유치원명</th>
				<th>연도</th>
				<th>시즌</th>
				<th>품목</th>
				<th>품목명</th>
				<th>90</th>
				<th>100</th>
				<th>110</th>
				<th>120</th>
				<th>130</th>
				<th>140</th>
				<th>150</th>
				<th>합계</th>
			</tr>
			{% if final_set %}
			{% regroup final_set by season as season_list %}
	        {% for season in season_list %}
	        {% regroup season.list by style as style_list %}
	        {% for style in style_list %}
	        {% for set in style.list %}
			{% if style.grouper == "정복" %}
			<tr class="divide-color-formal">
			{% elif style.grouper == "체육복" %}
			<tr class="divide-color-training">
			{% endif %}
				{% if forloop.first %}
				{% if forloop.parentloop.first %}
				{% if forloop.parentloop.parentloop.first %}
				<td rowspan="{{ final_set|length }}" class="backC_No">{{ order.contract_date|date:"Y-m-d" }}</td>
				<td rowspan="{{ final_set|length }}" class="backC_No">{{ order.kindergarten.name }}</td>
				<td rowspan="{{ final_set|length }}" class="backC_No">{{ order.contract_date|date:"y년" }}</td>
				{% endif %}
				<td rowspan="{{ season.list|length }}" class="seasonGroup backC_No">{{ season.grouper }}</td>
				{% endif %}
				<td rowspan="{{ style.list|length }}">{{ style.grouper }}</td>	
				{% endif %}
				<td>
					{{ set.product.product.product_type.get_name_display }}({% if set.gender == 'boy'%}남아{% elif set.gender == 'girl' %}여아{% endif %})
				</td>
				<td>{{ set.size_percentage.size90 }}</td>
				<td>{{ set.size_percentage.size100 }}</td>
				<td>{{ set.size_percentage.size110 }}</td>
				<td>{{ set.size_percentage.size120 }}</td>
				<td>{{ set.size_percentage.size130 }}</td>
				<td>{{ set.size_percentage.size140 }}</td>
				<td>{{ set.size_percentage.size150 }}</td>
				<td>100</td>
			</tr>
			{% endfor %}
			{% endfor %}
			{% endfor %}
			{% endif %}
		</table>
	</div>
	<div class="onepage">
		<br style='height:0; line-height:0'>
		<h3> 2. 비축재고(유통망별)</h3>
		<table class="table-size-status table-inventory">
			<colgroup>
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
			</colgroup>
			<caption>[단위:PCS]</caption>
			<tr>
				<th colspan="6"></th>
				<th colspan="8">사이즈</th>
			</tr>
			<tr>
				<th>일자</th>
				<th>유치원명</th>
				<th>연도</th>
				<th>시즌</th>
				<th>품목</th>
				<th>품목명</th>
				<th>90</th>
				<th>100</th>
				<th>110</th>
				<th>120</th>
				<th>130</th>
				<th>140</th>
				<th>150</th>
				<th>합계</th>
			</tr>
			{% if final_set %}
			{% regroup final_set by season as season_list %}
	        {% for season in season_list %}
	        {% regroup season.list by style as style_list %}
	        {% for style in style_list %}
	        {% for set in style.list %}
	        {% if style.grouper == "정복" %}
			<tr class="row-size divide-color-formal" data-product="{{ set.product.id }}" data-gender="{{ set.gender }}">
			{% elif style.grouper == "체육복" %}
			<tr class="row-size divide-color-training" data-product="{{ set.product.id }}" data-gender="{{ set.gender }}">
			{% endif %}
				{% if forloop.first %}
				{% if forloop.parentloop.first %}
				{% if forloop.parentloop.parentloop.first %}
				<td rowspan="{{ final_set|length }}" class="backC_No">{{ order.contract_date|date:"Y-m-d" }}</td>
				<td rowspan="{{ final_set|length }}" class="backC_No">{{ order.kindergarten.name }}</td>
				<td rowspan="{{ final_set|length }}" class="backC_No">{{ order.contract_date|date:"y년" }}</td>
				{% endif %}
				<td rowspan="{{ season.list|length }}" class="seasonGroup backC_No">{{ season.grouper }}</td>
				{% endif %}
				<td rowspan="{{ style.list|length }}">{{ style.grouper }}</td>	
				{% endif %}
				<td>
					{{ set.product.product.product_type.get_name_display }}({% if set.gender == 'boy'%}남아{% elif set.gender == 'girl' %}여아{% endif %})
				</td>
				<td><input class="inp-stock" type="number" name="inp-inventory-90" value="{{ set.inventory_by_size.size90 }}"></td>
				<td><input class="inp-stock" type="number" name="inp-inventory-100" value="{{ set.inventory_by_size.size100 }}"></td>
				<td><input class="inp-stock" type="number" name="inp-inventory-110" value="{{ set.inventory_by_size.size110 }}"></td>
				<td><input class="inp-stock" type="number" name="inp-inventory-120" value="{{ set.inventory_by_size.size120 }}"></td>
				<td><input class="inp-stock" type="number" name="inp-inventory-130" value="{{ set.inventory_by_size.size130 }}"></td>
				<td><input class="inp-stock" type="number" name="inp-inventory-140" value="{{ set.inventory_by_size.size140 }}"></td>
				<td><input class="inp-stock" type="number" name="inp-inventory-150" value="{{ set.inventory_by_size.size150 }}"></td>
				<td>{{ set.total_by_product }}</td>
			</tr>
			{% endfor %}
			{% endfor %}
			{% endfor %}
			{% endif %}
			<tr class="total">
				<td>합계</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
		</table>
		<div class="sizeBtns">
			<button class="sizeSave hide">저장</button>
			<button class="sizeSetting">편집</button>
		</div>
		<h3> 3. 필요 주문현황</h3>
		<table class="table-size-status">
			<colgroup>
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
				<col width="5%">
			</colgroup>
			<caption>[단위:PCS]</caption>
			<tr>
				<th colspan="6"></th>
				<th colspan="8">사이즈</th>
			</tr>
			<tr>
				<th>일자</th>
				<th>유치원명</th>
				<th>연도</th>
				<th>시즌</th>
				<th>품목</th>
				<th>품목명</th>
				<th>90</th>
				<th>100</th>
				<th>110</th>
				<th>120</th>
				<th>130</th>
				<th>140</th>
				<th>150</th>
				<th>합계</th>
			</tr>
			{% if final_set %}
			{% regroup final_set by season as season_list %}
		    {% for season in season_list %}
		    {% regroup season.list by style as style_list %}
		    {% for style in style_list %}
		    {% for set in style.list %}
			{% if style.grouper == "정복" %}
			<tr class="row-size divide-color-formal">
			{% elif style.grouper == "체육복" %}
			<tr class="row-size divide-color-training">
			{% endif %}
				{% if forloop.first %}
				{% if forloop.parentloop.first %}
				{% if forloop.parentloop.parentloop.first %}
				<td rowspan="{{ final_set|length }}" class="backC_No">{{ order.contract_date|date:"Y-m-d" }}</td>
				<td rowspan="{{ final_set|length }}" class="backC_No">{{ order.kindergarten.name }}</td>
				<td rowspan="{{ final_set|length }}" class="backC_No">{{ order.contract_date|date:"y년" }}</td>
				{% endif %}
				<td rowspan="{{ season.list|length }}" class="seasonGroup backC_No">{{ season.grouper }}</td>
				{% endif %}
				<td rowspan="{{ style.list|length }}">{{ style.grouper }}</td>	
				{% endif %}
				<td>
					{{ set.product.product.product_type.get_name_display }}({% if set.gender == 'boy'%}남아{% elif set.gender == 'girl' %}여아{% endif %})
				</td>
				<td>{{ set.required_inventory.size90 }}</td>
				<td>{{ set.required_inventory.size100 }}</td>
				<td>{{ set.required_inventory.size110 }}</td>
				<td>{{ set.required_inventory.size120 }}</td>
				<td>{{ set.required_inventory.size130 }}</td>
				<td>{{ set.required_inventory.size140 }}</td>
				<td>{{ set.required_inventory.size150 }}</td>
				<td>{{ set.required_inventory_total }}</td>
			</tr>
			{% endfor %}
			{% endfor %}
			{% endfor %}
			{% endif %}
			<tr class="total">
				<td>합계</td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
		</table>
	</div>
	<div class="onepage"><br style='height:0; line-height:0'>
		<h3> 4. Size Ratio</h3>
		<div class="SizeRatio">
			<div class="chart1" id="chart1">
			</div>
			<div class="chart2" id="chart2">
			</div>
			<div class="chart3" id="chart3">
			</div>
			<div class="chart4" id="chart4">
			</div>
		</div>
	</div>
</article>
{% endblock content %}
{% block extrascript %}
<script type="text/javascript" src="{% static 'order_contract/custom_admin/business_status/rank/jquery.jqplot.js' %}" ></script>
<script type="text/javascript" src="{% static 'order_contract/custom_admin/business_status/rank/jqplot.barRenderer.js' %}" ></script>
<script type="text/javascript" src="{% static 'order_contract/custom_admin/business_status/rank/jqplot.categoryAxisRenderer.js' %}" ></script>
<script type="text/javascript" src="{% static 'order_contract/custom_admin/business_status/rank/jqplot.canvasAxisLabelRenderer.js' %}" ></script>
<script type="text/javascript" src="{% static 'order_contract/custom_admin/business_status/rank/jqplot.canvasAxisTickRenderer.js' %}" ></script>
<script type="text/javascript" src="{% static 'order_contract/custom_admin/business_status/rank/jqplot.canvasOverlay.js' %}" ></script>
<script type="text/javascript" src="{% static 'order_contract/custom_admin/business_status/rank/jqplot.canvasTextRenderer.js' %}" ></script>
<script type="text/javascript" src="{% static 'measurement/js/size_status.js' %}"></script>
<script type="text/javascript">
	var order_id = '{{ order.id }}';
	var sizeset = {{ size_ratio|safe }};
	for(size in sizeset) {
		sizeset[size] = JSON.parse(sizeset[size]);
	}

	$(document).ready(function(){
		if (sizeset[0] !== undefined) {
			var title1 = sizeset[0].season + sizeset[0].style;
			var size1 = sizeset[0].size;
			var line1 = [
				['90', size1['size90']], 
				['100', size1['size100']], 
				['110', size1['size110']], 
				['120', size1['size120']], 
				['130', size1['size130']], 
				['140', size1['size140']], 
				['150', size1['size150']]
			];
			var plot1 = $.jqplot ('chart1', [line1], {
				title: title1,
				series: [{xaxis:'xaxis',yaxis:'yaxis'}],
				axes:{
					xaxis:{
						renderer: $.jqplot.CategoryAxisRenderer,
						labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
						tickRenderer: $.jqplot.CanvasAxisTickRenderer,
						tickOptions: {
							angle:50
						}
					},
					yaxis: {
						min: 0,
						max: 100
					}
				}
			});
		}
		
		if (sizeset[1] !== undefined) {
			var title2 = sizeset[1].season + sizeset[1].style;
			var size2 = sizeset[1].size;
			var line2 = [
				['90', size2['size90']], 
				['100', size2['size100']], 
				['110', size2['size110']], 
				['120', size2['size120']], 
				['130', size2['size130']], 
				['140', size2['size140']], 
				['150', size2['size150']]
			];
			var plot2 = $.jqplot ('chart2', [line2], {
				title:title2,
				series: [{xaxis:'xaxis',yaxis:'yaxis'}],
				axes:{
					xaxis:{
						renderer: $.jqplot.CategoryAxisRenderer,
						labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
						tickRenderer: $.jqplot.CanvasAxisTickRenderer,
						tickOptions: {
							angle:50
						}
					},
					yaxis: {
						min: 0,
						max: 100
					}
				}
			});
		}

		if (sizeset[2] !== undefined) {		
			var title3 = sizeset[2].season + sizeset[2].style;
			var size3 = sizeset[2].size;
			var line3 = [
				['90', size3['size90']], 
				['100', size3['size100']], 
				['110', size3['size110']], 
				['120', size3['size120']], 
				['130', size3['size130']], 
				['140', size3['size140']], 
				['150', size3['size150']]
			];
			var plot3 = $.jqplot ('chart3', [line3], {
				title:title3,
				series: [{xaxis:'xaxis',yaxis:'yaxis'}],
				axes:{
					xaxis:{
						renderer: $.jqplot.CategoryAxisRenderer,
						labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
						tickRenderer: $.jqplot.CanvasAxisTickRenderer,
						tickOptions: {
							angle:50
						}
					},
					yaxis: {
						min: 0,
						max: 100
					}
				}
			});
		}

		if (sizeset[3] !== undefined) {		
			var title4 = sizeset[3].season + sizeset[3].style;
			var size4 = sizeset[3].size;
			var line4 = [
				['90', size4['size90']], 
				['100', size4['size100']], 
				['110', size4['size110']], 
				['120', size4['size120']], 
				['130', size4['size130']], 
				['140', size4['size140']], 
				['150', size4['size150']]
			];
			var plot4 = $.jqplot ('chart4', [line4], {
				title:title4,
				series: [{xaxis:'xaxis',yaxis:'yaxis'}],
				axes:{
					xaxis:{
						renderer: $.jqplot.CategoryAxisRenderer,
						labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
						tickRenderer: $.jqplot.CanvasAxisTickRenderer,
						tickOptions: {
							angle:50
						}
					},
					yaxis: {
						min: 0,
						max: 100
					}
				}
			});
		}		
	 });
</script>
{% endblock extrascript %}
