The upgrading/downgrading system of WHMCS is actually quite simple. It takes into consideration two major things:
Days amount until billing due date;
Price difference between old & new package;
Client can't access upgrade/downgrade when they have an unpaid invoice for that service already. For example, the invoice for next month. That invoice should be cancelled manually by a Support Agent before. After the client has upgraded then, a new invoice for next month should be manually created after.
After paying upgrade invoice, clients package will automatically be updated to run with more RAM/Disk Space/Backups.
When Downgrading, client will receive the "overpaid" amount to their Client Balance as credits. That can be used for future server payments. It can't be withdrawn!