<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"),"SK300000702")))) then Call ReturnError()%>
<%
if not isnumeric(JCID(F("ID"))) then Call ReturnError10()
set rs=server.createobject("adodb.recordset")
if Session("Manager")=1 or Session("Manager")=2 then
sql="SELECT * from SK_SalesReturns where SK_Feet<>3 AND ReturnsID="&JCID(F("ID"))&""
elseif Session("Manager")=3 then
sql="SELECT * from SK_SalesReturns where SK_Feet<>3 AND ReturnsID="&JCID(F("ID"))&""
elseif Session("Manager")=4 then
sql="SELECT * from SK_SalesReturns where SK_Feet<>3 AND ReturnsID="&JCID(F("ID"))&""
elseif Session("Manager")=5 then
sql="SELECT * from SK_SalesReturns where SK_Feet<>3 AND ReturnsID="&JCID(F("ID"))&""
elseif Session("Manager")=6 then
sql="SELECT * from SK_SalesReturns where SK_SalesID="&Session("UID")&" AND SK_Feet<>3 AND ReturnsID="&JCID(F("ID"))&""
end if
rs.Open sql,conn,1,1
if rs.eof and rs.bof then Call ReturnError4()

'Add
if RQ("Action")="Mod" and F("S_Order")<>"" and F("S_Client")<>"" and F("S_Atime")<>"" and F("S_Di")<>"" then
Call ChkIsOuter()

set rs=server.createobject("adodb.recordset")
sql="select * from SK_SalesReturns where SK_Feet<>3 and ReturnsID="&F("ID")&""
rs.open sql,conn,1,3
rs("SK_ClientID")=NoCSSHackInput(F("S_ClientID"))
rs("SK_OrderID")=NoCSSHackInput(F("S_OrderID"))
rs("SK_Di")=NoCSSHackInput(F("S_Di"))
rs("SK_Atime")=NoCSSHackInput(F("S_Atime"))
rs("SK_Feet")=NoCSSHackInput(F("S_Feet"))
rs("SK_ReContent")=NoCSSHackContent(F("S_Content"))
rs("SK_Editor")=Session("UID")
rs("SK_Etime")=Now()

'自定义部分开始
set RsField=Server.createobject("adodb.recordset")
sqlField="SELECT * from SK_SalesFields where SK_Di=6 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=6 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

conn.Execute("delete from SK_SalesReturnsDetail where SK_ReturnsID="&F("ID")&"")

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_SalesReturnsDetail"
rs1.open sql1,conn,1,3
rs1.AddNew
rs1("SK_ReturnsID")=F("ID")
rs1("SK_OrderID")=NoCSSHackInput(F("S_OrderID"))
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")="修改产品订单退货"
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_Order.value=="")
  {
  alert("对不起,请选择关联订单！");
  document.thisForm.S_Order.focus();
  return false;
  }
  
  if (document.thisForm.S_ATime.value=="")
  {
  alert("对不起,日期不能为空！");
  document.thisForm.S_ATime.focus();
  return false;
  }
  
  if (document.thisForm.S_Di.value=="")
  {
  alert("对不起,请选择退货原因！");
  document.thisForm.S_Di.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=Mod" onSubmit="return Form1_Validator(this)"> 
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="b5d6e6">

<tr>
  <td width="12%" class="SK_Text2">关联订单</td>
  <td width="33%" class="SK_Text1"><input name="S_Order" type="text" size="30" value="<%
set rsOrders=server.createobject("adodb.recordset")
sqlOrders="select * from SK_SalesOrders where OrdersID="&Rs("SK_OrderID")&""
rsOrders.open sqlOrders,conn,1,1
if rsOrders.eof and rsOrders.bof then Call ReturnError21()
Response.write""&RsOrders("SK_OrdersNo")&""
RsOrders.close
RsOrders=Nothing
%>" readonly>
<input name="S_OrderID" type="hidden" value="<%=Rs("OrderID")%>"> <a onClick="JavaScript:window.open('SK.SalesProOrder.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></td>
  <td width="12%" class="SK_Text2">关联客户</td>
  <td width="43%" class="SK_Text1"><input name="S_Client" type="text" size="30" value="<%
set rsClient=server.createobject("adodb.recordset")
sqlClient="select * from SK_Client where ClientID="&Rs("SK_ClientID")&""
rsClient.open sqlClient,conn,1,1
if rsClient.eof and rsClient.bof then Call ReturnError13()
Response.write""&RsClient("SK_Wname")&""
RsClient.close
Set RsClient=Nothing
%>" readonly>
<input name="S_ClientID" type="hidden" value="<%=Rs("SK_ClientID")%>"></td>
</tr>
<tr>
  <td class="SK_Text2">退货日期</td>
  <td class="SK_Text1"><input name="S_ATime" type="text" size="12" onClick="new Calendar().show(this);" value="<%=Rs("SK_Atime")%>" readOnly /> <font color=red>*</font></td>
  <td class="SK_Text2">退货原因</td>
  <td class="SK_Text1"><select name="S_Di">
<%
set rsDi = server.createobject("adodb.recordset")
rsDi.open "SELECT * from SK_SystemCategory where SK_Di=46",conn,1,1
for BB=1 to rsDi.recordcount
selected=""
if rs("SK_Di")=rsDi("CategoryID") then selected="selected='selected'"
response.Write("<option "&selected&" value="&rsDi("CategoryID")&">"&rsDi("SK_Name")&"</option>")
rsDi.movenext
next
rsDi.close
set rsDi=Nothing
%></select> <font color=red>*</font></td>
</tr>
<tr>
  <td valign="top" class="SK_Text2">退货备注</td>
  <td colspan="3" valign="top" 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" value="<%=Rs("SK_ReContent")%>"></td>
</tr>
<%
'自定义选项开始
set RsOptions=server.createobject("adodb.recordset")
sqlOptions="SELECT * from SK_SalesOptions where SK_Di=6 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=""12%"">"&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
selected=""
if rs(""&RsOptions("SK_FieldName")&"")=rsOptionsDetail("OptionsDetailID") then selected="selected='selected'"
Response.write"<option value="&rsOptionsDetail("OptionsDetailID")&" "&selected&">"&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=6 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=""12%"">"&RsFields("SK_Title")&"</td><td class=""SK_Text1""><input type=""text"" size=""20"" name="&RsFields("SK_FieldName")&" value="&Rs(""&RsFields("SK_FieldName")&"")&"></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" 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">
<!--产品列表开始-->
<%
set RsDetail=Server.createobject("adodb.recordset")
SqlDetail="select * from SK_SalesReturnsDetail where SK_ReturnsID="&Rs("ReturnsID")&" order by ReturnsDetailID asc"
RsDetail.open SqlDetail,conn,1,1

set RsZG=server.createobject("adodb.recordset")
SqlZG="select sum(SK_Total*SK_Price) as ZG from SK_SalesReturnsDetail where SK_ReturnsID="&Rs("ReturnsID")&""
RsZG.open SqlZG,Conn,1,1
if RsZG("ZG")<>"" OR RsZG("ZG")<>"0" then
iZG=formatnumber(RsZG("ZG"),2)
else
iZG="0"
end if
RsZG.close
set RsZG=Nothing

set RsSL=server.createobject("adodb.recordset")
SqlSL="select sum(SK_Total) as SL from SK_SalesReturnsDetail where SK_ReturnsID="&Rs("ReturnsID")&""
RsSL.open SqlSL,Conn,1,1
if RsSL("SL")<>"" OR RsSL("SL")<>"0" then
iSL=RsSL("SL")
else
iSL="0"
end if
RsSL.close
set RsSL=Nothing
%>
<input type="hidden" id="rowcount" name="rowcount" value="<%=RsDetail.recordcount%>">
<TABLE width="100%" border=1 align="center" cellPadding=1 cellSpacing=0 borderColor=#ffffff borderColorLight=#dfdfdf borderColorDark=#ffffff id="sqd">
 <tr>
   <th width="7%" class="Pheadtd">编号</th>
   <th width="7%" class="Pheadtd">选择</th>
  <th width="36%" class="Pheadtd">产品名称</th>
   <th width="17%" class="Pheadtd">单价</th>
   <th width="18%" class="Pheadtd">数量</th>
   <th width="15%" class="Pheadtd">金额</th>
   </tr>
<%
For J = 1 To RsDetail.recordcount

set rsProduct=server.createobject("adodb.recordset")
sqlProduct="select * from SK_Product where ProID="&RsDetail("SK_ProID")&""
rsProduct.open sqlProduct,conn,1,1
%>
<tr>
<td class="Ptetd1"><%=J%></td>
<td class="Ptetd1"><input name="delNumber" type="checkbox" style="border:0"></td>
<td class="Ptetd1"><input name="P_AA<%=J%>" id="P_AA<%=J%>" type="text" size="30" value="<%=RsProduct("SK_ProName")%>" onClick="edit_row(<%=J%>)" readOnly>
<input name="P_ID<%=J%>" id="P_ID<%=J%>" type="hidden" value="<%=RsDetail("SK_ProID")%>" readOnly></td>
<td class="Ptetd1"><input name="P_Price<%=J%>" id="P_Price<%=J%>" type="text" size="8" value="<%=RsDetail("SK_Price")%>" onpropertychange="count(<%=J%>);"></td>
<td class="Ptetd1"><input name="number<%=J%>" id="number<%=J%>" type="text" size="8" value="<%=RsDetail("SK_Total")%>" onpropertychange="count(<%=J%>);"></td>
<td class="Ptetd1"><input name="money<%=J%>" id="money<%=J%>" type="text" size="8" value="<%=RsDetail("SK_Price")*RsDetail("SK_Total")%>"></td>
</tr>
<%
rsProduct.close
RsDetail.movenext
next
%>
</table>
<table width="100%" id="sqd1" align="center" border="1" cellpadding="1" cellspacing="0" borderColor=#ffffff borderColorLight=#dfdfdf borderColorDark=#ffffff>
<tr>
  <td width=67% class="SK_Text">合计</td>
  <td width=18%><input id="total_number" type="text" size="8" value="<%=iSL%>" readOnly></td>
  <td width=15%><input id="total_money" type="text" size="8" value="<%=iZG%>" readOnly></td>
  </tr>
</table>
<%
RsDetail.close
Set RsDetail=Nothing
%>
<!--产品列表结束--></td>
</tr>

<tr>
<td colspan="4" class="SK_Text">
<input type=hidden name="ToNum" value="<%=ToNum%>">
<input type="hidden" name="ID" value="<%=rs("ReturnsID")%>">
<input name="S_HiAmount" type="hidden">
<input name="S_Amount1" type="hidden">
<INPUT class="button1" type="submit" value=" 保存 "> 
<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>