@ -2,6 +2,7 @@ total = 0
products = [ ]
products = [ ]
menus = [ ]
menus = [ ]
cotisations = [ ]
cotisations = [ ]
reloads = [ ]
paymentMethod = null
paymentMethod = null
balance = 0
balance = 0
username = ""
username = ""
@ -95,12 +96,33 @@ function add_cotisation(pk, duration, amount){
generate_html ( ) ;
generate_html ( ) ;
}
}
function add_reload ( value , payment_method , payment_method_name ) {
exist = false ;
index = - 1 ;
for ( k = 0 ; k < reloads . length ; k ++ ) {
if ( reloads [ k ] . value == value && reloads [ k ] . payment_method == payment_method ) {
exist = true ;
index = k ;
}
}
if ( exist ) {
reloads [ index ] . quantity += 1 ;
} else {
reloads . push ( { "value" : value , "quantity" : 1 , "payment_method" : payment_method , "payment_method_name" : payment_method_name } ) ;
}
generate_html ( ) ;
}
function generate_html ( ) {
function generate_html ( ) {
html = "" ;
html = "" ;
for ( k = 0 ; k < cotisations . length ; k ++ ) {
for ( k = 0 ; k < cotisations . length ; k ++ ) {
cotisation = cotisations [ k ] ;
cotisation = cotisations [ k ] ;
html += '<tr><td></td><td>Cotisation ' + String ( cotisation . duration ) + ' jours</td><td>' + String ( cotisation . amount ) + ' €</td><td><input type="number" data-target="' + String ( k ) + '" onChange="updateCotisationInput(this)" value="' + String ( cotisation . quantity ) + '"/></td><td>' + String ( Number ( ( cotisation . quantity * cotisation . amount ) . toFixed ( 2 ) ) ) + ' €</td></tr>' ;
html += '<tr><td></td><td>Cotisation ' + String ( cotisation . duration ) + ' jours</td><td>' + String ( cotisation . amount ) + ' €</td><td><input type="number" data-target="' + String ( k ) + '" onChange="updateCotisationInput(this)" value="' + String ( cotisation . quantity ) + '"/></td><td>' + String ( Number ( ( cotisation . quantity * cotisation . amount ) . toFixed ( 2 ) ) ) + ' €</td></tr>' ;
}
}
for ( k = 0 ; k < reloads . length ; k ++ ) {
reload = reloads [ k ] ;
html += '<tr><td>Rechargement ' + String ( reload . payment_method_name ) + " " + String ( reload . value ) + ' €</td><td>-' + String ( reload . value ) + ' €</td><td><input type="number" data-target="' + String ( k ) + '" onChange="updateReloadInput(this)" value="' + String ( reload . quantity ) + '"/></td><td>-' + String ( Number ( ( reload . quantity * reload . value ) . toFixed ( 2 ) ) ) + ' €</td></tr>' ;
}
for ( k = 0 ; k < products . length ; k ++ ) {
for ( k = 0 ; k < products . length ; k ++ ) {
product = products [ k ]
product = products [ k ]
html += '<tr><td>' + product . name + '</td><td>' + String ( product . amount ) + ' €</td><td><input type="number" data-target="' + String ( k ) + '" onChange="updateInput(this)" value="' + String ( product . quantity ) + '"/></td><td>' + String ( Number ( ( product . quantity * product . amount ) . toFixed ( 2 ) ) ) + ' €</td></tr>' ;
html += '<tr><td>' + product . name + '</td><td>' + String ( product . amount ) + ' €</td><td><input type="number" data-target="' + String ( k ) + '" onChange="updateInput(this)" value="' + String ( product . quantity ) + '"/></td><td>' + String ( Number ( ( product . quantity * product . amount ) . toFixed ( 2 ) ) ) + ' €</td></tr>' ;
@ -109,7 +131,7 @@ function generate_html(){
menu = menus [ k ]
menu = menus [ k ]
html += '<tr><td>' + menu . name + '</td><td>' + String ( menu . amount ) + ' €</td><td><input type="number" data-target="' + String ( k ) + '" onChange="updateMenuInput(this)" value="' + String ( menu . quantity ) + '"/></td><td>' + String ( Number ( ( menu . quantity * menu . amount ) . toFixed ( 2 ) ) ) + ' €</td></tr>' ;
html += '<tr><td>' + menu . name + '</td><td>' + String ( menu . amount ) + ' €</td><td><input type="number" data-target="' + String ( k ) + '" onChange="updateMenuInput(this)" value="' + String ( menu . quantity ) + '"/></td><td>' + String ( Number ( ( menu . quantity * menu . amount ) . toFixed ( 2 ) ) ) + ' €</td></tr>' ;
}
}
$ ( "#items" ) . html ( html )
$ ( "#items" ) . html ( html ) ;
updateTotal ( ) ;
updateTotal ( ) ;
}
}
@ -124,6 +146,9 @@ function updateTotal(){
for ( k = 0 ; k < cotisations . length ; k ++ ) {
for ( k = 0 ; k < cotisations . length ; k ++ ) {
total += cotisations [ k ] . quantity * cotisations [ k ] . amount ;
total += cotisations [ k ] . quantity * cotisations [ k ] . amount ;
}
}
for ( k = 0 ; k < reloads . length ; k ++ ) {
total -= reloads [ k ] . quantity * reloads [ k ] . value ;
}
$ ( "#totalAmount" ) . text ( String ( Number ( total . toFixed ( 2 ) ) ) + "€" )
$ ( "#totalAmount" ) . text ( String ( Number ( total . toFixed ( 2 ) ) ) + "€" )
totalAfter = balance - total
totalAfter = balance - total
$ ( "#totalAfter" ) . text ( String ( Number ( totalAfter . toFixed ( 2 ) ) ) + "€" )
$ ( "#totalAfter" ) . text ( String ( Number ( totalAfter . toFixed ( 2 ) ) ) + "€" )
@ -150,6 +175,13 @@ function updateCotisationInput(a){
generate_html ( ) ;
generate_html ( ) ;
}
}
function updateReloadInput ( a ) {
quantity = parseInt ( a . value ) ;
k = parseInt ( a . getAttribute ( "data-target" ) ) ;
reloads [ k ] . quantity = quantity ;
generate_html ( ) ;
}
$ ( document ) . ready ( function ( ) {
$ ( document ) . ready ( function ( ) {
$ ( ".cotisation-hidden" ) . hide ( ) ;
$ ( ".cotisation-hidden" ) . hide ( ) ;
get_config ( ) ;
get_config ( ) ;
@ -166,6 +198,10 @@ $(document).ready(function(){
cotisation = get_cotisation ( $ ( this ) . attr ( 'target' ) ) ;
cotisation = get_cotisation ( $ ( this ) . attr ( 'target' ) ) ;
} ) ;
} ) ;
$ ( ".reload" ) . click ( function ( ) {
add_reload ( parseInt ( $ ( this ) . attr ( 'target' ) ) , parseInt ( $ ( this ) . attr ( 'data-payment' ) ) , $ ( this ) . attr ( 'data-payment-name' ) ) ;
} )
$ ( "#id_client" ) . on ( 'change' , function ( ) {
$ ( "#id_client" ) . on ( 'change' , function ( ) {
id_user = $ ( "#id_client" ) . val ( ) ;
id_user = $ ( "#id_client" ) . val ( ) ;
$ . get ( "/users/getUser/" + id_user , function ( data ) {
$ . get ( "/users/getUser/" + id_user , function ( data ) {
@ -206,7 +242,7 @@ $(document).ready(function(){
}
}
}
}
}
}
$ . post ( "order" , { "user" : id_user , "paymentMethod" : $ ( this ) . attr ( 'data-payment' ) , "order_length" : products . length + menus . length + cotisations . length , "order" : JSON . stringify ( products ) , "amount" : total , "menus" : JSON . stringify ( menus ) , "listPintes" : JSON . stringify ( listPintes ) , "cotisations" : JSON . stringify ( cotisations ) } , function ( data ) {
$ . post ( "order" , { "user" : id_user , "paymentMethod" : $ ( this ) . attr ( 'data-payment' ) , "order_length" : products . length + menus . length + cotisations . length + reloads . length , "order" : JSON . stringify ( products ) , "amount" : total , "menus" : JSON . stringify ( menus ) , "listPintes" : JSON . stringify ( listPintes ) , "cotisations" : JSON . stringify ( cotisations ) , "reloads" : JSON . stringify ( reload s ) } , function ( data ) {
alert ( data ) ;
alert ( data ) ;
location . reload ( ) ;
location . reload ( ) ;
} ) . fail ( function ( data ) {
} ) . fail ( function ( data ) {