has_accounts_engine 1.1.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/images/16x16/add.png +0 -0
- data/app/assets/images/16x16/alert.png +0 -0
- data/app/assets/images/16x16/combolink.png +0 -0
- data/app/assets/images/16x16/copy.png +0 -0
- data/app/assets/images/16x16/delete.png +0 -0
- data/app/assets/images/16x16/edit.png +0 -0
- data/app/assets/images/16x16/filter.png +0 -0
- data/app/assets/images/16x16/index.png +0 -0
- data/app/assets/images/16x16/notice.png +0 -0
- data/app/assets/images/16x16/pdf.png +0 -0
- data/app/assets/images/16x16/preferences.png +0 -0
- data/app/assets/images/16x16/print.png +0 -0
- data/app/assets/images/16x16/show.png +0 -0
- data/app/assets/images/22x22/arrow-right.png +0 -0
- data/app/assets/images/22x22/edit.png +0 -0
- data/app/assets/images/22x22/insert_booking.png +0 -0
- data/app/assets/images/22x22/remove.png +0 -0
- data/app/assets/images/32x32/edit.png +0 -0
- data/app/assets/images/32x32/remove.png +0 -0
- data/app/assets/images/48x48/accounting.png +0 -0
- data/app/assets/images/48x48/basic_claims_data.png +0 -0
- data/app/assets/images/48x48/contacts.png +0 -0
- data/app/assets/images/48x48/invoicing.png +0 -0
- data/app/assets/images/48x48/nav_users.png +0 -0
- data/app/assets/images/48x48/preferences.png +0 -0
- data/app/assets/images/48x48/projects.png +0 -0
- data/app/assets/images/48x48/salaries.png +0 -0
- data/app/assets/images/48x48/settings.png +0 -0
- data/app/assets/images/48x48/stocks.png +0 -0
- data/app/assets/images/48x48/store.png +0 -0
- data/app/assets/images/button_bg.png +0 -0
- data/app/assets/images/crystal-icons/16x16/filter.png +0 -0
- data/app/assets/images/down.png +0 -0
- data/app/assets/images/favicon.ico +0 -0
- data/app/assets/images/flavour-extended/48x48/invoice.png +0 -0
- data/app/assets/images/free-business-desktop-icons/48x48/business.png +0 -0
- data/app/assets/images/gnome-web-icons/48x48/Gnome-X-Office-Address-Book-48.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_flat_55_fbec88_40x100.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_glass_75_759fcf_1x400.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_glass_85_aeb9cf_1x400.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_gloss-wave_55_aeb9cf_500x100.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_inset-hard_100_759fcf_1x100.png +0 -0
- data/app/assets/images/jquery-ui/ui-bg_inset-hard_100_f6f6f6_1x100.png +0 -0
- data/app/assets/images/jquery-ui/ui-icons_217bc0_256x240.png +0 -0
- data/app/assets/images/jquery-ui/ui-icons_2e83ff_256x240.png +0 -0
- data/app/assets/images/jquery-ui/ui-icons_469bdd_256x240.png +0 -0
- data/app/assets/images/jquery-ui/ui-icons_6da8d5_256x240.png +0 -0
- data/app/assets/images/jquery-ui/ui-icons_cd0a0a_256x240.png +0 -0
- data/app/assets/images/jquery-ui/ui-icons_d8e7f3_256x240.png +0 -0
- data/app/assets/images/jquery-ui/ui-icons_f9bd01_256x240.png +0 -0
- data/app/assets/images/letter-logo.alpha.png +0 -0
- data/app/assets/images/letter-logo.big.png +0 -0
- data/app/assets/images/letter-logo.orig.png +0 -0
- data/app/assets/images/letter-logo.png +0 -0
- data/app/assets/images/loading.gif +0 -0
- data/app/assets/images/logo.png +0 -0
- data/app/assets/images/oxygen-icons/16x16/application-pdf.png +0 -0
- data/app/assets/images/oxygen-icons/16x16/document-preview.png +0 -0
- data/app/assets/images/oxygen-icons/16x16/document-print.png +0 -0
- data/app/assets/images/oxygen-icons/16x16/edit-copy.png +0 -0
- data/app/assets/images/oxygen-icons/16x16/go-next.png +0 -0
- data/app/assets/images/oxygen-icons/16x16/mail-mark-notjunk.png +0 -0
- data/app/assets/images/oxygen-icons/16x16/status_unknown.png +0 -0
- data/app/assets/images/oxygen-icons/48x48/preferences-system-time.png +0 -0
- data/app/assets/images/oxygen-icons/48x48/system-users.png +0 -0
- data/app/assets/images/oxygen-icons/48x48/view-bank-account-savings.png +0 -0
- data/app/assets/images/oxygen-icons/48x48/view-loan-asset.png +0 -0
- data/app/assets/images/rails.png +0 -0
- data/app/assets/images/up.png +0 -0
- data/app/assets/javascripts/has_accounts_engine/accounting-jquery.js +77 -0
- data/app/assets/javascripts/has_accounts_engine/accounting.js +411 -0
- data/app/assets/javascripts/has_accounts_engine/application.js +248 -0
- data/app/assets/javascripts/has_accounts_engine/bootstrap.datepicker.js +455 -0
- data/app/assets/javascripts/has_accounts_engine/cyt.js +117 -0
- data/app/assets/stylesheets/has_accounts_engine/.gitkeep +0 -0
- data/app/assets/stylesheets/has_accounts_engine/app_bootstrap.css.scss +5 -0
- data/app/assets/stylesheets/has_accounts_engine/application.css +14 -0
- data/app/assets/stylesheets/has_accounts_engine/bootstrap.datepicker.css +7 -0
- data/app/assets/stylesheets/has_accounts_engine/bootstrap.scss +1 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/_base.sass +39 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/_jquery.sass +1 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/content/_accounting.sass +16 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/content/_app.sass +46 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/content/_combobox.sass +6 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/content/_contextual.sass +10 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/content/_fixed_sidebar.sass +11 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/content/_form_view.sass +24 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/content/_icons.sass +29 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/content/_invoice.sass +10 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/content/_overview.sass +44 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/content/_select_form_labels.sass +28 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/jquery/_jquery_ui.sass +1461 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/print/_app.sass +2 -0
- data/app/assets/stylesheets/has_accounts_engine/partials/print/_layout.sass +66 -0
- data/app/assets/stylesheets/has_accounts_engine/print.scss +5 -0
- data/app/assets/stylesheets/has_accounts_engine/screen.scss +144 -0
- data/app/controllers/accounts_controller.rb +1 -1
- data/app/controllers/booking_templates_controller.rb +1 -1
- data/app/controllers/bookings_controller.rb +1 -1
- data/app/helpers/bootstrap_helper.rb +147 -0
- data/app/helpers/has_accounts_helper.rb +9 -0
- data/app/inputs/combobox_input.rb +22 -0
- data/app/inputs/date_field_input.rb +11 -0
- data/app/views/accounts/_booking_item.html.haml +2 -2
- data/app/views/accounts/_booking_list_header.html.haml +1 -1
- data/app/views/accounts/_booking_list_turnover.html.haml +1 -1
- data/app/views/accounts/_edit_booking.html.haml +1 -1
- data/app/views/accounts/_edit_bookings.html.haml +1 -1
- data/app/views/accounts/_show.html.haml +3 -2
- data/app/views/accounts/_show_bookings.html.haml +2 -2
- data/app/views/accounts/show.html.haml +1 -1
- data/app/views/booking_templates/_booking_template.html.haml +1 -1
- data/app/views/booking_templates/_form.html.haml +2 -2
- data/app/views/booking_templates/_list.html.haml +1 -1
- data/app/views/bookings/_booking.html.haml +1 -1
- data/app/views/bookings/_form.html.haml +6 -5
- data/app/views/bookings/_list.html.haml +1 -1
- data/app/views/bookings/_sidebar.html.haml +0 -5
- data/app/views/bookings/_simple_form.html.haml +2 -2
- data/app/views/has_accounts/_form.html.haml +5 -0
- data/app/views/has_accounts/_list.html.haml +15 -0
- data/app/views/has_accounts/_search_form.html.haml +6 -0
- data/app/views/has_accounts/_show.html.haml +2 -0
- data/app/views/has_accounts/_show_attachments.html.haml +9 -0
- data/app/views/has_accounts/_sidebar.html.haml +8 -0
- data/app/views/has_accounts/create.js.erb +3 -0
- data/app/views/has_accounts/destroy.js.erb +2 -0
- data/app/views/has_accounts/edit.html.haml +5 -0
- data/app/views/has_accounts/edit.js.erb +3 -0
- data/app/views/has_accounts/index.html.haml +6 -0
- data/app/views/has_accounts/new.html.haml +5 -0
- data/app/views/has_accounts/new.js.erb +3 -0
- data/app/views/has_accounts/show.html.haml +5 -0
- data/app/views/has_accounts/show_modal.js.erb +7 -0
- data/app/views/has_accounts/update.js.erb +3 -0
- data/app/views/layouts/has_accounts_engine.html.haml +48 -0
- data/config/locales/de.yml +14 -37
- data/config/locales/en.yml +26 -23
- data/lib/has_accounts_engine/railtie.rb +4 -0
- data/lib/has_accounts_engine/version.rb +1 -1
- metadata +169 -8
- data/app/controllers/bank_accounts_controller.rb +0 -3
- data/app/controllers/banks_controller.rb +0 -3
- data/app/views/bank_accounts/_bank_account.html.haml +0 -1
- data/app/views/bank_accounts/_form.html.haml +0 -10
- data/app/views/banks/_bank.html.haml +0 -3
- data/app/views/banks/_form.html.haml +0 -12
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,77 @@
|
|
1
|
+
/**
|
2
|
+
* accounting-jquery.js [alpha]
|
3
|
+
*
|
4
|
+
* jQuery plugin wrapper for accounting.js. Dependcies: jQuery, accounting.js (duh)
|
5
|
+
* Usage: `$(el).accounting("methodName", [opts]);`
|
6
|
+
*/
|
7
|
+
|
8
|
+
(function($) {
|
9
|
+
var methods = {
|
10
|
+
settings: function(options) {
|
11
|
+
// Merge new options into accounting.settings
|
12
|
+
accounting.settings = $.extend(true, accounting.settings, options);
|
13
|
+
|
14
|
+
// Return for chaining
|
15
|
+
return this;
|
16
|
+
},
|
17
|
+
formatNumber: function(options) {
|
18
|
+
// Apply accounting.formatNumber() to matched elements and return for chaining
|
19
|
+
return this.each(function() {
|
20
|
+
$(this).text(
|
21
|
+
accounting.formatNumber($(this).text(), options)
|
22
|
+
);
|
23
|
+
});
|
24
|
+
},
|
25
|
+
formatMoney: function(options) {
|
26
|
+
// Apply accounting.formatMoney() to matched elements and return for chaining
|
27
|
+
return this.each(function() {
|
28
|
+
$(this).text(
|
29
|
+
accounting.formatMoney($(this).text(), options)
|
30
|
+
);
|
31
|
+
});
|
32
|
+
},
|
33
|
+
formatColumn: function(options) {
|
34
|
+
var column = [];
|
35
|
+
|
36
|
+
// Collect our values into an array to pass to formatColumn()
|
37
|
+
this.each(function() {
|
38
|
+
column.push($(this).text());
|
39
|
+
});
|
40
|
+
|
41
|
+
// Format the column of values
|
42
|
+
column = accounting.formatColumn(column, options);
|
43
|
+
|
44
|
+
// Now set each of the elements' values and return for chaining
|
45
|
+
return this.each(function(i) {
|
46
|
+
$(this).text(column[i]);
|
47
|
+
});
|
48
|
+
},
|
49
|
+
toFixed: function(precision) {
|
50
|
+
// Apply accounting.toFixed() to matched elements and return for chaining
|
51
|
+
return this.each(function() {
|
52
|
+
$(this).text(
|
53
|
+
accounting.toFixed($(this).text(), precision)
|
54
|
+
);
|
55
|
+
});
|
56
|
+
},
|
57
|
+
unformat: function(decimal) {
|
58
|
+
// Apply accounting.unformat() to matched elements and return for chaining
|
59
|
+
return this.each(function() {
|
60
|
+
$(this).text(
|
61
|
+
accounting.unformat($(this).text(), decimal)
|
62
|
+
);
|
63
|
+
});
|
64
|
+
}
|
65
|
+
};
|
66
|
+
|
67
|
+
$.fn.accounting = function(method) {
|
68
|
+
// Method calling logic
|
69
|
+
if (methods[method]) {
|
70
|
+
return methods[method].apply( this, Array.prototype.slice.call(arguments, 1));
|
71
|
+
} else if (typeof method === 'object' || !method) {
|
72
|
+
return methods.settings.apply(this, arguments);
|
73
|
+
} else {
|
74
|
+
$.error('Method ' + method + ' does not exist on jQuery.accounting');
|
75
|
+
}
|
76
|
+
};
|
77
|
+
})(jQuery);
|
@@ -0,0 +1,411 @@
|
|
1
|
+
/*!
|
2
|
+
* accounting.js v0.3.1
|
3
|
+
* Copyright 2011, Joss Crowcroft
|
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://josscrowcroft.github.com/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.3.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 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 (default: "."), so if the number
|
172
|
+
* uses a non-standard decimal separator, provide it as the second argument.
|
173
|
+
*
|
174
|
+
* Also matches bracketed negatives (eg. "$ (1.99)" => -1.99)
|
175
|
+
*
|
176
|
+
* Doesn't throw any errors (`NaN`s become 0) but this may change in future
|
177
|
+
*/
|
178
|
+
var unformat = lib.unformat = lib.parse = function(value, decimal) {
|
179
|
+
// Recursively unformat arrays:
|
180
|
+
if (isArray(value)) {
|
181
|
+
return map(value, function(val) {
|
182
|
+
return unformat(val, decimal);
|
183
|
+
});
|
184
|
+
}
|
185
|
+
|
186
|
+
// Fails silently (need decent errors):
|
187
|
+
value = value || 0;
|
188
|
+
|
189
|
+
// Return the value as-is if it's already a number:
|
190
|
+
if (typeof value === "number") return value;
|
191
|
+
|
192
|
+
// Default decimal point is "." but could be set to eg. "," in opts:
|
193
|
+
decimal = decimal || ".";
|
194
|
+
|
195
|
+
// Build regex to strip out everything except digits, decimal point and minus sign:
|
196
|
+
var regex = new RegExp("[^0-9-" + decimal + "]", ["g"]),
|
197
|
+
unformatted = parseFloat(
|
198
|
+
("" + value)
|
199
|
+
.replace(/\((.*)\)/, "-$1") // replace bracketed values with negatives
|
200
|
+
.replace(regex, '') // strip out any cruft
|
201
|
+
.replace(decimal, '.') // make sure decimal point is standard
|
202
|
+
);
|
203
|
+
|
204
|
+
// This will fail silently which may cause trouble, let's wait and see:
|
205
|
+
return !isNaN(unformatted) ? unformatted : 0;
|
206
|
+
};
|
207
|
+
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Implementation of toFixed() that treats floats more like decimals
|
211
|
+
*
|
212
|
+
* Fixes binary rounding issues (eg. (0.615).toFixed(2) === "0.61") that present
|
213
|
+
* problems for accounting- and finance-related software.
|
214
|
+
*/
|
215
|
+
var toFixed = lib.toFixed = function(value, precision) {
|
216
|
+
precision = checkPrecision(precision, lib.settings.number.precision);
|
217
|
+
var power = Math.pow(10, precision);
|
218
|
+
|
219
|
+
// Multiply up by precision, round accurately, then divide and use native toFixed():
|
220
|
+
return (Math.round(lib.unformat(value) * power) / power).toFixed(precision);
|
221
|
+
};
|
222
|
+
|
223
|
+
|
224
|
+
/**
|
225
|
+
* Format a number, with comma-separated thousands and custom precision/decimal places
|
226
|
+
*
|
227
|
+
* Localise by overriding the precision and thousand / decimal separators
|
228
|
+
* 2nd parameter `precision` can be an object matching `settings.number`
|
229
|
+
*/
|
230
|
+
var formatNumber = lib.formatNumber = function(number, precision, thousand, decimal) {
|
231
|
+
// Resursively format arrays:
|
232
|
+
if (isArray(number)) {
|
233
|
+
return map(number, function(val) {
|
234
|
+
return formatNumber(val, precision, thousand, decimal);
|
235
|
+
});
|
236
|
+
}
|
237
|
+
|
238
|
+
// Clean up number:
|
239
|
+
number = unformat(number);
|
240
|
+
|
241
|
+
// Build options object from second param (if object) or all params, extending defaults:
|
242
|
+
var opts = defaults(
|
243
|
+
(isObject(precision) ? precision : {
|
244
|
+
precision : precision,
|
245
|
+
thousand : thousand,
|
246
|
+
decimal : decimal
|
247
|
+
}),
|
248
|
+
lib.settings.number
|
249
|
+
),
|
250
|
+
|
251
|
+
// Clean up precision
|
252
|
+
usePrecision = checkPrecision(opts.precision),
|
253
|
+
|
254
|
+
// Do some calc:
|
255
|
+
negative = number < 0 ? "-" : "",
|
256
|
+
base = parseInt(toFixed(Math.abs(number || 0), usePrecision), 10) + "",
|
257
|
+
mod = base.length > 3 ? base.length % 3 : 0;
|
258
|
+
|
259
|
+
// Format the number:
|
260
|
+
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] : "");
|
261
|
+
};
|
262
|
+
|
263
|
+
|
264
|
+
/**
|
265
|
+
* Format a number into currency
|
266
|
+
*
|
267
|
+
* Usage: accounting.formatMoney(number, symbol, precision, thousandsSep, decimalSep, format)
|
268
|
+
* defaults: (0, "$", 2, ",", ".", "%s%v")
|
269
|
+
*
|
270
|
+
* Localise by overriding the symbol, precision, thousand / decimal separators and format
|
271
|
+
* Second param can be an object matching `settings.currency` which is the easiest way.
|
272
|
+
*
|
273
|
+
* To do: tidy up the parameters
|
274
|
+
*/
|
275
|
+
var formatMoney = lib.formatMoney = function(number, symbol, precision, thousand, decimal, format) {
|
276
|
+
// Resursively format arrays:
|
277
|
+
if (isArray(number)) {
|
278
|
+
return map(number, function(val){
|
279
|
+
return formatMoney(val, symbol, precision, thousand, decimal, format);
|
280
|
+
});
|
281
|
+
}
|
282
|
+
|
283
|
+
// Clean up number:
|
284
|
+
number = unformat(number);
|
285
|
+
|
286
|
+
// Build options object from second param (if object) or all params, extending defaults:
|
287
|
+
var opts = defaults(
|
288
|
+
(isObject(symbol) ? symbol : {
|
289
|
+
symbol : symbol,
|
290
|
+
precision : precision,
|
291
|
+
thousand : thousand,
|
292
|
+
decimal : decimal,
|
293
|
+
format : format
|
294
|
+
}),
|
295
|
+
lib.settings.currency
|
296
|
+
),
|
297
|
+
|
298
|
+
// Check format (returns object with pos, neg and zero):
|
299
|
+
formats = checkCurrencyFormat(opts.format),
|
300
|
+
|
301
|
+
// Choose which format to use for this value:
|
302
|
+
useFormat = number > 0 ? formats.pos : number < 0 ? formats.neg : formats.zero;
|
303
|
+
|
304
|
+
// Return with currency symbol added:
|
305
|
+
return useFormat.replace('%s', opts.symbol).replace('%v', formatNumber(Math.abs(number), checkPrecision(opts.precision), opts.thousand, opts.decimal));
|
306
|
+
};
|
307
|
+
|
308
|
+
|
309
|
+
/**
|
310
|
+
* Format a list of numbers into an accounting column, padding with whitespace
|
311
|
+
* to line up currency symbols, thousand separators and decimals places
|
312
|
+
*
|
313
|
+
* List should be an array of numbers
|
314
|
+
* Second parameter can be an object containing keys that match the params
|
315
|
+
*
|
316
|
+
* Returns array of accouting-formatted number strings of same length
|
317
|
+
*
|
318
|
+
* NB: `white-space:pre` CSS rule is required on the list container to prevent
|
319
|
+
* browsers from collapsing the whitespace in the output strings.
|
320
|
+
*/
|
321
|
+
lib.formatColumn = function(list, symbol, precision, thousand, decimal, format) {
|
322
|
+
if (!list) return [];
|
323
|
+
|
324
|
+
// Build options object from second param (if object) or all params, extending defaults:
|
325
|
+
var opts = defaults(
|
326
|
+
(isObject(symbol) ? symbol : {
|
327
|
+
symbol : symbol,
|
328
|
+
precision : precision,
|
329
|
+
thousand : thousand,
|
330
|
+
decimal : decimal,
|
331
|
+
format : format
|
332
|
+
}),
|
333
|
+
lib.settings.currency
|
334
|
+
),
|
335
|
+
|
336
|
+
// Check format (returns object with pos, neg and zero), only need pos for now:
|
337
|
+
formats = checkCurrencyFormat(opts.format),
|
338
|
+
|
339
|
+
// Whether to pad at start of string or after currency symbol:
|
340
|
+
padAfterSymbol = formats.pos.indexOf("%s") < formats.pos.indexOf("%v") ? true : false,
|
341
|
+
|
342
|
+
// Store value for the length of the longest string in the column:
|
343
|
+
maxLength = 0,
|
344
|
+
|
345
|
+
// Format the list according to options, store the length of the longest string:
|
346
|
+
formatted = map(list, function(val, i) {
|
347
|
+
if (isArray(val)) {
|
348
|
+
// Recursively format columns if list is a multi-dimensional array:
|
349
|
+
return lib.formatColumn(val, opts);
|
350
|
+
} else {
|
351
|
+
// Clean up the value
|
352
|
+
val = unformat(val);
|
353
|
+
|
354
|
+
// Choose which format to use for this value (pos, neg or zero):
|
355
|
+
var useFormat = val > 0 ? formats.pos : val < 0 ? formats.neg : formats.zero,
|
356
|
+
|
357
|
+
// Format this value, push into formatted list and save the length:
|
358
|
+
fVal = useFormat.replace('%s', opts.symbol).replace('%v', formatNumber(Math.abs(val), checkPrecision(opts.precision), opts.thousand, opts.decimal));
|
359
|
+
|
360
|
+
if (fVal.length > maxLength) maxLength = fVal.length;
|
361
|
+
return fVal;
|
362
|
+
}
|
363
|
+
});
|
364
|
+
|
365
|
+
// Pad each number in the list and send back the column of numbers:
|
366
|
+
return map(formatted, function(val, i) {
|
367
|
+
// Only if this is a string (not a nested array, which would have already been padded):
|
368
|
+
if (isString(val) && val.length < maxLength) {
|
369
|
+
// Depending on symbol position, pad after symbol or at index 0:
|
370
|
+
return padAfterSymbol ? val.replace(opts.symbol, opts.symbol+(new Array(maxLength - val.length + 1).join(" "))) : (new Array(maxLength - val.length + 1).join(" ")) + val;
|
371
|
+
}
|
372
|
+
return val;
|
373
|
+
});
|
374
|
+
};
|
375
|
+
|
376
|
+
|
377
|
+
/* --- Module Definition --- */
|
378
|
+
|
379
|
+
// Export accounting for CommonJS. If being loaded as an AMD module, define it as such.
|
380
|
+
// Otherwise, just add `accounting` to the global object
|
381
|
+
if (typeof exports !== 'undefined') {
|
382
|
+
if (typeof module !== 'undefined' && module.exports) {
|
383
|
+
exports = module.exports = lib;
|
384
|
+
}
|
385
|
+
exports.accounting = lib;
|
386
|
+
} else if (typeof define === 'function' && define.amd) {
|
387
|
+
// Return the library as an AMD module:
|
388
|
+
define([], function() {
|
389
|
+
return lib;
|
390
|
+
});
|
391
|
+
} else {
|
392
|
+
// Use accounting.noConflict to restore `accounting` back to its original value.
|
393
|
+
// Returns a reference to the library's `accounting` object;
|
394
|
+
// e.g. `var numbers = accounting.noConflict();`
|
395
|
+
lib.noConflict = (function(oldAccounting) {
|
396
|
+
return function() {
|
397
|
+
// Reset the value of the root's `accounting` variable:
|
398
|
+
root.accounting = oldAccounting;
|
399
|
+
// Delete the noConflict method:
|
400
|
+
lib.noConflict = undefined;
|
401
|
+
// Return reference to the library to re-assign it:
|
402
|
+
return lib;
|
403
|
+
};
|
404
|
+
})(root.accounting);
|
405
|
+
|
406
|
+
// Declare `fx` on the root (global/window) object:
|
407
|
+
root['accounting'] = lib;
|
408
|
+
}
|
409
|
+
|
410
|
+
// Root will be `window` in browser or `global` on the server:
|
411
|
+
}(this));
|