dorsale 1.2.6 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/accounting.js +413 -0
- data/app/assets/javascripts/dorsale/billing_machine/all.coffee +20 -0
- data/app/assets/javascripts/dorsale/billing_machine/invoices.coffee +39 -0
- data/app/assets/javascripts/dorsale/billing_machine/quotations.coffee +38 -0
- data/app/assets/javascripts/dorsale/comments.coffee +4 -0
- data/app/assets/javascripts/dorsale/customer_vault/all.coffee +9 -0
- data/app/assets/javascripts/dorsale/datepicker.coffee +1 -1
- data/app/assets/javascripts/dorsale/flyboy/all.coffee +0 -0
- data/app/assets/javascripts/dorsale/forms.coffee +20 -6
- data/app/assets/stylesheets/dorsale/billing_machine/all.sass +15 -0
- data/app/assets/stylesheets/dorsale/bootstrap_nav_left.sass +34 -0
- data/app/assets/stylesheets/dorsale/comments.sass +25 -3
- data/app/assets/stylesheets/dorsale/customer_vault/all.sass +89 -0
- data/app/assets/stylesheets/dorsale/filters.sass +4 -1
- data/app/assets/stylesheets/dorsale/flyboy/all.sass +52 -0
- data/app/assets/stylesheets/dorsale/forms.sass +19 -0
- data/app/controllers/dorsale/alexandrie/attachments_controller.rb +52 -0
- data/app/controllers/dorsale/billing_machine/application_controller.rb +15 -0
- data/app/controllers/dorsale/billing_machine/invoices_controller.rb +180 -0
- data/app/controllers/dorsale/billing_machine/quotations_controller.rb +151 -0
- data/app/controllers/dorsale/comments_controller.rb +64 -17
- data/app/controllers/dorsale/customer_vault/application_controller.rb +26 -0
- data/app/controllers/dorsale/customer_vault/corporations_controller.rb +100 -0
- data/app/controllers/dorsale/customer_vault/individuals_controller.rb +104 -0
- data/app/controllers/dorsale/customer_vault/links_controller.rb +92 -0
- data/app/controllers/dorsale/customer_vault/people_controller.rb +42 -0
- data/app/controllers/dorsale/flyboy/application_controller.rb +9 -0
- data/app/controllers/dorsale/flyboy/folders_controller.rb +124 -0
- data/app/controllers/dorsale/flyboy/task_comments_controller.rb +29 -0
- data/app/controllers/dorsale/flyboy/tasks_controller.rb +171 -0
- data/app/controllers/dorsale/small_data/filters_controller.rb +7 -0
- data/app/helpers/dorsale/alexandrie/attachments_helper.rb +17 -0
- data/app/helpers/dorsale/all_helpers.rb +12 -9
- data/app/helpers/dorsale/button_helper.rb +23 -3
- data/app/helpers/dorsale/comments_helper.rb +4 -0
- data/app/helpers/dorsale/customer_vault/application_helper.rb +98 -0
- data/app/helpers/dorsale/flyboy/application_helper.rb +44 -0
- data/app/helpers/dorsale/form_helper.rb +7 -0
- data/app/helpers/dorsale/link_helper.rb +3 -2
- data/app/helpers/dorsale/routes_helper.rb +5 -3
- data/app/helpers/dorsale/text_helper.rb +28 -1
- data/app/models/dorsale/ability_helper.rb +7 -0
- data/app/models/dorsale/alexandrie/ability_helper.rb +9 -0
- data/app/models/dorsale/alexandrie/attachment.rb +18 -0
- data/app/models/dorsale/billing_machine/ability_helper.rb +10 -0
- data/app/models/dorsale/billing_machine/id_card.rb +18 -0
- data/app/models/dorsale/billing_machine/invoice.rb +126 -0
- data/app/models/dorsale/billing_machine/invoice_line.rb +27 -0
- data/app/models/dorsale/billing_machine/payment_term.rb +12 -0
- data/app/models/dorsale/billing_machine/quotation.rb +66 -0
- data/app/models/dorsale/billing_machine/quotation_line.rb +25 -0
- data/app/models/dorsale/billing_machine/small_data/filter_for_invoices.rb +21 -0
- data/app/models/dorsale/billing_machine/small_data/filter_for_quotations.rb +20 -0
- data/app/models/dorsale/billing_machine/small_data/filter_strategy_by_customer.rb +12 -0
- data/app/models/dorsale/billing_machine/small_data/filter_strategy_by_payment_status.rb +23 -0
- data/app/models/dorsale/billing_machine/small_data/filter_strategy_by_time_period.rb +27 -0
- data/app/models/dorsale/comment.rb +6 -2
- data/app/models/dorsale/customer_vault/ability_helper.rb +9 -0
- data/app/models/dorsale/customer_vault/corporation.rb +12 -0
- data/app/models/dorsale/customer_vault/individual.rb +17 -0
- data/app/models/dorsale/customer_vault/link.rb +10 -0
- data/app/models/dorsale/customer_vault/person.rb +35 -0
- data/app/models/dorsale/customer_vault/small_data/filter_for_people.rb +19 -0
- data/app/models/dorsale/customer_vault/small_data/filter_strategy_by_tags.rb +18 -0
- data/app/models/dorsale/flyboy/ability_helper.rb +41 -0
- data/app/models/dorsale/flyboy/folder.rb +77 -0
- data/app/models/dorsale/flyboy/small_data/filter_for_folders.rb +19 -0
- data/app/models/dorsale/flyboy/small_data/filter_for_tasks.rb +19 -0
- data/app/models/dorsale/flyboy/small_data/filter_strategy_by_done.rb +12 -0
- data/app/models/dorsale/flyboy/small_data/filter_strategy_by_nothing.rb +11 -0
- data/app/models/dorsale/flyboy/small_data/filter_strategy_by_status.rb +15 -0
- data/app/models/dorsale/flyboy/task.rb +97 -0
- data/app/models/dorsale/flyboy/task_comment.rb +35 -0
- data/app/pdfs/dorsale/billing_machine/invoice_pdf.rb +209 -0
- data/app/pdfs/dorsale/billing_machine/quotation_pdf.rb +53 -0
- data/app/pdfs/dorsale/flyboy/roadmap.rb +51 -0
- data/app/uploaders/dorsale/alexandrie/file_uploader.rb +6 -0
- data/app/uploaders/dorsale/file_uploader.rb +9 -0
- data/app/uploaders/dorsale/image_uploader.rb +7 -0
- data/app/views/dorsale/_contextual.html.slim +3 -0
- data/app/views/dorsale/alexandrie/attachments/_form.html.slim +13 -0
- data/app/views/dorsale/alexandrie/attachments/_form_and_list.html.slim +2 -0
- data/app/views/dorsale/alexandrie/attachments/_list.html.slim +7 -0
- data/app/views/dorsale/billing_machine/invoices/_data_context.html.slim +10 -0
- data/app/views/dorsale/billing_machine/invoices/_filters.html.slim +16 -0
- data/app/views/dorsale/billing_machine/invoices/_form.html.slim +62 -0
- data/app/views/dorsale/billing_machine/invoices/_line_fields.html.slim +23 -0
- data/app/views/dorsale/billing_machine/invoices/_list.html.slim +30 -0
- data/app/views/dorsale/billing_machine/invoices/edit.html.slim +2 -0
- data/app/views/dorsale/billing_machine/invoices/index.html.slim +15 -0
- data/app/views/dorsale/billing_machine/invoices/new.html.slim +2 -0
- data/app/views/dorsale/billing_machine/invoices/show.html.slim +53 -0
- data/app/views/dorsale/billing_machine/quotations/_data_context.html.slim +10 -0
- data/app/views/dorsale/billing_machine/quotations/_filters.html.slim +13 -0
- data/app/views/dorsale/billing_machine/quotations/_form.html.slim +55 -0
- data/app/views/dorsale/billing_machine/quotations/_line_fields.html.slim +23 -0
- data/app/views/dorsale/billing_machine/quotations/_list.html.slim +30 -0
- data/app/views/dorsale/billing_machine/quotations/edit.html.slim +2 -0
- data/app/views/dorsale/billing_machine/quotations/index.html.slim +14 -0
- data/app/views/dorsale/billing_machine/quotations/new.html.slim +2 -0
- data/app/views/dorsale/billing_machine/quotations/show.html.slim +61 -0
- data/app/views/dorsale/comments/_comment.html.slim +23 -9
- data/app/views/dorsale/comments/_comments.html.slim +2 -2
- data/app/views/dorsale/comments/_form.html.slim +1 -1
- data/app/views/dorsale/comments/_list.html.slim +2 -0
- data/app/views/dorsale/comments/edit.html.slim +5 -0
- data/app/views/dorsale/customer_vault/_breadcrumb.html.slim +4 -0
- data/app/views/dorsale/customer_vault/corporations/_context.html.slim +20 -0
- data/app/views/dorsale/customer_vault/corporations/_form.html.slim +21 -0
- data/app/views/dorsale/customer_vault/corporations/_list_details.html.slim +20 -0
- data/app/views/dorsale/customer_vault/corporations/edit.html.slim +14 -0
- data/app/views/dorsale/customer_vault/corporations/new.html.slim +14 -0
- data/app/views/dorsale/customer_vault/corporations/show.html.slim +1 -0
- data/app/views/dorsale/customer_vault/individuals/_context.html.slim +15 -0
- data/app/views/dorsale/customer_vault/individuals/_form.html.slim +22 -0
- data/app/views/dorsale/customer_vault/individuals/_list_details.html.slim +20 -0
- data/app/views/dorsale/customer_vault/individuals/edit.html.slim +14 -0
- data/app/views/dorsale/customer_vault/individuals/new.html.slim +14 -0
- data/app/views/dorsale/customer_vault/individuals/show.html.slim +1 -0
- data/app/views/dorsale/customer_vault/links/_title.html.slim +7 -0
- data/app/views/dorsale/customer_vault/links/edit.html.slim +19 -0
- data/app/views/dorsale/customer_vault/links/new.html.slim +15 -0
- data/app/views/dorsale/customer_vault/people/_activity_tab.html.slim +5 -0
- data/app/views/dorsale/customer_vault/people/_comment.html.slim +1 -0
- data/app/views/dorsale/customer_vault/people/_context.html.slim +4 -0
- data/app/views/dorsale/customer_vault/people/_data_context.html.slim +32 -0
- data/app/views/dorsale/customer_vault/people/_filters.html.slim +15 -0
- data/app/views/dorsale/customer_vault/people/_index_tabs.html.slim +7 -0
- data/app/views/dorsale/customer_vault/people/_links_tab.html.slim +16 -0
- data/app/views/dorsale/customer_vault/people/_new_people_contexts.html.slim +7 -0
- data/app/views/dorsale/customer_vault/people/_show.html.slim +31 -0
- data/app/views/dorsale/customer_vault/people/_tasks_tab.html.slim +1 -0
- data/app/views/dorsale/customer_vault/people/activity.slim +20 -0
- data/app/views/dorsale/customer_vault/people/list.html.slim +27 -0
- data/app/views/dorsale/flyboy/_filters.html.slim +12 -0
- data/app/views/dorsale/flyboy/folders/_actions.html.slim +15 -0
- data/app/views/dorsale/flyboy/folders/_context.html.slim +18 -0
- data/app/views/dorsale/flyboy/folders/_form.html.slim +22 -0
- data/app/views/dorsale/flyboy/folders/_list.html.slim +30 -0
- data/app/views/dorsale/flyboy/folders/edit.html.slim +2 -0
- data/app/views/dorsale/flyboy/folders/index.html.slim +8 -0
- data/app/views/dorsale/flyboy/folders/new.html.slim +2 -0
- data/app/views/dorsale/flyboy/folders/show.html.slim +9 -0
- data/app/views/dorsale/flyboy/task_comments/_list.html.slim +31 -0
- data/app/views/dorsale/flyboy/tasks/_actions.html.slim +9 -0
- data/app/views/dorsale/flyboy/tasks/_context.html.slim +15 -0
- data/app/views/dorsale/flyboy/tasks/_form.html.slim +29 -0
- data/app/views/dorsale/flyboy/tasks/_list.html.slim +43 -0
- data/app/views/dorsale/flyboy/tasks/_tasks_for_taskable.html.slim +6 -0
- data/app/views/dorsale/flyboy/tasks/edit.html.slim +2 -0
- data/app/views/dorsale/flyboy/tasks/index.html.slim +10 -0
- data/app/views/dorsale/flyboy/tasks/index.xls.erb +29 -0
- data/app/views/dorsale/flyboy/tasks/new.html.slim +2 -0
- data/app/views/dorsale/flyboy/tasks/show.html.slim +14 -0
- data/app/views/dorsale/search/_form.html.slim +6 -0
- data/config/locales/alexandrie.fr.yml +8 -0
- data/config/locales/billing_machine.fr.yml +50 -0
- data/config/locales/common.fr.yml +142 -0
- data/config/locales/customer_vault.fr.yml +69 -0
- data/config/locales/flyboy.fr.yml +66 -0
- data/config/locales/fr.yml +8 -87
- data/config/routes.rb +50 -1
- data/db/migrate/20141010140200_create_dorsale_addresses.rb +1 -1
- data/db/migrate/20150312083147_create_dorsale_comments.rb +3 -3
- data/db/migrate/20150616074852_create_dorsale_alexandrie_attachments.rb +9 -0
- data/db/migrate/20150622075000_create_flyboy.rb +50 -0
- data/db/migrate/20150622075038_create_billing_machine.rb +121 -0
- data/db/migrate/20150622105217_create_customer_vault.rb +49 -0
- data/db/migrate/20150623093218_dorsale_v2_changes.rb +68 -0
- data/db/migrate/20150625093326_billing_machine_quotations_add_expires_at.rb +5 -0
- data/db/migrate/20150625131155_billing_machine_add_tracking_ids.rb +6 -0
- data/lib/active_record_comma_type_cast.rb +12 -0
- data/lib/dorsale/alexandrie/prawn.rb +17 -0
- data/lib/dorsale/engine.rb +19 -0
- data/lib/dorsale/file_loader.rb +10 -0
- data/lib/dorsale/model_i18n.rb +21 -0
- data/lib/dorsale/model_to_s.rb +13 -0
- data/lib/dorsale/polymorphic_id.rb +2 -0
- data/lib/dorsale/version.rb +1 -1
- data/spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb +47 -0
- data/spec/controllers/dorsale/comments_controller_spec.rb +45 -0
- data/spec/controllers/dorsale/customer_vault/corporations_controller_spec.rb +132 -0
- data/spec/controllers/dorsale/customer_vault/individuals_controller_spec.rb +130 -0
- data/spec/controllers/dorsale/customer_vault/people_controller_spec.rb +59 -0
- data/spec/controllers/dorsale/flyboy/folders_controller_spec.rb +111 -0
- data/spec/controllers/dorsale/flyboy/task_comments_controller_spec.rb +16 -0
- data/spec/controllers/dorsale/flyboy/tasks_controller_spec.rb +234 -0
- data/spec/dummy/app/assets/javascripts/application.coffee +10 -0
- data/spec/dummy/app/assets/stylesheets/application.sass +9 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/models/ability.rb +16 -0
- data/spec/dummy/app/models/dummy_model.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +10 -3
- data/spec/dummy/config/application.rb +4 -2
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20150616082916_create_dorsale_dummy_models.rb +8 -0
- data/spec/dummy/db/migrate/20150624081204_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb +31 -0
- data/spec/dummy/db/migrate/20150624081205_add_missing_unique_indices.acts_as_taggable_on_engine.rb +20 -0
- data/spec/dummy/db/migrate/20150624081206_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +15 -0
- data/spec/dummy/db/migrate/20150624081207_add_missing_taggable_index.acts_as_taggable_on_engine.rb +10 -0
- data/spec/dummy/db/migrate/20150624081208_change_collation_for_tag_names.acts_as_taggable_on_engine.rb +10 -0
- data/spec/dummy/db/schema.rb +243 -5
- data/spec/dummy/db/seed.rb +1 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +227 -0
- data/spec/dummy/log/test.log +2740 -25
- data/spec/dummy/{app/assets/stylesheets/application.css → tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705} +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/factories/alexandrie_attachments.rb +12 -0
- data/spec/factories/billing_machine_id_cards.rb +26 -0
- data/spec/factories/billing_machine_invoice_lines.rb +11 -0
- data/spec/factories/billing_machine_invoices.rb +12 -0
- data/spec/factories/billing_machine_payment_terms.rb +5 -0
- data/spec/factories/billing_machine_quotation_lines.rb +12 -0
- data/spec/factories/billing_machine_quotations.rb +12 -0
- data/spec/factories/customer_vault_corporations.rb +14 -0
- data/spec/factories/customer_vault_individuals.rb +19 -0
- data/spec/factories/customer_vault_links.rb +7 -0
- data/spec/factories/dorsale_addresses.rb +6 -8
- data/spec/factories/dorsale_comments.rb +8 -0
- data/spec/factories/flyboy_folders.rb +7 -0
- data/spec/factories/flyboy_task_comments.rb +8 -0
- data/spec/factories/flyboy_tasks.rb +12 -0
- data/spec/files/pdf.pdf +0 -0
- data/spec/helpers/dorsale/flyboy/application_helper_spec.rb +91 -0
- data/spec/helpers/dorsale/link_helper_spec.rb +1 -0
- data/spec/helpers/dorsale/text_helper_spec.rb +33 -9
- data/spec/models/dorsale/ability_helper_spec.rb +11 -0
- data/spec/models/dorsale/alexandrie/ability_helper_spec.rb +10 -0
- data/spec/models/dorsale/alexandrie/attachment_spec.rb +12 -0
- data/spec/models/dorsale/billing_machine/id_card_spec.rb +12 -0
- data/spec/models/dorsale/billing_machine/invoice_line_spec.rb +50 -0
- data/spec/models/dorsale/billing_machine/invoice_spec.rb +156 -0
- data/spec/models/dorsale/billing_machine/quotation_line_spec.rb +36 -0
- data/spec/models/dorsale/billing_machine/quotation_spec.rb +91 -0
- data/spec/models/dorsale/comment_spec.rb +11 -0
- data/spec/models/dorsale/customer_vault/corporation_spec.rb +17 -0
- data/spec/models/dorsale/customer_vault/individual_spec.rb +17 -0
- data/spec/models/dorsale/customer_vault/link_spec.rb +12 -0
- data/spec/models/dorsale/customer_vault/person_spec.rb +44 -0
- data/spec/models/dorsale/flyboy/ability_spec.rb +148 -0
- data/spec/models/dorsale/flyboy/folder_spec.rb +103 -0
- data/spec/models/dorsale/flyboy/task_comment_spec.rb +52 -0
- data/spec/models/dorsale/flyboy/task_spec.rb +83 -0
- data/spec/pdfs/dorsale/billing_machine/invoice_pdf_spec.rb +252 -0
- data/spec/pdfs/dorsale/billing_machine/quotation_pdf_spec.rb +255 -0
- data/spec/rails_helper.rb +11 -11
- data/spec/routing/dorsale/alexandrie/attachments_routing_spec.rb +19 -0
- data/spec/routing/dorsale/billing_machine/invoices_routing_spec.rb +53 -0
- data/spec/routing/dorsale/billing_machine/quotations_routing_spec.rb +43 -0
- data/spec/routing/dorsale/comments_routing_spec.rb +25 -0
- data/spec/routing/dorsale/customer_vault/corporations_routing_spec.rb +66 -0
- data/spec/routing/dorsale/customer_vault/individual_routing_spec.rb +66 -0
- data/spec/routing/dorsale/customer_vault/people_routing_spec.rb +22 -0
- data/spec/routing/dorsale/flyboy/folders_routing_spec.rb +44 -0
- data/spec/routing/dorsale/flyboy/task_comments_routing_spec.rb +12 -0
- data/spec/routing/dorsale/flyboy/tasks_routing_spec.rb +44 -0
- data/spec/spec_helper.rb +0 -6
- metadata +439 -10
- data/MIT-LICENSE +0 -20
- data/README.rdoc +0 -3
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acf39d83e50a2963807161d6cc2896f269947da7
|
4
|
+
data.tar.gz: 06d508c738ad9c9361995e9d726a83d6ecf1874e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9efee4dff01582b2cae6a99200d02df2334fc278ac1772668b71f5ccf518c1c53108d939ba04ba6b1db232c1dc8873edb1cedc73d2789a103478953d06dfdc30
|
7
|
+
data.tar.gz: ca3c27fff0fda94b76be45d8936e851a1b54ff936f1f23f1991be945b02fc42e7838a481de1458752fc936a444b22b1a72e2f52164378d16b146f92142600896
|
@@ -0,0 +1,413 @@
|
|
1
|
+
/*!
|
2
|
+
* accounting.js v0.4.2
|
3
|
+
* Copyright 2014 Open Exchange Rates
|
4
|
+
*
|
5
|
+
* Freely distributable under the MIT license.
|
6
|
+
* Portions of accounting.js are inspired or borrowed from underscore.js
|
7
|
+
*
|
8
|
+
* Full details and documentation:
|
9
|
+
* http://openexchangerates.github.io/accounting.js/
|
10
|
+
*/
|
11
|
+
|
12
|
+
(function(root, undefined) {
|
13
|
+
|
14
|
+
/* --- Setup --- */
|
15
|
+
|
16
|
+
// Create the local library object, to be exported or referenced globally later
|
17
|
+
var lib = {};
|
18
|
+
|
19
|
+
// Current version
|
20
|
+
lib.version = '0.4.1';
|
21
|
+
|
22
|
+
|
23
|
+
/* --- Exposed settings --- */
|
24
|
+
|
25
|
+
// The library's settings configuration object. Contains default parameters for
|
26
|
+
// currency and number formatting
|
27
|
+
lib.settings = {
|
28
|
+
currency: {
|
29
|
+
symbol : "$", // default currency symbol is '$'
|
30
|
+
format : "%s%v", // controls output: %s = symbol, %v = value (can be object, see docs)
|
31
|
+
decimal : ".", // decimal point separator
|
32
|
+
thousand : ",", // thousands separator
|
33
|
+
precision : 2, // decimal places
|
34
|
+
grouping : 3 // digit grouping (not implemented yet)
|
35
|
+
},
|
36
|
+
number: {
|
37
|
+
precision : 0, // default precision on numbers is 0
|
38
|
+
grouping : 3, // digit grouping (not implemented yet)
|
39
|
+
thousand : ",",
|
40
|
+
decimal : "."
|
41
|
+
}
|
42
|
+
};
|
43
|
+
|
44
|
+
|
45
|
+
/* --- Internal Helper Methods --- */
|
46
|
+
|
47
|
+
// Store reference to possibly-available ECMAScript 5 methods for later
|
48
|
+
var nativeMap = Array.prototype.map,
|
49
|
+
nativeIsArray = Array.isArray,
|
50
|
+
toString = Object.prototype.toString;
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Tests whether supplied parameter is a string
|
54
|
+
* from underscore.js
|
55
|
+
*/
|
56
|
+
function isString(obj) {
|
57
|
+
return !!(obj === '' || (obj && obj.charCodeAt && obj.substr));
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Tests whether supplied parameter is a string
|
62
|
+
* from underscore.js, delegates to ECMA5's native Array.isArray
|
63
|
+
*/
|
64
|
+
function isArray(obj) {
|
65
|
+
return nativeIsArray ? nativeIsArray(obj) : toString.call(obj) === '[object Array]';
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Tests whether supplied parameter is a true object
|
70
|
+
*/
|
71
|
+
function isObject(obj) {
|
72
|
+
return obj && toString.call(obj) === '[object Object]';
|
73
|
+
}
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Extends an object with a defaults object, similar to underscore's _.defaults
|
77
|
+
*
|
78
|
+
* Used for abstracting parameter handling from API methods
|
79
|
+
*/
|
80
|
+
function defaults(object, defs) {
|
81
|
+
var key;
|
82
|
+
object = object || {};
|
83
|
+
defs = defs || {};
|
84
|
+
// Iterate over object non-prototype properties:
|
85
|
+
for (key in defs) {
|
86
|
+
if (defs.hasOwnProperty(key)) {
|
87
|
+
// Replace values with defaults only if undefined (allow empty/zero values):
|
88
|
+
if (object[key] == null) object[key] = defs[key];
|
89
|
+
}
|
90
|
+
}
|
91
|
+
return object;
|
92
|
+
}
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Implementation of `Array.map()` for iteration loops
|
96
|
+
*
|
97
|
+
* Returns a new Array as a result of calling `iterator` on each array value.
|
98
|
+
* Defers to native Array.map if available
|
99
|
+
*/
|
100
|
+
function map(obj, iterator, context) {
|
101
|
+
var results = [], i, j;
|
102
|
+
|
103
|
+
if (!obj) return results;
|
104
|
+
|
105
|
+
// Use native .map method if it exists:
|
106
|
+
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
|
107
|
+
|
108
|
+
// Fallback for native .map:
|
109
|
+
for (i = 0, j = obj.length; i < j; i++ ) {
|
110
|
+
results[i] = iterator.call(context, obj[i], i, obj);
|
111
|
+
}
|
112
|
+
return results;
|
113
|
+
}
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Check and normalise the value of precision (must be positive integer)
|
117
|
+
*/
|
118
|
+
function checkPrecision(val, base) {
|
119
|
+
val = Math.round(Math.abs(val));
|
120
|
+
return isNaN(val)? base : val;
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Parses a format string or object and returns format obj for use in rendering
|
126
|
+
*
|
127
|
+
* `format` is either a string with the default (positive) format, or object
|
128
|
+
* containing `pos` (required), `neg` and `zero` values (or a function returning
|
129
|
+
* either a string or object)
|
130
|
+
*
|
131
|
+
* Either string or format.pos must contain "%v" (value) to be valid
|
132
|
+
*/
|
133
|
+
function checkCurrencyFormat(format) {
|
134
|
+
var defaults = lib.settings.currency.format;
|
135
|
+
|
136
|
+
// Allow function as format parameter (should return string or object):
|
137
|
+
if ( typeof format === "function" ) format = format();
|
138
|
+
|
139
|
+
// Format can be a string, in which case `value` ("%v") must be present:
|
140
|
+
if ( isString( format ) && format.match("%v") ) {
|
141
|
+
|
142
|
+
// Create and return positive, negative and zero formats:
|
143
|
+
return {
|
144
|
+
pos : format,
|
145
|
+
neg : format.replace("-", "").replace("%v", "-%v"),
|
146
|
+
zero : format
|
147
|
+
};
|
148
|
+
|
149
|
+
// If no format, or object is missing valid positive value, use defaults:
|
150
|
+
} else if ( !format || !format.pos || !format.pos.match("%v") ) {
|
151
|
+
|
152
|
+
// If defaults is a string, casts it to an object for faster checking next time:
|
153
|
+
return ( !isString( defaults ) ) ? defaults : lib.settings.currency.format = {
|
154
|
+
pos : defaults,
|
155
|
+
neg : defaults.replace("%v", "-%v"),
|
156
|
+
zero : defaults
|
157
|
+
};
|
158
|
+
|
159
|
+
}
|
160
|
+
// Otherwise, assume format was fine:
|
161
|
+
return format;
|
162
|
+
}
|
163
|
+
|
164
|
+
|
165
|
+
/* --- API Methods --- */
|
166
|
+
|
167
|
+
/**
|
168
|
+
* Takes a string/array of strings, removes all formatting/cruft and returns the raw float value
|
169
|
+
* Alias: `accounting.parse(string)`
|
170
|
+
*
|
171
|
+
* Decimal must be included in the regular expression to match floats (defaults to
|
172
|
+
* accounting.settings.number.decimal), so if the number uses a non-standard decimal
|
173
|
+
* separator, provide it as the second argument.
|
174
|
+
*
|
175
|
+
* Also matches bracketed negatives (eg. "$ (1.99)" => -1.99)
|
176
|
+
*
|
177
|
+
* Doesn't throw any errors (`NaN`s become 0) but this may change in future
|
178
|
+
*/
|
179
|
+
var unformat = lib.unformat = lib.parse = function(value, decimal) {
|
180
|
+
// Recursively unformat arrays:
|
181
|
+
if (isArray(value)) {
|
182
|
+
return map(value, function(val) {
|
183
|
+
return unformat(val, decimal);
|
184
|
+
});
|
185
|
+
}
|
186
|
+
|
187
|
+
// Fails silently (need decent errors):
|
188
|
+
value = value || 0;
|
189
|
+
|
190
|
+
// Return the value as-is if it's already a number:
|
191
|
+
if (typeof value === "number") return value;
|
192
|
+
|
193
|
+
// Default decimal point comes from settings, but could be set to eg. "," in opts:
|
194
|
+
decimal = decimal || lib.settings.number.decimal;
|
195
|
+
|
196
|
+
// Build regex to strip out everything except digits, decimal point and minus sign:
|
197
|
+
var regex = new RegExp("[^0-9-" + decimal + "]", ["g"]),
|
198
|
+
unformatted = parseFloat(
|
199
|
+
("" + value)
|
200
|
+
.replace(/\((.*)\)/, "-$1") // replace bracketed values with negatives
|
201
|
+
.replace(regex, '') // strip out any cruft
|
202
|
+
.replace(decimal, '.') // make sure decimal point is standard
|
203
|
+
);
|
204
|
+
|
205
|
+
// This will fail silently which may cause trouble, let's wait and see:
|
206
|
+
return !isNaN(unformatted) ? unformatted : 0;
|
207
|
+
};
|
208
|
+
|
209
|
+
|
210
|
+
/**
|
211
|
+
* Implementation of toFixed() that treats floats more like decimals
|
212
|
+
*
|
213
|
+
* Fixes binary rounding issues (eg. (0.615).toFixed(2) === "0.61") that present
|
214
|
+
* problems for accounting- and finance-related software.
|
215
|
+
*/
|
216
|
+
var toFixed = lib.toFixed = function(value, precision) {
|
217
|
+
precision = checkPrecision(precision, lib.settings.number.precision);
|
218
|
+
var power = Math.pow(10, precision);
|
219
|
+
|
220
|
+
// Multiply up by precision, round accurately, then divide and use native toFixed():
|
221
|
+
return (Math.round(lib.unformat(value) * power) / power).toFixed(precision);
|
222
|
+
};
|
223
|
+
|
224
|
+
|
225
|
+
/**
|
226
|
+
* Format a number, with comma-separated thousands and custom precision/decimal places
|
227
|
+
* Alias: `accounting.format()`
|
228
|
+
*
|
229
|
+
* Localise by overriding the precision and thousand / decimal separators
|
230
|
+
* 2nd parameter `precision` can be an object matching `settings.number`
|
231
|
+
*/
|
232
|
+
var formatNumber = lib.formatNumber = lib.format = function(number, precision, thousand, decimal) {
|
233
|
+
// Resursively format arrays:
|
234
|
+
if (isArray(number)) {
|
235
|
+
return map(number, function(val) {
|
236
|
+
return formatNumber(val, precision, thousand, decimal);
|
237
|
+
});
|
238
|
+
}
|
239
|
+
|
240
|
+
// Clean up number:
|
241
|
+
number = unformat(number);
|
242
|
+
|
243
|
+
// Build options object from second param (if object) or all params, extending defaults:
|
244
|
+
var opts = defaults(
|
245
|
+
(isObject(precision) ? precision : {
|
246
|
+
precision : precision,
|
247
|
+
thousand : thousand,
|
248
|
+
decimal : decimal
|
249
|
+
}),
|
250
|
+
lib.settings.number
|
251
|
+
),
|
252
|
+
|
253
|
+
// Clean up precision
|
254
|
+
usePrecision = checkPrecision(opts.precision),
|
255
|
+
|
256
|
+
// Do some calc:
|
257
|
+
negative = number < 0 ? "-" : "",
|
258
|
+
base = parseInt(toFixed(Math.abs(number || 0), usePrecision), 10) + "",
|
259
|
+
mod = base.length > 3 ? base.length % 3 : 0;
|
260
|
+
|
261
|
+
// Format the number:
|
262
|
+
return negative + (mod ? base.substr(0, mod) + opts.thousand : "") + base.substr(mod).replace(/(\d{3})(?=\d)/g, "$1" + opts.thousand) + (usePrecision ? opts.decimal + toFixed(Math.abs(number), usePrecision).split('.')[1] : "");
|
263
|
+
};
|
264
|
+
|
265
|
+
|
266
|
+
/**
|
267
|
+
* Format a number into currency
|
268
|
+
*
|
269
|
+
* Usage: accounting.formatMoney(number, symbol, precision, thousandsSep, decimalSep, format)
|
270
|
+
* defaults: (0, "$", 2, ",", ".", "%s%v")
|
271
|
+
*
|
272
|
+
* Localise by overriding the symbol, precision, thousand / decimal separators and format
|
273
|
+
* Second param can be an object matching `settings.currency` which is the easiest way.
|
274
|
+
*
|
275
|
+
* To do: tidy up the parameters
|
276
|
+
*/
|
277
|
+
var formatMoney = lib.formatMoney = function(number, symbol, precision, thousand, decimal, format) {
|
278
|
+
// Resursively format arrays:
|
279
|
+
if (isArray(number)) {
|
280
|
+
return map(number, function(val){
|
281
|
+
return formatMoney(val, symbol, precision, thousand, decimal, format);
|
282
|
+
});
|
283
|
+
}
|
284
|
+
|
285
|
+
// Clean up number:
|
286
|
+
number = unformat(number);
|
287
|
+
|
288
|
+
// Build options object from second param (if object) or all params, extending defaults:
|
289
|
+
var opts = defaults(
|
290
|
+
(isObject(symbol) ? symbol : {
|
291
|
+
symbol : symbol,
|
292
|
+
precision : precision,
|
293
|
+
thousand : thousand,
|
294
|
+
decimal : decimal,
|
295
|
+
format : format
|
296
|
+
}),
|
297
|
+
lib.settings.currency
|
298
|
+
),
|
299
|
+
|
300
|
+
// Check format (returns object with pos, neg and zero):
|
301
|
+
formats = checkCurrencyFormat(opts.format),
|
302
|
+
|
303
|
+
// Choose which format to use for this value:
|
304
|
+
useFormat = number > 0 ? formats.pos : number < 0 ? formats.neg : formats.zero;
|
305
|
+
|
306
|
+
// Return with currency symbol added:
|
307
|
+
return useFormat.replace('%s', opts.symbol).replace('%v', formatNumber(Math.abs(number), checkPrecision(opts.precision), opts.thousand, opts.decimal));
|
308
|
+
};
|
309
|
+
|
310
|
+
|
311
|
+
/**
|
312
|
+
* Format a list of numbers into an accounting column, padding with whitespace
|
313
|
+
* to line up currency symbols, thousand separators and decimals places
|
314
|
+
*
|
315
|
+
* List should be an array of numbers
|
316
|
+
* Second parameter can be an object containing keys that match the params
|
317
|
+
*
|
318
|
+
* Returns array of accouting-formatted number strings of same length
|
319
|
+
*
|
320
|
+
* NB: `white-space:pre` CSS rule is required on the list container to prevent
|
321
|
+
* browsers from collapsing the whitespace in the output strings.
|
322
|
+
*/
|
323
|
+
lib.formatColumn = function(list, symbol, precision, thousand, decimal, format) {
|
324
|
+
if (!list) return [];
|
325
|
+
|
326
|
+
// Build options object from second param (if object) or all params, extending defaults:
|
327
|
+
var opts = defaults(
|
328
|
+
(isObject(symbol) ? symbol : {
|
329
|
+
symbol : symbol,
|
330
|
+
precision : precision,
|
331
|
+
thousand : thousand,
|
332
|
+
decimal : decimal,
|
333
|
+
format : format
|
334
|
+
}),
|
335
|
+
lib.settings.currency
|
336
|
+
),
|
337
|
+
|
338
|
+
// Check format (returns object with pos, neg and zero), only need pos for now:
|
339
|
+
formats = checkCurrencyFormat(opts.format),
|
340
|
+
|
341
|
+
// Whether to pad at start of string or after currency symbol:
|
342
|
+
padAfterSymbol = formats.pos.indexOf("%s") < formats.pos.indexOf("%v") ? true : false,
|
343
|
+
|
344
|
+
// Store value for the length of the longest string in the column:
|
345
|
+
maxLength = 0,
|
346
|
+
|
347
|
+
// Format the list according to options, store the length of the longest string:
|
348
|
+
formatted = map(list, function(val, i) {
|
349
|
+
if (isArray(val)) {
|
350
|
+
// Recursively format columns if list is a multi-dimensional array:
|
351
|
+
return lib.formatColumn(val, opts);
|
352
|
+
} else {
|
353
|
+
// Clean up the value
|
354
|
+
val = unformat(val);
|
355
|
+
|
356
|
+
// Choose which format to use for this value (pos, neg or zero):
|
357
|
+
var useFormat = val > 0 ? formats.pos : val < 0 ? formats.neg : formats.zero,
|
358
|
+
|
359
|
+
// Format this value, push into formatted list and save the length:
|
360
|
+
fVal = useFormat.replace('%s', opts.symbol).replace('%v', formatNumber(Math.abs(val), checkPrecision(opts.precision), opts.thousand, opts.decimal));
|
361
|
+
|
362
|
+
if (fVal.length > maxLength) maxLength = fVal.length;
|
363
|
+
return fVal;
|
364
|
+
}
|
365
|
+
});
|
366
|
+
|
367
|
+
// Pad each number in the list and send back the column of numbers:
|
368
|
+
return map(formatted, function(val, i) {
|
369
|
+
// Only if this is a string (not a nested array, which would have already been padded):
|
370
|
+
if (isString(val) && val.length < maxLength) {
|
371
|
+
// Depending on symbol position, pad after symbol or at index 0:
|
372
|
+
return padAfterSymbol ? val.replace(opts.symbol, opts.symbol+(new Array(maxLength - val.length + 1).join(" "))) : (new Array(maxLength - val.length + 1).join(" ")) + val;
|
373
|
+
}
|
374
|
+
return val;
|
375
|
+
});
|
376
|
+
};
|
377
|
+
|
378
|
+
|
379
|
+
/* --- Module Definition --- */
|
380
|
+
|
381
|
+
// Export accounting for CommonJS. If being loaded as an AMD module, define it as such.
|
382
|
+
// Otherwise, just add `accounting` to the global object
|
383
|
+
if (typeof exports !== 'undefined') {
|
384
|
+
if (typeof module !== 'undefined' && module.exports) {
|
385
|
+
exports = module.exports = lib;
|
386
|
+
}
|
387
|
+
exports.accounting = lib;
|
388
|
+
} else if (typeof define === 'function' && define.amd) {
|
389
|
+
// Return the library as an AMD module:
|
390
|
+
define([], function() {
|
391
|
+
return lib;
|
392
|
+
});
|
393
|
+
} else {
|
394
|
+
// Use accounting.noConflict to restore `accounting` back to its original value.
|
395
|
+
// Returns a reference to the library's `accounting` object;
|
396
|
+
// e.g. `var numbers = accounting.noConflict();`
|
397
|
+
lib.noConflict = (function(oldAccounting) {
|
398
|
+
return function() {
|
399
|
+
// Reset the value of the root's `accounting` variable:
|
400
|
+
root.accounting = oldAccounting;
|
401
|
+
// Delete the noConflict method:
|
402
|
+
lib.noConflict = undefined;
|
403
|
+
// Return reference to the library to re-assign it:
|
404
|
+
return lib;
|
405
|
+
};
|
406
|
+
})(root.accounting);
|
407
|
+
|
408
|
+
// Declare `fx` on the root (global/window) object:
|
409
|
+
root['accounting'] = lib;
|
410
|
+
}
|
411
|
+
|
412
|
+
// Root will be `window` in browser or `global` on the server:
|
413
|
+
}(this));
|
@@ -0,0 +1,20 @@
|
|
1
|
+
//= require_tree .
|
2
|
+
|
3
|
+
accounting.settings =
|
4
|
+
currency:
|
5
|
+
symbol : "€" # default currency symbol is '$'
|
6
|
+
format: "%v%s" # controls output: %s = symbol, %v = value/number (can be object: see below)
|
7
|
+
decimal : "," # decimal point separator
|
8
|
+
thousand: "." # thousands separator
|
9
|
+
precision : 2 # decimal places
|
10
|
+
|
11
|
+
number:
|
12
|
+
precision : 2 # default precision on numbers is 0
|
13
|
+
thousand: "."
|
14
|
+
decimal : ","
|
15
|
+
|
16
|
+
window.display_euros = (amount, target) ->
|
17
|
+
if isNaN amount
|
18
|
+
target.text('Saisie invalide')
|
19
|
+
else
|
20
|
+
target.text(accounting.formatMoney(amount))
|
@@ -0,0 +1,39 @@
|
|
1
|
+
$(document).on "ready page:load", ->
|
2
|
+
if ($('#invoice.edit').size() > 0)
|
3
|
+
sum_line = (line) ->
|
4
|
+
q = line.find('input.line-quantity').val().replace(',', '.')
|
5
|
+
up = line.find('input.line-unit_price').val().replace(',', '.')
|
6
|
+
total = q * up
|
7
|
+
|
8
|
+
update_line_total = (line)->
|
9
|
+
total = sum_line(line)
|
10
|
+
display_euros(total, line.find('.line-total'))
|
11
|
+
|
12
|
+
update_total = ->
|
13
|
+
total_duty = 0
|
14
|
+
vat_rate = $('#invoice_vat_rate').val().replace(',', '.')
|
15
|
+
advance = $('#invoice_advance').val().replace(',', '.')
|
16
|
+
|
17
|
+
$('.invoice-line').each (index, element)->
|
18
|
+
remove_me = $(element).find('.remove-line input[type="hidden"]').val()
|
19
|
+
total_duty += sum_line $(element) if remove_me == 'false'
|
20
|
+
vat_amount = vat_rate * total_duty / 100.0
|
21
|
+
|
22
|
+
display_euros(total_duty, $('#invoice-total_duty'))
|
23
|
+
display_euros(vat_amount, $('#invoice-vat_amount'))
|
24
|
+
display_euros(vat_amount+total_duty, $('#invoice-total_all_taxes'))
|
25
|
+
display_euros(vat_amount+total_duty-advance, $('#invoice-balance'))
|
26
|
+
|
27
|
+
# Set listener on inputs
|
28
|
+
$('#invoice-lines').on 'input', 'input.line-quantity, input.line-unit_price', (event) ->
|
29
|
+
update_line_total $(event.currentTarget).parents('.invoice-line')
|
30
|
+
update_total()
|
31
|
+
$('#invoice').on 'input', 'input#invoice_vat_rate, input#invoice_advance', (event) ->
|
32
|
+
update_total()
|
33
|
+
$('#invoice').on 'cocoon:after-remove', (event) ->
|
34
|
+
update_total()
|
35
|
+
|
36
|
+
# Update values on page loading
|
37
|
+
$('.invoice-line').each (index, element)->
|
38
|
+
update_line_total $(element)
|
39
|
+
update_total()
|