Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
third-party
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cooperatic-foodcoops
third-party
Commits
f58946f8
Commit
f58946f8
authored
Jul 01, 2021
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
display total order values
parent
1e31fc73
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
13 deletions
+86
-13
oders_helper_style.css
orders/static/css/oders_helper_style.css
+24
-2
orders_helper.js
orders/static/js/orders_helper.js
+42
-1
helper.html
templates/orders/helper.html
+20
-10
No files found.
orders/static/css/oders_helper_style.css
View file @
f58946f8
...
@@ -154,12 +154,34 @@
...
@@ -154,12 +154,34 @@
cursor
:
pointer
;
cursor
:
pointer
;
}
}
/* --
Bottom action button
*/
/* --
Footer
*/
#main_content_footer
{
#main_content_footer
{
margin
:
10px
0
35px
0
;
}
#footer_orders_recap
{
width
:
100%
;
display
:
flex
;
justify-content
:
space-evenly
;
margin-bottom
:
15px
;
}
#footer_actions
{
width
:
100%
;
display
:
flex
;
display
:
flex
;
justify-content
:
space-between
;
justify-content
:
space-between
;
margin
:
15px
0
35px
0
;
}
#suppliers_total_values
{
display
:
flex
;
}
.supplier_total_item
{
display
:
flex
;
flex-direction
:
column
;
justify-content
:
center
;
align-items
:
center
;
}
}
/* -- Suppliers list */
/* -- Suppliers list */
...
...
orders/static/js/orders_helper.js
View file @
f58946f8
...
@@ -253,7 +253,7 @@ function add_supplier() {
...
@@ -253,7 +253,7 @@ function add_supplier() {
const
user_input
=
$
(
"#supplier_input"
).
val
();
const
user_input
=
$
(
"#supplier_input"
).
val
();
// Check if user input is a valid supplier
// Check if user input is a valid supplier
cons
t
supplier
=
suppliers_list
.
find
(
s
=>
s
.
display_name
===
user_input
);
le
t
supplier
=
suppliers_list
.
find
(
s
=>
s
.
display_name
===
user_input
);
if
(
supplier
===
undefined
)
{
if
(
supplier
===
undefined
)
{
alert
(
"Le fournisseur renseigné n'est pas valide.
\
n"
alert
(
"Le fournisseur renseigné n'est pas valide.
\
n"
...
@@ -272,6 +272,7 @@ function add_supplier() {
...
@@ -272,6 +272,7 @@ function add_supplier() {
openModal
();
openModal
();
supplier
.
total_value
=
0
;
selected_suppliers
.
push
(
supplier
);
selected_suppliers
.
push
(
supplier
);
let
url
=
"/orders/get_supplier_products"
;
let
url
=
"/orders/get_supplier_products"
;
...
@@ -468,6 +469,25 @@ function is_product_related_to_supplier(product, supplier) {
...
@@ -468,6 +469,25 @@ function is_product_related_to_supplier(product, supplier) {
return
product
.
suppliersinfo
.
find
(
s
=>
s
.
supplier_id
===
supplier
.
id
)
!==
undefined
;
return
product
.
suppliersinfo
.
find
(
s
=>
s
.
supplier_id
===
supplier
.
id
)
!==
undefined
;
}
}
/**
* Calculate the total value purchased for all supplier
*/
function
_compute_total_values_by_supplier
()
{
// Reinit
for
(
let
s
of
selected_suppliers
)
{
s
.
total_value
=
0
;
}
for
(
let
p
of
products
)
{
for
(
let
supinfo
of
p
.
suppliersinfo
)
{
let
supplier_index
=
selected_suppliers
.
findIndex
(
s
=>
s
.
id
==
supinfo
.
supplier_id
);
let
product_supplier_value
=
(
'qty'
in
supinfo
)
?
supinfo
.
qty
*
supinfo
.
price
:
0
;
selected_suppliers
[
supplier_index
].
total_value
+=
product_supplier_value
;
}
}
}
/* - PRODUCT */
/* - PRODUCT */
/**
/**
...
@@ -1264,6 +1284,7 @@ function display_products(params) {
...
@@ -1264,6 +1284,7 @@ function display_products(params) {
.
draw
();
.
draw
();
update_cdb_order
();
update_cdb_order
();
display_total_values
();
}
else
{
}
else
{
$
(
this
).
val
(
''
);
$
(
this
).
val
(
''
);
}
}
...
@@ -1409,6 +1430,25 @@ function unselect_all_rows() {
...
@@ -1409,6 +1430,25 @@ function unselect_all_rows() {
}
}
/**
/**
* Display the total values for each supplier & the global total value
*/
function
display_total_values
()
{
_compute_total_values_by_supplier
();
$
(
'#suppliers_total_values_container'
).
empty
();
let
total_values_content
=
'<ul>'
;
let
order_total_value
=
0
;
for
(
let
supplier
of
selected_suppliers
)
{
total_values_content
+=
`<li>
${
supplier
.
display_name
}
:
${
supplier
.
total_value
}
€</li>`
;
order_total_value
+=
supplier
.
total_value
;
}
total_values_content
+=
'</ul>'
;
$
(
'#suppliers_total_values_container'
).
append
(
total_values_content
);
$
(
'#order_total_value'
).
text
(
`
${
order_total_value
}
€`
);
}
/**
* Update DOM display on main screen
* Update DOM display on main screen
*/
*/
function
update_main_screen
(
params
)
{
function
update_main_screen
(
params
)
{
...
@@ -1422,6 +1462,7 @@ function update_main_screen(params) {
...
@@ -1422,6 +1462,7 @@ function update_main_screen(params) {
$
(
".order_name_container"
).
text
(
order_doc
.
_id
);
$
(
".order_name_container"
).
text
(
order_doc
.
_id
);
display_suppliers
();
display_suppliers
();
display_products
(
params
);
display_products
(
params
);
display_total_values
();
// Re-select previously selected rows
// Re-select previously selected rows
if
(
selected_rows
.
length
>
0
)
{
if
(
selected_rows
.
length
>
0
)
{
...
...
templates/orders/helper.html
View file @
f58946f8
...
@@ -64,18 +64,28 @@
...
@@ -64,18 +64,28 @@
</div>
</div>
<div
id=
"main_content_footer"
style=
"display:none;"
>
<div
id=
"main_content_footer"
style=
"display:none;"
>
<div
class=
"add_product_container
"
>
<div
id=
"footer_orders_recap
"
>
<div
id=
"
product_form_container
"
>
<div
id=
"
suppliers_total_values
"
>
<
form
action=
"javascript:;"
id=
"product_form"
>
<
h4>
Total /fournisseur :
</h4><div
id=
"suppliers_total_values_container"
></div
>
<input
type=
"text"
name=
"article"
id=
"product_input"
placeholder=
"Rechercher un article"
>
</div
>
<button
type=
"submit"
class=
'btn--primary'
>
Ajouter l'article
</button
>
<div
id=
"order_total_value_container"
>
<
/form
>
<
h4>
Total :
<span
id=
"order_total_value"
></span></h4
>
</div>
</div>
</div>
</div>
<button
type=
"button"
class=
'btn--primary'
id=
"create_orders"
>
<div
id=
"footer_actions"
>
Générer les commandes
<div
class=
"add_product_container"
>
</button>
<div
id=
"product_form_container"
>
</div>
<form
action=
"javascript:;"
id=
"product_form"
>
<input
type=
"text"
name=
"article"
id=
"product_input"
placeholder=
"Rechercher un article"
>
<button
type=
"submit"
class=
'btn--primary'
>
Ajouter l'article
</button>
</form>
</div>
</div>
<button
type=
"button"
class=
'btn--primary'
id=
"create_orders"
>
Générer les commandes
</button>
</div>
</div>
</div>
</div>
<div
id=
"orders_created"
class=
"page_content"
style=
"display:none;"
>
<div
id=
"orders_created"
class=
"page_content"
style=
"display:none;"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment