@ -1,138 +1,122 @@
package controller . admin ;
import haxe . web . Dispatch ;
import Common ;
class Admin extends Controller {
public function n e w ( ) {
super ( ) ;
view . category = ' a d m i n ' ;
//trigger a "Nav" event
// trigger a "Nav" event
var nav = new Array < Link > ( ) ;
var e = Nav ( nav , " a d m i n " ) ;
var e = Nav ( nav , " a d m i n " ) ;
app . event ( e ) ;
view . nav = e . getParameters ( ) [ 0 ] ;
}
@ tpl ( " a d m i n / d e f a u l t . m t t " )
function doDefault ( ) {
view . now = Date . now ( ) ;
}
@ tpl ( " a d m i n / e m a i l s . m t t " )
function doEmails ( ) {
var browse = function ( index : Int , limit : Int ) {
return sugoi . db . BufferedMail . manager . search ( $sdate == null , { limit : [ index , limit ] , orderBy : - cdate } , false ) ;
return sugoi . db . BufferedMail . manager . search ( $sdate == null , { limit : [ index , limit ] , orderBy : - cdate } , false ) ;
}
var count = sugoi . db . BufferedMail . manager . count ( $sdate == null ) ;
view . browser = new sugoi . tools . ResultsBrowser ( count , 10 , browse ) ;
var count = sugoi . db . BufferedMail . manager . count ( $sdate == null ) ;
view . browser = new sugoi . tools . ResultsBrowser ( count , 10 , browse ) ;
view . num = count ;
}
@ tpl ( " f o r m . m t t " )
function doSmtp ( ) {
var f = new sugoi . form . Form ( " e m a i l s " ) ;
var data = [
{ label : " S M T P " , value : " s m t p " } ,
{ label : " M a n d r i l l A P I " , value : " m a n d r i l l " } ,
] ;
var mailer = sugoi . db . Variable . get ( " m a i l e r " ) == null ? " s m t p " : sugoi . db . Variable . get ( " m a i l e r " ) ;
var host = sugoi . db . Variable . get ( " s m t p _ h o s t " ) == null ? App . config . get ( " s m t p _ h o s t " ) : sugoi . db . Variable . get ( " s m t p _ h o s t " ) ;
var port = sugoi . db . Variable . get ( " s m t p _ p o r t " ) == null ? App . config . get ( " s m t p _ p o r t " ) : sugoi . db . Variable . get ( " s m t p _ p o r t " ) ;
var user = sugoi . db . Variable . get ( " s m t p _ u s e r " ) == null ? App . config . get ( " s m t p _ u s e r " ) : sugoi . db . Variable . get ( " s m t p _ u s e r " ) ;
var pass = sugoi . db . Variable . get ( " s m t p _ p a s s " ) == null ? App . config . get ( " s m t p _ p a s s " ) : sugoi . db . Variable . get ( " s m t p _ p a s s " ) ;
f . addElement ( new sugoi . form . elements . StringSelect ( " m a i l e r " , " M a i l e r " , data , mailer ) ) ;
var data = [ { label : " S M T P " , value : " s m t p " } , { label : " M a n d r i l l A P I " , value : " m a n d r i l l " } , ] ;
var mailer = sugoi . db . Variable . get ( " m a i l e r " ) == null ? " s m t p " : sugoi . db . Variable . get ( " m a i l e r " ) ;
var host = sugoi . db . Variable . get ( " s m t p _ h o s t " ) == null ? " < S M T P _ S E R V E R > " : sugoi . db . Variable . get ( " s m t p _ h o s t " ) ;
var port = sugoi . db . Variable . get ( " s m t p _ p o r t " ) == null ? " 5 8 7 " : sugoi . db . Variable . get ( " s m t p _ p o r t " ) ;
var user = sugoi . db . Variable . get ( " s m t p _ u s e r " ) == null ? " " : sugoi . db . Variable . get ( " s m t p _ u s e r " ) ;
var pass = sugoi . db . Variable . get ( " s m t p _ p a s s " ) == null ? " " : sugoi . db . Variable . get ( " s m t p _ p a s s " ) ;
f . addElement ( new sugoi . form . elements . StringSelect ( " m a i l e r " , " M a i l e r " , data , mailer ) ) ;
f . addElement ( new sugoi . form . elements . StringInput ( " s m t p _ h o s t " , " h o s t " , host ) ) ;
f . addElement ( new sugoi . form . elements . StringInput ( " s m t p _ p o r t " , " p o r t " , port ) ) ;
f . addElement ( new sugoi . form . elements . StringInput ( " s m t p _ u s e r " , " u s e r " , user ) ) ;
f . addElement ( new sugoi . form . elements . StringInput ( " s m t p _ p a s s " , " p a s s " , pass ) ) ;
if ( f . isValid ( ) ) {
for ( k in [ " m a i l e r " , " s m t p _ h o s t " , " s m t p _ p o r t " , " s m t p _ u s e r " , " s m t p _ p a s s " ] ) {
if ( f . isValid ( ) ) {
for ( k in [ " m a i l e r " , " s m t p _ h o s t " , " s m t p _ p o r t " , " s m t p _ u s e r " , " s m t p _ p a s s " ] ) {
sugoi . db . Variable . set ( k , f . getValueOf ( k ) ) ;
}
throw Ok ( " / a d m i n / e m a i l s " , t . _ ( " C o n f i g u r a t i o n u p d a t e d " ) ) ;
throw Ok ( " / a d m i n / e m a i l s " , t . _ ( " C o n f i g u r a t i o n u p d a t e d " ) ) ;
}
view . title = t . _ ( " E m a i l s e r v i c e c o n f i g u r a t i o n " ) ;
view . form = f ;
}
function doPlugins ( d : Dispatch ) {
d . dispatch ( new controller . admin . Plugins ( ) ) ;
}
@ tpl ( " a d m i n / t a x o . m t t " )
function doTaxo ( ) {
function doTaxo ( ) {
view . categ = db . TxpCategory . manager . all ( ) ;
}
/ * *
* Display errors logged in DB
* /
@ tpl ( " a d m i n / e r r o r s . m t t " )
function doErrors ( args : { ? user : Int , ? like : String , ? empty : Bool } ) {
function doErrors ( args : { ? user : Int , ? like : String , ? empty : Bool } ) {
view . now = Date . now ( ) ;
view . u = args . user != null ? db . User . manager . get ( args . user , false ) : null ;
view . like = args . like != null ? args . like : " " ;
view . u = args . user != null ? db . User . manager . get ( args . user , false ) : null ;
view . like = args . like != null ? args . like : " " ;
var sql = " " ;
if ( args . user != null ) sql += " A N D u i d = " + args . user ;
//if( args.like!=null && args.like != "" ) sql += " AND error like "+sys.db.Manager.cnx.quote("%"+args.like+"%");
if ( args . user != null )
sql += " A N D u i d = " + args . user ;
// if( args.like!=null && args.like != "" ) sql += " AND error like "+sys.db.Manager.cnx.quote("%"+args.like+"%");
if ( args . empty ) {
sys . db . Manager . cnx . request ( " t r u n c a t e t a b l e E r r o r " ) ;
}
var errorsStats = sys . db . Manager . cnx . request ( " s e l e c t c o u n t ( i d ) a s c , D A T E _ F O R M A T ( d a t e , ' % y - % m - % d ' ) a s d a y f r o m E r r o r w h e r e d a t e > N O W ( ) - I N T E R V A L 1 M O N T H " + sql + " g r o u p b y d a y o r d e r b y d a y " ) . results ( ) ;
var errorsStats = sys . db . Manager . cnx . request ( " s e l e c t c o u n t ( i d ) a s c , D A T E _ F O R M A T ( d a t e , ' % y - % m - % d ' ) a s d a y f r o m E r r o r w h e r e d a t e > N O W ( ) - I N T E R V A L 1 M O N T H "
+ sql
+ " g r o u p b y d a y o r d e r b y d a y " )
. results ( ) ;
view . errorsStats = errorsStats ;
view . browser = new sugoi . tools . ResultsBrowser (
sugoi . db . Error . manager . unsafeCount ( " S E L E C T c o u n t ( * ) F R O M E r r o r W H E R E 1 " + sql ) ,
20 ,
function ( start , limit ) { return sugoi . db . Error . manager . unsafeObjects ( " S E L E C T * F R O M E r r o r W H E R E 1 " + sql + " O R D E R B Y d a t e D E S C L I M I T " + start + " , " + limit , false ) ; }
) ;
view . browser = new sugoi . tools . ResultsBrowser ( sugoi . db . Error . manager . unsafeCount ( " S E L E C T c o u n t ( * ) F R O M E r r o r W H E R E 1 " + sql ) , 20 ,
function ( start , limit ) {
return sugoi . db . Error . manager . unsafeObjects ( " S E L E C T * F R O M E r r o r W H E R E 1 " + sql + " O R D E R B Y d a t e D E S C L I M I T " + start + " , " + limit , false ) ;
} ) ;
}
@ tpl ( " a d m i n / g r a p h . m t t " )
function doGraph ( ? key : String , ? year : Int , ? month : Int ) {
var from = new Date ( year , month , 1 , 0 , 0 , 0 ) ;
var to = new Date ( year , month + 1 , 0 , 23 , 59 , 59 ) ;
function doGraph ( ? key : String , ? year : Int , ? month : Int ) {
var from = new Date ( year , month , 1 , 0 , 0 , 0 ) ;
var to = new Date ( year , month + 1 , 0 , 23 , 59 , 59 ) ;
if ( app . params . exists ( " r e c o m p u t e " ) ) {
switch ( key ) {
if ( app . params . exists ( " r e c o m p u t e " ) ) {
switch ( key ) {
c ase " b a s k e t " :
for ( d in 1 ... to . getDate ( ) ) {
var _from = new Date ( year , month , d , 0 , 0 , 0 ) ;
var _to = new Date ( year , month , d , 23 , 59 , 59 ) ;
var value = db . Basket . manager . count ( $cdate >= _from && $cdate <= _to ) ;
var g = db . Graph . record ( key , value , _from ) ;
for ( d in 1 ... to . getDate ( ) ) {
var _from = new Date ( year , month , d , 0 , 0 , 0 ) ;
var _to = new Date ( year , month , d , 23 , 59 , 59 ) ;
var value = db . Basket . manager . count ( $cdate >= _from && $cdate <= _to ) ;
var g = db . Graph . record ( key , value , _from ) ;
// trace(value,_from,g);
}
}
}
var data = db . Graph . getRange ( key , from , to ) ;
var data = db . Graph . getRange ( key , from , to ) ;
view . data = data ;
view . from = from ;
view . to = to ;
@ -140,84 +124,69 @@ class Admin extends Controller {
var averageValue = 0.0 ;
var total = 0.0 ;
for ( d in data ) total += d . value ;
averageValue = total / data . length ;
for ( d in data )
total += d . value ;
averageValue = total / data . length ;
view . total = total ;
view . averageValue = averageValue ;
}
function doFixDistribValidation ( ) {
function doFixDistribValidation ( ) {
Sys . println ( " = = = = = L i s t e d e s d i s t r i b u t i o n s a y a n t é t é r e - v a l i d é e s = = = = < b r > " ) ;
//Get the current group
// Get the current group
var group = app . user . amap ;
//Get all the contracts for this given group
var contractIds = Lambda . map ( group . getContracts ( ) , function ( x ) return x . id ) ;
//Get all the validated distributions for this given group
var validatedDistribs = db . Distribution . manager . search ( ( $contractId in contractIds ) && $validated == true , { orderBy : date } , false ) ;
for ( distrib in validatedDistribs ) {
// Get all the contracts for this given group
var contractIds = Lambda . map ( group . getContracts ( ) , function ( x ) return x . id ) ;
// Get all the validated distributions for this given group
var validatedDistribs = db . Distribution . manager . search ( ( $contractId in contractIds ) && $validated == true , { orderBy : date } , false ) ;
for ( distrib in validatedDistribs ) {
service . PaymentService . validateDistribution ( distrib ) ;
Sys . println ( distrib . toString ( ) + " < b r > " ) ;
}
Sys . println ( " = = = = = F i n d e l a l i s t e = = = = " ) ;
}
function doCheckDistribValidation ( ) {
Sys . println ( " = = = = = L i s t e d e s d i s t r i b u t i o n s v a l i d é e s a y a n t d e s o p é r a t i o n s / p a i e m e n t s n o n v a l i d é s = = = = < b r > " ) ;
//Get the current group
// Get the current group
var group = app . user . amap ;
//Get all the contracts for this given group
var contractIds = Lambda . map ( group . getContracts ( ) , function ( x ) return x . id ) ;
//Get all the validated distributions for this given group
var validatedDistribs = db . Distribution . manager . search ( ( $contractId in contractIds ) && $validated == true , { orderBy : date } , false ) ;
for ( distrib in validatedDistribs ) {
for ( user in distrib . getUsers ( ) ) {
// Get all the contracts for this given group
var contractIds = Lambda . map ( group . getContracts ( ) , function ( x ) return x . id ) ;
// Get all the validated distributions for this given group
var validatedDistribs = db . Distribution . manager . search ( ( $contractId in contractIds ) && $validated == true , { orderBy : date } , false ) ;
for ( distrib in validatedDistribs ) {
for ( user in distrib . getUsers ( ) ) {
var basket = db . Basket . get ( user , distrib . place , distrib . date ) ;
if ( basket == null || basket . isValidated ( ) ) continue ;
for ( order in basket . getOrders ( ) ) {
if ( basket == null || basket . isValidated ( ) )
continue ;
for ( order in basket . getOrders ( ) ) {
if ( ! order . paid ) {
Sys . println ( order . distribution . toString ( ) + " < b r > " ) ;
Sys . println ( order . toString ( ) + " < b r > " ) ;
}
}
}
var operation = basket . getOrderOperation ( false ) ;
if ( operation != null ) {
if ( operation != null ) {
if ( operation . pending ) {
Sys . println ( distrib . toString ( ) + " < b r > " ) ;
Sys . println ( operation . toString ( ) + " < b r > " ) ;
}
for ( payment in basket . getPayments ( ) ) {
if ( payment . pending ) {
for ( payment in basket . getPayments ( ) ) {
if ( payment . pending ) {
Sys . println ( distrib . toString ( ) + " < b r > " ) ;
Sys . println ( payment . toString ( ) + " < b r > " ) ;
}
}
}
}
}
}
Sys . println ( " = = = = = F i n d e l a l i s t e = = = = " ) ;
}
}