The government's budget must be approved by the parliament (NPC), and every penny must be used according to the budget. Sometimes, loans provided by other countries can be used for extra-budgetary expenditures.
There are many reasons and functions for using foreign loans. For example, Japanese loans are all Japanese yen, and products must be purchased from Japan in the end, which has the function of balancing import and export.
This problem is very complicated, and how the country uses money cannot be compared with one household.