How to customize chargeback

We want to create a chargeback report with this very special formula:

  • if a VM with a tag X is up more than 2 days in a month, the Cost is X.Cost * days.o_fmonth (30)
    -if a VM with tag Y is up more than 15 days, the cost is Y.Cost * 15.
  • if a VM is up a full month, and the first day of next month only: this first day should not be charged.

How to do that with Cloudforms/MIQ?