<cfinclude template="/corporate/tags/form.title.cfm">
<cfif IsDefined("error") and Len(error)><cfinclude template="/corporate/tags/form.error.cfm"></cfif>
<cfset isEdit=form.appObject.getFormIsEdit()>
<cfif isModule><div style="display:none " id="<cfoutput>#form.appObject.getModuleName()#</cfoutput>_dataDiv"></cfif>
<table width="100%" border="1" bordercolor="#00008B" class="borderCollapse" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
	<tr>
		<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td width="50%" align="left" valign="top"><table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
					<tr>
						<td class="formItemName"><b><cfoutput>#messages.form.salesClientState#</cfoutput></b></td>
						<td>
						<cfif isEdit and form.appObject.getIdSalesClientUnit() gt 0>
							<select name="<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>idSalesClientState">
								<cfset _selectObject=form.appObject.getSalesClientState()>
								<cfif _employeeAccessProfile.getIdAccessProfile() eq application.accessProfile.sales>
									<cfset _selectObject.createSalesOptions(form.appObject.getIdSalesClientState())>
								<cfelse>
									<cfset _selectObject.createOptions(form.appObject.getIdSalesClientState())>
								</cfif>
							</select>
						<cfelse>
							<cfoutput>#form.appObject.getSalesClientState().getName()#</cfoutput>
							<cfset _salesClientUnitStateHistory=form.appObject.getSalesClientUnitStateHistory()>
							<cfset _salesClientUnitStateHistory.init()>
							<cfset _salesClientUnitStateHistory.setIdSalesClientUnit(form.appObject.getIdSalesClientUnit())>
							<cfset _salesClientUnitStateHistory.setIdSalesClientState(form.appObject.getIdSalesClientState())>
							<cfset _history=_salesClientUnitStateHistory.getList()>
							<cfif _history.recordcount gt 0>
								<br>
								<cfoutput>
									<b>Responsable:</b> #ToString(_history.employee)#<br>
									<b>Fecha:</b> #LSDateFormat(_history.dateRegistration, "dd/mm/yyyy")# #LSTimeFormat(_history.dateRegistration, "HH:mm")#
								</cfoutput>
							</cfif>
						</cfif>
						</td>
					</tr>
					<tr>
						<td class="formItemName"><b><cfoutput>#messages.form.project#</cfoutput></b></td>
						<td>
						<cfif isEdit and form.appObject.getIdSalesClientState() lte application.salesClientState.registered>
							<select name="<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>idProject" onChange="document.processForm.submit()">
								<cfset _selectObject=session.employee.getEmployeeAccessProfile()>
								<cfset form.appObject.setIdProject(_selectObject.createProjectOptions(form.appObject.getIdProject()))>
							</select>
						<cfelse>
							<cfoutput>#form.appObject.getProject().getName()#</cfoutput>
							<input type="hidden" name="<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>idProject" value="<cfoutput>#form.appObject.getIdProject()#</cfoutput>">
						</cfif>
						</td>
					</tr>
					<tr>
						<td class="formItemName"><b><cfoutput>#messages.form.salesUnit#</cfoutput></b></td>
						<td>
						<cfif isEdit and form.appObject.getIdSalesClientState() lte application.salesClientState.registered>
							<cfset _selectObject=form.appObject.getSalesUnit()>
							<cfset _selectObject.setIdProject(form.appObject.getIdProject())>
							<select name="<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>idSalesUnit" onChange="document.processForm.<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>sellPrice.value=0; document.processForm.<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>price.value=0; document.processForm.submit()">
								<cfset form.appObject.setIdSalesUnit(_selectObject.createAvailableOptions(form.appObject.getIdSalesUnit()))>
							</select>
							<input type="button" class="button" value="Ver datos de la unidad" onClick="showUnitData('salesUnit', 'view.print', <cfoutput>#form.appObject.getIdSalesUnit()#</cfoutput>, '/sales/salesUnit/index.cfm');">
							<input type="hidden" name="salesUnit_objectId" id="salesUnit_objectId" value="0">
							<input type="hidden" name="salesUnit_pageAction" id="salesUnit_pageAction" value="view.print">
<script language="javascript">
function showUnitData(moduleName, pageAction, id, page) {
	var prevAction=document.processForm.action;
	document.processForm.action=page;
	formActions(moduleName, pageAction, id, page);
	document.processForm.action=prevAction;
}
</script>
						<cfelse>
							<cfoutput>#form.appObject.getSalesUnit().getNumber()#</cfoutput>
							<input type="hidden" name="<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>idSalesUnit" value="<cfoutput>#form.appObject.getIdSalesUnit()#</cfoutput>">
						</cfif>
						</td>
					</tr>
					<tr>
						<td class="formItemName"><b><cfoutput>#messages.form.salesPaymentPlan#</cfoutput></b></td>
						<td>
						<cfif isEdit>
							<select name="<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>idSalesPaymentPlan" onChange="document.processForm.<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>sellPrice.value=0; document.processForm.<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>price.value=0; document.processForm.submit()">
								<option value="0"><cfoutput>#messages.na#</cfoutput></option>
								<cfif form.appObject.getIdSalesPaymentPlan() lt 1>
									<cfset form.appObject.setIdSalesPaymentPlan(form.appObject.getProject().getIdSalesPaymentPlan())>
								</cfif>
								<cfset _selectObject=form.appObject.getSalesPaymentPlan()>
								<cfset _selectObject.setIdProject(form.appObject.getIdProject())>
								<cfset _selectObject.createOptions(form.appObject.getIdSalesPaymentPlan())>
							</select>
						<cfelse>
							<cfoutput>#form.appObject.getSalesPaymentPlan().getName()#</cfoutput>
						</cfif>
						</td>
					</tr>
					<tr>
						<td class="formItemName"><b><cfoutput>#messages.form.sellPrice#</cfoutput></b></td>
						<td>
						<cfif isEdit>
							<!--- check if we have to define the sell price --->
							<cfif not Compare("$0.00", form.appObject.getSellPrice())>
								<!--- get default sell price --->
								<cfset _sellPrice=form.appObject.getSalesUnit().getPrice()>
								<!--- check if user have a sales payment plan selected --->
								<cfif form.appObject.getIdSalesPaymentPlan() gt 0>
									<!--- currency to number --->
									<cfset _sellPrice=form.appObject.parseCurrency(_sellPrice)>
									<!--- get sales payment plan info --->
									<cfset _salesPaymentPlan=form.appObject.getSalesPaymentPlan()>
									<cfset _sellPrice=_sellPrice+(_sellPrice*_salesPaymentPlan.getIncrement()/100)>
									<cfset form.appObject.setSellPrice(_sellPrice)>
									<cfset _sellPrice=LSCurrencyFormat(_sellPrice)>
								</cfif>
							<cfelse>
								<cfset _sellPrice=form.appObject.getSellPrice()>
							</cfif>
							<input onChange="formatCurrency(document.processForm.<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>sellPrice); document.processForm.submit();" 
							name="<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>sellPrice" type="text" 
							value="<cfoutput>#_sellPrice#</cfoutput>" size="20" maxlength="200">
							<cfset _currencyObj=form.appObject.getSalesUnit().getCurrency()>
							<cfoutput>#_currencyObj.getName()#</cfoutput><input type="hidden" name="<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>idCurrency" value="<cfoutput>#_currencyObj.getIdCurrency()#</cfoutput>">
						<cfelse>
							<cfoutput>#form.appObject.getSellPrice()# #form.appObject.getCurrency().getName()#</cfoutput>
						</cfif>
						</td>
					</tr>
				</table></td>
				<td width="50%" align="left" valign="top"><table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
					<tr>
						<td class="formItemName"><b><cfoutput>#messages.form.dateRegistration#</cfoutput></b></td>
						<td>
							<cfoutput>#form.appObject.getDateRegistration()#</cfoutput>
						</td>
					</tr>
					<tr>
						<td class="formItemName"><b><cfoutput>#messages.form.employee#</cfoutput></b></td>
						<td>
						<cfif isEdit and IsUserInRole("viewFull") and session.employee.getIdEmployeeType() neq application.employeeType.external>
							<cfset _selectObject=session.employee.getEmployeeAccessProfile()>
							<select name="<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>idEmployee">
								<cfset _selectObject.createSellerOptions(form.appObject.getIdEmployee())>
							</select>
						<cfelse>
							<cfif form.appObject.getIdEmployee() lt 1>
								<cfset form.appObject.setIdEmployee(session.employee.getIdEmployee())>
							</cfif>
							<input type="hidden" name="<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>idEmployee" value="<cfoutput>#form.appObject.getIdEmployee()#</cfoutput>">
							<cfoutput>#form.appObject.getEmployee().getNameFull()#</cfoutput>
						</cfif>
						</td>
					</tr>
					<tr>
						<td class="formItemName"><b><cfoutput>#messages.form.salesContactMedia#</cfoutput></b></td>
						<td>
						<cfif isEdit>
							<select name="<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>idSalesContactMedia">
								<option value="0"><cfoutput>#messages.na#</cfoutput></option>
								<cfset _selectObject=form.appObject.getSalesContactMedia()>
								<cfset _selectObject.setIdProject(form.appObject.getIdProject())>
								<cfset _selectObject.createOptions(form.appObject.getIdSalesContactMedia())>
							</select>
						<cfelse>
							<cfoutput>#form.appObject.getSalesContactMedia().getName()#</cfoutput>
						</cfif>
						</td>
					</tr>
					<tr>
						<td class="formItemName"><b><cfoutput>#messages.form.salesContact#</cfoutput></b></td>
						<td>
						<cfif isEdit>
							<select name="<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>idSalesContact">
								<option value="0"><cfoutput>#messages.na#</cfoutput></option>
								<!--- <cfset form.appObject.getSalesContact().createOptions(form.appObject.getIdSalesContact())> --->
								<cfquery name="qSalesContact" datasource="#application.datasource#">
									SELECT salesContact.idSalesContact, salesContact.idProject, project.name AS project, salesContact.name
									FROM salesContact
									LEFT JOIN project ON salesContact.idProject=project.idProject
									WHERE salesContact.idProject = #form.appObject.getIdProject()#
												OR salesContact.idProject IS NULL
									ORDER BY salesContact.idSalesContact ASC
								</cfquery>
								<cfoutput query="qSalesContact">
									<option value="#qSalesContact.idSalesContact#"<cfif qSalesContact.idSalesContact eq form.appObject.getIdSalesContact()> selected</cfif>>#qSalesContact.name#</option>
								</cfoutput>
							</select>
						<cfelse>
							<cfoutput>#form.appObject.getSalesContact().getName()#</cfoutput>
						</cfif>
						</td>
					</tr>
					<cfif form.appObject.getIdSalesClientState() neq application.salesClientState.client>
					<tr>
						<td class="formItemName"><b><cfoutput>#messages.form.price#</cfoutput></b></td>
						<td>
						<cfif not Compare("$0.00", form.appObject.getPrice())>
							<!--- get default sell price --->
							<cfset _sellPrice=form.appObject.getSalesUnit().getPrice()>
							<!--- check if user have a sales payment plan selected --->
							<cfif form.appObject.getIdSalesPaymentPlan() gt 0>
								<!--- currency to number --->
								<cfset _sellPrice=form.appObject.parseCurrency(_sellPrice)>
								<!--- get sales payment plan info --->
								<cfset _salesPaymentPlan=form.appObject.getSalesPaymentPlan()>
								<cfset _sellPrice=_sellPrice+(_sellPrice*_salesPaymentPlan.getIncrement()/100)>
								<cfset form.appObject.setPrice(_sellPrice)>
								<cfset _sellPrice=LSCurrencyFormat(_sellPrice)>
							</cfif>
						<cfelse>
							<cfset _sellPrice=form.appObject.getPrice()>
						</cfif>
							<cfoutput>#form.appObject.getPrice()# #form.appObject.getCurrency().getName()#</cfoutput>
							<input type="hidden" name="<cfoutput>#form.appObject.getFormPrefix()#</cfoutput>price" value="<cfoutput>#form.appObject.getPrice()#</cfoutput>">
						</td>
					</tr>
					</cfif>
				</table></td>
			</tr>
		</table>
		<cfset showPrintButton=true>
		<cfinclude template="form.buttons.cfm">
		<cfset showPrintButton=false>
		</td>
	</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td><img src="/images/tr.gif" width="100" height="1"></td></tr></table>
<cfif isModule></div><cfif isEdit or (IsDefined("showDataDiv") and showDataDiv)><script language="javascript"><cfoutput>#form.appObject.getModuleName()#</cfoutput>_showData();</script></cfif></cfif>
