<?page title="${labels.Order}" contentType="text/html;charset=UTF-8"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?taglib uri="/WEB-INF/security.tld" prefix="sec"?>
<zk>
	<window
		id="editWin"
		width="95%"
		height="95%"
		closable="true"
		border="normal"
		position="center"
		apply="org.zkoss.bind.BindComposer"
		viewModel="@id('vm') @init('info.bukova.isspst.ui.main.orders.created.OrderForm')"
		validationMessages="@id('vmsg')">
		<caption
			image="/img/autotruck-032.png"
			zclass="form-caption"
			label="${labels.Order}" />
		<vlayout
			sclass="addScrollbar"
			form="@id('fx') @init(vm.dataForm) @load(vm.dataBean) @save(vm.dataBean, before='save') @validator(vm.orderFormValidator)"
			hflex="1"
			vflex="1">
			<hlayout
				hflex="1"
				vflex="min">
				<tabbox
					hflex="10"
					vflex="1">
					<tabs>
						<tab label="${labels.Information}" />
					</tabs>
					<tabpanels>
						<tabpanel>
							<grid
								hflex="max"
								vflex="max">
								<columns>
									<column
										align="right"
										hflex="min" />
									<column />
								</columns>
								<rows vflex="max">
									<row>
										<cell sclass="row-title"></cell>
										<cell>
											<checkbox
												id="idOrderOrdered"
												disabled="@load(fx.icludedRequirementItemFromAnotherOrder)"
												label="${labels.OrderFormOrdered}"
												checked="@bind(fx.ordered)" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.OrderFormNumber} :</cell>
										<cell>
											<textbox
												id="idOrderNumber"
												width="150px"
												constraint="@load(vm.constriant)"
												value="@bind(fx.numser)"
												placeholder="${labels.NotYetFilled}..."
												readonly="true" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.OrderFormOrderDate} :</cell>
										<cell>
											<datebox
												id="idOrderDate"
												width="150px"
												value="@bind(fx.orderDate)"
												format="${labels.DateFormat}" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.OrderFormTotal} :</cell>
										<cell>
											<textbox
												id="idOrderTotal"
												readonly="true"
												width="150px"
												value="@bind(fx.total) @converter(vm.standardBigDecimalConverter)" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.RequirementsFormDeliveryDate} :</cell>
										<cell>
											<datebox
												id="idDeliveryDate"
												width="150px"
												value="@bind(fx.deliveryDate)"
												format="${labels.DateFormat}" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.OrderFormDeliveredDate} :</cell>
										<cell>
											<datebox
												id="idDeliveredDate"
												width="150px"
												value="@bind(fx.deliveredDate)"
												format="${labels.DateFormat}" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.OrderFormDescription} :</cell>
										<cell>
											<textbox
												id="idOrderDescription"
												width="100%"
												rows="5"
												value="@bind(fx.description)" />
										</cell>
									</row>
								</rows>
							</grid>
						</tabpanel>
					</tabpanels>
				</tabbox>
				<tabbox
					hflex="15"
					vflex="1">
					<tabs>
						<tab label="${labels.SuppliersFormTitle}" />
						<tab label="${labels.DeliveryAddress}" />
						<tab label="${labels.BillingAddress}" />
					</tabs>
					<tabpanels>
						<tabpanel>
							<grid
								hflex="1"
								vflex="1">
								<columns>
									<column
										align="right"
										hflex="min" />
									<column />
									<column
										align="right"
										hflex="min" />
									<column />
								</columns>
								<rows vflex="max">
									<row>
										<cell sclass="row-title">${labels.SuppliersFormCompany} :</cell>
										<cell colspan="3">
											<hbox hflex="1">
												<combobox
													ctrlKeys="${labels.HandleComboKey}"
													onCtrlKey="@command('handleComboKey', ctrl=self, keyEvent=event)"
													onChange="@command('doFillSuppAddress')"
													hflex="4"
													selectedItem="@bind(vm.selectedSuppAddrItem)"
													value="@bind(vm.suppCompany)"
													model="@load(vm.suppAddresses)"
													instant="true"
													readonly="false">
													<template name="model">
														<comboitem label="@load(each)" />
													</template>
												</combobox>
												<hbox hflex="2">
													<button image="/img/search.png" 
														label="${labels.SuppliersFormFindInARES}" 
														sclass="nicebutton" 
														disabled="@load((not empty vm.selectedSuppAddrItem) or ((empty vm.suppCompany) and (fx.suplier.ic eq 0)))" 
														onClick="@command('searchAddress')"/>
												</hbox>
											</hbox>
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormIC} :</cell>
										<cell>
											<textbox
												id="idSuppIC"
												value="@bind(fx.suplier.ic)"
												instant="true" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormDIC} :</cell>
										<cell>
											<textbox
												id="idSuppDIC"
												value="@bind(fx.suplier.dic)" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormDepartment} :</cell>
										<cell>
											<textbox
												id="idSuppDepartment"
												value="@bind(fx.suplier.department)"
												width="100%" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormContact} :</cell>
										<cell>
											<textbox
												id="idSuppContactName"
												value="@bind(fx.suplier.contactName)"
												width="100%" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormStreet} :</cell>
										<cell>
											<textbox
												id="idSuppStreet"
												value="@bind(fx.suplier.street)"
												width="100%" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormNo} :</cell>
										<cell>
											<textbox
												id="idSuppHouseNumber"
												value="@bind(fx.suplier.houseNumber)" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormCity} :</cell>
										<cell>
											<textbox
												id="idSuppCity"
												value="@bind(fx.suplier.city)"
												width="100%" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormZIP} :</cell>
										<cell>
											<textbox
												id="idSuppZIP"
												value="@bind(fx.suplier.zipCode)" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormPhone} :</cell>
										<cell>
											<textbox
												id="idSuppPhone"
												value="@bind(fx.suplier.phone)" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormEmail} :</cell>
										<cell>
											<textbox
												id="idSuppEmail"
												value="@bind(fx.suplier.email)"
												width="100%" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormWWW} :</cell>
										<cell colspan="3">
											<textbox
												id="idSuppWWW"
												value="@bind(fx.suplier.web)"
												width="100%" />
										</cell>
									</row>
								</rows>
							</grid>
						</tabpanel>
						<tabpanel>
							<grid
								hflex="1"
								vflex="1">
								<columns>
									<column
										align="right"
										hflex="min" />
									<column />
									<column
										align="right"
										hflex="min" />
									<column />
								</columns>
								<rows vflex="max">
									<row>
										<cell sclass="row-title">${labels.SuppliersFormCompany} :</cell>
										<cell colspan="3">
											<combobox
												ctrlKeys="${labels.HandleComboKey}"
												onCtrlKey="@command('handleComboKey', ctrl=self, keyEvent=event)"
												onChange="@command('doFillDeliveryAddress')"
												width="100%"
												selectedItem="@bind(vm.selectedDeliveryAddrItem)"
												value="@bind(vm.deliveryCompany)"
												model="@load(vm.deliveryAddresses)"
												readonly="false">
												<template name="model">
													<comboitem label="@load(each)" />
												</template>
											</combobox>
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormIC} :</cell>
										<cell>
											<textbox
												id="idDeliveryIC"
												value="@bind(fx.deliveryAddress.ic)" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormDIC} :</cell>
										<cell>
											<textbox
												id="idDeliveryDIC"
												value="@bind(fx.deliveryAddress.dic)" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormDepartment} :</cell>
										<cell>
											<textbox
												id="idDeliveryDepartment"
												value="@bind(fx.deliveryAddress.department)"
												width="100%" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormContact} :</cell>
										<cell>
											<textbox
												id="idDeliveryContactName"
												value="@bind(fx.deliveryAddress.contactName)"
												width="100%" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormStreet} :</cell>
										<cell>
											<textbox
												id="idDeliveryStreet"
												value="@bind(fx.deliveryAddress.street)"
												width="100%" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormNo} :</cell>
										<cell>
											<textbox
												id="idDeliveryHouseNumber"
												value="@bind(fx.deliveryAddress.houseNumber)" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormCity} :</cell>
										<cell>
											<textbox
												id="idDeliveryCity"
												value="@bind(fx.deliveryAddress.city)"
												width="100%" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormZIP} :</cell>
										<cell>
											<textbox
												id="idDeliveryZIP"
												value="@bind(fx.deliveryAddress.zipCode)" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormPhone} :</cell>
										<cell>
											<textbox
												id="idDeliveryPhone"
												value="@bind(fx.deliveryAddress.phone)" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormEmail} :</cell>
										<cell>
											<textbox
												id="idDeliveryEmail"
												value="@bind(fx.deliveryAddress.email)"
												width="100%" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormWWW} :</cell>
										<cell colspan="3">
											<textbox
												id="idDeliveryWWW"
												value="@bind(fx.deliveryAddress.web)"
												width="100%" />
										</cell>
									</row>
								</rows>
							</grid>
						</tabpanel>
						<tabpanel>
							<grid
								hflex="1"
								vflex="1">
								<columns>
									<column
										align="right"
										hflex="min" />
									<column />
									<column
										align="right"
										hflex="min" />
									<column />
								</columns>
								<rows vflex="max">
									<row>
										<cell sclass="row-title">${labels.SuppliersFormCompany} :</cell>
										<cell colspan="3">
											<textbox
												id="idInvoiceCompany"
												value="@bind(fx.address.company)"
												width="100%" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormIC} :</cell>
										<cell>
											<textbox
												id="idInvoiceIC"
												value="@bind(fx.address.ic)" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormDIC} :</cell>
										<cell>
											<textbox
												id="idInvoiceDIC"
												value="@bind(fx.address.dic)" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormDepartment} :</cell>
										<cell>
											<textbox
												id="idInvoiceDepartment"
												value="@bind(fx.address.department)"
												width="100%" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormContact} :</cell>
										<cell>
											<textbox
												id="idInvoiceContactName"
												value="@bind(fx.address.contactName)"
												width="100%" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormStreet} :</cell>
										<cell>
											<textbox
												id="idInvoiceStreet"
												value="@bind(fx.address.street)"
												width="100%" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormNo} :</cell>
										<cell>
											<textbox
												id="idInvoiceHouseNumber"
												value="@bind(fx.address.houseNumber)" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormCity} :</cell>
										<cell>
											<textbox
												id="idInvoiceCity"
												value="@bind(fx.address.city)"
												width="100%" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormZIP} :</cell>
										<cell>
											<textbox
												id="idInvoiceZIP"
												value="@bind(fx.address.zipCode)" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormPhone} :</cell>
										<cell>
											<textbox
												id="idInvoicePhone"
												value="@bind(fx.address.phone)" />
										</cell>
										<cell sclass="row-title">${labels.SuppliersFormEmail} :</cell>
										<cell>
											<textbox
												id="idInvoiceEmail"
												value="@bind(fx.address.email)"
												width="100%" />
										</cell>
									</row>
									<row>
										<cell sclass="row-title">${labels.SuppliersFormWWW} :</cell>
										<cell colspan="3">
											<textbox
												id="idInvoiceWWW"
												value="@bind(fx.address.web)"
												width="100%" />
										</cell>
									</row>
								</rows>
							</grid>
						</tabpanel>
					</tabpanels>
				</tabbox>
			</hlayout>
			<listbox
				vflex="1"
				selectedItem="@bind(vm.selectedItem)"
				model="@load(vm.syncOrderItems)">
				<listhead menupopup="auto">
					<listheader
						hflex="7"
						sort="czech(code)"
						label="${labels.RequirementItemCode}" />
					<listheader
						hflex="15"
						sort="czech(name)"
						label="${labels.RequirementItemName}" />
					<listheader
						hflex="20"
						sort="czech(textItem)"
						label="${labels.RequirementItemText}" />
					<listheader
						hflex="5"
						sort="auto(quantity)"
						align="right"
						label="${labels.RequirementItemQuantity}" />
					<listheader
						hflex="5"
						sort="auto(munit.name)"
						label="${labels.RequirementItemMUnit}" />
					<listheader
						hflex="7"
						align="right"
						sort="auto(unitPrice)"
						label="${labels.RequirementItemUnitPrice}" />
					<listheader
						hflex="7"
						align="right"
						sort="auto(total)"
						label="${labels.RequirementItemTotal}" />
					<listheader
						hflex="15"
						sort="czech(description)"
						label="${labels.RequirementItemDescription}" />
					<listheader
						hflex="5"
						sort="auto(reqItem.orderNum)"
						label="${labels.OrderAbr}" />
				</listhead>
				<template name="model">
					<listitem>
						<listcell label="@load(each.code)" />
						<listcell label="@load(each.name)" />
						<listcell label="@load(each.textItem)" />
						<listcell>
							<textbox
								inplace="true"
								sclass="grid-textbox-max-right"
								readonly="true"
								onFocus="@command('onFocusItem', item=each, ctrl=self)"
								onChange="@command('recalculate', form=fx, changed='quantity')"
								value="@bind(each.quantity) @converter(vm.standardBigDecimalConverter)" />
						</listcell>
						<listcell label="@load(each.munit.name)" />
						<listcell>
							<textbox
								inplace="true"
								sclass="grid-textbox-max-right"
								readonly="${not sec:isAllGranted('ROLE_ADMIN')}"
								onFocus="@command('onFocusItem', item=each, ctrl=self)"
								onChange="@command('recalculate', form=fx, changed='unitPrice')"
								value="@bind(each.unitPrice) @converter(vm.standardBigDecimalConverter)" />
						</listcell>
						<listcell>
							<textbox
								inplace="true"
								sclass="grid-textbox-max-right"
								readonly="${not sec:isAllGranted('ROLE_ADMIN')}"
								onFocus="@command('onFocusItem', item=each, ctrl=self)"
								onChange="@command('recalculate', form=fx, changed='total')"
								value="@bind(each.total) @converter(vm.standardBigDecimalConverter)" />
						</listcell>
						<listcell label="@load(each.description)" />
						<listcell label="@load(each.reqItem.orderNum)" />
					</listitem>
				</template>
			</listbox>
			<include
				vflex="min"
				src="/app/formButtons.zul" />
		</vlayout>
	</window>
</zk>