Salesperson commision based on rules

Hi! I would like your help figuring out how to calculate the payment to sales representatives based on the amount of money in sales they made. The payroll would be calculated every 15 days.

Something along the lines of,
if total_sales <= $5000: payment=0.5*sales else if total_sales<=$30000: payment=0.1*sales else: payment=0.15*sales+bonus ...
I don’t think this can be done alone with commission per sales as the percentage changes depending on what the salesperson has sold during those days. Any thoughts?

Just a suggestion:
You can add total_sales as custom field to the Salary Structure Employee. And add payment as some Salary Component.
And create a Salary Structure, using your conditions and formula.
https://frappe.github.io/erpnext/user/manual/en/human-resources/salary-and-payroll

If I add the salary component total_sales,how do I link that to the invoices that I need to pay my sales person commission on?
Where does it pull the value from that I can use in the salary structure to calculate the commission.
Once it pulls that value Commission = total_sales * x%