config {
    engine CGI;
    template_engine TT;
    Init Std { }
    SQL Postgres {  }
    Control Gantry { dbix 1; }
    SiteLook GantryDefault { gantry_wrapper `/home/pcrow/srcgantry/root/sample_wrapper.tt`; }
    Model GantryDBIxClass {  }
    CGI Gantry { instance billing; with_server 1; }
    Conf General {  }
}
app Apps::Billing {
#    location `/billing`;
    authors `Tim Keefer`, `Phil Crow` => `philcrow2000@yahoo.com`;
    config {
        dbconn `dbi:Pg:dbname=billing` => no_accessor;
        dbuser apache => no_accessor;
        template_wrapper `genwrapper.tt` => no_accessor;
        root `/home/pcrow/srcgantry/docs/books/studies/Apps-Billing/html:/home/pcrow/srcgantry/root` => no_accessor;
        css_root `/home/pcrow/srcgantry/root/css` => no_accessor;
        css_rootp `/css` => no_accessor;
        app_rootp `/billing` => no_accessor;
    }
    sequence mycomp_seq {}
    sequence customers_seq {}
    sequence line_items_seq {}
    sequence invoices_seq {}
    sequence status_seq {}
    table my_companies {
        sequence mycomp_seq;
        foreign_display `%name`;
        field id {
            is int4, primary_key, assign_by_sequence;
        }
        field name {
            is varchar;
            label Name;
            html_form_type text;
        }
        field address {
            is varchar;
            label Address;
            html_form_type text;
        }
        field city {
            is varchar;
            label City;
            html_form_type text;
        }
        field state {
            is varchar;
            label State;
            html_form_type text;
        }
        field zip {
            is varchar;
            label Zip;
            html_form_type text;
        }
        field descr {
            is varchar;
            label Description;
            html_form_type text;
            html_form_optional 1;
        }
        field contact_name {
            is varchar;
            label `Contact Name`;
            html_form_type text;
        }
        field contact_email {
            is varchar;
            label `Contact Email`;
            html_form_type text;
        }
        field contact_phone {
            is varchar;
            label `Contact Phone`;
            html_form_type text;
        }
    }
    table customers {
        sequence invoices_seq;
        foreign_display `%name`;
        field id {
            is int4, primary_key, assign_by_sequence;
        }
        field name {
            is varchar;
            label Name;
            html_form_type text;
        }
        field address {
            is varchar;
            label Address;
            html_form_type text;
        }
        field city {
            is varchar;
            label City;
            html_form_type text;
        }
        field state {
            is varchar;
            label State;
            html_form_type text;
        }
        field zip {
            is varchar;
            label Zip;
            html_form_type text;
        }
        field descr {
            is varchar;
            label Description;
            html_form_type text;
            html_form_optional 1;
        }
        field contact_name {
            is varchar;
            label `Contact Name`;
            html_form_type text;
            html_form_optional 1;
        }
        field contact_email {
            is varchar;
            label `Contact Email`;
            html_form_type text;
            html_form_optional 1;
        }
        field contact_phone {
            is varchar;
            label `Contact Phone`;
            html_form_type text;
            html_form_optional 1;
        }
    }
    table line_items {
        sequence line_items_seq;
        foreign_display `%name`;
        field id {
            is int4, primary_key, assign_by_sequence;
        }
        field due_date {
            is date;
            label `Due Date`;
            date_select_text Select;
            html_form_type text;
        }
        field name {
            is varchar;
            label Name;
            html_form_type text;
        }
        field company_id {
            is int4;
            label `My Company`;
            refers_to my_companies;
            html_form_type select;
        }
        field customer_id {
            is int4;
            label Customer;
            refers_to customers;
            html_form_type select;
        }
        field invoice_id {
            is int4;
            label `Invoice Number`;
            refers_to invoices;
            html_form_type select;
        }
        field hours {
            is int4;
            label Hours;
            html_form_type text;
        }
        field charge_per_hour {
            is int4;
            label Rate;
            html_form_type text;
        }
        field notes {
            is text;
            label `Notes to Customer`;
            html_form_type textarea;
            html_form_optional 1;
            html_form_rows 4;
            html_form_cols 50;
        }
        field descr {
            is text;
            label `Notes to Self`;
            html_form_type textarea;
            html_form_optional 1;
            html_form_rows 4;
            html_form_cols 50;
        }
    }
    table invoices {
        sequence invoices_seq;
        foreign_display `%number`;
        field id {
            is int4, primary_key, assign_by_sequence;
        }
        field number {
            is int4;
            label Number;
            html_form_type text;
        }
        field status_id {
            is int4;
            label Status;
            refers_to status;
            html_form_type select;
        }
        field sent {
            is date;
            label `Sent On`;
            date_select_text `Popup Calendar`;
            html_form_type text;
            html_form_optional 1;
        }
        field paid {
            is date;
            label `Paid On`;
            date_select_text `Popup Calendar`;
            html_form_type text;
            html_form_optional 1;
        }
        field company_id {
            is int4;
            label `My Company`;
            refers_to my_companies;
            html_form_type select;
        }
        field customer_id {
            is int4;
            label Customer;
            refers_to customers;
            html_form_type select;
        }
        field notes {
            is text;
            label `Notes to Customer`;
            html_form_type textarea;
            html_form_optional 1;
            html_form_rows 4;
            html_form_cols 50;
        }
        field descr {
            is text;
            label `Notes to Self`;
            html_form_type textarea;
            html_form_optional 1;
            html_form_rows 4;
            html_form_cols 50;
        }
    }
    table status {
        sequence status_seq;
        foreign_display `%name: %descr`;
        field id {
            is int4, primary_key, assign_by_sequence;
        }
        field name {
            is varchar;
            label Name;
            html_form_type text;
        }
        field descr {
            is varchar;
            label Description;
            html_form_type text;
        }
        data name => Working, descr => `Work in Progress, NOT Billed`;
        data name => Sent, descr => `Mailed to Customer`;
        data name => Paid, descr => `Payment Received`;
    }
    controller Status {
        controls_table status;
        rel_location status;
        uses `Gantry::Plugins::AutoCRUD`;
        text_description status;
        page_link_label Status;
        method do_main is main_listing {
            title Status;
            cols name;
            header_options Add;
            row_options Edit, Delete;
        }
        method form is AutoCRUD_form {
            form_name status;
            fields name, descr;
            extra_keys legend => `$self->path_info =~ /edit/i ? 'Edit' : 'Add'`;
        }
    }
    controller Company {
        controls_table my_companies;
        rel_location company;
        uses `Gantry::Plugins::AutoCRUD`;
        text_description company;
        page_link_label Companies;
        method do_main is main_listing {
            title `My Companies`;
            cols name, contact_phone;
            header_options Add;
            row_options Edit, Delete;
        }
        method form is AutoCRUD_form {
            form_name company;
            all_fields_but id;
            extra_keys legend => `$self->path_info =~ /edit/i ? 'Edit' : 'Add'`;
        }
    }
    controller Customer {
        controls_table customers;
        rel_location customer;
        uses `Gantry::Plugins::AutoCRUD`;
        text_description customer;
        page_link_label Customers;
        method do_main is main_listing {
            title Customers;
            cols name, contact_name, contact_phone;
            header_options Add;
            row_options Edit, Delete;
        }
        method form is AutoCRUD_form {
            form_name customer;
            all_fields_but id;
            extra_keys legend => `$self->path_info =~ /edit/i ? 'Edit' : 'Add'`;
        }
    }
    controller LineItem {
        controls_table line_items;
        rel_location lineitem;
        uses `Gantry::Plugins::AutoCRUD`, `Gantry::Plugins::Calendar`;
        text_description `line item`;
        page_link_label `Line Items`;
        method do_main is main_listing {
            title `Line Items`;
            cols name, due_date, customer_id;
            header_options Add;
            row_options Edit, Delete;
        }
        method form is AutoCRUD_form {
            form_name line_item;
            all_fields_but id;
            extra_keys legend => `$self->path_info =~ /edit/i ? 'Edit' : 'Add'`, javascript => `$self->calendar_month_js( 'line_item' )`;
        }
    }
    controller Invoice {
        controls_table invoices;
        rel_location invoice;
        uses `Gantry::Plugins::AutoCRUD`, `Gantry::Plugins::Calendar`;
        text_description invoice;
        page_link_label Invoices;
        method do_tasks is stub {
            extra_args `$id`;
        }
        method do_pdf is stub {
            extra_args `$id`;
        }
        method do_main is main_listing {
            title Invoices;
            cols number, status_id;
            header_options Add;
            row_options Tasks, PDF, Edit, Delete;
        }
        method form is AutoCRUD_form {
            form_name invoice;
            all_fields_but id;
            extra_keys legend => `$self->path_info =~ /edit/i ? 'Edit' : 'Add'`, javascript => `$self->calendar_month_js( 'invoice' )`;
        }
    }
}
