Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cicer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Quique
cicer
Commits
ee516091
Unverified
Commit
ee516091
authored
3 years ago
by
meskio
Browse files
Options
Downloads
Patches
Plain Diff
Annual report
parent
237fc745
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Head.js
+3
-0
3 additions, 0 deletions
src/Head.js
src/Panel.js
+4
-0
4 additions, 0 deletions
src/Panel.js
src/product/AnnualReport.js
+96
-0
96 additions, 0 deletions
src/product/AnnualReport.js
with
103 additions
and
0 deletions
src/Head.js
+
3
−
0
View file @
ee516091
...
...
@@ -28,6 +28,9 @@ function Head(props) {
<
LinkContainer
to
=
"
/transaction
"
>
<
NavDropdown
.
Item
>
Transacciones
<
/NavDropdown.Item
>
<
/LinkContainer
>
<
LinkContainer
to
=
"
/annual
"
>
<
NavDropdown
.
Item
>
Listado
Anual
<
/NavDropdown.Item
>
<
/LinkContainer
>
<
/NavDropdown
>
);
}
...
...
This diff is collapsed.
Click to expand it.
src/Panel.js
+
4
−
0
View file @
ee516091
...
...
@@ -5,6 +5,7 @@ import MemberAdder from "./member/MemberAdder";
import
MemberEditer
from
"
./member/MemberEditer
"
;
import
MemberList
from
"
./member/MemberList
"
;
import
ProductList
from
"
./product/ProductList
"
;
import
AnnualReport
from
"
./product/AnnualReport
"
;
import
ShowProduct
from
"
./product/ShowProduct
"
;
import
CreateProduct
from
"
./product/CreateProduct
"
;
import
Inventary
from
"
./inventary/Inventary
"
;
...
...
@@ -56,6 +57,9 @@ function LogedPanel(props) {
<
Route
path
=
"
/products
"
>
<
ProductList
/>
<
/Route
>
<
Route
path
=
"
/annual
"
>
<
AnnualReport
/>
<
/Route
>
<
Route
path
=
"
/product/add
"
>
<
CreateProduct
/>
<
/Route
>
...
...
This diff is collapsed.
Click to expand it.
src/product/AnnualReport.js
0 → 100644
+
96
−
0
View file @
ee516091
import
React
,
{
useState
}
from
"
react
"
;
import
Fetcher
from
"
../Fetcher
"
;
import
{
date2string
}
from
"
../util
"
;
function
transactionsPerMonth
(
transactions
)
{
let
productsPerMonth
=
{};
const
incProduct
=
(
date
,
name
,
amount
)
=>
{
if
(
amount
===
0
)
{
return
;
}
const
strDate
=
String
(
date
.
getFullYear
())
+
"
-
"
+
(
date
.
getMonth
()
+
1
);
if
(
productsPerMonth
[
strDate
]
===
undefined
)
{
productsPerMonth
[
strDate
]
=
{};
}
if
(
productsPerMonth
[
strDate
][
name
]
===
undefined
)
{
productsPerMonth
[
strDate
][
name
]
=
amount
;
}
else
{
productsPerMonth
[
strDate
][
name
]
+=
amount
;
}
};
transactions
.
forEach
((
t
)
=>
{
const
date
=
new
Date
(
Date
.
parse
(
t
.
date
));
const
monthDate
=
new
Date
(
date
.
getFullYear
(),
date
.
getMonth
());
switch
(
t
.
type
)
{
case
"
purchase
"
:
t
.
purchase
.
forEach
((
e
)
=>
incProduct
(
monthDate
,
e
.
product
.
name
,
e
.
amount
)
);
break
;
case
"
order
"
:
t
.
order_purchase
.
forEach
((
e
)
=>
incProduct
(
monthDate
,
e
.
order_product
.
product
.
name
,
e
.
amount
)
);
break
;
default
:
return
;
}
});
return
productsPerMonth
;
}
function
AnnualReport
()
{
const
[
data
,
setData
]
=
useState
([]);
const
setTransactions
=
(
transactions
)
=>
{
const
d
=
transactionsPerMonth
(
transactions
);
setData
(
d
);
};
let
dates
=
Object
.
keys
(
data
);
dates
=
dates
.
sort
((
a
,
b
)
=>
b
.
localeCompare
(
a
));
const
months
=
dates
.
map
((
date
)
=>
{
let
products
=
Object
.
keys
(
data
[
date
]);
console
.
log
(
data
);
products
=
products
.
sort
((
a
,
b
)
=>
data
[
date
][
a
]
<
data
[
date
][
b
]
?
1
:
-
1
);
console
.
log
(
products
);
const
productList
=
products
.
map
((
product
)
=>
(
<
li
key
=
{
date
+
"
-
"
+
product
}
>
{
product
}:
{
data
[
date
][
product
]}
<
/li
>
));
return
(
<
div
>
<
h3
>
{
date
}
<
/h3
>
<
ul
>
{
productList
}
<
/ul
>
<
/div
>
);
});
const
now
=
new
Date
();
const
end
=
date2string
(
now
);
const
start
=
date2string
(
new
Date
(
now
.
getFullYear
()
-
1
,
now
.
getMonth
()));
return
(
<
Fetcher
url
=
{
"
/api/transaction?start-date=
"
+
start
+
"
&end-date=
"
+
end
+
"
&type=purchase&type=order
"
}
onFetch
=
{
setTransactions
}
oneShot
>
{
months
}
<
/Fetcher
>
);
}
export
default
AnnualReport
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment