Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
089f137636 | ||
|
|
0426a175aa | ||
|
|
59b7c48a89 | ||
|
|
d13c85be61 | ||
|
|
2714f44b44 | ||
|
|
04cb4343ad | ||
|
|
e94c4eae67 | ||
|
|
47abd95962 | ||
|
|
c346584d46 | ||
|
|
bbeea934e4 | ||
|
|
3c8a2507d9 | ||
|
|
6c0e632ef2 | ||
|
|
f94e005a91 | ||
|
|
15f89039b3 | ||
|
|
0d3a32a018 | ||
|
|
2641e70eaf | ||
|
|
0ebb698c54 | ||
|
|
3621289fee | ||
|
|
544db390ef | ||
|
|
f357d716b7 | ||
|
|
a49bee1a52 | ||
|
|
286bfd14ea | ||
|
|
068288ddd1 | ||
|
|
30d4c85250 | ||
|
|
6170e5f499 | ||
|
|
b1d56d85c0 | ||
|
|
3c76533541 | ||
|
|
076c03d6c6 | ||
|
|
4f1b4d90a6 | ||
|
|
10f916f262 | ||
|
|
744581bad9 | ||
|
|
b80fe490dc | ||
|
|
179e35a88b | ||
|
|
28b825db07 | ||
|
|
d8c72cf249 | ||
|
|
c4250cc201 | ||
|
|
f54f78b03e | ||
|
|
97a9c1c4e3 | ||
|
|
6ca6e89cd5 | ||
|
|
f5d09537b9 |
+2
-2
@@ -1,6 +1,7 @@
|
||||
*.n
|
||||
*.php
|
||||
config.xml
|
||||
package-lock.json
|
||||
www/plugin/*
|
||||
tmp/*
|
||||
*node_modules*
|
||||
@@ -29,9 +30,8 @@ www/file/*
|
||||
www/js/app.js
|
||||
www/js/libs.js
|
||||
|
||||
|
||||
www/css/.sass-cache
|
||||
www/css/*.css
|
||||
!www/css/bootstrap.min.css
|
||||
|
||||
|
||||
config-dev.xml
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
1.8.1
|
||||
@@ -26,12 +26,6 @@ install_dev:
|
||||
#template tools
|
||||
haxelib run templo
|
||||
sudo mv temploc2 /usr/bin
|
||||
#extra plugins
|
||||
@if [ $(PLUGINS) = 1 ]; then \
|
||||
haxelib git cagette-pro git@bitbucket.org:bubar/cagette-pro.git; \
|
||||
haxelib git cagette-hosted git@bitbucket.org:bubar/cagette-hosted.git; \
|
||||
haxelib git cagette-wholesale-order git@github.com:bablukid/cagette-wholesale-order.git; \
|
||||
fi
|
||||
#install npm dependencies
|
||||
npm install
|
||||
npm run libs:dev
|
||||
@@ -80,22 +74,8 @@ templates:
|
||||
@make LANG=fr ctemplates
|
||||
msgfmt www/lang/texts_fr.po -o www/lang/texts_fr.mo
|
||||
chown www-data:www-data -R www
|
||||
chown www-data:www-data -R lang
|
||||
|
||||
ctemplates:
|
||||
# (cd lang/$(LANG)/tpl; temploc2 -macros macros.mtt -output ../tmp/ *.mtt */*.mtt */*/*.mtt */*/*/*.mtt */*/*/*/*.mtt)
|
||||
(cd lang/$(LANG)/tpl; temploc2 -macros macros.mtt -output ../tmp/ *.mtt */*.mtt */*/*.mtt)
|
||||
|
||||
#Compile and run unit tests
|
||||
tests:
|
||||
@if [ $(PLUGINS) = 1 ]; then \
|
||||
haxe testsPlugins.hxml; \
|
||||
else \
|
||||
haxe tests.hxml; \
|
||||
fi
|
||||
@docker-compose run --workdir="/var/www/www" neko neko tests.n mysql://root:root@mysql/tests
|
||||
|
||||
cp_plugin:
|
||||
cp -R .haxelib/cagette-hosted/git/tpl/* lang/master/tpl/plugin/hosted/
|
||||
cp -R .haxelib/cagette-pro/git/tpl/* lang/master/tpl/plugin/pro/
|
||||
cp -R .haxelib/cagette-wholesale-order/git/tpl/* lang/master/tpl/plugin/who/
|
||||
|
||||
|
||||
@@ -1,8 +1,174 @@
|
||||
# Cagette péi
|
||||
CAGETTE PEI
|
||||
===========
|
||||
|
||||
Fourche du logiciel [Cagette.net](https://github.com/CagetteNet) à partir de la version 0.9.2 Novembre 2018
|
||||
|
||||
Certaines portions du code source de Cagette.net n'étant plus disponibles en téléchargement,
|
||||
j'ai repris sur la base d'un existant pour adapter au marché local réunionnais et leurs AMAPéi.
|
||||
|
||||
## INSTALL FROM SCRATCH (debian-buster)
|
||||
|
||||
* apt install -y curl
|
||||
* curl -L https://deb.nodesource.com/setup_8.x | bash -
|
||||
* apt install -y nodejs=8.17.0-1nodesource1
|
||||
* apt install -y sudo haxe apache2 make git imagemagick gettext libapache2-mod-neko mariadb-server
|
||||
* mysql -u root <<EOF
|
||||
CREATE DATABASE cagettepei;
|
||||
GRANT ALL ON cagettepei.* TO 'cagettepei'@'%' IDENTIFIED BY 'cagettepei';
|
||||
EOF
|
||||
* cd /var/www
|
||||
* git clone https://git.artcode.re/cagetters/cagettepei.git
|
||||
* cd cagettepei
|
||||
* make install ENV=dev # first time
|
||||
* make compile # classes
|
||||
* make templates # templates + i18n
|
||||
* vim /etc/apache2/sites-available/cagettepei.conf
|
||||
```
|
||||
<VirtualHost *:80>
|
||||
ServerName cagettepei
|
||||
DirectoryIndex index.n
|
||||
DocumentRoot /var/www/cagettepei/www/
|
||||
|
||||
|
||||
</VirtualHost>
|
||||
```
|
||||
* sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
|
||||
* a2dissite 000-default.conf
|
||||
* a2ensite cagettepei.conf
|
||||
* a2enmod neko rewrite
|
||||
* systemctl restart apache2
|
||||
|
||||
## CONFIGURATION
|
||||
|
||||
* cd /var/www/cagettepei
|
||||
* vim config.xml
|
||||
```
|
||||
<config
|
||||
host="<DOMAIN.TLD>"
|
||||
key="<SECRET_PHRASE>"
|
||||
name = "CagettePéi"
|
||||
default_email = "<EMAIL>"
|
||||
webmaster_email = "<EMAIL>"
|
||||
database="mysql://cagettepei:cagettepei@localhost/cagettepei"
|
||||
|
||||
smtp_host="localhost"
|
||||
smtp_port="25"
|
||||
smtp_user=""
|
||||
smtp_pass=""
|
||||
|
||||
lang="fr"
|
||||
langs="fr"
|
||||
langnames="Français"
|
||||
maintain="0"
|
||||
debug="0"
|
||||
sqllog="0"
|
||||
cache="1"
|
||||
cachetpl="0"
|
||||
/>
|
||||
```
|
||||
|
||||
ADMIN RESET PASSWORD
|
||||
--------------------
|
||||
|
||||
go to http://localhost for ERROR + table regeneration, then
|
||||
|
||||
* cd /var/www/cagettepei
|
||||
* SECRET=$(grep key= config.xml | cut -d= -f2 | cut -d'"' -f2)
|
||||
* echo "insert into User values (1,'fr',MD5('${SECRET}cagettepei'),1,'Administrateur','Cagette Péi', 'admin', null, null, null, null, null, null, null, null, null, now(), now(),6,null, null)" | mysql -h localhost -u cagettepei -pcagettepei cagettepei
|
||||
|
||||
then, connect with admin / cagettepei
|
||||
|
||||
### change admin password
|
||||
|
||||
* echo "update User set pass=MD5('${SECRET}cagettepei') where id=1" | mysql -h localhost -u cagettepei -pcagettepei cagettepei
|
||||
|
||||
|
||||
SYSTEMD-TIMERS
|
||||
--------------
|
||||
|
||||
* vim /var/www/cagettepei-batch
|
||||
```
|
||||
#!/bin/bash
|
||||
|
||||
case $1 in
|
||||
minute);;
|
||||
daily);;
|
||||
*) echo "expected [minute|daily]" && exit 1;;
|
||||
esac
|
||||
|
||||
SELECTOR=$1
|
||||
|
||||
for i in /var/www/cagettepei-* ; do
|
||||
if [[ -d $i ]]; then
|
||||
cd $i/www
|
||||
echo "cron-$SELECTOR in: $i"
|
||||
neko index.n cron/$SELECTOR
|
||||
echo
|
||||
fi
|
||||
done
|
||||
```
|
||||
|
||||
* chmod +x /var/www/cagettepei-batch
|
||||
* vim /etc/systemd/system/cagettepei-batch-minute.service
|
||||
```
|
||||
[Unit]
|
||||
Description=Run batch cagettepei every minute
|
||||
|
||||
[Service]
|
||||
User=www-data
|
||||
SyslogIdentifier=cagettepei
|
||||
ExecStart=/var/www/cagettepei-batch minute
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
* vim /etc/systemd/system/cagettepei-batch-day.service
|
||||
```
|
||||
[Unit]
|
||||
Description=Run batch cagettepei every day
|
||||
|
||||
[Service]
|
||||
User=www-data
|
||||
SyslogIdentifier=cagettepei
|
||||
ExecStart=/var/www/cagettepei-batch daily
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
* vim /etc/systemd/system/cagettepei-batch-minute.timer
|
||||
```
|
||||
[Unit]
|
||||
Description=Timer for batch cagettepei every minute
|
||||
Requires=apache2.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar=minutely
|
||||
Unit=cagettepei-batch-minute.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
```
|
||||
|
||||
* vim /etc/systemd/system/cagettepei-batch-day.timer
|
||||
```
|
||||
[Unit]
|
||||
Description=Timer for batch cagettepei every day
|
||||
Requires=apache2.service
|
||||
|
||||
[Timer]
|
||||
OnCalendar=daily
|
||||
Unit=cagettepei-batch-day.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
```
|
||||
* systemctl daemon-reload
|
||||
* systemctl edit apache2 # bind the 2 timers to apache2 cagette
|
||||
```
|
||||
[Unit]
|
||||
BindsTo = cagettepei-batch-minute.timer cagettepei-batch-day.timer
|
||||
```
|
||||
* systemctl enable cagettepei-batch-minute.timer cagettepei-batch-day.timer
|
||||
* systemctl start cagettepei-batch-minute.timer cagettepei-batch-day.timer
|
||||
+3
-3
@@ -23,9 +23,9 @@
|
||||
-lib tink_typecrawler:0.7.0
|
||||
|
||||
## GIT
|
||||
-lib sugoi:git:git@artcode.re:cagetters/sugoi.git
|
||||
-lib record-macros:git:git@artcode.re:cagetters/record-macros.git
|
||||
-lib dbadmin:git:git@artcode.re:cagetters/dbadmin.git
|
||||
-lib sugoi:git:https://git.artcode.re/cagetters/sugoi.git
|
||||
-lib record-macros:git:https://git.artcode.re/cagetters/record-macros.git
|
||||
-lib dbadmin:git:https://git.artcode.re/cagetters/dbadmin.git
|
||||
|
||||
## SCRIPT
|
||||
-cp common
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
-lib templo
|
||||
-lib hxevents
|
||||
-lib thx.semver
|
||||
-lib thx.csv
|
||||
-lib datetime
|
||||
-lib hscript
|
||||
-lib smtpmailer
|
||||
-lib tink_json
|
||||
|
||||
-lib sugoi:git:https://github.com/bablukid/sugoi#master
|
||||
-lib record-macros:git:https://github.com/HaxeFoundation/record-macros#master
|
||||
-lib dbadmin:git:https://github.com/ncannasse/dbadmin.git#master
|
||||
|
||||
-lib cagette-pro:git:https://bubar@bitbucket.org/bubar/cagette-pro.git#master
|
||||
-lib cagette-hosted:git:https://bubar@bitbucket.org/bubar/cagette-hosted.git#master
|
||||
-lib cagette-wholesale-order:git:https://github.com/bablukid/cagette-wholesale-order.git#master
|
||||
|
||||
-cp common
|
||||
-cp src
|
||||
-cp lang/master/tpl
|
||||
|
||||
-D plugins
|
||||
|
||||
|
||||
-neko www/index.n
|
||||
-main App
|
||||
@@ -1,76 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project version="2">
|
||||
<!-- Output SWF options -->
|
||||
<output>
|
||||
<movie outputType="Application" />
|
||||
<movie input="" />
|
||||
<movie path="www\index.n" />
|
||||
<movie fps="30" />
|
||||
<movie width="800" />
|
||||
<movie height="600" />
|
||||
<movie version="0" />
|
||||
<movie minorVersion="0" />
|
||||
<movie platform="Neko" />
|
||||
<movie background="#FFFFFF" />
|
||||
</output>
|
||||
<!-- Other classes to be compiled into your SWF -->
|
||||
<classpaths>
|
||||
<class path="common" />
|
||||
<class path="src" />
|
||||
<class path="lang\master\tpl" />
|
||||
</classpaths>
|
||||
<!-- Build options -->
|
||||
<build>
|
||||
<option directives="plugins" />
|
||||
<option flashStrict="False" />
|
||||
<option noInlineOnDebug="False" />
|
||||
<option mainClass="App" />
|
||||
<option enabledebug="False" />
|
||||
<option additional="" />
|
||||
</build>
|
||||
<!-- haxelib libraries -->
|
||||
<haxelib>
|
||||
<library name="templo" />
|
||||
<library name="thx.semver" />
|
||||
<library name="thx.csv" />
|
||||
<library name="hxevents" />
|
||||
<library name="hscript" />
|
||||
<library name="record-macros" />
|
||||
<library name="smtpmailer" />
|
||||
<library name="datetime" />
|
||||
<library name="sugoi:git:https://github.com/bablukid/sugoi#i18n" />
|
||||
<library name="record-macros:git:https://github.com/HaxeFoundation/record-macros#maste" />
|
||||
<library name="dbadmin:git:https://github.com/ncannasse/dbadmin.git#master" />
|
||||
<library name="cagette-pro:git:https://bubar@bitbucket.org/bubar/cagette-pro.git#master" />
|
||||
<library name="cagette-connector:git:https://bubar@bitbucket.org/bubar/cagette-connector.git#master" />
|
||||
<library name="cagette-wholesale-order:git:https://bubar@bitbucket.org/bubar/cagette-wholesale-order.git#master" />
|
||||
<library name="cagette-hosted:git:https://bubar@bitbucket.org/bubar/cagette-hosted.git#master" />
|
||||
</haxelib>
|
||||
<!-- Class files to compile (other referenced classes will automatically be included) -->
|
||||
<compileTargets>
|
||||
<!-- example: <compile path="..." /> -->
|
||||
</compileTargets>
|
||||
<!-- Paths to exclude from the Project Explorer tree -->
|
||||
<hiddenPaths>
|
||||
<hidden path="project.hxml" />
|
||||
<hidden path="lang\fr\tmp" />
|
||||
<hidden path="preLaunch" />
|
||||
<hidden path="art" />
|
||||
<hidden path="www\file" />
|
||||
<hidden path="config.tpl.xml" />
|
||||
<hidden path="clearFileCache.bat" />
|
||||
<hidden path="obj" />
|
||||
</hiddenPaths>
|
||||
<!-- Executed before build -->
|
||||
<preBuildCommand />
|
||||
<!-- Executed after build -->
|
||||
<postBuildCommand alwaysRun="False" />
|
||||
<!-- Other project options -->
|
||||
<options>
|
||||
<option showHiddenPaths="True" />
|
||||
<option testMovie="Custom" />
|
||||
<option testMovieCommand="" />
|
||||
</options>
|
||||
<!-- Plugin storage -->
|
||||
<storage />
|
||||
</project>
|
||||
@@ -1,17 +0,0 @@
|
||||
-dce no
|
||||
-cp common
|
||||
-cp js
|
||||
-lib sugoi:git:https://github.com/bablukid/sugoi#i18n
|
||||
-lib hxleaflet:git:https://github.com/bablukid/hxleaflet
|
||||
-lib cagette-hosted
|
||||
-lib react
|
||||
-lib react-router-4
|
||||
-lib modular
|
||||
-lib tink_json
|
||||
|
||||
-D plugins
|
||||
-D no-deprecation-warnings
|
||||
|
||||
-main App
|
||||
-js www/js/app.js
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
-dce no
|
||||
-cp common
|
||||
-cp js
|
||||
-lib sugoi:git:git@artcode.re:cagetters/sugoi.git
|
||||
-lib hxleaflet:git:git@artcode.re:cagetters/hxleaflet.git
|
||||
-lib sugoi:git:https://git.artcode.re/cagetters/sugoi.git
|
||||
-lib hxleaflet:git:https://git.artcode.re/cagetters/hxleaflet.git
|
||||
-lib react:1.4.0
|
||||
-lib react-router-4:0.2.3
|
||||
-lib modular:0.10.15
|
||||
|
||||
+5
-5
@@ -1,11 +1,11 @@
|
||||
<config
|
||||
|
||||
database="mysql://<USER>:<PASSWORD>@<HOST>/<DBNAME>"
|
||||
host="<URL without http>"
|
||||
database = "mysql://<USER>:<PASSWORD>@<HOST>/<DBNAME>"
|
||||
host = "<URL without http>"
|
||||
name = "<HTML head title>"
|
||||
default_email = "<default email>"
|
||||
|
||||
key="carotteMagique"
|
||||
default_email = "<EMAIL>"
|
||||
webmaster_email = "<EMAIL>"
|
||||
key = "<SECRET_PHRASE>"
|
||||
|
||||
maintain="0"
|
||||
cache="1"
|
||||
|
||||
@@ -142,9 +142,11 @@
|
||||
<a href="http://www.cagette.net/wiki" target="_blank">::_("Documentation")::</a>
|
||||
</li>
|
||||
<li>
|
||||
::if (user!=null && user.isAmapManager()):: <a href="https://cagette.uservoice.com" target="_blank">::_("Propose features")::</a> ::end::
|
||||
<a href="https://pad1.zourit.net/p/4a3b09afd25b4fdcb3f0a9598db21e61" target="_blank">Proposer une amélioration</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://pad1.zourit.net/p/4a3b09afd25b4fdcb3f0a9598db21e61" target="_blank">Soumettre une anomalie</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!--<p style="position: absolute;display: block;top: 96px;width: 700px;">
|
||||
|
||||
@@ -17,7 +17,7 @@ table.table td{
|
||||
<hr/>
|
||||
|
||||
<div style="color:#666;font-size:12px;">
|
||||
XXX ::_("This e-mail was sent from"):: <a href="http://::raw HOST::">::_("Cagette.net")::</a>.
|
||||
> ::_("This e-mail was sent from"):: <a href="http://::raw HOST::">::_("Cagette.net")::</a>.
|
||||
|
||||
::if group!=null::
|
||||
<br/>
|
||||
|
||||
Generated
-6187
File diff suppressed because it is too large
Load Diff
+4
-5
@@ -1,9 +1,7 @@
|
||||
{
|
||||
"name": "Cagette.net",
|
||||
"name": "CagettePei",
|
||||
"description": "le logiciel libre du circuit court",
|
||||
"author": "François Barbut <francois@alilo.fr>",
|
||||
"license": "GPL-2.0",
|
||||
"homepage": "http://www.cagette.net",
|
||||
"license": "AGPL-3.0",
|
||||
"dependencies": {
|
||||
"bootstrap": "^3.3.4",
|
||||
"eonasdan-bootstrap-datetimepicker": "^4.7.14",
|
||||
@@ -48,5 +46,6 @@
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/bablukid/cagette/issues"
|
||||
}
|
||||
},
|
||||
"version": "1.8.1"
|
||||
}
|
||||
|
||||
+64
-68
@@ -3,28 +3,26 @@ import thx.semver.Version;
|
||||
import Common;
|
||||
|
||||
class App extends sugoi.BaseApp {
|
||||
|
||||
public static var current : App = null;
|
||||
public static var t : sugoi.i18n.translator.ITranslator;
|
||||
public static var current:App = null;
|
||||
public static var t:sugoi.i18n.translator.ITranslator;
|
||||
public static var config = sugoi.BaseApp.config;
|
||||
|
||||
public var eventDispatcher :hxevents.Dispatcher<Event>;
|
||||
public var plugins : Array<sugoi.plugin.IPlugIn>;
|
||||
public var eventDispatcher:hxevents.Dispatcher<Event>;
|
||||
public var plugins:Array<sugoi.plugin.IPlugIn>;
|
||||
|
||||
/**
|
||||
* Version management
|
||||
* @doc https://github.com/fponticelli/thx.semver
|
||||
*/
|
||||
//public static var VERSION = ([0,9,2] : Version).withPre("july");
|
||||
//public static var VERSION = ([0,9,2] : Version).withPre(MyMacros.getGitShortSHA(), MyMacros.getGitCommitDate());
|
||||
// public static var VERSION = ([0,9,2] : Version).withPre("july");
|
||||
// public static var VERSION = ([0,9,2] : Version).withPre(MyMacros.getGitShortSHA(), MyMacros.getGitCommitDate());
|
||||
public static var VERSION = "cagette-péi " + MyMacros.getGitCommitDate();
|
||||
|
||||
public function new(){
|
||||
public function new() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static function main() {
|
||||
|
||||
App.t = sugoi.form.Form.translator = new sugoi.i18n.translator.TMap(getTranslationArray(), "fr");
|
||||
sugoi.BaseApp.main();
|
||||
}
|
||||
@@ -35,58 +33,59 @@ class App extends sugoi.BaseApp {
|
||||
override public function mainLoop() {
|
||||
eventDispatcher = new hxevents.Dispatcher<Event>();
|
||||
plugins = [];
|
||||
//internal plugins
|
||||
// internal plugins
|
||||
plugins.push(new plugin.Tutorial());
|
||||
|
||||
//optionnal plugins
|
||||
// optionnal plugins
|
||||
#if plugins
|
||||
plugins.push( new hosted.HostedPlugIn() );
|
||||
plugins.push( new pro.ProPlugIn() );
|
||||
plugins.push( new connector.ConnectorPlugIn() );
|
||||
plugins.push( new pro.LemonwayEC() );
|
||||
plugins.push( new who.WhoPlugIn() );
|
||||
plugins.push(new hosted.HostedPlugIn());
|
||||
plugins.push(new pro.ProPlugIn());
|
||||
plugins.push(new connector.ConnectorPlugIn());
|
||||
plugins.push(new pro.LemonwayEC());
|
||||
plugins.push(new who.WhoPlugIn());
|
||||
#end
|
||||
|
||||
super.mainLoop();
|
||||
}
|
||||
|
||||
public function getCurrentGroup(){
|
||||
if (session == null) return null;
|
||||
if (session.data == null ) return null;
|
||||
public function getCurrentGroup() {
|
||||
if (session == null)
|
||||
return null;
|
||||
if (session.data == null)
|
||||
return null;
|
||||
var a = session.data.amapId;
|
||||
if (a == null) {
|
||||
return null;
|
||||
}else {
|
||||
return db.Amap.manager.get(a,false);
|
||||
} else {
|
||||
return db.Amap.manager.get(a, false);
|
||||
}
|
||||
}
|
||||
|
||||
override function beforeDispatch() {
|
||||
|
||||
//send "current page" event
|
||||
event( Page(this.uri) );
|
||||
// send "current page" event
|
||||
event(Page(this.uri));
|
||||
|
||||
super.beforeDispatch();
|
||||
}
|
||||
|
||||
public function getPlugin(name:String):sugoi.plugin.IPlugIn {
|
||||
for (p in plugins) {
|
||||
if (p.getName() == name) return p;
|
||||
if (p.getName() == name)
|
||||
return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function log(t:Dynamic) {
|
||||
if(App.config.DEBUG) {
|
||||
neko.Web.logMessage(Std.string(t)); //write in Apache error log
|
||||
#if weblog
|
||||
Weblog.log(t); //write en Weblog console (https://lib.haxe.org/p/weblog/)
|
||||
#end
|
||||
}
|
||||
public static function log(t:Dynamic, ?infos:haxe.PosInfos) {
|
||||
// if (App.config.DEBUG) {
|
||||
// neko.Web.logMessage(Std.string(t)); // write in Apache error log
|
||||
// }
|
||||
neko.Web.logMessage('[${infos.fileName}:${infos.lineNumber} ${infos.className}#${infos.methodName}] ' + Std.string(t));
|
||||
}
|
||||
|
||||
public function event(e:Event) {
|
||||
if(e==null) return null;
|
||||
if (e == null)
|
||||
return null;
|
||||
this.eventDispatcher.dispatch(e);
|
||||
return e;
|
||||
}
|
||||
@@ -95,16 +94,16 @@ class App extends sugoi.BaseApp {
|
||||
* Translate DB objects fields in forms
|
||||
*/
|
||||
public static function getTranslationArray() {
|
||||
//var t = sugoi.i18n.Locale.texts;
|
||||
var out = new Map<String,String>();
|
||||
//out.set("firstName", t._("First name") );
|
||||
//out.set("lastName", t._("Last name"));
|
||||
// var t = sugoi.i18n.Locale.texts;
|
||||
var out = new Map<String, String>();
|
||||
// out.set("firstName", t._("First name") );
|
||||
// out.set("lastName", t._("Last name"));
|
||||
out.set("firstName2", "Prénom du conjoint");
|
||||
out.set("lastName2", "Nom du conjoint");
|
||||
out.set("email2", "e-mail du conjoint");
|
||||
//out.set("pass", t._("Password") );
|
||||
//out.set("address1", t._("address") );
|
||||
//out.set("address2", t._("address") );
|
||||
// out.set("pass", t._("Password") );
|
||||
// out.set("address1", t._("address") );
|
||||
// out.set("address2", t._("address") );
|
||||
out.set("zipCode", "code postal");
|
||||
out.set("city", "commune");
|
||||
out.set("phone", "téléphone");
|
||||
@@ -231,25 +230,22 @@ class App extends sugoi.BaseApp {
|
||||
}
|
||||
|
||||
public static function getMailer():sugoi.mail.IMailer {
|
||||
var mailer:sugoi.mail.IMailer = new sugoi.mail.BufferedMailer();
|
||||
|
||||
var mailer : sugoi.mail.IMailer = new sugoi.mail.BufferedMailer();
|
||||
|
||||
if(App.config.DEBUG){
|
||||
|
||||
//Dev env : emails are written to tmp folder
|
||||
if (App.config.DEBUG) {
|
||||
// Dev env : emails are written to tmp folder
|
||||
mailer = new sugoi.mail.DebugMailer();
|
||||
}else{
|
||||
|
||||
if (sugoi.db.Variable.get("mailer") == null){
|
||||
} else {
|
||||
if (sugoi.db.Variable.get("mailer") == null) {
|
||||
var msg = sugoi.i18n.Locale.texts._("Please configure the email settings in a <href='/admin/emails'>this section</a>");
|
||||
throw sugoi.ControllerAction.ErrorAction("/",msg);
|
||||
throw sugoi.ControllerAction.ErrorAction("/", msg);
|
||||
}
|
||||
|
||||
if (sugoi.db.Variable.get("mailer") == "mandrill"){
|
||||
//Buffered emails with Mandrill
|
||||
if (sugoi.db.Variable.get("mailer") == "mandrill") {
|
||||
// Buffered emails with Mandrill
|
||||
untyped mailer.defineFinalMailer("mandrill");
|
||||
}else{
|
||||
//Buffered emails with SMTP
|
||||
} else {
|
||||
// Buffered emails with SMTP
|
||||
untyped mailer.defineFinalMailer("smtp");
|
||||
}
|
||||
}
|
||||
@@ -259,24 +255,27 @@ class App extends sugoi.BaseApp {
|
||||
/**
|
||||
* Send an email
|
||||
*/
|
||||
public static function sendMail(m:sugoi.mail.Mail, ?group:db.Amap, ?listId:String, ?sender:db.User){
|
||||
|
||||
if (group == null) group = App.current.user == null ? null:App.current.user.getAmap();
|
||||
public static function sendMail(m:sugoi.mail.Mail, ?group:db.Amap, ?listId:String, ?sender:db.User) {
|
||||
if (group == null)
|
||||
group = App.current.user == null ? null : App.current.user.getAmap();
|
||||
|
||||
current.event(SendEmail(m));
|
||||
|
||||
var params = group==null ? null : {remoteId:group.id};
|
||||
|
||||
getMailer().send(m,params,function(o){});
|
||||
var params = group == null ? null : {remoteId: group.id};
|
||||
|
||||
App.log('about to send email with subject=<${m.getSubject()}> ...');
|
||||
getMailer().send(m, params, function(o) {});
|
||||
App.log('email from=<${m.getSender().email}>, subject=<${m.getSubject()}> successfully sent');
|
||||
}
|
||||
|
||||
public static function quickMail(to:String, subject:String, html:String,?group:db.Amap){
|
||||
public static function quickMail(to:String, subject:String, html:String, ?group:db.Amap) {
|
||||
App.log('quickMail subject=$subject');
|
||||
|
||||
var e = new sugoi.mail.Mail();
|
||||
e.setSubject(subject);
|
||||
e.setRecipient(to);
|
||||
e.setSender(App.config.get("default_email"),"Cagette.net");
|
||||
var html = App.current.processTemplate("mail/message.mtt", {text:html,group:group});
|
||||
e.setSender(App.config.get("default_email"), "Cagette.net");
|
||||
var html = App.current.processTemplate("mail/message.mtt", {text: html, group: group});
|
||||
e.setHtmlBody(html);
|
||||
App.sendMail(e);
|
||||
}
|
||||
@@ -287,21 +286,18 @@ class App extends sugoi.BaseApp {
|
||||
* @param ctx
|
||||
*/
|
||||
public function processTemplate(tpl:String, ctx:Dynamic):String {
|
||||
|
||||
Reflect.setField(ctx, 'HOST', App.config.HOST);
|
||||
Reflect.setField(ctx, 'hDate', App.current.view.hDate);
|
||||
//i18n functions
|
||||
// i18n functions
|
||||
ctx._ = App.current.view._;
|
||||
ctx.__ = App.current.view.__;
|
||||
|
||||
var tpl = loadTemplate(tpl);
|
||||
var html = tpl.execute(ctx);
|
||||
#if php
|
||||
if ( html.substr(0, 4) == "null") html = html.substr(4);
|
||||
if (html.substr(0, 4) == "null")
|
||||
html = html.substr(4);
|
||||
#end
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+374
-368
File diff suppressed because it is too large
Load Diff
+195
-181
@@ -1,48 +1,43 @@
|
||||
package controller;
|
||||
|
||||
import sugoi.db.Cache;
|
||||
import sugoi.Web;
|
||||
import sugoi.mail.Mail;
|
||||
import Common;
|
||||
|
||||
using Lambda;
|
||||
using tools.DateTool;
|
||||
|
||||
class Cron extends Controller
|
||||
{
|
||||
|
||||
public function doDefault()
|
||||
{
|
||||
|
||||
}
|
||||
class Cron extends Controller {
|
||||
public function doDefault() {}
|
||||
|
||||
/**
|
||||
* CLI only en prod
|
||||
*/
|
||||
function canRun() {
|
||||
if (App.current.user != null && App.current.user.isAdmin()){
|
||||
if (App.current.user != null && App.current.user.isAdmin()) {
|
||||
return true;
|
||||
}else if (App.config.DEBUG) {
|
||||
} else if (App.config.DEBUG) {
|
||||
return true;
|
||||
}else {
|
||||
|
||||
} else {
|
||||
if (Web.isModNeko) {
|
||||
Sys.print("only CLI.");
|
||||
return false;
|
||||
}else {
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function doMinute() {
|
||||
|
||||
print("Cron.doMinute is called");
|
||||
|
||||
if (!canRun()) return;
|
||||
if (!canRun())
|
||||
return;
|
||||
|
||||
app.event(MinutelyCron);
|
||||
|
||||
sendEmailsfromBuffer();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,64 +46,62 @@ class Cron extends Controller
|
||||
* this function can be locally tested with `neko index.n cron/hour > cron.log`
|
||||
*/
|
||||
public function doHour() {
|
||||
|
||||
app.event(HourlyCron);
|
||||
|
||||
distribNotif(4,db.User.UserFlags.HasEmailNotif4h); //4h before
|
||||
distribNotif(24,db.User.UserFlags.HasEmailNotif24h); //24h before
|
||||
distribNotif(0, db.User.UserFlags.HasEmailNotifOuverture); //on command open
|
||||
distribNotif(4, db.User.UserFlags.HasEmailNotif4h); // 4h before
|
||||
distribNotif(24, db.User.UserFlags.HasEmailNotif24h); // 24h before
|
||||
distribNotif(0, db.User.UserFlags.HasEmailNotifOuverture); // on command open
|
||||
|
||||
distribValidationNotif();
|
||||
//sendOrdersByProductWhenOrdersClose();
|
||||
// sendOrdersByProductWhenOrdersClose();
|
||||
}
|
||||
|
||||
|
||||
public function doDaily() {
|
||||
if (!canRun()) return;
|
||||
if (!canRun())
|
||||
return;
|
||||
|
||||
app.event(DailyCron);
|
||||
|
||||
//ERRORS MONITORING
|
||||
// ERRORS MONITORING
|
||||
var n = Date.now();
|
||||
var yest24h = new Date(n.getFullYear(), n.getMonth(), n.getDate(), 0, 0, 0);
|
||||
var yest0h = DateTools.delta(yest24h, -1000 * 60 * 60 * 24);
|
||||
|
||||
var errors = sugoi.db.Error.manager.search( $date < yest24h && $date > yest0h );
|
||||
var errors = sugoi.db.Error.manager.search($date < yest24h && $date > yest0h);
|
||||
if (errors.length > 0) {
|
||||
var report = new StringBuf();
|
||||
report.add("<h1>" + App.config.NAME + " : ERRORS</h1>");
|
||||
for (e in errors) {
|
||||
report.add("<div><pre>"+e.error + " at URL " + e.url + " ( user : " + (e.user!=null?e.user.toString():"none") + ", IP : " + e.ip + ")</pre></div><hr/>");
|
||||
report.add("<div><pre>" + e.error + " at URL " + e.url + " ( user : " + (e.user != null ? e.user.toString() : "none") + ", IP : " + e.ip
|
||||
+ ")</pre></div><hr/>");
|
||||
}
|
||||
|
||||
var m = new Mail();
|
||||
m.setSender(App.config.get("default_email"),"Cagette.net");
|
||||
m.setSender(App.config.get("default_email"), "Cagette.net");
|
||||
m.addRecipient(App.config.get("webmaster_email"));
|
||||
m.setSubject(App.config.NAME+" Errors");
|
||||
m.setHtmlBody( app.processTemplate("mail/message.mtt", { text:report.toString() } ) );
|
||||
m.setSubject(App.config.NAME + " Errors");
|
||||
m.setHtmlBody(app.processTemplate("mail/message.mtt", {text: report.toString()}));
|
||||
App.sendMail(m);
|
||||
}
|
||||
|
||||
// DEMO CONTRATS deletion after 7 days ( see controller.Group.doCreate() )
|
||||
db.Contract.manager.delete($name == "Contrat AMAP Maraîcher Exemple"
|
||||
&& $startDate < DateTools.delta(Date.now(), -1000.0 * 60 * 60 * 24 * 7));
|
||||
db.Contract.manager.delete($name == "Contrat Poulet Exemple"
|
||||
&& $startDate < DateTools.delta(Date.now(), -1000.0 * 60 * 60 * 24 * 7));
|
||||
|
||||
//DEMO CONTRATS deletion after 7 days ( see controller.Group.doCreate() )
|
||||
db.Contract.manager.delete($name == "Contrat AMAP Maraîcher Exemple" && $startDate < DateTools.delta(Date.now(), -1000.0 * 60 * 60 * 24 * 7));
|
||||
db.Contract.manager.delete($name == "Contrat Poulet Exemple" && $startDate < DateTools.delta(Date.now(), -1000.0 * 60 * 60 * 24 * 7));
|
||||
|
||||
|
||||
//Old Messages cleaning
|
||||
// Old Messages cleaning
|
||||
db.Message.manager.delete($date < DateTools.delta(Date.now(), -1000.0 * 60 * 60 * 24 * 30 * 6));
|
||||
|
||||
//DB cleaning : I dont know how, but some people have empty string emails...
|
||||
// DB cleaning : I dont know how, but some people have empty string emails...
|
||||
/*for ( u in db.User.manager.search($email == "", true)){
|
||||
u.email = Std.random(9999) + "@cagette.net";
|
||||
u.update();
|
||||
}
|
||||
for ( u in db.User.manager.search($email2 == "", true)){
|
||||
u.email2 = null;
|
||||
u.update();
|
||||
u.email = Std.random(9999) + "@cagette.net";
|
||||
u.update();
|
||||
}
|
||||
for ( u in db.User.manager.search($email2 == "", true)){
|
||||
u.email2 = null;
|
||||
u.update();
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,28 +110,28 @@ class Cron extends Controller
|
||||
* @param flag
|
||||
*/
|
||||
function distribNotif(hour:Int, flag:db.User.UserFlags) {
|
||||
// trouve les distrib qui commencent dans le nombre d'heures demandé
|
||||
// on recherche celles qui commencent jusqu'à une heure avant pour ne pas en rater
|
||||
var from = DateTools.delta(Date.now(), 1000.0 * 60 * 60 * (hour - 1));
|
||||
var to = DateTools.delta(Date.now(), 1000.0 * 60 * 60 * hour);
|
||||
|
||||
//trouve les distrib qui commencent dans le nombre d'heures demandé
|
||||
//on recherche celles qui commencent jusqu'à une heure avant pour ne pas en rater
|
||||
var from = DateTools.delta(Date.now(), 1000.0 * 60 * 60 * (hour-1));
|
||||
var to = DateTools.delta(Date.now(), 1000.0 * 60 * 60 * hour);
|
||||
|
||||
//if (App.config.DEBUG) from = DateTools.delta(from, 1000.0 * 60 * 60 * 24 * -30);
|
||||
// if (App.config.DEBUG) from = DateTools.delta(from, 1000.0 * 60 * 60 * 24 * -30);
|
||||
|
||||
// dans le cas HasEmailNotifOuverture la date à prendre est le orderStartDate
|
||||
// et non pas date qui est la date de la distribution
|
||||
var distribs;
|
||||
if ( db.User.UserFlags.HasEmailNotifOuverture == flag )
|
||||
distribs = db.Distribution.manager.search( $orderStartDate >= from && $orderStartDate <= to , false);
|
||||
if (db.User.UserFlags.HasEmailNotifOuverture == flag)
|
||||
distribs = db.Distribution.manager.search($orderStartDate >= from && $orderStartDate <= to, false);
|
||||
else
|
||||
distribs = db.Distribution.manager.search( $date >= from && $date <= to , false);
|
||||
distribs = db.Distribution.manager.search($date >= from && $date <= to, false);
|
||||
|
||||
//Sys.print("distribNotif "+hour+" from "+from+" to "+to+"<br/>\n");
|
||||
// Sys.print("distribNotif "+hour+" from "+from+" to "+to+"<br/>\n");
|
||||
|
||||
//on s'arrete immédiatement si aucune distibution trouvée
|
||||
if (distribs.length == 0) return;
|
||||
// on s'arrete immédiatement si aucune distibution trouvée
|
||||
if (distribs.length == 0)
|
||||
return;
|
||||
|
||||
//cherche plus tard si on a pas une "grappe" de distrib
|
||||
// cherche plus tard si on a pas une "grappe" de distrib
|
||||
/*while (true) {
|
||||
var extraDistribs ;
|
||||
if ( db.User.UserFlags.HasEmailNotifOuverture != flag )
|
||||
@@ -155,9 +148,9 @@ class Cron extends Controller
|
||||
}
|
||||
}*/
|
||||
|
||||
//on vérifie dans le cache du jour que ces distrib n'ont pas deja été traitées lors d'un cron précédent
|
||||
var cacheId = Date.now().toString().substr(0, 10)+Std.string(flag);
|
||||
var dist :Array<Int> = sugoi.db.Cache.get(cacheId);
|
||||
// on vérifie dans le cache du jour que ces distrib n'ont pas deja été traitées lors d'un cron précédent
|
||||
var cacheId = Date.now().toString().substr(0, 10) + Std.string(flag);
|
||||
var dist:Array<Int> = sugoi.db.Cache.get(cacheId);
|
||||
if (dist != null) {
|
||||
for (d in Lambda.array(distribs)) {
|
||||
if (Lambda.exists(dist, function(x) return x == d.id)) {
|
||||
@@ -165,37 +158,42 @@ class Cron extends Controller
|
||||
distribs.remove(d);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
dist = [];
|
||||
}
|
||||
|
||||
//toutes les distribs trouvées ont deja été traitées
|
||||
if (distribs.length == 0) return;
|
||||
// toutes les distribs trouvées ont deja été traitées
|
||||
if (distribs.length == 0)
|
||||
return;
|
||||
|
||||
//stocke cache
|
||||
for (d in distribs) dist.push(d.id);
|
||||
// stocke cache
|
||||
for (d in distribs)
|
||||
dist.push(d.id);
|
||||
Cache.set(cacheId, dist, 24 * 60 * 60);
|
||||
|
||||
//We have now the distribs we want to notify about.
|
||||
var distribsByContractId = new Map<Int,db.Distribution>();
|
||||
// We have now the distribs we want to notify about.
|
||||
var distribsByContractId = new Map<Int, db.Distribution>();
|
||||
for (d in distribs) {
|
||||
if (d == null || d.contract==null) continue;
|
||||
if (d == null || d.contract == null)
|
||||
continue;
|
||||
distribsByContractId.set(d.contract.id, d);
|
||||
}
|
||||
|
||||
//Boucle sur les distributions pour gerer le cas de plusieurs distributions le même jour sur le même contrat
|
||||
var orders = [];
|
||||
for (d in distribs) {
|
||||
if (d == null || d.contract==null) continue;
|
||||
//get orders for both type of contracts
|
||||
for ( x in d.contract.getOrders(d)) orders.push(x);
|
||||
// Boucle sur les distributions pour gerer le cas de plusieurs distributions le même jour sur le même contrat
|
||||
var orders = [];
|
||||
for (d in distribs) {
|
||||
if (d == null || d.contract == null)
|
||||
continue;
|
||||
// get orders for both type of contracts
|
||||
for (x in d.contract.getOrders(d))
|
||||
orders.push(x);
|
||||
}
|
||||
|
||||
/*
|
||||
* Group orders by users-group to receive separate emails by groups for the same user.
|
||||
* Map key is $userId-$groupId
|
||||
*/
|
||||
var users = new Map <String,{
|
||||
*/
|
||||
var users = new Map<String, {
|
||||
user:db.User,
|
||||
distrib:db.Distribution,
|
||||
products:Array<db.UserContract>,
|
||||
@@ -203,77 +201,92 @@ class Cron extends Controller
|
||||
}>();
|
||||
|
||||
for (o in orders) {
|
||||
|
||||
var x = users.get(o.user.id+"-"+o.product.contract.amap.id);
|
||||
if (x == null) x = {user:o.user,distrib:null,products:[],vendors:[]};
|
||||
var x = users.get(o.user.id + "-" + o.product.contract.amap.id);
|
||||
if (x == null)
|
||||
x = {
|
||||
user: o.user,
|
||||
distrib: null,
|
||||
products: [],
|
||||
vendors: []
|
||||
};
|
||||
x.distrib = distribsByContractId.get(o.product.contract.id);
|
||||
x.products.push(o);
|
||||
users.set(o.user.id+"-"+o.product.contract.amap.id, x);
|
||||
//trace (o.userId+"-"+o.product.contract.amap.id, x);Sys.print("<br/>\n");
|
||||
users.set(o.user.id + "-" + o.product.contract.amap.id, x);
|
||||
// trace (o.userId+"-"+o.product.contract.amap.id, x);Sys.print("<br/>\n");
|
||||
|
||||
// Prévenir également le deuxième user en cas des commandes alternées
|
||||
if (o.user2 != null) {
|
||||
var x = users.get(o.user2.id+"-"+o.product.contract.amap.id);
|
||||
if (x == null) x = {user:o.user2,distrib:null,products:[],vendors:[]};
|
||||
x.distrib = distribsByContractId.get(o.product.contract.id);
|
||||
x.products.push(o);
|
||||
users.set(o.user2.id+"-"+o.product.contract.amap.id, x);
|
||||
//trace (o.user2.id+"-"+o.product.contract.amap.id, x);Sys.print("<br/>\n");
|
||||
}
|
||||
if (o.user2 != null) {
|
||||
var x = users.get(o.user2.id + "-" + o.product.contract.amap.id);
|
||||
if (x == null)
|
||||
x = {
|
||||
user: o.user2,
|
||||
distrib: null,
|
||||
products: [],
|
||||
vendors: []
|
||||
};
|
||||
x.distrib = distribsByContractId.get(o.product.contract.id);
|
||||
x.products.push(o);
|
||||
users.set(o.user2.id + "-" + o.product.contract.amap.id, x);
|
||||
// trace (o.user2.id+"-"+o.product.contract.amap.id, x);Sys.print("<br/>\n");
|
||||
}
|
||||
}
|
||||
|
||||
//remove zero qt orders
|
||||
for( k in users.keys()){
|
||||
// remove zero qt orders
|
||||
for (k in users.keys()) {
|
||||
var x = users.get(k);
|
||||
var total = 0.0;
|
||||
for( o in x.products) total += o.quantity;
|
||||
if(total==0.0) users.remove(k);
|
||||
for (o in x.products)
|
||||
total += o.quantity;
|
||||
if (total == 0.0)
|
||||
users.remove(k);
|
||||
}
|
||||
|
||||
// Dans le cas de l'ouverture de commande, ce sont tous les users qu'il faut intégrer
|
||||
if ( db.User.UserFlags.HasEmailNotifOuverture == flag )
|
||||
{
|
||||
for (d in distribs) {
|
||||
if (db.User.UserFlags.HasEmailNotifOuverture == flag) {
|
||||
for (d in distribs) {
|
||||
var memberList = d.contract.amap.getMembers();
|
||||
for (u in memberList) {
|
||||
var x = users.get(u.id+"-"+d.contract.amap.id);
|
||||
if (x == null) x = {user:u,distrib:null,products:[],vendors:[]};
|
||||
var x = users.get(u.id + "-" + d.contract.amap.id);
|
||||
if (x == null)
|
||||
x = {
|
||||
user: u,
|
||||
distrib: null,
|
||||
products: [],
|
||||
vendors: []
|
||||
};
|
||||
x.distrib = distribsByContractId.get(d.contract.id);
|
||||
x.vendors.push(d.contract.vendor);
|
||||
users.set(u.id+"-"+d.contract.amap.id, x);
|
||||
//print(u.id+"-"+d.contract.amap.id, x);
|
||||
users.set(u.id + "-" + d.contract.amap.id, x);
|
||||
// print(u.id+"-"+d.contract.amap.id, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ( u in users) {
|
||||
|
||||
if (u.user.flags.has(flag) ) {
|
||||
|
||||
for (u in users) {
|
||||
if (u.user.flags.has(flag)) {
|
||||
if (u.user.email != null) {
|
||||
var group = u.distrib.contract.amap;
|
||||
this.t = sugoi.i18n.Locale.init(u.user.lang); //switch to the user language
|
||||
this.t = sugoi.i18n.Locale.init(u.user.lang); // switch to the user language
|
||||
|
||||
var text;
|
||||
if ( db.User.UserFlags.HasEmailNotifOuverture == flag )
|
||||
{
|
||||
//order opening notif
|
||||
text = t._("Opening of orders for the delivery of <b>::date::</b>", {date:view.hDate(u.distrib.date)});
|
||||
if (db.User.UserFlags.HasEmailNotifOuverture == flag) {
|
||||
// order opening notif
|
||||
text = t._("Opening of orders for the delivery of <b>::date::</b>", {date: view.hDate(u.distrib.date)});
|
||||
text += "<br/>";
|
||||
text += t._("The following suppliers are involved :");
|
||||
text += "<br/><ul>";
|
||||
for ( v in u.vendors) {
|
||||
for (v in u.vendors) {
|
||||
text += "<li>" + v + "</li>";
|
||||
}
|
||||
text += "</ul>";
|
||||
|
||||
}else{
|
||||
//Distribution notif to the users
|
||||
} else {
|
||||
// Distribution notif to the users
|
||||
var d = u.distrib;
|
||||
text = t._("Do not forget the delivery on <b>::day::</b> from ::from:: to ::to::<br/>", {day:view.dDate(d.date),from:view.hHour(d.date),to:view.hHour(d.end)});
|
||||
text = t._("Do not forget the delivery on <b>::day::</b> from ::from:: to ::to::<br/>",
|
||||
{day: view.dDate(d.date), from: view.hHour(d.date), to: view.hHour(d.end)});
|
||||
text += t._("Your products to collect :") + "<br/><ul>";
|
||||
for ( p in u.products) {
|
||||
text += "<li>"+p.quantity+" x "+p.product.getName();
|
||||
for (p in u.products) {
|
||||
text += "<li>" + p.quantity + " x " + p.product.getName();
|
||||
// Gerer le cas des contrats en alternance
|
||||
if (p.user2 != null) {
|
||||
text += " " + t._("alternated with") + " ";
|
||||
@@ -291,36 +304,35 @@ class Cron extends Controller
|
||||
text += t._("<b>Warning: you are in charge of the delivery ! Do not forget to print the attendance sheet.</b>");
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
var m = new Mail();
|
||||
m.setSender(App.config.get("default_email"), "Cagette.net");
|
||||
if(group.contact!=null) m.setReplyTo(group.contact.email, group.name);
|
||||
if (group.contact != null)
|
||||
m.setReplyTo(group.contact.email, group.name);
|
||||
m.addRecipient(u.user.email, u.user.getName());
|
||||
if (u.user.email2 != null) m.addRecipient(u.user.email2);
|
||||
m.setSubject( group.name+" : "+t._("Distribution on ::date::",{date:app.view.hDate(u.distrib.date)}) );
|
||||
m.setHtmlBody( app.processTemplate("mail/message.mtt", { text:text,group:group } ) );
|
||||
App.sendMail(m , u.distrib.contract.amap);
|
||||
}catch (e:Dynamic){
|
||||
app.logError(e); //email could be invalid
|
||||
if (u.user.email2 != null)
|
||||
m.addRecipient(u.user.email2);
|
||||
m.setSubject(group.name + " : " + t._("Distribution on ::date::", {date: app.view.hDate(u.distrib.date)}));
|
||||
m.setHtmlBody(app.processTemplate("mail/message.mtt", {text: text, group: group}));
|
||||
App.sendMail(m, u.distrib.contract.amap);
|
||||
} catch (e:Dynamic) {
|
||||
app.logError(e); // email could be invalid
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if there is a multi-distrib to validate.
|
||||
*
|
||||
* Autovalidate it after 10 days
|
||||
*/
|
||||
function distribValidationNotif(){
|
||||
|
||||
function distribValidationNotif() {
|
||||
var now = Date.now();
|
||||
|
||||
var from = now.setHourMinute( now.getHours(), 0 );
|
||||
var to = now.setHourMinute( now.getHours()+1 , 0);
|
||||
var from = now.setHourMinute(now.getHours(), 0);
|
||||
var to = now.setHourMinute(now.getHours() + 1, 0);
|
||||
|
||||
var explain = t._("<p>This step is important in order to:</p>");
|
||||
explain += t._("<ul><li>Update orders if delivered quantities are different from ordered quantities</li>");
|
||||
@@ -329,12 +341,12 @@ class Cron extends Controller
|
||||
/*
|
||||
* warn administrator if a distribution just ended
|
||||
*/
|
||||
var ds = db.Distribution.manager.search( !$validated && ($end >= from) && ($end < to) , false);
|
||||
var ds = db.Distribution.manager.search(!$validated && ($end >= from) && ($end < to), false);
|
||||
|
||||
for ( d in Lambda.array(ds)){
|
||||
if ( d.contract.type != db.Contract.TYPE_VARORDER ){
|
||||
for (d in Lambda.array(ds)) {
|
||||
if (d.contract.type != db.Contract.TYPE_VARORDER) {
|
||||
ds.remove(d);
|
||||
}else if ( !d.contract.amap.hasPayments() ){
|
||||
} else if (!d.contract.amap.hasPayments()) {
|
||||
ds.remove(d);
|
||||
}
|
||||
}
|
||||
@@ -342,15 +354,16 @@ class Cron extends Controller
|
||||
var ds = tools.ObjectListTool.deduplicateDistribsByKey(ds);
|
||||
var view = App.current.view;
|
||||
|
||||
for ( d in ds ){
|
||||
for (d in ds) {
|
||||
// var subj = "["+d.contract.amap.name+"] " + t._("Validation of the ::date:: distribution",{date:view.hDate(d.date)});
|
||||
var subj = t._("[::group::] Validation of the ::date:: distribution",{group : d.contract.amap.name , date : view.hDate(d.date)});
|
||||
var subj = t._("[::group::] Validation of the ::date:: distribution", {group: d.contract.amap.name, date: view.hDate(d.date)});
|
||||
|
||||
var url = "http://" + App.config.HOST + "/distribution/validate/"+d.date.toString().substr(0,10)+"/"+d.place.id;
|
||||
var url = "http://" + App.config.HOST + "/distribution/validate/" + d.date.toString().substr(0, 10) + "/" + d.place.id;
|
||||
|
||||
var html = t._("<p>Your distribution just finished, don't forget to <b>validate</b> it</p>");
|
||||
html += explain;
|
||||
html += t._("<p><a href='::distriburl::'>Click here to validate the distribution</a> (You must be connected to your group Cagette)", {distriburl:url});
|
||||
html += t._("<p><a href='::distriburl::'>Click here to validate the distribution</a> (You must be connected to your group Cagette)",
|
||||
{distriburl: url});
|
||||
|
||||
App.quickMail(d.contract.amap.contact.email, subj, html);
|
||||
}
|
||||
@@ -359,66 +372,67 @@ class Cron extends Controller
|
||||
* warn administrator if a distribution ended 3 days ago
|
||||
*/
|
||||
|
||||
var from = now.setHourMinute( now.getHours() , 0 ).deltaDays(-3);
|
||||
var to = now.setHourMinute( now.getHours()+1 , 0).deltaDays(-3);
|
||||
var from = now.setHourMinute(now.getHours(), 0).deltaDays(-3);
|
||||
var to = now.setHourMinute(now.getHours() + 1, 0).deltaDays(-3);
|
||||
|
||||
//warn administrator if a distribution just ended
|
||||
var ds = db.Distribution.manager.search( !$validated && ($end >= from) && ($end < to) , false);
|
||||
// warn administrator if a distribution just ended
|
||||
var ds = db.Distribution.manager.search(!$validated && ($end >= from) && ($end < to), false);
|
||||
|
||||
for ( d in Lambda.array(ds)){
|
||||
if ( d.contract.type != db.Contract.TYPE_VARORDER ){
|
||||
for (d in Lambda.array(ds)) {
|
||||
if (d.contract.type != db.Contract.TYPE_VARORDER) {
|
||||
ds.remove(d);
|
||||
}else if ( !d.contract.amap.hasPayments() ){
|
||||
} else if (!d.contract.amap.hasPayments()) {
|
||||
ds.remove(d);
|
||||
}
|
||||
}
|
||||
|
||||
var ds = tools.ObjectListTool.deduplicateDistribsByKey(ds);
|
||||
|
||||
for ( d in ds ){
|
||||
for (d in ds) {
|
||||
// var subj = d.contract.amap.name + t._(": Validation of the delivery of the ") + App.current.view.hDate(d.date);
|
||||
var subj = t._("[::group::] Validation of the ::date:: distribution",{group : d.contract.amap.name , date : view.hDate(d.date)});
|
||||
var subj = t._("[::group::] Validation of the ::date:: distribution", {group: d.contract.amap.name, date: view.hDate(d.date)});
|
||||
|
||||
var url = "http://" + App.config.HOST + "/distribution/validate/"+d.date.toString().substr(0,10)+"/"+d.place.id;
|
||||
var url = "http://" + App.config.HOST + "/distribution/validate/" + d.date.toString().substr(0, 10) + "/" + d.place.id;
|
||||
|
||||
var html = t._("<p>Reminder: you have a delivery to validate.</p>");
|
||||
html += explain;
|
||||
html += t._("<p><a href='::distriburl::'>Click here to validate the delivery</a> (You must be connected to your Cagette group)", {distriburl:url});
|
||||
html += t._("<p><a href='::distriburl::'>Click here to validate the delivery</a> (You must be connected to your Cagette group)",
|
||||
{distriburl: url});
|
||||
|
||||
App.quickMail(d.contract.amap.contact.email, subj, html);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Autovalidate unvalidated distributions after 10 days
|
||||
*/
|
||||
var from = now.setHourMinute( now.getHours() , 0 ).deltaDays( 0 - db.Distribution.DISTRIBUTION_VALIDATION_LIMIT );
|
||||
var to = now.setHourMinute( now.getHours() + 1 , 0).deltaDays( 0 - db.Distribution.DISTRIBUTION_VALIDATION_LIMIT );
|
||||
var from = now.setHourMinute(now.getHours(), 0).deltaDays(0 - db.Distribution.DISTRIBUTION_VALIDATION_LIMIT);
|
||||
var to = now.setHourMinute(now.getHours() + 1, 0).deltaDays(0 - db.Distribution.DISTRIBUTION_VALIDATION_LIMIT);
|
||||
print('AUTOVALIDATION');
|
||||
print('Find distributions from $from to $to');
|
||||
var ds = db.Distribution.manager.search( !$validated && ($end >= from) && ($end < to) , true);
|
||||
for ( d in Lambda.array(ds)){
|
||||
if ( d.contract.type != db.Contract.TYPE_VARORDER ){
|
||||
var ds = db.Distribution.manager.search(!$validated && ($end >= from) && ($end < to), true);
|
||||
for (d in Lambda.array(ds)) {
|
||||
if (d.contract.type != db.Contract.TYPE_VARORDER) {
|
||||
ds.remove(d);
|
||||
}else if ( !d.contract.amap.hasPayments() ){
|
||||
} else if (!d.contract.amap.hasPayments()) {
|
||||
ds.remove(d);
|
||||
}
|
||||
}
|
||||
for ( d in ds){
|
||||
for (d in ds) {
|
||||
print(d.toString());
|
||||
|
||||
service.PaymentService.validateDistribution(d);
|
||||
|
||||
}
|
||||
//email
|
||||
// email
|
||||
var ds = tools.ObjectListTool.deduplicateDistribsByKey(ds);
|
||||
for ( d in ds ){
|
||||
for (d in ds) {
|
||||
// var subj = d.contract.amap.name + t._(": Validation of the distribution of the ") + App.current.view.hDate(d.date);
|
||||
var subj = t._("[::group::] Validation of the ::date:: distribution",{group : d.contract.amap.name , date : view.hDate(d.date)});
|
||||
var html = t._("<p>As you did not validate it manually after 10 days, <br/>the delivery of the ::deliveryDate:: has been validated automatically</p>", {deliveryDate:App.current.view.hDate(d.date)});
|
||||
var subj = t._("[::group::] Validation of the ::date:: distribution", {group: d.contract.amap.name, date: view.hDate(d.date)});
|
||||
var html = t._("<p>As you did not validate it manually after 10 days, <br/>the delivery of the ::deliveryDate:: has been validated automatically</p>",
|
||||
{
|
||||
deliveryDate: App.current.view.hDate(d.date)
|
||||
});
|
||||
App.quickMail(d.contract.amap.contact.email, subj, html);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -428,28 +442,31 @@ class Cron extends Controller
|
||||
* you should consider the right amount of emails to send each minute in order to avoid overlaping and getting in concurrency problems.
|
||||
* (like "SELECT * FROM BufferedMail WHERE sdate IS NULL ORDER BY cdate DESC LIMIT 100 FOR UPDATE Lock wait timeout exceeded; try restarting transaction")
|
||||
*/
|
||||
function sendEmailsfromBuffer(){
|
||||
function sendEmailsfromBuffer() {
|
||||
App.log("Send Emails from Buffer");
|
||||
print("<h3>Send Emails from Buffer</h3>");
|
||||
|
||||
//send
|
||||
for( e in sugoi.db.BufferedMail.manager.search($sdate==null,{limit:50,orderBy:-cdate},false) ){
|
||||
// send
|
||||
for (e in sugoi.db.BufferedMail.manager.search($sdate == null, {limit: 50, orderBy: -cdate}, false)) {
|
||||
e.lock();
|
||||
if(e.isSent()) continue;
|
||||
if (e.isSent())
|
||||
continue;
|
||||
|
||||
App.log('Send Email id=${e.id} - title=${e.title}');
|
||||
print('#${e.id} - ${e.title}');
|
||||
e.finallySend();
|
||||
Sys.sleep(0.1);
|
||||
}
|
||||
|
||||
//delete old emails
|
||||
var threeMonthsAgo = DateTools.delta(Date.now(), -1000.0*60*60*24*30*3);
|
||||
// delete old emails
|
||||
var threeMonthsAgo = DateTools.delta(Date.now(), -1000.0 * 60 * 60 * 24 * 30 * 3);
|
||||
sugoi.db.BufferedMail.manager.delete($cdate < threeMonthsAgo);
|
||||
|
||||
//emails that cannot be sent
|
||||
for( e in sugoi.db.BufferedMail.manager.search($tries>100,{limit:50,orderBy:-cdate},true) ){
|
||||
if(e.sender.email != App.config.get("default_email")){
|
||||
var str = t._("Sorry, the email entitled <b>::title::</b> could not be sent.",{title:e.title});
|
||||
App.quickMail(e.sender.email,t._("Email not sent"),str);
|
||||
// emails that cannot be sent
|
||||
for (e in sugoi.db.BufferedMail.manager.search($tries > 100, {limit: 50, orderBy: -cdate}, true)) {
|
||||
if (e.sender.email != App.config.get("default_email")) {
|
||||
var str = t._("Sorry, the email entitled <b>::title::</b> could not be sent.", {title: e.title});
|
||||
App.quickMail(e.sender.email, t._("Email not sent"), str);
|
||||
}
|
||||
e.delete();
|
||||
}
|
||||
@@ -457,21 +474,18 @@ class Cron extends Controller
|
||||
|
||||
/**
|
||||
* Email product report when orders close
|
||||
**/
|
||||
function sendOrdersByProductWhenOrdersClose(){
|
||||
|
||||
**/
|
||||
function sendOrdersByProductWhenOrdersClose() {
|
||||
var range = tools.DateTool.getLastHourRange();
|
||||
// Sys.println("Time is "+Date.now()+"<br/>");
|
||||
// Sys.println('Find all distributions that have closed in the last hour from ${range.from} to ${range.to} \n<br/>');
|
||||
|
||||
for ( d in db.Distribution.manager.search($orderEndDate >= range.from && $orderEndDate < range.to, false)){
|
||||
for (d in db.Distribution.manager.search($orderEndDate >= range.from && $orderEndDate < range.to, false)) {
|
||||
service.OrderService.sendOrdersByProductReport(d);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function print(text){
|
||||
Sys.println( text + "<br/>" );
|
||||
function print(text) {
|
||||
Sys.println(text + "<br/>");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,17 @@ class Distribution extends Controller
|
||||
|
||||
}
|
||||
|
||||
function getUser(uid:Int):db.User {
|
||||
return db.User.manager.get(uid, false);
|
||||
}
|
||||
|
||||
function getBasket(userId, placeId, date){
|
||||
var user = getUser(userId);
|
||||
var place = db.Place.manager.get(placeId, false);
|
||||
return db.Basket.getOrCreate(user, place, date);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attendance sheet to print ( mutidistrib )
|
||||
*/
|
||||
@@ -174,18 +185,25 @@ class Distribution extends Controller
|
||||
var data = new Array<Dynamic>();
|
||||
|
||||
for (o in orders3) {
|
||||
|
||||
|
||||
var basket = getBasket(o.userId,view.place.id,view.date);
|
||||
|
||||
data.push( {
|
||||
"name":o.userName,
|
||||
"productName":o.productName,
|
||||
"price":view.formatNum(o.productPrice),
|
||||
"quantity":o.quantity,
|
||||
"fees":view.formatNum(o.fees),
|
||||
"total":view.formatNum(o.total),
|
||||
"paid":o.paid
|
||||
"NUM": basket.num,
|
||||
"ADHERENT":o.userName,
|
||||
"PRODUIT":o.productName,
|
||||
"QTÉ":o.quantity,
|
||||
// "price":view.formatNum(o.productPrice),
|
||||
// "fees":view.formatNum(o.fees),
|
||||
// "total":view.formatNum(o.total),
|
||||
// "paid":o.paid
|
||||
});
|
||||
}
|
||||
|
||||
sugoi.tools.Csv.printCsvDataFromObjects(data, ["name", "productName", "price", "quantity","fees","total", "paid"],"Export-commandes-"+date.toString().substr(0,10)+"-Cagette");
|
||||
sugoi.tools.Csv.printCsvDataFromObjects(data, ["NUM","ADHERENT", "PRODUIT", "QTÉ"],"Export-commandes-"+date.toString().substr(0,10)+"-Cagette");
|
||||
//sugoi.tools.Csv.printCsvDataFromObjects(data, ["NUM","ADHERENT", "PRODUIT", "QTÉ","price","fees","total","paid"],"Export-commandes-"+date.toString().substr(0,10)+"-Cagette");
|
||||
//sugoi.tools.Csv.printCsvDataFromObjects(data, ["NUM","ADHERENT", "PRODUIT", "price", "quantity","fees","total", "paid"],"Export-commandes-"+date.toString().substr(0,10)+"-Cagette");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+88
-91
@@ -1,22 +1,20 @@
|
||||
package controller;
|
||||
|
||||
import db.Message;
|
||||
import db.UserContract;
|
||||
import sugoi.form.ListData;
|
||||
import sugoi.form.elements.*;
|
||||
import sugoi.form.Form;
|
||||
|
||||
class Messages extends Controller
|
||||
{
|
||||
|
||||
public function new()
|
||||
{
|
||||
class Messages extends Controller {
|
||||
public function new() {
|
||||
super();
|
||||
if (!app.user.canAccessMessages()) throw Redirect("/");
|
||||
if (!app.user.canAccessMessages())
|
||||
throw Redirect("/");
|
||||
}
|
||||
|
||||
@tpl("messages/default.mtt")
|
||||
function doDefault() {
|
||||
|
||||
var form = new Form("msg");
|
||||
|
||||
var senderName = "";
|
||||
@@ -25,79 +23,87 @@ class Messages extends Controller
|
||||
if (App.current.session.data.whichUser == 1 && app.user.email2 != null) {
|
||||
senderMail = app.user.email2;
|
||||
senderName = app.user.firstName2 + " " + app.user.lastName2;
|
||||
|
||||
}else {
|
||||
} else {
|
||||
senderMail = app.user.email;
|
||||
senderName = app.user.firstName + " " + app.user.lastName;
|
||||
}
|
||||
|
||||
var lists = getLists();
|
||||
form.addElement( new StringInput("senderName", t._("Sender name"),senderName,true));
|
||||
form.addElement( new StringInput("senderMail", t._("Sender E-Mail"),senderMail,true));
|
||||
form.addElement( new StringSelect("list", t._("Recipients"),lists,"1", true,null,"style='width:500px;'"));
|
||||
form.addElement( new StringInput("subject", t._("Subject:"),"",false,null,"style='width:500px;'") );
|
||||
form.addElement( new TextArea("text", t._("Message:"), "", false, null, "style='width:500px;height:350px;'") );
|
||||
form.addElement(new StringInput("senderName", t._("Sender name"), senderName, true));
|
||||
form.addElement(new StringInput("senderMail", t._("Sender E-Mail"), senderMail, true));
|
||||
form.addElement(new StringSelect("list", t._("Recipients"), lists, "1", true, null, "style='width:500px;'"));
|
||||
form.addElement(new StringInput("subject", t._("Subject:"), "", false, null, "style='width:500px;'"));
|
||||
form.addElement(new TextArea("text", t._("Message:"), "", false, null, "style='width:500px;height:350px;'"));
|
||||
|
||||
if (form.checkToken()) {
|
||||
|
||||
var listId = form.getElement("list").value;
|
||||
var dest = getSelection(listId);
|
||||
|
||||
App.log('about to send emails to listId=<$listId> to destination=${dest.length}');
|
||||
|
||||
var mails = [];
|
||||
for ( d in dest) {
|
||||
if (d.email != null) mails.push(d.email);
|
||||
if (d.email2 != null) mails.push(d.email2);
|
||||
for (d in dest) {
|
||||
if (d.email != null)
|
||||
mails.push(d.email);
|
||||
if (d.email2 != null)
|
||||
mails.push(d.email2);
|
||||
}
|
||||
|
||||
//send mail confirmation link
|
||||
// send mail confirmation link
|
||||
var e = new sugoi.mail.Mail();
|
||||
e.setSubject(form.getValueOf("subject"));
|
||||
for ( x in mails) e.addRecipient(x);
|
||||
for (x in mails)
|
||||
e.addRecipient(x);
|
||||
|
||||
e.setSender(App.config.get("default_email"),form.getValueOf("senderName"));
|
||||
e.setReplyTo(form.getValueOf("senderMail"),form.getValueOf("senderName"));
|
||||
//sender : default email ( explicitly tells that the server send an email on behalf of the user )
|
||||
//e.setHeader("Sender", App.config.get("default_email"));
|
||||
var text :String = form.getValueOf("text");
|
||||
var html = app.processTemplate("mail/message.mtt", { text:text,group:app.user.amap,list:getListName(listId) });
|
||||
e.setSender(App.config.get("default_email"), form.getValueOf("senderName"));
|
||||
e.setReplyTo(form.getValueOf("senderMail"), form.getValueOf("senderName"));
|
||||
|
||||
App.log('add CC header to message: ${e.getSubject()}');
|
||||
e.setHeader("CC", "pvincent@comptoirduvrac.re");
|
||||
|
||||
// sender : default email ( explicitly tells that the server send an email on behalf of the user )
|
||||
// e.setHeader("Sender", App.config.get("default_email"));
|
||||
var text:String = form.getValueOf("text");
|
||||
var html = app.processTemplate("mail/message.mtt", {text: text, group: app.user.amap, list: getListName(listId)});
|
||||
e.setHtmlBody(html);
|
||||
|
||||
App.sendMail(e,app.user.getAmap(),listId,app.user);
|
||||
App.sendMail(e, app.user.getAmap(), listId, app.user);
|
||||
|
||||
//store message
|
||||
// store message
|
||||
var lm = new db.Message();
|
||||
lm.amap = app.user.amap;
|
||||
lm.amap = app.user.amap;
|
||||
lm.recipients = Lambda.array(Lambda.map(e.getRecipients(), function(x) return x.email));
|
||||
lm.title = e.getSubject();
|
||||
lm.date = Date.now();
|
||||
lm.body = e.getHtmlBody();
|
||||
if (listId != null) lm.recipientListId = listId;
|
||||
if (listId != null)
|
||||
lm.recipientListId = listId;
|
||||
lm.sender = app.user;
|
||||
lm.insert();
|
||||
|
||||
|
||||
throw Ok("/messages", t._("The message has been sent"));
|
||||
}
|
||||
|
||||
view.form = form;
|
||||
|
||||
if (app.user.isAmapManager()) {
|
||||
view.sentMessages = Message.manager.search($amap == app.user.amap && $recipientListId!=null, {orderBy:-date,limit:20}, false);
|
||||
}else {
|
||||
view.sentMessages = Message.manager.search($sender == app.user && $recipientListId!=null && $amap == app.user.amap , {orderBy:-date,limit:20}, false);
|
||||
view.sentMessages = Message.manager.search($amap == app.user.amap && $recipientListId != null, {orderBy: -date, limit: 20}, false);
|
||||
} else {
|
||||
view.sentMessages = Message.manager.search($sender == app.user && $recipientListId != null && $amap == app.user.amap, {orderBy: -date, limit: 20},
|
||||
false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@tpl("messages/message.mtt")
|
||||
public function doMessage(msg:Message) {
|
||||
|
||||
if (!app.user.isAmapManager() && msg.sender.id != app.user.id) throw Error("/", t._("Non authorized access"));
|
||||
if (!app.user.isAmapManager() && msg.sender.id != app.user.id)
|
||||
throw Error("/", t._("Non authorized access"));
|
||||
|
||||
view.list = getListName(msg.recipientListId);
|
||||
view.msg = msg;
|
||||
|
||||
//make status easier to display
|
||||
var s = new Array<{email:String,success:String,failure:String}>();
|
||||
// make status easier to display
|
||||
var s = new Array<{email:String, success:String, failure:String}>();
|
||||
/*if (msg.status != null){
|
||||
for ( k in msg.status.keys()) {
|
||||
var r = msg.getMailerResultMessage(k);
|
||||
@@ -106,27 +112,25 @@ class Messages extends Controller
|
||||
}*/
|
||||
|
||||
view.status = s;
|
||||
|
||||
}
|
||||
|
||||
function getLists() :FormData<String>{
|
||||
function getLists():FormData<String> {
|
||||
var out = [
|
||||
{value:'1', label: t._("Everyone")},
|
||||
{value:'2', label: t._("The board: persons in charge + contracts + memberships")},
|
||||
{value: '1', label: t._("Everyone")},
|
||||
{value: '2', label: t._("The board: persons in charge + contracts + memberships")},
|
||||
];
|
||||
|
||||
out.push( { value:'3', label: t._("TEST: me + spouse") } );
|
||||
out.push( { value:'4', label: t._("Members without contract/order") } );
|
||||
if(app.user.amap.hasMembership()) out.push( { value:'5', label:t._("Memberships to be renewed")} );
|
||||
out.push({value: '3', label: t._("TEST: me + spouse")});
|
||||
out.push({value: '4', label: t._("Members without contract/order")});
|
||||
if (app.user.amap.hasMembership())
|
||||
out.push({value: '5', label: t._("Memberships to be renewed")});
|
||||
|
||||
|
||||
var contracts = db.Contract.getActiveContracts(app.user.amap,true);
|
||||
for ( c in contracts) {
|
||||
var label = t._("Subscribers") + " " + c.toString();
|
||||
out.push({value:'c'+c.id,label:label});
|
||||
var contracts = db.Contract.getActiveContracts(app.user.amap, true);
|
||||
for (c in contracts) {
|
||||
var label = t._("Subscribers") + " " + c.toString();
|
||||
out.push({value: 'c' + c.id, label: label});
|
||||
}
|
||||
return out ;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,25 +141,24 @@ class Messages extends Controller
|
||||
var l = getLists();
|
||||
|
||||
for (ll in l) {
|
||||
if (ll.value == listId) return ll.label;
|
||||
if (ll.value == listId)
|
||||
return ll.label;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
function getSelection(listId:String) {
|
||||
if (listId.substr(0, 1) == "c") {
|
||||
//contrats
|
||||
// contrats
|
||||
var contract = Std.parseInt(listId.substr(1));
|
||||
|
||||
var pids = db.Product.manager.search($contractId == contract, false);
|
||||
var pids = Lambda.map(pids, function(x) return x.id);
|
||||
var up = db.UserContract.manager.search($productId in pids, false);
|
||||
|
||||
|
||||
var users = [];
|
||||
for ( order in up) {
|
||||
for (order in up) {
|
||||
if (!Lambda.has(users, order.user)) {
|
||||
users.push(order.user);
|
||||
}
|
||||
@@ -164,48 +167,42 @@ class Messages extends Controller
|
||||
}
|
||||
}
|
||||
return users;
|
||||
|
||||
}else {
|
||||
} else {
|
||||
var out = [];
|
||||
switch(listId) {
|
||||
case "1":
|
||||
//tout le monde
|
||||
out = Lambda.array(app.user.amap.getMembers());
|
||||
switch (listId) {
|
||||
case "1":
|
||||
// tout le monde
|
||||
out = Lambda.array(app.user.amap.getMembers());
|
||||
|
||||
case "2":
|
||||
var users = [];
|
||||
users.push(app.user.amap.contact);
|
||||
for ( c in db.Contract.manager.search($amap == app.user.amap)) {
|
||||
if (!Lambda.has(users, c.contact)) {
|
||||
users.push(c.contact);
|
||||
case "2":
|
||||
var users = [];
|
||||
users.push(app.user.amap.contact);
|
||||
for (c in db.Contract.manager.search($amap == app.user.amap)) {
|
||||
if (!Lambda.has(users, c.contact)) {
|
||||
users.push(c.contact);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//ajouter les autres personnes ayant les droits Admin ou Gestion Adhérents ou Gestion Contrats
|
||||
for (ua in Lambda.array(db.UserAmap.manager.search($rights != null && $amap == app.user.amap, false))) {
|
||||
if (ua.hasRight(GroupAdmin) || ua.hasRight(Membership) || ua.hasRight(ContractAdmin())) {
|
||||
if (!Lambda.has(users, ua.user)) users.push(ua.user);
|
||||
}
|
||||
}
|
||||
// ajouter les autres personnes ayant les droits Admin ou Gestion Adhérents ou Gestion Contrats
|
||||
for (ua in Lambda.array(db.UserAmap.manager.search($rights != null && $amap == app.user.amap, false))) {
|
||||
if (ua.hasRight(GroupAdmin) || ua.hasRight(Membership) || ua.hasRight(ContractAdmin())) {
|
||||
if (!Lambda.has(users, ua.user))
|
||||
users.push(ua.user);
|
||||
}
|
||||
}
|
||||
|
||||
out = users;
|
||||
out = users;
|
||||
|
||||
case "3":
|
||||
//moi
|
||||
return [app.user];
|
||||
case "4":
|
||||
return Lambda.array(db.User.getUsers_NoContracts());
|
||||
case "5":
|
||||
return Lambda.array(db.User.getUsers_NoMembership());
|
||||
case "3":
|
||||
// moi
|
||||
return [app.user];
|
||||
case "4":
|
||||
return Lambda.array(db.User.getUsers_NoContracts());
|
||||
case "5":
|
||||
return Lambda.array(db.User.getUsers_NoMembership());
|
||||
}
|
||||
|
||||
return out;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,299 +0,0 @@
|
||||
package test;
|
||||
|
||||
/**
|
||||
* Test distribution creation
|
||||
*
|
||||
* @author web-wizard
|
||||
*/
|
||||
class TestDistributions extends haxe.unit.TestCase
|
||||
{
|
||||
|
||||
public function new(){
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
override function setup(){
|
||||
TestSuite.initDB();
|
||||
TestSuite.initDatas();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that we can add a distribution outside existing time range for a specific contract and place
|
||||
* Check that we can't add a distribution overlapping with existing distribution for a specific contract and place
|
||||
*/
|
||||
function testOverlapping() {
|
||||
var existingDistrib = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE;
|
||||
var e1 = null;
|
||||
try {
|
||||
var distrib1 = service.DistributionService.create(existingDistrib.contract,new Date(2018, 5, 1, 18, 0, 0),new Date(2018, 5, 1, 18, 30, 0),
|
||||
existingDistrib.place.id,null,null,null,null,new Date(2018, 4, 1, 18, 0, 0),new Date(2018, 4, 30, 18, 30, 0));
|
||||
}
|
||||
catch(x:tink.core.Error) {
|
||||
e1 = x;
|
||||
}
|
||||
assertEquals(e1, null);
|
||||
|
||||
//existingDistrib.date <= distrib2.date && existingDistrib.end >= distrib2.date
|
||||
var e2 = null;
|
||||
try {
|
||||
var distrib2 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 5, 1, 19, 30, 0),new Date(2017, 5, 1, 20, 30, 0),
|
||||
existingDistrib.place.id,null,null,null,null,new Date(2017, 4, 1, 18, 0, 0),new Date(2017, 4, 30, 18, 30, 0));
|
||||
}
|
||||
catch(x:tink.core.Error) {
|
||||
e2 = x;
|
||||
}
|
||||
assertEquals(e2.message, "There is already a distribution at this place overlapping with the time range you've selected.");
|
||||
|
||||
//existingDistrib.date <= distrib3.end && existingDistrib.end >= distrib3.end
|
||||
var e3 = null;
|
||||
try{
|
||||
var distrib3 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 5, 1, 17, 30, 0),new Date(2017, 5, 1, 19, 30, 0),
|
||||
existingDistrib.place.id,null,null,null,null,new Date(2017, 4, 1, 18, 0, 0),new Date(2017, 4, 30, 18, 30, 0));
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e3 = x;
|
||||
}
|
||||
assertEquals(e3.message, "There is already a distribution at this place overlapping with the time range you've selected.");
|
||||
|
||||
//existingDistrib.date >= distrib4.date && existingDistrib.end <= distrib4.end
|
||||
var e4 = null;
|
||||
try{
|
||||
var distrib4 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 5, 1, 17, 30, 0),new Date(2017, 5, 1, 21, 30, 0),
|
||||
existingDistrib.place.id,null,null,null,null,new Date(2017, 4, 1, 18, 0, 0),new Date(2017, 4, 30, 18, 30, 0));
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e4 = x;
|
||||
}
|
||||
assertEquals(e4.message, "There is already a distribution at this place overlapping with the time range you've selected.");
|
||||
|
||||
//existingDistrib.date > distrib5.end
|
||||
var e5 = null;
|
||||
try{
|
||||
var distrib5 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 5, 1, 17, 30, 0),new Date(2017, 5, 1, 18, 59, 0),
|
||||
existingDistrib.place.id,null,null,null,null,new Date(2017, 4, 1, 18, 0, 0),new Date(2017, 4, 30, 18, 30, 0));
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e5 = x;
|
||||
}
|
||||
assertEquals(e5, null);
|
||||
|
||||
//existingDistrib.date > distrib6.end
|
||||
var e6 = null;
|
||||
try{
|
||||
var distrib6 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 3, 1, 17, 30, 0),new Date(2017, 3, 1, 18, 59, 0),
|
||||
existingDistrib.place.id,null,null,null,null,new Date(2017, 2, 1, 18, 0, 0),new Date(2017, 3, 30, 18, 30, 0));
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e6 = x;
|
||||
}
|
||||
assertEquals(e6.message, "The distribution start date must be set after the orders end date.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that we can add a distribution outside existing time range for a specific contract and place
|
||||
* Check that we can't add a distribution overlapping with existing distribution for a specific contract and place
|
||||
*/
|
||||
function testEdit() {
|
||||
|
||||
//TO DO
|
||||
assertEquals(true, true);
|
||||
}
|
||||
|
||||
function testCreateCycle() {
|
||||
TestSuite.CONTRAT_LEGUMES.startDate = new Date(2018, 0, 1, 0, 0, 0);
|
||||
TestSuite.CONTRAT_LEGUMES.endDate = new Date(2019, 11, 31, 23, 59, 0);
|
||||
TestSuite.CONTRAT_LEGUMES.update();
|
||||
|
||||
var weeklyDistribCycle = service.DistributionService.createCycle(TestSuite.CONTRAT_LEGUMES,Weekly,new Date(2018, 11, 24, 0, 0, 0),
|
||||
new Date(2019, 0, 24, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2,
|
||||
new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id);
|
||||
|
||||
var weeklyDistribs = Lambda.array(db.Distribution.manager.search($distributionCycle == weeklyDistribCycle, false));
|
||||
assertEquals(weeklyDistribs.length, 5);
|
||||
assertEquals(weeklyDistribs[0].date.toString(), new Date(2018, 11, 24, 13, 0, 0).toString());
|
||||
assertEquals(weeklyDistribs[0].end.toString(), new Date(2018, 11, 24, 14, 0, 0).toString());
|
||||
assertEquals(weeklyDistribs[1].date.toString(), new Date(2018, 11, 31, 13, 0, 0).toString());
|
||||
assertEquals(weeklyDistribs[1].end.toString(), new Date(2018, 11, 31, 14, 0, 0).toString());
|
||||
assertEquals(weeklyDistribs[2].date.toString(), new Date(2019, 0, 7, 13, 0, 0).toString());
|
||||
assertEquals(weeklyDistribs[2].end.toString(), new Date(2019, 0, 7, 14, 0, 0).toString());
|
||||
assertEquals(weeklyDistribs[3].date.toString(), new Date(2019, 0, 14, 13, 0, 0).toString());
|
||||
assertEquals(weeklyDistribs[3].end.toString(), new Date(2019, 0, 14, 14, 0, 0).toString());
|
||||
assertEquals(weeklyDistribs[4].date.toString(), new Date(2019, 0, 21, 13, 0, 0).toString());
|
||||
assertEquals(weeklyDistribs[4].end.toString(), new Date(2019, 0, 21, 14, 0, 0).toString());
|
||||
service.DistributionService.deleteCycleDistribs(weeklyDistribCycle);
|
||||
|
||||
var monthlyDistribCycle = service.DistributionService.createCycle(TestSuite.CONTRAT_LEGUMES,Monthly,new Date(2018, 9, 30, 0, 0, 0),
|
||||
new Date(2019, 2, 31, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2,
|
||||
new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id);
|
||||
|
||||
var monthlyDistribs = Lambda.array(db.Distribution.manager.search($distributionCycle == monthlyDistribCycle, false));
|
||||
assertEquals(monthlyDistribs.length, 6);
|
||||
assertEquals(monthlyDistribs[0].date.toString(), new Date(2018, 9, 30, 13, 0, 0).toString());
|
||||
assertEquals(monthlyDistribs[0].end.toString(), new Date(2018, 9, 30, 14, 0, 0).toString());
|
||||
assertEquals(monthlyDistribs[1].date.toString(), new Date(2018, 10, 27, 13, 0, 0).toString());
|
||||
assertEquals(monthlyDistribs[1].end.toString(), new Date(2018, 10, 27, 14, 0, 0).toString());
|
||||
assertEquals(monthlyDistribs[2].date.toString(), new Date(2018, 11, 25, 13, 0, 0).toString());
|
||||
assertEquals(monthlyDistribs[2].end.toString(), new Date(2018, 11, 25, 14, 0, 0).toString());
|
||||
assertEquals(monthlyDistribs[3].date.toString(), new Date(2019, 0, 29, 13, 0, 0).toString());
|
||||
assertEquals(monthlyDistribs[3].end.toString(), new Date(2019, 0, 29, 14, 0, 0).toString());
|
||||
assertEquals(monthlyDistribs[4].date.toString(), new Date(2019, 1, 26, 13, 0, 0).toString());
|
||||
assertEquals(monthlyDistribs[4].end.toString(), new Date(2019, 1, 26, 14, 0, 0).toString());
|
||||
assertEquals(monthlyDistribs[5].date.toString(), new Date(2019, 2, 26, 13, 0, 0).toString());
|
||||
assertEquals(monthlyDistribs[5].end.toString(), new Date(2019, 2, 26, 14, 0, 0).toString());
|
||||
service.DistributionService.deleteCycleDistribs(monthlyDistribCycle);
|
||||
|
||||
var biweeklyDistribCycle = service.DistributionService.createCycle(TestSuite.CONTRAT_LEGUMES,BiWeekly,new Date(2018, 9, 30, 0, 0, 0),
|
||||
new Date(2019, 0, 31, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2,
|
||||
new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id);
|
||||
|
||||
var biweeklyDistribs = Lambda.array(db.Distribution.manager.search($distributionCycle == biweeklyDistribCycle, false));
|
||||
assertEquals(biweeklyDistribs.length, 7);
|
||||
assertEquals(biweeklyDistribs[0].date.toString(), new Date(2018, 9, 30, 13, 0, 0).toString());
|
||||
assertEquals(biweeklyDistribs[0].end.toString(), new Date(2018, 9, 30, 14, 0, 0).toString());
|
||||
assertEquals(biweeklyDistribs[1].date.toString(), new Date(2018, 10, 13, 13, 0, 0).toString());
|
||||
assertEquals(biweeklyDistribs[1].end.toString(), new Date(2018, 10, 13, 14, 0, 0).toString());
|
||||
assertEquals(biweeklyDistribs[2].date.toString(), new Date(2018, 10, 27, 13, 0, 0).toString());
|
||||
assertEquals(biweeklyDistribs[2].end.toString(), new Date(2018, 10, 27, 14, 0, 0).toString());
|
||||
assertEquals(biweeklyDistribs[3].date.toString(), new Date(2018, 11, 11, 13, 0, 0).toString());
|
||||
assertEquals(biweeklyDistribs[3].end.toString(), new Date(2018, 11, 11, 14, 0, 0).toString());
|
||||
assertEquals(biweeklyDistribs[4].date.toString(), new Date(2018, 11, 25, 13, 0, 0).toString());
|
||||
assertEquals(biweeklyDistribs[4].end.toString(), new Date(2018, 11, 25, 14, 0, 0).toString());
|
||||
assertEquals(biweeklyDistribs[5].date.toString(), new Date(2019, 0, 8, 13, 0, 0).toString());
|
||||
assertEquals(biweeklyDistribs[5].end.toString(), new Date(2019, 0, 8, 14, 0, 0).toString());
|
||||
assertEquals(biweeklyDistribs[6].date.toString(), new Date(2019, 0, 22, 13, 0, 0).toString());
|
||||
assertEquals(biweeklyDistribs[6].end.toString(), new Date(2019, 0, 22, 14, 0, 0).toString());
|
||||
service.DistributionService.deleteCycleDistribs(biweeklyDistribCycle);
|
||||
|
||||
var triweeklyDistribCycle = service.DistributionService.createCycle(TestSuite.CONTRAT_LEGUMES,TriWeekly,new Date(2018, 9, 30, 0, 0, 0),
|
||||
new Date(2019, 0, 31, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2,
|
||||
new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id);
|
||||
|
||||
var triweeklyDistribs = Lambda.array(db.Distribution.manager.search($distributionCycle == triweeklyDistribCycle, false));
|
||||
assertEquals(triweeklyDistribs.length, 5);
|
||||
assertEquals(triweeklyDistribs[0].date.toString(), new Date(2018, 9, 30, 13, 0, 0).toString());
|
||||
assertEquals(triweeklyDistribs[0].end.toString(), new Date(2018, 9, 30, 14, 0, 0).toString());
|
||||
assertEquals(triweeklyDistribs[1].date.toString(), new Date(2018, 10, 20, 13, 0, 0).toString());
|
||||
assertEquals(triweeklyDistribs[1].end.toString(), new Date(2018, 10, 20, 14, 0, 0).toString());
|
||||
assertEquals(triweeklyDistribs[2].date.toString(), new Date(2018, 11, 11, 13, 0, 0).toString());
|
||||
assertEquals(triweeklyDistribs[2].end.toString(), new Date(2018, 11, 11, 14, 0, 0).toString());
|
||||
assertEquals(triweeklyDistribs[3].date.toString(), new Date(2019, 0, 1, 13, 0, 0).toString());
|
||||
assertEquals(triweeklyDistribs[3].end.toString(), new Date(2019, 0, 1, 14, 0, 0).toString());
|
||||
assertEquals(triweeklyDistribs[4].date.toString(), new Date(2019, 0, 22, 13, 0, 0).toString());
|
||||
assertEquals(triweeklyDistribs[4].end.toString(), new Date(2019, 0, 22, 14, 0, 0).toString());
|
||||
service.DistributionService.deleteCycleDistribs(triweeklyDistribCycle);
|
||||
}
|
||||
|
||||
function testDelete() {
|
||||
//A variable contract with a distribution that has orders
|
||||
var ordersDistrib = TestSuite.DISTRIB_LEGUMES_RUE_SAUCISSE;
|
||||
var ordersDistribId = ordersDistrib.id;
|
||||
var chicken = TestSuite.CHICKEN;
|
||||
var order = service.OrderService.make(TestSuite.FRANCOIS, 1, chicken, ordersDistrib.id);
|
||||
|
||||
var e = null;
|
||||
try{
|
||||
service.DistributionService.delete(ordersDistrib);
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e = x;
|
||||
}
|
||||
assertEquals(e.message, "Deletion non possible: some orders are saved for this delivery.");
|
||||
assertTrue(db.Distribution.manager.get(ordersDistribId) != null);
|
||||
|
||||
//A variable contract with a distribution that has no orders
|
||||
var noOrdersDistrib = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE;
|
||||
var noOrdersDistribId = noOrdersDistrib.id;
|
||||
|
||||
var e = null;
|
||||
try{
|
||||
service.DistributionService.delete(noOrdersDistrib);
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e = x;
|
||||
}
|
||||
assertEquals(e, null);
|
||||
assertEquals(db.Distribution.manager.get(noOrdersDistribId), null);
|
||||
|
||||
//An Amap contract with a distribution that has orders
|
||||
var amapDistrib = TestSuite.DISTRIB_CONTRAT_AMAP;
|
||||
var amapDistribId = amapDistrib.id;
|
||||
var panier = TestSuite.PANIER_AMAP_LEGUMES;
|
||||
var amapOrder = service.OrderService.make(TestSuite.FRANCOIS, 1, panier, amapDistrib.id);
|
||||
|
||||
var e = null;
|
||||
try{
|
||||
service.DistributionService.delete(amapDistrib);
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e = x;
|
||||
}
|
||||
assertEquals(e, null);
|
||||
assertEquals(db.Distribution.manager.get(amapDistribId), null);
|
||||
|
||||
}
|
||||
|
||||
function testUpdateAmapContractOperations(){
|
||||
|
||||
var t = sugoi.i18n.Locale.texts;
|
||||
|
||||
//Take an amap contract with payments enabled
|
||||
//Take 2 users and make orders for each
|
||||
var amapDistrib = TestSuite.DISTRIB_CONTRAT_AMAP;
|
||||
var contract = amapDistrib.contract;
|
||||
var panier = TestSuite.PANIER_AMAP_LEGUMES;
|
||||
var francoisOrder = service.OrderService.make(TestSuite.FRANCOIS, 1, panier, amapDistrib.id);
|
||||
db.Operation.onOrderConfirm([francoisOrder]);
|
||||
var sebOrder = service.OrderService.make(TestSuite.SEB, 3, panier, amapDistrib.id);
|
||||
db.Operation.onOrderConfirm([sebOrder]);
|
||||
|
||||
//Check initial operation names and amounts
|
||||
var francoisOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.FRANCOIS);
|
||||
assertEquals(francoisOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 1 deliveries");
|
||||
assertEquals(francoisOperation.amount, -13);
|
||||
var sebOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.SEB);
|
||||
assertEquals(sebOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 1 deliveries");
|
||||
assertEquals(sebOperation.amount, -39);
|
||||
|
||||
//Add a distrib
|
||||
var distrib = null;
|
||||
var e = null;
|
||||
try{
|
||||
distrib = service.DistributionService.create(contract,new Date(2018, 5, 1, 18, 0, 0),new Date(2018, 5, 1, 18, 30, 0),
|
||||
amapDistrib.place.id,null,null,null,null,new Date(2018, 4, 1, 18, 0, 0),new Date(2018, 4, 30, 18, 30, 0));
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e = x;
|
||||
}
|
||||
//Check names and amounts are modified accordingly
|
||||
assertEquals(francoisOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 2 deliveries");
|
||||
assertEquals(francoisOperation.amount, -26);
|
||||
var sebOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.SEB);
|
||||
assertEquals(sebOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 2 deliveries");
|
||||
assertEquals(sebOperation.amount, -78);
|
||||
|
||||
//Add a distrib cycle
|
||||
var weeklyDistribCycle = service.DistributionService.createCycle(contract,Weekly,new Date(2018, 11, 24, 0, 0, 0),
|
||||
new Date(2019, 0, 24, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2,
|
||||
new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id);
|
||||
//Check names and amounts are modified accordingly
|
||||
assertEquals(francoisOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 7 deliveries");
|
||||
assertEquals(francoisOperation.amount, -91);
|
||||
var sebOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.SEB);
|
||||
assertEquals(sebOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 7 deliveries");
|
||||
assertEquals(sebOperation.amount, -273);
|
||||
|
||||
//Delete the distrib cycle
|
||||
service.DistributionService.deleteCycleDistribs(weeklyDistribCycle);
|
||||
//Check names and amounts are modified accordingly
|
||||
assertEquals(francoisOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 2 deliveries");
|
||||
assertEquals(francoisOperation.amount, -26);
|
||||
var sebOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.SEB);
|
||||
assertEquals(sebOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 2 deliveries");
|
||||
assertEquals(sebOperation.amount, -78);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,473 +0,0 @@
|
||||
package test;
|
||||
import Common;
|
||||
import service.OrderService;
|
||||
/**
|
||||
* Test order making, updating and deleting
|
||||
*
|
||||
* @author fbarbut
|
||||
*/
|
||||
class TestOrders extends haxe.unit.TestCase
|
||||
{
|
||||
|
||||
public function new(){
|
||||
super();
|
||||
}
|
||||
|
||||
var c : db.Contract;
|
||||
var p : db.Product;
|
||||
var bob : db.User;
|
||||
|
||||
/**
|
||||
* get a contract + a user + a product + empty orders
|
||||
*/
|
||||
override function setup(){
|
||||
|
||||
TestSuite.initDB();
|
||||
TestSuite.initDatas();
|
||||
|
||||
db.Basket.emptyCache();
|
||||
|
||||
c = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.contract;
|
||||
|
||||
p = TestSuite.STRAWBERRIES;
|
||||
p.lock();
|
||||
p.stock = 8;
|
||||
p.update();
|
||||
|
||||
bob = db.User.manager.get(1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Test Basket creation and numbering
|
||||
**/
|
||||
public function testBasket(){
|
||||
|
||||
var d = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE;
|
||||
|
||||
var o = OrderService.make(TestSuite.FRANCOIS, 3, TestSuite.STRAWBERRIES, d.id);
|
||||
assertEquals(1, o.basket.num);
|
||||
|
||||
var o = OrderService.make(TestSuite.SEB, 1, TestSuite.STRAWBERRIES, d.id);
|
||||
assertEquals(2, o.basket.num);
|
||||
|
||||
//order again, should keep existing basket number
|
||||
var o = OrderService.make(TestSuite.FRANCOIS, 1, TestSuite.APPLES, d.id);
|
||||
assertEquals(1, o.basket.num);
|
||||
|
||||
//check bug of 2018-07 : changing the date and place of the distribution leads to lost basket (because basket were indexed on user-date-place)
|
||||
d.lock();
|
||||
d.date = new Date(2028,1,1,0,0,0);
|
||||
|
||||
var place = new db.Place();
|
||||
place.name = "Chez Momo";
|
||||
place.zipCode = "54";
|
||||
place.amap = d.contract.amap;
|
||||
place.insert();
|
||||
|
||||
d.place = place;
|
||||
d.update();
|
||||
|
||||
//Seb's basket is still 2
|
||||
var basket = db.Basket.get(TestSuite.SEB,place,d.date);
|
||||
assertEquals(2, basket.num);
|
||||
|
||||
var o = OrderService.make(TestSuite.SEB, 1, TestSuite.APPLES, d.id);
|
||||
assertEquals(2, o.basket.num);
|
||||
|
||||
var o2 = OrderService.edit(o,5,true,null,false);
|
||||
assertEquals(2, o2.basket.num);
|
||||
|
||||
//order to a different distrib in same contract should start a new numbering
|
||||
var d2 = service.DistributionService.create(d.contract,new Date(2026,6,6,0,0,0),new Date(2026,6,6,1,0,0),place.id,null,null,null,null,new Date(2026,6,4,0,0,0),new Date(2026,6,5,0,0,0));
|
||||
var o = OrderService.make(TestSuite.SEB, 12, TestSuite.APPLES, d2.id);
|
||||
assertEquals(1, o.basket.num);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* make orders & stock management
|
||||
*/
|
||||
public function testStocks(){
|
||||
|
||||
var stock = p.stock;
|
||||
|
||||
assertTrue(c.type == db.Contract.TYPE_VARORDER);
|
||||
assertTrue(c.flags.has(db.Contract.ContractFlags.StockManagement));
|
||||
assertTrue(stock == 8);
|
||||
|
||||
//bob orders 3 strawberries, stock fall to 2
|
||||
//order is update to 6 berries
|
||||
App.current.eventDispatcher.addOnce(function(e:Event){
|
||||
switch(e){
|
||||
case StockMove(e):
|
||||
assertTrue(e.move==-3);
|
||||
assertTrue(e.product==p);
|
||||
default:
|
||||
}
|
||||
});
|
||||
var o = OrderService.make(bob, 3, p, TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.id);
|
||||
assertTrue(p.stock == 5);
|
||||
assertTrue(o.quantity == 3);
|
||||
|
||||
//bob orders 6 more. stock fall to 0, order is reduced to 5
|
||||
//quantity is not 9 but 8
|
||||
App.current.eventDispatcher.addOnce(function(e:Event){
|
||||
switch(e){
|
||||
case StockMove(e):
|
||||
assertTrue(e.move==-5);
|
||||
assertTrue(e.product==p);
|
||||
default:
|
||||
}
|
||||
});
|
||||
var o = OrderService.make(bob, 6, p, TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.id);
|
||||
assertTrue(p.stock == 0);
|
||||
assertTrue(o.quantity == 8);
|
||||
|
||||
//bob orders again but cant order anything
|
||||
var o = OrderService.make(bob, 3, p, TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.id);
|
||||
assertTrue(p.stock == 0);
|
||||
assertTrue(o.quantity == 8);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* test edit orders and stock management
|
||||
*/
|
||||
function testOrderEdit(){
|
||||
|
||||
var o = db.UserContract.manager.select( $user == bob && $product == p, true);
|
||||
|
||||
//no order, stock at 8
|
||||
assertEquals(p.stock , 8);
|
||||
assertEquals(o , null);
|
||||
|
||||
//bob orders 3 strawberries
|
||||
var o = OrderService.make(bob, 3, p , TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.id);
|
||||
assertEquals(o.product.name, p.name);
|
||||
assertEquals(o.quantity, 3);
|
||||
assertEquals(p.stock , 5);
|
||||
|
||||
//order edit, order 6 berries
|
||||
App.current.eventDispatcher.addOnce(function(e:Event){
|
||||
switch(e){
|
||||
case StockMove(e):
|
||||
assertTrue(e.move==-3);
|
||||
assertTrue(e.product==p);
|
||||
default:
|
||||
}
|
||||
});
|
||||
var o = OrderService.edit(o, 6);
|
||||
assertTrue(p.stock == 2);
|
||||
assertTrue(o.quantity == 6);
|
||||
|
||||
//order edit, order 9 berries. ( 3 more, but stock fall to 0, reduced to 2 )
|
||||
App.current.eventDispatcher.addOnce(function(e:Event){
|
||||
switch(e){
|
||||
case StockMove(e):
|
||||
assertEquals( -2.0 , e.move );
|
||||
assertEquals( p , e.product);
|
||||
default:
|
||||
}
|
||||
});
|
||||
var o = OrderService.edit(o, 9);
|
||||
assertEquals(0.0 , p.stock);
|
||||
assertEquals(8.0 , o.quantity);
|
||||
|
||||
//order more, but stock at 0
|
||||
var o = OrderService.edit(o, 12);
|
||||
assertEquals(0.0 , p.stock);
|
||||
assertEquals(8.0 , o.quantity);
|
||||
|
||||
//order less
|
||||
var o = OrderService.edit(o, 6);
|
||||
assertEquals(2.0 , p.stock);
|
||||
assertEquals(6.0 , o.quantity);
|
||||
|
||||
|
||||
//floatQt : ordering float quantities should throw an exception
|
||||
var err = null;
|
||||
try{
|
||||
var o = OrderService.edit(o, 6.4);
|
||||
}catch(e:tink.core.Error){
|
||||
err = e.message;
|
||||
}
|
||||
assertTrue( err!=null );
|
||||
}
|
||||
|
||||
/**
|
||||
* test orders with multiweight product
|
||||
*/
|
||||
function testOrderWithMultiWeightProduct(){
|
||||
|
||||
var chicken = TestSuite.CHICKEN;
|
||||
var distrib = db.Distribution.manager.select($contract == chicken.contract, false);
|
||||
|
||||
var order = OrderService.make(bob, 1, chicken, distrib.id);
|
||||
assertEquals(1.0, order.quantity);
|
||||
assertEquals(chicken.id, order.product.id);
|
||||
assertEquals(chicken.price, order.productPrice);
|
||||
|
||||
//order 2 more, should not aggregate because multiWeight is true
|
||||
var order2 = OrderService.make(bob, 2, chicken, distrib.id);
|
||||
|
||||
assertTrue(order2.id != order.id);
|
||||
|
||||
//we should get 3 different orders
|
||||
var orders = distrib.getOrders();
|
||||
|
||||
//trace(OrderService.prepare(orders));
|
||||
|
||||
assertEquals(3, orders.length);
|
||||
for ( o in orders){
|
||||
assertEquals(o.user.id, bob.id);
|
||||
assertEquals(o.product.id, chicken.id);
|
||||
assertEquals(1.0, o.quantity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @author fbarbut
|
||||
* @date 2018-01-26
|
||||
* order a product, edit and set qt to zero, order again.
|
||||
* the same record should be re-used ( if not multiweight )
|
||||
*/
|
||||
function testMakeOrderAndZeroQuantity(){
|
||||
var fraises = TestSuite.STRAWBERRIES;
|
||||
var distrib = db.Distribution.manager.select($contract == fraises.contract, false);
|
||||
|
||||
var order = OrderService.make(bob, 1, fraises, distrib.id);
|
||||
|
||||
order = OrderService.edit(order, 0);
|
||||
|
||||
assertEquals(0.0, order.quantity);
|
||||
|
||||
var order2 = OrderService.make(bob, 1, fraises, distrib.id);
|
||||
|
||||
var bobOrders = [];
|
||||
for ( o in distrib.getOrders()) if (o.user.id == bob.id) bobOrders.push(o);
|
||||
|
||||
assertFalse(fraises.multiWeight);
|
||||
assertEquals(1, bobOrders.length);
|
||||
assertEquals(1.0, bobOrders[0].quantity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test order deletion and operation deletion in various contexts
|
||||
@author jbarbic
|
||||
*/
|
||||
function testDelete(){
|
||||
|
||||
var t = sugoi.i18n.Locale.texts;
|
||||
|
||||
//[Test case] Should throw an error when trying to delete order and that the quantity is not zero
|
||||
var amapDistrib = TestSuite.DISTRIB_CONTRAT_AMAP;
|
||||
var amapContract = amapDistrib.contract;
|
||||
var order = OrderService.make(TestSuite.FRANCOIS, 1, TestSuite.PANIER_AMAP_LEGUMES, amapDistrib.id);
|
||||
var orderId = order.id;
|
||||
db.Operation.onOrderConfirm([order]);
|
||||
var e1 = null;
|
||||
try {
|
||||
service.OrderService.delete(order);
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e1 = x;
|
||||
}
|
||||
assertEquals(e1.message, "Deletion not possible: quantity is not zero.");
|
||||
assertTrue(db.UserContract.manager.get(orderId) != null);
|
||||
|
||||
//[Test case] Amap contract and quantity zero with payments disabled
|
||||
//Check that order is deleted
|
||||
order = OrderService.edit(order, 0);
|
||||
var e2 = null;
|
||||
try {
|
||||
OrderService.delete(order);
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e2 = x;
|
||||
}
|
||||
assertEquals(e2, null);
|
||||
assertEquals(db.UserContract.manager.get(orderId), null);
|
||||
|
||||
//[Test case] Amap contract and quantity zero with payments enabled and 2 orders
|
||||
//Check that first order is deleted but operation amount is at 0
|
||||
//Check that operation is deleted only at the second order deletion
|
||||
var order1 = OrderService.make(TestSuite.FRANCOIS, 1, TestSuite.PANIER_AMAP_LEGUMES, amapDistrib.id);
|
||||
db.Operation.onOrderConfirm([order1]);
|
||||
var order1Id = order1.id;
|
||||
order1 = OrderService.edit(order1, 0);
|
||||
db.Operation.onOrderConfirm([order1]);
|
||||
var order2 = OrderService.make(TestSuite.FRANCOIS, 1, TestSuite.PANIER_AMAP_LEGUMES, amapDistrib.id);
|
||||
db.Operation.onOrderConfirm([order2]);
|
||||
var order2Id = order2.id;
|
||||
order2 = OrderService.edit(order2, 0);
|
||||
db.Operation.onOrderConfirm([order2]);
|
||||
var operation = db.Operation.findCOrderTransactionFor(amapContract, TestSuite.FRANCOIS);
|
||||
var operationId = operation.id;
|
||||
var e3 = null;
|
||||
try {
|
||||
service.OrderService.delete(order1);
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e3 = x;
|
||||
}
|
||||
assertEquals(e3, null);
|
||||
assertEquals(db.UserContract.manager.get(order1Id), null);
|
||||
assertTrue(db.Operation.manager.get(operationId) != null);
|
||||
assertEquals(operation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 1 deliveries");
|
||||
assertEquals(operation.amount, 0);
|
||||
var e4 = null;
|
||||
try {
|
||||
service.OrderService.delete(order2);
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e4 = x;
|
||||
}
|
||||
assertEquals(null, e4);
|
||||
assertEquals(null, db.UserContract.manager.get(order2Id));
|
||||
assertEquals(null, db.Operation.manager.get(operationId));
|
||||
|
||||
//[Test case] Var Order contract and quantity zero with payments disabled
|
||||
//Check that order is deleted
|
||||
var variableDistrib = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE;
|
||||
|
||||
var g = variableDistrib.contract.amap;
|
||||
g.lock();
|
||||
g.flags.unset(HasPayments);
|
||||
g.update();
|
||||
|
||||
var order = OrderService.make(TestSuite.FRANCOIS, 2, TestSuite.STRAWBERRIES, variableDistrib.id);
|
||||
var orderId = order.id;
|
||||
db.Operation.onOrderConfirm([order]);
|
||||
order = OrderService.edit(order, 0);
|
||||
db.Operation.onOrderConfirm([order]);
|
||||
var e1 = null;
|
||||
try {
|
||||
service.OrderService.delete(order);
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e1 = x;
|
||||
}
|
||||
assertEquals(false,variableDistrib.contract.amap.hasPayments() );
|
||||
assertEquals(null, e1);
|
||||
assertEquals(null, db.UserContract.manager.get(orderId));
|
||||
|
||||
//[Test case] Var Order contract and quantity zero with payments enabled and 2 orders
|
||||
//Check that first order is deleted
|
||||
//Check that operation is deleted only at the second order deletion
|
||||
variableDistrib = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE;
|
||||
var variableContract = variableDistrib.contract;
|
||||
var g = variableDistrib.contract.amap;
|
||||
g.lock();
|
||||
g.flags.set(HasPayments);
|
||||
g.update();
|
||||
assertTrue(variableContract.amap.hasPayments());
|
||||
|
||||
var order1 = OrderService.make(TestSuite.FRANCOIS, 2, TestSuite.STRAWBERRIES, variableDistrib.id);
|
||||
db.Operation.onOrderConfirm([order1]);
|
||||
var order1Id = order1.id;
|
||||
|
||||
var order2 = OrderService.make(TestSuite.FRANCOIS, 3, TestSuite.APPLES, variableDistrib.id);
|
||||
db.Operation.onOrderConfirm([order2]);
|
||||
var order2Id = order2.id;
|
||||
|
||||
order1 = OrderService.edit(order1, 0);
|
||||
db.Operation.onOrderConfirm([order1]);
|
||||
|
||||
order2 = OrderService.edit(order2, 0);
|
||||
db.Operation.onOrderConfirm([order2]);
|
||||
|
||||
assertEquals(2, variableContract.getUserOrders(TestSuite.FRANCOIS,variableDistrib).length); //François has 2 orders
|
||||
var basket = db.Basket.get(TestSuite.FRANCOIS,variableDistrib.place,variableDistrib.date);
|
||||
assertEquals(2, basket.getOrders().length);
|
||||
|
||||
var operation1 = db.Operation.findVOrderTransactionFor(order1.distribution.getKey(), TestSuite.FRANCOIS, variableContract.amap);
|
||||
var operation1Id = operation1.id;
|
||||
var operation2 = db.Operation.findVOrderTransactionFor(order2.distribution.getKey(), TestSuite.FRANCOIS, variableContract.amap);
|
||||
var operation2Id = operation2.id;
|
||||
assertEquals(operation1Id,operation2Id);
|
||||
var e2 = null;
|
||||
try {
|
||||
//delete strawberries order
|
||||
service.OrderService.delete(order1);
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e2 = x;
|
||||
}
|
||||
assertEquals(null, e2);
|
||||
assertEquals(null, db.UserContract.manager.get(order1Id) ); //order 1 is deleted
|
||||
assertTrue( db.Operation.manager.get(operation1Id) != null); //operation should be here
|
||||
assertEquals(0.0,operation1.amount);
|
||||
assertEquals(1 , basket.getOrders().length);
|
||||
var e3 = null;
|
||||
try {
|
||||
//delete apple order
|
||||
service.OrderService.delete(order2);
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e3 = x;
|
||||
}
|
||||
assertEquals(null, e3);
|
||||
assertEquals(null, db.UserContract.manager.get(order2Id)); //order 2 is deleted
|
||||
assertEquals(null, db.Operation.manager.get(operation1Id)); //operation should be deleted
|
||||
assertEquals(0 , basket.getOrders().length);
|
||||
|
||||
//[Test case] 2 VarOrderContracts and quantity zero with payments enabled and 1 order each
|
||||
//Check that first order is deleted but operation amount is at 0
|
||||
//Check that operation is deleted only at the second order deletion
|
||||
var variableDistrib1 = TestSuite.DISTRIB_LEGUMES_RUE_SAUCISSE;
|
||||
var order1 = OrderService.make(TestSuite.FRANCOIS, 2, TestSuite.COURGETTES, variableDistrib1.id);
|
||||
assertTrue(order1.basket!=null);
|
||||
// trace("WE GOT A BASKET "+order1.basket.id);
|
||||
// trace("... THEN RE-GET BASKET user "+TestSuite.FRANCOIS.id+" place "+variableDistrib1.place.id+" date "+variableDistrib1.date);
|
||||
var basket = db.Basket.get(TestSuite.FRANCOIS,variableDistrib1.place,variableDistrib1.date);
|
||||
assertTrue(basket!=null);
|
||||
assertEquals(1, basket.getOrders().length);
|
||||
db.Operation.onOrderConfirm([order1]);
|
||||
var order1Id = order1.id;
|
||||
|
||||
var variableDistrib2 = TestSuite.DISTRIB_PATISSERIES;
|
||||
var order2 = OrderService.make(TestSuite.FRANCOIS, 3, TestSuite.FLAN, variableDistrib2.id);
|
||||
db.Operation.onOrderConfirm([order2]);
|
||||
var order2Id = order2.id;
|
||||
|
||||
order1 = OrderService.edit(order1, 0);
|
||||
db.Operation.onOrderConfirm([order1]);
|
||||
|
||||
order2 = OrderService.edit(order2, 0);
|
||||
db.Operation.onOrderConfirm([order2]);
|
||||
|
||||
//check basket
|
||||
var basket = db.Basket.get(TestSuite.FRANCOIS,variableDistrib1.place,variableDistrib1.date);
|
||||
assertEquals(2, basket.getOrders().length);
|
||||
|
||||
var operation = db.Operation.findVOrderTransactionFor(order1.distribution.getKey(), TestSuite.FRANCOIS, variableDistrib1.contract.amap);
|
||||
var operationId = operation.id;
|
||||
|
||||
|
||||
var e4 = null;
|
||||
try {
|
||||
service.OrderService.delete(order1);
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e4 = x;
|
||||
}
|
||||
assertEquals(e4, null);
|
||||
assertEquals(db.UserContract.manager.get(order1Id), null);
|
||||
assertTrue(db.Operation.manager.get(operationId) != null); //op should still be here
|
||||
assertEquals(0.0,operation.amount);//...with amount 0
|
||||
|
||||
var e5 = null;
|
||||
try {
|
||||
service.OrderService.delete(order2);
|
||||
}
|
||||
catch(x:tink.core.Error){
|
||||
e5 = x;
|
||||
}
|
||||
assertEquals(e5, null);
|
||||
assertEquals(db.UserContract.manager.get(order2Id), null);
|
||||
assertEquals(null, db.Operation.manager.get(operationId), null); //op should have been deleted
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package test;
|
||||
|
||||
/**
|
||||
* Test payments
|
||||
*
|
||||
* @author web-wizard
|
||||
*/
|
||||
class TestPayments extends haxe.unit.TestCase
|
||||
{
|
||||
|
||||
public function new(){
|
||||
super();
|
||||
}
|
||||
|
||||
override function setup(){
|
||||
TestSuite.initDB();
|
||||
TestSuite.initDatas();
|
||||
db.Basket.emptyCache();
|
||||
}
|
||||
|
||||
function testValidateDistribution() {
|
||||
|
||||
//Take a contract with payments enabled
|
||||
//Take 2 users and make orders for each
|
||||
var distrib = TestSuite.DISTRIB_LEGUMES_RUE_SAUCISSE;
|
||||
var contract = distrib.contract;
|
||||
var product = TestSuite.COURGETTES;
|
||||
var francoisOrder = service.OrderService.make(TestSuite.FRANCOIS, 1, product, distrib.id);
|
||||
var francoisOrderOperation = db.Operation.onOrderConfirm([francoisOrder]);
|
||||
var sebOrder = service.OrderService.make(TestSuite.SEB, 3, product, distrib.id);
|
||||
var sebOrderOperation = db.Operation.onOrderConfirm([sebOrder]);
|
||||
//They both pay by check
|
||||
var francoisPayment = db.Operation.makePaymentOperation(TestSuite.FRANCOIS,contract.amap, payment.Check.TYPE, product.price, "Payment by check", francoisOrderOperation[0]);
|
||||
var sebPayment = db.Operation.makePaymentOperation(TestSuite.SEB,contract.amap, payment.Check.TYPE, 3 * product.price, "Payment by check", sebOrderOperation[0] );
|
||||
|
||||
//Autovalidate this old distrib and check that all the payments are validated
|
||||
service.PaymentService.validateDistribution(distrib);
|
||||
|
||||
//distrib should be validated
|
||||
assertTrue(contract.amap.hasPayments());
|
||||
assertEquals(true, distrib.validated);
|
||||
|
||||
//orders should be marked as paid
|
||||
assertEquals(true, francoisOrder.paid);
|
||||
assertEquals(true, sebOrder.paid);
|
||||
|
||||
//order operation is not pending
|
||||
var francoisOperation = db.Operation.findVOrderTransactionFor(francoisOrder.distribution.getKey(), TestSuite.FRANCOIS, contract.amap, false);
|
||||
var sebOperation = db.Operation.findVOrderTransactionFor(sebOrder.distribution.getKey(), TestSuite.SEB, contract.amap, false);
|
||||
assertEquals(francoisOperation.pending, false);
|
||||
assertEquals(sebOperation.pending, false);
|
||||
|
||||
//payment operation is not pending
|
||||
assertEquals(francoisPayment.pending, false);
|
||||
assertEquals(sebPayment.pending, false);
|
||||
|
||||
//basket are validated
|
||||
var b = db.Basket.get(TestSuite.SEB,distrib.place,distrib.date);
|
||||
assertEquals(true, b.isValidated());
|
||||
var b = db.Basket.get(TestSuite.FRANCOIS,distrib.place,distrib.date);
|
||||
assertEquals(true, b.isValidated());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
package test;
|
||||
import Common;
|
||||
import test.TestSuite;
|
||||
import service.ReportService;
|
||||
import service.OrderService;
|
||||
|
||||
/**
|
||||
* Test order reports
|
||||
*
|
||||
* @author fbarbut
|
||||
*/
|
||||
class TestReports extends haxe.unit.TestCase
|
||||
{
|
||||
|
||||
public function new(){
|
||||
|
||||
super();
|
||||
}
|
||||
|
||||
override function setup(){
|
||||
|
||||
TestSuite.initDB();
|
||||
TestSuite.initDatas();
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testOrdersByProduct(){
|
||||
|
||||
//record orders
|
||||
var seb = TestSuite.SEB;
|
||||
var francois = TestSuite.FRANCOIS;
|
||||
var julie = TestSuite.JULIE;
|
||||
|
||||
//distrib de légumes
|
||||
var d = TestSuite.DISTRIB_LEGUMES_RUE_SAUCISSE;
|
||||
var carrots = TestSuite.CARROTS;
|
||||
var courgettes = TestSuite.COURGETTES;
|
||||
var poulet = TestSuite.CHICKEN;
|
||||
|
||||
OrderService.make(seb,4,courgettes,d.id);
|
||||
OrderService.make(seb,1,poulet,d.id);
|
||||
|
||||
OrderService.make(francois,6,courgettes,d.id);
|
||||
OrderService.make(francois,2,poulet,d.id);
|
||||
OrderService.make(francois,3,carrots,d.id);
|
||||
|
||||
OrderService.make(julie,8,carrots,d.id);
|
||||
OrderService.make(julie,3,poulet,d.id);
|
||||
|
||||
//record orders on ANOTHER distrib
|
||||
var d2 = service.DistributionService.create(
|
||||
d.contract,
|
||||
new Date(2018,2,12,0,0,0),
|
||||
new Date(2018,2,12,0,3,0),
|
||||
d.contract.amap.getPlaces().first().id,
|
||||
null,null,null,null,
|
||||
new Date(2018,2,8,0,0,0),
|
||||
new Date(2018,2,11,0,0,0)
|
||||
);
|
||||
OrderService.make(julie,6,carrots,d2.id);
|
||||
OrderService.make(julie,1,poulet,d2.id);
|
||||
|
||||
var orders = ReportService.getOrdersByProduct(d);
|
||||
|
||||
//courgettes x 10
|
||||
var courgettesOrder = Lambda.find(orders, function(o) return o.pid==courgettes.id);
|
||||
assertEquals( 10.0 , courgettesOrder.quantity );
|
||||
assertEquals( 35.0 , courgettesOrder.totalTTC );
|
||||
assertEquals( 33.18 , tools.FloatTool.clean(courgettesOrder.totalHT) );
|
||||
|
||||
//the report stays the same, even if the product has a new price.
|
||||
courgettes.lock();
|
||||
courgettes.price+=4;
|
||||
courgettes.update();
|
||||
var orders = ReportService.getOrdersByProduct(d);
|
||||
var courgettesOrder = Lambda.find(orders, function(o) return o.pid==courgettes.id);
|
||||
assertEquals( 10.0 , courgettesOrder.quantity );
|
||||
assertEquals( 35.0 , courgettesOrder.totalTTC );
|
||||
assertEquals( 33.18 , tools.FloatTool.clean(courgettesOrder.totalHT) );
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* run once at the beginning
|
||||
*/
|
||||
/*override function setup(){
|
||||
|
||||
sys.db.Manager.cnx.request("TRUNCATE TABLE UserContract;");
|
||||
|
||||
var bubar = db.User.manager.get(1);
|
||||
var seb = db.User.manager.get(2);
|
||||
|
||||
//fruits from group 1
|
||||
var fraises = db.Product.manager.get(2);
|
||||
fraises.stock = 30;
|
||||
var pommes = db.Product.manager.get(3);
|
||||
var distrib = fraises.contract.getDistribs().first();
|
||||
|
||||
db.UserContract.make(bubar, 4, fraises, distrib.id);
|
||||
db.UserContract.make(seb, 2, pommes, distrib.id);
|
||||
|
||||
//vegetables from group 2
|
||||
var courgettes = db.Product.manager.get(4);
|
||||
var carottes = db.Product.manager.get(5);
|
||||
var distrib = courgettes.contract.getDistribs().first();
|
||||
|
||||
db.UserContract.make(bubar, 1, carottes ,distrib.id);
|
||||
db.UserContract.make(seb, 5, courgettes ,distrib.id);
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* test a simple report with just a time frame
|
||||
*/
|
||||
/*public function testTimeFrameReport(){
|
||||
|
||||
var fraises = db.Product.manager.get(2);
|
||||
var pommes = db.Product.manager.get(3);
|
||||
var courgettes = db.Product.manager.get(4);
|
||||
var carottes = db.Product.manager.get(5);
|
||||
|
||||
//check we got the right products
|
||||
assertEquals("Fraises",fraises.name);
|
||||
assertEquals("Pommes",pommes.name);
|
||||
assertEquals("Courgettes",courgettes.name);
|
||||
assertEquals("Carottes", carottes.name);
|
||||
|
||||
var options = { startDate:new Date(2017, 5, 1, 0, 0, 0), endDate:new Date(2017, 5, 31, 0, 0, 0), groups:[], contracts:[] };
|
||||
|
||||
var rep = new pro.OrderReport(options);
|
||||
|
||||
var data = rep.byProduct();
|
||||
|
||||
assertEquals(4,data.length); //should be the 4 products
|
||||
|
||||
for ( d in data){
|
||||
switch(d.pname){
|
||||
case "Fraises": assertEquals(d.qt, 4);
|
||||
case "Pommes": assertEquals(d.qt, 2);
|
||||
case "Carottes": assertEquals(d.qt, 1);
|
||||
case "Courgettes": assertEquals(d.qt, 5);
|
||||
}
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* test a report with time frame + group
|
||||
*/
|
||||
/*public function testGroupReport(){
|
||||
|
||||
var options = { startDate:new Date(2017, 5, 1, 0, 0, 0), endDate:new Date(2017, 5, 31, 0, 0, 0), groups:[1], contracts:[] };
|
||||
|
||||
var rep = new pro.OrderReport(options);
|
||||
var data = rep.byProduct();
|
||||
assertEquals(2,data.length); //should be the 2 products
|
||||
|
||||
for ( d in data){
|
||||
switch(d.pname){
|
||||
case "Fraises": assertEquals(d.qt, 4);
|
||||
case "Pommes": assertEquals(d.qt, 2);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,413 +0,0 @@
|
||||
package test;
|
||||
import Common;
|
||||
/**
|
||||
* CAGETTE.NET TEST SUITE
|
||||
* @author fbarbut
|
||||
*/
|
||||
class TestSuite
|
||||
{
|
||||
|
||||
static function main() {
|
||||
|
||||
connectDb();
|
||||
var r = new haxe.unit.TestRunner();
|
||||
|
||||
//Cagette core tests
|
||||
r.add(new test.TestUser());
|
||||
r.add(new test.TestOrders());
|
||||
r.add(new test.TestTools());
|
||||
r.add(new test.TestDistributions());
|
||||
r.add(new test.TestPayments());
|
||||
r.add(new test.TestReports());
|
||||
|
||||
#if plugins
|
||||
//Cagette-pro tests, keep in this order
|
||||
r.add(new pro.test.TestProductService());
|
||||
r.add(new pro.test.TestRemoteCatalog());
|
||||
r.add(new pro.test.TestDistribService());
|
||||
r.add(new pro.test.TestReports());
|
||||
//wholesale-order tests
|
||||
r.add(new who.test.TestWho());
|
||||
#end
|
||||
|
||||
r.run();
|
||||
}
|
||||
|
||||
static function connectDb() {
|
||||
var dbstr = Sys.args()[0];
|
||||
var dbreg = ~/([^:]+):\/\/([^:]+):([^@]*?)@([^:]+)(:[0-9]+)?\/(.*?)$/;
|
||||
if( !dbreg.match(dbstr) )
|
||||
throw "Configuration requires a valid database attribute, format is : mysql://user:password@host:port/dbname";
|
||||
var port = dbreg.matched(5);
|
||||
var dbparams = {
|
||||
user:dbreg.matched(2),
|
||||
pass:dbreg.matched(3),
|
||||
host:dbreg.matched(4),
|
||||
port:port == null ? 3306 : Std.parseInt(port.substr(1)),
|
||||
database:dbreg.matched(6),
|
||||
socket:null
|
||||
};
|
||||
|
||||
sys.db.Manager.cnx = sys.db.Mysql.connect(dbparams);
|
||||
sys.db.Manager.initialize();
|
||||
}
|
||||
|
||||
|
||||
public static function initDB(){
|
||||
//NUKE EVERYTHING BWAAAAH !!
|
||||
sys.db.Manager.cleanup(); //cleanup cache objects
|
||||
sql("DROP DATABASE tests;");
|
||||
sql("CREATE DATABASE tests;");
|
||||
sql("USE tests;");
|
||||
|
||||
var tables : Array<Dynamic> = [
|
||||
|
||||
//cagette
|
||||
db.TxpProduct.manager,
|
||||
db.TxpCategory.manager,
|
||||
db.TxpSubCategory.manager,
|
||||
db.Category.manager,
|
||||
db.CategoryGroup.manager,
|
||||
db.ProductCategory.manager,
|
||||
|
||||
db.Basket.manager,
|
||||
db.UserContract.manager,
|
||||
db.UserAmap.manager,
|
||||
db.Operation.manager,
|
||||
|
||||
db.User.manager,
|
||||
db.Amap.manager,
|
||||
db.Contract.manager,
|
||||
db.Product.manager,
|
||||
db.Vendor.manager,
|
||||
db.Place.manager,
|
||||
db.Distribution.manager,
|
||||
db.DistributionCycle.manager,
|
||||
|
||||
//sugoi tables
|
||||
sugoi.db.Cache.manager,
|
||||
sugoi.db.Error.manager,
|
||||
sugoi.db.File.manager,
|
||||
sugoi.db.Session.manager,
|
||||
sugoi.db.Variable.manager,
|
||||
];
|
||||
|
||||
for(t in tables) createTable(t);
|
||||
|
||||
#if plugins
|
||||
//add Cpro datas : we need those tables even in cagette core tests
|
||||
pro.test.ProTestSuite.initDB();
|
||||
pro.test.ProTestSuite.initDatas();
|
||||
#end
|
||||
}
|
||||
|
||||
public static function createTable( m ){
|
||||
if ( sys.db.TableCreate.exists(m) ){
|
||||
drop(m);
|
||||
}
|
||||
// Sys.println("Creating table "+ m.dbInfos().name);
|
||||
sys.db.TableCreate.create(m);
|
||||
}
|
||||
|
||||
public static function truncate(m){
|
||||
sql("TRUNCATE TABLE "+m.dbInfos().name+";");
|
||||
}
|
||||
|
||||
public static function drop(m){
|
||||
sql("DROP TABLE "+m.dbInfos().name+";");
|
||||
}
|
||||
|
||||
public static function sql(sql){
|
||||
return sys.db.Manager.cnx.request(sql);
|
||||
}
|
||||
|
||||
//shortcut to datas
|
||||
public static var FRANCOIS:db.User = null;
|
||||
public static var SEB:db.User = null;
|
||||
public static var JULIE:db.User = null;
|
||||
|
||||
public static var CHICKEN:db.Product = null;
|
||||
public static var STRAWBERRIES:db.Product = null;
|
||||
public static var APPLES:db.Product = null;
|
||||
public static var AMAP_DU_JARDIN:db.Amap = null;
|
||||
public static var LOCAVORES:db.Amap = null;
|
||||
public static var PANIER_AMAP_LEGUMES:db.Product = null;
|
||||
public static var DISTRIB_CONTRAT_AMAP:db.Distribution = null;
|
||||
public static var DISTRIB_FRUITS_PLACE_DU_VILLAGE:db.Distribution = null;
|
||||
public static var DISTRIB_LEGUMES_RUE_SAUCISSE:db.Distribution = null;
|
||||
public static var CONTRAT_LEGUMES:db.Contract = null;
|
||||
public static var PLACE_DU_VILLAGE:db.Place = null;
|
||||
public static var COURGETTES:db.Product = null;
|
||||
public static var CARROTS:db.Product = null;
|
||||
public static var FLAN:db.Product = null;
|
||||
public static var CROISSANT:db.Product = null;
|
||||
public static var DISTRIB_PATISSERIES:db.Distribution = null;
|
||||
|
||||
public static function initDatas(){
|
||||
|
||||
//USERS
|
||||
|
||||
var f = new db.User();
|
||||
f.firstName = "François";
|
||||
f.lastName = "B";
|
||||
f.email = "francois@alilo.fr";
|
||||
f.insert();
|
||||
|
||||
FRANCOIS = f;
|
||||
|
||||
var u = new db.User();
|
||||
u.firstName = "Seb";
|
||||
u.lastName = "Z";
|
||||
u.email = "sebastien@alilo.fr";
|
||||
u.insert();
|
||||
|
||||
SEB = u;
|
||||
|
||||
var u = new db.User();
|
||||
u.firstName = "Julie";
|
||||
u.lastName = "B";
|
||||
u.email = "julie@alilo.fr";
|
||||
u.insert();
|
||||
|
||||
JULIE = u;
|
||||
|
||||
initApp(u);
|
||||
|
||||
//GROUP "AMAP du Jardin public"
|
||||
var a = new db.Amap();
|
||||
a.name = "AMAP du Jardin public";
|
||||
a.contact = f;
|
||||
a.flags.set(db.Amap.AmapFlags.HasPayments);
|
||||
a.insert();
|
||||
AMAP_DU_JARDIN = a;
|
||||
|
||||
var place = new db.Place();
|
||||
place.name = "Place du village";
|
||||
place.zipCode = "00000";
|
||||
place.city = "St Martin";
|
||||
place.amap = a;
|
||||
place.insert();
|
||||
|
||||
PLACE_DU_VILLAGE = place;
|
||||
|
||||
//VENDOR "Ferme de la galinette"
|
||||
var v = new db.Vendor();
|
||||
v.name = "La ferme de la Galinette";
|
||||
v.email = "galinette@gmail.com";
|
||||
v.zipCode = "00000";
|
||||
v.city = "Bourligheim";
|
||||
v.insert();
|
||||
|
||||
var c = new db.Contract();
|
||||
c.name = "Contrat AMAP Légumes";
|
||||
c.startDate = new Date(2017, 1, 1, 0, 0, 0);
|
||||
c.endDate = new Date(2030, 12, 31, 23, 59, 0);
|
||||
c.vendor = v;
|
||||
c.amap = a;
|
||||
c.type = db.Contract.TYPE_CONSTORDERS;
|
||||
c.insert();
|
||||
|
||||
var p = new db.Product();
|
||||
p.name = "Panier Légumes";
|
||||
p.price = 13;
|
||||
p.contract = c;
|
||||
p.insert();
|
||||
|
||||
PANIER_AMAP_LEGUMES = p;
|
||||
|
||||
var d = new db.Distribution();
|
||||
d.date = new Date(2017, 5, 1, 19, 0, 0);
|
||||
d.end = new Date(2017, 5, 1, 20, 0, 0);
|
||||
d.orderStartDate = new Date(2017, 4, 1, 20, 0, 0);
|
||||
d.orderEndDate = new Date(2017, 4, 30, 20, 0, 0);
|
||||
d.contract = c;
|
||||
d.place = place;
|
||||
d.insert();
|
||||
|
||||
DISTRIB_CONTRAT_AMAP = d;
|
||||
|
||||
//varying contract for strawberries with stock mgmt
|
||||
var c = new db.Contract();
|
||||
c.name = "Commande fruits";
|
||||
c.vendor = v;
|
||||
c.startDate = new Date(2017, 1, 1, 0, 0, 0);
|
||||
c.endDate = new Date(2030, 12, 31, 23, 59, 0);
|
||||
c.flags.set(db.Contract.ContractFlags.StockManagement);
|
||||
c.type = db.Contract.TYPE_VARORDER;
|
||||
c.amap = a;
|
||||
c.insert();
|
||||
|
||||
var p = new db.Product();
|
||||
p.name = "Fraises";
|
||||
p.qt = 1;
|
||||
p.unitType = Common.Unit.Kilogram;
|
||||
p.price = 10;
|
||||
p.organic = true;
|
||||
p.contract = c;
|
||||
p.stock = 8;
|
||||
p.insert();
|
||||
|
||||
STRAWBERRIES = p;
|
||||
|
||||
var p = new db.Product();
|
||||
p.name = "Pommes";
|
||||
p.qt = 1;
|
||||
p.unitType = Common.Unit.Kilogram;
|
||||
p.price = 6;
|
||||
p.organic = true;
|
||||
p.contract = c;
|
||||
p.stock = 12;
|
||||
p.insert();
|
||||
|
||||
APPLES = p;
|
||||
|
||||
var d = new db.Distribution();
|
||||
d.date = new Date(2017, 5, 1, 19, 0, 0);
|
||||
d.end = new Date(2017, 5, 1, 20, 0, 0);
|
||||
d.orderStartDate = new Date(2017, 4, 1, 20, 0, 0);
|
||||
d.orderEndDate = new Date(2017, 4, 30, 20, 0, 0);
|
||||
d.contract = c;
|
||||
d.place = place;
|
||||
d.insert();
|
||||
|
||||
DISTRIB_FRUITS_PLACE_DU_VILLAGE = d;
|
||||
|
||||
//second group
|
||||
var a = new db.Amap();
|
||||
a.name = "Les Locavores de la Rue Saucisse";
|
||||
a.contact = f;
|
||||
a.flags.set(db.Amap.AmapFlags.HasPayments);
|
||||
a.insert();
|
||||
LOCAVORES = a;
|
||||
|
||||
var place = new db.Place();
|
||||
place.name = "Rue Saucisse";
|
||||
place.zipCode = "00000";
|
||||
place.city = "St Martin";
|
||||
place.amap = a;
|
||||
place.insert();
|
||||
|
||||
var v = new db.Vendor();
|
||||
v.name = "La ferme de la courgette enragée";
|
||||
v.email = "courgette@gmail.com";
|
||||
v.zipCode = "00000";
|
||||
v.city = "Bourligeac";
|
||||
v.insert();
|
||||
|
||||
var c = new db.Contract();
|
||||
c.name = "Commande Legumes";
|
||||
c.startDate = new Date(2017, 1, 1, 0, 0, 0);
|
||||
c.endDate = new Date(2030, 12, 31, 23, 59, 0);
|
||||
c.vendor = v;
|
||||
c.amap = a;
|
||||
c.type = db.Contract.TYPE_VARORDER;
|
||||
c.insert();
|
||||
|
||||
CONTRAT_LEGUMES = c;
|
||||
|
||||
var p = new db.Product();
|
||||
p.name = "Courgettes";
|
||||
p.qt = 1;
|
||||
p.unitType = Common.Unit.Kilogram;
|
||||
p.price = 3.5;
|
||||
p.vat = 5.5;
|
||||
p.organic = true;
|
||||
p.contract = c;
|
||||
p.insert();
|
||||
|
||||
COURGETTES = p;
|
||||
|
||||
var p = new db.Product();
|
||||
p.name = "Carottes";
|
||||
p.qt = 1;
|
||||
p.unitType = Common.Unit.Kilogram;
|
||||
p.price = 2.8;
|
||||
p.vat = 5.5;
|
||||
p.contract = c;
|
||||
p.insert();
|
||||
|
||||
CARROTS = p;
|
||||
|
||||
var p = new db.Product();
|
||||
p.name = "Poulet";
|
||||
p.qt = 1.5;
|
||||
p.unitType = Common.Unit.Kilogram;
|
||||
p.price = 15;
|
||||
p.vat = 5.5;
|
||||
p.multiWeight = true;
|
||||
p.hasFloatQt = true;
|
||||
p.contract = c;
|
||||
p.insert();
|
||||
|
||||
CHICKEN = p;
|
||||
|
||||
var d = service.DistributionService.create(c,new Date(2017, 5, 1, 19, 0, 0),new Date(2017, 5, 1, 19, 2, 0),place.id,null,null,null,null,new Date(2017, 4, 10, 19, 0, 0),new Date(2017, 4, 20, 19, 0, 0));
|
||||
DISTRIB_LEGUMES_RUE_SAUCISSE = d;
|
||||
|
||||
//PASTRY
|
||||
|
||||
var c = new db.Contract();
|
||||
c.name = "Commande Pâtisseries";
|
||||
c.startDate = new Date(2017, 1, 1, 0, 0, 0);
|
||||
c.endDate = new Date(2017, 12, 31, 23, 59, 0);
|
||||
c.vendor = v;
|
||||
c.amap = a;
|
||||
c.type = db.Contract.TYPE_VARORDER;
|
||||
c.insert();
|
||||
|
||||
var p = new db.Product();
|
||||
p.name = "Flan";
|
||||
p.qt = 1;
|
||||
p.unitType = Common.Unit.Kilogram;
|
||||
p.price = 3.5;
|
||||
p.organic = true;
|
||||
p.contract = c;
|
||||
p.insert();
|
||||
|
||||
FLAN = p;
|
||||
|
||||
var p = new db.Product();
|
||||
p.name = "Croissant";
|
||||
p.qt = 1;
|
||||
p.unitType = Common.Unit.Kilogram;
|
||||
p.price = 2.8;
|
||||
p.contract = c;
|
||||
p.insert();
|
||||
|
||||
CROISSANT = p;
|
||||
|
||||
var d = new db.Distribution();
|
||||
d.date = new Date(2017, 5, 1, 19, 0, 0);
|
||||
d.contract = c;
|
||||
d.place = place;
|
||||
d.insert();
|
||||
|
||||
DISTRIB_PATISSERIES = d;
|
||||
}
|
||||
|
||||
static function initApp(u:db.User){
|
||||
|
||||
//setup App
|
||||
var app = App.current = new App();
|
||||
App.config.DEBUG = true;
|
||||
app.initLang("en");
|
||||
|
||||
app.eventDispatcher = new hxevents.Dispatcher<Event>();
|
||||
app.plugins = [];
|
||||
//internal plugins
|
||||
app.plugins.push(new plugin.Tutorial());
|
||||
|
||||
//optionnal plugins
|
||||
#if plugins
|
||||
//app.plugins.push( new hosted.HostedPlugIn() );
|
||||
app.plugins.push( new pro.ProPlugIn() );
|
||||
app.plugins.push( new connector.ConnectorPlugIn() );
|
||||
//app.plugins.push( new pro.LemonwayEC() );
|
||||
app.plugins.push( new who.WhoPlugIn() );
|
||||
#end
|
||||
|
||||
App.current.user = u;
|
||||
App.current.view = new View();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
package test;
|
||||
import Common;
|
||||
|
||||
/**
|
||||
* Test various tools
|
||||
*
|
||||
* @author fbarbut
|
||||
*/
|
||||
class TestTools extends haxe.unit.TestCase
|
||||
{
|
||||
|
||||
public function new(){
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
function testDateRanges(){
|
||||
// test last hour range
|
||||
var now = Date.fromString("2018-01-01 00:30:12");
|
||||
var r = tools.DateTool.getLastHourRange(now);
|
||||
assertEquals("2017-12-31 23:00:00",r.from.toString());
|
||||
assertEquals("2018-01-01 00:00:00",r.to.toString());
|
||||
|
||||
// test last minute
|
||||
var now = Date.fromString("2018-01-01 00:30:12");
|
||||
var r = tools.DateTool.getLastMinuteRange(now);
|
||||
assertEquals("2018-01-01 00:29:00",r.from.toString());
|
||||
assertEquals("2018-01-01 00:30:00",r.to.toString());
|
||||
}
|
||||
|
||||
|
||||
function testFloatTool(){
|
||||
|
||||
assertEquals( true , tools.FloatTool.isEqual(10.0,10.000) );
|
||||
assertEquals( true , tools.FloatTool.isEqual(10.0,10) );
|
||||
assertEquals( true , tools.FloatTool.isEqual(10,10) );
|
||||
assertEquals( true , tools.FloatTool.isEqual(10.00000001,10) );
|
||||
assertEquals( false , tools.FloatTool.isEqual(10.02,10) );
|
||||
|
||||
assertEquals( false , tools.FloatTool.isInt(10.08) );
|
||||
assertEquals( true , tools.FloatTool.isInt(10.00) );
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@admin
|
||||
public function doTests() {
|
||||
|
||||
var assertTrue = function(val, ?desc="") {
|
||||
if (val) {
|
||||
Sys.println("OK : <br/>");
|
||||
}else {
|
||||
Sys.println("ERROR : "+desc+"<br/>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//test les fonctions de cotisation
|
||||
|
||||
var amap = db.Amap.manager.get(1);
|
||||
|
||||
amap.membershipRenewalDate = new Date(2015, 0, 1,0,0,0);
|
||||
amap.update();
|
||||
|
||||
assertTrue(amap.getMembershipYear(new Date(2015, 3, 3, 0, 0, 0) ) == 2015);
|
||||
assertTrue(amap.getPeriodName(new Date(2015, 3, 3, 0, 0, 0)) == "2015");
|
||||
|
||||
assertTrue(amap.getMembershipYear(new Date(2014, 8, 8, 0, 0, 0) ) == 2014);
|
||||
assertTrue(amap.getPeriodName(new Date(2014, 8, 8, 0, 0, 0) ) == "2014");
|
||||
|
||||
assertTrue(amap.getMembershipYear(new Date(2013, 11, 12, 0, 0, 0) ) == 2013);
|
||||
assertTrue(amap.getPeriodName(new Date(2013, 11, 12, 0, 0, 0) ) == "2013");
|
||||
|
||||
amap.membershipRenewalDate = new Date(2015, 8, 1,0,0,0);
|
||||
amap.update();
|
||||
|
||||
assertTrue(amap.getMembershipYear(new Date(2015, 3, 3, 0, 0, 0) ) == 2014);
|
||||
assertTrue(amap.getPeriodName(new Date(2015, 3, 3, 0, 0, 0)) == "2014-2015");
|
||||
|
||||
var d = amap.getMembershipYear(new Date(2015, 8, 8, 0, 0, 0) );
|
||||
assertTrue( d == 2015, "le 8 sept 2015, on doit etre en cotis 2015, la c " + d);
|
||||
assertTrue(amap.getPeriodName(new Date(2015, 8, 8, 0, 0, 0)) == "2015-2016");
|
||||
|
||||
var d = new Date(2013, 11, 12, 0, 0, 0) ;
|
||||
assertTrue( amap.getMembershipYear(d) == 2013, "le 12 oct 2013, on doit etre en cotis 2013 , là c " + amap.getMembershipYear(d) );
|
||||
assertTrue(amap.getPeriodName(d) == "2013-2014", "le 12 oct 2013, on doit etre en 2013-2014 , là c " + amap.getPeriodName(d) );
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
|
||||
|
||||
package test;
|
||||
import db.UserAmap;
|
||||
import Common;
|
||||
|
||||
/**
|
||||
* Test user rights to view contracts
|
||||
*
|
||||
* @author web-wizard
|
||||
*/
|
||||
class TestUser extends haxe.unit.TestCase
|
||||
{
|
||||
|
||||
public function new(){
|
||||
super();
|
||||
}
|
||||
|
||||
var contract : db.Contract;
|
||||
var user : db.User;
|
||||
var group1 : db.Amap;
|
||||
var group2 : db.Amap;
|
||||
var userAmap : db.UserAmap;
|
||||
|
||||
/**
|
||||
* get a contract + a user
|
||||
*/
|
||||
override function setup(){
|
||||
TestSuite.initDB();
|
||||
TestSuite.initDatas();
|
||||
|
||||
contract = db.Contract.manager.get(3);
|
||||
user = db.User.manager.get(1);
|
||||
group1 = db.Amap.manager.get(1);
|
||||
group2 = db.Amap.manager.get(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a user who has admin rights for his/her group can't view a contract from a group
|
||||
he/she doesn't belong to
|
||||
*/
|
||||
function testViewContract(){
|
||||
userAmap = db.UserAmap.getOrCreate(user, group1);
|
||||
userAmap.giveRight(Right.GroupAdmin);
|
||||
assertFalse(user.canManageContract(contract));
|
||||
}
|
||||
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
-lib dbadmin
|
||||
-lib templo
|
||||
-lib sugoi
|
||||
-lib hxevents
|
||||
-lib thx.semver
|
||||
-lib thx.csv
|
||||
-lib datetime
|
||||
-lib hscript
|
||||
-lib smtpmailer
|
||||
-lib record-macros
|
||||
-lib tink_json
|
||||
-cp common
|
||||
-cp src
|
||||
-cp lang/master/tpl
|
||||
-neko www/tests.n
|
||||
-main test.TestSuite
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
# JS
|
||||
-js js/test/tests.js
|
||||
-main test.TestAll
|
||||
-cp js
|
||||
-cp common
|
||||
-lib utest
|
||||
-lib hxnodejs
|
||||
-lib sugoi:git:https://github.com/bablukid/sugoi#i18n
|
||||
-D test
|
||||
@@ -1,21 +0,0 @@
|
||||
-lib dbadmin
|
||||
-lib templo
|
||||
-lib sugoi
|
||||
-lib hxevents
|
||||
-lib thx.semver
|
||||
-lib thx.csv
|
||||
-lib datetime
|
||||
-lib hscript
|
||||
-lib smtpmailer
|
||||
-lib record-macros
|
||||
-lib cagette-pro
|
||||
-lib cagette-hosted
|
||||
-lib cagette-wholesale-order
|
||||
-lib tink_json
|
||||
-cp common
|
||||
-cp src
|
||||
-cp lang/master/tpl
|
||||
-neko www/tests.n
|
||||
-D plugins
|
||||
-main test.TestSuite
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 27 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 27 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 27 KiB |
Reference in New Issue
Block a user