Created
July 8, 2015 14:29
-
-
Save deletosh/1f80caa113e5d5d04275 to your computer and use it in GitHub Desktop.
something.asp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--#include virtual="/ajaxed/bootstrap.asp" --> | |
<!--#include virtual="/includes/authCheck.asp" --> | |
<!-- classes --> | |
<!--#include virtual="/ajaxed/class_email/email.asp" --> | |
<!--#include virtual="/class/split.inc" --> | |
<!--#include virtual="/class/csvparser.inc" --> | |
<% | |
'dim msgBody | |
'Messages for Email' | |
'Open DB connection' | |
db.openDefault() | |
set sp = new Splits | |
if page.QSHas("send_email") then | |
sendEmail() | |
Elseif page.QSHas("close_cycle") then | |
closeBillCycle () | |
Elseif page.QSHas("close_split") then | |
closeSplit() | |
Elseif page.QSHas("open_bill_month") then | |
OpenBillMonth() | |
Elseif page.QSHas("add_new_project") then | |
sp.setCompany( str.trimComplete( page.RF("company") ) ) | |
AddNewProject() | |
Elseif page.QSHas("remove_incomplete") then | |
sp.setCompany( str.trimComplete( page.QS("company") ) ) | |
RemoveIncompleteLine() | |
Elseif page.QSHas("add_new_line") then | |
AddNewLine() | |
Elseif page.QSHas("add_pending_project_code") then | |
AddPendingProjectCode() | |
Elseif page.QSHas("approve_pending_project") then | |
ApprovePendingProjectCode() | |
Elseif page.QSHas("deny_pending_project") then | |
DenyPendingProjectCode() | |
End if | |
%> | |
<% | |
sub AddPendingProjectCode() | |
company = str.trimComplete( page.RF("company") ) | |
redirectTo = page.RF("refUrl") | |
Session("new_project_code") = "true" | |
sp.setCompany(company) | |
location_code = str.trimComplete( page.RF("location_code") ) | |
account_code = str.trimComplete( page.RF("account_code") ) | |
description = str.trimComplete( page.RF("description") ) | |
billable_project_code = str.trimComplete( page.RF("billable_project_code") ) | |
code_status = str.trimComplete( page.RF("code_status") ) | |
display_order = str.trimComplete( page.RF("display_order")) | |
entered_by = Session("user.email") | |
if location_code = "" then | |
Session("new_project_code_msg") = "You cannot have an empty project code..." | |
redirectTo = redirectTo | |
Response.Redirect(redirectTo) | |
else | |
on error resume next | |
insertedRecords = sp.addNewProject(location_code, account_code, description, billable_project_code, code_status, display_order, entered_by) | |
if Err.Number <> 0 then | |
'handle Error' | |
lib.logger(Err.Msg) | |
Err.Clear | |
End if | |
on error goto 0 | |
if insertedRecords > 0 AND insertedRecords <> 99 then | |
Session("new_project_code_msg") = "Project " & location_code & " added, you can now select it from drop-down" | |
redirectTo = redirectTo | |
Response.Redirect(redirectTo) | |
elseif not sp.isProjectCodeActive(location_code) then | |
Session("new_project_code_msg") = "The project code (" & location_code & ") that you are trying to add has previously been reviewed and is currently labeled as non-billable. Please reach out to your line manager to confirm that this code is approved for wireless charges to be passed through. Once confirmed, please reach out to the PAREXEL Split Billing portal administrator listed on your project homepage for further review." | |
redirectTo = redirectTo | |
Response.Redirect(redirectTo) | |
else | |
Session("new_project_code_msg") = "Project " & location_code & " already exists, you can now select it from drop-down" | |
redirectTo = redirectTo | |
Response.Redirect(redirectTo) | |
end if | |
end if | |
end sub | |
sub ApprovePendingProjectCode() | |
company = str.trimComplete( page.RF("company") ) | |
redirectTo = page.RF("ref_url") | |
sp.setCompany(company) | |
project_code_id = str.trimComplete( page.RF("project_code_id") ) | |
location_code = str.trimComplete( page.RF("location_code") ) | |
billable = str.trimComplete( page.RF("billable") ) | |
code_status = str.trimComplete( page.RF("code_status") ) | |
display_order = str.trimComplete( page.RF("display_order") ) | |
acted_by = Session("user.email") | |
entered_by = str.trimComplete( page.RF("entered_by") ) | |
approval_status = "Approved" | |
if location_code = "" then | |
Session("pending_project_code_msg") = "You cannot have an empty project code..." | |
redirectTo = redirectTo | |
Response.Redirect(redirectTo) | |
else | |
on error resume next | |
updatedProject = sp.updateProject(project_code_id, location_code, billable,code_status,display_order, acted_by) | |
if Err.Number <> 0 then | |
'handle Error' | |
lib.logger.error(Err.Msg) | |
Err.Clear | |
End if | |
on error goto 0 | |
Set Mail = Server.CreateObject("Persits.MailSender") | |
Mail.Host = "10.1.20.13" | |
' Mail.Host = "66.29.215.45" 'MaxASP, deprecaiting | |
Mail.RegKey = "59931-06309-76540" | |
Mail.Queue = True 'Queues all messages by default | |
Mail.IsHTML = True 'Sends as HTML by defaults | |
'Set up Email' | |
Mail.From = "[email protected] " | |
Mail.FromName = "[CRA] WA Support" | |
set t = new TextTemplate | |
t.filename = "../../template/email/min/user_split_status.html" | |
t.add "locationCode", location_code | |
t.add "approvalStatus", approval_status | |
Mail.Subject = t.getFirstLine() | |
Mail.Body = t.getAllButFirstLine() | |
Mail.AddAddress entered_by | |
On Error Resume Next | |
Mail.Send | |
Session("pending_project_code_msg") = "Project " & location_code & " "& approval_status &" and " & entered_by &" notified" | |
redirectTo = redirectTo | |
Response.Redirect(redirectTo) | |
end if | |
end sub | |
sub DenyPendingProjectCode() | |
company = str.trimComplete( page.RF("company") ) | |
redirectTo = page.RF("ref_url") | |
sp.setCompany(company) | |
project_code_id = str.trimComplete( page.RF("project_code_id") ) | |
location_code = str.trimComplete( page.RF("location_code") ) | |
billable = str.trimComplete( page.RF("billable") ) | |
code_status = str.trimComplete( page.RF("code_status") ) | |
display_order = str.trimComplete( page.RF("display_order") ) | |
acted_by = Session("user.email") | |
entered_by = str.trimComplete( page.RF("entered_by") ) | |
approval_status = "Denied" | |
default_project_codes = array("100205","440040","100140","320005") | |
fallback_project_code = "100205" | |
if location_code = "" then | |
Session("pending_project_code_msg") = "You cannot have an empty project code..." | |
redirectTo = redirectTo | |
Response.Redirect(redirectTo) | |
else | |
on error resume next | |
'updatedProject = sp.updateProject(project_code_id, location_code, billable,code_status,display_order, acted_by) | |
if Err.Number <> 0 then | |
'handle Error' | |
lib.logger.error(Err.Msg) | |
Err.Clear | |
End if | |
on error goto 0 | |
'get splits on that project code | |
Call sp.loadUsersByLocationCode(usersOnProjectCode, location_code) | |
'iterate and send emails | |
count = 0 | |
do while not usersOnProjectCode.EOF | |
're-assign to Home Cost Center | |
if(sp.inArray(usersOnProjectCode("defaultProjectCode"), default_project_codes)) then | |
Call sp.getProjectCodeId(reAssignTo,usersOnProjectCode("defaultProjectCode")) | |
else | |
Call sp.getProjectCodeId(reAssignTo,fallback_project_code) | |
end if | |
sp.reassignSplitProject location_code,reAssignTo("projectCode") | |
tpl.filename = "../../template/email/full/split_projectcode_status.html" | |
tpl.add "locationCode", location_code | |
tpl.add "approvalStatus", approval_status | |
with new Email | |
.addRecipient "to", usersOnProjectCode("employeeEmail"), usersOnProjectCode("username") | |
.addRecipient "bcc", "[email protected]", "Allocations Team" | |
.sendersName = "[CRA] WA Support" | |
.subject = tpl.getFirstLine() | |
.body = tpl.getAllButFirstLine() | |
if not .send() then lib.logger.error("Could not send: " & .errorMsg) | |
count = count + 1 | |
end with | |
usersOnProjectCode.MoveNext | |
Loop | |
Session("pending_project_code_msg") = "Project " & location_code & " "& approval_status &" and " & count &" users notified" | |
redirectTo = redirectTo | |
Response.Redirect(redirectTo) | |
end if | |
end sub | |
sub OpenBillMonth() | |
sp.setCarrierId( page.RF("carrier_id") ) | |
bill_month = formatDateToSQL( page.RF("bill_month") ) | |
carrier_id = page.RF("carrier_id") | |
' curr_date = Date() | |
' newMonth = split(curr_date, "/")(0) | |
' newDay = split(curr_date, "/")(1) | |
' newYear = split(curr_date, "/")(2) | |
' if newMonth = 12 then | |
' newMonth = newMonth - 11 | |
' else | |
' newMonth = newMonth + 1 | |
' End if | |
' new_bill_cycle = DateSerial(newYear, newMonth -1, 1) | |
insertNewBillMonth = sp.openBillCycle( bill_month, page.RF("company") ) | |
'also fast-forward the current splits | |
updatedSplits = sp.updateSplitsToCurrCycle(bill_month, page.RF("company")) | |
redirectTo = "//" & server_path & "/platform/admin/splits" | |
Response.Redirect(redirectTo) | |
end sub | |
%> | |
<% sub AddNewProject() %> | |
<% | |
location_code = str.trimComplete( page.RF("location_code") ) | |
account_code = str.trimComplete( page.RF("saccount_code") ) | |
description = str.trimComplete( page.RF("description") ) | |
billable_project_code = page.RF("billable_project_code") | |
if location_code = "" then | |
str.write "You cannot have an empty project code..." | |
else | |
on error resume next | |
insertedRecords = sp.addNewProject(location_code, account_code, description, billable_project_code) | |
if Err.Number <> 0 then | |
'handle Error' | |
Err.Clear | |
End if | |
on error goto 0 | |
if insertedRecords > 0 then | |
'str.writef "Added Project Code: {0} with ID: {1}", array(location_code, insertedRecords) | |
redirectTo = "//" & server_path & "/platform/admin/splits/default.asp?inserted_record=" & insertedRecords & "&project_code=" & location_code & "#simpleContained3" | |
Response.Redirect(redirectTo) | |
end if | |
end if | |
%> | |
<% end sub %> | |
<% sub AddNewLine() | |
add_line = page.QS("add_new_line") | |
' sp.setCompany(company) | |
Randomize | |
unique_stamp = (rnd*10000) + 1 | |
select case add_line | |
case "upload" | |
set CSVStream = new CSVParser | |
set Upload = Server.CreateObject("Persits.Upload") | |
upload_path = root_path & "platform\uploads\" | |
Upload.Save | |
sp.setCompany( Upload.Form("company") ) | |
for each File in Upload.Files | |
if File.Ext = ".csv" then | |
upload_path = upload_path & File.Name & "_" & unique_stamp & File.Ext | |
File.SaveAs upload_path | |
file_name = File.OriginalFileName | |
'read the files into stream' | |
Call CSVStream.ReadFile(upload_path, inStream) | |
dim arrRow() | |
count = 0 | |
'populate the Array' | |
do while not inStream.AtEndOfStream | |
Redim Preserve arrRow(count) | |
sRow = inStream.readLine | |
arrRow(count) = split(sRow, ",") | |
'skip the header line:' | |
if count > 0 then | |
on error resume next | |
sp.addNewLine arrRow(count)(0), arrRow(count)(1), arrRow(count)(2), arrRow(count)(3), arrRow(count)(4) | |
End if | |
if err.number <> 0 then | |
error = Err.Description | |
redirectTo = "//" & server_path & "/platform/admin/splits/default.asp?error=" & error & "#simpleContained4" | |
End if | |
count = count + 1 | |
Loop | |
else | |
error = "You can only upload a CSV file, please try again" | |
end if | |
Next | |
if error = "" then | |
redirectTo = "//" & server_path & "/platform/admin/splits/default.asp?upload_success=" & count - 1 & " lines added successfully!" & "#simpleContained4" | |
Else | |
redirectTo = "//" & server_path & "/platform/admin/splits/default.asp?error=Oops: " & error & "company="&company & "#simpleContained4" | |
End if | |
case "single" | |
sp.setCompany( page.RF("company") ) | |
mobile_number = page.RF("mobile_number") | |
split_value = page.RF("split_value") | |
bill_method = page.RF("bill_method") | |
project_code = page.RF("project_code") | |
carrier_id = page.RF("carrier_id") | |
'API: addNewLine(mobile_number, split_value, bill_method, project_code) | |
on error resume next | |
sp.addNewLine mobile_number, split_value, bill_method, project_code, carrier_id | |
if err.number <> 0 then | |
error = Err.Description | |
redirectTo = "//" & server_path & "/platform/admin/splits/default.asp?error=" & error & "#simpleContained4" | |
End if | |
if error = "" then | |
redirectTo = "//" & server_path & "/platform/admin/splits/default.asp?single_line_success=Mobile Numnber: "& mobile_number &" was%20successfully%20added!#simpleContained4" | |
Else | |
redirectTo = "//" & server_path & "/platform/admin/splits/default.asp?error=Oops: "& error &"#simpleContained4" | |
End if | |
end select | |
Response.Redirect(redirectTo) | |
end sub %> | |
<% sub closeBillCycle() %> | |
<% | |
sp.setCompany( page.RF("company") ) | |
sp.setBillMonth( page.RF("bill_month") ) | |
sp.setCarrierId( page.RF("carrier_id") ) | |
lib.logger.info( page.RF("carrier_id") ) | |
On Error Resume Next | |
updated = sp.closeBillCycle() | |
if Err.Number <> 0 then | |
lib.logger.error(Err.Description) | |
str.write "<h2> We're sorry, the record did not update</h2>" | |
Else %> | |
<p>Bill Cycle <%= sp.getBillMonth()%> for <%= sp.getCompany() %> <strong>Closed</strong></p> | |
<% | |
redirectTo = "//" & server_path & "/platform/admin/splits" | |
'' | |
Response.Redirect( redirectTo ) | |
%> | |
<% | |
End if | |
%> | |
<% On Error goto 0 %> | |
<% end sub %> | |
<% sub closeSplit() %> | |
<% | |
'get where this referral is from | |
referral = page.QS("ref") | |
'request can come from a RF or QS' | |
if page.RF("mobile_number") = "" then | |
mobile_number = page.QS("mobile_number") | |
else | |
mobile_number = page.RF("mobile_number") | |
end if | |
if page.RF("bill_month") = "" then | |
bill_month = page.QS("bill_month") | |
else | |
bill_month = page.RF("bill_month") | |
end if | |
sp.setMobileNumber( mobile_number ) | |
sp.setBillMonth( bill_month ) | |
On Error Resume Next | |
sp.closeSplit() | |
If Err.Number <> 0 then | |
lib.logger.error(Err.Description) | |
str.write "<p>Sorry, cannot close this line</p>" | |
Else %> | |
<% if referral <> "" then %> | |
<p> The line <%= sp.getMobileNumber() %> is now <strong>removed from Split</strong> for Bill Month: <%= sp.getBillMonth %></p> | |
<p><a href="//<%=server_path%>/helpdesk/case_show.asp?case_status=Open">Return to Helpdesk</a></p> | |
<% else | |
'send back to location' | |
redirectTo = "//" & server_path & "/platform/admin/splits/default.asp" | |
Response.Redirect(redirectTo) | |
end if%> | |
<%End if%> | |
<% On Error Goto 0 | |
end sub | |
%> | |
<% sub sendEmail() | |
account_number = page.RF("account_number") | |
invoice_number = page.RF("invoice_number") | |
billOpenUntil = page.RF("bill_open_until") | |
carrierId = page.RF("carrier_id") | |
'default to 5 days from when sent if left empty' | |
if billOpenUntil = "" then | |
billOpenUntil = Date + 5 | |
end if | |
send_test_email = page.RF("send_test_email") | |
send_to_email = page.RF("send_to_email") | |
'Set the session to the current value >> preserving states' | |
if page.RF("company") = "" OR page.RF("bill_month") = "" then | |
company = Session("loaded_company") | |
bill_month = Session("loaded_bill_month") | |
Else | |
company = page.RF("company") | |
bill_month = page.RF("bill_month") | |
End if | |
sp.setCompany( company ) | |
sp.setBillMonth( bill_month ) | |
sp.setCarrierId( carrierId ) | |
sp.setup() | |
emailCount = 0 | |
Call sp.loadSplitNumbers(spNumRS, account_number, invoice_number) | |
do while not spNumRS.EOF | |
Set Mail = Server.CreateObject("Persits.MailSender") | |
Mail.Host = "10.1.20.13" | |
' Mail.Host = "66.29.215.45" 'MaxASP, deprecaiting | |
Mail.RegKey = "59931-06309-76540" | |
Mail.Queue = True 'Queues all messages by default | |
Mail.IsHTML = True 'Sends as HTML by defaults | |
'Set up Email' | |
Mail.From = "[email protected] " | |
Mail.FromName = "WA Support" | |
set t = new TextTemplate | |
if send_test_email = "true" AND send_to_email = "" then | |
'is this a test email? | |
Mail.AddAddress "[email protected]" | |
'str.write "Sending notification to: [email protected]<br/>" | |
elseif send_test_email = "true" AND send_to_email <> "" then | |
Mail.AddAddress send_to_email | |
'str.write "Sending notification to: " & send_to_email &"<br/>" | |
else | |
Mail.AddAddress spNumRS("email") | |
'str.write "Sending notification to: " & spNumRS("email") | |
end if | |
projectCount = "1" | |
if spNumRS("ProjectCode") = "0" then 'it doesn't have a project code' | |
t.filename = "../../template/email/min/user_split_incomplete.html" 'the template used' | |
else | |
t.filename = "../../template/email/min/user_split.html" 'the template used' | |
end if | |
currbillMonth = sp.getBillMonth | |
t.add "billMonth", currbillMonth | |
t.add "company", sp.getCompany | |
t.add "server", server_path | |
t.add "monthName", MonthName( Month(currbillMonth) ) & " " & Year(currbillMonth) | |
'@params: | |
mobileNumber = spNumRS("MobileNumber") | |
userName = spNumRS("username") | |
TAC = CDbl( spNumRS("TAC") ) | |
billEndDate = spNumRS("billEndDate") | |
'debug >>> | |
dim outContent : outContent = "" | |
t.add "mobileNumber", mobileNumber | |
t.add "userName", userName | |
t.add "accountNumber", account_number | |
t.add "billEndDate", billEndDate | |
t.add "closeBillEndDate", billOpenUntil | |
t.add "TAC", TAC '<< total Allocated Charge | |
'inner Stack to populate split info' | |
Call sp.loadRecipientSplit( spRS, spNumRS("MobileNumber") ) | |
do while not spRS.EOF | |
projectCode = spRS("ProjectCode") | |
description = spRS("Description") | |
splitValue = CDbl( spRS("SplitValue") ) | |
splitProjectNew = "splitProject"&projectCount | |
'add the respective projects ' | |
'should break out into fixed and percents | |
if( spRS("BillMethodId") = 1 ) then | |
t.add "splitProject"&projectCount, "<tr style='border-bottom:1px solid'><td style='text-align:center;'>"& projectCode &"</td><td style='text-align:center;'>"& FormatNumber( splitValue * 100, 2) & "% ($" & FormatNumber( splitValue * TAC, 2) &")</td></tr>" | |
else | |
t.add "splitProject"&projectCount, "<tr style='border-bottom:1px solid'><td style='text-align:center;'>"& projectCode &"</td><td style='text-align:center;'>$"& FormatNumber( splitValue, 2) & "</td></tr>" | |
end if | |
outContent = outContent & " " & projectCode & " " & description & " " & splitProject & " <br/>" | |
projectCount = projectCount + 1 | |
spRS.MoveNext | |
Loop | |
Mail.Subject = t.getFirstLine() | |
Mail.Body = t.getAllButFirstLine() | |
On Error Resume Next | |
Mail.Send : emailCount = emailCount + 1 | |
If Err <> 0 then | |
str.write "There was an issue: " & Err.Err | |
Description.clear | |
End if | |
On Error Goto 0 | |
spNumRS.MoveNext | |
Loop | |
str.write send_to_email | |
if send_test_email = "true" OR send_to_email = "" then | |
message_success = "Successfully notified " & emailCount & " Users (testing 1, 2, 3... check test email now)" | |
else | |
message_success = "Successfully notified " & emailCount & " Users" | |
end if | |
'Log the sent email' | |
sp.setEmailSentTime sp.getBillMonth(), sp.getClientId(), sp.getCarrierId(), emailCount | |
'send back to location' | |
redirectTo = "//" & server_path & "/platform/admin/splits/default.asp?load_company=true&message_success=" & message_success &"#simpleContained2" | |
Response.Redirect(redirectTo) | |
end sub %> | |
<% sub RemoveIncompleteLine() %> | |
<% | |
mobile_number = page.QS("remove_incomplete") | |
bill_month = page.QS("bill_month") | |
%> | |
<%= mobile_number %> | |
<%= bill_month %> | |
<% | |
sp.removeIncompleteLine mobile_number,bill_month | |
'send back to location' | |
redirectTo = "//" & server_path & "/platform/admin/splits/default.asp?remove_success=" & mobile_number &"#simpleContained2" | |
Response.Redirect(redirectTo) | |
%> | |
<% end sub %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment