|
|
@@ -1,4 +1,5 @@
|
|
|
|
package controller;
|
|
|
|
package controller;
|
|
|
|
|
|
|
|
|
|
|
|
import db.UserContract;
|
|
|
|
import db.UserContract;
|
|
|
|
import sugoi.form.elements.Checkbox;
|
|
|
|
import sugoi.form.elements.Checkbox;
|
|
|
|
import sugoi.form.elements.Selectbox;
|
|
|
|
import sugoi.form.elements.Selectbox;
|
|
|
@@ -6,19 +7,20 @@ import sugoi.form.Form;
|
|
|
|
import sugoi.form.elements.StringInput;
|
|
|
|
import sugoi.form.elements.StringInput;
|
|
|
|
import Common;
|
|
|
|
import Common;
|
|
|
|
import datetime.DateTime;
|
|
|
|
import datetime.DateTime;
|
|
|
|
|
|
|
|
|
|
|
|
using tools.ObjectListTool;
|
|
|
|
using tools.ObjectListTool;
|
|
|
|
using tools.DateTool;
|
|
|
|
using tools.DateTool;
|
|
|
|
|
|
|
|
|
|
|
|
import service.OrderService;
|
|
|
|
import service.OrderService;
|
|
|
|
|
|
|
|
|
|
|
|
class ContractAdmin extends Controller
|
|
|
|
class ContractAdmin extends Controller {
|
|
|
|
{
|
|
|
|
public function new() {
|
|
|
|
|
|
|
|
|
|
|
|
public function new()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
super();
|
|
|
|
super();
|
|
|
|
if (!app.user.isContractManager()) throw Error("/", t._("You don't have the authorization to manage contracts"));
|
|
|
|
if (!app.user.isContractManager())
|
|
|
|
|
|
|
|
throw Error("/", t._("You don't have the authorization to manage contracts"));
|
|
|
|
view.nav = ["contractadmin"];
|
|
|
|
view.nav = ["contractadmin"];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
App.log("first message");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function sendNav(c) {
|
|
|
|
public function sendNav(c) {
|
|
|
@@ -33,7 +35,6 @@ class ContractAdmin extends Controller
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@tpl("contractadmin/default.mtt")
|
|
|
|
@tpl("contractadmin/default.mtt")
|
|
|
|
function doDefault(?args:{old:Bool}) {
|
|
|
|
function doDefault(?args:{old:Bool}) {
|
|
|
|
|
|
|
|
|
|
|
|
view.nav.push("default");
|
|
|
|
view.nav.push("default");
|
|
|
|
|
|
|
|
|
|
|
|
var now = Date.now();
|
|
|
|
var now = Date.now();
|
|
|
@@ -48,7 +49,8 @@ class ContractAdmin extends Controller
|
|
|
|
// filter if current user is not manager
|
|
|
|
// filter if current user is not manager
|
|
|
|
if (!app.user.isAmapManager()) {
|
|
|
|
if (!app.user.isAmapManager()) {
|
|
|
|
for (c in Lambda.array(contracts).copy()) {
|
|
|
|
for (c in Lambda.array(contracts).copy()) {
|
|
|
|
if(!app.user.canManageContract(c)) contracts.remove(c);
|
|
|
|
if (!app.user.canManageContract(c))
|
|
|
|
|
|
|
|
contracts.remove(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -65,7 +67,6 @@ class ContractAdmin extends Controller
|
|
|
|
if(md.hasOnlyConstantOrders()) multidistribs.remove(md);
|
|
|
|
if(md.hasOnlyConstantOrders()) multidistribs.remove(md);
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
view.multidistribs = multidistribs;
|
|
|
|
view.multidistribs = multidistribs;
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
view.multidistribs = [];
|
|
|
|
view.multidistribs = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -79,14 +80,18 @@ class ContractAdmin extends Controller
|
|
|
|
view.nav.push("products");
|
|
|
|
view.nav.push("products");
|
|
|
|
sendNav(contract);
|
|
|
|
sendNav(contract);
|
|
|
|
|
|
|
|
|
|
|
|
if (!app.user.canManageContract(contract)) throw Error("/", t._("Access forbidden") );
|
|
|
|
if (!app.user.canManageContract(contract))
|
|
|
|
|
|
|
|
throw Error("/", t._("Access forbidden"));
|
|
|
|
view.c = contract;
|
|
|
|
view.c = contract;
|
|
|
|
|
|
|
|
|
|
|
|
// checks
|
|
|
|
// checks
|
|
|
|
if (app.user.amap.hasShopMode() && !app.user.amap.hasTaxonomy()) {
|
|
|
|
if (app.user.amap.hasShopMode() && !app.user.amap.hasTaxonomy()) {
|
|
|
|
for (p in contract.getProducts(false)) {
|
|
|
|
for (p in contract.getProducts(false)) {
|
|
|
|
if (p.getCategories().length == 0) {
|
|
|
|
if (p.getCategories().length == 0) {
|
|
|
|
app.session.addMessage(t._("Warning, at least one product does not have any category. <a href='/product/categorize/::contractid::'>Click here to add categories</a>", {contractid:contract.id}), true);
|
|
|
|
app.session.addMessage(t._("Warning, at least one product does not have any category. <a href='/product/categorize/::contractid::'>Click here to add categories</a>",
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
contractid: contract.id
|
|
|
|
|
|
|
|
}), true);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -94,7 +99,6 @@ class ContractAdmin extends Controller
|
|
|
|
|
|
|
|
|
|
|
|
// batch enable / disable products
|
|
|
|
// batch enable / disable products
|
|
|
|
if (args != null) {
|
|
|
|
if (args != null) {
|
|
|
|
|
|
|
|
|
|
|
|
if (args.disable != null) {
|
|
|
|
if (args.disable != null) {
|
|
|
|
var pids = Lambda.array(Lambda.map(args.disable.split("|"), function(x) return Std.parseInt(x)));
|
|
|
|
var pids = Lambda.array(Lambda.map(args.disable.split("|"), function(x) return Std.parseInt(x)));
|
|
|
|
service.ProductService.batchDisableProducts(pids);
|
|
|
|
service.ProductService.batchDisableProducts(pids);
|
|
|
@@ -104,14 +108,12 @@ class ContractAdmin extends Controller
|
|
|
|
var pids = Lambda.array(Lambda.map(args.enable.split("|"), function(x) return Std.parseInt(x)));
|
|
|
|
var pids = Lambda.array(Lambda.map(args.enable.split("|"), function(x) return Std.parseInt(x)));
|
|
|
|
service.ProductService.batchEnableProducts(pids);
|
|
|
|
service.ProductService.batchEnableProducts(pids);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// generate a token
|
|
|
|
// generate a token
|
|
|
|
checkToken();
|
|
|
|
checkToken();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* - hidden page -
|
|
|
|
* - hidden page -
|
|
|
|
* copy products from a contract to an other
|
|
|
|
* copy products from a contract to an other
|
|
|
@@ -125,7 +127,6 @@ class ContractAdmin extends Controller
|
|
|
|
form.addElement(new sugoi.form.elements.Selectbox("source", t._("Copy products from: "), Lambda.array(contracts)));
|
|
|
|
form.addElement(new sugoi.form.elements.Selectbox("source", t._("Copy products from: "), Lambda.array(contracts)));
|
|
|
|
form.addElement(new sugoi.form.elements.Checkbox("delete", t._("Delete existing products (all orders will be deleted!)")));
|
|
|
|
form.addElement(new sugoi.form.elements.Checkbox("delete", t._("Delete existing products (all orders will be deleted!)")));
|
|
|
|
if (form.checkToken()) {
|
|
|
|
if (form.checkToken()) {
|
|
|
|
|
|
|
|
|
|
|
|
if (form.getValueOf("delete") == "1") {
|
|
|
|
if (form.getValueOf("delete") == "1") {
|
|
|
|
for (p in contract.getProducts()) {
|
|
|
|
for (p in contract.getProducts()) {
|
|
|
|
p.lock();
|
|
|
|
p.lock();
|
|
|
@@ -145,11 +146,8 @@ class ContractAdmin extends Controller
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
throw Ok("/contractAdmin/products/" + contract.id, t._("Products copied from ") + source.name);
|
|
|
|
throw Ok("/contractAdmin/products/" + contract.id, t._("Products copied from ") + source.name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
view.form = form;
|
|
|
|
view.form = form;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -159,7 +157,6 @@ class ContractAdmin extends Controller
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@tpl('contractadmin/calendar.mtt')
|
|
|
|
@tpl('contractadmin/calendar.mtt')
|
|
|
|
public function doCalendar() {
|
|
|
|
public function doCalendar() {
|
|
|
|
|
|
|
|
|
|
|
|
var contracts = db.Contract.getActiveContracts(app.user.amap, true, false);
|
|
|
|
var contracts = db.Contract.getActiveContracts(app.user.amap, true, false);
|
|
|
|
|
|
|
|
|
|
|
|
// Events of the month in a calendar
|
|
|
|
// Events of the month in a calendar
|
|
|
@@ -203,18 +200,13 @@ class ContractAdmin extends Controller
|
|
|
|
v.push({name: t._("End of orders") + d.contract.name, color: Calendar.COLOR_ORDER});
|
|
|
|
v.push({name: t._("End of orders") + d.contract.name, color: Calendar.COLOR_ORDER});
|
|
|
|
cal.set(k, v);
|
|
|
|
cal.set(k, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var n = Date.now();
|
|
|
|
var n = Date.now();
|
|
|
|
view.now = new Date(n.getFullYear(), n.getMonth(), n.getDate(), 0, 0, 0).getTime();
|
|
|
|
view.now = new Date(n.getFullYear(), n.getMonth(), n.getDate(), 0, 0, 0).getTime();
|
|
|
|
view.calendar = Calendar.mapToArray(cal);
|
|
|
|
view.calendar = Calendar.mapToArray(cal);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@@ -222,16 +214,13 @@ class ContractAdmin extends Controller
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@tpl('contractadmin/ordersByTimeFrame.mtt')
|
|
|
|
@tpl('contractadmin/ordersByTimeFrame.mtt')
|
|
|
|
function doOrdersByTimeFrame(?from:Date, ?to:Date /*, ?place:db.Place*/) {
|
|
|
|
function doOrdersByTimeFrame(?from:Date, ?to:Date /*, ?place:db.Place*/) {
|
|
|
|
|
|
|
|
|
|
|
|
if (from == null) {
|
|
|
|
if (from == null) {
|
|
|
|
|
|
|
|
|
|
|
|
var f = new sugoi.form.Form("listBydate", null, sugoi.form.Form.FormMethod.GET);
|
|
|
|
var f = new sugoi.form.Form("listBydate", null, sugoi.form.Form.FormMethod.GET);
|
|
|
|
|
|
|
|
|
|
|
|
var now = DateTime.now();
|
|
|
|
var now = DateTime.now();
|
|
|
|
var from = now.snap(Month(Down)).getDate();
|
|
|
|
var from = now.snap(Month(Down)).getDate();
|
|
|
|
var to = now.snap(Month(Up)).add(Day(-1)).getDate();
|
|
|
|
var to = now.snap(Month(Up)).add(Day(-1)).getDate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var el = new sugoi.form.elements.DatePicker("from", t._("Start date"), from, true);
|
|
|
|
var el = new sugoi.form.elements.DatePicker("from", t._("Start date"), from, true);
|
|
|
|
el.format = 'LL';
|
|
|
|
el.format = 'LL';
|
|
|
|
f.addElement(el);
|
|
|
|
f.addElement(el);
|
|
|
@@ -248,32 +237,33 @@ class ContractAdmin extends Controller
|
|
|
|
app.setTemplate("form.mtt");
|
|
|
|
app.setTemplate("form.mtt");
|
|
|
|
|
|
|
|
|
|
|
|
if (f.checkToken()) {
|
|
|
|
if (f.checkToken()) {
|
|
|
|
|
|
|
|
var url = '/contractAdmin/ordersByTimeFrame/' + f.getValueOf("from").toString().substr(0, 10) + "/"
|
|
|
|
var url = '/contractAdmin/ordersByTimeFrame/' + f.getValueOf("from").toString().substr(0, 10) +"/"+f.getValueOf("to").toString().substr(0, 10);
|
|
|
|
+ f.getValueOf("to").toString().substr(0, 10);
|
|
|
|
// var p = f.getValueOf("placeId");
|
|
|
|
// var p = f.getValueOf("placeId");
|
|
|
|
// if (p != null) url += "/"+p;
|
|
|
|
// if (p != null) url += "/"+p;
|
|
|
|
throw Redirect(url);
|
|
|
|
throw Redirect(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
var d1 = tools.DateTool.setHourMinute(from, 0, 0);
|
|
|
|
var d1 = tools.DateTool.setHourMinute(from, 0, 0);
|
|
|
|
var d2 = tools.DateTool.setHourMinute(to, 23, 59);
|
|
|
|
var d2 = tools.DateTool.setHourMinute(to, 23, 59);
|
|
|
|
var contracts = app.user.amap.getActiveContracts(true);
|
|
|
|
var contracts = app.user.amap.getActiveContracts(true);
|
|
|
|
var cconst = [];
|
|
|
|
var cconst = [];
|
|
|
|
var cvar = [];
|
|
|
|
var cvar = [];
|
|
|
|
for (c in contracts) {
|
|
|
|
for (c in contracts) {
|
|
|
|
if (c.type == db.Contract.TYPE_CONSTORDERS) cconst.push(c.id);
|
|
|
|
if (c.type == db.Contract.TYPE_CONSTORDERS)
|
|
|
|
if (c.type == db.Contract.TYPE_VARORDER) cvar.push(c.id);
|
|
|
|
cconst.push(c.id);
|
|
|
|
|
|
|
|
if (c.type == db.Contract.TYPE_VARORDER)
|
|
|
|
|
|
|
|
cvar.push(c.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// distribs
|
|
|
|
// distribs
|
|
|
|
var vdistribs = db.Distribution.manager.search(($contractId in cvar) && $date >= d1 && $date <= d2 /*&& place.id==$placeId*/, false);
|
|
|
|
var vdistribs = db.Distribution.manager.search(($contractId in cvar) && $date >= d1 && $date <= d2 /*&& place.id==$placeId*/, false);
|
|
|
|
var cdistribs = db.Distribution.manager.search(($contractId in cconst) && $date >= d1 && $date <= d2 /*&& place.id==$placeId*/, false);
|
|
|
|
var cdistribs = db.Distribution.manager.search(($contractId in cconst) && $date >= d1 && $date <= d2 /*&& place.id==$placeId*/, false);
|
|
|
|
|
|
|
|
|
|
|
|
if (vdistribs.length == 0 && cdistribs.length == 0) throw Error("/contractAdmin/ordersByDate", t._("There is no delivery at this date"));
|
|
|
|
if (vdistribs.length == 0 && cdistribs.length == 0)
|
|
|
|
|
|
|
|
throw Error("/contractAdmin/ordersByDate", t._("There is no delivery at this date"));
|
|
|
|
|
|
|
|
|
|
|
|
// varying orders
|
|
|
|
// varying orders
|
|
|
|
var varorders = db.UserContract.manager.search($distributionId in vdistribs.getIds(), {orderBy: userId});
|
|
|
|
var varorders = db.UserContract.manager.search($distributionId in vdistribs.getIds(), {orderBy: userId});
|
|
|
@@ -293,11 +283,7 @@ class ContractAdmin extends Controller
|
|
|
|
view.from = from;
|
|
|
|
view.from = from;
|
|
|
|
view.to = to;
|
|
|
|
view.to = to;
|
|
|
|
view.ctotal = app.params.exists("ctotal");
|
|
|
|
view.ctotal = app.params.exists("ctotal");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@@ -308,7 +294,6 @@ class ContractAdmin extends Controller
|
|
|
|
@tpl('contractadmin/ordersByDate.mtt')
|
|
|
|
@tpl('contractadmin/ordersByDate.mtt')
|
|
|
|
function doOrdersByDate(?date:Date, ?place:db.Place) {
|
|
|
|
function doOrdersByDate(?date:Date, ?place:db.Place) {
|
|
|
|
if (date == null) {
|
|
|
|
if (date == null) {
|
|
|
|
|
|
|
|
|
|
|
|
var f = new sugoi.form.Form("listBydate", null, sugoi.form.Form.FormMethod.GET);
|
|
|
|
var f = new sugoi.form.Form("listBydate", null, sugoi.form.Form.FormMethod.GET);
|
|
|
|
var el = new sugoi.form.elements.DatePicker("date", t._("Delivery date"), true);
|
|
|
|
var el = new sugoi.form.elements.DatePicker("date", t._("Delivery date"), true);
|
|
|
|
el.format = 'LL';
|
|
|
|
el.format = 'LL';
|
|
|
@@ -324,32 +309,33 @@ class ContractAdmin extends Controller
|
|
|
|
app.setTemplate("form.mtt");
|
|
|
|
app.setTemplate("form.mtt");
|
|
|
|
|
|
|
|
|
|
|
|
if (f.checkToken()) {
|
|
|
|
if (f.checkToken()) {
|
|
|
|
|
|
|
|
|
|
|
|
var url = '/contractAdmin/ordersByDate/' + f.getValueOf("date").toString().substr(0, 10);
|
|
|
|
var url = '/contractAdmin/ordersByDate/' + f.getValueOf("date").toString().substr(0, 10);
|
|
|
|
var p = f.getValueOf("placeId");
|
|
|
|
var p = f.getValueOf("placeId");
|
|
|
|
if (p != null) url += "/"+p;
|
|
|
|
if (p != null)
|
|
|
|
|
|
|
|
url += "/" + p;
|
|
|
|
throw Redirect(url);
|
|
|
|
throw Redirect(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
var d1 = date.setHourMinute(0, 0);
|
|
|
|
var d1 = date.setHourMinute(0, 0);
|
|
|
|
var d2 = date.setHourMinute(23, 59);
|
|
|
|
var d2 = date.setHourMinute(23, 59);
|
|
|
|
var contracts = app.user.amap.getActiveContracts(true);
|
|
|
|
var contracts = app.user.amap.getActiveContracts(true);
|
|
|
|
var cconst = [];
|
|
|
|
var cconst = [];
|
|
|
|
var cvar = [];
|
|
|
|
var cvar = [];
|
|
|
|
for (c in contracts) {
|
|
|
|
for (c in contracts) {
|
|
|
|
if (c.type == db.Contract.TYPE_CONSTORDERS) cconst.push(c.id);
|
|
|
|
if (c.type == db.Contract.TYPE_CONSTORDERS)
|
|
|
|
if (c.type == db.Contract.TYPE_VARORDER) cvar.push(c.id);
|
|
|
|
cconst.push(c.id);
|
|
|
|
|
|
|
|
if (c.type == db.Contract.TYPE_VARORDER)
|
|
|
|
|
|
|
|
cvar.push(c.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// distribs
|
|
|
|
// distribs
|
|
|
|
var vdistribs = db.Distribution.manager.search(($contractId in cvar) && $date >= d1 && $date <= d2 && place.id == $placeId, false);
|
|
|
|
var vdistribs = db.Distribution.manager.search(($contractId in cvar) && $date >= d1 && $date <= d2 && place.id == $placeId, false);
|
|
|
|
var cdistribs = db.Distribution.manager.search(($contractId in cconst) && $date >= d1 && $date <= d2 && place.id == $placeId, false);
|
|
|
|
var cdistribs = db.Distribution.manager.search(($contractId in cconst) && $date >= d1 && $date <= d2 && place.id == $placeId, false);
|
|
|
|
|
|
|
|
|
|
|
|
if (vdistribs.length == 0 && cdistribs.length == 0) throw Error("/contractAdmin/ordersByDate", t._("There is no delivery at this date"));
|
|
|
|
if (vdistribs.length == 0 && cdistribs.length == 0)
|
|
|
|
|
|
|
|
throw Error("/contractAdmin/ordersByDate", t._("There is no delivery at this date"));
|
|
|
|
|
|
|
|
|
|
|
|
// varying orders
|
|
|
|
// varying orders
|
|
|
|
var varorders = db.UserContract.manager.search($distributionId in vdistribs.getIds(), {orderBy: userId});
|
|
|
|
var varorders = db.UserContract.manager.search($distributionId in vdistribs.getIds(), {orderBy: userId});
|
|
|
@@ -372,13 +358,11 @@ class ContractAdmin extends Controller
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Global view on orders, producer view
|
|
|
|
* Global view on orders, producer view
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@tpl('contractadmin/vendorsByDate.mtt')
|
|
|
|
@tpl('contractadmin/vendorsByDate.mtt')
|
|
|
|
function doVendorsByDate(date:Date, place:db.Place) {
|
|
|
|
function doVendorsByDate(date:Date, place:db.Place) {
|
|
|
|
|
|
|
|
|
|
|
|
var d1 = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
|
|
|
|
var d1 = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
|
|
|
|
var d2 = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59);
|
|
|
|
var d2 = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59);
|
|
|
|
var contracts = app.user.amap.getActiveContracts(true);
|
|
|
|
var contracts = app.user.amap.getActiveContracts(true);
|
|
|
@@ -387,8 +371,8 @@ class ContractAdmin extends Controller
|
|
|
|
// distribs for both types in active contracts
|
|
|
|
// distribs for both types in active contracts
|
|
|
|
var distribs = db.Distribution.manager.search(($contractId in cids) && $date >= d1 && $date <= d2 && $place == place, false);
|
|
|
|
var distribs = db.Distribution.manager.search(($contractId in cids) && $date >= d1 && $date <= d2 && $place == place, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (distribs.length == 0)
|
|
|
|
if ( distribs.length == 0 ) throw Error("/contractAdmin/ordersByDate", t._("There is no delivery at this date"));
|
|
|
|
throw Error("/contractAdmin/ordersByDate", t._("There is no delivery at this date"));
|
|
|
|
|
|
|
|
|
|
|
|
var out = new Map<Int, Dynamic>(); // key : vendor id
|
|
|
|
var out = new Map<Int, Dynamic>(); // key : vendor id
|
|
|
|
|
|
|
|
|
|
|
@@ -399,10 +383,8 @@ class ContractAdmin extends Controller
|
|
|
|
if (o == null) {
|
|
|
|
if (o == null) {
|
|
|
|
out.set(vid, {contract: d.contract, distrib: d, orders: service.ReportService.getOrdersByProduct(d)});
|
|
|
|
out.set(vid, {contract: d.contract, distrib: d, orders: service.ReportService.getOrdersByProduct(d)});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
// add orders with existing ones
|
|
|
|
// add orders with existing ones
|
|
|
|
for (x in service.ReportService.getOrdersByProduct(d)) {
|
|
|
|
for (x in service.ReportService.getOrdersByProduct(d)) {
|
|
|
|
|
|
|
|
|
|
|
|
// find record in existing orders
|
|
|
|
// find record in existing orders
|
|
|
|
var f:Dynamic = Lambda.find(o.orders, function(a) return a.pid == x.pid);
|
|
|
|
var f:Dynamic = Lambda.find(o.orders, function(a) return a.pid == x.pid);
|
|
|
|
if (f == null) {
|
|
|
|
if (f == null) {
|
|
|
@@ -422,13 +404,11 @@ class ContractAdmin extends Controller
|
|
|
|
view.date = date;
|
|
|
|
view.date = date;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Global view on orders, producer view
|
|
|
|
* Global view on orders, producer view
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@tpl('contractadmin/vendorsByTimeFrame.mtt')
|
|
|
|
@tpl('contractadmin/vendorsByTimeFrame.mtt')
|
|
|
|
function doVendorsByTimeFrame(from:Date, to:Date) {
|
|
|
|
function doVendorsByTimeFrame(from:Date, to:Date) {
|
|
|
|
|
|
|
|
|
|
|
|
var d1 = tools.DateTool.setHourMinute(from, 0, 0);
|
|
|
|
var d1 = tools.DateTool.setHourMinute(from, 0, 0);
|
|
|
|
var d2 = tools.DateTool.setHourMinute(to, 23, 59);
|
|
|
|
var d2 = tools.DateTool.setHourMinute(to, 23, 59);
|
|
|
|
var contracts = app.user.amap.getActiveContracts(true);
|
|
|
|
var contracts = app.user.amap.getActiveContracts(true);
|
|
|
@@ -436,7 +416,8 @@ class ContractAdmin extends Controller
|
|
|
|
|
|
|
|
|
|
|
|
// distribs for both types in active contracts
|
|
|
|
// distribs for both types in active contracts
|
|
|
|
var distribs = db.Distribution.manager.search(($contractId in cids) && $date >= d1 && $date <= d2 /*&& $place==place*/, false);
|
|
|
|
var distribs = db.Distribution.manager.search(($contractId in cids) && $date >= d1 && $date <= d2 /*&& $place==place*/, false);
|
|
|
|
if ( distribs.length == 0 ) throw Error("/contractAdmin/", t._("There is no delivery during this period"));
|
|
|
|
if (distribs.length == 0)
|
|
|
|
|
|
|
|
throw Error("/contractAdmin/", t._("There is no delivery during this period"));
|
|
|
|
|
|
|
|
|
|
|
|
var out = new Map<Int, {contract:db.Contract, distrib:db.Distribution, orders:Array<OrderByProduct>}>(); // key : vendor id
|
|
|
|
var out = new Map<Int, {contract:db.Contract, distrib:db.Distribution, orders:Array<OrderByProduct>}>(); // key : vendor id
|
|
|
|
|
|
|
|
|
|
|
@@ -447,10 +428,8 @@ class ContractAdmin extends Controller
|
|
|
|
if (o == null) {
|
|
|
|
if (o == null) {
|
|
|
|
out.set(vid, {contract: d.contract, distrib: d, orders: service.ReportService.getOrdersByProduct(d)});
|
|
|
|
out.set(vid, {contract: d.contract, distrib: d, orders: service.ReportService.getOrdersByProduct(d)});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
// add orders with existing ones
|
|
|
|
// add orders with existing ones
|
|
|
|
for (x in service.ReportService.getOrdersByProduct(d)) {
|
|
|
|
for (x in service.ReportService.getOrdersByProduct(d)) {
|
|
|
|
|
|
|
|
|
|
|
|
// find record in existing orders
|
|
|
|
// find record in existing orders
|
|
|
|
var f:OrderByProduct = Lambda.find(o.orders, function(a:OrderByProduct) return a.pid == x.pid);
|
|
|
|
var f:OrderByProduct = Lambda.find(o.orders, function(a:OrderByProduct) return a.pid == x.pid);
|
|
|
|
if (f == null) {
|
|
|
|
if (f == null) {
|
|
|
@@ -476,11 +455,28 @@ class ContractAdmin extends Controller
|
|
|
|
var orders = [];
|
|
|
|
var orders = [];
|
|
|
|
for (x in out) {
|
|
|
|
for (x in out) {
|
|
|
|
// empty line
|
|
|
|
// empty line
|
|
|
|
orders.push({"quantity":null, "pname":null, "ref":null, "priceHT":null, "priceTTC":null, "totalHT":null, "totalTTC":null});
|
|
|
|
orders.push({
|
|
|
|
orders.push({"quantity":null, "pname":x.contract.vendor.name, "ref":null, "priceHT":null, "priceTTC":null, "totalHT":null, "totalTTC":null});
|
|
|
|
"quantity": null,
|
|
|
|
|
|
|
|
"pname": null,
|
|
|
|
|
|
|
|
"ref": null,
|
|
|
|
|
|
|
|
"priceHT": null,
|
|
|
|
|
|
|
|
"priceTTC": null,
|
|
|
|
|
|
|
|
"totalHT": null,
|
|
|
|
|
|
|
|
"totalTTC": null
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
orders.push({
|
|
|
|
|
|
|
|
"quantity": null,
|
|
|
|
|
|
|
|
"pname": x.contract.vendor.name,
|
|
|
|
|
|
|
|
"ref": null,
|
|
|
|
|
|
|
|
"priceHT": null,
|
|
|
|
|
|
|
|
"priceTTC": null,
|
|
|
|
|
|
|
|
"totalHT": null,
|
|
|
|
|
|
|
|
"totalTTC": null
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
for (o in x.orders) {
|
|
|
|
for (o in x.orders) {
|
|
|
|
if(o.vat==null) o.vat = 0;
|
|
|
|
if (o.vat == null)
|
|
|
|
|
|
|
|
o.vat = 0;
|
|
|
|
orders.push({
|
|
|
|
orders.push({
|
|
|
|
"quantity": view.formatNum(o.quantity),
|
|
|
|
"quantity": view.formatNum(o.quantity),
|
|
|
|
"pname": o.pname,
|
|
|
|
"pname": o.pname,
|
|
|
@@ -506,9 +502,9 @@ class ContractAdmin extends Controller
|
|
|
|
});
|
|
|
|
});
|
|
|
|
totalTTC = 0;
|
|
|
|
totalTTC = 0;
|
|
|
|
totalHT = 0;
|
|
|
|
totalHT = 0;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var fileName = t._("Orders from the ::fromDate:: to the ::toDate:: per supplier.csv", {fromDate:from.toString().substr(0, 10), toDate:to.toString().substr(0, 10)});
|
|
|
|
var fileName = t._("Orders from the ::fromDate:: to the ::toDate:: per supplier.csv",
|
|
|
|
|
|
|
|
{fromDate: from.toString().substr(0, 10), toDate: to.toString().substr(0, 10)});
|
|
|
|
sugoi.tools.Csv.printCsvDataFromObjects(orders, ["quantity", "pname", "ref", "priceHT", "priceTTC", "totalHT", "totalTTC"], fileName);
|
|
|
|
sugoi.tools.Csv.printCsvDataFromObjects(orders, ["quantity", "pname", "ref", "priceHT", "priceTTC", "totalHT", "totalTTC"], fileName);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -517,7 +513,6 @@ class ContractAdmin extends Controller
|
|
|
|
view.to = to;
|
|
|
|
view.to = to;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Overview of orders for this contract in backoffice
|
|
|
|
* Overview of orders for this contract in backoffice
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@@ -527,7 +522,8 @@ class ContractAdmin extends Controller
|
|
|
|
sendNav(contract);
|
|
|
|
sendNav(contract);
|
|
|
|
|
|
|
|
|
|
|
|
// Checking permissions
|
|
|
|
// Checking permissions
|
|
|
|
if (!app.user.canManageContract(contract)) throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
if (!app.user.canManageContract(contract))
|
|
|
|
|
|
|
|
throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
if (contract.type == db.Contract.TYPE_VARORDER && args != null && args.d == null) {
|
|
|
|
if (contract.type == db.Contract.TYPE_VARORDER && args != null && args.d == null) {
|
|
|
|
throw Redirect("/contractAdmin/selectDistrib/" + contract.id);
|
|
|
|
throw Redirect("/contractAdmin/selectDistrib/" + contract.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -544,7 +540,6 @@ class ContractAdmin extends Controller
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw Ok("/contractAdmin/orders/" + contract.id, t._("The order has been deleted."));
|
|
|
|
throw Ok("/contractAdmin/orders/" + contract.id, t._("The order has been deleted."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var d = null;
|
|
|
|
var d = null;
|
|
|
@@ -556,7 +551,6 @@ class ContractAdmin extends Controller
|
|
|
|
var orders = db.UserContract.getOrders(contract, d, app.params.exists("csv"));
|
|
|
|
var orders = db.UserContract.getOrders(contract, d, app.params.exists("csv"));
|
|
|
|
|
|
|
|
|
|
|
|
if (!app.params.exists("csv")) {
|
|
|
|
if (!app.params.exists("csv")) {
|
|
|
|
|
|
|
|
|
|
|
|
// show orders on disabled products
|
|
|
|
// show orders on disabled products
|
|
|
|
var disabledProducts = 0;
|
|
|
|
var disabledProducts = 0;
|
|
|
|
for (o in orders) {
|
|
|
|
for (o in orders) {
|
|
|
@@ -569,18 +563,16 @@ class ContractAdmin extends Controller
|
|
|
|
view.disabledProducts = disabledProducts;
|
|
|
|
view.disabledProducts = disabledProducts;
|
|
|
|
view.orders = orders;
|
|
|
|
view.orders = orders;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* hidden feature : updates orders by setting current product price.
|
|
|
|
* hidden feature : updates orders by setting current product price.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function doUpdatePrices(contract:db.Contract, args:{?d:db.Distribution}) {
|
|
|
|
function doUpdatePrices(contract:db.Contract, args:{?d:db.Distribution}) {
|
|
|
|
|
|
|
|
|
|
|
|
sendNav(contract);
|
|
|
|
sendNav(contract);
|
|
|
|
|
|
|
|
|
|
|
|
if (!app.user.canManageContract(contract)) throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
if (!app.user.canManageContract(contract))
|
|
|
|
|
|
|
|
throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
if (contract.type == db.Contract.TYPE_VARORDER && args.d == null) {
|
|
|
|
if (contract.type == db.Contract.TYPE_VARORDER && args.d == null) {
|
|
|
|
throw Redirect("/contractAdmin/selectDistrib/" + contract.id);
|
|
|
|
throw Redirect("/contractAdmin/selectDistrib/" + contract.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -597,7 +589,6 @@ class ContractAdmin extends Controller
|
|
|
|
o.feesRate = contract.percentageValue;
|
|
|
|
o.feesRate = contract.percentageValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
o.update();
|
|
|
|
o.update();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw Ok("/contractAdmin/orders/" + contract.id + "?d=" + args.d.id, t._("Prices are now up to date."));
|
|
|
|
throw Ok("/contractAdmin/orders/" + contract.id + "?d=" + args.d.id, t._("Prices are now up to date."));
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -607,9 +598,9 @@ class ContractAdmin extends Controller
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@tpl("form.mtt")
|
|
|
|
@tpl("form.mtt")
|
|
|
|
function doDuplicate(contract:db.Contract) {
|
|
|
|
function doDuplicate(contract:db.Contract) {
|
|
|
|
|
|
|
|
|
|
|
|
sendNav(contract);
|
|
|
|
sendNav(contract);
|
|
|
|
if (!app.user.isAmapManager()) throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
if (!app.user.isAmapManager())
|
|
|
|
|
|
|
|
throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
|
|
|
|
|
|
|
|
view.title = "Dupliquer le contrat '" + contract.name + "'";
|
|
|
|
view.title = "Dupliquer le contrat '" + contract.name + "'";
|
|
|
|
var form = new Form("duplicate");
|
|
|
|
var form = new Form("duplicate");
|
|
|
@@ -619,7 +610,6 @@ class ContractAdmin extends Controller
|
|
|
|
form.addElement(new Checkbox("copyDeliveries", t._("Copy deliveries"), true));
|
|
|
|
form.addElement(new Checkbox("copyDeliveries", t._("Copy deliveries"), true));
|
|
|
|
|
|
|
|
|
|
|
|
if (form.checkToken()) {
|
|
|
|
if (form.checkToken()) {
|
|
|
|
|
|
|
|
|
|
|
|
var nc = new db.Contract();
|
|
|
|
var nc = new db.Contract();
|
|
|
|
nc.name = form.getValueOf("name");
|
|
|
|
nc.name = form.getValueOf("name");
|
|
|
|
nc.startDate = contract.startDate;
|
|
|
|
nc.startDate = contract.startDate;
|
|
|
@@ -641,7 +631,6 @@ class ContractAdmin extends Controller
|
|
|
|
ua.giveRight(ContractAdmin(nc.id));
|
|
|
|
ua.giveRight(ContractAdmin(nc.id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (form.getValueOf("copyProducts") == true) {
|
|
|
|
if (form.getValueOf("copyProducts") == true) {
|
|
|
|
var prods = contract.getProducts();
|
|
|
|
var prods = contract.getProducts();
|
|
|
|
for (source_p in prods) {
|
|
|
|
for (source_p in prods) {
|
|
|
@@ -695,27 +684,27 @@ class ContractAdmin extends Controller
|
|
|
|
view.form = form;
|
|
|
|
view.form = form;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Orders grouped by product
|
|
|
|
* Orders grouped by product
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@tpl("contractadmin/ordersByProduct.mtt")
|
|
|
|
@tpl("contractadmin/ordersByProduct.mtt")
|
|
|
|
function doOrdersByProduct(contract:db.Contract, args:{?d:db.Distribution}) {
|
|
|
|
function doOrdersByProduct(contract:db.Contract, args:{?d:db.Distribution}) {
|
|
|
|
|
|
|
|
|
|
|
|
sendNav(contract);
|
|
|
|
sendNav(contract);
|
|
|
|
if (!app.user.canManageContract(contract)) throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
if (!app.user.canManageContract(contract))
|
|
|
|
if (contract.type == db.Contract.TYPE_VARORDER && args.d == null ) throw Redirect("/contractAdmin/selectDistrib/" + contract.id);
|
|
|
|
throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
|
|
|
|
if (contract.type == db.Contract.TYPE_VARORDER && args.d == null)
|
|
|
|
|
|
|
|
throw Redirect("/contractAdmin/selectDistrib/" + contract.id);
|
|
|
|
|
|
|
|
|
|
|
|
var d = args != null ? args.d : null;
|
|
|
|
var d = args != null ? args.d : null;
|
|
|
|
if (d == null) d = contract.getDistribs(false).first();
|
|
|
|
if (d == null)
|
|
|
|
if (d == null) throw Error("/contractAdmin/orders/"+contract.id,t._("There is no delivery in this contract, please create at least one distribution."));
|
|
|
|
d = contract.getDistribs(false).first();
|
|
|
|
|
|
|
|
if (d == null)
|
|
|
|
|
|
|
|
throw Error("/contractAdmin/orders/" + contract.id, t._("There is no delivery in this contract, please create at least one distribution."));
|
|
|
|
|
|
|
|
|
|
|
|
var orders = service.ReportService.getOrdersByProduct(d, app.params.exists("csv"));
|
|
|
|
var orders = service.ReportService.getOrdersByProduct(d, app.params.exists("csv"));
|
|
|
|
view.orders = orders;
|
|
|
|
view.orders = orders;
|
|
|
|
view.distribution = d;
|
|
|
|
view.distribution = d;
|
|
|
|
view.c = contract;
|
|
|
|
view.c = contract;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@@ -723,17 +712,21 @@ class ContractAdmin extends Controller
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@tpl("contractadmin/ordersByProductList.mtt")
|
|
|
|
@tpl("contractadmin/ordersByProductList.mtt")
|
|
|
|
function doOrdersByProductList(contract:db.Contract, args:{?d:db.Distribution}) {
|
|
|
|
function doOrdersByProductList(contract:db.Contract, args:{?d:db.Distribution}) {
|
|
|
|
|
|
|
|
|
|
|
|
sendNav(contract);
|
|
|
|
sendNav(contract);
|
|
|
|
if (!app.user.canManageContract(contract)) throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
if (!app.user.canManageContract(contract))
|
|
|
|
if (contract.type == db.Contract.TYPE_VARORDER && args.d == null ) throw Redirect("/contractAdmin/selectDistrib/" + contract.id);
|
|
|
|
throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
|
|
|
|
if (contract.type == db.Contract.TYPE_VARORDER && args.d == null)
|
|
|
|
|
|
|
|
throw Redirect("/contractAdmin/selectDistrib/" + contract.id);
|
|
|
|
|
|
|
|
|
|
|
|
if (contract.type == db.Contract.TYPE_VARORDER ) view.distribution = args.d;
|
|
|
|
if (contract.type == db.Contract.TYPE_VARORDER)
|
|
|
|
|
|
|
|
view.distribution = args.d;
|
|
|
|
view.c = contract;
|
|
|
|
view.c = contract;
|
|
|
|
view.group = contract.amap;
|
|
|
|
view.group = contract.amap;
|
|
|
|
var d = args != null ? args.d : null;
|
|
|
|
var d = args != null ? args.d : null;
|
|
|
|
if (d == null) d = contract.getDistribs(false).first();
|
|
|
|
if (d == null)
|
|
|
|
if (d == null) throw t._("No delivery in this contract");
|
|
|
|
d = contract.getDistribs(false).first();
|
|
|
|
|
|
|
|
if (d == null)
|
|
|
|
|
|
|
|
throw t._("No delivery in this contract");
|
|
|
|
|
|
|
|
|
|
|
|
var orders = service.ReportService.getOrdersByProduct(d, false);
|
|
|
|
var orders = service.ReportService.getOrdersByProduct(d, false);
|
|
|
|
view.orders = orders;
|
|
|
|
view.orders = orders;
|
|
|
@@ -747,18 +740,20 @@ class ContractAdmin extends Controller
|
|
|
|
view.nav.push("distributions");
|
|
|
|
view.nav.push("distributions");
|
|
|
|
sendNav(contract);
|
|
|
|
sendNav(contract);
|
|
|
|
|
|
|
|
|
|
|
|
if (!app.user.canManageContract(contract)) throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
if (!app.user.canManageContract(contract))
|
|
|
|
|
|
|
|
throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
view.c = contract;
|
|
|
|
view.c = contract;
|
|
|
|
|
|
|
|
|
|
|
|
if (args != null && args.old) {
|
|
|
|
if (args != null && args.old) {
|
|
|
|
// display also old deliveries
|
|
|
|
// display also old deliveries
|
|
|
|
view.deliveries = contract.getDistribs(false);
|
|
|
|
view.deliveries = contract.getDistribs(false);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
view.deliveries = db.Distribution.manager.search($end > DateTools.delta(Date.now(), -1000.0 * 60 * 60 * 24 * 30) && $contract == contract, { orderBy:date} );
|
|
|
|
view.deliveries = db.Distribution.manager.search($end > DateTools.delta(Date.now(), -1000.0 * 60 * 60 * 24 * 30)
|
|
|
|
|
|
|
|
&& $contract == contract,
|
|
|
|
|
|
|
|
{orderBy: date});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
view.cycles = db.DistributionCycle.manager.search($contract == contract && $endDate > Date.now(), false);
|
|
|
|
view.cycles = db.DistributionCycle.manager.search($contract == contract && $endDate > Date.now(), false);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@@ -769,16 +764,19 @@ class ContractAdmin extends Controller
|
|
|
|
view.nav.push("distributions");
|
|
|
|
view.nav.push("distributions");
|
|
|
|
sendNav(contract);
|
|
|
|
sendNav(contract);
|
|
|
|
|
|
|
|
|
|
|
|
if (!app.user.canManageContract(contract)) throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
if (!app.user.canManageContract(contract))
|
|
|
|
|
|
|
|
throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
|
|
|
|
|
|
|
|
var distribs = contract.getDistribs(false);
|
|
|
|
var distribs = contract.getDistribs(false);
|
|
|
|
var userCount = new Map<Int, Int>();
|
|
|
|
var userCount = new Map<Int, Int>();
|
|
|
|
var suscribers = contract.getUsers();
|
|
|
|
var suscribers = contract.getUsers();
|
|
|
|
for( u in suscribers) userCount[u.id] = 0;
|
|
|
|
for (u in suscribers)
|
|
|
|
|
|
|
|
userCount[u.id] = 0;
|
|
|
|
// populate
|
|
|
|
// populate
|
|
|
|
|
|
|
|
|
|
|
|
var increment = function(user:db.User) {
|
|
|
|
var increment = function(user:db.User) {
|
|
|
|
if(user==null) return;
|
|
|
|
if (user == null)
|
|
|
|
|
|
|
|
return;
|
|
|
|
var x = userCount[user.id];
|
|
|
|
var x = userCount[user.id];
|
|
|
|
if (x == null) {
|
|
|
|
if (x == null) {
|
|
|
|
userCount[user.id] = 1;
|
|
|
|
userCount[user.id] = 1;
|
|
|
@@ -802,7 +800,6 @@ class ContractAdmin extends Controller
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
out2.push({user: db.User.manager.get(k), count: userCount[k]});
|
|
|
|
out2.push({user: db.User.manager.get(k), count: userCount[k]});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var num = (distribs.length * contract.distributorNum) / suscribers.length;
|
|
|
|
var num = (distribs.length * contract.distributorNum) / suscribers.length;
|
|
|
@@ -821,18 +818,20 @@ class ContractAdmin extends Controller
|
|
|
|
view.nav.push("view");
|
|
|
|
view.nav.push("view");
|
|
|
|
sendNav(contract);
|
|
|
|
sendNav(contract);
|
|
|
|
|
|
|
|
|
|
|
|
if (!app.user.canManageContract(contract)) throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
if (!app.user.canManageContract(contract))
|
|
|
|
|
|
|
|
throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
view.c = view.contract = contract;
|
|
|
|
view.c = view.contract = contract;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@tpl("contractadmin/stats.mtt")
|
|
|
|
@tpl("contractadmin/stats.mtt")
|
|
|
|
function doStats(contract:db.Contract, ?args:{stat:Int}) {
|
|
|
|
function doStats(contract:db.Contract, ?args:{stat:Int}) {
|
|
|
|
sendNav(contract);
|
|
|
|
sendNav(contract);
|
|
|
|
if (!app.user.canManageContract(contract)) throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
if (!app.user.canManageContract(contract))
|
|
|
|
|
|
|
|
throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
view.c = contract;
|
|
|
|
view.c = contract;
|
|
|
|
|
|
|
|
|
|
|
|
if (args == null) args = { stat:0 };
|
|
|
|
if (args == null)
|
|
|
|
|
|
|
|
args = {stat: 0};
|
|
|
|
view.stat = args.stat;
|
|
|
|
view.stat = args.stat;
|
|
|
|
var pids = contract.getProducts().map(function(x) return x.id);
|
|
|
|
var pids = contract.getProducts().map(function(x) return x.id);
|
|
|
|
switch (args.stat) {
|
|
|
|
switch (args.stat) {
|
|
|
@@ -842,7 +841,10 @@ class ContractAdmin extends Controller
|
|
|
|
if (pids.length == 0) {
|
|
|
|
if (pids.length == 0) {
|
|
|
|
view.anciennete = new List();
|
|
|
|
view.anciennete = new List();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
view.anciennete = sys.db.Manager.cnx.request("select YEAR(u.cdate) as uyear ,count(DISTINCT u.id) as cnt from User u, UserContract up where up.userId=u.id and up.productId IN (" + pids.join(",") + ") group by uyear;").results();
|
|
|
|
view.anciennete = sys.db.Manager.cnx.request("select YEAR(u.cdate) as uyear ,count(DISTINCT u.id) as cnt from User u, UserContract up where up.userId=u.id and up.productId IN ("
|
|
|
|
|
|
|
|
+ pids.join(",")
|
|
|
|
|
|
|
|
+ ") group by uyear;")
|
|
|
|
|
|
|
|
.results();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
@@ -851,7 +853,10 @@ class ContractAdmin extends Controller
|
|
|
|
var total = 0;
|
|
|
|
var total = 0;
|
|
|
|
var totalPrice = 0;
|
|
|
|
var totalPrice = 0;
|
|
|
|
if (pids.length != 0) {
|
|
|
|
if (pids.length != 0) {
|
|
|
|
var repartition = sys.db.Manager.cnx.request("select sum(quantity) as quantity,productId,p.name,p.price from UserContract up, Product p where up.productId IN (" + contract.getProducts().map(function(x) return x.id).join(",") + ") and up.productId=p.id group by productId").results();
|
|
|
|
var repartition = sys.db.Manager.cnx.request("select sum(quantity) as quantity,productId,p.name,p.price from UserContract up, Product p where up.productId IN ("
|
|
|
|
|
|
|
|
+ contract.getProducts().map(function(x) return x.id).join(",")
|
|
|
|
|
|
|
|
+ ") and up.productId=p.id group by productId")
|
|
|
|
|
|
|
|
.results();
|
|
|
|
for (r in repartition) {
|
|
|
|
for (r in repartition) {
|
|
|
|
total += r.quantity;
|
|
|
|
total += r.quantity;
|
|
|
|
totalPrice += r.price * r.quantity;
|
|
|
|
totalPrice += r.price * r.quantity;
|
|
|
@@ -861,32 +866,29 @@ class ContractAdmin extends Controller
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (app.params.exists("csv")) {
|
|
|
|
if (app.params.exists("csv")) {
|
|
|
|
sugoi.tools.Csv.printCsvDataFromObjects(Lambda.array(repartition), ["quantity","productId","name","price","percent"], "stats-" + contract.name+".csv");
|
|
|
|
sugoi.tools.Csv.printCsvDataFromObjects(Lambda.array(repartition), ["quantity", "productId", "name", "price", "percent"],
|
|
|
|
|
|
|
|
"stats-" + contract.name + ".csv");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
view.repartition = repartition;
|
|
|
|
view.repartition = repartition;
|
|
|
|
view.totalQuantity = total;
|
|
|
|
view.totalQuantity = total;
|
|
|
|
view.totalPrice = totalPrice;
|
|
|
|
view.totalPrice = totalPrice;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Efface une commande
|
|
|
|
* Efface une commande
|
|
|
|
* @param uc
|
|
|
|
* @param uc
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function doDelete(uc:UserContract) {
|
|
|
|
function doDelete(uc:UserContract) {
|
|
|
|
if (!app.user.canManageContract(uc.product.contract)) throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
if (!app.user.canManageContract(uc.product.contract))
|
|
|
|
|
|
|
|
throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
uc.lock();
|
|
|
|
uc.lock();
|
|
|
|
uc.delete();
|
|
|
|
uc.delete();
|
|
|
|
throw Ok('/contractAdmin/orders/' + uc.product.contract.id, t._("The contract has been canceled"));
|
|
|
|
throw Ok('/contractAdmin/orders/' + uc.product.contract.id, t._("The contract has been canceled"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@tpl("contractadmin/selectDistrib.mtt")
|
|
|
|
@tpl("contractadmin/selectDistrib.mtt")
|
|
|
|
function doSelectDistrib(c:db.Contract, ?args:{old:Bool}) {
|
|
|
|
function doSelectDistrib(c:db.Contract, ?args:{old:Bool}) {
|
|
|
|
view.nav.push("orders");
|
|
|
|
view.nav.push("orders");
|
|
|
@@ -898,7 +900,6 @@ class ContractAdmin extends Controller
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
view.distributions = c.getDistribs(true);
|
|
|
|
view.distributions = c.getDistribs(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@@ -909,8 +910,10 @@ class ContractAdmin extends Controller
|
|
|
|
view.nav.push("orders");
|
|
|
|
view.nav.push("orders");
|
|
|
|
sendNav(c);
|
|
|
|
sendNav(c);
|
|
|
|
|
|
|
|
|
|
|
|
if (!app.user.canManageContract(c)) throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
if (!app.user.canManageContract(c))
|
|
|
|
if (args.d != null && args.d.validated) throw Error("/contractAdmin/orders/" + c.id + "?d=" + args.d.id, t._("This delivery has been already validated"));
|
|
|
|
throw Error("/", t._("You do not have the authorization to manage this contract"));
|
|
|
|
|
|
|
|
if (args.d != null && args.d.validated)
|
|
|
|
|
|
|
|
throw Error("/contractAdmin/orders/" + c.id + "?d=" + args.d.id, t._("This delivery has been already validated"));
|
|
|
|
|
|
|
|
|
|
|
|
view.c = view.contract = c;
|
|
|
|
view.c = view.contract = c;
|
|
|
|
view.u = user;
|
|
|
|
view.u = user;
|
|
|
@@ -918,11 +921,8 @@ class ContractAdmin extends Controller
|
|
|
|
|
|
|
|
|
|
|
|
// need to select a distribution for varying orders contracts
|
|
|
|
// need to select a distribution for varying orders contracts
|
|
|
|
if (c.type == db.Contract.TYPE_VARORDER && args.d == null) {
|
|
|
|
if (c.type == db.Contract.TYPE_VARORDER && args.d == null) {
|
|
|
|
|
|
|
|
|
|
|
|
throw Redirect("/contractAdmin/orders/" + c.id);
|
|
|
|
throw Redirect("/contractAdmin/orders/" + c.id);
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
// members of the group
|
|
|
|
// members of the group
|
|
|
|
view.users = app.user.amap.getMembersFormElementData();
|
|
|
|
view.users = app.user.amap.getMembersFormElementData();
|
|
|
|
|
|
|
|
|
|
|
@@ -939,13 +939,13 @@ class ContractAdmin extends Controller
|
|
|
|
order = db.UserContract.manager.select($user == user && $productId == p.id, true);
|
|
|
|
order = db.UserContract.manager.select($user == user && $productId == p.id, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (order != null) ua.order = order;
|
|
|
|
if (order != null)
|
|
|
|
|
|
|
|
ua.order = order;
|
|
|
|
userOrders.push(ua);
|
|
|
|
userOrders.push(ua);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// form check
|
|
|
|
// form check
|
|
|
|
if (checkToken()) {
|
|
|
|
if (checkToken()) {
|
|
|
|
|
|
|
|
|
|
|
|
// it's a new order, the user has been defined in the form.
|
|
|
|
// it's a new order, the user has been defined in the form.
|
|
|
|
if (user == null) {
|
|
|
|
if (user == null) {
|
|
|
|
user = db.User.manager.get(Std.parseInt(app.params.get("user")));
|
|
|
|
user = db.User.manager.get(Std.parseInt(app.params.get("user")));
|
|
|
@@ -953,7 +953,8 @@ class ContractAdmin extends Controller
|
|
|
|
var user = app.params.get("user");
|
|
|
|
var user = app.params.get("user");
|
|
|
|
throw t._("Unable to find user #::num::", {num: user});
|
|
|
|
throw t._("Unable to find user #::num::", {num: user});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!user.isMemberOf(app.user.amap)) throw user + " is not member of this group";
|
|
|
|
if (!user.isMemberOf(app.user.amap))
|
|
|
|
|
|
|
|
throw user + " is not member of this group";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// get distrib if needed
|
|
|
|
// get distrib if needed
|
|
|
@@ -967,11 +968,11 @@ class ContractAdmin extends Controller
|
|
|
|
for (k in app.params.keys()) {
|
|
|
|
for (k in app.params.keys()) {
|
|
|
|
var param = app.params.get(k);
|
|
|
|
var param = app.params.get(k);
|
|
|
|
if (k.substr(0, "product".length) == "product") {
|
|
|
|
if (k.substr(0, "product".length) == "product") {
|
|
|
|
|
|
|
|
|
|
|
|
// trouve le produit dans userOrders
|
|
|
|
// trouve le produit dans userOrders
|
|
|
|
var pid = Std.parseInt(k.substr("product".length));
|
|
|
|
var pid = Std.parseInt(k.substr("product".length));
|
|
|
|
var uo = Lambda.find(userOrders, function(uo) return uo.product.id == pid);
|
|
|
|
var uo = Lambda.find(userOrders, function(uo) return uo.product.id == pid);
|
|
|
|
if (uo == null) throw t._("Unable to find product ::pid::", {pid:pid});
|
|
|
|
if (uo == null)
|
|
|
|
|
|
|
|
throw t._("Unable to find product ::pid::", {pid: pid});
|
|
|
|
|
|
|
|
|
|
|
|
// user2 ?
|
|
|
|
// user2 ?
|
|
|
|
var user2:db.User = null;
|
|
|
|
var user2:db.User = null;
|
|
|
@@ -982,8 +983,10 @@ class ContractAdmin extends Controller
|
|
|
|
var user = app.params.get("user2");
|
|
|
|
var user = app.params.get("user2");
|
|
|
|
throw t._("Unable to find user #::num::", {num: user});
|
|
|
|
throw t._("Unable to find user #::num::", {num: user});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!user2.isMemberOf(app.user.amap)) throw t._("::user:: is not part of this group",{user:user2});
|
|
|
|
if (!user2.isMemberOf(app.user.amap))
|
|
|
|
if (user.id == user2.id) throw t._("Both selected accounts must be different ones");
|
|
|
|
throw t._("::user:: is not part of this group", {user: user2});
|
|
|
|
|
|
|
|
if (user.id == user2.id)
|
|
|
|
|
|
|
|
throw t._("Both selected accounts must be different ones");
|
|
|
|
|
|
|
|
|
|
|
|
invert = app.params.get("invert" + pid) == "1";
|
|
|
|
invert = app.params.get("invert" + pid) == "1";
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -996,17 +999,21 @@ class ContractAdmin extends Controller
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
q = Std.parseInt(param);
|
|
|
|
q = Std.parseInt(param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(q==null) continue; //ignore bad qt input
|
|
|
|
if (q == null)
|
|
|
|
|
|
|
|
continue; // ignore bad qt input
|
|
|
|
|
|
|
|
|
|
|
|
// record order
|
|
|
|
// record order
|
|
|
|
if (uo.order != null) {
|
|
|
|
if (uo.order != null) {
|
|
|
|
// existing record
|
|
|
|
// existing record
|
|
|
|
var o = OrderService.edit(uo.order, q, (app.params.get("paid" + pid) == "1"), user2, invert);
|
|
|
|
var o = OrderService.edit(uo.order, q, (app.params.get("paid" + pid) == "1"), user2, invert);
|
|
|
|
if (o != null) orders.push(o);
|
|
|
|
if (o != null)
|
|
|
|
|
|
|
|
orders.push(o);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// new record
|
|
|
|
// new record
|
|
|
|
var o = OrderService.make(user, q, uo.product, distrib == null ? null : distrib.id, (app.params.get("paid" + pid) == "1"), user2, invert);
|
|
|
|
var o = OrderService.make(user, q, uo.product, distrib == null ? null : distrib.id, (app.params.get("paid" + pid) == "1"), user2,
|
|
|
|
if (o != null) orders.push(o);
|
|
|
|
invert);
|
|
|
|
|
|
|
|
if (o != null)
|
|
|
|
|
|
|
|
orders.push(o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -1023,5 +1030,4 @@ class ContractAdmin extends Controller
|
|
|
|
view.userOrders = userOrders;
|
|
|
|
view.userOrders = userOrders;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|