mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-20 02:01:19 +00:00
Compare commits
264 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83594e6f1f | ||
|
|
0f6008705c | ||
|
|
c58b653bb7 | ||
|
|
f69b6f9b4e | ||
|
|
7750b06476 | ||
|
|
873384a34b | ||
|
|
ac299e7279 | ||
|
|
7895d7f5d0 | ||
|
|
fe05d218fc | ||
|
|
8196313ac0 | ||
|
|
6d8f84654f | ||
|
|
ab4f34a96b | ||
|
|
139d985904 | ||
|
|
44705f0e18 | ||
|
|
ddea7d696a | ||
|
|
f814f45e36 | ||
|
|
f7117d47c2 | ||
|
|
01b0a1058d | ||
|
|
21f362c7b9 | ||
|
|
aaab7f8e0e | ||
|
|
09e1f68c69 | ||
|
|
03729aa5ae | ||
|
|
ef39f31ea1 | ||
|
|
0f1437dd6a | ||
|
|
03aac2f744 | ||
|
|
2f8b10e82c | ||
|
|
3231effd20 | ||
|
|
f7722c1189 | ||
|
|
70c2450ac4 | ||
|
|
2d5b0d0f99 | ||
|
|
f0c0002a6d | ||
|
|
dd9f08d4fa | ||
|
|
de2e384225 | ||
|
|
ffcd1fde0f | ||
|
|
d5e1da5948 | ||
|
|
ad479a5c7f | ||
|
|
0707603b63 | ||
|
|
2f9c383004 | ||
|
|
8ad0d7af93 | ||
|
|
9b4391c0bf | ||
|
|
da7802a0a4 | ||
|
|
9c69949e8c | ||
|
|
b1d7a9451a | ||
|
|
004488d453 | ||
|
|
fc91372dd0 | ||
|
|
5970a9dc91 | ||
|
|
264cac4f9b | ||
|
|
633328a965 | ||
|
|
4d4b62a766 | ||
|
|
aeb2c7deeb | ||
|
|
c323942d92 | ||
|
|
a0afa25145 | ||
|
|
4533b46436 | ||
|
|
e5f8db78f9 | ||
|
|
899f61671f | ||
|
|
d84d88cc10 | ||
|
|
97e7ac4052 | ||
|
|
ba4ffa44d2 | ||
|
|
07caeccf68 | ||
|
|
d54832f61f | ||
|
|
b212753633 | ||
|
|
f38d80cbf5 | ||
|
|
8bea1acd8e | ||
|
|
42458ce11d | ||
|
|
aceb683d07 | ||
|
|
b7517b49ed | ||
|
|
849b711b79 | ||
|
|
25585b28c7 | ||
|
|
073da8fb2a | ||
|
|
a787ff3f3c | ||
|
|
733b6d7eb7 | ||
|
|
36d8dee853 | ||
|
|
65a2e07d24 | ||
|
|
7c97c558ab | ||
|
|
a6bb61050c | ||
|
|
b184aa2315 | ||
|
|
e4595333e7 | ||
|
|
41dd139bde | ||
|
|
c577dd302a | ||
|
|
0ab87de78b | ||
|
|
8a22509b41 | ||
|
|
b024c18441 | ||
|
|
d9ac681a68 | ||
|
|
637a5579ec | ||
|
|
4794156e80 | ||
|
|
5f4db7874c | ||
|
|
b4ea1839a5 | ||
|
|
6a6d889983 | ||
|
|
287c2e7af8 | ||
|
|
0fe6acc8cf | ||
|
|
7d2dab7ca0 | ||
|
|
f68c1aff26 | ||
|
|
81662473a6 | ||
|
|
d40645be68 | ||
|
|
a53550537f | ||
|
|
223ad16616 | ||
|
|
3f060979d7 | ||
|
|
2eac9081ea | ||
|
|
b3eef4f40b | ||
|
|
dd70fbad3f | ||
|
|
8cb7a1aef8 | ||
|
|
a687140056 | ||
|
|
3cba673a9c | ||
|
|
01de230785 | ||
|
|
e405d06f23 | ||
|
|
d9b70f7ad8 | ||
|
|
0ef5825d98 | ||
|
|
1e76a5fc3f | ||
|
|
1fbdb3d0ae | ||
|
|
d5bcf5497f | ||
|
|
28aaea1aa3 | ||
|
|
980d9ce885 | ||
|
|
ec601efa6e | ||
|
|
b3209d3b4d | ||
|
|
4ce978b9f3 | ||
|
|
a84064663a | ||
|
|
6798cea268 | ||
|
|
8e86196352 | ||
|
|
1b3d345fbd | ||
|
|
7d2627515f | ||
|
|
aa9eb8ca64 | ||
|
|
9015d6ca16 | ||
|
|
217483639d | ||
|
|
78e80530d3 | ||
|
|
3bbecfe830 | ||
|
|
9ab3679d49 | ||
|
|
fc44a52ba5 | ||
|
|
bb2b71bdc0 | ||
|
|
b23d2a9d95 | ||
|
|
eeb773fd7b | ||
|
|
53a582f374 | ||
|
|
73110f6a51 | ||
|
|
5667663fef | ||
|
|
fb664ba17d | ||
|
|
0c10190a8e | ||
|
|
183a323ef6 | ||
|
|
90bada5497 | ||
|
|
7c043e1923 | ||
|
|
2720ae3c46 | ||
|
|
401508577e | ||
|
|
b0a31cebc2 | ||
|
|
95adb428fa | ||
|
|
f92a0310dd | ||
|
|
84f0cb3765 | ||
|
|
d49e6787d6 | ||
|
|
0884853a6f | ||
|
|
1967c63006 | ||
|
|
9461e7b70a | ||
|
|
f1e5df566c | ||
|
|
fb02a0d5ad | ||
|
|
e438a02fa3 | ||
|
|
b112452aa1 | ||
|
|
1a2fc81af3 | ||
|
|
38bbda982c | ||
|
|
41ad6e64d1 | ||
|
|
efcad0b935 | ||
|
|
e892b69a96 | ||
|
|
5dfc04e777 | ||
|
|
c119a42d70 | ||
|
|
802541b796 | ||
|
|
0770c79777 | ||
|
|
5f4669341e | ||
|
|
f15fc80233 | ||
|
|
a7d75ea94a | ||
|
|
ba4bddf756 | ||
|
|
6a26408552 | ||
|
|
c39c59fff5 | ||
|
|
c1ba8dc6a7 | ||
|
|
f2825da878 | ||
|
|
c61f1307d8 | ||
|
|
9e88d7a60d | ||
|
|
406ae25162 | ||
|
|
dbfb342021 | ||
|
|
4632142e06 | ||
|
|
9ae036f297 | ||
|
|
497b8c48c8 | ||
|
|
5d11949313 | ||
|
|
a91c9f04c5 | ||
|
|
4f3493f9ff | ||
|
|
49b8742082 | ||
|
|
69cee59e23 | ||
|
|
19402b9022 | ||
|
|
62ba40b687 | ||
|
|
f9af9a4fbe | ||
|
|
c2ab43d0ab | ||
|
|
af28e6e7b9 | ||
|
|
114ad7f292 | ||
|
|
44eb67f94e | ||
|
|
0203fee174 | ||
|
|
a1ba340ead | ||
|
|
0ae9ff4575 | ||
|
|
5b501cb942 | ||
|
|
0255b7a4a0 | ||
|
|
15ef0bab1d | ||
|
|
decad6830b | ||
|
|
b6e0b985c2 | ||
|
|
c140f71878 | ||
|
|
87044e6b8e | ||
|
|
affa9014d2 | ||
|
|
4bbc3c3bd8 | ||
|
|
d296dbbc23 | ||
|
|
9bcd27b847 | ||
|
|
2a54b36db0 | ||
|
|
77fb02daa4 | ||
|
|
1963ac191f | ||
|
|
33da8aa987 | ||
|
|
0192484044 | ||
|
|
3c0863d8ea | ||
|
|
710d6dfb74 | ||
|
|
2359542d72 | ||
|
|
e1a2b4b9af | ||
|
|
0eadfa1c83 | ||
|
|
c8dd935460 | ||
|
|
e2227271b5 | ||
|
|
7a639a1d6e | ||
|
|
9edb9b91b2 | ||
|
|
b2adeb20d9 | ||
|
|
fa665de847 | ||
|
|
ab9e5f716d | ||
|
|
5788db9f07 | ||
|
|
3068a8d58d | ||
|
|
14aacf42b9 | ||
|
|
d1b97da309 | ||
|
|
867074e7b2 | ||
|
|
18748510b1 | ||
|
|
bcf71cdf85 | ||
|
|
3290ce85a9 | ||
|
|
60ef80c1a5 | ||
|
|
74e852b8bd | ||
|
|
90ae21d257 | ||
|
|
fdf03cd8e2 | ||
|
|
f6586be5e7 | ||
|
|
f9dc627d84 | ||
|
|
309177ca9c | ||
|
|
456d2342b6 | ||
|
|
0717aa22d7 | ||
|
|
b8e07ac38e | ||
|
|
c7273e4b60 | ||
|
|
33d4fd4af0 | ||
|
|
71b11e26d2 | ||
|
|
77f4111b09 | ||
|
|
9965297f36 | ||
|
|
5ca466a826 | ||
|
|
90f417facc | ||
|
|
eacbd038b7 | ||
|
|
5446e85424 | ||
|
|
77b4942691 | ||
|
|
824cf71e0b | ||
|
|
239bbd30c0 | ||
|
|
6f6b653d54 | ||
|
|
e4155ce735 | ||
|
|
7eaf307834 | ||
|
|
7db7950415 | ||
|
|
fcc184cd2a | ||
|
|
6423feff3a | ||
|
|
e97da25d5a | ||
|
|
f49a37a38e | ||
|
|
07e6b33095 | ||
|
|
9136b50e3c | ||
|
|
c3fd5c7136 | ||
|
|
98612dd253 | ||
|
|
4d7f5238dd | ||
|
|
f472a01a80 | ||
|
|
420b5790e3 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -12,3 +12,5 @@ _ide_helper.php
|
||||
/build/logs/clover.xml
|
||||
index.html*
|
||||
app/storage/firefly-export*
|
||||
.vagrant
|
||||
firefly-iii-import-*.json
|
||||
|
||||
55
README.md
55
README.md
@@ -2,7 +2,6 @@ firefly-iii
|
||||
===========
|
||||
|
||||
[](https://travis-ci.org/JC5/firefly-iii)
|
||||
[](https://coveralls.io/r/JC5/firefly-iii?branch=master)
|
||||

|
||||
|
||||
[](https://packagist.org/packages/grumpydictator/firefly-iii)
|
||||
@@ -14,42 +13,56 @@ Firefly Mark III is a new version of Firefly built upon best practices and lesso
|
||||
from building [Firefly](https://github.com/JC5/Firefly). It's Mark III since the original Firefly never made it outside of my
|
||||
laptop and [Firefly II](https://github.com/JC5/Firefly) is live.
|
||||
|
||||
## Current features
|
||||
|
||||
- [A double-entry bookkeeping system](http://en.wikipedia.org/wiki/Double-entry_bookkeeping_system).
|
||||
- You can store, edit and remove withdrawals, deposits and transfers. This allows you full financial management;
|
||||
- It's possible to create, change and manage money using _budgets_;
|
||||
- Organize transactions using categories;
|
||||
- Save towards a goal using piggy banks;
|
||||
- Predict and anticipate large expenses using "repeated expenses" (ie. yearly taxes);
|
||||
- Predict and anticipate bills using "recurring transactions" (rent for example).
|
||||
|
||||
Everything is organised:
|
||||
|
||||
- Clear views that should show you how you're doing;
|
||||
- Easy navigation through your records;
|
||||
- Browse back and forth to see previous months or even years;
|
||||
- Lots of charts because we all love them.
|
||||
|
||||
## Changes
|
||||
|
||||
Firefly III will feature:
|
||||
Firefly III will feature, but does not feature yet:
|
||||
|
||||
- Double-entry bookkeeping system;
|
||||
- Better budgeting tools;
|
||||
- Better financial reporting;
|
||||
- Financial reporting showing you how well you are doing;
|
||||
- Lots of help text in case you don't get it;
|
||||
- More control over other resources outside of personal finance
|
||||
- Accounts shared with a partner (household accounts)
|
||||
- Debts
|
||||
- Credit cards
|
||||
- More robust code base (mainly for my own peace of mind);
|
||||
- More test-coverage (aka: actual test coverage);
|
||||
|
||||
## More features
|
||||
|
||||
- Firefly will be able to split transactions; a single purchase can be split in multiple entries, for more fine-grained control.
|
||||
- Firefly will be able to join transactions.
|
||||
- Transfers and transactions will be combined into one internal datatype which is more consistent with what you're actually doing: moving money from A to B. The fact that A or B or both are yours should not matter. And it will not, in the future.
|
||||
- The nesting of budgets, categories and beneficiaries will be removed.
|
||||
- Firefly will be able to automatically login a specified account. Although this is pretty unsafe, it removes the need for you to login to your own tool.
|
||||
- Transfers and transactions are combined into one internal datatype which is more consistent with what you're actually doing: moving money from A to B. The fact that A or B or both are yours should not matter.
|
||||
- Any other features I might not have thought of.
|
||||
|
||||
## Not changed
|
||||
Some stuff has been removed:
|
||||
|
||||
- The nesting of budgets, categories and beneficiaries is removed because it was pretty pointless.
|
||||
- Firefly will not encrypt the content of the (MySQL) tables. Old versions of Firefly had this capability but it sucks when searching, sorting and organizing entries.
|
||||
|
||||
## Screenshots
|
||||
|
||||

|
||||
|
||||
## Current state
|
||||
I have the basics up and running and test coverage is doing very well.
|
||||
I have the basics up and running. Test coverage is currently non-existent.
|
||||
|
||||
Current issues are the consistent look-and-feel of forms and likewise, the consistent inner workings of most of Firefly.
|
||||
Example: every "create"-action tends to be slightly different from the rest. Also is the fact that not all lists
|
||||
and forms are equally well thought of; some are not looking very well or miss feedback.
|
||||
Although I have not checked extensively, some forms and views have CSRF vulnerabilities. This is because not all
|
||||
views escape all characters by default. Will be fixed.
|
||||
|
||||
Most forms will not allow you to enter invalid data because the database cracks, not because it's actually checked.
|
||||
I'm still thinking about a way to build consistent forms. Laravel doesn't really cut it.
|
||||
|
||||
A lot of views have CSRF vulnerabilities. The general advice is NOT to use this tool in production.
|
||||
The current layout / look & feel is a pretty basic Bootstrap3 template. I am currently working on a more consistent,
|
||||
expanded layout which will feature shiny AJAX things and data tables and all the Web 3.0 goodies you've come to expect
|
||||
from social media sites.
|
||||
|
||||
Questions, ideas or other things to contribute? [Let me know](https://github.com/JC5/firefly-iii/issues/new)!
|
||||
@@ -1 +0,0 @@
|
||||
If you place an image here called foobar.png then you can access that image by going to http://<hostname>/assets/foobar.png
|
||||
@@ -1,16 +0,0 @@
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
// but before any files alphabetically greater than 'application.js'
|
||||
//
|
||||
// The available directives right now are require, require_directory, and require_tree
|
||||
//
|
||||
//= require highslide/highslide-full.min
|
||||
//= require highslide/highslide.config
|
||||
//= require_tree highcharts
|
||||
//= require firefly/accounts
|
||||
@@ -1,15 +0,0 @@
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
// but before any files alphabetically greater than 'application.js'
|
||||
//
|
||||
// The available directives right now are require, require_directory, and require_tree
|
||||
//
|
||||
//= require jquery
|
||||
//= require bootstrap/bootstrap.min
|
||||
//= require firefly/reminders
|
||||
@@ -1,14 +0,0 @@
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
// but before any files alphabetically greater than 'application.js'
|
||||
//
|
||||
// The available directives right now are require, require_directory, and require_tree
|
||||
//
|
||||
//= require_tree highcharts
|
||||
//= require firefly/budgets/default
|
||||
@@ -1,14 +0,0 @@
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
// but before any files alphabetically greater than 'application.js'
|
||||
//
|
||||
// The available directives right now are require, require_directory, and require_tree
|
||||
//
|
||||
//= require_tree highcharts
|
||||
//= require firefly/budgets/limit
|
||||
@@ -1,14 +0,0 @@
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
// but before any files alphabetically greater than 'application.js'
|
||||
//
|
||||
// The available directives right now are require, require_directory, and require_tree
|
||||
//
|
||||
//= require_tree highcharts
|
||||
//= require firefly/budgets/nolimit
|
||||
@@ -1,14 +0,0 @@
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
// but before any files alphabetically greater than 'application.js'
|
||||
//
|
||||
// The available directives right now are require, require_directory, and require_tree
|
||||
//
|
||||
//= require_tree highcharts
|
||||
//= require firefly/budgets/session
|
||||
@@ -1,14 +0,0 @@
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
// but before any files alphabetically greater than 'application.js'
|
||||
//
|
||||
// The available directives right now are require, require_directory, and require_tree
|
||||
//
|
||||
//= require_tree highcharts
|
||||
//= require firefly/budgets
|
||||
@@ -1,14 +0,0 @@
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
// but before any files alphabetically greater than 'application.js'
|
||||
//
|
||||
// The available directives right now are require, require_directory, and require_tree
|
||||
//
|
||||
//= require_tree highcharts
|
||||
//= require firefly/categories
|
||||
@@ -1,95 +0,0 @@
|
||||
$(function () {
|
||||
if($('#chart').length == 1) {
|
||||
/**
|
||||
* get data from controller for home charts:
|
||||
*/
|
||||
$.getJSON('chart/home/account/' + accountID).success(function (data) {
|
||||
var options = {
|
||||
chart: {
|
||||
renderTo: 'chart',
|
||||
type: 'spline'
|
||||
},
|
||||
|
||||
series: data.series,
|
||||
title: {
|
||||
text: data.chart_title
|
||||
},
|
||||
yAxis: {
|
||||
formatter: function () {
|
||||
return '$' + Highcharts.numberFormat(this.y, 0);
|
||||
}
|
||||
},
|
||||
subtitle: {
|
||||
text: data.subtitle,
|
||||
useHTML: true
|
||||
},
|
||||
|
||||
xAxis: {
|
||||
floor: 0,
|
||||
type: 'datetime',
|
||||
dateTimeLabelFormats: {
|
||||
day: '%e %b',
|
||||
year: '%b'
|
||||
},
|
||||
title: {
|
||||
text: 'Date'
|
||||
}
|
||||
},
|
||||
tooltip: {
|
||||
shared: true,
|
||||
crosshairs: false,
|
||||
formatter: function () {
|
||||
var str = '<span style="font-size:80%;">' + Highcharts.dateFormat("%A, %e %B", this.x) + '</span><br />';
|
||||
for (x in this.points) {
|
||||
var point = this.points[x];
|
||||
var colour = point.point.pointAttr[''].fill;
|
||||
str += '<span style="color:' + colour + '">' + point.series.name + '</span>: € ' + Highcharts.numberFormat(point.y, 2) + '<br />';
|
||||
}
|
||||
//console.log();
|
||||
return str;
|
||||
return '<span style="font-size:80%;">' + this.series.name + ' on ' + Highcharts.dateFormat("%e %B", this.x) + ':</span><br /> € ' + Highcharts.numberFormat(this.y, 2);
|
||||
}
|
||||
},
|
||||
plotOptions: {
|
||||
line: {
|
||||
shadow: true
|
||||
},
|
||||
series: {
|
||||
cursor: 'pointer',
|
||||
negativeColor: '#FF0000',
|
||||
threshold: 0,
|
||||
lineWidth: 1,
|
||||
marker: {
|
||||
radius: 2
|
||||
},
|
||||
point: {
|
||||
events: {
|
||||
click: function (e) {
|
||||
hs.htmlExpand(null, {
|
||||
src: 'chart/home/info/' + this.series.name + '/' + Highcharts.dateFormat("%d/%m/%Y", this.x),
|
||||
pageOrigin: {
|
||||
x: e.pageX,
|
||||
y: e.pageY
|
||||
},
|
||||
objectType: 'ajax',
|
||||
headingText: '<a href="#">' + this.series.name + '</a>',
|
||||
width: 250
|
||||
}
|
||||
)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
credits: {
|
||||
enabled: false
|
||||
}
|
||||
};
|
||||
$('#chart').highcharts(options);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
@@ -1,234 +0,0 @@
|
||||
$(function () {
|
||||
|
||||
|
||||
/**
|
||||
* get data from controller for home charts:
|
||||
*/
|
||||
$.getJSON('chart/home/account').success(function (data) {
|
||||
var options = {
|
||||
chart: {
|
||||
renderTo: 'chart',
|
||||
type: 'line'
|
||||
},
|
||||
|
||||
series: data.series,
|
||||
title: {
|
||||
text: data.chart_title
|
||||
},
|
||||
yAxis: {
|
||||
formatter: function () {
|
||||
return '$' + Highcharts.numberFormat(this.y, 0);
|
||||
}
|
||||
},
|
||||
subtitle: {
|
||||
text: data.subtitle,
|
||||
useHTML: true
|
||||
},
|
||||
|
||||
xAxis: {
|
||||
floor: 0,
|
||||
type: 'datetime',
|
||||
dateTimeLabelFormats: {
|
||||
day: '%e %b',
|
||||
year: '%b'
|
||||
},
|
||||
title: {
|
||||
text: 'Date'
|
||||
}
|
||||
},
|
||||
tooltip: {
|
||||
shared: true,
|
||||
crosshairs: false,
|
||||
formatter: function () {
|
||||
var str = '<span style="font-size:80%;">' + Highcharts.dateFormat("%A, %e %B", this.x) + '</span><br />';
|
||||
for (x in this.points) {
|
||||
var point = this.points[x];
|
||||
var colour = point.point.pointAttr[''].fill;
|
||||
str += '<span style="color:' + colour + '">' + point.series.name + '</span>: € ' + Highcharts.numberFormat(point.y, 2) + '<br />';
|
||||
}
|
||||
//console.log();
|
||||
return str;
|
||||
}
|
||||
},
|
||||
plotOptions: {
|
||||
line: {
|
||||
shadow: true
|
||||
},
|
||||
series: {
|
||||
cursor: 'pointer',
|
||||
negativeColor: '#FF0000',
|
||||
threshold: 0,
|
||||
lineWidth: 1,
|
||||
marker: {
|
||||
radius: 2
|
||||
},
|
||||
point: {
|
||||
events: {
|
||||
click: function (e) {
|
||||
hs.htmlExpand(null, {
|
||||
src: 'chart/home/info/' + this.series.name + '/' + Highcharts.dateFormat("%d/%m/%Y", this.x),
|
||||
pageOrigin: {
|
||||
x: e.pageX,
|
||||
y: e.pageY
|
||||
},
|
||||
objectType: 'ajax',
|
||||
headingText: '<a href="accounts/show/' + this.series.id + '">' + this.series.name + '</a>',
|
||||
width: 250
|
||||
}
|
||||
)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
credits: {
|
||||
enabled: false
|
||||
}
|
||||
};
|
||||
$('#chart').highcharts(options);
|
||||
});
|
||||
|
||||
/**
|
||||
* Get chart data for categories chart:
|
||||
*/
|
||||
$.getJSON('chart/home/categories').success(function (data) {
|
||||
$('#categories').highcharts({
|
||||
chart: {
|
||||
type: 'column'
|
||||
},
|
||||
title: {
|
||||
text: 'Expenses for each categorie'
|
||||
},
|
||||
subtitle: {
|
||||
text: '<a href="categories/index">View more</a>',
|
||||
useHTML: true
|
||||
},
|
||||
credits: {
|
||||
enabled: false
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
labels: {
|
||||
rotation: -45,
|
||||
style: {
|
||||
fontSize: '12px',
|
||||
fontFamily: 'Verdana, sans-serif'
|
||||
}
|
||||
}
|
||||
},
|
||||
yAxis: {
|
||||
min: 0,
|
||||
title: {
|
||||
text: 'Expense (€)'
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
enabled: false
|
||||
},
|
||||
tooltip: {
|
||||
pointFormat: 'Total expense: <strong>€ {point.y:.2f}</strong>',
|
||||
},
|
||||
plotOptions: {
|
||||
column: {
|
||||
cursor: 'pointer'
|
||||
}
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: 'Population',
|
||||
data: data,
|
||||
|
||||
events: {
|
||||
click: function (e) {
|
||||
alert('klik!');
|
||||
}
|
||||
},
|
||||
dataLabels: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Get chart data for budget charts.
|
||||
*/
|
||||
$.getJSON('chart/home/budgets').success(function (data) {
|
||||
$('#budgets').highcharts({
|
||||
chart: {
|
||||
type: 'bar'
|
||||
},
|
||||
title: {
|
||||
text: 'Budgets and spending'
|
||||
},
|
||||
subtitle: {
|
||||
text: '<a href="#">View more</a>',
|
||||
useHTML: true
|
||||
},
|
||||
xAxis: {
|
||||
categories: data.labels,
|
||||
title: {
|
||||
text: null
|
||||
},
|
||||
labels: {
|
||||
style: {
|
||||
fontSize: '11px',
|
||||
fontFamily: 'Verdana, sans-serif'
|
||||
}
|
||||
}
|
||||
},
|
||||
yAxis: {
|
||||
min: 0,
|
||||
title: {
|
||||
text: 'Amount (€)',
|
||||
align: 'high'
|
||||
},
|
||||
labels: {
|
||||
overflow: 'justify'
|
||||
}
|
||||
},
|
||||
tooltip: {
|
||||
formatter: function () {
|
||||
return false;
|
||||
return '€ ' + Highcharts.numberFormat(this.y, 2);
|
||||
}
|
||||
},
|
||||
plotOptions: {
|
||||
bar: {
|
||||
cursor: 'pointer',
|
||||
events: {
|
||||
click: function(e) {
|
||||
alert('klik!!');
|
||||
}
|
||||
},
|
||||
dataLabels: {
|
||||
enabled: true,
|
||||
formatter: function () {
|
||||
return '€ ' + Highcharts.numberFormat(this.y, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
enabled:false,
|
||||
layout: 'vertical',
|
||||
align: 'right',
|
||||
verticalAlign: 'top',
|
||||
x: -40,
|
||||
y: 100,
|
||||
floating: true,
|
||||
borderWidth: 1,
|
||||
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor || '#FFFFFF'),
|
||||
shadow: true
|
||||
},
|
||||
credits: {
|
||||
enabled: false
|
||||
},
|
||||
series: data.series
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
@@ -1,4 +0,0 @@
|
||||
$(function () {
|
||||
|
||||
|
||||
});
|
||||
@@ -1,7 +0,0 @@
|
||||
$.getJSON('json/beneficiaries').success(function (data) {
|
||||
$('input[name="beneficiary"]').typeahead({ source: data });
|
||||
});
|
||||
|
||||
$.getJSON('json/categories').success(function (data) {
|
||||
$('input[name="category"]').typeahead({ source: data });
|
||||
});
|
||||
@@ -1,307 +0,0 @@
|
||||
/*
|
||||
Highcharts JS v4.0.3 (2014-07-03)
|
||||
|
||||
(c) 2009-2014 Torstein Honsi
|
||||
|
||||
License: www.highcharts.com/license
|
||||
*/
|
||||
(function(){function r(a,b){var c;a||(a={});for(c in b)a[c]=b[c];return a}function w(){var a,b=arguments,c,d={},e=function(a,b){var c,d;typeof a!=="object"&&(a={});for(d in b)b.hasOwnProperty(d)&&(c=b[d],a[d]=c&&typeof c==="object"&&Object.prototype.toString.call(c)!=="[object Array]"&&d!=="renderTo"&&typeof c.nodeType!=="number"?e(a[d]||{},c):b[d]);return a};b[0]===!0&&(d=b[1],b=Array.prototype.slice.call(b,2));c=b.length;for(a=0;a<c;a++)d=e(d,b[a]);return d}function z(a,b){return parseInt(a,b||
|
||||
10)}function Fa(a){return typeof a==="string"}function da(a){return a&&typeof a==="object"}function La(a){return Object.prototype.toString.call(a)==="[object Array]"}function ia(a){return typeof a==="number"}function za(a){return V.log(a)/V.LN10}function ja(a){return V.pow(10,a)}function ka(a,b){for(var c=a.length;c--;)if(a[c]===b){a.splice(c,1);break}}function s(a){return a!==t&&a!==null}function F(a,b,c){var d,e;if(Fa(b))s(c)?a.setAttribute(b,c):a&&a.getAttribute&&(e=a.getAttribute(b));else if(s(b)&&
|
||||
da(b))for(d in b)a.setAttribute(d,b[d]);return e}function ra(a){return La(a)?a:[a]}function p(){var a=arguments,b,c,d=a.length;for(b=0;b<d;b++)if(c=a[b],c!==t&&c!==null)return c}function A(a,b){if(Aa&&!ba&&b&&b.opacity!==t)b.filter="alpha(opacity="+b.opacity*100+")";r(a.style,b)}function $(a,b,c,d,e){a=x.createElement(a);b&&r(a,b);e&&A(a,{padding:0,border:P,margin:0});c&&A(a,c);d&&d.appendChild(a);return a}function la(a,b){var c=function(){return t};c.prototype=new a;r(c.prototype,b);return c}function Ga(a,
|
||||
b,c,d){var e=L.lang,a=+a||0,f=b===-1?(a.toString().split(".")[1]||"").length:isNaN(b=Q(b))?2:b,b=c===void 0?e.decimalPoint:c,d=d===void 0?e.thousandsSep:d,e=a<0?"-":"",c=String(z(a=Q(a).toFixed(f))),g=c.length>3?c.length%3:0;return e+(g?c.substr(0,g)+d:"")+c.substr(g).replace(/(\d{3})(?=\d)/g,"$1"+d)+(f?b+Q(a-c).toFixed(f).slice(2):"")}function Ha(a,b){return Array((b||2)+1-String(a).length).join(0)+a}function Ma(a,b,c){var d=a[b];a[b]=function(){var a=Array.prototype.slice.call(arguments);a.unshift(d);
|
||||
return c.apply(this,a)}}function Ia(a,b){for(var c="{",d=!1,e,f,g,h,i,j=[];(c=a.indexOf(c))!==-1;){e=a.slice(0,c);if(d){f=e.split(":");g=f.shift().split(".");i=g.length;e=b;for(h=0;h<i;h++)e=e[g[h]];if(f.length)f=f.join(":"),g=/\.([0-9])/,h=L.lang,i=void 0,/f$/.test(f)?(i=(i=f.match(g))?i[1]:-1,e!==null&&(e=Ga(e,i,h.decimalPoint,f.indexOf(",")>-1?h.thousandsSep:""))):e=bb(f,e)}j.push(e);a=a.slice(c+1);c=(d=!d)?"}":"{"}j.push(a);return j.join("")}function lb(a){return V.pow(10,U(V.log(a)/V.LN10))}
|
||||
function mb(a,b,c,d){var e,c=p(c,1);e=a/c;b||(b=[1,2,2.5,5,10],d&&d.allowDecimals===!1&&(c===1?b=[1,2,5,10]:c<=0.1&&(b=[1/c])));for(d=0;d<b.length;d++)if(a=b[d],e<=(b[d]+(b[d+1]||b[d]))/2)break;a*=c;return a}function nb(a,b){var c=a.length,d,e;for(e=0;e<c;e++)a[e].ss_i=e;a.sort(function(a,c){d=b(a,c);return d===0?a.ss_i-c.ss_i:d});for(e=0;e<c;e++)delete a[e].ss_i}function Na(a){for(var b=a.length,c=a[0];b--;)a[b]<c&&(c=a[b]);return c}function Ba(a){for(var b=a.length,c=a[0];b--;)a[b]>c&&(c=a[b]);
|
||||
return c}function Oa(a,b){for(var c in a)a[c]&&a[c]!==b&&a[c].destroy&&a[c].destroy(),delete a[c]}function Pa(a){cb||(cb=$(Ja));a&&cb.appendChild(a);cb.innerHTML=""}function ea(a){return parseFloat(a.toPrecision(14))}function Qa(a,b){va=p(a,b.animation)}function Ab(){var a=L.global.useUTC,b=a?"getUTC":"get",c=a?"setUTC":"set";Ra=(a&&L.global.timezoneOffset||0)*6E4;db=a?Date.UTC:function(a,b,c,g,h,i){return(new Date(a,b,p(c,1),p(g,0),p(h,0),p(i,0))).getTime()};ob=b+"Minutes";pb=b+"Hours";qb=b+"Day";
|
||||
Wa=b+"Date";eb=b+"Month";fb=b+"FullYear";Bb=c+"Minutes";Cb=c+"Hours";rb=c+"Date";Db=c+"Month";Eb=c+"FullYear"}function G(){}function Sa(a,b,c,d){this.axis=a;this.pos=b;this.type=c||"";this.isNew=!0;!c&&!d&&this.addLabel()}function ma(){this.init.apply(this,arguments)}function Xa(){this.init.apply(this,arguments)}function Fb(a,b,c,d,e){var f=a.chart.inverted;this.axis=a;this.isNegative=c;this.options=b;this.x=d;this.total=null;this.points={};this.stack=e;this.alignOptions={align:b.align||(f?c?"left":
|
||||
"right":"center"),verticalAlign:b.verticalAlign||(f?"middle":c?"bottom":"top"),y:p(b.y,f?4:c?14:-6),x:p(b.x,f?c?-6:6:0)};this.textAlign=b.textAlign||(f?c?"right":"left":"center")}var t,x=document,H=window,V=Math,v=V.round,U=V.floor,Ka=V.ceil,u=V.max,C=V.min,Q=V.abs,aa=V.cos,fa=V.sin,na=V.PI,Ca=na*2/360,wa=navigator.userAgent,Gb=H.opera,Aa=/msie/i.test(wa)&&!Gb,gb=x.documentMode===8,sb=/AppleWebKit/.test(wa),Ta=/Firefox/.test(wa),Hb=/(Mobile|Android|Windows Phone)/.test(wa),xa="http://www.w3.org/2000/svg",
|
||||
ba=!!x.createElementNS&&!!x.createElementNS(xa,"svg").createSVGRect,Nb=Ta&&parseInt(wa.split("Firefox/")[1],10)<4,ga=!ba&&!Aa&&!!x.createElement("canvas").getContext,Ya,Za,Ib={},tb=0,cb,L,bb,va,ub,B,oa,sa=function(){return t},W=[],$a=0,Ja="div",P="none",Ob=/^[0-9]+$/,Pb="stroke-width",db,Ra,ob,pb,qb,Wa,eb,fb,Bb,Cb,rb,Db,Eb,J={},S;H.Highcharts?oa(16,!0):S=H.Highcharts={};bb=function(a,b,c){if(!s(b)||isNaN(b))return"Invalid date";var a=p(a,"%Y-%m-%d %H:%M:%S"),d=new Date(b-Ra),e,f=d[pb](),g=d[qb](),
|
||||
h=d[Wa](),i=d[eb](),j=d[fb](),k=L.lang,l=k.weekdays,d=r({a:l[g].substr(0,3),A:l[g],d:Ha(h),e:h,b:k.shortMonths[i],B:k.months[i],m:Ha(i+1),y:j.toString().substr(2,2),Y:j,H:Ha(f),I:Ha(f%12||12),l:f%12||12,M:Ha(d[ob]()),p:f<12?"AM":"PM",P:f<12?"am":"pm",S:Ha(d.getSeconds()),L:Ha(v(b%1E3),3)},S.dateFormats);for(e in d)for(;a.indexOf("%"+e)!==-1;)a=a.replace("%"+e,typeof d[e]==="function"?d[e](b):d[e]);return c?a.substr(0,1).toUpperCase()+a.substr(1):a};oa=function(a,b){var c="Highcharts error #"+a+": www.highcharts.com/errors/"+
|
||||
a;if(b)throw c;H.console&&console.log(c)};B={millisecond:1,second:1E3,minute:6E4,hour:36E5,day:864E5,week:6048E5,month:26784E5,year:31556952E3};ub={init:function(a,b,c){var b=b||"",d=a.shift,e=b.indexOf("C")>-1,f=e?7:3,g,b=b.split(" "),c=[].concat(c),h,i,j=function(a){for(g=a.length;g--;)a[g]==="M"&&a.splice(g+1,0,a[g+1],a[g+2],a[g+1],a[g+2])};e&&(j(b),j(c));a.isArea&&(h=b.splice(b.length-6,6),i=c.splice(c.length-6,6));if(d<=c.length/f&&b.length===c.length)for(;d--;)c=[].concat(c).splice(0,f).concat(c);
|
||||
a.shift=0;if(b.length)for(a=c.length;b.length<a;)d=[].concat(b).splice(b.length-f,f),e&&(d[f-6]=d[f-2],d[f-5]=d[f-1]),b=b.concat(d);h&&(b=b.concat(h),c=c.concat(i));return[b,c]},step:function(a,b,c,d){var e=[],f=a.length;if(c===1)e=d;else if(f===b.length&&c<1)for(;f--;)d=parseFloat(a[f]),e[f]=isNaN(d)?a[f]:c*parseFloat(b[f]-d)+d;else e=b;return e}};(function(a){H.HighchartsAdapter=H.HighchartsAdapter||a&&{init:function(b){var c=a.fx,d=c.step,e,f=a.Tween,g=f&&f.propHooks;e=a.cssHooks.opacity;a.extend(a.easing,
|
||||
{easeOutQuad:function(a,b,c,d,e){return-d*(b/=e)*(b-2)+c}});a.each(["cur","_default","width","height","opacity"],function(a,b){var e=d,k;b==="cur"?e=c.prototype:b==="_default"&&f&&(e=g[b],b="set");(k=e[b])&&(e[b]=function(c){var d,c=a?c:this;if(c.prop!=="align")return d=c.elem,d.attr?d.attr(c.prop,b==="cur"?t:c.now):k.apply(this,arguments)})});Ma(e,"get",function(a,b,c){return b.attr?b.opacity||0:a.call(this,b,c)});e=function(a){var c=a.elem,d;if(!a.started)d=b.init(c,c.d,c.toD),a.start=d[0],a.end=
|
||||
d[1],a.started=!0;c.attr("d",b.step(a.start,a.end,a.pos,c.toD))};f?g.d={set:e}:d.d=e;this.each=Array.prototype.forEach?function(a,b){return Array.prototype.forEach.call(a,b)}:function(a,b){var c,d=a.length;for(c=0;c<d;c++)if(b.call(a[c],a[c],c,a)===!1)return c};a.fn.highcharts=function(){var a="Chart",b=arguments,c,d;if(this[0]){Fa(b[0])&&(a=b[0],b=Array.prototype.slice.call(b,1));c=b[0];if(c!==t)c.chart=c.chart||{},c.chart.renderTo=this[0],new S[a](c,b[1]),d=this;c===t&&(d=W[F(this[0],"data-highcharts-chart")])}return d}},
|
||||
getScript:a.getScript,inArray:a.inArray,adapterRun:function(b,c){return a(b)[c]()},grep:a.grep,map:function(a,c){for(var d=[],e=0,f=a.length;e<f;e++)d[e]=c.call(a[e],a[e],e,a);return d},offset:function(b){return a(b).offset()},addEvent:function(b,c,d){a(b).bind(c,d)},removeEvent:function(b,c,d){var e=x.removeEventListener?"removeEventListener":"detachEvent";x[e]&&b&&!b[e]&&(b[e]=function(){});a(b).unbind(c,d)},fireEvent:function(b,c,d,e){var f=a.Event(c),g="detached"+c,h;!Aa&&d&&(delete d.layerX,
|
||||
delete d.layerY,delete d.returnValue);r(f,d);b[c]&&(b[g]=b[c],b[c]=null);a.each(["preventDefault","stopPropagation"],function(a,b){var c=f[b];f[b]=function(){try{c.call(f)}catch(a){b==="preventDefault"&&(h=!0)}}});a(b).trigger(f);b[g]&&(b[c]=b[g],b[g]=null);e&&!f.isDefaultPrevented()&&!h&&e(f)},washMouseEvent:function(a){var c=a.originalEvent||a;if(c.pageX===t)c.pageX=a.pageX,c.pageY=a.pageY;return c},animate:function(b,c,d){var e=a(b);if(!b.style)b.style={};if(c.d)b.toD=c.d,c.d=1;e.stop();c.opacity!==
|
||||
t&&b.attr&&(c.opacity+="px");e.animate(c,d)},stop:function(b){a(b).stop()}}})(H.jQuery);var T=H.HighchartsAdapter,M=T||{};T&&T.init.call(T,ub);var hb=M.adapterRun,Qb=M.getScript,Da=M.inArray,q=M.each,vb=M.grep,Rb=M.offset,Ua=M.map,N=M.addEvent,X=M.removeEvent,K=M.fireEvent,Sb=M.washMouseEvent,ib=M.animate,ab=M.stop,M={enabled:!0,x:0,y:15,style:{color:"#606060",cursor:"default",fontSize:"11px"}};L={colors:"#7cb5ec,#434348,#90ed7d,#f7a35c,#8085e9,#f15c80,#e4d354,#8085e8,#8d4653,#91e8e1".split(","),
|
||||
symbols:["circle","diamond","square","triangle","triangle-down"],lang:{loading:"Loading...",months:"January,February,March,April,May,June,July,August,September,October,November,December".split(","),shortMonths:"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(","),weekdays:"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(","),decimalPoint:".",numericSymbols:"k,M,G,T,P,E".split(","),resetZoom:"Reset zoom",resetZoomTitle:"Reset zoom level 1:1",thousandsSep:","},global:{useUTC:!0,
|
||||
canvasToolsURL:"http://code.highcharts.com/4.0.3/modules/canvas-tools.js",VMLRadialGradientURL:"http://code.highcharts.com/4.0.3/gfx/vml-radial-gradient.png"},chart:{borderColor:"#4572A7",borderRadius:0,defaultSeriesType:"line",ignoreHiddenSeries:!0,spacing:[10,10,15,10],backgroundColor:"#FFFFFF",plotBorderColor:"#C0C0C0",resetZoomButton:{theme:{zIndex:20},position:{align:"right",x:-10,y:10}}},title:{text:"Chart title",align:"center",margin:15,style:{color:"#333333",fontSize:"18px"}},subtitle:{text:"",
|
||||
align:"center",style:{color:"#555555"}},plotOptions:{line:{allowPointSelect:!1,showCheckbox:!1,animation:{duration:1E3},events:{},lineWidth:2,marker:{lineWidth:0,radius:4,lineColor:"#FFFFFF",states:{hover:{enabled:!0,lineWidthPlus:1,radiusPlus:2},select:{fillColor:"#FFFFFF",lineColor:"#000000",lineWidth:2}}},point:{events:{}},dataLabels:w(M,{align:"center",enabled:!1,formatter:function(){return this.y===null?"":Ga(this.y,-1)},verticalAlign:"bottom",y:0}),cropThreshold:300,pointRange:0,states:{hover:{lineWidthPlus:1,
|
||||
marker:{},halo:{size:10,opacity:0.25}},select:{marker:{}}},stickyTracking:!0,turboThreshold:1E3}},labels:{style:{position:"absolute",color:"#3E576F"}},legend:{enabled:!0,align:"center",layout:"horizontal",labelFormatter:function(){return this.name},borderColor:"#909090",borderRadius:0,navigation:{activeColor:"#274b6d",inactiveColor:"#CCC"},shadow:!1,itemStyle:{color:"#333333",fontSize:"12px",fontWeight:"bold"},itemHoverStyle:{color:"#000"},itemHiddenStyle:{color:"#CCC"},itemCheckboxStyle:{position:"absolute",
|
||||
width:"13px",height:"13px"},symbolPadding:5,verticalAlign:"bottom",x:0,y:0,title:{style:{fontWeight:"bold"}}},loading:{labelStyle:{fontWeight:"bold",position:"relative",top:"45%"},style:{position:"absolute",backgroundColor:"white",opacity:0.5,textAlign:"center"}},tooltip:{enabled:!0,animation:ba,backgroundColor:"rgba(249, 249, 249, .85)",borderWidth:1,borderRadius:3,dateTimeLabelFormats:{millisecond:"%A, %b %e, %H:%M:%S.%L",second:"%A, %b %e, %H:%M:%S",minute:"%A, %b %e, %H:%M",hour:"%A, %b %e, %H:%M",
|
||||
day:"%A, %b %e, %Y",week:"Week from %A, %b %e, %Y",month:"%B %Y",year:"%Y"},headerFormat:'<span style="font-size: 10px">{point.key}</span><br/>',pointFormat:'<span style="color:{series.color}">●</span> {series.name}: <b>{point.y}</b><br/>',shadow:!0,snap:Hb?25:10,style:{color:"#333333",cursor:"default",fontSize:"12px",padding:"8px",whiteSpace:"nowrap"}},credits:{enabled:!0,text:"Highcharts.com",href:"http://www.highcharts.com",position:{align:"right",x:-10,verticalAlign:"bottom",y:-5},style:{cursor:"pointer",
|
||||
color:"#909090",fontSize:"9px"}}};var ca=L.plotOptions,T=ca.line;Ab();var Tb=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]?(?:\.[0-9]+)?)\s*\)/,Ub=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/,Vb=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/,ya=function(a){var b=[],c,d;(function(a){a&&a.stops?d=Ua(a.stops,function(a){return ya(a[1])}):(c=Tb.exec(a))?b=[z(c[1]),z(c[2]),z(c[3]),parseFloat(c[4],10)]:(c=Ub.exec(a))?b=[z(c[1],16),z(c[2],16),z(c[3],
|
||||
16),1]:(c=Vb.exec(a))&&(b=[z(c[1]),z(c[2]),z(c[3]),1])})(a);return{get:function(c){var f;d?(f=w(a),f.stops=[].concat(f.stops),q(d,function(a,b){f.stops[b]=[f.stops[b][0],a.get(c)]})):f=b&&!isNaN(b[0])?c==="rgb"?"rgb("+b[0]+","+b[1]+","+b[2]+")":c==="a"?b[3]:"rgba("+b.join(",")+")":a;return f},brighten:function(a){if(d)q(d,function(b){b.brighten(a)});else if(ia(a)&&a!==0){var c;for(c=0;c<3;c++)b[c]+=z(a*255),b[c]<0&&(b[c]=0),b[c]>255&&(b[c]=255)}return this},rgba:b,setOpacity:function(a){b[3]=a;return this}}};
|
||||
G.prototype={opacity:1,textProps:"fontSize,fontWeight,fontFamily,color,lineHeight,width,textDecoration,textShadow,HcTextStroke".split(","),init:function(a,b){this.element=b==="span"?$(b):x.createElementNS(xa,b);this.renderer=a},animate:function(a,b,c){b=p(b,va,!0);ab(this);if(b){b=w(b,{});if(c)b.complete=c;ib(this,a,b)}else this.attr(a),c&&c();return this},colorGradient:function(a,b,c){var d=this.renderer,e,f,g,h,i,j,k,l,m,n,o=[];a.linearGradient?f="linearGradient":a.radialGradient&&(f="radialGradient");
|
||||
if(f){g=a[f];h=d.gradients;j=a.stops;m=c.radialReference;La(g)&&(a[f]=g={x1:g[0],y1:g[1],x2:g[2],y2:g[3],gradientUnits:"userSpaceOnUse"});f==="radialGradient"&&m&&!s(g.gradientUnits)&&(g=w(g,{cx:m[0]-m[2]/2+g.cx*m[2],cy:m[1]-m[2]/2+g.cy*m[2],r:g.r*m[2],gradientUnits:"userSpaceOnUse"}));for(n in g)n!=="id"&&o.push(n,g[n]);for(n in j)o.push(j[n]);o=o.join(",");h[o]?a=h[o].attr("id"):(g.id=a="highcharts-"+tb++,h[o]=i=d.createElement(f).attr(g).add(d.defs),i.stops=[],q(j,function(a){a[1].indexOf("rgba")===
|
||||
0?(e=ya(a[1]),k=e.get("rgb"),l=e.get("a")):(k=a[1],l=1);a=d.createElement("stop").attr({offset:a[0],"stop-color":k,"stop-opacity":l}).add(i);i.stops.push(a)}));c.setAttribute(b,"url("+d.url+"#"+a+")")}},attr:function(a,b){var c,d,e=this.element,f,g=this,h;typeof a==="string"&&b!==t&&(c=a,a={},a[c]=b);if(typeof a==="string")g=(this[a+"Getter"]||this._defaultGetter).call(this,a,e);else{for(c in a){d=a[c];h=!1;this.symbolName&&/^(x|y|width|height|r|start|end|innerR|anchorX|anchorY)/.test(c)&&(f||(this.symbolAttr(a),
|
||||
f=!0),h=!0);if(this.rotation&&(c==="x"||c==="y"))this.doTransform=!0;h||(this[c+"Setter"]||this._defaultSetter).call(this,d,c,e);this.shadows&&/^(width|height|visibility|x|y|d|transform|cx|cy|r)$/.test(c)&&this.updateShadows(c,d)}if(this.doTransform)this.updateTransform(),this.doTransform=!1}return g},updateShadows:function(a,b){for(var c=this.shadows,d=c.length;d--;)c[d].setAttribute(a,a==="height"?u(b-(c[d].cutHeight||0),0):a==="d"?this.d:b)},addClass:function(a){var b=this.element,c=F(b,"class")||
|
||||
"";c.indexOf(a)===-1&&F(b,"class",c+" "+a);return this},symbolAttr:function(a){var b=this;q("x,y,r,start,end,width,height,innerR,anchorX,anchorY".split(","),function(c){b[c]=p(a[c],b[c])});b.attr({d:b.renderer.symbols[b.symbolName](b.x,b.y,b.width,b.height,b)})},clip:function(a){return this.attr("clip-path",a?"url("+this.renderer.url+"#"+a.id+")":P)},crisp:function(a){var b,c={},d,e=a.strokeWidth||this.strokeWidth||0;d=v(e)%2/2;a.x=U(a.x||this.x||0)+d;a.y=U(a.y||this.y||0)+d;a.width=U((a.width||this.width||
|
||||
0)-2*d);a.height=U((a.height||this.height||0)-2*d);a.strokeWidth=e;for(b in a)this[b]!==a[b]&&(this[b]=c[b]=a[b]);return c},css:function(a){var b=this.styles,c={},d=this.element,e,f,g="";e=!b;if(a&&a.color)a.fill=a.color;if(b)for(f in a)a[f]!==b[f]&&(c[f]=a[f],e=!0);if(e){e=this.textWidth=a&&a.width&&d.nodeName.toLowerCase()==="text"&&z(a.width);b&&(a=r(b,c));this.styles=a;e&&(ga||!ba&&this.renderer.forExport)&&delete a.width;if(Aa&&!ba)A(this.element,a);else{b=function(a,b){return"-"+b.toLowerCase()};
|
||||
for(f in a)g+=f.replace(/([A-Z])/g,b)+":"+a[f]+";";F(d,"style",g)}e&&this.added&&this.renderer.buildText(this)}return this},on:function(a,b){var c=this,d=c.element;Za&&a==="click"?(d.ontouchstart=function(a){c.touchEventFired=Date.now();a.preventDefault();b.call(d,a)},d.onclick=function(a){(wa.indexOf("Android")===-1||Date.now()-(c.touchEventFired||0)>1100)&&b.call(d,a)}):d["on"+a]=b;return this},setRadialReference:function(a){this.element.radialReference=a;return this},translate:function(a,b){return this.attr({translateX:a,
|
||||
translateY:b})},invert:function(){this.inverted=!0;this.updateTransform();return this},updateTransform:function(){var a=this.translateX||0,b=this.translateY||0,c=this.scaleX,d=this.scaleY,e=this.inverted,f=this.rotation,g=this.element;e&&(a+=this.attr("width"),b+=this.attr("height"));a=["translate("+a+","+b+")"];e?a.push("rotate(90) scale(-1,1)"):f&&a.push("rotate("+f+" "+(g.getAttribute("x")||0)+" "+(g.getAttribute("y")||0)+")");(s(c)||s(d))&&a.push("scale("+p(c,1)+" "+p(d,1)+")");a.length&&g.setAttribute("transform",
|
||||
a.join(" "))},toFront:function(){var a=this.element;a.parentNode.appendChild(a);return this},align:function(a,b,c){var d,e,f,g,h={};e=this.renderer;f=e.alignedObjects;if(a){if(this.alignOptions=a,this.alignByTranslate=b,!c||Fa(c))this.alignTo=d=c||"renderer",ka(f,this),f.push(this),c=null}else a=this.alignOptions,b=this.alignByTranslate,d=this.alignTo;c=p(c,e[d],e);d=a.align;e=a.verticalAlign;f=(c.x||0)+(a.x||0);g=(c.y||0)+(a.y||0);if(d==="right"||d==="center")f+=(c.width-(a.width||0))/{right:1,center:2}[d];
|
||||
h[b?"translateX":"x"]=v(f);if(e==="bottom"||e==="middle")g+=(c.height-(a.height||0))/({bottom:1,middle:2}[e]||1);h[b?"translateY":"y"]=v(g);this[this.placed?"animate":"attr"](h);this.placed=!0;this.alignAttr=h;return this},getBBox:function(){var a=this.bBox,b=this.renderer,c,d,e=this.rotation;c=this.element;var f=this.styles,g=e*Ca;d=this.textStr;var h;if(d===""||Ob.test(d))h="num."+d.toString().length+(f?"|"+f.fontSize+"|"+f.fontFamily:"");h&&(a=b.cache[h]);if(!a){if(c.namespaceURI===xa||b.forExport){try{a=
|
||||
c.getBBox?r({},c.getBBox()):{width:c.offsetWidth,height:c.offsetHeight}}catch(i){}if(!a||a.width<0)a={width:0,height:0}}else a=this.htmlGetBBox();if(b.isSVG){c=a.width;d=a.height;if(Aa&&f&&f.fontSize==="11px"&&d.toPrecision(3)==="16.9")a.height=d=14;if(e)a.width=Q(d*fa(g))+Q(c*aa(g)),a.height=Q(d*aa(g))+Q(c*fa(g))}this.bBox=a;h&&(b.cache[h]=a)}return a},show:function(a){return a&&this.element.namespaceURI===xa?(this.element.removeAttribute("visibility"),this):this.attr({visibility:a?"inherit":"visible"})},
|
||||
hide:function(){return this.attr({visibility:"hidden"})},fadeOut:function(a){var b=this;b.animate({opacity:0},{duration:a||150,complete:function(){b.hide()}})},add:function(a){var b=this.renderer,c=a||b,d=c.element||b.box,e=this.element,f=this.zIndex,g,h;if(a)this.parentGroup=a;this.parentInverted=a&&a.inverted;this.textStr!==void 0&&b.buildText(this);if(f)c.handleZ=!0,f=z(f);if(c.handleZ){a=d.childNodes;for(g=0;g<a.length;g++)if(b=a[g],c=F(b,"zIndex"),b!==e&&(z(c)>f||!s(f)&&s(c))){d.insertBefore(e,
|
||||
b);h=!0;break}}h||d.appendChild(e);this.added=!0;if(this.onAdd)this.onAdd();return this},safeRemoveChild:function(a){var b=a.parentNode;b&&b.removeChild(a)},destroy:function(){var a=this,b=a.element||{},c=a.shadows,d=a.renderer.isSVG&&b.nodeName==="SPAN"&&a.parentGroup,e,f;b.onclick=b.onmouseout=b.onmouseover=b.onmousemove=b.point=null;ab(a);if(a.clipPath)a.clipPath=a.clipPath.destroy();if(a.stops){for(f=0;f<a.stops.length;f++)a.stops[f]=a.stops[f].destroy();a.stops=null}a.safeRemoveChild(b);for(c&&
|
||||
q(c,function(b){a.safeRemoveChild(b)});d&&d.div&&d.div.childNodes.length===0;)b=d.parentGroup,a.safeRemoveChild(d.div),delete d.div,d=b;a.alignTo&&ka(a.renderer.alignedObjects,a);for(e in a)delete a[e];return null},shadow:function(a,b,c){var d=[],e,f,g=this.element,h,i,j,k;if(a){i=p(a.width,3);j=(a.opacity||0.15)/i;k=this.parentInverted?"(-1,-1)":"("+p(a.offsetX,1)+", "+p(a.offsetY,1)+")";for(e=1;e<=i;e++){f=g.cloneNode(0);h=i*2+1-2*e;F(f,{isShadow:"true",stroke:a.color||"black","stroke-opacity":j*
|
||||
e,"stroke-width":h,transform:"translate"+k,fill:P});if(c)F(f,"height",u(F(f,"height")-h,0)),f.cutHeight=h;b?b.element.appendChild(f):g.parentNode.insertBefore(f,g);d.push(f)}this.shadows=d}return this},xGetter:function(a){this.element.nodeName==="circle"&&(a={x:"cx",y:"cy"}[a]||a);return this._defaultGetter(a)},_defaultGetter:function(a){a=p(this[a],this.element?this.element.getAttribute(a):null,0);/^[\-0-9\.]+$/.test(a)&&(a=parseFloat(a));return a},dSetter:function(a,b,c){a&&a.join&&(a=a.join(" "));
|
||||
/(NaN| {2}|^$)/.test(a)&&(a="M 0 0");c.setAttribute(b,a);this[b]=a},dashstyleSetter:function(a){var b;if(a=a&&a.toLowerCase()){a=a.replace("shortdashdotdot","3,1,1,1,1,1,").replace("shortdashdot","3,1,1,1").replace("shortdot","1,1,").replace("shortdash","3,1,").replace("longdash","8,3,").replace(/dot/g,"1,3,").replace("dash","4,3,").replace(/,$/,"").replace("solid",1).split(",");for(b=a.length;b--;)a[b]=z(a[b])*this["stroke-width"];a=a.join(",");this.element.setAttribute("stroke-dasharray",a)}},alignSetter:function(a){this.element.setAttribute("text-anchor",
|
||||
{left:"start",center:"middle",right:"end"}[a])},opacitySetter:function(a,b,c){this[b]=a;c.setAttribute(b,a)},titleSetter:function(a){var b=this.element.getElementsByTagName("title")[0];b||(b=x.createElementNS(xa,"title"),this.element.appendChild(b));b.textContent=a},textSetter:function(a){if(a!==this.textStr)delete this.bBox,this.textStr=a,this.added&&this.renderer.buildText(this)},fillSetter:function(a,b,c){typeof a==="string"?c.setAttribute(b,a):a&&this.colorGradient(a,b,c)},zIndexSetter:function(a,
|
||||
b,c){c.setAttribute(b,a);this[b]=a},_defaultSetter:function(a,b,c){c.setAttribute(b,a)}};G.prototype.yGetter=G.prototype.xGetter;G.prototype.translateXSetter=G.prototype.translateYSetter=G.prototype.rotationSetter=G.prototype.verticalAlignSetter=G.prototype.scaleXSetter=G.prototype.scaleYSetter=function(a,b){this[b]=a;this.doTransform=!0};G.prototype["stroke-widthSetter"]=G.prototype.strokeSetter=function(a,b,c){this[b]=a;if(this.stroke&&this["stroke-width"])this.strokeWidth=this["stroke-width"],
|
||||
G.prototype.fillSetter.call(this,this.stroke,"stroke",c),c.setAttribute("stroke-width",this["stroke-width"]),this.hasStroke=!0;else if(b==="stroke-width"&&a===0&&this.hasStroke)c.removeAttribute("stroke"),this.hasStroke=!1};var ta=function(){this.init.apply(this,arguments)};ta.prototype={Element:G,init:function(a,b,c,d,e){var f=location,g,d=this.createElement("svg").attr({version:"1.1"}).css(this.getStyle(d));g=d.element;a.appendChild(g);a.innerHTML.indexOf("xmlns")===-1&&F(g,"xmlns",xa);this.isSVG=
|
||||
!0;this.box=g;this.boxWrapper=d;this.alignedObjects=[];this.url=(Ta||sb)&&x.getElementsByTagName("base").length?f.href.replace(/#.*?$/,"").replace(/([\('\)])/g,"\\$1").replace(/ /g,"%20"):"";this.createElement("desc").add().element.appendChild(x.createTextNode("Created with Highcharts 4.0.3"));this.defs=this.createElement("defs").add();this.forExport=e;this.gradients={};this.cache={};this.setSize(b,c,!1);var h;if(Ta&&a.getBoundingClientRect)this.subPixelFix=b=function(){A(a,{left:0,top:0});h=a.getBoundingClientRect();
|
||||
A(a,{left:Ka(h.left)-h.left+"px",top:Ka(h.top)-h.top+"px"})},b(),N(H,"resize",b)},getStyle:function(a){return this.style=r({fontFamily:'"Lucida Grande", "Lucida Sans Unicode", Arial, Helvetica, sans-serif',fontSize:"12px"},a)},isHidden:function(){return!this.boxWrapper.getBBox().width},destroy:function(){var a=this.defs;this.box=null;this.boxWrapper=this.boxWrapper.destroy();Oa(this.gradients||{});this.gradients=null;if(a)this.defs=a.destroy();this.subPixelFix&&X(H,"resize",this.subPixelFix);return this.alignedObjects=
|
||||
null},createElement:function(a){var b=new this.Element;b.init(this,a);return b},draw:function(){},buildText:function(a){for(var b=a.element,c=this,d=c.forExport,e=p(a.textStr,"").toString(),f=e.indexOf("<")!==-1,g=b.childNodes,h,i,j=F(b,"x"),k=a.styles,l=a.textWidth,m=k&&k.lineHeight,n=k&&k.HcTextStroke,o=g.length,Y=function(a){return m?z(m):c.fontMetrics(/(px|em)$/.test(a&&a.style.fontSize)?a.style.fontSize:k&&k.fontSize||c.style.fontSize||12,a).h};o--;)b.removeChild(g[o]);!f&&!n&&e.indexOf(" ")===
|
||||
-1?b.appendChild(x.createTextNode(e)):(h=/<.*style="([^"]+)".*>/,i=/<.*href="(http[^"]+)".*>/,l&&!a.added&&this.box.appendChild(b),e=f?e.replace(/<(b|strong)>/g,'<span style="font-weight:bold">').replace(/<(i|em)>/g,'<span style="font-style:italic">').replace(/<a/g,"<span").replace(/<\/(b|strong|i|em|a)>/g,"</span>").split(/<br.*?>/g):[e],e[e.length-1]===""&&e.pop(),q(e,function(e,f){var g,m=0,e=e.replace(/<span/g,"|||<span").replace(/<\/span>/g,"</span>|||");g=e.split("|||");q(g,function(e){if(e!==
|
||||
""||g.length===1){var n={},o=x.createElementNS(xa,"tspan"),p;h.test(e)&&(p=e.match(h)[1].replace(/(;| |^)color([ :])/,"$1fill$2"),F(o,"style",p));i.test(e)&&!d&&(F(o,"onclick",'location.href="'+e.match(i)[1]+'"'),A(o,{cursor:"pointer"}));e=(e.replace(/<(.|\n)*?>/g,"")||" ").replace(/</g,"<").replace(/>/g,">");if(e!==" "){o.appendChild(x.createTextNode(e));if(m)n.dx=0;else if(f&&j!==null)n.x=j;F(o,n);b.appendChild(o);!m&&f&&(!ba&&d&&A(o,{display:"block"}),F(o,"dy",Y(o)));if(l)for(var e=e.replace(/([^\^])-/g,
|
||||
"$1- ").split(" "),n=g.length>1||e.length>1&&k.whiteSpace!=="nowrap",q,E,s=k.HcHeight,u=[],t=Y(o),Kb=1;n&&(e.length||u.length);)delete a.bBox,q=a.getBBox(),E=q.width,!ba&&c.forExport&&(E=c.measureSpanWidth(o.firstChild.data,a.styles)),q=E>l,!q||e.length===1?(e=u,u=[],e.length&&(Kb++,s&&Kb*t>s?(e=["..."],a.attr("title",a.textStr)):(o=x.createElementNS(xa,"tspan"),F(o,{dy:t,x:j}),p&&F(o,"style",p),b.appendChild(o))),E>l&&(l=E)):(o.removeChild(o.firstChild),u.unshift(e.pop())),e.length&&o.appendChild(x.createTextNode(e.join(" ").replace(/- /g,
|
||||
"-")));m++}}})}))},button:function(a,b,c,d,e,f,g,h,i){var j=this.label(a,b,c,i,null,null,null,null,"button"),k=0,l,m,n,o,p,q,a={x1:0,y1:0,x2:0,y2:1},e=w({"stroke-width":1,stroke:"#CCCCCC",fill:{linearGradient:a,stops:[[0,"#FEFEFE"],[1,"#F6F6F6"]]},r:2,padding:5,style:{color:"black"}},e);n=e.style;delete e.style;f=w(e,{stroke:"#68A",fill:{linearGradient:a,stops:[[0,"#FFF"],[1,"#ACF"]]}},f);o=f.style;delete f.style;g=w(e,{stroke:"#68A",fill:{linearGradient:a,stops:[[0,"#9BD"],[1,"#CDF"]]}},g);p=g.style;
|
||||
delete g.style;h=w(e,{style:{color:"#CCC"}},h);q=h.style;delete h.style;N(j.element,Aa?"mouseover":"mouseenter",function(){k!==3&&j.attr(f).css(o)});N(j.element,Aa?"mouseout":"mouseleave",function(){k!==3&&(l=[e,f,g][k],m=[n,o,p][k],j.attr(l).css(m))});j.setState=function(a){(j.state=k=a)?a===2?j.attr(g).css(p):a===3&&j.attr(h).css(q):j.attr(e).css(n)};return j.on("click",function(){k!==3&&d.call(j)}).attr(e).css(r({cursor:"default"},n))},crispLine:function(a,b){a[1]===a[4]&&(a[1]=a[4]=v(a[1])-b%
|
||||
2/2);a[2]===a[5]&&(a[2]=a[5]=v(a[2])+b%2/2);return a},path:function(a){var b={fill:P};La(a)?b.d=a:da(a)&&r(b,a);return this.createElement("path").attr(b)},circle:function(a,b,c){a=da(a)?a:{x:a,y:b,r:c};b=this.createElement("circle");b.xSetter=function(a){this.element.setAttribute("cx",a)};b.ySetter=function(a){this.element.setAttribute("cy",a)};return b.attr(a)},arc:function(a,b,c,d,e,f){if(da(a))b=a.y,c=a.r,d=a.innerR,e=a.start,f=a.end,a=a.x;a=this.symbol("arc",a||0,b||0,c||0,c||0,{innerR:d||0,start:e||
|
||||
0,end:f||0});a.r=c;return a},rect:function(a,b,c,d,e,f){var e=da(a)?a.r:e,g=this.createElement("rect"),a=da(a)?a:a===t?{}:{x:a,y:b,width:u(c,0),height:u(d,0)};if(f!==t)a.strokeWidth=f,a=g.crisp(a);if(e)a.r=e;g.rSetter=function(a){F(this.element,{rx:a,ry:a})};return g.attr(a)},setSize:function(a,b,c){var d=this.alignedObjects,e=d.length;this.width=a;this.height=b;for(this.boxWrapper[p(c,!0)?"animate":"attr"]({width:a,height:b});e--;)d[e].align()},g:function(a){var b=this.createElement("g");return s(a)?
|
||||
b.attr({"class":"highcharts-"+a}):b},image:function(a,b,c,d,e){var f={preserveAspectRatio:P};arguments.length>1&&r(f,{x:b,y:c,width:d,height:e});f=this.createElement("image").attr(f);f.element.setAttributeNS?f.element.setAttributeNS("http://www.w3.org/1999/xlink","href",a):f.element.setAttribute("hc-svg-href",a);return f},symbol:function(a,b,c,d,e,f){var g,h=this.symbols[a],h=h&&h(v(b),v(c),d,e,f),i=/^url\((.*?)\)$/,j,k;if(h)g=this.path(h),r(g,{symbolName:a,x:b,y:c,width:d,height:e}),f&&r(g,f);else if(i.test(a))k=
|
||||
function(a,b){a.element&&(a.attr({width:b[0],height:b[1]}),a.alignByTranslate||a.translate(v((d-b[0])/2),v((e-b[1])/2)))},j=a.match(i)[1],a=Ib[j],g=this.image(j).attr({x:b,y:c}),g.isImg=!0,a?k(g,a):(g.attr({width:0,height:0}),$("img",{onload:function(){k(g,Ib[j]=[this.width,this.height])},src:j}));return g},symbols:{circle:function(a,b,c,d){var e=0.166*c;return["M",a+c/2,b,"C",a+c+e,b,a+c+e,b+d,a+c/2,b+d,"C",a-e,b+d,a-e,b,a+c/2,b,"Z"]},square:function(a,b,c,d){return["M",a,b,"L",a+c,b,a+c,b+d,a,b+
|
||||
d,"Z"]},triangle:function(a,b,c,d){return["M",a+c/2,b,"L",a+c,b+d,a,b+d,"Z"]},"triangle-down":function(a,b,c,d){return["M",a,b,"L",a+c,b,a+c/2,b+d,"Z"]},diamond:function(a,b,c,d){return["M",a+c/2,b,"L",a+c,b+d/2,a+c/2,b+d,a,b+d/2,"Z"]},arc:function(a,b,c,d,e){var f=e.start,c=e.r||c||d,g=e.end-0.001,d=e.innerR,h=e.open,i=aa(f),j=fa(f),k=aa(g),g=fa(g),e=e.end-f<na?0:1;return["M",a+c*i,b+c*j,"A",c,c,0,e,1,a+c*k,b+c*g,h?"M":"L",a+d*k,b+d*g,"A",d,d,0,e,0,a+d*i,b+d*j,h?"":"Z"]},callout:function(a,b,c,d,
|
||||
e){var f=C(e&&e.r||0,c,d),g=f+6,h=e&&e.anchorX,i=e&&e.anchorY,e=v(e.strokeWidth||0)%2/2;a+=e;b+=e;e=["M",a+f,b,"L",a+c-f,b,"C",a+c,b,a+c,b,a+c,b+f,"L",a+c,b+d-f,"C",a+c,b+d,a+c,b+d,a+c-f,b+d,"L",a+f,b+d,"C",a,b+d,a,b+d,a,b+d-f,"L",a,b+f,"C",a,b,a,b,a+f,b];h&&h>c&&i>b+g&&i<b+d-g?e.splice(13,3,"L",a+c,i-6,a+c+6,i,a+c,i+6,a+c,b+d-f):h&&h<0&&i>b+g&&i<b+d-g?e.splice(33,3,"L",a,i+6,a-6,i,a,i-6,a,b+f):i&&i>d&&h>a+g&&h<a+c-g?e.splice(23,3,"L",h+6,b+d,h,b+d+6,h-6,b+d,a+f,b+d):i&&i<0&&h>a+g&&h<a+c-g&&e.splice(3,
|
||||
3,"L",h-6,b,h,b-6,h+6,b,c-f,b);return e}},clipRect:function(a,b,c,d){var e="highcharts-"+tb++,f=this.createElement("clipPath").attr({id:e}).add(this.defs),a=this.rect(a,b,c,d,0).add(f);a.id=e;a.clipPath=f;return a},text:function(a,b,c,d){var e=ga||!ba&&this.forExport,f={};if(d&&!this.forExport)return this.html(a,b,c);f.x=Math.round(b||0);if(c)f.y=Math.round(c);if(a||a===0)f.text=a;a=this.createElement("text").attr(f);e&&a.css({position:"absolute"});if(!d)a.xSetter=function(a,b,c){var d=c.getElementsByTagName("tspan"),
|
||||
e,f=c.getAttribute(b),m;for(m=0;m<d.length;m++)e=d[m],e.getAttribute(b)===f&&e.setAttribute(b,a);c.setAttribute(b,a)};return a},fontMetrics:function(a,b){a=a||this.style.fontSize;if(b&&H.getComputedStyle)b=b.element||b,a=H.getComputedStyle(b,"").fontSize;var a=/px/.test(a)?z(a):/em/.test(a)?parseFloat(a)*12:12,c=a<24?a+4:v(a*1.2),d=v(c*0.8);return{h:c,b:d,f:a}},label:function(a,b,c,d,e,f,g,h,i){function j(){var a,b;a=o.element.style;E=(u===void 0||wb===void 0||n.styles.textAlign)&&o.textStr&&o.getBBox();
|
||||
n.width=(u||E.width||0)+2*D+jb;n.height=(wb||E.height||0)+2*D;R=D+m.fontMetrics(a&&a.fontSize,o).b;if(z){if(!p)a=v(-I*D),b=h?-R:0,n.box=p=d?m.symbol(d,a,b,n.width,n.height,y):m.rect(a,b,n.width,n.height,0,y[Pb]),p.attr("fill",P).add(n);p.isImg||p.attr(r({width:v(n.width),height:v(n.height)},y));y=null}}function k(){var a=n.styles,a=a&&a.textAlign,b=jb+D*(1-I),c;c=h?0:R;if(s(u)&&E&&(a==="center"||a==="right"))b+={center:0.5,right:1}[a]*(u-E.width);if(b!==o.x||c!==o.y)o.attr("x",b),c!==t&&o.attr("y",
|
||||
c);o.x=b;o.y=c}function l(a,b){p?p.attr(a,b):y[a]=b}var m=this,n=m.g(i),o=m.text("",0,0,g).attr({zIndex:1}),p,E,I=0,D=3,jb=0,u,wb,xb,x,Jb=0,y={},R,z;n.onAdd=function(){o.add(n);n.attr({text:a||"",x:b,y:c});p&&s(e)&&n.attr({anchorX:e,anchorY:f})};n.widthSetter=function(a){u=a};n.heightSetter=function(a){wb=a};n.paddingSetter=function(a){s(a)&&a!==D&&(D=a,k())};n.paddingLeftSetter=function(a){s(a)&&a!==jb&&(jb=a,k())};n.alignSetter=function(a){I={left:0,center:0.5,right:1}[a]};n.textSetter=function(a){a!==
|
||||
t&&o.textSetter(a);j();k()};n["stroke-widthSetter"]=function(a,b){a&&(z=!0);Jb=a%2/2;l(b,a)};n.strokeSetter=n.fillSetter=n.rSetter=function(a,b){b==="fill"&&a&&(z=!0);l(b,a)};n.anchorXSetter=function(a,b){e=a;l(b,a+Jb-xb)};n.anchorYSetter=function(a,b){f=a;l(b,a-x)};n.xSetter=function(a){n.x=a;I&&(a-=I*((u||E.width)+D));xb=v(a);n.attr("translateX",xb)};n.ySetter=function(a){x=n.y=v(a);n.attr("translateY",x)};var C=n.css;return r(n,{css:function(a){if(a){var b={},a=w(a);q(n.textProps,function(c){a[c]!==
|
||||
t&&(b[c]=a[c],delete a[c])});o.css(b)}return C.call(n,a)},getBBox:function(){return{width:E.width+2*D,height:E.height+2*D,x:E.x-D,y:E.y-D}},shadow:function(a){p&&p.shadow(a);return n},destroy:function(){X(n.element,"mouseenter");X(n.element,"mouseleave");o&&(o=o.destroy());p&&(p=p.destroy());G.prototype.destroy.call(n);n=m=j=k=l=null}})}};Ya=ta;r(G.prototype,{htmlCss:function(a){var b=this.element;if(b=a&&b.tagName==="SPAN"&&a.width)delete a.width,this.textWidth=b,this.updateTransform();this.styles=
|
||||
r(this.styles,a);A(this.element,a);return this},htmlGetBBox:function(){var a=this.element,b=this.bBox;if(!b){if(a.nodeName==="text")a.style.position="absolute";b=this.bBox={x:a.offsetLeft,y:a.offsetTop,width:a.offsetWidth,height:a.offsetHeight}}return b},htmlUpdateTransform:function(){if(this.added){var a=this.renderer,b=this.element,c=this.translateX||0,d=this.translateY||0,e=this.x||0,f=this.y||0,g=this.textAlign||"left",h={left:0,center:0.5,right:1}[g],i=this.shadows;A(b,{marginLeft:c,marginTop:d});
|
||||
i&&q(i,function(a){A(a,{marginLeft:c+1,marginTop:d+1})});this.inverted&&q(b.childNodes,function(c){a.invertChild(c,b)});if(b.tagName==="SPAN"){var j=this.rotation,k,l=z(this.textWidth),m=[j,g,b.innerHTML,this.textWidth].join(",");if(m!==this.cTT){k=a.fontMetrics(b.style.fontSize).b;s(j)&&this.setSpanRotation(j,h,k);i=p(this.elemWidth,b.offsetWidth);if(i>l&&/[ \-]/.test(b.textContent||b.innerText))A(b,{width:l+"px",display:"block",whiteSpace:"normal"}),i=l;this.getSpanCorrection(i,k,h,j,g)}A(b,{left:e+
|
||||
(this.xCorr||0)+"px",top:f+(this.yCorr||0)+"px"});if(sb)k=b.offsetHeight;this.cTT=m}}else this.alignOnAdd=!0},setSpanRotation:function(a,b,c){var d={},e=Aa?"-ms-transform":sb?"-webkit-transform":Ta?"MozTransform":Gb?"-o-transform":"";d[e]=d.transform="rotate("+a+"deg)";d[e+(Ta?"Origin":"-origin")]=d.transformOrigin=b*100+"% "+c+"px";A(this.element,d)},getSpanCorrection:function(a,b,c){this.xCorr=-a*c;this.yCorr=-b}});r(ta.prototype,{html:function(a,b,c){var d=this.createElement("span"),e=d.element,
|
||||
f=d.renderer;d.textSetter=function(a){a!==e.innerHTML&&delete this.bBox;e.innerHTML=this.textStr=a};d.xSetter=d.ySetter=d.alignSetter=d.rotationSetter=function(a,b){b==="align"&&(b="textAlign");d[b]=a;d.htmlUpdateTransform()};d.attr({text:a,x:v(b),y:v(c)}).css({position:"absolute",whiteSpace:"nowrap",fontFamily:this.style.fontFamily,fontSize:this.style.fontSize});d.css=d.htmlCss;if(f.isSVG)d.add=function(a){var b,c=f.box.parentNode,j=[];if(this.parentGroup=a){if(b=a.div,!b){for(;a;)j.push(a),a=a.parentGroup;
|
||||
q(j.reverse(),function(a){var d;b=a.div=a.div||$(Ja,{className:F(a.element,"class")},{position:"absolute",left:(a.translateX||0)+"px",top:(a.translateY||0)+"px"},b||c);d=b.style;r(a,{translateXSetter:function(b,c){d.left=b+"px";a[c]=b;a.doTransform=!0},translateYSetter:function(b,c){d.top=b+"px";a[c]=b;a.doTransform=!0},visibilitySetter:function(a,b){d[b]=a}})})}}else b=c;b.appendChild(e);d.added=!0;d.alignOnAdd&&d.htmlUpdateTransform();return d};return d}});var Z;if(!ba&&!ga){Z={init:function(a,
|
||||
b){var c=["<",b,' filled="f" stroked="f"'],d=["position: ","absolute",";"],e=b===Ja;(b==="shape"||e)&&d.push("left:0;top:0;width:1px;height:1px;");d.push("visibility: ",e?"hidden":"visible");c.push(' style="',d.join(""),'"/>');if(b)c=e||b==="span"||b==="img"?c.join(""):a.prepVML(c),this.element=$(c);this.renderer=a},add:function(a){var b=this.renderer,c=this.element,d=b.box,d=a?a.element||a:d;a&&a.inverted&&b.invertChild(c,d);d.appendChild(c);this.added=!0;this.alignOnAdd&&!this.deferUpdateTransform&&
|
||||
this.updateTransform();if(this.onAdd)this.onAdd();return this},updateTransform:G.prototype.htmlUpdateTransform,setSpanRotation:function(){var a=this.rotation,b=aa(a*Ca),c=fa(a*Ca);A(this.element,{filter:a?["progid:DXImageTransform.Microsoft.Matrix(M11=",b,", M12=",-c,", M21=",c,", M22=",b,", sizingMethod='auto expand')"].join(""):P})},getSpanCorrection:function(a,b,c,d,e){var f=d?aa(d*Ca):1,g=d?fa(d*Ca):0,h=p(this.elemHeight,this.element.offsetHeight),i;this.xCorr=f<0&&-a;this.yCorr=g<0&&-h;i=f*g<
|
||||
0;this.xCorr+=g*b*(i?1-c:c);this.yCorr-=f*b*(d?i?c:1-c:1);e&&e!=="left"&&(this.xCorr-=a*c*(f<0?-1:1),d&&(this.yCorr-=h*c*(g<0?-1:1)),A(this.element,{textAlign:e}))},pathToVML:function(a){for(var b=a.length,c=[];b--;)if(ia(a[b]))c[b]=v(a[b]*10)-5;else if(a[b]==="Z")c[b]="x";else if(c[b]=a[b],a.isArc&&(a[b]==="wa"||a[b]==="at"))c[b+5]===c[b+7]&&(c[b+7]+=a[b+7]>a[b+5]?1:-1),c[b+6]===c[b+8]&&(c[b+8]+=a[b+8]>a[b+6]?1:-1);return c.join(" ")||"x"},clip:function(a){var b=this,c;a?(c=a.members,ka(c,b),c.push(b),
|
||||
b.destroyClip=function(){ka(c,b)},a=a.getCSS(b)):(b.destroyClip&&b.destroyClip(),a={clip:gb?"inherit":"rect(auto)"});return b.css(a)},css:G.prototype.htmlCss,safeRemoveChild:function(a){a.parentNode&&Pa(a)},destroy:function(){this.destroyClip&&this.destroyClip();return G.prototype.destroy.apply(this)},on:function(a,b){this.element["on"+a]=function(){var a=H.event;a.target=a.srcElement;b(a)};return this},cutOffPath:function(a,b){var c,a=a.split(/[ ,]/);c=a.length;if(c===9||c===11)a[c-4]=a[c-2]=z(a[c-
|
||||
2])-10*b;return a.join(" ")},shadow:function(a,b,c){var d=[],e,f=this.element,g=this.renderer,h,i=f.style,j,k=f.path,l,m,n,o;k&&typeof k.value!=="string"&&(k="x");m=k;if(a){n=p(a.width,3);o=(a.opacity||0.15)/n;for(e=1;e<=3;e++){l=n*2+1-2*e;c&&(m=this.cutOffPath(k.value,l+0.5));j=['<shape isShadow="true" strokeweight="',l,'" filled="false" path="',m,'" coordsize="10 10" style="',f.style.cssText,'" />'];h=$(g.prepVML(j),null,{left:z(i.left)+p(a.offsetX,1),top:z(i.top)+p(a.offsetY,1)});if(c)h.cutOff=
|
||||
l+1;j=['<stroke color="',a.color||"black",'" opacity="',o*e,'"/>'];$(g.prepVML(j),null,null,h);b?b.element.appendChild(h):f.parentNode.insertBefore(h,f);d.push(h)}this.shadows=d}return this},updateShadows:sa,setAttr:function(a,b){gb?this.element[a]=b:this.element.setAttribute(a,b)},classSetter:function(a){this.element.className=a},dashstyleSetter:function(a,b,c){(c.getElementsByTagName("stroke")[0]||$(this.renderer.prepVML(["<stroke/>"]),null,null,c))[b]=a||"solid";this[b]=a},dSetter:function(a,b,
|
||||
c){var d=this.shadows,a=a||[];this.d=a.join&&a.join(" ");c.path=a=this.pathToVML(a);if(d)for(c=d.length;c--;)d[c].path=d[c].cutOff?this.cutOffPath(a,d[c].cutOff):a;this.setAttr(b,a)},fillSetter:function(a,b,c){var d=c.nodeName;if(d==="SPAN")c.style.color=a;else if(d!=="IMG")c.filled=a!==P,this.setAttr("fillcolor",this.renderer.color(a,c,b,this))},opacitySetter:sa,rotationSetter:function(a,b,c){c=c.style;this[b]=c[b]=a;c.left=-v(fa(a*Ca)+1)+"px";c.top=v(aa(a*Ca))+"px"},strokeSetter:function(a,b,c){this.setAttr("strokecolor",
|
||||
this.renderer.color(a,c,b))},"stroke-widthSetter":function(a,b,c){c.stroked=!!a;this[b]=a;ia(a)&&(a+="px");this.setAttr("strokeweight",a)},titleSetter:function(a,b){this.setAttr(b,a)},visibilitySetter:function(a,b,c){a==="inherit"&&(a="visible");this.shadows&&q(this.shadows,function(c){c.style[b]=a});c.nodeName==="DIV"&&(a=a==="hidden"?"-999em":0,gb||(c.style[b]=a?"visible":"hidden"),b="top");c.style[b]=a},xSetter:function(a,b,c){this[b]=a;b==="x"?b="left":b==="y"&&(b="top");this.updateClipping?(this[b]=
|
||||
a,this.updateClipping()):c.style[b]=a},zIndexSetter:function(a,b,c){c.style[b]=a}};S.VMLElement=Z=la(G,Z);Z.prototype.ySetter=Z.prototype.widthSetter=Z.prototype.heightSetter=Z.prototype.xSetter;var ha={Element:Z,isIE8:wa.indexOf("MSIE 8.0")>-1,init:function(a,b,c,d){var e;this.alignedObjects=[];d=this.createElement(Ja).css(r(this.getStyle(d),{position:"relative"}));e=d.element;a.appendChild(d.element);this.isVML=!0;this.box=e;this.boxWrapper=d;this.cache={};this.setSize(b,c,!1);if(!x.namespaces.hcv){x.namespaces.add("hcv",
|
||||
"urn:schemas-microsoft-com:vml");try{x.createStyleSheet().cssText="hcv\\:fill, hcv\\:path, hcv\\:shape, hcv\\:stroke{ behavior:url(#default#VML); display: inline-block; } "}catch(f){x.styleSheets[0].cssText+="hcv\\:fill, hcv\\:path, hcv\\:shape, hcv\\:stroke{ behavior:url(#default#VML); display: inline-block; } "}}},isHidden:function(){return!this.box.offsetWidth},clipRect:function(a,b,c,d){var e=this.createElement(),f=da(a);return r(e,{members:[],left:(f?a.x:a)+1,top:(f?a.y:b)+1,width:(f?a.width:
|
||||
c)-1,height:(f?a.height:d)-1,getCSS:function(a){var b=a.element,c=b.nodeName,a=a.inverted,d=this.top-(c==="shape"?b.offsetTop:0),e=this.left,b=e+this.width,f=d+this.height,d={clip:"rect("+v(a?e:d)+"px,"+v(a?f:b)+"px,"+v(a?b:f)+"px,"+v(a?d:e)+"px)"};!a&&gb&&c==="DIV"&&r(d,{width:b+"px",height:f+"px"});return d},updateClipping:function(){q(e.members,function(a){a.element&&a.css(e.getCSS(a))})}})},color:function(a,b,c,d){var e=this,f,g=/^rgba/,h,i,j=P;a&&a.linearGradient?i="gradient":a&&a.radialGradient&&
|
||||
(i="pattern");if(i){var k,l,m=a.linearGradient||a.radialGradient,n,o,p,E,I,D="",a=a.stops,u,s=[],t=function(){h=['<fill colors="'+s.join(",")+'" opacity="',p,'" o:opacity2="',o,'" type="',i,'" ',D,'focus="100%" method="any" />'];$(e.prepVML(h),null,null,b)};n=a[0];u=a[a.length-1];n[0]>0&&a.unshift([0,n[1]]);u[0]<1&&a.push([1,u[1]]);q(a,function(a,b){g.test(a[1])?(f=ya(a[1]),k=f.get("rgb"),l=f.get("a")):(k=a[1],l=1);s.push(a[0]*100+"% "+k);b?(p=l,E=k):(o=l,I=k)});if(c==="fill")if(i==="gradient")c=
|
||||
m.x1||m[0]||0,a=m.y1||m[1]||0,n=m.x2||m[2]||0,m=m.y2||m[3]||0,D='angle="'+(90-V.atan((m-a)/(n-c))*180/na)+'"',t();else{var j=m.r,r=j*2,v=j*2,x=m.cx,y=m.cy,R=b.radialReference,w,j=function(){R&&(w=d.getBBox(),x+=(R[0]-w.x)/w.width-0.5,y+=(R[1]-w.y)/w.height-0.5,r*=R[2]/w.width,v*=R[2]/w.height);D='src="'+L.global.VMLRadialGradientURL+'" size="'+r+","+v+'" origin="0.5,0.5" position="'+x+","+y+'" color2="'+I+'" ';t()};d.added?j():d.onAdd=j;j=E}else j=k}else if(g.test(a)&&b.tagName!=="IMG")f=ya(a),h=
|
||||
["<",c,' opacity="',f.get("a"),'"/>'],$(this.prepVML(h),null,null,b),j=f.get("rgb");else{j=b.getElementsByTagName(c);if(j.length)j[0].opacity=1,j[0].type="solid";j=a}return j},prepVML:function(a){var b=this.isIE8,a=a.join("");b?(a=a.replace("/>",' xmlns="urn:schemas-microsoft-com:vml" />'),a=a.indexOf('style="')===-1?a.replace("/>",' style="display:inline-block;behavior:url(#default#VML);" />'):a.replace('style="','style="display:inline-block;behavior:url(#default#VML);')):a=a.replace("<","<hcv:");
|
||||
return a},text:ta.prototype.html,path:function(a){var b={coordsize:"10 10"};La(a)?b.d=a:da(a)&&r(b,a);return this.createElement("shape").attr(b)},circle:function(a,b,c){var d=this.symbol("circle");if(da(a))c=a.r,b=a.y,a=a.x;d.isCircle=!0;d.r=c;return d.attr({x:a,y:b})},g:function(a){var b;a&&(b={className:"highcharts-"+a,"class":"highcharts-"+a});return this.createElement(Ja).attr(b)},image:function(a,b,c,d,e){var f=this.createElement("img").attr({src:a});arguments.length>1&&f.attr({x:b,y:c,width:d,
|
||||
height:e});return f},createElement:function(a){return a==="rect"?this.symbol(a):ta.prototype.createElement.call(this,a)},invertChild:function(a,b){var c=this,d=b.style,e=a.tagName==="IMG"&&a.style;A(a,{flip:"x",left:z(d.width)-(e?z(e.top):1),top:z(d.height)-(e?z(e.left):1),rotation:-90});q(a.childNodes,function(b){c.invertChild(b,a)})},symbols:{arc:function(a,b,c,d,e){var f=e.start,g=e.end,h=e.r||c||d,c=e.innerR,d=aa(f),i=fa(f),j=aa(g),k=fa(g);if(g-f===0)return["x"];f=["wa",a-h,b-h,a+h,b+h,a+h*d,
|
||||
b+h*i,a+h*j,b+h*k];e.open&&!c&&f.push("e","M",a,b);f.push("at",a-c,b-c,a+c,b+c,a+c*j,b+c*k,a+c*d,b+c*i,"x","e");f.isArc=!0;return f},circle:function(a,b,c,d,e){e&&(c=d=2*e.r);e&&e.isCircle&&(a-=c/2,b-=d/2);return["wa",a,b,a+c,b+d,a+c,b+d/2,a+c,b+d/2,"e"]},rect:function(a,b,c,d,e){return ta.prototype.symbols[!s(e)||!e.r?"square":"callout"].call(0,a,b,c,d,e)}}};S.VMLRenderer=Z=function(){this.init.apply(this,arguments)};Z.prototype=w(ta.prototype,ha);Ya=Z}ta.prototype.measureSpanWidth=function(a,b){var c=
|
||||
x.createElement("span"),d;d=x.createTextNode(a);c.appendChild(d);A(c,b);this.box.appendChild(c);d=c.offsetWidth;Pa(c);return d};var Lb;if(ga)S.CanVGRenderer=Z=function(){xa="http://www.w3.org/1999/xhtml"},Z.prototype.symbols={},Lb=function(){function a(){var a=b.length,d;for(d=0;d<a;d++)b[d]();b=[]}var b=[];return{push:function(c,d){b.length===0&&Qb(d,a);b.push(c)}}}(),Ya=Z;Sa.prototype={addLabel:function(){var a=this.axis,b=a.options,c=a.chart,d=a.horiz,e=a.categories,f=a.names,g=this.pos,h=b.labels,
|
||||
i=h.rotation,j=a.tickPositions,d=d&&e&&!h.step&&!h.staggerLines&&!h.rotation&&c.plotWidth/j.length||!d&&(c.margin[3]||c.chartWidth*0.33),k=g===j[0],l=g===j[j.length-1],m,f=e?p(e[g],f[g],g):g,e=this.label,n=j.info;a.isDatetimeAxis&&n&&(m=b.dateTimeLabelFormats[n.higherRanks[g]||n.unitName]);this.isFirst=k;this.isLast=l;b=a.labelFormatter.call({axis:a,chart:c,isFirst:k,isLast:l,dateTimeLabelFormat:m,value:a.isLog?ea(ja(f)):f});g=d&&{width:u(1,v(d-2*(h.padding||10)))+"px"};g=r(g,h.style);if(s(e))e&&
|
||||
e.attr({text:b}).css(g);else{m={align:a.labelAlign};if(ia(i))m.rotation=i;if(d&&h.ellipsis)g.HcHeight=a.len/j.length;this.label=e=s(b)&&h.enabled?c.renderer.text(b,0,0,h.useHTML).attr(m).css(g).add(a.labelGroup):null;a.tickBaseline=c.renderer.fontMetrics(h.style.fontSize,e).b;i&&a.side===2&&(a.tickBaseline*=aa(i*Ca))}this.yOffset=e?p(h.y,a.tickBaseline+(a.side===2?8:-(e.getBBox().height/2))):0},getLabelSize:function(){var a=this.label,b=this.axis;return a?a.getBBox()[b.horiz?"height":"width"]:0},
|
||||
getLabelSides:function(){var a=this.label.getBBox(),b=this.axis,c=b.horiz,d=b.options.labels,a=c?a.width:a.height,b=c?d.x-a*{left:0,center:0.5,right:1}[b.labelAlign]:0;return[b,c?a+b:a]},handleOverflow:function(a,b){var c=!0,d=this.axis,e=this.isFirst,f=this.isLast,g=d.horiz?b.x:b.y,h=d.reversed,i=d.tickPositions,j=this.getLabelSides(),k=j[0],j=j[1],l,m,n,o=this.label.line||0;l=d.labelEdge;m=d.justifyLabels&&(e||f);l[o]===t||g+k>l[o]?l[o]=g+j:m||(c=!1);if(m){l=(m=d.justifyToPlot)?d.pos:0;m=m?l+d.len:
|
||||
d.chart.chartWidth;do a+=e?1:-1,n=d.ticks[i[a]];while(i[a]&&(!n||!n.label||n.label.line!==o));d=n&&n.label.xy&&n.label.xy.x+n.getLabelSides()[e?0:1];e&&!h||f&&h?g+k<l&&(g=l-k,n&&g+j>d&&(c=!1)):g+j>m&&(g=m-j,n&&g+k<d&&(c=!1));b.x=g}return c},getPosition:function(a,b,c,d){var e=this.axis,f=e.chart,g=d&&f.oldChartHeight||f.chartHeight;return{x:a?e.translate(b+c,null,null,d)+e.transB:e.left+e.offset+(e.opposite?(d&&f.oldChartWidth||f.chartWidth)-e.right-e.left:0),y:a?g-e.bottom+e.offset-(e.opposite?e.height:
|
||||
0):g-e.translate(b+c,null,null,d)-e.transB}},getLabelPosition:function(a,b,c,d,e,f,g,h){var i=this.axis,j=i.transA,k=i.reversed,l=i.staggerLines,a=a+e.x-(f&&d?f*j*(k?-1:1):0),b=b+this.yOffset-(f&&!d?f*j*(k?1:-1):0);if(l)c.line=g/(h||1)%l,b+=c.line*(i.labelOffset/l);return{x:a,y:b}},getMarkPath:function(a,b,c,d,e,f){return f.crispLine(["M",a,b,"L",a+(e?0:-c),b+(e?c:0)],d)},render:function(a,b,c){var d=this.axis,e=d.options,f=d.chart.renderer,g=d.horiz,h=this.type,i=this.label,j=this.pos,k=e.labels,
|
||||
l=this.gridLine,m=h?h+"Grid":"grid",n=h?h+"Tick":"tick",o=e[m+"LineWidth"],q=e[m+"LineColor"],E=e[m+"LineDashStyle"],I=e[n+"Length"],m=e[n+"Width"]||0,D=e[n+"Color"],u=e[n+"Position"],n=this.mark,s=k.step,r=!0,v=d.tickmarkOffset,w=this.getPosition(g,j,v,b),x=w.x,w=w.y,y=g&&x===d.pos+d.len||!g&&w===d.pos?-1:1,c=p(c,1);this.isActive=!0;if(o){j=d.getPlotLinePath(j+v,o*y,b,!0);if(l===t){l={stroke:q,"stroke-width":o};if(E)l.dashstyle=E;if(!h)l.zIndex=1;if(b)l.opacity=0;this.gridLine=l=o?f.path(j).attr(l).add(d.gridGroup):
|
||||
null}if(!b&&l&&j)l[this.isNew?"attr":"animate"]({d:j,opacity:c})}if(m&&I)u==="inside"&&(I=-I),d.opposite&&(I=-I),h=this.getMarkPath(x,w,I,m*y,g,f),n?n.animate({d:h,opacity:c}):this.mark=f.path(h).attr({stroke:D,"stroke-width":m,opacity:c}).add(d.axisGroup);if(i&&!isNaN(x))i.xy=w=this.getLabelPosition(x,w,i,g,k,v,a,s),this.isFirst&&!this.isLast&&!p(e.showFirstLabel,1)||this.isLast&&!this.isFirst&&!p(e.showLastLabel,1)?r=!1:!d.isRadial&&!k.step&&!k.rotation&&!b&&c!==0&&(r=this.handleOverflow(a,w)),
|
||||
s&&a%s&&(r=!1),r&&!isNaN(w.y)?(w.opacity=c,i[this.isNew?"attr":"animate"](w),this.isNew=!1):i.attr("y",-9999)},destroy:function(){Oa(this,this.axis)}};S.PlotLineOrBand=function(a,b){this.axis=a;if(b)this.options=b,this.id=b.id};S.PlotLineOrBand.prototype={render:function(){var a=this,b=a.axis,c=b.horiz,d=(b.pointRange||0)/2,e=a.options,f=e.label,g=a.label,h=e.width,i=e.to,j=e.from,k=s(j)&&s(i),l=e.value,m=e.dashStyle,n=a.svgElem,o=[],p,q=e.color,I=e.zIndex,D=e.events,r={},t=b.chart.renderer;b.isLog&&
|
||||
(j=za(j),i=za(i),l=za(l));if(h){if(o=b.getPlotLinePath(l,h),r={stroke:q,"stroke-width":h},m)r.dashstyle=m}else if(k){j=u(j,b.min-d);i=C(i,b.max+d);o=b.getPlotBandPath(j,i,e);if(q)r.fill=q;if(e.borderWidth)r.stroke=e.borderColor,r["stroke-width"]=e.borderWidth}else return;if(s(I))r.zIndex=I;if(n)if(o)n.animate({d:o},null,n.onGetPath);else{if(n.hide(),n.onGetPath=function(){n.show()},g)a.label=g=g.destroy()}else if(o&&o.length&&(a.svgElem=n=t.path(o).attr(r).add(),D))for(p in d=function(b){n.on(b,function(c){D[b].apply(a,
|
||||
[c])})},D)d(p);if(f&&s(f.text)&&o&&o.length&&b.width>0&&b.height>0){f=w({align:c&&k&&"center",x:c?!k&&4:10,verticalAlign:!c&&k&&"middle",y:c?k?16:10:k?6:-4,rotation:c&&!k&&90},f);if(!g){r={align:f.textAlign||f.align,rotation:f.rotation};if(s(I))r.zIndex=I;a.label=g=t.text(f.text,0,0,f.useHTML).attr(r).css(f.style).add()}b=[o[1],o[4],k?o[6]:o[1]];k=[o[2],o[5],k?o[7]:o[2]];o=Na(b);c=Na(k);g.align(f,!1,{x:o,y:c,width:Ba(b)-o,height:Ba(k)-c});g.show()}else g&&g.hide();return a},destroy:function(){ka(this.axis.plotLinesAndBands,
|
||||
this);delete this.axis;Oa(this)}};ma.prototype={defaultOptions:{dateTimeLabelFormats:{millisecond:"%H:%M:%S.%L",second:"%H:%M:%S",minute:"%H:%M",hour:"%H:%M",day:"%e. %b",week:"%e. %b",month:"%b '%y",year:"%Y"},endOnTick:!1,gridLineColor:"#C0C0C0",labels:M,lineColor:"#C0D0E0",lineWidth:1,minPadding:0.01,maxPadding:0.01,minorGridLineColor:"#E0E0E0",minorGridLineWidth:1,minorTickColor:"#A0A0A0",minorTickLength:2,minorTickPosition:"outside",startOfWeek:1,startOnTick:!1,tickColor:"#C0D0E0",tickLength:10,
|
||||
tickmarkPlacement:"between",tickPixelInterval:100,tickPosition:"outside",tickWidth:1,title:{align:"middle",style:{color:"#707070"}},type:"linear"},defaultYAxisOptions:{endOnTick:!0,gridLineWidth:1,tickPixelInterval:72,showLastLabel:!0,labels:{x:-8,y:3},lineWidth:0,maxPadding:0.05,minPadding:0.05,startOnTick:!0,tickWidth:0,title:{rotation:270,text:"Values"},stackLabels:{enabled:!1,formatter:function(){return Ga(this.total,-1)},style:M.style}},defaultLeftAxisOptions:{labels:{x:-15,y:null},title:{rotation:270}},
|
||||
defaultRightAxisOptions:{labels:{x:15,y:null},title:{rotation:90}},defaultBottomAxisOptions:{labels:{x:0,y:null},title:{rotation:0}},defaultTopAxisOptions:{labels:{x:0,y:-15},title:{rotation:0}},init:function(a,b){var c=b.isX;this.horiz=a.inverted?!c:c;this.coll=(this.isXAxis=c)?"xAxis":"yAxis";this.opposite=b.opposite;this.side=b.side||(this.horiz?this.opposite?0:2:this.opposite?1:3);this.setOptions(b);var d=this.options,e=d.type;this.labelFormatter=d.labels.formatter||this.defaultLabelFormatter;
|
||||
this.userOptions=b;this.minPixelPadding=0;this.chart=a;this.reversed=d.reversed;this.zoomEnabled=d.zoomEnabled!==!1;this.categories=d.categories||e==="category";this.names=[];this.isLog=e==="logarithmic";this.isDatetimeAxis=e==="datetime";this.isLinked=s(d.linkedTo);this.tickmarkOffset=this.categories&&d.tickmarkPlacement==="between"?0.5:0;this.ticks={};this.labelEdge=[];this.minorTicks={};this.plotLinesAndBands=[];this.alternateBands={};this.len=0;this.minRange=this.userMinRange=d.minRange||d.maxZoom;
|
||||
this.range=d.range;this.offset=d.offset||0;this.stacks={};this.oldStacks={};this.min=this.max=null;this.crosshair=p(d.crosshair,ra(a.options.tooltip.crosshairs)[c?0:1],!1);var f,d=this.options.events;Da(this,a.axes)===-1&&(c&&!this.isColorAxis?a.axes.splice(a.xAxis.length,0,this):a.axes.push(this),a[this.coll].push(this));this.series=this.series||[];if(a.inverted&&c&&this.reversed===t)this.reversed=!0;this.removePlotLine=this.removePlotBand=this.removePlotBandOrLine;for(f in d)N(this,f,d[f]);if(this.isLog)this.val2lin=
|
||||
za,this.lin2val=ja},setOptions:function(a){this.options=w(this.defaultOptions,this.isXAxis?{}:this.defaultYAxisOptions,[this.defaultTopAxisOptions,this.defaultRightAxisOptions,this.defaultBottomAxisOptions,this.defaultLeftAxisOptions][this.side],w(L[this.coll],a))},defaultLabelFormatter:function(){var a=this.axis,b=this.value,c=a.categories,d=this.dateTimeLabelFormat,e=L.lang.numericSymbols,f=e&&e.length,g,h=a.options.labels.format,a=a.isLog?b:a.tickInterval;if(h)g=Ia(h,this);else if(c)g=b;else if(d)g=
|
||||
bb(d,b);else if(f&&a>=1E3)for(;f--&&g===t;)c=Math.pow(1E3,f+1),a>=c&&e[f]!==null&&(g=Ga(b/c,-1)+e[f]);g===t&&(g=Q(b)>=1E4?Ga(b,0):Ga(b,-1,t,""));return g},getSeriesExtremes:function(){var a=this,b=a.chart;a.hasVisibleSeries=!1;a.dataMin=a.dataMax=null;a.buildStacks&&a.buildStacks();q(a.series,function(c){if(c.visible||!b.options.chart.ignoreHiddenSeries){var d;d=c.options.threshold;var e;a.hasVisibleSeries=!0;a.isLog&&d<=0&&(d=null);if(a.isXAxis){if(d=c.xData,d.length)a.dataMin=C(p(a.dataMin,d[0]),
|
||||
Na(d)),a.dataMax=u(p(a.dataMax,d[0]),Ba(d))}else{c.getExtremes();e=c.dataMax;c=c.dataMin;if(s(c)&&s(e))a.dataMin=C(p(a.dataMin,c),c),a.dataMax=u(p(a.dataMax,e),e);if(s(d))if(a.dataMin>=d)a.dataMin=d,a.ignoreMinPadding=!0;else if(a.dataMax<d)a.dataMax=d,a.ignoreMaxPadding=!0}}})},translate:function(a,b,c,d,e,f){var g=1,h=0,i=d?this.oldTransA:this.transA,d=d?this.oldMin:this.min,j=this.minPixelPadding,e=(this.options.ordinal||this.isLog&&e)&&this.lin2val;if(!i)i=this.transA;if(c)g*=-1,h=this.len;this.reversed&&
|
||||
(g*=-1,h-=g*(this.sector||this.len));b?(a=a*g+h,a-=j,a=a/i+d,e&&(a=this.lin2val(a))):(e&&(a=this.val2lin(a)),f==="between"&&(f=0.5),a=g*(a-d)*i+h+g*j+(ia(f)?i*f*this.pointRange:0));return a},toPixels:function(a,b){return this.translate(a,!1,!this.horiz,null,!0)+(b?0:this.pos)},toValue:function(a,b){return this.translate(a-(b?0:this.pos),!0,!this.horiz,null,!0)},getPlotLinePath:function(a,b,c,d,e){var f=this.chart,g=this.left,h=this.top,i,j,k=c&&f.oldChartHeight||f.chartHeight,l=c&&f.oldChartWidth||
|
||||
f.chartWidth,m;i=this.transB;e=p(e,this.translate(a,null,null,c));a=c=v(e+i);i=j=v(k-e-i);if(isNaN(e))m=!0;else if(this.horiz){if(i=h,j=k-this.bottom,a<g||a>g+this.width)m=!0}else if(a=g,c=l-this.right,i<h||i>h+this.height)m=!0;return m&&!d?null:f.renderer.crispLine(["M",a,i,"L",c,j],b||1)},getLinearTickPositions:function(a,b,c){var d,e=ea(U(b/a)*a),f=ea(Ka(c/a)*a),g=[];if(b===c&&ia(b))return[b];for(b=e;b<=f;){g.push(b);b=ea(b+a);if(b===d)break;d=b}return g},getMinorTickPositions:function(){var a=
|
||||
this.options,b=this.tickPositions,c=this.minorTickInterval,d=[],e;if(this.isLog){e=b.length;for(a=1;a<e;a++)d=d.concat(this.getLogTickPositions(c,b[a-1],b[a],!0))}else if(this.isDatetimeAxis&&a.minorTickInterval==="auto")d=d.concat(this.getTimeTicks(this.normalizeTimeTickInterval(c),this.min,this.max,a.startOfWeek)),d[0]<this.min&&d.shift();else for(b=this.min+(b[0]-this.min)%c;b<=this.max;b+=c)d.push(b);return d},adjustForMinRange:function(){var a=this.options,b=this.min,c=this.max,d,e=this.dataMax-
|
||||
this.dataMin>=this.minRange,f,g,h,i,j;if(this.isXAxis&&this.minRange===t&&!this.isLog)s(a.min)||s(a.max)?this.minRange=null:(q(this.series,function(a){i=a.xData;for(g=j=a.xIncrement?1:i.length-1;g>0;g--)if(h=i[g]-i[g-1],f===t||h<f)f=h}),this.minRange=C(f*5,this.dataMax-this.dataMin));if(c-b<this.minRange){var k=this.minRange;d=(k-c+b)/2;d=[b-d,p(a.min,b-d)];if(e)d[2]=this.dataMin;b=Ba(d);c=[b+k,p(a.max,b+k)];if(e)c[2]=this.dataMax;c=Na(c);c-b<k&&(d[0]=c-k,d[1]=p(a.min,c-k),b=Ba(d))}this.min=b;this.max=
|
||||
c},setAxisTranslation:function(a){var b=this,c=b.max-b.min,d=b.axisPointRange||0,e,f=0,g=0,h=b.linkedParent,i=!!b.categories,j=b.transA;if(b.isXAxis||i||d)h?(f=h.minPointOffset,g=h.pointRangePadding):q(b.series,function(a){var h=i?1:b.isXAxis?a.pointRange:b.axisPointRange||0,j=a.options.pointPlacement,n=a.closestPointRange;h>c&&(h=0);d=u(d,h);f=u(f,Fa(j)?0:h/2);g=u(g,j==="on"?0:h);!a.noSharedTooltip&&s(n)&&(e=s(e)?C(e,n):n)}),h=b.ordinalSlope&&e?b.ordinalSlope/e:1,b.minPointOffset=f*=h,b.pointRangePadding=
|
||||
g*=h,b.pointRange=C(d,c),b.closestPointRange=e;if(a)b.oldTransA=j;b.translationSlope=b.transA=j=b.len/(c+g||1);b.transB=b.horiz?b.left:b.bottom;b.minPixelPadding=j*f},setTickPositions:function(a){var b=this,c=b.chart,d=b.options,e=d.startOnTick,f=d.endOnTick,g=b.isLog,h=b.isDatetimeAxis,i=b.isXAxis,j=b.isLinked,k=b.options.tickPositioner,l=d.maxPadding,m=d.minPadding,n=d.tickInterval,o=d.minTickInterval,Y=d.tickPixelInterval,E,I=b.categories;j?(b.linkedParent=c[b.coll][d.linkedTo],c=b.linkedParent.getExtremes(),
|
||||
b.min=p(c.min,c.dataMin),b.max=p(c.max,c.dataMax),d.type!==b.linkedParent.options.type&&oa(11,1)):(b.min=p(b.userMin,d.min,b.dataMin),b.max=p(b.userMax,d.max,b.dataMax));if(g)!a&&C(b.min,p(b.dataMin,b.min))<=0&&oa(10,1),b.min=ea(za(b.min)),b.max=ea(za(b.max));if(b.range&&s(b.max))b.userMin=b.min=u(b.min,b.max-b.range),b.userMax=b.max,b.range=null;b.beforePadding&&b.beforePadding();b.adjustForMinRange();if(!I&&!b.axisPointRange&&!b.usePercentage&&!j&&s(b.min)&&s(b.max)&&(c=b.max-b.min)){if(!s(d.min)&&
|
||||
!s(b.userMin)&&m&&(b.dataMin<0||!b.ignoreMinPadding))b.min-=c*m;if(!s(d.max)&&!s(b.userMax)&&l&&(b.dataMax>0||!b.ignoreMaxPadding))b.max+=c*l}if(ia(d.floor))b.min=u(b.min,d.floor);if(ia(d.ceiling))b.max=C(b.max,d.ceiling);b.min===b.max||b.min===void 0||b.max===void 0?b.tickInterval=1:j&&!n&&Y===b.linkedParent.options.tickPixelInterval?b.tickInterval=b.linkedParent.tickInterval:(b.tickInterval=p(n,I?1:(b.max-b.min)*Y/u(b.len,Y)),!s(n)&&b.len<Y&&!this.isRadial&&!this.isLog&&!I&&e&&f&&(E=!0,b.tickInterval/=
|
||||
4));i&&!a&&q(b.series,function(a){a.processData(b.min!==b.oldMin||b.max!==b.oldMax)});b.setAxisTranslation(!0);b.beforeSetTickPositions&&b.beforeSetTickPositions();if(b.postProcessTickInterval)b.tickInterval=b.postProcessTickInterval(b.tickInterval);if(b.pointRange)b.tickInterval=u(b.pointRange,b.tickInterval);if(!n&&b.tickInterval<o)b.tickInterval=o;if(!h&&!g&&!n)b.tickInterval=mb(b.tickInterval,null,lb(b.tickInterval),d);b.minorTickInterval=d.minorTickInterval==="auto"&&b.tickInterval?b.tickInterval/
|
||||
5:d.minorTickInterval;b.tickPositions=a=d.tickPositions?[].concat(d.tickPositions):k&&k.apply(b,[b.min,b.max]);if(!a)!b.ordinalPositions&&(b.max-b.min)/b.tickInterval>u(2*b.len,200)&&oa(19,!0),a=h?b.getTimeTicks(b.normalizeTimeTickInterval(b.tickInterval,d.units),b.min,b.max,d.startOfWeek,b.ordinalPositions,b.closestPointRange,!0):g?b.getLogTickPositions(b.tickInterval,b.min,b.max):b.getLinearTickPositions(b.tickInterval,b.min,b.max),E&&a.splice(1,a.length-2),b.tickPositions=a;if(!j)d=a[0],g=a[a.length-
|
||||
1],h=b.minPointOffset||0,!e&&!f&&!I&&a.length===2&&a.splice(1,0,(g+d)/2),e?b.min=d:b.min-h>d&&a.shift(),f?b.max=g:b.max+h<g&&a.pop(),a.length===1&&(e=Q(b.max)>1E13?1:0.001,b.min-=e,b.max+=e)},setMaxTicks:function(){var a=this.chart,b=a.maxTicks||{},c=this.tickPositions,d=this._maxTicksKey=[this.coll,this.pos,this.len].join("-");if(!this.isLinked&&!this.isDatetimeAxis&&c&&c.length>(b[d]||0)&&this.options.alignTicks!==!1)b[d]=c.length;a.maxTicks=b},adjustTickAmount:function(){var a=this._maxTicksKey,
|
||||
b=this.tickPositions,c=this.chart.maxTicks;if(c&&c[a]&&!this.isDatetimeAxis&&!this.categories&&!this.isLinked&&this.options.alignTicks!==!1&&this.min!==t){var d=this.tickAmount,e=b.length;this.tickAmount=a=c[a];if(e<a){for(;b.length<a;)b.push(ea(b[b.length-1]+this.tickInterval));this.transA*=(e-1)/(a-1);this.max=b[b.length-1]}if(s(d)&&a!==d)this.isDirty=!0}},setScale:function(){var a=this.stacks,b,c,d,e;this.oldMin=this.min;this.oldMax=this.max;this.oldAxisLength=this.len;this.setAxisSize();e=this.len!==
|
||||
this.oldAxisLength;q(this.series,function(a){if(a.isDirtyData||a.isDirty||a.xAxis.isDirty)d=!0});if(e||d||this.isLinked||this.forceRedraw||this.userMin!==this.oldUserMin||this.userMax!==this.oldUserMax){if(!this.isXAxis)for(b in a)for(c in a[b])a[b][c].total=null,a[b][c].cum=0;this.forceRedraw=!1;this.getSeriesExtremes();this.setTickPositions();this.oldUserMin=this.userMin;this.oldUserMax=this.userMax;if(!this.isDirty)this.isDirty=e||this.min!==this.oldMin||this.max!==this.oldMax}else if(!this.isXAxis){if(this.oldStacks)a=
|
||||
this.stacks=this.oldStacks;for(b in a)for(c in a[b])a[b][c].cum=a[b][c].total}this.setMaxTicks()},setExtremes:function(a,b,c,d,e){var f=this,g=f.chart,c=p(c,!0),e=r(e,{min:a,max:b});K(f,"setExtremes",e,function(){f.userMin=a;f.userMax=b;f.eventArgs=e;f.isDirtyExtremes=!0;c&&g.redraw(d)})},zoom:function(a,b){var c=this.dataMin,d=this.dataMax,e=this.options;this.allowZoomOutside||(s(c)&&a<=C(c,p(e.min,c))&&(a=t),s(d)&&b>=u(d,p(e.max,d))&&(b=t));this.displayBtn=a!==t||b!==t;this.setExtremes(a,b,!1,t,
|
||||
{trigger:"zoom"});return!0},setAxisSize:function(){var a=this.chart,b=this.options,c=b.offsetLeft||0,d=this.horiz,e=p(b.width,a.plotWidth-c+(b.offsetRight||0)),f=p(b.height,a.plotHeight),g=p(b.top,a.plotTop),b=p(b.left,a.plotLeft+c),c=/%$/;c.test(f)&&(f=parseInt(f,10)/100*a.plotHeight);c.test(g)&&(g=parseInt(g,10)/100*a.plotHeight+a.plotTop);this.left=b;this.top=g;this.width=e;this.height=f;this.bottom=a.chartHeight-f-g;this.right=a.chartWidth-e-b;this.len=u(d?e:f,0);this.pos=d?b:g},getExtremes:function(){var a=
|
||||
this.isLog;return{min:a?ea(ja(this.min)):this.min,max:a?ea(ja(this.max)):this.max,dataMin:this.dataMin,dataMax:this.dataMax,userMin:this.userMin,userMax:this.userMax}},getThreshold:function(a){var b=this.isLog,c=b?ja(this.min):this.min,b=b?ja(this.max):this.max;c>a||a===null?a=c:b<a&&(a=b);return this.translate(a,0,1,0,1)},autoLabelAlign:function(a){a=(p(a,0)-this.side*90+720)%360;return a>15&&a<165?"right":a>195&&a<345?"left":"center"},getOffset:function(){var a=this,b=a.chart,c=b.renderer,d=a.options,
|
||||
e=a.tickPositions,f=a.ticks,g=a.horiz,h=a.side,i=b.inverted?[1,0,3,2][h]:h,j,k,l=0,m,n=0,o=d.title,Y=d.labels,E=0,I=b.axisOffset,b=b.clipOffset,D=[-1,1,1,-1][h],r,v=1,w=p(Y.maxStaggerLines,5),x,z,C,y,R;a.hasData=j=a.hasVisibleSeries||s(a.min)&&s(a.max)&&!!e;a.showAxis=k=j||p(d.showEmpty,!0);a.staggerLines=a.horiz&&Y.staggerLines;if(!a.axisGroup)a.gridGroup=c.g("grid").attr({zIndex:d.gridZIndex||1}).add(),a.axisGroup=c.g("axis").attr({zIndex:d.zIndex||2}).add(),a.labelGroup=c.g("axis-labels").attr({zIndex:Y.zIndex||
|
||||
7}).addClass("highcharts-"+a.coll.toLowerCase()+"-labels").add();if(j||a.isLinked){a.labelAlign=p(Y.align||a.autoLabelAlign(Y.rotation));q(e,function(b){f[b]?f[b].addLabel():f[b]=new Sa(a,b)});if(a.horiz&&!a.staggerLines&&w&&!Y.rotation){for(j=a.reversed?[].concat(e).reverse():e;v<w;){x=[];z=!1;for(r=0;r<j.length;r++)C=j[r],y=(y=f[C].label&&f[C].label.getBBox())?y.width:0,R=r%v,y&&(C=a.translate(C),x[R]!==t&&C<x[R]&&(z=!0),x[R]=C+y);if(z)v++;else break}if(v>1)a.staggerLines=v}q(e,function(b){if(h===
|
||||
0||h===2||{1:"left",3:"right"}[h]===a.labelAlign)E=u(f[b].getLabelSize(),E)});if(a.staggerLines)E*=a.staggerLines,a.labelOffset=E}else for(r in f)f[r].destroy(),delete f[r];if(o&&o.text&&o.enabled!==!1){if(!a.axisTitle)a.axisTitle=c.text(o.text,0,0,o.useHTML).attr({zIndex:7,rotation:o.rotation||0,align:o.textAlign||{low:"left",middle:"center",high:"right"}[o.align]}).addClass("highcharts-"+this.coll.toLowerCase()+"-title").css(o.style).add(a.axisGroup),a.axisTitle.isNew=!0;if(k)l=a.axisTitle.getBBox()[g?
|
||||
"height":"width"],m=o.offset,n=s(m)?0:p(o.margin,g?5:10);a.axisTitle[k?"show":"hide"]()}a.offset=D*p(d.offset,I[h]);c=h===2?a.tickBaseline:0;g=E+n+(E&&D*(g?p(Y.y,a.tickBaseline+8):Y.x)-c);a.axisTitleMargin=p(m,g);I[h]=u(I[h],a.axisTitleMargin+l+D*a.offset,g);b[i]=u(b[i],U(d.lineWidth/2)*2)},getLinePath:function(a){var b=this.chart,c=this.opposite,d=this.offset,e=this.horiz,f=this.left+(c?this.width:0)+d,d=b.chartHeight-this.bottom-(c?this.height:0)+d;c&&(a*=-1);return b.renderer.crispLine(["M",e?
|
||||
this.left:f,e?d:this.top,"L",e?b.chartWidth-this.right:f,e?d:b.chartHeight-this.bottom],a)},getTitlePosition:function(){var a=this.horiz,b=this.left,c=this.top,d=this.len,e=this.options.title,f=a?b:c,g=this.opposite,h=this.offset,i=z(e.style.fontSize||12),d={low:f+(a?0:d),middle:f+d/2,high:f+(a?d:0)}[e.align],b=(a?c+this.height:b)+(a?1:-1)*(g?-1:1)*this.axisTitleMargin+(this.side===2?i:0);return{x:a?d:b+(g?this.width:0)+h+(e.x||0),y:a?b-(g?this.height:0)+h:d+(e.y||0)}},render:function(){var a=this,
|
||||
b=a.horiz,c=a.reversed,d=a.chart,e=d.renderer,f=a.options,g=a.isLog,h=a.isLinked,i=a.tickPositions,j,k=a.axisTitle,l=a.ticks,m=a.minorTicks,n=a.alternateBands,o=f.stackLabels,p=f.alternateGridColor,E=a.tickmarkOffset,I=f.lineWidth,D=d.hasRendered&&s(a.oldMin)&&!isNaN(a.oldMin),r=a.hasData,u=a.showAxis,v,w=f.labels.overflow,x=a.justifyLabels=b&&w!==!1,z;a.labelEdge.length=0;a.justifyToPlot=w==="justify";q([l,m,n],function(a){for(var b in a)a[b].isActive=!1});if(r||h)if(a.minorTickInterval&&!a.categories&&
|
||||
q(a.getMinorTickPositions(),function(b){m[b]||(m[b]=new Sa(a,b,"minor"));D&&m[b].isNew&&m[b].render(null,!0);m[b].render(null,!1,1)}),i.length&&(j=i.slice(),(b&&c||!b&&!c)&&j.reverse(),x&&(j=j.slice(1).concat([j[0]])),q(j,function(b,c){x&&(c=c===j.length-1?0:c+1);if(!h||b>=a.min&&b<=a.max)l[b]||(l[b]=new Sa(a,b)),D&&l[b].isNew&&l[b].render(c,!0,0.1),l[b].render(c)}),E&&a.min===0&&(l[-1]||(l[-1]=new Sa(a,-1,null,!0)),l[-1].render(-1))),p&&q(i,function(b,c){if(c%2===0&&b<a.max)n[b]||(n[b]=new S.PlotLineOrBand(a)),
|
||||
v=b+E,z=i[c+1]!==t?i[c+1]+E:a.max,n[b].options={from:g?ja(v):v,to:g?ja(z):z,color:p},n[b].render(),n[b].isActive=!0}),!a._addedPlotLB)q((f.plotLines||[]).concat(f.plotBands||[]),function(b){a.addPlotBandOrLine(b)}),a._addedPlotLB=!0;q([l,m,n],function(a){var b,c,e=[],f=va?va.duration||500:0,g=function(){for(c=e.length;c--;)a[e[c]]&&!a[e[c]].isActive&&(a[e[c]].destroy(),delete a[e[c]])};for(b in a)if(!a[b].isActive)a[b].render(b,!1,0),a[b].isActive=!1,e.push(b);a===n||!d.hasRendered||!f?g():f&&setTimeout(g,
|
||||
f)});if(I)b=a.getLinePath(I),a.axisLine?a.axisLine.animate({d:b}):a.axisLine=e.path(b).attr({stroke:f.lineColor,"stroke-width":I,zIndex:7}).add(a.axisGroup),a.axisLine[u?"show":"hide"]();if(k&&u)k[k.isNew?"attr":"animate"](a.getTitlePosition()),k.isNew=!1;o&&o.enabled&&a.renderStackTotals();a.isDirty=!1},redraw:function(){this.render();q(this.plotLinesAndBands,function(a){a.render()});q(this.series,function(a){a.isDirty=!0})},destroy:function(a){var b=this,c=b.stacks,d,e=b.plotLinesAndBands;a||X(b);
|
||||
for(d in c)Oa(c[d]),c[d]=null;q([b.ticks,b.minorTicks,b.alternateBands],function(a){Oa(a)});for(a=e.length;a--;)e[a].destroy();q("stackTotalGroup,axisLine,axisTitle,axisGroup,cross,gridGroup,labelGroup".split(","),function(a){b[a]&&(b[a]=b[a].destroy())});this.cross&&this.cross.destroy()},drawCrosshair:function(a,b){if(this.crosshair)if((s(b)||!p(this.crosshair.snap,!0))===!1)this.hideCrosshair();else{var c,d=this.crosshair,e=d.animation;p(d.snap,!0)?s(b)&&(c=this.chart.inverted!=this.horiz?b.plotX:
|
||||
this.len-b.plotY):c=this.horiz?a.chartX-this.pos:this.len-a.chartY+this.pos;c=this.isRadial?this.getPlotLinePath(this.isXAxis?b.x:p(b.stackY,b.y)):this.getPlotLinePath(null,null,null,null,c);if(c===null)this.hideCrosshair();else if(this.cross)this.cross.attr({visibility:"visible"})[e?"animate":"attr"]({d:c},e);else{e={"stroke-width":d.width||1,stroke:d.color||"#C0C0C0",zIndex:d.zIndex||2};if(d.dashStyle)e.dashstyle=d.dashStyle;this.cross=this.chart.renderer.path(c).attr(e).add()}}},hideCrosshair:function(){this.cross&&
|
||||
this.cross.hide()}};r(ma.prototype,{getPlotBandPath:function(a,b){var c=this.getPlotLinePath(b),d=this.getPlotLinePath(a);d&&c?d.push(c[4],c[5],c[1],c[2]):d=null;return d},addPlotBand:function(a){return this.addPlotBandOrLine(a,"plotBands")},addPlotLine:function(a){return this.addPlotBandOrLine(a,"plotLines")},addPlotBandOrLine:function(a,b){var c=(new S.PlotLineOrBand(this,a)).render(),d=this.userOptions;c&&(b&&(d[b]=d[b]||[],d[b].push(a)),this.plotLinesAndBands.push(c));return c},removePlotBandOrLine:function(a){for(var b=
|
||||
this.plotLinesAndBands,c=this.options,d=this.userOptions,e=b.length;e--;)b[e].id===a&&b[e].destroy();q([c.plotLines||[],d.plotLines||[],c.plotBands||[],d.plotBands||[]],function(b){for(e=b.length;e--;)b[e].id===a&&ka(b,b[e])})}});ma.prototype.getTimeTicks=function(a,b,c,d){var e=[],f={},g=L.global.useUTC,h,i=new Date(b-Ra),j=a.unitRange,k=a.count;if(s(b)){j>=B.second&&(i.setMilliseconds(0),i.setSeconds(j>=B.minute?0:k*U(i.getSeconds()/k)));if(j>=B.minute)i[Bb](j>=B.hour?0:k*U(i[ob]()/k));if(j>=B.hour)i[Cb](j>=
|
||||
B.day?0:k*U(i[pb]()/k));if(j>=B.day)i[rb](j>=B.month?1:k*U(i[Wa]()/k));j>=B.month&&(i[Db](j>=B.year?0:k*U(i[eb]()/k)),h=i[fb]());j>=B.year&&(h-=h%k,i[Eb](h));if(j===B.week)i[rb](i[Wa]()-i[qb]()+p(d,1));b=1;Ra&&(i=new Date(i.getTime()+Ra));h=i[fb]();for(var d=i.getTime(),l=i[eb](),m=i[Wa](),n=g?Ra:(864E5+i.getTimezoneOffset()*6E4)%864E5;d<c;)e.push(d),j===B.year?d=db(h+b*k,0):j===B.month?d=db(h,l+b*k):!g&&(j===B.day||j===B.week)?d=db(h,l,m+b*k*(j===B.day?1:7)):d+=j*k,b++;e.push(d);q(vb(e,function(a){return j<=
|
||||
B.hour&&a%B.day===n}),function(a){f[a]="day"})}e.info=r(a,{higherRanks:f,totalRange:j*k});return e};ma.prototype.normalizeTimeTickInterval=function(a,b){var c=b||[["millisecond",[1,2,5,10,20,25,50,100,200,500]],["second",[1,2,5,10,15,30]],["minute",[1,2,5,10,15,30]],["hour",[1,2,3,4,6,8,12]],["day",[1,2]],["week",[1,2]],["month",[1,2,3,4,6]],["year",null]],d=c[c.length-1],e=B[d[0]],f=d[1],g;for(g=0;g<c.length;g++)if(d=c[g],e=B[d[0]],f=d[1],c[g+1]&&a<=(e*f[f.length-1]+B[c[g+1][0]])/2)break;e===B.year&&
|
||||
a<5*e&&(f=[1,2,5]);c=mb(a/e,f,d[0]==="year"?u(lb(a/e),1):1);return{unitRange:e,count:c,unitName:d[0]}};ma.prototype.getLogTickPositions=function(a,b,c,d){var e=this.options,f=this.len,g=[];if(!d)this._minorAutoInterval=null;if(a>=0.5)a=v(a),g=this.getLinearTickPositions(a,b,c);else if(a>=0.08)for(var f=U(b),h,i,j,k,l,e=a>0.3?[1,2,4]:a>0.15?[1,2,4,6,8]:[1,2,3,4,5,6,7,8,9];f<c+1&&!l;f++){i=e.length;for(h=0;h<i&&!l;h++)j=za(ja(f)*e[h]),j>b&&(!d||k<=c)&&k!==t&&g.push(k),k>c&&(l=!0),k=j}else if(b=ja(b),
|
||||
c=ja(c),a=e[d?"minorTickInterval":"tickInterval"],a=p(a==="auto"?null:a,this._minorAutoInterval,(c-b)*(e.tickPixelInterval/(d?5:1))/((d?f/this.tickPositions.length:f)||1)),a=mb(a,null,lb(a)),g=Ua(this.getLinearTickPositions(a,b,c),za),!d)this._minorAutoInterval=a/5;if(!d)this.tickInterval=a;return g};var Mb=S.Tooltip=function(){this.init.apply(this,arguments)};Mb.prototype={init:function(a,b){var c=b.borderWidth,d=b.style,e=z(d.padding);this.chart=a;this.options=b;this.crosshairs=[];this.now={x:0,
|
||||
y:0};this.isHidden=!0;this.label=a.renderer.label("",0,0,b.shape||"callout",null,null,b.useHTML,null,"tooltip").attr({padding:e,fill:b.backgroundColor,"stroke-width":c,r:b.borderRadius,zIndex:8}).css(d).css({padding:0}).add().attr({y:-9999});ga||this.label.shadow(b.shadow);this.shared=b.shared},destroy:function(){if(this.label)this.label=this.label.destroy();clearTimeout(this.hideTimer);clearTimeout(this.tooltipTimeout)},move:function(a,b,c,d){var e=this,f=e.now,g=e.options.animation!==!1&&!e.isHidden&&
|
||||
(Q(a-f.x)>1||Q(b-f.y)>1),h=e.followPointer||e.len>1;r(f,{x:g?(2*f.x+a)/3:a,y:g?(f.y+b)/2:b,anchorX:h?t:g?(2*f.anchorX+c)/3:c,anchorY:h?t:g?(f.anchorY+d)/2:d});e.label.attr(f);if(g)clearTimeout(this.tooltipTimeout),this.tooltipTimeout=setTimeout(function(){e&&e.move(a,b,c,d)},32)},hide:function(){var a=this,b;clearTimeout(this.hideTimer);if(!this.isHidden)b=this.chart.hoverPoints,this.hideTimer=setTimeout(function(){a.label.fadeOut();a.isHidden=!0},p(this.options.hideDelay,500)),b&&q(b,function(a){a.setState()}),
|
||||
this.chart.hoverPoints=null},getAnchor:function(a,b){var c,d=this.chart,e=d.inverted,f=d.plotTop,g=0,h=0,i,a=ra(a);c=a[0].tooltipPos;this.followPointer&&b&&(b.chartX===t&&(b=d.pointer.normalize(b)),c=[b.chartX-d.plotLeft,b.chartY-f]);c||(q(a,function(a){i=a.series.yAxis;g+=a.plotX;h+=(a.plotLow?(a.plotLow+a.plotHigh)/2:a.plotY)+(!e&&i?i.top-f:0)}),g/=a.length,h/=a.length,c=[e?d.plotWidth-h:g,this.shared&&!e&&a.length>1&&b?b.chartY-f:e?d.plotHeight-g:h]);return Ua(c,v)},getPosition:function(a,b,c){var d=
|
||||
this.chart,e=this.distance,f={},g,h=["y",d.chartHeight,b,c.plotY+d.plotTop],i=["x",d.chartWidth,a,c.plotX+d.plotLeft],j=c.ttBelow||d.inverted&&!c.negative||!d.inverted&&c.negative,k=function(a,b,c,d){var g=c<d-e,b=d+e+c<b,c=d-e-c;d+=e;if(j&&b)f[a]=d;else if(!j&&g)f[a]=c;else if(g)f[a]=c;else if(b)f[a]=d;else return!1},l=function(a,b,c,d){if(d<e||d>b-e)return!1;else f[a]=d<c/2?1:d>b-c/2?b-c-2:d-c/2},m=function(a){var b=h;h=i;i=b;g=a},n=function(){k.apply(0,h)!==!1?l.apply(0,i)===!1&&!g&&(m(!0),n()):
|
||||
g?f.x=f.y=0:(m(!0),n())};(d.inverted||this.len>1)&&m();n();return f},defaultFormatter:function(a){var b=this.points||ra(this),c=b[0].series,d;d=[a.tooltipHeaderFormatter(b[0])];q(b,function(a){c=a.series;d.push(c.tooltipFormatter&&c.tooltipFormatter(a)||a.point.tooltipFormatter(c.tooltipOptions.pointFormat))});d.push(a.options.footerFormat||"");return d.join("")},refresh:function(a,b){var c=this.chart,d=this.label,e=this.options,f,g,h={},i,j=[];i=e.formatter||this.defaultFormatter;var h=c.hoverPoints,
|
||||
k,l=this.shared;clearTimeout(this.hideTimer);this.followPointer=ra(a)[0].series.tooltipOptions.followPointer;g=this.getAnchor(a,b);f=g[0];g=g[1];l&&(!a.series||!a.series.noSharedTooltip)?(c.hoverPoints=a,h&&q(h,function(a){a.setState()}),q(a,function(a){a.setState("hover");j.push(a.getLabelConfig())}),h={x:a[0].category,y:a[0].y},h.points=j,this.len=j.length,a=a[0]):h=a.getLabelConfig();i=i.call(h,this);h=a.series;this.distance=p(h.tooltipOptions.distance,16);i===!1?this.hide():(this.isHidden&&(ab(d),
|
||||
d.attr("opacity",1).show()),d.attr({text:i}),k=e.borderColor||a.color||h.color||"#606060",d.attr({stroke:k}),this.updatePosition({plotX:f,plotY:g,negative:a.negative,ttBelow:a.ttBelow}),this.isHidden=!1);K(c,"tooltipRefresh",{text:i,x:f+c.plotLeft,y:g+c.plotTop,borderColor:k})},updatePosition:function(a){var b=this.chart,c=this.label,c=(this.options.positioner||this.getPosition).call(this,c.width,c.height,a);this.move(v(c.x),v(c.y),a.plotX+b.plotLeft,a.plotY+b.plotTop)},tooltipHeaderFormatter:function(a){var b=
|
||||
a.series,c=b.tooltipOptions,d=c.dateTimeLabelFormats,e=c.xDateFormat,f=b.xAxis,g=f&&f.options.type==="datetime"&&ia(a.key),c=c.headerFormat,f=f&&f.closestPointRange,h;if(g&&!e){if(f)for(h in B){if(B[h]>=f||B[h]<=B.day&&a.key%B[h]>0){e=d[h];break}}else e=d.day;e=e||d.year}g&&e&&(c=c.replace("{point.key}","{point.key:"+e+"}"));return Ia(c,{point:a,series:b})}};var pa;Za=x.documentElement.ontouchstart!==t;var Va=S.Pointer=function(a,b){this.init(a,b)};Va.prototype={init:function(a,b){var c=b.chart,d=
|
||||
c.events,e=ga?"":c.zoomType,c=a.inverted,f;this.options=b;this.chart=a;this.zoomX=f=/x/.test(e);this.zoomY=e=/y/.test(e);this.zoomHor=f&&!c||e&&c;this.zoomVert=e&&!c||f&&c;this.hasZoom=f||e;this.runChartClick=d&&!!d.click;this.pinchDown=[];this.lastValidTouch={};if(S.Tooltip&&b.tooltip.enabled)a.tooltip=new Mb(a,b.tooltip),this.followTouchMove=b.tooltip.followTouchMove;this.setDOMEvents()},normalize:function(a,b){var c,d,a=a||window.event,a=Sb(a);if(!a.target)a.target=a.srcElement;d=a.touches?a.touches.length?
|
||||
a.touches.item(0):a.changedTouches[0]:a;if(!b)this.chartPosition=b=Rb(this.chart.container);d.pageX===t?(c=u(a.x,a.clientX-b.left),d=a.y):(c=d.pageX-b.left,d=d.pageY-b.top);return r(a,{chartX:v(c),chartY:v(d)})},getCoordinates:function(a){var b={xAxis:[],yAxis:[]};q(this.chart.axes,function(c){b[c.isXAxis?"xAxis":"yAxis"].push({axis:c,value:c.toValue(a[c.horiz?"chartX":"chartY"])})});return b},getIndex:function(a){var b=this.chart;return b.inverted?b.plotHeight+b.plotTop-a.chartY:a.chartX-b.plotLeft},
|
||||
runPointActions:function(a){var b=this.chart,c=b.series,d=b.tooltip,e,f,g=b.hoverPoint,h=b.hoverSeries,i,j,k=b.chartWidth,l=this.getIndex(a);if(d&&this.options.tooltip.shared&&(!h||!h.noSharedTooltip)){f=[];i=c.length;for(j=0;j<i;j++)if(c[j].visible&&c[j].options.enableMouseTracking!==!1&&!c[j].noSharedTooltip&&c[j].singularTooltips!==!0&&c[j].tooltipPoints.length&&(e=c[j].tooltipPoints[l])&&e.series)e._dist=Q(l-e.clientX),k=C(k,e._dist),f.push(e);for(i=f.length;i--;)f[i]._dist>k&&f.splice(i,1);if(f.length&&
|
||||
f[0].clientX!==this.hoverX)d.refresh(f,a),this.hoverX=f[0].clientX}c=h&&h.tooltipOptions.followPointer;if(h&&h.tracker&&!c){if((e=h.tooltipPoints[l])&&e!==g)e.onMouseOver(a)}else d&&c&&!d.isHidden&&(h=d.getAnchor([{}],a),d.updatePosition({plotX:h[0],plotY:h[1]}));if(d&&!this._onDocumentMouseMove)this._onDocumentMouseMove=function(a){if(W[pa])W[pa].pointer.onDocumentMouseMove(a)},N(x,"mousemove",this._onDocumentMouseMove);q(b.axes,function(b){b.drawCrosshair(a,p(e,g))})},reset:function(a){var b=this.chart,
|
||||
c=b.hoverSeries,d=b.hoverPoint,e=b.tooltip,f=e&&e.shared?b.hoverPoints:d;(a=a&&e&&f)&&ra(f)[0].plotX===t&&(a=!1);if(a)e.refresh(f),d&&d.setState(d.state,!0);else{if(d)d.onMouseOut();if(c)c.onMouseOut();e&&e.hide();if(this._onDocumentMouseMove)X(x,"mousemove",this._onDocumentMouseMove),this._onDocumentMouseMove=null;q(b.axes,function(a){a.hideCrosshair()});this.hoverX=null}},scaleGroups:function(a,b){var c=this.chart,d;q(c.series,function(e){d=a||e.getPlotBox();e.xAxis&&e.xAxis.zoomEnabled&&(e.group.attr(d),
|
||||
e.markerGroup&&(e.markerGroup.attr(d),e.markerGroup.clip(b?c.clipRect:null)),e.dataLabelsGroup&&e.dataLabelsGroup.attr(d))});c.clipRect.attr(b||c.clipBox)},dragStart:function(a){var b=this.chart;b.mouseIsDown=a.type;b.cancelClick=!1;b.mouseDownX=this.mouseDownX=a.chartX;b.mouseDownY=this.mouseDownY=a.chartY},drag:function(a){var b=this.chart,c=b.options.chart,d=a.chartX,e=a.chartY,f=this.zoomHor,g=this.zoomVert,h=b.plotLeft,i=b.plotTop,j=b.plotWidth,k=b.plotHeight,l,m=this.mouseDownX,n=this.mouseDownY,
|
||||
o=c.panKey&&a[c.panKey+"Key"];d<h?d=h:d>h+j&&(d=h+j);e<i?e=i:e>i+k&&(e=i+k);this.hasDragged=Math.sqrt(Math.pow(m-d,2)+Math.pow(n-e,2));if(this.hasDragged>10){l=b.isInsidePlot(m-h,n-i);if(b.hasCartesianSeries&&(this.zoomX||this.zoomY)&&l&&!o&&!this.selectionMarker)this.selectionMarker=b.renderer.rect(h,i,f?1:j,g?1:k,0).attr({fill:c.selectionMarkerFill||"rgba(69,114,167,0.25)",zIndex:7}).add();this.selectionMarker&&f&&(d-=m,this.selectionMarker.attr({width:Q(d),x:(d>0?0:d)+m}));this.selectionMarker&&
|
||||
g&&(d=e-n,this.selectionMarker.attr({height:Q(d),y:(d>0?0:d)+n}));l&&!this.selectionMarker&&c.panning&&b.pan(a,c.panning)}},drop:function(a){var b=this.chart,c=this.hasPinched;if(this.selectionMarker){var d={xAxis:[],yAxis:[],originalEvent:a.originalEvent||a},e=this.selectionMarker,f=e.attr?e.attr("x"):e.x,g=e.attr?e.attr("y"):e.y,h=e.attr?e.attr("width"):e.width,i=e.attr?e.attr("height"):e.height,j;if(this.hasDragged||c)q(b.axes,function(b){if(b.zoomEnabled){var c=b.horiz,e=a.type==="touchend"?b.minPixelPadding:
|
||||
0,n=b.toValue((c?f:g)+e),c=b.toValue((c?f+h:g+i)-e);!isNaN(n)&&!isNaN(c)&&(d[b.coll].push({axis:b,min:C(n,c),max:u(n,c)}),j=!0)}}),j&&K(b,"selection",d,function(a){b.zoom(r(a,c?{animation:!1}:null))});this.selectionMarker=this.selectionMarker.destroy();c&&this.scaleGroups()}if(b)A(b.container,{cursor:b._cursor}),b.cancelClick=this.hasDragged>10,b.mouseIsDown=this.hasDragged=this.hasPinched=!1,this.pinchDown=[]},onContainerMouseDown:function(a){a=this.normalize(a);a.preventDefault&&a.preventDefault();
|
||||
this.dragStart(a)},onDocumentMouseUp:function(a){W[pa]&&W[pa].pointer.drop(a)},onDocumentMouseMove:function(a){var b=this.chart,c=this.chartPosition,d=b.hoverSeries,a=this.normalize(a,c);c&&d&&!this.inClass(a.target,"highcharts-tracker")&&!b.isInsidePlot(a.chartX-b.plotLeft,a.chartY-b.plotTop)&&this.reset()},onContainerMouseLeave:function(){var a=W[pa];if(a)a.pointer.reset(),a.pointer.chartPosition=null},onContainerMouseMove:function(a){var b=this.chart;pa=b.index;a=this.normalize(a);a.returnValue=
|
||||
!1;b.mouseIsDown==="mousedown"&&this.drag(a);(this.inClass(a.target,"highcharts-tracker")||b.isInsidePlot(a.chartX-b.plotLeft,a.chartY-b.plotTop))&&!b.openMenu&&this.runPointActions(a)},inClass:function(a,b){for(var c;a;){if(c=F(a,"class"))if(c.indexOf(b)!==-1)return!0;else if(c.indexOf("highcharts-container")!==-1)return!1;a=a.parentNode}},onTrackerMouseOut:function(a){var b=this.chart.hoverSeries,c=(a=a.relatedTarget||a.toElement)&&a.point&&a.point.series;if(b&&!b.options.stickyTracking&&!this.inClass(a,
|
||||
"highcharts-tooltip")&&c!==b)b.onMouseOut()},onContainerClick:function(a){var b=this.chart,c=b.hoverPoint,d=b.plotLeft,e=b.plotTop,a=this.normalize(a);a.cancelBubble=!0;b.cancelClick||(c&&this.inClass(a.target,"highcharts-tracker")?(K(c.series,"click",r(a,{point:c})),b.hoverPoint&&c.firePointEvent("click",a)):(r(a,this.getCoordinates(a)),b.isInsidePlot(a.chartX-d,a.chartY-e)&&K(b,"click",a)))},setDOMEvents:function(){var a=this,b=a.chart.container;b.onmousedown=function(b){a.onContainerMouseDown(b)};
|
||||
b.onmousemove=function(b){a.onContainerMouseMove(b)};b.onclick=function(b){a.onContainerClick(b)};N(b,"mouseleave",a.onContainerMouseLeave);$a===1&&N(x,"mouseup",a.onDocumentMouseUp);if(Za)b.ontouchstart=function(b){a.onContainerTouchStart(b)},b.ontouchmove=function(b){a.onContainerTouchMove(b)},$a===1&&N(x,"touchend",a.onDocumentTouchEnd)},destroy:function(){var a;X(this.chart.container,"mouseleave",this.onContainerMouseLeave);$a||(X(x,"mouseup",this.onDocumentMouseUp),X(x,"touchend",this.onDocumentTouchEnd));
|
||||
clearInterval(this.tooltipTimeout);for(a in this)this[a]=null}};r(S.Pointer.prototype,{pinchTranslate:function(a,b,c,d,e,f){(this.zoomHor||this.pinchHor)&&this.pinchTranslateDirection(!0,a,b,c,d,e,f);(this.zoomVert||this.pinchVert)&&this.pinchTranslateDirection(!1,a,b,c,d,e,f)},pinchTranslateDirection:function(a,b,c,d,e,f,g,h){var i=this.chart,j=a?"x":"y",k=a?"X":"Y",l="chart"+k,m=a?"width":"height",n=i["plot"+(a?"Left":"Top")],o,p,q=h||1,r=i.inverted,D=i.bounds[a?"h":"v"],u=b.length===1,s=b[0][l],
|
||||
v=c[0][l],t=!u&&b[1][l],w=!u&&c[1][l],x,c=function(){!u&&Q(s-t)>20&&(q=h||Q(v-w)/Q(s-t));p=(n-v)/q+s;o=i["plot"+(a?"Width":"Height")]/q};c();b=p;b<D.min?(b=D.min,x=!0):b+o>D.max&&(b=D.max-o,x=!0);x?(v-=0.8*(v-g[j][0]),u||(w-=0.8*(w-g[j][1])),c()):g[j]=[v,w];r||(f[j]=p-n,f[m]=o);f=r?1/q:q;e[m]=o;e[j]=b;d[r?a?"scaleY":"scaleX":"scale"+k]=q;d["translate"+k]=f*n+(v-f*s)},pinch:function(a){var b=this,c=b.chart,d=b.pinchDown,e=b.followTouchMove,f=a.touches,g=f.length,h=b.lastValidTouch,i=b.hasZoom,j=b.selectionMarker,
|
||||
k={},l=g===1&&(b.inClass(a.target,"highcharts-tracker")&&c.runTrackerClick||c.runChartClick),m={};(i||e)&&!l&&a.preventDefault();Ua(f,function(a){return b.normalize(a)});if(a.type==="touchstart")q(f,function(a,b){d[b]={chartX:a.chartX,chartY:a.chartY}}),h.x=[d[0].chartX,d[1]&&d[1].chartX],h.y=[d[0].chartY,d[1]&&d[1].chartY],q(c.axes,function(a){if(a.zoomEnabled){var b=c.bounds[a.horiz?"h":"v"],d=a.minPixelPadding,e=a.toPixels(p(a.options.min,a.dataMin)),f=a.toPixels(p(a.options.max,a.dataMax)),g=
|
||||
C(e,f),e=u(e,f);b.min=C(a.pos,g-d);b.max=u(a.pos+a.len,e+d)}});else if(d.length){if(!j)b.selectionMarker=j=r({destroy:sa},c.plotBox);b.pinchTranslate(d,f,k,j,m,h);b.hasPinched=i;b.scaleGroups(k,m);!i&&e&&g===1&&this.runPointActions(b.normalize(a))}},onContainerTouchStart:function(a){var b=this.chart;pa=b.index;a.touches.length===1?(a=this.normalize(a),b.isInsidePlot(a.chartX-b.plotLeft,a.chartY-b.plotTop)?(this.runPointActions(a),this.pinch(a)):this.reset()):a.touches.length===2&&this.pinch(a)},onContainerTouchMove:function(a){(a.touches.length===
|
||||
1||a.touches.length===2)&&this.pinch(a)},onDocumentTouchEnd:function(a){W[pa]&&W[pa].pointer.drop(a)}});if(H.PointerEvent||H.MSPointerEvent){var ua={},yb=!!H.PointerEvent,Wb=function(){var a,b=[];b.item=function(a){return this[a]};for(a in ua)ua.hasOwnProperty(a)&&b.push({pageX:ua[a].pageX,pageY:ua[a].pageY,target:ua[a].target});return b},zb=function(a,b,c,d){a=a.originalEvent||a;if((a.pointerType==="touch"||a.pointerType===a.MSPOINTER_TYPE_TOUCH)&&W[pa])d(a),d=W[pa].pointer,d[b]({type:c,target:a.currentTarget,
|
||||
preventDefault:sa,touches:Wb()})};r(Va.prototype,{onContainerPointerDown:function(a){zb(a,"onContainerTouchStart","touchstart",function(a){ua[a.pointerId]={pageX:a.pageX,pageY:a.pageY,target:a.currentTarget}})},onContainerPointerMove:function(a){zb(a,"onContainerTouchMove","touchmove",function(a){ua[a.pointerId]={pageX:a.pageX,pageY:a.pageY};if(!ua[a.pointerId].target)ua[a.pointerId].target=a.currentTarget})},onDocumentPointerUp:function(a){zb(a,"onContainerTouchEnd","touchend",function(a){delete ua[a.pointerId]})},
|
||||
batchMSEvents:function(a){a(this.chart.container,yb?"pointerdown":"MSPointerDown",this.onContainerPointerDown);a(this.chart.container,yb?"pointermove":"MSPointerMove",this.onContainerPointerMove);a(x,yb?"pointerup":"MSPointerUp",this.onDocumentPointerUp)}});Ma(Va.prototype,"init",function(a,b,c){a.call(this,b,c);(this.hasZoom||this.followTouchMove)&&A(b.container,{"-ms-touch-action":P,"touch-action":P})});Ma(Va.prototype,"setDOMEvents",function(a){a.apply(this);(this.hasZoom||this.followTouchMove)&&
|
||||
this.batchMSEvents(N)});Ma(Va.prototype,"destroy",function(a){this.batchMSEvents(X);a.call(this)})}var kb=S.Legend=function(a,b){this.init(a,b)};kb.prototype={init:function(a,b){var c=this,d=b.itemStyle,e=p(b.padding,8),f=b.itemMarginTop||0;this.options=b;if(b.enabled)c.itemStyle=d,c.itemHiddenStyle=w(d,b.itemHiddenStyle),c.itemMarginTop=f,c.padding=e,c.initialItemX=e,c.initialItemY=e-5,c.maxItemWidth=0,c.chart=a,c.itemHeight=0,c.lastLineHeight=0,c.symbolWidth=p(b.symbolWidth,16),c.pages=[],c.render(),
|
||||
N(c.chart,"endResize",function(){c.positionCheckboxes()})},colorizeItem:function(a,b){var c=this.options,d=a.legendItem,e=a.legendLine,f=a.legendSymbol,g=this.itemHiddenStyle.color,c=b?c.itemStyle.color:g,h=b?a.legendColor||a.color||"#CCC":g,g=a.options&&a.options.marker,i={fill:h},j;d&&d.css({fill:c,color:c});e&&e.attr({stroke:h});if(f){if(g&&f.isMarker)for(j in i.stroke=h,g=a.convertAttribs(g),g)d=g[j],d!==t&&(i[j]=d);f.attr(i)}},positionItem:function(a){var b=this.options,c=b.symbolPadding,b=!b.rtl,
|
||||
d=a._legendItemPos,e=d[0],d=d[1],f=a.checkbox;a.legendGroup&&a.legendGroup.translate(b?e:this.legendWidth-e-2*c-4,d);if(f)f.x=e,f.y=d},destroyItem:function(a){var b=a.checkbox;q(["legendItem","legendLine","legendSymbol","legendGroup"],function(b){a[b]&&(a[b]=a[b].destroy())});b&&Pa(a.checkbox)},destroy:function(){var a=this.group,b=this.box;if(b)this.box=b.destroy();if(a)this.group=a.destroy()},positionCheckboxes:function(a){var b=this.group.alignAttr,c,d=this.clipHeight||this.legendHeight;if(b)c=
|
||||
b.translateY,q(this.allItems,function(e){var f=e.checkbox,g;f&&(g=c+f.y+(a||0)+3,A(f,{left:b.translateX+e.checkboxOffset+f.x-20+"px",top:g+"px",display:g>c-6&&g<c+d-6?"":P}))})},renderTitle:function(){var a=this.padding,b=this.options.title,c=0;if(b.text){if(!this.title)this.title=this.chart.renderer.label(b.text,a-3,a-4,null,null,null,null,null,"legend-title").attr({zIndex:1}).css(b.style).add(this.group);a=this.title.getBBox();c=a.height;this.offsetWidth=a.width;this.contentGroup.attr({translateY:c})}this.titleHeight=
|
||||
c},renderItem:function(a){var b=this.chart,c=b.renderer,d=this.options,e=d.layout==="horizontal",f=this.symbolWidth,g=d.symbolPadding,h=this.itemStyle,i=this.itemHiddenStyle,j=this.padding,k=e?p(d.itemDistance,20):0,l=!d.rtl,m=d.width,n=d.itemMarginBottom||0,o=this.itemMarginTop,q=this.initialItemX,r=a.legendItem,s=a.series&&a.series.drawLegendSymbol?a.series:a,D=s.options,D=this.createCheckboxForItem&&D&&D.showCheckbox,t=d.useHTML;if(!r){a.legendGroup=c.g("legend-item").attr({zIndex:1}).add(this.scrollGroup);
|
||||
a.legendItem=r=c.text(d.labelFormat?Ia(d.labelFormat,a):d.labelFormatter.call(a),l?f+g:-g,this.baseline||0,t).css(w(a.visible?h:i)).attr({align:l?"left":"right",zIndex:2}).add(a.legendGroup);if(!this.baseline)this.baseline=c.fontMetrics(h.fontSize,r).f+3+o,r.attr("y",this.baseline);s.drawLegendSymbol(this,a);this.setItemEvents&&this.setItemEvents(a,r,t,h,i);this.colorizeItem(a,a.visible);D&&this.createCheckboxForItem(a)}c=r.getBBox();f=a.checkboxOffset=d.itemWidth||a.legendItemWidth||f+g+c.width+
|
||||
k+(D?20:0);this.itemHeight=g=v(a.legendItemHeight||c.height);if(e&&this.itemX-q+f>(m||b.chartWidth-2*j-q-d.x))this.itemX=q,this.itemY+=o+this.lastLineHeight+n,this.lastLineHeight=0;this.maxItemWidth=u(this.maxItemWidth,f);this.lastItemY=o+this.itemY+n;this.lastLineHeight=u(g,this.lastLineHeight);a._legendItemPos=[this.itemX,this.itemY];e?this.itemX+=f:(this.itemY+=o+g+n,this.lastLineHeight=g);this.offsetWidth=m||u((e?this.itemX-q-k:f)+j,this.offsetWidth)},getAllItems:function(){var a=[];q(this.chart.series,
|
||||
function(b){var c=b.options;if(p(c.showInLegend,!s(c.linkedTo)?t:!1,!0))a=a.concat(b.legendItems||(c.legendType==="point"?b.data:b))});return a},render:function(){var a=this,b=a.chart,c=b.renderer,d=a.group,e,f,g,h,i=a.box,j=a.options,k=a.padding,l=j.borderWidth,m=j.backgroundColor;a.itemX=a.initialItemX;a.itemY=a.initialItemY;a.offsetWidth=0;a.lastItemY=0;if(!d)a.group=d=c.g("legend").attr({zIndex:7}).add(),a.contentGroup=c.g().attr({zIndex:1}).add(d),a.scrollGroup=c.g().add(a.contentGroup);a.renderTitle();
|
||||
e=a.getAllItems();nb(e,function(a,b){return(a.options&&a.options.legendIndex||0)-(b.options&&b.options.legendIndex||0)});j.reversed&&e.reverse();a.allItems=e;a.display=f=!!e.length;q(e,function(b){a.renderItem(b)});g=j.width||a.offsetWidth;h=a.lastItemY+a.lastLineHeight+a.titleHeight;h=a.handleOverflow(h);if(l||m){g+=k;h+=k;if(i){if(g>0&&h>0)i[i.isNew?"attr":"animate"](i.crisp({width:g,height:h})),i.isNew=!1}else a.box=i=c.rect(0,0,g,h,j.borderRadius,l||0).attr({stroke:j.borderColor,"stroke-width":l||
|
||||
0,fill:m||P}).add(d).shadow(j.shadow),i.isNew=!0;i[f?"show":"hide"]()}a.legendWidth=g;a.legendHeight=h;q(e,function(b){a.positionItem(b)});f&&d.align(r({width:g,height:h},j),!0,"spacingBox");b.isResizing||this.positionCheckboxes()},handleOverflow:function(a){var b=this,c=this.chart,d=c.renderer,e=this.options,f=e.y,f=c.spacingBox.height+(e.verticalAlign==="top"?-f:f)-this.padding,g=e.maxHeight,h,i=this.clipRect,j=e.navigation,k=p(j.animation,!0),l=j.arrowSize||12,m=this.nav,n=this.pages,o,r=this.allItems;
|
||||
e.layout==="horizontal"&&(f/=2);g&&(f=C(f,g));n.length=0;if(a>f&&!e.useHTML){this.clipHeight=h=u(f-20-this.titleHeight-this.padding,0);this.currentPage=p(this.currentPage,1);this.fullHeight=a;q(r,function(a,b){var c=a._legendItemPos[1],d=v(a.legendItem.getBBox().height),e=n.length;if(!e||c-n[e-1]>h&&(o||c)!==n[e-1])n.push(o||c),e++;b===r.length-1&&c+d-n[e-1]>h&&n.push(c);c!==o&&(o=c)});if(!i)i=b.clipRect=d.clipRect(0,this.padding,9999,0),b.contentGroup.clip(i);i.attr({height:h});if(!m)this.nav=m=
|
||||
d.g().attr({zIndex:1}).add(this.group),this.up=d.symbol("triangle",0,0,l,l).on("click",function(){b.scroll(-1,k)}).add(m),this.pager=d.text("",15,10).css(j.style).add(m),this.down=d.symbol("triangle-down",0,0,l,l).on("click",function(){b.scroll(1,k)}).add(m);b.scroll(0);a=f}else if(m)i.attr({height:c.chartHeight}),m.hide(),this.scrollGroup.attr({translateY:1}),this.clipHeight=0;return a},scroll:function(a,b){var c=this.pages,d=c.length,e=this.currentPage+a,f=this.clipHeight,g=this.options.navigation,
|
||||
h=g.activeColor,g=g.inactiveColor,i=this.pager,j=this.padding;e>d&&(e=d);if(e>0)b!==t&&Qa(b,this.chart),this.nav.attr({translateX:j,translateY:f+this.padding+7+this.titleHeight,visibility:"visible"}),this.up.attr({fill:e===1?g:h}).css({cursor:e===1?"default":"pointer"}),i.attr({text:e+"/"+d}),this.down.attr({x:18+this.pager.getBBox().width,fill:e===d?g:h}).css({cursor:e===d?"default":"pointer"}),c=-c[e-1]+this.initialItemY,this.scrollGroup.animate({translateY:c}),this.currentPage=e,this.positionCheckboxes(c)}};
|
||||
M=S.LegendSymbolMixin={drawRectangle:function(a,b){var c=a.options.symbolHeight||12;b.legendSymbol=this.chart.renderer.rect(0,a.baseline-5-c/2,a.symbolWidth,c,a.options.symbolRadius||0).attr({zIndex:3}).add(b.legendGroup)},drawLineMarker:function(a){var b=this.options,c=b.marker,d;d=a.symbolWidth;var e=this.chart.renderer,f=this.legendGroup,a=a.baseline-v(e.fontMetrics(a.options.itemStyle.fontSize,this.legendItem).b*0.3),g;if(b.lineWidth){g={"stroke-width":b.lineWidth};if(b.dashStyle)g.dashstyle=
|
||||
b.dashStyle;this.legendLine=e.path(["M",0,a,"L",d,a]).attr(g).add(f)}if(c&&c.enabled!==!1)b=c.radius,this.legendSymbol=d=e.symbol(this.symbol,d/2-b,a-b,2*b,2*b).add(f),d.isMarker=!0}};(/Trident\/7\.0/.test(wa)||Ta)&&Ma(kb.prototype,"positionItem",function(a,b){var c=this,d=function(){b._legendItemPos&&a.call(c,b)};d();setTimeout(d)});Xa.prototype={init:function(a,b){var c,d=a.series;a.series=null;c=w(L,a);c.series=a.series=d;this.userOptions=a;d=c.chart;this.margin=this.splashArray("margin",d);this.spacing=
|
||||
this.splashArray("spacing",d);var e=d.events;this.bounds={h:{},v:{}};this.callback=b;this.isResizing=0;this.options=c;this.axes=[];this.series=[];this.hasCartesianSeries=d.showAxes;var f=this,g;f.index=W.length;W.push(f);$a++;d.reflow!==!1&&N(f,"load",function(){f.initReflow()});if(e)for(g in e)N(f,g,e[g]);f.xAxis=[];f.yAxis=[];f.animation=ga?!1:p(d.animation,!0);f.pointCount=f.colorCounter=f.symbolCounter=0;f.firstRender()},initSeries:function(a){var b=this.options.chart;(b=J[a.type||b.type||b.defaultSeriesType])||
|
||||
oa(17,!0);b=new b;b.init(this,a);return b},isInsidePlot:function(a,b,c){var d=c?b:a,a=c?a:b;return d>=0&&d<=this.plotWidth&&a>=0&&a<=this.plotHeight},adjustTickAmounts:function(){this.options.chart.alignTicks!==!1&&q(this.axes,function(a){a.adjustTickAmount()});this.maxTicks=null},redraw:function(a){var b=this.axes,c=this.series,d=this.pointer,e=this.legend,f=this.isDirtyLegend,g,h,i=this.hasCartesianSeries,j=this.isDirtyBox,k=c.length,l=k,m=this.renderer,n=m.isHidden(),o=[];Qa(a,this);n&&this.cloneRenderTo();
|
||||
for(this.layOutTitles();l--;)if(a=c[l],a.options.stacking&&(g=!0,a.isDirty)){h=!0;break}if(h)for(l=k;l--;)if(a=c[l],a.options.stacking)a.isDirty=!0;q(c,function(a){a.isDirty&&a.options.legendType==="point"&&(f=!0)});if(f&&e.options.enabled)e.render(),this.isDirtyLegend=!1;g&&this.getStacks();if(i){if(!this.isResizing)this.maxTicks=null,q(b,function(a){a.setScale()});this.adjustTickAmounts()}this.getMargins();i&&(q(b,function(a){a.isDirty&&(j=!0)}),q(b,function(a){if(a.isDirtyExtremes)a.isDirtyExtremes=
|
||||
!1,o.push(function(){K(a,"afterSetExtremes",r(a.eventArgs,a.getExtremes()));delete a.eventArgs});(j||g)&&a.redraw()}));j&&this.drawChartBox();q(c,function(a){a.isDirty&&a.visible&&(!a.isCartesian||a.xAxis)&&a.redraw()});d&&d.reset(!0);m.draw();K(this,"redraw");n&&this.cloneRenderTo(!0);q(o,function(a){a.call()})},get:function(a){var b=this.axes,c=this.series,d,e;for(d=0;d<b.length;d++)if(b[d].options.id===a)return b[d];for(d=0;d<c.length;d++)if(c[d].options.id===a)return c[d];for(d=0;d<c.length;d++){e=
|
||||
c[d].points||[];for(b=0;b<e.length;b++)if(e[b].id===a)return e[b]}return null},getAxes:function(){var a=this,b=this.options,c=b.xAxis=ra(b.xAxis||{}),b=b.yAxis=ra(b.yAxis||{});q(c,function(a,b){a.index=b;a.isX=!0});q(b,function(a,b){a.index=b});c=c.concat(b);q(c,function(b){new ma(a,b)});a.adjustTickAmounts()},getSelectedPoints:function(){var a=[];q(this.series,function(b){a=a.concat(vb(b.points||[],function(a){return a.selected}))});return a},getSelectedSeries:function(){return vb(this.series,function(a){return a.selected})},
|
||||
getStacks:function(){var a=this;q(a.yAxis,function(a){if(a.stacks&&a.hasVisibleSeries)a.oldStacks=a.stacks});q(a.series,function(b){if(b.options.stacking&&(b.visible===!0||a.options.chart.ignoreHiddenSeries===!1))b.stackKey=b.type+p(b.options.stack,"")})},setTitle:function(a,b,c){var g;var d=this,e=d.options,f;f=e.title=w(e.title,a);g=e.subtitle=w(e.subtitle,b),e=g;q([["title",a,f],["subtitle",b,e]],function(a){var b=a[0],c=d[b],e=a[1],a=a[2];c&&e&&(d[b]=c=c.destroy());a&&a.text&&!c&&(d[b]=d.renderer.text(a.text,
|
||||
0,0,a.useHTML).attr({align:a.align,"class":"highcharts-"+b,zIndex:a.zIndex||4}).css(a.style).add())});d.layOutTitles(c)},layOutTitles:function(a){var b=0,c=this.title,d=this.subtitle,e=this.options,f=e.title,e=e.subtitle,g=this.renderer,h=this.spacingBox.width-44;if(c&&(c.css({width:(f.width||h)+"px"}).align(r({y:g.fontMetrics(f.style.fontSize,c).b-3},f),!1,"spacingBox"),!f.floating&&!f.verticalAlign))b=c.getBBox().height;d&&(d.css({width:(e.width||h)+"px"}).align(r({y:b+(f.margin-13)+g.fontMetrics(f.style.fontSize,
|
||||
d).b},e),!1,"spacingBox"),!e.floating&&!e.verticalAlign&&(b=Ka(b+d.getBBox().height)));c=this.titleOffset!==b;this.titleOffset=b;if(!this.isDirtyBox&&c)this.isDirtyBox=c,this.hasRendered&&p(a,!0)&&this.isDirtyBox&&this.redraw()},getChartSize:function(){var a=this.options.chart,b=a.width,a=a.height,c=this.renderToClone||this.renderTo;if(!s(b))this.containerWidth=hb(c,"width");if(!s(a))this.containerHeight=hb(c,"height");this.chartWidth=u(0,b||this.containerWidth||600);this.chartHeight=u(0,p(a,this.containerHeight>
|
||||
19?this.containerHeight:400))},cloneRenderTo:function(a){var b=this.renderToClone,c=this.container;a?b&&(this.renderTo.appendChild(c),Pa(b),delete this.renderToClone):(c&&c.parentNode===this.renderTo&&this.renderTo.removeChild(c),this.renderToClone=b=this.renderTo.cloneNode(0),A(b,{position:"absolute",top:"-9999px",display:"block"}),b.style.setProperty&&b.style.setProperty("display","block","important"),x.body.appendChild(b),c&&b.appendChild(c))},getContainer:function(){var a,b=this.options.chart,
|
||||
c,d,e;this.renderTo=a=b.renderTo;e="highcharts-"+tb++;if(Fa(a))this.renderTo=a=x.getElementById(a);a||oa(13,!0);c=z(F(a,"data-highcharts-chart"));!isNaN(c)&&W[c]&&W[c].hasRendered&&W[c].destroy();F(a,"data-highcharts-chart",this.index);a.innerHTML="";!b.skipClone&&!a.offsetWidth&&this.cloneRenderTo();this.getChartSize();c=this.chartWidth;d=this.chartHeight;this.container=a=$(Ja,{className:"highcharts-container"+(b.className?" "+b.className:""),id:e},r({position:"relative",overflow:"hidden",width:c+
|
||||
"px",height:d+"px",textAlign:"left",lineHeight:"normal",zIndex:0,"-webkit-tap-highlight-color":"rgba(0,0,0,0)"},b.style),this.renderToClone||a);this._cursor=a.style.cursor;this.renderer=b.forExport?new ta(a,c,d,b.style,!0):new Ya(a,c,d,b.style);ga&&this.renderer.create(this,a,c,d)},getMargins:function(){var a=this.spacing,b,c=this.legend,d=this.margin,e=this.options.legend,f=p(e.margin,20),g=e.x,h=e.y,i=e.align,j=e.verticalAlign,k=this.titleOffset;this.resetMargins();b=this.axisOffset;if(k&&!s(d[0]))this.plotTop=
|
||||
u(this.plotTop,k+this.options.title.margin+a[0]);if(c.display&&!e.floating)if(i==="right"){if(!s(d[1]))this.marginRight=u(this.marginRight,c.legendWidth-g+f+a[1])}else if(i==="left"){if(!s(d[3]))this.plotLeft=u(this.plotLeft,c.legendWidth+g+f+a[3])}else if(j==="top"){if(!s(d[0]))this.plotTop=u(this.plotTop,c.legendHeight+h+f+a[0])}else if(j==="bottom"&&!s(d[2]))this.marginBottom=u(this.marginBottom,c.legendHeight-h+f+a[2]);this.extraBottomMargin&&(this.marginBottom+=this.extraBottomMargin);this.extraTopMargin&&
|
||||
(this.plotTop+=this.extraTopMargin);this.hasCartesianSeries&&q(this.axes,function(a){a.getOffset()});s(d[3])||(this.plotLeft+=b[3]);s(d[0])||(this.plotTop+=b[0]);s(d[2])||(this.marginBottom+=b[2]);s(d[1])||(this.marginRight+=b[1]);this.setChartSize()},reflow:function(a){var b=this,c=b.options.chart,d=b.renderTo,e=c.width||hb(d,"width"),f=c.height||hb(d,"height"),c=a?a.target:H,d=function(){if(b.container)b.setSize(e,f,!1),b.hasUserSize=null};if(!b.hasUserSize&&e&&f&&(c===H||c===x)){if(e!==b.containerWidth||
|
||||
f!==b.containerHeight)clearTimeout(b.reflowTimeout),a?b.reflowTimeout=setTimeout(d,100):d();b.containerWidth=e;b.containerHeight=f}},initReflow:function(){var a=this,b=function(b){a.reflow(b)};N(H,"resize",b);N(a,"destroy",function(){X(H,"resize",b)})},setSize:function(a,b,c){var d=this,e,f,g;d.isResizing+=1;g=function(){d&&K(d,"endResize",null,function(){d.isResizing-=1})};Qa(c,d);d.oldChartHeight=d.chartHeight;d.oldChartWidth=d.chartWidth;if(s(a))d.chartWidth=e=u(0,v(a)),d.hasUserSize=!!e;if(s(b))d.chartHeight=
|
||||
f=u(0,v(b));(va?ib:A)(d.container,{width:e+"px",height:f+"px"},va);d.setChartSize(!0);d.renderer.setSize(e,f,c);d.maxTicks=null;q(d.axes,function(a){a.isDirty=!0;a.setScale()});q(d.series,function(a){a.isDirty=!0});d.isDirtyLegend=!0;d.isDirtyBox=!0;d.layOutTitles();d.getMargins();d.redraw(c);d.oldChartHeight=null;K(d,"resize");va===!1?g():setTimeout(g,va&&va.duration||500)},setChartSize:function(a){var b=this.inverted,c=this.renderer,d=this.chartWidth,e=this.chartHeight,f=this.options.chart,g=this.spacing,
|
||||
h=this.clipOffset,i,j,k,l;this.plotLeft=i=v(this.plotLeft);this.plotTop=j=v(this.plotTop);this.plotWidth=k=u(0,v(d-i-this.marginRight));this.plotHeight=l=u(0,v(e-j-this.marginBottom));this.plotSizeX=b?l:k;this.plotSizeY=b?k:l;this.plotBorderWidth=f.plotBorderWidth||0;this.spacingBox=c.spacingBox={x:g[3],y:g[0],width:d-g[3]-g[1],height:e-g[0]-g[2]};this.plotBox=c.plotBox={x:i,y:j,width:k,height:l};d=2*U(this.plotBorderWidth/2);b=Ka(u(d,h[3])/2);c=Ka(u(d,h[0])/2);this.clipBox={x:b,y:c,width:U(this.plotSizeX-
|
||||
u(d,h[1])/2-b),height:u(0,U(this.plotSizeY-u(d,h[2])/2-c))};a||q(this.axes,function(a){a.setAxisSize();a.setAxisTranslation()})},resetMargins:function(){var a=this.spacing,b=this.margin;this.plotTop=p(b[0],a[0]);this.marginRight=p(b[1],a[1]);this.marginBottom=p(b[2],a[2]);this.plotLeft=p(b[3],a[3]);this.axisOffset=[0,0,0,0];this.clipOffset=[0,0,0,0]},drawChartBox:function(){var a=this.options.chart,b=this.renderer,c=this.chartWidth,d=this.chartHeight,e=this.chartBackground,f=this.plotBackground,g=
|
||||
this.plotBorder,h=this.plotBGImage,i=a.borderWidth||0,j=a.backgroundColor,k=a.plotBackgroundColor,l=a.plotBackgroundImage,m=a.plotBorderWidth||0,n,o=this.plotLeft,p=this.plotTop,q=this.plotWidth,r=this.plotHeight,u=this.plotBox,s=this.clipRect,v=this.clipBox;n=i+(a.shadow?8:0);if(i||j)if(e)e.animate(e.crisp({width:c-n,height:d-n}));else{e={fill:j||P};if(i)e.stroke=a.borderColor,e["stroke-width"]=i;this.chartBackground=b.rect(n/2,n/2,c-n,d-n,a.borderRadius,i).attr(e).addClass("highcharts-background").add().shadow(a.shadow)}if(k)f?
|
||||
f.animate(u):this.plotBackground=b.rect(o,p,q,r,0).attr({fill:k}).add().shadow(a.plotShadow);if(l)h?h.animate(u):this.plotBGImage=b.image(l,o,p,q,r).add();s?s.animate({width:v.width,height:v.height}):this.clipRect=b.clipRect(v);if(m)g?g.animate(g.crisp({x:o,y:p,width:q,height:r})):this.plotBorder=b.rect(o,p,q,r,0,-m).attr({stroke:a.plotBorderColor,"stroke-width":m,fill:P,zIndex:1}).add();this.isDirtyBox=!1},propFromSeries:function(){var a=this,b=a.options.chart,c,d=a.options.series,e,f;q(["inverted",
|
||||
"angular","polar"],function(g){c=J[b.type||b.defaultSeriesType];f=a[g]||b[g]||c&&c.prototype[g];for(e=d&&d.length;!f&&e--;)(c=J[d[e].type])&&c.prototype[g]&&(f=!0);a[g]=f})},linkSeries:function(){var a=this,b=a.series;q(b,function(a){a.linkedSeries.length=0});q(b,function(b){var d=b.options.linkedTo;if(Fa(d)&&(d=d===":previous"?a.series[b.index-1]:a.get(d)))d.linkedSeries.push(b),b.linkedParent=d})},renderSeries:function(){q(this.series,function(a){a.translate();a.setTooltipPoints&&a.setTooltipPoints();
|
||||
a.render()})},renderLabels:function(){var a=this,b=a.options.labels;b.items&&q(b.items,function(c){var d=r(b.style,c.style),e=z(d.left)+a.plotLeft,f=z(d.top)+a.plotTop+12;delete d.left;delete d.top;a.renderer.text(c.html,e,f).attr({zIndex:2}).css(d).add()})},render:function(){var a=this.axes,b=this.renderer,c=this.options;this.setTitle();this.legend=new kb(this,c.legend);this.getStacks();q(a,function(a){a.setScale()});this.getMargins();this.maxTicks=null;q(a,function(a){a.setTickPositions(!0);a.setMaxTicks()});
|
||||
this.adjustTickAmounts();this.getMargins();this.drawChartBox();this.hasCartesianSeries&&q(a,function(a){a.render()});if(!this.seriesGroup)this.seriesGroup=b.g("series-group").attr({zIndex:3}).add();this.renderSeries();this.renderLabels();this.showCredits(c.credits);this.hasRendered=!0},showCredits:function(a){if(a.enabled&&!this.credits)this.credits=this.renderer.text(a.text,0,0).on("click",function(){if(a.href)location.href=a.href}).attr({align:a.position.align,zIndex:8}).css(a.style).add().align(a.position)},
|
||||
destroy:function(){var a=this,b=a.axes,c=a.series,d=a.container,e,f=d&&d.parentNode;K(a,"destroy");W[a.index]=t;$a--;a.renderTo.removeAttribute("data-highcharts-chart");X(a);for(e=b.length;e--;)b[e]=b[e].destroy();for(e=c.length;e--;)c[e]=c[e].destroy();q("title,subtitle,chartBackground,plotBackground,plotBGImage,plotBorder,seriesGroup,clipRect,credits,pointer,scroller,rangeSelector,legend,resetZoomButton,tooltip,renderer".split(","),function(b){var c=a[b];c&&c.destroy&&(a[b]=c.destroy())});if(d)d.innerHTML=
|
||||
"",X(d),f&&Pa(d);for(e in a)delete a[e]},isReadyToRender:function(){var a=this;return!ba&&H==H.top&&x.readyState!=="complete"||ga&&!H.canvg?(ga?Lb.push(function(){a.firstRender()},a.options.global.canvasToolsURL):x.attachEvent("onreadystatechange",function(){x.detachEvent("onreadystatechange",a.firstRender);x.readyState==="complete"&&a.firstRender()}),!1):!0},firstRender:function(){var a=this,b=a.options,c=a.callback;if(a.isReadyToRender()){a.getContainer();K(a,"init");a.resetMargins();a.setChartSize();
|
||||
a.propFromSeries();a.getAxes();q(b.series||[],function(b){a.initSeries(b)});a.linkSeries();K(a,"beforeRender");if(S.Pointer)a.pointer=new Va(a,b);a.render();a.renderer.draw();c&&c.apply(a,[a]);q(a.callbacks,function(b){b.apply(a,[a])});a.cloneRenderTo(!0);K(a,"load")}},splashArray:function(a,b){var c=b[a],c=da(c)?c:[c,c,c,c];return[p(b[a+"Top"],c[0]),p(b[a+"Right"],c[1]),p(b[a+"Bottom"],c[2]),p(b[a+"Left"],c[3])]}};Xa.prototype.callbacks=[];Z=S.CenteredSeriesMixin={getCenter:function(){var a=this.options,
|
||||
b=this.chart,c=2*(a.slicedOffset||0),d,e=b.plotWidth-2*c,f=b.plotHeight-2*c,b=a.center,a=[p(b[0],"50%"),p(b[1],"50%"),a.size||"100%",a.innerSize||0],g=C(e,f),h;return Ua(a,function(a,b){h=/%$/.test(a);d=b<2||b===2&&h;return(h?[e,f,g,g][b]*z(a)/100:a)+(d?c:0)})}};var Ea=function(){};Ea.prototype={init:function(a,b,c){this.series=a;this.applyOptions(b,c);this.pointAttr={};if(a.options.colorByPoint&&(b=a.options.colors||a.chart.options.colors,this.color=this.color||b[a.colorCounter++],a.colorCounter===
|
||||
b.length))a.colorCounter=0;a.chart.pointCount++;return this},applyOptions:function(a,b){var c=this.series,d=c.options.pointValKey||c.pointValKey,a=Ea.prototype.optionsToObject.call(this,a);r(this,a);this.options=this.options?r(this.options,a):a;if(d)this.y=this[d];if(this.x===t&&c)this.x=b===t?c.autoIncrement():b;return this},optionsToObject:function(a){var b={},c=this.series,d=c.pointArrayMap||["y"],e=d.length,f=0,g=0;if(typeof a==="number"||a===null)b[d[0]]=a;else if(La(a)){if(a.length>e){c=typeof a[0];
|
||||
if(c==="string")b.name=a[0];else if(c==="number")b.x=a[0];f++}for(;g<e;)b[d[g++]]=a[f++]}else if(typeof a==="object"){b=a;if(a.dataLabels)c._hasPointLabels=!0;if(a.marker)c._hasPointMarkers=!0}return b},destroy:function(){var a=this.series.chart,b=a.hoverPoints,c;a.pointCount--;if(b&&(this.setState(),ka(b,this),!b.length))a.hoverPoints=null;if(this===a.hoverPoint)this.onMouseOut();if(this.graphic||this.dataLabel)X(this),this.destroyElements();this.legendItem&&a.legend.destroyItem(this);for(c in this)this[c]=
|
||||
null},destroyElements:function(){for(var a="graphic,dataLabel,dataLabelUpper,group,connector,shadowGroup".split(","),b,c=6;c--;)b=a[c],this[b]&&(this[b]=this[b].destroy())},getLabelConfig:function(){return{x:this.category,y:this.y,key:this.name||this.category,series:this.series,point:this,percentage:this.percentage,total:this.total||this.stackTotal}},tooltipFormatter:function(a){var b=this.series,c=b.tooltipOptions,d=p(c.valueDecimals,""),e=c.valuePrefix||"",f=c.valueSuffix||"";q(b.pointArrayMap||
|
||||
["y"],function(b){b="{point."+b;if(e||f)a=a.replace(b+"}",e+b+"}"+f);a=a.replace(b+"}",b+":,."+d+"f}")});return Ia(a,{point:this,series:this.series})},firePointEvent:function(a,b,c){var d=this,e=this.series.options;(e.point.events[a]||d.options&&d.options.events&&d.options.events[a])&&this.importEvents();a==="click"&&e.allowPointSelect&&(c=function(a){d.select(null,a.ctrlKey||a.metaKey||a.shiftKey)});K(this,a,b,c)}};var O=function(){};O.prototype={isCartesian:!0,type:"line",pointClass:Ea,sorted:!0,
|
||||
requireSorting:!0,pointAttrToOptions:{stroke:"lineColor","stroke-width":"lineWidth",fill:"fillColor",r:"radius"},axisTypes:["xAxis","yAxis"],colorCounter:0,parallelArrays:["x","y"],init:function(a,b){var c=this,d,e,f=a.series,g=function(a,b){return p(a.options.index,a._i)-p(b.options.index,b._i)};c.chart=a;c.options=b=c.setOptions(b);c.linkedSeries=[];c.bindAxes();r(c,{name:b.name,state:"",pointAttr:{},visible:b.visible!==!1,selected:b.selected===!0});if(ga)b.animation=!1;e=b.events;for(d in e)N(c,
|
||||
d,e[d]);if(e&&e.click||b.point&&b.point.events&&b.point.events.click||b.allowPointSelect)a.runTrackerClick=!0;c.getColor();c.getSymbol();q(c.parallelArrays,function(a){c[a+"Data"]=[]});c.setData(b.data,!1);if(c.isCartesian)a.hasCartesianSeries=!0;f.push(c);c._i=f.length-1;nb(f,g);this.yAxis&&nb(this.yAxis.series,g);q(f,function(a,b){a.index=b;a.name=a.name||"Series "+(b+1)})},bindAxes:function(){var a=this,b=a.options,c=a.chart,d;q(a.axisTypes||[],function(e){q(c[e],function(c){d=c.options;if(b[e]===
|
||||
d.index||b[e]!==t&&b[e]===d.id||b[e]===t&&d.index===0)c.series.push(a),a[e]=c,c.isDirty=!0});!a[e]&&a.optionalAxis!==e&&oa(18,!0)})},updateParallelArrays:function(a,b){var c=a.series,d=arguments;q(c.parallelArrays,typeof b==="number"?function(d){var f=d==="y"&&c.toYData?c.toYData(a):a[d];c[d+"Data"][b]=f}:function(a){Array.prototype[b].apply(c[a+"Data"],Array.prototype.slice.call(d,2))})},autoIncrement:function(){var a=this.options,b=this.xIncrement,b=p(b,a.pointStart,0);this.pointInterval=p(this.pointInterval,
|
||||
a.pointInterval,1);this.xIncrement=b+this.pointInterval;return b},getSegments:function(){var a=-1,b=[],c,d=this.points,e=d.length;if(e)if(this.options.connectNulls){for(c=e;c--;)d[c].y===null&&d.splice(c,1);d.length&&(b=[d])}else q(d,function(c,g){c.y===null?(g>a+1&&b.push(d.slice(a+1,g)),a=g):g===e-1&&b.push(d.slice(a+1,g+1))});this.segments=b},setOptions:function(a){var b=this.chart,c=b.options.plotOptions,b=b.userOptions||{},d=b.plotOptions||{},e=c[this.type];this.userOptions=a;c=w(e,c.series,
|
||||
a);this.tooltipOptions=w(L.tooltip,L.plotOptions[this.type].tooltip,b.tooltip,d.series&&d.series.tooltip,d[this.type]&&d[this.type].tooltip,a.tooltip);e.marker===null&&delete c.marker;return c},getCyclic:function(a,b,c){var d=this.userOptions,e="_"+a+"Index",f=a+"Counter";b||(s(d[e])?b=d[e]:(d[e]=b=this.chart[f]%c.length,this.chart[f]+=1),b=c[b]);this[a]=b},getColor:function(){this.options.colorByPoint||this.getCyclic("color",this.options.color||ca[this.type].color,this.chart.options.colors)},getSymbol:function(){var a=
|
||||
this.options.marker;this.getCyclic("symbol",a.symbol,this.chart.options.symbols);if(/^url/.test(this.symbol))a.radius=0},drawLegendSymbol:M.drawLineMarker,setData:function(a,b,c,d){var e=this,f=e.points,g=f&&f.length||0,h,i=e.options,j=e.chart,k=null,l=e.xAxis,m=l&&!!l.categories,n=e.tooltipPoints,o=i.turboThreshold,r=this.xData,u=this.yData,s=(h=e.pointArrayMap)&&h.length,a=a||[];h=a.length;b=p(b,!0);if(d!==!1&&h&&g===h&&!e.cropped&&!e.hasGroupedData)q(a,function(a,b){f[b].update(a,!1)});else{e.xIncrement=
|
||||
null;e.pointRange=m?1:i.pointRange;e.colorCounter=0;q(this.parallelArrays,function(a){e[a+"Data"].length=0});if(o&&h>o){for(c=0;k===null&&c<h;)k=a[c],c++;if(ia(k)){m=p(i.pointStart,0);i=p(i.pointInterval,1);for(c=0;c<h;c++)r[c]=m,u[c]=a[c],m+=i;e.xIncrement=m}else if(La(k))if(s)for(c=0;c<h;c++)i=a[c],r[c]=i[0],u[c]=i.slice(1,s+1);else for(c=0;c<h;c++)i=a[c],r[c]=i[0],u[c]=i[1];else oa(12)}else for(c=0;c<h;c++)if(a[c]!==t&&(i={series:e},e.pointClass.prototype.applyOptions.apply(i,[a[c]]),e.updateParallelArrays(i,
|
||||
c),m&&i.name))l.names[i.x]=i.name;Fa(u[0])&&oa(14,!0);e.data=[];e.options.data=a;for(c=g;c--;)f[c]&&f[c].destroy&&f[c].destroy();if(n)n.length=0;if(l)l.minRange=l.userMinRange;e.isDirty=e.isDirtyData=j.isDirtyBox=!0;c=!1}b&&j.redraw(c)},processData:function(a){var b=this.xData,c=this.yData,d=b.length,e;e=0;var f,g,h=this.xAxis,i=this.options,j=i.cropThreshold,k=0,l=this.isCartesian,m,n;if(l&&!this.isDirty&&!h.isDirty&&!this.yAxis.isDirty&&!a)return!1;if(l&&this.sorted&&(!j||d>j||this.forceCrop))if(m=
|
||||
h.getExtremes(),n=m.min,m=m.max,b[d-1]<n||b[0]>m)b=[],c=[];else if(b[0]<n||b[d-1]>m)e=this.cropData(this.xData,this.yData,n,m),b=e.xData,c=e.yData,e=e.start,f=!0,k=b.length;for(a=b.length-1;a>=0;a--)d=b[a]-b[a-1],!f&&b[a]>n&&b[a]<m&&k++,d>0&&(g===t||d<g)?g=d:d<0&&this.requireSorting&&oa(15);this.cropped=f;this.cropStart=e;this.processedXData=b;this.processedYData=c;this.activePointCount=k;if(i.pointRange===null)this.pointRange=g||1;this.closestPointRange=g},cropData:function(a,b,c,d){var e=a.length,
|
||||
f=0,g=e,h=p(this.cropShoulder,1),i;for(i=0;i<e;i++)if(a[i]>=c){f=u(0,i-h);break}for(;i<e;i++)if(a[i]>d){g=i+h;break}return{xData:a.slice(f,g),yData:b.slice(f,g),start:f,end:g}},generatePoints:function(){var a=this.options.data,b=this.data,c,d=this.processedXData,e=this.processedYData,f=this.pointClass,g=d.length,h=this.cropStart||0,i,j=this.hasGroupedData,k,l=[],m;if(!b&&!j)b=[],b.length=a.length,b=this.data=b;for(m=0;m<g;m++)i=h+m,j?l[m]=(new f).init(this,[d[m]].concat(ra(e[m]))):(b[i]?k=b[i]:a[i]!==
|
||||
t&&(b[i]=k=(new f).init(this,a[i],d[m])),l[m]=k);if(b&&(g!==(c=b.length)||j))for(m=0;m<c;m++)if(m===h&&!j&&(m+=g),b[m])b[m].destroyElements(),b[m].plotX=t;this.data=b;this.points=l},getExtremes:function(a){var b=this.yAxis,c=this.processedXData,d,e=[],f=0;d=this.xAxis.getExtremes();var g=d.min,h=d.max,i,j,k,l,a=a||this.stackedYData||this.processedYData;d=a.length;for(l=0;l<d;l++)if(j=c[l],k=a[l],i=k!==null&&k!==t&&(!b.isLog||k.length||k>0),j=this.getExtremesFromAll||this.cropped||(c[l+1]||j)>=g&&
|
||||
(c[l-1]||j)<=h,i&&j)if(i=k.length)for(;i--;)k[i]!==null&&(e[f++]=k[i]);else e[f++]=k;this.dataMin=p(void 0,Na(e));this.dataMax=p(void 0,Ba(e))},translate:function(){this.processedXData||this.processData();this.generatePoints();for(var a=this.options,b=a.stacking,c=this.xAxis,d=c.categories,e=this.yAxis,f=this.points,g=f.length,h=!!this.modifyValue,i=a.pointPlacement,j=i==="between"||ia(i),k=a.threshold,a=0;a<g;a++){var l=f[a],m=l.x,n=l.y,o=l.low,q=b&&e.stacks[(this.negStacks&&n<k?"-":"")+this.stackKey];
|
||||
if(e.isLog&&n<=0)l.y=n=null;l.plotX=c.translate(m,0,0,0,1,i,this.type==="flags");if(b&&this.visible&&q&&q[m])q=q[m],n=q.points[this.index+","+a],o=n[0],n=n[1],o===0&&(o=p(k,e.min)),e.isLog&&o<=0&&(o=null),l.total=l.stackTotal=q.total,l.percentage=q.total&&l.y/q.total*100,l.stackY=n,q.setOffset(this.pointXOffset||0,this.barW||0);l.yBottom=s(o)?e.translate(o,0,1,0,1):null;h&&(n=this.modifyValue(n,l));l.plotY=typeof n==="number"&&n!==Infinity?e.translate(n,0,1,0,1):t;l.clientX=j?c.translate(m,0,0,0,
|
||||
1):l.plotX;l.negative=l.y<(k||0);l.category=d&&d[l.x]!==t?d[l.x]:l.x}this.getSegments()},animate:function(a){var b=this.chart,c=b.renderer,d;d=this.options.animation;var e=this.clipBox||b.clipBox,f=b.inverted,g;if(d&&!da(d))d=ca[this.type].animation;g=["_sharedClip",d.duration,d.easing,e.height].join(",");a?(a=b[g],d=b[g+"m"],a||(b[g]=a=c.clipRect(r(e,{width:0})),b[g+"m"]=d=c.clipRect(-99,f?-b.plotLeft:-b.plotTop,99,f?b.chartWidth:b.chartHeight)),this.group.clip(a),this.markerGroup.clip(d),this.sharedClipKey=
|
||||
g):((a=b[g])&&a.animate({width:b.plotSizeX},d),b[g+"m"]&&b[g+"m"].animate({width:b.plotSizeX+99},d),this.animate=null)},afterAnimate:function(){var a=this.chart,b=this.sharedClipKey,c=this.group,d=this.clipBox;if(c&&this.options.clip!==!1){if(!b||!d)c.clip(d?a.renderer.clipRect(d):a.clipRect);this.markerGroup.clip()}K(this,"afterAnimate");setTimeout(function(){b&&a[b]&&(d||(a[b]=a[b].destroy()),a[b+"m"]&&(a[b+"m"]=a[b+"m"].destroy()))},100)},drawPoints:function(){var a,b=this.points,c=this.chart,
|
||||
d,e,f,g,h,i,j,k;d=this.options.marker;var l=this.pointAttr[""],m,n=this.markerGroup,o=p(d.enabled,this.activePointCount<0.5*this.xAxis.len/d.radius);if(d.enabled!==!1||this._hasPointMarkers)for(f=b.length;f--;)if(g=b[f],d=U(g.plotX),e=g.plotY,k=g.graphic,i=g.marker||{},a=o&&i.enabled===t||i.enabled,m=c.isInsidePlot(v(d),e,c.inverted),a&&e!==t&&!isNaN(e)&&g.y!==null)if(a=g.pointAttr[g.selected?"select":""]||l,h=a.r,i=p(i.symbol,this.symbol),j=i.indexOf("url")===0,k)k[m?"show":"hide"](!0).animate(r({x:d-
|
||||
h,y:e-h},k.symbolName?{width:2*h,height:2*h}:{}));else{if(m&&(h>0||j))g.graphic=c.renderer.symbol(i,d-h,e-h,2*h,2*h).attr(a).add(n)}else if(k)g.graphic=k.destroy()},convertAttribs:function(a,b,c,d){var e=this.pointAttrToOptions,f,g,h={},a=a||{},b=b||{},c=c||{},d=d||{};for(f in e)g=e[f],h[f]=p(a[g],b[f],c[f],d[f]);return h},getAttribs:function(){var a=this,b=a.options,c=ca[a.type].marker?b.marker:b,d=c.states,e=d.hover,f,g=a.color;f={stroke:g,fill:g};var h=a.points||[],i,j=[],k,l=a.pointAttrToOptions;
|
||||
k=a.hasPointSpecificOptions;var m=b.negativeColor,n=c.lineColor,o=c.fillColor;i=b.turboThreshold;var p;b.marker?(e.radius=e.radius||c.radius+e.radiusPlus,e.lineWidth=e.lineWidth||c.lineWidth+e.lineWidthPlus):e.color=e.color||ya(e.color||g).brighten(e.brightness).get();j[""]=a.convertAttribs(c,f);q(["hover","select"],function(b){j[b]=a.convertAttribs(d[b],j[""])});a.pointAttr=j;g=h.length;if(!i||g<i||k)for(;g--;){i=h[g];if((c=i.options&&i.options.marker||i.options)&&c.enabled===!1)c.radius=0;if(i.negative&&
|
||||
m)i.color=i.fillColor=m;k=b.colorByPoint||i.color;if(i.options)for(p in l)s(c[l[p]])&&(k=!0);if(k){c=c||{};k=[];d=c.states||{};f=d.hover=d.hover||{};if(!b.marker)f.color=f.color||!i.options.color&&e.color||ya(i.color).brighten(f.brightness||e.brightness).get();f={color:i.color};if(!o)f.fillColor=i.color;if(!n)f.lineColor=i.color;k[""]=a.convertAttribs(r(f,c),j[""]);k.hover=a.convertAttribs(d.hover,j.hover,k[""]);k.select=a.convertAttribs(d.select,j.select,k[""])}else k=j;i.pointAttr=k}},destroy:function(){var a=
|
||||
this,b=a.chart,c=/AppleWebKit\/533/.test(wa),d,e,f=a.data||[],g,h,i;K(a,"destroy");X(a);q(a.axisTypes||[],function(b){if(i=a[b])ka(i.series,a),i.isDirty=i.forceRedraw=!0});a.legendItem&&a.chart.legend.destroyItem(a);for(e=f.length;e--;)(g=f[e])&&g.destroy&&g.destroy();a.points=null;clearTimeout(a.animationTimeout);q("area,graph,dataLabelsGroup,group,markerGroup,tracker,graphNeg,areaNeg,posClip,negClip".split(","),function(b){a[b]&&(d=c&&b==="group"?"hide":"destroy",a[b][d]())});if(b.hoverSeries===
|
||||
a)b.hoverSeries=null;ka(b.series,a);for(h in a)delete a[h]},getSegmentPath:function(a){var b=this,c=[],d=b.options.step;q(a,function(e,f){var g=e.plotX,h=e.plotY,i;b.getPointSpline?c.push.apply(c,b.getPointSpline(a,e,f)):(c.push(f?"L":"M"),d&&f&&(i=a[f-1],d==="right"?c.push(i.plotX,h):d==="center"?c.push((i.plotX+g)/2,i.plotY,(i.plotX+g)/2,h):c.push(g,i.plotY)),c.push(e.plotX,e.plotY))});return c},getGraphPath:function(){var a=this,b=[],c,d=[];q(a.segments,function(e){c=a.getSegmentPath(e);e.length>
|
||||
1?b=b.concat(c):d.push(e[0])});a.singlePoints=d;return a.graphPath=b},drawGraph:function(){var a=this,b=this.options,c=[["graph",b.lineColor||this.color]],d=b.lineWidth,e=b.dashStyle,f=b.linecap!=="square",g=this.getGraphPath(),h=b.negativeColor;h&&c.push(["graphNeg",h]);q(c,function(c,h){var k=c[0],l=a[k];if(l)ab(l),l.animate({d:g});else if(d&&g.length)l={stroke:c[1],"stroke-width":d,fill:P,zIndex:1},e?l.dashstyle=e:f&&(l["stroke-linecap"]=l["stroke-linejoin"]="round"),a[k]=a.chart.renderer.path(g).attr(l).add(a.group).shadow(!h&&
|
||||
b.shadow)})},clipNeg:function(){var a=this.options,b=this.chart,c=b.renderer,d=a.negativeColor||a.negativeFillColor,e,f=this.graph,g=this.area,h=this.posClip,i=this.negClip;e=b.chartWidth;var j=b.chartHeight,k=u(e,j),l=this.yAxis;if(d&&(f||g)){d=v(l.toPixels(a.threshold||0,!0));d<0&&(k-=d);a={x:0,y:0,width:k,height:d};k={x:0,y:d,width:k,height:k};if(b.inverted)a.height=k.y=b.plotWidth-d,c.isVML&&(a={x:b.plotWidth-d-b.plotLeft,y:0,width:e,height:j},k={x:d+b.plotLeft-e,y:0,width:b.plotLeft+d,height:e});
|
||||
l.reversed?(b=k,e=a):(b=a,e=k);h?(h.animate(b),i.animate(e)):(this.posClip=h=c.clipRect(b),this.negClip=i=c.clipRect(e),f&&this.graphNeg&&(f.clip(h),this.graphNeg.clip(i)),g&&(g.clip(h),this.areaNeg.clip(i)))}},invertGroups:function(){function a(){var a={width:b.yAxis.len,height:b.xAxis.len};q(["group","markerGroup"],function(c){b[c]&&b[c].attr(a).invert()})}var b=this,c=b.chart;if(b.xAxis)N(c,"resize",a),N(b,"destroy",function(){X(c,"resize",a)}),a(),b.invertGroups=a},plotGroup:function(a,b,c,d,
|
||||
e){var f=this[a],g=!f;g&&(this[a]=f=this.chart.renderer.g(b).attr({visibility:c,zIndex:d||0.1}).add(e));f[g?"attr":"animate"](this.getPlotBox());return f},getPlotBox:function(){var a=this.chart,b=this.xAxis,c=this.yAxis;if(a.inverted)b=c,c=this.xAxis;return{translateX:b?b.left:a.plotLeft,translateY:c?c.top:a.plotTop,scaleX:1,scaleY:1}},render:function(){var a=this,b=a.chart,c,d=a.options,e=(c=d.animation)&&!!a.animate&&b.renderer.isSVG&&p(c.duration,500)||0,f=a.visible?"visible":"hidden",g=d.zIndex,
|
||||
h=a.hasRendered,i=b.seriesGroup;c=a.plotGroup("group","series",f,g,i);a.markerGroup=a.plotGroup("markerGroup","markers",f,g,i);e&&a.animate(!0);a.getAttribs();c.inverted=a.isCartesian?b.inverted:!1;a.drawGraph&&(a.drawGraph(),a.clipNeg());a.drawDataLabels&&a.drawDataLabels();a.visible&&a.drawPoints();a.drawTracker&&a.options.enableMouseTracking!==!1&&a.drawTracker();b.inverted&&a.invertGroups();d.clip!==!1&&!a.sharedClipKey&&!h&&c.clip(b.clipRect);e&&a.animate();if(!h)e?a.animationTimeout=setTimeout(function(){a.afterAnimate()},
|
||||
e):a.afterAnimate();a.isDirty=a.isDirtyData=!1;a.hasRendered=!0},redraw:function(){var a=this.chart,b=this.isDirtyData,c=this.group,d=this.xAxis,e=this.yAxis;c&&(a.inverted&&c.attr({width:a.plotWidth,height:a.plotHeight}),c.animate({translateX:p(d&&d.left,a.plotLeft),translateY:p(e&&e.top,a.plotTop)}));this.translate();this.setTooltipPoints&&this.setTooltipPoints(!0);this.render();b&&K(this,"updatedData")}};Fb.prototype={destroy:function(){Oa(this,this.axis)},render:function(a){var b=this.options,
|
||||
c=b.format,c=c?Ia(c,this):b.formatter.call(this);this.label?this.label.attr({text:c,visibility:"hidden"}):this.label=this.axis.chart.renderer.text(c,null,null,b.useHTML).css(b.style).attr({align:this.textAlign,rotation:b.rotation,visibility:"hidden"}).add(a)},setOffset:function(a,b){var c=this.axis,d=c.chart,e=d.inverted,f=this.isNegative,g=c.translate(c.usePercentage?100:this.total,0,0,0,1),c=c.translate(0),c=Q(g-c),h=d.xAxis[0].translate(this.x)+a,i=d.plotHeight,f={x:e?f?g:g-c:h,y:e?i-h-b:f?i-g-
|
||||
c:i-g,width:e?c:b,height:e?b:c};if(e=this.label)e.align(this.alignOptions,null,f),f=e.alignAttr,e[this.options.crop===!1||d.isInsidePlot(f.x,f.y)?"show":"hide"](!0)}};ma.prototype.buildStacks=function(){var a=this.series,b=p(this.options.reversedStacks,!0),c=a.length;if(!this.isXAxis){for(this.usePercentage=!1;c--;)a[b?c:a.length-c-1].setStackedPoints();if(this.usePercentage)for(c=0;c<a.length;c++)a[c].setPercentStacks()}};ma.prototype.renderStackTotals=function(){var a=this.chart,b=a.renderer,c=
|
||||
this.stacks,d,e,f=this.stackTotalGroup;if(!f)this.stackTotalGroup=f=b.g("stack-labels").attr({visibility:"visible",zIndex:6}).add();f.translate(a.plotLeft,a.plotTop);for(d in c)for(e in a=c[d],a)a[e].render(f)};O.prototype.setStackedPoints=function(){if(this.options.stacking&&!(this.visible!==!0&&this.chart.options.chart.ignoreHiddenSeries!==!1)){var a=this.processedXData,b=this.processedYData,c=[],d=b.length,e=this.options,f=e.threshold,g=e.stack,e=e.stacking,h=this.stackKey,i="-"+h,j=this.negStacks,
|
||||
k=this.yAxis,l=k.stacks,m=k.oldStacks,n,o,p,q,r,s;for(q=0;q<d;q++){r=a[q];s=b[q];p=this.index+","+q;o=(n=j&&s<f)?i:h;l[o]||(l[o]={});if(!l[o][r])m[o]&&m[o][r]?(l[o][r]=m[o][r],l[o][r].total=null):l[o][r]=new Fb(k,k.options.stackLabels,n,r,g);o=l[o][r];o.points[p]=[o.cum||0];e==="percent"?(n=n?h:i,j&&l[n]&&l[n][r]?(n=l[n][r],o.total=n.total=u(n.total,o.total)+Q(s)||0):o.total=ea(o.total+(Q(s)||0))):o.total=ea(o.total+(s||0));o.cum=(o.cum||0)+(s||0);o.points[p].push(o.cum);c[q]=o.cum}if(e==="percent")k.usePercentage=
|
||||
!0;this.stackedYData=c;k.oldStacks={}}};O.prototype.setPercentStacks=function(){var a=this,b=a.stackKey,c=a.yAxis.stacks,d=a.processedXData;q([b,"-"+b],function(b){var e;for(var f=d.length,g,h;f--;)if(g=d[f],e=(h=c[b]&&c[b][g])&&h.points[a.index+","+f],g=e)h=h.total?100/h.total:0,g[0]=ea(g[0]*h),g[1]=ea(g[1]*h),a.stackedYData[f]=g[1]})};r(Xa.prototype,{addSeries:function(a,b,c){var d,e=this;a&&(b=p(b,!0),K(e,"addSeries",{options:a},function(){d=e.initSeries(a);e.isDirtyLegend=!0;e.linkSeries();b&&
|
||||
e.redraw(c)}));return d},addAxis:function(a,b,c,d){var e=b?"xAxis":"yAxis",f=this.options;new ma(this,w(a,{index:this[e].length,isX:b}));f[e]=ra(f[e]||{});f[e].push(a);p(c,!0)&&this.redraw(d)},showLoading:function(a){var b=this,c=b.options,d=b.loadingDiv,e=c.loading,f=function(){d&&A(d,{left:b.plotLeft+"px",top:b.plotTop+"px",width:b.plotWidth+"px",height:b.plotHeight+"px"})};if(!d)b.loadingDiv=d=$(Ja,{className:"highcharts-loading"},r(e.style,{zIndex:10,display:P}),b.container),b.loadingSpan=$("span",
|
||||
null,e.labelStyle,d),N(b,"redraw",f);b.loadingSpan.innerHTML=a||c.lang.loading;if(!b.loadingShown)A(d,{opacity:0,display:""}),ib(d,{opacity:e.style.opacity},{duration:e.showDuration||0}),b.loadingShown=!0;f()},hideLoading:function(){var a=this.options,b=this.loadingDiv;b&&ib(b,{opacity:0},{duration:a.loading.hideDuration||100,complete:function(){A(b,{display:P})}});this.loadingShown=!1}});r(Ea.prototype,{update:function(a,b,c){var d=this,e=d.series,f=d.graphic,g,h=e.data,i=e.chart,j=e.options,b=p(b,
|
||||
!0);d.firePointEvent("update",{options:a},function(){d.applyOptions(a);if(da(a)){e.getAttribs();if(f)a&&a.marker&&a.marker.symbol?d.graphic=f.destroy():f.attr(d.pointAttr[d.state||""]);if(a&&a.dataLabels&&d.dataLabel)d.dataLabel=d.dataLabel.destroy()}g=Da(d,h);e.updateParallelArrays(d,g);j.data[g]=d.options;e.isDirty=e.isDirtyData=!0;if(!e.fixedBox&&e.hasCartesianSeries)i.isDirtyBox=!0;j.legendType==="point"&&i.legend.destroyItem(d);b&&i.redraw(c)})},remove:function(a,b){var c=this,d=c.series,e=d.points,
|
||||
f=d.chart,g,h=d.data;Qa(b,f);a=p(a,!0);c.firePointEvent("remove",null,function(){g=Da(c,h);h.length===e.length&&e.splice(g,1);h.splice(g,1);d.options.data.splice(g,1);d.updateParallelArrays(c,"splice",g,1);c.destroy();d.isDirty=!0;d.isDirtyData=!0;a&&f.redraw()})}});r(O.prototype,{addPoint:function(a,b,c,d){var e=this.options,f=this.data,g=this.graph,h=this.area,i=this.chart,j=this.xAxis&&this.xAxis.names,k=g&&g.shift||0,l=e.data,m,n=this.xData;Qa(d,i);c&&q([g,h,this.graphNeg,this.areaNeg],function(a){if(a)a.shift=
|
||||
k+1});if(h)h.isArea=!0;b=p(b,!0);d={series:this};this.pointClass.prototype.applyOptions.apply(d,[a]);g=d.x;h=n.length;if(this.requireSorting&&g<n[h-1])for(m=!0;h&&n[h-1]>g;)h--;this.updateParallelArrays(d,"splice",h,0,0);this.updateParallelArrays(d,h);if(j)j[g]=d.name;l.splice(h,0,a);m&&(this.data.splice(h,0,null),this.processData());e.legendType==="point"&&this.generatePoints();c&&(f[0]&&f[0].remove?f[0].remove(!1):(f.shift(),this.updateParallelArrays(d,"shift"),l.shift()));this.isDirtyData=this.isDirty=
|
||||
!0;b&&(this.getAttribs(),i.redraw())},remove:function(a,b){var c=this,d=c.chart,a=p(a,!0);if(!c.isRemoving)c.isRemoving=!0,K(c,"remove",null,function(){c.destroy();d.isDirtyLegend=d.isDirtyBox=!0;d.linkSeries();a&&d.redraw(b)});c.isRemoving=!1},update:function(a,b){var c=this,d=this.chart,e=this.userOptions,f=this.type,g=J[f].prototype,h=["group","markerGroup","dataLabelsGroup"],i;q(h,function(a){h[a]=c[a];delete c[a]});a=w(e,{animation:!1,index:this.index,pointStart:this.xData[0]},{data:this.options.data},
|
||||
a);this.remove(!1);for(i in g)g.hasOwnProperty(i)&&(this[i]=t);r(this,J[a.type||f].prototype);q(h,function(a){c[a]=h[a]});this.init(d,a);d.linkSeries();p(b,!0)&&d.redraw(!1)}});r(ma.prototype,{update:function(a,b){var c=this.chart,a=c.options[this.coll][this.options.index]=w(this.userOptions,a);this.destroy(!0);this._addedPlotLB=t;this.init(c,r(a,{events:t}));c.isDirtyBox=!0;p(b,!0)&&c.redraw()},remove:function(a){for(var b=this.chart,c=this.coll,d=this.series,e=d.length;e--;)d[e]&&d[e].remove(!1);
|
||||
ka(b.axes,this);ka(b[c],this);b.options[c].splice(this.options.index,1);q(b[c],function(a,b){a.options.index=b});this.destroy();b.isDirtyBox=!0;p(a,!0)&&b.redraw()},setTitle:function(a,b){this.update({title:a},b)},setCategories:function(a,b){this.update({categories:a},b)}});ha=la(O);J.line=ha;ca.area=w(T,{threshold:0});var qa=la(O,{type:"area",getSegments:function(){var a=this,b=[],c=[],d=[],e=this.xAxis,f=this.yAxis,g=f.stacks[this.stackKey],h={},i,j,k=this.points,l=this.options.connectNulls,m,n;
|
||||
if(this.options.stacking&&!this.cropped){for(m=0;m<k.length;m++)h[k[m].x]=k[m];for(n in g)g[n].total!==null&&d.push(+n);d.sort(function(a,b){return a-b});q(d,function(b){var d=0,k;if(!l||h[b]&&h[b].y!==null)if(h[b])c.push(h[b]);else{for(m=a.index;m<=f.series.length;m++)if(k=g[b].points[m+","+b]){d=k[1];break}i=e.translate(b);j=f.toPixels(d,!0);c.push({y:null,plotX:i,clientX:i,plotY:j,yBottom:j,onMouseOver:sa})}});c.length&&b.push(c)}else O.prototype.getSegments.call(this),b=this.segments;this.segments=
|
||||
b},getSegmentPath:function(a){var b=O.prototype.getSegmentPath.call(this,a),c=[].concat(b),d,e=this.options;d=b.length;var f=this.yAxis.getThreshold(e.threshold),g;d===3&&c.push("L",b[1],b[2]);if(e.stacking&&!this.closedStacks)for(d=a.length-1;d>=0;d--)g=p(a[d].yBottom,f),d<a.length-1&&e.step&&c.push(a[d+1].plotX,g),c.push(a[d].plotX,g);else this.closeSegment(c,a,f);this.areaPath=this.areaPath.concat(c);return b},closeSegment:function(a,b,c){a.push("L",b[b.length-1].plotX,c,"L",b[0].plotX,c)},drawGraph:function(){this.areaPath=
|
||||
[];O.prototype.drawGraph.apply(this);var a=this,b=this.areaPath,c=this.options,d=c.negativeColor,e=c.negativeFillColor,f=[["area",this.color,c.fillColor]];(d||e)&&f.push(["areaNeg",d,e]);q(f,function(d){var e=d[0],f=a[e];f?f.animate({d:b}):a[e]=a.chart.renderer.path(b).attr({fill:p(d[2],ya(d[1]).setOpacity(p(c.fillOpacity,0.75)).get()),zIndex:0}).add(a.group)})},drawLegendSymbol:M.drawRectangle});J.area=qa;ca.spline=w(T);ha=la(O,{type:"spline",getPointSpline:function(a,b,c){var d=b.plotX,e=b.plotY,
|
||||
f=a[c-1],g=a[c+1],h,i,j,k;if(f&&g){a=f.plotY;j=g.plotX;var g=g.plotY,l;h=(1.5*d+f.plotX)/2.5;i=(1.5*e+a)/2.5;j=(1.5*d+j)/2.5;k=(1.5*e+g)/2.5;l=(k-i)*(j-d)/(j-h)+e-k;i+=l;k+=l;i>a&&i>e?(i=u(a,e),k=2*e-i):i<a&&i<e&&(i=C(a,e),k=2*e-i);k>g&&k>e?(k=u(g,e),i=2*e-k):k<g&&k<e&&(k=C(g,e),i=2*e-k);b.rightContX=j;b.rightContY=k}c?(b=["C",f.rightContX||f.plotX,f.rightContY||f.plotY,h||d,i||e,d,e],f.rightContX=f.rightContY=null):b=["M",d,e];return b}});J.spline=ha;ca.areaspline=w(ca.area);qa=qa.prototype;ha=la(ha,
|
||||
{type:"areaspline",closedStacks:!0,getSegmentPath:qa.getSegmentPath,closeSegment:qa.closeSegment,drawGraph:qa.drawGraph,drawLegendSymbol:M.drawRectangle});J.areaspline=ha;ca.column=w(T,{borderColor:"#FFFFFF",borderRadius:0,groupPadding:0.2,marker:null,pointPadding:0.1,minPointLength:0,cropThreshold:50,pointRange:null,states:{hover:{brightness:0.1,shadow:!1,halo:!1},select:{color:"#C0C0C0",borderColor:"#000000",shadow:!1}},dataLabels:{align:null,verticalAlign:null,y:null},stickyTracking:!1,tooltip:{distance:6},
|
||||
threshold:0});ha=la(O,{type:"column",pointAttrToOptions:{stroke:"borderColor",fill:"color",r:"borderRadius"},cropShoulder:0,trackerGroups:["group","dataLabelsGroup"],negStacks:!0,init:function(){O.prototype.init.apply(this,arguments);var a=this,b=a.chart;b.hasRendered&&q(b.series,function(b){if(b.type===a.type)b.isDirty=!0})},getColumnMetrics:function(){var a=this,b=a.options,c=a.xAxis,d=a.yAxis,e=c.reversed,f,g={},h,i=0;b.grouping===!1?i=1:q(a.chart.series,function(b){var c=b.options,e=b.yAxis;if(b.type===
|
||||
a.type&&b.visible&&d.len===e.len&&d.pos===e.pos)c.stacking?(f=b.stackKey,g[f]===t&&(g[f]=i++),h=g[f]):c.grouping!==!1&&(h=i++),b.columnIndex=h});var c=C(Q(c.transA)*(c.ordinalSlope||b.pointRange||c.closestPointRange||c.tickInterval||1),c.len),j=c*b.groupPadding,k=(c-2*j)/i,l=b.pointWidth,b=s(l)?(k-l)/2:k*b.pointPadding,l=p(l,k-2*b);return a.columnMetrics={width:l,offset:b+(j+((e?i-(a.columnIndex||0):a.columnIndex)||0)*k-c/2)*(e?-1:1)}},translate:function(){var a=this,b=a.chart,c=a.options,d=a.borderWidth=
|
||||
p(c.borderWidth,a.activePointCount>0.5*a.xAxis.len?0:1),e=a.yAxis,f=a.translatedThreshold=e.getThreshold(c.threshold),g=p(c.minPointLength,5),h=a.getColumnMetrics(),i=h.width,j=a.barW=u(i,1+2*d),k=a.pointXOffset=h.offset,l=-(d%2?0.5:0),m=d%2?0.5:1;b.renderer.isVML&&b.inverted&&(m+=1);c.pointPadding&&(j=Ka(j));O.prototype.translate.apply(a);q(a.points,function(c){var d=p(c.yBottom,f),h=C(u(-999-d,c.plotY),e.len+999+d),q=c.plotX+k,r=j,s=C(h,d),t;t=u(h,d)-s;Q(t)<g&&g&&(t=g,s=v(Q(s-f)>g?d-g:f-(e.translate(c.y,
|
||||
0,1,0,1)<=f?g:0)));c.barX=q;c.pointWidth=i;c.tooltipPos=b.inverted?[e.len-h,a.xAxis.len-q-r/2]:[q+r/2,h];r=v(q+r)+l;q=v(q)+l;r-=q;d=Q(s)<0.5;t=v(s+t)+m;s=v(s)+m;t-=s;d&&(s-=1,t+=1);c.shapeType="rect";c.shapeArgs={x:q,y:s,width:r,height:t}})},getSymbol:sa,drawLegendSymbol:M.drawRectangle,drawGraph:sa,drawPoints:function(){var a=this,b=this.chart,c=a.options,d=b.renderer,e=c.animationLimit||250,f,g;q(a.points,function(h){var i=h.plotY,j=h.graphic;if(i!==t&&!isNaN(i)&&h.y!==null)f=h.shapeArgs,i=s(a.borderWidth)?
|
||||
{"stroke-width":a.borderWidth}:{},g=h.pointAttr[h.selected?"select":""]||a.pointAttr[""],j?(ab(j),j.attr(i)[b.pointCount<e?"animate":"attr"](w(f))):h.graphic=d[h.shapeType](f).attr(g).attr(i).add(a.group).shadow(c.shadow,null,c.stacking&&!c.borderRadius);else if(j)h.graphic=j.destroy()})},animate:function(a){var b=this.yAxis,c=this.options,d=this.chart.inverted,e={};if(ba)a?(e.scaleY=0.001,a=C(b.pos+b.len,u(b.pos,b.toPixels(c.threshold))),d?e.translateX=a-b.len:e.translateY=a,this.group.attr(e)):
|
||||
(e.scaleY=1,e[d?"translateX":"translateY"]=b.pos,this.group.animate(e,this.options.animation),this.animate=null)},remove:function(){var a=this,b=a.chart;b.hasRendered&&q(b.series,function(b){if(b.type===a.type)b.isDirty=!0});O.prototype.remove.apply(a,arguments)}});J.column=ha;ca.bar=w(ca.column);qa=la(ha,{type:"bar",inverted:!0});J.bar=qa;ca.scatter=w(T,{lineWidth:0,tooltip:{headerFormat:'<span style="color:{series.color}">●</span> <span style="font-size: 10px;"> {series.name}</span><br/>',pointFormat:"x: <b>{point.x}</b><br/>y: <b>{point.y}</b><br/>"},
|
||||
stickyTracking:!1});qa=la(O,{type:"scatter",sorted:!1,requireSorting:!1,noSharedTooltip:!0,trackerGroups:["markerGroup","dataLabelsGroup"],takeOrdinalPosition:!1,singularTooltips:!0,drawGraph:function(){this.options.lineWidth&&O.prototype.drawGraph.call(this)}});J.scatter=qa;ca.pie=w(T,{borderColor:"#FFFFFF",borderWidth:1,center:[null,null],clip:!1,colorByPoint:!0,dataLabels:{distance:30,enabled:!0,formatter:function(){return this.point.name}},ignoreHiddenPoint:!0,legendType:"point",marker:null,size:null,
|
||||
showInLegend:!1,slicedOffset:10,states:{hover:{brightness:0.1,shadow:!1}},stickyTracking:!1,tooltip:{followPointer:!0}});T={type:"pie",isCartesian:!1,pointClass:la(Ea,{init:function(){Ea.prototype.init.apply(this,arguments);var a=this,b;if(a.y<0)a.y=null;r(a,{visible:a.visible!==!1,name:p(a.name,"Slice")});b=function(b){a.slice(b.type==="select")};N(a,"select",b);N(a,"unselect",b);return a},setVisible:function(a){var b=this,c=b.series,d=c.chart;b.visible=b.options.visible=a=a===t?!b.visible:a;c.options.data[Da(b,
|
||||
c.data)]=b.options;q(["graphic","dataLabel","connector","shadowGroup"],function(c){if(b[c])b[c][a?"show":"hide"](!0)});b.legendItem&&d.legend.colorizeItem(b,a);if(!c.isDirty&&c.options.ignoreHiddenPoint)c.isDirty=!0,d.redraw()},slice:function(a,b,c){var d=this.series;Qa(c,d.chart);p(b,!0);this.sliced=this.options.sliced=a=s(a)?a:!this.sliced;d.options.data[Da(this,d.data)]=this.options;a=a?this.slicedTranslation:{translateX:0,translateY:0};this.graphic.animate(a);this.shadowGroup&&this.shadowGroup.animate(a)},
|
||||
haloPath:function(a){var b=this.shapeArgs,c=this.series.chart;return this.sliced||!this.visible?[]:this.series.chart.renderer.symbols.arc(c.plotLeft+b.x,c.plotTop+b.y,b.r+a,b.r+a,{innerR:this.shapeArgs.r,start:b.start,end:b.end})}}),requireSorting:!1,noSharedTooltip:!0,trackerGroups:["group","dataLabelsGroup"],axisTypes:[],pointAttrToOptions:{stroke:"borderColor","stroke-width":"borderWidth",fill:"color"},singularTooltips:!0,getColor:sa,animate:function(a){var b=this,c=b.points,d=b.startAngleRad;
|
||||
if(!a)q(c,function(a){var c=a.graphic,a=a.shapeArgs;c&&(c.attr({r:b.center[3]/2,start:d,end:d}),c.animate({r:a.r,start:a.start,end:a.end},b.options.animation))}),b.animate=null},setData:function(a,b,c,d){O.prototype.setData.call(this,a,!1,c,d);this.processData();this.generatePoints();p(b,!0)&&this.chart.redraw(c)},generatePoints:function(){var a,b=0,c,d,e,f=this.options.ignoreHiddenPoint;O.prototype.generatePoints.call(this);c=this.points;d=c.length;for(a=0;a<d;a++)e=c[a],b+=f&&!e.visible?0:e.y;this.total=
|
||||
b;for(a=0;a<d;a++)e=c[a],e.percentage=b>0?e.y/b*100:0,e.total=b},translate:function(a){this.generatePoints();var b=0,c=this.options,d=c.slicedOffset,e=d+c.borderWidth,f,g,h,i=c.startAngle||0,j=this.startAngleRad=na/180*(i-90),i=(this.endAngleRad=na/180*(p(c.endAngle,i+360)-90))-j,k=this.points,l=c.dataLabels.distance,c=c.ignoreHiddenPoint,m,n=k.length,o;if(!a)this.center=a=this.getCenter();this.getX=function(b,c){h=V.asin(C((b-a[1])/(a[2]/2+l),1));return a[0]+(c?-1:1)*aa(h)*(a[2]/2+l)};for(m=0;m<
|
||||
n;m++){o=k[m];f=j+b*i;if(!c||o.visible)b+=o.percentage/100;g=j+b*i;o.shapeType="arc";o.shapeArgs={x:a[0],y:a[1],r:a[2]/2,innerR:a[3]/2,start:v(f*1E3)/1E3,end:v(g*1E3)/1E3};h=(g+f)/2;h>1.5*na?h-=2*na:h<-na/2&&(h+=2*na);o.slicedTranslation={translateX:v(aa(h)*d),translateY:v(fa(h)*d)};f=aa(h)*a[2]/2;g=fa(h)*a[2]/2;o.tooltipPos=[a[0]+f*0.7,a[1]+g*0.7];o.half=h<-na/2||h>na/2?1:0;o.angle=h;e=C(e,l/2);o.labelPos=[a[0]+f+aa(h)*l,a[1]+g+fa(h)*l,a[0]+f+aa(h)*e,a[1]+g+fa(h)*e,a[0]+f,a[1]+g,l<0?"center":o.half?
|
||||
"right":"left",h]}},drawGraph:null,drawPoints:function(){var a=this,b=a.chart.renderer,c,d,e=a.options.shadow,f,g;if(e&&!a.shadowGroup)a.shadowGroup=b.g("shadow").add(a.group);q(a.points,function(h){d=h.graphic;g=h.shapeArgs;f=h.shadowGroup;if(e&&!f)f=h.shadowGroup=b.g("shadow").add(a.shadowGroup);c=h.sliced?h.slicedTranslation:{translateX:0,translateY:0};f&&f.attr(c);d?d.animate(r(g,c)):h.graphic=d=b[h.shapeType](g).setRadialReference(a.center).attr(h.pointAttr[h.selected?"select":""]).attr({"stroke-linejoin":"round"}).attr(c).add(a.group).shadow(e,
|
||||
f);h.visible!==void 0&&h.setVisible(h.visible)})},sortByAngle:function(a,b){a.sort(function(a,d){return a.angle!==void 0&&(d.angle-a.angle)*b})},drawLegendSymbol:M.drawRectangle,getCenter:Z.getCenter,getSymbol:sa};T=la(O,T);J.pie=T;O.prototype.drawDataLabels=function(){var a=this,b=a.options,c=b.cursor,d=b.dataLabels,e=a.points,f,g,h,i;if(d.enabled||a._hasPointLabels)a.dlProcessOptions&&a.dlProcessOptions(d),i=a.plotGroup("dataLabelsGroup","data-labels",d.defer?"hidden":"visible",d.zIndex||6),!a.hasRendered&&
|
||||
p(d.defer,!0)&&(i.attr({opacity:0}),N(a,"afterAnimate",function(){a.visible&&i.show();i[b.animation?"animate":"attr"]({opacity:1},{duration:200})})),g=d,q(e,function(b){var e,l=b.dataLabel,m,n,o=b.connector,q=!0;f=b.options&&b.options.dataLabels;e=p(f&&f.enabled,g.enabled);if(l&&!e)b.dataLabel=l.destroy();else if(e){d=w(g,f);e=d.rotation;m=b.getLabelConfig();h=d.format?Ia(d.format,m):d.formatter.call(m,d);d.style.color=p(d.color,d.style.color,a.color,"black");if(l)if(s(h))l.attr({text:h}),q=!1;else{if(b.dataLabel=
|
||||
l=l.destroy(),o)b.connector=o.destroy()}else if(s(h)){l={fill:d.backgroundColor,stroke:d.borderColor,"stroke-width":d.borderWidth,r:d.borderRadius||0,rotation:e,padding:d.padding,zIndex:1};for(n in l)l[n]===t&&delete l[n];l=b.dataLabel=a.chart.renderer[e?"text":"label"](h,0,-999,null,null,null,d.useHTML).attr(l).css(r(d.style,c&&{cursor:c})).add(i).shadow(d.shadow)}l&&a.alignDataLabel(b,l,d,null,q)}})};O.prototype.alignDataLabel=function(a,b,c,d,e){var f=this.chart,g=f.inverted,h=p(a.plotX,-999),
|
||||
i=p(a.plotY,-999),j=b.getBBox();if(a=this.visible&&(a.series.forceDL||f.isInsidePlot(h,v(i),g)||d&&f.isInsidePlot(h,g?d.x+1:d.y+d.height-1,g)))d=r({x:g?f.plotWidth-i:h,y:v(g?f.plotHeight-h:i),width:0,height:0},d),r(c,{width:j.width,height:j.height}),c.rotation?b[e?"attr":"animate"]({x:d.x+c.x+d.width/2,y:d.y+c.y+d.height/2}).attr({align:c.align}):(b.align(c,null,d),g=b.alignAttr,p(c.overflow,"justify")==="justify"?this.justifyDataLabel(b,c,g,j,d,e):p(c.crop,!0)&&(a=f.isInsidePlot(g.x,g.y)&&f.isInsidePlot(g.x+
|
||||
j.width,g.y+j.height)));if(!a)b.attr({y:-999}),b.placed=!1};O.prototype.justifyDataLabel=function(a,b,c,d,e,f){var g=this.chart,h=b.align,i=b.verticalAlign,j,k;j=c.x;if(j<0)h==="right"?b.align="left":b.x=-j,k=!0;j=c.x+d.width;if(j>g.plotWidth)h==="left"?b.align="right":b.x=g.plotWidth-j,k=!0;j=c.y;if(j<0)i==="bottom"?b.verticalAlign="top":b.y=-j,k=!0;j=c.y+d.height;if(j>g.plotHeight)i==="top"?b.verticalAlign="bottom":b.y=g.plotHeight-j,k=!0;if(k)a.placed=!f,a.align(b,null,e)};if(J.pie)J.pie.prototype.drawDataLabels=
|
||||
function(){var a=this,b=a.data,c,d=a.chart,e=a.options.dataLabels,f=p(e.connectorPadding,10),g=p(e.connectorWidth,1),h=d.plotWidth,i=d.plotHeight,j,k,l=p(e.softConnector,!0),m=e.distance,n=a.center,o=n[2]/2,r=n[1],s=m>0,t,w,x,z=[[],[]],B,A,K,J,y,R=[0,0,0,0],N=function(a,b){return b.y-a.y};if(a.visible&&(e.enabled||a._hasPointLabels)){O.prototype.drawDataLabels.apply(a);q(b,function(a){a.dataLabel&&a.visible&&z[a.half].push(a)});for(J=2;J--;){var H=[],M=[],F=z[J],L=F.length,G;if(L){a.sortByAngle(F,
|
||||
J-0.5);for(y=b=0;!b&&F[y];)b=F[y]&&F[y].dataLabel&&(F[y].dataLabel.getBBox().height||21),y++;if(m>0){w=C(r+o+m,d.plotHeight);for(y=u(0,r-o-m);y<=w;y+=b)H.push(y);w=H.length;if(L>w){c=[].concat(F);c.sort(N);for(y=L;y--;)c[y].rank=y;for(y=L;y--;)F[y].rank>=w&&F.splice(y,1);L=F.length}for(y=0;y<L;y++){c=F[y];x=c.labelPos;c=9999;var S,P;for(P=0;P<w;P++)S=Q(H[P]-x[1]),S<c&&(c=S,G=P);if(G<y&&H[y]!==null)G=y;else for(w<L-y+G&&H[y]!==null&&(G=w-L+y);H[G]===null;)G++;M.push({i:G,y:H[G]});H[G]=null}M.sort(N)}for(y=
|
||||
0;y<L;y++){c=F[y];x=c.labelPos;t=c.dataLabel;K=c.visible===!1?"hidden":"visible";c=x[1];if(m>0){if(w=M.pop(),G=w.i,A=w.y,c>A&&H[G+1]!==null||c<A&&H[G-1]!==null)A=C(u(0,c),d.plotHeight)}else A=c;B=e.justify?n[0]+(J?-1:1)*(o+m):a.getX(A===r-o-m||A===r+o+m?c:A,J);t._attr={visibility:K,align:x[6]};t._pos={x:B+e.x+({left:f,right:-f}[x[6]]||0),y:A+e.y-10};t.connX=B;t.connY=A;if(this.options.size===null)w=t.width,B-w<f?R[3]=u(v(w-B+f),R[3]):B+w>h-f&&(R[1]=u(v(B+w-h+f),R[1])),A-b/2<0?R[0]=u(v(-A+b/2),R[0]):
|
||||
A+b/2>i&&(R[2]=u(v(A+b/2-i),R[2]))}}}if(Ba(R)===0||this.verifyDataLabelOverflow(R))this.placeDataLabels(),s&&g&&q(this.points,function(b){j=b.connector;x=b.labelPos;if((t=b.dataLabel)&&t._pos)K=t._attr.visibility,B=t.connX,A=t.connY,k=l?["M",B+(x[6]==="left"?5:-5),A,"C",B,A,2*x[2]-x[4],2*x[3]-x[5],x[2],x[3],"L",x[4],x[5]]:["M",B+(x[6]==="left"?5:-5),A,"L",x[2],x[3],"L",x[4],x[5]],j?(j.animate({d:k}),j.attr("visibility",K)):b.connector=j=a.chart.renderer.path(k).attr({"stroke-width":g,stroke:e.connectorColor||
|
||||
b.color||"#606060",visibility:K}).add(a.dataLabelsGroup);else if(j)b.connector=j.destroy()})}},J.pie.prototype.placeDataLabels=function(){q(this.points,function(a){var a=a.dataLabel,b;if(a)(b=a._pos)?(a.attr(a._attr),a[a.moved?"animate":"attr"](b),a.moved=!0):a&&a.attr({y:-999})})},J.pie.prototype.alignDataLabel=sa,J.pie.prototype.verifyDataLabelOverflow=function(a){var b=this.center,c=this.options,d=c.center,e=c=c.minSize||80,f;d[0]!==null?e=u(b[2]-u(a[1],a[3]),c):(e=u(b[2]-a[1]-a[3],c),b[0]+=(a[3]-
|
||||
a[1])/2);d[1]!==null?e=u(C(e,b[2]-u(a[0],a[2])),c):(e=u(C(e,b[2]-a[0]-a[2]),c),b[1]+=(a[0]-a[2])/2);e<b[2]?(b[2]=e,this.translate(b),q(this.points,function(a){if(a.dataLabel)a.dataLabel._pos=null}),this.drawDataLabels&&this.drawDataLabels()):f=!0;return f};if(J.column)J.column.prototype.alignDataLabel=function(a,b,c,d,e){var f=this.chart,g=f.inverted,h=a.dlBox||a.shapeArgs,i=a.below||a.plotY>p(this.translatedThreshold,f.plotSizeY),j=p(c.inside,!!this.options.stacking);if(h&&(d=w(h),g&&(d={x:f.plotWidth-
|
||||
d.y-d.height,y:f.plotHeight-d.x-d.width,width:d.height,height:d.width}),!j))g?(d.x+=i?0:d.width,d.width=0):(d.y+=i?d.height:0,d.height=0);c.align=p(c.align,!g||j?"center":i?"right":"left");c.verticalAlign=p(c.verticalAlign,g||j?"middle":i?"top":"bottom");O.prototype.alignDataLabel.call(this,a,b,c,d,e)};T=S.TrackerMixin={drawTrackerPoint:function(){var a=this,b=a.chart,c=b.pointer,d=a.options.cursor,e=d&&{cursor:d},f=function(c){var d=c.target,e;if(b.hoverSeries!==a)a.onMouseOver();for(;d&&!e;)e=d.point,
|
||||
d=d.parentNode;if(e!==t&&e!==b.hoverPoint)e.onMouseOver(c)};q(a.points,function(a){if(a.graphic)a.graphic.element.point=a;if(a.dataLabel)a.dataLabel.element.point=a});if(!a._hasTracking)q(a.trackerGroups,function(b){if(a[b]&&(a[b].addClass("highcharts-tracker").on("mouseover",f).on("mouseout",function(a){c.onTrackerMouseOut(a)}).css(e),Za))a[b].on("touchstart",f)}),a._hasTracking=!0},drawTrackerGraph:function(){var a=this,b=a.options,c=b.trackByArea,d=[].concat(c?a.areaPath:a.graphPath),e=d.length,
|
||||
f=a.chart,g=f.pointer,h=f.renderer,i=f.options.tooltip.snap,j=a.tracker,k=b.cursor,l=k&&{cursor:k},k=a.singlePoints,m,n=function(){if(f.hoverSeries!==a)a.onMouseOver()},o="rgba(192,192,192,"+(ba?1.0E-4:0.002)+")";if(e&&!c)for(m=e+1;m--;)d[m]==="M"&&d.splice(m+1,0,d[m+1]-i,d[m+2],"L"),(m&&d[m]==="M"||m===e)&&d.splice(m,0,"L",d[m-2]+i,d[m-1]);for(m=0;m<k.length;m++)e=k[m],d.push("M",e.plotX-i,e.plotY,"L",e.plotX+i,e.plotY);j?j.attr({d:d}):(a.tracker=h.path(d).attr({"stroke-linejoin":"round",visibility:a.visible?
|
||||
"visible":"hidden",stroke:o,fill:c?o:P,"stroke-width":b.lineWidth+(c?0:2*i),zIndex:2}).add(a.group),q([a.tracker,a.markerGroup],function(a){a.addClass("highcharts-tracker").on("mouseover",n).on("mouseout",function(a){g.onTrackerMouseOut(a)}).css(l);if(Za)a.on("touchstart",n)}))}};if(J.column)ha.prototype.drawTracker=T.drawTrackerPoint;if(J.pie)J.pie.prototype.drawTracker=T.drawTrackerPoint;if(J.scatter)qa.prototype.drawTracker=T.drawTrackerPoint;r(kb.prototype,{setItemEvents:function(a,b,c,d,e){var f=
|
||||
this;(c?b:a.legendGroup).on("mouseover",function(){a.setState("hover");b.css(f.options.itemHoverStyle)}).on("mouseout",function(){b.css(a.visible?d:e);a.setState()}).on("click",function(b){var c=function(){a.setVisible()},b={browserEvent:b};a.firePointEvent?a.firePointEvent("legendItemClick",b,c):K(a,"legendItemClick",b,c)})},createCheckboxForItem:function(a){a.checkbox=$("input",{type:"checkbox",checked:a.selected,defaultChecked:a.selected},this.options.itemCheckboxStyle,this.chart.container);N(a.checkbox,
|
||||
"click",function(b){K(a,"checkboxClick",{checked:b.target.checked},function(){a.select()})})}});L.legend.itemStyle.cursor="pointer";r(Xa.prototype,{showResetZoom:function(){var a=this,b=L.lang,c=a.options.chart.resetZoomButton,d=c.theme,e=d.states,f=c.relativeTo==="chart"?null:"plotBox";this.resetZoomButton=a.renderer.button(b.resetZoom,null,null,function(){a.zoomOut()},d,e&&e.hover).attr({align:c.position.align,title:b.resetZoomTitle}).add().align(c.position,!1,f)},zoomOut:function(){var a=this;
|
||||
K(a,"selection",{resetSelection:!0},function(){a.zoom()})},zoom:function(a){var b,c=this.pointer,d=!1,e;!a||a.resetSelection?q(this.axes,function(a){b=a.zoom()}):q(a.xAxis.concat(a.yAxis),function(a){var e=a.axis,h=e.isXAxis;if(c[h?"zoomX":"zoomY"]||c[h?"pinchX":"pinchY"])b=e.zoom(a.min,a.max),e.displayBtn&&(d=!0)});e=this.resetZoomButton;if(d&&!e)this.showResetZoom();else if(!d&&da(e))this.resetZoomButton=e.destroy();b&&this.redraw(p(this.options.chart.animation,a&&a.animation,this.pointCount<100))},
|
||||
pan:function(a,b){var c=this,d=c.hoverPoints,e;d&&q(d,function(a){a.setState()});q(b==="xy"?[1,0]:[1],function(b){var d=a[b?"chartX":"chartY"],h=c[b?"xAxis":"yAxis"][0],i=c[b?"mouseDownX":"mouseDownY"],j=(h.pointRange||0)/2,k=h.getExtremes(),l=h.toValue(i-d,!0)+j,i=h.toValue(i+c[b?"plotWidth":"plotHeight"]-d,!0)-j;h.series.length&&l>C(k.dataMin,k.min)&&i<u(k.dataMax,k.max)&&(h.setExtremes(l,i,!1,!1,{trigger:"pan"}),e=!0);c[b?"mouseDownX":"mouseDownY"]=d});e&&c.redraw(!1);A(c.container,{cursor:"move"})}});
|
||||
r(Ea.prototype,{select:function(a,b){var c=this,d=c.series,e=d.chart,a=p(a,!c.selected);c.firePointEvent(a?"select":"unselect",{accumulate:b},function(){c.selected=c.options.selected=a;d.options.data[Da(c,d.data)]=c.options;c.setState(a&&"select");b||q(e.getSelectedPoints(),function(a){if(a.selected&&a!==c)a.selected=a.options.selected=!1,d.options.data[Da(a,d.data)]=a.options,a.setState(""),a.firePointEvent("unselect")})})},onMouseOver:function(a){var b=this.series,c=b.chart,d=c.tooltip,e=c.hoverPoint;
|
||||
if(e&&e!==this)e.onMouseOut();this.firePointEvent("mouseOver");d&&(!d.shared||b.noSharedTooltip)&&d.refresh(this,a);this.setState("hover");c.hoverPoint=this},onMouseOut:function(){var a=this.series.chart,b=a.hoverPoints;this.firePointEvent("mouseOut");if(!b||Da(this,b)===-1)this.setState(),a.hoverPoint=null},importEvents:function(){if(!this.hasImportedEvents){var a=w(this.series.options.point,this.options).events,b;this.events=a;for(b in a)N(this,b,a[b]);this.hasImportedEvents=!0}},setState:function(a,
|
||||
b){var c=this.plotX,d=this.plotY,e=this.series,f=e.options.states,g=ca[e.type].marker&&e.options.marker,h=g&&!g.enabled,i=g&&g.states[a],j=i&&i.enabled===!1,k=e.stateMarkerGraphic,l=this.marker||{},m=e.chart,n=e.halo,o,a=a||"";o=this.pointAttr[a]||e.pointAttr[a];if(!(a===this.state&&!b||this.selected&&a!=="select"||f[a]&&f[a].enabled===!1||a&&(j||h&&i.enabled===!1)||a&&l.states&&l.states[a]&&l.states[a].enabled===!1)){if(this.graphic)g=g&&this.graphic.symbolName&&o.r,this.graphic.attr(w(o,g?{x:c-
|
||||
g,y:d-g,width:2*g,height:2*g}:{})),k&&k.hide();else{if(a&&i)if(g=i.radius,l=l.symbol||e.symbol,k&&k.currentSymbol!==l&&(k=k.destroy()),k)k[b?"animate":"attr"]({x:c-g,y:d-g});else if(l)e.stateMarkerGraphic=k=m.renderer.symbol(l,c-g,d-g,2*g,2*g).attr(o).add(e.markerGroup),k.currentSymbol=l;if(k)k[a&&m.isInsidePlot(c,d,m.inverted)?"show":"hide"]()}if((c=f[a]&&f[a].halo)&&c.size){if(!n)e.halo=n=m.renderer.path().add(e.seriesGroup);n.attr(r({fill:ya(this.color||e.color).setOpacity(c.opacity).get()},c.attributes))[b?
|
||||
"animate":"attr"]({d:this.haloPath(c.size)})}else n&&n.attr({d:[]});this.state=a}},haloPath:function(a){var b=this.series,c=b.chart,d=b.getPlotBox(),e=c.inverted;return c.renderer.symbols.circle(d.translateX+(e?b.yAxis.len-this.plotY:this.plotX)-a,d.translateY+(e?b.xAxis.len-this.plotX:this.plotY)-a,a*2,a*2)}});r(O.prototype,{onMouseOver:function(){var a=this.chart,b=a.hoverSeries;if(b&&b!==this)b.onMouseOut();this.options.events.mouseOver&&K(this,"mouseOver");this.setState("hover");a.hoverSeries=
|
||||
this},onMouseOut:function(){var a=this.options,b=this.chart,c=b.tooltip,d=b.hoverPoint;if(d)d.onMouseOut();this&&a.events.mouseOut&&K(this,"mouseOut");c&&!a.stickyTracking&&(!c.shared||this.noSharedTooltip)&&c.hide();this.setState();b.hoverSeries=null},setState:function(a){var b=this.options,c=this.graph,d=this.graphNeg,e=b.states,b=b.lineWidth,a=a||"";if(this.state!==a)this.state=a,e[a]&&e[a].enabled===!1||(a&&(b=e[a].lineWidth||b+(e[a].lineWidthPlus||0)),c&&!c.dashstyle&&(a={"stroke-width":b},c.attr(a),
|
||||
d&&d.attr(a)))},setVisible:function(a,b){var c=this,d=c.chart,e=c.legendItem,f,g=d.options.chart.ignoreHiddenSeries,h=c.visible;f=(c.visible=a=c.userOptions.visible=a===t?!h:a)?"show":"hide";q(["group","dataLabelsGroup","markerGroup","tracker"],function(a){if(c[a])c[a][f]()});if(d.hoverSeries===c)c.onMouseOut();e&&d.legend.colorizeItem(c,a);c.isDirty=!0;c.options.stacking&&q(d.series,function(a){if(a.options.stacking&&a.visible)a.isDirty=!0});q(c.linkedSeries,function(b){b.setVisible(a,!1)});if(g)d.isDirtyBox=
|
||||
!0;b!==!1&&d.redraw();K(c,f)},setTooltipPoints:function(a){var b=[],c,d,e=this.xAxis,f=e&&e.getExtremes(),g=e?e.tooltipLen||e.len:this.chart.plotSizeX,h,i,j=[];if(!(this.options.enableMouseTracking===!1||this.singularTooltips)){if(a)this.tooltipPoints=null;q(this.segments||this.points,function(a){b=b.concat(a)});e&&e.reversed&&(b=b.reverse());this.orderTooltipPoints&&this.orderTooltipPoints(b);a=b.length;for(i=0;i<a;i++)if(e=b[i],c=e.x,c>=f.min&&c<=f.max){h=b[i+1];c=d===t?0:d+1;for(d=b[i+1]?C(u(0,
|
||||
U((e.clientX+(h?h.wrappedClientX||h.clientX:g))/2)),g):g;c>=0&&c<=d;)j[c++]=e}this.tooltipPoints=j}},show:function(){this.setVisible(!0)},hide:function(){this.setVisible(!1)},select:function(a){this.selected=a=a===t?!this.selected:a;if(this.checkbox)this.checkbox.checked=a;K(this,a?"select":"unselect")},drawTracker:T.drawTrackerGraph});r(S,{Axis:ma,Chart:Xa,Color:ya,Point:Ea,Tick:Sa,Renderer:Ya,Series:O,SVGElement:G,SVGRenderer:ta,arrayMin:Na,arrayMax:Ba,charts:W,dateFormat:bb,format:Ia,pathAnim:ub,
|
||||
getOptions:function(){return L},hasBidiBug:Nb,isTouchDevice:Hb,numberFormat:Ga,seriesTypes:J,setOptions:function(a){L=w(!0,L,a);Ab();return L},addEvent:N,removeEvent:X,createElement:$,discardElement:Pa,css:A,each:q,extend:r,map:Ua,merge:w,pick:p,splat:ra,extendClass:la,pInt:z,wrap:Ma,svg:ba,canvas:ga,vml:!ba&&!ga,product:"Highcharts",version:"4.0.3"})})();
|
||||
File diff suppressed because one or more lines are too long
@@ -1,12 +0,0 @@
|
||||
/**
|
||||
* Site-specific configuration settings for Highslide JS
|
||||
*/
|
||||
hs.graphicsDir = 'assets/highslide/';
|
||||
hs.outlineType = 'rounded-white';
|
||||
hs.wrapperClassName = 'draggable-header';
|
||||
hs.captionEval = 'this.a.title';
|
||||
hs.showCredits = false;
|
||||
hs.marginTop = 20;
|
||||
hs.marginRight = 20;
|
||||
hs.marginBottom = 20;
|
||||
hs.marginLeft = 20;
|
||||
@@ -1,16 +0,0 @@
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
// but before any files alphabetically greater than 'application.js'
|
||||
//
|
||||
// The available directives right now are require, require_directory, and require_tree
|
||||
//
|
||||
//= require highslide/highslide-full.min
|
||||
//= require highslide/highslide.config
|
||||
//= require_tree highcharts
|
||||
//= require firefly/index
|
||||
@@ -1,13 +0,0 @@
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
// but before any files alphabetically greater than 'application.js'
|
||||
//
|
||||
// The available directives right now are require, require_directory, and require_tree
|
||||
//
|
||||
//= require firefly/piggybanks-create
|
||||
@@ -1,13 +0,0 @@
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
// but before any files alphabetically greater than 'application.js'
|
||||
//
|
||||
// The available directives right now are require, require_directory, and require_tree
|
||||
//
|
||||
//= require firefly/piggybanks
|
||||
@@ -1,14 +0,0 @@
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
// but before any files alphabetically greater than 'application.js'
|
||||
//
|
||||
// The available directives right now are require, require_directory, and require_tree
|
||||
//
|
||||
//= require tagsinput/bootstrap-tagsinput.min
|
||||
//= require firefly/recurring
|
||||
@@ -1,14 +0,0 @@
|
||||
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
||||
// listed below.
|
||||
//
|
||||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
// can be referenced here using a relative path.
|
||||
//
|
||||
// It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
// gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
// but before any files alphabetically greater than 'application.js'
|
||||
//
|
||||
// The available directives right now are require, require_directory, and require_tree
|
||||
//
|
||||
//= require typeahead/bootstrap3-typeahead.min
|
||||
//= require firefly/transactions
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
||||
* listed below.
|
||||
*
|
||||
* Any Css/Less files within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
* can be referenced here using a relative path.
|
||||
*
|
||||
* It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
* gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
* but before any files alphabetically greater than 'application.css'
|
||||
*
|
||||
*= require highslide/highslide
|
||||
*/
|
||||
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
||||
* listed below.
|
||||
*
|
||||
* Any Css/Less files within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
* can be referenced here using a relative path.
|
||||
*
|
||||
* It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
* gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
* but before any files alphabetically greater than 'application.css'
|
||||
*
|
||||
*= require bootstrap/bootstrap.min
|
||||
*/
|
||||
@@ -1,889 +0,0 @@
|
||||
/**
|
||||
* @file: highslide.css
|
||||
* @version: 4.1.13
|
||||
*/
|
||||
.highslide-container div {
|
||||
font-family: Verdana, Helvetica;
|
||||
font-size: 10pt;
|
||||
}
|
||||
.highslide-container table {
|
||||
background: none;
|
||||
}
|
||||
.highslide {
|
||||
outline: none;
|
||||
text-decoration: none;
|
||||
}
|
||||
.highslide img {
|
||||
border: 2px solid silver;
|
||||
}
|
||||
.highslide:hover img {
|
||||
border-color: gray;
|
||||
}
|
||||
.highslide-active-anchor img {
|
||||
visibility: hidden;
|
||||
}
|
||||
.highslide-gallery .highslide-active-anchor img {
|
||||
border-color: black;
|
||||
visibility: visible;
|
||||
cursor: default;
|
||||
}
|
||||
.highslide-image {
|
||||
border-width: 2px;
|
||||
border-style: solid;
|
||||
border-color: white;
|
||||
}
|
||||
.highslide-wrapper, .highslide-outline {
|
||||
background: white;
|
||||
}
|
||||
.glossy-dark {
|
||||
background: #111;
|
||||
}
|
||||
|
||||
.highslide-image-blur {
|
||||
}
|
||||
.highslide-number {
|
||||
font-weight: bold;
|
||||
color: gray;
|
||||
font-size: .9em;
|
||||
}
|
||||
.highslide-caption {
|
||||
display: none;
|
||||
font-size: 1em;
|
||||
padding: 5px;
|
||||
/*background: white;*/
|
||||
}
|
||||
.highslide-heading {
|
||||
display: none;
|
||||
font-weight: bold;
|
||||
margin: 0.4em;
|
||||
}
|
||||
.highslide-dimming {
|
||||
/*position: absolute;*/
|
||||
background: black;
|
||||
}
|
||||
a.highslide-full-expand {
|
||||
background: url(highslide/fullexpand.gif) no-repeat;
|
||||
display: block;
|
||||
margin: 0 10px 10px 0;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
}
|
||||
.highslide-loading {
|
||||
display: block;
|
||||
color: black;
|
||||
font-size: 9px;
|
||||
font-weight: bold;
|
||||
text-transform: uppercase;
|
||||
text-decoration: none;
|
||||
padding: 3px;
|
||||
border: 1px solid white;
|
||||
background-color: white;
|
||||
padding-left: 22px;
|
||||
background-image: url(highslide/loader.white.gif);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 3px 1px;
|
||||
}
|
||||
a.highslide-credits,
|
||||
a.highslide-credits i {
|
||||
padding: 2px;
|
||||
color: silver;
|
||||
text-decoration: none;
|
||||
font-size: 10px;
|
||||
}
|
||||
a.highslide-credits:hover,
|
||||
a.highslide-credits:hover i {
|
||||
color: white;
|
||||
background-color: gray;
|
||||
}
|
||||
.highslide-move, .highslide-move * {
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
.highslide-viewport {
|
||||
display: none;
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 1;
|
||||
background: none;
|
||||
left: 0;
|
||||
top: 0;
|
||||
}
|
||||
.highslide-overlay {
|
||||
display: none;
|
||||
}
|
||||
.hidden-container {
|
||||
display: none;
|
||||
}
|
||||
/* Example of a semitransparent, offset closebutton */
|
||||
.closebutton {
|
||||
position: relative;
|
||||
top: -15px;
|
||||
left: 15px;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
cursor: pointer;
|
||||
background: url(highslide/close.png);
|
||||
/* NOTE! For IE6, you also need to update the highslide-ie6.css file. */
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Thumbnail boxes for the galleries. */
|
||||
/* Remove these if you are not using a gallery. */
|
||||
/*****************************************************************************/
|
||||
.highslide-gallery ul {
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.highslide-gallery ul li {
|
||||
display: block;
|
||||
position: relative;
|
||||
float: left;
|
||||
width: 106px;
|
||||
height: 106px;
|
||||
border: 1px solid silver;
|
||||
background: #ededed;
|
||||
margin: 2px;
|
||||
padding: 0;
|
||||
line-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.highslide-gallery ul a {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
}
|
||||
.highslide-gallery ul img {
|
||||
position: relative;
|
||||
top: -50%;
|
||||
left: -50%;
|
||||
}
|
||||
html>/**/body .highslide-gallery ul li {
|
||||
display: table;
|
||||
text-align: center;
|
||||
}
|
||||
html>/**/body .highslide-gallery ul li {
|
||||
text-align: center;
|
||||
}
|
||||
html>/**/body .highslide-gallery ul a {
|
||||
position: static;
|
||||
display: table-cell;
|
||||
vertical-align: middle;
|
||||
}
|
||||
html>/**/body .highslide-gallery ul img {
|
||||
position: static;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Controls for the galleries. */
|
||||
/* Remove these if you are not using a gallery */
|
||||
/*****************************************************************************/
|
||||
.highslide-controls {
|
||||
width: 195px;
|
||||
height: 40px;
|
||||
background: url(highslide/controlbar-white.gif) 0 -90px no-repeat;
|
||||
margin: 20px 15px 10px 0;
|
||||
}
|
||||
.highslide-controls ul {
|
||||
position: relative;
|
||||
left: 15px;
|
||||
height: 40px;
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: url(highslide/controlbar-white.gif) right -90px no-repeat;
|
||||
|
||||
}
|
||||
.highslide-controls li {
|
||||
float: left;
|
||||
padding: 5px 0;
|
||||
margin:0;
|
||||
list-style: none;
|
||||
}
|
||||
.highslide-controls a {
|
||||
background-image: url(highslide/controlbar-white.gif);
|
||||
display: block;
|
||||
float: left;
|
||||
height: 30px;
|
||||
width: 30px;
|
||||
outline: none;
|
||||
}
|
||||
.highslide-controls a.disabled {
|
||||
cursor: default;
|
||||
}
|
||||
.highslide-controls a.disabled span {
|
||||
cursor: default;
|
||||
}
|
||||
.highslide-controls a span {
|
||||
/* hide the text for these graphic buttons */
|
||||
display: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
/* The CSS sprites for the controlbar - see http://www.google.com/search?q=css+sprites */
|
||||
.highslide-controls .highslide-previous a {
|
||||
background-position: 0 0;
|
||||
}
|
||||
.highslide-controls .highslide-previous a:hover {
|
||||
background-position: 0 -30px;
|
||||
}
|
||||
.highslide-controls .highslide-previous a.disabled {
|
||||
background-position: 0 -60px !important;
|
||||
}
|
||||
.highslide-controls .highslide-play a {
|
||||
background-position: -30px 0;
|
||||
}
|
||||
.highslide-controls .highslide-play a:hover {
|
||||
background-position: -30px -30px;
|
||||
}
|
||||
.highslide-controls .highslide-play a.disabled {
|
||||
background-position: -30px -60px !important;
|
||||
}
|
||||
.highslide-controls .highslide-pause a {
|
||||
background-position: -60px 0;
|
||||
}
|
||||
.highslide-controls .highslide-pause a:hover {
|
||||
background-position: -60px -30px;
|
||||
}
|
||||
.highslide-controls .highslide-next a {
|
||||
background-position: -90px 0;
|
||||
}
|
||||
.highslide-controls .highslide-next a:hover {
|
||||
background-position: -90px -30px;
|
||||
}
|
||||
.highslide-controls .highslide-next a.disabled {
|
||||
background-position: -90px -60px !important;
|
||||
}
|
||||
.highslide-controls .highslide-move a {
|
||||
background-position: -120px 0;
|
||||
}
|
||||
.highslide-controls .highslide-move a:hover {
|
||||
background-position: -120px -30px;
|
||||
}
|
||||
.highslide-controls .highslide-full-expand a {
|
||||
background-position: -150px 0;
|
||||
}
|
||||
.highslide-controls .highslide-full-expand a:hover {
|
||||
background-position: -150px -30px;
|
||||
}
|
||||
.highslide-controls .highslide-full-expand a.disabled {
|
||||
background-position: -150px -60px !important;
|
||||
}
|
||||
.highslide-controls .highslide-close a {
|
||||
background-position: -180px 0;
|
||||
}
|
||||
.highslide-controls .highslide-close a:hover {
|
||||
background-position: -180px -30px;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Styles for the HTML popups */
|
||||
/* Remove these if you are not using Highslide HTML */
|
||||
/*****************************************************************************/
|
||||
.highslide-maincontent {
|
||||
display: none;
|
||||
}
|
||||
.highslide-html {
|
||||
background-color: white;
|
||||
}
|
||||
.mobile .highslide-html {
|
||||
border: 1px solid silver;
|
||||
}
|
||||
.highslide-html-content {
|
||||
display: none;
|
||||
width: 400px;
|
||||
padding: 0 5px 5px 5px;
|
||||
}
|
||||
.highslide-header {
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
.highslide-header ul {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
text-align: right;
|
||||
}
|
||||
.highslide-header ul li {
|
||||
display: inline;
|
||||
padding-left: 1em;
|
||||
}
|
||||
.highslide-header ul li.highslide-previous, .highslide-header ul li.highslide-next {
|
||||
display: none;
|
||||
}
|
||||
.highslide-header a {
|
||||
font-weight: bold;
|
||||
color: gray;
|
||||
text-transform: uppercase;
|
||||
text-decoration: none;
|
||||
}
|
||||
.highslide-header a:hover {
|
||||
color: black;
|
||||
}
|
||||
.highslide-header .highslide-move a {
|
||||
cursor: move;
|
||||
}
|
||||
.highslide-footer {
|
||||
height: 16px;
|
||||
}
|
||||
.highslide-footer .highslide-resize {
|
||||
display: block;
|
||||
float: right;
|
||||
margin-top: 5px;
|
||||
height: 11px;
|
||||
width: 11px;
|
||||
background: url(highslide/resize.gif) no-repeat;
|
||||
}
|
||||
.highslide-footer .highslide-resize span {
|
||||
display: none;
|
||||
}
|
||||
.highslide-body {
|
||||
}
|
||||
.highslide-resize {
|
||||
cursor: nw-resize;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Styles for the Individual wrapper class names. */
|
||||
/* See www.highslide.com/ref/hs.wrapperClassName */
|
||||
/* You can safely remove the class name themes you don't use */
|
||||
/*****************************************************************************/
|
||||
|
||||
/* hs.wrapperClassName = 'draggable-header' */
|
||||
.draggable-header .highslide-header {
|
||||
height: 18px;
|
||||
border-bottom: 1px solid #dddddd;
|
||||
}
|
||||
.draggable-header .highslide-heading {
|
||||
position: absolute;
|
||||
margin: 2px 0.4em;
|
||||
}
|
||||
|
||||
.draggable-header .highslide-header .highslide-move {
|
||||
cursor: move;
|
||||
display: block;
|
||||
height: 16px;
|
||||
position: absolute;
|
||||
right: 24px;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
z-index: 1;
|
||||
}
|
||||
.draggable-header .highslide-header .highslide-move * {
|
||||
display: none;
|
||||
}
|
||||
.draggable-header .highslide-header .highslide-close {
|
||||
position: absolute;
|
||||
right: 2px;
|
||||
top: 2px;
|
||||
z-index: 5;
|
||||
padding: 0;
|
||||
}
|
||||
.draggable-header .highslide-header .highslide-close a {
|
||||
display: block;
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
background-image: url(highslide/closeX.png);
|
||||
}
|
||||
.draggable-header .highslide-header .highslide-close a:hover {
|
||||
background-position: 0 16px;
|
||||
}
|
||||
.draggable-header .highslide-header .highslide-close span {
|
||||
display: none;
|
||||
}
|
||||
.draggable-header .highslide-maincontent {
|
||||
padding-top: 1em;
|
||||
}
|
||||
|
||||
/* hs.wrapperClassName = 'titlebar' */
|
||||
.titlebar .highslide-header {
|
||||
height: 18px;
|
||||
border-bottom: 1px solid #dddddd;
|
||||
}
|
||||
.titlebar .highslide-heading {
|
||||
position: absolute;
|
||||
width: 90%;
|
||||
margin: 1px 0 1px 5px;
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.titlebar .highslide-header .highslide-move {
|
||||
cursor: move;
|
||||
display: block;
|
||||
height: 16px;
|
||||
position: absolute;
|
||||
right: 24px;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
z-index: 1;
|
||||
}
|
||||
.titlebar .highslide-header .highslide-move * {
|
||||
display: none;
|
||||
}
|
||||
.titlebar .highslide-header li {
|
||||
position: relative;
|
||||
top: 3px;
|
||||
z-index: 2;
|
||||
padding: 0 0 0 1em;
|
||||
}
|
||||
.titlebar .highslide-maincontent {
|
||||
padding-top: 1em;
|
||||
}
|
||||
|
||||
/* hs.wrapperClassName = 'no-footer' */
|
||||
.no-footer .highslide-footer {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* hs.wrapperClassName = 'wide-border' */
|
||||
.wide-border {
|
||||
background: white;
|
||||
}
|
||||
.wide-border .highslide-image {
|
||||
border-width: 10px;
|
||||
}
|
||||
.wide-border .highslide-caption {
|
||||
padding: 0 10px 10px 10px;
|
||||
}
|
||||
|
||||
/* hs.wrapperClassName = 'borderless' */
|
||||
.borderless .highslide-image {
|
||||
border: none;
|
||||
}
|
||||
.borderless .highslide-caption {
|
||||
border-bottom: 1px solid white;
|
||||
border-top: 1px solid white;
|
||||
background: silver;
|
||||
}
|
||||
|
||||
/* hs.wrapperClassName = 'outer-glow' */
|
||||
.outer-glow {
|
||||
background: #444;
|
||||
}
|
||||
.outer-glow .highslide-image {
|
||||
border: 5px solid #444444;
|
||||
}
|
||||
.outer-glow .highslide-caption {
|
||||
border: 5px solid #444444;
|
||||
border-top: none;
|
||||
padding: 5px;
|
||||
background-color: gray;
|
||||
}
|
||||
|
||||
/* hs.wrapperClassName = 'colored-border' */
|
||||
.colored-border {
|
||||
background: white;
|
||||
}
|
||||
.colored-border .highslide-image {
|
||||
border: 2px solid green;
|
||||
}
|
||||
.colored-border .highslide-caption {
|
||||
border: 2px solid green;
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
/* hs.wrapperClassName = 'dark' */
|
||||
.dark {
|
||||
background: #111;
|
||||
}
|
||||
.dark .highslide-image {
|
||||
border-color: black black #202020 black;
|
||||
background: gray;
|
||||
}
|
||||
.dark .highslide-caption {
|
||||
color: white;
|
||||
background: #111;
|
||||
}
|
||||
.dark .highslide-controls,
|
||||
.dark .highslide-controls ul,
|
||||
.dark .highslide-controls a {
|
||||
background-image: url(highslide/controlbar-black-border.gif);
|
||||
}
|
||||
|
||||
/* hs.wrapperClassName = 'floating-caption' */
|
||||
.floating-caption .highslide-caption {
|
||||
position: absolute;
|
||||
padding: 1em 0 0 0;
|
||||
background: none;
|
||||
color: white;
|
||||
border: none;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* hs.wrapperClassName = 'controls-in-heading' */
|
||||
.controls-in-heading .highslide-heading {
|
||||
color: gray;
|
||||
font-weight: bold;
|
||||
height: 20px;
|
||||
overflow: hidden;
|
||||
cursor: default;
|
||||
padding: 0 0 0 22px;
|
||||
margin: 0;
|
||||
background: url(highslide/icon.gif) no-repeat 0 1px;
|
||||
}
|
||||
.controls-in-heading .highslide-controls {
|
||||
width: 105px;
|
||||
height: 20px;
|
||||
position: relative;
|
||||
margin: 0;
|
||||
top: -23px;
|
||||
left: 7px;
|
||||
background: none;
|
||||
}
|
||||
.controls-in-heading .highslide-controls ul {
|
||||
position: static;
|
||||
height: 20px;
|
||||
background: none;
|
||||
}
|
||||
.controls-in-heading .highslide-controls li {
|
||||
padding: 0;
|
||||
}
|
||||
.controls-in-heading .highslide-controls a {
|
||||
background-image: url(highslide/controlbar-white-small.gif);
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
.controls-in-heading .highslide-controls .highslide-move {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.controls-in-heading .highslide-controls .highslide-previous a {
|
||||
background-position: 0 0;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-previous a:hover {
|
||||
background-position: 0 -20px;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-previous a.disabled {
|
||||
background-position: 0 -40px !important;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-play a {
|
||||
background-position: -20px 0;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-play a:hover {
|
||||
background-position: -20px -20px;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-play a.disabled {
|
||||
background-position: -20px -40px !important;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-pause a {
|
||||
background-position: -40px 0;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-pause a:hover {
|
||||
background-position: -40px -20px;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-next a {
|
||||
background-position: -60px 0;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-next a:hover {
|
||||
background-position: -60px -20px;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-next a.disabled {
|
||||
background-position: -60px -40px !important;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-full-expand a {
|
||||
background-position: -100px 0;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-full-expand a:hover {
|
||||
background-position: -100px -20px;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-full-expand a.disabled {
|
||||
background-position: -100px -40px !important;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-close a {
|
||||
background-position: -120px 0;
|
||||
}
|
||||
.controls-in-heading .highslide-controls .highslide-close a:hover {
|
||||
background-position: -120px -20px;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Styles for text based controls. */
|
||||
/* You can safely remove this if you don't use text based controls */
|
||||
/*****************************************************************************/
|
||||
|
||||
.text-controls .highslide-controls {
|
||||
width: auto;
|
||||
height: auto;
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
background: none;
|
||||
}
|
||||
.text-controls ul {
|
||||
position: static;
|
||||
background: none;
|
||||
height: auto;
|
||||
left: 0;
|
||||
}
|
||||
.text-controls .highslide-move {
|
||||
display: none;
|
||||
}
|
||||
.text-controls li {
|
||||
background-image: url(highslide/controlbar-text-buttons.png);
|
||||
background-position: right top !important;
|
||||
padding: 0;
|
||||
margin-left: 15px;
|
||||
display: block;
|
||||
width: auto;
|
||||
}
|
||||
.text-controls a {
|
||||
background: url(highslide/controlbar-text-buttons.png) no-repeat;
|
||||
background-position: left top !important;
|
||||
position: relative;
|
||||
left: -10px;
|
||||
display: block;
|
||||
width: auto;
|
||||
height: auto;
|
||||
text-decoration: none !important;
|
||||
}
|
||||
.text-controls a span {
|
||||
background: url(highslide/controlbar-text-buttons.png) no-repeat;
|
||||
margin: 1px 2px 1px 10px;
|
||||
display: block;
|
||||
min-width: 4em;
|
||||
height: 18px;
|
||||
line-height: 18px;
|
||||
padding: 1px 0 1px 18px;
|
||||
color: #333;
|
||||
font-family: "Trebuchet MS", Arial, sans-serif;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.text-controls .highslide-next {
|
||||
margin-right: 1em;
|
||||
}
|
||||
.text-controls .highslide-full-expand a span {
|
||||
min-width: 0;
|
||||
margin: 1px 0;
|
||||
padding: 1px 0 1px 10px;
|
||||
}
|
||||
.text-controls .highslide-close a span {
|
||||
min-width: 0;
|
||||
}
|
||||
.text-controls a:hover span {
|
||||
color: black;
|
||||
}
|
||||
.text-controls a.disabled span {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.text-controls .highslide-previous span {
|
||||
background-position: 0 -40px;
|
||||
}
|
||||
.text-controls .highslide-previous a.disabled {
|
||||
background-position: left top !important;
|
||||
}
|
||||
.text-controls .highslide-previous a.disabled span {
|
||||
background-position: 0 -140px;
|
||||
}
|
||||
.text-controls .highslide-play span {
|
||||
background-position: 0 -60px;
|
||||
}
|
||||
.text-controls .highslide-play a.disabled {
|
||||
background-position: left top !important;
|
||||
}
|
||||
.text-controls .highslide-play a.disabled span {
|
||||
background-position: 0 -160px;
|
||||
}
|
||||
.text-controls .highslide-pause span {
|
||||
background-position: 0 -80px;
|
||||
}
|
||||
.text-controls .highslide-next span {
|
||||
background-position: 0 -100px;
|
||||
}
|
||||
.text-controls .highslide-next a.disabled {
|
||||
background-position: left top !important;
|
||||
}
|
||||
.text-controls .highslide-next a.disabled span {
|
||||
background-position: 0 -200px;
|
||||
}
|
||||
.text-controls .highslide-full-expand span {
|
||||
background: none;
|
||||
}
|
||||
.text-controls .highslide-full-expand a.disabled {
|
||||
background-position: left top !important;
|
||||
}
|
||||
.text-controls .highslide-close span {
|
||||
background-position: 0 -120px;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Styles for the thumbstrip. */
|
||||
/* See www.highslide.com/ref/hs.addSlideshow */
|
||||
/* You can safely remove this if you don't use a thumbstrip */
|
||||
/*****************************************************************************/
|
||||
|
||||
.highslide-thumbstrip {
|
||||
height: 100%;
|
||||
direction: ltr;
|
||||
}
|
||||
.highslide-thumbstrip div {
|
||||
overflow: hidden;
|
||||
}
|
||||
.highslide-thumbstrip table {
|
||||
position: relative;
|
||||
padding: 0;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.highslide-thumbstrip td {
|
||||
padding: 1px;
|
||||
/*text-align: center;*/
|
||||
}
|
||||
.highslide-thumbstrip a {
|
||||
outline: none;
|
||||
}
|
||||
.highslide-thumbstrip img {
|
||||
display: block;
|
||||
border: 1px solid gray;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.highslide-thumbstrip .highslide-active-anchor img {
|
||||
visibility: visible;
|
||||
}
|
||||
.highslide-thumbstrip .highslide-marker {
|
||||
position: absolute;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-width: 0;
|
||||
border-style: solid;
|
||||
border-color: transparent; /* change this to actual background color in highslide-ie6.css */
|
||||
}
|
||||
.highslide-thumbstrip-horizontal div {
|
||||
width: auto;
|
||||
/* width: 100% breaks in small strips in IE */
|
||||
}
|
||||
.highslide-thumbstrip-horizontal .highslide-scroll-up {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
left: 3px;
|
||||
width: 25px;
|
||||
height: 42px;
|
||||
}
|
||||
.highslide-thumbstrip-horizontal .highslide-scroll-up div {
|
||||
margin-bottom: 10px;
|
||||
cursor: pointer;
|
||||
background: url(highslide/scrollarrows.png) left center no-repeat;
|
||||
height: 42px;
|
||||
}
|
||||
.highslide-thumbstrip-horizontal .highslide-scroll-down {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
right: 3px;
|
||||
width: 25px;
|
||||
height: 42px;
|
||||
}
|
||||
.highslide-thumbstrip-horizontal .highslide-scroll-down div {
|
||||
margin-bottom: 10px;
|
||||
cursor: pointer;
|
||||
background: url(highslide/scrollarrows.png) center right no-repeat;
|
||||
height: 42px;
|
||||
}
|
||||
.highslide-thumbstrip-horizontal table {
|
||||
margin: 2px 0 10px 0;
|
||||
}
|
||||
.highslide-viewport .highslide-thumbstrip-horizontal table {
|
||||
margin-left: 10px;
|
||||
}
|
||||
.highslide-thumbstrip-horizontal img {
|
||||
width: auto;
|
||||
height: 40px;
|
||||
}
|
||||
.highslide-thumbstrip-horizontal .highslide-marker {
|
||||
top: 47px;
|
||||
border-left-width: 6px;
|
||||
border-right-width: 6px;
|
||||
border-bottom: 6px solid gray;
|
||||
}
|
||||
.highslide-viewport .highslide-thumbstrip-horizontal .highslide-marker {
|
||||
margin-left: 10px;
|
||||
}
|
||||
.dark .highslide-thumbstrip-horizontal .highslide-marker, .highslide-viewport .highslide-thumbstrip-horizontal .highslide-marker {
|
||||
border-bottom-color: white !important;
|
||||
}
|
||||
|
||||
.highslide-thumbstrip-vertical-overlay {
|
||||
overflow: hidden !important;
|
||||
}
|
||||
.highslide-thumbstrip-vertical div {
|
||||
height: 100%;
|
||||
}
|
||||
.highslide-thumbstrip-vertical a {
|
||||
display: block;
|
||||
}
|
||||
.highslide-thumbstrip-vertical .highslide-scroll-up {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 25px;
|
||||
}
|
||||
.highslide-thumbstrip-vertical .highslide-scroll-up div {
|
||||
margin-left: 10px;
|
||||
cursor: pointer;
|
||||
background: url(highslide/scrollarrows.png) top center no-repeat;
|
||||
height: 25px;
|
||||
}
|
||||
.highslide-thumbstrip-vertical .highslide-scroll-down {
|
||||
display: none;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 25px;
|
||||
}
|
||||
.highslide-thumbstrip-vertical .highslide-scroll-down div {
|
||||
margin-left: 10px;
|
||||
cursor: pointer;
|
||||
background: url(highslide/scrollarrows.png) bottom center no-repeat;
|
||||
height: 25px;
|
||||
}
|
||||
.highslide-thumbstrip-vertical table {
|
||||
margin: 10px 0 0 10px;
|
||||
}
|
||||
.highslide-thumbstrip-vertical img {
|
||||
width: 60px; /* t=5481 */
|
||||
}
|
||||
.highslide-thumbstrip-vertical .highslide-marker {
|
||||
left: 0;
|
||||
margin-top: 8px;
|
||||
border-top-width: 6px;
|
||||
border-bottom-width: 6px;
|
||||
border-left: 6px solid gray;
|
||||
}
|
||||
.dark .highslide-thumbstrip-vertical .highslide-marker, .highslide-viewport .highslide-thumbstrip-vertical .highslide-marker {
|
||||
border-left-color: white;
|
||||
}
|
||||
|
||||
.highslide-viewport .highslide-thumbstrip-float {
|
||||
overflow: auto;
|
||||
}
|
||||
.highslide-thumbstrip-float ul {
|
||||
margin: 2px 0;
|
||||
padding: 0;
|
||||
}
|
||||
.highslide-thumbstrip-float li {
|
||||
display: block;
|
||||
height: 60px;
|
||||
margin: 0 2px;
|
||||
list-style: none;
|
||||
float: left;
|
||||
}
|
||||
.highslide-thumbstrip-float img {
|
||||
display: inline;
|
||||
border-color: silver;
|
||||
max-height: 56px;
|
||||
}
|
||||
.highslide-thumbstrip-float .highslide-active-anchor img {
|
||||
border-color: black;
|
||||
}
|
||||
.highslide-thumbstrip-float .highslide-scroll-up div, .highslide-thumbstrip-float .highslide-scroll-down div {
|
||||
display: none;
|
||||
}
|
||||
.highslide-thumbstrip-float .highslide-marker {
|
||||
display: none;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
||||
* listed below.
|
||||
*
|
||||
* Any Css/Less files within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
* can be referenced here using a relative path.
|
||||
*
|
||||
* It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
* gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
* but before any files alphabetically greater than 'application.css'
|
||||
*
|
||||
*= require highslide/highslide
|
||||
*/
|
||||
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
||||
* listed below.
|
||||
*
|
||||
* Any Css/Less files within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
||||
* can be referenced here using a relative path.
|
||||
*
|
||||
* It's not advisable to add code directly here, but if you do, it'll appear in whatever order it
|
||||
* gets included (e.g. say you have require_tree . then the code will appear after all the directories
|
||||
* but before any files alphabetically greater than 'application.css'
|
||||
*
|
||||
*= require tagsinput/bootstrap-tagsinput
|
||||
*/
|
||||
7
app/breadcrumbs.php
Normal file
7
app/breadcrumbs.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/*
|
||||
* Back home.
|
||||
*/
|
||||
Breadcrumbs::register('home', function($breadcrumbs) {
|
||||
$breadcrumbs->push('Home', route('index'));
|
||||
});
|
||||
1
app/config/.gitignore
vendored
1
app/config/.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
local/
|
||||
laptop/
|
||||
vagrant/
|
||||
@@ -6,6 +6,7 @@ return [
|
||||
'timezone' => 'UTC',
|
||||
'locale' => 'en',
|
||||
'fallback_locale' => 'en',
|
||||
'log_level' => 'notice',
|
||||
'key' => 'D93oqmVsIARg23FC3cbsHuBGk0uXQc3r',
|
||||
'cipher' => MCRYPT_RIJNDAEL_128,
|
||||
'providers' => [
|
||||
@@ -36,12 +37,13 @@ return [
|
||||
'Illuminate\Validation\ValidationServiceProvider',
|
||||
'Illuminate\View\ViewServiceProvider',
|
||||
'Illuminate\Workbench\WorkbenchServiceProvider',
|
||||
# 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',
|
||||
# 'Barryvdh\Debugbar\ServiceProvider',
|
||||
'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',
|
||||
'Barryvdh\Debugbar\ServiceProvider',
|
||||
'Firefly\Storage\StorageServiceProvider',
|
||||
'Firefly\Helper\HelperServiceProvider',
|
||||
'Firefly\Validation\ValidationServiceProvider',
|
||||
'Codesleeve\AssetPipeline\AssetPipelineServiceProvider',
|
||||
'DaveJamesMiller\Breadcrumbs\ServiceProvider',
|
||||
'Grumpydictator\Gchart\GchartServiceProvider',
|
||||
],
|
||||
'manifest' => storage_path() . '/meta',
|
||||
'aliases' => [
|
||||
@@ -84,6 +86,8 @@ return [
|
||||
'URL' => 'Illuminate\Support\Facades\URL',
|
||||
'Validator' => 'Illuminate\Support\Facades\Validator',
|
||||
'View' => 'Illuminate\Support\Facades\View',
|
||||
'Breadcrumbs' => 'DaveJamesMiller\Breadcrumbs\Facade',
|
||||
'Twig' => 'TwigBridge\Facade\Twig',
|
||||
|
||||
],
|
||||
|
||||
|
||||
@@ -2,9 +2,13 @@
|
||||
use Carbon\Carbon;
|
||||
|
||||
return [
|
||||
'index_periods' => ['1D', '1W', '1M', '3M', '6M', 'custom'],
|
||||
'index_periods' => ['1D', '1W', '1M', '3M', '6M', '1Y', 'custom'],
|
||||
'budget_periods' => ['daily', 'weekly', 'monthly', 'quarterly', 'half-year', 'yearly'],
|
||||
'piggybank_periods' => ['day', 'week', 'month', 'year'],
|
||||
'piggybank_periods' => [
|
||||
'week' => 'Week',
|
||||
'month' => 'Month',
|
||||
'year' => 'Year'
|
||||
],
|
||||
'periods_to_text' => [
|
||||
'weekly' => 'A week',
|
||||
'monthly' => 'A month',
|
||||
@@ -21,6 +25,14 @@ return [
|
||||
'6M' => 'half year',
|
||||
'custom' => '(custom)'
|
||||
],
|
||||
'range_to_name' => [
|
||||
'1D' => 'one day',
|
||||
'1W' => 'one week',
|
||||
'1M' => 'one month',
|
||||
'3M' => 'three months',
|
||||
'6M' => 'six months',
|
||||
'1Y' => 'one year',
|
||||
],
|
||||
'range_to_repeat_freq' => [
|
||||
'1D' => 'weekly',
|
||||
'1W' => 'weekly',
|
||||
|
||||
@@ -1,331 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| EnvironmentFilter
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is used to run filters on specific environments. For example, if you
|
||||
| only want to run a filter on production and staging environments
|
||||
|
|
||||
| new EnvironmentFilter(new FilterExample, App::environment(), ['production', 'staging')),
|
||||
|
|
||||
*/
|
||||
use Codesleeve\AssetPipeline\Filters\EnvironmentFilter;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| routing array
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This is passed to the Route::group and allows us to group and filter the
|
||||
| routes for our package
|
||||
|
|
||||
*/
|
||||
'routing' => [
|
||||
'prefix' => '/assets'
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| paths
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These are the directories we search for files in.
|
||||
|
|
||||
| NOTE that the '.' in require_tree . is relative to where the manifest file
|
||||
| (i.e. app/assets/javascripts/application.js) is located
|
||||
|
|
||||
*/
|
||||
'paths' => [
|
||||
'app/assets/javascripts',
|
||||
'app/assets/stylesheets',
|
||||
'app/assets/images',
|
||||
'lib/assets/javascripts',
|
||||
'lib/assets/stylesheets',
|
||||
'lib/assets/images',
|
||||
'provider/assets/javascripts',
|
||||
'provider/assets/stylesheets',
|
||||
'provider/assets/images'
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| mimes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| In order to know which mime type to send back to the server
|
||||
| we need to know if it is a javascript or stylesheet type. If
|
||||
| the extension is not found below then we just return a regular
|
||||
| download.
|
||||
|
|
||||
*/
|
||||
'mimes' => [
|
||||
'javascripts' => ['.js', '.js.coffee', '.coffee', '.html', '.min.js'],
|
||||
'stylesheets' => ['.css', '.css.less', '.css.sass', '.css.scss', '.less', '.sass', '.scss', '.min.css'],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| filters
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| In order for a file to be included with sprockets, it needs to be listed
|
||||
| here and we can also do any preprocessing on files with the extension if
|
||||
| we choose to.
|
||||
|
|
||||
*/
|
||||
'filters' => [
|
||||
'.min.js' => [
|
||||
|
||||
],
|
||||
'.min.css' => [
|
||||
new Codesleeve\AssetPipeline\Filters\URLRewrite(App::make('url')->to('/')),
|
||||
],
|
||||
'.js' => [
|
||||
new EnvironmentFilter(new Codesleeve\AssetPipeline\Filters\JSMinPlusFilter, App::environment()),
|
||||
],
|
||||
'.js.coffee' => [
|
||||
new Codesleeve\AssetPipeline\Filters\CoffeeScript,
|
||||
new EnvironmentFilter(new Codesleeve\AssetPipeline\Filters\JSMinPlusFilter, App::environment()),
|
||||
],
|
||||
'.coffee' => [
|
||||
new Codesleeve\AssetPipeline\Filters\CoffeeScript,
|
||||
new EnvironmentFilter(new Codesleeve\AssetPipeline\Filters\JSMinPlusFilter, App::environment()),
|
||||
],
|
||||
'.css' => [
|
||||
new Codesleeve\AssetPipeline\Filters\URLRewrite(App::make('url')->to('/')),
|
||||
new EnvironmentFilter(new Codesleeve\AssetPipeline\Filters\CssMinFilter, App::environment()),
|
||||
],
|
||||
'.css.less' => [
|
||||
new Codesleeve\AssetPipeline\Filters\LessphpFilter,
|
||||
new Codesleeve\AssetPipeline\Filters\URLRewrite(App::make('url')->to('/')),
|
||||
new EnvironmentFilter(new Codesleeve\AssetPipeline\Filters\CssMinFilter, App::environment()),
|
||||
],
|
||||
'.css.sass' => [
|
||||
new Codesleeve\AssetPipeline\Filters\SassFilter,
|
||||
new Codesleeve\AssetPipeline\Filters\URLRewrite(App::make('url')->to('/')),
|
||||
new EnvironmentFilter(new Codesleeve\AssetPipeline\Filters\CssMinFilter, App::environment()),
|
||||
],
|
||||
'.css.scss' => [
|
||||
new Assetic\Filter\ScssphpFilter,
|
||||
new Codesleeve\AssetPipeline\Filters\URLRewrite(App::make('url')->to('/')),
|
||||
new EnvironmentFilter(new Codesleeve\AssetPipeline\Filters\CssMinFilter, App::environment()),
|
||||
],
|
||||
'.less' => [
|
||||
new Codesleeve\AssetPipeline\Filters\LessphpFilter,
|
||||
new Codesleeve\AssetPipeline\Filters\URLRewrite(App::make('url')->to('/')),
|
||||
new EnvironmentFilter(new Codesleeve\AssetPipeline\Filters\CssMinFilter, App::environment()),
|
||||
],
|
||||
'.sass' => [
|
||||
new Codesleeve\AssetPipeline\Filters\SassFilter,
|
||||
new Codesleeve\AssetPipeline\Filters\URLRewrite(App::make('url')->to('/')),
|
||||
new EnvironmentFilter(new Codesleeve\AssetPipeline\Filters\CssMinFilter, App::environment()),
|
||||
],
|
||||
'.scss' => [
|
||||
new Assetic\Filter\ScssphpFilter,
|
||||
new Codesleeve\AssetPipeline\Filters\URLRewrite(App::make('url')->to('/')),
|
||||
new EnvironmentFilter(new Codesleeve\AssetPipeline\Filters\CssMinFilter, App::environment()),
|
||||
],
|
||||
'.html' => [
|
||||
new Codesleeve\AssetPipeline\Filters\JST,
|
||||
new EnvironmentFilter(new Codesleeve\AssetPipeline\Filters\JSMinPlusFilter, App::environment()),
|
||||
]
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| cache
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By default we cache assets on production environment permanently. We also cache
|
||||
| all files using the `cache_server` driver below but the cache is busted anytime
|
||||
| those files are modified. On production we will cache and the only way to bust
|
||||
| the cache is to delete files from app/storage/cache/asset-pipeline or run a
|
||||
| command php artisan assets:clean -f somefilename.js -f application.css ...
|
||||
|
|
||||
*/
|
||||
'cache' => ['production'],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| cache_server
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You can create your own CacheInterface if the filesystem cache is not up to
|
||||
| your standards. This is for caching asset files on the server-side.
|
||||
|
|
||||
| Please note that caching is used on **ALL** environments always. This is done
|
||||
| to increase performance of the pipeline. Cached files will be busted when the
|
||||
| file changes.
|
||||
|
|
||||
| However, manifest files are regenerated (not cached) when the environment is
|
||||
| not found within the 'cache' array. This lets you develop on local and still
|
||||
| utilize caching, so you don't have to regenerate all precompiled files while
|
||||
| developing on your assets.
|
||||
|
|
||||
| See more in CacheInterface.php at
|
||||
|
|
||||
| https://github.com/kriswallsmith/assetic/blob/master/src/Assetic/Cache
|
||||
|
|
||||
|
|
||||
*/
|
||||
'cache_server' => new Assetic\Cache\FilesystemCache(App::make('path.storage') . '/cache/asset-pipeline'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| cache_client
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If you want to handle 304's and what not, to keep users from refetching
|
||||
| your assets and saving your bandwidth you can use a cache_client driver
|
||||
| that handles this. This doesn't handle assets on the server-side, use
|
||||
| cache_server for that. This only works when the current environment is
|
||||
| listed within `cache`
|
||||
|
|
||||
| Note that this needs to implement the interface
|
||||
|
|
||||
| Codesleeve\Sprockets\Interfaces\ClientCacheInterface
|
||||
|
|
||||
| or this won't work correctly. It is a wrapper class around your cache_server
|
||||
| driver and also uses the AssetCache class to help access files.
|
||||
|
|
||||
*/
|
||||
'cache_client' => new Codesleeve\AssetPipeline\Filters\ClientCacheFilter,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| concat
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This allows us to turn on the asset concatenation for specific
|
||||
| environments listed below. You can turn off local environment if
|
||||
| you are trying to troubleshoot, but you will likely have better
|
||||
| performance if you leave concat on (except if you are doing a lot
|
||||
| of minification stuff on each page refresh)
|
||||
|
|
||||
*/
|
||||
'concat' => ['production', 'local'],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| directives
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This allows us to turn completely control which directives are used
|
||||
| for the sprockets parser that asset pipeline uses to parse manifest files.
|
||||
|
|
||||
| It is probably safe just to leave this alone unless you are familar with
|
||||
| what is actually going on here.
|
||||
|
|
||||
*/
|
||||
'directives' => [
|
||||
'require ' => new Codesleeve\Sprockets\Directives\RequireFile,
|
||||
'require_directory ' => new Codesleeve\Sprockets\Directives\RequireDirectory,
|
||||
'require_tree ' => new Codesleeve\Sprockets\Directives\RequireTree,
|
||||
'require_tree_df ' => new Codesleeve\Sprockets\Directives\RequireTreeDf,
|
||||
'require_self' => new Codesleeve\Sprockets\Directives\RequireSelf,
|
||||
'include ' => new Codesleeve\Sprockets\Directives\IncludeFile,
|
||||
'include_directory ' => new Codesleeve\Sprockets\Directives\IncludeDirectory,
|
||||
'include_tree ' => new Codesleeve\Sprockets\Directives\IncludeTree,
|
||||
'stub ' => new Codesleeve\Sprockets\Directives\Stub,
|
||||
'depend_on ' => new Codesleeve\Sprockets\Directives\DependOn,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| javascript_include_tag
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This allows us to completely control how the javascript_include_tag function
|
||||
| works for asset pipeline.
|
||||
|
|
||||
| It is probably safe just to leave this alone unless you are familar with
|
||||
| what is actually going on here.
|
||||
|
|
||||
*/
|
||||
'javascript_include_tag' => new Codesleeve\AssetPipeline\Composers\JavascriptComposer,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| stylesheet_link_tag
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This allows us to completely control how the stylesheet_link_tag function
|
||||
| works for asset pipeline.
|
||||
|
|
||||
| It is probably safe just to leave this alone unless you are familar with
|
||||
| what is actually going on here.
|
||||
|
|
||||
*/
|
||||
'stylesheet_link_tag' => new Codesleeve\AssetPipeline\Composers\StylesheetComposer,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| image_tag
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This allows us to completely control how the image_tag function
|
||||
| works for asset pipeline.
|
||||
|
|
||||
| It is probably safe just to leave this alone unless you are familar with
|
||||
| what is actually going on here.
|
||||
|
|
||||
*/
|
||||
'image_tag' => new Codesleeve\AssetPipeline\Composers\ImageComposer,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| controller_action
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Asset pipeline will route all requests through the controller action
|
||||
| listed here. This allows us to completely control how the controller
|
||||
| should behave for incoming requests for assets.
|
||||
|
|
||||
| It is probably safe just to leave this alone unless you are familar with
|
||||
| what is actually going on here.
|
||||
|
|
||||
*/
|
||||
'controller_action' => '\Codesleeve\AssetPipeline\AssetPipelineController@file',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| sprockets_filter
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When concatenation is turned on, when an asset is fetched from the sprockets
|
||||
| generator it is filtered through this filter class named below. This allows us
|
||||
| to modify the sprockets filter if we need to behave differently.
|
||||
|
|
||||
| It is probably safe just to leave this alone unless you are familar with
|
||||
| what is actually going on here.
|
||||
|
|
||||
*/
|
||||
'sprockets_filter' => '\Codesleeve\Sprockets\SprocketsFilter',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| sprockets_filter
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When concatenation is turned on, assets are filtered via SprocketsFilter
|
||||
| and we can do global filters on the resulting dump file. This would be
|
||||
| useful if you wanted to apply a filter to all javascript or stylesheet files
|
||||
| like minification. Out of the box we don't have any filters here. Add at
|
||||
| your own risk. I don't put minification filters here because the minify
|
||||
| doesn't always work perfectly and can bjork your entire concatenated
|
||||
| javascript or stylesheet file if it messes up.
|
||||
|
|
||||
| It is probably safe just to leave this alone unless you are familar with
|
||||
| what is actually going on here.
|
||||
|
|
||||
*/
|
||||
'sprockets_filters' => [
|
||||
'javascripts' => [],
|
||||
'stylesheets' => [],
|
||||
],
|
||||
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'view' => 'laravel-breadcrumbs::bootstrap3',
|
||||
);
|
||||
134
app/config/packages/rcrowe/twigbridge/extensions.php
Normal file
134
app/config/packages/rcrowe/twigbridge/extensions.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the TwigBridge package.
|
||||
*
|
||||
* @copyright Robert Crowe <hello@vivalacrowe.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Configuration options for the built-in extensions.
|
||||
*/
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Extensions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Enabled extensions.
|
||||
|
|
||||
| `Twig_Extension_Debug` is enabled automatically if twig.debug is TRUE.
|
||||
|
|
||||
*/
|
||||
'enabled' => [
|
||||
'TwigBridge\Extension\Loader\Facades',
|
||||
'TwigBridge\Extension\Loader\Filters',
|
||||
'TwigBridge\Extension\Loader\Functions',
|
||||
|
||||
'TwigBridge\Extension\Laravel\Auth',
|
||||
'TwigBridge\Extension\Laravel\Config',
|
||||
'TwigBridge\Extension\Laravel\Form',
|
||||
'TwigBridge\Extension\Laravel\Html',
|
||||
'TwigBridge\Extension\Laravel\Input',
|
||||
'TwigBridge\Extension\Laravel\Session',
|
||||
'TwigBridge\Extension\Laravel\String',
|
||||
'TwigBridge\Extension\Laravel\Translator',
|
||||
'TwigBridge\Extension\Laravel\Url',
|
||||
|
||||
// 'TwigBridge\Extension\Laravel\Legacy\Facades',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Facades
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Available facades. Access like `{{ Config.get('foo.bar') }}`.
|
||||
|
|
||||
| Each facade can take an optional array of options. To mark the whole facade
|
||||
| as safe you can set the option `'is_safe' => true`. Setting the facade as
|
||||
| safe means that any HTML returned will not be escaped.
|
||||
|
|
||||
| It is advisable to not set the whole facade as safe and instead mark the
|
||||
| each appropriate method as safe for security reasons. You can do that with
|
||||
| the following syntax:
|
||||
|
|
||||
| <code>
|
||||
| 'Form' => [
|
||||
| 'is_safe' => [
|
||||
| 'open'
|
||||
| ]
|
||||
| ]
|
||||
| </code>
|
||||
|
|
||||
| The values of the `is_safe` array must match the called method on the facade
|
||||
| in order to be marked as safe.
|
||||
|
|
||||
*/
|
||||
'facades' => [],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Available functions. Access like `{{ secure_url(...) }}`.
|
||||
|
|
||||
| Each function can take an optional array of options. These options are
|
||||
| passed directly to `Twig_SimpleFunction`.
|
||||
|
|
||||
| So for example, to mark a function as safe you can do the following:
|
||||
|
|
||||
| <code>
|
||||
| 'link_to' => [
|
||||
| 'is_safe' => ['html']
|
||||
| ]
|
||||
| </code>
|
||||
|
|
||||
| The options array also takes a `callback` that allows you to name the
|
||||
| function differently in your Twig templates than what it's actually called.
|
||||
|
|
||||
| <code>
|
||||
| 'link' => [
|
||||
| 'callback' => 'link_to'
|
||||
| ]
|
||||
| </code>
|
||||
|
|
||||
*/
|
||||
'functions' => [],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Filters
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Available filters. Access like `{{ variable|filter }}`.
|
||||
|
|
||||
| Each filter can take an optional array of options. These options are
|
||||
| passed directly to `Twig_SimpleFilter`.
|
||||
|
|
||||
| So for example, to mark a filter as safe you can do the following:
|
||||
|
|
||||
| <code>
|
||||
| 'studly_case' => [
|
||||
| 'is_safe' => ['html']
|
||||
| ]
|
||||
| </code>
|
||||
|
|
||||
| The options array also takes a `callback` that allows you to name the
|
||||
| filter differently in your Twig templates than what is actually called.
|
||||
|
|
||||
| <code>
|
||||
| 'snake' => [
|
||||
| 'callback' => 'snake_case'
|
||||
| ]
|
||||
| </code>
|
||||
|
|
||||
*/
|
||||
'filters' => [],
|
||||
|
||||
];
|
||||
88
app/config/packages/rcrowe/twigbridge/twig.php
Normal file
88
app/config/packages/rcrowe/twigbridge/twig.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the TwigBridge package.
|
||||
*
|
||||
* @copyright Robert Crowe <hello@vivalacrowe.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
/**
|
||||
* Configuration options for Twig.
|
||||
*/
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Extension
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| File extension for Twig view files.
|
||||
|
|
||||
*/
|
||||
'extension' => 'twig',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Accepts all Twig environment configuration options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| http://twig.sensiolabs.org/doc/api.html#environment-options
|
||||
|
|
||||
*/
|
||||
'environment' => [
|
||||
|
||||
// When set to true, the generated templates have a __toString() method
|
||||
// that you can use to display the generated nodes.
|
||||
// default: false
|
||||
'debug' => Config::get('app.debug', false),
|
||||
|
||||
// The charset used by the templates.
|
||||
// default: utf-8
|
||||
'charset' => 'utf-8',
|
||||
|
||||
// The base template class to use for generated templates.
|
||||
// default: TwigBridge\Twig\Template
|
||||
'base_template_class' => 'TwigBridge\Twig\Template',
|
||||
|
||||
// An absolute path where to store the compiled templates, or false to disable caching. If null
|
||||
// then the cache file path is used.
|
||||
// default: cache file storage path
|
||||
'cache' => null,
|
||||
|
||||
// When developing with Twig, it's useful to recompile the template
|
||||
// whenever the source code changes. If you don't provide a value
|
||||
// for the auto_reload option, it will be determined automatically based on the debug value.
|
||||
'auto_reload' => true,
|
||||
|
||||
// If set to false, Twig will silently ignore invalid variables
|
||||
// (variables and or attributes/methods that do not exist) and
|
||||
// replace them with a null value. When set to true, Twig throws an exception instead.
|
||||
// default: false
|
||||
'strict_variables' => false,
|
||||
|
||||
// If set to true, auto-escaping will be enabled by default for all templates.
|
||||
// default: true
|
||||
'autoescape' => true,
|
||||
|
||||
// A flag that indicates which optimizations to apply
|
||||
// (default to -1 -- all optimizations are enabled; set it to 0 to disable)
|
||||
'optimizations' => -1,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global variables
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These will always be passed in and can be accessed as Twig variables.
|
||||
| NOTE: these will be overwritten if you pass data into the view with the same key.
|
||||
|
|
||||
*/
|
||||
'globals' => [],
|
||||
|
||||
];
|
||||
@@ -1,35 +1,134 @@
|
||||
<?php
|
||||
|
||||
use Firefly\Helper\Controllers\AccountInterface as AI;
|
||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
use Firefly\Exception\FireflyException;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
* Class AccountController
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class AccountController extends \BaseController
|
||||
class AccountController extends BaseController
|
||||
{
|
||||
|
||||
protected $_repository;
|
||||
protected $_accounts;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
View::share('mainTitleIcon', 'fa-credit-card');
|
||||
View::share('title', 'Accounts');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ARI $repository
|
||||
* @param AI $accounts
|
||||
* @param string $what
|
||||
*
|
||||
* @return View
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function __construct(ARI $repository, AI $accounts)
|
||||
public function index($what = 'default')
|
||||
{
|
||||
$this->_accounts = $accounts;
|
||||
$this->_repository = $repository;
|
||||
switch ($what) {
|
||||
default:
|
||||
throw new FireflyException('Cannot handle account type "' . e($what) . '".');
|
||||
break;
|
||||
case 'asset':
|
||||
View::share('subTitleIcon', 'fa-money');
|
||||
View::share('subTitle', 'Asset accounts');
|
||||
break;
|
||||
case 'expense':
|
||||
View::share('subTitleIcon', 'fa-shopping-cart');
|
||||
View::share('subTitle', 'Expense accounts');
|
||||
break;
|
||||
case 'revenue':
|
||||
View::share('subTitleIcon', 'fa-download');
|
||||
View::share('subTitle', 'Revenue accounts');
|
||||
break;
|
||||
}
|
||||
return View::make('accounts.index')->with('what', $what);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $what
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function json($what = 'default')
|
||||
{
|
||||
/** @var \FireflyIII\Database\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account');
|
||||
|
||||
/** @var \FireflyIII\Shared\Json\Json $json */
|
||||
$json = App::make('FireflyIII\Shared\Json\Json');
|
||||
|
||||
$parameters = $json->dataTableParameters();
|
||||
|
||||
switch ($what) {
|
||||
default:
|
||||
throw new FireflyException('Cannot handle account type "' . e($what) . '".');
|
||||
break;
|
||||
case 'asset':
|
||||
$accounts = $acct->getAssetAccounts($parameters);
|
||||
$count = $acct->countAssetAccounts();
|
||||
break;
|
||||
case 'expense':
|
||||
$accounts = $acct->getExpenseAccounts($parameters);
|
||||
$count = $acct->countExpenseAccounts();
|
||||
break;
|
||||
case 'revenue':
|
||||
$accounts = $acct->getRevenueAccounts($parameters);
|
||||
$count = $acct->countRevenueAccounts();
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Output the set compatible with data tables:
|
||||
*/
|
||||
$return = [
|
||||
'draw' => intval(Input::get('draw')),
|
||||
'recordsTotal' => $count,
|
||||
'recordsFiltered' => $accounts->count(),
|
||||
'data' => [],
|
||||
];
|
||||
|
||||
/*
|
||||
* Loop the accounts:
|
||||
*/
|
||||
/** @var \Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$entry = [
|
||||
'name' => ['name' => $account->name, 'url' => route('accounts.show', $account->id)],
|
||||
'balance' => $account->balance(),
|
||||
'id' => [
|
||||
'edit' => route('accounts.edit', $account->id),
|
||||
'delete' => route('accounts.delete', $account->id),
|
||||
]
|
||||
];
|
||||
$return['data'][] = $entry;
|
||||
}
|
||||
|
||||
|
||||
return Response::jsoN($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
public function create($what)
|
||||
{
|
||||
return View::make('accounts.create')->with('title', 'Create account');
|
||||
switch ($what) {
|
||||
case 'asset':
|
||||
View::share('subTitleIcon', 'fa-money');
|
||||
break;
|
||||
case 'expense':
|
||||
View::share('subTitleIcon', 'fa-shopping-cart');
|
||||
break;
|
||||
case 'revenue':
|
||||
View::share('subTitleIcon', 'fa-download');
|
||||
break;
|
||||
}
|
||||
|
||||
return View::make('accounts.create')->with('subTitle', 'Create a new ' . $what . ' account')->with('what', $what);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +139,9 @@ class AccountController extends \BaseController
|
||||
public function delete(Account $account)
|
||||
{
|
||||
return View::make('accounts.delete')->with('account', $account)
|
||||
->with('title', 'Delete account "' . $account->name . '"');
|
||||
->with(
|
||||
'subTitle', 'Delete ' . strtolower($account->accountType->type) . ' "' . $account->name . '"'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,10 +152,69 @@ class AccountController extends \BaseController
|
||||
public function destroy(Account $account)
|
||||
{
|
||||
|
||||
$this->_repository->destroy($account);
|
||||
Session::flash('success', 'The account was deleted.');
|
||||
$type = $account->accountType->type;
|
||||
|
||||
/** @var \FireflyIII\Database\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account');
|
||||
|
||||
/** @var \FireflyIII\Database\TransactionJournal $jrnls */
|
||||
$jrnls = App::make('FireflyIII\Database\TransactionJournal');
|
||||
|
||||
/*
|
||||
* Find the "initial balance account", should it exist:
|
||||
*/
|
||||
$initialBalance = $acct->findInitialBalanceAccount($account);
|
||||
|
||||
/*
|
||||
* Get all the transaction journals that are part of this/these account(s):
|
||||
*/
|
||||
$journals = [];
|
||||
if ($initialBalance) {
|
||||
$transactions = $initialBalance->transactions()->get();
|
||||
/** @var \Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$journals[] = $transaction->transaction_journal_id;
|
||||
}
|
||||
}
|
||||
/** @var \Transaction $transaction */
|
||||
foreach ($account->transactions() as $transaction) {
|
||||
$journals[] = $transaction->transaction_journal_id;
|
||||
}
|
||||
|
||||
$journals = array_unique($journals);
|
||||
|
||||
/*
|
||||
* Delete the journals. Should get rid of the transactions as well.
|
||||
*/
|
||||
foreach ($journals as $id) {
|
||||
$journal = $jrnls->find($id);
|
||||
$journal->delete();
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete it
|
||||
*/
|
||||
if ($initialBalance) {
|
||||
$acct->destroy($initialBalance);
|
||||
}
|
||||
|
||||
$acct->destroy($account);
|
||||
|
||||
Session::flash('success', 'The account was deleted.');
|
||||
switch ($type) {
|
||||
case 'Asset account':
|
||||
case 'Default account':
|
||||
return Redirect::route('accounts.index', 'asset');
|
||||
break;
|
||||
case 'Expense account':
|
||||
case 'Beneficiary account':
|
||||
return Redirect::route('accounts.index', 'expense');
|
||||
break;
|
||||
case 'Revenue account':
|
||||
return Redirect::route('accounts.index', 'revenue');
|
||||
break;
|
||||
}
|
||||
|
||||
return Redirect::route('accounts.index');
|
||||
|
||||
}
|
||||
|
||||
@@ -65,32 +225,38 @@ class AccountController extends \BaseController
|
||||
*/
|
||||
public function edit(Account $account)
|
||||
{
|
||||
$openingBalance = $this->_accounts->openingBalanceTransaction($account);
|
||||
return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance)->with('title','Edit account "'.$account->name.'"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$accounts = $this->_repository->get();
|
||||
$set = [
|
||||
'personal' => [],
|
||||
'beneficiaries' => []
|
||||
];
|
||||
foreach ($accounts as $account) {
|
||||
switch ($account->accounttype->type) {
|
||||
switch ($account->accountType->type) {
|
||||
case 'Asset account':
|
||||
case 'Default account':
|
||||
$set['personal'][] = $account;
|
||||
View::share('subTitleIcon', 'fa-money');
|
||||
break;
|
||||
case 'Expense account':
|
||||
case 'Beneficiary account':
|
||||
$set['beneficiaries'][] = $account;
|
||||
View::share('subTitleIcon', 'fa-shopping-cart');
|
||||
break;
|
||||
case 'Revenue account':
|
||||
View::share('subTitleIcon', 'fa-download');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return View::make('accounts.index')->with('accounts', $set)->with('title','All your accounts');
|
||||
/** @var \FireflyIII\Database\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account');
|
||||
|
||||
$openingBalance = $acct->openingBalanceTransaction($account);
|
||||
Session::forget('prefilled');
|
||||
if (!is_null($openingBalance)) {
|
||||
$prefilled['openingbalancedate'] = $openingBalance->date->format('Y-m-d');
|
||||
$prefilled['openingbalance'] = floatval($openingBalance->transactions()->where('account_id', $account->id)->first()->amount);
|
||||
Session::flash('prefilled', $prefilled);
|
||||
}
|
||||
|
||||
|
||||
return View::make('accounts.edit')->with('account', $account)->with('openingBalance', $openingBalance)->with(
|
||||
'subTitle', 'Edit ' . strtolower(
|
||||
$account->accountType->type
|
||||
) . ' "' . $account->name . '"'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,53 +266,131 @@ class AccountController extends \BaseController
|
||||
*/
|
||||
public function show(Account $account)
|
||||
{
|
||||
$data = $this->_accounts->show($account, 40);
|
||||
switch ($account->accountType->type) {
|
||||
case 'Asset account':
|
||||
case 'Default account':
|
||||
View::share('subTitleIcon', 'fa-money');
|
||||
break;
|
||||
case 'Expense account':
|
||||
case 'Beneficiary account':
|
||||
View::share('subTitleIcon', 'fa-shopping-cart');
|
||||
break;
|
||||
case 'Revenue account':
|
||||
View::share('subTitleIcon', 'fa-download');
|
||||
break;
|
||||
}
|
||||
|
||||
return View::make('accounts.show')->with('account', $account)->with('show', $data)->with('title',
|
||||
'Details for account "' . $account->name . '"');
|
||||
|
||||
//$data = $this->_accounts->show($account, 40);
|
||||
return View::make('accounts.show')
|
||||
->with('account', $account)
|
||||
->with('subTitle', 'Details for ' . strtolower($account->accountType->type) . ' "' . $account->name . '"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
|
||||
$account = $this->_repository->store(Input::all());
|
||||
$data = Input::all();
|
||||
$data['what'] = isset($data['what']) && $data['what'] != '' ? $data['what'] : 'asset';
|
||||
/** @var \FireflyIII\Database\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account');
|
||||
|
||||
if ($account->validate()) {
|
||||
// saved! return to wherever.
|
||||
Session::flash('success', 'Account "' . $account->name . '" created!');
|
||||
if (intval(Input::get('create')) === 1) {
|
||||
return Redirect::route('accounts.create')->withInput();
|
||||
} else {
|
||||
return Redirect::route('accounts.index');
|
||||
switch ($data['post_submit_action']) {
|
||||
default:
|
||||
throw new FireflyException('Cannot handle post_submit_action "' . e($data['post_submit_action']) . '"');
|
||||
break;
|
||||
case 'create_another':
|
||||
case 'store':
|
||||
$messages = $acct->validate($data);
|
||||
/** @var MessageBag $messages ['errors'] */
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('error', 'Could not save account: ' . $messages['errors']->first());
|
||||
return Redirect::route('accounts.create', $data['what'])->withInput()->withErrors($messages['errors']);
|
||||
}
|
||||
// store!
|
||||
$acct->store($data);
|
||||
Session::flash('success', 'New account stored!');
|
||||
|
||||
if ($data['post_submit_action'] == 'create_another') {
|
||||
return Redirect::route('accounts.create', $data['what']);
|
||||
} else {
|
||||
// did not save, return with error:
|
||||
Session::flash('error', 'Could not save the new account: ' . $account->errors()->first());
|
||||
|
||||
return Redirect::route('accounts.create')->withErrors($account->errors())->withInput();
|
||||
|
||||
return Redirect::route('accounts.index', $data['what']);
|
||||
}
|
||||
break;
|
||||
case 'validate_only':
|
||||
$messageBags = $acct->validate($data);
|
||||
Session::flash('warnings', $messageBags['warnings']);
|
||||
Session::flash('successes', $messageBags['successes']);
|
||||
Session::flash('errors', $messageBags['errors']);
|
||||
return Redirect::route('accounts.create', $data['what'])->withInput();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
* @return $this
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(Account $account)
|
||||
{
|
||||
$account = $this->_repository->update($account, Input::all());
|
||||
if ($account->validate()) {
|
||||
Session::flash('success', 'Account "' . $account->name . '" updated.');
|
||||
|
||||
return Redirect::route('accounts.index');
|
||||
/** @var \FireflyIII\Database\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account');
|
||||
$data = Input::except('_token');
|
||||
|
||||
switch ($account->accountType->type) {
|
||||
default:
|
||||
throw new FireflyException('Cannot handle account type "' . e($account->accountType->type) . '"');
|
||||
break;
|
||||
case 'Default account':
|
||||
$data['what'] = 'asset';
|
||||
break;
|
||||
case 'Beneficiary account':
|
||||
$data['what'] = 'expense';
|
||||
break;
|
||||
case 'Revenue account':
|
||||
$data['what'] = 'revenue';
|
||||
break;
|
||||
}
|
||||
|
||||
switch (Input::get('post_submit_action')) {
|
||||
default:
|
||||
throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"');
|
||||
break;
|
||||
case 'create_another':
|
||||
case 'update':
|
||||
$messages = $acct->validate($data);
|
||||
/** @var MessageBag $messages ['errors'] */
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('error', 'Could not save account: ' . $messages['errors']->first());
|
||||
return Redirect::route('accounts.edit', $account->id)->withInput()->withErrors($messages['errors']);
|
||||
}
|
||||
// store!
|
||||
$acct->update($account, $data);
|
||||
Session::flash('success', 'Account updated!');
|
||||
|
||||
if ($data['post_submit_action'] == 'create_another') {
|
||||
return Redirect::route('accounts.edit', $account->id);
|
||||
} else {
|
||||
Session::flash('error', 'Could not update account: ' . $account->errors()->first());
|
||||
|
||||
return Redirect::route('accounts.edit', $account->id)->withInput()->withErrors($account->errors());
|
||||
return Redirect::route('accounts.index',$data['what']);
|
||||
}
|
||||
case 'validate_only':
|
||||
$messageBags = $acct->validate($data);
|
||||
Session::flash('warnings', $messageBags['warnings']);
|
||||
Session::flash('successes', $messageBags['successes']);
|
||||
Session::flash('errors', $messageBags['errors']);
|
||||
return Redirect::route('accounts.edit', $account->id)->withInput();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
/**
|
||||
* Class BaseController
|
||||
*/
|
||||
@@ -11,8 +13,6 @@ class BaseController extends Controller
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
\Event::fire('limits.check');
|
||||
\Event::fire('piggybanks.check');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Firefly\Exception\FireflyException;
|
||||
use Firefly\Helper\Controllers\BudgetInterface as BI;
|
||||
use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
|
||||
/**
|
||||
* Class BudgetController
|
||||
@@ -10,27 +14,165 @@ use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
|
||||
class BudgetController extends BaseController
|
||||
{
|
||||
|
||||
protected $_budgets;
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* @param BI $budgets
|
||||
* @param BRI $repository
|
||||
*/
|
||||
public function __construct(BI $budgets, BRI $repository)
|
||||
public function __construct()
|
||||
{
|
||||
$this->_budgets = $budgets;
|
||||
$this->_repository = $repository;
|
||||
View::share('title', 'Budgets');
|
||||
View::share('mainTitleIcon', 'fa-tasks');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\View\View
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postUpdateIncome()
|
||||
{
|
||||
/** @var \Firefly\Helper\Preferences\PreferencesHelperInterface $preferences */
|
||||
$preferences = App::make('Firefly\Helper\Preferences\PreferencesHelperInterface');
|
||||
$date = Session::get('start');
|
||||
|
||||
$value = intval(Input::get('amount'));
|
||||
$preferences->set('budgetIncomeTotal' . $date->format('FY'), $value);
|
||||
return Redirect::route('budgets.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the amount for a budget's limitrepetition and/or create it.
|
||||
*
|
||||
* @param Budget $budget
|
||||
*/
|
||||
public function amount(Budget $budget)
|
||||
{
|
||||
$amount = intval(Input::get('amount'));
|
||||
$date = Session::get('start');
|
||||
/** @var \Limit $limit */
|
||||
$limit = $budget->limits()->where('startdate', $date->format('Y-m-d'))->first();
|
||||
if (!$limit) {
|
||||
// create one!
|
||||
$limit = new Limit;
|
||||
$limit->budget()->associate($budget);
|
||||
$limit->startdate = $date;
|
||||
$limit->amount = $amount;
|
||||
$limit->repeat_freq = 'monthly';
|
||||
$limit->repeats = 0;
|
||||
$limit->save();
|
||||
Event::fire('limits.store', [$limit]);
|
||||
|
||||
} else {
|
||||
if ($amount > 0) {
|
||||
$limit->amount = $amount;
|
||||
$limit->save();
|
||||
Event::fire('limits.update', [$limit]);
|
||||
} else {
|
||||
$limit->delete();
|
||||
}
|
||||
}
|
||||
// try to find the limit repetition for this limit:
|
||||
$repetition = $limit->limitrepetitions()->first();
|
||||
if ($repetition) {
|
||||
return Response::json(['name' => $budget->name, 'repetition' => $repetition->id]);
|
||||
} else {
|
||||
return Response::json(['name' => $budget->name, 'repetition' => null]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
/** @var \Firefly\Helper\Preferences\PreferencesHelperInterface $preferences */
|
||||
$preferences = App::make('Firefly\Helper\Preferences\PreferencesHelperInterface');
|
||||
$date = Session::get('start');
|
||||
|
||||
/** @var \FireflyIII\Database\Budget $repos */
|
||||
$repos = App::make('FireflyIII\Database\Budget');
|
||||
$budgets = $repos->get();
|
||||
|
||||
// get the limits for the current month.
|
||||
$date = \Session::get('start');
|
||||
$spent = 0;
|
||||
/** @var \Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
|
||||
$budget->spent = $repos->spentInMonth($budget, $date);
|
||||
$spent += $budget->spent;
|
||||
$budget->pct = 0;
|
||||
$budget->limit = 0;
|
||||
|
||||
/** @var \Limit $limit */
|
||||
foreach ($budget->limits as $limit) {
|
||||
/** @var \LimitRepetition $repetition */
|
||||
foreach ($limit->limitrepetitions as $repetition) {
|
||||
if ($repetition->startdate == $date) {
|
||||
$budget->currentRep = $repetition;
|
||||
$budget->limit = floatval($repetition->amount);
|
||||
if ($budget->limit > $budget->spent) {
|
||||
// not overspent:
|
||||
$budget->pct = 30;
|
||||
} else {
|
||||
$budget->pct = 50;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$budgetAmount = $preferences->get('budgetIncomeTotal' . $date->format('FY'), 1000);
|
||||
$amount = floatval($budgetAmount->data);
|
||||
$overspent = $spent > $amount;
|
||||
if($overspent) {
|
||||
// overspent on total amount
|
||||
$spentPCT = ceil($amount / $spent * 100);
|
||||
} else {
|
||||
// not overspent on total amount.
|
||||
$spentPCT = ceil($spent / $amount * 100);
|
||||
}
|
||||
|
||||
return View::make('budgets.index', compact('budgets','spent','spentPCT','overspent'))->with('budgetAmount', $budgetAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function updateIncome()
|
||||
{
|
||||
$date = Session::get('start');
|
||||
/** @var \Firefly\Helper\Preferences\PreferencesHelperInterface $preferences */
|
||||
$preferences = App::make('Firefly\Helper\Preferences\PreferencesHelperInterface');
|
||||
$budgetAmount = $preferences->get('budgetIncomeTotal' . $date->format('FY'), 1000);
|
||||
return View::make('budgets.income')->with('amount', $budgetAmount)->with('date', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param LimitRepetition $repetition
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function show(Budget $budget, LimitRepetition $repetition = null)
|
||||
{
|
||||
if (!is_null($repetition) && $repetition->limit->budget->id != $budget->id) {
|
||||
App::abort(500);
|
||||
}
|
||||
|
||||
if (is_null($repetition)) {
|
||||
// get all other repetitions:
|
||||
$limits = $budget->limits()->orderBy('startdate', 'DESC')->get();
|
||||
|
||||
} else {
|
||||
// get nothing? i dunno
|
||||
$limits = [$repetition->limit];
|
||||
}
|
||||
|
||||
return View::make('budgets.show', compact('limits', 'budget', 'repetition'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$periods = \Config::get('firefly.periods_to_text');
|
||||
|
||||
return View::make('budgets.create')->with('periods', $periods);
|
||||
return View::make('budgets.create')->with('subTitle', 'Create a new budget');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,29 +182,16 @@ class BudgetController extends BaseController
|
||||
*/
|
||||
public function delete(Budget $budget)
|
||||
{
|
||||
return View::make('budgets.delete')->with('budget', $budget);
|
||||
return View::make('budgets.delete')->with('budget', $budget)->with('subTitle', 'Delete budget "' . $budget->name . '"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Budget $budget)
|
||||
{
|
||||
Event::fire('budgets.destroy', [$budget]); // just before deletion.
|
||||
$result = $this->_repository->destroy($budget);
|
||||
if ($result === true) {
|
||||
/** @var \FireflyIII\Database\Budget $repos */
|
||||
$repos = App::make('FireflyIII\Database\Budget');
|
||||
// remove budget
|
||||
$repos->destroy($budget);
|
||||
Session::flash('success', 'The budget was deleted.');
|
||||
if (Input::get('from') == 'date') {
|
||||
return Redirect::route('budgets.index');
|
||||
} else {
|
||||
return Redirect::route('budgets.index.budget');
|
||||
}
|
||||
} else {
|
||||
Session::flash('error', 'Could not delete the budget. Check the logs to be sure.');
|
||||
}
|
||||
|
||||
return Redirect::route('budgets.index');
|
||||
|
||||
}
|
||||
@@ -74,126 +203,96 @@ class BudgetController extends BaseController
|
||||
*/
|
||||
public function edit(Budget $budget)
|
||||
{
|
||||
return View::make('budgets.edit')->with('budget', $budget);
|
||||
Session::flash('prefilled', ['name' => $budget->name]);
|
||||
return View::make('budgets.edit')->with('budget', $budget)->with('subTitle', 'Edit budget "' . $budget->name . '"');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\View\View
|
||||
*/
|
||||
public function indexByBudget()
|
||||
{
|
||||
$budgets = $this->_repository->get();
|
||||
$today = new Carbon;
|
||||
|
||||
|
||||
return View::make('budgets.indexByBudget')->with('budgets', $budgets)->with('today', $today);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\View\View
|
||||
* @throws Firefly\Exception\FireflyException
|
||||
*/
|
||||
public function indexByDate()
|
||||
{
|
||||
// get a list of dates by getting all repetitions:
|
||||
$set = $this->_repository->get();
|
||||
$budgets = $this->_budgets->organizeByDate($set);
|
||||
|
||||
|
||||
return View::make('budgets.indexByDate')->with('budgets', $budgets);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function show(Budget $budget)
|
||||
{
|
||||
/**
|
||||
* Use the
|
||||
*/
|
||||
$useSessionDates = Input::get('useSession') == 'true' ? true : false;
|
||||
|
||||
|
||||
$filters = [];
|
||||
|
||||
if (!is_null(Input::get('rep'))) {
|
||||
$repetitionId = intval(Input::get('rep'));
|
||||
$repetitions = $this->_budgets->organizeRepetition($repetitionId);
|
||||
$filters[] = $repetitions[0]['limit'];
|
||||
$filters[] = $repetitions[0]['limitrepetition'];
|
||||
} else {
|
||||
if (Input::get('noenvelope') == 'true') {
|
||||
$repetitions = $this->_budgets->outsideRepetitions($budget);
|
||||
$filters[] = 'no_envelope';
|
||||
} else {
|
||||
// grab all limit repetitions, order them, show them:
|
||||
$repetitions = $this->_budgets->organizeRepetitions($budget, $useSessionDates);
|
||||
}
|
||||
}
|
||||
|
||||
return View::make('budgets.show')->with('budget', $budget)->with('repetitions', $repetitions)->with(
|
||||
'filters', $filters
|
||||
)->with('highlight', Input::get('highlight'))->with('useSessionDates', $useSessionDates);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
/** @var \FireflyIII\Database\Budget $repos */
|
||||
$repos = App::make('FireflyIII\Database\Budget');
|
||||
$data = Input::except('_token');
|
||||
|
||||
$budget = $this->_repository->store(Input::all());
|
||||
if ($budget->validate()) {
|
||||
Event::fire('budgets.store', [$budget]);
|
||||
Session::flash('success', 'Budget created!');
|
||||
|
||||
if (Input::get('create') == '1') {
|
||||
return Redirect::route('budgets.create', ['from' => Input::get('from')]);
|
||||
switch ($data['post_submit_action']) {
|
||||
default:
|
||||
throw new FireflyException('Cannot handle post_submit_action "' . e($data['post_submit_action']) . '"');
|
||||
break;
|
||||
case 'create_another':
|
||||
case 'store':
|
||||
$messages = $repos->validate($data);
|
||||
/** @var MessageBag $messages ['errors'] */
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('error', 'Could not save budget: ' . $messages['errors']->first());
|
||||
return Redirect::route('budgets.create')->withInput()->withErrors($messages['errors']);
|
||||
}
|
||||
// store!
|
||||
$repos->store($data);
|
||||
Session::flash('success', 'New budget stored!');
|
||||
|
||||
if (Input::get('from') == 'date') {
|
||||
if ($data['post_submit_action'] == 'create_another') {
|
||||
return Redirect::route('budgets.create');
|
||||
} else {
|
||||
return Redirect::route('budgets.index');
|
||||
} else {
|
||||
return Redirect::route('budgets.index.budget');
|
||||
}
|
||||
} else {
|
||||
Session::flash('error', 'Could not save the new budget');
|
||||
|
||||
return Redirect::route('budgets.create')->withInput()->withErrors($budget->errors());
|
||||
break;
|
||||
case 'validate_only':
|
||||
$messageBags = $repos->validate($data);
|
||||
Session::flash('warnings', $messageBags['warnings']);
|
||||
Session::flash('successes', $messageBags['successes']);
|
||||
Session::flash('errors', $messageBags['errors']);
|
||||
return Redirect::route('budgets.create')->withInput();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(Budget $budget)
|
||||
{
|
||||
$budget = $this->_repository->update($budget, Input::all());
|
||||
if ($budget->validate()) {
|
||||
Event::fire('budgets.update', [$budget]);
|
||||
Session::flash('success', 'Budget "' . $budget->name . '" updated.');
|
||||
|
||||
if (Input::get('from') == 'date') {
|
||||
/** @var \FireflyIII\Database\Budget $repos */
|
||||
$repos = App::make('FireflyIII\Database\Budget');
|
||||
$data = Input::except('_token');
|
||||
|
||||
switch (Input::get('post_submit_action')) {
|
||||
default:
|
||||
throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"');
|
||||
break;
|
||||
case 'create_another':
|
||||
case 'update':
|
||||
$messages = $repos->validate($data);
|
||||
/** @var MessageBag $messages ['errors'] */
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('error', 'Could not save budget: ' . $messages['errors']->first());
|
||||
return Redirect::route('budgets.edit', $budget->id)->withInput()->withErrors($messages['errors']);
|
||||
}
|
||||
// store!
|
||||
$repos->update($budget, $data);
|
||||
Session::flash('success', 'Budget updated!');
|
||||
|
||||
if ($data['post_submit_action'] == 'create_another') {
|
||||
return Redirect::route('budgets.edit', $budget->id);
|
||||
} else {
|
||||
return Redirect::route('budgets.index');
|
||||
} else {
|
||||
return Redirect::route('budgets.index.budget');
|
||||
}
|
||||
} else {
|
||||
Session::flash('error', 'Could not update budget: ' . $budget->errors()->first());
|
||||
|
||||
return Redirect::route('budgets.edit', $budget->id)->withInput()->withErrors($budget->errors());
|
||||
case 'validate_only':
|
||||
$messageBags = $repos->validate($data);
|
||||
Session::flash('warnings', $messageBags['warnings']);
|
||||
Session::flash('successes', $messageBags['successes']);
|
||||
Session::flash('errors', $messageBags['errors']);
|
||||
return Redirect::route('budgets.edit', $budget->id)->withInput();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,6 +5,8 @@ use Firefly\Storage\Category\CategoryRepositoryInterface as CRI;
|
||||
|
||||
/**
|
||||
* Class CategoryController
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class CategoryController extends BaseController
|
||||
{
|
||||
@@ -19,6 +21,8 @@ class CategoryController extends BaseController
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
$this->_category = $category;
|
||||
View::share('title','Categories');
|
||||
View::share('mainTitleIcon', 'fa-bar-chart');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,7 +30,7 @@ class CategoryController extends BaseController
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return View::make('categories.create');
|
||||
return View::make('categories.create')->with('subTitle', 'Create a new category');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +40,8 @@ class CategoryController extends BaseController
|
||||
*/
|
||||
public function delete(Category $category)
|
||||
{
|
||||
return View::make('categories.delete')->with('category', $category);
|
||||
return View::make('categories.delete')->with('category', $category)
|
||||
->with('subTitle', 'Delete category "' . $category->name . '"');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,13 +51,8 @@ class CategoryController extends BaseController
|
||||
*/
|
||||
public function destroy(Category $category)
|
||||
{
|
||||
$result = $this->_repository->destroy($category);
|
||||
if ($result === true) {
|
||||
$this->_repository->destroy($category);
|
||||
Session::flash('success', 'The category was deleted.');
|
||||
} else {
|
||||
Session::flash('error', 'Could not delete the category. Check the logs to be sure.');
|
||||
}
|
||||
|
||||
return Redirect::route('categories.index');
|
||||
}
|
||||
|
||||
@@ -63,7 +63,8 @@ class CategoryController extends BaseController
|
||||
*/
|
||||
public function edit(Category $category)
|
||||
{
|
||||
return View::make('categories.edit')->with('category', $category);
|
||||
return View::make('categories.edit')->with('category', $category)
|
||||
->with('subTitle', 'Edit category "' . $category->name . '"');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +74,8 @@ class CategoryController extends BaseController
|
||||
{
|
||||
$categories = $this->_repository->get();
|
||||
|
||||
return View::make('categories.index')->with('categories', $categories);
|
||||
return View::make('categories.index')->with('categories', $categories)
|
||||
->with('subTitle', 'All your categories');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +93,7 @@ class CategoryController extends BaseController
|
||||
|
||||
return View::make('categories.show')->with('category', $category)->with('journals', $journals)->with(
|
||||
'highlight', Input::get('highlight')
|
||||
);
|
||||
)->with('subTitle', 'Overview for category "' . $category->name . '"');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Firefly\Exception\FireflyException;
|
||||
use Firefly\Helper\Controllers\ChartInterface;
|
||||
use Firefly\Storage\Account\AccountRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class ChartController
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class ChartController extends BaseController
|
||||
{
|
||||
@@ -25,35 +30,28 @@ class ChartController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* This method takes a budget, all limits and all their repetitions and displays three numbers per repetition:
|
||||
* the amount of money in the repetition (represented as "an envelope"), the amount spent and the spent percentage.
|
||||
*
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function budgetDefault(\Budget $budget)
|
||||
{
|
||||
$expense = [];
|
||||
$left = [];
|
||||
$envelope = [];
|
||||
// get all limit repetitions for this budget.
|
||||
/** @var \Limit $limit */
|
||||
foreach ($budget->limits as $limit) {
|
||||
/** @var \LimitRepetition $rep */
|
||||
foreach ($limit->limitrepetitions as $rep) {
|
||||
$spentInRep = \Transaction::
|
||||
leftJoin(
|
||||
'transaction_journals', 'transaction_journals.id', '=',
|
||||
'transactions.transaction_journal_id'
|
||||
)
|
||||
->leftJoin(
|
||||
'component_transaction_journal', 'component_transaction_journal.transaction_journal_id',
|
||||
'=',
|
||||
'transaction_journals.id'
|
||||
)->where('component_transaction_journal.component_id', '=', $budget->id)->where(
|
||||
'transaction_journals.date', '>=', $rep->startdate->format('Y-m-d')
|
||||
)->where('transaction_journals.date', '<=', $rep->enddate->format('Y-m-d'))->where(
|
||||
'amount', '>', 0
|
||||
)->sum('amount');
|
||||
|
||||
|
||||
$pct = round(($spentInRep / $limit->amount) * 100, 2);
|
||||
// get the amount of money spent in this period on this budget.
|
||||
$spentInRep = $rep->amount - $rep->leftInRepetition();
|
||||
$pct = round((floatval($spentInRep) / floatval($limit->amount)) * 100, 2);
|
||||
$name = $rep->periodShow();
|
||||
$envelope[] = [$name, floatval($limit->amount)];
|
||||
$expense[] = [$name, floatval($spentInRep)];
|
||||
$left[] = [$name, $pct];
|
||||
}
|
||||
@@ -63,6 +61,12 @@ class ChartController extends BaseController
|
||||
'chart_title' => 'Overview for budget ' . $budget->name,
|
||||
'subtitle' => 'All envelopes',
|
||||
'series' => [
|
||||
[
|
||||
'type' => 'line',
|
||||
'yAxis' => 1,
|
||||
'name' => 'Amount in envelope',
|
||||
'data' => $envelope
|
||||
],
|
||||
[
|
||||
'type' => 'column',
|
||||
'name' => 'Expenses in envelope',
|
||||
@@ -75,6 +79,7 @@ class ChartController extends BaseController
|
||||
'data' => $left
|
||||
]
|
||||
|
||||
|
||||
]
|
||||
];
|
||||
|
||||
@@ -82,7 +87,12 @@ class ChartController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* This method takes a single limit repetition (so a single "envelope") and displays the amount of money spent
|
||||
* per day and subsequently how much money is left.
|
||||
*
|
||||
* @param LimitRepetition $rep
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function budgetLimit(\LimitRepetition $rep)
|
||||
{
|
||||
@@ -92,14 +102,7 @@ class ChartController extends BaseController
|
||||
$leftInLimit = [];
|
||||
$currentLeftInLimit = floatval($rep->limit->amount);
|
||||
while ($current <= $rep->enddate) {
|
||||
$spent = \Transaction::
|
||||
leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin(
|
||||
'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=',
|
||||
'transaction_journals.id'
|
||||
)->where('component_transaction_journal.component_id', '=', $budget->id)->where(
|
||||
'transaction_journals.date', $current->format('Y-m-d')
|
||||
)->where('amount', '>', 0)->sum('amount');
|
||||
$spent = $this->_chart->spentOnDay($budget, $current);
|
||||
$spent = floatval($spent) == 0 ? null : floatval($spent);
|
||||
$entry = [$current->timestamp * 1000, $spent];
|
||||
$expense[] = $entry;
|
||||
@@ -132,49 +135,40 @@ class ChartController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* This method takes a budget and gets all transactions in it which haven't got an envelope (limit).
|
||||
*
|
||||
* Usually this means that very old and unorganized or very NEW transactions get displayed; there was never an
|
||||
* envelope or it hasn't been created (yet).
|
||||
*
|
||||
*
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function budgetNoLimits(\Budget $budget)
|
||||
{
|
||||
$inRepetitions = [];
|
||||
foreach ($budget->limits as $limit) {
|
||||
foreach ($limit->limitrepetitions as $repetition) {
|
||||
$set = $budget->transactionjournals()->leftJoin(
|
||||
'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'
|
||||
)->where('transaction_types.type', 'Withdrawal')->where(
|
||||
'date', '>=', $repetition->startdate->format('Y-m-d')
|
||||
)->where('date', '<=', $repetition->enddate->format('Y-m-d'))->orderBy('date', 'DESC')->get(
|
||||
['transaction_journals.id']
|
||||
);
|
||||
foreach ($set as $item) {
|
||||
$inRepetitions[] = $item->id;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Firefly can go about this two ways. Either it finds all transactions which definitely are IN an envelope
|
||||
* and exclude them or it searches for transactions outside of the range of any of the envelopes there are.
|
||||
*
|
||||
* Since either is kinda shitty Firefly uses the first one because it's easier to build.
|
||||
*/
|
||||
$inRepetitions = $this->_chart->allJournalsInBudgetEnvelope($budget);
|
||||
|
||||
}
|
||||
|
||||
$query = $budget->transactionjournals()->whereNotIn(
|
||||
'transaction_journals.id', $inRepetitions
|
||||
)->orderBy('date', 'DESC')->orderBy(
|
||||
'transaction_journals.id', 'DESC'
|
||||
);
|
||||
/*
|
||||
* With this set of id's, Firefly can search for all journals NOT in that set.
|
||||
* BUT they have to be in the budget (duh).
|
||||
*/
|
||||
$set = $this->_chart->journalsNotInSet($budget, $inRepetitions);
|
||||
/*
|
||||
* Next step: get all transactions for those journals.
|
||||
*/
|
||||
$transactions = $this->_chart->transactionsByJournals($set);
|
||||
|
||||
|
||||
$result = $query->get(['transaction_journals.id']);
|
||||
$set = [];
|
||||
foreach ($result as $entry) {
|
||||
$set[] = $entry->id;
|
||||
}
|
||||
// all transactions for these journals, grouped by date and SUM
|
||||
$transactions = \Transaction::whereIn('transaction_journal_id', $set)->leftJoin(
|
||||
'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'
|
||||
)
|
||||
->groupBy('transaction_journals.date')->where('amount', '>', 0)->get(
|
||||
['transaction_journals.date', DB::Raw('SUM(`amount`) as `aggregate`')]
|
||||
);
|
||||
|
||||
|
||||
// this set builds the chart:
|
||||
/*
|
||||
* this set builds the chart:
|
||||
*/
|
||||
$expense = [];
|
||||
|
||||
foreach ($transactions as $t) {
|
||||
@@ -186,126 +180,104 @@ class ChartController extends BaseController
|
||||
'subtitle' => 'Not organized by an envelope',
|
||||
'series' => [
|
||||
[
|
||||
'type' => 'spline',
|
||||
'type' => 'column',
|
||||
'name' => 'Expenses per day',
|
||||
'data' => $expense
|
||||
]
|
||||
|
||||
]
|
||||
];
|
||||
|
||||
return Response::json($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets all transactions within a budget within the period set by the current session
|
||||
* start and end date. It also includes any envelopes which might exist within this period.
|
||||
*
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function budgetSession(\Budget $budget)
|
||||
{
|
||||
$expense = [];
|
||||
$repetitionSeries = [];
|
||||
$current = clone Session::get('start');
|
||||
$series = [];
|
||||
$end = clone Session::get('end');
|
||||
while ($current <= $end) {
|
||||
$spent = \Transaction::
|
||||
leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin(
|
||||
'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=',
|
||||
'transaction_journals.id'
|
||||
)->where('component_transaction_journal.component_id', '=', $budget->id)->where(
|
||||
'transaction_journals.date', $current->format('Y-m-d')
|
||||
)->where('amount', '>', 0)->sum('amount');
|
||||
$spent = floatval($spent) == 0 ? null : floatval($spent);
|
||||
if (!is_null($spent)) {
|
||||
$expense[] = [$current->timestamp * 1000, $spent];
|
||||
}
|
||||
$start = clone Session::get('start');
|
||||
|
||||
|
||||
/*
|
||||
* Expenses per day in the session's period. That's easy.
|
||||
*/
|
||||
$expense = [];
|
||||
$current = clone Session::get('start');
|
||||
while ($current <= $end) {
|
||||
$spent = $this->_chart->spentOnDay($budget, $current);
|
||||
$spent = floatval($spent) == 0 ? null : floatval($spent);
|
||||
$expense[] = [$current->timestamp * 1000, $spent];
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
// find all limit repetitions (for this budget) between start and end.
|
||||
$start = clone Session::get('start');
|
||||
$repetitionSeries[] = [
|
||||
$series[] = [
|
||||
'type' => 'column',
|
||||
'name' => 'Expenses per day',
|
||||
'data' => $expense
|
||||
];
|
||||
unset($expense, $spent, $current);
|
||||
|
||||
/*
|
||||
* Find all limit repetitions (for this budget) between start and end. This is
|
||||
* quite a complex query.
|
||||
*/
|
||||
$reps = $this->_chart->limitsInRange($budget, $start, $end);
|
||||
|
||||
/** @var \Limit $limit */
|
||||
foreach ($budget->limits as $limit) {
|
||||
$reps = $limit->limitrepetitions()->where(
|
||||
function ($q) use ($start, $end) {
|
||||
// startdate is between range
|
||||
$q->where(
|
||||
function ($q) use ($start, $end) {
|
||||
$q->where('startdate', '>=', $start->format('Y-m-d'));
|
||||
$q->where('startdate', '<=', $end->format('Y-m-d'));
|
||||
}
|
||||
);
|
||||
|
||||
// or enddate is between range.
|
||||
$q->orWhere(
|
||||
function ($q) use ($start, $end) {
|
||||
$q->where('enddate', '>=', $start->format('Y-m-d'));
|
||||
$q->where('enddate', '<=', $end->format('Y-m-d'));
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
->get();
|
||||
$currentLeftInLimit = floatval($limit->amount);
|
||||
/*
|
||||
* For each limitrepetition Firefly creates a serie that contains the amount left in
|
||||
* the limitrepetition for its entire date-range. Entries are only actually included when they
|
||||
* fall into the charts date range.
|
||||
*
|
||||
* So example: the user has a session date from Jan 15 to Jan 30. The limitrepetition
|
||||
* starts at 1 Jan until 1 Feb.
|
||||
*
|
||||
* Firefly loops from 1 Jan to 1 Feb but only includes Jan 15 / Jan 30.
|
||||
* But it does keep count of the amount outside of these dates because otherwise the line might be wrong.
|
||||
*/
|
||||
/** @var \LimitRepetition $repetition */
|
||||
foreach ($reps as $repetition) {
|
||||
$limitAmount = $repetition->limit->amount;
|
||||
|
||||
// create a serie for the repetition.
|
||||
$currentSerie = [
|
||||
'type' => 'spline',
|
||||
'id' => 'rep-' . $repetition->id,
|
||||
'yAxis' => 1,
|
||||
'name' => 'Envelope in ' . $repetition->periodShow(),
|
||||
'name' => 'Envelope #' . $repetition->id . ' in ' . $repetition->periodShow(),
|
||||
'data' => []
|
||||
];
|
||||
$current = clone $repetition->startdate;
|
||||
while ($current <= $repetition->enddate) {
|
||||
if ($current >= Session::get('start') && $current <= Session::get('end')) {
|
||||
if ($current >= $start && $current <= $end) {
|
||||
// spent on limit:
|
||||
$spentSoFar = \Transaction::
|
||||
leftJoin(
|
||||
'transaction_journals', 'transaction_journals.id', '=',
|
||||
'transactions.transaction_journal_id'
|
||||
)
|
||||
->leftJoin(
|
||||
'component_transaction_journal', 'component_transaction_journal.transaction_journal_id',
|
||||
'=',
|
||||
'transaction_journals.id'
|
||||
)->where('component_transaction_journal.component_id', '=', $budget->id)->where(
|
||||
'transaction_journals.date', '>=', $repetition->startdate->format('Y-m-d')
|
||||
)->where('transaction_journals.date', '<=', $current->format('Y-m-d'))->where(
|
||||
'amount', '>', 0
|
||||
)->sum('amount');
|
||||
$spent = floatval($spent) == 0 ? null : floatval($spent);
|
||||
$currentLeftInLimit = floatval($limit->amount) - floatval($spentSoFar);
|
||||
$spentSoFar = $this->_chart->spentOnLimitRepetitionBetweenDates(
|
||||
$repetition, $repetition->startdate, $current
|
||||
);
|
||||
$leftInLimit = floatval($limitAmount) - floatval($spentSoFar);
|
||||
|
||||
$currentSerie['data'][] = [$current->timestamp * 1000, $currentLeftInLimit];
|
||||
$currentSerie['data'][] = [$current->timestamp * 1000, $leftInLimit];
|
||||
}
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
// do something here.
|
||||
$repetitionSeries[] = $currentSerie;
|
||||
|
||||
$series[] = $currentSerie;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$return = [
|
||||
'chart_title' => 'Overview for budget ' . $budget->name,
|
||||
'subtitle' =>
|
||||
'Between ' . Session::get('start')->format('M jS, Y') . ' and ' . Session::get('end')->format(
|
||||
'M jS, Y'
|
||||
),
|
||||
'series' => $repetitionSeries
|
||||
'series' => $series
|
||||
];
|
||||
|
||||
return Response::json($return);
|
||||
@@ -371,7 +343,6 @@ class ChartController extends BaseController
|
||||
];
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
\Log::debug('Now building series for ' . $account->name);
|
||||
$data['series'][] = $this->_chart->account($account, $start, $end);
|
||||
}
|
||||
|
||||
@@ -403,9 +374,102 @@ class ChartController extends BaseController
|
||||
*/
|
||||
public function homeBudgets()
|
||||
{
|
||||
$start = \Session::get('start');
|
||||
$start = Session::get('start');
|
||||
$end = Session::get('end');
|
||||
$data = [
|
||||
'labels' => [],
|
||||
'series' => [
|
||||
[
|
||||
'name' => 'Limit',
|
||||
'data' => []
|
||||
],
|
||||
[
|
||||
'name' => 'Spent',
|
||||
'data' => []
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// Get all budgets.
|
||||
$budgets = \Auth::user()->budgets()->orderBy('name', 'ASC')->get();
|
||||
$budgetIds = [];
|
||||
/** @var \Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
$budgetIds[] = $budget->id;
|
||||
|
||||
// Does the budget have a limit starting on $start?
|
||||
$rep = \LimitRepetition::
|
||||
leftJoin('limits', 'limit_repetitions.limit_id', '=', 'limits.id')->leftJoin(
|
||||
'components', 'limits.component_id', '=', 'components.id'
|
||||
)->where('limit_repetitions.startdate', $start->format('Y-m-d'))->where(
|
||||
'components.id', $budget->id
|
||||
)->first(['limit_repetitions.*']);
|
||||
|
||||
if (is_null($rep)) {
|
||||
$limit = 0.0;
|
||||
$id = null;
|
||||
$parameter = 'useSession=true';
|
||||
} else {
|
||||
$limit = floatval($rep->amount);
|
||||
$id = $rep->id;
|
||||
$parameter = '';
|
||||
}
|
||||
|
||||
// Date range to check for expenses made?
|
||||
if (is_null($rep)) {
|
||||
// use the session start and end for our search query
|
||||
$expenseStart = Session::get('start');
|
||||
$expenseEnd = Session::get('end');
|
||||
|
||||
} else {
|
||||
// use the limit's start and end for our search query
|
||||
$expenseStart = $rep->startdate;
|
||||
$expenseEnd = $rep->enddate;
|
||||
}
|
||||
// How much have we spent on this budget?
|
||||
$expenses = floatval($budget->transactionjournals()->before($expenseEnd)->after($expenseStart)->lessThan(0)->sum('amount')) * -1;
|
||||
|
||||
// Append to chart:
|
||||
if ($limit > 0 || $expenses > 0) {
|
||||
$data['labels'][] = $budget->name;
|
||||
$data['series'][0]['data'][] = [
|
||||
'y' => $limit,
|
||||
'url' => route('budgets.show', [$budget->id, $id]) . '?' . $parameter
|
||||
];
|
||||
$data['series'][1]['data'][] = [
|
||||
'y' => $expenses,
|
||||
'url' => route('budgets.show', [$budget->id, $id]) . '?' . $parameter
|
||||
];
|
||||
}
|
||||
}
|
||||
// Add expenses that have no budget:
|
||||
$set = \Auth::user()->transactionjournals()->whereNotIn(
|
||||
'transaction_journals.id', function ($query) use ($start, $end) {
|
||||
$query->select('transaction_journals.id')->from('transaction_journals')
|
||||
->leftJoin(
|
||||
'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=',
|
||||
'transaction_journals.id'
|
||||
)
|
||||
->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id')
|
||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
||||
->where('components.class', 'Budget');
|
||||
}
|
||||
)->before($end)->after($start)->lessThan(0)->transactionTypes(['Withdrawal'])->sum('amount');
|
||||
|
||||
// This can be debugged by using get(['transaction_journals.*','transactions.amount']);
|
||||
$data['labels'][] = 'No budget';
|
||||
$data['series'][0]['data'][] = [
|
||||
'y' => 0,
|
||||
'url' => route('budgets.nobudget', 'session')
|
||||
];
|
||||
$data['series'][1]['data'][] = [
|
||||
'y' => floatval($set) * -1,
|
||||
'url' => route('budgets.nobudget', 'session')
|
||||
];
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
return Response::json($this->_chart->budgets($start));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -420,4 +484,120 @@ class ChartController extends BaseController
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks all recurring transactions, calculates the current "moment" and returns
|
||||
* a list of yet to be paid (and paid) recurring transactions. This list can be used to show a beautiful chart
|
||||
* to the end user who will love it and cherish it.
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function homeRecurring()
|
||||
{
|
||||
/** @var \Firefly\Helper\Toolkit\ToolkitInterface $toolkit */
|
||||
$toolkit = App::make('Firefly\Helper\Toolkit\ToolkitInterface');
|
||||
|
||||
/*
|
||||
* Set of paid transaction journals.
|
||||
* Set of unpaid recurring transactions.
|
||||
*/
|
||||
$paid = [];
|
||||
$unpaid = [];
|
||||
|
||||
/*
|
||||
* Loop the recurring transactions.
|
||||
*/
|
||||
|
||||
/** @var \RecurringTransaction $recurring */
|
||||
foreach (\Auth::user()->recurringtransactions()->get() as $recurring) {
|
||||
/*
|
||||
* Start another loop starting at the $date.
|
||||
*/
|
||||
$start = clone $recurring->date;
|
||||
$end = Carbon::now();
|
||||
|
||||
/*
|
||||
* The jump we make depends on the $repeat_freq
|
||||
*/
|
||||
$current = clone $start;
|
||||
|
||||
while ($current <= $end) {
|
||||
/*
|
||||
* Get end of period for $current:
|
||||
*/
|
||||
$currentEnd = clone $current;
|
||||
$toolkit->endOfPeriod($currentEnd, $recurring->repeat_freq);
|
||||
|
||||
/*
|
||||
* In the current session range?
|
||||
*/
|
||||
if (\Session::get('end') >= $current and $currentEnd >= \Session::get('start')) {
|
||||
/*
|
||||
* Lets see if we've already spent money on this recurring transaction (it hath recurred).
|
||||
*/
|
||||
/** @var TransactionJournal $set */
|
||||
$transaction = \Auth::user()->transactionjournals()->where('recurring_transaction_id', $recurring->id)->after($current)->before($currentEnd)->first();
|
||||
|
||||
if(is_null($transaction)) {
|
||||
$unpaid[] = $recurring;
|
||||
} else {
|
||||
$paid[] = $transaction;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Add some time for the next loop!
|
||||
*/
|
||||
$toolkit->addPeriod($current, $recurring->repeat_freq, intval($recurring->skip));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Get some colors going.
|
||||
*/
|
||||
$unPaidColours = $toolkit->colorRange('AA4643', 'FFFFFF', count($unpaid) == 0 ? 1 : count($unpaid));
|
||||
$paidColours = $toolkit->colorRange('4572A7', 'FFFFFF', count($paid) == 0 ? 1 : count($paid));
|
||||
|
||||
/*
|
||||
* The chart serie:
|
||||
*/
|
||||
$serie = [
|
||||
'type' => 'pie',
|
||||
'name' => 'Amount',
|
||||
'data' => []
|
||||
];
|
||||
|
||||
/*
|
||||
* Loop paid and unpaid to make two haves for a pie chart.
|
||||
*/
|
||||
/** @var TransactionJournal $entry */
|
||||
foreach ($paid as $index => $entry) {
|
||||
$transactions = $entry->transactions()->get();
|
||||
$amount = max(floatval($transactions[0]->amount), floatval($transactions[1]->amount));
|
||||
$serie['data'][] = [
|
||||
'name' => 'Already paid "'.$entry->description.'"',
|
||||
'y' => $amount,
|
||||
'url' => route('transactions.show',$entry->id),
|
||||
'objType' => 'paid',
|
||||
'color' => $paidColours[$index]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var RecurringTransaction $entry */
|
||||
foreach ($unpaid as $index => $entry) {
|
||||
$amount = (floatval($entry->amount_max) + floatval($entry->amount_min)) / 2;
|
||||
$serie['data'][] = [
|
||||
'name' => 'Still due: '.$entry->name,
|
||||
'y' => $amount,
|
||||
'url' => route('recurring.show',$entry->id),
|
||||
'objType' => 'unpaid',
|
||||
'color' => $unPaidColours[$index]
|
||||
];
|
||||
}
|
||||
|
||||
return Response::json([$serie]);
|
||||
|
||||
}
|
||||
}
|
||||
600
app/controllers/GoogleChartController.php
Normal file
600
app/controllers/GoogleChartController.php
Normal file
@@ -0,0 +1,600 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class GoogleChartController
|
||||
*/
|
||||
class GoogleChartController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* This method renders the b
|
||||
*/
|
||||
public function allAccountsBalanceChart()
|
||||
{
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('Day of the month', 'date');
|
||||
|
||||
/** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
|
||||
$preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
|
||||
$pref = $preferences->get('frontpageAccounts');
|
||||
|
||||
/** @var \FireflyIII\Database\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account');
|
||||
$accounts = $acct->getByIds($pref->data);
|
||||
|
||||
|
||||
/*
|
||||
* Add a column for each account.
|
||||
*/
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$chart->addColumn('Balance for ' . $account->name, 'number');
|
||||
}
|
||||
/*
|
||||
* Loop the date, then loop the accounts, then add balance.
|
||||
*/
|
||||
$start = Session::get('start');
|
||||
$end = Session::get('end');
|
||||
$current = clone $start;
|
||||
|
||||
while ($end >= $current) {
|
||||
$row = [clone $current];
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
//if ($current > Carbon::now()) {
|
||||
// $row[] = 0;
|
||||
//} else {
|
||||
$row[] = $account->balance($current);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
$chart->addRowArray($row);
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $year
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function yearInExp($year)
|
||||
{
|
||||
try {
|
||||
$start = new Carbon('01-01-' . $year);
|
||||
} catch (Exception $e) {
|
||||
App::abort(500);
|
||||
}
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('Month', 'date');
|
||||
$chart->addColumn('Income', 'number');
|
||||
$chart->addColumn('Expenses', 'number');
|
||||
|
||||
/** @var \FireflyIII\Database\TransactionJournal $tj */
|
||||
$tj = App::make('FireflyIII\Database\TransactionJournal');
|
||||
|
||||
$end = clone $start;
|
||||
$end->endOfYear();
|
||||
while ($start < $end) {
|
||||
|
||||
// total income:
|
||||
$income = $tj->getSumOfIncomesByMonth($start);
|
||||
$expense = $tj->getSumOfExpensesByMonth($start);
|
||||
|
||||
$chart->addRow(clone $start, $income, $expense);
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $year
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function yearInExpSum($year)
|
||||
{
|
||||
try {
|
||||
$start = new Carbon('01-01-' . $year);
|
||||
} catch (Exception $e) {
|
||||
App::abort(500);
|
||||
}
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('Summary', 'string');
|
||||
$chart->addColumn('Income', 'number');
|
||||
$chart->addColumn('Expenses', 'number');
|
||||
|
||||
/** @var \FireflyIII\Database\TransactionJournal $tj */
|
||||
$tj = App::make('FireflyIII\Database\TransactionJournal');
|
||||
|
||||
$end = clone $start;
|
||||
$end->endOfYear();
|
||||
$income = 0;
|
||||
$expense = 0;
|
||||
$count = 0;
|
||||
while ($start < $end) {
|
||||
|
||||
// total income:
|
||||
$income += $tj->getSumOfIncomesByMonth($start);
|
||||
$expense += $tj->getSumOfExpensesByMonth($start);
|
||||
$count++;
|
||||
|
||||
$start->addMonth();
|
||||
}
|
||||
$chart->addRow('Sum', $income, $expense);
|
||||
$count = $count > 0 ? $count : 1;
|
||||
$chart->addRow('Average', ($income / $count), ($expense / $count));
|
||||
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function budgetsReportChart($year)
|
||||
{
|
||||
|
||||
try {
|
||||
$start = new Carbon('01-01-' . $year);
|
||||
} catch (Exception $e) {
|
||||
App::abort(500);
|
||||
}
|
||||
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
|
||||
/** @var \FireflyIII\Database\Budget $bdt */
|
||||
$bdt = App::make('FireflyIII\Database\Budget');
|
||||
$budgets = $bdt->get();
|
||||
|
||||
$chart->addColumn('Month', 'date');
|
||||
/** @var \Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
$chart->addColumn($budget->name, 'number');
|
||||
}
|
||||
$chart->addColumn('No budget','number');
|
||||
|
||||
/*
|
||||
* Loop budgets this year.
|
||||
*/
|
||||
$end = clone $start;
|
||||
$end->endOfYear();
|
||||
while ($start <= $end) {
|
||||
$row = [clone $start];
|
||||
|
||||
foreach($budgets as $budget) {
|
||||
$row[] = $bdt->spentInMonth($budget, $start);
|
||||
}
|
||||
|
||||
/*
|
||||
* Without a budget:
|
||||
*/
|
||||
$endOfMonth = clone $start;
|
||||
$endOfMonth->endOfMonth();
|
||||
$set = $bdt->transactionsWithoutBudgetInDateRange($start, $endOfMonth);
|
||||
$row[] = floatval($set->sum('amount')) * -1;
|
||||
|
||||
$chart->addRowArray($row);
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
}
|
||||
|
||||
public function budgetsAndSpending(Budget $budget, $year) {
|
||||
try {
|
||||
$start = new Carbon('01-01-' . $year);
|
||||
} catch (Exception $e) {
|
||||
App::abort(500);
|
||||
}
|
||||
|
||||
/** @var \FireflyIII\Database\Budget $bdt */
|
||||
$bdt = App::make('FireflyIII\Database\Budget');
|
||||
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('Month', 'date');
|
||||
$chart->addColumn('Budgeted', 'number');
|
||||
$chart->addColumn('Spent', 'number');
|
||||
|
||||
$end = clone $start;
|
||||
$end->endOfYear();
|
||||
while($start <= $end) {
|
||||
|
||||
$spent = $bdt->spentInMonth($budget, $start);
|
||||
$repetition = $bdt->repetitionOnStartingOnDate($budget, $start);
|
||||
if($repetition) {
|
||||
$budgeted = floatval($repetition->amount);
|
||||
} else {
|
||||
$budgeted = 0;
|
||||
}
|
||||
|
||||
$chart->addRow(clone $start, $budgeted, $spent);
|
||||
|
||||
$start->addMonth();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function allBudgetsHomeChart()
|
||||
{
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('Budget', 'string');
|
||||
$chart->addColumn('Budgeted', 'number');
|
||||
$chart->addColumn('Spent', 'number');
|
||||
|
||||
/** @var \FireflyIII\Database\Budget $bdt */
|
||||
$bdt = App::make('FireflyIII\Database\Budget');
|
||||
$budgets = $bdt->get();
|
||||
|
||||
/*
|
||||
* Loop budgets:
|
||||
*/
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
|
||||
/*
|
||||
* Is there a repetition starting on this particular date? We can use that.
|
||||
*/
|
||||
/** @var \LimitRepetition $repetition */
|
||||
$repetition = $bdt->repetitionOnStartingOnDate($budget, Session::get('start'));
|
||||
|
||||
/*
|
||||
* If there is, use it. Otherwise, forget it.
|
||||
*/
|
||||
if (is_null($repetition)) {
|
||||
// use the session start and end for our search query
|
||||
$searchStart = Session::get('start');
|
||||
$searchEnd = Session::get('end');
|
||||
// the limit is zero:
|
||||
$limit = 0;
|
||||
|
||||
} else {
|
||||
// use the limit's start and end for our search query
|
||||
$searchStart = $repetition->startdate;
|
||||
$searchEnd = $repetition->enddate;
|
||||
// the limit is the repetitions limit:
|
||||
$limit = floatval($repetition->amount);
|
||||
}
|
||||
|
||||
/*
|
||||
* No matter the result of the search for the repetition, get all the transactions associated
|
||||
* with the budget, and sum up the expenses made.
|
||||
*/
|
||||
$expenses = floatval($budget->transactionjournals()->before($searchEnd)->after($searchStart)->lessThan(0)->sum('amount')) * -1;
|
||||
if ($expenses > 0) {
|
||||
$chart->addRow($budget->name, $limit, $expenses);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Finally, get all transactions WITHOUT a budget and add those as well.
|
||||
* (yes this method is oddly specific).
|
||||
*/
|
||||
$noBudgetSet = $bdt->transactionsWithoutBudgetInDateRange(Session::get('start'), Session::get('end'));
|
||||
$sum = $noBudgetSet->sum('amount') * -1;
|
||||
$chart->addRow('No budget', 0, $sum);
|
||||
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function allCategoriesHomeChart()
|
||||
{
|
||||
$data = [];
|
||||
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('Category', 'string');
|
||||
$chart->addColumn('Spent', 'number');
|
||||
|
||||
/** @var \FireflyIII\Database\TransactionJournal $tj */
|
||||
$tj = App::make('FireflyIII\Database\TransactionJournal');
|
||||
|
||||
/*
|
||||
* Get the journals:
|
||||
*/
|
||||
$journals = $tj->getInDateRange(Session::get('start'), Session::get('end'));
|
||||
|
||||
/** @var \TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
if ($journal->transactionType->type == 'Withdrawal') {
|
||||
$amount = $journal->getAmount();
|
||||
$category = $journal->categories()->first();
|
||||
if (!is_null($category)) {
|
||||
if (isset($data[$category->name])) {
|
||||
$data[$category->name] += $amount;
|
||||
} else {
|
||||
$data[$category->name] = $amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
arsort($data);
|
||||
foreach ($data as $key => $entry) {
|
||||
$chart->addRow($key, $entry);
|
||||
}
|
||||
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws \Firefly\Exception\FireflyException
|
||||
*/
|
||||
public function recurringTransactionsOverview()
|
||||
{
|
||||
|
||||
/*
|
||||
* Set of paid transaction journals.
|
||||
* Set of unpaid recurring transactions.
|
||||
*/
|
||||
$paid = [
|
||||
'items' => [],
|
||||
'amount' => 0
|
||||
];
|
||||
$unpaid = [
|
||||
'items' => [],
|
||||
'amount' => 0
|
||||
];
|
||||
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('Name', 'string');
|
||||
$chart->addColumn('Amount', 'number');
|
||||
|
||||
/** @var \FireflyIII\Database\Recurring $rcr */
|
||||
$rcr = App::make('FireflyIII\Database\Recurring');
|
||||
|
||||
/** @var \FireflyIII\Shared\Toolkit\Date $dateKit */
|
||||
$dateKit = App::make('FireflyIII\Shared\Toolkit\Date');
|
||||
|
||||
$recurring = $rcr->get();
|
||||
|
||||
/** @var \RecurringTransaction $entry */
|
||||
foreach ($recurring as $entry) {
|
||||
/*
|
||||
* Start another loop starting at the $date.
|
||||
*/
|
||||
$start = clone $entry->date;
|
||||
$end = Carbon::now();
|
||||
|
||||
/*
|
||||
* The jump we make depends on the $repeat_freq
|
||||
*/
|
||||
$current = clone $start;
|
||||
|
||||
while ($current <= $end) {
|
||||
/*
|
||||
* Get end of period for $current:
|
||||
*/
|
||||
$currentEnd = clone $current;
|
||||
$dateKit->endOfPeriod($currentEnd, $entry->repeat_freq);
|
||||
|
||||
/*
|
||||
* In the current session range?
|
||||
*/
|
||||
if (\Session::get('end') >= $current and $currentEnd >= \Session::get('start')) {
|
||||
/*
|
||||
* Lets see if we've already spent money on this recurring transaction (it hath recurred).
|
||||
*/
|
||||
/** @var TransactionJournal $set */
|
||||
$journal = $rcr->getJournalForRecurringInRange($entry, $current, $currentEnd);
|
||||
|
||||
if (is_null($journal)) {
|
||||
$unpaid['items'][] = $entry->name;
|
||||
$unpaid['amount'] += (($entry->amount_max + $entry->amount_min) / 2);
|
||||
} else {
|
||||
$amount = $journal->getAmount();
|
||||
$paid['items'][] = $journal->description;
|
||||
$paid['amount'] += $amount;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Add some time for the next loop!
|
||||
*/
|
||||
$dateKit->addPeriod($current, $entry->repeat_freq, intval($entry->skip));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/** @var \RecurringTransaction $entry */
|
||||
$chart->addRow('Unpaid: ' . join(', ', $unpaid['items']), $unpaid['amount']);
|
||||
$chart->addRow('Paid: ' . join(', ', $paid['items']), $paid['amount']);
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*/
|
||||
public function accountBalanceChart(Account $account)
|
||||
{
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('Day of month', 'date');
|
||||
$chart->addColumn('Balance for ' . $account->name, 'number');
|
||||
|
||||
/*
|
||||
* Loop the date, then loop the accounts, then add balance.
|
||||
*/
|
||||
$start = Session::get('start');
|
||||
$end = Session::get('end');
|
||||
$current = clone $start;
|
||||
|
||||
while ($end >= $current) {
|
||||
$row = [clone $current];
|
||||
if ($current > Carbon::now()) {
|
||||
$row[] = null;
|
||||
} else {
|
||||
$row[] = $account->balance($current);
|
||||
}
|
||||
|
||||
$chart->addRowArray($row);
|
||||
$current->addDay();
|
||||
}
|
||||
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function accountSankeyOutChart(Account $account)
|
||||
{
|
||||
// collect all relevant entries.
|
||||
$set = [];
|
||||
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('From', 'string');
|
||||
$chart->addColumn('To', 'string', 'domain');
|
||||
$chart->addColumn('Weight', 'number');
|
||||
|
||||
$transactions = $account->transactions()->with(
|
||||
['transactionjournal', 'transactionjournal.transactions', 'transactionjournal.budgets', 'transactionjournal.transactiontype',
|
||||
'transactionjournal.categories']
|
||||
)->before(Session::get('end'))->after(
|
||||
Session::get('start')
|
||||
)->get();
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$amount = floatval($transaction->amount);
|
||||
$type = $transaction->transactionJournal->transactionType->type;
|
||||
|
||||
if ($amount < 0 && $type != 'Transfer') {
|
||||
|
||||
// from account to a budget (if present).
|
||||
$budgetName = isset($transaction->transactionJournal->budgets[0]) ? $transaction->transactionJournal->budgets[0]->name : '(no budget)';
|
||||
$set[] = [$account->name, $budgetName, $amount * -1];
|
||||
|
||||
// from budget to category.
|
||||
$categoryName = isset($transaction->transactionJournal->categories[0]) ? ' ' . $transaction->transactionJournal->categories[0]->name
|
||||
: '(no cat)';
|
||||
$set[] = [$budgetName, $categoryName, $amount * -1];
|
||||
}
|
||||
}
|
||||
// loop the set, group everything together:
|
||||
$grouped = [];
|
||||
foreach ($set as $entry) {
|
||||
$key = $entry[0] . $entry[1];
|
||||
if (isset($grouped[$key])) {
|
||||
$grouped[$key][2] += $entry[2];
|
||||
} else {
|
||||
$grouped[$key] = $entry;
|
||||
}
|
||||
}
|
||||
|
||||
// add rows to the chart:
|
||||
foreach ($grouped as $entry) {
|
||||
$chart->addRow($entry[0], $entry[1], $entry[2]);
|
||||
}
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function accountSankeyInChart(Account $account)
|
||||
{
|
||||
// collect all relevant entries.
|
||||
$set = [];
|
||||
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('From', 'string');
|
||||
$chart->addColumn('To', 'string', 'domain');
|
||||
$chart->addColumn('Weight', 'number');
|
||||
|
||||
$transactions = $account->transactions()->with(
|
||||
['transactionjournal', 'transactionjournal.transactions' => function ($q) {
|
||||
$q->where('amount', '<', 0);
|
||||
}, 'transactionjournal.budgets', 'transactionjournal.transactiontype', 'transactionjournal.categories']
|
||||
)->before(Session::get('end'))->after(
|
||||
Session::get('start')
|
||||
)->get();
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$amount = floatval($transaction->amount);
|
||||
$type = $transaction->transactionJournal->transactionType->type;
|
||||
|
||||
if ($amount > 0 && $type != 'Transfer') {
|
||||
|
||||
$otherAccount = $transaction->transactionJournal->transactions[0]->account->name;
|
||||
$categoryName = isset($transaction->transactionJournal->categories[0]) ? $transaction->transactionJournal->categories[0]->name
|
||||
: '(no cat)';
|
||||
$set[] = [$otherAccount, $categoryName, $amount];
|
||||
$set[] = [$categoryName, $account->name, $amount];
|
||||
}
|
||||
}
|
||||
// loop the set, group everything together:
|
||||
$grouped = [];
|
||||
foreach ($set as $entry) {
|
||||
$key = $entry[0] . $entry[1];
|
||||
if (isset($grouped[$key])) {
|
||||
$grouped[$key][2] += $entry[2];
|
||||
} else {
|
||||
$grouped[$key] = $entry;
|
||||
}
|
||||
}
|
||||
|
||||
// add rows to the chart:
|
||||
foreach ($grouped as $entry) {
|
||||
$chart->addRow($entry[0], $entry[1], $entry[2]);
|
||||
}
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
|
||||
}
|
||||
}
|
||||
240
app/controllers/GoogleTableController.php
Normal file
240
app/controllers/GoogleTableController.php
Normal file
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use Firefly\Exception\FireflyException;
|
||||
|
||||
/**
|
||||
* Class GoogleTableController
|
||||
*/
|
||||
class GoogleTableController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $what
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function accountList($what)
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Database\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account');
|
||||
|
||||
switch ($what) {
|
||||
default:
|
||||
throw new FireflyException('Cannot handle "' . e($what) . '" in accountList.');
|
||||
break;
|
||||
case 'asset':
|
||||
$list = $acct->getAssetAccounts();
|
||||
break;
|
||||
case 'expense':
|
||||
$list = $acct->getExpenseAccounts();
|
||||
break;
|
||||
case 'revenue':
|
||||
$list = $acct->getRevenueAccounts();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('ID', 'number');
|
||||
$chart->addColumn('ID_Edit', 'string');
|
||||
$chart->addColumn('ID_Delete', 'string');
|
||||
$chart->addColumn('Name_URL', 'string');
|
||||
$chart->addColumn('Name', 'string');
|
||||
$chart->addColumn('Balance', 'number');
|
||||
|
||||
/** @var \Account $entry */
|
||||
foreach ($list as $entry) {
|
||||
$edit = route('accounts.edit', $entry->id);
|
||||
$delete = route('accounts.delete', $entry->id);
|
||||
$show = route('accounts.show', $entry->id);
|
||||
$chart->addRow($entry->id, $edit, $delete, $show, $entry->name, $entry->balance());
|
||||
}
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param LimitRepetition $repetition
|
||||
*/
|
||||
public function transactionsByBudget(Budget $budget, LimitRepetition $repetition = null)
|
||||
{
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('ID', 'number');
|
||||
$chart->addColumn('ID_Edit', 'string');
|
||||
$chart->addColumn('ID_Delete', 'string');
|
||||
$chart->addColumn('Date', 'date');
|
||||
$chart->addColumn('Description_URL', 'string');
|
||||
$chart->addColumn('Description', 'string');
|
||||
$chart->addColumn('Amount', 'number');
|
||||
$chart->addColumn('From_URL', 'string');
|
||||
$chart->addColumn('From', 'string');
|
||||
$chart->addColumn('To_URL', 'string');
|
||||
$chart->addColumn('To', 'string');
|
||||
$chart->addColumn('Budget_URL', 'string');
|
||||
$chart->addColumn('Budget', 'string');
|
||||
$chart->addColumn('Category_URL', 'string');
|
||||
$chart->addColumn('Category', 'string');
|
||||
|
||||
if (is_null($repetition)) {
|
||||
$journals = $budget->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->orderBy('date', 'DESC')->get();
|
||||
} else {
|
||||
$journals = $budget->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->
|
||||
after($repetition->startdate)->before($repetition->enddate)->orderBy('date', 'DESC')->get();
|
||||
}
|
||||
/** @var TransactionJournal $transaction */
|
||||
foreach ($journals as $journal) {
|
||||
$date = $journal->date;
|
||||
$descriptionURL = route('transactions.show', $journal->id);
|
||||
$description = $journal->description;
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
if (floatval($transaction->amount) > 0) {
|
||||
$amount = floatval($transaction->amount);
|
||||
$to = $transaction->account->name;
|
||||
$toURL = route('accounts.show', $transaction->account->id);
|
||||
} else {
|
||||
$from = $transaction->account->name;
|
||||
$fromURL = route('accounts.show', $transaction->account->id);
|
||||
}
|
||||
|
||||
}
|
||||
if (isset($journal->budgets[0])) {
|
||||
$budgetURL = route('budgets.show', $journal->budgets[0]->id);
|
||||
$budget = $journal->budgets[0]->name;
|
||||
} else {
|
||||
$budgetURL = '';
|
||||
$budget = '';
|
||||
}
|
||||
|
||||
if (isset($journal->categories[0])) {
|
||||
$categoryURL = route('categories.show', $journal->categories[0]->id);
|
||||
$category = $journal->categories[0]->name;
|
||||
} else {
|
||||
$categoryURL = '';
|
||||
$category = '';
|
||||
}
|
||||
|
||||
|
||||
$id = $journal->id;
|
||||
$edit = route('transactions.edit', $journal->id);
|
||||
$delete = route('transactions.delete', $journal->id);
|
||||
$chart->addRow(
|
||||
$id, $edit, $delete, $date, $descriptionURL, $description, $amount, $fromURL, $from, $toURL, $to, $budgetURL, $budget, $categoryURL,
|
||||
$category
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*/
|
||||
public function transactionsByAccount(Account $account)
|
||||
{
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
$chart->addColumn('ID', 'number');
|
||||
$chart->addColumn('ID_Edit', 'string');
|
||||
$chart->addColumn('ID_Delete', 'string');
|
||||
$chart->addColumn('Date', 'date');
|
||||
$chart->addColumn('Description_URL', 'string');
|
||||
$chart->addColumn('Description', 'string');
|
||||
$chart->addColumn('Amount', 'number');
|
||||
$chart->addColumn('From_URL', 'string');
|
||||
$chart->addColumn('From', 'string');
|
||||
$chart->addColumn('To_URL', 'string');
|
||||
$chart->addColumn('To', 'string');
|
||||
$chart->addColumn('Budget_URL', 'string');
|
||||
$chart->addColumn('Budget', 'string');
|
||||
$chart->addColumn('Category_URL', 'string');
|
||||
$chart->addColumn('Category', 'string');
|
||||
|
||||
/*
|
||||
* Find transactions:
|
||||
*/
|
||||
$accountID = $account->id;
|
||||
$transactions = $account->transactions()->with(
|
||||
['transactionjournal', 'transactionjournal.transactions' => function ($q) use ($accountID) {
|
||||
$q->where('account_id', '!=', $accountID);
|
||||
}, 'transactionjournal.budgets', 'transactionjournal.transactiontype',
|
||||
'transactionjournal.categories']
|
||||
)->before(Session::get('end'))->after(
|
||||
Session::get('start')
|
||||
)->orderBy('date', 'DESC')->get();
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$date = $transaction->transactionJournal->date;
|
||||
$descriptionURL = route('transactions.show', $transaction->transaction_journal_id);
|
||||
$description = $transaction->transactionJournal->description;
|
||||
$amount = floatval($transaction->amount);
|
||||
|
||||
if ($transaction->transactionJournal->transactions[0]->account->id == $account->id) {
|
||||
$opposingAccountURI = route('accounts.show', $transaction->transactionJournal->transactions[1]->account->id);
|
||||
$opposingAccountName = $transaction->transactionJournal->transactions[1]->account->name;
|
||||
} else {
|
||||
$opposingAccountURI = route('accounts.show', $transaction->transactionJournal->transactions[0]->account->id);
|
||||
$opposingAccountName = $transaction->transactionJournal->transactions[0]->account->name;
|
||||
}
|
||||
if (isset($transaction->transactionJournal->budgets[0])) {
|
||||
$budgetURL = route('budgets.show', $transaction->transactionJournal->budgets[0]->id);
|
||||
$budget = $transaction->transactionJournal->budgets[0]->name;
|
||||
} else {
|
||||
$budgetURL = '';
|
||||
$budget = '';
|
||||
}
|
||||
|
||||
if (isset($transaction->transactionJournal->categories[0])) {
|
||||
$categoryURL = route('categories.show', $transaction->transactionJournal->categories[0]->id);
|
||||
$category = $transaction->transactionJournal->categories[0]->name;
|
||||
} else {
|
||||
$categoryURL = '';
|
||||
$category = '';
|
||||
}
|
||||
|
||||
|
||||
if ($amount < 0) {
|
||||
$from = $account->name;
|
||||
$fromURL = route('accounts.show', $account->id);
|
||||
|
||||
$to = $opposingAccountName;
|
||||
$toURL = $opposingAccountURI;
|
||||
} else {
|
||||
$to = $account->name;
|
||||
$toURL = route('accounts.show', $account->id);
|
||||
|
||||
$from = $opposingAccountName;
|
||||
$fromURL = $opposingAccountURI;
|
||||
}
|
||||
|
||||
$id = $transaction->transactionJournal->id;
|
||||
$edit = route('transactions.edit', $transaction->transactionJournal->id);
|
||||
$delete = route('transactions.delete', $transaction->transactionJournal->id);
|
||||
$chart->addRow(
|
||||
$id, $edit, $delete, $date, $descriptionURL, $description, $amount, $fromURL, $from, $toURL, $to, $budgetURL, $budget, $categoryURL, $category
|
||||
);
|
||||
}
|
||||
|
||||
// <th>Date</th>
|
||||
// <th>Description</th>
|
||||
// <th>Amount (€)</th>
|
||||
// <th>From</th>
|
||||
// <th>To</th>
|
||||
// <th>Budget / category</th>
|
||||
// <th>ID</th>
|
||||
|
||||
|
||||
$chart->generate();
|
||||
return Response::json($chart->getData());
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,73 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
|
||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
use Firefly\Storage\Reminder\ReminderRepositoryInterface as RRI;
|
||||
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
||||
|
||||
/**
|
||||
* Class HomeController
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class HomeController extends BaseController
|
||||
{
|
||||
protected $_accounts;
|
||||
protected $_preferences;
|
||||
protected $_journal;
|
||||
protected $_reminders;
|
||||
|
||||
public function __construct(ARI $accounts, PHI $preferences, TJRI $journal, RRI $reminders)
|
||||
/**
|
||||
* @param ARI $accounts
|
||||
* @param PHI $preferences
|
||||
* @param TJRI $journal
|
||||
*/
|
||||
public function __construct(ARI $accounts, PHI $preferences, TJRI $journal)
|
||||
{
|
||||
$this->_accounts = $accounts;
|
||||
$this->_preferences = $preferences;
|
||||
$this->_journal = $journal;
|
||||
$this->_reminders = $reminders;
|
||||
}
|
||||
|
||||
public function jobDev()
|
||||
{
|
||||
$fullName = storage_path() . DIRECTORY_SEPARATOR . 'firefly-export-2014-07-23.json';
|
||||
\Log::notice('Pushed start job.');
|
||||
Queue::push('Firefly\Queue\Import@start', ['file' => $fullName, 'user' => 1]);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public function sessionPrev()
|
||||
{
|
||||
/** @var \Firefly\Helper\Toolkit\ToolkitInterface $toolkit */
|
||||
$toolkit = App::make('Firefly\Helper\Toolkit\ToolkitInterface');
|
||||
$toolkit->prev();
|
||||
return Redirect::back();
|
||||
//return Redirect::route('index');
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public function sessionNext()
|
||||
{
|
||||
/** @var \Firefly\Helper\Toolkit\ToolkitInterface $toolkit */
|
||||
$toolkit = App::make('Firefly\Helper\Toolkit\ToolkitInterface');
|
||||
$toolkit->next();
|
||||
return Redirect::back();
|
||||
//return Redirect::route('index');
|
||||
}
|
||||
|
||||
public function rangeJump($range)
|
||||
{
|
||||
|
||||
$valid = ['1D', '1W', '1M', '3M', '6M', '1Y',];
|
||||
|
||||
if (in_array($range, $valid)) {
|
||||
$this->_preferences->set('viewRange', $range);
|
||||
Session::forget('range');
|
||||
}
|
||||
return Redirect::back();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,13 +85,11 @@ class HomeController extends BaseController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
Event::fire('limits.check');
|
||||
Event::fire('piggybanks.check');
|
||||
Event::fire('recurring.check');
|
||||
|
||||
\Event::fire('limits.check');
|
||||
\Event::fire('piggybanks.check');
|
||||
\Event::fire('recurring.check');
|
||||
|
||||
|
||||
// count, maybe we need some introducing text to show:
|
||||
// count, maybe Firefly needs some introducing text to show:
|
||||
$count = $this->_accounts->count();
|
||||
$start = Session::get('start');
|
||||
$end = Session::get('end');
|
||||
@@ -66,21 +111,63 @@ class HomeController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
if (count($transactions) % 2 == 0) {
|
||||
$transactions = array_chunk($transactions, 2);
|
||||
} elseif (count($transactions) == 1) {
|
||||
$transactions = array_chunk($transactions, 3);
|
||||
} else {
|
||||
$transactions = array_chunk($transactions, 3);
|
||||
// build the home screen:
|
||||
return View::make('index')->with('count', $count)->with('transactions', $transactions)->with('title', 'Firefly')
|
||||
->with('subTitle', 'What\'s playing?')->with('mainTitleIcon', 'fa-fire');
|
||||
}
|
||||
|
||||
// get the users reminders:
|
||||
public function cleanup()
|
||||
{
|
||||
/** @var \FireflyIII\Database\TransactionJournal $jrnls */
|
||||
$jrnls = App::make('FireflyIII\Database\TransactionJournal');
|
||||
|
||||
/** @var \FireflyIII\Database\Account $acct */
|
||||
$acct = \App::make('FireflyIII\Database\Account');
|
||||
|
||||
/** @var \FireflyIII\Database\AccountType $acctType */
|
||||
$acctType = \App::make('FireflyIII\Database\AccountType');
|
||||
$rightAcctType = $acctType->findByWhat('revenue');
|
||||
|
||||
$all = $jrnls->get();
|
||||
|
||||
/** @var \TransactionJournal $entry */
|
||||
foreach ($all as $entry) {
|
||||
$wrongFromType = false;
|
||||
$wrongToType = false;
|
||||
$transactions = $entry->transactions;
|
||||
if (count($transactions) == 2) {
|
||||
switch ($entry->transactionType->type) {
|
||||
case 'Deposit':
|
||||
/** @var \Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
if (floatval($transaction->amount) < 0) {
|
||||
$accountType = $transaction->account->accountType;
|
||||
if ($accountType->type == 'Beneficiary account') {
|
||||
// should be a Revenue account!
|
||||
$name = $transaction->account->name;
|
||||
/** @var \Account $account */
|
||||
$account = \Auth::user()->accounts()->where('name', $name)->where('account_type_id', $rightAcctType->id)->first();
|
||||
if (!$account) {
|
||||
$new = [
|
||||
'name' => $name,
|
||||
'what' => 'revenue'
|
||||
];
|
||||
$account = $acct->store($new);
|
||||
}
|
||||
$transaction->account()->associate($account);
|
||||
$transaction->save();
|
||||
}
|
||||
|
||||
echo 'Paid by: ' . $transaction->account->name . ' (' . $transaction->account->accountType->type . ')<br />';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$reminders = $this->_reminders->getCurrentRecurringReminders();
|
||||
|
||||
// build the home screen:
|
||||
return View::make('index')->with('count', $count)->with('transactions', $transactions)->with(
|
||||
'reminders', $reminders
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,56 @@
|
||||
<?php
|
||||
|
||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
use Firefly\Storage\Budget\BudgetRepositoryInterface as Bud;
|
||||
use Firefly\Storage\Category\CategoryRepositoryInterface as Cat;
|
||||
use Firefly\Storage\Component\ComponentRepositoryInterface as CRI;
|
||||
use Firefly\Helper\Controllers\JsonInterface as JI;
|
||||
use Illuminate\Support\Collection;
|
||||
use LaravelBook\Ardent\Builder;
|
||||
|
||||
/**
|
||||
* Class JsonController
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class JsonController extends BaseController
|
||||
{
|
||||
protected $_accounts;
|
||||
protected $_components;
|
||||
protected $_categories;
|
||||
protected $_budgets;
|
||||
/** @var \Firefly\Helper\Controllers\JsonInterface $helper */
|
||||
protected $helper;
|
||||
|
||||
public function __construct(JI $helper)
|
||||
{
|
||||
$this->helper = $helper;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ARI $accounts
|
||||
* @param CRI $components
|
||||
* @param Cat $categories
|
||||
* @param Bud $budgets
|
||||
* Returns a list of categories.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function __construct(ARI $accounts, CRI $components, Cat $categories, Bud $budgets)
|
||||
public function categories()
|
||||
{
|
||||
$this->_components = $components;
|
||||
$this->_accounts = $accounts;
|
||||
$this->_categories = $categories;
|
||||
$this->_budgets = $budgets;
|
||||
/** @var \Firefly\Storage\Category\EloquentCategoryRepository $categories */
|
||||
$categories = App::make('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
$list = $categories->get();
|
||||
$return = [];
|
||||
foreach ($list as $entry) {
|
||||
$return[] = $entry->name;
|
||||
}
|
||||
|
||||
return Response::json($return);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a JSON list of all beneficiaries.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function beneficiaries()
|
||||
public function expenseAccounts()
|
||||
{
|
||||
$list = $this->_accounts->getBeneficiaries();
|
||||
/** @var \Firefly\Storage\Account\EloquentAccountRepository $accounts */
|
||||
$accounts = App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$list = $accounts->getOfTypes(['Expense account', 'Beneficiary account']);
|
||||
$return = [];
|
||||
foreach ($list as $entry) {
|
||||
$return[] = $entry->name;
|
||||
@@ -45,11 +61,99 @@ class JsonController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds some JSON for typeahead fields.
|
||||
* Returns a list of transactions, expenses only, using the given parameters.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function categories()
|
||||
public function expenses()
|
||||
{
|
||||
$list = $this->_categories->get();
|
||||
|
||||
/*
|
||||
* Gets most parameters from the Input::all() array:
|
||||
*/
|
||||
$parameters = $this->helper->dataTableParameters();
|
||||
|
||||
/*
|
||||
* Add some more parameters to fine tune the query:
|
||||
*/
|
||||
$parameters['transactionTypes'] = ['Withdrawal'];
|
||||
$parameters['amount'] = 'negative';
|
||||
|
||||
/*
|
||||
* Get the query:
|
||||
*/
|
||||
$query = $this->helper->journalQuery($parameters);
|
||||
|
||||
/*
|
||||
* Build result set:
|
||||
*/
|
||||
$resultSet = $this->helper->journalDataset($parameters, $query);
|
||||
|
||||
|
||||
/*
|
||||
* Build return data:
|
||||
*/
|
||||
return Response::json($resultSet);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function recurringjournals(RecurringTransaction $recurringTransaction)
|
||||
{
|
||||
$parameters = $this->helper->dataTableParameters();
|
||||
$parameters['transactionTypes'] = ['Withdrawal'];
|
||||
$parameters['amount'] = 'negative';
|
||||
|
||||
$query = $this->helper->journalQuery($parameters);
|
||||
|
||||
$query->where('recurring_transaction_id', $recurringTransaction->id);
|
||||
$resultSet = $this->helper->journalDataset($parameters, $query);
|
||||
|
||||
|
||||
/*
|
||||
* Build return data:
|
||||
*/
|
||||
return Response::json($resultSet);
|
||||
}
|
||||
|
||||
public function recurring()
|
||||
{
|
||||
$parameters = $this->helper->dataTableParameters();
|
||||
$query = $this->helper->recurringTransactionsQuery($parameters);
|
||||
$resultSet = $this->helper->recurringTransactionsDataset($parameters, $query);
|
||||
return Response::json($resultSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\JsonResponse|string
|
||||
*/
|
||||
public function revenue()
|
||||
{
|
||||
$parameters = $this->helper->dataTableParameters();
|
||||
$parameters['transactionTypes'] = ['Deposit'];
|
||||
$parameters['amount'] = 'positive';
|
||||
|
||||
$query = $this->helper->journalQuery($parameters);
|
||||
$resultSet = $this->helper->journalDataset($parameters, $query);
|
||||
|
||||
|
||||
/*
|
||||
* Build return data:
|
||||
*/
|
||||
return Response::json($resultSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a JSON list of all revenue accounts.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function revenueAccounts()
|
||||
{
|
||||
/** @var \Firefly\Storage\Account\EloquentAccountRepository $accounts */
|
||||
$accounts = App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$list = $accounts->getOfTypes(['Revenue account']);
|
||||
$return = [];
|
||||
foreach ($list as $entry) {
|
||||
$return[] = $entry->name;
|
||||
@@ -57,6 +161,26 @@ class JsonController extends BaseController
|
||||
|
||||
return Response::json($return);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all transfers.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function transfers()
|
||||
{
|
||||
$parameters = $this->helper->dataTableParameters();
|
||||
$parameters['transactionTypes'] = ['Transfer'];
|
||||
$parameters['amount'] = 'positive';
|
||||
|
||||
$query = $this->helper->journalQuery($parameters);
|
||||
$resultSet = $this->helper->journalDataset($parameters, $query);
|
||||
|
||||
|
||||
/*
|
||||
* Build return data:
|
||||
*/
|
||||
return Response::json($resultSet);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ use Firefly\Storage\Limit\LimitRepositoryInterface as LRI;
|
||||
|
||||
/**
|
||||
* Class LimitController
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class LimitController extends BaseController
|
||||
{
|
||||
@@ -20,6 +22,9 @@ class LimitController extends BaseController
|
||||
{
|
||||
$this->_budgets = $budgets;
|
||||
$this->_limits = $limits;
|
||||
|
||||
View::share('title','Envelopes');
|
||||
View::share('mainTitleIcon', 'fa-tasks');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,11 +41,13 @@ class LimitController extends BaseController
|
||||
'budget_id' => $budget ? $budget->id : null
|
||||
];
|
||||
|
||||
$budgets = $this->_budgets->getAsSelectList();
|
||||
/** @var \Firefly\Helper\Toolkit\Toolkit $toolkit */
|
||||
$toolkit = App::make('Firefly\Helper\Toolkit\Toolkit');
|
||||
$budgets = $toolkit->makeSelectList($this->_budgets->get());
|
||||
|
||||
return View::make('limits.create')->with('budgets', $budgets)->with(
|
||||
'periods', $periods
|
||||
)->with('prefilled', $prefilled);
|
||||
)->with('prefilled', $prefilled)->with('subTitle','New envelope');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +57,7 @@ class LimitController extends BaseController
|
||||
*/
|
||||
public function delete(\Limit $limit)
|
||||
{
|
||||
return View::make('limits.delete')->with('limit', $limit);
|
||||
return View::make('limits.delete')->with('limit', $limit)->with('subTitle','Delete envelope');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,12 +89,15 @@ class LimitController extends BaseController
|
||||
*/
|
||||
public function edit(Limit $limit)
|
||||
{
|
||||
$budgets = $this->_budgets->getAsSelectList();
|
||||
/** @var \Firefly\Helper\Toolkit\Toolkit $toolkit */
|
||||
$toolkit = App::make('Firefly\Helper\Toolkit\Toolkit');
|
||||
|
||||
$budgets = $toolkit->makeSelectList($this->_budgets->get());
|
||||
$periods = \Config::get('firefly.periods_to_text');
|
||||
|
||||
return View::make('limits.edit')->with('limit', $limit)->with('budgets', $budgets)->with(
|
||||
'periods', $periods
|
||||
);
|
||||
)->with('subTitle','Edit envelope');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +108,7 @@ class LimitController extends BaseController
|
||||
public function store(Budget $budget = null)
|
||||
{
|
||||
|
||||
// find a limit with these properties, as we might already have one:
|
||||
// find a limit with these properties, as Firefly might already have one:
|
||||
$limit = $this->_limits->store(Input::all());
|
||||
if ($limit->validate()) {
|
||||
Session::flash('success', 'Envelope created!');
|
||||
|
||||
52
app/controllers/MigrateController.php
Normal file
52
app/controllers/MigrateController.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class MigrateController
|
||||
*/
|
||||
class MigrateController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return View::make('migrate.index')->with('index', 'Migration')->with('title','Migrate')->
|
||||
with('subTitle','From Firefly II to Firefly III');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
if (Input::hasFile('file') && Input::file('file')->isValid()) {
|
||||
$path = storage_path();
|
||||
$fileName = 'firefly-iii-import-' . date('Y-m-d-H-i') . '.json';
|
||||
$fullName = $path . DIRECTORY_SEPARATOR . $fileName;
|
||||
if (Input::file('file')->move($path, $fileName)) {
|
||||
// so now Firefly pushes something in a queue and does something with it! Yay!
|
||||
\Log::debug('Pushed a job to start the import.');
|
||||
Queue::push('Firefly\Queue\Import@start', ['file' => $fullName, 'user' => \Auth::user()->id]);
|
||||
if (Config::get('queue.default') == 'sync') {
|
||||
Session::flash('success', 'Your data has been imported!');
|
||||
} else {
|
||||
Session::flash(
|
||||
'success',
|
||||
'The import job has been queued. Please be patient. Data will appear slowly. Please be patient.'
|
||||
);
|
||||
}
|
||||
|
||||
return Redirect::route('index');
|
||||
}
|
||||
Session::flash('error', 'Could not save file to storage.');
|
||||
return Redirect::route('migrate.index');
|
||||
|
||||
} else {
|
||||
Session::flash('error', 'Please upload a file.');
|
||||
return Redirect::route('migrate.index');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
use Firefly\Exception\FireflyException;
|
||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
use Firefly\Storage\Piggybank\PiggybankRepositoryInterface as PRI;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
* Class PiggybankController
|
||||
@@ -11,53 +12,31 @@ use Firefly\Storage\Piggybank\PiggybankRepositoryInterface as PRI;
|
||||
class PiggybankController extends BaseController
|
||||
{
|
||||
|
||||
protected $_repository;
|
||||
protected $_accounts;
|
||||
|
||||
/**
|
||||
* @param PRI $repository
|
||||
* @param ARI $accounts
|
||||
*
|
||||
*/
|
||||
public function __construct(PRI $repository, ARI $accounts)
|
||||
public function __construct()
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
$this->_accounts = $accounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Piggybank $piggyBank
|
||||
* @throws NotImplementedException
|
||||
*/
|
||||
public function addMoney(Piggybank $piggyBank)
|
||||
public function create()
|
||||
{
|
||||
$what = 'add';
|
||||
$maxAdd = $this->_repository->leftOnAccount($piggyBank->account);
|
||||
$maxRemove = null;
|
||||
|
||||
return View::make('piggybanks.modifyAmount')->with('what', $what)->with('maxAdd', $maxAdd)->with(
|
||||
'maxRemove', $maxRemove
|
||||
)->with('piggybank', $piggyBank);
|
||||
}
|
||||
/** @var \FireflyIII\Database\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account');
|
||||
|
||||
/** @var \FireflyIII\Shared\Toolkit\Form $toolkit */
|
||||
$toolkit = App::make('FireflyIII\Shared\Toolkit\Form');
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function createPiggybank()
|
||||
{
|
||||
$periods = Config::get('firefly.piggybank_periods');
|
||||
$accounts = $this->_accounts->getActiveDefaultAsSelectList();
|
||||
|
||||
return View::make('piggybanks.create-piggybank')->with('accounts', $accounts)->with('periods', $periods);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function createRepeated()
|
||||
{
|
||||
$periods = Config::get('firefly.piggybank_periods');
|
||||
$accounts = $this->_accounts->getActiveDefaultAsSelectList();
|
||||
|
||||
return View::make('piggybanks.create-repeated')->with('accounts', $accounts)->with('periods', $periods);
|
||||
$accounts = $toolkit->makeSelectList($acct->getAssetAccounts());
|
||||
return View::make('piggybanks.create', compact('accounts', 'periods'))->with('title', 'Piggy banks')->with('mainTitleIcon', 'fa-sort-amount-asc')
|
||||
->with('subTitle', 'Create new piggy bank')->with('subTitleIcon', 'fa-plus');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,9 +44,13 @@ class PiggybankController extends BaseController
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function delete(Piggybank $piggyBank)
|
||||
public function delete(Piggybank $piggybank)
|
||||
{
|
||||
return View::make('piggybanks.delete')->with('piggybank', $piggyBank);
|
||||
View::share('subTitle', 'Delete "' . $piggybank->name . '"');
|
||||
View::share('title', 'Piggy banks');
|
||||
View::share('mainTitleIcon', 'fa-sort-amount-asc');
|
||||
|
||||
return View::make('piggybanks.delete')->with('piggybank', $piggybank);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,8 +61,10 @@ class PiggybankController extends BaseController
|
||||
public function destroy(Piggybank $piggyBank)
|
||||
{
|
||||
Event::fire('piggybanks.destroy', [$piggyBank]);
|
||||
$this->_repository->destroy($piggyBank);
|
||||
|
||||
/** @var \FireflyIII\Database\Piggybank $acct */
|
||||
$repos = App::make('FireflyIII\Database\Piggybank');
|
||||
$repos->destroy($piggyBank);
|
||||
Session::flash('success', 'Piggy bank deleted.');
|
||||
|
||||
return Redirect::route('piggybanks.index');
|
||||
@@ -90,188 +75,247 @@ class PiggybankController extends BaseController
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function edit(Piggybank $piggyBank)
|
||||
public function edit(Piggybank $piggybank)
|
||||
{
|
||||
$accounts = $this->_accounts->getActiveDefaultAsSelectList();
|
||||
|
||||
/** @var \FireflyIII\Database\Account $acct */
|
||||
$acct = App::make('FireflyIII\Database\Account');
|
||||
|
||||
/** @var \FireflyIII\Shared\Toolkit\Form $toolkit */
|
||||
$toolkit = App::make('FireflyIII\Shared\Toolkit\Form');
|
||||
|
||||
$periods = Config::get('firefly.piggybank_periods');
|
||||
if ($piggyBank->repeats == 1) {
|
||||
return View::make('piggybanks.edit-repeated')->with('piggybank', $piggyBank)->with('accounts', $accounts)
|
||||
->with('periods', $periods);
|
||||
} else {
|
||||
return View::make('piggybanks.edit-piggybank')->with('piggybank', $piggyBank)->with('accounts', $accounts)
|
||||
->with('periods', $periods);
|
||||
}
|
||||
|
||||
$accounts = $toolkit->makeSelectList($acct->getAssetAccounts());
|
||||
|
||||
/*
|
||||
* Flash some data to fill the form.
|
||||
*/
|
||||
$prefilled = [
|
||||
'name' => $piggybank->name,
|
||||
'account_id' => $piggybank->account_id,
|
||||
'targetamount' => $piggybank->targetamount,
|
||||
'targetdate' => $piggybank->targetdate,
|
||||
'remind_me' => intval($piggybank->remind_me) == 1 ? true : false
|
||||
];
|
||||
Session::flash('prefilled', $prefilled);
|
||||
|
||||
return View::make('piggybanks.edit', compact('piggybank', 'accounts', 'periods', 'prefilled'))->with('title', 'Piggybanks')->with(
|
||||
'mainTitleIcon', 'fa-sort-amount-asc'
|
||||
)
|
||||
->with('subTitle', 'Edit piggy bank "' . e($piggybank->name) . '"')->with('subTitleIcon', 'fa-pencil');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Piggybank $piggybank
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function index()
|
||||
public function add(Piggybank $piggybank)
|
||||
{
|
||||
$countRepeating = $this->_repository->countRepeating();
|
||||
$countNonRepeating = $this->_repository->countNonrepeating();
|
||||
/** @var \FireflyIII\Database\Piggybank $acct */
|
||||
$repos = App::make('FireflyIII\Database\Piggybank');
|
||||
|
||||
$piggybanks = $this->_repository->get();
|
||||
$leftOnAccount = $repos->leftOnAccount($piggybank->account);
|
||||
$savedSoFar = $piggybank->currentRelevantRep()->currentamount;
|
||||
$leftToSave = $piggybank->targetamount - $savedSoFar;
|
||||
$amount = min($leftOnAccount, $leftToSave);
|
||||
|
||||
// get the accounts with each piggy bank and check their balance; we might need to
|
||||
// show the user a correction.
|
||||
|
||||
$accounts = [];
|
||||
/** @var \Piggybank $piggybank */
|
||||
foreach ($piggybanks as $piggybank) {
|
||||
$account = $piggybank->account;
|
||||
$id = $account->id;
|
||||
if (!isset($accounts[$id])) {
|
||||
$accounts[$id] = ['account' => $account, 'left' => $this->_repository->leftOnAccount($account)];
|
||||
}
|
||||
}
|
||||
|
||||
return View::make('piggybanks.index')->with('piggybanks', $piggybanks)
|
||||
->with('countRepeating', $countRepeating)
|
||||
->with('countNonRepeating', $countNonRepeating)
|
||||
->with('accounts', $accounts);
|
||||
return View::make('piggybanks.add', compact('piggybank'))->with('maxAmount', $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Piggybank $piggyBank
|
||||
* @param Piggybank $piggybank
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws Firefly\Exception\FireflyException
|
||||
*/
|
||||
public function modMoney(Piggybank $piggyBank)
|
||||
public function postAdd(Piggybank $piggybank)
|
||||
{
|
||||
$amount = floatval(Input::get('amount'));
|
||||
switch (Input::get('what')) {
|
||||
default:
|
||||
throw new FireflyException('No such action');
|
||||
break;
|
||||
case 'add':
|
||||
$maxAdd = $this->_repository->leftOnAccount($piggyBank->account);
|
||||
if (round($amount, 2) <= round(min($maxAdd, $piggyBank->targetamount), 2)) {
|
||||
Session::flash('success', 'Amount updated!');
|
||||
$this->_repository->modifyAmount($piggyBank, $amount);
|
||||
Event::fire('piggybanks.modifyAmountAdd', [$piggyBank, $amount]);
|
||||
} else {
|
||||
Session::flash('warning', 'Could not!');
|
||||
}
|
||||
break;
|
||||
case 'remove':
|
||||
$rep = $piggyBank->currentRelevantRep();
|
||||
$maxRemove = $rep->currentamount;
|
||||
if (round($amount, 2) <= round($maxRemove, 2)) {
|
||||
Session::flash('success', 'Amount updated!');
|
||||
$this->_repository->modifyAmount($piggyBank, ($amount * -1));
|
||||
Event::fire('piggybanks.modifyAmountRemove', [$piggyBank, ($amount * -1)]);
|
||||
} else {
|
||||
Session::flash('warning', 'Could not!');
|
||||
}
|
||||
break;
|
||||
}
|
||||
$amount = round(floatval(Input::get('amount')), 2);
|
||||
|
||||
/** @var \FireflyIII\Database\Piggybank $acct */
|
||||
$repos = App::make('FireflyIII\Database\Piggybank');
|
||||
|
||||
$leftOnAccount = $repos->leftOnAccount($piggybank->account);
|
||||
$savedSoFar = $piggybank->currentRelevantRep()->currentamount;
|
||||
$leftToSave = $piggybank->targetamount - $savedSoFar;
|
||||
$maxAmount = round(min($leftOnAccount, $leftToSave), 2);
|
||||
|
||||
if ($amount <= $maxAmount) {
|
||||
$repetition = $piggybank->currentRelevantRep();
|
||||
$repetition->currentamount += $amount;
|
||||
$repetition->save();
|
||||
Session::flash('success', 'Added ' . mf($amount, false) . ' to "' . e($piggybank->name) . '".');
|
||||
} else {
|
||||
Session::flash('error', 'Could not add ' . mf($amount, false) . ' to "' . e($piggybank->name) . '".');
|
||||
}
|
||||
return Redirect::route('piggybanks.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Piggybank $piggyBank
|
||||
* @param Piggybank $piggybank
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function removeMoney(Piggybank $piggyBank)
|
||||
public function remove(Piggybank $piggybank)
|
||||
{
|
||||
$what = 'remove';
|
||||
$maxAdd = $this->_repository->leftOnAccount($piggyBank->account);
|
||||
$maxRemove = $piggyBank->currentRelevantRep()->currentamount;
|
||||
return View::make('piggybanks.remove', compact('piggybank'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Piggybank $piggybank
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postRemove(Piggybank $piggybank)
|
||||
{
|
||||
$amount = floatval(Input::get('amount'));
|
||||
|
||||
$savedSoFar = $piggybank->currentRelevantRep()->currentamount;
|
||||
|
||||
if ($amount <= $savedSoFar) {
|
||||
$repetition = $piggybank->currentRelevantRep();
|
||||
$repetition->currentamount -= $amount;
|
||||
$repetition->save();
|
||||
Session::flash('success', 'Removed ' . mf($amount, false) . ' from "' . e($piggybank->name) . '".');
|
||||
} else {
|
||||
Session::flash('error', 'Could not remove ' . mf($amount, false) . ' from "' . e($piggybank->name) . '".');
|
||||
}
|
||||
return Redirect::route('piggybanks.index');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
/** @var \FireflyIII\Database\Piggybank $repos */
|
||||
$repos = App::make('FireflyIII\Database\Piggybank');
|
||||
|
||||
/** @var Collection $piggybanks */
|
||||
$piggybanks = $repos->get();
|
||||
|
||||
$accounts = [];
|
||||
/** @var Piggybank $piggybank */
|
||||
foreach ($piggybanks as $piggybank) {
|
||||
$piggybank->savedSoFar = floatval($piggybank->currentRelevantRep()->currentamount);
|
||||
$piggybank->percentage = intval($piggybank->savedSoFar / $piggybank->targetamount * 100);
|
||||
$piggybank->leftToSave = $piggybank->targetamount - $piggybank->savedSoFar;
|
||||
|
||||
/*
|
||||
* Fill account information:
|
||||
*/
|
||||
$account = $piggybank->account;
|
||||
if (!isset($accounts[$account->id])) {
|
||||
$accounts[$account->id] = [
|
||||
'name' => $account->name,
|
||||
'balance' => $account->balance(),
|
||||
'leftForPiggybanks' => $repos->leftOnAccount($account),
|
||||
'sumOfSaved' => $piggybank->savedSoFar,
|
||||
'sumOfTargets' => floatval($piggybank->targetamount),
|
||||
'leftToSave' => $piggybank->leftToSave
|
||||
];
|
||||
} else {
|
||||
$accounts[$account->id]['sumOfSaved'] += $piggybank->savedSoFar;
|
||||
$accounts[$account->id]['sumOfTargets'] += floatval($piggybank->targetamount);
|
||||
$accounts[$account->id]['leftToSave'] += $piggybank->leftToSave;
|
||||
}
|
||||
}
|
||||
return View::make('piggybanks.index', compact('piggybanks', 'accounts'))->with('title', 'Piggy banks')->with('mainTitleIcon', 'fa-sort-amount-asc');
|
||||
}
|
||||
|
||||
|
||||
public function show(Piggybank $piggyBank)
|
||||
{
|
||||
throw new NotImplementedException;
|
||||
|
||||
return View::make('piggybanks.modifyAmount')->with('what', $what)->with('maxAdd', $maxAdd)->with(
|
||||
'maxRemove', $maxRemove
|
||||
)->with('piggybank', $piggyBank);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function show(Piggybank $piggyBank)
|
||||
{
|
||||
$leftOnAccount = $this->_repository->leftOnAccount($piggyBank->account);
|
||||
$balance = $piggyBank->account->balance();
|
||||
|
||||
return View::make('piggybanks.show')->with('piggyBank', $piggyBank)->with('leftOnAccount', $leftOnAccount)
|
||||
->with('balance', $balance);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function storePiggybank()
|
||||
public function store()
|
||||
{
|
||||
$data = Input::all();
|
||||
unset($data['_token']);
|
||||
|
||||
// extend the data array with the settings needed to create a piggy bank:
|
||||
$data['repeats'] = 0;
|
||||
$data['rep_times'] = 1;
|
||||
$data['rep_every'] = 1;
|
||||
$data['order'] = 0;
|
||||
/** @var \FireflyIII\Database\Piggybank $repos */
|
||||
$repos = App::make('FireflyIII\Database\Piggybank');
|
||||
|
||||
$piggyBank = $this->_repository->store($data);
|
||||
if (!is_null($piggyBank->id)) {
|
||||
Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!');
|
||||
Event::fire('piggybanks.store', [$piggyBank]);
|
||||
|
||||
return Redirect::route('piggybanks.index');
|
||||
|
||||
|
||||
} else {
|
||||
Session::flash('error', 'Could not save piggy bank: ' . $piggyBank->errors()->first());
|
||||
|
||||
return Redirect::route('piggybanks.create.piggybank')->withInput()->withErrors($piggyBank->errors());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function storeRepeated()
|
||||
{
|
||||
|
||||
$data = Input::all();
|
||||
unset($data['_token']);
|
||||
|
||||
// extend the data array with the settings needed to create a repeated:
|
||||
$data['repeats'] = 1;
|
||||
$data['order'] = 0;
|
||||
|
||||
$piggyBank = $this->_repository->store($data);
|
||||
if ($piggyBank->id) {
|
||||
Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!');
|
||||
Event::fire('piggybanks.store', [$piggyBank]);
|
||||
|
||||
return Redirect::route('piggybanks.index');
|
||||
|
||||
} else {
|
||||
Session::flash('error', 'Could not save piggy bank: ' . $piggyBank->errors()->first());
|
||||
|
||||
return Redirect::route('piggybanks.create.repeated')->withInput()->withErrors($piggyBank->errors());
|
||||
switch ($data['post_submit_action']) {
|
||||
default:
|
||||
throw new FireflyException('Cannot handle post_submit_action "' . e($data['post_submit_action']) . '"');
|
||||
break;
|
||||
case 'create_another':
|
||||
case 'store':
|
||||
$messages = $repos->validate($data);
|
||||
/** @var MessageBag $messages ['errors'] */
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('error', 'Could not save piggy bank: ' . $messages['errors']->first());
|
||||
return Redirect::route('piggybanks.create')->withInput()->withErrors($messages['errors']);
|
||||
}
|
||||
// store!
|
||||
$repos->store($data);
|
||||
Session::flash('success', 'New piggy bank stored!');
|
||||
|
||||
if ($data['post_submit_action'] == 'create_another') {
|
||||
return Redirect::route('piggybanks.create');
|
||||
} else {
|
||||
return Redirect::route('piggybanks.index');
|
||||
}
|
||||
break;
|
||||
case 'validate_only':
|
||||
$messageBags = $repos->validate($data);
|
||||
Session::flash('warnings', $messageBags['warnings']);
|
||||
Session::flash('successes', $messageBags['successes']);
|
||||
Session::flash('errors', $messageBags['errors']);
|
||||
|
||||
return Redirect::route('piggybanks.create')->withInput();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Piggybank $piggyBank
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Piggybank $piggyBank)
|
||||
{
|
||||
$piggyBank = $this->_repository->update($piggyBank, Input::all());
|
||||
if ($piggyBank->validate()) {
|
||||
Session::flash('success', 'Piggy bank "' . $piggyBank->name . '" updated.');
|
||||
Event::fire('piggybanks.update', [$piggyBank]);
|
||||
|
||||
return Redirect::route('piggybanks.index');
|
||||
/** @var \FireflyIII\Database\Piggybank $repos */
|
||||
$repos = App::make('FireflyIII\Database\Piggybank');
|
||||
$data = Input::except('_token');
|
||||
|
||||
switch (Input::get('post_submit_action')) {
|
||||
default:
|
||||
throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"');
|
||||
break;
|
||||
case 'create_another':
|
||||
case 'update':
|
||||
$messages = $repos->validate($data);
|
||||
/** @var MessageBag $messages ['errors'] */
|
||||
if ($messages['errors']->count() > 0) {
|
||||
Session::flash('warnings', $messages['warnings']);
|
||||
Session::flash('successes', $messages['successes']);
|
||||
Session::flash('error', 'Could not save piggy bank: ' . $messages['errors']->first());
|
||||
return Redirect::route('piggybanks.edit', $piggyBank->id)->withInput()->withErrors($messages['errors']);
|
||||
}
|
||||
// store!
|
||||
$repos->update($piggyBank, $data);
|
||||
Session::flash('success', 'Piggy bank updated!');
|
||||
|
||||
if ($data['post_submit_action'] == 'create_another') {
|
||||
return Redirect::route('piggybanks.edit', $piggyBank->id);
|
||||
} else {
|
||||
Session::flash('error', 'Could not update piggy bank: ' . $piggyBank->errors()->first());
|
||||
|
||||
return Redirect::route('piggybanks.edit', $piggyBank->id)->withErrors($piggyBank->errors())->withInput();
|
||||
return Redirect::route('piggybanks.index');
|
||||
}
|
||||
case 'validate_only':
|
||||
$messageBags = $repos->validate($data);
|
||||
Session::flash('warnings', $messageBags['warnings']);
|
||||
Session::flash('successes', $messageBags['successes']);
|
||||
Session::flash('errors', $messageBags['errors']);
|
||||
return Redirect::route('piggybanks.edit', $piggyBank->id)->withInput();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
|
||||
/**
|
||||
* Class PreferencesController
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class PreferencesController extends BaseController
|
||||
{
|
||||
@@ -20,6 +22,8 @@ class PreferencesController extends BaseController
|
||||
|
||||
$this->_accounts = $accounts;
|
||||
$this->_preferences = $preferences;
|
||||
View::share('title','Preferences');
|
||||
View::share('mainTitleIcon','fa-gear');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,9 @@ class ProfileController extends BaseController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
View::share('title', 'Profile');
|
||||
View::share('subTitle', Auth::user()->email);
|
||||
View::share('mainTitleIcon', 'fa-user');
|
||||
return View::make('profile.index');
|
||||
}
|
||||
|
||||
@@ -30,6 +33,9 @@ class ProfileController extends BaseController
|
||||
*/
|
||||
public function changePassword()
|
||||
{
|
||||
View::share('title', Auth::user()->email);
|
||||
View::share('subTitle', 'Change your password');
|
||||
View::share('mainTitleIcon', 'fa-user');
|
||||
return View::make('profile.change-password');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Firefly\Exception\FireflyException;
|
||||
use Firefly\Storage\RecurringTransaction\RecurringTransactionRepositoryInterface as RTR;
|
||||
use Firefly\Helper\Controllers\RecurringInterface as RI;
|
||||
|
||||
/**
|
||||
* Class RecurringController
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class RecurringController extends BaseController
|
||||
{
|
||||
protected $_repository;
|
||||
protected $_helper;
|
||||
|
||||
/**
|
||||
* @param RTR $repository
|
||||
* @param RI $helper
|
||||
*/
|
||||
public function __construct(RTR $repository)
|
||||
public function __construct(RTR $repository, RI $helper)
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
$this->_helper = $helper;
|
||||
|
||||
View::share('title', 'Recurring transactions');
|
||||
View::share('mainTitleIcon', 'fa-rotate-right');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -22,6 +32,7 @@ class RecurringController extends BaseController
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
View::share('subTitle', 'Create new');
|
||||
$periods = \Config::get('firefly.periods_to_text');
|
||||
|
||||
return View::make('recurring.create')->with('periods', $periods);
|
||||
@@ -34,6 +45,7 @@ class RecurringController extends BaseController
|
||||
*/
|
||||
public function delete(RecurringTransaction $recurringTransaction)
|
||||
{
|
||||
View::share('subTitle', 'Delete "' . $recurringTransaction->name . '"');
|
||||
return View::make('recurring.delete')->with('recurringTransaction', $recurringTransaction);
|
||||
}
|
||||
|
||||
@@ -44,7 +56,7 @@ class RecurringController extends BaseController
|
||||
*/
|
||||
public function destroy(RecurringTransaction $recurringTransaction)
|
||||
{
|
||||
Event::fire('recurring.destroy', [$recurringTransaction]);
|
||||
//Event::fire('recurring.destroy', [$recurringTransaction]);
|
||||
$result = $this->_repository->destroy($recurringTransaction);
|
||||
if ($result === true) {
|
||||
Session::flash('success', 'The recurring transaction was deleted.');
|
||||
@@ -65,6 +77,8 @@ class RecurringController extends BaseController
|
||||
{
|
||||
$periods = \Config::get('firefly.periods_to_text');
|
||||
|
||||
View::share('subTitle', 'Edit "' . $recurringTransaction->name . '"');
|
||||
|
||||
return View::make('recurring.edit')->with('periods', $periods)->with(
|
||||
'recurringTransaction', $recurringTransaction
|
||||
);
|
||||
@@ -75,9 +89,7 @@ class RecurringController extends BaseController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$list = $this->_repository->get();
|
||||
|
||||
return View::make('recurring.index')->with('list', $list);
|
||||
return View::make('recurring.index');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,53 +97,142 @@ class RecurringController extends BaseController
|
||||
*/
|
||||
public function show(RecurringTransaction $recurringTransaction)
|
||||
{
|
||||
View::share('subTitle', $recurringTransaction->name);
|
||||
return View::make('recurring.show')->with('recurring', $recurringTransaction);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
* @param RecurringTransaction $recurringTransaction
|
||||
* @return mixed
|
||||
*/
|
||||
public function rescan(RecurringTransaction $recurringTransaction)
|
||||
{
|
||||
if (intval($recurringTransaction->active) == 0) {
|
||||
Session::flash('warning', 'Inactive recurring transactions cannot be scanned.');
|
||||
return Redirect::back();
|
||||
}
|
||||
// do something!
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $repo */
|
||||
$repo = App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$set = $repo->get();
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($set as $journal) {
|
||||
Event::fire('recurring.rescan', [$recurringTransaction, $journal]);
|
||||
}
|
||||
Session::flash('success', 'Rescanned everything.');
|
||||
return Redirect::back();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
$recurringTransaction = $this->_repository->store(Input::all());
|
||||
if ($recurringTransaction->validate()) {
|
||||
Session::flash('success', 'Recurring transaction "' . $recurringTransaction->name . '" saved!');
|
||||
Event::fire('recurring.store', [$recurringTransaction]);
|
||||
if (Input::get('create') == '1') {
|
||||
$data = Input::except(['_token', 'post_submit_action']);
|
||||
switch (Input::get('post_submit_action')) {
|
||||
default:
|
||||
throw new FireflyException('Method ' . Input::get('post_submit_action') . ' not implemented yet.');
|
||||
break;
|
||||
case 'store':
|
||||
case 'create_another':
|
||||
/*
|
||||
* Try to store:
|
||||
*/
|
||||
$messageBag = $this->_repository->store($data);
|
||||
|
||||
/*
|
||||
* Failure!
|
||||
*/
|
||||
if ($messageBag->count() > 0) {
|
||||
Session::flash('error', 'Could not save recurring transaction: ' . $messageBag->first());
|
||||
return Redirect::route('recurring.create')->withInput()->withErrors($messageBag);
|
||||
}
|
||||
|
||||
/*
|
||||
* Success!
|
||||
*/
|
||||
Session::flash('success', 'Recurring transaction "' . e(Input::get('name')) . '" saved!');
|
||||
|
||||
/*
|
||||
* Redirect to original location or back to the form.
|
||||
*/
|
||||
if (Input::get('post_submit_action') == 'create_another') {
|
||||
return Redirect::route('recurring.create')->withInput();
|
||||
} else {
|
||||
return Redirect::route('recurring.index');
|
||||
}
|
||||
} else {
|
||||
Session::flash(
|
||||
'error', 'Could not save the recurring transaction: ' . $recurringTransaction->errors()->first()
|
||||
);
|
||||
break;
|
||||
case 'validate_only':
|
||||
$messageBags = $this->_helper->validate($data);
|
||||
|
||||
Session::flash('warnings', $messageBags['warnings']);
|
||||
Session::flash('successes', $messageBags['successes']);
|
||||
Session::flash('errors', $messageBags['errors']);
|
||||
return Redirect::route('recurring.create')->withInput();
|
||||
break;
|
||||
}
|
||||
|
||||
return Redirect::route('recurring.create')->withInput()->withErrors($recurringTransaction->errors());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RecurringTransaction $recurringTransaction
|
||||
*/
|
||||
public function update(RecurringTransaction $recurringTransaction)
|
||||
{
|
||||
/** @var \RecurringTransaction $recurringTransaction */
|
||||
$recurringTransaction = $this->_repository->update($recurringTransaction, Input::all());
|
||||
if ($recurringTransaction->errors()->count() == 0) {
|
||||
Session::flash('success', 'The recurring transaction has been updated.');
|
||||
Event::fire('recurring.update', [$recurringTransaction]);
|
||||
$data = Input::except(['_token', 'post_submit_action']);
|
||||
switch (Input::get('post_submit_action')) {
|
||||
case 'update':
|
||||
case 'return_to_edit':
|
||||
$messageBag = $this->_repository->update($recurringTransaction, $data);
|
||||
if ($messageBag->count() == 0) {
|
||||
// has been saved, return to index:
|
||||
Session::flash('success', 'Recurring transaction updated!');
|
||||
|
||||
return Redirect::route('recurring.index');
|
||||
if (Input::get('post_submit_action') == 'return_to_edit') {
|
||||
return Redirect::route('recurring.edit', $recurringTransaction->id)->withInput();
|
||||
} else {
|
||||
Session::flash(
|
||||
'error', 'Could not update the recurring transaction: ' . $recurringTransaction->errors()->first()
|
||||
);
|
||||
|
||||
return Redirect::route('recurring.edit', $recurringTransaction->id)->withInput()->withErrors(
|
||||
$recurringTransaction->errors()
|
||||
);
|
||||
return Redirect::route('recurring.index');
|
||||
}
|
||||
} else {
|
||||
Session::flash('error', 'Could not update recurring transaction: ' . $messageBag->first());
|
||||
|
||||
return Redirect::route('transactions.edit', $recurringTransaction->id)->withInput()
|
||||
->withErrors($messageBag);
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case 'validate_only':
|
||||
$data = Input::all();
|
||||
$data['id'] = $recurringTransaction->id;
|
||||
$messageBags = $this->_helper->validate($data);
|
||||
|
||||
Session::flash('warnings', $messageBags['warnings']);
|
||||
Session::flash('successes', $messageBags['successes']);
|
||||
Session::flash('errors', $messageBags['errors']);
|
||||
return Redirect::route('recurring.edit', $recurringTransaction->id)->withInput();
|
||||
|
||||
break;
|
||||
// update
|
||||
default:
|
||||
throw new FireflyException('Method ' . Input::get('post_submit_action') . ' not implemented yet.');
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// /** @var \RecurringTransaction $recurringTransaction */
|
||||
// $recurringTransaction = $this->_repository->update($recurringTransaction, Input::all());
|
||||
// if ($recurringTransaction->errors()->count() == 0) {
|
||||
// Session::flash('success', 'The recurring transaction has been updated.');
|
||||
// //Event::fire('recurring.update', [$recurringTransaction]);
|
||||
//
|
||||
// return Redirect::route('recurring.index');
|
||||
// } else {
|
||||
// Session::flash(
|
||||
// 'error', 'Could not update the recurring transaction: ' . $recurringTransaction->errors()->first()
|
||||
// );
|
||||
//
|
||||
// return Redirect::route('recurring.edit', $recurringTransaction->id)->withInput()->withErrors(
|
||||
// $recurringTransaction->errors()
|
||||
// );
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -1,89 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Firefly\Storage\Reminder\ReminderRepositoryInterface as RRI;
|
||||
|
||||
/**
|
||||
* Class ReminderController
|
||||
*
|
||||
*/
|
||||
class ReminderController extends BaseController
|
||||
{
|
||||
|
||||
protected $_repository;
|
||||
|
||||
public function __construct(RRI $repository)
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Reminder $reminder
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function dismiss(\Reminder $reminder)
|
||||
{
|
||||
$reminder = $this->_repository->deactivate($reminder);
|
||||
|
||||
return Response::json($reminder->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reminders currently active for the modal dialog.
|
||||
*/
|
||||
public function modalDialog()
|
||||
{
|
||||
$today = new Carbon;
|
||||
$reminders = $this->_repository->get();
|
||||
|
||||
/** @var \Reminder $reminder */
|
||||
foreach ($reminders as $index => $reminder) {
|
||||
if (\Session::has('dismissal-' . $reminder->id)) {
|
||||
$time = \Session::get('dismissal-' . $reminder->id);
|
||||
if ($time >= $today) {
|
||||
unset($reminders[$index]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return View::make('reminders.popup')->with('reminders', $reminders);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Reminder $reminder
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function postpone(\Reminder $reminder)
|
||||
{
|
||||
$now = new Carbon;
|
||||
$now->addDay();
|
||||
Session::put('dismissal-' . $reminder->id, $now);
|
||||
|
||||
return Response::json($reminder->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Reminder $reminder
|
||||
*/
|
||||
public function redirect(\Reminder $reminder)
|
||||
{
|
||||
if ($reminder instanceof PiggybankReminder) {
|
||||
// fields to prefill:
|
||||
$parameters = [
|
||||
'account_to_id' => $reminder->piggybank->account->id,
|
||||
'amount' => round($reminder->amountToSave(), 2),
|
||||
'description' => 'Money for ' . $reminder->piggybank->name,
|
||||
'piggybank_id' => $reminder->piggybank->id,
|
||||
'reminder_id' => $reminder->id
|
||||
];
|
||||
|
||||
return Redirect::to(
|
||||
route('transactions.create', ['what' => 'transfer']) . '?' . http_build_query($parameters)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class ReportController
|
||||
@@ -12,7 +13,55 @@ class ReportController extends BaseController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
/** @var \FireflyIII\Database\TransactionJournal $journals */
|
||||
$journals = App::make('FireflyIII\Database\TransactionJournal');
|
||||
$journal = $journals->first();
|
||||
|
||||
$date = $journal->date;
|
||||
$years = [];
|
||||
while ($date <= Carbon::now()) {
|
||||
$years[] = $date->format('Y');
|
||||
$date->addYear();
|
||||
}
|
||||
|
||||
|
||||
return View::make('reports.index', compact('years'))->with('title', 'Reports')->with('mainTitleIcon', 'fa-line-chart');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $year
|
||||
*/
|
||||
public function year($year)
|
||||
{
|
||||
try {
|
||||
$date = new Carbon('01-01-' . $year);
|
||||
} catch (Exception $e) {
|
||||
App::abort(500);
|
||||
}
|
||||
|
||||
/** @var \FireflyIII\Database\TransactionJournal $tj */
|
||||
$tj = App::make('FireflyIII\Database\TransactionJournal');
|
||||
|
||||
// get some sums going
|
||||
$summary = [];
|
||||
|
||||
|
||||
$end = clone $date;
|
||||
$end->endOfYear();
|
||||
while ($date < $end) {
|
||||
$summary[] = [
|
||||
'month' => $date->format('F'),
|
||||
'income' => $tj->getSumOfIncomesByMonth($date),
|
||||
'expense' => $tj->getSumOfExpensesByMonth($date),
|
||||
];
|
||||
$date->addMonth();
|
||||
}
|
||||
|
||||
|
||||
// draw some charts etc.
|
||||
return View::make('reports.year', compact('summary'))->with('title', 'Reports')->with('mainTitleIcon', 'fa-line-chart')->with('subTitle', $year)->with(
|
||||
'subTitleIcon', 'fa-bar-chart'
|
||||
)->with('year', $year);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,50 @@
|
||||
<?php
|
||||
|
||||
use Firefly\Helper\Controllers\SearchInterface as SI;
|
||||
|
||||
/**
|
||||
* Class SearchController
|
||||
*/
|
||||
class SearchController extends BaseController
|
||||
{
|
||||
protected $_helper;
|
||||
|
||||
public function __construct(SI $helper)
|
||||
{
|
||||
$this->_helper = $helper;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Results always come in the form of an array [results, count, fullCount]
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$subTitle = null;
|
||||
$rawQuery = null;
|
||||
$result = [];
|
||||
if (!is_null(Input::get('q'))) {
|
||||
$rawQuery = trim(Input::get('q'));
|
||||
$words = explode(' ', $rawQuery);
|
||||
$subTitle = 'Results for "' . e($rawQuery) . '"';
|
||||
|
||||
$transactions = $this->_helper->searchTransactions($words);
|
||||
$accounts = $this->_helper->searchAccounts($words);
|
||||
$categories = $this->_helper->searchCategories($words);
|
||||
$budgets = $this->_helper->searchBudgets($words);
|
||||
$tags = $this->_helper->searchTags($words);
|
||||
$result = [
|
||||
'transactions' => $transactions,
|
||||
'accounts' => $accounts,
|
||||
'categories' => $categories,
|
||||
'budgets' => $budgets,
|
||||
'tags' => $tags
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
return View::make('search.index')->with('title', 'Search')->with('subTitle', $subTitle)->with(
|
||||
'mainTitleIcon', 'fa-search'
|
||||
)->with('query', $rawQuery)->with('result',$result);
|
||||
}
|
||||
}
|
||||
@@ -1,61 +1,103 @@
|
||||
<?php
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Firefly\Exception\FireflyException;
|
||||
use Firefly\Helper\Controllers\TransactionInterface as TI;
|
||||
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
* Class TransactionController
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*
|
||||
*/
|
||||
class TransactionController extends BaseController
|
||||
{
|
||||
|
||||
protected $_helper;
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* Construct a new transaction controller with two of the most often used helpers.
|
||||
*
|
||||
* @param TJRI $repository
|
||||
* @param TI $helper
|
||||
*/
|
||||
public function __construct(TJRI $repository)
|
||||
public function __construct(TJRI $repository, TI $helper)
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
$this->_helper = $helper;
|
||||
View::share('title', 'Transactions');
|
||||
View::share('mainTitleIcon', 'fa-repeat');
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the view helping the user to create a new transaction journal.
|
||||
*
|
||||
* @param string $what
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create($what = 'deposit')
|
||||
{
|
||||
// get accounts with names and id's.
|
||||
/*
|
||||
* The repositories we need:
|
||||
*/
|
||||
/** @var \Firefly\Helper\Toolkit\Toolkit $toolkit */
|
||||
$toolkit = App::make('Firefly\Helper\Toolkit\Toolkit');
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts = $accountRepository->getActiveDefaultAsSelectList();
|
||||
|
||||
// get budgets as a select list.
|
||||
/** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budgetRepository */
|
||||
$budgetRepository = App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets = $budgetRepository->getAsSelectList();
|
||||
|
||||
/** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface $piggyRepository */
|
||||
$piggyRepository = App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
|
||||
// get asset accounts with names and id's.
|
||||
$assetAccounts = $toolkit->makeSelectList($accountRepository->getActiveDefault());
|
||||
|
||||
// get budgets as a select list.
|
||||
$budgets = $toolkit->makeSelectList($budgetRepository->get());
|
||||
$budgets[0] = '(no budget)';
|
||||
|
||||
// get the piggy banks.
|
||||
/** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface $piggyRepository */
|
||||
$piggyRepository = App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
$piggies = $piggyRepository->get();
|
||||
$piggies = $toolkit->makeSelectList($piggyRepository->get());
|
||||
$piggies[0] = '(no piggy bank)';
|
||||
|
||||
return View::make('transactions.create')->with('accounts', $accounts)->with('budgets', $budgets)->with(
|
||||
/*
|
||||
* respond to a possible given values in the URL.
|
||||
*/
|
||||
$prefilled = Session::has('prefilled') ? Session::get('prefilled') : [];
|
||||
$respondTo = ['account_id', 'account_from_id'];
|
||||
foreach ($respondTo as $r) {
|
||||
if (!is_null(Input::get($r))) {
|
||||
$prefilled[$r] = Input::get($r);
|
||||
}
|
||||
}
|
||||
Session::put('prefilled', $prefilled);
|
||||
|
||||
return View::make('transactions.create')->with('accounts', $assetAccounts)->with('budgets', $budgets)->with(
|
||||
'what', $what
|
||||
)->with('piggies', $piggies);
|
||||
)->with('piggies', $piggies)->with('subTitle', 'Add a new ' . $what);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the form that allows a user to delete a transaction journal.
|
||||
*
|
||||
* @param TransactionJournal $transactionJournal
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function delete(TransactionJournal $transactionJournal)
|
||||
{
|
||||
return View::make('transactions.delete')->with('journal', $transactionJournal);
|
||||
$type = strtolower($transactionJournal->transactionType->type);
|
||||
|
||||
return View::make('transactions.delete')->with('journal', $transactionJournal)->with(
|
||||
'subTitle', 'Delete ' . $type . ' "' . $transactionJournal->description . '"'
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
@@ -68,103 +110,142 @@ class TransactionController extends BaseController
|
||||
*/
|
||||
public function destroy(TransactionJournal $transactionJournal)
|
||||
{
|
||||
$type = $transactionJournal->transactionType->type;
|
||||
$transactionJournal->delete();
|
||||
|
||||
return Redirect::route('transactions.index');
|
||||
|
||||
switch ($type) {
|
||||
case 'Withdrawal':
|
||||
return Redirect::route('transactions.expenses');
|
||||
break;
|
||||
case 'Deposit':
|
||||
return Redirect::route('transactions.revenue');
|
||||
break;
|
||||
case 'Transfer':
|
||||
return Redirect::route('transactions.transfers');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the view to edit a transaction.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function edit(TransactionJournal $journal)
|
||||
{
|
||||
/*
|
||||
* All the repositories we need:
|
||||
*/
|
||||
/** @var \Firefly\Helper\Toolkit\Toolkit $toolkit */
|
||||
$toolkit = App::make('Firefly\Helper\Toolkit\Toolkit');
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budgetRepository */
|
||||
$budgetRepository = App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface $piggyRepository */
|
||||
$piggyRepository = App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
|
||||
// type is useful for display:
|
||||
$what = strtolower($journal->transactiontype->type);
|
||||
|
||||
// some lists prefilled:
|
||||
// get accounts with names and id's.
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts = $accountRepository->getActiveDefaultAsSelectList();
|
||||
// get asset accounts with names and id's.
|
||||
$accounts = $toolkit->makeSelectList($accountRepository->getActiveDefault());
|
||||
|
||||
// get budgets as a select list.
|
||||
/** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budgetRepository */
|
||||
$budgetRepository = App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets = $budgetRepository->getAsSelectList();
|
||||
$budgets = $toolkit->makeSelectList($budgetRepository->get());
|
||||
$budgets[0] = '(no budget)';
|
||||
|
||||
/*
|
||||
* Get all piggy banks plus (if any) the relevant piggy bank. Since just one
|
||||
* of the transactions in the journal has this field, it should all fill in nicely.
|
||||
*/
|
||||
// get the piggy banks.
|
||||
/** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface $piggyRepository */
|
||||
$piggyRepository = App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
$piggies = $piggyRepository->get();
|
||||
// piggy bank id?
|
||||
$piggyBankId = null;
|
||||
$piggies = $toolkit->makeSelectList($piggyRepository->get());
|
||||
$piggies[0] = '(no piggy bank)';
|
||||
$piggyBankId = 0;
|
||||
foreach ($journal->transactions as $t) {
|
||||
if (!is_null($t->piggybank_id)) {
|
||||
$piggyBankId = $t->piggybank_id;
|
||||
}
|
||||
}
|
||||
|
||||
// data to properly display form:
|
||||
$data = [
|
||||
/*
|
||||
* Data to properly display the edit form.
|
||||
*/
|
||||
$prefilled = [
|
||||
'date' => $journal->date->format('Y-m-d'),
|
||||
'category' => '',
|
||||
'budget_id' => 0,
|
||||
'piggybank_id' => $piggyBankId
|
||||
];
|
||||
|
||||
/*
|
||||
* Fill in the category.
|
||||
*/
|
||||
$category = $journal->categories()->first();
|
||||
if (!is_null($category)) {
|
||||
$data['category'] = $category->name;
|
||||
$prefilled['category'] = $category->name;
|
||||
}
|
||||
switch ($journal->transactiontype->type) {
|
||||
case 'Withdrawal':
|
||||
$data['account_id'] = $journal->transactions[0]->account->id;
|
||||
$data['beneficiary'] = $journal->transactions[1]->account->name;
|
||||
$data['amount'] = floatval($journal->transactions[1]->amount);
|
||||
|
||||
/*
|
||||
* Switch on the type of transaction edited by the user and fill in other
|
||||
* relevant fields:
|
||||
*/
|
||||
switch ($what) {
|
||||
case 'withdrawal':
|
||||
$prefilled['account_id'] = $journal->transactions[0]->account->id;
|
||||
$prefilled['expense_account'] = $journal->transactions[1]->account->name;
|
||||
$prefilled['amount'] = floatval($journal->transactions[1]->amount);
|
||||
$budget = $journal->budgets()->first();
|
||||
if (!is_null($budget)) {
|
||||
$data['budget_id'] = $budget->id;
|
||||
$prefilled['budget_id'] = $budget->id;
|
||||
}
|
||||
break;
|
||||
case 'Deposit':
|
||||
$data['account_id'] = $journal->transactions[1]->account->id;
|
||||
$data['beneficiary'] = $journal->transactions[0]->account->name;
|
||||
$data['amount'] = floatval($journal->transactions[1]->amount);
|
||||
case 'deposit':
|
||||
$prefilled['account_id'] = $journal->transactions[1]->account->id;
|
||||
$prefilled['revenue_account'] = $journal->transactions[0]->account->name;
|
||||
$prefilled['amount'] = floatval($journal->transactions[1]->amount);
|
||||
break;
|
||||
case 'Transfer':
|
||||
$data['account_from_id'] = $journal->transactions[1]->account->id;
|
||||
$data['account_to_id'] = $journal->transactions[0]->account->id;
|
||||
$data['amount'] = floatval($journal->transactions[1]->amount);
|
||||
case 'transfer':
|
||||
$prefilled['account_from_id'] = $journal->transactions[1]->account->id;
|
||||
$prefilled['account_to_id'] = $journal->transactions[0]->account->id;
|
||||
$prefilled['amount'] = floatval($journal->transactions[1]->amount);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Show the view.
|
||||
*/
|
||||
return View::make('transactions.edit')->with('journal', $journal)->with('accounts', $accounts)->with(
|
||||
'what', $what
|
||||
)->with('budgets', $budgets)->with('data', $data)->with('piggies', $piggies);
|
||||
)->with('budgets', $budgets)->with('data', $prefilled)->with('piggies', $piggies)->with(
|
||||
'subTitle', 'Edit ' . $what . ' "' . $journal->description . '"'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this|\Illuminate\View\View
|
||||
* @return $this
|
||||
*/
|
||||
public function index()
|
||||
public function expenses()
|
||||
{
|
||||
$start = is_null(Input::get('startdate')) ? null : new Carbon(Input::get('startdate'));
|
||||
$end = is_null(Input::get('enddate')) ? null : new Carbon(Input::get('enddate'));
|
||||
if ($start <= $end && !is_null($start) && !is_null($end)) {
|
||||
$journals = $this->_repository->paginate(25, $start, $end);
|
||||
$filtered = true;
|
||||
$filters = ['start' => $start, 'end' => $end];
|
||||
} else {
|
||||
$journals = $this->_repository->paginate(25);
|
||||
$filtered = false;
|
||||
$filters = null;
|
||||
return View::make('transactions.list')->with('subTitle', 'Expenses')->with(
|
||||
'subTitleIcon', 'fa-long-arrow-left'
|
||||
)->with('what', 'expenses');
|
||||
}
|
||||
|
||||
|
||||
return View::make('transactions.index')->with('journals', $journals)->with('filtered', $filtered)->with(
|
||||
'filters', $filters
|
||||
);
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function revenue()
|
||||
{
|
||||
return View::make('transactions.list')->with('subTitle', 'Revenue')->with(
|
||||
'subTitleIcon', 'fa-long-arrow-right'
|
||||
)->with('what', 'revenue');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,63 +255,122 @@ class TransactionController extends BaseController
|
||||
*/
|
||||
public function show(TransactionJournal $journal)
|
||||
{
|
||||
return View::make('transactions.show')->with('journal', $journal);
|
||||
return View::make('transactions.show')->with('journal', $journal)->with(
|
||||
'subTitle', $journal->transactionType->type . ' "' . $journal->description . '"'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $what
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store($what)
|
||||
{
|
||||
$journal = $this->_repository->store($what, Input::all());
|
||||
if ($journal->validate()) {
|
||||
Session::flash('success', 'Transaction "' . $journal->description . '" saved!');
|
||||
/*
|
||||
* Collect data to process:
|
||||
*/
|
||||
$data = Input::except(['_token']);
|
||||
$data['what'] = $what;
|
||||
|
||||
// if reminder present, deactivate it:
|
||||
if (Input::get('reminder')) {
|
||||
/** @var \Firefly\Storage\Reminder\ReminderRepositoryInterface $reminders */
|
||||
$reminders = App::make('Firefly\Storage\Reminder\ReminderRepositoryInterface');
|
||||
$reminder = $reminders->find(Input::get('reminder'));
|
||||
$reminders->deactivate($reminder);
|
||||
switch (Input::get('post_submit_action')) {
|
||||
case 'store':
|
||||
case 'create_another':
|
||||
/*
|
||||
* Try to store:
|
||||
*/
|
||||
$messageBag = $this->_helper->store($data);
|
||||
|
||||
/*
|
||||
* Failure!
|
||||
*/
|
||||
if ($messageBag->count() > 0) {
|
||||
Session::flash('error', 'Could not save transaction: ' . $messageBag->first());
|
||||
return Redirect::route('transactions.create', [$what])->withInput()->withErrors($messageBag);
|
||||
}
|
||||
|
||||
// trigger the creation for recurring transactions.
|
||||
/*
|
||||
* Success!
|
||||
*/
|
||||
Session::flash('success', 'Transaction "' . e(Input::get('description')) . '" saved!');
|
||||
|
||||
if (Input::get('create') == '1') {
|
||||
/*
|
||||
* Redirect to original location or back to the form.
|
||||
*/
|
||||
if (Input::get('post_submit_action') == 'create_another') {
|
||||
return Redirect::route('transactions.create', $what)->withInput();
|
||||
} else {
|
||||
return Redirect::route('transactions.index.' . $what);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'validate_only':
|
||||
$messageBags = $this->_helper->validate($data);
|
||||
|
||||
Session::flash('warnings', $messageBags['warnings']);
|
||||
Session::flash('successes', $messageBags['successes']);
|
||||
Session::flash('errors', $messageBags['errors']);
|
||||
return Redirect::route('transactions.create', [$what])->withInput();
|
||||
} else {
|
||||
return Redirect::route('transactions.index');
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException('Method ' . Input::get('post_submit_action') . ' not implemented yet.');
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
Session::flash('error', 'Could not save transaction: ' . $journal->errors()->first());
|
||||
|
||||
return Redirect::route('transactions.create', [$what])->withInput()->withErrors(
|
||||
$journal->errors()
|
||||
);
|
||||
}
|
||||
|
||||
public function transfers()
|
||||
{
|
||||
return View::make('transactions.list')->with('subTitle', 'Transfers')->with(
|
||||
'subTitleIcon', 'fa-arrows-h'
|
||||
)->with('what', 'transfers');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(TransactionJournal $journal)
|
||||
{
|
||||
$journal = $this->_repository->update($journal, Input::all());
|
||||
if ($journal->validate()) {
|
||||
switch (Input::get('post_submit_action')) {
|
||||
case 'update':
|
||||
case 'return_to_edit':
|
||||
$what = strtolower($journal->transactionType->type);
|
||||
$messageBag = $this->_helper->update($journal, Input::all());
|
||||
if ($messageBag->count() == 0) {
|
||||
// has been saved, return to index:
|
||||
Session::flash('success', 'Transaction updated!');
|
||||
Event::fire('journals.update', [$journal]);
|
||||
|
||||
return Redirect::route('transactions.index');
|
||||
if (Input::get('post_submit_action') == 'return_to_edit') {
|
||||
return Redirect::route('transactions.edit', $journal->id)->withInput();
|
||||
} else {
|
||||
return Redirect::route('transactions.index.' . $what);
|
||||
}
|
||||
} else {
|
||||
Session::flash('error', 'Could not update transaction: ' . $journal->errors()->first());
|
||||
|
||||
return Redirect::route('transactions.edit', $journal->id)->withInput()->withErrors($journal->errors());
|
||||
return Redirect::route('transactions.edit', $journal->id)->withInput()->withErrors(
|
||||
$journal->errors()
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
case 'validate_only':
|
||||
$data = Input::all();
|
||||
$data['what'] = strtolower($journal->transactionType->type);
|
||||
$messageBags = $this->_helper->validate($data);
|
||||
|
||||
Session::flash('warnings', $messageBags['warnings']);
|
||||
Session::flash('successes', $messageBags['successes']);
|
||||
Session::flash('errors', $messageBags['errors']);
|
||||
return Redirect::route('transactions.edit', $journal->id)->withInput();
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException('Method ' . Input::get('post_submit_action') . ' not implemented yet.');
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -47,8 +47,6 @@ class UserController extends BaseController
|
||||
];
|
||||
$result = Auth::attempt($data, $rememberMe);
|
||||
if ($result) {
|
||||
Session::flash('success', 'Logged in!');
|
||||
|
||||
return Redirect::route('index');
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ class CreatePiggybanksTable extends Migration
|
||||
$table->smallInteger('rep_times')->unsigned()->nullable();
|
||||
$table->enum('reminder', ['day', 'week', 'month', 'year'])->nullable();
|
||||
$table->smallInteger('reminder_skip')->unsigned();
|
||||
$table->boolean('remind_me');
|
||||
$table->integer('order')->unsigned();
|
||||
|
||||
// connect account to piggybank.
|
||||
|
||||
@@ -25,8 +25,8 @@ class CreateRecurringTransactionsTable extends Migration
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->string('name', 50);
|
||||
$table->string('match', 255);
|
||||
$table->decimal('amount_max', 10, 2);
|
||||
$table->decimal('amount_min', 10, 2);
|
||||
$table->decimal('amount_max', 10, 2);
|
||||
$table->date('date');
|
||||
$table->boolean('active');
|
||||
|
||||
@@ -24,6 +24,7 @@ class CreateTransactionJournalsTable extends Migration
|
||||
$table->timestamps();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->integer('transaction_type_id')->unsigned();
|
||||
$table->integer('recurring_transaction_id')->unsigned()->nullable();
|
||||
$table->integer('transaction_currency_id')->unsigned();
|
||||
$table->string('description', 255)->nullable();
|
||||
$table->boolean('completed');
|
||||
@@ -34,6 +35,11 @@ class CreateTransactionJournalsTable extends Migration
|
||||
->references('id')->on('transaction_types')
|
||||
->onDelete('cascade');
|
||||
|
||||
// connect transaction journals to recurring transactions
|
||||
$table->foreign('recurring_transaction_id')
|
||||
->references('id')->on('recurring_transactions')
|
||||
->onDelete('set null');
|
||||
|
||||
// connect transaction journals to transaction currencies
|
||||
$table->foreign('transaction_currency_id')
|
||||
->references('id')->on('transaction_currencies')
|
||||
|
||||
@@ -27,26 +27,11 @@ class CreateRemindersTable extends Migration
|
||||
'reminders', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->string('class', 40);
|
||||
$table->integer('piggybank_id')->unsigned()->nullable();
|
||||
$table->integer('recurring_transaction_id')->unsigned()->nullable();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->date('startdate');
|
||||
$table->date('enddate');
|
||||
$table->date('enddate')->nullable();
|
||||
$table->boolean('active');
|
||||
|
||||
|
||||
// connect reminders to piggy banks.
|
||||
$table->foreign('piggybank_id')
|
||||
->references('id')->on('piggybanks')
|
||||
->onDelete('set null');
|
||||
|
||||
// connect reminders to recurring transactions.
|
||||
$table->foreign('recurring_transaction_id')
|
||||
->references('id')->on('recurring_transactions')
|
||||
->onDelete('set null');
|
||||
|
||||
|
||||
// connect reminders to users
|
||||
$table->foreign('user_id')
|
||||
->references('id')->on('users')
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateImportmapsTable extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('importmaps', function(Blueprint $table)
|
||||
{
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->string('file',500);
|
||||
$table->integer('totaljobs')->unsigned();
|
||||
$table->integer('jobsdone')->unsigned();
|
||||
|
||||
// connect maps to users
|
||||
$table->foreign('user_id')
|
||||
->references('id')->on('users')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('importmaps');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateImportentriesTable extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('importentries', function(Blueprint $table)
|
||||
{
|
||||
$table->increments('id');
|
||||
$table->timestamps();
|
||||
$table->string('class',200);
|
||||
$table->integer('importmap_id')->unsigned();
|
||||
$table->integer('old')->unsigned();
|
||||
$table->integer('new')->unsigned();
|
||||
|
||||
// map import entries to import map.
|
||||
// connect accounts to account_types
|
||||
$table->foreign('importmap_id')
|
||||
->references('id')->on('importmaps')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('importentries');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateFailedJobsTable extends Migration
|
||||
{
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('failed_jobs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->text('payload');
|
||||
$table->timestamp('failed_at');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,16 +11,29 @@ class AccountTypeSeeder extends Seeder
|
||||
DB::table('account_types')->delete();
|
||||
|
||||
AccountType::create(
|
||||
['type' => 'Default account','editable' => true]
|
||||
['type' => 'Default account', 'editable' => true]
|
||||
);
|
||||
AccountType::create(
|
||||
['type' => 'Cash account','editable' => false]
|
||||
['type' => 'Cash account', 'editable' => false]
|
||||
);
|
||||
AccountType::create(
|
||||
['type' => 'Initial balance account','editable' => false]
|
||||
['type' => 'Asset account', 'editable' => true]
|
||||
);
|
||||
AccountType::create(
|
||||
['type' => 'Beneficiary account','editable' => true]
|
||||
['type' => 'Expense account', 'editable' => true]
|
||||
);
|
||||
AccountType::create(
|
||||
['type' => 'Revenue account', 'editable' => true]
|
||||
);
|
||||
AccountType::create(
|
||||
['type' => 'Initial balance account', 'editable' => false]
|
||||
);
|
||||
AccountType::create(
|
||||
['type' => 'Beneficiary account', 'editable' => true]
|
||||
);
|
||||
|
||||
AccountType::create(
|
||||
['type' => 'Import account', 'editable' => false]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,11 @@ App::before(
|
||||
function ($request) {
|
||||
|
||||
if (Auth::check()) {
|
||||
/** @var \Firefly\Helper\Toolkit\ToolkitInterface $toolkit */
|
||||
$toolkit = App::make('Firefly\Helper\Toolkit\ToolkitInterface');
|
||||
$toolkit->getDateRange($request);
|
||||
$toolkit->getReminders();
|
||||
|
||||
$toolkit->getDateRange();
|
||||
$toolkit->checkImportJobs();
|
||||
Event::fire('recurring.verify');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
namespace Firefly\Database;
|
||||
|
||||
use LaravelBook\Ardent\Ardent;
|
||||
@@ -73,7 +70,7 @@ abstract class SingleTableInheritanceEntity extends Ardent
|
||||
// newEloquentBuilder() was added in 4.1
|
||||
$builder = $this->newEloquentBuilder($this->newBaseQueryBuilder());
|
||||
|
||||
// Once we have the query builders, we will set the model instances so the
|
||||
// Once Firefly has the query builders, it will set the model instances so the
|
||||
// builder can easily access any information it may need from the model
|
||||
// while it is constructing and executing various queries against it.
|
||||
$builder->setModel($this)->with($this->with);
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Helper;
|
||||
|
||||
|
||||
/**
|
||||
* Class MigrationException
|
||||
*
|
||||
* @package Firefly\Helper
|
||||
*/
|
||||
class MigrationException extends \Exception
|
||||
{
|
||||
|
||||
}
|
||||
11
app/lib/Firefly/Exception/ValidationException.php
Normal file
11
app/lib/Firefly/Exception/ValidationException.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace Firefly\Exception;
|
||||
|
||||
/**
|
||||
* Class ValidationException
|
||||
*
|
||||
* @package Firefly\Exception
|
||||
*/
|
||||
class ValidationException extends \Exception {
|
||||
|
||||
}
|
||||
365
app/lib/Firefly/Form/Form.php
Normal file
365
app/lib/Firefly/Form/Form.php
Normal file
@@ -0,0 +1,365 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Form;
|
||||
|
||||
|
||||
use Firefly\Exception\FireflyException;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
class Form
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $value
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public static function ffInteger($name, $value = null, array $options = [])
|
||||
{
|
||||
$options['step'] = '1';
|
||||
return self::ffInput('number', $name, $value, $options);
|
||||
|
||||
}
|
||||
|
||||
public static function ffCheckbox($name, $value = 1, $checked = null, $options = [])
|
||||
{
|
||||
$options['checked'] = $checked ? true : null;
|
||||
return self::ffInput('checkbox', $name, $value, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $value
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public static function ffAmount($name, $value = null, array $options = [])
|
||||
{
|
||||
$options['step'] = 'any';
|
||||
$options['min'] = '0.01';
|
||||
return self::ffInput('amount', $name, $value, $options);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $value
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public static function ffBalance($name, $value = null, array $options = [])
|
||||
{
|
||||
$options['step'] = 'any';
|
||||
return self::ffInput('amount', $name, $value, $options);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $value
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public static function ffDate($name, $value = null, array $options = [])
|
||||
{
|
||||
return self::ffInput('date', $name, $value, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $value
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public static function ffTags($name, $value = null, array $options = [])
|
||||
{
|
||||
$options['data-role'] = 'tagsinput';
|
||||
return self::ffInput('text', $name, $value, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param array $list
|
||||
* @param null $selected
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public static function ffSelect($name, array $list = [], $selected = null, array $options = [])
|
||||
{
|
||||
return self::ffInput('select', $name, $selected, $options, $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $value
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public static function ffText($name, $value = null, array $options = array())
|
||||
{
|
||||
return self::ffInput('text', $name, $value, $options);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function label($name, $options)
|
||||
{
|
||||
if (isset($options['label'])) {
|
||||
return $options['label'];
|
||||
}
|
||||
$labels = [
|
||||
'amount_min' => 'Amount (min)',
|
||||
'amount_max' => 'Amount (max)',
|
||||
'match' => 'Matches on',
|
||||
'repeat_freq' => 'Repetition',
|
||||
'account_from_id' => 'Account from',
|
||||
'account_to_id' => 'Account to',
|
||||
'account_id' => 'Asset account'
|
||||
];
|
||||
|
||||
return isset($labels[$name]) ? $labels[$name] : str_replace('_', ' ', ucfirst($name));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return buttons for update/validate/return.
|
||||
*
|
||||
* @param $type
|
||||
* @param $name
|
||||
*/
|
||||
public static function ffOptionsList($type, $name)
|
||||
{
|
||||
$previousValue = \Input::old('post_submit_action');
|
||||
$previousValue = is_null($previousValue) ? 'store' : $previousValue;
|
||||
/*
|
||||
* Store.
|
||||
*/
|
||||
$store = '';
|
||||
switch ($type) {
|
||||
case 'create':
|
||||
$store = '<div class="form-group"><label for="default" class="col-sm-4 control-label">Store</label>';
|
||||
$store .= '<div class="col-sm-8"><div class="radio"><label>';
|
||||
$store .= \Form::radio('post_submit_action', 'store', $previousValue == 'store');
|
||||
$store .= 'Store ' . $name . '</label></div></div></div>';
|
||||
break;
|
||||
case 'update':
|
||||
$store = '<div class="form-group"><label for="default" class="col-sm-4 control-label">Store</label>';
|
||||
$store .= '<div class="col-sm-8"><div class="radio"><label>';
|
||||
$store .= \Form::radio('post_submit_action', 'update', $previousValue == 'store');
|
||||
$store .= 'Update ' . $name . '</label></div></div></div>';
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException('Cannot create ffOptionsList for option (store) ' . $type);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* validate is always the same:
|
||||
*/
|
||||
$validate = '<div class="form-group"><label for="validate_only" class="col-sm-4 control-label">Validate only';
|
||||
$validate .= '</label><div class="col-sm-8"><div class="radio"><label>';
|
||||
$validate .= \Form::radio('post_submit_action', 'validate_only', $previousValue == 'validate_only');
|
||||
$validate .= 'Only validate, do not save</label></div></div></div>';
|
||||
|
||||
/*
|
||||
* Store & return:
|
||||
*/
|
||||
switch ($type) {
|
||||
case 'create':
|
||||
$return = '<div class="form-group"><label for="return_to_form" class="col-sm-4 control-label">';
|
||||
$return .= 'Return here</label><div class="col-sm-8"><div class="radio"><label>';
|
||||
$return .= \Form::radio('post_submit_action', 'create_another', $previousValue == 'create_another');
|
||||
$return .= 'After storing, return here to create another one.</label></div></div></div>';
|
||||
break;
|
||||
case 'update':
|
||||
$return = '<div class="form-group"><label for="return_to_edit" class="col-sm-4 control-label">';
|
||||
$return .= 'Return here</label><div class="col-sm-8"><div class="radio"><label>';
|
||||
$return .= \Form::radio('post_submit_action', 'return_to_edit', $previousValue == 'return_to_edit');
|
||||
$return .= 'After updating, return here.</label></div></div></div>';
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException('Cannot create ffOptionsList for option (store+return) ' . $type);
|
||||
break;
|
||||
}
|
||||
return $store . $validate . $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
* @param $name
|
||||
* @param null $value
|
||||
* @param array $options
|
||||
* @param array $list
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public static function ffInput($type, $name, $value = null, array $options = array(), $list = [])
|
||||
{
|
||||
/*
|
||||
* add some defaults to this method:
|
||||
*/
|
||||
$options['class'] = 'form-control';
|
||||
$options['id'] = 'ffInput_' . $name;
|
||||
$options['autocomplete'] = 'off';
|
||||
$label = self::label($name, $options);
|
||||
/*
|
||||
* Make label and placeholder look nice.
|
||||
*/
|
||||
$options['placeholder'] = ucfirst($name);
|
||||
|
||||
/*
|
||||
* Get prefilled value:
|
||||
*/
|
||||
if (\Session::has('prefilled')) {
|
||||
$prefilled = \Session::get('prefilled');
|
||||
$value = isset($prefilled[$name]) && is_null($value) ? $prefilled[$name] : $value;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the value.
|
||||
*/
|
||||
if (!is_null(\Input::old($name))) {
|
||||
/*
|
||||
* Old value overrules $value.
|
||||
*/
|
||||
$value = \Input::old($name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get errors, warnings and successes from session:
|
||||
*/
|
||||
/** @var MessageBag $errors */
|
||||
$errors = \Session::get('errors');
|
||||
|
||||
/** @var MessageBag $warnings */
|
||||
$warnings = \Session::get('warnings');
|
||||
|
||||
/** @var MessageBag $successes */
|
||||
$successes = \Session::get('successes');
|
||||
|
||||
|
||||
/*
|
||||
* If errors, add some more classes.
|
||||
*/
|
||||
switch (true) {
|
||||
case (!is_null($errors) && $errors->has($name)):
|
||||
$classes = 'form-group has-error has-feedback';
|
||||
break;
|
||||
case (!is_null($warnings) && $warnings->has($name)):
|
||||
$classes = 'form-group has-warning has-feedback';
|
||||
break;
|
||||
case (!is_null($successes) && $successes->has($name)):
|
||||
$classes = 'form-group has-success has-feedback';
|
||||
break;
|
||||
default:
|
||||
$classes = 'form-group';
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add some HTML.
|
||||
*/
|
||||
$html = '<div class="' . $classes . '">';
|
||||
$html .= '<label for="' . $options['id'] . '" class="col-sm-4 control-label">' . $label . '</label>';
|
||||
$html .= '<div class="col-sm-8">';
|
||||
|
||||
|
||||
/*
|
||||
* Switch input type:
|
||||
*/
|
||||
unset($options['label']);
|
||||
switch ($type) {
|
||||
case 'text':
|
||||
$html .= \Form::input('text', $name, $value, $options);
|
||||
break;
|
||||
case 'amount':
|
||||
$html .= '<div class="input-group"><div class="input-group-addon">€</div>';
|
||||
$html .= \Form::input('number', $name, $value, $options);
|
||||
$html .= '</div>';
|
||||
break;
|
||||
case 'number':
|
||||
$html .= \Form::input('number', $name, $value, $options);
|
||||
break;
|
||||
case 'checkbox':
|
||||
$checked = $options['checked'];
|
||||
unset($options['checked'], $options['placeholder'], $options['autocomplete'], $options['class']);
|
||||
$html .= '<div class="checkbox"><label>';
|
||||
$html .= \Form::checkbox($name, $value, $checked, $options);
|
||||
$html .= '</label></div>';
|
||||
|
||||
|
||||
break;
|
||||
case 'date':
|
||||
$html .= \Form::input('date', $name, $value, $options);
|
||||
break;
|
||||
case 'select':
|
||||
$html .= \Form::select($name, $list, $value, $options);
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException('Cannot handle type "' . $type . '" in FFFormBuilder.');
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* If errors, respond to them:
|
||||
*/
|
||||
|
||||
if (!is_null($errors)) {
|
||||
if ($errors->has($name)) {
|
||||
$html .= '<span class="glyphicon glyphicon-remove form-control-feedback"></span>';
|
||||
$html .= '<p class="text-danger">' . e($errors->first($name)) . '</p>';
|
||||
}
|
||||
}
|
||||
unset($errors);
|
||||
/*
|
||||
* If warnings, respond to them:
|
||||
*/
|
||||
|
||||
if (!is_null($warnings)) {
|
||||
if ($warnings->has($name)) {
|
||||
$html .= '<span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>';
|
||||
$html .= '<p class="text-warning">' . e($warnings->first($name)) . '</p>';
|
||||
}
|
||||
}
|
||||
unset($warnings);
|
||||
|
||||
/*
|
||||
* If successes, respond to them:
|
||||
*/
|
||||
|
||||
if (!is_null($successes)) {
|
||||
if ($successes->has($name)) {
|
||||
$html .= '<span class="glyphicon glyphicon-ok form-control-feedback"></span>';
|
||||
$html .= '<p class="text-success">' . e($successes->first($name)) . '</p>';
|
||||
}
|
||||
}
|
||||
unset($successes);
|
||||
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Firefly\Helper\Controllers;
|
||||
|
||||
use Firefly\Exception\FireflyException;
|
||||
|
||||
/**
|
||||
* Class Account
|
||||
*
|
||||
@@ -11,44 +9,58 @@ use Firefly\Exception\FireflyException;
|
||||
*/
|
||||
class Account implements AccountInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
*
|
||||
* @return mixed
|
||||
* @return \TransactionJournal|null
|
||||
*/
|
||||
public function openingBalanceTransaction(\Account $account)
|
||||
{
|
||||
return \TransactionJournal::
|
||||
withRelevantData()->account($account)
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=',
|
||||
'transaction_journals.transaction_type_id')
|
||||
return \TransactionJournal::withRelevantData()
|
||||
->accountIs($account)
|
||||
->leftJoin(
|
||||
'transaction_types', 'transaction_types.id', '=',
|
||||
'transaction_journals.transaction_type_id'
|
||||
)
|
||||
->where('transaction_types.type', 'Opening balance')
|
||||
->first(['transaction_journals.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Since it is entirely possible the database is messed up somehow it might be that a transaction
|
||||
* journal has only one transaction. This is mainly caused by wrong deletions and other artefacts from the past.
|
||||
*
|
||||
* If it is the case, Firefly removes $item and continues like nothing ever happened. This will however,
|
||||
* mess up some statisics but it's decided everybody should learn to live with that.
|
||||
*
|
||||
* Firefly might be needing some cleanup routine in the future.
|
||||
*
|
||||
* For now, Firefly simply warns the user of this.
|
||||
*
|
||||
* @param \Account $account
|
||||
* @param $perPage
|
||||
*
|
||||
* @return mixed|void
|
||||
* @return array|mixed
|
||||
* @throws \Firefly\Exception\FireflyException
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function show(\Account $account, $perPage)
|
||||
{
|
||||
$start = \Session::get('start');
|
||||
$end = \Session::get('end');
|
||||
$stats = [
|
||||
'budgets' => [],
|
||||
'categories' => [],
|
||||
'accounts' => []
|
||||
];
|
||||
$items = [];
|
||||
|
||||
|
||||
// build a query:
|
||||
$query = \TransactionJournal::withRelevantData()->defaultSorting()->account($account)->after($start)
|
||||
$query = \TransactionJournal::withRelevantData()
|
||||
->defaultSorting()
|
||||
->accountIs($account)
|
||||
->after($start)
|
||||
->before($end);
|
||||
// filter some:
|
||||
if (\Input::get('type')) {
|
||||
switch (\Input::get('type')) {
|
||||
case 'transactions':
|
||||
$query->transactionTypes(['Deposit', 'Withdrawal']);
|
||||
@@ -56,13 +68,8 @@ class Account implements AccountInterface
|
||||
case 'transfers':
|
||||
$query->transactionTypes(['Transfer']);
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException('No case for type "' . \Input::get('type') . '"!');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (\Input::get('show')) {
|
||||
switch (\Input::get('show')) {
|
||||
case 'expenses':
|
||||
case 'out':
|
||||
@@ -72,10 +79,6 @@ class Account implements AccountInterface
|
||||
case 'in':
|
||||
$query->moreThan(0);
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException('No case for show "' . \Input::get('show') . '"!');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,26 +94,11 @@ class Account implements AccountInterface
|
||||
foreach ($result as $index => $item) {
|
||||
|
||||
foreach ($item->components as $component) {
|
||||
if ($component->class == 'Budget') {
|
||||
$stats['budgets'][$component->id] = $component;
|
||||
$stats[$component->class][$component->id] = $component;
|
||||
}
|
||||
if ($component->class == 'Category') {
|
||||
$stats['categories'][$component->id] = $component;
|
||||
}
|
||||
}
|
||||
// since it is entirely possible the database is messed up somehow
|
||||
// it might be that a transaction journal has only one transaction.
|
||||
// this is mainly caused by wrong deletions and other artefacts from the past.
|
||||
// if it is the case, we remove $item and continue like nothing ever happened.
|
||||
|
||||
// this will however, mess up some statisics but we can live with that.
|
||||
// we might be needing some cleanup routine in the future.
|
||||
|
||||
// for now, we simply warn the user of this.
|
||||
|
||||
if (count($item->transactions) < 2) {
|
||||
\Session::flash('warning',
|
||||
'Some transactions are incomplete; they will not be shown. Statistics may differ.');
|
||||
\Session::flash('warning', 'Some transactions are incomplete; they will not be shown.');
|
||||
unset($result[$index]);
|
||||
continue;
|
||||
}
|
||||
@@ -125,20 +113,27 @@ class Account implements AccountInterface
|
||||
|
||||
|
||||
// statistics (transactions)
|
||||
$trIn = floatval(\Transaction::before($end)->after($start)->account($account)->moreThan(0)
|
||||
->transactionTypes(['Deposit', 'Withdrawal'])->sum('transactions.amount'));
|
||||
$trOut = floatval(\Transaction::before($end)->after($start)->account($account)->lessThan(0)
|
||||
->transactionTypes(['Deposit', 'Withdrawal'])->sum('transactions.amount'));
|
||||
$trIn = floatval(
|
||||
\Transaction::before($end)->after($start)->accountIs($account)->moreThan(0)
|
||||
->transactionTypes(['Deposit', 'Withdrawal'])->sum('transactions.amount')
|
||||
);
|
||||
$trOut = floatval(
|
||||
\Transaction::before($end)->after($start)->accountIs($account)->lessThan(0)
|
||||
->transactionTypes(['Deposit', 'Withdrawal'])->sum('transactions.amount')
|
||||
);
|
||||
$trDiff = $trIn + $trOut;
|
||||
|
||||
// statistics (transfers)
|
||||
$trfIn = floatval(\Transaction::before($end)->after($start)->account($account)->moreThan(0)
|
||||
->transactionTypes(['Transfer'])->sum('transactions.amount'));
|
||||
$trfOut = floatval(\Transaction::before($end)->after($start)->account($account)->lessThan(0)
|
||||
->transactionTypes(['Transfer'])->sum('transactions.amount'));
|
||||
$trfIn = floatval(
|
||||
\Transaction::before($end)->after($start)->accountIs($account)->moreThan(0)
|
||||
->transactionTypes(['Transfer'])->sum('transactions.amount')
|
||||
);
|
||||
$trfOut = floatval(
|
||||
\Transaction::before($end)->after($start)->accountIs($account)->lessThan(0)
|
||||
->transactionTypes(['Transfer'])->sum('transactions.amount')
|
||||
);
|
||||
$trfDiff = $trfIn + $trfOut;
|
||||
|
||||
|
||||
$stats['period'] = [
|
||||
'in' => $trIn,
|
||||
'out' => $trOut,
|
||||
@@ -155,7 +150,5 @@ class Account implements AccountInterface
|
||||
];
|
||||
|
||||
return $return;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,11 @@ class Budget implements BudgetInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* First, loop all budgets, all of their limits and all repetitions to get an overview per period
|
||||
* and some basic information about that repetition's data.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param Collection $budgets
|
||||
*
|
||||
* @return mixed|void
|
||||
@@ -21,32 +26,30 @@ class Budget implements BudgetInterface
|
||||
{
|
||||
$return = [];
|
||||
|
||||
/** @var \Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
|
||||
/** @var \Limit $limit */
|
||||
foreach ($budget->limits as $limit) {
|
||||
|
||||
/** @var \LimitRepetition $rep */
|
||||
foreach ($limit->limitrepetitions as $rep) {
|
||||
$periodOrder = $rep->periodOrder();
|
||||
$period = $rep->periodShow();
|
||||
$return[$periodOrder] = isset($return[$periodOrder])
|
||||
? $return[$periodOrder]
|
||||
: ['date' => $period,
|
||||
'dateObject' => $rep->startdate,
|
||||
'start' => $rep->startdate,
|
||||
'end' => $rep->enddate,
|
||||
'budget_id' => $limit->budget_id];
|
||||
/** @var \LimitRepetition $repetition */
|
||||
foreach ($limit->limitrepetitions as $repetition) {
|
||||
$repetition->left = $repetition->leftInRepetition();
|
||||
$periodOrder = $repetition->periodOrder();
|
||||
$period = $repetition->periodShow();
|
||||
if (!isset($return[$periodOrder])) {
|
||||
|
||||
$return[$periodOrder] = [
|
||||
'date' => $period,
|
||||
'start' => $repetition->startdate,
|
||||
'end' => $repetition->enddate,
|
||||
'budget_id' => $budget->id,
|
||||
'limitrepetitions' => [$repetition]
|
||||
];
|
||||
} else {
|
||||
$return[$periodOrder]['limitrepetitions'][] = $repetition;
|
||||
}
|
||||
}
|
||||
}
|
||||
// put all the budgets under their respective date:
|
||||
foreach ($budgets as $budget) {
|
||||
foreach ($budget->limits as $limit) {
|
||||
foreach ($limit->limitrepetitions as $rep) {
|
||||
$rep->left = $rep->left();
|
||||
|
||||
$month = $rep->periodOrder();
|
||||
$return[$month]['limitrepetitions'][] = $rep;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,30 +59,24 @@ class Budget implements BudgetInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a repetition (complex because of user check)
|
||||
* and then get the transactions in it.
|
||||
* @param $repetitionId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function organizeRepetition($repetitionId)
|
||||
public function organizeRepetition(\LimitRepetition $repetition)
|
||||
{
|
||||
$result = [];
|
||||
$repetition = \LimitRepetition::with('limit', 'limit.budget')->leftJoin(
|
||||
'limits', 'limit_repetitions.limit_id', '=', 'limits.id'
|
||||
)->leftJoin('components', 'limits.component_id', '=', 'components.id')->where(
|
||||
'components.user_id', \Auth::user()->id
|
||||
)
|
||||
->where('limit_repetitions.id', $repetitionId)->first(['limit_repetitions.*']);
|
||||
|
||||
// get transactions:
|
||||
$set = $repetition->limit->budget->transactionjournals()->with(
|
||||
'transactions', 'transactions.account', 'components', 'transactiontype'
|
||||
)->leftJoin(
|
||||
'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'
|
||||
)->where('transaction_types.type', 'Withdrawal')->where(
|
||||
'date', '>=', $repetition->startdate->format('Y-m-d')
|
||||
)->where('date', '<=', $repetition->enddate->format('Y-m-d'))->orderBy('date', 'DESC')->orderBy(
|
||||
'id', 'DESC'
|
||||
)->get(['transaction_journals.*']);
|
||||
$set = $repetition->limit->budget
|
||||
->transactionjournals()
|
||||
->withRelevantData()
|
||||
->transactionTypes(['Withdrawal'])
|
||||
->after($repetition->startdate)
|
||||
->before($repetition->enddate)
|
||||
->defaultSorting()
|
||||
->get(['transaction_journals.*']);
|
||||
|
||||
$result[0] = [
|
||||
'date' => $repetition->periodShow(),
|
||||
@@ -93,6 +90,8 @@ class Budget implements BudgetInterface
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param \Budget $budget
|
||||
* @param bool $useSessionDates
|
||||
*
|
||||
@@ -128,15 +127,13 @@ class Budget implements BudgetInterface
|
||||
'paginated' => false
|
||||
];
|
||||
$transactions = [];
|
||||
$set = $budget->transactionjournals()->with(
|
||||
'transactions', 'transactions.account', 'components', 'transactiontype'
|
||||
)->leftJoin(
|
||||
'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'
|
||||
)->where('transaction_types.type', 'Withdrawal')->where(
|
||||
'date', '>=', $repetition->startdate->format('Y-m-d')
|
||||
)->where('date', '<=', $repetition->enddate->format('Y-m-d'))->orderBy('date', 'DESC')->orderBy(
|
||||
'id', 'DESC'
|
||||
)->get(['transaction_journals.*']);
|
||||
$set = $budget->transactionjournals()
|
||||
->withRelevantData()
|
||||
->transactionTypes(['Withdrawal'])
|
||||
->after($repetition->startdate)
|
||||
->before($repetition->enddate)
|
||||
->defaultSorting()
|
||||
->get(['transaction_journals.*']);
|
||||
foreach ($set as $entry) {
|
||||
$transactions[] = $entry;
|
||||
$inRepetition[] = $entry->id;
|
||||
@@ -146,22 +143,9 @@ class Budget implements BudgetInterface
|
||||
|
||||
}
|
||||
if ($useSessionDates === false) {
|
||||
$query = $budget->transactionjournals()->withRelevantData()->defaultSorting();
|
||||
if (count($inRepetition) > 0) {
|
||||
$query = $budget->transactionjournals()->with(
|
||||
'transactions', 'transactions.account', 'components', 'transactiontype',
|
||||
'transactions.account.accounttype'
|
||||
)->whereNotIn(
|
||||
'transaction_journals.id', $inRepetition
|
||||
)->orderBy('date', 'DESC')->orderBy(
|
||||
'transaction_journals.id', 'DESC'
|
||||
);
|
||||
} else {
|
||||
$query = $budget->transactionjournals()->with(
|
||||
'transactions', 'transactions.account', 'components', 'transactiontype',
|
||||
'transactions.account.accounttype'
|
||||
)->orderBy('date', 'DESC')->orderBy(
|
||||
'transaction_journals.id', 'DESC'
|
||||
);
|
||||
$query->whereNotIn('transaction_journals.id', $inRepetition);
|
||||
}
|
||||
|
||||
// build paginator:
|
||||
@@ -178,7 +162,10 @@ class Budget implements BudgetInterface
|
||||
$items[] = $item;
|
||||
}
|
||||
$paginator = \Paginator::make($items, $totalItems, $perPage);
|
||||
$result['0000'] = ['date' => 'Not in an envelope', 'limit' => null, 'paginated' => true,
|
||||
$result['0000'] = [
|
||||
'date' => 'Not in an envelope',
|
||||
'limit' => null,
|
||||
'paginated' => true,
|
||||
'journals' => $paginator];
|
||||
}
|
||||
krsort($result);
|
||||
@@ -196,13 +183,12 @@ class Budget implements BudgetInterface
|
||||
$inRepetitions = [];
|
||||
foreach ($budget->limits as $limit) {
|
||||
foreach ($limit->limitrepetitions as $repetition) {
|
||||
$set = $budget->transactionjournals()->leftJoin(
|
||||
'transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'
|
||||
)->where('transaction_types.type', 'Withdrawal')->where(
|
||||
'date', '>=', $repetition->startdate->format('Y-m-d')
|
||||
)->where('date', '<=', $repetition->enddate->format('Y-m-d'))->orderBy('date', 'DESC')->get(
|
||||
['transaction_journals.id']
|
||||
);
|
||||
$set = $budget->transactionjournals()
|
||||
->transactionTypes(['Withdrawal'])
|
||||
->after($repetition->startdate)
|
||||
->before($repetition->enddate)
|
||||
->defaultSorting()
|
||||
->get(['transaction_journals.id']);
|
||||
foreach ($set as $item) {
|
||||
$inRepetitions[] = $item->id;
|
||||
}
|
||||
@@ -210,14 +196,10 @@ class Budget implements BudgetInterface
|
||||
|
||||
}
|
||||
|
||||
$query = $budget->transactionjournals()->with(
|
||||
'transactions', 'transactions.account', 'components', 'transactiontype',
|
||||
'transactions.account.accounttype'
|
||||
)->whereNotIn(
|
||||
'transaction_journals.id', $inRepetitions
|
||||
)->orderBy('date', 'DESC')->orderBy(
|
||||
'transaction_journals.id', 'DESC'
|
||||
);
|
||||
$query = $budget->transactionjournals()
|
||||
->withRelevantData()
|
||||
->whereNotIn('transaction_journals.id', $inRepetitions)
|
||||
->defaultSorting();
|
||||
|
||||
// build paginator:
|
||||
$perPage = 25;
|
||||
@@ -233,8 +215,12 @@ class Budget implements BudgetInterface
|
||||
$items[] = $item;
|
||||
}
|
||||
$paginator = \Paginator::make($items, $totalItems, $perPage);
|
||||
$result = [0 => ['date' => 'Not in an envelope', 'limit' => null, 'paginated' => true,
|
||||
'journals' => $paginator]];
|
||||
$result = [0 => [
|
||||
'date' => 'Not in an envelope',
|
||||
'limit' => null,
|
||||
'paginated' => true,
|
||||
'journals' => $paginator
|
||||
]];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ interface BudgetInterface
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function organizeRepetition($repetitionId);
|
||||
public function organizeRepetition(\LimitRepetition $repetition);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Firefly\Helper\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Firefly\Exception\FireflyException;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class Chart
|
||||
@@ -24,13 +25,20 @@ class Chart implements ChartInterface
|
||||
{
|
||||
$current = clone $start;
|
||||
$today = new Carbon;
|
||||
$return = ['name' => $account->name, 'id' => $account->id, 'data' => []];
|
||||
$return = [
|
||||
'name' => $account->name,
|
||||
'id' => $account->id,
|
||||
'type' => 'spline',
|
||||
'pointStart' => $start->timestamp * 1000,
|
||||
'pointInterval' => 24 * 3600 * 1000, // one day
|
||||
'data' => []
|
||||
];
|
||||
|
||||
while ($current <= $end) {
|
||||
if ($current > $today) {
|
||||
$return['data'][] = [$current->timestamp * 1000, $account->predict(clone $current)];
|
||||
$return['data'][] = $account->predict(clone $current);
|
||||
} else {
|
||||
$return['data'][] = [$current->timestamp * 1000, $account->balance(clone $current)];
|
||||
$return['data'][] = $account->balance(clone $current);
|
||||
}
|
||||
|
||||
$current->addDay();
|
||||
@@ -94,92 +102,6 @@ class Chart implements ChartInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function budgets(Carbon $start)
|
||||
{
|
||||
// grab all budgets in the time period, like the index does:
|
||||
// get the budgets for this period:
|
||||
|
||||
$data = [];
|
||||
|
||||
$budgets = \Auth::user()->budgets()->with(
|
||||
['limits' => function ($q) {
|
||||
$q->orderBy('limits.startdate', 'ASC');
|
||||
}, 'limits.limitrepetitions' => function ($q) use ($start) {
|
||||
$q->orderBy('limit_repetitions.startdate', 'ASC');
|
||||
$q->where('startdate', $start->format('Y-m-d'));
|
||||
}]
|
||||
)->orderBy('name', 'ASC')->get();
|
||||
$limitInPeriod = '';
|
||||
$spentInPeriod = '';
|
||||
|
||||
foreach ($budgets as $budget) {
|
||||
$budget->count = 0;
|
||||
foreach ($budget->limits as $limit) {
|
||||
/** @var $rep \LimitRepetition */
|
||||
foreach ($limit->limitrepetitions as $index => $rep) {
|
||||
if ($index == 0) {
|
||||
$limitInPeriod = 'Envelope for ' . $rep->periodShow();
|
||||
$spentInPeriod = 'Spent in ' . $rep->periodShow();
|
||||
}
|
||||
$rep->left = $rep->left();
|
||||
// overspent:
|
||||
if ($rep->left < 0) {
|
||||
$rep->spent = ($rep->left * -1) + $rep->amount;
|
||||
$rep->overspent = $rep->left * -1;
|
||||
$total = $rep->spent + $rep->overspent;
|
||||
$rep->spent_pct = round(($rep->spent / $total) * 100);
|
||||
$rep->overspent_pct = 100 - $rep->spent_pct;
|
||||
} else {
|
||||
$rep->spent = $rep->amount - $rep->left;
|
||||
$rep->spent_pct = round(($rep->spent / $rep->amount) * 100);
|
||||
$rep->left_pct = 100 - $rep->spent_pct;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
$budget->count += count($limit->limitrepetitions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$data['series'] = [
|
||||
[
|
||||
'name' => $limitInPeriod,
|
||||
'data' => []
|
||||
],
|
||||
[
|
||||
'name' => $spentInPeriod,
|
||||
'data' => []
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
foreach ($budgets as $budget) {
|
||||
if ($budget->count > 0) {
|
||||
$data['labels'][] = wordwrap($budget->name, 12, "<br>");
|
||||
}
|
||||
foreach ($budget->limits as $limit) {
|
||||
foreach ($limit->limitrepetitions as $rep) {
|
||||
//0: envelope for period:
|
||||
$amount = floatval($rep->amount);
|
||||
$spent = $rep->spent;
|
||||
$color = $spent > $amount ? '#FF0000' : null;
|
||||
$data['series'][0]['data'][] = ['y' => $amount, 'id' => 'amount-' . $rep->id];
|
||||
$data['series'][1]['data'][] = ['y' => $rep->spent, 'color' => $color, 'id' => 'spent-' . $rep->id];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
@@ -401,4 +323,153 @@ class Chart implements ChartInterface
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return float|null
|
||||
*/
|
||||
public function spentOnDay(\Budget $budget, Carbon $date)
|
||||
{
|
||||
return floatval(
|
||||
\Transaction::
|
||||
leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin(
|
||||
'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=',
|
||||
'transaction_journals.id'
|
||||
)->where('component_transaction_journal.component_id', '=', $budget->id)->where(
|
||||
'transaction_journals.date', $date->format('Y-m-d')
|
||||
)->where('amount', '>', 0)->sum('amount')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public function allJournalsInBudgetEnvelope(\Budget $budget)
|
||||
{
|
||||
$inRepetitions = [];
|
||||
|
||||
foreach ($budget->limits as $limit) {
|
||||
foreach ($limit->limitrepetitions as $repetition) {
|
||||
$set = $budget
|
||||
->transactionjournals()
|
||||
->transactionTypes(['Withdrawal'])
|
||||
->after($repetition->startdate)
|
||||
->before($repetition->enddate)
|
||||
->get(['transaction_journals.id']);
|
||||
|
||||
foreach ($set as $item) {
|
||||
$inRepetitions[] = $item->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $inRepetitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
* @param array $ids
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function journalsNotInSet(\Budget $budget, array $ids)
|
||||
{
|
||||
$query = $budget->transactionjournals()
|
||||
->whereNotIn('transaction_journals.id', $ids)
|
||||
->orderBy('date', 'DESC')
|
||||
->orderBy('transaction_journals.id', 'DESC');
|
||||
|
||||
$result = $query->get(['transaction_journals.id']);
|
||||
$set = [];
|
||||
foreach ($result as $entry) {
|
||||
$set[] = $entry->id;
|
||||
}
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $set
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function transactionsByJournals(array $set)
|
||||
{
|
||||
$transactions = \Transaction::whereIn('transaction_journal_id', $set)
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->groupBy('transaction_journals.date')
|
||||
->where('amount', '>', 0)->get(['transaction_journals.date', \DB::Raw('SUM(`amount`) as `aggregate`')]);
|
||||
return $transactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all limit (LimitRepetitions) for a budget falling in a certain date range.
|
||||
*
|
||||
* @param \Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function limitsInRange(\Budget $budget, Carbon $start, Carbon $end)
|
||||
{
|
||||
$reps = new Collection;
|
||||
/** @var \Limit $limit */
|
||||
foreach ($budget->limits as $limit) {
|
||||
$set = $limit->limitrepetitions()->where(
|
||||
function ($q) use ($start, $end) {
|
||||
// startdate is between range
|
||||
$q->where(
|
||||
function ($q) use ($start, $end) {
|
||||
$q->where('startdate', '>=', $start->format('Y-m-d'));
|
||||
$q->where('startdate', '<=', $end->format('Y-m-d'));
|
||||
}
|
||||
);
|
||||
|
||||
// or enddate is between range.
|
||||
$q->orWhere(
|
||||
function ($q) use ($start, $end) {
|
||||
$q->where('enddate', '>=', $start->format('Y-m-d'));
|
||||
$q->where('enddate', '<=', $end->format('Y-m-d'));
|
||||
}
|
||||
);
|
||||
}
|
||||
)->get();
|
||||
|
||||
$reps = $reps->merge($set);
|
||||
}
|
||||
return $reps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Firefly checks how much money has been spend on the limitrepetition (aka: the current envelope) in
|
||||
* the period denoted. Aka, the user has a certain amount of money in an envelope and wishes to know how
|
||||
* much he has spent between the dates entered. This date range can be a partial match with the date range
|
||||
* of the envelope or no match at all.
|
||||
*
|
||||
* @param \LimitRepetition $repetition
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function spentOnLimitRepetitionBetweenDates(\LimitRepetition $repetition, Carbon $start, Carbon $end)
|
||||
{
|
||||
return floatval(
|
||||
\Transaction::
|
||||
leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin(
|
||||
'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=',
|
||||
'transaction_journals.id'
|
||||
)->where('component_transaction_journal.component_id', '=', $repetition->limit->budget->id)->where(
|
||||
'transaction_journals.date', '>=', $start->format('Y-m-d')
|
||||
)->where('transaction_journals.date', '<=', $end->format('Y-m-d'))->where(
|
||||
'amount', '>', 0
|
||||
)->sum('amount')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -30,13 +30,6 @@ interface ChartInterface
|
||||
*/
|
||||
public function categories(Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function budgets(Carbon $start);
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param Carbon $date
|
||||
@@ -54,4 +47,62 @@ interface ChartInterface
|
||||
* @return mixed
|
||||
*/
|
||||
public function categoryShowChart(\Category $category, $range, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return float|null
|
||||
*/
|
||||
public function spentOnDay(\Budget $budget, Carbon $date);
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public function allJournalsInBudgetEnvelope(\Budget $budget);
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
* @param array $ids
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function journalsNotInSet(\Budget $budget, array $ids);
|
||||
|
||||
/**
|
||||
* @param array $set
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function transactionsByJournals(array $set);
|
||||
|
||||
/**
|
||||
* Get all limit (LimitRepetitions) for a budget falling in a certain date range.
|
||||
*
|
||||
* @param \Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function limitsInRange(\Budget $budget, Carbon $start, Carbon $end);
|
||||
|
||||
|
||||
/**
|
||||
* Firefly checks how much money has been spend on the limitrepetition (aka: the current envelope) in
|
||||
* the period denoted. Aka, the user has a certain amount of money in an envelope and wishes to know how
|
||||
* much he has spent between the dates entered. This date range can be a partial match with the date range
|
||||
* of the envelope or no match at all.
|
||||
*
|
||||
* @param \LimitRepetition $repetition
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function spentOnLimitRepetitionBetweenDates(\LimitRepetition $repetition, Carbon $start, Carbon $end);
|
||||
|
||||
|
||||
}
|
||||
396
app/lib/Firefly/Helper/Controllers/Json.php
Normal file
396
app/lib/Firefly/Helper/Controllers/Json.php
Normal file
@@ -0,0 +1,396 @@
|
||||
<?php
|
||||
namespace Firefly\Helper\Controllers;
|
||||
|
||||
use LaravelBook\Ardent\Builder;
|
||||
|
||||
/**
|
||||
* Class Json
|
||||
*
|
||||
* @package Firefly\Helper\Controllers
|
||||
*/
|
||||
class Json implements JsonInterface
|
||||
{
|
||||
/**
|
||||
* Grabs all the parameters entered by the DataTables JQuery plugin and creates
|
||||
* a nice array to be used by the other methods. It's also cleaning up and what-not.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dataTableParameters()
|
||||
{
|
||||
/*
|
||||
* Process all parameters!
|
||||
*/
|
||||
if (intval(\Input::get('length')) < 0) {
|
||||
$length = 10000; // we get them all if no length is defined.
|
||||
} else {
|
||||
$length = intval(\Input::get('length'));
|
||||
}
|
||||
$parameters = [
|
||||
'start' => intval(\Input::get('start')),
|
||||
'length' => $length,
|
||||
'draw' => intval(\Input::get('draw')),
|
||||
];
|
||||
|
||||
|
||||
/*
|
||||
* Columns:
|
||||
*/
|
||||
if (!is_null(\Input::get('columns')) && is_array(\Input::get('columns'))) {
|
||||
foreach (\Input::get('columns') as $column) {
|
||||
$parameters['columns'][] = [
|
||||
'data' => $column['data'],
|
||||
'name' => $column['name'],
|
||||
'searchable' => $column['searchable'] == 'true' ? true : false,
|
||||
'orderable' => $column['orderable'] == 'true' ? true : false,
|
||||
'search' => [
|
||||
'value' => $column['search']['value'],
|
||||
'regex' => $column['search']['regex'] == 'true' ? true : false,
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Sorting.
|
||||
*/
|
||||
$parameters['orderOnAccount'] = false;
|
||||
if (!is_null(\Input::get('order')) && is_array(\Input::get('order'))) {
|
||||
foreach (\Input::get('order') as $order) {
|
||||
$columnIndex = intval($order['column']);
|
||||
$columnName = $parameters['columns'][$columnIndex]['name'];
|
||||
$parameters['order'][] = [
|
||||
'name' => $columnName,
|
||||
'dir' => strtoupper($order['dir'])
|
||||
];
|
||||
if ($columnName == 'to' || $columnName == 'from') {
|
||||
$parameters['orderOnAccount'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Search parameters:
|
||||
*/
|
||||
$parameters['search'] = [
|
||||
'value' => '',
|
||||
'regex' => false
|
||||
];
|
||||
if (!is_null(\Input::get('search')) && is_array(\Input::get('search'))) {
|
||||
$search = \Input::get('search');
|
||||
$parameters['search'] = [
|
||||
'value' => $search['value'],
|
||||
'regex' => $search['regex'] == 'true' ? true : false
|
||||
];
|
||||
}
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do some sorting, counting and ordering on the query and return a nicely formatted array
|
||||
* that can be used by the DataTables JQuery plugin.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param Builder $query
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function journalDataset(array $parameters, Builder $query)
|
||||
{
|
||||
/*
|
||||
* Count query:
|
||||
*/
|
||||
$count = $query->count();
|
||||
|
||||
/*
|
||||
* Update the selection:
|
||||
*/
|
||||
|
||||
$query->take($parameters['length']);
|
||||
if ($parameters['start'] > 0) {
|
||||
$query->skip($parameters['start']);
|
||||
}
|
||||
|
||||
/*
|
||||
* Input search parameters:
|
||||
*/
|
||||
$filtered = $count;
|
||||
if (strlen($parameters['search']['value']) > 0) {
|
||||
$query->where('transaction_journals.description', 'LIKE', '%' . e($parameters['search']['value']) . '%');
|
||||
$filtered = $query->count();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Build return array:
|
||||
*/
|
||||
$data = [
|
||||
'draw' => $parameters['draw'],
|
||||
'recordsTotal' => $count,
|
||||
'recordsFiltered' => $filtered,
|
||||
'data' => [],
|
||||
|
||||
];
|
||||
|
||||
/*
|
||||
* Get paginated result set:
|
||||
*/
|
||||
if ($parameters['orderOnAccount'] === true) {
|
||||
/** @var Collection $set */
|
||||
$set = $query->get(
|
||||
[
|
||||
'transaction_journals.*',
|
||||
't1.amount',
|
||||
't1.account_id AS from_id',
|
||||
'a1.name AS from',
|
||||
't2.account_id AS to_id',
|
||||
'a2.name AS to',
|
||||
]
|
||||
);
|
||||
} else {
|
||||
/** @var Collection $set */
|
||||
$set = $query->get(
|
||||
[
|
||||
'transaction_journals.*',
|
||||
'transactions.amount',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop set and create entries to return.
|
||||
*/
|
||||
/** @var \TransactionJournal $entry */
|
||||
foreach ($set as $entry) {
|
||||
$from = $entry->transactions[0]->account;
|
||||
$to = $entry->transactions[1]->account;
|
||||
$budget = $entry->budgets()->first();
|
||||
$category = $entry->categories()->first();
|
||||
$recurring = $entry->recurringTransaction()->first();
|
||||
$arr = [
|
||||
'date' => $entry->date->format('j F Y'),
|
||||
'description' => [
|
||||
'description' => $entry->description,
|
||||
'url' => route('transactions.show', $entry->id)
|
||||
],
|
||||
'amount' => floatval($entry->amount),
|
||||
'from' => ['name' => $from->name, 'url' => route('accounts.show', $from->id)],
|
||||
'to' => ['name' => $to->name, 'url' => route('accounts.show', $to->id)],
|
||||
'components' => [
|
||||
'budget_id' => 0,
|
||||
'budget_url' => '',
|
||||
'budget_name' => '',
|
||||
'category_id' => 0,
|
||||
'category_url' => '',
|
||||
'category_name' => ''
|
||||
],
|
||||
'id' => [
|
||||
'edit' => route('transactions.edit', $entry->id),
|
||||
'delete' => route('transactions.delete', $entry->id)
|
||||
]
|
||||
];
|
||||
if ($budget) {
|
||||
$arr['components']['budget_id'] = $budget->id;
|
||||
$arr['components']['budget_name'] = $budget->name;
|
||||
$arr['components']['budget_url'] = route('budgets.show', $budget->id);
|
||||
}
|
||||
if ($category) {
|
||||
$arr['components']['category_id'] = $category->id;
|
||||
$arr['components']['category_name'] = $category->name;
|
||||
$arr['components']['category_url'] = route('categories.show', $category->id);
|
||||
}
|
||||
if ($recurring) {
|
||||
$arr['components']['recurring_id'] = $recurring->id;
|
||||
$arr['components']['recurring_name'] = e($recurring->name);
|
||||
$arr['components']['recurring_url'] = route('recurring.show', $recurring->id);
|
||||
}
|
||||
|
||||
$data['data'][] = $arr;
|
||||
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds most of the query required to grab transaction journals from the database.
|
||||
* This is useful because all three pages showing different kinds of transactions use
|
||||
* the exact same query with only slight differences.
|
||||
*
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function journalQuery(array $parameters)
|
||||
{
|
||||
/*
|
||||
* We need the following vars to fine tune the query:
|
||||
*/
|
||||
if ($parameters['amount'] == 'negative') {
|
||||
$operator = '<';
|
||||
$operatorNegated = '>';
|
||||
$function = 'lessThan';
|
||||
} else {
|
||||
$operator = '>';
|
||||
$operatorNegated = '<';
|
||||
$function = 'moreThan';
|
||||
}
|
||||
|
||||
/*
|
||||
* Build query:
|
||||
*/
|
||||
$query = \TransactionJournal::transactionTypes($parameters['transactionTypes'])->withRelevantData();
|
||||
$query->where('user_id', \Auth::user()->id);
|
||||
$query->where('completed', 1);
|
||||
/*
|
||||
* This is complex. Join `transactions` twice, once for the "to" account and once for the
|
||||
* "from" account. Then get the amount from one of these (depends on type).
|
||||
*
|
||||
* Only need to do this when there's a sort order for "from" or "to".
|
||||
*
|
||||
* Also need the table prefix for this to work.
|
||||
*/
|
||||
if ($parameters['orderOnAccount'] === true) {
|
||||
$connection = \Config::get('database.default');
|
||||
$prefix = \Config::get('database.connections.' . $connection . '.prefix');
|
||||
// left join first table for "from" account:
|
||||
$query->leftJoin(
|
||||
'transactions AS ' . $prefix . 't1', function ($join) use ($operator) {
|
||||
$join->on('t1.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->on('t1.amount', $operator, \DB::Raw(0));
|
||||
}
|
||||
);
|
||||
// left join second table for "to" account:
|
||||
$query->leftJoin(
|
||||
'transactions AS ' . $prefix . 't2', function ($join) use ($operatorNegated) {
|
||||
$join->on('t2.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->on('t2.amount', $operatorNegated, \DB::Raw(0));
|
||||
}
|
||||
);
|
||||
|
||||
// also join accounts twice to get the account's name, which we need for sorting.
|
||||
$query->leftJoin('accounts as ' . $prefix . 'a1', 'a1.id', '=', 't1.account_id');
|
||||
$query->leftJoin('accounts as ' . $prefix . 'a2', 'a2.id', '=', 't2.account_id');
|
||||
} else {
|
||||
// less complex
|
||||
$query->$function(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add sort parameters to query:
|
||||
*/
|
||||
if (isset($parameters['order']) && count($parameters['order']) > 0) {
|
||||
foreach ($parameters['order'] as $order) {
|
||||
$query->orderBy($order['name'], $order['dir']);
|
||||
}
|
||||
} else {
|
||||
$query->defaultSorting();
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do some sorting, counting and ordering on the query and return a nicely formatted array
|
||||
* that can be used by the DataTables JQuery plugin.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param Builder $query
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function recurringTransactionsDataset(array $parameters, Builder $query)
|
||||
{
|
||||
/*
|
||||
* Count query:
|
||||
*/
|
||||
$count = $query->count();
|
||||
|
||||
/*
|
||||
* Update the selection:
|
||||
*/
|
||||
|
||||
$query->take($parameters['length']);
|
||||
if ($parameters['start'] > 0) {
|
||||
$query->skip($parameters['start']);
|
||||
}
|
||||
|
||||
/*
|
||||
* Input search parameters:
|
||||
*/
|
||||
$filtered = $count;
|
||||
if (strlen($parameters['search']['value']) > 0) {
|
||||
$query->where('recurring_transactions.description', 'LIKE', '%' . e($parameters['search']['value']) . '%');
|
||||
$filtered = $query->count();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Build return array:
|
||||
*/
|
||||
$data = [
|
||||
'draw' => $parameters['draw'],
|
||||
'recordsTotal' => $count,
|
||||
'recordsFiltered' => $filtered,
|
||||
'data' => [],
|
||||
|
||||
];
|
||||
|
||||
/*
|
||||
* Get paginated result set:
|
||||
*/
|
||||
/** @var Collection $set */
|
||||
$set = $query->get(
|
||||
[
|
||||
'recurring_transactions.*',
|
||||
]
|
||||
);
|
||||
|
||||
/*
|
||||
* Loop set and create entries to return.
|
||||
*/
|
||||
foreach ($set as $entry) {
|
||||
$set = [
|
||||
|
||||
'name' => ['name' => $entry->name, 'url' => route('recurring.show', $entry->id)],
|
||||
'match' => explode(' ', $entry->match),
|
||||
'amount_max' => floatval($entry->amount_max),
|
||||
'amount_min' => floatval($entry->amount_min),
|
||||
'date' => $entry->date->format('j F Y'),
|
||||
'active' => intval($entry->active),
|
||||
'automatch' => intval($entry->automatch),
|
||||
'repeat_freq' => $entry->repeat_freq,
|
||||
'id' => [
|
||||
'edit' => route('recurring.edit', $entry->id),
|
||||
'delete' => route('recurring.delete', $entry->id)
|
||||
]
|
||||
];
|
||||
if (intval($entry->skip) > 0) {
|
||||
$set['repeat_freq'] = $entry->repeat_freq . ' (skip ' . $entry->skip . ')';
|
||||
}
|
||||
$data['data'][] = $set;
|
||||
|
||||
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a query that will pick up all recurring transactions from the database.
|
||||
*
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function recurringTransactionsQuery(array $parameters)
|
||||
{
|
||||
$query = \RecurringTransaction::where('user_id', \Auth::user()->id);
|
||||
|
||||
if (isset($parameters['order']) && count($parameters['order']) > 0) {
|
||||
foreach ($parameters['order'] as $order) {
|
||||
$query->orderBy($order['name'], $order['dir']);
|
||||
}
|
||||
} else {
|
||||
$query->orderBy('name', 'ASC');
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
64
app/lib/Firefly/Helper/Controllers/JsonInterface.php
Normal file
64
app/lib/Firefly/Helper/Controllers/JsonInterface.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Helper\Controllers;
|
||||
|
||||
use LaravelBook\Ardent\Builder;
|
||||
|
||||
/**
|
||||
* Interface JsonInterface
|
||||
*
|
||||
* @package Firefly\Helper\Controllers
|
||||
*/
|
||||
interface JsonInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Grabs all the parameters entered by the DataTables JQuery plugin and creates
|
||||
* a nice array to be used by the other methods. It's also cleaning up and what-not.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dataTableParameters();
|
||||
|
||||
/**
|
||||
* Do some sorting, counting and ordering on the query and return a nicely formatted array
|
||||
* that can be used by the DataTables JQuery plugin.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param Builder $query
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function journalDataset(array $parameters, Builder $query);
|
||||
|
||||
/**
|
||||
* Builds most of the query required to grab transaction journals from the database.
|
||||
* This is useful because all three pages showing different kinds of transactions use
|
||||
* the exact same query with only slight differences.
|
||||
*
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function journalQuery(array $parameters);
|
||||
|
||||
/**
|
||||
* Do some sorting, counting and ordering on the query and return a nicely formatted array
|
||||
* that can be used by the DataTables JQuery plugin.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param Builder $query
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function recurringTransactionsDataset(array $parameters, Builder $query);
|
||||
|
||||
/**
|
||||
* Create a query that will pick up all recurring transactions from the database.
|
||||
*
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function recurringTransactionsQuery(array $parameters);
|
||||
}
|
||||
120
app/lib/Firefly/Helper/Controllers/Recurring.php
Normal file
120
app/lib/Firefly/Helper/Controllers/Recurring.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Helper\Controllers;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
class Recurring implements RecurringInterface
|
||||
{
|
||||
/**
|
||||
* Returns messages about the validation.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function validate(array $data)
|
||||
{
|
||||
$errors = new MessageBag;
|
||||
$warnings = new MessageBag;
|
||||
$successes = new MessageBag;
|
||||
|
||||
/*
|
||||
* Name:
|
||||
*/
|
||||
if (strlen($data['name']) == 0) {
|
||||
$errors->add('name', 'The name should not be this short.');
|
||||
}
|
||||
if (strlen($data['name']) > 250) {
|
||||
$errors->add('name', 'The name should not be this long.');
|
||||
}
|
||||
if (! isset($data['id'])) {
|
||||
$count = \Auth::user()->recurringtransactions()->whereName($data['name'])->count();
|
||||
} else {
|
||||
$count = \Auth::user()->recurringtransactions()->whereName($data['name'])->where('id', '!=', $data['id'])->count();
|
||||
}
|
||||
if ($count > 0) {
|
||||
$errors->add('name', 'A recurring transaction with this name already exists.');
|
||||
}
|
||||
if (count($errors->get('name')) == 0) {
|
||||
$successes->add('name', 'OK!');
|
||||
}
|
||||
|
||||
/*
|
||||
* Match
|
||||
*/
|
||||
if (count(explode(',', $data['match'])) > 10) {
|
||||
$warnings->add('match', 'This many matches is pretty pointless');
|
||||
}
|
||||
if (strlen($data['match']) == 0) {
|
||||
$errors->add('match', 'Cannot match on nothing.');
|
||||
}
|
||||
if (count($errors->get('match')) == 0) {
|
||||
$successes->add('match', 'OK!');
|
||||
}
|
||||
|
||||
/*
|
||||
* Amount
|
||||
*/
|
||||
if (floatval($data['amount_max']) == 0 && floatval($data['amount_min']) == 0) {
|
||||
$errors->add('amount_min', 'Amount max and min cannot both be zero.');
|
||||
$errors->add('amount_max', 'Amount max and min cannot both be zero.');
|
||||
}
|
||||
|
||||
if (floatval($data['amount_max']) < floatval($data['amount_min'])) {
|
||||
$errors->add('amount_max', 'Amount max must be more than amount min.');
|
||||
}
|
||||
|
||||
if (floatval($data['amount_min']) > floatval($data['amount_max'])) {
|
||||
$errors->add('amount_max', 'Amount min must be less than amount max.');
|
||||
}
|
||||
if (count($errors->get('amount_min')) == 0) {
|
||||
$successes->add('amount_min', 'OK!');
|
||||
}
|
||||
if (count($errors->get('amount_max')) == 0) {
|
||||
$successes->add('amount_max', 'OK!');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Date
|
||||
*/
|
||||
try {
|
||||
$date = new Carbon($data['date']);
|
||||
} catch (Exception $e) {
|
||||
$errors->add('date', 'The date entered was invalid');
|
||||
}
|
||||
if (strlen($data['date']) == 0) {
|
||||
$errors->add('date', 'The date entered was invalid');
|
||||
}
|
||||
if (!$errors->has('date')) {
|
||||
$successes->add('date', 'OK!');
|
||||
}
|
||||
|
||||
$successes->add('active', 'OK!');
|
||||
$successes->add('automatch', 'OK!');
|
||||
|
||||
if (intval($data['skip']) < 0) {
|
||||
$errors->add('skip', 'Cannot be below zero.');
|
||||
} else if (intval($data['skip']) > 31) {
|
||||
$errors->add('skip', 'Cannot be above 31.');
|
||||
}
|
||||
if (count($errors->get('skip')) == 0) {
|
||||
$successes->add('skip', 'OK!');
|
||||
}
|
||||
|
||||
$set = \Config::get('firefly.budget_periods');
|
||||
if (!in_array($data['repeat_freq'], $set)) {
|
||||
$errors->add('repeat_freq', 'Invalid value.');
|
||||
}
|
||||
if (count($errors->get('repeat_freq')) == 0) {
|
||||
$successes->add('repeat_freq', 'OK!');
|
||||
}
|
||||
|
||||
return ['errors' => $errors, 'warnings' => $warnings, 'successes' => $successes];
|
||||
|
||||
}
|
||||
}
|
||||
15
app/lib/Firefly/Helper/Controllers/RecurringInterface.php
Normal file
15
app/lib/Firefly/Helper/Controllers/RecurringInterface.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Helper\Controllers;
|
||||
|
||||
|
||||
interface RecurringInterface {
|
||||
/**
|
||||
* Returns messages about the validation.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function validate(array $data);
|
||||
}
|
||||
101
app/lib/Firefly/Helper/Controllers/Search.php
Normal file
101
app/lib/Firefly/Helper/Controllers/Search.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
namespace Firefly\Helper\Controllers;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class Search
|
||||
*
|
||||
* @package Firefly\Helper\Controllers
|
||||
*/
|
||||
class Search implements SearchInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param array $words
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchTransactions(array $words)
|
||||
{
|
||||
return \Auth::user()->transactionjournals()->withRelevantData()->where(
|
||||
function ($q) use ($words) {
|
||||
foreach ($words as $word) {
|
||||
$q->orWhere('description', 'LIKE', '%' . e($word) . '%');
|
||||
}
|
||||
}
|
||||
)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $words
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchAccounts(array $words)
|
||||
{
|
||||
return \Auth::user()->accounts()->with('accounttype')->where(
|
||||
function ($q) use ($words) {
|
||||
foreach ($words as $word) {
|
||||
$q->orWhere('name', 'LIKE', '%' . e($word) . '%');
|
||||
}
|
||||
}
|
||||
)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $words
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchCategories(array $words)
|
||||
{
|
||||
/** @var Collection $set */
|
||||
$set = \Auth::user()->categories()->get();
|
||||
$newSet = $set->filter(
|
||||
function (\Category $c) use ($words) {
|
||||
$found = 0;
|
||||
foreach ($words as $word) {
|
||||
if (!(strpos(strtolower($c->name), strtolower($word)) === false)) {
|
||||
$found++;
|
||||
}
|
||||
}
|
||||
return $found > 0;
|
||||
}
|
||||
);
|
||||
return $newSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $words
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchBudgets(array $words)
|
||||
{
|
||||
/** @var Collection $set */
|
||||
$set = \Auth::user()->budgets()->get();
|
||||
$newSet = $set->filter(
|
||||
function (\Budget $b) use ($words) {
|
||||
$found = 0;
|
||||
foreach ($words as $word) {
|
||||
if (!(strpos(strtolower($b->name), strtolower($word)) === false)) {
|
||||
$found++;
|
||||
}
|
||||
}
|
||||
return $found > 0;
|
||||
}
|
||||
);
|
||||
return $newSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $words
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchTags(array $words)
|
||||
{
|
||||
return new Collection;
|
||||
}
|
||||
}
|
||||
36
app/lib/Firefly/Helper/Controllers/SearchInterface.php
Normal file
36
app/lib/Firefly/Helper/Controllers/SearchInterface.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Firefly\Helper\Controllers;
|
||||
|
||||
/**
|
||||
* Interface SearchInterface
|
||||
*
|
||||
* @package Firefly\Helper\Controllers
|
||||
*/
|
||||
interface SearchInterface
|
||||
{
|
||||
/**
|
||||
* @param array $words
|
||||
*/
|
||||
public function searchTransactions(array $words);
|
||||
|
||||
/**
|
||||
* @param array $words
|
||||
*/
|
||||
public function searchAccounts(array $words);
|
||||
|
||||
/**
|
||||
* @param array $words
|
||||
*/
|
||||
public function searchCategories(array $words);
|
||||
|
||||
/**
|
||||
* @param array $words
|
||||
*/
|
||||
public function searchBudgets(array $words);
|
||||
|
||||
/**
|
||||
* @param array $words
|
||||
*/
|
||||
public function searchTags(array $words);
|
||||
|
||||
}
|
||||
485
app/lib/Firefly/Helper/Controllers/Transaction.php
Normal file
485
app/lib/Firefly/Helper/Controllers/Transaction.php
Normal file
@@ -0,0 +1,485 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Helper\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Firefly\Exception\FireflyException;
|
||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
|
||||
use Firefly\Storage\Category\CategoryRepositoryInterface as CRI;
|
||||
use Firefly\Storage\Piggybank\PiggybankRepositoryInterface as PRI;
|
||||
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
* Class Transaction
|
||||
*
|
||||
* @package Firefly\Helper\Controllers
|
||||
*/
|
||||
class Transaction implements TransactionInterface
|
||||
{
|
||||
protected $_user = null;
|
||||
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $_journals */
|
||||
protected $_journals;
|
||||
|
||||
/** @var \Firefly\Storage\Category\CategoryRepositoryInterface $_categories */
|
||||
protected $_categories;
|
||||
|
||||
/** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $_budgets */
|
||||
protected $_budgets;
|
||||
|
||||
/** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface $_piggybanks */
|
||||
protected $_piggybanks;
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $_accounts */
|
||||
protected $_accounts;
|
||||
|
||||
|
||||
/**
|
||||
* @param TJRI $journals
|
||||
* @param CRI $categories
|
||||
* @param BRI $budgets
|
||||
* @param PRI $piggybanks
|
||||
* @param ARI $accounts
|
||||
*/
|
||||
public function __construct(TJRI $journals, CRI $categories, BRI $budgets, PRI $piggybanks, ARI $accounts)
|
||||
{
|
||||
$this->_journals = $journals;
|
||||
$this->_categories = $categories;
|
||||
$this->_budgets = $budgets;
|
||||
$this->_piggybanks = $piggybanks;
|
||||
$this->_accounts = $accounts;
|
||||
$this->overruleUser(\Auth::user());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
$this->_journals->overruleUser($user);
|
||||
$this->_categories->overruleUser($user);
|
||||
$this->_budgets->overruleUser($user);
|
||||
$this->_piggybanks->overruleUser($user);
|
||||
$this->_accounts->overruleUser($user);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \TransactionJournal $journal
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag|\TransactionJournal
|
||||
*/
|
||||
public function update(\TransactionJournal $journal, array $data)
|
||||
{
|
||||
/*
|
||||
* Update the journal using the repository.
|
||||
*/
|
||||
$journal = $this->_journals->update($journal, $data);
|
||||
|
||||
/*
|
||||
* If invalid, return the message bag:
|
||||
*/
|
||||
if (!$journal->validate()) {
|
||||
return $journal->errors();
|
||||
}
|
||||
|
||||
/*
|
||||
* find budget using repository
|
||||
*/
|
||||
|
||||
if (isset($data['budget_id'])) {
|
||||
$budget = $this->_budgets->find($data['budget_id']);
|
||||
}
|
||||
|
||||
/*
|
||||
* find category using repository
|
||||
*/
|
||||
$category = $this->_categories->firstOrCreate($data['category']);
|
||||
|
||||
/*
|
||||
* Find piggy bank using repository:
|
||||
*/
|
||||
$piggybank = null;
|
||||
if (isset($data['piggybank_id'])) {
|
||||
$piggybank = $this->_piggybanks->find($data['piggybank_id']);
|
||||
}
|
||||
|
||||
/*
|
||||
* save accounts using repositories
|
||||
* this depends on the kind of transaction and i've yet to fix this.
|
||||
*/
|
||||
|
||||
if (isset($data['account_id'])) {
|
||||
$from = $this->_accounts->findAssetAccountById($data['account_id']);
|
||||
}
|
||||
if (isset($data['expense_account'])) {
|
||||
$to = $this->_accounts->findExpenseAccountByName($data['expense_account']);
|
||||
}
|
||||
if (isset($data['revenue_account'])) {
|
||||
$from = $this->_accounts->findRevenueAccountByName($data['revenue_account']);
|
||||
$to = $this->_accounts->findAssetAccountById($data['account_id']);
|
||||
}
|
||||
if (isset($data['account_from_id'])) {
|
||||
$from = $this->_accounts->findAssetAccountById($data['account_from_id']);
|
||||
}
|
||||
if (isset($data['account_to_id'])) {
|
||||
$to = $this->_accounts->findAssetAccountById($data['account_to_id']);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Add a custom error when they are the same.
|
||||
*/
|
||||
if ($to->id == $from->id) {
|
||||
$bag = new MessageBag;
|
||||
$bag->add('account_from_id', 'The account from cannot be the same as the account to.');
|
||||
return $bag;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the transactions need new data:
|
||||
*/
|
||||
$transactions = $journal->transactions()->orderBy('amount', 'ASC')->get();
|
||||
/** @var \Transaction $transaction */
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
switch (true) {
|
||||
case ($index == 0): // FROM account
|
||||
$transaction->account()->associate($from);
|
||||
$transaction->amount = floatval($data['amount']) * -1;
|
||||
break;
|
||||
case ($index == 1): // TO account.
|
||||
$transaction->account()->associate($to);
|
||||
$transaction->amount = floatval($data['amount']);
|
||||
break;
|
||||
}
|
||||
$transaction->save();
|
||||
// either way, try to attach the piggy bank:
|
||||
if (!is_null($piggybank)) {
|
||||
if ($piggybank->account_id == $transaction->account_id) {
|
||||
$transaction->piggybank()->associate($piggybank);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Connect budget and category:
|
||||
*/
|
||||
$budgetids = !isset($budget) || (isset($budget) && is_null($budget)) ? [] : [$budget->id];
|
||||
$catids = is_null($category) ? [] : [$category->id];
|
||||
$components = array_merge($budgetids,$catids);
|
||||
$journal->components()->sync($components);
|
||||
$journal->save();
|
||||
|
||||
if (isset($data['return_journal']) && $data['return_journal'] == true) {
|
||||
return $journal;
|
||||
}
|
||||
return $journal->errors();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns messages about the validation.
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function validate(array $data)
|
||||
{
|
||||
$errors = new MessageBag;
|
||||
$warnings = new MessageBag;
|
||||
$successes = new MessageBag;
|
||||
|
||||
/*
|
||||
* Description:
|
||||
*/
|
||||
if (strlen($data['description']) == 0) {
|
||||
$errors->add('description', 'The description should not be this short.');
|
||||
}
|
||||
if (strlen($data['description']) > 250) {
|
||||
$errors->add('description', 'The description should not be this long.');
|
||||
}
|
||||
|
||||
/*
|
||||
* Amount
|
||||
*/
|
||||
if (floatval($data['amount']) <= 0) {
|
||||
$errors->add('amount', 'The amount cannot be zero or less than zero.');
|
||||
}
|
||||
if (floatval($data['amount']) > 10000) {
|
||||
$warnings->add('amount', 'OK, but that\'s a lot of money dude.');
|
||||
}
|
||||
|
||||
/*
|
||||
* Date
|
||||
*/
|
||||
try {
|
||||
$date = new Carbon($data['date']);
|
||||
} catch (Exception $e) {
|
||||
$errors->add('date', 'The date entered was invalid');
|
||||
}
|
||||
if (strlen($data['date']) == 0) {
|
||||
$errors->add('date', 'The date entered was invalid');
|
||||
}
|
||||
if (!$errors->has('date')) {
|
||||
$successes->add('date', 'OK!');
|
||||
}
|
||||
|
||||
/*
|
||||
* Category
|
||||
*/
|
||||
$category = $this->_categories->findByName($data['category']);
|
||||
if (strlen($data['category']) == 0) {
|
||||
$warnings->add('category', 'No category will be created.');
|
||||
} else {
|
||||
if (is_null($category)) {
|
||||
$warnings->add('category', 'Will have to be created.');
|
||||
} else {
|
||||
$successes->add('category', 'OK!');
|
||||
}
|
||||
}
|
||||
|
||||
switch ($data['what']) {
|
||||
default:
|
||||
throw new FireflyException('Cannot validate a ' . $data['what']);
|
||||
break;
|
||||
case 'deposit':
|
||||
/*
|
||||
* Tests for deposit
|
||||
*/
|
||||
// asset account
|
||||
$accountId = isset($data['account_id']) ? intval($data['account_id']) : 0;
|
||||
$account = $this->_accounts->find($accountId);
|
||||
if (is_null($account)) {
|
||||
$errors->add('account_id', 'Cannot find this asset account.');
|
||||
} else {
|
||||
$successes->add('account_id', 'OK!');
|
||||
}
|
||||
|
||||
// revenue account:
|
||||
if (strlen($data['revenue_account']) == 0) {
|
||||
$warnings->add('revenue_account', 'Revenue account will be "cash".');
|
||||
} else {
|
||||
$exp = $this->_accounts->findRevenueAccountByName($data['revenue_account'], false);
|
||||
if (is_null($exp)) {
|
||||
$warnings->add('revenue_account', 'Expense account will be created.');
|
||||
} else {
|
||||
$successes->add('revenue_account', 'OK!');
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 'transfer':
|
||||
// account from
|
||||
$accountId = isset($data['account_from_id']) ? intval($data['account_from_id']) : 0;
|
||||
$account = $this->_accounts->find($accountId);
|
||||
if (is_null($account)) {
|
||||
$errors->add('account_from_id', 'Cannot find this asset account.');
|
||||
} else {
|
||||
$successes->add('account_from_id', 'OK!');
|
||||
}
|
||||
unset($accountId);
|
||||
// account to
|
||||
$accountId = isset($data['account_to_id']) ? intval($data['account_to_id']) : 0;
|
||||
$account = $this->_accounts->find($accountId);
|
||||
if (is_null($account)) {
|
||||
$errors->add('account_to_id', 'Cannot find this asset account.');
|
||||
} else {
|
||||
$successes->add('account_to_id', 'OK!');
|
||||
}
|
||||
unset($accountId);
|
||||
|
||||
// piggy bank
|
||||
$piggybankId = isset($data['piggybank_id']) ? intval($data['piggybank_id']) : 0;
|
||||
$piggybank = $this->_piggybanks->find($piggybankId);
|
||||
if (is_null($piggybank)) {
|
||||
$warnings->add('piggybank_id', 'No piggy bank will be modified.');
|
||||
} else {
|
||||
$successes->add('piggybank_id', 'OK!');
|
||||
}
|
||||
|
||||
break;
|
||||
case 'withdrawal':
|
||||
/*
|
||||
* Tests for withdrawal
|
||||
*/
|
||||
// asset account
|
||||
$accountId = isset($data['account_id']) ? intval($data['account_id']) : 0;
|
||||
$account = $this->_accounts->find($accountId);
|
||||
if (is_null($account)) {
|
||||
$errors->add('account_id', 'Cannot find this asset account.');
|
||||
} else {
|
||||
$successes->add('account_id', 'OK!');
|
||||
}
|
||||
|
||||
// expense account
|
||||
if (strlen($data['expense_account']) == 0) {
|
||||
$warnings->add('expense_account', 'Expense account will be "cash".');
|
||||
} else {
|
||||
$exp = $this->_accounts->findExpenseAccountByName($data['expense_account'], false);
|
||||
if (is_null($exp)) {
|
||||
$warnings->add('expense_account', 'Expense account will be created.');
|
||||
} else {
|
||||
$successes->add('expense_account', 'OK!');
|
||||
}
|
||||
}
|
||||
|
||||
// budget
|
||||
if (!isset($data['budget_id']) || (isset($data['budget_id']) && intval($data['budget_id']) == 0)) {
|
||||
$warnings->add('budget_id', 'No budget selected.');
|
||||
} else {
|
||||
$budget = $this->_budgets->find(intval($data['budget_id']));
|
||||
if (is_null($budget)) {
|
||||
$errors->add('budget_id', 'This budget does not exist');
|
||||
} else {
|
||||
$successes->add('budget_id', 'OK!');
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (count($errors->get('description')) == 0) {
|
||||
$successes->add('description', 'OK!');
|
||||
}
|
||||
|
||||
if (count($errors->get('amount')) == 0) {
|
||||
$successes->add('amount', 'OK!');
|
||||
}
|
||||
|
||||
return ['errors' => $errors, 'warnings' => $warnings, 'successes' => $successes];
|
||||
/*
|
||||
* Tests for deposit
|
||||
*/
|
||||
/*
|
||||
* Tests for transfer
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a full transaction journal and associated stuff
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag|\TransactionJournal
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ShortVariable)
|
||||
*/
|
||||
public function store(array $data)
|
||||
{
|
||||
/*
|
||||
* save journal using repository
|
||||
*/
|
||||
$journal = $this->_journals->store($data);
|
||||
|
||||
/*
|
||||
* If invalid, return the message bag:
|
||||
*/
|
||||
if (!$journal->validate()) {
|
||||
return $journal->errors();
|
||||
}
|
||||
|
||||
/*
|
||||
* find budget using repository
|
||||
*/
|
||||
if (isset($data['budget_id'])) {
|
||||
$budget = $this->_budgets->find($data['budget_id']);
|
||||
}
|
||||
|
||||
/*
|
||||
* find category using repository
|
||||
*/
|
||||
$category = $this->_categories->firstOrCreate($data['category']);
|
||||
|
||||
/*
|
||||
* Find piggy bank using repository:
|
||||
*/
|
||||
$piggybank = null;
|
||||
if (isset($data['piggybank_id'])) {
|
||||
$piggybank = $this->_piggybanks->find($data['piggybank_id']);
|
||||
}
|
||||
|
||||
/*
|
||||
* save accounts using repositories
|
||||
* this depends on the kind of transaction and i've yet to fix this.
|
||||
*/
|
||||
if (isset($data['account_id'])) {
|
||||
$from = $this->_accounts->findAssetAccountById($data['account_id']);
|
||||
}
|
||||
if (isset($data['expense_account'])) {
|
||||
$to = $this->_accounts->findExpenseAccountByName($data['expense_account']);
|
||||
|
||||
}
|
||||
if (isset($data['revenue_account'])) {
|
||||
$from = $this->_accounts->findRevenueAccountByName($data['revenue_account']);
|
||||
$to = $this->_accounts->findAssetAccountById($data['account_id']);
|
||||
}
|
||||
if (isset($data['account_from_id'])) {
|
||||
$from = $this->_accounts->findAssetAccountById($data['account_from_id']);
|
||||
}
|
||||
if (isset($data['account_to_id'])) {
|
||||
$to = $this->_accounts->findAssetAccountById($data['account_to_id']);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add a custom error when they are the same.
|
||||
*/
|
||||
if ($to->id == $from->id) {
|
||||
$bag = new MessageBag;
|
||||
$bag->add('account_from_id', 'The account from cannot be the same as the account to.');
|
||||
return $bag;
|
||||
}
|
||||
|
||||
/*
|
||||
* Save transactions using repository. We try to connect the (possibly existing)
|
||||
* piggy bank to either transaction, knowing it will only work with one of them.
|
||||
*/
|
||||
/** @var \Transaction $one */
|
||||
$one = $this->_journals->saveTransaction($journal, $from, floatval($data['amount']) * -1);
|
||||
$one->connectPiggybank($piggybank);
|
||||
$two = $this->_journals->saveTransaction($journal, $to, floatval($data['amount']));
|
||||
$two->connectPiggybank($piggybank);
|
||||
/*
|
||||
* Count for $journal is zero? Then there were errors!
|
||||
*/
|
||||
if ($journal->transactions()->count() < 2) {
|
||||
/*
|
||||
* Join message bags and return them:
|
||||
*/
|
||||
$bag = $one->errors();
|
||||
$bag->merge($two->errors());
|
||||
return $bag;
|
||||
}
|
||||
|
||||
/*
|
||||
* Connect budget, category and piggy bank:
|
||||
*/
|
||||
if (isset($budget) && !is_null($budget)) {
|
||||
$journal->budgets()->save($budget);
|
||||
}
|
||||
if (!is_null($category)) {
|
||||
$journal->categories()->save($category);
|
||||
}
|
||||
$journal->completed = true;
|
||||
$journal->save();
|
||||
|
||||
/*
|
||||
* Trigger recurring transaction event.
|
||||
*/
|
||||
\Event::fire('journals.store',[$journal]);
|
||||
|
||||
if (isset($data['return_journal']) && $data['return_journal'] == true) {
|
||||
return ['journal' => $journal, 'messagebag' => $journal->errors()];
|
||||
}
|
||||
return $journal->errors();
|
||||
}
|
||||
|
||||
}
|
||||
48
app/lib/Firefly/Helper/Controllers/TransactionInterface.php
Normal file
48
app/lib/Firefly/Helper/Controllers/TransactionInterface.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Helper\Controllers;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
* Interface TransactionInterface
|
||||
*
|
||||
* @package Firefly\Helper\Controllers
|
||||
*/
|
||||
interface TransactionInterface {
|
||||
|
||||
/**
|
||||
* Store a full transaction journal and associated stuff
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag|\TransactionJournal
|
||||
*/
|
||||
public function store(array $data);
|
||||
|
||||
/**
|
||||
* Returns messages about the validation.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function validate(array $data);
|
||||
|
||||
/**
|
||||
* @param \TransactionJournal $journal
|
||||
* @param array $data
|
||||
*
|
||||
* @return MessageBag|\TransactionJournal
|
||||
*/
|
||||
public function update(\TransactionJournal $journal, array $data);
|
||||
|
||||
/**
|
||||
* Overrule the user used when the class is created.
|
||||
*
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
|
||||
}
|
||||
@@ -38,7 +38,7 @@ class EmailHelper implements EmailHelperInterface
|
||||
{
|
||||
|
||||
$password = \Str::random(12);
|
||||
$user->password = \Hash::make($password);
|
||||
$user->password = $password;
|
||||
$user->reset = \Str::random(32); // new one.
|
||||
$user->forceSave();
|
||||
$email = $user->email;
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Helper\Form;
|
||||
|
||||
/**
|
||||
* Class FormHelper
|
||||
*
|
||||
* @package Firefly\Form
|
||||
*/
|
||||
class FormHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* @param null $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function budget($value = null)
|
||||
{
|
||||
|
||||
$str = '<select name="budget_id" class="form-control">';
|
||||
|
||||
$str .= '<option value="0" label="(no budget)"';
|
||||
if (is_null($value) || intval($value) == 0) {
|
||||
$str .= ' selected="selected"';
|
||||
}
|
||||
$str .= '</option>';
|
||||
|
||||
/** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budgets */
|
||||
$budgets = \App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$list = $budgets->getAsSelectList();
|
||||
foreach ($list as $id => $name) {
|
||||
$str .= '<option value="' . e($id) . '" label="' . e($name) . '"';
|
||||
if ($id == intval($value)) {
|
||||
$str .= ' selected="selected"';
|
||||
}
|
||||
$str .= '>' . e($name) . '</option>';
|
||||
}
|
||||
|
||||
|
||||
$str .= '</select>';
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Helper\Form;
|
||||
|
||||
use Illuminate\Events\Dispatcher;
|
||||
|
||||
/**
|
||||
* Class FormTrigger
|
||||
*
|
||||
* @package Firefly\Helper\Form
|
||||
*/
|
||||
class FormTrigger
|
||||
{
|
||||
|
||||
public function registerFormExtensions()
|
||||
{
|
||||
\Form::macro(
|
||||
'budget', function () {
|
||||
$helper = new FormHelper;
|
||||
|
||||
return $helper->budget();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen('laravel.booted', 'Firefly\Helper\Form\FormTrigger@registerFormExtensions');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,6 +26,27 @@ class HelperServiceProvider extends ServiceProvider
|
||||
'Firefly\Helper\Controllers\ChartInterface',
|
||||
'Firefly\Helper\Controllers\Chart'
|
||||
);
|
||||
|
||||
$this->app->bind(
|
||||
'Firefly\Helper\Controllers\JsonInterface',
|
||||
'Firefly\Helper\Controllers\Json'
|
||||
);
|
||||
|
||||
$this->app->bind(
|
||||
'Firefly\Helper\Controllers\RecurringInterface',
|
||||
'Firefly\Helper\Controllers\Recurring'
|
||||
);
|
||||
|
||||
$this->app->bind(
|
||||
'Firefly\Helper\Controllers\SearchInterface',
|
||||
'Firefly\Helper\Controllers\Search'
|
||||
);
|
||||
|
||||
$this->app->bind(
|
||||
'Firefly\Helper\Controllers\TransactionInterface',
|
||||
'Firefly\Helper\Controllers\Transaction'
|
||||
);
|
||||
|
||||
$this->app->bind(
|
||||
'Firefly\Helper\Controllers\CategoryInterface',
|
||||
'Firefly\Helper\Controllers\Category'
|
||||
|
||||
@@ -1,327 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Helper\Migration;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Firefly\Exception\FireflyException;
|
||||
|
||||
/**
|
||||
* Class MigrationHelper
|
||||
*
|
||||
* @package Firefly\Helper\Migration
|
||||
*/
|
||||
class MigrationHelper implements MigrationHelperInterface
|
||||
{
|
||||
protected $path;
|
||||
protected $JSON;
|
||||
protected $map = [];
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function loadFile($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function validFile()
|
||||
{
|
||||
// file does not exist:
|
||||
if (!file_exists($this->path)) {
|
||||
\Log::error('Migration file ' . $this->path . ' does not exist!');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// load the content:
|
||||
$content = file_get_contents($this->path);
|
||||
if ($content === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// parse the content
|
||||
$this->JSON = json_decode($content);
|
||||
if (is_null($this->JSON)) {
|
||||
return false;
|
||||
}
|
||||
\Log::info('Migration file ' . $this->path . ' is valid!');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function migrate()
|
||||
{
|
||||
\Log::info('Start of migration.');
|
||||
\DB::beginTransaction();
|
||||
|
||||
try {
|
||||
// create cash account:
|
||||
$this->_createCashAccount();
|
||||
|
||||
$this->_importAccounts();
|
||||
$this->_importComponents();
|
||||
//$this->_importPiggybanks();
|
||||
|
||||
// create transactions:
|
||||
$this->_importTransactions();
|
||||
|
||||
// create transfers:
|
||||
$this->_importTransfers();
|
||||
|
||||
// create limits:
|
||||
$this->_importLimits();
|
||||
|
||||
|
||||
} catch (FireflyException $e) {
|
||||
\DB::rollBack();
|
||||
\Log::error('Rollback because of error!');
|
||||
\Log::error($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
\DB::commit();
|
||||
\Log::info('Done!');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function _createCashAccount()
|
||||
{
|
||||
$cashAT = \AccountType::where('description', 'Cash account')->first();
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$cash = $accounts->store(['name' => 'Cash account', 'account_type' => $cashAT, 'active' => 0]);
|
||||
\Log::info('Created cash account (#' . $cash->id . ')');
|
||||
$this->map['cash'] = $cash;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function _importAccounts()
|
||||
{
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
\Log::info('Going to import ' . count($this->JSON->accounts) . ' accounts.');
|
||||
foreach ($this->JSON->accounts as $entry) {
|
||||
// create account:
|
||||
if ($entry->openingbalance == 0) {
|
||||
$account = $accounts->store(['name' => $entry->name]);
|
||||
} else {
|
||||
$account = $accounts->storeWithInitialBalance(
|
||||
['name' => $entry->name],
|
||||
new Carbon($entry->openingbalancedate),
|
||||
floatval($entry->openingbalance)
|
||||
);
|
||||
}
|
||||
$this->map['accounts'][$entry->id] = $account;
|
||||
\Log::info('Imported account "' . $entry->name . '" with balance ' . $entry->openingbalance);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function _importComponents()
|
||||
{
|
||||
$beneficiaryAT = \AccountType::where('description', 'Beneficiary account')->first();
|
||||
foreach ($this->JSON->components as $entry) {
|
||||
switch ($entry->type->type) {
|
||||
case 'beneficiary':
|
||||
/** @noinspection PhpParamsInspection */
|
||||
$beneficiary = $this->_importBeneficiary($entry, $beneficiaryAT);
|
||||
$this->map['accounts'][$entry->id] = $beneficiary;
|
||||
break;
|
||||
case 'category':
|
||||
$component = $this->_importCategory($entry);
|
||||
$this->map['categories'][$entry->id] = $component;
|
||||
break;
|
||||
case 'budget':
|
||||
$component = $this->_importBudget($entry);
|
||||
$this->map['budgets'][$entry->id] = $component;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $component
|
||||
* @param \AccountType $beneficiaryAT
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _importBeneficiary($component, \AccountType $beneficiaryAT)
|
||||
{
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accounts */
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
|
||||
return $accounts->store(
|
||||
[
|
||||
'name' => $component->name,
|
||||
'account_type' => $beneficiaryAT
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $component
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _importCategory($component)
|
||||
{
|
||||
/** @var \Firefly\Storage\Component\ComponentRepositoryInterface $components */
|
||||
$components = \App::make('Firefly\Storage\Component\ComponentRepositoryInterface');
|
||||
|
||||
return $components->store(['name' => $component->name, 'class' => 'Category']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $component
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _importBudget($component)
|
||||
{
|
||||
/** @var \Firefly\Storage\Component\ComponentRepositoryInterface $components */
|
||||
$components = \App::make('Firefly\Storage\Component\ComponentRepositoryInterface');
|
||||
|
||||
return $components->store(['name' => $component->name, 'class' => 'Budget']);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function _importTransactions()
|
||||
{
|
||||
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $journals */
|
||||
$journals = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
|
||||
// loop component_transaction to find beneficiaries, categories and budgets:
|
||||
$beneficiaries = [];
|
||||
$categories = [];
|
||||
$budgets = [];
|
||||
foreach ($this->JSON->component_transaction as $entry) {
|
||||
// beneficiaries
|
||||
if (isset($this->map['accounts'][$entry->component_id])) {
|
||||
$beneficiaries[$entry->transaction_id] = $this->map['accounts'][$entry->component_id];
|
||||
}
|
||||
|
||||
// categories
|
||||
if (isset($this->map['categories'][$entry->component_id])) {
|
||||
$categories[$entry->transaction_id] = $this->map['categories'][$entry->component_id];
|
||||
}
|
||||
|
||||
// budgets:
|
||||
if (isset($this->map['budgets'][$entry->component_id])) {
|
||||
$budgets[$entry->transaction_id] = $this->map['budgets'][$entry->component_id];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->JSON->transactions as $entry) {
|
||||
|
||||
// to properly save the amount, do it times -1:
|
||||
$amount = $entry->amount * -1;
|
||||
|
||||
/** @var \Account $fromAccount */
|
||||
$fromAccount = isset($this->map['accounts'][$entry->account_id])
|
||||
? $this->map['accounts'][$entry->account_id] : false;
|
||||
|
||||
/** @var \Account $toAccount */
|
||||
$toAccount = isset($beneficiaries[$entry->id]) ? $beneficiaries[$entry->id] : $this->map['cash'];
|
||||
|
||||
$date = new Carbon($entry->date);
|
||||
$journal = $journals->createSimpleJournal($fromAccount, $toAccount, $entry->description, $amount, $date);
|
||||
|
||||
// save budgets and categories, on the journal
|
||||
if (isset($budgets[$entry->id])) {
|
||||
$budget = $budgets[$entry->id];
|
||||
$journal->budgets()->save($budget);
|
||||
}
|
||||
if (isset($categories[$entry->id])) {
|
||||
$category = $categories[$entry->id];
|
||||
$journal->categories()->save($category);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function _importTransfers()
|
||||
{
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $journals */
|
||||
$journals = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
|
||||
foreach ($this->JSON->transfers as $entry) {
|
||||
|
||||
// to properly save the amount, do it times 1 (?):
|
||||
$amount = $entry->amount * -1;
|
||||
|
||||
/** @var \Account $fromAccount */
|
||||
$fromAccount = isset($this->map['accounts'][$entry->accountfrom_id])
|
||||
? $this->map['accounts'][$entry->accountto_id] : false;
|
||||
|
||||
/** @var \Account $toAccount */
|
||||
$toAccount = isset($this->map['accounts'][$entry->accountto_id])
|
||||
? $this->map['accounts'][$entry->accountfrom_id] : false;
|
||||
|
||||
$date = new Carbon($entry->date);
|
||||
$journals->createSimpleJournal($fromAccount, $toAccount, $entry->description, $amount, $date);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function _importLimits()
|
||||
{
|
||||
\Log::info('Importing limits');
|
||||
foreach ($this->JSON->limits as $entry) {
|
||||
\Log::debug(
|
||||
'Now at #' . $entry->id . ': EUR ' . $entry->amount . ' for month ' . $entry->date
|
||||
. ' and componentID: ' . $entry->component_id
|
||||
);
|
||||
$budget = isset($this->map['budgets'][$entry->component_id]) ? $this->map['budgets'][$entry->component_id]
|
||||
: null;
|
||||
if (!is_null($budget)) {
|
||||
\Log::debug('Found budget for this limit: #' . $budget->id . ', ' . $budget->name);
|
||||
|
||||
$limit = new \Limit;
|
||||
$limit->budget()->associate($budget);
|
||||
$limit->startdate = new Carbon($entry->date);
|
||||
$limit->amount = floatval($entry->amount);
|
||||
$limit->repeats = 0;
|
||||
$limit->repeat_freq = 'monthly';
|
||||
try {
|
||||
$limit->save();
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
} else {
|
||||
\Log::warning('No budget for this limit!');
|
||||
}
|
||||
|
||||
|
||||
// create repeat thing should not be necessary.
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Helper\Migration;
|
||||
|
||||
/**
|
||||
* Interface MigrationHelperInterface
|
||||
*
|
||||
* @package Firefly\Helper\Migration
|
||||
*/
|
||||
interface MigrationHelperInterface
|
||||
{
|
||||
/**
|
||||
* @param $path
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function loadFile($path);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function validFile();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function migrate();
|
||||
|
||||
}
|
||||
@@ -3,98 +3,115 @@
|
||||
namespace Firefly\Helper\Toolkit;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Firefly\Exception\FireflyException;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class Toolkit
|
||||
*
|
||||
* @package Firefly\Helper\Toolkit
|
||||
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
|
||||
*/
|
||||
class Toolkit implements ToolkitInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* Lots of code in Firefly III still depends on session['start'], session['end'] and
|
||||
* session['range'] to be available, even though this feature has been removed from Firefly
|
||||
* in favor of a new reporting feature. This reporting feature can show the user past and future
|
||||
* date ranges instead of the dashboard (the dashboard always shows "right now").
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|mixed|null
|
||||
* The only actual choice the user is left with is the range, which can be changed using the Preferences pane.
|
||||
*
|
||||
* The start/end dates are set here, regardless of what the user might want to see.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function getDateRange(Request $request)
|
||||
public function getDateRange()
|
||||
{
|
||||
/*
|
||||
* Get all data from the session:
|
||||
*/
|
||||
$range = $this->_getRange();
|
||||
$start = $this->_getStartDate();
|
||||
$end = $this->_getEndDate();
|
||||
#\Log::debug('Range is: ' . $range);
|
||||
$start = \Session::has('start') ? \Session::get('start') : new Carbon;
|
||||
|
||||
// update start only:
|
||||
#\Log::debug('Session start is: ' . $start->format('Y-m-d'));
|
||||
$end = \Session::has('end') ? \Session::get('end') : new Carbon;
|
||||
#\Log::debug('Session end is : ' . $end->format('Y-m-d'));
|
||||
|
||||
/*
|
||||
* Force start date to at the start of the $range.
|
||||
* Ie. the start of the week, month, year.
|
||||
*/
|
||||
$start = $this->_updateStartDate($range, $start);
|
||||
#\Log::debug('After update, session start is: ' . $start->format('Y-m-d'));
|
||||
|
||||
// update end only:
|
||||
$end = $this->_updateEndDate($range, $start, $end);
|
||||
/*
|
||||
* Force end date to at the END of the $range. Always based on $start.
|
||||
* Ie. the END of the week, month, year.
|
||||
*/
|
||||
$end = $this->_updateEndDate($range, $start);
|
||||
#\Log::debug('After update, session end is : ' . $end->format('Y-m-d'));
|
||||
|
||||
if (\Input::get('action') == 'prev') {
|
||||
$start = $this->_moveStartPrevious($range, $start);
|
||||
$end = $this->_moveEndPrevious($range, $end);
|
||||
}
|
||||
if (\Input::get('action') == 'next') {
|
||||
$start = $this->_moveStartNext($range, $start);
|
||||
$end = $this->_moveEndNext($range, $end);
|
||||
}
|
||||
/*
|
||||
* get the name of the month, depending on the range. Purely for astetics
|
||||
*/
|
||||
$period = $this->_periodName($range, $start);
|
||||
|
||||
// save in session:
|
||||
/*
|
||||
* Get the date for the previous and next period.
|
||||
* Ie. next week, next month, etc.
|
||||
*/
|
||||
$prev = $this->_previous($range, clone $start);
|
||||
$next = $this->_next($range, clone $start);
|
||||
|
||||
/*
|
||||
* Save everything in the session:
|
||||
*/
|
||||
\Session::put('start', $start);
|
||||
\Session::put('end', $end);
|
||||
\Session::put('range', $range);
|
||||
if (!is_null(\Input::get('action'))) {
|
||||
return \Redirect::to($request->url());
|
||||
|
||||
}
|
||||
|
||||
\Session::put('period', $period);
|
||||
\Session::put('prev', $this->_periodName($range, $prev));
|
||||
\Session::put('next', $this->_periodName($range, $next));
|
||||
return null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function getDateRangeDates()
|
||||
public function checkImportJobs()
|
||||
{
|
||||
return [\Session::get('start'), \Session::get('end')];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
/*
|
||||
* Get all jobs.
|
||||
*/
|
||||
public function getReminders()
|
||||
{
|
||||
// get reminders, for menu, mumble mumble:
|
||||
/** @var \Importmap $importJob */
|
||||
$importJob = \Importmap::where('user_id', \Auth::user()->id)
|
||||
->where('totaljobs', '>', \DB::Raw('`jobsdone`'))
|
||||
->orderBy('created_at', 'DESC')
|
||||
->first();
|
||||
if (!is_null($importJob)) {
|
||||
$diff = intval($importJob->totaljobs) - intval($importJob->jobsdone);
|
||||
$date = new Carbon;
|
||||
$today = new Carbon;
|
||||
$reminders = \Auth::user()->reminders()->where('class', 'PiggybankReminder')->validOn($today)->get();
|
||||
|
||||
/** @var \Reminder $reminder */
|
||||
foreach ($reminders as $index => $reminder) {
|
||||
if (\Session::has('dismissal-' . $reminder->id)) {
|
||||
$time = \Session::get('dismissal-' . $reminder->id);
|
||||
if ($time >= $today) {
|
||||
unset($reminders[$index]);
|
||||
$date->addSeconds($diff);
|
||||
\Session::put('job_pct', $importJob->pct());
|
||||
\Session::put('job_text', $date->diffForHumans());
|
||||
} else {
|
||||
\Session::forget('job_pct');
|
||||
\Session::forget('job_text');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
\Session::put('reminderCount', count($reminders));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _getrange()
|
||||
protected function _getRange()
|
||||
{
|
||||
if (!is_null(\Input::get('range'))) {
|
||||
$range = \Input::get('range');
|
||||
} else {
|
||||
if (!is_null(\Session::get('range'))) {
|
||||
$range = \Session::get('range');
|
||||
} else {
|
||||
@@ -104,39 +121,12 @@ class Toolkit implements ToolkitInterface
|
||||
|
||||
// default range:
|
||||
$range = $viewRange->data;
|
||||
\Session::put('range', $range);
|
||||
}
|
||||
}
|
||||
|
||||
return $range;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon|mixed
|
||||
*/
|
||||
protected function _getStartDate()
|
||||
{
|
||||
$start = \Session::has('start') ? \Session::get('start') : new Carbon;
|
||||
if (\Input::get('start') && \Input::get('end')) {
|
||||
$start = new Carbon(\Input::get('start'));
|
||||
}
|
||||
|
||||
return $start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon|mixed
|
||||
*/
|
||||
protected function _getEndDate()
|
||||
{
|
||||
$end = \Session::has('end') ? \Session::get('end') : new Carbon;
|
||||
if (\Input::get('start') && \Input::get('end')) {
|
||||
$end = new Carbon(\Input::get('end'));
|
||||
}
|
||||
|
||||
return $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
* @param Carbon $start
|
||||
@@ -145,7 +135,6 @@ class Toolkit implements ToolkitInterface
|
||||
*/
|
||||
protected function _updateStartDate($range, Carbon $start)
|
||||
{
|
||||
$today = new Carbon;
|
||||
switch ($range) {
|
||||
case '1D':
|
||||
$start->startOfDay();
|
||||
@@ -160,12 +149,15 @@ class Toolkit implements ToolkitInterface
|
||||
$start->firstOfQuarter();
|
||||
break;
|
||||
case '6M':
|
||||
if (intval($today->format('m')) >= 7) {
|
||||
if (intval($start->format('m')) >= 7) {
|
||||
$start->startOfYear()->addMonths(6);
|
||||
} else {
|
||||
$start->startOfYear();
|
||||
}
|
||||
break;
|
||||
case '1Y':
|
||||
$start->startOfYear();
|
||||
break;
|
||||
}
|
||||
|
||||
return $start;
|
||||
@@ -179,150 +171,337 @@ class Toolkit implements ToolkitInterface
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
protected function _updateEndDate($range, Carbon $start, Carbon $end)
|
||||
protected function _updateEndDate($range, Carbon $start)
|
||||
{
|
||||
$today = new Carbon;
|
||||
switch ($range) {
|
||||
case '1D':
|
||||
$end = clone $start;
|
||||
switch ($range) {
|
||||
default:
|
||||
throw new FireflyException('_updateEndDate cannot handle $range ' . $range);
|
||||
break;
|
||||
case '1D':
|
||||
$end->endOfDay();
|
||||
break;
|
||||
case '1W':
|
||||
$end = clone $start;
|
||||
$end->endOfWeek();
|
||||
break;
|
||||
case '1M':
|
||||
$end = clone $start;
|
||||
$end->endOfMonth();
|
||||
break;
|
||||
case '3M':
|
||||
$end = clone $start;
|
||||
$end->lastOfQuarter();
|
||||
break;
|
||||
case '6M':
|
||||
$end = clone $start;
|
||||
if (intval($today->format('m')) >= 7) {
|
||||
if (intval($start->format('m')) >= 7) {
|
||||
$end->endOfYear();
|
||||
} else {
|
||||
$end->startOfYear()->addMonths(6);
|
||||
}
|
||||
break;
|
||||
case '1Y':
|
||||
$end->endOfYear();
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
* @param Carbon $start
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
protected function _moveStartPrevious($range, Carbon $start)
|
||||
protected function _periodName($range, Carbon $date)
|
||||
{
|
||||
switch ($range) {
|
||||
default:
|
||||
throw new FireflyException('No _periodName() for range "' . $range . '"');
|
||||
break;
|
||||
case '1D':
|
||||
return $date->format('jS F Y');
|
||||
break;
|
||||
case '1W':
|
||||
return 'week ' . $date->format('W, Y');
|
||||
break;
|
||||
case '1M':
|
||||
return $date->format('F Y');
|
||||
break;
|
||||
case '3M':
|
||||
$month = intval($date->format('m'));
|
||||
return 'Q' . ceil(($month / 12) * 4) . ' ' . $date->format('Y');
|
||||
break;
|
||||
case '6M':
|
||||
$month = intval($date->format('m'));
|
||||
$half = ceil(($month / 12) * 2);
|
||||
$halfName = $half == 1 ? 'first' : 'second';
|
||||
return $halfName . ' half of ' . $date->format('d-m-Y');
|
||||
break;
|
||||
case '1Y':
|
||||
return $date->format('Y');
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected function _previous($range, Carbon $date)
|
||||
{
|
||||
switch ($range) {
|
||||
default:
|
||||
throw new FireflyException('Cannot do _previous() on ' . $range);
|
||||
break;
|
||||
case '1D':
|
||||
$date->startOfDay()->subDay();
|
||||
break;
|
||||
case '1W':
|
||||
$date->startOfWeek()->subWeek();
|
||||
break;
|
||||
case '1M':
|
||||
$date->startOfMonth()->subMonth();
|
||||
break;
|
||||
case '3M':
|
||||
$date->firstOfQuarter()->subMonths(3)->firstOfQuarter();
|
||||
break;
|
||||
case '6M':
|
||||
$month = intval($date->format('m'));
|
||||
if ($month <= 6) {
|
||||
$date->startOfYear()->subMonths(6);
|
||||
} else {
|
||||
$date->startOfYear();
|
||||
}
|
||||
break;
|
||||
case '1Y':
|
||||
$date->startOfYear()->subYear();
|
||||
break;
|
||||
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
|
||||
protected function _next($range, Carbon $date)
|
||||
{
|
||||
switch ($range) {
|
||||
case '1D':
|
||||
$start->subDay();
|
||||
$date->endOfDay()->addDay();
|
||||
break;
|
||||
case '1W':
|
||||
$start->subWeek();
|
||||
$date->endOfWeek()->addDay()->startOfWeek();
|
||||
break;
|
||||
case '1M':
|
||||
$start->subMonth();
|
||||
$date->endOfMonth()->addDay()->startOfMonth();
|
||||
break;
|
||||
case '3M':
|
||||
$start->subMonths(3)->firstOfQuarter();
|
||||
$date->lastOfQuarter()->addDay();
|
||||
break;
|
||||
case '6M':
|
||||
$start->subMonths(6);
|
||||
if (intval($date->format('m')) >= 7) {
|
||||
$date->startOfYear()->addYear();
|
||||
} else {
|
||||
$date->startOfYear()->addMonths(6);
|
||||
}
|
||||
break;
|
||||
case '1Y':
|
||||
$date->startOfYear()->addYear();
|
||||
break;
|
||||
default:
|
||||
throw new FireflyException('Cannot do _next() on ' . $range);
|
||||
break;
|
||||
}
|
||||
return $start;
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
/*
|
||||
* Get the start date and the range from the session
|
||||
*/
|
||||
$range = $this->_getRange();
|
||||
$start = \Session::get('start');
|
||||
|
||||
/*
|
||||
* Add some period to $start.
|
||||
*/
|
||||
$next = $this->_next($range, clone $start);
|
||||
|
||||
/*
|
||||
* Save in session:
|
||||
*/
|
||||
\Session::put('start', $next);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function prev()
|
||||
{
|
||||
/*
|
||||
* Get the start date and the range from the session
|
||||
*/
|
||||
$range = $this->_getRange();
|
||||
$start = \Session::get('start');
|
||||
|
||||
/*
|
||||
* Substract some period to $start.
|
||||
*/
|
||||
$prev = $this->_previous($range, clone $start);
|
||||
|
||||
/*
|
||||
* Save in session:
|
||||
*/
|
||||
\Session::put('start', $prev);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
* @param Carbon $end
|
||||
* Takes any collection and tries to make a sensible select list compatible array of it.
|
||||
*
|
||||
* @return Carbon
|
||||
* @param Collection $set
|
||||
* @param null $titleField
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _moveEndPrevious($range, Carbon $end)
|
||||
public function makeSelectList(Collection $set, $titleField = null)
|
||||
{
|
||||
switch ($range) {
|
||||
case '1D':
|
||||
$end->subDay();
|
||||
break;
|
||||
case '1W':
|
||||
$end->subWeek();
|
||||
break;
|
||||
case '1M':
|
||||
$end->startOfMonth()->subMonth()->endOfMonth();
|
||||
break;
|
||||
case '3M':
|
||||
$end->subMonths(3)->lastOfQuarter();
|
||||
break;
|
||||
case '6M':
|
||||
$end->subMonths(6);
|
||||
break;
|
||||
$selectList = [];
|
||||
/** @var Model $entry */
|
||||
foreach ($set as $entry) {
|
||||
$id = intval($entry->id);
|
||||
$title = null;
|
||||
if (is_null($titleField)) {
|
||||
// try 'title' field.
|
||||
if (isset($entry->title)) {
|
||||
$title = $entry->title;
|
||||
}
|
||||
// try 'name' field
|
||||
if (is_null($title)) {
|
||||
$title = $entry->name;
|
||||
}
|
||||
return $end;
|
||||
|
||||
// try 'description' field
|
||||
if (is_null($title)) {
|
||||
$title = $entry->description;
|
||||
}
|
||||
} else {
|
||||
$title = $entry->$titleField;
|
||||
}
|
||||
$selectList[$id] = $title;
|
||||
}
|
||||
return $selectList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
* @param Carbon $start
|
||||
*
|
||||
* @return Carbon
|
||||
* @param string $start
|
||||
* @param string $end
|
||||
* @param int $steps
|
||||
*/
|
||||
protected function _moveStartNext($range, Carbon $start)
|
||||
public function colorRange($start, $end, $steps = 5)
|
||||
{
|
||||
switch ($range) {
|
||||
case '1D':
|
||||
$start->addDay();
|
||||
break;
|
||||
case '1W':
|
||||
$start->addWeek();
|
||||
break;
|
||||
case '1M':
|
||||
$start->addMonth();
|
||||
break;
|
||||
case '3M':
|
||||
$start->addMonths(3)->firstOfQuarter();
|
||||
break;
|
||||
case '6M':
|
||||
$start->addMonths(6);
|
||||
break;
|
||||
if (strlen($start) != 6) {
|
||||
throw new FireflyException('Start, ' . e($start) . ' should be a six character HTML colour.');
|
||||
}
|
||||
return $start;
|
||||
if (strlen($end) != 6) {
|
||||
throw new FireflyException('End, ' . e($end) . ' should be a six character HTML colour.');
|
||||
}
|
||||
if ($steps < 1) {
|
||||
throw new FireflyException('Steps must be > 1');
|
||||
}
|
||||
|
||||
$start = '#' . $start;
|
||||
$end = '#' . $end;
|
||||
/*
|
||||
* Split html colours.
|
||||
*/
|
||||
list($rs, $gs, $bs) = sscanf($start, "#%02x%02x%02x");
|
||||
list($re, $ge, $be) = sscanf($end, "#%02x%02x%02x");
|
||||
|
||||
$stepr = ($re - $rs) / $steps;
|
||||
$stepg = ($ge - $gs) / $steps;
|
||||
$stepb = ($be - $bs) / $steps;
|
||||
|
||||
$return = [];
|
||||
for ($i = 0; $i <= $steps; $i++) {
|
||||
$cr = $rs + ($stepr * $i);
|
||||
$cg = $gs + ($stepg * $i);
|
||||
$cb = $bs + ($stepb * $i);
|
||||
|
||||
$return[] = $this->rgb2html($cr, $cg, $cb);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
protected function rgb2html($r, $g = -1, $b = -1)
|
||||
{
|
||||
$r = dechex($r < 0 ? 0 : ($r > 255 ? 255 : $r));
|
||||
$g = dechex($g < 0 ? 0 : ($g > 255 ? 255 : $g));
|
||||
$b = dechex($b < 0 ? 0 : ($b > 255 ? 255 : $b));
|
||||
|
||||
$color = (strlen($r) < 2 ? '0' : '') . $r;
|
||||
$color .= (strlen($g) < 2 ? '0' : '') . $g;
|
||||
$color .= (strlen($b) < 2 ? '0' : '') . $b;
|
||||
return '#' . $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $range
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Carbon
|
||||
* @param Carbon $currentEnd
|
||||
* @param $repeatFreq
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function _moveEndNext($range, Carbon $end)
|
||||
public function endOfPeriod(Carbon $currentEnd, $repeatFreq)
|
||||
{
|
||||
switch ($range) {
|
||||
case '1D':
|
||||
$end->addDay();
|
||||
switch ($repeatFreq) {
|
||||
default:
|
||||
throw new FireflyException('Cannot do getFunctionForRepeatFreq for $repeat_freq ' . $repeatFreq);
|
||||
break;
|
||||
case '1W':
|
||||
$end->addWeek();
|
||||
case 'daily':
|
||||
$currentEnd->addDay();
|
||||
break;
|
||||
case '1M':
|
||||
$end->addMonth();
|
||||
case 'weekly':
|
||||
$currentEnd->addWeek()->subDay();
|
||||
break;
|
||||
case '3M':
|
||||
$end->addMonths(6)->lastOfQuarter();
|
||||
case 'monthly':
|
||||
$currentEnd->addMonth()->subDay();
|
||||
break;
|
||||
case '6M':
|
||||
$end->addMonths(6);
|
||||
case 'quarterly':
|
||||
$currentEnd->addMonths(3)->subDay();
|
||||
break;
|
||||
case 'half-year':
|
||||
$currentEnd->addMonths(6)->subDay();
|
||||
break;
|
||||
case 'yearly':
|
||||
$currentEnd->addYear()->subDay();
|
||||
break;
|
||||
}
|
||||
return $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param $repeatFreq
|
||||
* @param $skip
|
||||
* @return Carbon
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function addPeriod(Carbon $date, $repeatFreq, $skip)
|
||||
{
|
||||
$add = ($skip + 1);
|
||||
switch ($repeatFreq) {
|
||||
default:
|
||||
throw new FireflyException('Cannot do getFunctionForRepeatFreq for $repeat_freq ' . $repeatFreq);
|
||||
break;
|
||||
case 'daily':
|
||||
$date->addDays($add);
|
||||
break;
|
||||
case 'weekly':
|
||||
$date->addWeeks($add);
|
||||
break;
|
||||
case 'monthly':
|
||||
$date->addMonths($add);
|
||||
break;
|
||||
case 'quarterly':
|
||||
$months = $add * 3;
|
||||
$date->addMonths($months);
|
||||
break;
|
||||
case 'half-year':
|
||||
$months = $add * 6;
|
||||
$date->addMonths($months);
|
||||
break;
|
||||
case 'yearly':
|
||||
$date->addYears($add);
|
||||
break;
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
namespace Firefly\Helper\Toolkit;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface ToolkitInterface
|
||||
@@ -12,20 +13,40 @@ use Illuminate\Http\Request;
|
||||
interface ToolkitInterface
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function getDateRange();
|
||||
|
||||
/**
|
||||
* Takes any collection and tries to make a sensible select list compatible array of it.
|
||||
*
|
||||
* @param Collection $set
|
||||
* @param null $titleField
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDateRange(Request $request);
|
||||
public function makeSelectList(Collection $set, $titleField = null);
|
||||
|
||||
public function next();
|
||||
|
||||
public function prev();
|
||||
|
||||
public function checkImportJobs();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @param string $start
|
||||
* @param string $end
|
||||
* @param int $steps
|
||||
*/
|
||||
public function getDateRangeDates();
|
||||
public function colorRange($start, $end, $steps = 5);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @param Carbon $date
|
||||
* @param $repeatFreq
|
||||
* @param $skip
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getReminders();
|
||||
public function addPeriod(Carbon $date, $repeatFreq, $skip);
|
||||
|
||||
}
|
||||
596
app/lib/Firefly/Queue/Import.php
Normal file
596
app/lib/Firefly/Queue/Import.php
Normal file
@@ -0,0 +1,596 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Queue;
|
||||
|
||||
use Illuminate\Queue\Jobs\Job;
|
||||
|
||||
/**
|
||||
* Class Import
|
||||
*
|
||||
* @package Firefly\Queue
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
class Import
|
||||
{
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface */
|
||||
protected $_accounts;
|
||||
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface */
|
||||
protected $_repository;
|
||||
|
||||
/** @var \Firefly\Storage\Piggybank\PiggybankRepositoryInterface */
|
||||
protected $_piggybanks;
|
||||
|
||||
/**
|
||||
* This constructs the import handler and initiates all the relevant interfaces / classes.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$this->_repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
$this->_piggybanks = \App::make('Firefly\Storage\Piggybank\PiggybankRepositoryInterface');
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The final step in the import routine is to get all transactions which have one of their accounts
|
||||
* still set to "import", which means it is a cash transaction. This routine will set them all to cash instead.
|
||||
*
|
||||
* If there was no account present for these accounts in the import routine (no beneficiary set), Firefly
|
||||
* II would fall back to the import account.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function cleanImportAccount(Job $job, array $payload)
|
||||
{
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $this->_repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
// two import account types.
|
||||
$importAccountType = $this->_accounts->findAccountType('Import account');
|
||||
$cashAccountType = $this->_accounts->findAccountType('Cash account');
|
||||
|
||||
// find or create import account:
|
||||
$importAccount = $this->_accounts->firstOrCreate(
|
||||
[
|
||||
'name' => 'Import account',
|
||||
'account_type_id' => $importAccountType->id,
|
||||
'active' => 1,
|
||||
'user_id' => $user->id,
|
||||
]
|
||||
);
|
||||
|
||||
// find or create cash account:
|
||||
$cashAccount = $this->_accounts->firstOrCreate(
|
||||
[
|
||||
'name' => 'Cash account',
|
||||
'account_type_id' => $cashAccountType->id,
|
||||
'active' => 1,
|
||||
'user_id' => $user->id,
|
||||
]
|
||||
);
|
||||
|
||||
// update all users transactions:
|
||||
$count = \DB::table('transactions')
|
||||
->where('account_id', $importAccount->id)->count();
|
||||
|
||||
\DB::table('transactions')
|
||||
->where('account_id', $importAccount->id)
|
||||
->update(['account_id' => $cashAccount->id]);
|
||||
|
||||
\Log::debug('Updated ' . $count . ' transactions from Import Account to cash.');
|
||||
$job->delete(); // no count fix
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*/
|
||||
protected function overruleUser(\User $user)
|
||||
{
|
||||
$this->_accounts->overruleUser($user);
|
||||
$this->_repository->overruleUser($user);
|
||||
$this->_piggybanks->overruleUser($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* This job queues new jobs that will connect components to their proper transactions and updates the
|
||||
* expense account: categories, budgets an beneficiaries used to be components.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function importComponentTransaction(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $this->_repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
/*
|
||||
* Took too long to fix this:
|
||||
*/
|
||||
if ($job->attempts() > 10) {
|
||||
\Log::error('Could not map transaction to component after 10 tries. KILL');
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Prep some vars from the payload
|
||||
*/
|
||||
$transactionId = intval($payload['data']['transaction_id']);
|
||||
$componentId = intval($payload['data']['component_id']);
|
||||
|
||||
/*
|
||||
* We don't know what kind of component we have. So we search for it. We have a specific function
|
||||
* for this:
|
||||
*/
|
||||
$oldComponentMap = $this->_repository->findImportComponentMap($importMap, $componentId);
|
||||
|
||||
/*
|
||||
* If the map is null, the component (whatever it is) is not imported yet, and we release the job.
|
||||
*/
|
||||
if (is_null($oldComponentMap)) {
|
||||
\Log::notice('No map for this component, release transaction/component import.');
|
||||
|
||||
/*
|
||||
* When in sync, its pointless to release jobs. Simply remove them.
|
||||
*/
|
||||
if (\Config::get('queue.default') == 'sync') {
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
} else {
|
||||
$job->release(300); // proper release.
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Switch on the class found in the map, and push a new job to update the transaction journal:
|
||||
*/
|
||||
switch ($oldComponentMap->class) {
|
||||
default:
|
||||
\Log::error('Cannot handle "' . $oldComponentMap->class . '" in component<>transaction routine!');
|
||||
$job->delete();
|
||||
break;
|
||||
case 'Budget':
|
||||
\Log::debug('Push job to connect budget to transaction #' . $transactionId);
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Storage\Budget\BudgetRepositoryInterface@importUpdateTransaction', $payload
|
||||
);
|
||||
$importMap->totaljobs++;
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
break;
|
||||
case 'Category':
|
||||
\Log::debug('Push job to connect category to transaction #' . $transactionId);
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Storage\Category\CategoryRepositoryInterface@importUpdateTransaction', $payload
|
||||
);
|
||||
|
||||
$importMap->totaljobs++;
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
break;
|
||||
case 'Account':
|
||||
\Log::debug('Push job to connect account to transaction #' . $transactionId);
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Storage\Account\AccountRepositoryInterface@importUpdateTransaction', $payload
|
||||
);
|
||||
|
||||
$importMap->totaljobs++;
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
break;
|
||||
}
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This job queues new jobs that will connect components to their proper transfers and updates the
|
||||
* expense account: categories, budgets an beneficiaries used to be components. Even though not all
|
||||
* of the transfers used to have these components, we check for them all.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function importComponentTransfer(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $this->_repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
/*
|
||||
* Took too long to fix this:
|
||||
*/
|
||||
if ($job->attempts() > 10) {
|
||||
\Log::error('Could not map transaction to component after 10 tries. KILL');
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Prep some vars from the payload
|
||||
*/
|
||||
$transferId = intval($payload['data']['transfer_id']);
|
||||
$componentId = intval($payload['data']['component_id']);
|
||||
|
||||
/*
|
||||
* We don't know what kind of component we have. So we search for it. We have a specific function
|
||||
* for this:
|
||||
*/
|
||||
$oldComponentMap = $this->_repository->findImportComponentMap($importMap, $componentId);
|
||||
|
||||
/*
|
||||
* If the map is null, the component (whatever it is) is not imported yet, and we release the job.
|
||||
*/
|
||||
if (is_null($oldComponentMap)) {
|
||||
\Log::notice('No map for this component, release transfer/component import.');
|
||||
/*
|
||||
* When in sync, its pointless to release jobs. Simply remove them.
|
||||
*/
|
||||
if (\Config::get('queue.default') == 'sync') {
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
} else {
|
||||
$job->release(300); // proper release.
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Switch on the class found in the map, and push a new job to update the transaction journal:
|
||||
*/
|
||||
switch ($oldComponentMap->class) {
|
||||
default:
|
||||
\Log::error('Cannot handle "' . $oldComponentMap->class . '" in component<>transfer routine!');
|
||||
$job->delete();
|
||||
break;
|
||||
case 'Category':
|
||||
\Log::debug('Push job to connect category to transfer #' . $transferId);
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Storage\Category\CategoryRepositoryInterface@importUpdateTransfer', $payload
|
||||
);
|
||||
|
||||
$importMap->totaljobs++;
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
break;
|
||||
case 'Budget':
|
||||
\Log::debug('Push job to connect budget to transfer #' . $transferId);
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Storage\Budget\BudgetRepositoryInterface@importUpdateTransfer', $payload
|
||||
);
|
||||
$importMap->totaljobs++;
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This job will see if the particular setting is a 'piggyAccount' setting,
|
||||
* one we need to fix all imported piggy banks.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*/
|
||||
public function importSetting(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $this->_repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
if ($job->attempts() > 10) {
|
||||
\Log::error('No account found for piggyAccount setting after 10 tries. KILL!');
|
||||
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
return;
|
||||
}
|
||||
$name = $payload['data']['name'];
|
||||
switch ($name) {
|
||||
default:
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed.
|
||||
return;
|
||||
break;
|
||||
case 'piggyAccount':
|
||||
|
||||
/*
|
||||
* If user has this account, update all piggy banks:
|
||||
*/
|
||||
$accountID = intval($payload['data']['value']);
|
||||
|
||||
/*
|
||||
* Is account imported already?
|
||||
*/
|
||||
$importEntry = $this->_repository->findImportEntry($importMap, 'Account', $accountID);
|
||||
|
||||
/*
|
||||
* We imported this account already.
|
||||
*/
|
||||
if ($importEntry) {
|
||||
$all = $this->_piggybanks->get();
|
||||
$account = $this->_accounts->find($importEntry->new);
|
||||
/*
|
||||
* Update all piggy banks.
|
||||
*/
|
||||
if (!is_null($account)) {
|
||||
\Log::debug('Updating all piggybanks, found the right setting.');
|
||||
foreach ($all as $piggy) {
|
||||
$piggy->account()->associate($account);
|
||||
unset($piggy->leftInAccount);
|
||||
$piggy->save();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
\Log::notice('Account not yet imported, hold or 5 minutes.');
|
||||
/*
|
||||
* When in sync, its pointless to release jobs. Simply remove them.
|
||||
*/
|
||||
if (\Config::get('queue.default') == 'sync') {
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
} else {
|
||||
$job->release(300); // proper release.
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// update map:
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed.
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This job will loop and queue jobs for the import file; almost every set of records will be imported.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param $payload
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*/
|
||||
public function start(Job $job, array $payload)
|
||||
{
|
||||
\Log::debug('Start with job "start"');
|
||||
$user = \User::find($payload['user']);
|
||||
$filename = $payload['file'];
|
||||
if (file_exists($filename) && !is_null($user)) {
|
||||
/*
|
||||
* Make an import map. Need it to refer back to import.
|
||||
*/
|
||||
$importMap = new \Importmap;
|
||||
$importMap->user()->associate($user);
|
||||
$importMap->file = $filename;
|
||||
$importMap->totaljobs = 0;
|
||||
$importMap->jobsdone = 0;
|
||||
$importMap->save();
|
||||
|
||||
$totalJobs = 0;
|
||||
|
||||
/*
|
||||
* Loop over all data in the JSON file, then create jobs.
|
||||
*/
|
||||
$raw = file_get_contents($filename);
|
||||
$JSON = json_decode($raw);
|
||||
|
||||
// first import all asset accounts:
|
||||
foreach ($JSON->accounts as $entry) {
|
||||
\Log::debug('Create job to import asset account');
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Storage\Account\AccountRepositoryInterface@importAccount', [
|
||||
'data' => $entry,
|
||||
'class' => 'Account',
|
||||
'account_type' => 'Asset account',
|
||||
'mapID' => $importMap->id
|
||||
]
|
||||
);
|
||||
$totalJobs++;
|
||||
}
|
||||
|
||||
// then import all beneficiaries:
|
||||
foreach ($JSON->components as $entry) {
|
||||
if ($entry->type->type == 'beneficiary') {
|
||||
\Log::debug('Create job to import expense account');
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Storage\Account\AccountRepositoryInterface@importAccount', [
|
||||
'data' => $entry,
|
||||
'class' => 'Account',
|
||||
'account_type' => 'Expense account',
|
||||
'mapID' => $importMap->id
|
||||
]
|
||||
);
|
||||
$totalJobs++;
|
||||
}
|
||||
}
|
||||
|
||||
// then import all categories.
|
||||
foreach ($JSON->components as $entry) {
|
||||
if ($entry->type->type == 'category') {
|
||||
\Log::debug('Create job to import category');
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Storage\Category\CategoryRepositoryInterface@importCategory', [
|
||||
'data' => $entry,
|
||||
'class' => 'Category',
|
||||
'mapID' => $importMap->id
|
||||
]
|
||||
);
|
||||
$totalJobs++;
|
||||
}
|
||||
}
|
||||
|
||||
// then import all budgets:
|
||||
foreach ($JSON->components as $entry) {
|
||||
if ($entry->type->type == 'budget') {
|
||||
\Log::debug('Create job to import budget');
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Storage\Budget\BudgetRepositoryInterface@importBudget', [
|
||||
'data' => $entry,
|
||||
'class' => 'Budget',
|
||||
'mapID' => $importMap->id
|
||||
]
|
||||
);
|
||||
$totalJobs++;
|
||||
}
|
||||
}
|
||||
|
||||
// then import all limits.
|
||||
foreach ($JSON->limits as $entry) {
|
||||
\Log::debug('Create job to import limit');
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Storage\Limit\LimitRepositoryInterface@importLimit', [
|
||||
'data' => $entry,
|
||||
'class' => 'Limit',
|
||||
'mapID' => $importMap->id
|
||||
]
|
||||
);
|
||||
$totalJobs++;
|
||||
}
|
||||
|
||||
// all piggy banks
|
||||
foreach ($JSON->piggybanks as $entry) {
|
||||
\Log::debug('Create job to import piggy bank');
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Storage\Piggybank\PiggybankRepositoryInterface@importPiggybank', [
|
||||
'data' => $entry,
|
||||
'class' => 'Piggybank',
|
||||
'mapID' => $importMap->id
|
||||
]
|
||||
);
|
||||
$totalJobs++;
|
||||
}
|
||||
|
||||
// all predictables.
|
||||
foreach ($JSON->predictables as $entry) {
|
||||
\Log::debug('Create job to import predictable');
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Storage\RecurringTransaction\RecurringTransactionRepositoryInterface@importPredictable', [
|
||||
'data' => $entry,
|
||||
'class' => 'Predictable',
|
||||
'mapID' => $importMap->id
|
||||
]
|
||||
);
|
||||
$totalJobs++;
|
||||
}
|
||||
|
||||
// all settings (to fix the piggy banks)
|
||||
foreach ($JSON->settings as $entry) {
|
||||
\Log::debug('Create job to import setting');
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Queue\Import@importSetting', [
|
||||
'data' => $entry,
|
||||
'class' => 'Setting',
|
||||
'mapID' => $importMap->id
|
||||
]
|
||||
);
|
||||
$totalJobs++;
|
||||
}
|
||||
|
||||
// all transactions
|
||||
foreach ($JSON->transactions as $entry) {
|
||||
|
||||
\Log::debug('Create job to import transaction');
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface@importTransaction', [
|
||||
'data' => $entry,
|
||||
'class' => 'Transaction',
|
||||
'mapID' => $importMap->id
|
||||
]
|
||||
);
|
||||
|
||||
$totalJobs++;
|
||||
}
|
||||
|
||||
// all transfers
|
||||
foreach ($JSON->transfers as $entry) {
|
||||
\Log::debug('Create job to import transfer');
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface@importTransfer', [
|
||||
'data' => $entry,
|
||||
'class' => 'Transfer',
|
||||
'mapID' => $importMap->id
|
||||
]
|
||||
);
|
||||
$totalJobs++;
|
||||
}
|
||||
|
||||
// then, fix all component <> transaction links
|
||||
foreach ($JSON->component_transaction as $entry) {
|
||||
\Log::debug('Create job to import components_transaction');
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Queue\Import@importComponentTransaction',
|
||||
[
|
||||
'data' => $entry,
|
||||
'mapID' => $importMap->id
|
||||
]
|
||||
);
|
||||
$totalJobs++;
|
||||
}
|
||||
|
||||
|
||||
// then, fix all component <> transfer links
|
||||
foreach ($JSON->component_transfer as $entry) {
|
||||
\Log::debug('Create job to import components_transfer');
|
||||
\Queue::push( // count fixed
|
||||
'Firefly\Queue\Import@importComponentTransfer',
|
||||
[
|
||||
'data' => $entry,
|
||||
'mapID' => $importMap->id
|
||||
]
|
||||
);
|
||||
$totalJobs++;
|
||||
}
|
||||
|
||||
$importMap->totaljobs = $totalJobs;
|
||||
$importMap->save();
|
||||
/*
|
||||
* We save the import map which now holds the number of jobs we've got planned.
|
||||
*/
|
||||
|
||||
\Queue::push('Firefly\Queue\Import@cleanImportAccount', ['mapID' => $importMap->id]);
|
||||
|
||||
$job->delete(); // count fixed
|
||||
|
||||
\Log::debug('Done with job "start"');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
namespace Firefly\Storage\Account;
|
||||
|
||||
use Illuminate\Queue\Jobs\Job;
|
||||
|
||||
/**
|
||||
* Interface AccountRepositoryInterface
|
||||
*
|
||||
@@ -11,25 +13,35 @@ namespace Firefly\Storage\Account;
|
||||
interface AccountRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importAccount(Job $job, array $payload);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function count();
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param \AccountType $type
|
||||
* Gets a list of accounts that have the mentioned type. Will automatically convert
|
||||
* strings in this array to actual (model) account types.
|
||||
*
|
||||
* @return mixed
|
||||
* @param array $types
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function createOrFind($name, \AccountType $type);
|
||||
public function getOfTypes(array $types);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param array $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function createOrFindBeneficiary($name);
|
||||
public function firstOrCreate(array $data);
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
@@ -46,32 +58,50 @@ interface AccountRepositoryInterface
|
||||
public function find($accountId);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByName($name);
|
||||
public function findAccountType($type);
|
||||
|
||||
/**
|
||||
* Takes a transaction/account component and updates the transaction journal to match.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get();
|
||||
public function importUpdateTransaction(Job $job, array $payload);
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
*
|
||||
* @return |Account|null
|
||||
*/
|
||||
public function findAssetAccountById($id);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $create
|
||||
*
|
||||
* @return |Account|null
|
||||
*/
|
||||
public function findExpenseAccountByName($name, $create = true);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $create
|
||||
*
|
||||
* @return |Account|null
|
||||
*/
|
||||
public function findRevenueAccountByName($name, $create = true);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getActiveDefault();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getActiveDefaultAsSelectList();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBeneficiaries();
|
||||
|
||||
/**
|
||||
* @param $ids
|
||||
*
|
||||
@@ -82,12 +112,21 @@ interface AccountRepositoryInterface
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCashAccount();
|
||||
public function getDefault();
|
||||
|
||||
/**
|
||||
* @param \AccountType $type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDefault();
|
||||
public function getByAccountType(\AccountType $type);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
namespace Firefly\Storage\Account;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Queue\Jobs\Job;
|
||||
|
||||
/**
|
||||
* Class EloquentAccountRepository
|
||||
@@ -12,11 +14,15 @@ use Carbon\Carbon;
|
||||
*/
|
||||
class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
|
||||
protected $_user = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_user = \Auth::user();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,45 +30,10 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return \Auth::user()->accounts()->count();
|
||||
return $this->_user->accounts()->count();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param \AccountType $type
|
||||
*
|
||||
* @return \Account|mixed
|
||||
*/
|
||||
public function createOrFind($name, \AccountType $type = null)
|
||||
{
|
||||
$account = $this->findByName($name, $type);
|
||||
if (!$account) {
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'account_type' => $type
|
||||
];
|
||||
|
||||
return $this->store($data);
|
||||
}
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return \Account|mixed|null
|
||||
*/
|
||||
public function createOrFindBeneficiary($name)
|
||||
{
|
||||
if (is_null($name) || strlen($name) == 0) {
|
||||
return null;
|
||||
}
|
||||
$type = \AccountType::where('type', 'Beneficiary account')->first();
|
||||
return $this->createOrFind($name, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
*
|
||||
@@ -71,7 +42,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
public function destroy(\Account $account)
|
||||
{
|
||||
// find all transaction journals related to this account:
|
||||
$journals = \TransactionJournal::withRelevantData()->account($account)->get(['transaction_journals.*']);
|
||||
$journals = \TransactionJournal::withRelevantData()->accountIs($account)->get(['transaction_journals.*']);
|
||||
$accountIDs = [];
|
||||
|
||||
/** @var \TransactionJournal $journal */
|
||||
@@ -86,7 +57,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
$accountIDs = array_unique($accountIDs);
|
||||
if (count($accountIDs) > 0) {
|
||||
// find the "initial balance" type accounts in this list. Should be just 1.
|
||||
$query = \Auth::user()->accounts()->accountTypeIn(['Initial balance account'])
|
||||
$query = $this->_user->accounts()->accountTypeIn(['Initial balance account'])
|
||||
->whereIn('accounts.id', $accountIDs);
|
||||
if ($query->count() == 1) {
|
||||
$iba = $query->first(['accounts.*']);
|
||||
@@ -105,81 +76,169 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $accountId
|
||||
* @param $id
|
||||
*
|
||||
* @return mixed
|
||||
* @return |Account|null
|
||||
*/
|
||||
public function find($accountId)
|
||||
public function findAssetAccountById($id)
|
||||
{
|
||||
return \Auth::user()->accounts()->where('id', $accountId)->first();
|
||||
return $this->_user->accounts()->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method finds the expense account mentioned by name. This method is a sneaky little hobbits,
|
||||
* because when you feed it "Import account" it will always return an import account of that type.
|
||||
*
|
||||
* @param $name
|
||||
* @param $create
|
||||
*
|
||||
* @return null|\Account
|
||||
*/
|
||||
public function findExpenseAccountByName($name, $create = true)
|
||||
{
|
||||
$cashType = $this->findAccountType('Cash account');
|
||||
$importType = $this->findAccountType('Import account');
|
||||
// catch Import account:
|
||||
if ($name == 'Import account') {
|
||||
|
||||
$import = $this->firstOrCreate(
|
||||
[
|
||||
'name' => 'Import account',
|
||||
'user_id' => $this->_user->id,
|
||||
'account_type_id' => $importType->id,
|
||||
'active' => 1
|
||||
]
|
||||
);
|
||||
return $import;
|
||||
}
|
||||
|
||||
// find account:
|
||||
|
||||
$account = $this->_user->accounts()->where('name', $name)->accountTypeIn(
|
||||
['Expense account', 'Beneficiary account']
|
||||
)->first(['accounts.*']);
|
||||
|
||||
// create if not found:
|
||||
if (strlen($name) > 0 && is_null($account) && $create === true) {
|
||||
$type = $this->findAccountType('Expense account');
|
||||
$set = [
|
||||
'name' => $name,
|
||||
'user_id' => $this->_user->id,
|
||||
'active' => 1,
|
||||
'account_type_id' => $type->id
|
||||
];
|
||||
$account = $this->firstOrCreate($set);
|
||||
} else if (strlen($name) > 0 && is_null($account) && $create === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// find cash account as fall back:
|
||||
if (is_null($account)) {
|
||||
|
||||
$account = $this->_user->accounts()->where('account_type_id', $cashType->id)->first();
|
||||
}
|
||||
|
||||
// create cash account as ultimate fall back:
|
||||
if (is_null($account)) {
|
||||
$set = [
|
||||
'name' => 'Cash account',
|
||||
'user_id' => $this->_user->id,
|
||||
'active' => 1,
|
||||
'account_type_id' => $cashType->id
|
||||
];
|
||||
$account = $this->firstOrCreate($set);
|
||||
}
|
||||
|
||||
if ($account->active == 0 && $account->account_type_id != $cashType->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
*
|
||||
* @return \AccountType|null
|
||||
*/
|
||||
public function findAccountType($type)
|
||||
{
|
||||
return \AccountType::where('type', $type)->first();
|
||||
}
|
||||
|
||||
public function firstOrCreate(array $data)
|
||||
{
|
||||
return \Account::firstOrCreate($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param \AccountType $type
|
||||
* @param $create
|
||||
*
|
||||
* @return mixed
|
||||
* @return |Account|null
|
||||
*/
|
||||
public function findByName($name, \AccountType $type = null)
|
||||
public function findRevenueAccountByName($name, $create = true)
|
||||
{
|
||||
$type = is_null($type) ? \AccountType::where('type', 'Default account')->first() : $type;
|
||||
|
||||
return \Auth::user()->accounts()->where('account_type_id', $type->id)
|
||||
->where('name', 'like', '%' . $name . '%')
|
||||
->first();
|
||||
// catch Import account:
|
||||
if ($name == 'Import account') {
|
||||
$importType = $this->findAccountType('Import account');
|
||||
$import = $this->firstOrCreate(
|
||||
[
|
||||
'name' => 'Import account',
|
||||
'user_id' => $this->_user->id,
|
||||
'account_type_id' => $importType->id,
|
||||
'active' => 1
|
||||
]
|
||||
);
|
||||
return $import;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \Auth::user()->accounts()->with('accounttype')->orderBy('name', 'ASC')->get();
|
||||
// find account:
|
||||
$type = $this->findAccountType('Revenue account');
|
||||
$account = $this->_user->accounts()->where('name', $name)->where('account_type_id', $type->id)->first();
|
||||
|
||||
// create if not found:
|
||||
if (strlen($name) > 0 && is_null($account) && $create === true) {
|
||||
$set = [
|
||||
'name' => $name,
|
||||
'user_id' => $this->_user->id,
|
||||
'active' => 1,
|
||||
'account_type_id' => $type->id
|
||||
];
|
||||
$account = $this->firstOrCreate($set);
|
||||
} else if (strlen($name) > 0 && is_null($account) && $create === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getActiveDefault()
|
||||
{
|
||||
return \Auth::user()->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->where('account_types.type', 'Default account')->where('accounts.active', 1)
|
||||
|
||||
->get(['accounts.*']);
|
||||
// find cash account as fall back:
|
||||
if (is_null($account)) {
|
||||
$cashType = $this->findAccountType('Cash account');
|
||||
$account = $this->_user->accounts()->where('account_type_id', $cashType->id)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getActiveDefaultAsSelectList()
|
||||
{
|
||||
$list = \Auth::user()->accounts()->leftJoin(
|
||||
'account_types', 'account_types.id', '=', 'accounts.account_type_id'
|
||||
)
|
||||
->where('account_types.type', 'Default account')->where('accounts.active', 1)
|
||||
|
||||
->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
||||
$return = [];
|
||||
foreach ($list as $entry) {
|
||||
$return[intval($entry->id)] = $entry->name;
|
||||
// create cash account as ultimate fall back:
|
||||
if (is_null($account)) {
|
||||
$set = [
|
||||
'name' => 'Cash account',
|
||||
'user_id' => $this->_user->id,
|
||||
'active' => 1,
|
||||
'account_type_id' => $cashType->id
|
||||
];
|
||||
$account = $this->firstOrCreate($set);
|
||||
}
|
||||
|
||||
return $return;
|
||||
if ($account->active == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBeneficiaries()
|
||||
return $account;
|
||||
}
|
||||
|
||||
public function getByAccountType(\AccountType $type)
|
||||
{
|
||||
$list = \Auth::user()->accounts()->leftJoin(
|
||||
'account_types', 'account_types.id', '=', 'accounts.account_type_id'
|
||||
)
|
||||
->where('account_types.type', 'Beneficiary account')->where('accounts.active', 1)
|
||||
|
||||
->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
||||
|
||||
return $list;
|
||||
return $this->_user->accounts()->with('accounttype')->orderBy('name', 'ASC')
|
||||
->where('account_type_id', $type->id)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,22 +249,71 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
public function getByIds(array $ids)
|
||||
{
|
||||
if (count($ids) > 0) {
|
||||
return \Auth::user()->accounts()->with('accounttype')->whereIn('id', $ids)->orderBy('name', 'ASC')->get();
|
||||
return $this->_user->accounts()->with('accounttype')->whereIn('id', $ids)->orderBy('name', 'ASC')->get();
|
||||
} else {
|
||||
return $this->getActiveDefault();
|
||||
}
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * @param $name
|
||||
// *
|
||||
// * @return \Account|mixed|null
|
||||
// */
|
||||
// public function createOrFindBeneficiary($name)
|
||||
// {
|
||||
// if (is_null($name) || strlen($name) == 0) {
|
||||
// return null;
|
||||
// }
|
||||
// $type = \AccountType::where('type', 'Expense account')->first();
|
||||
// return $this->createOrFind($name, $type);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param $name
|
||||
// * @param \AccountType $type
|
||||
// *
|
||||
// * @return \Account|mixed
|
||||
// */
|
||||
// public function createOrFind($name, \AccountType $type = null)
|
||||
// {
|
||||
// $account = $this->findByName($name, $type);
|
||||
// if (!$account) {
|
||||
// $data = [
|
||||
// 'name' => $name,
|
||||
// 'account_type' => $type
|
||||
// ];
|
||||
//
|
||||
// return $this->store($data);
|
||||
// }
|
||||
//
|
||||
// return $account;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param $name
|
||||
// * @param \AccountType $type
|
||||
// *
|
||||
// * @return mixed
|
||||
// */
|
||||
// public function findByName($name, \AccountType $type = null)
|
||||
// {
|
||||
// $type = is_null($type) ? \AccountType::where('type', 'Asset account')->first() : $type;
|
||||
//
|
||||
// return $this->_user->accounts()->where('account_type_id', $type->id)
|
||||
// ->where('name', 'like', '%' . $name . '%')
|
||||
// ->first();
|
||||
// }
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCashAccount()
|
||||
public function getActiveDefault()
|
||||
{
|
||||
$type = \AccountType::where('type', 'Cash account')->first();
|
||||
$cash = \Auth::user()->accounts()->where('account_type_id', $type->id)->first();
|
||||
|
||||
return $cash;
|
||||
|
||||
return $this->_user->accounts()->accountTypeIn(['Default account', 'Asset account'])->where(
|
||||
'accounts.active', 1
|
||||
)
|
||||
->get(['accounts.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -213,12 +321,120 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
return \Auth::user()->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->where('account_types.type', 'Default account')
|
||||
|
||||
return $this->_user->accounts()->accountTypeIn(['Default account', 'Asset account'])
|
||||
->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of accounts that have the mentioned type. Will automatically convert
|
||||
* strings in this array to actual (model) account types.
|
||||
*
|
||||
* @param array $types
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getOfTypes(array $types)
|
||||
{
|
||||
$accounts = $this->_user->accounts()->accountTypeIn($types)->get(['accounts.*']);
|
||||
return $accounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importAccount(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
/*
|
||||
* maybe Account is already imported:
|
||||
*/
|
||||
$importEntry = $repository->findImportEntry($importMap, 'Account', intval($payload['data']['id']));
|
||||
|
||||
/*
|
||||
* if so, delete job and return:
|
||||
*/
|
||||
if (!is_null($importEntry)) {
|
||||
\Log::debug('Already imported ' . $payload['data']['name'] . ' of type ' . $payload['account_type']);
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* find the payload's account type:
|
||||
*/
|
||||
$payload['account_type'] = isset($payload['account_type']) ? $payload['account_type'] : 'Expense account';
|
||||
$type = $this->findAccountType($payload['account_type']);
|
||||
|
||||
/*
|
||||
* Create data array for store() procedure.
|
||||
*/
|
||||
$data = [
|
||||
'account_type' => $type,
|
||||
'name' => $payload['data']['name'],
|
||||
];
|
||||
if (isset($payload['data']['openingbalance'])) {
|
||||
$data['openingbalance'] = floatval($payload['data']['openingbalance']);
|
||||
$data['openingbalancedate'] = $payload['data']['openingbalancedate'];
|
||||
}
|
||||
if (isset($payload['data']['inactive'])) {
|
||||
$data['active'] = intval($payload['data']['inactive']) == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to store:
|
||||
*/
|
||||
$account = $this->store($data);
|
||||
|
||||
/*
|
||||
* Check for failure.
|
||||
*/
|
||||
if (count($account->errors()) > 0) {
|
||||
\Log::error('Account creation error: ' . $account->errors()->first());
|
||||
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
return;
|
||||
}
|
||||
\Log::debug('Imported ' . $payload['account_type'] . ': ' . $payload['data']['name']);
|
||||
|
||||
/*
|
||||
* Save meta data
|
||||
*/
|
||||
$repository->store($importMap, 'Account', intval($payload['data']['id']), $account->id);
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed.
|
||||
return;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Used for import
|
||||
// *
|
||||
// * @param $name
|
||||
// *
|
||||
// * @return mixed
|
||||
// */
|
||||
// public function findByNameAny($name)
|
||||
// {
|
||||
// return $this->_user->accounts()
|
||||
// ->where('name', 'like', '%' . $name . '%')
|
||||
// ->first();
|
||||
// }
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
@@ -234,16 +450,24 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
&& get_class($data['account_type']) == 'AccountType'
|
||||
) {
|
||||
$accountType = $data['account_type'];
|
||||
} else if (isset($data['account_type']) && is_string($data['account_type'])) {
|
||||
// if it isnt but set as string, find it:
|
||||
$accountType = \AccountType::where('type', $data['account_type'])->first();
|
||||
|
||||
} else {
|
||||
$accountType = \AccountType::where('type', 'Default account')->first();
|
||||
$accountType = \AccountType::where('type', 'Asset account')->first();
|
||||
}
|
||||
$active = isset($data['active']) && intval($data['active']) >= 0 && intval($data['active']) <= 1 ? intval(
|
||||
$data['active']
|
||||
) : 1;
|
||||
|
||||
/**
|
||||
* Create new account:
|
||||
*/
|
||||
$account = new \Account;
|
||||
$account->accountType()->associate($accountType);
|
||||
$account->user()->associate(\Auth::user());
|
||||
$account->user()->associate($this->_user);
|
||||
|
||||
$account->name = $data['name'];
|
||||
$account->active
|
||||
= isset($data['active']) && intval($data['active']) >= 0 && intval($data['active']) <= 1 ? intval(
|
||||
@@ -251,20 +475,226 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
) : 1;
|
||||
|
||||
// try to save it:
|
||||
try {
|
||||
if ($account->save()) {
|
||||
// create initial balance, if necessary:
|
||||
if (isset($data['openingbalance']) && isset($data['openingbalancedate'])) {
|
||||
$amount = floatval($data['openingbalance']);
|
||||
$date = new Carbon($data['openingbalancedate']);
|
||||
if ($amount != 0) {
|
||||
$this->_createInitialBalance($account, $amount, $date);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (QueryException $e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
// whatever the result, return the account.
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param int $amount
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
|
||||
*/
|
||||
protected function _createInitialBalance(\Account $account, $amount = 0, Carbon $date)
|
||||
{
|
||||
/*
|
||||
* The repositories we need:
|
||||
*/
|
||||
/** @var \Firefly\Helper\Controllers\TransactionInterface $transactions */
|
||||
$transactions = \App::make('Firefly\Helper\Controllers\TransactionInterface');
|
||||
$transactions->overruleUser($this->_user);
|
||||
|
||||
|
||||
/*
|
||||
* get account type:
|
||||
*/
|
||||
$initialBalanceAT = $this->findAccountType('Initial balance account');
|
||||
|
||||
/*
|
||||
* create new account
|
||||
*/
|
||||
$initial = new \Account;
|
||||
$initial->accountType()->associate($initialBalanceAT);
|
||||
$initial->user()->associate($this->_user);
|
||||
$initial->name = $account->name . ' initial balance';
|
||||
$initial->active = 0;
|
||||
if ($initial->validate()) {
|
||||
$initial->save();
|
||||
/*
|
||||
* create new transaction journal (and transactions):
|
||||
*/
|
||||
|
||||
$set = [
|
||||
'account_from_id' => $initial->id,
|
||||
'account_to_id' => $account->id,
|
||||
'description' => 'Initial Balance for ' . $account->name,
|
||||
'what' => 'Opening balance',
|
||||
'amount' => $amount,
|
||||
'category' => '',
|
||||
'date' => $date->format('Y-m-d')
|
||||
];
|
||||
$transactions->store($set);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a transaction/account component and updates the transaction journal to match.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importUpdateTransaction(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
if ($job->attempts() > 10) {
|
||||
\Log::error('Never found budget/account combination "' . $payload['data']['transaction_id'] . '"');
|
||||
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed.
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $journals */
|
||||
$journals = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$journals->overruleUser($user);
|
||||
|
||||
/*
|
||||
* Prep some vars from the payload
|
||||
*/
|
||||
$transactionId = intval($payload['data']['transaction_id']);
|
||||
$componentId = intval($payload['data']['component_id']);
|
||||
|
||||
/*
|
||||
* Find the import map for both:
|
||||
*/
|
||||
$accountMap = $repository->findImportEntry($importMap, 'Account', $componentId);
|
||||
$transactionMap = $repository->findImportEntry($importMap, 'Transaction', $transactionId);
|
||||
|
||||
/*
|
||||
* Either may be null:
|
||||
*/
|
||||
if (is_null($accountMap) || is_null($transactionMap)) {
|
||||
\Log::notice('No map found in account/transaction mapper. Release.');
|
||||
if (\Config::get('queue.default') == 'sync') {
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
} else {
|
||||
$job->release(300); // proper release.
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the account and the transaction:
|
||||
*/
|
||||
$account = $this->find($accountMap->new);
|
||||
/** @var \TransactionJournal $journal */
|
||||
$journal = $journals->find($transactionMap->new);
|
||||
|
||||
/*
|
||||
* If either is null, release:
|
||||
*/
|
||||
if (is_null($account) || is_null($journal)) {
|
||||
\Log::notice('Map is incorrect in account/transaction mapper. Release.');
|
||||
if (\Config::get('queue.default') == 'sync') {
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
} else {
|
||||
$job->release(300); // proper release.
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update one of the journal's transactions to have the right account:
|
||||
*/
|
||||
$importType = $this->findAccountType('Import account');
|
||||
/** @var \Transaction $transaction */
|
||||
$updated = false;
|
||||
\Log::debug(
|
||||
'Connect "' . $account->name . '" (#' . $account->id . ') to "' . $journal->description . '" (#'
|
||||
. $journal->id . ')'
|
||||
);
|
||||
foreach ($journal->transactions as $index => $transaction) {
|
||||
/*
|
||||
* If it's of the right type, update it!
|
||||
*/
|
||||
\Log::debug(
|
||||
'Transaction ' . $index . ' (#' . $transaction->id . '): [' . $transaction->account->account_type_id
|
||||
. ' vs. ' . $importType->id . ']'
|
||||
);
|
||||
if ($transaction->account->account_type_id == $importType->id) {
|
||||
$transaction->account()->associate($account);
|
||||
$transaction->save();
|
||||
$updated = true;
|
||||
\Log::debug(
|
||||
'Connected expense account "' . $account->name . '" to journal "' . $journal->description . '"'
|
||||
);
|
||||
}
|
||||
}
|
||||
if ($updated === false) {
|
||||
\Log::error(
|
||||
'Did not connect transactions of journal #' . $journal->id . ' to expense account ' . $account->id
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$journal->save();
|
||||
|
||||
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $accountId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($accountId)
|
||||
{
|
||||
return $this->_user->accounts()->where('id', $accountId)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param $data
|
||||
@@ -279,12 +709,12 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
$account->save();
|
||||
}
|
||||
// update initial balance if necessary:
|
||||
if (floatval($data['openingbalance']) != 0) {
|
||||
if (isset($data['openingbalance']) && floatval($data['openingbalance']) != 0) {
|
||||
|
||||
/** @var \Firefly\Helper\Controllers\AccountInterface $interface */
|
||||
$interface = \App::make('Firefly\Helper\Controllers\AccountInterface');
|
||||
|
||||
if ($account->accounttype->type == 'Default account') {
|
||||
if ($account->accounttype->type == 'Default account' || $account->accounttype->type == 'Asset account') {
|
||||
|
||||
|
||||
$journal = $interface->openingBalanceTransaction($account);
|
||||
@@ -302,41 +732,5 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param int $amount
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
|
||||
*/
|
||||
protected function _createInitialBalance(\Account $account, $amount = 0, Carbon $date)
|
||||
{
|
||||
// get account type:
|
||||
$initialBalanceAT = \AccountType::where('type', 'Initial balance account')->first();
|
||||
|
||||
// create new account:
|
||||
$initial = new \Account;
|
||||
$initial->accountType()->associate($initialBalanceAT);
|
||||
$initial->user()->associate(\Auth::user());
|
||||
$initial->name = $account->name . ' initial balance';
|
||||
$initial->active = 0;
|
||||
if ($initial->validate()) {
|
||||
$initial->save();
|
||||
// create new transaction journal (and transactions):
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $transactionJournal */
|
||||
$transactionJournal = \App::make(
|
||||
'Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'
|
||||
);
|
||||
|
||||
$transactionJournal->createSimpleJournal(
|
||||
$initial, $account, 'Initial Balance for ' . $account->name, $amount, $date
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Storage\Budget;
|
||||
use Illuminate\Queue\Jobs\Job;
|
||||
|
||||
/**
|
||||
* Interface BudgetRepositoryInterface
|
||||
@@ -9,6 +10,34 @@ namespace Firefly\Storage\Budget;
|
||||
*/
|
||||
interface BudgetRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importBudget(Job $job, array $payload);
|
||||
|
||||
/**
|
||||
* Takes a transaction/budget component and updates the transaction journal to match.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importUpdateTransaction(Job $job, array $payload);
|
||||
|
||||
/**
|
||||
* Takes a transfer/budget component and updates the transaction journal to match.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importUpdateTransfer(Job $job, array $payload);
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
*
|
||||
@@ -23,15 +52,23 @@ interface BudgetRepositoryInterface
|
||||
*/
|
||||
public function find($budgetId);
|
||||
|
||||
|
||||
/**
|
||||
* @param $budgetName
|
||||
* @return mixed
|
||||
*/
|
||||
public function get();
|
||||
public function findByName($budgetName);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAsSelectList();
|
||||
public function get();
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
|
||||
@@ -3,19 +3,361 @@
|
||||
namespace Firefly\Storage\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Queue\Jobs\Job;
|
||||
|
||||
/**
|
||||
* Class EloquentBudgetRepository
|
||||
*
|
||||
* @package Firefly\Storage\Budget
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
||||
*
|
||||
*/
|
||||
class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
{
|
||||
|
||||
protected $_user = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_user = \Auth::user();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importBudget(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
/*
|
||||
* maybe Budget is already imported:
|
||||
*/
|
||||
$importEntry = $repository->findImportEntry($importMap, 'Budget', intval($payload['data']['id']));
|
||||
|
||||
/*
|
||||
* if so, delete job and return:
|
||||
*/
|
||||
if (!is_null($importEntry)) {
|
||||
\Log::debug('Already imported budget ' . $payload['data']['name']);
|
||||
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* maybe Budget is already imported.
|
||||
*/
|
||||
$budget = $this->findByName($payload['data']['name']);
|
||||
|
||||
if (is_null($budget)) {
|
||||
/*
|
||||
* Not imported yet.
|
||||
*/
|
||||
$budget = $this->store($payload['data']);
|
||||
$repository->store($importMap, 'Budget', $payload['data']['id'], $budget->id);
|
||||
\Log::debug('Imported budget "' . $payload['data']['name'] . '".');
|
||||
} else {
|
||||
/*
|
||||
* already imported.
|
||||
*/
|
||||
$repository->store($importMap, 'Budget', $payload['data']['id'], $budget->id);
|
||||
\Log::debug('Already had budget "' . $payload['data']['name'] . '".');
|
||||
}
|
||||
|
||||
// update map:
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
// delete job.
|
||||
$job->delete(); // count fixed
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $budgetName
|
||||
*
|
||||
* @return \Budget|null
|
||||
*/
|
||||
public function findByName($budgetName)
|
||||
{
|
||||
|
||||
return $this->_user->budgets()->whereName($budgetName)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return \Budget
|
||||
*/
|
||||
public function store($data)
|
||||
{
|
||||
$budget = new \Budget;
|
||||
$budget->name = $data['name'];
|
||||
$budget->user()->associate($this->_user);
|
||||
$budget->save();
|
||||
|
||||
// if limit, create limit (repetition itself will be picked up elsewhere).
|
||||
if (isset($data['amount']) && floatval($data['amount']) > 0) {
|
||||
$startDate = new Carbon;
|
||||
$limitData = [
|
||||
'budget_id' => $budget->id,
|
||||
'startdate' => $startDate->format('Y-m-d'),
|
||||
'period' => $data['repeat_freq'],
|
||||
'amount' => floatval($data['amount']),
|
||||
'repeats' => 0
|
||||
];
|
||||
/** @var \Firefly\Storage\Limit\LimitRepositoryInterface $limitRepository */
|
||||
$limitRepository = \App::make('Firefly\Storage\Limit\LimitRepositoryInterface');
|
||||
$limitRepository->overruleUser($this->_user);
|
||||
$limit = $limitRepository->store($limitData);
|
||||
\Event::fire('limits.store', [$limit]);
|
||||
}
|
||||
|
||||
if ($budget->validate()) {
|
||||
$budget->save();
|
||||
}
|
||||
|
||||
return $budget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a transfer/budget component and updates the transaction journal to match.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importUpdateTransfer(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
if ($job->attempts() > 10) {
|
||||
\Log::error('Never found budget/transfer combination "' . $payload['data']['transfer_id'] . '"');
|
||||
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $journals */
|
||||
$journals = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$journals->overruleUser($user);
|
||||
|
||||
/*
|
||||
* Prep some vars from the payload
|
||||
*/
|
||||
$transferId = intval($payload['data']['transfer_id']);
|
||||
$componentId = intval($payload['data']['component_id']);
|
||||
|
||||
/*
|
||||
* Find the import map for both:
|
||||
*/
|
||||
$budgetMap = $repository->findImportEntry($importMap, 'Budget', $componentId);
|
||||
$transferMap = $repository->findImportEntry($importMap, 'Transfer', $transferId);
|
||||
|
||||
/*
|
||||
* Either may be null:
|
||||
*/
|
||||
if (is_null($budgetMap) || is_null($transferMap)) {
|
||||
\Log::notice('No map found in budget/transfer mapper. Release.');
|
||||
if(\Config::get('queue.default') == 'sync') {
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
} else {
|
||||
$job->release(300); // proper release.
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the budget and the transaction:
|
||||
*/
|
||||
$budget = $this->find($budgetMap->new);
|
||||
/** @var \TransactionJournal $journal */
|
||||
$journal = $journals->find($transferMap->new);
|
||||
|
||||
/*
|
||||
* If either is null, release:
|
||||
*/
|
||||
if (is_null($budget) || is_null($journal)) {
|
||||
\Log::notice('Map is incorrect in budget/transfer mapper. Release.');
|
||||
if(\Config::get('queue.default') == 'sync') {
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
} else {
|
||||
$job->release(300); // proper release.
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update journal to have budget:
|
||||
*/
|
||||
$journal->budgets()->save($budget);
|
||||
$journal->save();
|
||||
\Log::debug('Connected budget "' . $budget->name . '" to journal "' . $journal->description . '"');
|
||||
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a transaction/budget component and updates the transaction journal to match.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importUpdateTransaction(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
if ($job->attempts() > 10) {
|
||||
\Log::error('Never found budget/transaction combination "' . $payload['data']['transaction_id'] . '"');
|
||||
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $journals */
|
||||
$journals = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$journals->overruleUser($user);
|
||||
|
||||
/*
|
||||
* Prep some vars from the payload
|
||||
*/
|
||||
$transactionId = intval($payload['data']['transaction_id']);
|
||||
$componentId = intval($payload['data']['component_id']);
|
||||
|
||||
/*
|
||||
* Find the import map for both:
|
||||
*/
|
||||
$budgetMap = $repository->findImportEntry($importMap, 'Budget', $componentId);
|
||||
$transactionMap = $repository->findImportEntry($importMap, 'Transaction', $transactionId);
|
||||
|
||||
/*
|
||||
* Either may be null:
|
||||
*/
|
||||
if (is_null($budgetMap) || is_null($transactionMap)) {
|
||||
\Log::notice('No map found in budget/transaction mapper. Release.');
|
||||
if(\Config::get('queue.default') == 'sync') {
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
} else {
|
||||
$job->release(300); // proper release.
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the budget and the transaction:
|
||||
*/
|
||||
$budget = $this->find($budgetMap->new);
|
||||
/** @var \TransactionJournal $journal */
|
||||
$journal = $journals->find($transactionMap->new);
|
||||
|
||||
/*
|
||||
* If either is null, release:
|
||||
*/
|
||||
if (is_null($budget) || is_null($journal)) {
|
||||
\Log::notice('Map is incorrect in budget/transaction mapper. Release.');
|
||||
if(\Config::get('queue.default') == 'sync') {
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
} else {
|
||||
$job->release(300); // proper release.
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update journal to have budget:
|
||||
*/
|
||||
$journal->budgets()->save($budget);
|
||||
$journal->save();
|
||||
\Log::debug('Connected budget "' . $budget->name . '" to journal "' . $journal->description . '"');
|
||||
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $budgetId
|
||||
*
|
||||
* @return \Budget|null
|
||||
*/
|
||||
public function find($budgetId)
|
||||
{
|
||||
|
||||
return $this->_user->budgets()->find($budgetId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
*
|
||||
* @return bool|mixed
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(\Budget $budget)
|
||||
{
|
||||
@@ -25,112 +367,20 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $budgetId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($budgetId)
|
||||
{
|
||||
|
||||
return \Auth::user()->budgets()->find($budgetId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @return Collection
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$set = \Auth::user()->budgets()->with(
|
||||
$set = $this->_user->budgets()->with(
|
||||
['limits' => function ($q) {
|
||||
$q->orderBy('limits.startdate', 'DESC');
|
||||
}, 'limits.limitrepetitions' => function ($q) {
|
||||
$q->orderBy('limit_repetitions.startdate', 'ASC');
|
||||
}]
|
||||
)->orderBy('name', 'ASC')->get();
|
||||
foreach ($set as $budget) {
|
||||
foreach ($budget->limits as $limit) {
|
||||
foreach ($limit->limitrepetitions as $rep) {
|
||||
$rep->left = $rep->left();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getAsSelectList()
|
||||
{
|
||||
$list = \Auth::user()->budgets()->with(
|
||||
['limits', 'limits.limitrepetitions']
|
||||
)->orderBy('name', 'ASC')->get();
|
||||
$return = [];
|
||||
foreach ($list as $entry) {
|
||||
$return[intval($entry->id)] = $entry->name;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return \Budget|mixed
|
||||
*/
|
||||
public function store($data)
|
||||
{
|
||||
$budget = new \Budget;
|
||||
$budget->name = $data['name'];
|
||||
$budget->user()->associate(\Auth::user());
|
||||
$budget->save();
|
||||
|
||||
// if limit, create limit (repetition itself will be picked up elsewhere).
|
||||
if (floatval($data['amount']) > 0) {
|
||||
$limit = new \Limit;
|
||||
$limit->budget()->associate($budget);
|
||||
$startDate = new Carbon;
|
||||
switch ($data['repeat_freq']) {
|
||||
case 'daily':
|
||||
$startDate->startOfDay();
|
||||
break;
|
||||
case 'weekly':
|
||||
$startDate->startOfWeek();
|
||||
break;
|
||||
case 'monthly':
|
||||
$startDate->startOfMonth();
|
||||
break;
|
||||
case 'quarterly':
|
||||
$startDate->firstOfQuarter();
|
||||
break;
|
||||
case 'half-year':
|
||||
$startDate->startOfYear();
|
||||
if (intval($startDate->format('m')) >= 7) {
|
||||
$startDate->addMonths(6);
|
||||
}
|
||||
break;
|
||||
case 'yearly':
|
||||
$startDate->startOfYear();
|
||||
break;
|
||||
}
|
||||
$limit->startdate = $startDate;
|
||||
$limit->amount = $data['amount'];
|
||||
$limit->repeats = isset($data['repeats']) ? $data['repeats'] : 0;
|
||||
$limit->repeat_freq = $data['repeat_freq'];
|
||||
if ($limit->validate()) {
|
||||
$limit->save();
|
||||
\Event::fire('limits.store', [$limit]);
|
||||
}
|
||||
}
|
||||
if ($budget->validate()) {
|
||||
$budget->save();
|
||||
}
|
||||
|
||||
return $budget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
* @param $data
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Storage\Category;
|
||||
use Illuminate\Queue\Jobs\Job;
|
||||
|
||||
/**
|
||||
* Interface CategoryRepositoryInterface
|
||||
@@ -9,6 +10,33 @@ namespace Firefly\Storage\Category;
|
||||
*/
|
||||
interface CategoryRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Takes a transaction/category component and updates the transaction journal to match.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importUpdateTransaction(Job $job, array $payload);
|
||||
|
||||
/**
|
||||
* Takes a transfer/category component and updates the transaction journal to match.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importUpdateTransfer(Job $job, array $payload);
|
||||
|
||||
/**
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importCategory(Job $job, array $payload);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
@@ -27,7 +55,13 @@ interface CategoryRepositoryInterface
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function createOrFind($name);
|
||||
public function firstOrCreate($name);
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function overruleUser(\User $user);
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Firefly\Storage\Category;
|
||||
|
||||
use Illuminate\Queue\Jobs\Job;
|
||||
|
||||
/**
|
||||
* Class EloquentCategoryRepository
|
||||
*
|
||||
@@ -9,23 +11,340 @@ namespace Firefly\Storage\Category;
|
||||
*/
|
||||
class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
{
|
||||
protected $_user = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_user = \Auth::user();
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a transfer/category component and updates the transaction journal to match.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importUpdateTransfer(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
|
||||
if ($job->attempts() > 10) {
|
||||
\Log::error('Never found category/transfer combination "' . $payload['data']['transfer_id'] . '"');
|
||||
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed.
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $journals */
|
||||
$journals = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$journals->overruleUser($user);
|
||||
|
||||
/*
|
||||
* Prep some vars from the payload
|
||||
*/
|
||||
$transferId = intval($payload['data']['transfer_id']);
|
||||
$componentId = intval($payload['data']['component_id']);
|
||||
|
||||
/*
|
||||
* Find the import map for both:
|
||||
*/
|
||||
$categoryMap = $repository->findImportEntry($importMap, 'Category', $componentId);
|
||||
$transferMap = $repository->findImportEntry($importMap, 'Transfer', $transferId);
|
||||
|
||||
/*
|
||||
* Either may be null:
|
||||
*/
|
||||
if (is_null($categoryMap) || is_null($transferMap)) {
|
||||
\Log::notice('No map found in category/transfer mapper. Release.');
|
||||
if (\Config::get('queue.default') == 'sync') {
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
} else {
|
||||
$job->release(300); // proper release.
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the budget and the transaction:
|
||||
*/
|
||||
$category = $this->find($categoryMap->new);
|
||||
/** @var \TransactionJournal $journal */
|
||||
$journal = $journals->find($transferMap->new);
|
||||
|
||||
/*
|
||||
* If either is null, release:
|
||||
*/
|
||||
if (is_null($category) || is_null($journal)) {
|
||||
\Log::notice('Map is incorrect in category/transfer mapper. Release.');
|
||||
if (\Config::get('queue.default') == 'sync') {
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
} else {
|
||||
$job->release(300); // proper release.
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update journal to have budget:
|
||||
*/
|
||||
$journal->categories()->save($category);
|
||||
$journal->save();
|
||||
\Log::debug('Connected category "' . $category->name . '" to journal "' . $journal->description . '"');
|
||||
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \User $user
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function overruleUser(\User $user)
|
||||
{
|
||||
$this->_user = $user;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $categoryId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($categoryId)
|
||||
{
|
||||
return $this->_user->categories()->find($categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a transaction/category component and updates the transaction journal to match.
|
||||
*
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importUpdateTransaction(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
|
||||
if ($job->attempts() > 10) {
|
||||
\Log::error('Never found category/transaction combination "' . $payload['data']['transaction_id'] . '"');
|
||||
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed.
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface $journals */
|
||||
$journals = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface');
|
||||
$journals->overruleUser($user);
|
||||
|
||||
/*
|
||||
* Prep some vars from the payload
|
||||
*/
|
||||
$transactionId = intval($payload['data']['transaction_id']);
|
||||
$componentId = intval($payload['data']['component_id']);
|
||||
|
||||
/*
|
||||
* Find the import map for both:
|
||||
*/
|
||||
$categoryMap = $repository->findImportEntry($importMap, 'Category', $componentId);
|
||||
$transactionMap = $repository->findImportEntry($importMap, 'Transaction', $transactionId);
|
||||
|
||||
/*
|
||||
* Either may be null:
|
||||
*/
|
||||
if (is_null($categoryMap) || is_null($transactionMap)) {
|
||||
\Log::notice('No map found in category/transaction mapper. Release.');
|
||||
if (\Config::get('queue.default') == 'sync') {
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
} else {
|
||||
$job->release(300); // proper release.
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the budget and the transaction:
|
||||
*/
|
||||
$category = $this->find($categoryMap->new);
|
||||
/** @var \TransactionJournal $journal */
|
||||
$journal = $journals->find($transactionMap->new);
|
||||
|
||||
/*
|
||||
* If either is null, release:
|
||||
*/
|
||||
if (is_null($category) || is_null($journal)) {
|
||||
\Log::notice('Map is incorrect in category/transaction mapper. Release.');
|
||||
if (\Config::get('queue.default') == 'sync') {
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
$job->delete(); // count fixed
|
||||
} else {
|
||||
$job->release(300); // proper release.
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update journal to have budget:
|
||||
*/
|
||||
$journal->categories()->save($category);
|
||||
$journal->save();
|
||||
\Log::debug('Connected category "' . $category->name . '" to journal "' . $journal->description . '"');
|
||||
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Job $job
|
||||
* @param array $payload
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function importCategory(Job $job, array $payload)
|
||||
{
|
||||
/** @var \Firefly\Storage\Import\ImportRepositoryInterface $repository */
|
||||
$repository = \App::make('Firefly\Storage\Import\ImportRepositoryInterface');
|
||||
|
||||
/** @var \Importmap $importMap */
|
||||
$importMap = $repository->findImportmap($payload['mapID']);
|
||||
$user = $importMap->user;
|
||||
$this->overruleUser($user);
|
||||
|
||||
/*
|
||||
* Maybe the category has already been imported
|
||||
*/
|
||||
$importEntry = $repository->findImportEntry($importMap, 'Category', intval($payload['data']['id']));
|
||||
|
||||
/*
|
||||
* if so, delete job and return:
|
||||
*/
|
||||
if (!is_null($importEntry)) {
|
||||
\Log::debug('Already imported category ' . $payload['data']['name']);
|
||||
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* try to find category first
|
||||
*/
|
||||
$current = $this->findByName($payload['data']['name']);
|
||||
|
||||
/*
|
||||
* If not found, create it:
|
||||
*/
|
||||
if (is_null($current)) {
|
||||
$category = $this->store($payload['data']);
|
||||
$repository->store($importMap, 'Category', $payload['data']['id'], $category->id);
|
||||
\Log::debug('Imported category "' . $payload['data']['name'] . '".');
|
||||
} else {
|
||||
$repository->store($importMap, 'Category', $payload['data']['id'], $current->id);
|
||||
\Log::debug('Already had category "' . $payload['data']['name'] . '".');
|
||||
}
|
||||
|
||||
// update map:
|
||||
$importMap->jobsdone++;
|
||||
$importMap->save();
|
||||
|
||||
$job->delete(); // count fixed
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByName($name)
|
||||
{
|
||||
if ($name == '' || strlen($name) == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->_user->categories()->where('name', $name)->first();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return \Category|mixed
|
||||
*/
|
||||
public function store($data)
|
||||
{
|
||||
$category = new \Category;
|
||||
$category->name = $data['name'];
|
||||
|
||||
$category->user()->associate($this->_user);
|
||||
$category->save();
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return \Category|mixed
|
||||
*/
|
||||
public function createOrFind($name)
|
||||
public function firstOrCreate($name)
|
||||
{
|
||||
if (strlen($name) == 0) {
|
||||
return null;
|
||||
}
|
||||
$category = $this->findByName($name);
|
||||
if (!$category) {
|
||||
return $this->store(['name' => $name]);
|
||||
}
|
||||
|
||||
return $category;
|
||||
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'user_id' => $this->_user->id,
|
||||
];
|
||||
return \Category::firstOrCreate($data);
|
||||
|
||||
}
|
||||
|
||||
@@ -41,53 +360,12 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $categoryId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($categoryId)
|
||||
{
|
||||
return \Auth::user()->categories()->find($categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function findByName($name)
|
||||
{
|
||||
if ($name == '' || strlen($name) == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return \Auth::user()->categories()->where('name', 'LIKE', '%' . $name . '%')->first();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \Auth::user()->categories()->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
*
|
||||
* @return \Category|mixed
|
||||
*/
|
||||
public function store($data)
|
||||
{
|
||||
$category = new \Category;
|
||||
$category->name = $data['name'];
|
||||
|
||||
$category->user()->associate(\Auth::user());
|
||||
$category->save();
|
||||
|
||||
return $category;
|
||||
return $this->_user->categories()->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user