#!/usr/bin/env python
"""
Parse the outstanding bills from Unicorn generated by the export_unicorn.pl script
and generate data to COPY into a bills staging table
"""

#    Copyright (C) 2009, Dan Scott
#    Thanks to the Robertson Library, UPEI, for funding these scripts. 

#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import UnicornImport as ui

if __name__ == '__main__':
   
    # Incoming data:
    # Amount|Balance|Date|Reason|Library|ItemBarcode|UserBarcode|
    # 300|300|20080530|OVERDUE|DESMARAIS|3929292929      |00007000929292|
    fields_in = ("amount_charged", "balance", "date_billed", "reason", "library", "usr", "item")
    
    # This is all that the staging table currently wants
    fields_out = ("amount_charged", "balance", "date_billed", "reason", "library", "usr", "item")

    date_fields = ("date_billed")
    
    # create our Unicorn reader
    hldg = ui.Holdings('../export2eg/bills.lst', 'bills.sql', fields_in, fields_out, date_fields)
    
    # print out the header
    hldg.file_out.write('COPY staging_bills(amount_charged, balance, date_billed, reason, library, usr, item) from STDIN;\n')
    
    hldg.dump_fields()
