-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Link to Billing #73
Open
jan-krueger
wants to merge
7
commits into
dolkensp:release
Choose a base branch
from
starcitizendotguide:feature-billing-link
base: release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Link to Billing #73
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6609500
link to invoices (WIP)
jan-krueger b92bb1c
fix eslint issues
jan-krueger ced0841
fix popup issues
jan-krueger 7f701a5
make XMLHttpRequest async
jan-krueger b61a346
add fuse as backup search
jan-krueger 6d28044
improvements
jan-krueger 011e7c2
fixes & better performance for people with a lot of upgrades
jan-krueger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
var HangarXPLOR = window.HangarXPLOR || {}; | ||
HangarXPLOR.Billing = window.HangarXPLOR.Billing || {}; | ||
|
||
HangarXPLOR.Billing.Keys = []; | ||
HangarXPLOR.Billing.Bills = []; | ||
HangarXPLOR.Billing.UpgradeBills = []; | ||
HangarXPLOR.Billing.DoneLoading = false; | ||
|
||
HangarXPLOR.Billing.LoadData = function() { | ||
HangarXPLOR.Billing.parseBills(1); | ||
}; | ||
|
||
HangarXPLOR.Billing.getBill = function(name, date, isUpgraded = false, upgradedName = null) { | ||
date = HangarXPLOR.Billing.parseDate(date); | ||
const bills = HangarXPLOR.Billing.Bills[date]; | ||
|
||
if(typeof bills === 'undefined') { | ||
return []; | ||
} | ||
|
||
name = name.toLowerCase(); | ||
|
||
let findBill = function(bills, name) { | ||
let bill = null; | ||
|
||
for(let i = 0; i < bills.length; i++) { | ||
if(bills[i]['name'].includes(name)) { | ||
bill = bills[i]; | ||
} | ||
} | ||
|
||
if(bill === null) { | ||
let fuse = new Fuse(bills, {keys: ['name']}) | ||
let results = fuse.search(name); | ||
|
||
if(results.length > 0) { | ||
bill = results[0]; | ||
} | ||
} | ||
|
||
return bill; | ||
} | ||
|
||
let bill = findBill(bills, name); | ||
|
||
// --- if this item was upgraded then also try to find the bill for the upgrade | ||
if(bill !== null && isUpgraded) { | ||
upgradedName = upgradedName.toLowerCase(); | ||
let upgraded_bill = null; | ||
for(let key in HangarXPLOR.Billing.UpgradeBills) { | ||
if(key >= date) { // exploits lexicographic ordering - might be a bit hacky but avoids creating new Date objects | ||
upgraded_bill = findBill(HangarXPLOR.Billing.UpgradeBills[key], upgradedName); | ||
if(upgraded_bill !== null) { | ||
let splitted = upgraded_bill.name.split(/( to )/gm); | ||
if(splitted.length === 2 && splitted[1].indexOf(upgradedName)) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if(upgraded_bill !== null) { | ||
return [bill, upgraded_bill]; | ||
} | ||
} | ||
|
||
if(bill !== null) { | ||
return [bill]; | ||
} | ||
|
||
return []; | ||
} | ||
|
||
HangarXPLOR.Billing.parseDate = function(date) { | ||
date = new Date(date); | ||
date.setHours(0); | ||
date.setMinutes(0); | ||
|
||
return date.toISOString().split('T')[0]; | ||
} | ||
|
||
HangarXPLOR.Billing.parseBills = function(pageNo) { | ||
let page_size = 100; // <-- 100 is probably max | ||
var request = new XMLHttpRequest(); | ||
request.open('GET', 'https://robertsspaceindustries.com/account/billing?page=' + pageNo + '&pagesize=' + page_size + '&order_status=O,C ', true); | ||
request.onload = function() { | ||
if (request.readyState === 4 && request.status === 200) { | ||
// --- parse html & get the list of orders on that site | ||
var doc = new DOMParser().parseFromString(request.responseText, "text/html"); | ||
let order_items = doc.getElementsByClassName('orders-item')[0].children; | ||
|
||
// --- go through each order and extract the name and the slug | ||
for(let i = 0; i < order_items.length; i++) { | ||
|
||
let order_name = order_items[i].getElementsByClassName('billing-summary')[0].children[0].children[1].children[0].firstChild.nodeValue; | ||
let order_slug = order_items[i].querySelector('[data-order-slug]'); | ||
let order_date = HangarXPLOR.Billing.parseDate( new Date(order_items[i].getElementsByClassName('col date')[0].lastChild.data.trim())); | ||
|
||
if(HangarXPLOR.Billing.Keys.length === 0 || HangarXPLOR.Billing.Keys[HangarXPLOR.Billing.Keys.length - 1] !== order_date) { | ||
HangarXPLOR.Billing.Keys.push(order_date); | ||
} | ||
|
||
|
||
// --- if the order slug is null then no invoice exists (e.g. cancelled, payment failed, etc.) | ||
if(order_slug !== null) { | ||
order_slug = order_slug.dataset.orderSlug; | ||
|
||
let bill = { | ||
'name': order_name.toLowerCase(), | ||
'slug': order_slug, | ||
'date': order_date, | ||
}; | ||
|
||
if(bill.name.startsWith('upgrade') || bill.name.startsWith('ship upgrades ')) { | ||
if(!(order_date in HangarXPLOR.Billing.UpgradeBills)) { | ||
HangarXPLOR.Billing.UpgradeBills[order_date] = []; | ||
} | ||
|
||
HangarXPLOR.Billing.UpgradeBills[order_date].push(bill); | ||
} else { | ||
if(!(order_date in HangarXPLOR.Billing.Bills)) { | ||
HangarXPLOR.Billing.Bills[order_date] = []; | ||
} | ||
|
||
HangarXPLOR.Billing.Bills[order_date].push(bill); | ||
} | ||
|
||
|
||
} | ||
} | ||
|
||
if(order_items.length == page_size) { | ||
HangarXPLOR.Billing.parseBills(pageNo + 1); | ||
} else { | ||
HangarXPLOR.Billing.Keys.reverse(); | ||
HangarXPLOR.Billing.DoneLoading = true; | ||
} | ||
} | ||
} | ||
request.send(); | ||
} |
This file contains 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
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're only linking to billing data - perhaps the lookup could be executed on-click rather than pre-loaded?
Might help with larger hangars/billing history
EDIT: I see in ProcessItem you may already be doing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. The look up happens when you click the arrow button to open up each item. The look ups should also always be fairly fast unless the user has a lot of bills on one specific day.