/beta/inventory/changeOwner.asp

http://github.com/khaneh/Orders · ASP · 316 lines · 267 code · 37 blank · 12 comment · 39 complexity · 05591a36c9e815a360e1025c39a32a99 MD5 · raw file

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2. 'Inventory (5)
  3. PageTitle= " "
  4. SubmenuItem=11
  5. if not Auth(5 , "B") then NotAllowdToViewThisPage()
  6. %>
  7. <!--#include file="top.asp" -->
  8. <!--#include File="../include_farsiDateHandling.asp"-->
  9. <!--#include File="../include_JS_InputMasks.asp"-->
  10. <%
  11. '-----------------------------------------------------------------------------------------------------
  12. '------------------------------------------------------------------------------------- Submit Trnasfer
  13. '-----------------------------------------------------------------------------------------------------
  14. if request("submit")="" then
  15. itemName = sqlSafe(request.form("itemName"))
  16. itemID = clng(request.form("itemID"))
  17. fromID = clng(request.form("fromID"))
  18. toID = clng(request.form("toID"))
  19. qtty = cdbl(request.form("qtty"))
  20. accountName = sqlSafe(request.form("accountName"))
  21. comments = sqlSafe(left(request.form("comments"),220)) ' Max Size of the field is 250
  22. errorFound=false
  23. mySQL="SELECT SUM(sumQtty) AS sumQtty, AccountID FROM (SELECT SUM((CONVERT(tinyint, InventoryLog.IsInput) - .5) * 2 * InventoryLog.Qtty) AS sumQtty, InventoryLog.owner AS AccountID FROM InventoryLog WHERE (InventoryLog.ItemID = " & itemID & ") AND (InventoryLog.voided = 0) GROUP BY InventoryLog.owner) DERIVEDTBL GROUP BY AccountID HAVING (SUM(sumQtty) <> 0) AND (DERIVEDTBL.AccountID = " & fromID & ")"
  24. set RSS = Conn.Execute(mySQL)
  25. if not RSS.eof then
  26. currentQtty=cdbl(RSS("sumQtty"))
  27. if currentQtty < qtty then errorFound=true
  28. else
  29. errorFound=true
  30. end if
  31. RSS.close
  32. if errorFound then
  33. Conn.close
  34. response.redirect "?errMsg="&Server.URLEncode(" .")
  35. end if
  36. mySql="INSERT INTO InventoryLog (ItemID, RelatedID, logDate, Qtty, owner, CreatedBy, IsInput, comments, type) VALUES ("& itemID & ", -5 ,N'"& shamsiToday() & "', "& qtty & ", "& fromID & ", "& session("id") & ", 0, N' " & toID & " (" & comments & ")', 5 )"
  37. conn.Execute mySql
  38. mySql="INSERT INTO InventoryLog (ItemID, RelatedID, logDate, Qtty, owner, CreatedBy, IsInput, comments, type) VALUES ("& itemID & ", -5 ,N'"& shamsiToday() & "', "& qtty & ", "& toID & ", "& session("id") & ", 1, N' " & fromID & " (" & comments & ")', 5 )"
  39. conn.Execute mySql
  40. if fromID = "-1" then fromName = " ǁ " else fromName = fromID
  41. if toID = "-1" then toName = " ǁ " else toName = toID
  42. response.write "<br><br>"
  43. call showAlert (" " & qtty & " " & itemName & " " & fromName & " " & toName & " ." , CONST_MSG_INFORM)
  44. response.end
  45. '-----------------------------------------------------------------------------------------------------
  46. '--------------------------------------------------------------------------------------- Trnasfer Form
  47. '-----------------------------------------------------------------------------------------------------
  48. elseif request("submit")="" then
  49. if not isNumeric(request("oldItemID")) then
  50. response.write "<br>!"
  51. response.end
  52. end if
  53. set RSS=Conn.Execute ("SELECT * from inventoryItems where oldItemID = " & request("oldItemID") )
  54. id = RSS("id")
  55. set RSS=Conn.Execute ("SELECT SUM(DERIVEDTBL.sumQtty) AS sumQttys, DERIVEDTBL.AccountID, dbo.Accounts.AccountTitle FROM (SELECT SUM((CONVERT(tinyint, dbo.InventoryLog.IsInput) - .5) * 2 * dbo.InventoryLog.Qtty) AS sumQtty, dbo.InventoryLog.owner AS AccountID FROM dbo.InventoryLog WHERE (dbo.InventoryLog.ItemID = " & id & " and dbo.InventoryLog.voided=0) GROUP BY dbo.InventoryLog.owner) DERIVEDTBL left outer JOIN dbo.Accounts ON DERIVEDTBL.AccountID = dbo.Accounts.ID GROUP BY DERIVEDTBL.AccountID, dbo.Accounts.AccountTitle having SUM(DERIVEDTBL.sumQtty)<>0")
  56. %><BR><BR>
  57. <FORM METHOD=POST ACTION="?" onsubmit="return checkValidation();">
  58. <CENTER><H3></H3> </CENTER>
  59. <TABLE align=center width=70%>
  60. <TR height=30>
  61. <TD align=left valign=top> :</TD>
  62. <TD align=right valign=top><b><%=request("accountName")%> <INPUT TYPE="hidden" name="itemName" value="<%=request("accountName")%>"><INPUT TYPE="hidden" name="itemID" value="<%=id%>"></b></TD>
  63. </TR>
  64. <TR>
  65. <TD align=left valign=top> : </TD>
  66. <TD align=right valign=top>
  67. <TABLE dir=rtl align=center width=100%>
  68. <TR bgcolor="eeeeee">
  69. <TD><INPUT TYPE="radio" NAME="" disabled></TD>
  70. <TD><SMALL></SMALL></A></TD>
  71. <TD align=center><!A HREF="default.asp?s=1"><SMALL> </SMALL></A></TD>
  72. <TD align=center><!A HREF="default.asp?s=3"><SMALL></SMALL></A></TD>
  73. </TR>
  74. <%
  75. tmpCounter=0
  76. Do while not RSS.eof
  77. tmpCounter = tmpCounter + 1
  78. if tmpCounter mod 2 = 1 then
  79. tmpColor="#FFFFFF"
  80. tmpColor2="#FFFFBB"
  81. Else
  82. tmpColor="#FFFFFF"
  83. tmpColor2="#FFFFBB"
  84. 'tmpColor="#DDDDDD"
  85. 'tmpColor2="#EEEEBB"
  86. End if
  87. %>
  88. <TR bgcolor="<%=tmpColor%>" height=25 style="cursor:hand" onclick="this.getElementsByTagName('input')[0].click();this.getElementsByTagName('input')[0].focus();">
  89. <TD><INPUT TYPE="radio" NAME="fromID" value="<%=RSS("AccountID")%>"></TD>
  90. <TD><%
  91. if RSS("AccountID")="-1" then
  92. response.write " ǁ "
  93. else
  94. response.write RSS("AccountTitle")
  95. end if %></TD>
  96. <TD align=center dir=ltr><%
  97. if RSS("AccountID")="-1" then
  98. response.write "-"
  99. else
  100. response.write RSS("AccountID")
  101. end if %></TD>
  102. <TD align=center dir=ltr><%=RSS("sumQttys")%></TD>
  103. </TR>
  104. <%
  105. RSS.moveNext
  106. Loop
  107. %>
  108. </TABLE><br>
  109. </TD>
  110. </TR>
  111. <TR height=30>
  112. <TD align=left valign=top> : </TD>
  113. <TD align=right valign=top>
  114. <SELECT NAME="aaa2" onchange="hideIT()">
  115. <option value=1 > ǁ </option>
  116. <option value=2> ( )</option>
  117. </SELECT>
  118. <span name="aaa1" id="aaa1" style="visibility:'hidden'">
  119. <input type="hidden" Name='tmpDlgArg' value=''>
  120. <input type="hidden" Name='tmpDlgTxt' value=''>
  121. <INPUT dir="LTR" TYPE="text" NAME="toID" maxlength="10" size="13" value="-1" onKeyPress='return mask(this);' onBlur='check(this);'> &nbsp;&nbsp; <INPUT TYPE="text" NAME="accountName" size=30 readonly value="<%=accountName%>" style="background-color:transparent">
  122. </span><br></TD>
  123. </TR>
  124. <TR height=30>
  125. <TD align=left valign=top>:</TD>
  126. <TD align=right valign=top><INPUT dir=ltr TYPE="text" NAME="qtty" size=25 value="<%=preQtty%>" ><!onKeyPress="return maskNumber(this);" ><br><br></TD>
  127. </TR>
  128. <TR>
  129. <TD align=left valign=top></TD>
  130. <TD align=right>
  131. <TEXTAREA NAME="comments" ROWS="4" COLS="" style="width:100%"></TEXTAREA><br><br>
  132. </TD>
  133. </TR>
  134. <TR>
  135. <TD align=left valign=top></TD>
  136. <TD align=center valign=top><INPUT TYPE="submit" name="submit" value=""></TD>
  137. </TR>
  138. </TABLE>
  139. </FORM>
  140. <SCRIPT LANGUAGE="JavaScript">
  141. <!--
  142. function checkValidation(){
  143. found = false;
  144. len = document.getElementsByName('fromID').length
  145. for (i = 0; i <len; i++) {
  146. if (document.getElementsByName('fromID')[i].checked) {
  147. found = true;
  148. }
  149. }
  150. if ( !found )
  151. {
  152. alert(' ');
  153. document.getElementsByName('fromID')[0].focus()
  154. return false;
  155. }
  156. if( !(parseFloat(document.getElementsByName('qtty')[0].value)>0) )
  157. {
  158. alert(' ');
  159. document.getElementsByName('qtty')[0].focus();
  160. return false;
  161. }
  162. if(document.getElementsByName('comments')[0].value.length>220)
  163. {
  164. alert(' \n\n 220 ( 4 ) ');
  165. document.getElementsByName('comments')[0].focus();
  166. return false;
  167. }
  168. return true;
  169. }
  170. var dialogActive=false;
  171. function mask(src){
  172. var theKey=event.keyCode;
  173. if (theKey==13){
  174. event.keyCode=9
  175. dialogActive=true
  176. document.all.tmpDlgArg.value="#"
  177. document.all.tmpDlgTxt.value=" :"
  178. var myTinyWindow = window.showModalDialog('../dialog_GenInput.asp',document.all.tmpDlgTxt,'dialogHeight:200px; dialogWidth:440px; dialogTop:; dialogLeft:; edge:None; center:Yes; help:No; resizable:No; status:No;');
  179. if (document.all.tmpDlgTxt.value !="") {
  180. var myTinyWindow = window.showModalDialog('../ar/dialog_selectAccount.asp?act=select&search='+escape(document.all.tmpDlgTxt.value),document.all.tmpDlgArg,'dialogHeight:500px; dialogWidth:380px; dialogTop:; dialogLeft:; edge:Raised; center:Yes; help:No; resizable:Yes; status:No;');
  181. dialogActive=false
  182. if (document.all.tmpDlgArg.value!="#"){
  183. Arguments=document.all.tmpDlgArg.value.split("#")
  184. src.value=Arguments[0];
  185. document.all.accountName.value=Arguments[1];
  186. }
  187. }
  188. }
  189. }
  190. function check(src){
  191. if (!dialogActive){
  192. badCode = false;
  193. if (window.XMLHttpRequest) {
  194. var objHTTP=new XMLHttpRequest();
  195. } else if (window.ActiveXObject) {
  196. var objHTTP = new ActiveXObject("Microsoft.XMLHTTP");
  197. }
  198. objHTTP.open('GET','../accounting/xml_CustomerAccount.asp?id='+src.value,false)
  199. objHTTP.send()
  200. tmpStr = unescape(objHTTP.responseText)
  201. document.all.accountName.value=tmpStr;
  202. }
  203. }
  204. function hideIT()
  205. {
  206. //alert(document.all.aaa2.value)
  207. if(document.all.aaa2.value==2)
  208. {
  209. document.all.aaa1.style.visibility= 'visible'
  210. document.all.toID.value = ""
  211. document.all.toID.focus()
  212. }
  213. else
  214. {
  215. document.all.aaa1.style.visibility= 'hidden'
  216. document.all.toID.value = "-1"
  217. }
  218. }
  219. //-->
  220. </SCRIPT>
  221. <%
  222. response.end
  223. end if
  224. '-----------------------------------------------------------------------------------------------------
  225. '------------------------------------------------------------------------------ Search Form
  226. '-----------------------------------------------------------------------------------------------------
  227. if request("catItem") = "" then
  228. %><BR>
  229. <FORM METHOD=POST ACTION=""><BR><center>
  230. <INPUT TYPE="hidden" name="radif" value="-1">
  231. <input type="hidden" Name='tmpDlgArg' value=''>
  232. <input type="hidden" Name='tmpDlgTxt' value=''>
  233. : &nbsp;&nbsp;&nbsp;<INPUT dir="LTR" TYPE="text" NAME="oldItemID" maxlength="10" size="13" onKeyPress='return mask(this);' onBlur='check(this);'> &nbsp;&nbsp; <INPUT TYPE="text" NAME="accountName" size=30 readonly value="<%=accountName%>" style="background-color:transparent">
  234. &nbsp;&nbsp;<INPUT TYPE="submit" Name="Submit" Value="" style="width:80px;" tabIndex="14">
  235. </center>
  236. </FORM>
  237. <SCRIPT LANGUAGE="JavaScript">
  238. <!--
  239. document.all.oldItemID.focus()
  240. var dialogActive=false;
  241. function mask(src){
  242. var theKey=event.keyCode;
  243. if (theKey==13){
  244. event.keyCode=9
  245. dialogActive=true
  246. document.all.tmpDlgArg.value="#"
  247. document.all.tmpDlgTxt.value=" "
  248. var myTinyWindow = window.showModalDialog('../dialog_GenInput.asp',document.all.tmpDlgTxt,'dialogHeight:200px; dialogWidth:440px; dialogTop:; dialogLeft:; edge:None; center:Yes; help:No; resizable:No; status:No;');
  249. if (document.all.tmpDlgTxt.value !="") {
  250. var myTinyWindow = window.showModalDialog('dialog_selectInvItem.asp?act=select&name='+escape(document.all.tmpDlgTxt.value),document.all.tmpDlgArg,'dialogHeight:500px; dialogWidth:380px; dialogTop:; dialogLeft:; edge:Raised; center:Yes; help:No; resizable:Yes; status:No;');
  251. dialogActive=false
  252. if (document.all.tmpDlgArg.value!="#"){
  253. Arguments=document.all.tmpDlgArg.value.split("#")
  254. src.value=Arguments[0];
  255. document.all.accountName.value=Arguments[1];
  256. }
  257. }
  258. }
  259. }
  260. function check(src){
  261. if (!dialogActive){
  262. badCode = false;
  263. if (window.XMLHttpRequest) {
  264. var objHTTP=new XMLHttpRequest();
  265. } else if (window.ActiveXObject) {
  266. var objHTTP = new ActiveXObject("Microsoft.XMLHTTP");
  267. }
  268. objHTTP.open('GET','xml_InventoryItem.asp?id='+src.value,false)
  269. objHTTP.send()
  270. tmpStr = unescape(objHTTP.responseText)
  271. document.all.accountName.value=tmpStr;
  272. }
  273. }
  274. //-->
  275. </SCRIPT>
  276. <%
  277. end if
  278. %>
  279. <!--#include file="tah.asp" -->