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
ef2f29e4
Commit
ef2f29e4
authored
Mar 10, 2022
by
Damien Moulard
Browse files
Options
Browse Files
Download
Plain Diff
fix merge conflict
parents
310ce8a3
47f168b8
Pipeline
#1901
passed with stage
in 1 minute 29 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
102 additions
and
66 deletions
+102
-66
orders_helper.js
orders/static/js/orders_helper.js
+102
-66
No files found.
orders/static/js/orders_helper.js
View file @
ef2f29e4
...
@@ -9,7 +9,8 @@ var suppliers_list = [],
...
@@ -9,7 +9,8 @@ var suppliers_list = [],
new_product_supplier_association
=
{
new_product_supplier_association
=
{
package_qty
:
null
,
package_qty
:
null
,
price
:
null
price
:
null
};
},
qties_values
=
{};
var
dbc
=
null
,
var
dbc
=
null
,
sync
=
null
,
sync
=
null
,
...
@@ -30,6 +31,10 @@ var dbc = null,
...
@@ -30,6 +31,10 @@ var dbc = null,
var
clicked_order_pill
=
null
;
var
clicked_order_pill
=
null
;
let
userAgent
=
navigator
.
userAgent
;
var
timerId
;
var
timerId
;
/* - UTILS */
/* - UTILS */
...
@@ -124,12 +129,74 @@ function debounceFunction(func, delay = 1000) {
...
@@ -124,12 +129,74 @@ function debounceFunction(func, delay = 1000) {
timerId
=
setTimeout
(
func
,
delay
);
timerId
=
setTimeout
(
func
,
delay
);
}
}
/* - PRODUCTS */
/* - PRODUCTS */
var
process_new_product_qty
=
function
(
input
)
{
// Remove line coloring on input blur
const
row
=
$
(
input
).
closest
(
'tr'
);
row
.
removeClass
(
'focused_line'
);
let
val
=
(
$
(
input
).
val
()
==
''
)
?
0
:
$
(
input
).
val
();
const
id_split
=
$
(
input
).
attr
(
'id'
)
.
split
(
'_'
);
const
prod_id
=
id_split
[
1
];
const
supplier_id
=
id_split
[
3
];
if
(
val
==
-
1
)
{
let
modal_end_supplier_product_association
=
$
(
'#templates #modal_end_supplier_product_association'
);
const
product
=
products
.
find
(
p
=>
p
.
id
==
prod_id
);
modal_end_supplier_product_association
.
find
(
".product_name"
).
text
(
product
.
name
);
const
supplier
=
selected_suppliers
.
find
(
s
=>
s
.
id
==
supplier_id
);
modal_end_supplier_product_association
.
find
(
".supplier_name"
).
text
(
supplier
.
display_name
);
openModal
(
modal_end_supplier_product_association
.
html
(),
()
=>
{
if
(
is_time_to
(
'validate_end_supplier_product_association'
))
{
end_supplier_product_association
(
product
,
supplier
);
}
},
'Valider'
,
false
,
true
,
()
=>
{
// Reset value in input on cancel
const
psi
=
product
.
suppliersinfo
.
find
(
psi_item
=>
psi_item
.
supplier_id
==
supplier_id
);
$
(
input
).
val
(
psi
.
qty
);
}
);
}
else
{
val
=
parseFloat
(
val
);
// If value is a number
if
(
!
isNaN
(
val
))
{
// Save value
save_product_supplier_qty
(
prod_id
,
supplier_id
,
val
);
// Update row
const
product
=
products
.
find
(
p
=>
p
.
id
==
prod_id
);
const
new_row_data
=
prepare_datatable_data
([
product
.
id
])[
0
];
products_table
.
row
(
$
(
input
).
closest
(
'tr'
)).
data
(
new_row_data
)
.
draw
();
debounceFunction
(
update_cdb_order
);
display_total_values
();
}
else
{
$
(
input
).
val
(
''
);
}
}
};
/**
/**
* Add a product.
* Add a product.
*
*
* @returns -1 if validation failed, 0 otherwise
* @returns -1 if validation failed, 0 otherwise
*/
*/
function
add_product
()
{
function
add_product
()
{
const
user_input
=
$
(
"#product_input"
).
val
();
const
user_input
=
$
(
"#product_input"
).
val
();
...
@@ -224,6 +291,7 @@ function compute_and_affect_product_supplier_quantities(coeff, days) {
...
@@ -224,6 +291,7 @@ function compute_and_affect_product_supplier_quantities(coeff, days) {
const
stock
=
product
.
qty_available
;
const
stock
=
product
.
qty_available
;
const
incoming_qty
=
product
.
incoming_qty
;
const
incoming_qty
=
product
.
incoming_qty
;
const
daily_conso
=
product
.
daily_conso
;
const
daily_conso
=
product
.
daily_conso
;
purchase_package_qty_for_coverage
=
compute_purchase_qty_for_coverage
(
product
,
coeff
,
stock
,
incoming_qty
,
daily_conso
,
days
);
purchase_package_qty_for_coverage
=
compute_purchase_qty_for_coverage
(
product
,
coeff
,
stock
,
incoming_qty
,
daily_conso
,
days
);
// Set qty to purchase for first supplier only
// Set qty to purchase for first supplier only
products
[
key
].
suppliersinfo
[
0
].
qty
=
purchase_package_qty_for_coverage
;
products
[
key
].
suppliersinfo
[
0
].
qty
=
purchase_package_qty_for_coverage
;
...
@@ -241,6 +309,7 @@ function compute_products_coverage_qties() {
...
@@ -241,6 +309,7 @@ function compute_products_coverage_qties() {
return
new
Promise
((
resolve
)
=>
{
return
new
Promise
((
resolve
)
=>
{
const
pc_adjust
=
$
(
'#percent_adjust_input'
).
val
();
const
pc_adjust
=
$
(
'#percent_adjust_input'
).
val
();
let
coeff
=
1
;
let
coeff
=
1
;
if
(
!
isNaN
(
parseFloat
(
pc_adjust
)))
{
if
(
!
isNaN
(
parseFloat
(
pc_adjust
)))
{
coeff
=
(
1
+
parseFloat
(
pc_adjust
)
/
100
);
coeff
=
(
1
+
parseFloat
(
pc_adjust
)
/
100
);
}
}
...
@@ -256,7 +325,7 @@ function compute_products_coverage_qties() {
...
@@ -256,7 +325,7 @@ function compute_products_coverage_qties() {
step
=
1
;
step
=
1
;
//Let's compute the nearst amount, by changing days quantity
//Let's compute the nearst amount, by changing days quantity
while
(
go_on
==
true
&&
iter
<
max_iter
)
{
while
(
go_on
==
true
&&
iter
<
max_iter
)
{
order_total_value
=
0
;
order_total_value
=
0
;
compute_and_affect_product_supplier_quantities
(
coeff
,
days
);
compute_and_affect_product_supplier_quantities
(
coeff
,
days
);
_compute_total_values_by_supplier
();
_compute_total_values_by_supplier
();
...
@@ -1681,68 +1750,11 @@ function display_products(params) {
...
@@ -1681,68 +1750,11 @@ function display_products(params) {
row
.
addClass
(
'focused_line'
);
row
.
addClass
(
'focused_line'
);
});
});
// Manage data on inputs blur
$
(
'#products_table'
).
on
(
'blur'
,
'tbody td .product_qty_input'
,
function
()
{
// Remove line coloring on input blur
const
row
=
$
(
this
).
closest
(
'tr'
);
row
.
removeClass
(
'focused_line'
);
let
val
=
(
$
(
this
).
val
()
==
''
)
?
0
:
$
(
this
).
val
();
const
id_split
=
$
(
this
).
attr
(
'id'
)
// Manage data on inputs blur
.
split
(
'_'
);
$
(
'#products_table'
)
const
prod_id
=
id_split
[
1
];
.
on
(
'blur'
,
'tbody td .product_qty_input'
,
function
()
{
const
supplier_id
=
id_split
[
3
];
process_new_product_qty
(
this
);
if
(
val
==
-
1
)
{
let
modal_end_supplier_product_association
=
$
(
'#templates #modal_end_supplier_product_association'
);
const
product
=
products
.
find
(
p
=>
p
.
id
==
prod_id
);
modal_end_supplier_product_association
.
find
(
".product_name"
).
text
(
product
.
name
);
const
supplier
=
selected_suppliers
.
find
(
s
=>
s
.
id
==
supplier_id
);
modal_end_supplier_product_association
.
find
(
".supplier_name"
).
text
(
supplier
.
display_name
);
openModal
(
modal_end_supplier_product_association
.
html
(),
()
=>
{
if
(
is_time_to
(
'validate_end_supplier_product_association'
))
{
end_supplier_product_association
(
product
,
supplier
);
}
},
'Valider'
,
false
,
true
,
()
=>
{
// Reset value in input on cancel
const
psi
=
product
.
suppliersinfo
.
find
(
psi_item
=>
psi_item
.
supplier_id
==
supplier_id
);
$
(
this
).
val
(
psi
.
qty
);
}
);
}
else
{
val
=
parseFloat
(
val
);
// If value is a number
if
(
!
isNaN
(
val
))
{
// Save value
save_product_supplier_qty
(
prod_id
,
supplier_id
,
val
);
// Update row
const
product
=
products
.
find
(
p
=>
p
.
id
==
prod_id
);
const
new_row_data
=
prepare_datatable_data
([
product
.
id
])[
0
];
products_table
.
row
(
$
(
this
).
closest
(
'tr'
)).
data
(
new_row_data
)
.
draw
();
debounceFunction
(
update_cdb_order
);
display_total_values
();
}
else
{
$
(
this
).
val
(
''
);
}
}
})
})
.
on
(
'keypress'
,
'tbody td .product_qty_input'
,
function
(
e
)
{
.
on
(
'keypress'
,
'tbody td .product_qty_input'
,
function
(
e
)
{
// Validate on Enter pressed
// Validate on Enter pressed
...
@@ -2261,12 +2273,12 @@ $(document).ready(function() {
...
@@ -2261,12 +2273,12 @@ $(document).ready(function() {
.
then
(()
=>
{
.
then
(()
=>
{
debounceFunction
(
update_cdb_order
);
debounceFunction
(
update_cdb_order
);
update_main_screen
();
update_main_screen
();
})
});
}
else
{
}
else
{
$
(
"#coverage_days_input"
).
val
(
order_doc
.
coverage_days
||
''
);
$
(
"#coverage_days_input"
).
val
(
order_doc
.
coverage_days
||
''
);
$
(
'#targeted_amount_input'
).
val
(
order_doc
.
targeted_amount
||
''
);
$
(
'#targeted_amount_input'
).
val
(
order_doc
.
targeted_amount
||
''
);
alert
(
"Ni le nombre de jours de couverture, ni le montant à atteindre sont correctement renseignés"
)
alert
(
"Ni le nombre de jours de couverture, ni le montant à atteindre sont correctement renseignés"
)
;
}
}
}
}
...
@@ -2326,7 +2338,7 @@ $(document).ready(function() {
...
@@ -2326,7 +2338,7 @@ $(document).ready(function() {
update_main_screen
();
update_main_screen
();
debounceFunction
(
update_cdb_order
);
debounceFunction
(
update_cdb_order
);
closeModal
();
closeModal
();
})
});
});
});
}
}
...
@@ -2597,6 +2609,30 @@ $(document).ready(function() {
...
@@ -2597,6 +2609,30 @@ $(document).ready(function() {
panel
.
style
.
display
=
"block"
;
panel
.
style
.
display
=
"block"
;
}
}
});
});
if
(
/Firefox
\/
/
.
exec
(
userAgent
))
{
// needed to prevent bug using number input arrow to change quantity (https://bugzilla.mozilla.org/show_bug.cgi?id=1012818)
// Have to capture mousedown and mouseup events, instead of using only click event
// Indeed, capturing click only remove the ability to click to have focus on the input to type a number.
$
(
document
).
on
(
"mousedown"
,
'[type="number"]'
,
function
()
{
const
clicked
=
this
;
qties_values
[
$
(
clicked
).
attr
(
'id'
)]
=
$
(
clicked
).
val
();
});
$
(
document
).
on
(
"mouseup"
,
'[type="number"]'
,
function
()
{
const
clicked
=
this
;
try
{
if
(
$
(
clicked
).
val
()
!=
qties_values
[
$
(
clicked
).
attr
(
'id'
)])
{
process_new_product_qty
(
clicked
);
}
}
catch
(
err
)
{
console
.
log
(
err
);
}
});
}
}
else
{
}
else
{
$
(
'#not_connected_content'
).
show
();
$
(
'#not_connected_content'
).
show
();
}
}
...
...
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