/beta/AR/InvoiceEdit.asp
ASP | 1514 lines | 1127 code | 171 blank | 216 comment | 162 complexity | f93a5fdcfb1610c18b07624add893b81 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
1<%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><% 2' AR (6) 3PageTitle="����� ������ " 4SubmenuItem=1 5'if not Auth(6 , 1) then NotAllowdToViewThisPage() 6 7%> 8<!--#include file="top.asp" --> 9<!--#include File="../include_farsiDateHandling.asp"--> 10<!--#include File="../include_JS_InputMasks.asp"--> 11 12<% 13function ShowErrorMessage(msg) 14 response.write "<table align='center' cellpadding='5'><tr><td bgcolor='#FFCCCC' dir='rtl' align='center'> ��� ! <br>"& msg & "<br></td></tr></table><br>" 15end function 16 17function Link2Trace(OrderNo) 18 Link2Trace="<A HREF='../order/TraceOrder.asp?act=show&order="& OrderNo & "' target='_balnk'>"& OrderNo & "</A>" 19end function 20 21function Link2TraceQuote(QuoteNo) 22 Link2TraceQuote = "<A HREF='../order/Inquiry.asp?act=show"e="& QuoteNo & "' target='_balnk'>"& QuoteNo & "</A>" 23end function 24 25%> 26<style> 27 Table { font-size: 9pt;} 28 div.InvHead {background-color: #CC8;text-align: center;padding: 5px 0;} 29 div.InvHead2 {background-color: #AC7;text-align: center;padding: 5px 0;} 30 div.InvHead3 {background-color: #F0F0F0;text-align: center;padding: 5px 0;} 31 div.InvHead4 {background-color: #F90;text-align: center;padding: 5px 0;} 32 div.InvLine {background-color: #F0F0F0;text-align: right;} 33 div.InvLine2 {background-color: #F0FFF0;text-align: right;} 34 div.InvLine4 {background-color: #FFD3A8;text-align: right;} 35 36 .InvRowInput { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0F0F0; text-align:right;} 37 .InvHeadInput { font-family:tahoma; font-size: 9pt; border: none; background-color: #CCCC88; text-align:center;} 38 .InvRowInput2 { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0FFF0; text-align:right; height: 22px; margin: 0;padding: 0;} 39 .InvRowInput4 { font-family:tahoma; font-size: 9pt; border: none; background-color: #FFD3A8; direction:LTR; text-align:right;} 40 .InvHeadInput2 { font-family:tahoma; font-size: 9pt; border: none; background-color: #AACC77; text-align:center;} 41 .InvHeadInput3 { font-family:tahoma; font-size: 9pt; border: none; background-color: #F0F0F0; text-align:right;} 42 .InvHeadInput4 { font-family:tahoma; font-size: 9pt; border: none; background-color: #FF9900; text-align:center;} 43 .InvGenInput { font-family:tahoma; font-size: 9pt; border: none; } 44 .InvGenButton { font-family:tahoma; font-size: 9pt; border: 1px solid black; } 45 .order {background-color: #C3C300;font-weight: bold;padding: 6px 10px 6px 10px;} 46 .quote {background-color: #AAAAEE;font-weight: bold;padding: 6px 10px 6px 10px;} 47 #header {width: 100%;border-left: 1px solid #585;border-right: 1px solid #585;} 48 #header div {padding: 5px 2px;float: right;border-left: 1px solid #585; text-align: center;} 49 div.invRow {clear: both;float: none;width: 100%;} 50 div.invRow div {padding: 5px 2px 0 2px;float: right;border-bottom: 1px solid #585;border-left: 1px solid #585;text-align: right;height: 22px;} 51 table.invTable {border-collapse:collapse; width:100%;} 52 #tbody{height:60px;overflow-y:auto;width:100%;background:yellow;border-top: 1px solid #585;} 53 td[class*="td"] {padding: 1px 2px;border-left: 1px solid red;border-bottom: 1px solid red;} 54 div.td15{width: 15px;} 55 td.td15{width: 15px;} 56 div.td40{width: 40px;} 57 td.td40{width: 40px;} 58 div.td170{width: 170px;} 59 td.td170{width: 170px;} 60 div.td60{width: 60px;} 61 td.td60{width: 60px;} 62 div.td80{width: 80px;} 63 td.td80{width: 80px;} 64 div.td35{width: 35px;} 65 td.td35{width: 35px;} 66 div.td25{width: 25px;} 67 td.td25{width: 25px;} 68 div.td55{width: 55px;} 69 td.td55{width: 55px;} 70 div.td50{width: 50px;} 71 td.td50{width: 50px;} 72 div.td75{width: 75px;} 73 td.td75{width: 75px;} 74</style> 75<SCRIPT LANGUAGE="JavaScript"> 76<!-- 77var okToProceed=false; 78var currentRow=0; 79//--> 80</SCRIPT> 81<% 82if request("act")="search" then 83 if isnumeric(request("order")) then 84 OrderID = clng(request("order")) 85 mySQL="SELECT InvoiceOrderRelations.Invoice FROM InvoiceOrderRelations INNER JOIN Invoices ON InvoiceOrderRelations.Invoice = Invoices.ID WHERE (InvoiceOrderRelations.[Order] = '"& OrderID & "') AND (Invoices.IsReverse = 0) AND (Invoices.Voided = 0)" 86 Set RS1=Conn.Execute(mySQL) 87 if RS1.eof then 88 Conn.close 89 response.redirect "?errmsg=" & Server.URLEncode("��� ����� ���� ������ ���� ���.") 90 else 91 theInvoice=RS1("Invoice") 92 Conn.close 93 response.redirect "?act=editInvoice&invoice=" & theInvoice 94 end if 95 elseif isnumeric(request("invoice")) then 96 response.redirect "?act=editInvoice&invoice=" & request("invoice") 97 else 98 response.redirect "?errmsg=" & Server.URLEncode("����� ����� ���� ���� ��� ����.") 99 end if 100'----------------------------------------------------------------------------------------------------- 101'---------------------------------------------------------------------------------------- Edit Invoice 102'----------------------------------------------------------------------------------------------------- 103elseif request("act")="editInvoice" then 104 if isnumeric(request("invoice")) then 105 InvoiceID=clng(request("invoice")) 106 mySQL="SELECT * FROM Invoices WHERE (ID='"& InvoiceID & "')" 107 Set RS1 = conn.Execute(mySQL) 108 if RS1.eof then 109 conn.close 110 response.redirect "?errmsg=" & Server.URLEncode("������ ���� ���.") 111 end if 112 else 113 response.redirect "?errmsg=" & Server.URLEncode("����� ������ ���� ���� ��� ����.") 114 end if 115 116 customerID= RS1("Customer") 117 creationDate= RS1("CreatedDate") 118 IssuedDate= RS1("IssuedDate") 119 totalPrice= cdbl(RS1("totalPrice")) 120 totalDiscount= cdbl(RS1("totalDiscount")) 121 totalReverse= cdbl(RS1("totalReverse")) 122 totalVat = cdbl(RS1("totalVat")) 123 Voided= RS1("Voided") 124 Issued= RS1("Issued") 125 Approved= RS1("Approved") 126 isReverse= RS1("IsReverse") 127 IsA= RS1("IsA") 128 InvoiceNo= RS1("Number") 129 130 mySQL="SELECT ID,AccountTitle FROM Accounts WHERE (ID='"& customerID & "')" 131 Set RS1 = conn.Execute(mySQL) 132 AccountNo=RS1("ID") 133 customerName=RS1("AccountTitle") 134 135 RS1.close 136 137 if isReverse then 138 'Check for permission for EDITTING Rev. Invoice 139 if not Auth(6 , 5) then NotAllowdToViewThisPage() 140 itemTypeName="������ �ѐ��" 141 HeaderColor="#FF9900" 142 else 143 'Check for permission for EDITTING Invoice 144 if not Auth(6 , 3) then NotAllowdToViewThisPage() 145 itemTypeName="������" 146 HeaderColor="#C3C300" 147 end if 148 149 if Voided then 150 Conn.close 151 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("��� ������ ���� ��� ���.") 152 elseif Issued then 153 if Auth(6 , "A") then 154 ' Has the Priviledge to change the Invoice 155 response.write "<BR>" 156 if Auth(6,"N") then 157 set rs=Conn.Execute("select * from effectiveGlrows where sys='AR' and link in (select id from arItems where type=1 and reason=1 and link=" & invoiceID & ")") 158 if rs.eof then 159 call showAlert ("��� ������ ���� ��� ���.<br>�э�� �� ��� ����� ����� ��� ������ �� ύ�� ������� ��� ����<br>������ ������ ������� �� �� �����Ͽ",CONST_MSG_INFORM) 160 else 161 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("��� ������ ��� �������� ���ϡ <br>��� �� ��������� ������� ��� ���ϡ ����� ���� ���� ���� ����.") 162 end if 163 else 164 call showAlert ("��� ������ ���� ��� ���.<br>�э�� �� ��� ����� ����� �� ��� ������ �� ����� �����<br>������ ������ ������� �� �� �����Ͽ",CONST_MSG_INFORM) 165 end if 166 else 167 Conn.close 168 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("��� ������ ���� ��� ���.") 169 end if 170 end if 171%> 172<!-- ���� ������� ������ --> 173 <br> 174 <input type="hidden" Name='tmpDlgArg' value=''> 175 <input type="hidden" Name='tmpDlgTxt' value=''> 176 <input type="hidden" name="VatRate" id="VatRate" value="<%=session("VatRate")%>"> 177 <FORM METHOD=POST ACTION="?act=submitEdit"> 178 <table Border="0" align="center" Width="100%" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#558855"> 179 <tr bgcolor='<%=HeaderColor%>'> 180 <td colspan='2'> 181 <TABLE width='100%'> 182 <TR> 183 <TD align="left" >����� <%=itemTypeName%>:</TD> 184 <TD align="right" width='15%'> <INPUT readonly class="InvGenInput" NAME="InvoiceID" value="<%=InvoiceID%>" style="direction:ltr" TYPE="text" maxlength="10" size="10"></TD> 185 </TR> 186 </TABLE></td> 187 </tr> 188 <tr bgcolor='<%=HeaderColor%>'> 189 <td colspan="2"> 190 <TABLE Border="0" Width="100%" Cellspacing="1" Cellpadding="0" Dir="RTL"> 191 <TR> 192 <TD><table> 193 <tr> 194 <td align="left">����:</td> 195 <td align="right"> 196 <span id="customer"><%' after any changes in this span "./Customers.asp" must be revised%> 197 <INPUT TYPE="hidden" NAME="customerID" value="<%=customerID%>"><span><%=CustomerName%></span>. 198 </span></td> 199 <td></td> 200 </tr> 201 </table></TD> 202 <TD align="left"><table> 203 <tr> 204 <td align="left">����� ����:</td> 205 <td dir="LTR"> 206 <INPUT <%'if not Auth(6,"N") then response.write " readonly='readonly' "%> class="InvGenInput" NAME="issueDate" TYPE="text" maxlength="10" size="10" value="<%=IssuedDate%>" onblur="acceptDate(this)"></td> 207 <td dir="RTL"><%="�����"%></td> 208 </tr> 209 </table></TD> 210 </TR></TABLE> 211 </td> 212 </tr> 213 <tr bgcolor='<%=HeaderColor%>'> 214 <TD align="right" width="50%"> 215 ����� �� �����/�������(���): 216 <% 217 mySQL="SELECT * FROM InvoiceOrderRelations inner join Orders on InvoiceOrderRelations.[order]=orders.id WHERE (Invoice='"& InvoiceID & "')" 218 Set RS1 = conn.Execute(mySQL) 219 if not rs1.eof then 220 if rs1("isOrder")="True" then 221 isOrder="order" 222 else 223 isOrder="quote" 224 end if 225 end if 226 %> 227 <span id="orders" class="<%=isOrder%>"> 228<% 229 tempWriteAnd="" 230 while not(RS1.eof) 231 response.write tempWriteAnd & Link2Trace(RS1("Order")) 232 tempWriteAnd=" � " 233 RS1.moveNext 234 wend 235%> </span> 236 </TD> 237 <TD align="left"><table> 238 <tr> 239 <td align="left">�����:</td> 240 <td dir="LTR"> 241 <INPUT class="InvGenInput" NAME="InvoiceNo" value="<%=InvoiceNo%>" style="border:1px solid black;" TYPE="text" maxlength="10" size="10"></td> 242 <td dir="RTL"> 243 <INPUT TYPE="checkbox" value="on" NAME="IsA" onClick='checkIsA();' 244 <% if IsA then response.write " checked='checked' " 245 if Issued and not Auth(6,"N") then response.write " disabled='disabled' "%>> ��� 246 </td> 247 </tr> 248 </table></TD> 249 </tr> 250 <tr bgcolor='#CCCC88'> 251 <TD colspan="10"> 252 <div id="header"> 253 <div class="td15 InvHead">#</div> 254 <div class="td40 InvHead2">����</div> 255 <div class="td170 InvHead2">�������</div> 256 <div class="td25 InvHead2">���</div> 257 <div class="td25 InvHead2">���</div> 258 <div class="td25 InvHead2">�����</div> 259 <div class="td25 InvHead2">���</div> 260 <div class="td50 InvHead">����� ����</div> 261 <div class="td40 InvHead">��</div> 262 <div class="td50 InvHead">����</div> 263 <div class="td50 InvHead">�����</div> 264 <div class="td40 InvHead">�ѐ��</div> 265 <div class="td50 InvHead4">������</div> 266 <div class="td75 InvHead2">���� ������</div> 267 </div> 268 <div id="tbody"> 269<% 270 i=0 271 mySQL="SELECT *,InvoiceLines.ID as lineID,isnull(invoiceItems.fee,0) as ItemFee FROM InvoiceLines LEFT OUTER JOIN invoiceItems ON InvoiceLines.item = invoiceItems.id WHERE (Invoice='"& InvoiceID & "') " 272 Set RS1 = conn.Execute(mySQL) 273 while not(RS1.eof) 274 if RS1("Item") <> 39999 then 275 i=i+1 276%> 277 <div class="invRow"> 278 <div class="td15 InvLine"><%=i%></div> 279 <div class="td40 InvLine2"><%=RS1("Item")%> 280 <input type='hidden' name='hasVat' value='<%=text2value(RS1("hasVat"))%>'> 281 <input type='hidden' name='lineID' value='<%=RS1("lineID")%>'> 282 </div> 283 <div class="td170 InvLine2" style="padding:2px 2px 3px 2px;"> 284 <INPUT class="InvRowInput2" TYPE="text" NAME="Descriptions" value="<%=RS1("Description")%>" size="30"> 285 </div> 286 <div class="td25 InvLine2"><%=RS1("Length")%></div> 287 <div class="td25 InvLine2"><%=RS1("Width")%></div> 288 <div class="td25 InvLine2"><%=RS1("Qtty")%></div> 289 <div class="td25 InvLine2"><%=RS1("Sets")%></div> 290 <div class="td50 InvLine"><%=Separate(RS1("AppQtty"))%></div> 291 <div class="td40 InvLine"><%=Separate(RS1("Price")/RS1("AppQtty"))%></div> 292 <div class="td50 InvLine"><%=Separate(RS1("Price"))%></div> 293 <div class="td50 InvLine"><%=Separate(RS1("Discount"))%></div> 294 <div class="td40 InvLine"><%=Separate(RS1("Reverse"))%></div> 295 <div class="td50 InvLine4"><%=Separate(RS1("Vat"))%></div> 296 <div class="td75 InvLine2"><%=Separate(RS1("Price") - RS1("Discount") - RS1("Reverse") + RS1("Vat"))%></div> 297 </div> 298 299<% 300 end if 301 RS1.moveNext 302 wend 303 RS1.close 304%> 305 306 </div> 307 </TD> 308 </TR> 309 310 <tr bgcolor='#CCCC88'> 311 <TD colspan="10"><div> 312 <TABLE Border="0" Cellspacing="1" Cellpadding="0" Dir="RTL" bgcolor="#CCCC88"> 313 <tr bgcolor='#CCCC88'> 314 <td colspan='9' width='500px'>***����� ��� ������ ��� �� ��� ��� ����� ��***</td> 315 <td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalPrice" value="<%=Separate(totalPrice)%>" TYPE="text" size="9"></td> 316 <!-- S A M --> 317 <td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalDiscount" value="<%=Separate(totalDiscount)%>" TYPE="text" size="7"></td> 318 <td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalReverse" value="<%=Separate(totalReverse)%>" TYPE="text" size="5"></td> 319 <td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="TotalVat" value="<%=Separate(totalVat)%>" TYPE="text" size="6"></td> 320 <td dir="LTR"><INPUT readonly class="InvHeadInput3" Name="Payable" value="<%=Separate(totalPrice - totalDiscount - totalReverse + totalVat)%>" TYPE="text" size="9"></td> 321 </tr> 322 <tr bgcolor='#CCCC88'> 323 <td colspan="9"> </td> 324 <td dir="LTR"><INPUT readonly class="InvHeadInput" TYPE="text" size="9"></td> 325 <!-- S A M --> 326 <td dir="LTR"><INPUT readonly class="InvHeadInput3" TYPE="text" Name="TPDiscount" value="<%=Pourcent(totalDiscount,totalPrice) & "%�����"%>" size="7"></td> 327 <td dir="LTR"><INPUT readonly class="InvHeadInput3" TYPE="text" Name="TPReverse" value="<%=Pourcent(totalReverse,totalPrice) & "%�ѐ��"%>" size="5"></td> 328 <td dir="LTR"><INPUT readonly calss="InvHeadINput" TYPE="text" size="6" value="<%=session("VatRate")%>%������"></td> 329 <td dir="LTR"><INPUT readonly class="InvHeadInput" TYPE="text" size="9" value="��� ���"></td> 330 </tr> 331 </TABLE></div></TD> 332 </TR> 333 </table> 334 <TABLE Border="0" Cellspacing="5" Cellpadding="0" Dir="RTL" align='left'> 335 <tr> 336 <td align='center'> <!-- <INPUT class="InvGenButton" TYPE="button" value="����� ������" onclick="ApproveInvoice();"> --></td> 337 <td width="40"> </td> 338 <td align='center'> <!-- <INPUT class="InvGenButton" TYPE="button" value="���� ������" onclick="IssueInvoice();"> --></td> 339 <td width="40"> </td> 340 <td align='center'><INPUT class="InvGenButton" TYPE="button" value="����� " onclick="submitOperations();"></td> 341 <td align='center'><INPUT class="InvGenButton" TYPE="button" value="������" onclick="window.location='AccountReport.asp?act=showInvoice&invoice=<%=InvoiceID%>';"></td> 342 </tr> 343 </TABLE> 344 </FORM> 345 <SCRIPT LANGUAGE="JavaScript"> 346 <!-- 347 //document.getElementsByName("Items")[0].focus(); 348 //--> 349 </SCRIPT> 350 351<% 352elseif request("act")="submitEdit" then 353 354 '******************** Checking and Preparing Input **************** 355 errorFound=false 356 ON ERROR RESUME NEXT 357 358 InvoiceID= clng(request.form("InvoiceID")) 359 CustomerID= clng(request.form("CustomerID")) 360 361 issueDate= request.form("issueDate") 362' response.write "is A: " & request.form("IsA") 363 364 if request.form("IsA") = "on" then 365 IsA=1 366 InvoiceNo=request.form("InvoiceNo") 367 if InvoiceNo <> "" then InvoiceNo = cdbl(InvoiceNo) 368 else 369 set rs = Conn.Execute("select * from invoices where id=" & invoiceID) 370 IsA=0 371 InvoiceNo="" 372 if rs("issued") and not auth(6,"N") then 373 if rs("isA") then 374 IsA=1 375 InvoiceNo=request.form("InvoiceNo") 376 if InvoiceNo <> "" then InvoiceNo = cdbl(InvoiceNo) 377 end if 378 end if 379 end if 380' response.write "<br>is A now:" & IsA 381' response.end 382 for i=1 to request.form("selectedOrders").count 383 theOrder = clng(request.form("selectedOrders")(i)) 384 mySQL="SELECT ID FROM Orders WHERE ID=" & theOrder 385 Set rs=conn.Execute(mySQL) 386 if rs.eof then 387 errorFound=True 388 exit for 389 end if 390 rs.close 391 next 392 393 for i=1 to request.form("selectedQuotes").count 394 theQuote= clng(request.form("selectedQuotes")(i)) 395 mySQL="SELECT ID FROM Quotes WHERE ID=" & theQuote 396 Set rs=conn.Execute(mySQL) 397 if rs.eof then 398 errorFound=True 399 exit for 400 end if 401 rs.close 402 next 403 404 Set rs= Nothing 405 406 mySQL="SELECT * FROM Invoices WHERE (ID='"& InvoiceID & "')" 407 Set rs= conn.Execute(mySQL) 408 if NOT rs.eof then 409 voided= rs("Voided") 410 issued= rs("Issued") 411 approved= rs("Approved") 412 isReverse= rs("IsReverse") 413 ApprovedBy= rs("ApprovedBy") 414 if issued and not auth(6 , "N") then isA=rs("isA") 415 else 416 errorFound=True 417 end if 418 419 if Err.Number<>0 then 420 Err.clear 421 errorFound=True 422 end if 423 424 if NOT errorFound then 425 TotalPrice = 0 426 TotalDiscount = 0 427 TotalReverse = 0 428 TotalReceivable = 0 429 TotalVat = 0 430 RFD = 0 431 432 for i=1 to request.form("Items").count 433 434 theItem = clng(text2value(request.form("Items")(i))) 435 mySQL="SELECT ID FROM InvoiceItems WHERE ID=" & theItem 436 Set rs=conn.Execute(mySQL) 437 if rs.eof then 438 errorFound=True 439 exit for 440 end if 441 rs.close 442 443 theDescription = left(sqlSafe(request.form("Descriptions")(i)),100) 444 445 theAppQtty = cdbl(text2value(request.form("AppQttys")(i))) 446 thePrice = clng(text2value(request.form("Prices")(i))) 447 448 theDiscount = text2value(request.form("Discounts")(i)) 449 theReverse = text2value(request.form("Reverses")(i)) 450 451 theLength = text2value(request.form("Lengths")(i)) 452 theWidth = text2value(request.form("Widths")(i)) 453 theQtty = text2value(request.form("Qttys")(i)) 454 theSets = text2value(request.form("Sets")(i)) 455 theVat = text2value(request.form("Vat")(i)) 456 'theHasVat = text2value(request.form("hasVat")(i)) 457 458 if theDiscount <>"" then theDiscount= clng(theDiscount) 459 if theReverse <> "" then theReverse = clng(theReverse) 460 461 if theLength <> "" then theLength = cdbl(theLength) 462 if theWidth <> "" then theWidth = cdbl(theWidth) 463 if theQtty <> "" then theQtty = clng(theQtty) 464 if theSets <> "" then theSets = clng(theSets) 465 466 TotalPrice = TotalPrice + thePrice 467 TotalDiscount = TotalDiscount + theDiscount 468 TotalReverse = TotalReverse + theReverse 469 TotalReceivable = TotalReceivable + (thePrice - theDiscount - theReverse + theVat) 470 TotalVat = TotalVat + theVat 471 472 next 473 RFD = TotalReceivable - fix(TotalReceivable / 1000) * 1000 474 'RFD = RFD / 1.03 475 TotalReceivable = TotalReceivable - RFD 476 TotalDiscount = TotalDiscount + RFD 477 end if 478 479 if Err.Number<>0 then 480 Err.clear 481 errorFound=True 482 end if 483 484 ON ERROR GOTO 0 485 486 if errorFound then 487 response.write "<br>" 488 call showAlert ("��� �� �����",CONST_MSG_ERROR) 489 response.end 490 end if 491 '^^^^---------------- Checking Input ------------^^^^ 492 493 if isReverse then 494 'Check for permission for EDITTING Rev. Invoice 495 if not Auth(6 , 5) then NotAllowdToViewThisPage() 496 itemType=4 497 else 498 'Check for permission for EDITTING Invoice 499 if not Auth(6 , 3) then NotAllowdToViewThisPage() 500 itemType=1 501 end if 502 503 if voided then 504 Conn.close 505 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("��� ������ ���� ���� ��� ���.") 506 elseif issued then 507 if Auth(6 , "A") then 508 ' Has the Priviledge to change the Invoice / Reverse Invoice 509 510 'mySQL="SELECT ID FROM ARItems WHERE (Type='"& itemType & "') AND (GL_Update=1) AND (Link='"& InvoiceID & "')" 511 'Changed by Kid ! 831124 512 mySQL="SELECT ARItems.ID, ARItems.GL_Update, EffGLRows.GL, EffGLRows.GLDocID FROM ARItems LEFT OUTER JOIN (SELECT Link, GL, GLDocID FROM EffectiveGLRows WHERE SYS = 'AR') EffGLRows ON ARItems.ID = EffGLRows.Link WHERE (ARItems.Type = '"& itemType & "') AND (ARItems.Link = '"& InvoiceID & "')" 513 514 Set RS2 = conn.Execute(mySQL) 515 516 if RS2.eof then 517 Conn.close 518 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("��� !! <br><br> ���� ���.") 519 else 520 if RS2("GL_Update") = False then 521 tmpGL=RS2("GL") 522 tmpGLDoc=RS2("GLDocID") 523 Conn.close 524 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("���� ���� ��� ������ ��� �������� ���� ��� ���.<br><br>���� ��:"& tmpGL & " ��� �����: "& tmpGLDoc & " .") 525 else 526 ARItemID=RS2("ID") 527 IssuedButEdit=true 528 end if 529 end if 530 RS2.close 531 else 532 Conn.close 533 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("��� ������ ���� ���� ��� ���.") 534 end if 535 elseif approved then 536 call UnApproveInvoice ( InvoiceID , ApprovedBy ) 537 end if 538 539 540 '******************* Editing ******************* 541 ' **** 542 if IssuedButEdit then 543 ' Only Updating IssuedDate, Number & no IsA 544 ' and related Orders 545 546 '---- Checking wether issueDate is valid in current open GL 547 If Not CheckDateFormat(issueDate) Then 548 Conn.close 549 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("����� ���� ��� ����� ����.") 550 end if 551 552 if (issueDate < session("OpenGLStartDate")) OR (issueDate > session("OpenGLEndDate")) then 553 Conn.close 554 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("���!<br>����� ���� ��� ����� ����. <br>(�� ��� ���� ���� ����)") 555 end if 556 '---- 557 '----- Check GL is closed 558 559 if (session("IsClosed")="True") then 560 Conn.close 561 response.redirect "?errMsg=" & Server.URLEncode("���! ��� ���� ���� ���� ��� � ��� ���� �� ����� �� �� ������.") 562 end if 563 '---- 564 565 mySQL="UPDATE Invoices SET IssuedDate=N'" & issueDate & "', Number='"& InvoiceNo & "', IsA='"&IsA&"',issuedDate_en=dbo.udf_date_solarToDate(cast(substring('" & issueDate & "',1,4) as int),cast(substring('" & issueDate & "',6,2) as int),cast(substring('" & issueDate & "',9,2) as int)) WHERE (ID='"& InvoiceID & "')" 566 'response.write mySQL 567 'response.end 568 conn.Execute(mySQL) 569'--------------------------------------------------------------------------------------------------- 570 for i=1 to request.form("Items").count 571 if request.form("lineID") <> "" then 572 'response.write text2value(request.form("lineID")(i)) 573 theID = clng(text2value(request.form("lineID")(i))) 574 theItem = clng(text2value(request.form("Items")(i))) 575 theDescription = left(sqlSafe(request.form("Descriptions")(i)),100) 576 'theAppQtty = cdbl(text2value(request.form("AppQttys")(i))) 577 theLength = text2value(request.form("Lengths")(i)) 578 theWidth = text2value(request.form("Widths")(i)) 579 theQtty = text2value(request.form("Qttys")(i)) 580 theSets = text2value(request.form("Sets")(i)) 581 if theLength <> "" then theLength = cdbl(theLength) 582 if theWidth <> "" then theWidth = cdbl(theWidth) 583 if theQtty <> "" then theQtty = clng(theQtty) 584 if theSets <> "" then theSets = clng(theSets) 585 586 mySQL="UPDATE InvoiceLines SET Item='" & theItem & "', Description=N'" & theDescription & "', Length='" & theLength & "', Width='" & theWidth & "', Qtty='" & theQtty & "', Sets='" & theSets & "' WHERE ID = " & theID 587 conn.Execute(mySQL) 588'response.write "<br>" & mySQL 589'response.end 590 end if 591 next 592 593 594'--------------------------------------------------------------------------------------------------- 595 if IsA then 596 GLAccount= "91001" 'This must be changed... (Sales A) 597 else 598 GLAccount= "91002" 'This must be changed... (Sales B) 599 end if 600 601 ' Changed By Kid 860118 , seasing to use Sales B 602 603 'GLAccount= "91001" 'This must be changed... (Sales A) 604 605 conn.Execute("UPDATE ARItems SET GL='"& OpenGL & "', EffectiveDate='" & issueDate & "', GLAccount='"& GLAccount & "' WHERE (ID='" & ARItemID & "')") 606 607 '**************** Updating Invoice-Order Relations **************** 608 'mySQL="UPDATE Orders SET Closed=0 WHERE ID IN (SELECT [Order] FROM InvoiceOrderRelations WHERE (Invoice= '" & InvoiceID & "'))" 609 'Changed By Kid ! 840509 610 'set orders which are ONLY related to this invoice, "Open" 611 'that means, orders which are related to this invoice and are NOT related to any OTHER issued invoices. 612 mySQL ="UPDATE Orders SET Closed=0 WHERE ID IN (SELECT [Order] FROM InvoiceOrderRelations WHERE (Invoice = '" & InvoiceID & "') AND ([Order] NOT IN (SELECT InvoiceOrderRelations.[ORDER] FROM Invoices INNER JOIN InvoiceOrderRelations ON Invoices.ID = InvoiceOrderRelations.Invoice WHERE (Invoices.Issued = 1) AND (Invoices.Voided = 0) AND (Invoices.isReverse = 0) AND (Invoices.ID <> '" & InvoiceID & "'))))" 613 conn.Execute(mySQL) 614 615' mySQL ="DELETE FROM InvoiceOrderRelations WHERE (Invoice='" & InvoiceID & "')" 616' 'mySQL ="DELETE FROM InvoiceOrderRelations WHERE (Invoice = '" & InvoiceID & "') AND ([Order] NOT IN (SELECT InvoiceOrderRelations.[ORDER] FROM Invoices INNER JOIN InvoiceOrderRelations ON Invoices.ID = InvoiceOrderRelations.Invoice WHERE (Invoices.Issued = 1) AND (Invoices.Voided = 0) AND (Invoices.isReverse = 0) AND (Invoices.ID <> '" & InvoiceID & "')))" 617' conn.Execute(mySQL) 618' 619' for i=1 to request.form("selectedOrders").count 620' theOrder= clng(request.form("selectedOrders")(i)) 621' mySQL="INSERT INTO InvoiceOrderRelations (Invoice,[Order]) VALUES ('" & InvoiceID & "', '" & theOrder & "')" 622' conn.Execute(mySQL) 623' next 624 625 conn.Execute("UPDATE Orders SET Closed=1 WHERE ID IN (SELECT [Order] FROM InvoiceOrderRelations WHERE (Invoice='" & InvoiceID & "'))") 626 '^^^^------------ Updating Invoice-Order Relations ------------^^^^ 627 628 629 '**************** Updating Invoice-Quote Relations **************** 630 mySQL ="UPDATE Quotes SET Closed=0 WHERE ID IN (SELECT [Quote] FROM InvoiceQuoteRelations WHERE (Invoice = '" & InvoiceID & "') AND ([Quote] NOT IN (SELECT InvoiceQuoteRelations.[Quote] FROM Invoices INNER JOIN InvoiceQuoteRelations ON Invoices.ID = InvoiceQuoteRelations.Invoice WHERE (Invoices.Issued = 1) AND (Invoices.Voided = 0) AND (Invoices.isReverse = 0) AND (Invoices.ID <> '" & InvoiceID & "'))))" 631 conn.Execute(mySQL) 632 633 mySQL ="DELETE FROM InvoiceQuoteRelations WHERE (Invoice='" & InvoiceID & "')" 634 conn.Execute(mySQL) 635 636 for i=1 to request.form("selectedQuotes").count 637 theQuote= clng(request.form("selectedQuotes")(i)) 638 mySQL="INSERT INTO InvoiceQuoteRelations (Invoice,[Quote]) VALUES ('" & InvoiceID & "', '" & theQuote & "')" 639 conn.Execute(mySQL) 640 next 641 642 conn.Execute("UPDATE Quotes SET Closed=1 WHERE ID IN (SELECT [Quote] FROM InvoiceQuoteRelations WHERE (Invoice='" & InvoiceID & "'))") 643 '^^^^------------ Updating Invoice-Quote Relations ------------^^^^ 644 mySQL = "SELECT * FROM ARItems WHERE Type=1 AND Link=" & InvoiceID 645 set RSSS=conn.Execute(mySQL) 646 if RSSS.eof or not Auth(6 , "N") then 647 response.redirect "AccountReport.asp?act=showInvoice&invoice=" & InvoiceID & "&msg=" &Server.URLEncode("��� ������ ���� ��� � ��� ���� �� ������� ��� �� �� ������.") 648 else 649 if RSSS("GL_Update") then 650 ' In this secssion we update all issued invoice has not GLs 651 '--------------------------------------------------------------------------------------------------- 652 '--------------------------------------------------------------------------------------------------- 653 '--------------------------------------------------------------------------------------------------- 654 '--------------------------------------------------------------------------------------------------- 655 '--------------------------------------------------------------------------------------------------- 656 set RSinvoice=conn.Execute("SELECT * FROM Invoices WHERE ID="&InvoiceID) 657 'response.write TotalReceivable & "<br>" 658 'response.write totalVat & "<br>" 659 'response.write TotalPrice & "<br>" 660 'response.write TotalDiscount & "<br>" 661 'response.end 662 if (not RSinvoice.eof) and (clng(RSinvoice("TotalReceivable"))<>TotalReceivable or Cdbl(RSinvoice("TotalVat"))<>TotalVat) then 663 oldTotalReceivable = CLng(RSinvoice("TotalReceivable")) 664 665 666 mySQL="UPDATE Invoices SET Customer='"& CustomerID & "', Number='"& InvoiceNo & "', TotalPrice='"& TotalPrice & "', TotalDiscount='"& TotalDiscount & "', TotalReverse='"& TotalReverse & "', TotalReceivable='"& TotalReceivable & "' , IsA="& IsA & ", TotalVat='" & totalVat & "' WHERE (ID='"& InvoiceID & "')" 667 conn.Execute(mySQL) 668 669 mySQL="DELETE FROM InvoiceLines WHERE (Invoice='"& InvoiceID & "')" 670 conn.Execute(mySQL) 671 672 '**************************** Inserting Invoice Lines **************** 673 for i=1 to request.form("Items").count 674 theItem = clng(text2value(request.form("Items")(i))) 675 theDescription = left(sqlSafe(request.form("Descriptions")(i)),100) 676 677 theAppQtty = cdbl(text2value(request.form("AppQttys")(i))) 678 thePrice = clng(text2value(request.form("Prices")(i))) 679 680 theDiscount = text2value(request.form("Discounts")(i)) 681 theReverse = text2value(request.form("Reverses")(i)) 682 683 theLength = text2value(request.form("Lengths")(i)) 684 theWidth = text2value(request.form("Widths")(i)) 685 theQtty = text2value(request.form("Qttys")(i)) 686 theSets = text2value(request.form("Sets")(i)) 687 theVat = clng(text2value(request.form("Vat")(i))) 688 theHasVat = text2value(request.form("hasVat")(i)) 689 690 if theDiscount <>"" then theDiscount= clng(theDiscount) 691 if theReverse <> "" then theReverse = clng(theReverse) 692 693 if theLength <> "" then theLength = cdbl(theLength) 694 if theWidth <> "" then theWidth = cdbl(theWidth) 695 if theQtty <> "" then theQtty = clng(theQtty) 696 if theSets <> "" then theSets = clng(theSets) 697 698 mySQL="INSERT INTO InvoiceLines (Invoice, Item, Description, Length, Width, Qtty, Sets, AppQtty, Price, Discount, Reverse, Vat, hasVat) VALUES ('"& InvoiceID & "', '" & theItem & "', N'" & theDescription & "', '" & theLength & "', '" & theWidth & "', '" & theQtty & "', '" & theSets & "', '" & theAppQtty & "', '" & thePrice & "', '" & theDiscount & "', '" & theReverse & "', '" & theVat & "', "& theHasVat &")" 699 conn.Execute(mySQL) 700 next 701 if RFD > 0 then 702 theItem = 39999 703 theDescription = "����� ��� ������" 704 705 theAppQtty = 0 706 thePrice = 0 707 708 theDiscount = RFD 709 theReverse = 0 710 711 theLength = 0 712 theWidth = 0 713 theQtty = 0 714 theSets = 0 715 theVat = 0 716 mySQL="INSERT INTO InvoiceLines (Invoice, Item, Description, Length, Width, Qtty, Sets, AppQtty, Price, Discount, Reverse, Vat) VALUES ('"& InvoiceID & "', '" & theItem & "', N'" & theDescription & "', '" & theLength & "', '" & theWidth & "', '" & theQtty & "', '" & theSets & "', '" & theAppQtty & "', '" & thePrice & "', '" & theDiscount & "', '" & theReverse & "', '" & theVat & "')" 717 conn.Execute(mySQL) 718 end if 719 mySQL="UPDATE ARItems SET AmountOriginal='"& TotalReceivable &"', RemainedAmount='"& TotalReceivable &"' ,Vat='"& totalVat &"', FullyApplied = 0 WHERE ID=" & RSSS("ID") 720 Conn.Execute(mySQL) 721 Conn.Execute("Delete from ARItemsRelations where DebitARItem = " & RSSS("ID")) 722 Conn.Execute(mySQL) 723 mySQL="UPDATE Accounts SET ARBalance=ARBalance - "&TotalReceivable - oldTotalReceivable&" WHERE id=" & CustomerID 724 conn.Execute(mySQL) 725 end if 726 'end if 727 '**** 728 '^^^^--------------- Editing ---------------^^^^ 729 '-------------------------------------------------------------------------------------------------- 730 '--------------------------------------------------------------------------------------------------- 731 '--------------------------------------------------------------------------------------------------- 732 response.redirect "AccountReport.asp?act=showInvoice&invoice=" & InvoiceID & "&msg=" &Server.URLEncode("������ ��� ύ�� ������� ��� ��") 733 '--------------------------------------------------------------------------------------------------- 734 '--------------------------------------------------------------------------------------------------- 735 '--------------------------------------------------------------------------------------------------- 736 '--------------------------------------------------------------------------------------------------- 737 else 738 response.redirect "AccountReport.asp?act=showInvoice&invoice=" & InvoiceID & "&msg=" &Server.URLEncode("���� ��� ������ ���� ��� �������� ���� ���� �� ���� �������� ������ ���.") 739 end if 740 end if 741 conn.close 742 response.redirect "AccountReport.asp?act=showInvoice&invoice=" & InvoiceID & "&msg=" &Server.URLEncode("��� ������ ���� ���� ��� ���.<br>�э�� �� ��� ����� ����� �� ��� ������ �� ����� �����<br>���� ��� �� ��� ��� �� ����� �����.") 743 else 744' S A M 745'response.write(totalDiscount) 746'response.end 747 mySQL="UPDATE Invoices SET Customer='"& CustomerID & "', Number='"& InvoiceNo & "', TotalPrice='"& TotalPrice & "', TotalDiscount='"& TotalDiscount & "', TotalReverse='"& TotalReverse & "', TotalReceivable='"& TotalReceivable & "' , IsA='"& IsA & "', TotalVat='" & totalVat & "' WHERE (ID='"& InvoiceID & "')" 748 conn.Execute(mySQL) 749 750 mySQL="DELETE FROM InvoiceLines WHERE (Invoice='"& InvoiceID & "')" 751 conn.Execute(mySQL) 752 753 '**************************** Inserting Invoice Lines **************** 754 for i=1 to request.form("Items").count 755 theItem = clng(text2value(request.form("Items")(i))) 756 theDescription = left(sqlSafe(request.form("Descriptions")(i)),100) 757 758 theAppQtty = cdbl(text2value(request.form("AppQttys")(i))) 759 thePrice = clng(text2value(request.form("Prices")(i))) 760 761 theDiscount = text2value(request.form("Discounts")(i)) 762 theReverse = text2value(request.form("Reverses")(i)) 763 764 theLength = text2value(request.form("Lengths")(i)) 765 theWidth = text2value(request.form("Widths")(i)) 766 theQtty = text2value(request.form("Qttys")(i)) 767 theSets = text2value(request.form("Sets")(i)) 768 theVat = clng(text2value(request.form("Vat")(i))) 769 theHasVat = text2value(request.form("hasVat")(i)) 770 771 if theDiscount <>"" then theDiscount= clng(theDiscount) 772 if theReverse <> "" then theReverse = clng(theReverse) 773 774 if theLength <> "" then theLength = cdbl(theLength) 775 if theWidth <> "" then theWidth = cdbl(theWidth) 776 if theQtty <> "" then theQtty = clng(theQtty) 777 if theSets <> "" then theSets = clng(theSets) 778 779 mySQL="INSERT INTO InvoiceLines (Invoice, Item, Description, Length, Width, Qtty, Sets, AppQtty, Price, Discount, Reverse, Vat, hasVat) VALUES ('"& InvoiceID & "', '" & theItem & "', N'" & theDescription & "', '" & theLength & "', '" & theWidth & "', '" & theQtty & "', '" & theSets & "', '" & theAppQtty & "', '" & thePrice & "', '" & theDiscount & "', '" & theReverse & "', '" & theVat & "', "& theHasVat &")" 780 conn.Execute(mySQL) 781 next 782 if RFD > 0 then 783 theItem = 39999 784 theDescription = "����� ��� ������" 785 786 theAppQtty = 0 787 thePrice = 0 788 789 theDiscount = RFD 790 theReverse = 0 791 792 theLength = 0 793 theWidth = 0 794 theQtty = 0 795 theSets = 0 796 theVat = 0 797 mySQL="INSERT INTO InvoiceLines (Invoice, Item, Description, Length, Width, Qtty, Sets, AppQtty, Price, Discount, Reverse, Vat) VALUES ('"& InvoiceID & "', '" & theItem & "', N'" & theDescription & "', '" & theLength & "', '" & theWidth & "', '" & theQtty & "', '" & theSets & "', '" & theAppQtty & "', '" & thePrice & "', '" & theDiscount & "', '" & theReverse & "', '" & theVat & "')" 798 conn.Execute(mySQL) 799 end if 800 801 '**************** Updating Invoice-Order Relations **************** 802' mySQL="DELETE FROM InvoiceOrderRelations WHERE (Invoice='" & InvoiceID & "')" 803' conn.Execute(mySQL) 804' response.write "aaaa:" 805' response.write request.form("selectedOrders").count 806' for i=1 to request.form("selectedOrders").count 807' theOrder= clng(request.form("selectedOrders")(i)) 808' mySQL="INSERT INTO InvoiceOrderRelations (Invoice,[Order]) VALUES ('" & InvoiceID & "', '" & theOrder & "')" 809' '--------------------------SAM------------------------------ 810' ' response.write mySQL 811' '----------------------------------------------------------- 812' conn.Execute(mySQL) 813' next 814 '^^^^------------ Updating Invoice-Order Relations ------------^^^^ 815 816 ' '**************** Updating Invoice-Quote Relations **************** 817' mySQL="DELETE FROM InvoiceQuoteRelations WHERE (Invoice='" & InvoiceID & "')" 818' conn.Execute(mySQL) 819' for i=1 to request.form("selectedQuotes").count 820' theQuote= clng(request.form("selectedQuotes")(i)) 821' mySQL="INSERT INTO InvoiceQuoteRelations (Invoice,[Quote]) VALUES ('" & InvoiceID & "', '" & theQuote & "')" 822' conn.Execute(mySQL) 823' next 824 '^^^^------------ Updating Invoice-Quote Relations ------------^^^^ 825 826 end if 827 '**** 828 '^^^^--------------- Editing ---------------^^^^ 829 830 response.redirect "AccountReport.asp?act=showInvoice&invoice=" & InvoiceID 831'-------------------------------------------------------------------------------------------------------------------- 832elseif request("act")="approveInvoice" then 833 834 if not Auth(6 , "C") then 835 'Doesn't have the Priviledge to APPROVE the Invoice 836 response.write "<br>" 837 call showAlert ("��� ���� �� ����� ������ ������",CONST_MSG_ERROR) 838 response.end 839 end if 840 841 if request("invoice")<>"" then 842 843 InvoiceID=request("invoice") 844 if not(isnumeric(request("invoice"))) then 845 ShowErrorMessage("���") 846 response.end 847 end if 848 mySQL="SELECT * FROM Invoices WHERE (ID='"& InvoiceID & "')" 849 Set RS1 = conn.Execute(mySQL) 850 if RS1.eof then 851 ShowErrorMessage("���� ��� ") 852 response.end 853 else 854 855 '------------------------------------------------------------------------- 856 '---- CHECK pickup list 857 '------------------------------------------------------------------------- 858 mySQL="select distinct sales.item, sales.description, sales.appQtty,pik.itemID,pik.itemName,pik.qtty from (select invoiceLines.item,max(invoiceLines.description) as description,sum(invoiceLines.appQtty) as appQtty, InventoryInvoiceRelations.inventoryItem from InvoiceLines inner join Invoices on invoices.ID=invoiceLines.Invoice inner join InventoryInvoiceRelations on InventoryInvoiceRelations.invoiceItem=invoiceLines.Item WHERE Invoices.id=" & InvoiceID & " group by invoiceLines.item, InventoryInvoiceRelations.inventoryItem) as sales full outer join (SELECT InventoryPickuplistItems.itemID, max(InventoryPickuplistItems.ItemName) AS ItemName, sum(InventoryPickuplistItems.Qtty) AS Qtty, InventoryInvoiceRelations.invoiceItem FROM InventoryPickuplistItems INNER JOIN InventoryPickuplists ON InventoryPickuplistItems.pickupListID = InventoryPickuplists.id INNER JOIN InvoiceOrderRelations ON InventoryPickuplistItems.Order_ID = InvoiceOrderRelations.[Order] inner join invoices on InvoiceOrderRelations.invoice=invoices.id inner join InventoryInvoiceRelations on InventoryInvoiceRelations.inventoryItem=InventoryPickuplistItems.itemID WHERE NOT InventoryPickuplists.Status = N'del' and InventoryPickuplistItems.CustomerHaveInvItem=0 and Invoices.id=" & InvoiceID & " group by InventoryPickuplistItems.itemID, InventoryInvoiceRelations.invoiceItem ) as pik on pik.itemID=sales.inventoryItem or pik.invoiceItem=sales.item" 859 set rs=Conn.Execute (mySQL) 860 errmsg="" 861 msg="" 862 while not rs.eof 863 skeepNext=0 864 if IsNull(rs("appQtty")) then 865 errmsg = errmsg & "���� ������� " & rs("itemName") & " ��� ��� ����� �� ������ ��� ������<br>" 866 else 867 if IsNull(rs("qtty")) then 868 errmsg = errmsg & "���� " & rs("description") & " ��� ��� �������� ���� ���������<br>" 869 else 870 if CDbl(rs("qtty")) <> CDbl(rs("appQtty")) then 871 item=rs("item") 872 appQtty=CDbl(rs("appQtty")) 873 desc=rs("description") 874 itemName="" 875 sumQtty=0 876 do 877 skeepNext=0 878 if item<>rs("item") then exit do 879 sumQtty=sumQtty+cdbl(rs("qtty")) 880 if itemName="" then 881 itemName = rs("itemName") 882 else 883 itemName=itemName & ", " & rs("itemName") 884 end if 885 rs.moveNext 886 skeepNext=1 887 if rs.eof then exit do 888 loop while item=rs("item") 889 'rs.MovePrevious 890 891 if appQtty<>sumQtty then errmsg = errmsg & "����� ����� <b>" & itemName & "</b> �� ����� <b>" & desc & "</b> ����� ���.<br>" 892 end if 893 end if 894 end if 895 if skeepNext=0 then rs.moveNext 896 wend 897 set rs=nothing 898 899 '------------------------------------------------------------------------- 900 '---- CHECK out Service 901 '------------------------------------------------------------------------- 902 mySQL="select * from (SELECT PurchaseOrders.TypeID,max(PurchaseRequests.TypeName) as TypeName, sum(PurchaseOrders.Qtty) as Qtty FROM PurchaseOrders FULL OUTER JOIN PurchaseRequestOrderRelations RIGHT OUTER JOIN PurchaseRequests INNER JOIN InvoiceOrderRelations ON PurchaseRequests.Order_ID = InvoiceOrderRelations.[Order] ON PurchaseRequestOrderRelations.Req_ID = PurchaseRequests.ID ON PurchaseOrders.ID = PurchaseRequestOrderRelations.Ord_ID WHERE (InvoiceOrderRelations.Invoice =" & InvoiceID & ") and PurchaseRequests.Status<> 'del' and PurchaseOrders.Status<>'CANCEL' and PurchaseOrders.IsService=1 group by PurchaseOrders.TypeID) as outService full outer join (select InvoiceItems.RelatedInventoryItemID,max(description) as description,sum(appQtty) as appQtty from InvoiceLines inner join InvoiceItems on InvoiceItems.ID=invoiceLines.Item and InvoiceItems.Type=5 where Invoice=" & InvoiceID & " group by InvoiceItems.RelatedInventoryItemID) as sales on sales.RelatedInventoryItemID=outService.TypeID" 903 set rs=Conn.Execute (mySQL) 904 while not rs.eof 905 if IsNull(rs("appQtty")) then 906 errmsg = errmsg & "���� ����� " & rs("typeName") & " ��� ��� ����� �� ������ ��� ������<br>" 907 else 908 if IsNull(rs("qtty")) then 909 errmsg = errmsg & "���� " & rs("description") & " ��� ��� ������� ������ ��� ���������<br>" 910 else 911 if CDbl(rs("qtty")) <> CDbl(rs("appQtty")) then msg = msg & "����� <b>" & rs("typeName") & "</b> �� ����� <b>" & rs("description") & "</b> ����� ���.<br>" 912 end if 913 end if 914 915 rs.moveNext 916 wend 917 set rs=nothing 918 if (errmsg<>"") then 919 Conn.close 920 response.redirect "?errMsg=" & Server.URLEncode(errmsg) 921 end if 922 '------------------------------------------------------------------------- 923 '--------------------------------------------- 924 '------------------------------------------------------------------------- 925 926 if RS1("Voided") = True then 927 Conn.close 928 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("��� ������ ���� ���� ��� ���.") 929 elseif RS1("Issued") = True then 930 Conn.close 931 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("��� ������ ���� ���� ��� ���.") 932 elseif RS1("Approved") = True then 933 Conn.close 934 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("��� ������ ���� ����� ��� ���.") 935 end if 936 end if 937 else 938 ShowErrorMessage("���") 939 response.end 940 end if 941 '--------------------SAM, Iqnore multi invoice in one order 942 'mySQL="SELECT COUNT(*) AS OrderCount FROM InvoiceOrderRelations WHERE [Order] IN (SELECT [Order] FROM InvoiceOrderRelations WHERE Invoice=" & InvoiceID &")"-----------SAM coorect this on 9 mar 2011 943 mySQL = "SELECT COUNT(Invoice) AS OrderCount FROM (SELECT DISTINCT InvoiceOrderRelations.Invoice FROM InvoiceOrderRelations inner join Invoices on InvoiceOrderRelations.Invoice = Invoices.ID WHERE InvoiceOrderRelations.[Order] IN (SELECT [Order] FROM InvoiceOrderRelations WHERE Invoice=204133) and Invoices.Voided=0) tbl" 944 set RS1= conn.Execute(mySQL) 945' response.write rs1("OrderCount") 946' response.end 947 if RS1("OrderCount")>1 then 948 conn.close 949 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("�� ��� ����� �� ������ ����� ���! ���� �� �� ����� ��� �� ������ ���� ����.") 950 end if 951 '------------------------------------------------ 952 mySQL="UPDATE Invoices SET Approved=1, ApprovedDate=N'"& shamsiToday() & "', ApprovedBy='"& session("ID") & "' WHERE (ID='"& InvoiceID & "')" 953 conn.Execute(mySQL) 954 955 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&msg=" & Server.URLEncode(msg) 956'------------------------------------------------------------------------------------------------------- 957elseif request("act")="IssueInvoice" then 958 959 if not Auth(6 , "D") then 960 'Doesn't have the Priviledge to ISSUE the Invoice 961 response.write "<br>" 962 call showAlert ("��� ���� �� ���� ������ ������",CONST_MSG_ERROR) 963 response.end 964 end if 965 966 ON ERROR RESUME NEXT 967 InvoiceID= clng(request("Invoice")) 968 969 if Err.Number<>0 then 970 Err.clear 971 conn.close 972 response.redirect "top.asp?errMsg=" & Server.URLEncode("���!") 973 end if 974 ON ERROR GOTO 0 975 976 creationDate= shamsiToday() 977 issueDate= SqlSafe(request("issueDate")) 978 if issueDate="" then issueDate=creationDate 979 980 if issueDate<>creationDate then 981 if Auth(6 , "I") then 982 ' can ISSUE the Invoice / Rev. Invoice on another Date 983 984 '---- Checking wether issueDate is valid in current open GL 985 If Not CheckDateFormat(issueDate) Then 986 Conn.close 987 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("����� ���� ��� ����� ����.") 988 end if 989 990 if (issueDate < session("OpenGLStartDate")) OR (issueDate > session("OpenGLEndDate")) then 991 Conn.close 992 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("���!<br>����� ���� ��� ����� ����. <br>(�� ��� ���� ���� ����)") 993 end if 994 '---- 995 else 996 'Doesn't have the Priviledge to ISSUE the Invoice on another Date 997 response.write "<br>" 998 call showAlert ("��� ���� �� ���� ������ �� ��� ����� ������",CONST_MSG_ERROR) 999 response.end 1000 end if 1001 end if 1002 '----- Check GL is closed 1003 if (session("IsClosed")="True") then 1004 Conn.close 1005 response.redirect "?errMsg=" & Server.URLEncode("���! ��� ���� ���� ���� ��� � ��� ���� �� ����� �� �� ������.") 1006 end if 1007 '---- 1008 1009 '---- Checking wether issueDate is valid in current open GL 1010 If Not CheckDateFormat(issueDate) Then 1011 Conn.close 1012 response.redirect "AccountReport.asp?act=showInvoice&invoice="& InvoiceID & "&errmsg=" & Server.URLEncode("���!<br>����� ���� ����� ����.") 1013 end if 1014 1015 if (issueDate < session("OpenGLStartDate")) OR (issueDate > session("OpenGLEndDate")) then 1016 Conn.close 1017 response.redirect "AccountReport.asp?act=showInvoice&invoice=" & InvoiceID & "&errmsg=" & Server.URLEncode("���!<br>����� ���� ����� ����. <br>(�� ��� ���� ���� ����)") 1018 end if 1019 '---- 1020 '---- CHECK pickup list 1021 mySQL="select distinct sales.item, sales.description, sales.appQtty,pik.itemID,pik.itemName,pik.qtty from (select invoiceLines.item,max(invoiceLines.description) as description,sum(invoiceLines.appQtty) as appQtty, InventoryInvoiceRelations.inventoryItem from InvoiceLines inner join Invoices on invoices.ID=invoiceLines.Invoice inner join InventoryInvoiceRelations on InventoryInvoiceRelations.invoiceItem=invoiceLines.Item WHERE Invoices.id=" & InvoiceID & " group by invoiceLines.item, InventoryInvoiceRelations.inventoryItem) as sales full outer join (SELECT InventoryPickuplistItems.itemID, max(InventoryPickuplistItems.ItemName) AS ItemName, sum(InventoryPickuplistItems.Qtty) AS Qtty, InventoryInvoiceRelations.invoiceItem FROM InventoryPickuplistItems INNER JOIN InventoryPickuplists ON InventoryPickuplistItems.pickupListID = InventoryPickuplists.id INNER JOIN InvoiceOrderRelations ON InventoryPickuplistItems.Order_ID = InvoiceOrderRelations.[Order] inner join invoices on InvoiceOrderRelations.invoice=invoices.id inner join InventoryInvoiceRelations on InventoryInvoiceRelations.inventoryItem=InventoryPickuplistItems.itemID WHERE NOT InventoryPickuplists.Status = N'del' and InventoryPickuplistItems.CustomerHaveInvItem=0 and Invoices.id=" & InvoiceID & " group by InventoryPickuplistItems.itemID, InventoryInvoiceRelations.invoiceItem ) as pik on pik.itemID=sales.inventoryItem or pik.invoiceItem=sales.item" 1022 set rs=Conn.Execute (mySQL) 1023 errMsg="" 1024 while not rs.eof 1025 if IsNull(rs("appQtty")) then 1026 errMsg = errMsg & "���� ������� " & rs("itemName") & " ��� ��� ����� �� ������ ��� ������<br>" 1027 else 1028 if IsNull(rs("qtty")) then 1029 errMsg = errMsg & "���� " & rs("description") & " ��� ��� �������� ���� ���������<br>" 1030 else 1031 if CDbl(rs("qtty")) <> CDbl(rs("appQtty")) then 1032 'errMsg = errMsg & "����� ����� <b>" & rs("itemName") & "</b> �� ����� <b>" & rs("description") & "</b> ����� ���.<br>" 1033 item=rs("item") 1034 appQtty=CDbl(rs("appQtty")) 1035 desc=rs("description") 1036 itemName="" 1037 sumQtty=0 1038 do 1039 skeepNext=0 1040 if item<>rs("item") then exit do 1041 sumQtty=sumQtty+cdbl(rs("qtty")) 1042 if itemName="" then 1043 itemName = rs("itemName") 1044 else 1045 itemName=itemName & ", " & rs("itemName") 1046 end if 1047 rs.moveNext 1048 skeepNext=1 1049 if rs.eof then exit do 1050 loop while item=rs("item") 1051 'rs.MovePrevious 1052 1053 if appQtty<>sumQtty then errmsg = errmsg & "����� ����� <b>" & itemName & "</b> �� ����� <b>" & desc & "</b> ����� ���.<br>" 1054 1055 end if 1056 end if 1057 end if 1058 1059 rs.moveNext 1060 wend 1061 set rs=nothing 1062 1063 '---- 1064 '---- CHECK out Service 1065 mySQL="select * from (SELECT PurchaseOrders.TypeID,max(PurchaseRequests.TypeName) as TypeName, sum(PurchaseOrders.Qtty) as Qtty FROM PurchaseOrders FULL OUTER JOIN PurchaseRequestOrderRelations RIGHT OUTER JOIN PurchaseRequests INNER JOIN InvoiceOrderRelations ON PurchaseRequests.Order_ID = InvoiceOrderRelations.[Order] ON PurchaseRequestOrderRelations.Req_ID…
Large files files are truncated, but you can click here to view the full file