#!/bin/env python
 
import sys
import AccountingReports

def main(argv=None):
    AccountingReports.UseArgs(argv)

    if not AccountingReports.CheckDB() :
        return 1

    argOutput = AccountingReports.gOutput
    if (argOutput == "all"):
       text = {}
       for iterOutput in ("text","csv","html"):
          text[iterOutput] = AccountingReports.RangeSummup(range_begin = AccountingReports.gBegin,
                                 range_end = AccountingReports.gEnd ,
                                 output=iterOutput);
          text[iterOutput] += AccountingReports.RangeSiteReport(range_begin = AccountingReports.gBegin,
                                 range_end = AccountingReports.gEnd,
                                 output = iterOutput,
                                 header = True,
                                 with_panda = AccountingReports.gWithPanda);
          text[iterOutput] += AccountingReports.RangeVOReport(range_begin = AccountingReports.gBegin,
                               range_end = AccountingReports.gEnd,
                               output = iterOutput,
                               header = False,
                               with_panda = AccountingReports.gWithPanda);
          text[iterOutput] += AccountingReports.RangeSiteVOReport(range_begin = AccountingReports.gBegin,
                                   range_end = AccountingReports.gEnd,
                                   output = iterOutput,
                                   header = False,
                                   with_panda = AccountingReports.gWithPanda);
          text[iterOutput] += AccountingReports.RangeVOSiteReport(range_begin = AccountingReports.gBegin,
                                   range_end = AccountingReports.gEnd,
                                   output = iterOutput,
                                   header = False,
                                   with_panda = AccountingReports.gWithPanda);
       AccountingReports.sendAll(text)

    else:
          print AccountingReports.RangeSiteReport(range_begin = AccountingReports.gBegin,
                                 range_end = AccountingReports.gEnd,
                                 output = iterOutput,
                                 header = True,
                                 with_panda = AccountingReports.gWithPanda);
          print AccountingReports.RangeSiteReport(range_begin = AccountingReports.gBegin,
                                 range_end = AccountingReports.gEnd,
                                 output = iterOutput,
                                 header = True,
                                 with_panda = AccountingReports.gWithPanda);
          print AccountingReports.RangeVOReport(range_begin = AccountingReports.gBegin,
                               range_end = AccountingReports.gEnd,
                               output = iterOutput,
                               header = False,
                               with_panda = AccountingReports.gWithPanda);
          print AccountingReports.RangeSiteVOReport(range_begin = AccountingReports.gBegin,
                                   range_end = AccountingReports.gEnd,
                                   output = iterOutput,
                                   header = False,
                                   with_panda = AccountingReports.gWithPanda);
          print AccountingReports.RangeVOSiteReport(range_begin = AccountingReports.gBegin,
                                   range_end = AccountingReports.gEnd,
                                   output = iterOutput,
                                   header = False,
                                   with_panda = AccountingReports.gWithPanda);

if __name__ == "__main__":
    sys.exit(main())
