<html xmlns="http://www.w3.org/1999/xhtml">
<!--#include file="../Inc/Conn.asp" -->
<!--#include file="../Inc/SK.Session.asp" -->
<!--#include file="../Inc/SK.Funtion.asp" -->
<%if Not (Getconfig("SK_Sales")="0" AND (Session("Manager")="1" OR (JudgePopedomTF(Session("UserName"),"SK300000000") AND JudgePopedomTF(Session("UserName"),"SK300000301")))) then Call ReturnError()%>
<%
Dim PriceAid
PriceAid=conn.execute("select count(*) from SK_SalesProPrice where datediff(day,[SK_Time],getdate())=0")(0)
Dim PriceNN
PriceNN=PriceAid+1

'AddNew
if RQ("Action")="Add" and F("S_Di")<>"" and F("S_ClientID")<>"" and F("S_Title")<>"" and F("S_PriceNo")<>"" and F("S_PriceTime")<>"" then
Call ChkIsOuter()
set rs=server.createobject("adodb.recordset")
sql="select * from SK_SalesProPrice"
rs.open sql,conn,1,3
rs.AddNew
rs("SK_Di")=NoCSSHackInput(F("S_Di"))
rs("SK_ClientID")=NoCSSHackInput(F("S_ClientID"))
rs("SK_PriceNo")=NoCSSHackInput(F("S_PriceNo"))
rs("SK_PriceTitle")=NoCSSHackInput(F("S_Title"))
rs("SK_PriceTime")=NoCSSHackInput(F("S_PriceTime"))
rs("SK_Feet")=NoCSSHackInput(F("S_Feet"))
rs("SK_Currency")=NoCSSHackInput(F("S_Currency"))
rs("SK_Content")=NoCSSHackContent(F("S_Content"))
rs("SK_SalesID")=Session("UID")
rs("SK_Addor")=Session("Oname")
rs("SK_Time")=Now()
rs("SK_Del")="0"

'自定义字段部分开始
set RsField=Server.createobject("adodb.recordset")
sqlField="SELECT * from SK_SalesFields where SK_Di=2 and SK_ShowOnForm=0"
RsField.Open sqlField,conn,1,1
A=0
while not RsField.eof
A=A+1
rs(""&RsField("SK_FieldName")&"")=NoCSSHackInput(F(""&RsField("SK_FieldName")&""))
RsField.movenext
wend
RsField.close
Set RsField=Nothing

set RsOption=Server.createobject("adodb.recordset")
sqlOption="SELECT * from SK_SalesOptions where SK_Di=2 and SK_ShowOnForm=0"
RsOption.Open sqlOption,conn,1,1
B=0
while not RsOption.eof
B=B+1
rs(""&RsOption("SK_FieldName")&"")=NoCSSHackInput(F(""&RsOption("SK_FieldName")&""))
RsOption.movenext
wend
RsOption.close
Set RsOption=Nothing
'自定义字段部分结束

rs.Update

set rs=conn.execute("select @@IDENTITY")
GetNewID=rs(0)

for K=1 to F("rowcount")
if F("P_AA"&K)<>"" and F("P_ID"&K)<>"" then '判断不为空时可录入
set rs1=server.createobject("adodb.recordset")
sql1="select * from SK_SalesProPriceDetail"
rs1.open sql1,conn,1,3
rs1.AddNew
rs1("SK_ProPriceID")=GetNewID
rs1("SK_ProID")=F("P_ID"&K)
rs1("SK_Total")=F("number"&K)
rs1("SK_Price")=F("P_Price"&K)
rs1("SK_SalesID")=Session("UID")
rs1("SK_Addor")=Session("UserName")
rs1("SK_Atime")=Now()
rs1.Update
rs1.close
set rs1=Nothing
end if
next

rs.Close 
set rs=Nothing

'Event Begin
if getconfig("SK_Event")=0 then
set rsEvent=server.createobject("adodb.recordset")
sqlEvent="select * from SK_SystemEvent"
rsEvent.open sqlEvent,conn,1,3
rsEvent.AddNew
rsEvent("SK_Title")="新建产品销售报价："&NoCSSHackInput(F("S_Title"))&""
rsEvent("SK_User")=Session("UserName")
rsEvent("SK_Time")=Now()
rsEvent("SK_IP")=request.ServerVariables("Remote_Addr")
rsEvent.Update
rsEvent.Close 
set rsEvent=Nothing
end if
'Event End
Response.Write("<script LANGUAGE='javascript'>alert('恭喜你,操作成功！');window.close();window.opener.location.reload();</script>")
Response.End
end if
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<title>新建产品销售报价</title>
<META http-equiv=Page-Enter content=SKCRM>
<META http-equiv=Page-Exit content=SKCRM>
<META content="MSHTML 6.00.3790.2858" name=GENERATOR>
<LINK href="../images/style.css" type=text/css rel=stylesheet>
<script language="javascript" src="../Inc/Check.js"></script>
<script language="javascript" src="../Inc/Calendar.js"></script>
<script language="JavaScript" src="../Inc/xmlhttp.js"></script>
<script language="JavaScript" src="../Inc/addrow.js"></script>
<script language="JavaScript" src="../Inc/jquery.js"></script>
<SCRIPT language=javascript src="../inc/Openwin.js"></SCRIPT>
<script>
window.onbeforeunload = function()
{
if (document.body.offsetWidth-50 < event.VendX && event.VendY<0)
{
return "是否关闭当前窗口？关闭本窗口将放弃新建信息！";
}
}
function checkOrdersNo(){
var temp = "";
var temp1 = "";
$.post("../Inc/SK_AjaxProcureOrders.asp",{S_OrdersNo:escape($("#S_OrdersNo").val())},
function(data)
{ 
 if (data == "False"){
	 alert("有重复单号，请再次点击保存");
		temp = $("#tittle_lable").html();
		temp1 = "000"+String(Number(temp.substring(14))+1);
	 $('#tittle_lable').html(temp.substring(0,14)+temp1.substring(temp1.length-4)); 
	 $('#S_OrdersNo').attr("value",$('#tittle_lable').html());
	 return false;
 }
}
);		
}

function bar(){
  if ((event.keyCode == 13) && ($("#S_Tm").val()!="")){
	addrow_bar();
  $.post("../Inc/SK_InPutProTm.asp",{S_Tm:escape($("#S_Tm").val())},
	function(data)
	{ 
	 i=$("#rowcount").val();
	 str=data.split("|");
	 $("#P_AA"+i).val(str[0]);
	 $("#P_ID"+i).val(str[1]);
	 $("#number"+i).val("1");
	 $("#P_Price"+i).val(str[2]);
	}
	);
	$("#S_Tm").val("");
  }
}
function check(){
  if (document.thisForm.S_Client.value=="")
  {
  alert("对不起,请选择关联客户！");
  document.thisForm.S_Client.focus();
  return false;
  }
  if (document.thisForm.S_PriceNo.value=="")
  {
  alert("对不起,报价编号不能为空！");
  document.thisForm.S_PriceNo.focus();
  return false;
  }
  if (document.thisForm.S_Title.value=="")
  {
  alert("对不起,报价主题不能为空！");
  document.thisForm.S_Title.focus();
  return false;
  }
  if (document.thisForm.S_PriceTime.value=="")
  {
  alert("对不起,报价日期不能为空！");
  document.thisForm.S_PriceTime.focus();
  return false;
  }
  if (document.thisForm.S_Di.value=="")
  {
  alert("对不起,请选择报价类别！");
  document.thisForm.S_Di.focus();
  return false;
  }
  if (document.thisForm.S_Feet.value=="")
  {
  alert("对不起,请选择报价状态！");
  document.thisForm.S_Feet.focus();
  return false;
  }
  if (document.thisForm.S_Currency.value=="")
  {
  alert("对不起,请选择货币类别！");
  document.thisForm.S_Currency.focus();
  return false;
  }
  if (document.thisForm.rowcount.value == "") 
  {
  alert("对不起,请添加产品明细！");
  return false;
  }
}

function edit_row(i)
{
window.open ('../Products/SK.SProList.asp?id='+i, 'newwindow', 'height=400, width=800,top=100,left=150,toolbar=no,menubar=no, scrollbars=yes, resizable=no,location=no, status=no')
}

function count(i){
r_price=Number(document.getElementById("P_Price"+i).value);
r_number=Number(document.getElementById("number"+i).value);
document.getElementById("money"+i).value=(r_price*r_number).toFixed(2);
document.getElementById('total_money').value=0;
document.getElementById('total_number').value=0;
  for (j=1;j<document.all.sqd.rows.length;j++)
	{	
	document.getElementById('total_money').value=(Number(document.getElementById('total_money').value)+Number(document.getElementById("money"+j).value)).toFixed(2);
	document.getElementById('total_number').value=Number(document.getElementById('total_number').value)+Number(document.getElementById("number"+j).value);
	}
}

function add_row(){
  //addrow();
	window.open ('../Products/SK.SProList.asp', 'newwindow', 'height=400, width=800,,top=100,left=150,toolbar=no,menubar=no, scrollbars=yes, resizable=no,location=no, status=yes')
}
function del_row() {
  if(sqd.rows.length==1) return;
  var checkit = false
  for (var i=0;i<document.all.delNumber.length;i++) {
    if (document.all.delNumber[i].checked) {
    checkit=true;
    sqd.deleteRow(i+1);
			count(i);
    break;
    }
  }
  if (checkit) {
    for(i=1;i<sqd.rows.length;i++){
    sqd.rows[i].cells[0].innerText=i
		document.getElementById("rowcount").value=sqd.rows.length-1
    }

  } else
  {
  alert("请选择一个要删除的对象");
  return false}
}
</script>
<style type="text/css">
<!--
body {
margin: 5px 0px 5px 0px;
overflow-x: hidden;
}
-->
</style>
</head>
<body>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
<TBODY>
<tr>
<td class="SK_Td_Top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="12" height="25"><img src="../images/tab_03.gif" width="12" height="25" /></td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="46%" valign="middle">新建产品销售报价</td>
<td width="54%"></td>
</tr>
</table></td>
<td width="16"><img src="../images/tab_07.gif" width="16" height="25" /></td>
</tr>
</table></td>
</tr>
<tr>
<td>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="8" background="../images/tab_12.gif"></td>
<td>

<form name="thisForm" id="form1" method="post" action="?Action=Add" onKeyPress="if(event.keyCode==13){return false;}">
<input type="hidden" id="rowcount" name="rowcount">
<input type="hidden" name="_check" id="_check" value="false">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="b5d6e6">

<tr>
  <td width="14%" class="SK_Text2">关联客户</td>
  <td class="SK_Text1"><input name="S_Client" type="text" size="30" readonly>
<input name="S_ClientID" type="hidden">
<a onClick="JavaScript:window.open('../Client/SK.SeMyClient.asp','SClinet','directorys=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=820,height=400,top=176,left=161');" style="cursor:hand"><img src="../images/sclient.gif" /></a> <font color=red>*</font>
 <input name="S_Linkman" type="hidden">
  <input name="S_LinkmanID" type="hidden">  </td>
  <td width="13%" class="SK_Text2">报价编号</td>
  <td width="40%" class="SK_Text1"><input name="S_PriceNo" type="text" size="20" value="PR<%=Year(Date())%><%=right("0"&Month(Date()),2)%><%=right("0"&Day(Date()),2)%>-<%=right(("00"&PriceNN),3)%>"> <font color=red>*</font></td>
</tr>
<tr>
  <td class="SK_Text2">报价主题</td>
  <td class="SK_Text1"><input name="S_Title" type="text" size="35"> <font color=red>*</font></td>
  <td class="SK_Text2">报价日期</td>
  <td class="SK_Text1"><input name="S_PriceTime" type="text" size="12" onClick="new Calendar().show(this);" value="<%=Date()%>" readOnly /> <font color=red>*</font></td>
</tr>
<tr>
  <td class="SK_Text2">报价类别</td>
  <td class="SK_Text1"><select name="S_Di">
<option value="" selected>---请选择---</option>
<%
Set rsDi=Server.CreateObject("ADODB.RecordSet") 
sqlDi="SELECT * from SK_SystemCategory where SK_Di=43 order by CategoryID asc" 
rsDi.Open sqlDi,conn,1,1
do while not rsDi.eof
%><option value="<%=rsDi("CategoryID")%>"><%=rsDi("SK_Name")%></option>
<%
rsDi.movenext
loop
rsDi.close
set rsDi=Nothing
%></select> <font color=red>*</font></td>
  <td class="SK_Text2">报价状态</td>
  <td class="SK_Text1"><select name="S_Feet">
<option value="" selected>---请选择---</option>
<option value="0">计划报价</option>
<option value="1">已经报价</option>
</select> <font color=red>* 已经报价将不能修改</font></td>
</tr>
<tr>
  <td class="SK_Text2">货币类别</td>
  <td class="SK_Text1"><select name="S_Currency">
<option value="" selected>---请选择---</option>
<%
Set rsCurrency=Server.CreateObject("ADODB.RecordSet") 
sqlCurrency="SELECT * from SK_SystemCategory where SK_Di=142 order by CategoryID asc" 
rsCurrency.Open sqlCurrency,conn,1,1
do while not rsCurrency.eof
%><option value="<%=rsCurrency("CategoryID")%>"><%=rsCurrency("SK_Name")%></option>
<%
rsCurrency.movenext
loop
rsCurrency.close
set rsCurrency=Nothing
%></select> <font color=red>*</font></td>
  <td class="SK_Text2">&nbsp;</td>
  <td class="SK_Text1">&nbsp;</td>
</tr>

<tr>
  <td valign="top" class="SK_Text2">报价备注</td>
  <td colspan="3" class="SK_Text1"><IFRAME ID="eWebEditor1" SRC="<%=getconfig("SK_EditorPath")%>/ewebeditor.htm?id=S_Content&style=mini" FRAMEBORDER="0" SCROLLING="no" WIDTH="600" HEIGHT="200"></IFRAME>
<input type="hidden" name="S_Content"></td>
</tr>
<%
'自定义选项开始
set RsOptions=server.createobject("adodb.recordset")
sqlOptions="SELECT * from SK_SalesOptions where SK_Di=2 and SK_ShowOnForm=0 Order by SK_OrderID asc"
RsOptions.Open sqlOptions,conn,1,1
if RsOptions.bof and RsOptions.eof then
else
%>
<tr>
  <td colspan="4" class="SK_Title1">自定义选项</td>
  </tr>
<tr>
  <td colspan="4" class="SK_Text1">
<%
Response.write"<table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""1"">"
for Optionsi=1 to RsOptions.recordCount '变量i从1循环到数据库中的全部记录数 
if (Optionsi mod 2 =1) then '每个tr即每行显示1个记录,可根据需要自行修改, 将左边的1修改为2即显示两行。
response.write "<tr>" 
end if
Response.write"<td class=""SK_Text2"" width=""14%"">"&RsOptions("SK_Title")&"</td><td class=""SK_Text1""><select name="&RsOptions("SK_FieldName")&">"

Set rsOptionsDetail=Server.CreateObject("ADODB.RecordSet") 
sqlOptionsDetail="SELECT * from SK_SalesOptionsDetail where SK_OptionsID="&RsOptions("FieldID")&"" 
rsOptionsDetail.Open sqlOptionsDetail,conn,1,1
Response.write"<option value="""" selected>--请选择--</option>"
do while not rsOptionsDetail.eof
Response.write"<option value="&rsOptionsDetail("OptionsDetailID")&">"&rsOptionsDetail("SK_OName")&"</option>"
rsOptionsDetail.movenext
loop
rsOptionsDetail.close
set rsOptionsDetail=Nothing

Response.write"</select></td>"
if (Optionsi mod 2 = 0) then '每个tr即每行显示1个记录,可根据需要自行修改, 将左边的1修改为2即显示两行。
response.write "</tr>" 
end if 
RsOptions.movenext 
next 
Response.write"</table>"
%>
</td>
</tr>
<%
end if
RsOptions.close
set RsOptions=Nothing
'自定义选项结束

'自定义字段开始
set RsFields=server.createobject("adodb.recordset")
sqlFields="SELECT * from SK_SalesFields where SK_Di=2 and SK_ShowOnForm=0 Order by SK_OrderID asc"
RsFields.Open sqlFields,conn,1,1
if RsFields.bof and RsFields.eof then
else
%>
<tr>
  <td colspan="4" class="SK_Title1">自定义字段</td>
  </tr>
<tr>
  <td colspan="4" class="SK_Text1">
<%
Response.write"<table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""1"">"
for Fieldsi=1 to RsFields.recordCount '变量i从1循环到数据库中的全部记录数 
if (Fieldsi mod 2 =1) then '每个tr即每行显示1个记录,可根据需要自行修改, 将左边的1修改为2即显示两行。
response.write "<tr>" 
end if
Response.write"<td class=""SK_Text2"" width=""14%"">"&RsFields("SK_Title")&"</td><td class=""SK_Text1""><input type=""text"" size=""20"" name="&RsFields("SK_FieldName")&" title="&RsFields("SK_Tips")&"></td>"
if (Fieldsi mod 2 = 0) then '每个tr即每行显示1个记录,可根据需要自行修改, 将左边的1修改为2即显示两行。
response.write "</tr>" 
end if 
RsFields.movenext 
next 
Response.write"</table>"
%>
</td>
</tr>
<%
end if
RsFields.close
set RsFields=Nothing
'自定义字段结束
%>
<tr>
  <td colspan="4" valign="top" class="SK_Title1">产品明细 <input name="add" type="button" onClick="add_row()" class="button1" value=" 添加 ">
<input name="del" onClick="del_row()" type="button" class="button1" value=" 删除 ">
&nbsp;&nbsp;输入条形码：<input name="S_Tm" id="S_Tm" size="16" onKeyUp="bar();"></td>
</tr>
<tr>
  <td colspan="4" valign="top" class="SK_Text">
<!--产品列表开始-->
<TABLE width="100%" border=1 align="center" cellPadding=1 cellSpacing=0 borderColor=#ffffff borderColorLight=#dfdfdf borderColorDark=#ffffff id="sqd">
<tr>
  <th width="6%" class="Pheadtd">编号</th>
  <th width="7%" class="Pheadtd">选择</th>
  <th width="40%" class="Pheadtd">产品名称</th>
  <th width="16%" class="Pheadtd">单价</th>
  <th width="16%" class="Pheadtd">数量</th>
  <th width="15%" class="Pheadtd">金额</th>
</tr>
</table>

<table width="100%" id="sqd1" align="center" border="1" cellpadding="1" cellspacing="0" borderColor=#ffffff borderColorLight=#dfdfdf borderColorDark=#ffffff>
<tr>
  <td width=69% class="SK_Text">合计</td>
  <td width=16%><input id="total_number" type="text" size="8" readOnly></td>
  <td width=15%><input id="total_money" type="text" size="8" readOnly></td>
  </tr>
</table>
<!--产品列表结束-->
</td>
</tr>

<tr>
<td colspan="4" class="SK_Text">
<input type="submit" onClick="return check();" class="button1" value=" 保 存 " name="B1">
<input type="button" value=" 关闭 " onClick="window.opener.location.reload();window.close();" class="button1" /></td>
</tr>
</table>
</form>

</td>
<td width="8" background="../images/tab_15.gif"></td>
</tr>
</table></td>
</tr>
<tr>
<td class="SK_Td_Foot">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="1%" height="20"><img src="../images/tab_18.gif" width="12" height="20" /></td>
<td width="98%" class="SK_Td_Page"></td>
<td width="1%"><img src="../images/tab_20.gif" width="16" height="20" /></td>
</tr>
</table>

</td>
</tr>
</TBODY>
</table>
</body>
<%
Call CloseDB()
%>
</html>