brisk-bills 0.7.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +55 -0
- data/TODO.txt +36 -67
- data/app/controllers/admin/activities_controller.rb +4 -3
- data/app/controllers/admin/activities_with_prices_controller.rb +28 -14
- data/app/controllers/admin/client_accounting_controller.rb +11 -8
- data/app/controllers/admin/client_representatives_controller.rb +34 -5
- data/app/controllers/admin/clients_controller.rb +1 -1
- data/app/controllers/admin/draft_invoices_controller.rb +92 -0
- data/app/controllers/admin/{employee_client_labor_rate_controller.rb → employee_client_labor_rates_controller.rb} +1 -1
- data/app/controllers/admin/employees_controller.rb +3 -4
- data/app/controllers/admin/invoices_controller.rb +111 -53
- data/app/controllers/admin/payments_controller.rb +168 -41
- data/app/controllers/authentication_controller.rb +3 -3
- data/app/helpers/admin/activities_helper.rb +16 -13
- data/app/helpers/admin/activities_helper/labor_helper.rb +4 -4
- data/app/helpers/admin/activities_helper/proposal_helper.rb +1 -1
- data/app/helpers/admin/activities_helper/slimtimer_helper.rb +1 -1
- data/app/helpers/admin/activities_with_prices_helper.rb +2 -2
- data/app/helpers/admin/activity_type_controller_helper.rb +6 -0
- data/app/helpers/admin/activity_type_field_helper.rb +9 -9
- data/app/helpers/admin/adjustments_helper.rb +9 -1
- data/app/helpers/admin/client_accounting_helper.rb +2 -2
- data/app/helpers/admin/client_financial_transactions_helper.rb +1 -1
- data/app/helpers/admin/client_representatives_helper.rb +16 -12
- data/app/helpers/admin/clients_helper.rb +2 -0
- data/app/helpers/admin/draft_invoices_helper.rb +24 -0
- data/app/helpers/admin/{employee_client_labor_rate_helper.rb → employee_client_labor_rates_helper.rb} +8 -8
- data/app/helpers/admin/employees_helper.rb +6 -0
- data/app/helpers/admin/has_credential_column_helper.rb +8 -8
- data/app/helpers/admin/invoices_helper.rb +71 -16
- data/app/helpers/admin/is_active_column_helper.rb +2 -2
- data/app/helpers/admin/labors_helper.rb +12 -1
- data/app/helpers/admin/labors_helper/slimtimer_helper.rb +1 -1
- data/app/helpers/admin/materials_helper.rb +11 -0
- data/app/helpers/admin/payments_helper.rb +204 -29
- data/app/helpers/admin/proposals_helper.rb +10 -0
- data/app/helpers/admin/settings_helper.rb +1 -1
- data/app/helpers/admin_layout_helper.rb +3 -6
- data/app/helpers/authentication_helper.rb +7 -10
- data/app/helpers/money_model_helper.rb +1 -2
- data/app/models/activity.rb +17 -7
- data/app/models/client.rb +35 -8
- data/app/{model_views → models}/client_financial_transaction.rb +0 -0
- data/app/models/client_representative.rb +6 -14
- data/app/models/credential.rb +1 -1
- data/app/models/employee.rb +9 -11
- data/app/models/invoice.rb +13 -9
- data/app/models/invoice_payment.rb +1 -1
- data/app/models/notifier.rb +2 -2
- data/app/models/payment.rb +51 -7
- data/app/models/setting.rb +3 -1
- data/app/views/active_scaffold_overrides/add_existing.js.rjs +25 -0
- data/app/views/admin/activities/_adjustment_column.html.erb +10 -0
- data/app/views/admin/activities/{_form.rhtml → _form.html.erb} +0 -0
- data/app/views/admin/activities/{_form_attribute.rhtml → _form_attribute.html.erb} +0 -0
- data/app/views/admin/activities/{_labor_column.rhtml → _labor_column.html.erb} +0 -0
- data/app/views/admin/activities/{_material_column.rhtml → _material_column.html.erb} +0 -0
- data/app/views/admin/activities/{_proposal_column.rhtml → _proposal_column.html.erb} +0 -0
- data/app/views/admin/activities_with_prices/{move_to_invoice.rhtml → move_to_invoice.html.erb} +2 -2
- data/app/views/admin/activities_with_prices/move_to_invoice.js.rjs +5 -0
- data/app/views/admin/draft_invoices/batch_create.html.erb +73 -0
- data/app/views/admin/draft_invoices/batch_create.js.rjs +5 -0
- data/app/views/admin/invoices/confirm_publish_modal.html.erb +48 -0
- data/app/views/admin/payments/commit_payment_warning.html.erb +8 -0
- data/app/views/admin/payments/observation_error.js.rjs +28 -0
- data/app/views/admin/payments/on_assignment_observation.js.rjs +28 -0
- data/app/views/authentication/{email.rjs → email.js.rjs} +0 -0
- data/app/views/authentication/{login.rhtml → login.html.erb} +21 -26
- data/app/views/authentication/{login.rjs → login.js.rjs} +0 -0
- data/app/views/authentication/{reset_password_via_token.rhtml → reset_password_via_token.html.erb} +0 -0
- data/app/views/authentication/{reset_password_via_token.rjs → reset_password_via_token.js.rjs} +0 -0
- data/app/views/authentication/{sign_in_error.rjs → sign_in_error.js.rjs} +0 -0
- data/app/views/layouts/{_navigation_tree.rhtml → _navigation_tree.html.erb} +0 -0
- data/app/views/layouts/{admin.rhtml → admin.html.erb} +0 -0
- data/app/views/layouts/{public.rhtml → public.html.erb} +0 -0
- data/app/views/notifier/{_email_footer.html.rhtml → _email_footer.html.erb} +0 -0
- data/app/views/notifier/{_email_footer.plain.rhtml → _email_footer.plain.erb} +0 -0
- data/app/views/notifier/{_email_header.html.rhtml → _email_header.html.erb} +0 -0
- data/app/views/notifier/invoice_available.html.erb +5 -0
- data/app/views/notifier/{invoice_available.plain.rhtml → invoice_available.plain.erb} +1 -1
- data/app/views/notifier/{reset_password_requested.html.rhtml → reset_password_requested.html.erb} +2 -2
- data/app/views/notifier/{reset_password_requested.plain.rhtml → reset_password_requested.plain.erb} +1 -1
- data/config/environment.rb +6 -5
- data/config/locale/en.rb +9 -0
- data/db/migrate/001_create_employees.rb +1 -1
- data/db/migrate/002_create_employee_slimtimers.rb +1 -1
- data/db/migrate/003_create_slimtimer_tasks.rb +1 -1
- data/db/migrate/004_create_slimtimer_time_entries.rb +1 -1
- data/db/migrate/005_create_clients.rb +1 -1
- data/db/migrate/006_create_client_representatives.rb +1 -1
- data/db/migrate/008_create_activities.rb +1 -1
- data/db/migrate/009_create_activity_labors.rb +1 -1
- data/db/migrate/010_create_employee_client_labor_rates.rb +1 -1
- data/db/migrate/011_create_activity_adjustments.rb +1 -1
- data/db/migrate/012_create_activity_materials.rb +1 -1
- data/db/migrate/013_create_activity_proposals.rb +1 -1
- data/db/migrate/014_create_invoices.rb +1 -1
- data/db/migrate/015_create_payments.rb +1 -1
- data/db/migrate/016_create_payment_methods.rb +1 -1
- data/db/migrate/017_create_invoice_payments.rb +1 -1
- data/db/migrate/018_create_activity_types.rb +2 -2
- data/db/migrate/019_create_settings.rb +1 -1
- data/db/migrate/023_create_credentials_migrate_representatives.rb +2 -2
- data/db/migrate/028_money_to_cents.rb +2 -2
- data/db/schema.rb +10 -10
- data/lib/brisk-bills.rb +2 -2
- data/lib/brisk-bills/initializer.rb +2 -2
- data/lib/generators/instance/templates/instance_environment.rb +1 -1
- data/lib/libpptable.rb +48 -0
- data/lib/tasks/create_last_months_invoices.rake +1 -14
- data/lib/tasks/first_time_setup.rake +2 -2
- data/lib/tasks/package.rake +2 -1
- data/lib/tasks/payment_assignment_consistency_check.rake +110 -0
- data/lib/utilities.rb +4 -4
- data/public/images/page-new.gif +0 -0
- data/public/javascripts/active_scaffold/default/active_scaffold.js +532 -430
- data/public/javascripts/active_scaffold/default/dhtml_history.js +1 -1
- data/public/javascripts/active_scaffold/default/form_enhancements.js +7 -4
- data/public/stylesheets/active_scaffold/default/stylesheet-ie.css +5 -5
- data/public/stylesheets/active_scaffold/default/stylesheet.css +54 -18
- data/public/stylesheets/admin/global.css +1 -1
- data/public/stylesheets/admin/pages.css +29 -0
- data/test/unit/activity/adjustment_test.rb +1 -1
- data/test/unit/activity/labor_test.rb +1 -1
- data/test/unit/activity/material_test.rb +1 -1
- data/test/unit/activity/proposal_test.rb +1 -1
- data/test/unit/activity_test.rb +1 -1
- data/test/unit/activity_type_test.rb +1 -1
- data/test/unit/client_eventlog_test.rb +1 -1
- data/test/unit/client_financial_transaction_test.rb +1 -1
- data/test/unit/client_representative_test.rb +1 -1
- data/test/unit/client_test.rb +37 -6
- data/test/unit/credential_test.rb +1 -1
- data/test/unit/employee/slimtimer_test.rb +1 -1
- data/test/unit/employee_client_labor_rate_test.rb +1 -1
- data/test/unit/employee_test.rb +1 -1
- data/test/unit/helpers/admin/draft_invoices_helper_test.rb +4 -0
- data/test/unit/invoice_payment_test.rb +90 -50
- data/test/unit/invoice_test.rb +48 -8
- data/test/unit/notifier_test.rb +1 -1
- data/test/unit/payment_method_test.rb +1 -1
- data/test/unit/payment_test.rb +7 -7
- data/test/unit/setting_test.rb +1 -1
- data/test/unit/slimtimer_task_test.rb +1 -1
- data/test/unit/slimtimer_time_entry_test.rb +1 -1
- data/vendor/plugins/active_scaffold/CHANGELOG +3 -1
- data/vendor/plugins/active_scaffold/README +18 -5
- data/vendor/plugins/active_scaffold/environment.rb +1 -1
- data/vendor/plugins/active_scaffold/frontends/default/javascripts/active_scaffold.js +532 -430
- data/vendor/plugins/active_scaffold/frontends/default/javascripts/dhtml_history.js +1 -1
- data/vendor/plugins/active_scaffold/frontends/default/javascripts/form_enhancements.js +7 -4
- data/vendor/plugins/active_scaffold/frontends/default/stylesheets/stylesheet-ie.css +5 -5
- data/vendor/plugins/active_scaffold/frontends/default/stylesheets/stylesheet.css +54 -18
- data/vendor/plugins/active_scaffold/frontends/default/views/_add_existing_form.html.erb +3 -7
- data/vendor/plugins/active_scaffold/frontends/default/views/_create_form.html.erb +10 -7
- data/vendor/plugins/active_scaffold/frontends/default/views/_field_search.html.erb +7 -12
- data/vendor/plugins/active_scaffold/frontends/default/views/_form.html.erb +3 -3
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_association.html.erb +15 -20
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_association_footer.html.erb +8 -10
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_attribute.html.erb +5 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_hidden_attribute.html.erb +2 -1
- data/vendor/plugins/active_scaffold/frontends/default/views/_horizontal_subform.html.erb +19 -21
- data/vendor/plugins/active_scaffold/frontends/default/views/{_form_association_header.html.erb → _horizontal_subform_header.html.erb} +2 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/_horizontal_subform_record.html.erb +31 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_list.html.erb +4 -18
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_actions.html.erb +18 -5
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_calculations.html.erb +2 -9
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_column_headings.html.erb +4 -4
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_header.html.erb +6 -6
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_inline_adapter.html.erb +2 -1
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_messages.html.erb +20 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_pagination.html.erb +11 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_pagination_links.html.erb +3 -5
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_record.html.erb +2 -26
- data/vendor/plugins/active_scaffold/frontends/default/views/_list_record_columns.html.erb +9 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_nested.html.erb +3 -12
- data/vendor/plugins/active_scaffold/frontends/default/views/_render_fields.js.rjs +11 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_search.html.erb +17 -11
- data/vendor/plugins/active_scaffold/frontends/default/views/_show.html.erb +3 -3
- data/vendor/plugins/active_scaffold/frontends/default/views/_show_columns.html.erb +8 -7
- data/vendor/plugins/active_scaffold/frontends/default/views/_update_actions.html.erb +3 -3
- data/vendor/plugins/active_scaffold/frontends/default/views/_update_form.html.erb +9 -6
- data/vendor/plugins/active_scaffold/frontends/default/views/_vertical_subform.html.erb +7 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/_vertical_subform_record.html.erb +38 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/add_existing.js.rjs +2 -1
- data/vendor/plugins/active_scaffold/frontends/default/views/delete.html.erb +1 -1
- data/vendor/plugins/active_scaffold/frontends/default/views/destroy.js.rjs +2 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/edit_associated.js.rjs +20 -15
- data/vendor/plugins/active_scaffold/frontends/default/views/list.html.erb +12 -8
- data/vendor/plugins/active_scaffold/frontends/default/views/list.js.rjs +1 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/mark.js.rjs +6 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/on_create.js.rjs +12 -8
- data/vendor/plugins/active_scaffold/frontends/default/views/on_update.js.rjs +13 -6
- data/vendor/plugins/active_scaffold/frontends/default/views/render_field.js.rjs +1 -0
- data/vendor/plugins/active_scaffold/frontends/default/views/search.html.erb +2 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/update.html.erb +2 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/update_column.js.rjs +4 -3
- data/vendor/plugins/active_scaffold/frontends/default/views/update_row.js.rjs +2 -0
- data/vendor/plugins/active_scaffold/init.rb +2 -2
- data/vendor/plugins/active_scaffold/install.rb +1 -2
- data/vendor/plugins/active_scaffold/install_assets.rb +1 -1
- data/vendor/plugins/active_scaffold/lib/active_record_permissions.rb +53 -42
- data/vendor/plugins/active_scaffold/lib/active_scaffold.rb +96 -23
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/common_search.rb +18 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/core.rb +152 -102
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/create.rb +81 -49
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/delete.rb +44 -17
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/field_search.rb +60 -46
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/list.rb +42 -37
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/mark.rb +72 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/nested.rb +94 -92
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/search.rb +54 -40
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/show.rb +30 -10
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/update.rb +62 -47
- data/vendor/plugins/active_scaffold/lib/active_scaffold/attribute_params.rb +187 -185
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/base.rb +28 -3
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb +43 -3
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/create.rb +8 -15
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/delete.rb +3 -4
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/field_search.rb +19 -17
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/form.rb +2 -9
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/list.rb +46 -9
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/nested.rb +17 -7
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/search.rb +36 -16
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/show.rb +5 -12
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/subform.rb +8 -6
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/update.rb +12 -8
- data/vendor/plugins/active_scaffold/lib/active_scaffold/configurable.rb +2 -2
- data/vendor/plugins/active_scaffold/lib/active_scaffold/constraints.rb +173 -178
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_columns.rb +101 -97
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_link.rb +29 -19
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/column.rb +74 -34
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/columns.rb +74 -74
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/set.rb +57 -62
- data/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/sorting.rb +73 -3
- data/vendor/plugins/active_scaffold/lib/active_scaffold/finder.rb +304 -234
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/association_helpers.rb +40 -40
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/controller_helpers.rb +39 -24
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/country_helpers.rb +32 -28
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/form_column_helpers.rb +157 -86
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/id_helpers.rb +7 -7
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/list_column_helpers.rb +278 -85
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/pagination_helpers.rb +38 -12
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb +74 -35
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/show_column_helpers.rb +53 -46
- data/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/view_helpers.rb +51 -17
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/de.yml +69 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/en.yml +72 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/es.yml +23 -13
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/fr.yml +68 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/hu.yml +24 -14
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/ja.yml +69 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/ru.yml +72 -0
- data/vendor/plugins/active_scaffold/lib/active_scaffold/marked_model.rb +38 -0
- data/vendor/plugins/active_scaffold/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb +47 -13
- data/vendor/plugins/active_scaffold/lib/bridges/dependent_protect/bridge.rb +10 -0
- data/vendor/plugins/active_scaffold/lib/bridges/dependent_protect/lib/dependent_protect_bridge.rb +11 -0
- data/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/as_file_column_bridge.rb +3 -6
- data/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/form_ui.rb +10 -2
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/bridge.rb +13 -0
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/lib/form_ui.rb +20 -0
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/lib/list_ui.rb +16 -0
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/lib/paperclip_bridge.rb +32 -0
- data/vendor/plugins/active_scaffold/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb +18 -0
- data/vendor/plugins/active_scaffold/lib/bridges/record_select/bridge.rb +5 -0
- data/vendor/plugins/active_scaffold/lib/bridges/record_select/lib/record_select_bridge.rb +79 -0
- data/vendor/plugins/active_scaffold/lib/bridges/semantic_attributes/bridge.rb +5 -0
- data/vendor/plugins/active_scaffold/lib/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +20 -0
- data/vendor/plugins/active_scaffold/lib/bridges/tiny_mce/bridge.rb +5 -0
- data/vendor/plugins/active_scaffold/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb +57 -0
- data/vendor/plugins/active_scaffold/lib/bridges/unobtrusive_date_picker/bridge.rb +9 -0
- data/vendor/plugins/active_scaffold/lib/bridges/unobtrusive_date_picker/lib/form_ui.rb +14 -0
- data/vendor/plugins/active_scaffold/lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb +15 -0
- data/vendor/plugins/active_scaffold/lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb +16 -0
- data/vendor/plugins/active_scaffold/lib/bridges/validation_reflection/bridge.rb +9 -0
- data/vendor/plugins/active_scaffold/lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb +19 -0
- data/vendor/plugins/active_scaffold/lib/extensions/action_view_rendering.rb +20 -8
- data/vendor/plugins/active_scaffold/lib/extensions/generic_view_paths.rb +2 -2
- data/vendor/plugins/active_scaffold/lib/extensions/paginator_extensions.rb +26 -0
- data/vendor/plugins/active_scaffold/lib/extensions/resources.rb +6 -5
- data/vendor/plugins/active_scaffold/lib/extensions/reverse_associations.rb +26 -20
- data/vendor/plugins/active_scaffold/lib/extensions/unsaved_associated.rb +1 -1
- data/vendor/plugins/active_scaffold/lib/paginator.rb +1 -1
- data/vendor/plugins/active_scaffold/lib/responds_to_parent.rb +1 -1
- data/vendor/plugins/active_scaffold/shoulda_macros/macros.rb +136 -0
- data/vendor/plugins/active_scaffold/test/bridges/active_scaffold_dependent_protect_test.rb +34 -0
- data/vendor/plugins/active_scaffold/test/bridges/bridge_test.rb +43 -0
- data/vendor/plugins/active_scaffold/test/bridges/company.rb +81 -0
- data/vendor/plugins/active_scaffold/test/bridges/paperclip_test.rb +68 -0
- data/vendor/plugins/active_scaffold/test/bridges/tiny_mce_test.rb +27 -0
- data/vendor/plugins/active_scaffold/test/bridges/unobtrusive_date_picker_test.rb +49 -0
- data/vendor/plugins/active_scaffold/test/bridges/validation_reflection_test.rb +57 -0
- data/vendor/plugins/active_scaffold/test/config/base_test.rb +15 -0
- data/vendor/plugins/active_scaffold/test/config/core_test.rb +58 -0
- data/vendor/plugins/active_scaffold/test/config/create_test.rb +9 -6
- data/vendor/plugins/active_scaffold/test/config/delete_test.rb +33 -0
- data/vendor/plugins/active_scaffold/test/config/field_search_test.rb +47 -0
- data/vendor/plugins/active_scaffold/test/config/list_test.rb +66 -11
- data/vendor/plugins/active_scaffold/test/config/nested_test.rb +62 -0
- data/vendor/plugins/active_scaffold/test/config/search_test.rb +60 -0
- data/vendor/plugins/active_scaffold/test/config/show_test.rb +43 -0
- data/vendor/plugins/active_scaffold/test/config/subform_test.rb +17 -0
- data/vendor/plugins/active_scaffold/test/config/update_test.rb +27 -4
- data/vendor/plugins/active_scaffold/test/data_structures/action_columns_test.rb +2 -8
- data/vendor/plugins/active_scaffold/test/data_structures/action_link_test.rb +11 -11
- data/vendor/plugins/active_scaffold/test/data_structures/action_links_test.rb +5 -5
- data/vendor/plugins/active_scaffold/test/data_structures/association_column_test.rb +4 -3
- data/vendor/plugins/active_scaffold/test/data_structures/column_test.rb +29 -5
- data/vendor/plugins/active_scaffold/test/data_structures/sorting_test.rb +31 -1
- data/vendor/plugins/active_scaffold/test/data_structures/standard_column_test.rb +3 -13
- data/vendor/plugins/active_scaffold/test/data_structures/virtual_column_test.rb +0 -11
- data/vendor/plugins/active_scaffold/test/extensions/{array.rb → array_test.rb} +0 -0
- data/vendor/plugins/active_scaffold/test/helpers/form_column_helpers_test.rb +31 -0
- data/vendor/plugins/active_scaffold/test/helpers/list_column_helpers_test.rb +42 -0
- data/vendor/plugins/active_scaffold/test/helpers/pagination_helpers_test.rb +59 -0
- data/vendor/plugins/active_scaffold/test/misc/active_record_permissions_test.rb +154 -0
- data/vendor/plugins/active_scaffold/test/misc/attribute_params_test.rb +146 -0
- data/vendor/plugins/active_scaffold/test/misc/configurable_test.rb +2 -2
- data/vendor/plugins/active_scaffold/test/misc/constraints_test.rb +26 -8
- data/vendor/plugins/active_scaffold/test/misc/finder_test.rb +41 -19
- data/vendor/plugins/active_scaffold/test/misc/lang_test.rb +5 -6
- data/vendor/plugins/active_scaffold/test/mock_app/app/controllers/application_controller.rb +10 -0
- data/vendor/plugins/active_scaffold/test/mock_app/app/helpers/application_helper.rb +3 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/boot.rb +110 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/environment.rb +43 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/environments/development.rb +17 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/environments/production.rb +28 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/environments/test.rb +28 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/inflections.rb +10 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/mime_types.rb +5 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/initializers/session_store.rb +15 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/locales/en.yml +5 -0
- data/vendor/plugins/active_scaffold/test/mock_app/config/routes.rb +43 -0
- data/vendor/plugins/active_scaffold/test/mock_app/db/test.sqlite3 +1 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/blank.html +33 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +2 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +2 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +532 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +867 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +117 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +370 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +2 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +35 -0
- data/vendor/plugins/active_scaffold/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +845 -0
- data/vendor/plugins/active_scaffold/test/model_stub.rb +17 -1
- data/vendor/plugins/active_scaffold/test/test_helper.rb +31 -5
- data/vendor/plugins/active_scaffold/uninstall.rb +2 -1
- data/vendor/plugins/active_scaffold_form_observation/init.rb +1 -1
- data/vendor/plugins/active_scaffold_form_observation/lib/active_scaffold_form_observation.rb +1 -2
- data/vendor/plugins/active_scaffold_full_refresh/init.rb +2 -0
- data/vendor/plugins/active_scaffold_full_refresh/lib/active_scaffold_full_refresh.rb +29 -0
- data/vendor/plugins/acts_as_money/{tasks → lib/tasks}/money_tasks.rake +0 -0
- metadata +668 -563
- data/app/model_views/client_accounting.rb +0 -5
- data/app/model_views/invoices_with_total.rb +0 -41
- data/app/views/admin/activities/_adjustment_column.rhtml +0 -23
- data/app/views/admin/activities_with_prices/move_to_invoice.rjs +0 -9
- data/app/views/notifier/invoice_available.html.rhtml +0 -5
- data/public/javascripts/prototype.js-1.6.0.3 +0 -4320
- data/test/functional/admin/activities_controller_test.rb +0 -8
- data/test/functional/admin/adjustments_controller_test.rb +0 -8
- data/test/functional/admin/client_accounting_controller_test.rb +0 -8
- data/test/functional/admin/client_financial_transactions_controller_test.rb +0 -8
- data/test/functional/admin/client_representatives_controller_test.rb +0 -8
- data/test/functional/admin/clients_controller_test.rb +0 -8
- data/test/functional/admin/employee_client_labor_rate_controller_test.rb +0 -8
- data/test/functional/admin/employees/slimtimer_controller_test.rb +0 -8
- data/test/functional/admin/employees_controller_test.rb +0 -8
- data/test/functional/admin/invoices_controller_test.rb +0 -8
- data/test/functional/admin/labors_controller_test.rb +0 -8
- data/test/functional/admin/materials_controller_test.rb +0 -8
- data/test/functional/admin/payments_controller_test.rb +0 -8
- data/test/functional/admin/proposals_controller_test.rb +0 -8
- data/test/functional/admin/settings_controller_test.rb +0 -8
- data/test/functional/authentication_controller_test.rb +0 -8
- data/vendor/plugins/active_scaffold/frontends/default/views/_form_association_record.html.erb +0 -27
- data/vendor/plugins/active_scaffold/frontends/default/views/_live_search.html.erb +0 -25
- data/vendor/plugins/active_scaffold/frontends/default/views/form_messages_on_create.js.rjs +0 -2
- data/vendor/plugins/active_scaffold/frontends/default/views/form_messages_on_update.js.rjs +0 -2
- data/vendor/plugins/active_scaffold/lib/active_scaffold/actions/live_search.rb +0 -46
- data/vendor/plugins/active_scaffold/lib/active_scaffold/config/live_search.rb +0 -52
- data/vendor/plugins/active_scaffold/lib/active_scaffold/locale/en.rb +0 -66
- data/vendor/plugins/active_scaffold/lib/extensions/name_option_for_datetime.rb +0 -12
- data/vendor/plugins/active_scaffold/test/misc/active_record_permissions.rb +0 -154
@@ -0,0 +1,92 @@
|
|
1
|
+
class Admin::DraftInvoicesController < Admin::InvoicesController
|
2
|
+
include Admin::DraftInvoicesHelper
|
3
|
+
|
4
|
+
@invoices_scaffold_config = superclass.instance_variable_get('@invoices_scaffold_config').dup
|
5
|
+
|
6
|
+
invoices_scaffold_config do |config|
|
7
|
+
config.label = "Draft Invoices"
|
8
|
+
|
9
|
+
config.list.columns.instance_eval do
|
10
|
+
@set.delete(:is_published)
|
11
|
+
@set.delete(:is_paid?)
|
12
|
+
end
|
13
|
+
|
14
|
+
config.action_links.add :batch_create, :label => 'Batch Create'
|
15
|
+
end
|
16
|
+
|
17
|
+
def conditions_for_collection
|
18
|
+
['is_published = ?', false]
|
19
|
+
end
|
20
|
+
|
21
|
+
# TODO: Put in a plugin-helper
|
22
|
+
# We need to be sure the view is looking in the right place, this little hack should do it:
|
23
|
+
def self.active_scaffold_paths
|
24
|
+
ret = super
|
25
|
+
ret << BRISKBILLS_ROOT+'/app/views/admin/invoices'
|
26
|
+
ret
|
27
|
+
end
|
28
|
+
# /TODO: Put in a plugin-helper
|
29
|
+
|
30
|
+
def batch_create_on_date_change
|
31
|
+
# This is kind of an annoying way to make a date ...
|
32
|
+
@invoice_date_at = utc_date_from_param(
|
33
|
+
params[:batch_invoice_date_at]
|
34
|
+
) if params[:batch_invoice_date_at]
|
35
|
+
logger.error "Well?" + @invoice_date_at.inspect
|
36
|
+
|
37
|
+
# I didn't really feel the need to create a partial just for this one line:
|
38
|
+
render :inline => '<%= batch_create_clients_form_column(@invoice_date_at) %>' if @invoice_date_at
|
39
|
+
end
|
40
|
+
|
41
|
+
def batch_create
|
42
|
+
if params.has_key? :batch_client
|
43
|
+
invoiceable_client_ids = params[:batch_client].keys.collect(&:to_i)
|
44
|
+
|
45
|
+
if invoiceable_client_ids.length > 0
|
46
|
+
all_activity_types = ActivityType.find(:all)
|
47
|
+
|
48
|
+
invoice_date = utc_date_from_param params[:batch_invoice_date_at]
|
49
|
+
|
50
|
+
@new_invoices = Client.find(
|
51
|
+
:all,
|
52
|
+
:conditions => ['id IN (?)', invoiceable_client_ids]
|
53
|
+
).each do |client|
|
54
|
+
Invoice.create!(
|
55
|
+
:client => client,
|
56
|
+
:activity_types => all_activity_types,
|
57
|
+
:issued_on => invoice_date,
|
58
|
+
:activities => Invoice.recommended_activities_for(
|
59
|
+
client.id,
|
60
|
+
invoice_date,
|
61
|
+
all_activity_types
|
62
|
+
)
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
do_list
|
67
|
+
end
|
68
|
+
|
69
|
+
render :action => 'batch_create.js'
|
70
|
+
else
|
71
|
+
@invoice_date_at = Time.utc(*Time.now.to_a).prev_month.end_of_month
|
72
|
+
render :action => 'batch_create.html', :layout => false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def utc_date_from_param(date_hash)
|
79
|
+
Time.utc(
|
80
|
+
date_hash[:year].to_i,
|
81
|
+
date_hash[:month].to_i,
|
82
|
+
date_hash[:day].to_i,
|
83
|
+
date_hash[:hour].to_i,
|
84
|
+
date_hash[:minute].to_i,
|
85
|
+
date_hash[:second].to_i
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
handle_extensions
|
90
|
+
|
91
|
+
invoices_scaffold_init
|
92
|
+
end
|
@@ -16,17 +16,16 @@ class Admin::EmployeesController < ApplicationController
|
|
16
16
|
|
17
17
|
config.list.sorting = [{:last_name => :asc}, {:first_name => :asc}]
|
18
18
|
|
19
|
-
config.nested.add_link "Labor Rates",
|
19
|
+
config.nested.add_link "Labor Rates", :employee_client_labor_rates
|
20
20
|
|
21
21
|
config.create.columns = [:first_name, :last_name, :email_address, :password, :phone_extension, :login_enabled]
|
22
|
-
config.update.columns = [:first_name, :last_name, :email_address, :password, :phone_extension, :is_active, :login_enabled]
|
23
|
-
|
22
|
+
config.update.columns = [:first_name, :last_name, :email_address, :password, :phone_extension, :is_active, :login_enabled]
|
24
23
|
config.full_list_refresh_on = [:update, :destroy]
|
25
24
|
end
|
26
25
|
|
27
26
|
def conditions_for_collection
|
28
27
|
['is_active = ?', true]
|
29
28
|
end
|
30
|
-
|
29
|
+
|
31
30
|
handle_extensions
|
32
31
|
end
|
@@ -5,8 +5,23 @@ class Admin::InvoicesController < ApplicationController
|
|
5
5
|
include ::InvoicePdfHelper
|
6
6
|
|
7
7
|
add_layout_conditions :except => 'download'
|
8
|
+
|
9
|
+
# TODO: Put in a plugin-helper
|
10
|
+
def self.invoices_scaffold_config(&block)
|
11
|
+
@invoices_scaffold_config ||= []
|
12
|
+
@invoices_scaffold_config << block.to_proc
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.invoices_scaffold_init
|
16
|
+
# I dont love this mechanism of scaffold_init - but I think its going to work quite well...
|
17
|
+
configs = @invoices_scaffold_config
|
18
|
+
|
19
|
+
active_scaffold(:invoice){|c| configs.each{|ac| ac.call c if ac.respond_to? :call} }
|
20
|
+
end
|
21
|
+
# /TODO: Put in a plugin-helper
|
22
|
+
|
8
23
|
|
9
|
-
|
24
|
+
invoices_scaffold_config do |config|
|
10
25
|
config.label = "Invoices"
|
11
26
|
|
12
27
|
config.show.columns = config.columns = [
|
@@ -25,10 +40,12 @@ class Admin::InvoicesController < ApplicationController
|
|
25
40
|
:created_at,
|
26
41
|
:updated_at
|
27
42
|
]
|
43
|
+
|
44
|
+
config.columns[:is_paid?].sort_by :sql => '`invoices`.is_paid'
|
28
45
|
|
29
|
-
config.columns[:
|
30
|
-
|
46
|
+
config.columns[:id].includes = [:payment_assignments]
|
31
47
|
config.columns[:id].label = 'Num'
|
48
|
+
|
32
49
|
config.columns[:is_published].label = 'Pub?'
|
33
50
|
config.columns[:is_paid?].label = 'Paid?'
|
34
51
|
config.columns[:activity_types].label = 'Include Activities'
|
@@ -45,27 +62,41 @@ class Admin::InvoicesController < ApplicationController
|
|
45
62
|
config.list.columns =[:id, :issued_on, :client, :amount, :is_published, :is_paid?]
|
46
63
|
config.list.sorting = [{:issued_on => :desc}]
|
47
64
|
|
48
|
-
config.create.columns = config.update.columns = [
|
65
|
+
config.create.columns = config.update.columns = [
|
66
|
+
:issued_on, :client, :activity_types, :comments
|
67
|
+
]
|
68
|
+
|
69
|
+
config.create.link
|
49
70
|
|
50
|
-
config.action_links.add
|
71
|
+
config.action_links.add(
|
72
|
+
'toggle_published',
|
73
|
+
:label => 'Publish',
|
74
|
+
:type => :member,
|
75
|
+
:inline => true,
|
76
|
+
:page => false,
|
77
|
+
:position => false
|
78
|
+
)
|
79
|
+
|
80
|
+
config.action_links.add(
|
51
81
|
'download',
|
52
82
|
:label => 'Download',
|
53
|
-
:type => :
|
83
|
+
:type => :member,
|
54
84
|
:inline => false,
|
55
85
|
:page => true
|
56
86
|
)
|
57
87
|
|
58
|
-
config.nested.add_link "Activities",
|
59
|
-
|
88
|
+
config.nested.add_link "Activities", :activities
|
60
89
|
config.full_list_refresh_on = [:update, :create]
|
61
90
|
|
62
91
|
end
|
63
92
|
|
93
|
+
# override_form_field_partial in the helper gets buggered out b/c our controller name doesn't match
|
94
|
+
# the model name. This fixes that:
|
64
95
|
def self.active_scaffold_controller_for(klass)
|
65
|
-
(klass == Activity) ? Admin::ActivitiesWithPricesController :
|
96
|
+
(klass == Activity) ? Admin::ActivitiesWithPricesController : self
|
66
97
|
end
|
67
98
|
|
68
|
-
# We
|
99
|
+
# We overide the defaut behavior here only so that we can use this method as a hook to detyermine the invoice.activity_type_ids
|
69
100
|
# Before they've been updated by the form. We reference @activity_type_ids_before in before_update_save to determine whether we
|
70
101
|
# need to update the activity associations for this invoice.
|
71
102
|
def update_record_from_params(*args)
|
@@ -75,7 +106,8 @@ class Admin::InvoicesController < ApplicationController
|
|
75
106
|
|
76
107
|
def before_update_save(invoice)
|
77
108
|
super
|
78
|
-
|
109
|
+
|
110
|
+
# Here we handle activity assignments:
|
79
111
|
invoice.activities = invoice.recommended_activities if (
|
80
112
|
invoice.new_record? or (
|
81
113
|
!invoice.is_published and
|
@@ -84,61 +116,85 @@ class Admin::InvoicesController < ApplicationController
|
|
84
116
|
(invoice.issued_on_changed? || (@activity_type_ids_before != invoice.activity_type_ids))
|
85
117
|
)
|
86
118
|
)
|
87
|
-
|
88
|
-
invoice.payment_assignments.clear if !invoice.is_published and invoice.is_published_changed?
|
89
|
-
|
90
|
-
# We're going to need this in the after_update_save... Note it now.
|
91
|
-
@invoice_changes = invoice.changes.keys.collect(&:to_sym)
|
92
|
-
@invoice_new_record = invoice.new_record?
|
93
119
|
end
|
94
120
|
|
95
121
|
alias before_create_save before_update_save
|
96
122
|
|
97
|
-
def after_update_save(invoice)
|
98
|
-
super
|
99
|
-
|
100
|
-
if successful? and invoice.is_published and (@invoice_new_record || @invoice_changes.include?(:is_published))
|
101
|
-
# Unfortunately we have to assign payments using the quick_create and not by concat'ing on the
|
102
|
-
# invoice AssociationProxy. THis is due to a bug in my InvoicesWithTotal wrapper that I think is related
|
103
|
-
# to the association proxy not resettting its owenr id on an id change (as is the case of a create)
|
104
|
-
invoice.client.recommend_payment_assignments_for(invoice.amount).each do |ip|
|
105
|
-
InvoicePayment.quick_create! invoice.id, ip.payment_id, ip.amount
|
106
|
-
end
|
107
|
-
|
108
|
-
define_invoice invoice
|
109
|
-
|
110
|
-
attachments = [
|
111
|
-
{
|
112
|
-
:content_type => "application/pdf",
|
113
|
-
:body => render_to_string(:action => 'download', :layout => false),
|
114
|
-
:disposition => "attachment",
|
115
|
-
:filename => @rails_pdf_name
|
116
|
-
}
|
117
|
-
]
|
118
|
-
|
119
|
-
mail = Notifier.deliver_invoice_available @invoice, @client, @footer_text, attachments
|
120
|
-
|
121
|
-
dest_addresses = []
|
122
|
-
dest_addresses += mail.to_addrs if mail.to_addrs
|
123
|
-
dest_addresses += mail.cc_addrs if mail.cc_addrs
|
124
|
-
|
125
|
-
dest_addresses.collect!{|t_a| '%s <%s>' % [t_a.name, t_a.address] }
|
126
|
-
|
127
|
-
flash[:warning] = "Invoice e-mailed to : %s" % dest_addresses.join(',')
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
alias after_create_save after_update_save
|
132
|
-
|
133
123
|
def download
|
134
124
|
define_invoice Invoice.find(params[:id].to_i, :include => [:client])
|
135
125
|
|
136
126
|
rescue
|
137
127
|
render :file => RAILS_ROOT+'/public/500.html', :status => 500
|
138
128
|
end
|
129
|
+
|
130
|
+
def toggle_published
|
131
|
+
if params[:is_confirmed] == '1'
|
132
|
+
invoice = find_if_allowed(params[:id], :toggle_published)
|
133
|
+
|
134
|
+
invoice.is_published = !invoice.is_published
|
135
|
+
invoice.payment_assignments.clear unless invoice.is_published
|
136
|
+
invoice.save!
|
137
|
+
|
138
|
+
if invoice.is_published
|
139
|
+
# Unfortunately we have to assign payments using the quick_create and not by concat'ing on the
|
140
|
+
# invoice AssociationProxy. This is due to a bug in my InvoicesWithTotal wrapper that I think is related
|
141
|
+
# to the association proxy not resettting its owenr id on an id change (as is the case of a create)
|
142
|
+
invoice.client.recommend_payment_assignments_for(invoice.amount).each do |ip|
|
143
|
+
InvoicePayment.quick_create! invoice.id, ip.payment_id, ip.amount
|
144
|
+
end
|
145
|
+
|
146
|
+
# Send the notifier
|
147
|
+
if params[:email_invoice].to_i == 1
|
148
|
+
define_invoice invoice
|
149
|
+
|
150
|
+
attachments = [
|
151
|
+
{
|
152
|
+
:content_type => "application/pdf",
|
153
|
+
:body => render_to_string(:action => 'download', :layout => false),
|
154
|
+
:disposition => "attachment",
|
155
|
+
:filename => @rails_pdf_name
|
156
|
+
}
|
157
|
+
]
|
158
|
+
|
159
|
+
mail = Notifier.deliver_invoice_available invoice, @client, @footer_text, attachments
|
160
|
+
|
161
|
+
dest_addresses = []
|
162
|
+
dest_addresses += mail.to_addrs if mail.to_addrs
|
163
|
+
dest_addresses += mail.cc_addrs if mail.cc_addrs
|
164
|
+
|
165
|
+
dest_addresses.collect!{|t_a| '%s <%s>' % [t_a.name, t_a.address] }
|
166
|
+
|
167
|
+
flash[:warning] = "Invoice e-mailed to : %s" % dest_addresses.join(',')
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
render(:update) do |page|
|
172
|
+
# Close the "Nested" Div, if it's open:
|
173
|
+
page << 'if($(%s)){Element.remove(%s);};' % ([element_row_id(:action => :nested, :id => invoice.id).to_json]*2)
|
174
|
+
|
175
|
+
page.replace(
|
176
|
+
element_row_id(:action => :list, :id => invoice.id),
|
177
|
+
:partial => 'list_record',
|
178
|
+
:locals => {:record => invoice}
|
179
|
+
)
|
180
|
+
|
181
|
+
# Update the flash as well, if needed:
|
182
|
+
page.replace_html active_scaffold_messages_id, :partial => 'messages'
|
183
|
+
end
|
184
|
+
else
|
185
|
+
@record = Invoice.find params[:id].to_i, :include => [:payment_assignments]
|
186
|
+
|
187
|
+
render :action => :confirm_publish_modal, :layout => false
|
188
|
+
end
|
189
|
+
end
|
139
190
|
|
140
191
|
private
|
192
|
+
|
141
193
|
|
194
|
+
def custom_finder_options
|
195
|
+
{:from => 'invoices_with_totals AS invoices'}
|
196
|
+
end
|
197
|
+
|
142
198
|
BAD_INDIFFERENTIZE_VARS = /^\@(#{%w(
|
143
199
|
request_origin _request active_scaffold_observations variables_added before_filter_chain_aborted
|
144
200
|
rendering_runtime query action_name _flash performed_render url _headers _cookies db_rt_after_render
|
@@ -198,4 +254,6 @@ class Admin::InvoicesController < ApplicationController
|
|
198
254
|
end
|
199
255
|
|
200
256
|
handle_extensions
|
257
|
+
|
258
|
+
invoices_scaffold_init
|
201
259
|
end
|
@@ -3,79 +3,206 @@ class Admin::PaymentsController < ApplicationController
|
|
3
3
|
include ExtensibleObjectHelper
|
4
4
|
include ApplicationHelper # We need h_money below...
|
5
5
|
|
6
|
+
VALID_INVOICE_ASSIGNMENT_INPUT = /^invoice_assignments_([\d]+)_amount$/
|
7
|
+
VALID_MONEY_INPUT = /^(?:[ ]*([\d]+\.[\d]{0,2}|[\d]+)[ ]*|)$/
|
8
|
+
|
9
|
+
class ObservedInvalidAmount < StandardError; end
|
10
|
+
|
6
11
|
active_scaffold :payment do |config|
|
7
12
|
config.label = "Payments"
|
8
13
|
|
9
|
-
config.columns = [
|
14
|
+
config.columns = [
|
15
|
+
:id,
|
16
|
+
:paid_on,
|
17
|
+
:client,
|
18
|
+
:payment_method,
|
19
|
+
:payment_method_identifier,
|
20
|
+
:amount,
|
21
|
+
# Unfortunately, if I actually tried to make the name of this column "invoice_assignments"
|
22
|
+
# active_scaffold would try to interpret the post on its own and get in my way:
|
23
|
+
:assignments,
|
24
|
+
:amount_unallocated,
|
25
|
+
:created_at,
|
26
|
+
:updated_at,
|
27
|
+
:is_allocated?
|
28
|
+
]
|
29
|
+
|
30
|
+
config.show.columns = [
|
31
|
+
:id,
|
32
|
+
:paid_on,
|
33
|
+
:client,
|
34
|
+
:payment_method,
|
35
|
+
:payment_method_identifier,
|
36
|
+
:amount,
|
37
|
+
:invoice_assignments,
|
38
|
+
:amount_unallocated,
|
39
|
+
:is_allocated?,
|
40
|
+
:created_at,
|
41
|
+
:updated_at
|
42
|
+
]
|
43
|
+
|
44
|
+
config.columns[:id].label = 'Num'
|
10
45
|
|
11
46
|
config.columns[:client].form_ui = :select
|
12
47
|
config.columns[:client].sort_by :sql => 'clients.company_name'
|
13
48
|
|
49
|
+
config.columns[:is_allocated?].label = "Alloc?"
|
50
|
+
config.columns[:is_allocated?].includes = [:invoice_assignments]
|
51
|
+
|
52
|
+
config.columns[:payment_method_identifier].label = "Identifier"
|
53
|
+
|
54
|
+
config.columns[:payment_method].label = 'Method'
|
14
55
|
config.columns[:payment_method].form_ui = :select
|
15
56
|
config.columns[:payment_method].sort_by :sql => 'payment_methods.name'
|
16
57
|
|
17
|
-
config.columns[:payment_method_identifier].description = 'Last four card digits, check number...'
|
18
|
-
config.columns[:payment_method_identifier].label = 'Method Identifier'
|
19
|
-
|
20
58
|
config.columns[:amount_unallocated].label = 'Unallocated'
|
21
|
-
config.columns[:
|
59
|
+
config.columns[:assignments].label = 'Applies To'
|
22
60
|
|
23
61
|
config.columns[:amount].sort_by :sql => 'amount_in_cents'
|
24
62
|
|
25
|
-
config.list.columns =[:client, :payment_method, :amount
|
63
|
+
config.list.columns =[:id, :client, :payment_method,:payment_method_identifier, :amount,:is_allocated?, :paid_on]
|
26
64
|
config.list.sorting = [{:paid_on => :desc}]
|
27
65
|
|
28
66
|
config.create.columns = config.update.columns = [
|
29
67
|
:paid_on,
|
30
68
|
:client,
|
69
|
+
:amount,
|
31
70
|
:payment_method,
|
32
|
-
:payment_method_identifier,
|
33
|
-
:
|
34
|
-
|
35
|
-
# :invoice_assignments
|
71
|
+
:payment_method_identifier,
|
72
|
+
:amount_unallocated,
|
73
|
+
:assignments
|
36
74
|
]
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
# observe_active_scaffold_form_fields :fields => %w(client amount), :action => :on_invoice_assignment_observation
|
75
|
+
|
76
|
+
observe_active_scaffold_form_fields :fields => %w(client amount), :action => :on_assignment_observation
|
41
77
|
end
|
42
78
|
|
43
|
-
|
44
|
-
|
79
|
+
# In here we update all the invoice assignments
|
80
|
+
def before_update_save(payment)
|
81
|
+
# Let's create a lookup map from the input params to make this easier:
|
82
|
+
input_assignments = {}
|
83
|
+
params[:record][:invoice_assignments].try(:each_pair) do |inv_id, fields|
|
84
|
+
input_assignments[inv_id.to_i] = Money.new(fields[:amount].tr('^\-0-9','').to_i)
|
85
|
+
end
|
86
|
+
|
87
|
+
assignment_deletes = []
|
88
|
+
# First we iterate through the existing relationships:
|
89
|
+
payment.invoice_assignments.each do |asgn|
|
90
|
+
# Did the assignment get changed by the input? If so...
|
91
|
+
if (
|
92
|
+
input_assignments.has_key?(asgn.invoice_id) &&
|
93
|
+
input_assignments[asgn.invoice_id] != asgn.amount
|
94
|
+
)
|
95
|
+
# They set this asignment to zero - which means we remove the assignment:
|
96
|
+
if input_assignments[asgn.invoice_id] == Money.new(0)
|
97
|
+
# Mark this assignment for deletion below
|
98
|
+
assignment_deletes << asgn
|
99
|
+
else # assign the new value:
|
100
|
+
asgn.amount = input_assignments[asgn.invoice_id]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# THis is a little more efficient than deleting in the loop above. Also,
|
106
|
+
# I think there's a bug whereby the iterator stops running as soon as you delete somethign in the
|
107
|
+
# assignment collection. This causes subsequent assignments not to run..
|
108
|
+
payment.invoice_assignments.delete *assignment_deletes
|
109
|
+
|
110
|
+
# And then we go through the open invoices to find if new assignments need to be created:
|
111
|
+
payment.client.unpaid_invoices.each do |inv|
|
112
|
+
# We need to add a new assignment if there's a non-zero value
|
113
|
+
payment.invoice_assignments.build(
|
114
|
+
:invoice_id => inv.id,
|
115
|
+
:amount => input_assignments[inv.id]
|
116
|
+
) if (
|
117
|
+
# We want to make sure we're not creating an assignment that already exists
|
118
|
+
!payment.invoice_assignments.any?{|asgn| asgn.invoice_id == inv.id} &&
|
119
|
+
input_assignments.has_key?(inv.id) &&
|
120
|
+
input_assignments[inv.id] != Money.new(0)
|
121
|
+
)
|
122
|
+
end
|
45
123
|
end
|
46
124
|
|
47
125
|
alias before_create_save before_update_save
|
48
126
|
|
127
|
+
def on_assignment_observation
|
128
|
+
@observed_column = params[:observed_column]
|
49
129
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
130
|
+
# First let's load the record in question (or create one) ...
|
131
|
+
@record = (/^[\d]+$/.match(params[:record_id])) ?
|
132
|
+
Payment.find(params[:record_id].to_i) : Payment.new
|
133
|
+
|
134
|
+
# We'll need these later in the helper/rjs...
|
135
|
+
params[:id] = params[:record_id] # This is a hack to make the options_for_column work as expected
|
136
|
+
define_scaffold_observations
|
137
|
+
|
138
|
+
# We don't have to raise on this one really. Its not consequential if this is screwy
|
139
|
+
@record.client_id = params[:client].to_i if /^[\d]+$/.match params[:client]
|
140
|
+
|
141
|
+
# Let's make sure all the amounts we've been given are acceptable:
|
142
|
+
@invalid_amount_columns = params.to_enum(:each_pair).collect{|key,value|
|
143
|
+
key if (VALID_INVOICE_ASSIGNMENT_INPUT.match key or key == 'amount') and !VALID_MONEY_INPUT.match value
|
144
|
+
}.compact
|
145
|
+
|
146
|
+
if @invalid_amount_columns.length > 0
|
147
|
+
# We'll end up needing this when we're clearing out amounts outstanding due to a mis-type
|
148
|
+
@invoice_map = Invoice.find(
|
149
|
+
:all,
|
150
|
+
:conditions => ['id IN (?)', @invalid_amount_columns.collect{|colname| $1 if VALID_INVOICE_ASSIGNMENT_INPUT.match colname}]
|
151
|
+
).inject({}){|ret, inv| ret.merge({inv.id => inv})}
|
58
152
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
153
|
+
raise ObservedInvalidAmount
|
154
|
+
end
|
155
|
+
|
156
|
+
# This is an important field to get right. Remember that we already validating this param above:
|
157
|
+
@record.amount = Money.new(params[:amount].to_f*100) if params.has_key? :amount
|
158
|
+
|
159
|
+
case @observed_column
|
160
|
+
when /^(?:amount|client)$/
|
161
|
+
# Let's try to guess the right assignments automatically:
|
162
|
+
@record.invoice_assignments = @record.client.recommend_invoice_assignments_for(
|
163
|
+
@record.amount
|
164
|
+
) if @record.client and @record.amount
|
165
|
+
|
166
|
+
when VALID_INVOICE_ASSIGNMENT_INPUT
|
167
|
+
@observed_invoice = Invoice.find $1.to_i
|
168
|
+
|
169
|
+
update_assignments_from_params @record
|
170
|
+
|
171
|
+
@observed_assignment = @record.invoice_assignments.to_a.find{|ia| ia.invoice_id == @observed_invoice.id}
|
172
|
+
end
|
173
|
+
|
174
|
+
rescue ObservedInvalidAmount
|
175
|
+
render :action => :observation_error
|
176
|
+
end
|
177
|
+
|
178
|
+
private
|
179
|
+
|
180
|
+
def update_assignments_from_params(record)
|
181
|
+
# First we build a lookup with all ids that were passed in the params,
|
182
|
+
# and which have an assignment amount greater than 0
|
183
|
+
assignments = {}
|
184
|
+
|
185
|
+
params.each_pair do |key,value|
|
186
|
+
if VALID_INVOICE_ASSIGNMENT_INPUT.match key
|
187
|
+
inv_id = $1.to_i
|
188
|
+
assignments[inv_id] = Money.new(params[key].to_f*100)
|
75
189
|
end
|
190
|
+
end
|
191
|
+
|
192
|
+
# Now go ahead and delete the invoice_assignments that no longer have money attributed to them
|
193
|
+
record.invoice_assignments.each do |ia|
|
194
|
+
record.invoice_assignments.delete ia unless assignments.keys.include? ia.invoice_id
|
195
|
+
end
|
196
|
+
|
197
|
+
# And lastly, add new the assignments and/or update existing assignments in the record:
|
198
|
+
assignments.each_pair do |inv_id,amount|
|
199
|
+
ia = record.invoice_assignments.to_a.find{|ia| ia.invoice_id == inv_id}
|
200
|
+
ia ||= record.invoice_assignments.build :invoice_id => inv_id
|
76
201
|
|
77
|
-
|
202
|
+
ia.amount = amount
|
78
203
|
end
|
204
|
+
|
205
|
+
record
|
79
206
|
end
|
80
207
|
|
81
208
|
handle_extensions
|