Dépôt officiel du code source de l'ERP OpenConcerto
/trunk/OpenConcerto/lib/jOpenDocument-1.4rc2.jar |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/trunk/OpenConcerto/lib/jOpenCalendar.jar |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/trunk/OpenConcerto/src/org/jopendocument/link/OOConnexion.java |
---|
84,8 → 84,14 |
perms.add(new RuntimePermission("modifyThread")); |
// needed by PrinterJob.getPrinterJob() |
perms.add(new RuntimePermission("queuePrintJob")); |
// ProcessBuilder.start() calls SecurityManager.checkExec() which requires |
// absolute path (or execute on "<<ALL FILES>>") |
// needed by OOConnexion.init() to find the port |
perms.add(new FilePermission("/usr/bin/lsof", "execute")); |
// macOS path |
perms.add(new FilePermission("/usr/sbin/lsof", "execute")); |
perms.add(new FilePermission("/bin/ps", "execute")); |
perms.add(new FilePermission("C:/Windows/System32/tasklist.exe", "execute")); |
perms.add(new RuntimePermission("getenv.*")); |
/trunk/OpenConcerto/src/org/jopendocument/link/OOInstallation.java |
---|
102,10 → 102,14 |
rootPaths.addAll(Arrays.asList(loRootPaths)); |
rootPaths.addAll(Arrays.asList(ooRootPaths)); |
} |
for (final String p : rootPaths) { |
if (DesktopEnvironment.test("reg", "query", p)) |
// On force à chercher dans le registre 64 bits sinon il va chercher dans le registre 32 |
// bits si os 64b et VM 32b |
if (DesktopEnvironment.test("reg", "query", p, "/reg:64")) |
return p; |
} |
return null; |
} |
123,7 → 127,8 |
// all string values for the passed registry path |
private static Map<String, String> getStringValues(final String path, final String option) throws IOException { |
final Map<String, String> values = new HashMap<String, String>(); |
final String out = DesktopEnvironment.cmdSubstitution(Runtime.getRuntime().exec(new String[] { "reg", "query", path, option })); |
// On force /reg:64 (utile si on utilise une VM 32 avec un systeme 64 bits) |
final String out = DesktopEnvironment.cmdSubstitution(Runtime.getRuntime().exec(new String[] { "reg", "query", path, option, "/reg:64" })); |
final Matcher matcher = stringValuePattern.matcher(out); |
while (matcher.find()) { |
values.put(matcher.group(1), matcher.group(2)); |
/trunk/OpenConcerto/src/org/openconcerto/utils/cc/IFactory.java |
---|
13,8 → 13,9 |
package org.openconcerto.utils.cc; |
public interface IFactory<E> { |
public interface IFactory<E> extends IExnFactory<E, RuntimeException> { |
@Override |
public abstract E createChecked(); |
} |
/trunk/OpenConcerto/src/org/openconcerto/utils/cc/CustomEquals.java |
---|
19,7 → 19,10 |
import java.util.Collection; |
import java.util.LinkedHashSet; |
import java.util.List; |
import java.util.ListIterator; |
import java.util.RandomAccess; |
import java.util.Set; |
import java.util.function.BiPredicate; |
/** |
* Allow to create a proxy object which uses a {@link HashingStrategy}. |
103,6 → 106,28 |
return CompareUtils.equals(sA, sB); |
} |
static public final <S, T1 extends S> int indexOf(final List<T1> s1, final S o, final HashingStrategy<S> s) { |
return indexOf(s1, o, s::equals); |
} |
static public final <S, T1 extends S> int indexOf(final List<T1> s1, final S o, final BiPredicate<S, S> s) { |
if (s1 instanceof RandomAccess) { |
final int stop = s1.size(); |
for (int i = 0; i < stop; i++) { |
if (s.test(s1.get(i), o)) |
return i; |
} |
} else { |
final ListIterator<T1> listIter = s1.listIterator(); |
while (listIter.hasNext()) { |
final T1 item = listIter.next(); |
if (s.test(item, o)) |
return listIter.previousIndex(); |
} |
} |
return -1; |
} |
static public class ProxyFull<S, E extends S> implements ProxyItf<E> { |
static public final <S, E extends S> Set<ProxyFull<S, E>> createSet(final HashingStrategy<S> strategy, final Collection<E> coll) { |
192,7 → 217,12 |
else |
return this.strategy.equals(this.getDelegate(), delegate2); |
} |
@Override |
public String toString() { |
return this.getClass().getSimpleName() + " using strategy " + this.getStrategy() + " for " + this.getDelegate(); |
} |
} |
/** |
* A proxy object which uses a {@link HashingStrategy}. |
/trunk/OpenConcerto/src/org/openconcerto/utils/cc/IExnFactory.java |
---|
New file |
0,0 → 1,20 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.utils.cc; |
public interface IExnFactory<E, X extends Exception> { |
public abstract E createChecked() throws X; |
} |
/trunk/OpenConcerto/src/org/openconcerto/utils/cc/Cookies.java |
---|
New file |
0,0 → 1,216 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.utils.cc; |
import java.util.Arrays; |
import java.util.Collection; |
import java.util.HashMap; |
import java.util.List; |
import java.util.Map; |
import java.util.Map.Entry; |
import java.util.Objects; |
import java.util.Set; |
import com.google.gson.reflect.TypeToken; |
import net.jcip.annotations.GuardedBy; |
import net.jcip.annotations.ThreadSafe; |
/** |
* Type-safer map (e.g. can store multiple types and collections). |
* |
* @author Sylvain |
*/ |
@ThreadSafe |
public class Cookies { |
@GuardedBy("this") |
private final Map<Object, Object> map; |
@GuardedBy("this") |
private Map<Object, Object> collectionTypes; |
public Cookies() { |
this(8); |
} |
public Cookies(final int initialCapacity) { |
this.map = new HashMap<>(initialCapacity); |
this.collectionTypes = null; |
} |
public Cookies(final Cookies source) { |
synchronized (source) { |
this.map = new HashMap<>(source.map); |
this.collectionTypes = source.collectionTypes == null ? null : new HashMap<>(source.collectionTypes); |
} |
} |
public final void putAll(final Cookies other) { |
if (this == other) |
return; |
final Map<Object, Object> map; |
final Map<Object, Object> collectionTypes; |
synchronized (other) { |
map = new HashMap<>(other.map); |
collectionTypes = other.collectionTypes == null ? null : new HashMap<>(other.collectionTypes); |
} |
synchronized (this) { |
// don't just use putAll() since it won't remove entries from collectionTypes for |
// replaced items |
for (final Entry<Object, Object> e : map.entrySet()) { |
this.put(e.getKey(), e.getValue(), collectionTypes == null ? null : collectionTypes.get(e.getKey())); |
} |
} |
} |
public final Object put(Object k, Object v) { |
return this.put(k, v, null); |
} |
private final Object putCollectionType(Object k, Object v, Object type) { |
if (type == null) |
throw new IllegalArgumentException("Null type"); |
return this.put(k, v, type); |
} |
private final synchronized Object put(Object k, Object v, Object type) { |
if (type != null) { |
if (this.collectionTypes == null) |
this.collectionTypes = new HashMap<>(4); |
this.collectionTypes.put(k, type); |
} else if (this.collectionTypes != null) { |
this.collectionTypes.remove(k); |
} |
return this.map.put(k, v); |
} |
public final <T> Object putCollection(Object k, Collection<T> v, Class<T> clazz) { |
return this.putCollectionType(k, v, clazz); |
} |
public final <K, V> Object putMap(Object k, Map<K, V> v, Class<K> keyClass, Class<V> valueClass) { |
Objects.requireNonNull(keyClass, "Key class"); |
Objects.requireNonNull(valueClass, "value class"); |
return this.putCollectionType(k, v, Arrays.asList(keyClass, valueClass)); |
} |
public final <T> Object putGeneric(Object k, T v, TypeToken<T> clazz) { |
return this.putCollectionType(k, v, clazz); |
} |
public final synchronized boolean containsKey(Object k) { |
return this.map.containsKey(k); |
} |
public final synchronized Object getObject(Object k) { |
return this.map.get(k); |
} |
public final int getInt(Object k) { |
return getObjectAs(k, Number.class).intValue(); |
} |
public final long getLong(Object k) { |
return getObjectAs(k, Number.class).longValue(); |
} |
public final Boolean getBoolean(Object k) { |
return getObjectAs(k, Boolean.class); |
} |
public final boolean getBoolean(Object k, final boolean def) { |
final Boolean res = getBoolean(k); |
return res == null ? def : res.booleanValue(); |
} |
public final String getString(Object k) { |
return getObjectAs(k, String.class); |
} |
public synchronized final <T> T getContainedObjectAs(Object key, Class<T> clazz) { |
if (!this.containsKey(key)) |
throw new IllegalArgumentException(key + " not present in this : " + this.map.keySet()); |
return this.getObjectAs(key, clazz); |
} |
public final <T> T getObjectAs(Object k, Class<T> clazz) { |
return this.getObjectAs(k, clazz, null); |
} |
public final <T> T getObjectAs(Object k, Class<T> clazz, final T defaultVal) { |
return this.getObjectAs(k, clazz, defaultVal, true); |
} |
public synchronized final <T> T getObjectAs(Object k, Class<T> clazz, final T defaultVal, final boolean useDefaultIfNullValue) { |
final Object res = this.getObject(k); |
if (res == null && (useDefaultIfNullValue || !this.containsKey(k))) |
return defaultVal; |
try { |
return clazz.cast(res); |
} catch (ClassCastException e) { |
throw new IllegalArgumentException("Couldn't access " + k + " in " + this + " as " + clazz.getSimpleName(), e); |
} |
} |
public final <T> Object checkType(Object k, Object wantedType, final String needMethodName) { |
final Object object; |
final Object type; |
synchronized (this) { |
object = this.getObject(k); |
type = this.collectionTypes == null ? null : this.collectionTypes.get(k); |
} |
// as getObject() : don't fail on null |
if (object == null) |
return null; |
if (type == null) |
throw new IllegalStateException("Wasn't stored with " + needMethodName + " : " + k); |
if (!type.equals(wantedType)) |
throw new IllegalArgumentException("Wasn't stored with the passed type : " + wantedType + " != " + type); |
return object; |
} |
public final <T> Collection<T> getCollection(Object k, Class<T> clazz) { |
final Object object = checkType(k, clazz, "putCollection()"); |
@SuppressWarnings("unchecked") |
final Collection<T> res = (Collection<T>) object; |
return res; |
} |
public final <T> List<T> getList(Object k, Class<T> clazz) { |
return (List<T>) this.getCollection(k, clazz); |
} |
public final <T> Set<T> getSet(Object k, Class<T> clazz) { |
return (Set<T>) this.getCollection(k, clazz); |
} |
public final <K, V> Map<K, V> getMap(Object k, Class<K> keyClass, Class<V> valueClass) { |
final Object object = checkType(k, Arrays.asList(keyClass, valueClass), "putMap()"); |
@SuppressWarnings("unchecked") |
final Map<K, V> res = (Map<K, V>) object; |
return res; |
} |
public final <T> T getGeneric(Object k, TypeToken<T> clazz) { |
final Object object = checkType(k, clazz, "putGeneric()"); |
@SuppressWarnings("unchecked") |
final T res = (T) object; |
return res; |
} |
@Override |
public synchronized String toString() { |
return this.getClass().getSimpleName() + " of " + this.map.keySet(); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/utils/CollectionUtils.java |
---|
18,6 → 18,7 |
import org.openconcerto.utils.cc.ITransformer; |
import org.openconcerto.utils.cc.IdentityHashSet; |
import org.openconcerto.utils.cc.IdentitySet; |
import org.openconcerto.utils.cc.LinkedIdentitySet; |
import org.openconcerto.utils.cc.Transformer; |
import java.io.Serializable; |
643,14 → 644,16 |
return collector; |
} |
@SuppressWarnings("unchecked") |
public static <T> Collection<T> subtract(final Collection<T> a, final Collection<? extends T> b) { |
return org.apache.commons.collections.CollectionUtils.subtract(a, b); |
final Collection<T> res = a instanceof IdentitySet ? new LinkedIdentitySet<>(a) : new ArrayList<>(a); |
for (Iterator<? extends T> it = b.iterator(); it.hasNext();) { |
res.remove(it.next()); |
} |
return res; |
} |
@SuppressWarnings("unchecked") |
public static <T> Collection<T> substract(final Collection<T> a, final Collection<? extends T> b) { |
return org.apache.commons.collections.CollectionUtils.subtract(a, b); |
return subtract(a, b); |
} |
public static final <T> T coalesce(T o1, T o2) { |
935,10 → 938,11 |
* @param <K> type of key. |
* @param <V> type of value. |
* @param keys the keys of the map. |
* @return a new map, if <code>keys</code> is a {@link List} it will be ordered. |
* @return a new ordered map. |
*/ |
public static <K, V> Map<K, V> createMap(Collection<? extends K> keys) { |
return fillMap(keys instanceof List ? new LinkedHashMap<K, V>(keys.size()) : new HashMap<K, V>(keys.size()), keys); |
// there's no way to tell if a Collection is ordered, so always use ordered map. |
return fillMap(new LinkedHashMap<K, V>(keys.size()), keys); |
} |
/** |
/trunk/OpenConcerto/src/org/openconcerto/utils/ooxml/XLSXFormat.java |
---|
New file |
0,0 → 1,71 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.utils.ooxml; |
import java.text.DecimalFormat; |
import java.text.Format; |
import java.text.SimpleDateFormat; |
public class XLSXFormat { |
private final int id; |
private final String format; |
private boolean isDateFormat = false; |
private Format jformat; |
public XLSXFormat(int id, String format) { |
this.id = id; |
this.format = format; |
final String f = format.toLowerCase(); |
if (f.contains("mm") || f.contains("dd") || f.contains("yy")) { |
this.isDateFormat = true; |
} |
} |
public XLSXFormat(int id, String format, boolean date) { |
this.id = id; |
this.format = format; |
this.isDateFormat = date; |
} |
public int getId() { |
return this.id; |
} |
public String getFormat() { |
return this.format; |
} |
public boolean isDateFormat() { |
return this.isDateFormat; |
} |
public String format(String txt) { |
if (this.format.equalsIgnoreCase("general")) { |
return txt; |
} |
if (this.jformat == null) { |
String javaFormat = this.format.replace("YYYY", "yyyy"); |
javaFormat = javaFormat.replace("YY", "yy"); |
javaFormat = javaFormat.replace("mm", "MM"); |
javaFormat = javaFormat.replace("dd", "DD"); |
if (this.isDateFormat) { |
this.jformat = new SimpleDateFormat(javaFormat); |
} else { |
this.jformat = new DecimalFormat(javaFormat); |
} |
} |
return this.jformat.format(txt); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/utils/ooxml/XLSXSheet.java |
---|
New file |
0,0 → 1,261 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.utils.ooxml; |
import org.openconcerto.utils.StringInputStream; |
import org.openconcerto.utils.StringUtils; |
import java.awt.Point; |
import java.io.IOException; |
import java.nio.charset.StandardCharsets; |
import java.util.ArrayList; |
import java.util.Calendar; |
import java.util.Date; |
import java.util.List; |
import java.util.regex.Matcher; |
import java.util.regex.Pattern; |
import javax.xml.parsers.DocumentBuilder; |
import javax.xml.parsers.ParserConfigurationException; |
import org.w3c.dom.Document; |
import org.w3c.dom.Node; |
import org.w3c.dom.NodeList; |
import org.xml.sax.SAXException; |
import com.ibm.icu.math.BigDecimal; |
public class XLSXSheet { |
private int columnCount; |
private int startX; |
private int startY; |
private int endX; |
private int endY; |
private static final String MINCELL = "\\$?([A-Z]+)\\$?([0-9]+)"; |
private static final Pattern minCellPattern = Pattern.compile(MINCELL); |
private final List<List<Object>> rows; |
private String id; |
private String rId; |
private String name; |
public XLSXSheet(XLSXDocument document, String id, String rId, String name, String xml) throws IOException, ParserConfigurationException, SAXException { |
this.id = id; |
this.rId = rId; |
this.name = name; |
final DocumentBuilder dBuilder = document.getDbFactory().newDocumentBuilder(); |
final Document doc = dBuilder.parse(new StringInputStream(xml, StandardCharsets.UTF_8.name())); |
doc.getDocumentElement().normalize(); |
final NodeList nList = doc.getElementsByTagName("dimension"); |
final String dimension = nList.item(0).getAttributes().getNamedItem("ref").getNodeValue(); |
final List<String> parts = StringUtils.fastSplit(dimension, ':'); |
final Point start = resolve(parts.get(0)); |
this.startX = start.x; |
this.startY = start.y; |
final Point end = resolve(parts.get(1)); |
this.endX = end.x; |
this.endY = end.y; |
this.rows = new ArrayList<>(end.y - start.y); |
this.columnCount = this.endX - this.startX + 1; |
for (int i = start.y; i <= end.y; i++) { |
List<Object> row = new ArrayList<>(); |
for (int j = 0; j < this.columnCount; j++) { |
row.add(null); |
} |
this.rows.add(row); |
} |
Calendar calendar = Calendar.getInstance(); |
NodeList nListRows = doc.getElementsByTagName("row"); |
int l1 = nListRows.getLength(); |
for (int i = 0; i < l1; i++) { |
Node r = nListRows.item(i); |
NodeList nListCells = r.getChildNodes(); |
int l2 = nListCells.getLength(); |
for (int j = 0; j < l2; j++) { |
Node c = nListCells.item(j); |
final String location = c.getAttributes().getNamedItem("r").getNodeValue(); |
final Point p = resolve(location); |
if (p == null) { |
throw new IllegalStateException("unable to parse location : " + location); |
} |
// The index of this cell's style. Style records are stored in the Styles Part. |
// The possible values for this attribute are defined by the W3C XML Schema |
// unsignedInt datatype. |
int style = 0; |
if (c.getAttributes().getNamedItem("s") != null) { |
style = Integer.parseInt(c.getAttributes().getNamedItem("s").getNodeValue()); |
} |
// An enumeration representing the cell's data type. |
// The possible values for this attribute are defined by the ST_CellType simple type |
// (§18.18.11): |
// "b" boolean |
// "d" ISO 8601 date |
// "n" number |
// "e" error |
// "s" strin |
// "str" formula |
// "inlineStr" the cell value is in the is element rather than the v |
// element in the cell |
String type = "n"; |
if (c.getAttributes().getNamedItem("t") != null) { |
type = c.getAttributes().getNamedItem("t").getNodeValue(); |
} |
NodeList nListCellParts = c.getChildNodes(); |
int l3 = nListCellParts.getLength(); |
for (int k = 0; k < l3; k++) { |
Node part = nListCellParts.item(k); |
if (part.getNodeName().equals("v")) { |
String value = part.getTextContent(); |
Object cellValue = null; |
if (type.equals("n")) { |
final XLSXFormat format = document.getFormatFromStyle(style); |
if (format != null) { |
if (format.isDateFormat()) { |
cellValue = stringToDate(calendar, value); |
} else { |
cellValue = new BigDecimal(value); |
} |
} else { |
cellValue = new BigDecimal(value); |
} |
} else if (type.equals("s")) { |
cellValue = document.getSharedString(Integer.parseInt(value)); |
} |
this.rows.get(p.y - this.startY).set(p.x - this.startX, cellValue); |
} |
} |
} |
} |
} |
public Object getValueAt(int col, int row) { |
return this.rows.get(row).get(col); |
} |
public int getColumnCount() { |
return this.columnCount; |
} |
public int getRowCount() { |
return this.rows.size(); |
} |
/** |
* Convert string coordinates into numeric ones. |
* |
* @param ref the string address, eg "$AA$34" or "AA34". |
* @return the numeric coordinates or <code>null</code> if <code>ref</code> is not valid, eg |
* {26, 33}. |
*/ |
static final Point resolve(String ref) { |
final Matcher matcher = minCellPattern.matcher(ref); |
if (!matcher.matches()) |
return null; |
return resolve(matcher.group(1), matcher.group(2)); |
} |
/** |
* Convert string coordinates into numeric ones. ATTN this method does no checks. |
* |
* @param letters the column, eg "AA". |
* @param digits the row, eg "34". |
* @return the numeric coordinates, eg {26, 33}. |
*/ |
static final Point resolve(final String letters, final String digits) { |
return new Point(toInt(letters), Integer.parseInt(digits) - 1); |
} |
// "AA" => 26 |
static final int toInt(String col) { |
if (col.length() < 1) |
throw new IllegalArgumentException("x cannot be empty"); |
col = col.toUpperCase(); |
int x = 0; |
for (int i = 0; i < col.length(); i++) { |
x = x * 26 + (col.charAt(i) - 'A' + 1); |
} |
// zero based |
return x - 1; |
} |
public static final String toStr(int col) { |
if (col < 0) |
throw new IllegalArgumentException("negative column : " + col); |
// one based (i.e. 0 is A) |
col++; |
final int radix = 26; |
final StringBuilder chars = new StringBuilder(4); |
while (col > 0) { |
chars.append((char) ('A' + ((col - 1) % radix))); |
col = (col - 1) / radix; |
} |
return chars.reverse().toString(); |
} |
/** |
* Convert numeric coordinates into string ones. |
* |
* @param p the numeric coordinates, e.g. {26, 33}. |
* @return the string address, e.g. "AA34". |
*/ |
static final String getAddress(Point p) { |
if (p.x < 0 || p.y < 0) |
throw new IllegalArgumentException("negative coordinates : " + p); |
return toStr(p.x) + (p.y + 1); |
} |
public String getId() { |
return this.id; |
} |
public static Date stringToDate(Calendar c, String d) { |
c.clear(); |
c.set(1900, 0, 0); |
c.add(Calendar.DAY_OF_YEAR, Integer.parseInt(d) - 1); |
return c.getTime(); |
} |
public int getStartX() { |
return this.startX; |
} |
public int getStartY() { |
return this.startY; |
} |
public int getEndX() { |
return this.endX; |
} |
public int getEndY() { |
return this.endY; |
} |
public String getName() { |
return this.name; |
} |
public String getRId() { |
return this.rId; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/utils/ooxml/XLSXDocument.java |
---|
New file |
0,0 → 1,273 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.utils.ooxml; |
import org.openconcerto.utils.StringInputStream; |
import java.io.ByteArrayOutputStream; |
import java.io.File; |
import java.io.IOException; |
import java.io.InputStream; |
import java.nio.charset.StandardCharsets; |
import java.util.ArrayList; |
import java.util.HashMap; |
import java.util.List; |
import java.util.Map; |
import java.util.zip.ZipEntry; |
import java.util.zip.ZipFile; |
import javax.xml.XMLConstants; |
import javax.xml.parsers.DocumentBuilder; |
import javax.xml.parsers.DocumentBuilderFactory; |
import javax.xml.parsers.ParserConfigurationException; |
import org.w3c.dom.Document; |
import org.w3c.dom.NamedNodeMap; |
import org.w3c.dom.Node; |
import org.w3c.dom.NodeList; |
import org.xml.sax.SAXException; |
public class XLSXDocument { |
private File file; |
private final List<XLSXSheet> sheets = new ArrayList<>(); |
private final Map<String, String> relationships = new HashMap<>(); |
private final List<String> sharedString = new ArrayList<>(); |
private final Map<Integer, XLSXFormat> mapFormats = new HashMap<>(); |
private final List<XLSXFormat> customFormats = new ArrayList<>(); |
private final List<XLSXStyle> styles = new ArrayList<>(); |
private final DocumentBuilderFactory dbFactory; |
public static XLSXDocument createFromFile(File f) throws IOException { |
XLSXDocument doc = new XLSXDocument(); |
doc.load(f); |
return doc; |
} |
public XLSXDocument() { |
this.mapFormats.put(0, new XLSXFormat(0, "General", false)); |
this.mapFormats.put(1, new XLSXFormat(1, "0", false)); |
this.mapFormats.put(2, new XLSXFormat(2, "0.00", false)); |
this.mapFormats.put(3, new XLSXFormat(3, "#,##0", false)); |
this.mapFormats.put(4, new XLSXFormat(4, "#,##0.00", false)); |
this.mapFormats.put(9, new XLSXFormat(9, "0%", false)); |
this.mapFormats.put(10, new XLSXFormat(10, "0.00%", false)); |
this.mapFormats.put(11, new XLSXFormat(11, "0.00E+00", false)); |
this.mapFormats.put(12, new XLSXFormat(12, "# ?/?", false)); |
this.mapFormats.put(13, new XLSXFormat(13, "# ??/??", false)); |
this.mapFormats.put(14, new XLSXFormat(14, "mm-dd-yy", true)); |
this.mapFormats.put(15, new XLSXFormat(15, "d-mmm-yy", true)); |
this.mapFormats.put(16, new XLSXFormat(16, "d-mmm", true)); |
this.mapFormats.put(17, new XLSXFormat(17, "mmm-yy", true)); |
this.mapFormats.put(18, new XLSXFormat(18, "h:mm AM/PM", false)); |
this.mapFormats.put(19, new XLSXFormat(19, "h:mm:ss AM/PM", false)); |
this.mapFormats.put(20, new XLSXFormat(20, "h:mm", false)); |
this.mapFormats.put(21, new XLSXFormat(21, "h:mm:ss", false)); |
this.mapFormats.put(22, new XLSXFormat(22, "m/d/yy h:mm", true)); |
this.mapFormats.put(27, new XLSXFormat(27, "[$-404]e/m/d", true)); |
this.mapFormats.put(30, new XLSXFormat(30, "m/d/yy", true)); |
this.mapFormats.put(36, new XLSXFormat(36, "[$-404]e/m/d", true)); |
this.mapFormats.put(37, new XLSXFormat(37, "#,##0 ;(#,##0)", false)); |
this.mapFormats.put(38, new XLSXFormat(38, "#,##0 ;[Red](#,##0)", false)); |
this.mapFormats.put(39, new XLSXFormat(39, "#,##0.00;(#,##0.00)", false)); |
this.mapFormats.put(40, new XLSXFormat(40, "#,##0.00;[Red](#,##0.00)", false)); |
this.mapFormats.put(44, new XLSXFormat(44, "_(\"$\"* #,##0.00_);_(\"$\"* (#,##0.00);_(\"$\"* \"-\"??_);_(@_)", false)); |
this.mapFormats.put(45, new XLSXFormat(45, "mm:ss", false)); |
this.mapFormats.put(46, new XLSXFormat(46, "[h]:mm:ss", false)); |
this.mapFormats.put(47, new XLSXFormat(47, "mmss.0", false)); |
this.mapFormats.put(48, new XLSXFormat(48, "##0.0E+0", false)); |
this.mapFormats.put(49, new XLSXFormat(49, "@", false)); |
this.mapFormats.put(50, new XLSXFormat(50, "[$-404]e/m/d", true)); |
this.mapFormats.put(57, new XLSXFormat(57, "[$-404]e/m/d", true)); |
this.mapFormats.put(59, new XLSXFormat(59, "t0", false)); |
this.mapFormats.put(60, new XLSXFormat(60, "t0.00", false)); |
this.mapFormats.put(61, new XLSXFormat(61, "t#,##0", false)); |
this.mapFormats.put(62, new XLSXFormat(62, "t#,##0.00", false)); |
this.mapFormats.put(67, new XLSXFormat(67, "t0%", false)); |
this.mapFormats.put(68, new XLSXFormat(68, "t0.00%", false)); |
this.mapFormats.put(69, new XLSXFormat(69, "t# ?/?", false)); |
this.mapFormats.put(70, new XLSXFormat(70, "t# ??/??", false)); |
this.dbFactory = DocumentBuilderFactory.newInstance(); |
try { |
this.dbFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); |
} catch (ParserConfigurationException e) { |
throw new IllegalStateException(e); |
} |
try { |
this.dbFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); |
this.dbFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, ""); |
} catch (Exception e) { |
// ignore |
} |
this.dbFactory.setNamespaceAware(true); |
} |
public File getFile() { |
return this.file; |
} |
private void load(File f) throws IOException { |
this.file = f; |
try (ZipFile zipFile = new ZipFile(f)) { |
try { |
parseSharedStrings(zipFile); |
parseStyles(zipFile); |
parseWorkBook(zipFile); |
} catch (ParserConfigurationException | SAXException e) { |
throw new IOException(e); |
} |
} |
} |
private void parseWorkBook(ZipFile zipFile) throws ParserConfigurationException, SAXException, IOException { |
final String relationxXML = getContent(zipFile, "xl/_rels/workbook.xml.rels"); |
final DocumentBuilder dBuilder1 = this.dbFactory.newDocumentBuilder(); |
final Document doc1 = dBuilder1.parse(new StringInputStream(relationxXML, StandardCharsets.UTF_8.name())); |
doc1.getDocumentElement().normalize(); |
final NodeList nList = doc1.getElementsByTagName("Relationship"); |
for (int i = 0; i < nList.getLength(); i++) { |
final NamedNodeMap attributes = nList.item(i).getAttributes(); |
final String rId = attributes.getNamedItem("Id").getNodeValue(); |
final String target = attributes.getNamedItem("Target").getNodeValue(); |
this.relationships.put(rId, target); |
} |
final String workbookXML = getContent(zipFile, "xl/workbook.xml"); |
final DocumentBuilder dBuilder2 = this.dbFactory.newDocumentBuilder(); |
final Document doc2 = dBuilder2.parse(new StringInputStream(workbookXML, StandardCharsets.UTF_8.name())); |
doc2.getDocumentElement().normalize(); |
doc2.getElementsByTagName("sheets"); |
final NodeList nListSheet = doc2.getElementsByTagName("sheet"); |
for (int i = 0; i < nListSheet.getLength(); i++) { |
final NamedNodeMap attributes = nListSheet.item(i).getAttributes(); |
final String sheetId = attributes.getNamedItem("sheetId").getNodeValue(); |
final String name = attributes.getNamedItem("name").getNodeValue(); |
final String rId = attributes.getNamedItemNS("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "id").getNodeValue(); |
final String target = "xl/" + this.relationships.get(rId); |
final String xml = getContent(zipFile, target); |
this.sheets.add(new XLSXSheet(this, sheetId, rId, name, xml)); |
} |
} |
private void parseSharedStrings(ZipFile zipFile) throws ParserConfigurationException, SAXException, IOException { |
final String relationxXML = getContent(zipFile, "xl/sharedStrings.xml"); |
final DocumentBuilder dBuilder1 = this.dbFactory.newDocumentBuilder(); |
final Document doc1 = dBuilder1.parse(new StringInputStream(relationxXML, StandardCharsets.UTF_8.name())); |
doc1.getDocumentElement().normalize(); |
final NodeList nList = doc1.getElementsByTagName("si"); |
for (int i = 0; i < nList.getLength(); i++) { |
final Node siNode = nList.item(i); |
StringBuilder b = new StringBuilder(); |
NodeList list = siNode.getChildNodes(); |
for (int j = 0; j < list.getLength(); j++) { |
Node n = list.item(j); |
if (n.getLocalName().equals("t")) { |
b.append(n.getTextContent()); |
} else { |
NodeList subList = n.getChildNodes(); |
for (int k = 0; k < subList.getLength(); k++) { |
Node nn = subList.item(k); |
if (nn.getLocalName().equals("t")) { |
b.append(nn.getTextContent()); |
} |
} |
} |
} |
this.sharedString.add(b.toString()); |
} |
} |
private void parseStyles(ZipFile zipFile) throws ParserConfigurationException, SAXException, IOException { |
final String relationxXML = getContent(zipFile, "xl/styles.xml"); |
final DocumentBuilder dBuilder1 = this.dbFactory.newDocumentBuilder(); |
final Document doc1 = dBuilder1.parse(new StringInputStream(relationxXML, StandardCharsets.UTF_8.name())); |
doc1.getDocumentElement().normalize(); |
final NodeList nListFormats = doc1.getElementsByTagName("numFmts"); |
for (int i = 0; i < nListFormats.getLength(); i++) { |
final Node siNode = nListFormats.item(i); |
NodeList list = siNode.getChildNodes(); |
for (int j = 0; j < list.getLength(); j++) { |
Node n = list.item(j); |
NamedNodeMap m = n.getAttributes(); |
int id = Integer.parseInt(m.getNamedItem("numFmtId").getNodeValue()); |
String format = m.getNamedItem("formatCode").getNodeValue(); |
final XLSXFormat f = new XLSXFormat(id, format); |
this.mapFormats.put(id, f); |
this.customFormats.add(f); |
} |
} |
final NodeList nListCellXfs = doc1.getElementsByTagName("cellXfs"); |
for (int i = 0; i < nListCellXfs.getLength(); i++) { |
final Node siNode = nListCellXfs.item(i); |
NodeList list = siNode.getChildNodes(); |
for (int j = 0; j < list.getLength(); j++) { |
// xf |
Node n = list.item(j); |
NamedNodeMap m = n.getAttributes(); |
int id = Integer.parseInt(m.getNamedItem("numFmtId").getNodeValue()); |
this.styles.add(new XLSXStyle(id)); |
} |
} |
} |
private String getContent(ZipFile zipFile, String string) throws IOException { |
final ZipEntry entry = zipFile.getEntry(string); |
if (entry == null) { |
throw new IOException("no entry : " + string); |
} |
final InputStream in = zipFile.getInputStream(entry); |
final ByteArrayOutputStream b = new ByteArrayOutputStream(); |
final byte[] bytes = new byte[8192]; |
while (in.available() > 0) { |
final int length = in.read(bytes); |
b.write(bytes, 0, length); |
} |
return b.toString(StandardCharsets.UTF_8.name()); |
} |
public XLSXSheet getSheet(int sheetNumber) { |
return this.sheets.get(sheetNumber); |
} |
public int getSheetCount() { |
return this.sheets.size(); |
} |
public String getSharedString(int index) { |
return this.sharedString.get(index); |
} |
public XLSXFormat getFormatFromStyle(int styleIndex) { |
final XLSXStyle style = this.styles.get(styleIndex); |
if (style == null) { |
return null; |
} |
return this.mapFormats.get(style.getFormatId()); |
} |
public DocumentBuilderFactory getDbFactory() { |
return this.dbFactory; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/utils/ooxml/XLSXStyle.java |
---|
New file |
0,0 → 1,26 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.utils.ooxml; |
public class XLSXStyle { |
private final int formatId; |
public XLSXStyle(int formatId) { |
this.formatId = formatId; |
} |
public int getFormatId() { |
return this.formatId; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/utils/NetUtils.java |
---|
22,11 → 22,17 |
import java.net.ServerSocket; |
import java.net.SocketException; |
import java.net.URL; |
import java.security.KeyManagementException; |
import java.security.NoSuchAlgorithmException; |
import java.security.cert.X509Certificate; |
import java.util.Enumeration; |
import javax.net.ssl.HostnameVerifier; |
import javax.net.ssl.HttpsURLConnection; |
import javax.net.ssl.SSLContext; |
import javax.net.ssl.SSLSession; |
import javax.net.ssl.TrustManager; |
import javax.net.ssl.X509TrustManager; |
public class NetUtils { |
125,6 → 131,10 |
} |
}; |
public static final String getHTTPContent(String address) { |
return getHTTPContent(address, false); |
} |
public static final String getHTTPContent(String address, final boolean dontVerify) { |
String content = ""; |
OutputStream out = null; |
167,4 → 177,23 |
return content; |
} |
// Create a trust manager that does not validate certificate chains |
static private final TrustManager[] TRUSTALL_MANAGERS = new TrustManager[] { new X509TrustManager() { |
public java.security.cert.X509Certificate[] getAcceptedIssuers() { |
return null; |
} |
public void checkClientTrusted(X509Certificate[] certs, String authType) { |
} |
public void checkServerTrusted(X509Certificate[] certs, String authType) { |
} |
} }; |
static public final SSLContext createTrustAllContext() throws KeyManagementException, NoSuchAlgorithmException { |
final SSLContext sc = SSLContext.getInstance("TLS"); |
sc.init(null, TRUSTALL_MANAGERS, new java.security.SecureRandom()); |
return sc; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/utils/StringUtils.java |
---|
28,6 → 28,7 |
import java.util.List; |
import java.util.Map; |
import java.util.Set; |
import java.util.regex.Matcher; |
import java.util.regex.Pattern; |
/** |
820,4 → 821,13 |
} |
return b.toString(); |
} |
public static final Matcher findFirstContaining(final String s, final Pattern... patterns) { |
for (final Pattern p : patterns) { |
final Matcher matcher = p.matcher(s); |
if (matcher.find()) |
return matcher; |
} |
return null; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/utils/sync/HashWriter.java |
---|
13,6 → 13,8 |
package org.openconcerto.utils.sync; |
import org.openconcerto.utils.MessageDigestUtils; |
import java.io.BufferedInputStream; |
import java.io.BufferedOutputStream; |
import java.io.DataOutputStream; |
38,8 → 40,8 |
} |
final DataOutputStream bOut = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile))); |
bOut.writeInt((int) this.in.length()); |
final MessageDigest hashSum = MessageDigest.getInstance("SHA-256"); |
final MessageDigest md5 = MessageDigest.getInstance("MD5"); |
final MessageDigest hashSum = MessageDigestUtils.getSHA256(); |
final MessageDigest md5 = MessageDigestUtils.getMD5(); |
fb = new BufferedInputStream(new FileInputStream(in)); |
final RollingChecksum32 r32 = new RollingChecksum32(); |
final byte[] buffer = new byte[BLOCK_SIZE]; |
74,8 → 76,8 |
} |
} |
public static byte[] getHash(File f) throws Exception { |
final MessageDigest hashSum = MessageDigest.getInstance("SHA-256"); |
public static byte[] getHash(File f) throws IOException { |
final MessageDigest hashSum = MessageDigestUtils.getSHA256(); |
FileInputStream fIn = null; |
try { |
fIn = new FileInputStream(f); |
123,4 → 125,15 |
return true; |
} |
private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); |
public static String bytesToHex(byte[] bytes) { |
char[] hexChars = new char[bytes.length * 2]; |
for (int j = 0; j < bytes.length; j++) { |
int v = bytes[j] & 0xFF; |
hexChars[j * 2] = hexArray[v >>> 4]; |
hexChars[j * 2 + 1] = hexArray[v & 0x0F]; |
} |
return new String(hexChars); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/utils/sync/SimpleSyncClient.java |
---|
New file |
0,0 → 1,413 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.utils.sync; |
import org.openconcerto.utils.CollectionUtils; |
import org.openconcerto.utils.MessageDigestUtils; |
import org.openconcerto.utils.StreamUtils; |
import java.io.BufferedOutputStream; |
import java.io.File; |
import java.io.IOException; |
import java.io.InputStream; |
import java.io.OutputStream; |
import java.io.UnsupportedEncodingException; |
import java.net.MalformedURLException; |
import java.net.ProtocolException; |
import java.net.URL; |
import java.nio.charset.StandardCharsets; |
import java.nio.file.Files; |
import java.nio.file.Path; |
import java.nio.file.StandardCopyOption; |
import java.nio.file.attribute.FileTime; |
import java.security.DigestOutputStream; |
import java.security.MessageDigest; |
import java.time.Instant; |
import java.util.ArrayList; |
import java.util.Base64; |
import java.util.Collections; |
import java.util.List; |
import java.util.Set; |
import java.util.concurrent.atomic.AtomicBoolean; |
import java.util.function.BiFunction; |
import java.util.function.Predicate; |
import java.util.zip.GZIPInputStream; |
import java.util.zip.GZIPOutputStream; |
import javax.net.ssl.HttpsURLConnection; |
import javax.net.ssl.SSLSocketFactory; |
import net.minidev.json.JSONArray; |
import net.minidev.json.JSONObject; |
import net.minidev.json.parser.JSONParser; |
public final class SimpleSyncClient { |
private static final int MIN_GZIP_SIZE = 64; |
static protected final long getLong(final Object o) { |
return ((Number) o).longValue(); |
} |
static protected final Instant getInstant(final Object o) { |
return Instant.ofEpochMilli(getLong(o)); |
} |
static public class ServerException extends RuntimeException { |
private final int responseCode; |
private final boolean authenticateError; |
protected ServerException(int responseCode, boolean authenticateError) { |
super("Response code was " + responseCode); |
this.responseCode = responseCode; |
this.authenticateError = authenticateError; |
} |
public final int getResponseCode() { |
return this.responseCode; |
} |
public final boolean isAuthenticateError() { |
return this.authenticateError; |
} |
} |
static public final class Response { |
protected final static Response create(HttpsURLConnection con, final Set<Integer> okCodes) throws IOException { |
final boolean success = okCodes == null ? con.getResponseCode() == 200 : okCodes.contains(con.getResponseCode()); |
return new Response(success, con.getResponseCode(), con.getResponseMessage(), con.getContentEncoding(), con.getContentType()); |
} |
private final boolean success; |
private final int code; |
private final String message; |
private final String contentEncoding, contentType; |
protected Response(boolean success, int code, String message, String contentEncoding, String contentType) { |
super(); |
this.success = success; |
this.code = code; |
this.message = message; |
this.contentEncoding = contentEncoding; |
this.contentType = contentType; |
} |
public final int getCode() { |
return this.code; |
} |
public final boolean isSuccess() { |
return this.success; |
} |
public final String getMessage() { |
return this.message; |
} |
public final String getContentEncoding() { |
return this.contentEncoding; |
} |
public final String getContentType() { |
return this.contentType; |
} |
} |
static protected abstract class BaseAttrs { |
private final String path; |
private final String name; |
private final Instant lastModified; |
protected BaseAttrs(final String path, final String name, final Instant lastModified) { |
super(); |
this.path = path; |
this.name = name; |
this.lastModified = lastModified; |
} |
public final String getPath() { |
return this.path; |
} |
public final String getName() { |
return this.name; |
} |
public final Instant getLastModified() { |
return this.lastModified; |
} |
@Override |
public String toString() { |
return this.getClass().getSimpleName() + " '" + this.getName() + "'"; |
} |
} |
static public final class DirAttrs extends BaseAttrs { |
static protected DirAttrs fromJSON(final String path, final JSONArray array) { |
return new DirAttrs(path, (String) array.get(0), getInstant(array.get(1))); |
} |
protected DirAttrs(final String path, String name, Instant lastModified) { |
super(path, name, lastModified); |
} |
} |
static public final class FileAttrs extends BaseAttrs { |
static protected FileAttrs fromJSON(final String path, final JSONArray array) { |
return new FileAttrs(path, (String) array.get(0), getInstant(array.get(2)), getLong(array.get(1)), (String) array.get(3)); |
} |
private final long size; |
private final String sha256; |
protected FileAttrs(final String path, String name, Instant lastModified, long size, String sha256) { |
super(path, name, lastModified); |
this.size = size; |
this.sha256 = sha256; |
} |
public final long getSize() { |
return this.size; |
} |
public final String getSHA256() { |
return this.sha256; |
} |
public final void saveFile(final InputStream in, final Path localFile) throws IOException { |
// Save to temporary file to avoid overwriting old file with a new invalid one. In |
// same folder for the move. |
final Path tmpFile = Files.createTempFile(localFile.getParent(), "partial", null); |
try { |
final MessageDigest md = this.getSHA256() == null ? null : MessageDigestUtils.getSHA256(); |
try (final BufferedOutputStream fileStream = new BufferedOutputStream(Files.newOutputStream(tmpFile)); |
// |
final OutputStream out = md == null ? fileStream : new DigestOutputStream(fileStream, md)) { |
StreamUtils.copy(in, out); |
} |
if (this.getSize() >= 0) { |
final long savedSize = Files.size(tmpFile); |
if (savedSize != this.getSize()) |
throw new IOException("Expected " + this.getSize() + " bytes but saved " + savedSize); |
} |
if (md != null) { |
final String savedHash = MessageDigestUtils.getHashString(md); |
if (!savedHash.equalsIgnoreCase(this.getSHA256())) |
throw new IOException("Expected hash was " + this.getSHA256() + " but saved " + savedHash); |
} |
Files.move(tmpFile, localFile, StandardCopyOption.REPLACE_EXISTING); |
} finally { |
Files.deleteIfExists(tmpFile); |
} |
if (this.getLastModified().compareTo(Instant.EPOCH) > 0) |
Files.setLastModifiedTime(localFile, FileTime.from(this.getLastModified())); |
} |
@Override |
public String toString() { |
return super.toString() + " of size " + getSize(); |
} |
} |
static public final class DirContent { |
private final String path; |
private final JSONObject json; |
protected DirContent(final String path, JSONObject json) { |
super(); |
this.path = path; |
this.json = json; |
} |
public final List<FileAttrs> getFiles() { |
return this.getFiles(null); |
} |
public final List<FileAttrs> getFiles(final Predicate<String> namePredicate) { |
return this.getContent("files", namePredicate, FileAttrs::fromJSON); |
} |
public final List<DirAttrs> getDirs() { |
return this.getDirs(null); |
} |
public final List<DirAttrs> getDirs(final Predicate<String> namePredicate) { |
return this.getContent("dirs", namePredicate, DirAttrs::fromJSON); |
} |
protected final <T extends BaseAttrs> List<T> getContent(final String key, final Predicate<String> namePredicate, final BiFunction<String, JSONArray, T> create) { |
final JSONArray files = (JSONArray) this.json.get(key); |
if (files == null) |
return Collections.emptyList(); |
final List<T> res = new ArrayList<>(); |
for (final Object f : files) { |
final JSONArray array = (JSONArray) f; |
if (namePredicate == null || namePredicate.test((String) array.get(0))) { |
res.add(create.apply(this.path, array)); |
} |
} |
return res; |
} |
} |
private final String url; |
private SSLSocketFactory socketFactory; |
private String token; |
private boolean throwException = true; |
public SimpleSyncClient(final String url) { |
this.url = url; |
} |
public final SSLSocketFactory getSocketFactory() { |
return this.socketFactory; |
} |
public final void setSocketFactory(SSLSocketFactory socketFactory) { |
this.socketFactory = socketFactory; |
} |
public final void setToken(String token) { |
this.token = token; |
} |
public final boolean hasToken() { |
return this.getToken() != null; |
} |
protected final String getToken() { |
return this.token; |
} |
public final void setThrowException(boolean throwException) { |
this.throwException = throwException; |
} |
public final boolean throwsException() { |
return this.throwException; |
} |
protected Response checkResponseCode(final HttpsURLConnection con) throws IOException { |
return checkResponseCode(con, null); |
} |
protected Response checkResponseCode(final HttpsURLConnection con, final Set<Integer> okCodes) throws IOException { |
final Response res = Response.create(con, okCodes); |
if (this.throwsException() && !res.isSuccess()) |
throw new ServerException(res.getCode(), con.getHeaderField("WWW-Authenticate") != null); |
return res; |
} |
private final HttpsURLConnection openConnection(final String path) throws IOException { |
final HttpsURLConnection con = (HttpsURLConnection) new URL(this.url + path).openConnection(); |
con.setRequestProperty("Accept-Encoding", "gzip"); |
if (this.getSocketFactory() != null) |
con.setSSLSocketFactory(this.getSocketFactory()); |
if (getToken() != null) |
con.setRequestProperty("Authorization", "Bearer " + Base64.getEncoder().encodeToString(getToken().getBytes(StandardCharsets.UTF_8))); |
return con; |
} |
private final InputStream getInputStream(final HttpsURLConnection con) throws IOException { |
return "gzip".equals(con.getContentEncoding()) ? new GZIPInputStream(con.getInputStream()) : con.getInputStream(); |
} |
private final HttpsURLConnection send(final HttpsURLConnection con, final String params) throws IOException { |
return this.send(con, params.getBytes(StandardCharsets.UTF_8), false); |
} |
private final HttpsURLConnection send(final HttpsURLConnection con, final byte[] toSend, final boolean allowGzip) throws IOException { |
final boolean useGzip = allowGzip && toSend.length >= MIN_GZIP_SIZE; |
if (useGzip) |
con.setRequestProperty("Content-Encoding", "gzip"); |
con.setRequestMethod("POST"); |
con.setDoOutput(true); |
try (final OutputStream o = useGzip ? new GZIPOutputStream(con.getOutputStream()) : con.getOutputStream()) { |
o.write(toSend); |
} |
return con; |
} |
public DirContent getDir(final String path) throws Exception { |
final HttpsURLConnection con = openConnection("/getDir"); |
final Response res = checkResponseCode(send(con, "rp=" + path + "&type=json")); |
if (!res.isSuccess()) |
return null; |
final JSONParser p = new JSONParser(JSONParser.MODE_STRICTEST); |
try (final InputStream in = getInputStream(con)) { |
return new DirContent(path, (JSONObject) p.parse(in)); |
} |
} |
@FunctionalInterface |
static public interface FileConsumer { |
public void accept(FileAttrs attrs, InputStream fileStream) throws IOException; |
} |
static private final Set<Integer> GETFILE_OK_CODES = CollectionUtils.createSet(200, 404); |
public Response getFile(final String path, final String fileName, final FileConsumer fileConsumer) throws IOException { |
final HttpsURLConnection con = openConnection("/get"); |
send(con, "rn=" + fileName + "&rp=" + path); |
final Response res = checkResponseCode(con, GETFILE_OK_CODES); |
if (res.getCode() == 404) { |
fileConsumer.accept(null, null); |
} else if (res.getCode() == 200) { |
final FileAttrs fileAttrs = new FileAttrs(path, fileName, Instant.ofEpochMilli(con.getLastModified()), -1, con.getHeaderField("X-SHA256")); |
try (final InputStream in = getInputStream(con)) { |
fileConsumer.accept(fileAttrs, in); |
} |
} |
return res; |
} |
// ATTN contrary to other methods, the result isn't if the request was OK : it ignores |
// throwsException() and always throws. The return value is true if the file existed and was |
// saved. |
public boolean saveFile(final String path, final String fileName, final Path localFile) throws IOException { |
final AtomicBoolean missing = new AtomicBoolean(true); |
final Response res = this.getFile(path, fileName, (fileAttrs, in) -> { |
missing.set(fileAttrs == null); |
if (!missing.get()) { |
fileAttrs.saveFile(in, localFile); |
} |
}); |
if (!res.isSuccess()) |
throw new IOException("Couldn't retrieve file " + fileName); |
return !missing.get(); |
} |
public Response deleteFile(final String path, final String fileName) throws MalformedURLException, IOException, ProtocolException, UnsupportedEncodingException { |
final HttpsURLConnection con = openConnection("/delete"); |
return checkResponseCode(send(con, "rn=" + fileName + "&rp=" + path)); |
} |
public Response sendFile(String path, File localFile) throws Exception, MalformedURLException, IOException, ProtocolException { |
byte[] newsha256 = HashWriter.getHash(localFile); |
long size = localFile.length(); |
final HttpsURLConnection con = openConnection("/put"); |
// We use Base64 because headers are not supporting UTF8 |
con.setRequestProperty("X_FILENAME_B64", Base64.getEncoder().encodeToString(localFile.getName().getBytes(StandardCharsets.UTF_8))); |
con.setRequestProperty("X_PATH_B64", Base64.getEncoder().encodeToString(path.getBytes(StandardCharsets.UTF_8))); |
con.setRequestProperty("X_FILESIZE", String.valueOf(size)); |
con.setRequestProperty("X_SHA256", HashWriter.bytesToHex(newsha256)); |
con.setRequestProperty("X-Last-Modified-ms", String.valueOf(localFile.lastModified())); |
return checkResponseCode(send(con, Files.readAllBytes(localFile.toPath()), true)); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/utils/i18n/TranslationManager.java |
---|
25,16 → 25,17 |
import java.util.Map; |
import java.util.ResourceBundle.Control; |
import javax.xml.XMLConstants; |
import javax.xml.parsers.DocumentBuilder; |
import javax.xml.parsers.DocumentBuilderFactory; |
import net.jcip.annotations.GuardedBy; |
import net.jcip.annotations.ThreadSafe; |
import org.w3c.dom.Document; |
import org.w3c.dom.Element; |
import org.w3c.dom.NodeList; |
import net.jcip.annotations.GuardedBy; |
import net.jcip.annotations.ThreadSafe; |
@ThreadSafe |
public class TranslationManager { |
private static final Locale FALLBACK_LOCALE = Locale.ENGLISH; |
64,7 → 65,7 |
@GuardedBy("classes") |
private Locale locale; |
private final Object trMutex = new String("translations mutex"); |
private final Object trMutex = new Object(); |
@GuardedBy("trMutex") |
private Map<String, String> menuTranslation; |
@GuardedBy("trMutex") |
73,7 → 74,7 |
private Map<String, String> actionTranslation; |
private TranslationManager() { |
this.classes = new ArrayList<Class<?>>(); |
this.classes = new ArrayList<>(); |
} |
public void addTranslationStreamFromClass(Class<?> c) { |
164,10 → 165,10 |
private void loadAllTranslation() { |
synchronized (this.trMutex) { |
this.menuTranslation = new HashMap<String, String>(); |
this.itemTranslation = new HashMap<String, String>(); |
this.actionTranslation = new HashMap<String, String>(); |
if (this.classes.size() == 0) { |
this.menuTranslation = new HashMap<>(); |
this.itemTranslation = new HashMap<>(); |
this.actionTranslation = new HashMap<>(); |
if (this.classes.isEmpty()) { |
Log.get().warning("TranslationManager has no resources to load (" + this.getLocale() + ")"); |
} |
for (Class<?> c : this.classes) { |
182,7 → 183,7 |
// return all existing (e.g fr_CA only specify differences with fr) |
private List<InputStream> findStream(final Locale locale, final Class<?> c, final boolean rootLast) { |
final Control cntrl = CONTROL; |
final List<InputStream> res = new ArrayList<InputStream>(); |
final List<InputStream> res = new ArrayList<>(); |
final String baseName = c.getPackage().getName() + "." + BASENAME; |
// test emptiness to not mix languages |
203,7 → 204,7 |
// we want more specific translations to replace general ones, i.e. root Locale first |
for (final InputStream input : findStream(l, c, false)) { |
// create new instances to check if there's no duplicates in each resource |
final Map<String, String> menuTranslation = new HashMap<String, String>(), itemTranslation = new HashMap<String, String>(), actionTranslation = new HashMap<String, String>(); |
final Map<String, String> menuTranslation = new HashMap<>(), itemTranslation = new HashMap<>(), actionTranslation = new HashMap<>(); |
loadTranslation(input, menuTranslation, itemTranslation, actionTranslation); |
// on the other hand, it's OK for one resource to override another |
this.menuTranslation.putAll(menuTranslation); |
214,10 → 215,14 |
return translationLoaded; |
} |
static private void loadTranslation(final InputStream input, final Map<String, String> menuTranslation, final Map<String, String> itemTranslation, final Map<String, String> actionTranslation) { |
private static void loadTranslation(final InputStream input, final Map<String, String> menuTranslation, final Map<String, String> itemTranslation, final Map<String, String> actionTranslation) { |
// FIXME : l'implementation de Java est lente |
// com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl : 60 ms! |
// On pourrait passer à 1ms avec Piccolo... |
final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); |
try { |
dbFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); |
dbFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); |
final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); |
final Document doc = dBuilder.parse(input); |
// Menus |
239,7 → 244,7 |
} |
} |
static private void loadTranslation(final Document doc, final String tagName, final Map<String, String> m) { |
private static void loadTranslation(final Document doc, final String tagName, final Map<String, String> m) { |
final NodeList menuChildren = doc.getElementsByTagName(tagName); |
final int size = menuChildren.getLength(); |
for (int i = 0; i < size; i++) { |
/trunk/OpenConcerto/src/org/openconcerto/utils/CollectionMap2.java |
---|
122,6 → 122,9 |
// ** copy constructors |
// ATTN getDelegate() is not in CollectionMap2Itf, so if one copies an unmodifiableMap() this |
// constructor won't be used and the delegate will be the default HashMap (even if the source |
// used a LinkedHashMap). |
public CollectionMap2(final CollectionMap2<K, C, ? extends V> m) { |
this(CopyUtils.copy(m.getDelegate()), m); |
} |
/trunk/OpenConcerto/src/org/openconcerto/utils/TableSorter.java |
---|
348,8 → 348,12 |
* @return the corresponding index in the model. |
*/ |
public int modelIndex(int viewIndex) { |
try { |
return getViewToModel()[viewIndex].modelIndex; |
} catch (Exception e) { |
throw new IllegalStateException(this + " couldn't get model index for view index " + viewIndex + " with " + this.getTableModel().getRowCount() + " row(s) in our model", e); |
} |
} |
private int[] getModelToView() { |
if (!SwingUtilities.isEventDispatchThread()) { |
430,6 → 434,11 |
this.supp.removePropertyChangeListener(l); |
} |
@Override |
public String toString() { |
return this.getClass().getSimpleName() + " on " + this.getTableModel(); |
} |
// Helper classes |
private class Row implements Comparable<Row> { |
/trunk/OpenConcerto/src/org/openconcerto/utils/FileUtils.java |
---|
695,6 → 695,7 |
* @see StreamUtils#createXMLWriter(java.io.OutputStream) |
*/ |
public static BufferedWriter createXMLWriter(final File f) throws IOException { |
FileUtils.mkParentDirs(f); |
final FileOutputStream outs = new FileOutputStream(f); |
try { |
return StreamUtils.createXMLWriter(outs); |
/trunk/OpenConcerto/src/org/openconcerto/utils/text/CSVReader.java |
---|
29,7 → 29,6 |
import java.io.BufferedReader; |
import java.io.Closeable; |
import java.io.FileReader; |
import java.io.IOException; |
import java.io.Reader; |
import java.util.ArrayList; |
248,11 → 247,4 |
br.close(); |
} |
public static void main(String[] args) throws IOException { |
CSVReader reader = new CSVReader(new FileReader("n:\\Sans nom 1.csv")); |
String[] s = reader.readNext(); |
for (int i = 0; i < s.length; i++) { |
System.err.println("CSVReader.main() :" + i + " : " + s[i]); |
} |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/utils/ProductInfo.java |
---|
14,6 → 14,9 |
package org.openconcerto.utils; |
import java.io.IOException; |
import java.io.OutputStream; |
import java.nio.file.Files; |
import java.nio.file.Path; |
import java.util.Map; |
import java.util.Properties; |
157,6 → 160,12 |
return this.getProperty(VERSION); |
} |
public final void store(final Path p) throws IOException { |
try (final OutputStream out = Files.newOutputStream(p)) { |
this.getProps().store(out, this.getClass().getName()); |
} |
} |
@Override |
public String toString() { |
return this.getClass().getSimpleName() + " for " + getName() + " " + getVersion(); |
/trunk/OpenConcerto/src/org/openconcerto/xml/AbstractXMLDecoder.java |
---|
New file |
0,0 → 1,381 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.xml; |
import org.openconcerto.utils.StringUtils; |
import org.openconcerto.utils.cache.CacheResult; |
import org.openconcerto.utils.cache.ICache; |
import org.openconcerto.utils.cc.ExnTransformer; |
import java.beans.XMLDecoder; |
import java.beans.XMLEncoder; |
import java.lang.reflect.Array; |
import java.lang.reflect.Constructor; |
import java.lang.reflect.InvocationTargetException; |
import java.lang.reflect.Method; |
import java.util.ArrayList; |
import java.util.HashMap; |
import java.util.LinkedList; |
import java.util.List; |
import java.util.Map; |
import java.util.Stack; |
/** |
* To decode XML in {@link XMLEncoder} format. |
* |
* @author Sylvain CUAZ |
* @param <S> type of source |
* @param <E> type of exception |
*/ |
public abstract class AbstractXMLDecoder<S, E extends Exception> { |
protected static interface Children<C> { |
C getNextChild(); |
} |
private static final ICache<Object, Method, Object> cache = new ICache<Object, Method, Object>(60, -1, "methods for " + XMLCodecUtils.class); |
private static final ICache<Object, Constructor<?>, Object> cacheCtor = new ICache<Object, Constructor<?>, Object>(60, -1, "constructors for " + XMLCodecUtils.class); |
protected abstract String getLocalName(S elem); |
protected abstract String getAttributeValue(S elem, final String attrName); |
protected abstract String getElementText(S elem) throws E; |
protected abstract S getFirstChild(S elem); |
protected abstract String toString(S elem); |
protected abstract Children<S> createChildren(S elem) throws E; |
public final <K, V> Map<K, V> decodeFromArray(final S elem, final Class<K> keyClass, final Class<V> valueClass) { |
return XMLCodecUtils.decodeFromArray((Object[]) this.decode1(elem), keyClass, valueClass); |
} |
/** |
* Tries to decode an xml element parsed from a string obtained from XMLEncoder. This doesn't |
* use {@link XMLDecoder} as it requires outputting it first to string which is inefficient. |
* NOTE: this decoder supports only a subset of XMLDecoder. |
* |
* @param javaElem a "java" element. |
* @return the decoded object. |
*/ |
public final Object decode1(S javaElem) { |
final S elem = getFirstChild(javaElem); |
try { |
return eval(elem, new Stack<Object>(), new HashMap<String, Object>()); |
} catch (Exception e) { |
throw new IllegalStateException("error decoding " + toString(javaElem), e); |
} |
} |
private final Object eval(S elem, Stack<Object> context, final Map<String, Object> ids) |
throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, E { |
preEval(elem); |
final Object res = this._eval(elem, context, ids); |
postEval(elem, res); |
return res; |
} |
protected void preEval(S elem) throws E { |
} |
protected void nullDecoded(S elem) throws E { |
} |
protected void idRefDecoded(S elem) throws E { |
} |
protected void postEval(S elem, final Object res) throws E { |
} |
private final Object _eval(S elem, Stack<Object> context, final Map<String, Object> ids) |
throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, E { |
final String n = getLocalName(elem); |
// Ordered from real world scenario |
// string : 80k |
// void : 53k |
// int : 18k |
// object : 9k |
// null : 6k |
switch (n) { |
case "string": |
return getElementText(elem); |
case "void": |
case "object": |
final String idref = getAttributeValue(elem, "idref"); |
if (idref != null) { |
if (!ids.containsKey(idref)) |
throw new IllegalStateException("id '" + idref + "' wasn't defined"); |
idRefDecoded(elem); |
return ids.get(idref); |
} |
final String id = getAttributeValue(elem, "id"); |
final String targetClass = getAttributeValue(elem, "class"); |
final Object target = targetClass == null ? context.peek() : Class.forName(targetClass); |
final String propAttr = getAttributeValue(elem, "property"); |
final String indexAttr = getAttributeValue(elem, "index"); |
final String methodAttr = getAttributeValue(elem, "method"); |
// statement or expression |
final Object res = evalContainer(elem, context, ids, new ExnTransformer<List<Object>, Object, Exception>() { |
@Override |
public Object transformChecked(List<Object> args) throws Exception { |
// call the statement |
final Object res; |
if (propAttr != null) { |
final String methodName = (args.size() == 0 ? "get" : "set") + StringUtils.firstUp(propAttr); |
res = invoke(target, methodName, args); |
} else if (indexAttr != null) { |
final String methodName; |
if (target instanceof List) { |
methodName = args.size() == 0 ? "get" : "set"; |
// get(index) or set(index, value) |
args.add(0, Integer.valueOf(indexAttr)); |
res = invoke(target, methodName, args); |
} else if (target.getClass().isArray()) { |
final Class<?> componentType = target.getClass().getComponentType(); |
// in Array there's set(array, int index, Object value) or |
// setPrimitive(array, int index, primitive value) |
methodName = (args.size() == 0 ? "get" : "set") + (componentType.isPrimitive() ? StringUtils.firstUp(componentType.getSimpleName()) : ""); |
args.add(0, target); |
args.add(1, Integer.valueOf(indexAttr)); |
res = invoke(Array.class, methodName, args); |
} else |
throw new IllegalStateException("use index with neither List nor array: " + target); |
} else if (methodAttr != null) { |
res = invoke(target, methodAttr, args); |
} else |
res = getCtor((Class<?>) target, args).newInstance(args.toArray()); |
return res; |
} |
}); |
// not very functional but it works |
if (id != null) |
ids.put(id, res); |
return res; |
case "int": |
return Integer.valueOf(getElementText(elem)); |
case "null": |
nullDecoded(elem); |
return null; |
case "boolean": |
return Boolean.valueOf(getElementText(elem)); |
case "byte": |
return Byte.valueOf(getElementText(elem)); |
case "char": |
return Character.valueOf(getElementText(elem).charAt(0)); |
case "short": |
return Short.valueOf(getElementText(elem)); |
case "long": |
return Long.valueOf(getElementText(elem)); |
case "float": |
return Float.valueOf(getElementText(elem)); |
case "double": |
return Double.valueOf(getElementText(elem)); |
case "array": |
final String classAttr = getAttributeValue(elem, "class"); |
final String lengthAttr = getAttributeValue(elem, "length"); |
final Class<?> componentClass = parseClassName(classAttr); |
if (lengthAttr != null) { |
context.push(Array.newInstance(componentClass, Integer.parseInt(lengthAttr))); |
final Children<S> children = createChildren(elem); |
S child; |
while ((child = children.getNextChild()) != null) { |
eval(child, context, ids); |
} |
return context.pop(); |
} else { |
final List<Object> items = new LinkedList<>(); |
final Children<S> children = createChildren(elem); |
S child; |
while ((child = children.getNextChild()) != null) { |
items.add(eval(child, context, ids)); |
} |
final Object resArray = Array.newInstance(componentClass, items.size()); |
int i = 0; |
for (final Object item : items) |
Array.set(resArray, i++, item); |
return resArray; |
} |
case "class": |
return Class.forName(getElementText(elem)); |
default: |
throw new UnsupportedOperationException("doesn't yet support " + n); |
} |
} |
private final Object evalContainer(final S parent, Stack<Object> context, final Map<String, Object> ids, final ExnTransformer<List<Object>, Object, ? extends Exception> transf) |
throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, E { |
final List<Object> args = new ArrayList<Object>(); |
final Children<S> children = createChildren(parent); |
boolean noVoid = true; |
S child = null; |
while (noVoid && (child = children.getNextChild()) != null) { |
if (getLocalName(child).equals("void")) |
noVoid = false; |
else { |
args.add(eval(child, context, ids)); |
} |
} |
// call the statement |
final Object res = transf.transformCheckedWithExn(args, false, InvocationTargetException.class, InstantiationException.class, IllegalAccessException.class); |
context.push(res); |
// now call the voids |
if (child != null) { |
do { |
eval(child, context, ids); |
} while ((child = children.getNextChild()) != null); |
} |
return context.pop(); |
} |
private static final Object invoke(final Object target, String methodName, final List<Object> args) throws IllegalAccessException, InvocationTargetException { |
// <object class="Cell" method="createEmpty" > |
// for static methods the target is already a class |
final Class clazz = target instanceof Class ? (Class) target : target.getClass(); |
final Method m = getMethod(clazz, methodName, args); |
return m.invoke(target, args.toArray()); |
} |
private static final Method getMethod(Class<?> clazz, String name, List<Object> actualArgs) { |
final List<Class<?>> actualClasses = objectsToClasses(actualArgs); |
final List<Object> key = new ArrayList<Object>(3); |
key.add(clazz); |
key.add(name); |
key.add(actualClasses); |
final CacheResult<Method> cacheRes = cache.check(key); |
if (cacheRes.getState() == CacheResult.State.VALID) |
return cacheRes.getRes(); |
final Method res = findMethod(clazz, name, actualClasses); |
if (res == null) |
throw new IllegalStateException("No matching method " + name + " found in " + clazz); |
cache.put(key, res); |
return res; |
} |
private static final Constructor getCtor(Class<?> clazz, List<Object> actualArgs) { |
final List<Class<?>> actualClasses = objectsToClasses(actualArgs); |
final List<Object> key = new ArrayList<Object>(3); |
key.add(clazz); |
key.add(actualClasses); |
final CacheResult<Constructor<?>> cacheRes = cacheCtor.check(key); |
if (cacheRes.getState() == CacheResult.State.VALID) |
return cacheRes.getRes(); |
final Constructor res = findCtor(clazz, actualClasses); |
cacheCtor.put(key, res); |
return res; |
} |
private static final List<Class<?>> objectsToClasses(List<Object> actualArgs) { |
final List<Class<?>> actualClasses = new ArrayList<Class<?>>(actualArgs.size()); |
for (final Object actualArg : actualArgs) |
actualClasses.add(actualArg == null ? null : actualArg.getClass()); |
return actualClasses; |
} |
// TODO return the most specific matching method instead of the first one |
// (handle both Sub/Superclass and primitive/object type) |
private static final Method findMethod(Class<?> clazz, String name, List<Class<?>> actualArgs) { |
for (final Method m : clazz.getMethods()) { |
if (m.getName().equals(name) && callableWith(m.getParameterTypes(), actualArgs)) { |
return m; |
} |
} |
return null; |
} |
// TODO see findMethod() |
private static final Constructor findCtor(Class<?> clazz, List<Class<?>> actualArgs) { |
for (final Constructor m : clazz.getConstructors()) { |
if (callableWith(m.getParameterTypes(), actualArgs)) { |
return m; |
} |
} |
return null; |
} |
private static final boolean callableWith(Class<?>[] formalArgs, List<Class<?>> actualArgs) { |
if (formalArgs.length != actualArgs.size()) |
return false; |
int i = 0; |
for (final Class<?> argClass : formalArgs) { |
final Class<?> actualArg = actualArgs.get(i); |
// null match everything |
if (actualArg != null && !argClass.isAssignableFrom(actualArg) && argClass != getPrimitive(actualArg)) |
return false; |
i++; |
} |
return true; |
} |
private static Class<?> getPrimitive(Class<?> argClass) { |
if (argClass == Boolean.class) |
return Boolean.TYPE; |
else if (argClass == Character.class) |
return Character.TYPE; |
else if (argClass == Byte.class) |
return Byte.TYPE; |
else if (argClass == Short.class) |
return Short.TYPE; |
else if (argClass == Integer.class) |
return Integer.TYPE; |
else if (argClass == Long.class) |
return Long.TYPE; |
else if (argClass == Float.class) |
return Float.TYPE; |
else if (argClass == Double.class) |
return Double.TYPE; |
else |
return null; |
} |
private static final Map<String, Class> primitiveNames = new HashMap<String, Class>(); |
static { |
primitiveNames.put("boolean", boolean.class); |
primitiveNames.put("byte", byte.class); |
primitiveNames.put("char", char.class); |
primitiveNames.put("short", short.class); |
primitiveNames.put("int", int.class); |
primitiveNames.put("long", long.class); |
primitiveNames.put("float", float.class); |
primitiveNames.put("double", double.class); |
} |
/** |
* Parse class names (including primitive). |
* |
* @param className a class name, eg "java.lang.String" or "int". |
* @return the matching class, eg java.lang.String.class or Integer.TYPE. |
* @throws ClassNotFoundException if the passed name doesn't exist. |
*/ |
private static Class<?> parseClassName(String className) throws ClassNotFoundException { |
final Class<?> primitive = primitiveNames.get(className); |
if (primitive != null) |
return primitive; |
else |
return Class.forName(className); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/xml/XMLCodecUtils.java |
---|
13,11 → 13,6 |
package org.openconcerto.xml; |
import org.openconcerto.utils.StringUtils; |
import org.openconcerto.utils.cache.CacheResult; |
import org.openconcerto.utils.cache.ICache; |
import org.openconcerto.utils.cc.ExnTransformer; |
import java.awt.Dimension; |
import java.awt.Point; |
import java.awt.Rectangle; |
35,11 → 30,8 |
import java.io.ByteArrayOutputStream; |
import java.io.IOException; |
import java.lang.reflect.Array; |
import java.lang.reflect.Constructor; |
import java.lang.reflect.InvocationTargetException; |
import java.lang.reflect.Method; |
import java.nio.charset.Charset; |
import java.util.ArrayList; |
import java.util.Collection; |
import java.util.HashMap; |
import java.util.List; |
47,7 → 39,6 |
import java.util.Map.Entry; |
import java.util.RandomAccess; |
import java.util.Set; |
import java.util.Stack; |
import org.jdom2.Element; |
import org.jdom2.JDOMException; |
62,9 → 53,6 |
private static final String END_DECL = "?>"; |
private static final ICache<Object, Method, Object> cache = new ICache<Object, Method, Object>(60, -1, "methods for " + XMLCodecUtils.class); |
private static final ICache<Object, Constructor<?>, Object> cacheCtor = new ICache<Object, Constructor<?>, Object>(60, -1, "constructors for " + XMLCodecUtils.class); |
// the same as XMLEncoder |
private static final Charset CS = Charset.forName("UTF-8"); |
85,6 → 73,9 |
} |
}; |
public static final XMLDecoderJDOM XML_DECODER_JDOM = new XMLDecoderJDOM(); |
public static final XMLDecoderStAX XML_DECODER_STAX = new XMLDecoderStAX(); |
/** |
* Register a {@link PersistenceDelegate} for the passed class. This method tries to set |
* <code>del</code> as the default for any subsequent {@link Encoder}, but with the current JRE |
130,7 → 121,46 |
return res; |
} |
public static final String encodeAsArray(final Map<?, ?> m) { |
return encodeAsArray(m, new StringBuilder(1024)).toString(); |
} |
/** |
* Encode a map as an array. Useful since parsing an array is faster than parsing a map. |
* |
* @param m the map to encode. |
* @param sb where to encode. |
* @return <code>sb</code>. |
* @see AbstractXMLDecoder#decodeFromArray(Object, Class, Class) |
*/ |
public static final StringBuilder encodeAsArray(final Map<?, ?> m, final StringBuilder sb) { |
final Object[] array = new Object[m.size() * 2]; |
int i = 0; |
for (final Entry<?, ?> e : m.entrySet()) { |
array[i++] = e.getKey(); |
array[i++] = e.getValue(); |
} |
assert i == array.length; |
return encodeSimple(array, sb); |
} |
public static final <K, V> Map<K, V> decodeFromArray(final Object[] array, final Class<K> keyClass, final Class<V> valueClass) { |
return decodeFromArray(array, keyClass, valueClass, null); |
} |
public static final <K, V> Map<K, V> decodeFromArray(final Object[] array, final Class<K> keyClass, final Class<V> valueClass, Map<K, V> m) { |
final int l = array.length; |
if (m == null) |
m = new HashMap<K, V>((int) (l / 2 / 0.8f) + 1, 0.8f); |
for (int i = 0; i < l; i += 2) { |
final K key = keyClass.cast(array[i]); |
final V value = valueClass.cast(array[i + 1]); |
m.put(key, value); |
} |
return m; |
} |
/** |
* Encodes an object using {@link XMLEncoder}, stripping the XML declaration. |
* |
* @param o the object to encode. |
153,10 → 183,14 |
*/ |
public static final String encodeSimple(Object o) { |
final StringBuilder sb = new StringBuilder(256); |
return encodeSimple(o, sb).toString(); |
} |
public static final StringBuilder encodeSimple(final Object o, final StringBuilder sb) { |
sb.append("<java version=\"1.6.0\" class=\"java.beans.XMLDecoder\">"); |
encodeSimpleRec(o, sb); |
sb.append("</java>"); |
return sb.toString(); |
return sb; |
} |
private static final void createElemEscaped(final String elemName, final Object o, final StringBuilder sb) { |
361,287 → 395,9 |
* @return the decoded object. |
*/ |
public static final Object decode1(Element javaElem) { |
final Element elem = (Element) javaElem.getChildren().get(0); |
try { |
return eval(elem, new Stack<Object>(), new HashMap<String, Object>()); |
} catch (Exception e) { |
throw new IllegalStateException("error decoding " + JDOM2Utils.output(javaElem), e); |
return XML_DECODER_JDOM.decode1(javaElem); |
} |
} |
private static final Object eval(Element elem, Stack<Object> context, final Map<String, Object> ids) |
throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException { |
final String n = elem.getName(); |
// Ordered from real world scenario |
// string : 80k |
// void : 53k |
// int : 18k |
// object : 9k |
// null : 6k |
if (n.equals("string")) { |
return elem.getText(); |
} else if (n.equals("void") || n.equals("object")) { |
final String idref = elem.getAttributeValue("idref"); |
if (idref != null) { |
if (!ids.containsKey(idref)) |
throw new IllegalStateException("id '" + idref + "' wasn't defined"); |
return ids.get(idref); |
} |
final String id = elem.getAttributeValue("id"); |
final String targetClass = elem.getAttributeValue("class"); |
final Object target = targetClass == null ? context.peek() : Class.forName(targetClass); |
final String propAttr = elem.getAttributeValue("property"); |
final String indexAttr = elem.getAttributeValue("index"); |
final String methodAttr = elem.getAttributeValue("method"); |
// statement or expression |
final Object res = evalContainer(elem, context, ids, new ExnTransformer<List<Object>, Object, Exception>() { |
@Override |
public Object transformChecked(List<Object> args) throws Exception { |
// call the statement |
final Object res; |
if (propAttr != null) { |
final String methodName = (args.size() == 0 ? "get" : "set") + StringUtils.firstUp(propAttr); |
res = invoke(target, methodName, args); |
} else if (indexAttr != null) { |
final String methodName; |
if (target instanceof List) { |
methodName = args.size() == 0 ? "get" : "set"; |
// get(index) or set(index, value) |
args.add(0, Integer.valueOf(indexAttr)); |
res = invoke(target, methodName, args); |
} else if (target.getClass().isArray()) { |
final Class<?> componentType = target.getClass().getComponentType(); |
// in Array there's set(array, int index, Object value) or |
// setPrimitive(array, int index, primitive value) |
methodName = (args.size() == 0 ? "get" : "set") + (componentType.isPrimitive() ? StringUtils.firstUp(componentType.getSimpleName()) : ""); |
args.add(0, target); |
args.add(1, Integer.valueOf(indexAttr)); |
res = invoke(Array.class, methodName, args); |
} else |
throw new IllegalStateException("use index with neither List nor array: " + target); |
} else if (methodAttr != null) { |
res = invoke(target, methodAttr, args); |
} else |
res = getCtor((Class<?>) target, args).newInstance(args.toArray()); |
return res; |
} |
}); |
// not very functional but it works |
if (id != null) |
ids.put(id, res); |
return res; |
} else if (n.equals("int")) { |
return Integer.valueOf(elem.getText()); |
} else if (n.equals("null")) { |
return null; |
} else if (n.equals("boolean")) { |
return Boolean.valueOf(elem.getText()); |
} else if (n.equals("byte")) { |
return Byte.valueOf(elem.getText()); |
} else if (n.equals("char")) { |
return Character.valueOf(elem.getText().charAt(0)); |
} else if (n.equals("short")) { |
return Short.valueOf(elem.getText()); |
} else if (n.equals("long")) { |
return Long.valueOf(elem.getText()); |
} else if (n.equals("float")) { |
return Float.valueOf(elem.getText()); |
} else if (n.equals("double")) { |
return Double.valueOf(elem.getText()); |
} else if (n.equals("array")) { |
final String classAttr = elem.getAttributeValue("class"); |
final String lengthAttr = elem.getAttributeValue("length"); |
final Class<?> componentClass = parseClassName(classAttr); |
if (lengthAttr != null) { |
context.push(Array.newInstance(componentClass, Integer.parseInt(lengthAttr))); |
for (final Object child : elem.getChildren()) { |
eval((Element) child, context, ids); |
} |
return context.pop(); |
} else { |
return evalContainer(elem, context, ids, new ExnTransformer<List<Object>, Object, RuntimeException>() { |
@Override |
public Object transformChecked(List<Object> args) { |
final Object res = Array.newInstance(componentClass, args.size()); |
for (int j = 0; j < args.size(); j++) { |
Array.set(res, j, args.get(j)); |
} |
return res; |
} |
}); |
} |
} else if (n.equals("class")) { |
return Class.forName(elem.getText()); |
} else |
throw new UnsupportedOperationException("doesn't yet support " + n); |
} |
private static final Object evalContainer(final Element parent, Stack<Object> context, final Map<String, Object> ids, final ExnTransformer<List<Object>, Object, ? extends Exception> transf) |
throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException { |
final List<Object> args = new ArrayList<Object>(); |
final List<?> children = parent.getChildren(); |
int i = 0; |
boolean noVoid = true; |
final int size = children.size(); |
while (i < size && noVoid) { |
final Element child = (Element) children.get(i); |
if (child.getName().equals("void")) |
noVoid = false; |
else { |
args.add(eval(child, context, ids)); |
i++; |
} |
} |
// call the statement |
final Object res = transf.transformCheckedWithExn(args, false, InvocationTargetException.class, InstantiationException.class, IllegalAccessException.class); |
context.push(res); |
// now call the voids |
while (i < children.size()) { |
final Element child = (Element) children.get(i); |
eval(child, context, ids); |
i++; |
} |
return context.pop(); |
} |
private static final Object invoke(final Object target, String methodName, final List<Object> args) throws IllegalAccessException, InvocationTargetException { |
// <object class="Cell" method="createEmpty" > |
// for static methods the target is already a class |
final Class clazz = target instanceof Class ? (Class) target : target.getClass(); |
final Method m = getMethod(clazz, methodName, args); |
return m.invoke(target, args.toArray()); |
} |
private static final Method getMethod(Class<?> clazz, String name, List<Object> actualArgs) { |
final List<Class<?>> actualClasses = objectsToClasses(actualArgs); |
final List<Object> key = new ArrayList<Object>(3); |
key.add(clazz); |
key.add(name); |
key.add(actualClasses); |
final CacheResult<Method> cacheRes = cache.check(key); |
if (cacheRes.getState() == CacheResult.State.VALID) |
return cacheRes.getRes(); |
final Method res = findMethod(clazz, name, actualClasses); |
cache.put(key, res); |
return res; |
} |
private static final Constructor getCtor(Class<?> clazz, List<Object> actualArgs) { |
final List<Class<?>> actualClasses = objectsToClasses(actualArgs); |
final List<Object> key = new ArrayList<Object>(3); |
key.add(clazz); |
key.add(actualClasses); |
final CacheResult<Constructor<?>> cacheRes = cacheCtor.check(key); |
if (cacheRes.getState() == CacheResult.State.VALID) |
return cacheRes.getRes(); |
final Constructor res = findCtor(clazz, actualClasses); |
cacheCtor.put(key, res); |
return res; |
} |
private static final List<Class<?>> objectsToClasses(List<Object> actualArgs) { |
final List<Class<?>> actualClasses = new ArrayList<Class<?>>(actualArgs.size()); |
for (final Object actualArg : actualArgs) |
actualClasses.add(actualArg == null ? null : actualArg.getClass()); |
return actualClasses; |
} |
// TODO return the most specific matching method instead of the first one |
// (handle both Sub/Superclass and primitive/object type) |
private static final Method findMethod(Class<?> clazz, String name, List<Class<?>> actualArgs) { |
for (final Method m : clazz.getMethods()) { |
if (m.getName().equals(name) && callableWith(m.getParameterTypes(), actualArgs)) { |
return m; |
} |
} |
return null; |
} |
// TODO see findMethod() |
private static final Constructor findCtor(Class<?> clazz, List<Class<?>> actualArgs) { |
for (final Constructor m : clazz.getConstructors()) { |
if (callableWith(m.getParameterTypes(), actualArgs)) { |
return m; |
} |
} |
return null; |
} |
private static final boolean callableWith(Class<?>[] formalArgs, List<Class<?>> actualArgs) { |
if (formalArgs.length != actualArgs.size()) |
return false; |
int i = 0; |
for (final Class<?> argClass : formalArgs) { |
final Class<?> actualArg = actualArgs.get(i); |
// null match everything |
if (actualArg != null && !argClass.isAssignableFrom(actualArg) && argClass != getPrimitive(actualArg)) |
return false; |
i++; |
} |
return true; |
} |
private static Class<?> getPrimitive(Class<?> argClass) { |
if (argClass == Boolean.class) |
return Boolean.TYPE; |
else if (argClass == Character.class) |
return Character.TYPE; |
else if (argClass == Byte.class) |
return Byte.TYPE; |
else if (argClass == Short.class) |
return Short.TYPE; |
else if (argClass == Integer.class) |
return Integer.TYPE; |
else if (argClass == Long.class) |
return Long.TYPE; |
else if (argClass == Float.class) |
return Float.TYPE; |
else if (argClass == Double.class) |
return Double.TYPE; |
else |
return null; |
} |
private static final Map<String, Class> primitiveNames = new HashMap<String, Class>(); |
static { |
primitiveNames.put("boolean", boolean.class); |
primitiveNames.put("byte", byte.class); |
primitiveNames.put("char", char.class); |
primitiveNames.put("short", short.class); |
primitiveNames.put("int", int.class); |
primitiveNames.put("long", long.class); |
primitiveNames.put("float", float.class); |
primitiveNames.put("double", double.class); |
} |
/** |
* Parse class names (including primitive). |
* |
* @param className a class name, eg "java.lang.String" or "int". |
* @return the matching class, eg java.lang.String.class or Integer.TYPE. |
* @throws ClassNotFoundException if the passed name doesn't exist. |
*/ |
private static Class<?> parseClassName(String className) throws ClassNotFoundException { |
final Class<?> primitive = primitiveNames.get(className); |
if (primitive != null) |
return primitive; |
else |
return Class.forName(className); |
} |
private XMLCodecUtils() { |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/xml/XMLUtils.java |
---|
New file |
0,0 → 1,133 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.xml; |
import javax.xml.stream.XMLStreamConstants; |
import javax.xml.stream.XMLStreamException; |
import javax.xml.stream.XMLStreamReader; |
public class XMLUtils { |
public static final String escapeAttribute(final String value) { |
final int len = value.length(); |
int idx = 0; |
checkloop: while (idx < len) { |
final char ch = value.charAt(idx); |
if (ch == '<' || ch == '>' || ch == '&' || ch == '\r' || ch == '\n' || ch == '"' || ch == '\t') { |
break checkloop; |
} |
idx++; |
} |
if (idx == len) { |
return value; |
} |
final StringBuilder sb = new StringBuilder(len + 5); |
sb.append(value, 0, idx); |
while (idx < len) { |
final char ch = value.charAt(idx++); |
switch (ch) { |
case '<': |
sb.append("<"); |
break; |
case '>': |
sb.append(">"); |
break; |
case '&': |
sb.append("&"); |
break; |
case '\r': |
sb.append("
"); |
break; |
case '"': |
sb.append("""); |
break; |
case '\t': |
sb.append("	"); |
break; |
case '\n': |
sb.append("
"); |
break; |
default: |
sb.append(ch); |
break; |
} |
} |
return sb.toString(); |
} |
public static final String escapeText(final String value) { |
final int right = value.length(); |
int idx = 0; |
checkloop: while (idx < right) { |
final char ch = value.charAt(idx); |
if (ch == '<' || ch == '>' || ch == '&' || ch == '\r' || ch == '\n') { |
break checkloop; |
} |
idx++; |
} |
if (idx == right) { |
// no escape needed. |
return value; |
} |
final StringBuilder sb = new StringBuilder(); |
if (idx > 0) { |
sb.append(value, 0, idx); |
} |
while (idx < right) { |
final char ch = value.charAt(idx++); |
switch (ch) { |
case '<': |
sb.append("<"); |
break; |
case '>': |
sb.append(">"); |
break; |
case '&': |
sb.append("&"); |
break; |
case '\r': |
sb.append("
"); |
break; |
case '\n': |
sb.append('\n'); |
break; |
default: |
sb.append(ch); |
break; |
} |
} |
return sb.toString(); |
} |
public static final void skipToEndElement(final XMLStreamReader reader) throws XMLStreamException { |
if (!reader.isStartElement()) |
throw new IllegalStateException("Not at a start of an element : " + reader.getEventType() + ", " + reader.getLocation()); |
final String name = reader.getLocalName(); |
int depth = 1; |
while (!(depth == 0 && reader.isEndElement() && reader.getLocalName().equals(name))) { |
final int eventType = reader.next(); |
if (eventType == XMLStreamConstants.START_ELEMENT) |
depth++; |
else if (eventType == XMLStreamConstants.END_ELEMENT) |
depth--; |
} |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/xml/XMLDecoderStAX.java |
---|
New file |
0,0 → 1,99 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.xml; |
import javax.xml.stream.XMLStreamException; |
import javax.xml.stream.XMLStreamReader; |
/** |
* To decode using {@link XMLStreamReader}. |
* |
* @author Sylvain CUAZ |
*/ |
public final class XMLDecoderStAX extends AbstractXMLDecoder<XMLStreamReader, XMLStreamException> { |
@Override |
protected String getAttributeValue(XMLStreamReader elem, String attrName) { |
return elem.getAttributeValue(null, attrName); |
} |
@Override |
protected String getLocalName(XMLStreamReader elem) { |
return elem.getLocalName(); |
} |
@Override |
protected String getElementText(XMLStreamReader elem) throws XMLStreamException { |
return elem.getElementText(); |
} |
@Override |
protected XMLStreamReader getFirstChild(XMLStreamReader reader) { |
try { |
reader.nextTag(); |
} catch (XMLStreamException e) { |
throw new IllegalStateException("Couldn't advance to first child", e); |
} |
return reader; |
} |
@Override |
protected void preEval(XMLStreamReader reader) throws XMLStreamException { |
assert reader.isStartElement(); |
} |
@Override |
protected void nullDecoded(XMLStreamReader reader) throws XMLStreamException { |
reader.nextTag(); |
} |
@Override |
protected void idRefDecoded(XMLStreamReader reader) throws XMLStreamException { |
reader.nextTag(); |
} |
@Override |
protected void postEval(XMLStreamReader reader, final Object res) throws XMLStreamException { |
assert reader.isEndElement(); |
reader.nextTag(); |
} |
@Override |
protected String toString(XMLStreamReader elem) { |
return elem.getLocation().toString(); |
} |
@Override |
protected Children<XMLStreamReader> createChildren(final XMLStreamReader reader) throws XMLStreamException { |
if (!reader.isStartElement()) |
throw new IllegalStateException("Not at a start of an element : " + reader.getLocation()); |
final String localName = reader.getLocalName(); |
// move from START parent to either : |
// 1. END parent if no children, or |
// 2. START child |
reader.nextTag(); |
return new Children<XMLStreamReader>() { |
@Override |
public XMLStreamReader getNextChild() { |
if (reader.isEndElement() && reader.getLocalName().equals(localName)) { |
return null; |
} |
return reader; |
} |
}; |
} |
protected XMLDecoderStAX() { |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/xml/FastXMLProperties.java |
---|
New file |
0,0 → 1,71 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.xml; |
import java.io.BufferedInputStream; |
import java.io.IOException; |
import java.io.InputStream; |
import java.io.OutputStream; |
import java.io.PrintStream; |
import java.util.Properties; |
import org.jdom2.Document; |
import org.jdom2.Element; |
import org.jdom2.input.SAXBuilder; |
import org.jdom2.input.sax.XMLReaderSAX2Factory; |
public class FastXMLProperties { |
public static void load(Properties props, InputStream in) throws IOException { |
final SAXBuilder builder = new SAXBuilder(new XMLReaderSAX2Factory(false, "com.bluecast.xml.Piccolo"), null, null); |
try { |
final Document document = builder.build(new BufferedInputStream(in)); |
for (Element element : document.getRootElement().getChildren()) { |
if (element.getName().equals("entry")) { |
props.setProperty(element.getAttributeValue("key"), element.getText()); |
} |
} |
} catch (Exception e) { |
throw new IOException(e); |
} |
} |
/** |
* Fast alternative (<1ms) for Properties.storeToXML (30ms) |
* |
*/ |
public static void store(Properties props, OutputStream out, String comment) throws IOException { |
PrintStream prt = new PrintStream(out, false, "UTF-8"); |
prt.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n"); |
prt.append("<properties>\\r\n"); |
if (comment != null) { |
prt.append("<comment>"); |
prt.append(comment); |
prt.append("</comment>\\r\n"); |
} |
synchronized (props) { |
for (String k : props.stringPropertyNames()) { |
prt.append("<entry key=\""); |
prt.append(XMLUtils.escapeAttribute(k)); |
prt.append("\">"); |
prt.append(XMLUtils.escapeText(props.getProperty(k))); |
prt.append("</entry>\\r\n"); |
} |
} |
prt.append("</properties>"); |
prt.close(); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/xml/XMLDecoderJDOM.java |
---|
New file |
0,0 → 1,74 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.xml; |
import java.beans.XMLDecoder; |
import java.beans.XMLEncoder; |
import java.util.Iterator; |
import org.jdom2.Element; |
/** |
* To encode and decode using {@link XMLEncoder} and {@link XMLDecoder}. |
* |
* @author Sylvain CUAZ |
*/ |
public final class XMLDecoderJDOM extends AbstractXMLDecoder<Element, RuntimeException> { |
@Override |
protected String getAttributeValue(Element elem, String attrName) { |
return elem.getAttributeValue(attrName); |
} |
@Override |
protected String getLocalName(Element elem) { |
return elem.getName(); |
} |
@Override |
protected String getElementText(Element elem) { |
return elem.getText(); |
} |
@Override |
protected Element getFirstChild(Element elem) { |
return elem.getChildren().get(0); |
} |
@Override |
protected String toString(Element elem) { |
return JDOM2Utils.output(elem); |
} |
@Override |
protected Children<Element> createChildren(final Element elem) { |
return new Children<Element>() { |
private final Iterator<Element> iter = elem.getChildren().iterator(); |
@Override |
public Element getNextChild() { |
if (!this.iter.hasNext()) |
return null; |
final Element res = this.iter.next(); |
assert res != null; |
return res; |
} |
}; |
} |
protected XMLDecoderJDOM() { |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/action/CreateIListFrameAbstractAction.java |
---|
27,6 → 27,10 |
super(conf, clazz); |
} |
protected CreateIListFrameAbstractAction(final ComptaPropsConfiguration conf, final E elem) { |
super(conf, elem); |
} |
protected SQLTableModelSource createTableSource() { |
return this.getElem().createTableSource(); |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/action/CreateEditFrameAbstractAction.java |
---|
29,7 → 29,11 |
private static final String[] TRANSLATION_KEY_ARRAY = new String[] { TRANSLATION_KEY }; |
protected CreateEditFrameAbstractAction(final PropsConfiguration conf, final Class<? extends E> clazz) { |
super(conf.getDirectory().getElement(clazz)); |
this(conf, conf.getDirectory().getElementOfClass(clazz, true)); |
} |
protected CreateEditFrameAbstractAction(final PropsConfiguration conf, final E elem) { |
super(elem); |
// TODO use conf to find TM |
final NounClass nounClass = this.getElem().getName().getNounClass(); |
final String[] translationKeys = nounClass == null ? TRANSLATION_KEY_ARRAY : new String[] { TRANSLATION_KEY + '.' + nounClass.getName(), TRANSLATION_KEY }; |
/trunk/OpenConcerto/src/org/openconcerto/erp/action/NouvelleConnexionAction.java |
---|
293,6 → 293,11 |
} |
static public void initCache(final ComptaPropsConfiguration comptaConf) { |
initCache(comptaConf, 600); |
} |
static public void initCache(final ComptaPropsConfiguration comptaConf, final int timeout) { |
final SQLBase baseSociete = comptaConf.getSQLBaseSociete(); |
Thread t = new Thread() { |
@Override |
299,7 → 304,7 |
public void run() { |
// laisse le temps au logiciel de demarrer |
try { |
Thread.sleep(1000); |
Thread.sleep(10000); |
} catch (InterruptedException e) { |
e.printStackTrace(); |
} |
310,19 → 315,19 |
Ville.init(new NXDatabaseAccessor(comptaConf), prefs.getBoolean(GestionClientPreferencePanel.LOAD_CITIES, true)); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("TAXE"), 600); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("ETAT_DEVIS"), 600); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("PREFS_COMPTE"), 600); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("COMPTE_PCE"), 600); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("JOURNAL"), 600); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("TAXE"), timeout); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("ETAT_DEVIS"), timeout); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("PREFS_COMPTE"), timeout); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("COMPTE_PCE"), timeout); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("JOURNAL"), timeout); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("COMMERCIAL"), 600); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("PERIODE_VALIDITE"), 1000); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("COMMERCIAL"), timeout); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("PERIODE_VALIDITE"), timeout); |
if (comptaConf.getRootSociete().contains("DEPOT_STOCK")) { |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("DEPOT_STOCK"), 600); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("DEPOT_STOCK"), timeout); |
} |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("TYPE_REGLEMENT"), 1000); |
SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("TYPE_REGLEMENT"), timeout); |
SQLBackgroundTableCache.getInstance().startCacheWatcher(); |
TaxeCache.getCache(); |
/trunk/OpenConcerto/src/org/openconcerto/erp/action/CreateListFrameAbstractAction.java |
---|
61,7 → 61,11 |
private final ComptaPropsConfiguration conf; |
protected CreateListFrameAbstractAction(final ComptaPropsConfiguration conf, final Class<? extends E> clazz) { |
super(conf.getDirectory().getElement(clazz)); |
this(conf, conf.getDirectory().getElementOfClass(clazz, true)); |
} |
protected CreateListFrameAbstractAction(final ComptaPropsConfiguration conf, final E elem) { |
super(elem); |
this.conf = conf; |
// TODO use conf to find TM |
final NounClass nounClass = this.getElem().getName().getNounClass(); |
/trunk/OpenConcerto/src/org/openconcerto/erp/injector/DevisCommandeSQLInjector.java |
---|
68,7 → 68,10 |
map(tableDevis.getField("MONTANT_REMISE"), getDestination().getField("MONTANT_REMISE")); |
map(tableDevis.getField("POURCENT_REMISE"), getDestination().getField("POURCENT_REMISE")); |
} |
if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) { |
map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE")); |
} |
} |
@Override |
protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) { |
78,9 → 81,9 |
final SQLTable tableElementSource = getSource().getTable("DEVIS_ELEMENT"); |
final SQLTable tableElementDestination = getSource().getTable("COMMANDE_CLIENT_ELEMENT"); |
final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource); |
transfertReference(srcRow, rowVals, "OBJET", "NOM"); |
transfertReference(srcRow, rowVals, "INFOS", "INFOS"); |
transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_COMMANDE_CLIENT"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_COMMANDE_CLIENT", "OBJET", "NOM"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_COMMANDE_CLIENT", "INFOS", "INFOS"); |
if (myListItem.size() != 0) { |
final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination); |
/trunk/OpenConcerto/src/org/openconcerto/erp/injector/DevisFactureSQLInjector.java |
---|
67,7 → 67,10 |
map(tableDevis.getField("MONTANT_REMISE"), tableFacture.getField("MONTANT_REMISE")); |
map(tableDevis.getField("POURCENT_REMISE"), tableFacture.getField("POURCENT_REMISE")); |
} |
if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) { |
map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE")); |
} |
} |
@Override |
protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) { |
78,9 → 81,9 |
final SQLTable tableElementSource = getSource().getTable("DEVIS_ELEMENT"); |
final SQLTable tableElementDestination = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT"); |
final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource); |
transfertReference(srcRow, rowVals, "OBJET", "NOM"); |
transfertReference(srcRow, rowVals, "INFOS", "INFOS"); |
transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE", "OBJET", "NOM"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE", "INFOS", "INFOS"); |
if (getDestination().contains("ID_TAXE_FRAIS_DOCUMENT")) { |
final SQLRowAccessor rowClient = srcRow.getForeign("ID_CLIENT"); |
/trunk/OpenConcerto/src/org/openconcerto/erp/injector/BonFactureSQLInjector.java |
---|
46,6 → 46,9 |
if (getSource().getTable().contains("ID_ADRESSE_LIVRAISON")) { |
map(getSource().getField("ID_ADRESSE_LIVRAISON"), getDestination().getField("ID_ADRESSE_LIVRAISON")); |
} |
if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) { |
map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE")); |
} |
if (tableBon.contains("ID_TAXE_PORT")) { |
map(tableBon.getField("ID_TAXE_PORT"), tableFacture.getField("ID_TAXE_PORT")); |
} |
77,9 → 80,9 |
final SQLTable tableElementSource = getSource().getTable("BON_DE_LIVRAISON_ELEMENT"); |
final SQLTable tableElementDestination = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT"); |
final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource); |
transfertReference(srcRow, rowVals, "NOM", "NOM"); |
transfertReference(srcRow, rowVals, "INFOS", "INFOS"); |
transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE", "NOM", "NOM"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE", "INFOS", "INFOS"); |
if (getDestination().contains("ID_TAXE_FRAIS_DOCUMENT")) { |
final SQLRowAccessor rowClient = srcRow.getForeign("ID_CLIENT"); |
SQLRowAccessor rowFrais = rowClient.getForeign("ID_FRAIS_DOCUMENT"); |
/trunk/OpenConcerto/src/org/openconcerto/erp/injector/DevisBlSQLInjector.java |
---|
45,7 → 45,10 |
if (getSource().getTable().contains("ID_ADRESSE_LIVRAISON")) { |
map(getSource().getField("ID_ADRESSE_LIVRAISON"), getDestination().getField("ID_ADRESSE_LIVRAISON")); |
} |
if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) { |
map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE")); |
} |
} |
@Override |
protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) { |
55,9 → 58,9 |
final SQLTable tableElementSource = getSource().getTable("DEVIS_ELEMENT"); |
final SQLTable tableElementDestination = getSource().getTable("BON_DE_LIVRAISON_ELEMENT"); |
final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource); |
transfertReference(srcRow, rowVals, "NOM", "NOM"); |
transfertReference(srcRow, rowVals, "INFOS", "INFOS"); |
transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON", "NOM", "NOM"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON", "INFOS", "INFOS"); |
if (myListItem.size() != 0) { |
final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination); |
/trunk/OpenConcerto/src/org/openconcerto/erp/injector/FactureBonSQLInjector.java |
---|
49,9 → 49,9 |
final SQLTable tableElementSource = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT"); |
final SQLTable tableElementDestination = getSource().getTable("BON_DE_LIVRAISON_ELEMENT"); |
final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource); |
transfertReference(srcRow, rowVals, "NOM", "NOM"); |
transfertReference(srcRow, rowVals, "INFOS", "INFOS"); |
transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON", "NOM", "NOM"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON", "INFOS", "INFOS"); |
if (myListItem.size() != 0) { |
final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination); |
/trunk/OpenConcerto/src/org/openconcerto/erp/injector/FactureAvoirSQLInjector.java |
---|
43,7 → 43,9 |
if (getSource().contains("ID_ADRESSE_LIVRAISON") && getDestination().contains("ID_ADRESSE_LIVRAISON")) { |
map(getSource().getField("ID_ADRESSE_LIVRAISON"), getDestination().getField("ID_ADRESSE_LIVRAISON")); |
} |
if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) { |
map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE")); |
} |
if (getSource().getTable().contains("DATE_LIVRAISON") && getDestination().contains("DATE_LIVRAISON")) { |
map(getSource().getField("DATE_LIVRAISON"), getDestination().getField("DATE_LIVRAISON")); |
} |
64,8 → 66,8 |
final SQLTable tableElementSource = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT"); |
final SQLTable tableElementDestination = getSource().getTable("AVOIR_CLIENT_ELEMENT"); |
final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource); |
transfertReference(srcRow, rowVals, "NOM", "NOM"); |
transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_AVOIR_CLIENT"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_AVOIR_CLIENT", "NOM", "NOM"); |
if (myListItem.size() != 0) { |
final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination); |
/trunk/OpenConcerto/src/org/openconcerto/erp/injector/CommandeFactureClientSQLInjector.java |
---|
72,8 → 72,10 |
if (tableFacture.contains("CREATE_VIRTUAL_STOCK")) { |
mapDefaultValues(tableFacture.getField("CREATE_VIRTUAL_STOCK"), Boolean.FALSE); |
} |
if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) { |
map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE")); |
} |
} |
@Override |
protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) { |
83,9 → 85,9 |
final SQLTable tableElementSource = getSource().getTable("COMMANDE_CLIENT_ELEMENT"); |
final SQLTable tableElementDestination = getSource().getTable("SAISIE_VENTE_FACTURE_ELEMENT"); |
final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource); |
transfertReference(srcRow, rowVals, "NOM", "NOM"); |
transfertReference(srcRow, rowVals, "INFOS", "INFOS"); |
transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE", "NOM", "NOM"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_SAISIE_VENTE_FACTURE", "INFOS", "INFOS"); |
if (getDestination().contains("ID_TAXE_FRAIS_DOCUMENT")) { |
final SQLRowAccessor rowClient = srcRow.getForeign("ID_CLIENT"); |
SQLRowAccessor rowFrais = rowClient.getForeign("ID_FRAIS_DOCUMENT"); |
/trunk/OpenConcerto/src/org/openconcerto/erp/injector/CommandeBlSQLInjector.java |
---|
69,7 → 69,10 |
if (getSource().getTable().contains("ID_ADRESSE_LIVRAISON")) { |
map(getSource().getField("ID_ADRESSE_LIVRAISON"), getDestination().getField("ID_ADRESSE_LIVRAISON")); |
} |
if (getSource().getTable().contains("ID_CATEGORIE_COMPTABLE") && getDestination().getTable().contains("ID_CATEGORIE_COMPTABLE")) { |
map(getSource().getField("ID_CATEGORIE_COMPTABLE"), getDestination().getField("ID_CATEGORIE_COMPTABLE")); |
} |
} |
@Override |
protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) { |
80,10 → 83,9 |
final SQLTable tableElementDestination = getSource().getTable("BON_DE_LIVRAISON_ELEMENT"); |
final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource); |
transfertReference(srcRow, rowVals, "NOM", "NOM"); |
transfertReference(srcRow, rowVals, "INFOS", "INFOS"); |
transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON", "NOM", "NOM"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_BON_DE_LIVRAISON", "INFOS", "INFOS"); |
if (myListItem.size() != 0) { |
final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination); |
/trunk/OpenConcerto/src/org/openconcerto/erp/injector/CommandeFactureEltSQLInjector.java |
---|
20,6 → 20,7 |
public CommandeFactureEltSQLInjector(final DBRoot root) { |
super(root, "COMMANDE_CLIENT_ELEMENT", "SAISIE_VENTE_FACTURE_ELEMENT", false); |
createDefaultMap(); |
remove(getSource().getField("QTE_LIVREE"), getDestination().getField("QTE_LIVREE")); |
if (getDestination().contains("ID_COMMANDE_CLIENT_ELEMENT")) { |
map(getSource().getKey(), getDestination().getField("ID_COMMANDE_CLIENT_ELEMENT")); |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/injector/CommandeFactureFournisseurSQLInjector.java |
---|
36,11 → 36,11 |
// Merge elements |
final SQLTable tableElementSource = getSource().getTable("COMMANDE_ELEMENT"); |
final SQLTable tableElementDestination = getSource().getTable("FACTURE_FOUNRISSEUR_ELEMENT"); |
final SQLTable tableElementDestination = getSource().getTable("FACTURE_FOURNISSEUR_ELEMENT"); |
final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource); |
transfertReference(srcRow, rowVals, "NOM", "NOM"); |
transfertReference(srcRow, rowVals, "INFOS", "INFOS"); |
transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_FACTURE_FOURNISSEUR"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_FACTURE_FOURNISSEUR", "NOM", "NOM"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_FACTURE_FOURNISSEUR", "INFOS", "INFOS"); |
if (myListItem.size() != 0) { |
final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination); |
for (SQLRowAccessor rowElt : myListItem) { |
/trunk/OpenConcerto/src/org/openconcerto/erp/injector/BonReceptionFactureFournisseurSQLInjector.java |
---|
34,7 → 34,13 |
map(getSource().getField("PORT_HT"), getDestination().getField("PORT_HT")); |
map(getSource().getField("ID_TAXE_PORT"), getDestination().getField("ID_TAXE_PORT")); |
} |
if (getSource().contains("ID_AFFAIRE") && getDestination().contains("ID_AFFAIRE")) { |
map(getSource().getField("ID_AFFAIRE"), getDestination().getField("ID_AFFAIRE")); |
} |
if (getSource().contains("ID_POLE_PRODUIT") && getDestination().contains("ID_POLE_PRODUIT")) { |
map(getSource().getField("ID_POLE_PRODUIT"), getDestination().getField("ID_POLE_PRODUIT")); |
} |
} |
@Override |
protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) { |
44,9 → 50,9 |
final SQLTable tableElementSource = getSource().getTable("BON_RECEPTION_ELEMENT"); |
final SQLTable tableElementDestination = getSource().getTable("FACTURE_FOURNISSEUR_ELEMENT"); |
final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource); |
transfertReference(srcRow, rowVals, "NOM", "NOM"); |
transfertReference(srcRow, rowVals, "INFOS", "INFOS"); |
transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_FACTURE_FOURNISSEUR"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_FACTURE_FOURNISSEUR", "NOM", "NOM"); |
transfertReference(srcRow, rowVals, tableElementDestination, "ID_FACTURE_FOURNISSEUR", "INFOS", "INFOS"); |
if (myListItem.size() != 0) { |
final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination); |
for (SQLRowAccessor rowElt : myListItem) { |
/trunk/OpenConcerto/src/org/openconcerto/erp/injector/CommandeBrSQLInjector.java |
---|
40,7 → 40,10 |
if (tableBr.contains("CREATE_VIRTUAL_STOCK")) { |
mapDefaultValues(tableBr.getField("CREATE_VIRTUAL_STOCK"), Boolean.FALSE); |
} |
if (getSource().contains("ID_AFFAIRE") && getDestination().contains("ID_AFFAIRE")) { |
map(getSource().getField("ID_AFFAIRE"), getDestination().getField("ID_AFFAIRE")); |
} |
} |
@Override |
protected void merge(SQLRowAccessor srcRow, SQLRowValues rowVals) { |
50,6 → 53,7 |
final SQLTable tableElementSource = getSource().getTable("COMMANDE_ELEMENT"); |
final SQLTable tableElementDestination = getSource().getTable("BON_RECEPTION_ELEMENT"); |
final Collection<? extends SQLRowAccessor> myListItem = srcRow.asRow().getReferentRows(tableElementSource); |
transfertNumberReference(srcRow, rowVals, tableElementDestination, "ID_BON_RECEPTION"); |
if (myListItem.size() != 0) { |
final SQLInjector injector = SQLInjector.getInjector(tableElementSource, tableElementDestination); |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationDoc/OOXMLField.java |
---|
266,6 → 266,9 |
result += stringValue; |
} |
if (suffix != null) { |
if (suffix.contains("#n")) { |
suffix = suffix.replaceAll("#n", "\n"); |
} |
result += suffix; |
} |
if (cellSize != null && cellSize.trim().length() != 0) { |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationDoc/OOgenerationXML.java |
---|
195,6 → 195,7 |
} |
} catch (Exception e) { |
ExceptionHandler.handle("Impossible de remplir le document " + templateId + " " + ((rowLanguage == null) ? "" : rowLanguage.getString("CHEMIN")), e); |
e.printStackTrace(); |
return null; |
} |
444,6 → 445,12 |
} |
calc.setRemise(valRemiseHTReel, totalAvtRemise); |
// Fix TVA si nécessaire pour facture fournisseur |
if (row.getTable().contains("TVA_ADJUSTMENT")) { |
BigDecimal tvaFix = row.getBigDecimal("TVA_ADJUSTMENT"); |
calc.addTVAAdjust(tvaFix); |
} |
for (int i = 0; i < rows.size(); i++) { |
SQLRowAccessor sqlRow = rows.get(i); |
calc.addLine(sqlRow, sqlRow.getForeign("ID_ARTICLE"), i, i == rows.size() - 1); |
490,6 → 497,20 |
calc.addLine(rowValsPort, rowValsPort.getForeign("ID_ARTICLE"), 1, false); |
} |
if (row.getTable().contains("FRAIS_DOCUMENT_HT") && row.getTable().contains("ID_TAXE_FRAIS_DOCUMENT")) { |
BigDecimal fraisDoc = BigDecimal.valueOf(row.getLong("FRAIS_DOCUMENT_HT")).movePointLeft(2); |
SQLRowAccessor tvafraisDoc = row.getForeign("ID_TAXE_FRAIS_DOCUMENT"); |
if (tvafraisDoc != null && fraisDoc.signum() != 0 && !tvafraisDoc.isUndefined()) { |
SQLRowValues rowValsfraisDoc = new SQLRowValues(tableElt); |
rowValsfraisDoc.put("T_PV_HT", fraisDoc); |
rowValsfraisDoc.put("QTE", 1); |
rowValsfraisDoc.put("ID_TAXE", tvafraisDoc.getIDNumber()); |
rowValsfraisDoc.put("SERVICE", Boolean.TRUE); |
rowValsfraisDoc.put("ID_FAMILLE_ARTICLE", null); |
calc.addLine(rowValsfraisDoc, null, 1, false); |
} |
} |
calc.checkResult(); |
Map<SQLRowAccessor, Tuple2<BigDecimal, BigDecimal>> taxeCalc = calc.getMapHtTVARowTaux(); |
for (SQLRowAccessor sqlRow : taxeCalc.keySet()) { |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationDoc/provider/ArticleCodeFournisseurProvider.java |
---|
New file |
0,0 → 1,69 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.generationDoc.provider; |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueContext; |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProvider; |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.SQLRowListRSH; |
import org.openconcerto.sql.model.SQLSelect; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.model.Where; |
import java.util.List; |
public class ArticleCodeFournisseurProvider implements SpreadSheetCellValueProvider { |
public ArticleCodeFournisseurProvider() { |
} |
public Object getValue(SpreadSheetCellValueContext context) { |
SQLRowAccessor row = context.getRow(); |
String code = row.getString("CODE"); |
if (row.getObject("ID_ARTICLE") != null && !row.isForeignEmpty("ID_ARTICLE")) { |
if (row.getTable().contains("ID_CODE_FOURNISSEUR")) { |
if (row.getObject("ID_CODE_FOURNISSEUR") != null && !row.isForeignEmpty("ID_CODE_FOURNISSEUR")) { |
code = row.getForeign("ID_CODE_FOURNISSEUR").getString("CODE"); |
} else { |
int idFournisseur = row.getForeign("ID_" + row.getTable().getName().replaceAll("_ELEMENT", "")).getForeignID("ID_FOURNISSEUR"); |
SQLSelect sel = new SQLSelect(); |
final SQLTable tableCodeFournisseur = row.getTable().getTable("CODE_FOURNISSEUR"); |
sel.addSelectStar(tableCodeFournisseur); |
Where w = new Where(tableCodeFournisseur.getField("ID_ARTICLE"), "=", row.getForeignID("ID_ARTICLE")); |
w = w.and(new Where(tableCodeFournisseur.getField("ID_FOURNISSEUR"), "=", idFournisseur)); |
sel.setWhere(w); |
List<SQLRow> result = SQLRowListRSH.execute(sel); |
if (!result.isEmpty()) { |
final String val = result.get(0).getString("CODE"); |
if (val.length() > 0) { |
code = val; |
} |
} |
} |
} |
} |
return code; |
} |
public static void register() { |
SpreadSheetCellValueProviderManager.put("supplier.product.code", new ArticleCodeFournisseurProvider()); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationDoc/provider/QteTotalDocProvider.java |
---|
New file |
0,0 → 1,68 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.generationDoc.provider; |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueContext; |
import org.openconcerto.erp.generationDoc.SpreadSheetCellValueProviderManager; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.SQLTable; |
import java.math.BigDecimal; |
import java.util.Collection; |
public class QteTotalDocProvider extends UserInitialsValueProvider { |
private enum TypeQteTotalDocProvider { |
QTE, COLIS |
}; |
private final TypeQteTotalDocProvider type; |
public QteTotalDocProvider(TypeQteTotalDocProvider t) { |
this.type = t; |
} |
@Override |
public Object getValue(SpreadSheetCellValueContext context) { |
SQLRowAccessor row = context.getRow(); |
final SQLTable table = row.getTable(); |
Collection<? extends SQLRowAccessor> cols = row.getReferentRows(table.getTable(table.getName() + "_ELEMENT")); |
BigDecimal total = BigDecimal.ZERO; |
for (SQLRowAccessor sqlRowAccessor : cols) { |
if (!sqlRowAccessor.getTable().contains("NIVEAU") || sqlRowAccessor.getInt("NIVEAU") == 1) { |
if (this.type == TypeQteTotalDocProvider.QTE) { |
BigDecimal qte = sqlRowAccessor.getBigDecimal("QTE_UNITAIRE").multiply(new BigDecimal(sqlRowAccessor.getInt("QTE"))); |
total = total.add(qte); |
} else { |
if (sqlRowAccessor.getObject("NB_COLIS") != null) { |
total = total.add(new BigDecimal(sqlRowAccessor.getInt("NB_COLIS"))); |
} |
} |
} |
} |
return total; |
} |
public static void register() { |
SpreadSheetCellValueProviderManager.put("sales.qty.total", new QteTotalDocProvider(TypeQteTotalDocProvider.QTE)); |
SpreadSheetCellValueProviderManager.put("sales.package.total", new QteTotalDocProvider(TypeQteTotalDocProvider.COLIS)); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationDoc/AbstractJOOReportsSheet.java |
---|
27,6 → 27,7 |
import org.openconcerto.utils.ExceptionHandler; |
import org.openconcerto.utils.FileUtils; |
import java.awt.print.PrinterJob; |
import java.io.BufferedInputStream; |
import java.io.File; |
import java.io.FileNotFoundException; |
245,9 → 246,13 |
return; |
} |
final Component doc = ooConnexion.loadDocument(fileOutOO, true); |
if (this.printer != null && this.printer.trim().length() > 0) { |
Map<String, Object> map = new HashMap<String, Object>(); |
map.put("Name", printer); |
map.put("Name", this.printer); |
doc.printDocument(map); |
} else { |
doc.printDocument(PrinterJob.getPrinterJob()); |
} |
doc.close(); |
} catch (LinkageError e) { |
JOptionPane.showMessageDialog(new JFrame(), "Merci d'installer OpenOffice ou LibreOffice"); |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationDoc/SheetXml.java |
---|
179,6 → 179,7 |
try { |
if (!useODSViewer) { |
if (exportToPDF || printDocument) { |
final Component doc = ComptaPropsConfiguration.getOOConnexion().loadDocument(generatedFile, !showDocument); |
if (printDocument) { |
193,6 → 194,9 |
doc.close(); |
} |
} else { |
openDocument(false); |
} |
} else { |
final OpenDocument doc = new OpenDocument(generatedFile); |
if (showDocument) { |
543,9 → 547,13 |
} |
public void showPreviewDocument() throws Exception { |
showPreviewDocument(null, null); |
} |
public void showPreviewDocument(String actionName, Runnable r) throws Exception { |
File f = null; |
f = getOrCreateDocumentFile(); |
PreviewFrame.show(f); |
PreviewFrame.show(f, actionName, r); |
} |
public void printDocument() { |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationDoc/gestcomm/EtatVentesXmlSheet.java |
---|
24,6 → 24,8 |
import org.openconcerto.sql.model.AliasedTable; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.model.SQLRowValuesListFetcher; |
import org.openconcerto.sql.model.SQLSelect; |
import org.openconcerto.sql.model.SQLSelectJoin; |
import org.openconcerto.sql.model.SQLTable; |
62,11 → 64,13 |
private Timestamp du, au; |
public boolean ticketCaisse = false; |
public boolean facture = false; |
public EtatVentesXmlSheet(Date du, Date au, boolean ticketCaisse) { |
public EtatVentesXmlSheet(Date du, Date au, boolean ticketCaisse, boolean facture) { |
super(); |
this.printer = PrinterNXProps.getInstance().getStringProperty("BonPrinter"); |
this.ticketCaisse = ticketCaisse; |
this.facture = facture; |
if (du != null) { |
final Calendar c1 = Calendar.getInstance(); |
c1.setTime(du); |
128,7 → 132,11 |
styleAllSheetValues.put(0, style); |
} |
final ArrayList<Map<String, Object>> listValuesStock = new ArrayList<>(); |
final Map<Integer, String> styleStock = new HashMap<>(); |
// Ventes |
final SQLTable foreignTableArticle = tableFactureElement.getForeignTable("ID_ARTICLE"); |
{ |
final AliasedTable tableModeReglement1 = new AliasedTable(tableModeReglement, MODE1); |
135,6 → 143,17 |
final AliasedTable tableModeReglement2 = new AliasedTable(tableModeReglement, MODE2); |
final AliasedTable tableTicket = new AliasedTable(eltTicketCaisse.getTable(), "ticket"); |
// Stock |
SQLRowValues rowValsArtStock = new SQLRowValues(foreignTableArticle); |
rowValsArtStock.putNulls("ID", "CODE", "NOM"); |
rowValsArtStock.putRowValues("ID_STOCK").putNulls("QTE_REEL", "QTE_TH", "QTE_MIN", "QTE_RECEPT_ATTENTE", "QTE_LIV_ATTENTE"); |
SQLRowValuesListFetcher fetcherStock = SQLRowValuesListFetcher.create(rowValsArtStock); |
List<SQLRowValues> resultStock = fetcherStock.fetch(); |
Map<Integer, SQLRowValues> mapStock = new HashMap<>(); |
for (SQLRowValues sqlRowValues : resultStock) { |
mapStock.put(sqlRowValues.getID(), sqlRowValues); |
} |
// Requete Pour obtenir les quantités pour chaque type de réglement |
SQLSelect sel = new SQLSelect(); |
193,12 → 212,16 |
selQte.addSelect(tableFactureElement.getField("T_PV_TTC"), "SUM"); |
selQte.addSelect(tableFactureElement.getField("ID_TAXE")); |
selQte.addSelect(tableFactureElement.getField("ID_ARTICLE")); |
if (!this.ticketCaisse) { |
if (this.ticketCaisse) { |
selQte.addJoin("LEFT", tableFactureElement.getField("ID_SAISIE_VENTE_FACTURE")).setWhere(Where.FALSE); |
selQte.addJoin("LEFT", tableFactureElement.getField("ID_TICKET_CAISSE"), "ticket").setWhere(w2); |
} else if (this.facture) { |
selQte.addJoin("LEFT", tableFactureElement.getField("ID_SAISIE_VENTE_FACTURE")).setWhere(w); |
selQte.addJoin("LEFT", tableFactureElement.getField("ID_TICKET_CAISSE"), "ticket").setWhere(Where.FALSE); |
} else { |
selQte.addJoin("LEFT", tableFactureElement.getField("ID_SAISIE_VENTE_FACTURE")).setWhere(Where.FALSE); |
selQte.addJoin("LEFT", tableFactureElement.getField("ID_SAISIE_VENTE_FACTURE")).setWhere(w); |
selQte.addJoin("LEFT", tableFactureElement.getField("ID_TICKET_CAISSE"), "ticket").setWhere(w2); |
} |
selQte.addJoin("LEFT", tableFactureElement.getField("ID_TICKET_CAISSE"), "ticket").setWhere(w2); |
SQLSelectJoin joinArt2 = selQte.addJoin("LEFT", tableFactureElement.getField("ID_ARTICLE")); |
SQLSelectJoin joinFamArt2 = selQte.addJoin("LEFT", joinArt2.getJoinedTable().getField("ID_FAMILLE_ARTICLE")); |
selQte.addSelect(joinFamArt2.getJoinedTable().getField("NOM")); |
234,8 → 257,8 |
mapTVAVT.put(tvaID.intValue(), Tuple2.create(t.get0().add((BigDecimal) ht), t.get1().add(ttc))); |
} |
Number articleID = (Number) sqlRow[7]; |
ArticleVendu a = new ArticleVendu(code, nom, qteVendu.intValue(), (BigDecimal) ht, (BigDecimal) ha, ttc, tvaID.intValue(), |
tableFactureElement.getForeignTable("ID_ARTICLE").getRow(articleID.intValue())); |
ArticleVendu a = new ArticleVendu(code, nom, qteVendu.intValue(), (BigDecimal) ht, (BigDecimal) ha, ttc, tvaID.intValue(), foreignTableArticle.getRow(articleID.intValue())); |
map.put(articleID + "##" + code + "##" + nom + "##" + tvaID, a); |
} |
256,6 → 279,8 |
mValues.put("NOM", famille); |
style.put(listValues.size(), "Titre 1"); |
listValues.add(mValues); |
styleStock.put(listValuesStock.size(), "Titre 1"); |
listValuesStock.add(mValues); |
} else if (valueFam != null && !valueFam.toString().equalsIgnoreCase(famille)) { |
famille = valueFam.toString(); |
Map<String, Object> mValues = new HashMap<String, Object>(); |
262,6 → 287,8 |
mValues.put("NOM", famille); |
style.put(listValues.size(), "Titre 1"); |
listValues.add(mValues); |
styleStock.put(listValuesStock.size(), "Titre 1"); |
listValuesStock.add(mValues); |
} |
Map<String, Object> mValues = new HashMap<String, Object>(); |
291,7 → 318,26 |
totalTPVTTC = totalTPVTTC.add(a.ttc); |
style.put(listValues.size(), "Normal"); |
listValues.add(mValues); |
Map<String, Object> mValuesStock = new HashMap<String, Object>(); |
mValuesStock.put("CODE", code); |
mValuesStock.put("NOM", nom); |
mValuesStock.put("QTE", a.qte); |
if (mapStock.containsKey(articleID)) { |
SQLRowValues rowValsArt = mapStock.get(articleID); |
if (rowValsArt.getObject("ID_STOCK") != null && !rowValsArt.isForeignEmpty("ID_STOCK")) { |
SQLRowAccessor rowValsStock = rowValsArt.getForeign("ID_STOCK"); |
mValuesStock.put("QTE_TH", rowValsStock.getObject("QTE_TH")); |
mValuesStock.put("QTE_REEL", rowValsStock.getObject("QTE_REEL")); |
mValuesStock.put("QTE_MIN", rowValsStock.getObject("QTE_MIN")); |
mValuesStock.put("QTE_RECEPT_ATTENTE", rowValsStock.getObject("QTE_RECEPT_ATTENTE")); |
mValuesStock.put("QTE_LIV_ATTENTE", rowValsStock.getObject("QTE_LIV_ATTENTE")); |
} |
styleStock.put(listValuesStock.size(), "Normal"); |
listValuesStock.add(mValuesStock); |
} |
} |
// System.out.println("EtatVentesXmlSheet.createListeValues():" + listValues); |
} |
} |
440,7 → 486,7 |
} |
Number articleID = (Number) sqlRow[7]; |
ArticleVendu a = new ArticleVendu(code, nom, -qteVendu.intValue(), ((BigDecimal) ht).negate(), ((BigDecimal) ha).negate(), ttc.negate(), tvaID.intValue(), |
tableFactureElement.getForeignTable("ID_ARTICLE").getRow(articleID.intValue())); |
foreignTableArticle.getRow(articleID.intValue())); |
map.put(articleID + "##" + code + "##" + nom + "##" + tvaID, a); |
} |
713,6 → 759,10 |
this.listAllSheetValues.put(3, listValuesTVA); |
valuesTVA.put("DATE", periode); |
this.mapAllSheetValues.put(3, valuesTVA); |
this.listAllSheetValues.put(4, listValuesStock); |
this.styleAllSheetValues.put(4, styleStock); |
this.mapAllSheetValues.put(4, values); |
} |
public static SQLRow rowDefaultCptService, rowDefaultCptProduit; |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationEcritures/Piece.java |
---|
New file |
0,0 → 1,58 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.generationEcritures; |
import org.openconcerto.sql.model.DBRoot; |
import org.openconcerto.sql.model.SQLInsert; |
import java.util.ArrayList; |
import java.util.List; |
public class Piece { |
private String nom; |
private List<Mouvement> mouvements = new ArrayList<>(); |
private Number id; |
public Piece(String nom) { |
this.nom = nom; |
} |
public String getNom() { |
return nom; |
} |
public void add(Mouvement mouvement) { |
this.mouvements.add(mouvement); |
mouvement.setPiece(this); |
} |
public List<Mouvement> getMouvements() { |
return mouvements; |
} |
public SQLInsert createInsert(final DBRoot root) { |
final SQLInsert insert = new SQLInsert(); |
insert.add(root.getTable("PIECE").getField("NOM"), this.nom); |
return insert; |
} |
public Number getId() { |
return this.id; |
} |
public void setId(Number id) { |
this.id = id; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationEcritures/Compte.java |
---|
New file |
0,0 → 1,69 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.generationEcritures; |
import org.openconcerto.sql.model.DBRoot; |
import org.openconcerto.sql.model.SQLInsert; |
import org.openconcerto.sql.model.SQLTable; |
public class Compte { |
private final Long id; |
private String numero; |
private String nom; |
public Compte(Long id, String numero, String nom) { |
this.id = id; |
this.numero = numero; |
this.nom = nom; |
} |
public Long getId() { |
return this.id; |
} |
public String getNumero() { |
return this.numero; |
} |
public String getNom() { |
return this.nom; |
} |
@Override |
public int hashCode() { |
return this.numero.hashCode(); |
} |
@Override |
public boolean equals(Object obj) { |
if (obj == null) |
return false; |
if (this.getClass() != obj.getClass()) |
return false; |
return ((Compte) obj).numero.equalsIgnoreCase(this.numero); |
} |
SQLInsert createInsert(DBRoot root) { |
final SQLInsert insert = new SQLInsert(); |
final SQLTable table = root.getTable("COMPTE_PCE"); |
insert.add(table.getField("NUMERO"), this.numero); |
insert.add(table.getField("NOM"), this.nom); |
return insert; |
} |
@Override |
public String toString() { |
return "Compte numero:" + this.numero + " " + this.nom + " (id:" + this.id + ")"; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationEcritures/Exercice.java |
---|
New file |
0,0 → 1,517 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.generationEcritures; |
import org.openconcerto.sql.element.SQLElementDirectory; |
import org.openconcerto.sql.model.ConnectionHandlerNoSetup; |
import org.openconcerto.sql.model.DBRoot; |
import org.openconcerto.sql.model.DBSystemRoot; |
import org.openconcerto.sql.model.SQLDataSource; |
import org.openconcerto.sql.model.SQLField; |
import org.openconcerto.sql.model.SQLInsert; |
import org.openconcerto.sql.model.SQLSelect; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.model.SQLUpdate; |
import org.openconcerto.sql.model.Where; |
import org.openconcerto.sql.users.User; |
import org.openconcerto.sql.utils.SQLUtils; |
import org.openconcerto.utils.CollectionUtils; |
import org.openconcerto.utils.cc.ITransformer; |
import java.sql.ResultSet; |
import java.sql.SQLException; |
import java.util.ArrayList; |
import java.util.Date; |
import java.util.HashMap; |
import java.util.HashSet; |
import java.util.Iterator; |
import java.util.LinkedList; |
import java.util.List; |
import java.util.Map; |
import java.util.Set; |
import java.util.logging.Level; |
import java.util.logging.Logger; |
import org.apache.commons.dbutils.ResultSetHandler; |
public class Exercice { |
private Date debut; |
private Date fin; |
private static final Logger LOGGER = Logger.getLogger(Exercice.class.getName()); |
public Exercice() { |
} |
public Exercice(Date debut, Date fin) { |
if (debut != null && debut.after(fin)) { |
throw new IllegalArgumentException("date de fin invalide"); |
} |
this.debut = debut; |
this.fin = fin; |
} |
public String toString() { |
return "Exercice " + this.debut + " -> " + this.fin; |
} |
public void insert(SQLElementDirectory directory, final DBRoot root, User user, List<Piece> pieces) throws SQLException { |
final DBSystemRoot sysRoot = root.getDBSystemRoot(); |
final List<SQLInsert> insertsPiece = new ArrayList<>(); |
LOGGER.log(Level.INFO, "insertion de {0} pièces comptables", pieces.size()); |
for (Piece p : pieces) { |
// Pièces |
insertsPiece.add(p.createInsert(root)); |
// Vérification des mouvements |
final List<Mouvement> mouvements = p.getMouvements(); |
if (mouvements.isEmpty()) { |
throw new IllegalStateException("Piece vide : " + p); |
} |
for (Mouvement m : mouvements) { |
if (!m.isBalanced()) { |
throw new IllegalStateException("Mouvement non balancé : " + m); |
} |
if (m.isEmpty()) { |
throw new IllegalStateException("Mouvement vide : " + m); |
} |
for (Ecriture e : m.getEcritures()) { |
if (this.debut != null && e.getDate().before(this.debut)) { |
throw new IllegalStateException("Mouvement invalide : " + m + " : une écriture est définie avant la date de début d'exercice : " + e); |
} |
if (e.getNom() == null) { |
throw new IllegalStateException("Ecriture sans nom : " + e); |
} |
} |
if (this.fin != null) { |
for (Ecriture e : m.getEcritures()) { |
if (e.getDate().after(this.fin)) { |
throw new IllegalStateException("Mouvement invalide : " + m + " : une écriture est définie après la date de fin d'exercice : " + e.getDate() + ">" + this.fin); |
} |
} |
} |
} |
} |
SQLUtils.executeAtomic(sysRoot.getDataSource(), new ConnectionHandlerNoSetup<Object, SQLException>() { |
@Override |
public Object handle(SQLDataSource ds) throws SQLException { |
// Insertion des journaux et comptes manquants et remplissage des champs journaux et |
// comptes des |
// écritures depuis les ids |
final Set<Journal> journauxACreerOuFetcher = new HashSet<>(); |
final Set<Number> journauxAresoudre = new HashSet<>(); |
final Set<Compte> comptesACreerOuFetcher = new HashSet<>(); |
final Set<Number> comptesAresoudre = new HashSet<>(); |
final List<Ecriture> ecrituresSansJournalID = new LinkedList<>(); |
final List<Ecriture> ecrituresSansCompteID = new LinkedList<>(); |
for (Piece p : pieces) { |
for (Mouvement m : p.getMouvements()) { |
for (Ecriture e : m.getEcritures()) { |
if (e.getJournalID() == null) { |
// Journal à creer |
journauxACreerOuFetcher.add(new Journal(null, e.getJournalCode(), e.getJournalNom())); |
ecrituresSansJournalID.add(e); |
} else { |
journauxAresoudre.add(e.getJournalID()); |
} |
if (e.getCompteID() == null) { |
// Compte à creer |
comptesACreerOuFetcher.add(new Compte(null, e.getCompteNumero(), e.getCompteNom())); |
ecrituresSansCompteID.add(e); |
} else { |
comptesAresoudre.add(e.getJournalID()); |
} |
} |
} |
} |
final Map<Long, Journal> mapJournaux = new HashMap<>(); |
if (!journauxACreerOuFetcher.isEmpty()) { |
if (LOGGER.isLoggable(Level.FINE)) { |
LOGGER.fine(journauxACreerOuFetcher.size() + " journaux à créer : " + journauxACreerOuFetcher); |
} |
// On récupère tous les journaux car il y en a peu |
final Map<String, Journal> codesDesJournauxExistants = getCodesJournaux(root); |
final List<SQLInsert> insertsJournaux = new ArrayList<>(); |
final List<Journal> list = new ArrayList<>(); |
for (Journal journal : journauxACreerOuFetcher) { |
// journal non déjà existant |
if (codesDesJournauxExistants.get(journal.getCode().toLowerCase()) == null) { |
list.add(journal); |
insertsJournaux.add(journal.createInsert(root)); |
} |
} |
final List<Number> journauxIds = new ArrayList<>(); |
if (!insertsJournaux.isEmpty()) { |
journauxIds.addAll(SQLInsert.executeSimilarInserts(sysRoot, insertsJournaux, true)); |
journauxAresoudre.addAll(journauxIds); |
} |
// Mise à jour de l'ID du journal pour les écritures dont le journal vient |
// d'être créé |
final int size = list.size(); |
for (int i = 0; i < size; i++) { |
final String journalCode = list.get(i).getCode(); |
final Number journalID = journauxIds.get(i); |
final Iterator<Ecriture> it = ecrituresSansJournalID.iterator(); |
while (it.hasNext()) { |
final Ecriture e = it.next(); |
if (e.getJournalCode().equalsIgnoreCase(journalCode)) { |
e.setJournalID(journalID); |
it.remove(); |
} |
} |
} |
final Iterator<Ecriture> it = ecrituresSansJournalID.iterator(); |
while (it.hasNext()) { |
final Ecriture e = it.next(); |
final Journal journal = codesDesJournauxExistants.get(e.getJournalCode().toLowerCase()); |
e.setJournalID(journal.getId()); |
it.remove(); |
} |
for (Journal journal : codesDesJournauxExistants.values()) { |
mapJournaux.put(journal.getId(), journal); |
} |
} |
final Map<Long, Compte> mapComptes = new HashMap<>(); |
if (!comptesACreerOuFetcher.isEmpty()) { |
if (LOGGER.isLoggable(Level.FINE)) { |
LOGGER.fine(comptesACreerOuFetcher.size() + " comptes à créer ou fetcher: " + comptesACreerOuFetcher); |
} |
final Map<String, Compte> numerosDesComptesExistants = getNumeroDesComptes(root, pieces); |
final List<SQLInsert> insertsComptes = new ArrayList<>(); |
final List<Compte> list = new ArrayList<>(); |
for (Compte c : comptesACreerOuFetcher) { |
if (numerosDesComptesExistants.get(c.getNumero().toLowerCase()) == null) { |
if (LOGGER.isLoggable(Level.FINE)) { |
LOGGER.fine("création du compte : " + c.getNumero().toLowerCase()); |
} |
list.add(c); |
insertsComptes.add(c.createInsert(root)); |
} |
} |
List<Number> comptesIds = new ArrayList<>(); |
if (!insertsComptes.isEmpty()) { |
final List<Number> insertedIDs = SQLInsert.executeSimilarInserts(sysRoot, insertsComptes, true); |
comptesIds.addAll(insertedIDs); |
if (LOGGER.isLoggable(Level.FINE)) { |
LOGGER.fine("IDs des comptes créés : " + comptesIds); |
} |
comptesAresoudre.addAll(comptesIds); |
} |
// Mise à jour de l'ID du compte pour les écritures dont le compte vient |
// d'être créé |
final int size = list.size(); |
for (int i = 0; i < size; i++) { |
final String compteCode = list.get(i).getNumero(); |
final Number compteID = comptesIds.get(i); |
final Iterator<Ecriture> it = ecrituresSansCompteID.iterator(); |
while (it.hasNext()) { |
final Ecriture e = it.next(); |
if (e.getCompteNumero().equalsIgnoreCase(compteCode)) { |
if (LOGGER.isLoggable(Level.FINEST)) { |
LOGGER.finest("mise à jour de l'écriture " + e + " avec le compte d'ID " + compteID); |
} |
e.setCompteID(compteID); |
it.remove(); |
} |
} |
} |
final Iterator<Ecriture> it = ecrituresSansCompteID.iterator(); |
while (it.hasNext()) { |
final Ecriture e = it.next(); |
Compte compte = numerosDesComptesExistants.get(e.getCompteNumero().toLowerCase()); |
if (compte != null) { |
e.setCompteID(compte.getId()); |
it.remove(); |
} |
} |
for (Compte compte : numerosDesComptesExistants.values()) { |
mapComptes.put(compte.getId(), compte); |
} |
} |
// fetch journaux et comptes, update des code/numéro et nom |
final List<String> queries = new ArrayList<>(); |
final List<ResultSetHandler> handlers = new ArrayList<>(); |
if (!comptesAresoudre.isEmpty()) { |
if (LOGGER.isLoggable(Level.FINE)) { |
LOGGER.fine(comptesAresoudre.size() + " comptes à résoudre : ids " + comptesAresoudre); |
} |
final SQLTable tableCompte = root.getTable("COMPTE_PCE"); |
final SQLSelect selCompte = new SQLSelect(); |
selCompte.addSelect(tableCompte.getKey()); |
selCompte.addSelect(tableCompte.getField("NUMERO")); |
selCompte.addSelect(tableCompte.getField("NOM")); |
selCompte.setWhere(new Where(tableCompte.getKey(), comptesAresoudre)); |
queries.add(selCompte.asString()); |
handlers.add(new ResultSetHandler() { |
@Override |
public Object handle(ResultSet rs) throws SQLException { |
while (rs.next()) { |
final Long id = rs.getLong(1); |
final String numero = rs.getString(2); |
final String nom = rs.getString(3); |
mapComptes.put(id, new Compte(id, numero, nom)); |
} |
return null; |
} |
}); |
} |
if (!journauxAresoudre.isEmpty()) { |
if (LOGGER.isLoggable(Level.FINE)) { |
LOGGER.fine(journauxAresoudre.size() + " journaux à résoudre ids : " + journauxAresoudre); |
} |
final SQLTable tableJournal = root.getTable("JOURNAL"); |
final SQLSelect selJournal = new SQLSelect(); |
selJournal.addSelect(tableJournal.getKey()); |
selJournal.addSelect(tableJournal.getField("CODE")); |
selJournal.addSelect(tableJournal.getField("NOM")); |
selJournal.setWhere(new Where(tableJournal.getKey(), journauxAresoudre)); |
queries.add(selJournal.asString()); |
handlers.add(new ResultSetHandler() { |
@Override |
public Object handle(ResultSet rs) throws SQLException { |
while (rs.next()) { |
final Long id = rs.getLong(1); |
final String code = rs.getString(2); |
final String nom = rs.getString(3); |
mapJournaux.put(id, new Journal(id, code, nom)); |
} |
return null; |
} |
}); |
} |
SQLUtils.executeMultiple(sysRoot, queries, handlers); |
for (Piece p : pieces) { |
for (Mouvement m : p.getMouvements()) { |
for (Ecriture e : m.getEcritures()) { |
Number compteID = e.getCompteID(); |
if (compteID == null) { |
throw new IllegalStateException("pas d'ID compte dans l'écriture " + e); |
} |
final Long idCompte = compteID.longValue(); |
final Compte c = mapComptes.get(idCompte); |
if (c == null) { |
throw new IllegalStateException("pas de compte d'ID " + idCompte + " dans la map " + mapComptes.keySet()); |
} |
e.setCompte(c.getNumero(), c.getNom()); |
final Long idJournal = e.getJournalID().longValue(); |
final Journal j = mapJournaux.get(idJournal); |
if (j == null) { |
throw new IllegalStateException("pas de journal d'ID " + idJournal + " dans la map " + mapJournaux.keySet()); |
} |
e.setJournal(j.getCode(), j.getNom()); |
} |
} |
} |
// Insertion des pieces |
final List<Number> idsPieces = SQLInsert.executeSimilarInserts(sysRoot, insertsPiece, true); |
// Creation des inserts des mouvements |
final List<SQLInsert> insertsMouvement = new ArrayList<>(insertsPiece.size() * 3); |
final List<Mouvement> listMvtWithoutIDs = new ArrayList<>(insertsPiece.size() * 3); |
for (int i = 0; i < pieces.size(); i++) { |
Piece piece = pieces.get(i); |
piece.setId(idsPieces.get(i)); |
for (Mouvement m : piece.getMouvements()) { |
listMvtWithoutIDs.add(m); |
insertsMouvement.add(m.createInsert(root)); |
} |
} |
// Insertion des mouvements |
final List<Number> idsMouvements = SQLInsert.executeSimilarInserts(sysRoot, insertsMouvement, true); |
// Mise à jour des numeros de mouvements |
SQLSelect sel = new SQLSelect(); |
final SQLTable tableMvt = root.getTable("MOUVEMENT"); |
sel.addSelect(tableMvt.getField("NUMERO"), "MAX"); |
Number maxMvtNumber = (Number) sysRoot.getDataSource().executeScalar(sel.asString()); |
int maxMvt = 1; |
if (maxMvtNumber != null) { |
maxMvt = maxMvtNumber.intValue(); |
} |
List<SQLUpdate> mvtUpdate = new ArrayList<>(); |
for (int i = 0; i < idsMouvements.size(); i++) { |
Number mvtId = idsMouvements.get(i); |
SQLUpdate update = new SQLUpdate(new Where(tableMvt.getKey(), "=", mvtId)); |
update.add(tableMvt.getField("NUMERO"), maxMvt); |
mvtUpdate.add(update); |
maxMvt++; |
listMvtWithoutIDs.get(i).setId(mvtId); |
} |
SQLUpdate.executeMultipleWithBatch(sysRoot, mvtUpdate); |
// Creation des inserts des écritures sans analytique |
final List<SQLInsert> insertsEcrituresSansAnalytique = new ArrayList<>(insertsMouvement.size() * 2); |
final List<SQLInsert> insertsEcrituresAvecAnalytique = new ArrayList<>(insertsMouvement.size() * 2); |
final List<Ecriture> ecrituresAvecAnalytique = new ArrayList<>(insertsEcrituresAvecAnalytique.size()); |
for (Piece p : pieces) { |
final List<Mouvement> mouvements = p.getMouvements(); |
final int stop = mouvements.size(); |
for (int i = 0; i < stop; i++) { |
final Mouvement m = mouvements.get(i); |
for (Ecriture e : m.getEcritures()) { |
if (e.hasAnalytique()) { |
insertsEcrituresAvecAnalytique.add(e.createInsert(root, user)); |
ecrituresAvecAnalytique.add(e); |
} else { |
insertsEcrituresSansAnalytique.add(e.createInsert(root, user)); |
} |
} |
} |
} |
// Insertions des écritures des mouvements |
SQLInsert.executeSimilarInserts(sysRoot, insertsEcrituresSansAnalytique, false); |
// Insertions des écritures avec analytique |
if (!ecrituresAvecAnalytique.isEmpty()) { |
final List<Number> idsEcritues = SQLInsert.executeSimilarInserts(sysRoot, insertsEcrituresAvecAnalytique, true); |
// Analytique |
final List<SQLInsert> insertsAssociationAnalytique = new ArrayList<>(insertsEcrituresAvecAnalytique.size()); |
final int size = ecrituresAvecAnalytique.size(); |
for (int i = 0; i < size; i++) { |
final Ecriture e = ecrituresAvecAnalytique.get(i); |
e.setId(idsEcritues.get(i)); |
for (AssociationAnalytique a : e.getAssociationsAnalytiques()) { |
insertsAssociationAnalytique.add(a.createInsert(root, user)); |
} |
} |
SQLInsert.executeSimilarInserts(sysRoot, insertsAssociationAnalytique, false); |
} |
for (Piece p : pieces) { |
final List<Mouvement> mouvements = p.getMouvements(); |
for (Mouvement m : mouvements) { |
if (m.getPostInsertionAction() != null) { |
m.getPostInsertionAction().afterInsert(m); |
} |
} |
} |
return null; |
} |
}); |
} |
/** |
* Map des numero de compte en minuscule <-> Compte |
* |
* @param pieces pièces servant à déterminer sur quels numéros de compte on limite la requête |
*/ |
protected Map<String, Compte> getNumeroDesComptes(DBRoot root, List<Piece> pieces) { |
// tous les comptes dont le numero |
// est parmis celles des écritures des pièces |
final Set<String> numerosDesComptes = new HashSet<>(); |
for (Piece p : pieces) { |
final List<Mouvement> mouvements = p.getMouvements(); |
for (Mouvement m : mouvements) { |
for (Ecriture e : m.getEcritures()) { |
numerosDesComptes.add(e.getCompteNumero().toLowerCase()); |
} |
} |
} |
final Map<String, Compte> result = new HashMap<>(); |
final SQLTable tableCompte = root.getTable("COMPTE_PCE"); |
final SQLSelect selCompte = new SQLSelect(); |
selCompte.addSelect(tableCompte.getKey()); |
final SQLField fNumero = tableCompte.getField("NUMERO"); |
selCompte.addSelect(fNumero); |
selCompte.addSelect(tableCompte.getField("NOM")); |
String numeros = CollectionUtils.join(numerosDesComptes, ",", new ITransformer<Object, String>() { |
@Override |
public String transformChecked(final Object input) { |
return fNumero.getField().getType().toString(input); |
} |
}); |
final Where w = Where.createRaw("lower(" + fNumero.getFieldRef() + ") in (" + numeros + ")", fNumero); |
selCompte.setWhere(w); |
final ResultSetHandler resultSetHandler = new ResultSetHandler() { |
@Override |
public Object handle(ResultSet rs) throws SQLException { |
while (rs.next()) { |
final Long id = rs.getLong(1); |
final String numero = rs.getString(2); |
final String nom = rs.getString(3); |
result.put(numero.toLowerCase(), new Compte(id, numero, nom)); |
} |
return null; |
} |
}; |
root.getDBSystemRoot().getDataSource().execute(selCompte.asString(), resultSetHandler); |
return result; |
} |
/** |
* Map des codes en minuscule <-> Journal |
*/ |
protected Map<String, Journal> getCodesJournaux(DBRoot root) { |
final Map<String, Journal> result = new HashMap<>(); |
final SQLTable tableJournal = root.getTable("JOURNAL"); |
final SQLSelect selJournal = new SQLSelect(); |
selJournal.addSelect(tableJournal.getKey()); |
selJournal.addSelect(tableJournal.getField("CODE")); |
selJournal.addSelect(tableJournal.getField("NOM")); |
final ResultSetHandler resultSetHandler = new ResultSetHandler() { |
@Override |
public Object handle(ResultSet rs) throws SQLException { |
while (rs.next()) { |
final Long id = rs.getLong(1); |
final String code = rs.getString(2); |
final String nom = rs.getString(3); |
result.put(code.toLowerCase(), new Journal(id, code, nom)); |
} |
return null; |
} |
}; |
root.getDBSystemRoot().getDataSource().execute(selJournal.asString(), resultSetHandler); |
return result; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationEcritures/AssociationAnalytique.java |
---|
New file |
0,0 → 1,67 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.generationEcritures; |
import org.openconcerto.sql.model.DBRoot; |
import org.openconcerto.sql.model.SQLInsert; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.users.User; |
import java.math.BigDecimal; |
public class AssociationAnalytique { |
private final int idPosteAnalytique; |
private int idSaisieKmElement = 1; |
private BigDecimal pourcentage; |
private long montant; // centimes |
private boolean gestionAuto = false; |
private Ecriture ecriture; |
public AssociationAnalytique(int idPosteAnalytique) { |
this.idPosteAnalytique = idPosteAnalytique; |
} |
public void setIdSaisieKmElement(int idSaisieKmElement) { |
this.idSaisieKmElement = idSaisieKmElement; |
} |
public void setPourcentage(BigDecimal pourcentage) { |
this.pourcentage = pourcentage; |
} |
public void setMontant(long montant) { |
this.montant = montant; |
} |
public void setGestionAuto(boolean gestionAuto) { |
this.gestionAuto = gestionAuto; |
} |
public void setEcriture(Ecriture ecriture) { |
this.ecriture = ecriture; |
} |
public SQLInsert createInsert(DBRoot root, User user) { |
final SQLInsert insert = new SQLInsert(); |
final SQLTable table = root.getTable("ASSOCIATION_ANALYTIQUE"); |
insert.add(table.getField("ID_ECRITURE"), this.ecriture.getId().intValue()); |
insert.add(table.getField("ID_SAISIE_KM_ELEMENT"), this.idSaisieKmElement); |
insert.add(table.getField("ID_POSTE_ANALYTIQUE"), this.idPosteAnalytique); |
insert.add(table.getField("POURCENT"), this.pourcentage); |
insert.add(table.getField("MONTANT"), this.montant); |
insert.add(table.getField("GESTION_AUTO"), this.gestionAuto); |
return insert; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationEcritures/Journal.java |
---|
New file |
0,0 → 1,69 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.generationEcritures; |
import org.openconcerto.sql.model.DBRoot; |
import org.openconcerto.sql.model.SQLInsert; |
import org.openconcerto.sql.model.SQLTable; |
public class Journal { |
private final Long id; |
private final String code; |
private final String nom; |
public Journal(Long id, final String code, final String nom) { |
this.id = id; |
this.code = code; |
this.nom = nom; |
} |
public Long getId() { |
return this.id; |
} |
public String getNom() { |
return this.nom; |
} |
public String getCode() { |
return this.code; |
} |
@Override |
public int hashCode() { |
return this.code.hashCode(); |
} |
@Override |
public boolean equals(Object obj) { |
if (obj == null) |
return false; |
if (this.getClass() != obj.getClass()) |
return false; |
return ((Journal) obj).code.equalsIgnoreCase(this.code); |
} |
SQLInsert createInsert(DBRoot root) { |
final SQLInsert insert = new SQLInsert(); |
final SQLTable table = root.getTable("JOURNAL"); |
insert.add(table.getField("CODE"), this.code); |
insert.add(table.getField("NOM"), this.nom); |
return insert; |
} |
@Override |
public String toString() { |
return "Journal code:" + this.code + " " + this.nom + " (id:" + this.id + ")"; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationEcritures/MouvementPostInsertionAction.java |
---|
New file |
0,0 → 1,22 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.generationEcritures; |
import java.sql.SQLException; |
public interface MouvementPostInsertionAction { |
public void afterInsert(Mouvement m) throws SQLException; |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationEcritures/Mouvement.java |
---|
New file |
0,0 → 1,114 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.generationEcritures; |
import org.openconcerto.sql.model.DBRoot; |
import org.openconcerto.sql.model.SQLInsert; |
import org.openconcerto.sql.model.SQLTable; |
import java.math.BigDecimal; |
import java.util.ArrayList; |
import java.util.List; |
public class Mouvement { |
private String numero; |
private List<Ecriture> ecritures = new ArrayList<>(); |
private Number id; |
private BigDecimal debit = BigDecimal.ZERO; |
private BigDecimal credit = BigDecimal.ZERO; |
private Piece piece; |
// Source |
private Number idSource; |
private String source; |
private Mouvement pere; |
private MouvementPostInsertionAction postInsertionAction; |
public Mouvement() { |
} |
public void setSource(Number idSource, String source) { |
this.idSource = idSource; |
this.source = source; |
} |
public void add(Ecriture e) { |
this.ecritures.add(e); |
this.debit = this.debit.add(e.getDebit()); |
this.credit = this.credit.add(e.getCredit()); |
e.setMouvement(this); |
} |
List<Ecriture> getEcritures() { |
return this.ecritures; |
} |
void setId(Number id) { |
this.id = id; |
} |
public Number getId() { |
return this.id; |
} |
SQLInsert createInsert(DBRoot root) { |
final SQLInsert insert = new SQLInsert(); |
final SQLTable table = root.getTable("MOUVEMENT"); |
// FIXME le numero doit être généré en auto |
// Thread.dumpStack(); |
// NUMERO = SELECT (MAX) ? |
// insert.add(table.getField("NUMERO"), this.numero); |
// select for update max(numero) |
if (this.idSource != null) { |
insert.add(table.getField("IDSOURCE"), this.idSource); |
insert.add(table.getField("SOURCE"), this.source); |
} |
insert.add(table.getField("ID_PIECE"), this.piece.getId().intValue()); |
if (this.pere != null) { |
insert.add(table.getField("ID_MOUVEMENT_PERE"), this.pere.getId().intValue()); |
} |
// TODO CREATION_DATE MODIFICATION_DATE |
return insert; |
} |
public boolean isBalanced() { |
BigDecimal d = BigDecimal.ZERO; |
BigDecimal c = BigDecimal.ZERO; |
for (Ecriture e : this.ecritures) { |
d = d.add(e.getDebit()); |
c = c.add(e.getCredit()); |
} |
return d.compareTo(c) == 0; |
} |
public Piece getPiece() { |
return this.piece; |
} |
public void setPiece(Piece piece) { |
this.piece = piece; |
} |
public boolean isEmpty() { |
return this.ecritures.isEmpty(); |
} |
public MouvementPostInsertionAction getPostInsertionAction() { |
return this.postInsertionAction; |
} |
public void setAfterInsert(MouvementPostInsertionAction insertionAction) { |
this.postInsertionAction = insertionAction; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationEcritures/GenerationEcritures.java |
---|
396,6 → 396,10 |
if (tiers.getObject("ID_CATEGORIE_COMPTABLE") != null && !tiers.isForeignEmpty("ID_CATEGORIE_COMPTABLE")) { |
rowCatCompta = tiers.getForeign("ID_CATEGORIE_COMPTABLE"); |
} |
if (row.getTable().contains("ID_CATEGORIE_COMPTABLE") && row.getObject("ID_CATEGORIE_COMPTABLE") != null && !row.isForeignEmpty("ID_CATEGORIE_COMPTABLE")) { |
rowCatCompta = row.getForeign("ID_CATEGORIE_COMPTABLE"); |
} |
TotalCalculator calc = new TotalCalculator("T_PA_HT", fieldTotalHT, null, achat, defaultCompte, rowCatCompta); |
calc.setIntraComm(intra); |
436,6 → 440,7 |
calc.addEchantillon((BigDecimal) sqlRow.getObject("T_PV_HT"), sqlRow.getForeign("ID_TAXE")); |
} |
} |
calc.checkResult(); |
totalAvtRemise = calc.getTotalHT(); |
} |
514,6 → 519,12 |
calc.addLine(rowValsFraisDoc, null, 1, false); |
} |
// Fix TVA si nécessaire pour facture fournisseur |
if (row.getTable().contains("TVA_ADJUSTMENT")) { |
BigDecimal tvaFix = row.getBigDecimal("TVA_ADJUSTMENT"); |
calc.addTVAAdjust(tvaFix); |
} |
calc.checkResult(); |
return calc; |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationEcritures/Ecriture.java |
---|
New file |
0,0 → 1,237 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.generationEcritures; |
import org.openconcerto.sql.model.DBRoot; |
import org.openconcerto.sql.model.SQLInsert; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.users.User; |
import java.math.BigDecimal; |
import java.util.ArrayList; |
import java.util.Date; |
import java.util.HashMap; |
import java.util.List; |
import java.util.Map; |
public class Ecriture { |
private Date date; |
private BigDecimal debit; |
private BigDecimal credit; |
private Mouvement mouvement; |
private String nom; |
private String compteNumero; |
private String compteNom; |
private Number compteID; |
private String journalNom; |
private String journalCode; |
private Number journalID; |
private List<AssociationAnalytique> associations; |
private Number id; |
private Map<String, Object> cookies; |
private boolean cloture; |
private boolean aNouveau; |
private Date dateValidation; |
private Date dateLettrage; |
private String lettrage; |
public Ecriture(Date date, BigDecimal debit, BigDecimal credit) { |
this.date = date; |
this.debit = debit; |
this.credit = credit; |
} |
public SQLInsert createInsert(DBRoot root, User user) { |
final SQLInsert insert = new SQLInsert(); |
final SQLTable table = root.getTable("ECRITURE"); |
insert.add(table.getField("DATE"), this.date); |
insert.add(table.getField("ID_MOUVEMENT"), this.mouvement.getId().intValue()); |
insert.add(table.getField("DEBIT"), this.debit.multiply(new BigDecimal(100)).longValue()); |
insert.add(table.getField("CREDIT"), this.credit.multiply(new BigDecimal(100)).longValue()); |
insert.add(table.getField("NOM"), this.nom); |
if (this.compteNom == null) { |
throw new IllegalStateException("nom du compte manquant"); |
} |
if (this.compteNumero == null || this.compteNumero.isEmpty()) { |
throw new IllegalStateException("numéro du compte manquant"); |
} |
insert.add(table.getField("ID_COMPTE_PCE"), this.compteID); |
insert.add(table.getField("COMPTE_NUMERO"), this.compteNumero); |
insert.add(table.getField("COMPTE_NOM"), this.compteNom); |
if (this.journalNom == null) { |
throw new IllegalStateException("nom du journal manquant"); |
} |
if (this.journalCode == null || this.journalCode.isEmpty()) { |
throw new IllegalStateException("code du journal manquant"); |
} |
insert.add(table.getField("ID_JOURNAL"), this.journalID); |
insert.add(table.getField("JOURNAL_NOM"), this.journalNom); |
insert.add(table.getField("JOURNAL_CODE"), this.journalCode); |
insert.add(table.getField("NOM_PIECE"), this.mouvement.getPiece().getNom()); |
insert.add(table.getField("ID_USER_COMMON_CREATE"), user.getId()); |
insert.add(table.getField("ID_USER_COMMON_MODIFY"), user.getId()); |
insert.add(table.getField("CLOTURE"), this.cloture); |
insert.add(table.getField("RAN"), this.aNouveau); |
if (this.dateValidation != null) { |
insert.add(table.getField("DATE_VALIDE"), this.dateValidation); |
insert.add(table.getField("VALIDE"), Boolean.TRUE); |
} else { |
insert.add(table.getField("DATE_VALIDE"), null); |
insert.add(table.getField("VALIDE"), Boolean.FALSE); |
} |
insert.add(table.getField("DATE_LETTRAGE"), this.dateLettrage); |
insert.add(table.getField("LETTRAGE"), this.lettrage == null || this.lettrage.isEmpty() ? " " : this.lettrage); |
return insert; |
} |
public void setDateValidation(Date dateValidation) { |
this.dateValidation = dateValidation; |
} |
public void setDateLettrage(Date dateLettrage) { |
this.dateLettrage = dateLettrage; |
} |
public void setLettrage(String lettrage) { |
this.lettrage = lettrage; |
} |
public void setCloture(boolean cloture) { |
this.cloture = cloture; |
} |
public void setaNouveau(boolean aNouveau) { |
this.aNouveau = aNouveau; |
} |
public String getNom() { |
return this.nom; |
} |
public void setNom(String nom) { |
this.nom = nom; |
} |
void setId(Number id) { |
this.id = id; |
} |
public Number getId() { |
return this.id; |
} |
public Number getCompteID() { |
return this.compteID; |
} |
public void setCompteID(Number compteID) { |
this.compteID = compteID; |
} |
public void setCompte(String numero, String nom) { |
this.compteNumero = numero; |
this.compteNom = nom; |
} |
public String getCompteNumero() { |
return this.compteNumero; |
} |
public String getCompteNom() { |
return this.compteNom; |
} |
public Number getJournalID() { |
return this.journalID; |
} |
public void setJournalID(Number journalID) { |
this.journalID = journalID; |
} |
public void setJournal(String code, String nom) { |
this.journalCode = code; |
this.journalNom = nom; |
} |
public String getJournalCode() { |
return this.journalCode; |
} |
public String getJournalNom() { |
return this.journalNom; |
} |
public BigDecimal getDebit() { |
return this.debit; |
} |
public BigDecimal getCredit() { |
return this.credit; |
} |
public Date getDate() { |
return this.date; |
} |
public void setMouvement(Mouvement mouvement) { |
this.mouvement = mouvement; |
} |
public List<AssociationAnalytique> getAssociationsAnalytiques() { |
return this.associations; |
} |
public void addAssociationAnalytique(AssociationAnalytique a) { |
if (this.associations == null) { |
this.associations = new ArrayList<>(); |
} |
a.setEcriture(this); |
this.associations.add(a); |
} |
public void removeAssociationAnalytique(AssociationAnalytique a) { |
if (this.associations == null) { |
a.setEcriture(null); |
return; |
} |
this.associations.remove(a); |
a.setEcriture(null); |
if (this.associations.isEmpty()) { |
this.associations = null; |
} |
} |
public boolean hasAnalytique() { |
return this.associations != null; |
} |
public void putCookie(String key, Object value) { |
if (this.cookies == null) { |
this.cookies = new HashMap<>(); |
} |
this.cookies.put(key, value); |
} |
public Object getCookie(String key) { |
return this.cookies.get(key); |
} |
@Override |
public String toString() { |
return "Ecriture : " + this.nom + ", Compte (id:" + this.compteID + ") " + this.compteNumero + " " + this.compteNom + ", Débit : " + this.debit + ", Crédit:" + this.credit; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationEcritures/GenerationReglementVenteNG.java |
---|
392,7 → 392,12 |
} |
} |
this.putValue("ID_JOURNAL", JournalSQLElement.BANQUES); |
int idJournal = JournalSQLElement.BANQUES; |
if (rowPrefsCompte.getObject("ID_JOURNAL_VALEUR_ENCAISSEMENT") != null && !rowPrefsCompte.isForeignEmpty("ID_JOURNAL_VALEUR_ENCAISSEMENT")) { |
idJournal = rowPrefsCompte.getForeignID("ID_JOURNAL_VALEUR_ENCAISSEMENT"); |
} |
this.putValue("ID_JOURNAL", idJournal); |
this.putValue("ID_COMPTE_PCE", idCompteClient); |
this.putValue("DEBIT", Long.valueOf(0)); |
this.putValue("CREDIT", Long.valueOf(ttc.getLongValue())); |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationEcritures/GenerationMvtFactureFournisseur.java |
---|
166,6 → 166,10 |
} |
} |
this.putValue("ID_COMPTE_PCE", new Integer(idCompteFourn)); |
if (rowFournisseur.getTable().getTable("ECRITURE").contains("CODE_CLIENT")) { |
this.putValue("CODE_CLIENT", rowFournisseur.getString("CODE")); |
} |
this.putValue("DEBIT", new Long(0)); |
if (rowFournisseur.getBoolean("UE")) { |
this.putValue("CREDIT", new Long(htLongValue)); |
/trunk/OpenConcerto/src/org/openconcerto/erp/generationEcritures/GenerationMvtDepotChequeClient.java |
---|
93,7 → 93,7 |
List<Integer> pieceIDs = new ArrayList<Integer>(); |
SQLRowValues rowValsDepotElt = new SQLRowValues(depot.getTable().getTable("DEPOT_CHEQUE_ELEMENT")); |
rowValsDepotElt.putNulls("MONTANT", "TIERS"); |
rowValsDepotElt.putNulls("MONTANT", "TIERS", "PIECE"); |
rowValsDepotElt.putRowValues("ID_CLIENT").putNulls("NOM", "ID_COMPTE_PCE"); |
final SQLRowValues rowValuesChq = rowValsDepotElt.putRowValues("ID_CHEQUE_A_ENCAISSER"); |
rowValuesChq.putNulls("SANS_VALEUR_ENCAISSEMENT").putRowValues("ID_MOUVEMENT").putNulls("ID_PIECE"); |
102,7 → 102,7 |
for (SQLRowValues sqlRowAccessor : cheques) { |
final SQLRowAccessor clientRow = sqlRowAccessor.getForeign("ID_CLIENT"); |
// this.nom = this.nom + " " + StringUtils.limitLength(clientRow.getString("NOM"), 20); |
this.putValue("NOM", this.nom + " " + StringUtils.limitLength(clientRow.getString("NOM"), 20)); |
this.putValue("NOM", this.nom + " " + sqlRowAccessor.getString("PIECE") + " " + StringUtils.limitLength(clientRow.getString("NOM"), 20)); |
SQLRowAccessor chequeRow = sqlRowAccessor.getForeign("ID_CHEQUE_A_ENCAISSER"); |
pieceIDs.add(chequeRow.getForeign("ID_MOUVEMENT").getForeignID("ID_PIECE")); |
// compte Clients |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/reports/stat/action/ReportingCommercialAction.java |
---|
New file |
0,0 → 1,42 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.reports.stat.action; |
import org.openconcerto.erp.action.CreateFrameAbstractAction; |
import org.openconcerto.erp.core.common.ui.PanelFrame; |
import org.openconcerto.erp.core.customerrelationship.customer.report.ReportingCommercialPanel; |
import org.openconcerto.sql.model.DBRoot; |
import javax.swing.Action; |
import javax.swing.JFrame; |
public class ReportingCommercialAction extends CreateFrameAbstractAction { |
private static final String TITLE = "CA par commercial"; |
private DBRoot root; |
public ReportingCommercialAction(DBRoot root) { |
super(); |
this.root = root; |
this.putValue(Action.NAME, TITLE); |
this.mustLoadState = false; |
} |
public JFrame createFrame() { |
final PanelFrame panelFrame = new PanelFrame(new ReportingCommercialPanel(this.root), TITLE); |
panelFrame.setResizable(false); |
return panelFrame; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/order/action/ListeDesCommandesAction.java |
---|
14,9 → 14,11 |
package org.openconcerto.erp.core.supplychain.order.action; |
import org.openconcerto.erp.action.CreateFrameAbstractAction; |
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.element.SQLElement; |
import org.openconcerto.sql.model.FieldPath; |
import org.openconcerto.sql.model.SQLField; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.graph.Path; |
import org.openconcerto.sql.model.graph.PathBuilder; |
25,13 → 27,17 |
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn; |
import org.openconcerto.sql.view.list.IListe; |
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline; |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import org.openconcerto.ui.table.PercentTableCellRenderer; |
import org.openconcerto.utils.CollectionUtils; |
import org.openconcerto.utils.DecimalUtils; |
import java.awt.GridBagConstraints; |
import java.math.BigDecimal; |
import java.math.RoundingMode; |
import java.util.Collection; |
import java.util.HashMap; |
import java.util.Map; |
import java.util.Set; |
import javax.swing.Action; |
47,28 → 53,135 |
final SQLElement elementCmd = Configuration.getInstance().getDirectory().getElement("COMMANDE"); |
final SQLTableModelSourceOnline tableSource = elementCmd.getTableSource(true); |
BaseSQLTableModelColumn colAvancement = new BaseSQLTableModelColumn("Avancement réception", BigDecimal.class) { |
BaseSQLTableModelColumn colAvancementR = new BaseSQLTableModelColumn("Avancement réception", BigDecimal.class) { |
@Override |
protected Object show_(SQLRowAccessor r) { |
return getAvancement(r); |
return getAvancementLFromBR(r); |
} |
@Override |
public Set<FieldPath> getPaths() { |
final Path p = new PathBuilder(elementCmd.getTable()).addTable("TR_COMMANDE").addTable("BON_RECEPTION").build(); |
return CollectionUtils.createSet(new FieldPath(p, "TOTAL_HT")); |
final Path p = new PathBuilder(elementCmd.getTable()).addTable("COMMANDE_ELEMENT").build(); |
return CollectionUtils.createSet(new FieldPath(p, "RECU_FORCED"), new FieldPath(p, "RECU"), new FieldPath(p, "QTE_RECUE"), new FieldPath(p, "PA_HT"), new FieldPath(p, "ID_ARTICLE"), |
new FieldPath(p, "QTE"), new FieldPath(p, "QTE_UNITAIRE")); |
} |
}; |
tableSource.getColumns().add(colAvancementR); |
colAvancementR.setRenderer(new PercentTableCellRenderer()); |
BaseSQLTableModelColumn colAvancement = new BaseSQLTableModelColumn("Avancement facturation", BigDecimal.class) { |
@Override |
protected Object show_(SQLRowAccessor r) { |
return getAvancementFact(r); |
} |
@Override |
public Set<FieldPath> getPaths() { |
final Path p = new PathBuilder(elementCmd.getTable()).addTable("TR_COMMANDE").addTable("SAISIE_ACHAT").build(); |
final Path p2 = new PathBuilder(elementCmd.getTable()).addTable("TR_COMMANDE").addTable("FACTURE_FOURNISSEUR").build(); |
final Path pBr = new PathBuilder(elementCmd.getTable()).addTable("TR_COMMANDE").addTable("BON_RECEPTION").build(); |
final Path trBr = pBr.add(elementCmd.getTable().getTable("TR_BON_RECEPTION")); |
final Path pFact2 = trBr.addTable("FACTURE_FOURNISSEUR"); |
final Path pAchat2 = trBr.addTable("SAISIE_ACHAT"); |
return CollectionUtils.createSet(new FieldPath(p, "MONTANT_HT"), new FieldPath(p2, "T_HT"), new FieldPath(pAchat2, "MONTANT_HT"), new FieldPath(pFact2, "T_HT")); |
} |
}; |
tableSource.getColumns().add(colAvancement); |
colAvancement.setRenderer(new PercentTableCellRenderer()); |
final IListFrame frame = new IListFrame(new ListeAddPanel(elementCmd, new IListe(tableSource))); |
final ListeAddPanel panel = new ListeAddPanel(elementCmd, new IListe(tableSource)); |
// Date panel |
Map<IListe, SQLField> map = new HashMap<IListe, SQLField>(); |
map.put(panel.getListe(), elementCmd.getTable().getField("DATE")); |
IListFilterDatePanel datePanel = new IListFilterDatePanel(map, IListFilterDatePanel.getDefaultMap()); |
GridBagConstraints c = new DefaultGridBagConstraints(); |
c.weightx = 0; |
c.fill = GridBagConstraints.NONE; |
c.gridy = 4; |
c.anchor = GridBagConstraints.CENTER; |
c.weighty = 0; |
datePanel.setFilterOnDefault(); |
panel.add(datePanel, c); |
final IListFrame frame = new IListFrame(panel); |
return frame; |
} |
private BigDecimal getAvancementLFromBR(SQLRowAccessor r) { |
Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("COMMANDE_ELEMENT")); |
BigDecimal totalQte = BigDecimal.ZERO; |
BigDecimal totalQteL = BigDecimal.ZERO; |
for (SQLRowAccessor row : rows) { |
BigDecimal qte = row.getBigDecimal("QTE_UNITAIRE").multiply(new BigDecimal(row.getInt("QTE"))); |
// On ne prend en compte que les articles ou les lignes différentes de 0 |
if (!row.isForeignEmpty("ID_ARTICLE") || row.getBigDecimal("PA_HT").signum() != 0) { |
totalQte = totalQte.add(qte); |
if (row.getBoolean("RECU_FORCED") || row.getBoolean("RECU")) { |
totalQteL = totalQteL.add(qte); |
} else if (row.getBigDecimal("QTE_RECUE") != null) { |
final BigDecimal qteLivree = row.getBigDecimal("QTE_RECUE"); |
if (qteLivree != null) { |
totalQteL = totalQteL.add(qteLivree); |
} |
} |
} |
} |
if (totalQte.signum() != 0) { |
return totalQteL.divide(totalQte, DecimalUtils.HIGH_PRECISION).movePointRight(2).setScale(2, RoundingMode.HALF_UP); |
} else { |
return BigDecimal.ONE.movePointRight(2); |
} |
} |
BigDecimal bigDecimal100 = new BigDecimal(100.0); |
private BigDecimal getAvancementFact(SQLRowAccessor r) { |
Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("TR_COMMANDE")); |
long totalFact = 0; |
long total = r.getLong("T_HT"); |
for (SQLRowAccessor row : rows) { |
if (!row.isForeignEmpty("ID_FACTURE_FOURNISSEUR")) { |
SQLRowAccessor rowFact = row.getForeign("ID_FACTURE_FOURNISSEUR"); |
Long l = rowFact.getLong("T_HT"); |
totalFact += l; |
} |
if (!row.isForeignEmpty("ID_SAISIE_ACHAT")) { |
SQLRowAccessor rowFact = row.getForeign("ID_SAISIE_ACHAT"); |
Long l = rowFact.getLong("MONTANT_HT"); |
totalFact += l; |
} |
if (!row.isForeignEmpty("ID_BON_RECEPTION")) { |
Collection<? extends SQLRowAccessor> rowsBr = row.getForeign("ID_BON_RECEPTION").getReferentRows(r.getTable().getTable("TR_BON_RECEPTION")); |
for (SQLRowAccessor rowTrBr : rowsBr) { |
if (!rowTrBr.isForeignEmpty("ID_FACTURE_FOURNISSEUR")) { |
SQLRowAccessor rowFact = rowTrBr.getForeign("ID_FACTURE_FOURNISSEUR"); |
Long l = rowFact.getLong("T_HT"); |
totalFact += l; |
} |
if (!rowTrBr.isForeignEmpty("ID_SAISIE_ACHAT")) { |
SQLRowAccessor rowFact = rowTrBr.getForeign("ID_SAISIE_ACHAT"); |
Long l = rowFact.getLong("MONTANT_HT"); |
totalFact += l; |
} |
} |
} |
} |
if (total > 0) { |
return this.bigDecimal100.min(new BigDecimal(totalFact).divide(new BigDecimal(total), DecimalUtils.HIGH_PRECISION).movePointRight(2).setScale(2, RoundingMode.HALF_UP)); |
} else { |
return BigDecimal.ONE.movePointRight(2); |
} |
} |
private BigDecimal getAvancement(SQLRowAccessor r) { |
Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("TR_COMMANDE")); |
long totalFact = 0; |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/order/component/FactureFournisseurSQLComponent.java |
---|
59,6 → 59,9 |
import java.beans.PropertyChangeListener; |
import java.math.BigDecimal; |
import java.sql.SQLException; |
import java.util.HashSet; |
import java.util.List; |
import java.util.Set; |
import javax.swing.JLabel; |
import javax.swing.JPanel; |
65,6 → 68,7 |
import javax.swing.JScrollPane; |
import javax.swing.JTextField; |
import javax.swing.SwingConstants; |
import javax.swing.SwingUtilities; |
import javax.swing.event.DocumentEvent; |
import javax.swing.event.DocumentListener; |
import javax.swing.event.TableModelEvent; |
102,7 → 106,7 |
int idModeRegl = rowFourn.getInt("ID_MODE_REGLEMENT"); |
if (idModeRegl > 1 && FactureFournisseurSQLComponent.this.eltModeRegl != null && getMode() == Mode.INSERTION) { |
SQLElement sqlEltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT"); |
SQLElement sqlEltModeRegl = getElement().getDirectory().getElement("MODE_REGLEMENT"); |
SQLRow rowModeRegl = sqlEltModeRegl.getTable().getRow(idModeRegl); |
SQLRowValues rowVals = rowModeRegl.createUpdateRow(); |
rowVals.clearPrimaryKeys(); |
124,6 → 128,15 |
return this.fourn; |
} |
@Override |
protected Set<String> createRequiredNames() { |
final Set<String> s = new HashSet<>(1); |
if (getTable().contains("ID_TYPE_CMD")) { |
s.add("ID_TYPE_CMD"); |
} |
return s; |
} |
public void addViews() { |
this.setLayout(new GridBagLayout()); |
final GridBagConstraints c = new DefaultGridBagConstraints(); |
480,10 → 493,10 |
ElementComboBox comboTaxePort = new ElementComboBox(); |
DeviseField textRemiseHT = new DeviseField(); |
final JPanel panelPoids = new JPanel(new GridBagLayout()); |
GridBagConstraints cPort = new DefaultGridBagConstraints(); |
if (getTable().contains("PORT_HT")) { |
addSQLObject(textPortHT, "PORT_HT"); |
final JPanel panelPoids = new JPanel(new GridBagLayout()); |
GridBagConstraints cPort = new DefaultGridBagConstraints(); |
cPort.gridx = 0; |
cPort.weightx = 0; |
panelPoids.add(new JLabel(getLabelFor("PORT_HT")), cPort); |
562,6 → 575,49 |
final TotalPanel totalTTC = new TotalPanel(this.table, fieldEco, fieldHT, fieldTVA, fieldTTC, textPortHT, textRemiseHT, fieldService, null, fieldDevise, null, null, |
(getTable().contains("ID_TAXE_PORT") ? comboTaxePort : null), null); |
if (getTable().contains("TVA_ADJUSTMENT")) { |
final JTextField textTvaAdujs = new JTextField(15); |
JLabel labelTvaAdujst = new JLabel(getLabelFor("TVA_ADJUSTMENT")); |
labelTvaAdujst.setHorizontalAlignment(SwingConstants.RIGHT); |
cPort.gridx = 0; |
cPort.gridy++; |
panelPoids.add(labelTvaAdujst, cPort); |
cPort.gridx++; |
panelPoids.add(textTvaAdujs, cPort); |
addView(textTvaAdujs, "TVA_ADJUSTMENT"); |
totalTTC.setTextFixTVA(textTvaAdujs); |
textTvaAdujs.getDocument().addDocumentListener(new SimpleDocumentListener() { |
@Override |
public void update(final DocumentEvent e) { |
final String text = textTvaAdujs.getText(); |
if (text != null && text.trim().length() > 0) { |
if (!text.trim().equals("-")) { |
BigDecimal tvaFix = new BigDecimal(text); |
if (tvaFix.abs().compareTo(new BigDecimal(0.05)) > 0) { |
final String limitedFix; |
if (tvaFix.signum() > 0) { |
limitedFix = tvaFix.min(new BigDecimal(0.05)).toString(); |
} else { |
limitedFix = tvaFix.max(new BigDecimal(-0.05)).toString(); |
} |
SwingUtilities.invokeLater(new Runnable() { |
@Override |
public void run() { |
textTvaAdujs.setText(limitedFix); |
} |
}); |
} |
} |
} |
totalTTC.updateTotal(); |
} |
}); |
DefaultGridBagConstraints.lockMinimumSize(textTvaAdujs); |
} |
c.gridx++; |
c.gridy--; |
c.gridwidth = GridBagConstraints.REMAINDER; |
858,4 → 914,48 |
} |
public void loadFactureExistante(int idFacture) { |
SQLElement fact = getElement(); |
SQLElement factElt = getElement().getDirectory().getElement("FACTURE_FOURNISSEUR_ELEMENT"); |
// On duplique la facture |
if (idFacture > 1) { |
SQLRow row = fact.getTable().getRow(idFacture); |
SQLRowValues rowVals = new SQLRowValues(fact.getTable()); |
rowVals.put("ID_FOURNISSEUR", row.getInt("ID_FOURNISSEUR")); |
// if (getTable().contains("ID_NUMEROTATION_AUTO")) { |
// rowVals.put("NUMERO", |
// NumerotationAutoSQLElement.getNextNumero(SaisieVenteFactureSQLElement.class, new |
// Date(), row.getForeign("ID_NUMEROTATION_AUTO"))); |
// } else { |
// rowVals.put("NUMERO", |
// NumerotationAutoSQLElement.getNextNumero(SaisieVenteFactureSQLElement.class, new |
// Date())); |
// } |
rowVals.put("NOM", row.getObject("NOM")); |
this.select(rowVals); |
} |
// On duplique les elements de facture |
List<SQLRow> myListItem = fact.getTable().getRow(idFacture).getReferentRows(factElt.getTable()); |
if (myListItem.size() != 0) { |
this.table.getModel().clearRows(); |
for (SQLRow rowElt : myListItem) { |
SQLRowValues rowVals = rowElt.createUpdateRow(); |
rowVals.clearPrimaryKeys(); |
this.table.getModel().addRow(rowVals); |
int rowIndex = this.table.getModel().getRowCount() - 1; |
this.table.getModel().fireTableModelModified(rowIndex); |
} |
} else { |
this.table.getModel().clearRows(); |
} |
this.table.getModel().fireTableDataChanged(); |
this.table.repaint(); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/order/component/CommandeSQLComponent.java |
---|
31,6 → 31,7 |
import org.openconcerto.erp.generationDoc.gestcomm.CommandeXmlSheet; |
import org.openconcerto.erp.panel.PanelOOSQLComponent; |
import org.openconcerto.erp.preferences.DefaultNXProps; |
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel; |
import org.openconcerto.erp.utils.TM; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.element.DefaultElementSQLObject; |
47,9 → 48,11 |
import org.openconcerto.sql.sqlobject.ElementComboBox; |
import org.openconcerto.sql.sqlobject.JUniqueTextField; |
import org.openconcerto.sql.sqlobject.SQLRequestComboBox; |
import org.openconcerto.sql.sqlobject.SQLTextCombo; |
import org.openconcerto.sql.users.UserManager; |
import org.openconcerto.sql.view.EditFrame; |
import org.openconcerto.sql.view.list.RowValuesTable; |
import org.openconcerto.sql.view.list.RowValuesTableModel; |
import org.openconcerto.ui.AutoHideListener; |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import org.openconcerto.ui.FormLayouter; |
61,6 → 64,7 |
import org.openconcerto.ui.component.InteractionMode; |
import org.openconcerto.ui.preferences.DefaultProps; |
import org.openconcerto.utils.ExceptionHandler; |
import org.openconcerto.utils.checks.ValidState; |
import java.awt.Color; |
import java.awt.GridBagConstraints; |
70,7 → 74,9 |
import java.beans.PropertyChangeEvent; |
import java.beans.PropertyChangeListener; |
import java.sql.SQLException; |
import java.util.HashSet; |
import java.util.List; |
import java.util.Set; |
import javax.swing.JCheckBox; |
import javax.swing.JLabel; |
109,6 → 115,17 |
return this.fourn; |
} |
@Override |
protected Set<String> createRequiredNames() { |
final Set<String> s = new HashSet<>(4); |
if (getTable().contains("ID_TYPE_CMD")) { |
s.add("ID_TYPE_CMD"); |
s.add("DA1"); |
s.add("ID_POLE_PRODUIT"); |
} |
return s; |
} |
public void addViews() { |
this.setLayout(new GridBagLayout()); |
final GridBagConstraints c = new DefaultGridBagConstraints(); |
184,7 → 201,9 |
} else { |
table.setRowCatComptable(null); |
} |
if (getTable().contains("OFFRE_COM")) { |
((SQLTextCombo) getView("OFFRE_COM").getComp()).setValue(rowF.getString("RESPONSABLE")); |
} |
} else { |
table.setRowCatComptable(null); |
} |
191,7 → 210,9 |
} |
}); |
if (!getTable().getFieldsName().contains("LIVRER")) { |
Boolean useCommandeEnCours = SQLPreferences.getMemCached(getElement().getTable().getDBRoot()).getBoolean(GestionCommercialeGlobalPreferencePanel.COMMANDE_FOURNISSEUR_EN_COURS, false); |
if (!getTable().getFieldsName().contains("LIVRER") && useCommandeEnCours) { |
// Commande en cours |
JCheckBox boxEnCours = new JCheckBox(getLabelFor("EN_COURS")); |
c.gridx += 2; |
1004,6 → 1025,27 |
stockUpdater.update(); |
} |
@Override |
public synchronized ValidState getValidState() { |
if (getTable().contains("ID_TYPE_CMD") && getTable().contains("ID_AFFAIRE") && getTable().getTable("COMMANDE_ELEMENT").contains("ID_AFFAIRE")) { |
SQLRequestComboBox boxAff = (SQLRequestComboBox) getView("ID_AFFAIRE").getComp(); |
final SQLRow selectedAff = boxAff.getSelectedRow(); |
if (selectedAff == null || selectedAff.isUndefined()) { |
RowValuesTableModel tableRow = this.table.getRowValuesTable().getRowValuesTableModel(); |
for (int i = 0; i < tableRow.getRowCount(); i++) { |
SQLRowValues rowVals = tableRow.getRowValuesAt(i); |
if (rowVals.getInt("QTE") != 0 && (rowVals.getObject("ID_AFFAIRE") == null || rowVals.isForeignEmpty("ID_AFFAIRE"))) { |
return ValidState.create(false, "Aucune affaire globale sélectionnée et une ligne avec une quantité > 0 n'est pas affectée à une affaire!"); |
} |
} |
} else { |
ValidState.create(false, "Aucune affaire globale sélectionnée!"); |
} |
} |
return super.getValidState(); |
} |
public void setDefaults() { |
this.resetValue(); |
this.numeroUniqueCommande.setText(NumerotationAutoSQLElement.getNextNumero(getElement().getClass())); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/order/element/EtatDemandeAchatItemSQLElement.java |
---|
17,9 → 17,9 |
package org.openconcerto.erp.core.supplychain.order.element; |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement; |
import org.openconcerto.erp.core.common.ui.IColorChooser; |
import org.openconcerto.sql.element.SQLComponent; |
import org.openconcerto.sql.element.UISQLComponent; |
import org.openconcerto.sql.ui.IColorChooser; |
import org.openconcerto.utils.ListMap; |
import java.util.ArrayList; |
68,7 → 68,7 |
return new UISQLComponent(this) { |
public void addViews() { |
this.addRequiredSQLObject(new JTextField(), "NOM", "left"); |
this.addRequiredSQLObject(new IColorChooser(), "COLOR", "right"); |
this.addRequiredSQLObject(new IColorChooser("Couleur"), "COLOR", "right"); |
} |
}; |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/order/element/FactureFournisseurSQLElement.java |
---|
19,15 → 19,23 |
import org.openconcerto.erp.generationDoc.gestcomm.FactureFournisseurXmlSheet; |
import org.openconcerto.erp.model.MouseSheetXmlListeListener; |
import org.openconcerto.sql.element.SQLComponent; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.view.EditFrame; |
import org.openconcerto.sql.view.EditPanel; |
import org.openconcerto.sql.view.list.IListe; |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent; |
import org.openconcerto.sql.view.list.RowAction; |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction; |
import org.openconcerto.utils.ListMap; |
import java.awt.event.ActionEvent; |
import java.util.ArrayList; |
import java.util.HashSet; |
import java.util.List; |
import java.util.Set; |
import javax.swing.AbstractAction; |
public class FactureFournisseurSQLElement extends ComptaSQLConfElement { |
public FactureFournisseurSQLElement() { |
41,7 → 49,22 |
actionAttachment.setPredicate(IListeEvent.getSingleSelectionPredicate()); |
getRowActions().add(actionAttachment); |
} |
RowAction actionClone = new RowAction(new AbstractAction() { |
public void actionPerformed(ActionEvent e) { |
EditFrame editFrame = new EditFrame(FactureFournisseurSQLElement.this, EditPanel.CREATION); |
((FactureFournisseurSQLComponent) editFrame.getSQLComponent()).loadFactureExistante(IListe.get(e).getSelectedId()); |
editFrame.setVisible(true); |
} |
}, true, "supplychain.invoice.clone") { |
public boolean enabledFor(IListeEvent evt) { |
List<? extends SQLRowAccessor> l = evt.getSelectedRows(); |
return (l != null && l.size() == 1); |
} |
}; |
getRowActions().add(actionClone); |
} |
@Override |
public Set<String> getReadOnlyFields() { |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/order/element/DemandeAchatItemSQLElement.java |
---|
25,6 → 25,7 |
import org.openconcerto.sql.element.SQLComponent; |
import org.openconcerto.sql.model.SQLInjector; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowListRSH; |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.model.SQLRowValuesListFetcher; |
import org.openconcerto.sql.model.SQLSelect; |
92,7 → 93,6 |
@Override |
public void actionPerformed(ActionEvent e) { |
List<SQLRowValues> rows = IListe.get(e).getSelectedRows(); |
StyleSQLElement styleElt = getDirectory().getElement(StyleSQLElement.class); |
int idNormal = styleElt.getAllStyleByName().get("Normal"); |
99,9 → 99,10 |
SQLRowValues rowVals = new SQLRowValues(getTable().getTable("DEMANDE_PRIX")); |
rowVals.put("DATE", new Date()); |
SQLInjector inj = SQLInjector.getInjector(getTable(), getTable().getTable("DEMANDE_PRIX_ELEMENT")); |
for (SQLRowValues sqlRowValues : rows) { |
SQLRow row = sqlRowValues.asRow(); |
row.fetchValues(); |
final List<SQLRow> rows = SQLRowListRSH.fetch(IListe.get(e).getRequest().getPrimaryTable(), IListe.get(e).getSelection().getSelectedIDs()); |
for (SQLRow row : rows) { |
rowVals.put("ID_AFFAIRE", row.getForeignID("ID_AFFAIRE")); |
SQLRowValues rowValsCmdElt = inj.createRowValuesFrom(row); |
rowValsCmdElt.put("ID_STYLE", idNormal); |
152,7 → 153,6 |
@Override |
public void actionPerformed(ActionEvent e) { |
List<SQLRowValues> rows = IListe.get(e).getSelectedRows(); |
StyleSQLElement styleElt = getDirectory().getElement(StyleSQLElement.class); |
int idNormal = styleElt.getAllStyleByName().get("Normal"); |
159,9 → 159,8 |
SQLRowValues rowVals = new SQLRowValues(getTable().getTable("COMMANDE")); |
rowVals.put("DATE", new Date()); |
SQLInjector inj = SQLInjector.getInjector(getTable(), getTable().getTable("COMMANDE_ELEMENT")); |
for (SQLRowValues sqlRowValues : rows) { |
SQLRow row = sqlRowValues.asRow(); |
row.fetchValues(); |
final List<SQLRow> rows = SQLRowListRSH.fetch(IListe.get(e).getRequest().getPrimaryTable(), IListe.get(e).getSelection().getSelectedIDs()); |
for (SQLRow row : rows) { |
rowVals.put("ID_AFFAIRE", row.getForeignID("ID_AFFAIRE")); |
SQLRowValues rowValsCmdElt = inj.createRowValuesFrom(row); |
rowValsCmdElt.put("ID_STYLE", idNormal); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/order/element/CommandeSQLElement.java |
---|
21,6 → 21,7 |
import org.openconcerto.erp.core.supplychain.receipt.component.BonReceptionSQLComponent; |
import org.openconcerto.erp.generationDoc.gestcomm.CommandeXmlSheet; |
import org.openconcerto.erp.model.MouseSheetXmlListeListener; |
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.element.SQLComponent; |
import org.openconcerto.sql.element.SQLElement; |
33,6 → 34,7 |
import org.openconcerto.sql.model.SQLSelectJoin; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.model.Where; |
import org.openconcerto.sql.preferences.SQLPreferences; |
import org.openconcerto.sql.view.EditFrame; |
import org.openconcerto.sql.view.EditPanel; |
import org.openconcerto.sql.view.list.IListe; |
50,6 → 52,8 |
import javax.swing.AbstractAction; |
import javax.swing.ImageIcon; |
import javax.swing.JFrame; |
import javax.swing.JOptionPane; |
import javax.swing.SwingWorker; |
import org.apache.commons.dbutils.handlers.ArrayListHandler; |
67,11 → 71,57 |
transfertBR(selectedRows); |
} |
}, false, "supplychain.order.create.receipt"); |
}, true, "supplychain.order.create.receipt"); |
bonAction.setPredicate(IListeEvent.getSingleSelectionPredicate()); |
getRowActions().add(bonAction); |
PredicateRowAction actionsTRFA = new PredicateRowAction(new AbstractAction("Transfert vers facture fournisseur") { |
public void actionPerformed(ActionEvent e) { |
final List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows(); |
SwingWorker<Boolean, Object> worker = new SwingWorker<Boolean, Object>() { |
@Override |
protected Boolean doInBackground() throws Exception { |
boolean b = TransfertBaseSQLComponent.isAlreadyAllTransfert(selectedRows, getTable(), getTable().getTable("FACTURE_FOURNISSEUR"), "T_HT", "T_HT"); |
if (b) { |
String label = "Attention "; |
if (selectedRows.size() > 1) { |
label += " les " + getPluralName() + " ont déjà été transféré!"; |
} else { |
label += getSingularName() + " a déjà été transféré!"; |
} |
label += "\n Voulez vous continuer?"; |
int ans = JOptionPane.showConfirmDialog(null, label, "Transfert " + getSingularName(), JOptionPane.YES_NO_OPTION); |
if (ans == JOptionPane.NO_OPTION) { |
return Boolean.FALSE; |
} |
} |
return Boolean.TRUE; |
} |
@Override |
protected void done() { |
try { |
Boolean b = get(); |
if (b) { |
TransfertBaseSQLComponent.openTransfertFrame(selectedRows, "FACTURE_FOURNISSEUR"); |
} |
} catch (Exception e) { |
ExceptionHandler.handle("Erreur lors du transfert des " + getPluralName() + "!", e); |
} |
} |
}; |
worker.execute(); |
} |
}, false); |
actionsTRFA.setPredicate(IListeEvent.getNonEmptySelectionPredicate()); |
getRowActions().add(actionsTRFA); |
// Transfert vers facture |
PredicateRowAction factureAction = new PredicateRowAction(new AbstractAction() { |
public void actionPerformed(ActionEvent e) { |
107,9 → 157,13 |
l.add("NOM"); |
l.add("DATE"); |
l.add("ID_FOURNISSEUR"); |
l.add("ID_COMMERCIAL"); |
l.add("T_HT"); |
l.add("T_TTC"); |
Boolean useCommandeEnCours = SQLPreferences.getMemCached(getTable().getDBRoot()).getBoolean(GestionCommercialeGlobalPreferencePanel.COMMANDE_FOURNISSEUR_EN_COURS, false); |
if (useCommandeEnCours) { |
l.add("EN_COURS"); |
} |
l.add("INFOS"); |
return l; |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/receipt/element/BonReceptionSQLElement.java |
---|
27,6 → 27,7 |
import org.openconcerto.sql.model.AliasedTable; |
import org.openconcerto.sql.model.SQLName; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.model.SQLSelect; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.model.Where; |
35,6 → 36,7 |
import org.openconcerto.sql.view.list.IListe; |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent; |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction; |
import org.openconcerto.utils.ExceptionHandler; |
import org.openconcerto.utils.ListMap; |
import java.awt.event.ActionEvent; |
45,6 → 47,8 |
import javax.swing.AbstractAction; |
import javax.swing.ImageIcon; |
import javax.swing.JFrame; |
import javax.swing.JOptionPane; |
import javax.swing.SwingWorker; |
import org.apache.commons.dbutils.handlers.ArrayListHandler; |
55,8 → 59,46 |
PredicateRowAction actionsTRFA = new PredicateRowAction(new AbstractAction("Transfert vers facture fournisseur") { |
public void actionPerformed(ActionEvent e) { |
TransfertBaseSQLComponent.openTransfertFrame(IListe.get(e).getSelectedRows(), "FACTURE_FOURNISSEUR"); |
final List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows(); |
SwingWorker<Boolean, Object> worker = new SwingWorker<Boolean, Object>() { |
@Override |
protected Boolean doInBackground() throws Exception { |
boolean b = TransfertBaseSQLComponent.isAlreadyAllTransfert(selectedRows, getTable(), getTable().getTable("FACTURE_FOURNISSEUR"), "TOTAL_HT", "T_HT"); |
if (b) { |
String label = "Attention "; |
if (selectedRows.size() > 1) { |
label += " les " + getPluralName() + " ont déjà été transféré!"; |
} else { |
label += getSingularName() + " a déjà été transféré!"; |
} |
label += "\n Voulez vous continuer?"; |
int ans = JOptionPane.showConfirmDialog(null, label, "Transfert " + getSingularName(), JOptionPane.YES_NO_OPTION); |
if (ans == JOptionPane.NO_OPTION) { |
return Boolean.FALSE; |
} |
} |
return Boolean.TRUE; |
} |
@Override |
protected void done() { |
try { |
Boolean b = get(); |
if (b) { |
TransfertBaseSQLComponent.openTransfertFrame(selectedRows, "FACTURE_FOURNISSEUR"); |
} |
} catch (Exception e) { |
ExceptionHandler.handle("Erreur lors du transfert des " + getPluralName() + "!", e); |
} |
} |
}; |
worker.execute(); |
} |
}, true); |
actionsTRFA.setPredicate(IListeEvent.getNonEmptySelectionPredicate()); |
85,6 → 127,7 |
protected List<String> getListFields() { |
final List<String> l = new ArrayList<>(5); |
l.add("NUMERO"); |
l.add("NOM"); |
l.add("DATE"); |
l.add("ID_FOURNISSEUR"); |
l.add("TOTAL_HT"); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/receipt/action/ListeDesBonsReceptionsAction.java |
---|
94,6 → 94,8 |
return frame; |
} |
private BigDecimal bigDecimal100 = new BigDecimal(100); |
private BigDecimal getAvancement(SQLRowAccessor r) { |
Collection<? extends SQLRowAccessor> rows = r.getReferentRows(r.getTable().getTable("TR_BON_RECEPTION")); |
long totalFact = 0; |
106,7 → 108,7 |
} |
} |
if (total > 0) { |
return new BigDecimal(totalFact).divide(new BigDecimal(total), DecimalUtils.HIGH_PRECISION).movePointRight(2).setScale(2, RoundingMode.HALF_UP); |
return this.bigDecimal100.min(new BigDecimal(totalFact).divide(new BigDecimal(total), DecimalUtils.HIGH_PRECISION).movePointRight(2).setScale(2, RoundingMode.HALF_UP)); |
} else { |
return BigDecimal.ONE.movePointRight(2); |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/receipt/component/BonReceptionSQLComponent.java |
---|
60,11 → 60,14 |
import java.math.BigDecimal; |
import java.sql.SQLException; |
import java.util.HashMap; |
import java.util.HashSet; |
import java.util.List; |
import java.util.Map; |
import java.util.Set; |
import javax.swing.JCheckBox; |
import javax.swing.JLabel; |
import javax.swing.JOptionPane; |
import javax.swing.JPanel; |
import javax.swing.JScrollPane; |
import javax.swing.JTextField; |
91,6 → 94,15 |
} |
@Override |
protected Set<String> createRequiredNames() { |
final Set<String> s = new HashSet<>(1); |
if (getTable().contains("ID_TYPE_CMD")) { |
s.add("ID_TYPE_CMD"); |
} |
return s; |
} |
@Override |
protected SQLRowValues createDefaults() { |
this.tableBonItem.getModel().clearRows(); |
this.textNumeroUnique.setText(NumerotationAutoSQLElement.getNextNumero(getElement().getClass())); |
628,6 → 640,8 |
} |
} |
int count = this.tableBonItem.getModel().getRowCount(); |
int receipt = 0; |
for (int i = 0; i < count; i++) { |
SQLRowValues r = this.tableBonItem.getModel().getRowValuesAt(i); |
SQLRowValues rowTR = map.get(r.getForeignID("ID_ARTICLE")); |
634,14 → 648,28 |
if (rowTR != null && !rowTR.isUndefined()) { |
if (r.getInt("QTE") > 0) { |
if (NumberUtils.areNumericallyEqual(r.getBigDecimal("QTE_UNITAIRE"), BigDecimal.ONE) || r.getInt("QTE") > 1) { |
this.tableBonItem.getModel().putValue(r.getInt("QTE") - rowTR.getInt("QTE"), i, "QTE"); |
int value = r.getInt("QTE") - rowTR.getInt("QTE"); |
if ((value <= 0)) { |
receipt++; |
} |
this.tableBonItem.getModel().putValue(Math.max(0, value), i, "QTE"); |
} else { |
this.tableBonItem.getModel().putValue(r.getBigDecimal("QTE_UNITAIRE").subtract(rowTR.getBigDecimal("QTE_UNITAIRE")), i, "QTE_UNITAIRE"); |
BigDecimal subtract = r.getBigDecimal("QTE_UNITAIRE").subtract(rowTR.getBigDecimal("QTE_UNITAIRE")); |
if (subtract.signum() <= 0) { |
receipt++; |
} |
this.tableBonItem.getModel().putValue(subtract.max(BigDecimal.ZERO), i, "QTE_UNITAIRE"); |
} |
} else { |
receipt++; |
} |
} |
} |
if (receipt == count) { |
JOptionPane.showMessageDialog(null, "Attention tous les articles ont déjà été réceptionné!"); |
} |
} |
@Override |
public void update() { |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/DepotStockSQLElement.java |
---|
14,16 → 14,27 |
package org.openconcerto.erp.core.supplychain.stock.element; |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement; |
import org.openconcerto.erp.core.common.ui.ListeViewPanel; |
import org.openconcerto.sql.element.BaseSQLComponent; |
import org.openconcerto.sql.element.SQLComponent; |
import org.openconcerto.sql.element.SQLElement; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.Where; |
import org.openconcerto.sql.view.IListFrame; |
import org.openconcerto.sql.view.list.IListe; |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent; |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction; |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import org.openconcerto.ui.FrameUtil; |
import org.openconcerto.utils.ListMap; |
import java.awt.GridBagConstraints; |
import java.awt.GridBagLayout; |
import java.awt.event.ActionEvent; |
import java.util.ArrayList; |
import java.util.List; |
import javax.swing.AbstractAction; |
import javax.swing.JLabel; |
import javax.swing.JTextField; |
33,7 → 44,22 |
public DepotStockSQLElement() { |
super("DEPOT_STOCK", "un dépôt", "dépôts"); |
PredicateRowAction actionStock = new PredicateRowAction(new AbstractAction("Voir le détails du stock") { |
@Override |
public void actionPerformed(ActionEvent e) { |
SQLRowAccessor selRow = IListe.get(e).getSelectedRow(); |
final SQLElement elementStock = getDirectory().getElement("STOCK"); |
IListFrame frame = new IListFrame( |
new ListeViewPanel(elementStock, new IListe(elementStock.createTableSource(new Where(elementStock.getTable().getField("ID_DEPOT_STOCK"), "=", selRow.getID()))))); |
FrameUtil.showPacked(frame); |
} |
}, true); |
actionStock.setPredicate(IListeEvent.getSingleSelectionPredicate()); |
getRowActions().add(actionStock); |
} |
protected List<String> getListFields() { |
final List<String> l = new ArrayList<String>(); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/StockItemsUpdater.java |
---|
25,6 → 25,8 |
import org.openconcerto.sql.model.SQLRowValuesListFetcher; |
import org.openconcerto.sql.model.SQLSelect; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.model.SQLTableEvent; |
import org.openconcerto.sql.model.SQLTableEvent.Mode; |
import org.openconcerto.sql.model.Where; |
import org.openconcerto.sql.utils.SQLUtils; |
import org.openconcerto.utils.DecimalUtils; |
154,12 → 156,13 |
for (String s : requests) { |
handlers.add(null); |
} |
// FIXME FIRE TABLE CHANGED TO UPDATE ILISTE ?? |
try { |
SQLUtils.executeAtomic(stockTable.getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<Object, IOException>() { |
@Override |
public Object handle(SQLDataSource ds) throws SQLException, IOException { |
SQLUtils.executeMultiple(stockTable.getDBSystemRoot(), requests, handlers); |
// FIXME FIRE ONLY CHANGED ROWS |
stockTable.fire(new SQLTableEvent(stockTable, SQLRow.NONEXISTANT_ID, Mode.ROW_UPDATED)); |
return null; |
} |
}); |
264,35 → 267,6 |
SQLUtils.executeMultiple(table.getDBSystemRoot(), multipleRequests, handlers); |
} |
private void fillProductComponent(List<ProductComponent> productComponents, int qte, int index, int level) { |
if (level > 0) { |
for (int i = index; i < items.size(); i++) { |
SQLRowAccessor r = items.get(i); |
if (!r.getTable().contains("NIVEAU") || r.getInt("NIVEAU") >= level) { |
// On ne calcul pas les stocks pour les éléments ayant des fils (le mouvement de |
// stock |
// des fils impactera les stocks automatiquement) |
if (r.getTable().contains("NIVEAU")) { |
if (i + 1 < items.size()) { |
SQLRowAccessor rNext = items.get(i + 1); |
if (rNext.getInt("NIVEAU") > r.getInt("NIVEAU")) { |
fillProductComponent(productComponents, qte * r.getInt("QTE"), i + 1, rNext.getInt("NIVEAU")); |
continue; |
} |
} |
} |
if ((!r.getTable().contains("NIVEAU") || r.getInt("NIVEAU") == level) && !r.isForeignEmpty("ID_ARTICLE") && r.getForeign("ID_ARTICLE") != null) { |
productComponents.add(ProductComponent.createFrom(r, qte, r)); |
} |
} else if (r.getInt("NIVEAU") < level) { |
// BREAK si on sort de l'article composé |
break; |
} |
} |
} |
} |
/** |
* Récupére les stocks associés aux articles non composés (inclus les fils des nomenclatures) et |
* les met à jour |
305,9 → 279,10 |
String mvtStockTableQuoted = rowSource.getTable().getTable("MOUVEMENT_STOCK").getSQLName().quote(); |
ProductHelper helper = new ProductHelper(rowSource.getTable().getDBRoot()); |
// Liste des éléments à mettre à jour |
List<ProductComponent> productComponents = new ArrayList<ProductComponent>(); |
fillProductComponent(productComponents, 1, 0, 1); |
helper.fillProductComponent(this.items, productComponents, 1, 0, 1); |
// for (int i = 0; i < items.size(); i++) { |
// SQLRowAccessor r = items.get(i); |
// |
327,7 → 302,6 |
// } |
// Liste des articles non composés à mettre à jour (avec les fils des nomenclatures) |
ProductHelper helper = new ProductHelper(rowSource.getTable().getDBRoot()); |
List<ProductComponent> boms = helper.getChildWithQtyFrom(productComponents); |
for (ProductComponent productComp : boms) { |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/StockSQLElement.java |
---|
20,6 → 20,7 |
import org.openconcerto.erp.model.MouseSheetXmlListeListener; |
import org.openconcerto.sql.element.BaseSQLComponent; |
import org.openconcerto.sql.element.SQLComponent; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.model.SQLRowValuesListFetcher; |
100,7 → 101,7 |
@Override |
public ListMap<String, String> getShowAs() { |
if (getTable().contains("ID_DEPOT_STOCK")) { |
return ListMap.singleton(null, "QTE_TH", "QTE_REEL", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE", "ID_DEPOT_STOCK"); |
return ListMap.singleton(null, "QTE_TH", "QTE_REEL", "QTE_MIN", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE", "ID_DEPOT_STOCK"); |
} else { |
return ListMap.singleton(null, "QTE_TH", "QTE_REEL", "QTE_LIV_ATTENTE", "QTE_RECEPT_ATTENTE"); |
} |
134,8 → 135,15 |
if (rowValsSource.getForeign("ID_DEPOT_STOCK") != null && !rowValsSource.isForeignEmpty("ID_DEPOT_STOCK")) { |
idDepot = rowValsSource.getForeignID("ID_DEPOT_STOCK"); |
} else { |
idDepot = rowValsSource.getForeign("ID_ARTICLE").getForeignID("ID_DEPOT_STOCK"); |
SQLRowAccessor rowValsArt = rowValsSource.getForeign("ID_ARTICLE"); |
if (rowValsArt.getObject("ID_DEPOT_STOCK") == null) { |
rowValsArt = rowValsArt.asRow(); |
((SQLRow) rowValsArt).fetchValues(); |
System.err.println("REFETCH ARTICLE"); |
Thread.dumpStack(); |
} |
idDepot = rowValsArt.getForeignID("ID_DEPOT_STOCK"); |
} |
SQLTable stockTable = rowValsSource.getTable().getTable("STOCK"); |
SQLRowValues putRowValuesStock = new SQLRowValues(stockTable); |
putRowValuesStock.putNulls(stockTable.getTable().getFieldsName()); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/stock/element/MouvementStockSQLElement.java |
---|
16,10 → 16,12 |
import org.openconcerto.erp.config.ComptaPropsConfiguration; |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement; |
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement; |
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement; |
import org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent; |
import org.openconcerto.erp.core.supplychain.order.ui.CommandeItemTable; |
import org.openconcerto.erp.core.supplychain.supplier.component.MouvementStockSQLComponent; |
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel; |
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.element.SQLComponent; |
import org.openconcerto.sql.element.SQLElement; |
50,6 → 52,7 |
import java.util.List; |
import java.util.Map.Entry; |
import javax.swing.JOptionPane; |
import javax.swing.SwingUtilities; |
public class MouvementStockSQLElement extends ComptaSQLConfElement { |
246,10 → 249,10 |
} |
public static void createCommandeF(final ListMap<SQLRow, SQLRowValues> col, final SQLRow rowDevise) { |
createCommandeF(col, rowDevise, "", true); |
createCommandeF(col, rowDevise, ""); |
} |
public static void createCommandeF(final ListMap<SQLRow, SQLRowValues> col, final SQLRow rowDevise, final String ref, final boolean useCommandeEnCours) { |
public static void createCommandeF(final ListMap<SQLRow, SQLRowValues> col, final SQLRow rowDevise, final String ref) { |
if (SwingUtilities.isEventDispatchThread()) { |
throw new IllegalStateException("This method must be called outside of EDT"); |
} |
256,6 → 259,7 |
if (col.size() > 0) { |
final SQLElement commande = Configuration.getInstance().getDirectory().getElement("COMMANDE"); |
Boolean useCommandeEnCours = SQLPreferences.getMemCached(commande.getTable().getDBRoot()).getBoolean(GestionCommercialeGlobalPreferencePanel.COMMANDE_FOURNISSEUR_EN_COURS, false); |
for (final Entry<SQLRow, List<SQLRowValues>> e : col.entrySet()) { |
final SQLRow fournisseur = e.getKey(); |
// On regarde si il existe une commande en cours existante |
324,9 → 328,23 |
} |
} |
if (rowValsMatch != null) { |
final int qte = rowValsMatch.getInt("QTE"); |
model.putValue(qte + rowValsElt.getInt("QTE"), index, "QTE"); |
int qte = rowValsMatch.getInt("QTE"); |
BigDecimal qteUV = rowValsMatch.getBigDecimal("QTE_UNITAIRE"); |
if (rowValsMatch.getObject("ID_UNITE_VENTE") != null && rowValsMatch.getForeignID("ID_UNITE_VENTE") != UniteVenteArticleSQLElement.A_LA_PIECE) { |
qteUV = qteUV.multiply(new BigDecimal(qte)); |
int qteElt = rowValsElt.getInt("QTE"); |
BigDecimal qteUVElt = rowValsElt.getBigDecimal("QTE_UNITAIRE"); |
qteUV = qteUV.add(qteUVElt.multiply(new BigDecimal(qteElt))); |
qte = 1; |
} else { |
qte += rowValsElt.getInt("QTE"); |
} |
model.putValue(qte, index, "QTE"); |
model.putValue(qteUV, index, "QTE_UNITAIRE"); |
} else { |
model.addRow(rowValsElt); |
if (rowValsElt.getObject("ID_ARTICLE") != null && !rowValsElt.isForeignEmpty("ID_ARTICLE")) { |
Object o = itemTable.tarifCompletion(rowValsElt.getForeign("ID_ARTICLE").asRow(), "PRIX_METRIQUE_HA_1"); |
342,9 → 360,16 |
} |
}); |
} |
} else { |
SwingUtilities.invokeLater(new Runnable() { |
@Override |
public void run() { |
JOptionPane.showMessageDialog(null, "Aucune commande à passer", "Commande fournisseur", JOptionPane.INFORMATION_MESSAGE); |
} |
}); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/customer/element/ContactSQLElement.java |
---|
File deleted |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/customer/element/CustomerGroup.java |
---|
94,6 → 94,9 |
final Group gCustomProduct = new Group("customerrelationship.customer.customproduct", LayoutHints.DEFAULT_SEPARATED_GROUP_HINTS); |
gCustomProduct.addItem("customerrelationship.customer.customproduct", new LayoutHints(true, true, true, true, true, true, true, true)); |
this.add(gCustomProduct); |
final Group gCustomRemiseProduct = new Group("customerrelationship.customer.customtarif", LayoutHints.DEFAULT_SEPARATED_GROUP_HINTS); |
gCustomRemiseProduct.addItem("customerrelationship.customer.customtarif", new LayoutHints(true, true, true, true, true, true, true, true)); |
this.add(gCustomRemiseProduct); |
this.add(gState); |
final Group gInfo = new Group("customerrelationship.customer.info", LayoutHints.DEFAULT_SEPARATED_GROUP_HINTS); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/customer/element/ClientNormalSQLElement.java |
---|
22,14 → 22,19 |
import org.openconcerto.ql.QLPrinter; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.element.SQLComponent; |
import org.openconcerto.sql.model.FieldPath; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.model.graph.Path; |
import org.openconcerto.sql.preferences.SQLPreferences; |
import org.openconcerto.sql.request.ListSQLRequest; |
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn; |
import org.openconcerto.sql.view.list.IListe; |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent; |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction; |
import org.openconcerto.sql.view.list.SQLTableModelSource; |
import org.openconcerto.ui.EmailComposer; |
import org.openconcerto.utils.CollectionUtils; |
import org.openconcerto.utils.ExceptionHandler; |
import java.awt.Font; |
37,6 → 42,7 |
import java.util.ArrayList; |
import java.util.Arrays; |
import java.util.List; |
import java.util.Set; |
import javax.swing.AbstractAction; |
180,6 → 186,28 |
return l; |
} |
@Override |
protected void _initTableSource(SQLTableModelSource res) { |
super._initTableSource(res); |
res.getColumns().add(new BaseSQLTableModelColumn(getDirectory().getTranslator().getLabelFor(getTable().getField("CATEGORIES")), String.class) { |
@Override |
protected Object show_(SQLRowAccessor r) { |
return r.getString("CATEGORIES"); |
} |
@Override |
public Set<FieldPath> getPaths() { |
Path p = new Path(getTable()); |
return CollectionUtils.createSet(new FieldPath(p, "CATEGORIES")); |
} |
}); |
} |
/* |
* (non-Javadoc) |
* |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/customer/element/ComptaContactSQLElement.java |
---|
New file |
0,0 → 1,63 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.customerrelationship.customer.element; |
import org.openconcerto.sql.view.list.IListe; |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent; |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction; |
import java.awt.event.ActionEvent; |
import javax.swing.AbstractAction; |
public abstract class ComptaContactSQLElement extends ContactSQLElementBase { |
static public class ContactFournisseurSQLElement extends ComptaContactSQLElement { |
public ContactFournisseurSQLElement() { |
super("CONTACT_FOURNISSEUR"); |
} |
} |
static public class ContactSalarieSQLElement extends ComptaContactSQLElement { |
public ContactSalarieSQLElement() { |
super("CONTACT_SALARIE"); |
} |
} |
static public class ContactAdministratifSQLElement extends ComptaContactSQLElement { |
public ContactAdministratifSQLElement() { |
super("CONTACT_ADMINISTRATIF"); |
} |
} |
static public class ContactSQLElement extends ComptaContactSQLElement { |
public ContactSQLElement() { |
super("CONTACT"); |
} |
} |
protected ComptaContactSQLElement(String tableName) { |
super(tableName); |
PredicateRowAction action = new PredicateRowAction(new AbstractAction() { |
@Override |
public void actionPerformed(ActionEvent e) { |
sendMail(IListe.get(e).getSelectedRows()); |
} |
}, true, "customerrelationship.customer.email.send"); |
action.setPredicate(IListeEvent.getNonEmptySelectionPredicate()); |
getRowActions().add(action); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/customer/element/CustomerSQLComponent.java |
---|
17,6 → 17,7 |
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement; |
import org.openconcerto.erp.core.customerrelationship.customer.ui.AdresseClientItemTable; |
import org.openconcerto.erp.core.sales.product.element.ClientCodeArticleTable; |
import org.openconcerto.erp.core.sales.product.ui.CustomerProductQtyPriceListTable; |
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel; |
import org.openconcerto.erp.utils.TM; |
import org.openconcerto.sql.Configuration; |
75,6 → 76,7 |
private ContactItemTable table; |
private ClientCodeArticleTable tableCustomProduct; |
private AdresseClientItemTable adresseTable = new AdresseClientItemTable(); |
private SQLTable contactTable = Configuration.getInstance().getDirectory().getElement("CONTACT").getTable(); |
private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO"); |
private final JUniqueTextField code = new JUniqueTextField(20) { |
88,6 → 90,7 |
} |
}; |
private CustomerProductQtyPriceListTable clienTarifTable = new CustomerProductQtyPriceListTable(); |
private SQLRowValues defaultContactRowVals = new SQLRowValues(UndefinedRowValuesCache.getInstance().getDefaultRowValues(this.contactTable)); |
private JCheckBox checkAdrLivraison, checkAdrFacturation; |
167,6 → 170,8 |
return this.table; |
} else if (id.equals("customerrelationship.customer.customproduct")) { |
return this.tableCustomProduct; |
} else if (id.equals("customerrelationship.customer.customtarif")) { |
return this.clienTarifTable; |
} else if (id.equals("customerrelationship.customer.addresses")) { |
return createAdressesComponent(); |
} else if (id.equals("NOM")) { |
243,6 → 248,7 |
super.update(); |
final int selectedID = getSelectedID(); |
this.table.updateField("ID_CLIENT", selectedID); |
this.clienTarifTable.updateField("ID_CLIENT", selectedID); |
this.tableCustomProduct.updateField("ID_CLIENT", selectedID); |
this.adresseTable.updateField("ID_CLIENT", selectedID); |
} |
254,6 → 260,7 |
this.checkAdrFacturation.setSelected(r == null || !r.getFields().contains("ID_ADRESSE_F") || r.isForeignEmpty("ID_ADRESSE_F")); |
if (r != null) { |
this.table.insertFrom("ID_CLIENT", r.asRowValues()); |
this.clienTarifTable.insertFrom("ID_CLIENT", r.asRowValues()); |
this.tableCustomProduct.insertFrom("ID_CLIENT", r.asRowValues()); |
this.adresseTable.insertFrom("ID_CLIENT", r.asRowValues()); |
} |
294,6 → 301,7 |
id = super.insert(order); |
this.table.updateField("ID_CLIENT", id); |
this.tableCustomProduct.updateField("ID_CLIENT", id); |
this.clienTarifTable.updateField("ID_CLIENT", id); |
this.adresseTable.updateField("ID_CLIENT", id); |
if (NumerotationAutoSQLElement.getNextNumero(getElement().getClass()).equalsIgnoreCase(this.code.getText().trim())) { |
SQLRowValues rowVals = new SQLRowValues(this.tableNum); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/customer/report/ReportingCommercialPDF.java |
---|
New file |
0,0 → 1,177 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.customerrelationship.customer.report; |
import java.awt.Color; |
import java.awt.Desktop; |
import java.io.File; |
import java.io.FileOutputStream; |
import java.io.IOException; |
import java.math.BigDecimal; |
import java.text.DecimalFormat; |
import java.text.DecimalFormatSymbols; |
import java.util.ArrayList; |
import java.util.Calendar; |
import java.util.Collections; |
import java.util.Comparator; |
import java.util.Date; |
import java.util.List; |
import com.ibm.icu.text.SimpleDateFormat; |
import com.lowagie.text.Document; |
import com.lowagie.text.Element; |
import com.lowagie.text.Font; |
import com.lowagie.text.PageSize; |
import com.lowagie.text.Paragraph; |
import com.lowagie.text.Phrase; |
import com.lowagie.text.Rectangle; |
import com.lowagie.text.pdf.PdfPCell; |
import com.lowagie.text.pdf.PdfPTable; |
import com.lowagie.text.pdf.PdfWriter; |
public class ReportingCommercialPDF { |
private final List<ReportingCommercial> items; |
public ReportingCommercialPDF(List<ReportingCommercial> items) { |
this.items = new ArrayList<>(items); |
Collections.sort(this.items, new Comparator<ReportingCommercial>() { |
@Override |
public int compare(ReportingCommercial o1, ReportingCommercial o2) { |
return o2.getTotal().compareTo(o1.getTotal()); |
} |
}); |
} |
public static void main(String[] args) throws IOException { |
final List<ReportingCommercial> list = new ArrayList<>(); |
final Calendar c = Calendar.getInstance(); |
final Date d1 = c.getTime(); |
c.add(Calendar.MONTH, 50); |
final Date d2 = c.getTime(); |
for (int i = 0; i < 5; i++) { |
ReportingCommercial r = new ReportingCommercial("commercial " + i, d1, d2); |
for (int j = 0; j < i * 5; j++) { |
final ReportingCommercialItem item = new ReportingCommercialItem("client " + j); |
item.addCA(BigDecimal.valueOf(j * 12345.78f)); |
r.add(item); |
} |
list.add(r); |
} |
final File file = new File("out.pdf"); |
final ReportingCommercialPDF pdf = new ReportingCommercialPDF(list); |
pdf.export(file); |
Desktop.getDesktop().open(file); |
} |
public void export(File file) throws IOException { |
try { |
final Document document = new Document(PageSize.A4); |
PdfWriter.getInstance(document, new FileOutputStream(file)); |
document.open(); |
// Formats |
final SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); |
final DecimalFormat decimalFormat = new DecimalFormat("###,###,##0.00"); |
final DecimalFormatSymbols formatSymbols = decimalFormat.getDecimalFormatSymbols(); |
formatSymbols.setGroupingSeparator(' '); |
formatSymbols.setDecimalSeparator(','); |
decimalFormat.setDecimalFormatSymbols(formatSymbols); |
// Fonts |
final Font fontHeader = new Font(Font.HELVETICA, 11f, Font.BOLD); |
fontHeader.setColor(Color.WHITE); |
final Font normal = new Font(Font.HELVETICA, 10f, Font.NORMAL); |
final Font fontTitle = new Font(Font.HELVETICA, 18f, Font.BOLD); |
final Font fontInfo = new Font(Font.HELVETICA, 11f, Font.NORMAL); |
// Colors |
final Color backgroundColor = new Color(57, 115, 157); |
final Color cellBackgroundColor = new Color(225, 236, 244); |
for (ReportingCommercial reporting : this.items) { |
final List<ReportingCommercialItem> rItems = new ArrayList<ReportingCommercialItem>(reporting.getItems()); |
Collections.sort(rItems, new Comparator<ReportingCommercialItem>() { |
@Override |
public int compare(ReportingCommercialItem o1, ReportingCommercialItem o2) { |
return o2.getCa().compareTo(o1.getCa()); |
} |
}); |
document.add(new Paragraph("Chiffre d'affaires", fontTitle)); |
document.add(new Paragraph("Commercial : " + reporting.getCommercial(), fontInfo)); |
document.add(new Paragraph("Période : du " + df.format(reporting.getDebut()) + " au " + df.format(reporting.getFin()), fontInfo)); |
if (rItems.isEmpty()) { |
document.add(new Paragraph("\n")); |
document.add(new Paragraph("\n")); |
final Font fontInfo2 = new Font(Font.HELVETICA, 13f, Font.ITALIC); |
fontInfo2.setColor(Color.GRAY); |
document.add(new Paragraph("Aucune donnée.", fontInfo2)); |
} else { |
document.add(new Paragraph("Total : " + decimalFormat.format(reporting.getTotal()) + " € HT", fontInfo)); |
document.add(new Paragraph("\n")); |
final PdfPTable table = new PdfPTable(2); |
table.setWidthPercentage(100); |
table.setWidths(new float[] { 800f, 160f }); |
final PdfPCell c1 = new PdfPCell(new Phrase("Clients", fontHeader)); |
c1.setBackgroundColor(backgroundColor); |
c1.setBorder(Rectangle.NO_BORDER); |
c1.setHorizontalAlignment(Element.ALIGN_LEFT); |
c1.setVerticalAlignment(Element.ALIGN_MIDDLE); |
c1.setPaddingBottom(7); |
c1.setPaddingLeft(6); |
table.addCell(c1); |
final PdfPCell c2 = new PdfPCell(new Phrase("C.A. H.T.", fontHeader)); |
c2.setBackgroundColor(backgroundColor); |
c2.setBorder(Rectangle.NO_BORDER); |
c2.setHorizontalAlignment(Element.ALIGN_CENTER); |
c2.setVerticalAlignment(Element.ALIGN_MIDDLE); |
c2.setPaddingBottom(7); |
c2.setPaddingLeft(6); |
table.addCell(c2); |
table.setHeaderRows(1); |
boolean pair = true; |
for (ReportingCommercialItem rItem : rItems) { |
final PdfPCell col1 = new PdfPCell(new Phrase(rItem.getClient(), normal)); |
col1.setBorder(Rectangle.NO_BORDER); |
col1.setHorizontalAlignment(Element.ALIGN_LEFT); |
col1.setVerticalAlignment(Element.ALIGN_CENTER); |
col1.setPaddingBottom(5); |
col1.setPaddingLeft(6); |
final PdfPCell col2 = new PdfPCell(new Phrase(decimalFormat.format(rItem.getCa()), normal)); |
col2.setHorizontalAlignment(Element.ALIGN_RIGHT); |
col2.setBorder(Rectangle.NO_BORDER); |
// Alternance couleur |
if (pair) { |
col1.setBackgroundColor(cellBackgroundColor); |
col2.setBackgroundColor(cellBackgroundColor); |
} |
table.addCell(col1); |
table.addCell(col2); |
pair = !pair; |
} |
document.add(table); |
} |
document.newPage(); |
} |
document.close(); |
} catch (Exception e) { |
throw new IOException(e); |
} |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/customer/report/ReportingCommercialItem.java |
---|
New file |
0,0 → 1,39 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.customerrelationship.customer.report; |
import java.math.BigDecimal; |
public class ReportingCommercialItem { |
private String client; |
private BigDecimal ca; |
public ReportingCommercialItem(String client) { |
this.client = client; |
this.ca = BigDecimal.ZERO; |
} |
public void addCA(BigDecimal c) { |
this.ca = this.ca.add(c); |
} |
public String getClient() { |
return this.client; |
} |
public BigDecimal getCa() { |
return this.ca; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/customer/report/ReportingCommercial.java |
---|
New file |
0,0 → 1,73 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.customerrelationship.customer.report; |
import java.math.BigDecimal; |
import java.util.Collection; |
import java.util.Date; |
import java.util.HashMap; |
import java.util.Map; |
public class ReportingCommercial { |
private String commercial; |
private Date debut; |
private Date fin; |
private Map<String, ReportingCommercialItem> items = new HashMap<>(); |
public ReportingCommercial(String commercial, Date debut, Date fin) { |
this.commercial = commercial; |
this.debut = debut; |
this.fin = fin; |
} |
public BigDecimal getTotal() { |
BigDecimal total = BigDecimal.ZERO; |
for (ReportingCommercialItem item : this.items.values()) { |
total = total.add(item.getCa()); |
} |
return total; |
} |
public void add(ReportingCommercialItem item) { |
this.items.put(item.getClient(), item); |
} |
public void add(String client, BigDecimal ht) { |
if (this.items.containsKey(client)) { |
this.items.get(client).addCA(ht); |
} else { |
ReportingCommercialItem reportingCommercialItem = new ReportingCommercialItem(client); |
reportingCommercialItem.addCA(ht); |
this.items.put(client, reportingCommercialItem); |
} |
} |
public Collection<ReportingCommercialItem> getItems() { |
return this.items.values(); |
} |
public String getCommercial() { |
return this.commercial; |
} |
public Date getDebut() { |
return this.debut; |
} |
public Date getFin() { |
return this.fin; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/customer/report/ReportingCommercialCreator.java |
---|
New file |
0,0 → 1,111 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.customerrelationship.customer.report; |
import org.openconcerto.sql.model.DBRoot; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.model.SQLRowValuesListFetcher; |
import org.openconcerto.sql.model.SQLSelect; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.model.Where; |
import org.openconcerto.utils.cc.ITransformer; |
import java.math.BigDecimal; |
import java.util.Collection; |
import java.util.Date; |
import java.util.HashMap; |
import java.util.List; |
import java.util.Map; |
public class ReportingCommercialCreator { |
final private Date deb, fin; |
final private DBRoot root; |
public ReportingCommercialCreator(Date deb, Date fin, DBRoot root) { |
this.deb = deb; |
this.fin = fin; |
this.root = root; |
} |
public Collection<ReportingCommercial> getValues() { |
// Facture |
final SQLTable tableFacture = this.root.getTable("SAISIE_VENTE_FACTURE"); |
SQLRowValues rowValues = new SQLRowValues(tableFacture); |
rowValues.putRowValues("ID_COMMERCIAL").putNulls("PRENOM", "NOM"); |
rowValues.putRowValues("ID_CLIENT").putNulls("CODE", "NOM"); |
rowValues.putNulls("T_HT", "T_TTC"); |
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValues); |
fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() { |
@Override |
public SQLSelect transformChecked(SQLSelect input) { |
Where w = new Where(tableFacture.getField("DATE"), deb, fin); |
input.setWhere(w); |
return input; |
} |
}); |
Map<Integer, ReportingCommercial> mapCommercial = new HashMap<>(); |
List<SQLRowValues> result = fetcher.fetch(); |
for (SQLRowValues sqlRowValues : result) { |
int commercialID = sqlRowValues.getForeignID("ID_COMMERCIAL"); |
if (!mapCommercial.containsKey(commercialID)) { |
SQLRowAccessor commercialRow = sqlRowValues.getForeign("ID_COMMERCIAL"); |
mapCommercial.put(commercialID, new ReportingCommercial(commercialRow.getString("PRENOM") + " " + commercialRow.getString("NOM"), deb, fin)); |
} |
ReportingCommercial r = mapCommercial.get(commercialID); |
BigDecimal bigDecimal = new BigDecimal(sqlRowValues.getLong("T_HT")).movePointLeft(2); |
r.add(sqlRowValues.getForeign("ID_CLIENT").getString("NOM"), bigDecimal); |
} |
// Avoir |
final SQLTable tableAvoir = this.root.getTable("AVOIR_CLIENT"); |
SQLRowValues rowValuesAvoir = new SQLRowValues(tableAvoir); |
rowValuesAvoir.putRowValues("ID_COMMERCIAL").putNulls("PRENOM", "NOM"); |
rowValuesAvoir.putRowValues("ID_CLIENT").putNulls("CODE", "NOM"); |
rowValuesAvoir.putNulls("MONTANT_HT", "MONTANT_TTC"); |
SQLRowValuesListFetcher fetcherAvoir = SQLRowValuesListFetcher.create(rowValuesAvoir); |
fetcherAvoir.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() { |
@Override |
public SQLSelect transformChecked(SQLSelect input) { |
Where w = new Where(tableAvoir.getField("DATE"), deb, fin); |
input.setWhere(w); |
return input; |
} |
}); |
List<SQLRowValues> resultA = fetcherAvoir.fetch(); |
for (SQLRowValues sqlRowValues : resultA) { |
int commercialID = sqlRowValues.getForeignID("ID_COMMERCIAL"); |
if (!mapCommercial.containsKey(commercialID)) { |
SQLRowAccessor commercialRow = sqlRowValues.getForeign("ID_COMMERCIAL"); |
mapCommercial.put(commercialID, new ReportingCommercial(commercialRow.getString("PRENOM") + " " + commercialRow.getString("NOM"), deb, fin)); |
} |
ReportingCommercial r = mapCommercial.get(commercialID); |
BigDecimal bigDecimal = new BigDecimal(sqlRowValues.getLong("MONTANT_HT")).movePointLeft(2).negate(); |
r.add(sqlRowValues.getForeign("ID_CLIENT").getString("NOM"), bigDecimal); |
} |
return mapCommercial.values(); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/customer/report/ReportingCommercialPanel.java |
---|
New file |
0,0 → 1,125 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
/* |
* Créé le 23 avr. 2012 |
*/ |
package org.openconcerto.erp.core.customerrelationship.customer.report; |
import org.openconcerto.sql.model.DBRoot; |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import org.openconcerto.ui.JDate; |
import org.openconcerto.utils.ExceptionHandler; |
import java.awt.Desktop; |
import java.awt.Frame; |
import java.awt.GridBagConstraints; |
import java.awt.GridBagLayout; |
import java.awt.event.ActionEvent; |
import java.beans.PropertyChangeEvent; |
import java.beans.PropertyChangeListener; |
import java.io.File; |
import java.io.IOException; |
import java.util.ArrayList; |
import java.util.Calendar; |
import java.util.List; |
import javax.swing.AbstractAction; |
import javax.swing.JButton; |
import javax.swing.JLabel; |
import javax.swing.JPanel; |
import javax.swing.SwingUtilities; |
public class ReportingCommercialPanel extends JPanel { |
public ReportingCommercialPanel(final DBRoot root) { |
super(new GridBagLayout()); |
JLabel labelCom = new JLabel("Période du "); |
GridBagConstraints c = new DefaultGridBagConstraints(); |
this.add(labelCom, c); |
c.gridx++; |
final JDate dateDeb = new JDate(); |
this.add(dateDeb, c); |
c.gridx++; |
JLabel labelYear = new JLabel("au"); |
final JDate dateFin = new JDate(); |
Calendar cal = Calendar.getInstance(); |
cal.set(Calendar.MONTH, Calendar.JANUARY); |
cal.set(Calendar.DAY_OF_MONTH, 1); |
dateDeb.setValue(cal.getTime()); |
this.add(labelYear, c); |
c.gridx++; |
this.add(dateFin, c); |
cal.set(Calendar.MONTH, Calendar.DECEMBER); |
cal.set(Calendar.DAY_OF_MONTH, 31); |
dateFin.setValue(cal.getTime()); |
final JButton buttonValid = new JButton(new AbstractAction("Valider") { |
@Override |
public void actionPerformed(ActionEvent e) { |
new Thread() { |
public void run() { |
ReportingCommercialCreator creator = new ReportingCommercialCreator(dateDeb.getValue(), dateFin.getValue(), root); |
List<ReportingCommercial> list = new ArrayList<>(creator.getValues()); |
ReportingCommercialPDF reporting = new ReportingCommercialPDF(list); |
File file; |
try { |
file = File.createTempFile("ReportingCommerical", ".pdf"); |
reporting.export(file); |
Desktop.getDesktop().open(file); |
} catch (IOException e) { |
ExceptionHandler.handle("Erreur lors de la cration du fichier", e); |
} |
SwingUtilities.invokeLater(new Runnable() { |
@Override |
public void run() { |
Frame frame = (Frame) SwingUtilities.getRoot(ReportingCommercialPanel.this); |
if (frame != null) { |
frame.dispose(); |
} |
} |
}); |
}; |
}.start(); |
} |
}); |
c.gridx++; |
// buttonValid.setEnabled(false); |
this.add(buttonValid, c); |
dateDeb.addValueListener(new PropertyChangeListener() { |
@Override |
public void propertyChange(PropertyChangeEvent evt) { |
buttonValid.setEnabled(dateDeb.getValue() != null && dateFin.getValue() != null); |
} |
}); |
dateFin.addValueListener(new PropertyChangeListener() { |
@Override |
public void propertyChange(PropertyChangeEvent evt) { |
buttonValid.setEnabled(dateDeb.getValue() != null && dateFin.getValue() != null); |
} |
}); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/customer/action/ListeDesClientsAction.java |
---|
15,9 → 15,8 |
import org.openconcerto.erp.action.CreateIListFrameAbstractAction; |
import org.openconcerto.erp.config.ComptaPropsConfiguration; |
import org.openconcerto.erp.core.customerrelationship.customer.element.ClientNormalSQLElement; |
import org.openconcerto.erp.core.customerrelationship.customer.element.CustomerSQLElement; |
import org.openconcerto.erp.core.sales.invoice.ui.EcheanceRenderer; |
import org.openconcerto.sql.element.SQLElement; |
import org.openconcerto.sql.model.SQLField; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.view.IListFrame; |
26,10 → 25,12 |
import javax.swing.JTable; |
public class ListeDesClientsAction extends CreateIListFrameAbstractAction<ClientNormalSQLElement> { |
public class ListeDesClientsAction extends CreateIListFrameAbstractAction<SQLElement> { |
public ListeDesClientsAction(final ComptaPropsConfiguration conf) { |
super(conf, CustomerSQLElement.class); |
// handle CustomerSQLElement/ClientSocieteSQLElement (or even a module replacing the |
// default element) |
super(conf, conf.getDirectory().getElement(conf.getRootSociete().getTable("CLIENT"))); |
} |
@Override |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/customer/action/ListeDesContactsAction.java |
---|
15,7 → 15,7 |
import org.openconcerto.erp.action.CreateIListFrameAbstractAction; |
import org.openconcerto.erp.config.ComptaPropsConfiguration; |
import org.openconcerto.erp.core.customerrelationship.customer.element.ContactSQLElement; |
import org.openconcerto.erp.core.customerrelationship.customer.element.ComptaContactSQLElement.ContactSQLElement; |
public class ListeDesContactsAction extends CreateIListFrameAbstractAction<ContactSQLElement> { |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/customer/ui/CategorieComptableChoiceUI.java |
---|
New file |
0,0 → 1,67 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.customerrelationship.customer.ui; |
import org.openconcerto.sql.element.BaseSQLComponent; |
import org.openconcerto.sql.element.SQLElement; |
import org.openconcerto.sql.model.Where; |
import org.openconcerto.sql.sqlobject.ElementComboBox; |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import java.awt.GridBagConstraints; |
import javax.swing.JLabel; |
import javax.swing.SwingConstants; |
public class CategorieComptableChoiceUI { |
private ElementComboBox comboCatCompt; |
public CategorieComptableChoiceUI() { |
// TODO Auto-generated constructor stub |
} |
public void addToUI(BaseSQLComponent comp, GridBagConstraints c) { |
// Adresse Facturation |
c.gridx = 0; |
c.gridy++; |
c.gridwidth = 1; |
final JLabel labelCat = new JLabel(comp.getLabelFor("ID_CATEGORIE_COMPTABLE")); |
labelCat.setHorizontalAlignment(SwingConstants.RIGHT); |
c.weightx = 0; |
c.gridwidth = 1; |
c.fill = GridBagConstraints.HORIZONTAL; |
comp.add(labelCat, c); |
this.comboCatCompt = new ElementComboBox(); |
this.comboCatCompt.setButtonsVisible(false); |
c.gridx++; |
c.gridwidth = 1; |
c.weightx = 0; |
c.weighty = 0; |
c.fill = GridBagConstraints.NONE; |
comp.add(this.comboCatCompt, c); |
final SQLElement catComptableElement = comp.getElement().getForeignElement("ID_CATEGORIE_COMPTABLE"); |
this.comboCatCompt.init(catComptableElement, catComptableElement.getComboRequest(true)); |
DefaultGridBagConstraints.lockMinimumSize(this.comboCatCompt); |
comp.addView(this.comboCatCompt, "ID_CATEGORIE_COMPTABLE"); |
this.comboCatCompt.setAddIconVisible(false); |
} |
public ElementComboBox getCombo() { |
return this.comboCatCompt; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/mail/EmailTemplateSQLComponent.java |
---|
New file |
0,0 → 1,32 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.customerrelationship.mail; |
import org.openconcerto.sql.element.GroupSQLComponent; |
import org.openconcerto.sql.element.SQLElement; |
import org.openconcerto.sql.model.SQLRowValues; |
public class EmailTemplateSQLComponent extends GroupSQLComponent { |
public EmailTemplateSQLComponent(SQLElement element) { |
super(element); |
} |
@Override |
protected SQLRowValues createDefaults() { |
final SQLRowValues defaultValues = super.createDefaults(); |
defaultValues.put("FORMAT_DATE", "dd/MM/yyyy"); |
return defaultValues; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/mail/EmailTemplateSQLElement.java |
---|
New file |
0,0 → 1,52 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.customerrelationship.mail; |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement; |
import org.openconcerto.sql.element.GlobalMapper; |
import org.openconcerto.sql.element.SQLComponent; |
import java.util.Arrays; |
import java.util.List; |
public class EmailTemplateSQLElement extends ComptaSQLConfElement { |
public static final String TABLE_NAME = "MODELE_EMAIL"; |
public EmailTemplateSQLElement() { |
super(TABLE_NAME, "un modèle d'email", "modèles d'emails"); |
final EmailTemplateGroup group = new EmailTemplateGroup(); |
GlobalMapper.getInstance().map(EmailTemplateGroup.ID, group); |
setDefaultGroup(group); |
} |
@Override |
protected List<String> getListFields() { |
return Arrays.asList("NOM", "PAR_DEFAUT"); |
} |
@Override |
protected List<String> getComboFields() { |
return Arrays.asList("NOM"); |
} |
@Override |
protected SQLComponent createComponent() { |
return new EmailTemplateSQLComponent(this); |
} |
@Override |
protected String createCode() { |
return "customerrelationship.mail.email.template"; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/mail/action/ListeDesModelesEmailAction.java |
---|
New file |
0,0 → 1,35 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.customerrelationship.mail.action; |
import org.openconcerto.erp.action.CreateFrameAbstractAction; |
import org.openconcerto.erp.core.customerrelationship.mail.EmailTemplateSQLElement; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.view.IListFrame; |
import org.openconcerto.sql.view.ListeAddPanel; |
import javax.swing.Action; |
import javax.swing.JFrame; |
public class ListeDesModelesEmailAction extends CreateFrameAbstractAction { |
public ListeDesModelesEmailAction() { |
super(); |
this.putValue(Action.NAME, "Liste des modèles d'email"); |
} |
public JFrame createFrame() { |
return new IListFrame(new ListeAddPanel(Configuration.getInstance().getDirectory().getElement(EmailTemplateSQLElement.TABLE_NAME))); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/mail/EmailTemplateGroup.java |
---|
New file |
0,0 → 1,30 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.customerrelationship.mail; |
import org.openconcerto.ui.group.Group; |
import org.openconcerto.ui.group.LayoutHints; |
public class EmailTemplateGroup extends Group { |
public static final String ID = "customerrelationship.mail.email.template"; |
public EmailTemplateGroup() { |
super(ID); |
addItem("NOM"); |
addItem("TITRE", LayoutHints.DEFAULT_LARGE_FIELD_HINTS); |
addItem("TEXTE", new LayoutHints(true, true, true, true, true, true, true)); |
addItem("FORMAT_DATE", new LayoutHints(false, false, true, true, false, false)); |
addItem("PAR_DEFAUT"); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/mail/ValueListener.java |
---|
New file |
0,0 → 1,18 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.customerrelationship.mail; |
public interface ValueListener { |
public void valueSelected(Object value); |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/customerrelationship/mail/EmailTemplate.java |
---|
New file |
0,0 → 1,170 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.customerrelationship.mail; |
import org.openconcerto.sql.model.DBRoot; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowListRSH; |
import org.openconcerto.sql.model.SQLSelect; |
import org.openconcerto.sql.model.SQLTable; |
import java.awt.BorderLayout; |
import java.awt.Component; |
import java.awt.Container; |
import java.awt.Dimension; |
import java.awt.FlowLayout; |
import java.awt.Frame; |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionListener; |
import java.util.ArrayList; |
import java.util.Collections; |
import java.util.Comparator; |
import java.util.List; |
import javax.swing.DefaultListCellRenderer; |
import javax.swing.JButton; |
import javax.swing.JComponent; |
import javax.swing.JDialog; |
import javax.swing.JLabel; |
import javax.swing.JList; |
import javax.swing.JPanel; |
import javax.swing.ListSelectionModel; |
import javax.swing.SwingUtilities; |
import com.lowagie.text.Font; |
public class EmailTemplate { |
private String name; |
private String title; |
private String text; |
private boolean isDefault; |
private String dateFormat; |
public EmailTemplate(String name, String title, String text, Boolean isDefault, String dateFormat) { |
this.name = name; |
this.title = title; |
this.text = text; |
this.isDefault = isDefault; |
this.dateFormat = dateFormat; |
} |
public static List<EmailTemplate> getAll(DBRoot root) { |
final List<EmailTemplate> result = new ArrayList<>(); |
final SQLSelect selF = new SQLSelect(); |
final SQLTable tFamilleArticle = root.getTable(EmailTemplateSQLElement.TABLE_NAME); |
selF.addSelect(tFamilleArticle.getKey()); |
selF.addSelect(tFamilleArticle.getField("NOM")); |
selF.addSelect(tFamilleArticle.getField("TITRE")); |
selF.addSelect(tFamilleArticle.getField("TEXTE")); |
selF.addSelect(tFamilleArticle.getField("PAR_DEFAUT")); |
selF.addSelect(tFamilleArticle.getField("FORMAT_DATE")); |
final List<SQLRow> lF = SQLRowListRSH.execute(selF); |
for (SQLRow sqlRow : lF) { |
result.add(new EmailTemplate(sqlRow.getString("NOM"), sqlRow.getString("TITRE"), sqlRow.getString("TEXTE"), sqlRow.getBoolean("PAR_DEFAUT"), sqlRow.getString("FORMAT_DATE"))); |
} |
return result; |
} |
public String getName() { |
return this.name; |
} |
public String getTitle() { |
return this.title; |
} |
public String getText() { |
return this.text; |
} |
public boolean isDefault() { |
return this.isDefault; |
} |
public String getDateFormat() { |
return this.dateFormat; |
} |
public static void askTemplate(JComponent parent, DBRoot root, ValueListener listener) { |
if (!SwingUtilities.isEventDispatchThread()) { |
throw new IllegalStateException("must be called from EDT"); |
} |
List<EmailTemplate> templates = getAll(root); |
if (templates.isEmpty()) { |
listener.valueSelected(null); |
return; |
} |
if (templates.size() == 1) { |
listener.valueSelected(templates.get(0)); |
return; |
} |
Collections.sort(templates, new Comparator<EmailTemplate>() { |
@Override |
public int compare(EmailTemplate o1, EmailTemplate o2) { |
return o1.getName().compareToIgnoreCase(o2.getName()); |
} |
}); |
final JDialog dialog = new JDialog((Frame) SwingUtilities.getWindowAncestor(parent), "Modèle à utiliser", true); |
final JList<EmailTemplate> list = new JList<>(templates.toArray(new EmailTemplate[0])); |
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
for (int i = 0; i < templates.size(); i++) { |
final EmailTemplate t = templates.get(i); |
if (t.isDefault) { |
list.setSelectedIndex(i); |
break; |
} |
} |
list.setFixedCellHeight((int) (new JLabel("t").getPreferredSize().height * 1.5)); |
list.setCellRenderer(new DefaultListCellRenderer() { |
@Override |
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
EmailTemplate t = (EmailTemplate) value; |
final JLabel l = (JLabel) super.getListCellRendererComponent(list, t.getName(), index, isSelected, cellHasFocus); |
if (t.isDefault) { |
l.setFont(l.getFont().deriveFont(Font.BOLD)); |
} else { |
l.setFont(l.getFont().deriveFont(Font.NORMAL)); |
} |
return l; |
} |
}); |
list.setMinimumSize(new Dimension(300, 200)); |
list.setPreferredSize(new Dimension(300, 200)); |
final Container contentPane = dialog.getContentPane(); |
contentPane.setLayout(new BorderLayout()); |
contentPane.add(list, BorderLayout.CENTER); |
JPanel p = new JPanel(); |
p.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
final JButton button = new JButton("Valider"); |
button.addActionListener(new ActionListener() { |
@Override |
public void actionPerformed(ActionEvent e) { |
listener.valueSelected(list.getSelectedValue()); |
dialog.dispose(); |
} |
}); |
p.add(button); |
contentPane.add(p, BorderLayout.SOUTH); |
dialog.pack(); |
dialog.setLocationRelativeTo(parent); |
dialog.setVisible(true); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/payment/element/EncaisserMontantSQLElement.java |
---|
17,9 → 17,13 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement; |
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement; |
import org.openconcerto.erp.core.finance.payment.component.EncaisserMontantSQLComponent; |
import org.openconcerto.erp.core.sales.invoice.component.SaisieVenteFactureSQLComponent; |
import org.openconcerto.erp.generationEcritures.GenerationReglementVenteNG; |
import org.openconcerto.erp.model.PrixTTC; |
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.element.SQLComponent; |
import org.openconcerto.sql.element.SQLElement; |
import org.openconcerto.sql.element.TreesOfSQLRows; |
import org.openconcerto.sql.model.FieldPath; |
import org.openconcerto.sql.model.SQLRow; |
32,6 → 36,7 |
import org.openconcerto.sql.model.graph.Path; |
import org.openconcerto.sql.model.graph.PathBuilder; |
import org.openconcerto.sql.preferences.SQLPreferences; |
import org.openconcerto.sql.view.EditFrame; |
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn; |
import org.openconcerto.sql.view.list.IListe; |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent; |
39,6 → 44,7 |
import org.openconcerto.sql.view.list.SQLTableModelSource; |
import org.openconcerto.utils.CollectionUtils; |
import org.openconcerto.utils.ExceptionHandler; |
import org.openconcerto.utils.StringUtils; |
import java.awt.event.ActionEvent; |
import java.sql.SQLException; |
51,6 → 57,8 |
import java.util.Set; |
import javax.swing.AbstractAction; |
import javax.swing.JOptionPane; |
import javax.swing.SwingUtilities; |
public class EncaisserMontantSQLElement extends ComptaSQLConfElement { |
164,7 → 172,77 |
super.archive(trees, cutLinks); |
} |
public void regleFacture(SQLRow row) throws Exception { |
System.out.println("Génération des ecritures du reglement"); |
String s = row.getString("NOM"); |
SQLRow rowModeRegl = row.getForeignRow("ID_MODE_REGLEMENT"); |
SQLRow rowTypeRegl = rowModeRegl.getForeignRow("ID_TYPE_REGLEMENT"); |
// Compte Client |
SQLRow clientRow = row.getForeignRow("ID_CLIENT"); |
String label = "Règlement vente " + ((s == null) ? "" : s) + " (" + rowTypeRegl.getString("NOM") + ") " + StringUtils.limitLength(clientRow.getString("NOM"), 20); |
long montant = row.getLong("MONTANT"); |
PrixTTC ttc = new PrixTTC(montant); |
List<SQLRow> l = row.getReferentRows(row.getTable().getTable("ENCAISSER_MONTANT_ELEMENT")); |
if (l.isEmpty()) { |
SwingUtilities.invokeLater(new Runnable() { |
@Override |
public void run() { |
JOptionPane.showMessageDialog(null, "Un problème a été rencontré lors de l'encaissement! \n Les écritures comptables non pu être générer!"); |
} |
}); |
System.err.println("Liste des échéances vides pour l'encaissement ID " + row.getID()); |
Thread.dumpStack(); |
return; |
} |
new GenerationReglementVenteNG(label, clientRow, ttc, row.getDate("DATE").getTime(), rowModeRegl, row, l.get(0).getForeignRow("ID_MOUVEMENT_ECHEANCE"), false, false, row.getString("TIERS"), |
row.getForeign("ID_COMPTE_PCE_TIERS")); |
// Mise a jour du montant de l'echeance |
boolean supplement = false; |
if (!row.getBoolean("ACOMPTE")) { |
// On marque les echeances comme reglees |
for (SQLRow sqlRow : l) { |
final SQLRow rowEch = sqlRow.getForeignRow("ID_ECHEANCE_CLIENT"); |
SQLRowValues rowValsEch = rowEch.createEmptyUpdateRow(); |
if (sqlRow.getLong("MONTANT_REGLE") >= sqlRow.getLong("MONTANT_A_REGLER")) { |
rowValsEch.put("REGLE", Boolean.TRUE); |
if (sqlRow.getLong("MONTANT_REGLE") > sqlRow.getLong("MONTANT_A_REGLER")) { |
supplement = true; |
} |
} |
rowValsEch.put("MONTANT", Long.valueOf(rowEch.getLong("MONTANT") - sqlRow.getLong("MONTANT_REGLE"))); |
rowValsEch.update(); |
// this.comboEcheance.rowDeleted(tableEch, rowEch.getID()); |
// getTable().fireTableModified(rowEch.getID()); |
} |
} |
// si le montant réglé est supérieur, on crée une facture de complément |
if (supplement) { |
SQLElement elt = getDirectory().getElement("SAISIE_VENTE_FACTURE"); |
SwingUtilities.invokeLater(new Runnable() { |
@Override |
public void run() { |
EditFrame f = new EditFrame(elt, EditFrame.CREATION); |
SaisieVenteFactureSQLComponent comp = (SaisieVenteFactureSQLComponent) f.getSQLComponent(); |
comp.setComplement(true); |
f.setVisible(true); |
} |
}); |
} |
} |
@Override |
protected String createCodeSuffix() { |
return ".category"; |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/payment/element/ChequeAEncaisserSQLElement.java |
---|
100,9 → 100,13 |
l.add("DATE_VENTE"); |
l.add(getMinDateFieldName()); |
l.add("ID_CLIENT"); |
final ShowAs showAs = new ShowAs(getTable().getDBRoot()); |
if (getTable().contains("ID_BANQUE")) { |
l.add("ID_BANQUE"); |
showAs.show(getTable().getForeignTable("ID_BANQUE"), "NOM"); |
} |
l.add("MONTANT"); |
final ShowAs showAs = new ShowAs(getTable().getDBRoot()); |
final SQLTable mvtT = getTable().getForeignTable("ID_MOUVEMENT"); |
showAs.show(mvtT, "ID_PIECE"); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/payment/ui/ListeDesChequesAEncaisserPanel.java |
---|
18,6 → 18,7 |
import org.openconcerto.erp.rights.ComptaTotalUserRight; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowListRSH; |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.sqlobject.SQLRequestComboBox; |
import org.openconcerto.sql.users.rights.UserRightsManager; |
53,10 → 54,10 |
@Override |
protected JTextComponent createLabelText() { |
if (fieldLabel == null) { |
if (this.fieldLabel == null) { |
this.fieldLabel = new JTextField(); |
} |
return fieldLabel; |
return this.fieldLabel; |
} |
@Override |
66,18 → 67,16 |
@Override |
public void actionPerformed(ActionEvent e) { |
final String s = text.getText(); |
SQLRowValues rowValsDepot = new SQLRowValues(element.getTable().getTable("DEPOT_CHEQUE")); |
SQLRowValues rowValsDepot = new SQLRowValues(ListeDesChequesAEncaisserPanel.this.element.getTable().getTable("DEPOT_CHEQUE")); |
rowValsDepot.put("DATE", dateDepot.getValue()); |
rowValsDepot.put("NOM", fieldLabel.getText()); |
rowValsDepot.put("NOM", ListeDesChequesAEncaisserPanel.this.fieldLabel.getText()); |
final SQLRow selectedBanque = banqueSelect.getSelectedRow(); |
if (selectedBanque != null) { |
rowValsDepot.put("ID_" + selectedBanque.getTable().getName(), selectedBanque.getID()); |
} |
List<SQLRowValues> chq = getListe().getSelectedRows(); |
for (SQLRowValues sqlRowValues : chq) { |
SQLRow rowChq = sqlRowValues.asRow(); |
rowChq.fetchValues(); |
SQLRowValues rowValsDepotElt = new SQLRowValues(element.getTable().getTable("DEPOT_CHEQUE_ELEMENT")); |
final List<SQLRow> chq = SQLRowListRSH.fetch(getListe().getRequest().getPrimaryTable(), getListe().getSelection().getSelectedIDs()); |
for (SQLRow rowChq : chq) { |
SQLRowValues rowValsDepotElt = new SQLRowValues(ListeDesChequesAEncaisserPanel.this.element.getTable().getTable("DEPOT_CHEQUE_ELEMENT")); |
rowValsDepotElt.put("ID_DEPOT_CHEQUE", rowValsDepot); |
if (rowChq.getObject("ID_CLIENT") != null && !rowChq.isForeignEmpty("ID_CLIENT")) { |
rowValsDepotElt.put("ID_CLIENT", rowChq.getForeignID("ID_CLIENT")); |
96,7 → 95,7 |
rowValsDepotElt.put("NUMERO", (rowChq.getObject("NUMERO") == null ? "" : rowChq.getObject("NUMERO"))); |
rowValsDepotElt.put("MONTANT", rowChq.getObject("MONTANT")); |
} |
EditFrame frame = new EditFrame(element.getDirectory().getElement("DEPOT_CHEQUE"), EditMode.CREATION); |
EditFrame frame = new EditFrame(ListeDesChequesAEncaisserPanel.this.element.getDirectory().getElement("DEPOT_CHEQUE"), EditMode.CREATION); |
frame.getSQLComponent().select(rowValsDepot); |
frame.setVisible(true); |
text.setText(""); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/payment/component/EncaisserMontantSQLComponent.java |
---|
16,11 → 16,9 |
import org.openconcerto.erp.core.common.element.BanqueSQLElement; |
import org.openconcerto.erp.core.common.ui.DeviseField; |
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement; |
import org.openconcerto.erp.core.finance.payment.element.EncaisserMontantSQLElement; |
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement; |
import org.openconcerto.erp.core.finance.payment.ui.EncaisseMontantTable; |
import org.openconcerto.erp.core.sales.invoice.component.SaisieVenteFactureSQLComponent; |
import org.openconcerto.erp.generationEcritures.GenerationReglementVenteNG; |
import org.openconcerto.erp.model.PrixTTC; |
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.element.BaseSQLComponent; |
33,7 → 31,6 |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.sqlobject.ElementComboBox; |
import org.openconcerto.sql.view.EditFrame; |
import org.openconcerto.sql.view.list.RowValuesTableModel; |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import org.openconcerto.ui.JDate; |
41,7 → 38,6 |
import org.openconcerto.ui.warning.JLabelWarning; |
import org.openconcerto.utils.ExceptionHandler; |
import org.openconcerto.utils.GestionDevise; |
import org.openconcerto.utils.StringUtils; |
import org.openconcerto.utils.text.SimpleDocumentListener; |
import java.awt.GridBagConstraints; |
55,7 → 51,6 |
import javax.swing.JCheckBox; |
import javax.swing.JLabel; |
import javax.swing.JOptionPane; |
import javax.swing.JTextField; |
import javax.swing.SwingConstants; |
import javax.swing.event.DocumentEvent; |
183,7 → 178,6 |
this.addSQLObject(this.nom, "NOM"); |
this.addSQLObject(new ElementComboBox(), "ID_COMPTE_PCE_TIERS"); |
this.addSQLObject(new JTextField(), "TIERS"); |
DefaultGridBagConstraints.lockMinimumSize(this.montant); |
305,64 → 299,17 |
public int insert(SQLRow order) { |
int id = super.insert(order); |
try { |
this.table.updateField("ID_ENCAISSER_MONTANT", id); |
System.out.println("Génération des ecritures du reglement"); |
SQLRow row = getTable().getRow(id); |
String s = row.getString("NOM"); |
SQLRow rowModeRegl = row.getForeignRow("ID_MODE_REGLEMENT"); |
SQLRow rowTypeRegl = rowModeRegl.getForeignRow("ID_TYPE_REGLEMENT"); |
// Compte Client |
SQLRow clientRow = row.getForeignRow("ID_CLIENT"); |
String label = "Règlement vente " + ((s == null) ? "" : s) + " (" + rowTypeRegl.getString("NOM") + ") " + StringUtils.limitLength(clientRow.getString("NOM"), 20); |
long montant = row.getLong("MONTANT"); |
PrixTTC ttc = new PrixTTC(montant); |
List<SQLRow> l = row.getReferentRows(Configuration.getInstance().getDirectory().getElement("ENCAISSER_MONTANT_ELEMENT").getTable()); |
if (l.isEmpty()) { |
JOptionPane.showMessageDialog(null, "Un problème a été rencontré lors de l'encaissement! \n Les écritures comptables non pu être générer!"); |
System.err.println("Liste des échéances vides pour l'encaissement ID " + id); |
Thread.dumpStack(); |
try { |
((EncaisserMontantSQLElement) getElement()).regleFacture(row); |
} catch (Exception e) { |
ExceptionHandler.handle("Erreur de génération des écritures", e); |
} |
new GenerationReglementVenteNG(label, clientRow, ttc, row.getDate("DATE").getTime(), rowModeRegl, row, l.get(0).getForeignRow("ID_MOUVEMENT_ECHEANCE"), false, false, |
row.getString("TIERS"), row.getForeign("ID_COMPTE_PCE_TIERS")); |
// Mise a jour du montant de l'echeance |
boolean supplement = false; |
if (!row.getBoolean("ACOMPTE")) { |
// On marque les echeances comme reglees |
for (SQLRow sqlRow : l) { |
final SQLRow rowEch = sqlRow.getForeignRow("ID_ECHEANCE_CLIENT"); |
SQLRowValues rowValsEch = rowEch.createEmptyUpdateRow(); |
if (sqlRow.getLong("MONTANT_REGLE") >= sqlRow.getLong("MONTANT_A_REGLER")) { |
rowValsEch.put("REGLE", Boolean.TRUE); |
if (sqlRow.getLong("MONTANT_REGLE") > sqlRow.getLong("MONTANT_A_REGLER")) { |
supplement = true; |
} |
} |
rowValsEch.put("MONTANT", Long.valueOf(rowEch.getLong("MONTANT") - sqlRow.getLong("MONTANT_REGLE"))); |
rowValsEch.update(); |
// this.comboEcheance.rowDeleted(tableEch, rowEch.getID()); |
// getTable().fireTableModified(rowEch.getID()); |
} |
} |
// si le montant réglé est supérieur, on crée une facture de complément |
if (supplement) { |
SQLElement elt = Configuration.getInstance().getDirectory().getElement("SAISIE_VENTE_FACTURE"); |
EditFrame f = new EditFrame(elt, EditFrame.CREATION); |
SaisieVenteFactureSQLComponent comp = (SaisieVenteFactureSQLComponent) f.getSQLComponent(); |
comp.setComplement(true); |
f.setVisible(true); |
} |
} catch (Exception e) { |
ExceptionHandler.handle("Erreur lors de la génération des ecritures du reglement", e); |
} |
return id; |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/accounting/element/AssociationAnalytiqueSQLElement.java |
---|
16,6 → 16,8 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement; |
import org.openconcerto.sql.element.BaseSQLComponent; |
import org.openconcerto.sql.element.SQLComponent; |
import org.openconcerto.sql.element.SQLElementLink.LinkType; |
import org.openconcerto.sql.element.SQLElementLinksSetup; |
import org.openconcerto.sql.model.FieldPath; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.graph.Path; |
44,6 → 46,14 |
this.setAction("ID_SAISIE_KM_ELEMENT", ReferenceAction.CASCADE); |
} |
@Override |
protected void setupLinks(SQLElementLinksSetup links) { |
super.setupLinks(links); |
if (getTable().contains("ID_ECRITURE")) { |
links.get("ID_ECRITURE").setType(LinkType.ASSOCIATION); |
} |
} |
protected List<String> getListFields() { |
final List<String> list = new ArrayList<String>(2); |
list.add("ID_ECRITURE"); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/accounting/element/EcritureSQLElement.java |
---|
65,8 → 65,6 |
import java.awt.event.ActionEvent; |
import java.awt.event.KeyAdapter; |
import java.awt.event.KeyEvent; |
import java.awt.event.MouseAdapter; |
import java.awt.event.MouseEvent; |
import java.math.BigDecimal; |
import java.math.BigInteger; |
import java.sql.SQLException; |
80,7 → 78,6 |
import javax.swing.JFrame; |
import javax.swing.JLabel; |
import javax.swing.JOptionPane; |
import javax.swing.JPopupMenu; |
import javax.swing.JTextField; |
import javax.swing.SwingUtilities; |
153,6 → 150,11 |
return "ID_MOUVEMENT"; |
} |
@Override |
public boolean isPrivate() { |
return false; |
} |
// Impossible de modifier si validée |
// FIXME impossible de saisir une écriture avant la date de debut d'exercice --> de saisir de |
// document de gest comm |
196,67 → 198,9 |
} |
public void consultationCompte(SQLRowAccessor rowCpt) { |
final ConsultationCompteFrame f = new ConsultationCompteFrame(new ListeDesEcrituresPanel(), "Consultation compte n°" + rowCpt.getString("NUMERO") + " " + rowCpt.getString("NOM")); |
final ListeDesEcrituresPanel panel = new ListeDesEcrituresPanel(); |
final ConsultationCompteFrame f = new ConsultationCompteFrame(panel, rowCpt); |
f.getPanel().getListe().getJTable().addMouseListener(new MouseAdapter() { |
public void mousePressed(final MouseEvent mE) { |
if (mE.getButton() == MouseEvent.BUTTON3) { |
JPopupMenu menuDroit = new JPopupMenu(); |
menuDroit.add(new AbstractAction("Voir les ecritures du journal") { |
public void actionPerformed(ActionEvent e) { |
int id = f.getPanel().getListe().idFromIndex(f.getPanel().getListe().getJTable().rowAtPoint(mE.getPoint())); |
// int id = f.getPanel().getListe().getSelectedId(); |
SQLTable ecrTable = getTable().getTable("ECRITURE"); |
System.err.println("Ecritures ID ::: " + id); |
SQLRow rowEcr = ecrTable.getRow(id); |
System.err.println("Ecritures ID ::: " + id + " --> ID_JOURNAL = " + rowEcr.getInt("ID_JOURNAL")); |
ConsultationCompteFrame f2 = new ConsultationCompteFrame(new ListeDesEcrituresPanel(), |
"Consultation du journal " + getTable().getTable("JOURNAL").getRow(rowEcr.getInt("ID_JOURNAL")).getString("NOM")); |
Where w = new Where(ecrTable.getField("ID_JOURNAL"), "=", rowEcr.getInt("ID_JOURNAL")); |
f2.getPanel().getListe().getRequest().setWhere(w); |
f2.getPanel().getListe().setModificationAllowed(false); |
f2.pack(); |
f2.setVisible(true); |
} |
}); |
menuDroit.add(new AbstractAction("Voir la source") { |
public void actionPerformed(ActionEvent e) { |
// int id = f.getPanel().getListe().getSelectedId(); |
int id = f.getPanel().getListe().idFromIndex(f.getPanel().getListe().getJTable().rowAtPoint(mE.getPoint())); |
System.err.println("ID COMPTE SELECTED " + id); |
SQLRow rowEcr = getTable().getTable("ECRITURE").getRow(id); |
System.out.println("MOUVEMENT VALIDE ------------->>>>>>>>>>>>>> " + MouvementSQLElement.isEditable(rowEcr.getInt("ID_MOUVEMENT"))); |
MouvementSQLElement.showSource(rowEcr.getInt("ID_MOUVEMENT")); |
System.out.println("Mouvement Numero : " + rowEcr.getInt("ID_MOUVEMENT")); |
} |
}); |
menuDroit.show(mE.getComponent(), mE.getX(), mE.getY()); |
} |
} |
}); |
SQLTable ecrTable = getTable().getTable("ECRITURE"); |
Where w = new Where(ecrTable.getField("ID_COMPTE_PCE"), "=", rowCpt.getID()); |
f.getPanel().getListe().getRequest().setWhere(w); |
f.getPanel().getListe().setModificationAllowed(false); |
f.pack(); |
f.setVisible(true); |
696,7 → 640,9 |
// on archive le mouvement |
if (dropMvt) { |
SQLElement elt = Configuration.getInstance().getDirectory().getElement(tableMvt); |
SQLElement elt = getDirectory().getElement(tableMvt); |
try { |
elt.archive(idMvt); |
} catch (SQLException e) { |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/accounting/report/Map2033A.java |
---|
499,9 → 499,9 |
// 120 -SommeSolde( 100, 103* )-SommeSolde( 108, 109* ) |
// Racine = "101, 104, 108" |
// S120=-10...101-108-104 |
long v120 = -this.sommeCompte.sommeCompteFils("101", this.dateDebut, this.dateFin) - this.sommeCompte.sommeCompteFils("103", this.dateDebut, this.dateFin) |
- this.sommeCompte.sommeCompteFils("108", this.dateDebut, this.dateFin) - this.sommeCompte.sommeCompteFils("104", this.dateDebut, this.dateFin) |
+ this.sommeCompte.soldeCompteCrediteur(109, 109, true, this.dateDebut, this.dateFin); |
long v120 = -this.sommeCompte.sommeCompteFils("101", this.dateDebut, this.dateFin) - this.sommeCompte.sommeCompteFils("102", this.dateDebut, this.dateFin) |
- this.sommeCompte.sommeCompteFils("103", this.dateDebut, this.dateFin) - this.sommeCompte.sommeCompteFils("108", this.dateDebut, this.dateFin) |
- this.sommeCompte.sommeCompteFils("104", this.dateDebut, this.dateFin) + this.sommeCompte.soldeCompteCrediteur(109, 109, true, this.dateDebut, this.dateFin); |
this.m.put("PASSIF3.15", GestionDevise.currencyToString(v120, false)); |
// 121 |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/accounting/report/Map2033B.java |
---|
215,7 → 215,7 |
* VARIATION DE STOCK |
******************************************************************************************/ |
// 240 SommeSolde( 6030, 6036* ) |
long v240 = this.sommeCompte.soldeCompte(6031, 6032, true, this.dateDeb, this.dateFin); |
long v240 = this.sommeCompte.soldeCompte(6031, 6036, true, this.dateDeb, this.dateFin); |
this.m.put("CHARGES3.11", GestionDevise.currencyToString(v240, false)); |
// 213 |
264,7 → 264,7 |
******************************************************************************************/ |
// 250 SommeSolde( 640, 644* )+SommeSolde( 648, 649* ) |
long v250 = this.sommeCompte.soldeCompte(644, 644, true, this.dateDeb, this.dateFin) + this.sommeCompte.soldeCompte(648, 649, true, this.dateDeb, this.dateFin) |
+ this.sommeCompte.soldeCompte(641, 641, true, this.dateDeb, this.dateFin); |
+ this.sommeCompte.soldeCompte(641, 641, true, this.dateDeb, this.dateFin)+ this.sommeCompte.soldeCompte(642, 642, true, this.dateDeb, this.dateFin); |
this.m.put("CHARGES3.14", GestionDevise.currencyToString(v250, false)); |
// 220 |
352,7 → 352,7 |
* PRODUITS FINANCIERS |
******************************************************************************************/ |
// 280 -SommeSolde( 760, 769* )-SommeSolde( 786, 786* )-SommeSolde( 796, 796* ) |
long v280 = -this.sommeCompte.soldeCompte(761, 768, true, this.dateDeb, this.dateFin) - this.sommeCompte.soldeCompte(786, 786, true, this.dateDeb, this.dateFin) |
long v280 = -this.sommeCompte.soldeCompte(760, 768, true, this.dateDeb, this.dateFin) - this.sommeCompte.soldeCompte(786, 786, true, this.dateDeb, this.dateFin) |
- this.sommeCompte.soldeCompte(796, 796, true, this.dateDeb, this.dateFin); |
this.m.put("PCHARGES3.21", GestionDevise.currencyToString(v280, false)); |
369,7 → 369,7 |
* PRODUITS EXCEPTIONNELS |
******************************************************************************************/ |
// 290 -SommeSolde( 77, 77* )-SommeSolde( 787, 789* )-SommeSolde( 797, 799* ) |
long v290 = -this.sommeCompte.soldeCompte(771, 772, true, this.dateDeb, this.dateFin) - this.sommeCompte.soldeCompte(775, 778, true, this.dateDeb, this.dateFin) |
long v290 = -this.sommeCompte.soldeCompte(770, 772, true, this.dateDeb, this.dateFin) - this.sommeCompte.soldeCompte(775, 778, true, this.dateDeb, this.dateFin) |
- this.sommeCompte.soldeCompte(787, 787, true, this.dateDeb, this.dateFin) - this.sommeCompte.soldeCompte(797, 797, true, this.dateDeb, this.dateFin); |
this.m.put("PCHARGES3.22", GestionDevise.currencyToString(v290, false)); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/accounting/report/GrandLivreSheetXML.java |
---|
179,47 → 179,8 |
@Override |
public SQLSelect transformChecked(SQLSelect sel) { |
Where w = (new Where(tableEcriture.getField("DATE"), GrandLivreSheetXML.this.dateDu, GrandLivreSheetXML.this.dateAu)); |
Where w = getWhere(lCompteSolde); |
if (GrandLivreSheetXML.this.compteDeb.equals(GrandLivreSheetXML.this.compteEnd)) { |
w = w.and(new Where(tableEcriture.getField("COMPTE_NUMERO"), "=", GrandLivreSheetXML.this.compteDeb)); |
} else { |
w = w.and(new Where(tableEcriture.getField("COMPTE_NUMERO"), (Object) GrandLivreSheetXML.this.compteDeb, (Object) GrandLivreSheetXML.this.compteEnd)); |
} |
w = w.and(new Where(tableEcriture.getField("ID_JOURNAL"), "!=", idJrnlExclude)); |
w = w.and(new Where(tableEcriture.getField("ID_MOUVEMENT"), "=", tableMvt.getField("ID"))); |
if (GrandLivreSheetXML.this.lettrage == GrandLivreSheet.MODELETTREE) { |
Object o = null; |
w = w.and(new Where(tableEcriture.getField("LETTRAGE"), "<>", o)); |
w = w.and(new Where(tableEcriture.getField("LETTRAGE"), "!=", "")); |
w = w.and(new Where(tableEcriture.getField("DATE_LETTRAGE"), "<=", GrandLivreSheetXML.this.dateAu)); |
} else if (GrandLivreSheetXML.this.lettrage == GrandLivreSheet.MODENONLETTREE_PERIODE) { |
Object o = null; |
Where w2 = new Where(tableEcriture.getField("LETTRAGE"), "=", o); |
Where wSTTC = new Where(tableEcriture.getField("DATE_LETTRAGE"), "<>", o); |
wSTTC = wSTTC.and(new Where(tableEcriture.getField("DATE_LETTRAGE"), ">", GrandLivreSheetXML.this.dateAu)); |
w2 = w2.or(wSTTC); |
w = w.and(w2.or(new Where(tableEcriture.getField("LETTRAGE"), "=", ""))); |
} else if (GrandLivreSheetXML.this.lettrage == GrandLivreSheet.MODENONLETTREE_ALL) { |
Object o = null; |
Where w2 = new Where(tableEcriture.getField("LETTRAGE"), "=", o); |
w = w.and(w2.or(new Where(tableEcriture.getField("LETTRAGE"), "=", ""))); |
} |
if (GrandLivreSheetXML.this.excludeCompteSolde) { |
System.err.println("Exclude compte"); |
w = w.and(new Where(tableEcriture.getField("ID_COMPTE_PCE"), lCompteSolde).not()); |
} |
w = w.and(new Where(tableEcriture.getField("NOM"), "NOT LIKE", "Fermeture du compte%")); |
if (!UserRightsManager.getCurrentUserRights().haveRight(ComptaUserRight.ACCES_NOT_RESCTRICTED_TO_411)) { |
// TODO Show Restricted acces in UI |
w = w.and(new Where(tableEcriture.getField("COMPTE_NUMERO"), "LIKE", "411%")); |
} |
sel.setWhere(w); |
sel.addFieldOrder(tableEcriture.getField("COMPTE_NUMERO")); |
sel.addFieldOrder(tableEcriture.getField("DATE")); |
567,36 → 528,8 |
sel.addSelect(tableEcriture.getField("DEBIT"), "SUM"); |
sel.addSelect(tableEcriture.getField("CREDIT"), "SUM"); |
Where w; |
if (this.compteDeb.equals(this.compteEnd)) { |
w = new Where(tableCompte.getField("NUMERO"), "=", this.compteDeb); |
} else { |
w = new Where(tableCompte.getField("NUMERO"), (Object) this.compteDeb, (Object) this.compteEnd); |
} |
Where w = getWhere(null); |
w = w.and(new Where(tableEcriture.getField("ID_COMPTE_PCE"), "=", tableCompte.getField("ID"))); |
if (this.cumul) { |
w = w.and(new Where(tableEcriture.getField("DATE"), "<=", this.dateAu)); |
} else { |
w = w.and(new Where(tableEcriture.getField("DATE"), this.dateDu, this.dateAu)); |
} |
w = w.and(new Where(tableEcriture.getField("ID_JOURNAL"), "!=", idJrnlExclude)); |
if (this.lettrage == GrandLivreSheet.MODELETTREE) { |
Object o = null; |
w = w.and(new Where(tableEcriture.getField("LETTRAGE"), "<>", o)); |
w = w.and(new Where(tableEcriture.getField("LETTRAGE"), "!=", "")); |
} else if (this.lettrage == GrandLivreSheet.MODENONLETTREE_ALL) { |
Object o = null; |
Where w2 = new Where(tableEcriture.getField("LETTRAGE"), "=", o); |
w = w.and(w2.or(new Where(tableEcriture.getField("LETTRAGE"), "=", ""))); |
} else if (this.lettrage == GrandLivreSheet.MODENONLETTREE_PERIODE) { |
Object o = null; |
Where w2 = new Where(tableEcriture.getField("LETTRAGE"), "=", o); |
w = w.and(w2.or(new Where(tableEcriture.getField("LETTRAGE"), "=", ""))); |
} |
sel.setWhere(w); |
String req = sel.asString() + " GROUP BY \"COMPTE_PCE\".\"ID\""; |
623,6 → 556,52 |
return list; |
} |
private Where getWhere(final List<Integer> lCompteSolde) { |
Where w = (new Where(tableEcriture.getField("DATE"), GrandLivreSheetXML.this.dateDu, GrandLivreSheetXML.this.dateAu)); |
if (GrandLivreSheetXML.this.compteDeb.equals(GrandLivreSheetXML.this.compteEnd)) { |
w = w.and(new Where(tableEcriture.getField("COMPTE_NUMERO"), "=", GrandLivreSheetXML.this.compteDeb)); |
} else { |
w = w.and(new Where(tableEcriture.getField("COMPTE_NUMERO"), (Object) GrandLivreSheetXML.this.compteDeb, (Object) GrandLivreSheetXML.this.compteEnd)); |
} |
w = w.and(new Where(tableEcriture.getField("ID_JOURNAL"), "!=", idJrnlExclude)); |
w = w.and(new Where(tableEcriture.getField("ID_MOUVEMENT"), "=", tableMvt.getField("ID"))); |
if (GrandLivreSheetXML.this.lettrage == GrandLivreSheet.MODELETTREE) { |
Object o = null; |
w = w.and(new Where(tableEcriture.getField("LETTRAGE"), "<>", o)); |
w = w.and(new Where(tableEcriture.getField("LETTRAGE"), "!=", "")); |
w = w.and(new Where(tableEcriture.getField("DATE_LETTRAGE"), "<=", GrandLivreSheetXML.this.dateAu)); |
} else if (GrandLivreSheetXML.this.lettrage == GrandLivreSheet.MODENONLETTREE_PERIODE) { |
Object o = null; |
Where w2 = new Where(tableEcriture.getField("LETTRAGE"), "=", o); |
Where wSTTC = new Where(tableEcriture.getField("DATE_LETTRAGE"), "<>", o); |
wSTTC = wSTTC.and(new Where(tableEcriture.getField("DATE_LETTRAGE"), ">", GrandLivreSheetXML.this.dateAu)); |
w2 = w2.or(wSTTC); |
w = w.and(w2.or(new Where(tableEcriture.getField("LETTRAGE"), "=", ""))); |
} else if (GrandLivreSheetXML.this.lettrage == GrandLivreSheet.MODENONLETTREE_ALL) { |
Object o = null; |
Where w2 = new Where(tableEcriture.getField("LETTRAGE"), "=", o); |
w = w.and(w2.or(new Where(tableEcriture.getField("LETTRAGE"), "=", ""))); |
} |
if (GrandLivreSheetXML.this.excludeCompteSolde) { |
System.err.println("Exclude compte"); |
if (lCompteSolde != null) { |
w = w.and(new Where(tableEcriture.getField("ID_COMPTE_PCE"), lCompteSolde).not()); |
} |
} |
w = w.and(new Where(tableEcriture.getField("NOM"), "NOT LIKE", "Fermeture du compte%")); |
if (!UserRightsManager.getCurrentUserRights().haveRight(ComptaUserRight.ACCES_NOT_RESCTRICTED_TO_411)) { |
// TODO Show Restricted acces in UI |
w = w.and(new Where(tableEcriture.getField("COMPTE_NUMERO"), "LIKE", "411%")); |
} |
return w; |
} |
/** |
* @param d date limite des cumuls |
* @return Map<Integer id compte, Long solde(debit-credit)> |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/accounting/ui/ComptaPrefTreeNode.java |
---|
31,7 → 31,6 |
import org.openconcerto.erp.preferences.GestionCommercialeGlobalPreferencePanel; |
import org.openconcerto.erp.preferences.GestionPieceCommercialePanel; |
import org.openconcerto.erp.preferences.ImpressionGestCommPreferencePanel; |
import org.openconcerto.erp.preferences.MailRelancePreferencePanel; |
import org.openconcerto.erp.preferences.ModeReglementDefautPrefPanel; |
import org.openconcerto.erp.preferences.NumerotationPreferencePanel; |
import org.openconcerto.erp.preferences.PayPalPreferencePanel; |
119,7 → 118,6 |
nsGlobale.add(new PrefTreeNode(GenerationDocGlobalPreferencePanel.class, "Génération des Documents", new String[] { "documents" })); |
nsGlobale.add(new PrefTreeNode(GestionClientPreferencePanel.class, "Gestion des clients", new String[] { "client", "service" })); |
nsGlobale.add(new PrefTreeNode(GestionCommercialeGlobalPreferencePanel.class, "Gestion des piéces commericales", new String[] { "transfert", "numéro" })); |
nsGlobale.add(new PrefTreeNode(MailRelancePreferencePanel.class, "Email de relance", new String[] { "relance", "mail" })); |
// PayPal |
final PrefTreeNode nPayPall = new PrefTreeNode(PayPalPreferencePanel.class, "PayPal", new String[] { "paypal", "facture" }); |
162,7 → 160,6 |
final PrefTreeNode nMail = new PrefTreeNode(EmailNode.class, "EMail", new String[] { "email", "mail", "courriel" }); |
nsPoste.add(nMail); |
// add preferences for modules |
for (final AbstractModule module : moduleManager.getRunningModules().values()) { |
for (final Entry<Boolean, List<ModulePreferencePanelDesc>> e : module.getPrefDescriptorsByLocation(moduleManager.getRoot()).entrySet()) { |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/accounting/ui/SaisieKmItemTable.java |
---|
20,6 → 20,7 |
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement; |
import org.openconcerto.erp.preferences.DefaultNXProps; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.TM; |
import org.openconcerto.sql.element.SQLElement; |
import org.openconcerto.sql.model.SQLBase; |
import org.openconcerto.sql.model.SQLRow; |
38,13 → 39,16 |
import org.openconcerto.sql.view.list.TextTableCellEditorWithCompletion; |
import org.openconcerto.sql.view.list.ValidStateChecker; |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import org.openconcerto.ui.JComponentUtils; |
import org.openconcerto.utils.checks.ValidState; |
import java.awt.GridBagConstraints; |
import java.awt.GridBagLayout; |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionListener; |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseListener; |
import java.util.Arrays; |
import java.util.HashMap; |
import java.util.List; |
import java.util.Map; |
51,6 → 55,7 |
import java.util.Vector; |
import javax.swing.AbstractAction; |
import javax.swing.JButton; |
import javax.swing.JPanel; |
import javax.swing.JPopupMenu; |
import javax.swing.JScrollPane; |
143,7 → 148,7 |
@Override |
public ValidState getValidState(Object o) { |
if (o != null) { |
return elt.getCompteNumeroValidState(o.toString()); |
return this.elt.getCompteNumeroValidState(o.toString()); |
} |
return super.getValidState(o); |
} |
161,8 → 166,19 |
m2.setWhere(w); |
TextTableCellEditorWithCompletion t = (TextTableCellEditorWithCompletion) this.tableElementNumeroCompte.getTableCellEditor(this.table); |
JButton buttonClone = new JButton(TM.tr("duplicateLine")); |
buttonClone.addActionListener(new ActionListener() { |
public void actionPerformed(ActionEvent event) { |
cloneLine(table.getSelectedRow()); |
} |
}); |
buttonClone.setEnabled(false); |
c.gridx++; |
JComponentUtils.setMinimumWidth(buttonClone, 95); |
this.add(new RowValuesTableControlPanel(this.table), c); |
RowValuesTableControlPanel rowValuesTableControlPanel = new RowValuesTableControlPanel(this.table, Arrays.asList(buttonClone)); |
rowValuesTableControlPanel.setVisibleButtonClone(false); |
this.add(rowValuesTableControlPanel, c); |
c.gridy++; |
c.fill = GridBagConstraints.BOTH; |
222,6 → 238,29 |
} |
private void cloneLine(int row) { |
if (row < 0) { |
System.err.println("RowValuesTableControlPanel.cloneLine() wrong selected line, index = " + row); |
Thread.dumpStack(); |
return; |
} |
SQLRowValues rowVals = this.table.getRowValuesTableModel().getRowValuesAt(row); |
SQLRowValues rowValsBis = rowVals.deepCopy(); |
rowValsBis.clearPrimaryKeys(); |
rowValsBis.put(rowValsBis.getTable().getOrderField().getName(), null); |
this.table.getRowValuesTableModel().getSQLElement().clearPrivateFields(rowValsBis); |
rowValsBis.putEmptyLink("ID_ECRITURE"); |
for (String elt : this.table.getClearCloneTableElement()) { |
if (rowValsBis.getTable().getFieldsName().contains(elt)) { |
rowValsBis.putEmptyLink(elt); |
} |
} |
this.table.getRowValuesTableModel().addRow(rowValsBis); |
} |
/** |
* Remplit la RowValuesTable avec les ecritures du mouvement |
* |
334,11 → 373,11 |
assert SwingUtilities.isEventDispatchThread(); |
if (text == null) |
return; |
RowValuesTableModel model = table.getRowValuesTableModel(); |
RowValuesTableModel model = this.table.getRowValuesTableModel(); |
int size = model.getRowCount(); |
for (int i = 0; i < size; i++) { |
SQLRowValues r = model.getRowValuesAt(i); |
if (r.getString("NOM_ECRITURE") == null || r.getString("NOM_ECRITURE").trim().isEmpty() || r.getString("NOM_ECRITURE").trim().equals(previousText)) { |
if (r.getString("NOM_ECRITURE") == null || r.getString("NOM_ECRITURE").trim().isEmpty() || r.getString("NOM_ECRITURE").equals(previousText)) { |
r.put("NOM_ECRITURE", text); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/accounting/ui/ConsultationCompteFrame.java |
---|
15,20 → 15,32 |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.State; |
import org.openconcerto.sql.model.SQLBackgroundTableCache; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.model.Where; |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent; |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction; |
import org.openconcerto.ui.state.WindowStateManager; |
import java.awt.DisplayMode; |
import java.awt.GraphicsEnvironment; |
import java.awt.GridLayout; |
import java.awt.event.ActionEvent; |
import java.awt.event.ComponentAdapter; |
import java.awt.event.ComponentEvent; |
import java.io.File; |
import java.util.ArrayList; |
import java.util.Collections; |
import java.util.Comparator; |
import java.util.List; |
import javax.swing.AbstractAction; |
import javax.swing.JFrame; |
import javax.swing.event.TableModelEvent; |
import javax.swing.event.TableModelListener; |
public class ConsultationCompteFrame extends JFrame { |
// panel contenant la liste des ecritures |
private final ListPanelEcritures panelEcritures; |
37,12 → 49,13 |
private String titre; |
public ConsultationCompteFrame(ListeDesEcrituresPanel panel, String titre) { |
private int indexID; |
public ConsultationCompteFrame(ListeDesEcrituresPanel panel, SQLRowAccessor rowCpt) { |
super(); |
this.panel = panel; |
this.panelEcritures = panel.getListPanelEcritures(); |
this.titre = titre; |
this.titre = "Consultation compte n°" + rowCpt.getString("NUMERO") + " " + rowCpt.getString("NOM"); |
// rafraichir le titre à chaque changement de la liste |
this.panelEcritures.getListe().addListener(new TableModelListener() { |
public void tableChanged(TableModelEvent e) { |
63,8 → 76,74 |
} |
}); |
} |
SQLTable ecrTable = rowCpt.getTable().getTable("ECRITURE"); |
final int id = rowCpt.getID(); |
Where w = new Where(ecrTable.getField("ID_COMPTE_PCE"), "=", id); |
getPanel().getListe().getRequest().setWhere(w); |
final SQLTable cptTable = ecrTable.getForeignTable("ID_COMPTE_PCE"); |
List<SQLRow> rowsCpt = new ArrayList<SQLRow>(SQLBackgroundTableCache.getInstance().getCacheForTable(cptTable).getRows()); |
Collections.sort(rowsCpt, new Comparator<SQLRow>() { |
@Override |
public int compare(SQLRow o1, SQLRow o2) { |
return o1.getString("NUMERO").compareTo(o2.getString("NUMERO")); |
} |
}); |
final List<Integer> idsCpt = new ArrayList<>(); |
for (SQLRow sqlRow : rowsCpt) { |
idsCpt.add(sqlRow.getID()); |
} |
this.indexID = idsCpt.indexOf(rowCpt.getID()); |
final PredicateRowAction prec = new PredicateRowAction(new AbstractAction("Précédent") { |
@Override |
public void actionPerformed(ActionEvent e) { |
if (indexID > 0) { |
int newCptId = idsCpt.get(indexID - 1); |
Where w = new Where(ecrTable.getField("ID_COMPTE_PCE"), "=", newCptId); |
getPanel().getListe().getRequest().setWhere(w); |
SQLRow rowCptNew = SQLBackgroundTableCache.getInstance().getCacheForTable(cptTable).getRowFromId(newCptId); |
setTitle("Consultation compte n°" + rowCptNew.getString("NUMERO") + " " + rowCptNew.getString("NOM")); |
indexID--; |
} |
} |
}, true, false); |
prec.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE)); |
panel.getListPanelEcritures().getListe().addIListeAction(prec); |
final PredicateRowAction suivant = new PredicateRowAction(new AbstractAction("Suivant") { |
@Override |
public void actionPerformed(ActionEvent e) { |
if (indexID < idsCpt.size() - 1) { |
int newCptId = idsCpt.get(indexID + 1); |
Where w = new Where(ecrTable.getField("ID_COMPTE_PCE"), "=", newCptId); |
getPanel().getListe().getRequest().setWhere(w); |
SQLRow rowCptNew = SQLBackgroundTableCache.getInstance().getCacheForTable(cptTable).getRowFromId(newCptId); |
setTitle("Consultation compte n°" + rowCptNew.getString("NUMERO") + " " + rowCptNew.getString("NOM")); |
indexID++; |
} |
} |
}, true, false); |
suivant.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE)); |
panel.getListPanelEcritures().getListe().addIListeAction(suivant); |
} |
@Override |
public void setTitle(String title) { |
this.titre = title; |
super.setTitle(title); |
} |
private String getPlural(String s, int nb) { |
return nb + " " + s + (nb > 1 ? "s" : ""); |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/accounting/ui/ListeDesEcrituresPanel.java |
---|
13,6 → 13,10 |
package org.openconcerto.erp.core.finance.accounting.ui; |
import org.openconcerto.erp.config.ComptaPropsConfiguration; |
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.view.list.ITableModel; |
import org.openconcerto.ui.DefaultGridBagConstraints; |
22,6 → 26,7 |
import java.awt.GridBagConstraints; |
import java.awt.GridBagLayout; |
import java.awt.Insets; |
import java.util.Date; |
import javax.swing.BorderFactory; |
import javax.swing.JLabel; |
54,9 → 59,18 |
c.fill = GridBagConstraints.BOTH; |
this.add(this.panelEcritures, c); |
SQLRow rowExercice = Configuration.getInstance().getBase().getTable("EXERCICE_COMMON").getRow(ComptaPropsConfiguration.getInstanceCompta().getRowSociete().getInt("ID_EXERCICE_COMMON")); |
final IListFilterDatePanel comp = new IListFilterDatePanel(this.panelEcritures.getListe(), this.panelEcritures.getListe().getSource().getElem().getTable().getField("DATE"), |
IListFilterDatePanel.getDefaultMap()); |
comp.setDateDu((Date) rowExercice.getObject("DATE_DEB")); |
c.weightx = 1; |
c.gridy++; |
this.add(comp, c); |
/* Panel Legende */ |
c.gridwidth = 1; |
c.gridy = GridBagConstraints.RELATIVE; |
c.gridy++; |
this.panelLegende = new JPanel(); |
this.panelLegende.setLayout(new GridBagLayout()); |
this.panelLegende.setBorder(BorderFactory.createTitledBorder("Légende")); |
67,6 → 81,7 |
panelValide.add(new JLabel("Ecritures validées")); |
panelValide.setBackground(Color.WHITE); |
// panelValide.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
c.gridy++; |
this.panelLegende.add(panelValide, c); |
JPanel panelNonValide = new JPanel(); |
74,6 → 89,7 |
panelNonValide.add(new JLabel("Ecritures non validées")); |
panelNonValide.setBackground(ListEcritureRenderer.getCouleurEcritureNonValide()); |
// panelNonValide.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
c.gridy++; |
this.panelLegende.add(panelNonValide, c); |
JPanel panelNonValideToDay = new JPanel(); |
81,9 → 97,10 |
panelNonValideToDay.add(new JLabel("Ecritures non validées du jour")); |
panelNonValideToDay.setBackground(ListEcritureRenderer.getCouleurEcritureToDay()); |
// panelNonValideToDay.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
c.gridy++; |
this.panelLegende.add(panelNonValideToDay, c); |
c.gridy = 1; |
c.gridy = 2; |
c.weightx = 0; |
c.weighty = 0; |
c.insets = new Insets(2, 2, 1, 2); |
91,7 → 108,7 |
/* Panel Total */ |
c.gridx = 0; |
c.gridy = 0; |
// c.gridy = 0; |
this.panelTotal = new JPanel(); |
this.panelTotal.setLayout(new GridBagLayout()); |
this.panelTotal.setBorder(BorderFactory.createTitledBorder("Totaux")); |
125,7 → 142,7 |
c.gridx++; |
this.panelTotal.add(this.montantSolde, c); |
c.gridy = 1; |
c.gridy = 2; |
c.gridx = 1; |
c.weightx = 0; |
c.fill = GridBagConstraints.NONE; |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/accounting/ui/EcritureGrandLivreRenderer.java |
---|
40,23 → 40,16 |
} |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
TableCellRendererUtils.setBackgroundColor(this, table, isSelected); |
if (!isSelected) { |
Ecriture ecrTmp = ((ConsultCompteModel) this.model.getTableModel()).getEcritures().get(this.model.viewIndex(row)); |
if (!ecrTmp.getValide()) { |
// this.setForeground(couleurEcritureValide); |
Date dateEcr = ecrTmp.getDate(); |
Date dateToDay = new Date(); |
if ((dateEcr.getDate() == dateToDay.getDate()) && (dateEcr.getMonth() == dateToDay.getMonth()) && (dateEcr.getYear() == dateToDay.getYear())) { |
// System.out.println("ToDay :: " + dateToDay + " Ecr ::: " + dateEcr); |
this.setBackground(couleurEcritureToDay); |
} else { |
this.setBackground(couleurEcritureValide); |
63,14 → 56,13 |
} |
} |
} |
if (value != null) { |
if (value instanceof Date) { |
this.setText(dateFormat.format((Date) value)); |
} |
if (value.getClass() == Long.class) { |
} else if (value.getClass() == Long.class) { |
this.setText(GestionDevise.currencyToString(((Long) value).longValue())); |
} |
} |
return this; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/accounting/ui/SaisieJournalItemTable.java |
---|
21,6 → 21,7 |
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieKm; |
import org.openconcerto.erp.preferences.DefaultNXProps; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.TM; |
import org.openconcerto.sql.element.SQLElement; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowAccessor; |
36,6 → 37,7 |
import org.openconcerto.sql.view.list.TextTableCellEditorWithCompletion; |
import org.openconcerto.sql.view.list.ValidStateChecker; |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import org.openconcerto.ui.JComponentUtils; |
import org.openconcerto.ui.RangedIntegerTableCellEditor; |
import org.openconcerto.utils.DecimalUtils; |
import org.openconcerto.utils.GestionDevise; |
45,6 → 47,7 |
import java.awt.GridBagConstraints; |
import java.awt.GridBagLayout; |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionListener; |
import java.awt.event.KeyEvent; |
import java.awt.event.KeyListener; |
import java.awt.event.MouseEvent; |
54,6 → 57,7 |
import java.math.BigDecimal; |
import java.math.RoundingMode; |
import java.sql.SQLException; |
import java.util.Arrays; |
import java.util.Calendar; |
import java.util.Collection; |
import java.util.Date; |
62,6 → 66,7 |
import javax.swing.AbstractAction; |
import javax.swing.BorderFactory; |
import javax.swing.JButton; |
import javax.swing.JCheckBox; |
import javax.swing.JLabel; |
import javax.swing.JOptionPane; |
295,10 → 300,21 |
TextTableCellEditorWithCompletion t = (TextTableCellEditorWithCompletion) this.tableElementNumeroCompte.getTableCellEditor(this.table); |
this.controlPanel = new RowValuesTableControlPanel(this.table); |
controlPanel.setButtonAjouterEnabled(false); |
this.add(controlPanel, c); |
JButton buttonClone = new JButton(TM.tr("duplicateLine")); |
buttonClone.addActionListener(new ActionListener() { |
public void actionPerformed(ActionEvent event) { |
cloneLine(table.getSelectedRow()); |
} |
}); |
buttonClone.setEnabled(false); |
c.gridx++; |
JComponentUtils.setMinimumWidth(buttonClone, 95); |
this.controlPanel = new RowValuesTableControlPanel(this.table, Arrays.asList(buttonClone)); |
this.controlPanel.setVisibleButtonClone(false); |
this.controlPanel.setButtonAjouterEnabled(false); |
this.add(this.controlPanel, c); |
c.gridy++; |
c.fill = GridBagConstraints.BOTH; |
c.weightx = 1; |
688,4 → 704,26 |
public void mouseExited(final MouseEvent e) { |
} |
private void cloneLine(int row) { |
if (row < 0) { |
System.err.println("RowValuesTableControlPanel.cloneLine() wrong selected line, index = " + row); |
Thread.dumpStack(); |
return; |
} |
SQLRowValues rowVals = this.table.getRowValuesTableModel().getRowValuesAt(row); |
SQLRowValues rowValsBis = rowVals.deepCopy(); |
rowValsBis.clearPrimaryKeys(); |
rowValsBis.put(rowValsBis.getTable().getOrderField().getName(), null); |
this.table.getRowValuesTableModel().getSQLElement().clearPrivateFields(rowValsBis); |
rowValsBis.putEmptyLink("ID_ECRITURE"); |
for (String elt : this.table.getClearCloneTableElement()) { |
if (rowValsBis.getTable().getFieldsName().contains(elt)) { |
rowValsBis.putEmptyLink(elt); |
} |
} |
this.table.getRowValuesTableModel().addRow(rowValsBis); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/accounting/ui/CompteCloturePreferencePanel.java |
---|
133,7 → 133,7 |
this.rowPrefCompteVals.put("ID_COMPTE_PCE_BILAN_O", this.selCompteOuverture.getValue()); |
this.rowPrefCompteVals.put("ID_COMPTE_PCE_BILAN_F", this.selCompteFermeture.getValue()); |
this.rowPrefCompteVals.put("ID_COMPTE_PCE_RESULTAT", this.selCompteResultat.getValue()); |
this.rowPrefCompteVals.put("ID_COMPTE_PCE_RESULTAT_PERTE", this.selCompteResultat.getValue()); |
this.rowPrefCompteVals.put("ID_COMPTE_PCE_RESULTAT_PERTE", this.selCompteResultatPerte.getValue()); |
this.rowPrefCompteVals.put("ID_JOURNAL_AN", this.selJournal.getValue()); |
this.rowPrefCompteVals.put("CREATE_NUL_SOLDE_ECR", this.boxCompteSolde.isSelected()); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/finance/accounting/ui/CompteGestCommPreferencePanel.java |
---|
15,6 → 15,7 |
import org.openconcerto.erp.config.ComptaPropsConfiguration; |
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement; |
import org.openconcerto.erp.core.finance.accounting.element.JournalSQLElement; |
import org.openconcerto.erp.generationEcritures.GenerationMvtSaisieVenteFacture; |
import org.openconcerto.erp.model.ISQLCompteSelector; |
import org.openconcerto.erp.preferences.DefaultNXProps; |
45,7 → 46,7 |
private ISQLCompteSelector selCompteTVAIntraComm, selCompteFourn, selCompteAchat, selCompteValeurEncaissement, selCompteAvanceClient, selCompteClient, selCompteVenteProduits, |
selCompteVenteService, selCompteTVACol, selCompteTVADed, selCompteTVAImmo, selCompteAchatIntra, selCompteFactor, selComptePortSoumis, selComptePortNonSoumis; |
private ElementComboBox selJrnlFactor; |
private ElementComboBox selJrnlFactor, selJrnlValEnc; |
private final static SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete(); |
private static final SQLTable tablePrefCompte = base.getTable("PREFS_COMPTE"); |
private SQLRowValues rowPrefCompteVals = new SQLRowValues(tablePrefCompte); |
174,6 → 175,17 |
this.selCompteValeurEncaissement.init(); |
this.add(this.selCompteValeurEncaissement, c); |
// Journal |
c.gridy++; |
c.weightx = 0; |
c.gridx = 0; |
this.add(new JLabel("Journal dépôt chèque"), c); |
c.weightx = 1; |
c.gridx++; |
this.selJrnlValEnc = new ElementComboBox(); |
this.selJrnlValEnc.init(Configuration.getInstance().getDirectory().getElement("JOURNAL")); |
this.add(this.selJrnlValEnc, c); |
// Compte vente produits |
c.gridy++; |
c.weightx = 0; |
325,6 → 337,10 |
this.rowPrefCompteVals.put("ID_COMPTE_PCE_FACTOR", this.selCompteFactor.getValue()); |
final int selectedId = this.selJrnlFactor.getSelectedId(); |
this.rowPrefCompteVals.put("ID_JOURNAL_FACTOR", (selectedId > 1) ? selectedId : 1); |
final int selectedIdEnc = this.selJrnlValEnc.getSelectedId(); |
this.rowPrefCompteVals.put("ID_JOURNAL_VALEUR_ENCAISSEMENT", (selectedIdEnc > 1) ? selectedIdEnc : 1); |
this.rowPrefCompteVals.put("ID_COMPTE_PCE_FOURNISSEUR", this.selCompteFourn.getValue()); |
this.rowPrefCompteVals.put("ID_COMPTE_PCE_CLIENT", this.selCompteClient.getValue()); |
this.rowPrefCompteVals.put("ID_COMPTE_PCE_AVANCE_CLIENT", this.selCompteAvanceClient.getValue()); |
388,6 → 404,7 |
this.selCompteFactor.setValue(value); |
this.selJrnlFactor.setValue(GenerationMvtSaisieVenteFacture.journal); |
this.selJrnlValEnc.setValue(JournalSQLElement.BANQUES); |
// Fournisseurs |
compte = ComptePCESQLElement.getComptePceDefault("Fournisseurs"); |
455,14 → 472,22 |
setComboValues(selCompteVenteService, "ID_COMPTE_PCE_VENTE_SERVICE", "VentesServices"); |
setComboValues(selCompteFactor, "ID_COMPTE_PCE_FACTOR", "Factor"); |
{ |
// Journal Factor |
int value = (this.rowPrefCompteVals.getObject("ID_JOURNAL_FACTOR") == null ? 1 : this.rowPrefCompteVals.getInt("ID_JOURNAL_FACTOR")); |
if (value <= 1) { |
value = GenerationMvtSaisieVenteFacture.journal; |
} |
this.selJrnlFactor.setValue(value); |
} |
{ |
// Journal Val enc |
int value = (this.rowPrefCompteVals.getObject("ID_JOURNAL_VALEUR_ENCAISSEMENT") == null ? 1 : this.rowPrefCompteVals.getInt("ID_JOURNAL_VALEUR_ENCAISSEMENT")); |
if (value <= 1) { |
value = JournalSQLElement.BANQUES; |
} |
this.selJrnlValEnc.setValue(value); |
} |
setComboValues(selCompteFourn, "ID_COMPTE_PCE_FOURNISSEUR", "Fournisseurs"); |
setComboValues(selCompteClient, "ID_COMPTE_PCE_CLIENT", "Clients"); |
setComboValues(selCompteAvanceClient, "ID_COMPTE_PCE_AVANCE_CLIENT", "AvanceClients"); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/humanresources/employe/element/EtatCivilSQLElement.java |
---|
293,7 → 293,7 |
c.gridwidth = 1; |
c.weightx = 1; |
JTextField fieldNTT = new JTextField(); |
panelSituation.add(fieldCNPS, c); |
panelSituation.add(fieldNTT, c); |
c.weightx = 0; |
c.gridwidth = 1; |
addView(fieldNTT, "NTT"); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/humanresources/payroll/ui/EditionFichePayePanel.java |
---|
165,7 → 165,7 |
@Override |
public void propertyChange(PropertyChangeEvent evt) { |
buttonValid.setEnabled(dateDeb.getValue() != null && dateFin.getValue() != null && dateDeb.getValue().before(dateFin.getValue())); |
buttonValid.setEnabled(dateDeb.getValue() != null && dateFin.getValue() != null && dateDeb.getValue().compareTo(dateFin.getValue()) <= 0); |
model.setDateLimit(dateDeb.getValue()); |
} |
}; |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/humanresources/payroll/element/ReglementPayeSQLElement.java |
---|
97,7 → 97,7 |
JLabel labelNomBq = new JLabel(getLabelFor("NOM_BANQUE")); |
labelNomBq.setHorizontalAlignment(SwingConstants.RIGHT); |
SQLTextCombo textNomBq = new SQLTextCombo(); |
c.weightx = 0; |
panelBanque.add(labelNomBq, c); |
c.gridx++; |
c.weightx = 1; |
104,6 → 104,32 |
panelBanque.add(textNomBq, c); |
c.weightx = 0; |
// IBAN |
JLabel labelIBAN = new JLabel(getLabelFor("IBAN")); |
labelIBAN.setHorizontalAlignment(SwingConstants.RIGHT); |
JTextField textIBAN = new JTextField(); |
c.gridy++; |
c.gridx = 0; |
c.weightx = 0; |
panelBanque.add(labelIBAN, c); |
c.gridx++; |
c.weightx = 1; |
panelBanque.add(textIBAN, c); |
// BIC |
JLabel labelBIC = new JLabel(getLabelFor("BIC")); |
labelBIC.setHorizontalAlignment(SwingConstants.RIGHT); |
JTextField textBIC = new JTextField(); |
c.gridy++; |
c.gridx = 0; |
c.weightx = 0; |
panelBanque.add(labelBIC, c); |
c.gridx++; |
c.weightx = 1; |
panelBanque.add(textBIC, c); |
// RIB |
JLabel labelRIB = new JLabel(getLabelFor("RIB")); |
labelRIB.setHorizontalAlignment(SwingConstants.RIGHT); |
153,11 → 179,13 |
c.gridy++; |
panelReglement.add(radioLe, c); |
c.gridx++; |
c.weightx = 1; |
panelReglement.add(textLe, c); |
textLe.setText("31"); |
c.gridx++; |
c.weightx = 0; |
panelReglement.add(labelDu, c); |
c.weightx = 1; |
panelReglement.add(labelDu, c); |
c.gridy++; |
c.gridx = 0; |
210,6 → 238,7 |
c.gridx = 0; |
c.gridy = 0; |
c.gridwidth = 1; |
c.weightx = 0; |
panelCompta.add(labelCompteSal, c); |
c.gridx++; |
c.weightx = 1; |
225,6 → 254,8 |
this.addSQLObject(textNomBq, "NOM_BANQUE"); |
this.addSQLObject(textRIB, "RIB"); |
this.addSQLObject(textIBAN, "IBAN"); |
this.addSQLObject(textBIC, "BIC"); |
this.addRequiredSQLObject(typeRegl, "ID_MODE_REGLEMENT_PAYE"); |
this.addRequiredSQLObject(textLe, "LE"); |
this.addRequiredSQLObject(compteSal, "ID_COMPTE_PCE"); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/humanresources/payroll/element/ContratSalarieSQLElement.java |
---|
113,6 → 113,20 |
c.weightx = 1; |
this.add(selCodeCatSocio, c); |
JLabel complPCSLabel = new JLabel(getLabelFor("COMPLEMENT_PCS")); |
complPCSLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
JTextField complPCS = new JTextField(); |
c.gridy++; |
c.gridx = 0; |
c.weightx = 0; |
this.add(complPCSLabel, c); |
c.gridx++; |
c.weightx = 1; |
this.add(complPCS, c); |
addView(complPCS,"COMPLEMENT_PCS"); |
// Contrat de travail |
JLabel labelContratTravail = new JLabel(getLabelFor("ID_CODE_CONTRAT_TRAVAIL")); |
labelContratTravail.setHorizontalAlignment(SwingConstants.RIGHT); |
225,87 → 239,91 |
this.add(selFF, c); |
this.addSQLObject(selFF, "ID_CONTRAT_MOTIF_RECOURS"); |
// Code Arrco, agirc retirés du contrat et ajoutés dans les caisses de cotisations |
// Code UGRR |
JLabel labelCodeUGRR = new JLabel(getLabelFor("CODE_IRC_UGRR")); |
labelCodeUGRR.setHorizontalAlignment(SwingConstants.RIGHT); |
JTextField textCodeUGRR = new JTextField(); |
c.gridy++; |
c.gridx = 0; |
c.weightx = 0; |
this.add(labelCodeUGRR, c); |
c.gridx++; |
c.weighty = 1; |
c.weightx = 1; |
this.add(textCodeUGRR, c); |
addView(textCodeUGRR, "CODE_IRC_UGRR"); |
JLabel labelNumUGRR = new JLabel(getLabelFor("NUMERO_RATTACHEMENT_UGRR")); |
labelNumUGRR.setHorizontalAlignment(SwingConstants.RIGHT); |
JTextField textNumUGRR = new JTextField(); |
c.gridy++; |
c.gridx = 0; |
c.weightx = 0; |
this.add(labelNumUGRR, c); |
c.gridx++; |
c.weighty = 1; |
c.weightx = 1; |
this.add(textNumUGRR, c); |
addView(textNumUGRR, "NUMERO_RATTACHEMENT_UGRR"); |
// JLabel labelCodeUGRR = new JLabel(getLabelFor("CODE_IRC_UGRR")); |
// labelCodeUGRR.setHorizontalAlignment(SwingConstants.RIGHT); |
// JTextField textCodeUGRR = new JTextField(); |
// c.gridy++; |
// c.gridx = 0; |
// c.weightx = 0; |
// this.add(labelCodeUGRR, c); |
// c.gridx++; |
// c.weighty = 1; |
// c.weightx = 1; |
// this.add(textCodeUGRR, c); |
// addView(textCodeUGRR, "CODE_IRC_UGRR"); |
// |
// JLabel labelNumUGRR = new JLabel(getLabelFor("NUMERO_RATTACHEMENT_UGRR")); |
// labelNumUGRR.setHorizontalAlignment(SwingConstants.RIGHT); |
// JTextField textNumUGRR = new JTextField(); |
// c.gridy++; |
// c.gridx = 0; |
// c.weightx = 0; |
// this.add(labelNumUGRR, c); |
// c.gridx++; |
// c.weighty = 1; |
// c.weightx = 1; |
// this.add(textNumUGRR, c); |
// addView(textNumUGRR, "NUMERO_RATTACHEMENT_UGRR"); |
// |
// // Code UGRC |
// JLabel labelCodeUGRC = new JLabel(getLabelFor("CODE_IRC_UGRC")); |
// labelCodeUGRC.setHorizontalAlignment(SwingConstants.RIGHT); |
// JTextField textCodeUGRC = new JTextField(); |
// c.gridy++; |
// c.gridx = 0; |
// c.weightx = 0; |
// this.add(labelCodeUGRC, c); |
// c.gridx++; |
// c.weighty = 1; |
// c.weightx = 1; |
// this.add(textCodeUGRC, c); |
// addView(textCodeUGRC, "CODE_IRC_UGRC"); |
// |
// JLabel labelNumUGRC = new JLabel(getLabelFor("NUMERO_RATTACHEMENT_UGRC")); |
// labelNumUGRC.setHorizontalAlignment(SwingConstants.RIGHT); |
// JTextField textNumUGRC = new JTextField(); |
// c.gridy++; |
// c.gridx = 0; |
// c.weightx = 0; |
// this.add(labelNumUGRC, c); |
// c.gridx++; |
// c.weighty = 1; |
// c.weightx = 1; |
// this.add(textNumUGRC, c); |
// addView(textNumUGRC, "NUMERO_RATTACHEMENT_UGRC"); |
// |
// // Retraite |
// JLabel labelCodeRetraite = new JLabel(getLabelFor("CODE_IRC_RETRAITE")); |
// labelCodeRetraite.setHorizontalAlignment(SwingConstants.RIGHT); |
// JTextField textCodeRetraite = new JTextField(); |
// c.gridy++; |
// c.gridx = 0; |
// c.weightx = 0; |
// this.add(labelCodeRetraite, c); |
// c.gridx++; |
// c.weighty = 1; |
// c.weightx = 1; |
// this.add(textCodeRetraite, c); |
// addView(textCodeRetraite, "CODE_IRC_RETRAITE"); |
// |
// JLabel labelNumRetraite = new |
// JLabel(getLabelFor("NUMERO_RATTACHEMENT_RETRAITE")); |
// labelNumRetraite.setHorizontalAlignment(SwingConstants.RIGHT); |
// JTextField textNumRetraite = new JTextField(); |
// c.gridy++; |
// c.gridx = 0; |
// c.weightx = 0; |
// this.add(labelNumRetraite, c); |
// c.gridx++; |
// c.weighty = 1; |
// c.weightx = 1; |
// this.add(textNumRetraite, c); |
// addView(textNumRetraite, "NUMERO_RATTACHEMENT_RETRAITE"); |
// Code UGRC |
JLabel labelCodeUGRC = new JLabel(getLabelFor("CODE_IRC_UGRC")); |
labelCodeUGRC.setHorizontalAlignment(SwingConstants.RIGHT); |
JTextField textCodeUGRC = new JTextField(); |
c.gridy++; |
c.gridx = 0; |
c.weightx = 0; |
this.add(labelCodeUGRC, c); |
c.gridx++; |
c.weighty = 1; |
c.weightx = 1; |
this.add(textCodeUGRC, c); |
addView(textCodeUGRC, "CODE_IRC_UGRC"); |
JLabel labelNumUGRC = new JLabel(getLabelFor("NUMERO_RATTACHEMENT_UGRC")); |
labelNumUGRC.setHorizontalAlignment(SwingConstants.RIGHT); |
JTextField textNumUGRC = new JTextField(); |
c.gridy++; |
c.gridx = 0; |
c.weightx = 0; |
this.add(labelNumUGRC, c); |
c.gridx++; |
c.weighty = 1; |
c.weightx = 1; |
this.add(textNumUGRC, c); |
addView(textNumUGRC, "NUMERO_RATTACHEMENT_UGRC"); |
// Retraite |
JLabel labelCodeRetraite = new JLabel(getLabelFor("CODE_IRC_RETRAITE")); |
labelCodeRetraite.setHorizontalAlignment(SwingConstants.RIGHT); |
JTextField textCodeRetraite = new JTextField(); |
c.gridy++; |
c.gridx = 0; |
c.weightx = 0; |
this.add(labelCodeRetraite, c); |
c.gridx++; |
c.weighty = 1; |
c.weightx = 1; |
this.add(textCodeRetraite, c); |
addView(textCodeRetraite, "CODE_IRC_RETRAITE"); |
JLabel labelNumRetraite = new JLabel(getLabelFor("NUMERO_RATTACHEMENT_RETRAITE")); |
labelNumRetraite.setHorizontalAlignment(SwingConstants.RIGHT); |
JTextField textNumRetraite = new JTextField(); |
c.gridy++; |
c.gridx = 0; |
c.weightx = 0; |
this.add(labelNumRetraite, c); |
c.gridx++; |
c.weighty = 1; |
c.weightx = 1; |
this.add(textNumRetraite, c); |
addView(textNumRetraite, "NUMERO_RATTACHEMENT_RETRAITE"); |
// JLabel labelCodeRegimeRetraite = new |
// JLabel(getLabelFor("CODE_REGIME_RETRAITE_DSN")); |
// labelCodeRegimeRetraite.setHorizontalAlignment(SwingConstants.RIGHT); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/humanresources/payroll/element/InfosSalariePayeSQLElement.java |
---|
442,6 → 442,19 |
panelBase.add(sectionAT, c); |
addView(sectionAT, "CODE_SECTION_AT"); |
if (getTable().contains("DUREE_FORFAIT")) { |
JLabel labelForfait = new JLabel(getLabelFor("DUREE_FORFAIT")); |
labelForfait.setHorizontalAlignment(SwingConstants.RIGHT); |
JTextField forfait = new JTextField(); |
c.gridx++; |
c.weightx = 0; |
panelBase.add(labelForfait, c); |
c.gridx++; |
c.weightx = 1; |
panelBase.add(forfait, c); |
addView(forfait, "DUREE_FORFAIT"); |
} |
c.gridy = 5; |
c.gridx = 0; |
c.gridwidth = GridBagConstraints.REMAINDER; |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/humanresources/payroll/element/SalarieSQLElement.java |
---|
15,6 → 15,7 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement; |
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement; |
import org.openconcerto.erp.core.customerrelationship.customer.element.ContactItemTable; |
import org.openconcerto.erp.core.edm.AttachmentAction; |
import org.openconcerto.sql.element.BaseSQLComponent; |
import org.openconcerto.sql.element.ElementSQLObject; |
25,15 → 26,17 |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.model.SQLSelect; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.model.UndefinedRowValuesCache; |
import org.openconcerto.sql.model.Where; |
import org.openconcerto.sql.sqlobject.ElementComboBox; |
import org.openconcerto.sql.view.EditFrame; |
import org.openconcerto.sql.view.EditPanel.EditMode; |
import org.openconcerto.sql.view.EditPanelListener; |
import org.openconcerto.sql.view.EditPanel.EditMode; |
import org.openconcerto.sql.view.list.IListe; |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent; |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction; |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import org.openconcerto.ui.FormLayouter; |
import org.openconcerto.ui.FrameUtil; |
import org.openconcerto.ui.warning.JLabelWarning; |
import org.openconcerto.utils.checks.ValidState; |
46,9 → 49,11 |
import java.util.ArrayList; |
import java.util.Date; |
import java.util.List; |
import java.util.Map; |
import javax.swing.AbstractAction; |
import javax.swing.BorderFactory; |
import javax.swing.JComponent; |
import javax.swing.JLabel; |
import javax.swing.JOptionPane; |
import javax.swing.JPanel; |
94,6 → 99,7 |
try { |
rowInfosAncien.createEmptyUpdateRow().put("ID_SALARIE", rowSelected.getID()).commit(); |
rowSelected.createEmptyUpdateRow().put("ID_INFOS_SALARIE_PAYE", id).commit(); |
infosPayeElement.getTable().getRow(id).createEmptyUpdateRow().put("ID_SALARIE", rowSelected.getID()).commit(); |
} catch (SQLException e) { |
e.printStackTrace(); |
} |
141,7 → 147,7 |
return new BaseSQLComponent(this) { |
private final JLabel warningCodeSalLabel = new JLabelWarning(); |
private final JTextField textCode = new JTextField(); |
ContactItemTable tableContact = new ContactItemTable(UndefinedRowValuesCache.getInstance().getDefaultRowValues(getTable().getTable("CONTACT_SALARIE"))); |
private JTabbedPane tabbedPane; |
private final SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO"); |
206,6 → 212,18 |
} |
}); |
// User |
final JLabel labelUser = new JLabel(getLabelFor("ID_USER_COMMON")); |
final ElementComboBox comboUser = new ElementComboBox(false, 50); |
c.gridx = 0; |
c.gridy++; |
this.add(labelUser, c); |
c.gridx++; |
c.weightx = 0; |
c.fill = GridBagConstraints.NONE; |
this.add(comboUser, c); |
this.addView(comboUser, "ID_USER_COMMON"); |
/*********************************************************************************** |
* TABBED PANE |
**********************************************************************************/ |
218,6 → 236,18 |
scrollEtatCivil.setBorder(null); |
this.tabbedPane.add("Etat Civil", scrollEtatCivil); |
// Contact |
JPanel panelContact = new JPanel(new GridBagLayout()); |
DefaultGridBagConstraints cContact = new DefaultGridBagConstraints(); |
cContact.weighty = 1; |
cContact.weightx = 1; |
cContact.fill = GridBagConstraints.BOTH; |
panelContact.add(tableContact, cContact); |
JScrollPane scrollContact = new JScrollPane(panelContact); |
scrollContact.setBorder(null); |
this.tabbedPane.add("Contacts", scrollContact); |
// Règlement de la paye |
this.addView("ID_REGLEMENT_PAYE", REQ + ";" + DEC + ";" + SEP); |
ElementSQLObject eltReglPaye = (ElementSQLObject) this.getView("ID_REGLEMENT_PAYE"); |
286,7 → 316,18 |
this.tabbedPane.add("Cumuls et variables de la période", new JScrollPane(panelAllCumul)); |
// this.tabbedPane.setEnabledAt(this.tabbedPane.getTabCount() - 1, false); |
Map<String, JComponent> additionalFields = getElement().getAdditionalFields(); |
if (additionalFields != null && additionalFields.size() > 0) { |
// Champ Module |
c.gridx = 0; |
c.gridy++; |
c.gridwidth = GridBagConstraints.REMAINDER; |
final JPanel addP = ComptaSQLConfElement.createAdditionalPanel(); |
this.setAdditionalFieldsPanel(new FormLayouter(addP, 2)); |
this.tabbedPane.add("Compléments", new JScrollPane(addP)); |
} |
c.gridy++; |
c.gridx = 0; |
c.weighty = 1; |
c.gridwidth = GridBagConstraints.REMAINDER; |
335,15 → 376,19 |
* } |
*/ |
checkCode(); |
if (r != null) { |
this.tableContact.insertFrom("ID_SALARIE", r.asRowValues()); |
} |
} |
public void update() { |
super.update(); |
SQLTable tableFichePaye = getTable().getBase().getTable("FICHE_PAYE"); |
SQLRowValues rowVals = new SQLRowValues(tableFichePaye); |
rowVals.put("ID_SALARIE", getSelectedID()); |
rowVals.put("ID_SALARIE", |
getSelectedID()); |
SQLRow row = getTable().getRow(getSelectedID()); |
try { |
rowVals.update(row.getInt("ID_FICHE_PAYE")); |
350,6 → 395,7 |
} catch (SQLException e) { |
e.printStackTrace(); |
} |
this.tableContact.updateField("ID_SALARIE", getSelectedID()); |
} |
public int insert(SQLRow order) { |
387,9 → 433,10 |
e.printStackTrace(); |
} |
} |
this.tableContact.updateField("ID_SALARIE", id); |
return id; |
} |
}; |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/humanresources/payroll/report/FichePayeSheetXML.java |
---|
198,10 → 198,36 |
ligneSimplifiee.put("MONTANT_SAL_DED", montantSalBulletinSimpl.add(montantSalLigne)); |
ligneSimplifiee.put("MONTANT_PAT", montantPatBulletinSimpl.add(montantPatLigne)); |
} |
BigDecimal tauxPatBulletinSimpl = BigDecimal.ZERO; |
BigDecimal tauxSalBulletinSimpl = BigDecimal.ZERO; |
if (ligneSimplifiee.getBigDecimal("TAUX_SAL") != null) { |
tauxSalBulletinSimpl = ligneSimplifiee.getBigDecimal("TAUX_SAL"); |
} |
if (ligneSimplifiee.getBigDecimal("TAUX_PAT") != null) { |
tauxPatBulletinSimpl = ligneSimplifiee.getBigDecimal("TAUX_PAT"); |
} |
BigDecimal tauxPatLigne = BigDecimal.ZERO; |
BigDecimal tauxSalLigne = BigDecimal.ZERO; |
if (sqlRowAccessor.getBigDecimal("TAUX_SAL") != null) { |
tauxSalLigne = sqlRowAccessor.getBigDecimal("TAUX_SAL"); |
} |
if (sqlRowAccessor.getBigDecimal("TAUX_PAT") != null) { |
tauxPatLigne = sqlRowAccessor.getBigDecimal("TAUX_PAT"); |
} |
if (tauxSalLigne.signum() > 0) { |
ligneSimplifiee.put("TAUX_SAL", tauxSalBulletinSimpl.add(tauxSalLigne)); |
} |
if (tauxPatLigne.signum() > 0) { |
ligneSimplifiee.put("TAUX_PAT", tauxPatBulletinSimpl.add(tauxPatLigne)); |
} |
} |
} |
} |
private StyleSQLElement eltStyle = Configuration.getInstance().getDirectory().getElement(StyleSQLElement.class); |
private Map<String, SQLRowValues> initCotisations(boolean cadre, List<SQLRowAccessor> resultCotis) { |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/credit/component/AvoirClientSQLComponent.java |
---|
27,6 → 27,7 |
import org.openconcerto.erp.core.common.ui.TotalPanel; |
import org.openconcerto.erp.core.customerrelationship.customer.ui.AddressChoiceUI; |
import org.openconcerto.erp.core.customerrelationship.customer.ui.AdresseType; |
import org.openconcerto.erp.core.customerrelationship.customer.ui.CategorieComptableChoiceUI; |
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement; |
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement; |
import org.openconcerto.erp.core.finance.payment.component.ModeDeReglementSQLComponent; |
193,6 → 194,9 |
boxTarif.setValue(foreignRow.getID()); |
} |
} |
if (!isFilling()) { |
AvoirClientSQLComponent.this.table.setClient(row, true); |
} |
} else { |
table.setRowCatComptable(null); |
423,7 → 427,25 |
} |
}); |
} |
if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.CATEGORIE_COMPTABLE_SPEC, false)) { |
// cat spe |
final CategorieComptableChoiceUI catUI = new CategorieComptableChoiceUI(); |
catUI.addToUI(this, c); |
catUI.getCombo().addModelListener("wantedID", new PropertyChangeListener() { |
@Override |
public void propertyChange(PropertyChangeEvent evt) { |
int wantedID = catUI.getCombo().getWantedID(); |
if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) { |
table.setRowCatComptable(catUI.getCombo().getElement().getTable().getRow(wantedID)); |
} else { |
table.setRowCatComptable(null); |
} |
} |
}); |
} |
final ComptaPropsConfiguration comptaPropsConfiguration = ((ComptaPropsConfiguration) Configuration.getInstance()); |
// Contact |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/order/element/CommandeClientElementSQLElement.java |
---|
16,11 → 16,11 |
import org.openconcerto.erp.config.ComptaPropsConfiguration; |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement; |
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement; |
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement; |
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement; |
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater; |
import org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater.TypeStockUpdate; |
import org.openconcerto.erp.core.supplychain.stock.element.StockLabel; |
import org.openconcerto.erp.core.supplychain.stock.element.StockSQLElement; |
import org.openconcerto.sql.element.SQLComponent; |
import org.openconcerto.sql.element.SQLElement; |
import org.openconcerto.sql.element.UISQLComponent; |
66,16 → 66,9 |
@Override |
public void actionPerformed(ActionEvent e) { |
final List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows(); |
ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() { |
@Override |
public void run() { |
createCommandeF(selectedRows); |
final List<SQLRow> rows = SQLRowListRSH.fetch(IListe.get(e).getRequest().getPrimaryTable(), IListe.get(e).getSelection().getSelectedIDs()); |
((CommandeClientSQLElement) getForeignElement("ID_COMMANDE_CLIENT")).transfertEltToCommandeF(rows); |
} |
}); |
} |
}, true); |
rowAction.setPredicate(IListeEvent.getNonEmptySelectionPredicate()); |
214,6 → 207,7 |
l.add("NOM"); |
l.add("ID_COMMANDE_CLIENT"); |
l.add("ID_ARTICLE"); |
l.add("ID_DEPOT_STOCK"); |
l.add("PA_HT"); |
l.add("PV_HT"); |
l.add("T_PA_HT"); |
234,6 → 228,11 |
*/ |
public void transfertCommande(List<SQLRowValues> commandeClientEltsRows) { |
ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() { |
@Override |
public void run() { |
SQLTable tableCmdElt = getDirectory().getElement("COMMANDE_ELEMENT").getTable(); |
SQLElement eltArticle = getDirectory().getElement("ARTICLE"); |
240,10 → 239,26 |
final ListMap<SQLRow, SQLRowValues> map = new ListMap<SQLRow, SQLRowValues>(); |
List<String> fields2copy = Arrays.asList("CODE", "NOM", "VALEUR_METRIQUE_1", "VALEUR_METRIQUE_2", "VALEUR_METRIQUE_3"); |
// Set<Integer> art = new HashSet<Integer>(); |
Set<Integer> artAdded = new HashSet<Integer>(); |
for (SQLRowValues sqlRow : commandeClientEltsRows) { |
boolean article = false; |
if (sqlRow.getTable().getName().equalsIgnoreCase("ARTICLE")) { |
article = true; |
} |
// renderer sur liste des ar |
// if() |
/// rowValsElt.put("QTE", sqlRow.getObject("QTE")); |
SQLRowAccessor rowArticleFind; |
SQLRowValues rowArticle; |
int qte = 1; |
BigDecimal qteUV = BigDecimal.ONE; |
boolean gestionStock = true; |
if (!article) { |
// on récupére l'article qui lui correspond |
SQLRowValues rowArticle = new SQLRowValues(eltArticle.getTable()); |
rowArticle = new SQLRowValues(eltArticle.getTable()); |
for (String field : fields2copy) { |
// if (sqlRow.getTable().getFieldsName().contains(field.getName())) { |
rowArticle.put(field, sqlRow.asRow().getObject(field)); |
251,54 → 266,43 |
} |
int idArticle = ReferenceArticleSQLElement.getIdForCNM(rowArticle, true); |
SQLRow rowArticleFind = eltArticle.getTable().getRow(idArticle); |
if (rowArticleFind != null && !rowArticleFind.isUndefined()) { |
SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCmdElt); |
SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticleFind)); |
rowValsElt.put("ID_STYLE", sqlRow.getObject("ID_STYLE")); |
rowArticleFind = eltArticle.getTable().getRow(idArticle); |
// if() |
gestionStock = rowArticleFind.getBoolean("GESTION_STOCK"); |
if (!gestionStock) { |
qte = sqlRow.getInt("QTE"); |
qteUV = sqlRow.getBigDecimal("QTE_UNITAIRE"); |
rowValsElt.put("QTE", sqlRow.getObject("QTE")); |
rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * rowValsElt.getInt("QTE")); |
rowValsElt.put("T_PA_HT", ((BigDecimal) rowValsElt.getObject("PA_HT")).multiply(new BigDecimal(rowValsElt.getInt("QTE")), DecimalUtils.HIGH_PRECISION)); |
rowValsElt.put("T_PA_TTC", |
((BigDecimal) rowValsElt.getObject("T_PA_HT")).multiply(new BigDecimal((rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0)), DecimalUtils.HIGH_PRECISION)); |
// rowValsElt.put("ID_DEVISE", |
// rowCmd.getForeignRow("ID_TARIF").getForeignID("ID_DEVISE")); |
map.add(rowArticleFind.getForeignRow("ID_FOURNISSEUR"), rowValsElt); |
if (sqlRow.getObject("ID_UNITE_VENTE") != null && sqlRow.getForeignID("ID_UNITE_VENTE") != UniteVenteArticleSQLElement.A_LA_PIECE) { |
qteUV = qteUV.multiply(new BigDecimal(qte)); |
qte = 1; |
} |
} else { |
if (rowArticle.getForeign("ID_STOCK") != null && !rowArticle.isForeignEmpty("ID_STOCK")) { |
SQLRowAccessor rowStock = rowArticle.getForeign("ID_STOCK"); |
qte = -Math.round(rowStock.getFloat("QTE_TH") - rowStock.getFloat("QTE_MIN")); |
} |
// TODO |
MouvementStockSQLElement.createCommandeF(map, null, "", false); |
} |
} else { |
rowArticleFind = sqlRow; |
rowArticle = sqlRow; |
if (rowArticle.getForeign("ID_STOCK") != null && !rowArticle.isForeignEmpty("ID_STOCK")) { |
SQLRowAccessor rowStock = rowArticle.getForeign("ID_STOCK"); |
qte = -Math.round(rowStock.getFloat("QTE_TH") - rowStock.getFloat("QTE_MIN")); |
} |
} |
if (rowArticleFind != null && !rowArticleFind.isUndefined() && (!gestionStock || !artAdded.contains(rowArticleFind.getID()))) { |
public void createCommandeF(final List<? extends SQLRowAccessor> rowsItems) { |
artAdded.add(rowArticleFind.getID()); |
ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() { |
SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCmdElt); |
SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticleFind.asRow())); |
@Override |
public void run() { |
final ListMap<SQLRow, SQLRowValues> map = new ListMap<SQLRow, SQLRowValues>(); |
final Set<Integer> stockChecked = new HashSet<Integer>(); |
for (SQLRowAccessor rowItem : rowsItems) { |
if (rowItem.getObject("ID_ARTICLE") != null && !rowItem.isForeignEmpty("ID_ARTICLE")) { |
SQLRowAccessor rowArticleFind = rowItem.getForeign("ID_ARTICLE"); |
rowValsElt.put("ID_STYLE", sqlRow.getObject("ID_STYLE")); |
SQLRow row = rowArticleFind.asRow(); |
SQLRowAccessor rowStock = StockSQLElement.getStock(rowItem); |
if (!stockChecked.contains(rowStock.getID())) { |
stockChecked.add(rowStock.getID()); |
rowValsElt.put("QTE", qte); |
rowValsElt.put("QTE_UNITAIRE", qteUV); |
int value = -Math.round(rowStock.getFloat("QTE_TH") - rowStock.getFloat("QTE_MIN")); |
if (value > 0) { |
SQLInjector inj = SQLInjector.getInjector(row.getTable(), row.getTable().getTable("COMMANDE_ELEMENT")); |
SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(row)); |
rowValsElt.put("QTE", value); |
rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * rowValsElt.getInt("QTE")); |
rowValsElt.put("T_PA_HT", ((BigDecimal) rowValsElt.getObject("PA_HT")).multiply(new BigDecimal(rowValsElt.getInt("QTE")), DecimalUtils.HIGH_PRECISION)); |
rowValsElt.put("T_PA_TTC", ((BigDecimal) rowValsElt.getObject("T_PA_HT")).multiply(new BigDecimal((rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0)), |
305,15 → 309,13 |
DecimalUtils.HIGH_PRECISION)); |
// rowValsElt.put("ID_DEVISE", |
// rowCmd.getForeignRow("ID_TARIF").getForeignID("ID_DEVISE")); |
map.add(rowArticleFind.getForeign("ID_FOURNISSEUR").asRow(), rowValsElt); |
map.add(rowArticleFind.asRow().getForeignRow("ID_FOURNISSEUR"), rowValsElt); |
} |
} |
MouvementStockSQLElement.createCommandeF(map, null, ""); |
} |
} |
MouvementStockSQLElement.createCommandeF(map, null, "", false); |
} |
}); |
} |
protected List<String> getComboFields() { |
338,7 → 340,7 |
res.putCollection("ID_COMMANDE_CLIENT", "NUMERO", "DATE", "DATE_LIVRAISON_PREV", "ID_CLIENT"); |
if (getTable().contains("ID_ARTICLE")) { |
res.putCollection("ID_ARTICLE", "ID_FAMILLE_ARTICLE", "ID_FOURNISSEUR"); |
res.putCollection("ID_ARTICLE", "GESTION_STOCK", "ID_FAMILLE_ARTICLE", "ID_FOURNISSEUR"); |
} |
res.putCollection(null, "NOM"); |
return res; |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/order/element/CommandeClientSQLElement.java |
---|
22,7 → 22,9 |
import org.openconcerto.erp.core.sales.order.component.CommandeClientSQLComponent; |
import org.openconcerto.erp.core.sales.order.report.CommandeClientXmlSheet; |
import org.openconcerto.erp.core.sales.order.ui.EtatCommandeClient; |
import org.openconcerto.erp.core.sales.product.element.ReferenceArticleSQLElement; |
import org.openconcerto.erp.core.sales.product.element.UniteVenteArticleSQLElement; |
import org.openconcerto.erp.core.sales.product.model.ProductComponent; |
import org.openconcerto.erp.core.sales.product.model.ProductHelper; |
import org.openconcerto.erp.core.sales.shipment.component.BonDeLivraisonSQLComponent; |
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement; |
import org.openconcerto.erp.core.supplychain.stock.element.StockSQLElement; |
36,7 → 38,6 |
import org.openconcerto.sql.element.TreesOfSQLRows; |
import org.openconcerto.sql.model.ConnectionHandlerNoSetup; |
import org.openconcerto.sql.model.SQLDataSource; |
import org.openconcerto.sql.model.SQLField; |
import org.openconcerto.sql.model.SQLInjector; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowAccessor; |
579,43 → 580,68 |
public void transfertCommande(int commandeID, boolean useCommandeEnCours) { |
SQLElement elt = Configuration.getInstance().getDirectory().getElement("COMMANDE_CLIENT_ELEMENT"); |
SQLTable tableCmdElt = Configuration.getInstance().getDirectory().getElement("COMMANDE_ELEMENT").getTable(); |
SQLElement eltArticle = Configuration.getInstance().getDirectory().getElement("ARTICLE"); |
SQLRow rowCmd = getTable().getRow(commandeID); |
List<SQLRow> rows = rowCmd.getReferentRows(elt.getTable()); |
transfertEltToCommandeF(rows); |
} |
public void transfertEltToCommandeF(List<? extends SQLRowAccessor> rowsItems) { |
ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor().execute(new Runnable() { |
@Override |
public void run() { |
ProductHelper helper = new ProductHelper(getTable().getDBRoot()); |
List<ProductComponent> productComp = new ArrayList<>(); |
helper.fillProductComponent(rowsItems, productComp, 1, 0, 1); |
List<ProductComponent> leafItems = helper.getChildWithQtyFrom(productComp); |
final ListMap<SQLRow, SQLRowValues> map = new ListMap<SQLRow, SQLRowValues>(); |
for (SQLRow sqlRow : rows) { |
// on récupére l'article qui lui correspond |
SQLRowValues rowArticle = new SQLRowValues(eltArticle.getTable()); |
for (SQLField field : eltArticle.getTable().getFields()) { |
if (sqlRow.getTable().getFieldsName().contains(field.getName())) { |
rowArticle.put(field.getName(), sqlRow.getObject(field.getName())); |
final Set<Integer> stockChecked = new HashSet<Integer>(); |
for (ProductComponent comp : leafItems) { |
SQLRowAccessor rowArticleFind = comp.getProduct(); |
SQLRow row = rowArticleFind.asRow(); |
SQLRowAccessor rowStock = comp.getStock(); |
int value = 0; |
if (row.getBoolean("GESTION_STOCK") && !stockChecked.contains(rowStock.getID())) { |
stockChecked.add(rowStock.getID()); |
value = -Math.round(rowStock.getFloat("QTE_TH") - rowStock.getFloat("QTE_MIN")); |
} else if (!row.getBoolean("GESTION_STOCK")) { |
value = comp.getQty().intValue(); |
} |
if (value > 0) { |
SQLInjector inj = SQLInjector.getInjector(row.getTable(), row.getTable().getTable("COMMANDE_ELEMENT")); |
SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(row)); |
int qte = 1; |
BigDecimal qteUV = BigDecimal.ONE; |
if (row.getObject("ID_UNITE_VENTE") != null && row.getForeignID("ID_UNITE_VENTE") != UniteVenteArticleSQLElement.A_LA_PIECE) { |
qteUV = comp.getQty(); |
} else { |
qte = comp.getQty().setScale(0, RoundingMode.HALF_UP).intValue(); |
} |
int idArticle = ReferenceArticleSQLElement.getIdForCNM(rowArticle, true); |
SQLRow rowArticleFind = eltArticle.getTable().getRow(idArticle); |
if (rowArticleFind != null && !rowArticleFind.isUndefined()) { |
SQLInjector inj = SQLInjector.getInjector(rowArticle.getTable(), tableCmdElt); |
SQLRowValues rowValsElt = new SQLRowValues(inj.createRowValuesFrom(rowArticleFind)); |
rowValsElt.put("ID_STYLE", sqlRow.getObject("ID_STYLE")); |
rowValsElt.put("QTE", sqlRow.getObject("QTE")); |
rowValsElt.put("QTE", qte); |
rowValsElt.put("QTE_UNITAIRE", qteUV); |
rowValsElt.put("T_POIDS", rowValsElt.getLong("POIDS") * rowValsElt.getInt("QTE")); |
rowValsElt.put("T_PA_HT", ((BigDecimal) rowValsElt.getObject("PA_HT")).multiply(new BigDecimal(rowValsElt.getInt("QTE")), DecimalUtils.HIGH_PRECISION)); |
rowValsElt.put("T_PA_TTC", |
((BigDecimal) rowValsElt.getObject("T_PA_HT")).multiply(new BigDecimal((rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0)), DecimalUtils.HIGH_PRECISION)); |
final SQLRow foreignRow = rowArticleFind.getForeignRow("ID_FOURNISSEUR"); |
if (foreignRow != null && !foreignRow.isUndefined()) { |
rowValsElt.put("ID_DEVISE", foreignRow.getForeignID("ID_DEVISE")); |
} else { |
rowValsElt.put("ID_DEVISE", rowCmd.getForeignRow("ID_TARIF").getForeignID("ID_DEVISE")); |
rowValsElt.put("T_PA_TTC", ((BigDecimal) rowValsElt.getObject("T_PA_HT")).multiply(new BigDecimal((rowValsElt.getForeign("ID_TAXE").getFloat("TAUX") / 100.0 + 1.0)), |
DecimalUtils.HIGH_PRECISION)); |
// rowValsElt.put("ID_DEVISE", |
// rowCmd.getForeignRow("ID_TARIF").getForeignID("ID_DEVISE")); |
map.add(rowArticleFind.getForeign("ID_FOURNISSEUR").asRow(), rowValsElt); |
} |
map.add(rowArticleFind.getForeignRow("ID_FOURNISSEUR"), rowValsElt); |
} |
} |
MouvementStockSQLElement.createCommandeF(map, rowCmd.getForeignRow("ID_TARIF").getForeignRow("ID_DEVISE"), rowCmd.getString("NUMERO") + " - " + rowCmd.getString("NOM"), useCommandeEnCours); |
MouvementStockSQLElement.createCommandeF(map, null, ""); |
} |
}); |
} |
/** |
* Transfert en BL |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/order/action/ListeDesElementsACommanderClientAction.java |
---|
18,6 → 18,7 |
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel; |
import org.openconcerto.erp.core.common.ui.ListeViewPanel; |
import org.openconcerto.erp.core.sales.order.element.CommandeClientElementSQLElement; |
import org.openconcerto.erp.core.sales.product.ui.QteAcommanderRenderer; |
import org.openconcerto.erp.core.supplychain.stock.element.StockSQLElement; |
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel; |
import org.openconcerto.sql.element.SQLElement; |
124,14 → 125,17 |
protected Object show_(SQLRowAccessor r) { |
final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE"); |
if (foreign != null && !foreign.isUndefined()) { |
if (foreign.getBoolean("GESTION_STOCK")) { |
SQLRowAccessor foreign2 = StockSQLElement.getStockFetched(r); |
if (foreign2 != null && !foreign2.isUndefined()) { |
return foreign2.getFloat("QTE_REEL"); |
} |
} |
return 0F; |
} |
return null; |
} |
@Override |
public Set<FieldPath> getPaths() { |
150,13 → 154,16 |
final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE"); |
if (foreign != null && !foreign.isUndefined()) { |
if (foreign.getBoolean("GESTION_STOCK")) { |
SQLRowAccessor foreign2 = StockSQLElement.getStockFetched(r); |
if (foreign2 != null && !foreign2.isUndefined()) { |
return foreign2.getFloat("QTE_TH"); |
} |
} |
return 0F; |
} |
return null; |
} |
@Override |
public Set<FieldPath> getPaths() { |
175,13 → 182,16 |
final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE"); |
if (foreign != null && !foreign.isUndefined()) { |
if (foreign.getBoolean("GESTION_STOCK")) { |
SQLRowAccessor foreign2 = StockSQLElement.getStockFetched(r); |
if (foreign2 != null && !foreign2.isUndefined()) { |
return foreign2.getFloat("QTE_MIN"); |
} |
} |
return 0F; |
} |
return null; |
} |
@Override |
public Set<FieldPath> getPaths() { |
200,6 → 210,8 |
final SQLRowAccessor foreign = r.getForeign("ID_ARTICLE"); |
if (foreign != null && !foreign.isUndefined()) { |
if (foreign.getBoolean("GESTION_STOCK")) { |
SQLRowAccessor foreign2 = StockSQLElement.getStockFetched(r); |
if (foreign2 != null && !foreign2.isUndefined()) { |
float qteMin = foreign2.getFloat("QTE_MIN"); |
206,10 → 218,13 |
float manque = foreign2.getFloat("QTE_TH") - qteMin; |
if (manque < 0) { |
return -manque; |
} else { |
return 0f; |
} |
} |
} |
return 0F; |
} |
return r.getBigDecimal("QTE_UNITAIRE").multiply(new BigDecimal(r.getInt("QTE"))).floatValue(); |
} |
222,7 → 237,7 |
} |
}; |
tableSource.getColumns().add(colSug); |
// colLiv2.setRenderer(new PercentTableCellRenderer()); |
colSug.setRenderer(new QteAcommanderRenderer()); |
return tableSource; |
} |
314,7 → 329,7 |
@Override |
public void actionPerformed(ActionEvent e) { |
List<SQLRowValues> selectedRows = IListe.get(e).getSelectedRows(); |
eltCmd.createCommandeF(selectedRows); |
eltCmd.transfertCommande(selectedRows); |
} |
}, true); |
predicateACtion.setPredicate(IListeEvent.getNonEmptySelectionPredicate()); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/order/component/CommandeClientSQLComponent.java |
---|
23,6 → 23,7 |
import org.openconcerto.erp.core.common.ui.TotalPanel; |
import org.openconcerto.erp.core.customerrelationship.customer.ui.AddressChoiceUI; |
import org.openconcerto.erp.core.customerrelationship.customer.ui.AdresseType; |
import org.openconcerto.erp.core.customerrelationship.customer.ui.CategorieComptableChoiceUI; |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache; |
import org.openconcerto.erp.core.sales.order.report.CommandeClientXmlSheet; |
import org.openconcerto.erp.core.sales.order.ui.CommandeClientItemTable; |
255,8 → 256,16 |
// } |
// table.setTarif(foreignRow, true); |
} |
if (!isFilling()) { |
table.setClient(row, true); |
} |
} else { |
if (!isFilling()) { |
table.setClient(null, true); |
} |
} |
} |
} |
}); |
393,6 → 402,24 |
}); |
} |
if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.CATEGORIE_COMPTABLE_SPEC, false)) { |
// cat spe |
final CategorieComptableChoiceUI catUI = new CategorieComptableChoiceUI(); |
catUI.addToUI(this, c); |
catUI.getCombo().addModelListener("wantedID", new PropertyChangeListener() { |
@Override |
public void propertyChange(PropertyChangeEvent evt) { |
int wantedID = catUI.getCombo().getWantedID(); |
if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) { |
table.setRowCatComptable(catUI.getCombo().getElement().getTable().getRow(wantedID)); |
} else { |
table.setRowCatComptable(null); |
} |
} |
}); |
} |
if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.ORDER_PACKAGING_MANAGEMENT, true)) { |
// Emballage |
c.gridy++; |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/invoice/component/SaisieVenteFactureSQLComponent.java |
---|
24,6 → 24,7 |
import org.openconcerto.erp.core.common.ui.DeviseField; |
import org.openconcerto.erp.core.common.ui.TotalPanel; |
import org.openconcerto.erp.core.customerrelationship.customer.ui.AdresseType; |
import org.openconcerto.erp.core.customerrelationship.customer.ui.CategorieComptableChoiceUI; |
import org.openconcerto.erp.core.finance.accounting.element.ComptePCESQLElement; |
import org.openconcerto.erp.core.finance.accounting.element.EcritureSQLElement; |
import org.openconcerto.erp.core.finance.payment.component.ModeDeReglementSQLComponent; |
160,6 → 161,10 |
tableFacture.setRowCatComptable(null); |
} |
if (!isFilling()) { |
tableFacture.setClient(rowCli, true); |
} |
if (getMode() == SQLComponent.Mode.INSERTION || !isFilling()) { |
SQLElement sqleltModeRegl = Configuration.getInstance().getDirectory().getElement("MODE_REGLEMENT"); |
int idModeRegl = rowCli.getInt("ID_MODE_REGLEMENT"); |
480,6 → 485,26 |
} |
}); |
// } |
SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot()); |
if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.CATEGORIE_COMPTABLE_SPEC, false)) { |
// cat spe |
final CategorieComptableChoiceUI catUI = new CategorieComptableChoiceUI(); |
catUI.addToUI(this, c); |
catUI.getCombo().addModelListener("wantedID", new PropertyChangeListener() { |
@Override |
public void propertyChange(PropertyChangeEvent evt) { |
int wantedID = catUI.getCombo().getWantedID(); |
if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) { |
tableFacture.setRowCatComptable(catUI.getCombo().getElement().getTable().getRow(wantedID)); |
} else { |
tableFacture.setRowCatComptable(null); |
} |
} |
}); |
} |
// Contact |
this.contact = new ElementComboBox() { |
@Override |
726,7 → 751,6 |
final DeviseField textFraisDocHT = new DeviseField(); |
final SQLRequestComboBox boxTaxeFraisDoc = new SQLRequestComboBox(false, 8); |
SQLPreferences prefs = SQLPreferences.getMemCached(getTable().getDBRoot()); |
final boolean showFrais = prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.FRAIS_DOCUMENT, false); |
if (showFrais) { |
1915,4 → 1939,57 |
this.tableFacture.setDateDevise(this.dateSaisie.getValue()); |
} |
@Override |
protected void initDone() { |
super.initDone(); |
// FIXME listener pour le module project à déplacer dans le module quand l'interface passera |
// en group |
if (getTable().contains("ID_AFFAIRE")) { |
final SQLRequestComboBox viewClient = (SQLRequestComboBox) getView("ID_CLIENT").getComp(); |
final SQLRequestComboBox viewAffaire = (SQLRequestComboBox) getView("ID_AFFAIRE").getComp(); |
final SQLRequestComboBox viewComm = (SQLRequestComboBox) getView("ID_COMMERCIAL").getComp(); |
final SQLRequestComboBox viewAgence; |
if (getTable().contains("ID_POLE_PRODUIT")) { |
viewAgence = (SQLRequestComboBox) getView("ID_POLE_PRODUIT").getComp(); |
} else { |
viewAgence = null; |
} |
viewAffaire.addModelListener("wantedID", new PropertyChangeListener() { |
@Override |
public void propertyChange(PropertyChangeEvent evt) { |
if (!isFilling()) { |
SQLRowAccessor selAffaire = viewAffaire.getSelectedRow(); |
if (selAffaire != null && !selAffaire.isUndefined()) { |
viewClient.setValue(selAffaire.getForeignID("ID_CLIENT")); |
if (selAffaire.getTable().contains("ID_COMMERCIAL")) { |
viewComm.setValue(selAffaire.getForeignID("ID_COMMERCIAL")); |
} |
} |
} |
} |
}); |
if (viewAgence != null) { |
viewComm.addModelListener("wantedID", new PropertyChangeListener() { |
@Override |
public void propertyChange(PropertyChangeEvent evt) { |
if (!isFilling()) { |
SQLRowAccessor selComm = viewComm.getSelectedRow(); |
if (selComm != null && !selComm.isUndefined() && selComm.getTable().contains("ID_POLE_PRODUIT")) { |
viewAgence.setValue(selComm.getForeignID("ID_POLE_PRODUIT")); |
} |
} |
} |
}); |
} |
} |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/invoice/element/EcheanceClientSQLElement.java |
---|
18,7 → 18,11 |
import org.openconcerto.erp.core.common.element.NumerotationAutoSQLElement; |
import org.openconcerto.erp.core.common.ui.DeviseField; |
import org.openconcerto.erp.core.customerrelationship.customer.element.RelanceSQLElement; |
import org.openconcerto.erp.core.customerrelationship.mail.EmailTemplate; |
import org.openconcerto.erp.core.customerrelationship.mail.ValueListener; |
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement; |
import org.openconcerto.erp.core.finance.payment.element.EncaisserMontantSQLElement; |
import org.openconcerto.erp.core.sales.invoice.action.ImportReglementSage; |
import org.openconcerto.erp.core.sales.invoice.report.MailRelanceCreator; |
import org.openconcerto.erp.core.sales.invoice.report.VenteFactureXmlSheet; |
import org.openconcerto.erp.rights.ComptaUserRight; |
26,18 → 30,25 |
import org.openconcerto.sql.element.BaseSQLComponent; |
import org.openconcerto.sql.element.SQLComponent; |
import org.openconcerto.sql.element.SQLElement; |
import org.openconcerto.sql.model.ConnectionHandlerNoSetup; |
import org.openconcerto.sql.model.FieldPath; |
import org.openconcerto.sql.model.SQLBase; |
import org.openconcerto.sql.model.SQLDataSource; |
import org.openconcerto.sql.model.SQLField; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.SQLRowListRSH; |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.model.SQLRowValuesListFetcher; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.model.Where; |
import org.openconcerto.sql.model.graph.Link; |
import org.openconcerto.sql.model.graph.Path; |
import org.openconcerto.sql.model.graph.PathBuilder; |
import org.openconcerto.sql.request.ListSQLRequest; |
import org.openconcerto.sql.sqlobject.ElementComboBox; |
import org.openconcerto.sql.users.rights.UserRightsManager; |
import org.openconcerto.sql.utils.SQLUtils; |
import org.openconcerto.sql.view.EditFrame; |
import org.openconcerto.sql.view.EditPanel.EditMode; |
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn; |
49,11 → 60,15 |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import org.openconcerto.ui.EmailComposer; |
import org.openconcerto.ui.JDate; |
import org.openconcerto.ui.SwingThreadUtils; |
import org.openconcerto.utils.CollectionUtils; |
import org.openconcerto.utils.ExceptionHandler; |
import org.openconcerto.utils.GestionDevise; |
import org.openconcerto.utils.ListMap; |
import java.awt.Component; |
import java.awt.FileDialog; |
import java.awt.Frame; |
import java.awt.GridBagConstraints; |
import java.awt.GridBagLayout; |
import java.awt.event.ActionEvent; |
62,6 → 77,7 |
import java.sql.SQLException; |
import java.text.SimpleDateFormat; |
import java.util.ArrayList; |
import java.util.Calendar; |
import java.util.Date; |
import java.util.List; |
import java.util.Locale; |
71,7 → 87,6 |
import javax.swing.JLabel; |
import javax.swing.JOptionPane; |
import javax.swing.JTextField; |
import javax.swing.SwingUtilities; |
public class EcheanceClientSQLElement extends ComptaSQLConfElement { |
111,16 → 126,90 |
} |
{ |
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Envoyer un mail") { |
PredicateRowAction action = new PredicateRowAction(new AbstractAction("Envoyer un mail de relance") { |
@Override |
public void actionPerformed(ActionEvent arg0) { |
public void actionPerformed(ActionEvent e) { |
final IListe iListe = IListe.get(e); |
if (iListe.getSelectedRows().isEmpty()) { |
int result = JOptionPane.showConfirmDialog(iListe, |
"Souhaitez vous envoyer un email de relance pour toutes les factures\ndont l'échéance est dépassée?\nLes relances ne seront pas envoyées si les factures ont déjà une relance de moins d'un mois. ", |
"Relance automatique", JOptionPane.YES_NO_OPTION); |
if (result == JOptionPane.YES_OPTION) { |
EmailTemplate.askTemplate(iListe, getTable().getDBRoot(), new ValueListener() { |
SQLRow row = IListe.get(arg0).fetchSelectedRow(); |
sendMail(row); |
@Override |
public void valueSelected(Object value) { |
final Thread t = new Thread(new Runnable() { |
@Override |
public void run() { |
try { |
EmailTemplate template = (EmailTemplate) value; |
final SQLTable table = getTable(); |
final SQLRowValues v = new SQLRowValues(table); |
v.putNulls(table.getFieldsName()); |
Where w = new Where(table.getField("REGLE"), "=", false); |
w = w.and(new Where(table.getField("REG_COMPTA"), "=", false)); |
final Calendar c = Calendar.getInstance(); |
c.add(Calendar.MONTH, -1); |
w = w.and(new Where(table.getField("DATE_LAST_RELANCE"), ">", c.getTime())); |
w = w.and(new Where(table.getField("DATE"), "<=", Calendar.getInstance().getTime())); |
List<SQLRowValues> rowValues = SQLRowValuesListFetcher.create(v).fetch(w); |
if (rowValues.isEmpty()) { |
JOptionPane.showMessageDialog(iListe, "Aucune relance à envoyer."); |
} else { |
for (SQLRowValues row : rowValues) { |
sendMail(row.asRow(), template); |
} |
}, false); |
action.setPredicate(IListeEvent.getSingleSelectionPredicate()); |
} |
} catch (Exception e) { |
ExceptionHandler.handle("erreur lors de l'envoi", e); |
} |
} |
}); |
t.setDaemon(true); |
t.setName("email relance"); |
t.start(); |
} |
}); |
} |
} else { |
final SQLTable primaryTable = iListe.getRequest().getPrimaryTable(); |
final List<Integer> selectedIDs = iListe.getSelection().getSelectedIDs(); |
EmailTemplate.askTemplate(iListe, getTable().getDBRoot(), new ValueListener() { |
@Override |
public void valueSelected(Object value) { |
final Thread t = new Thread(new Runnable() { |
@Override |
public void run() { |
try { |
EmailTemplate template = (EmailTemplate) value; |
final List<SQLRow> rows = SQLRowListRSH.fetch(primaryTable, selectedIDs); |
for (SQLRow row : rows) { |
sendMail(row, template); |
} |
} catch (Exception e) { |
ExceptionHandler.handle("erreur lors de l'envoi", e); |
} |
} |
}); |
t.setDaemon(true); |
t.setName("email relance selection"); |
t.start(); |
} |
}); |
} |
} |
}, true); |
action.setPredicate(IListeEvent.createTotalRowCountPredicate(0, Integer.MAX_VALUE)); |
getRowActions().add(action); |
} |
143,6 → 232,7 |
} |
} |
}, false) { |
@Override |
public boolean enabledFor(List<SQLRowValues> selection) { |
if (selection != null && selection.size() == 1) { |
184,6 → 274,7 |
} |
} |
}, false) { |
@Override |
public boolean enabledFor(List<SQLRowValues> selection) { |
if (selection != null && selection.size() == 1) { |
193,24 → 284,63 |
return true; |
} |
} |
}; |
getRowActions().add(actionRegul); |
} |
RowAction actionImport = new RowAction(new AbstractAction("Importer") { |
public void actionPerformed(ActionEvent e) { |
final Frame frame = SwingThreadUtils.getAncestorOrSelf(Frame.class, (Component) e.getSource()); |
final FileDialog fd = new FileDialog(frame, "Import XML des réglements Sage", FileDialog.LOAD); |
if (fd.getFile() != null) { |
try { |
SQLUtils.executeAtomic(getTable().getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<Object, IOException>() { |
@Override |
public Object handle(final SQLDataSource ds) throws SQLException, IOException { |
ImportReglementSage sageImporter = new ImportReglementSage(getDirectory().getElement(EncaisserMontantSQLElement.class)); |
try { |
sageImporter.importFromFile(new File(fd.getDirectory(), fd.getFile())); |
} catch (Exception e) { |
e.printStackTrace(); |
new SQLException(e); |
} |
return null; |
} |
}); |
JOptionPane.showMessageDialog(null, "Import des paiements terminés!"); |
} catch (IOException exn) { |
ExceptionHandler.handle(frame, "Erreur lors de la lecture du fichier", exn); |
} catch (SQLException exn) { |
ExceptionHandler.handle(frame, "Erreur lors de l'insertion des paiements dans la base", exn); |
} |
private void sendMail(final SQLRow row) { |
} |
fd.setVisible(true); |
} |
}, true) { |
@Override |
public boolean enabledFor(List<SQLRowValues> selection) { |
return true; |
} |
}; |
getRowActions().add(actionImport); |
} |
private void sendMail(final SQLRow row, EmailTemplate template) throws Exception { |
SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete(); |
if (row != null) { |
int idMvtSource = MouvementSQLElement.getSourceId(row.getInt("ID_MOUVEMENT")); |
SQLRow rowMvtSource = base.getTable("MOUVEMENT").getRow(idMvtSource); |
if (!rowMvtSource.getString("SOURCE").equalsIgnoreCase("SAISIE_VENTE_FACTURE")) { |
// this.relancer.setEnabled(false); |
return; |
} |
int idFact = rowMvtSource.getInt("IDSOURCE"); |
242,16 → 372,12 |
} |
final String adresseMail = mail; |
MailRelanceCreator creator = new MailRelanceCreator(); |
final String references = creator.getObject(row); |
final String text = creator.getValue(row); |
MailRelanceCreator creator = new MailRelanceCreator(template, row); |
final String references = creator.getObject(); |
final String text = creator.getValue(); |
final Thread t = new Thread() { |
@Override |
public void run() { |
final File f; |
final File f; |
try { |
f = sheet.getOrCreatePDFDocumentFile(true); |
EmailComposer.getInstance().compose(adresseMail, references, text, f.getAbsoluteFile()); |
266,7 → 392,7 |
rowValsR.put("MONTANT", row.getObject("MONTANT")); |
rowValsR.put("INFOS", "Email"); |
rowValsR.put("ID_ECHEANCE_CLIENT", row.getID()); |
try { |
rowValsR.insert(); |
SQLTable tableNum = getTable().getBase().getTable("NUMEROTATION_AUTO"); |
287,26 → 413,8 |
rowValsEch.update(row.getID()); |
} catch (SQLException e) { |
e.printStackTrace(); |
} |
} catch (IOException exn) { |
exn.printStackTrace(); |
} catch (InterruptedException exn) { |
exn.printStackTrace(); |
} catch (Exception e1) { |
// TODO Auto-generated catch block |
e1.printStackTrace(); |
} |
} |
}; |
t.start(); |
} |
} |
@Override |
public ListMap<String, String> getShowAs() { |
ListMap<String, String> map = new ListMap<String, String>(); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/invoice/report/ReportingStockXmlSheet.java |
---|
13,7 → 13,6 |
package org.openconcerto.erp.core.sales.invoice.report; |
import org.openconcerto.erp.core.sales.invoice.report.ReportingVenteXmlSheet.Line; |
import org.openconcerto.erp.generationDoc.AbstractListeSheetXml; |
import org.openconcerto.erp.preferences.PrinterNXProps; |
import org.openconcerto.sql.Configuration; |
37,8 → 36,6 |
import java.util.Map; |
import java.util.TreeMap; |
import javax.swing.JProgressBar; |
public class ReportingStockXmlSheet extends AbstractListeSheetXml { |
private final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy"); |
125,11 → 122,12 |
Float qte = vals.getForeign("ID_STOCK").getFloat("QTE_REEL"); |
BigDecimal ha = BigDecimal.ZERO; |
if (qte > 0) { |
ha = vals.getBigDecimal("PA_HT").multiply(new BigDecimal(qte)); |
final BigDecimal puHA = vals.getBigDecimal("PA_HT"); |
ha = puHA.multiply(new BigDecimal(qte)); |
int idFamille = vals.getForeignID("ID_FAMILLE_ARTICLE"); |
SQLRow rowF = mapF.get(idFamille); |
Line lineArt = new Line(vals.getString("NOM"), vals.getString("CODE"), ha, qte); |
Line lineArt = new Line(vals.getString("NOM"), vals.getString("CODE"), puHA, ha, qte); |
// Init des lines familles |
225,13 → 223,18 |
class Line { |
final private String nomArt, codeArt; |
private BigDecimal totalHA; |
private BigDecimal totalHA, puHA; |
private Float qte; |
public Line(String nomArt, String codeArt, BigDecimal totalHA, Float qte) { |
this(nomArt, codeArt, BigDecimal.ZERO, totalHA, qte); |
} |
public Line(String nomArt, String codeArt, BigDecimal puHA, BigDecimal totalHA, Float qte) { |
this.nomArt = nomArt; |
this.codeArt = codeArt; |
this.totalHA = totalHA; |
this.puHA = puHA; |
this.qte = qte; |
} |
243,6 → 246,10 |
return codeArt; |
} |
public BigDecimal getPuHA() { |
return puHA; |
} |
public String getNomArt() { |
return nomArt; |
} |
263,6 → 270,7 |
m.put("CODE", getCodeArt()); |
m.put("NOM", getNomArt()); |
m.put("QTE", getQte()); |
m.put("PU_HA", getPuHA()); |
m.put("TOTAL_HA", getTotalHA()); |
return m; |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/invoice/report/MailRelanceCreator.java |
---|
14,11 → 14,10 |
package org.openconcerto.erp.core.sales.invoice.report; |
import org.openconcerto.erp.config.ComptaPropsConfiguration; |
import org.openconcerto.erp.core.customerrelationship.mail.EmailTemplate; |
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement; |
import org.openconcerto.erp.preferences.MailRelancePreferencePanel; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.preferences.SQLPreferences; |
import org.openconcerto.sql.users.UserManager; |
import org.openconcerto.utils.GestionDevise; |
30,10 → 29,18 |
public class MailRelanceCreator { |
SQLRow rowEcheance; |
private final EmailTemplate template; |
private final SQLRow rowEcheance; |
private final Map<String, String> map; |
public MailRelanceCreator() { |
public MailRelanceCreator(EmailTemplate template, SQLRow row) { |
if (template == null) { |
template = new EmailTemplate("defautl", getDefaultObject(), getDefaultValue(), true, "dd/MM/yyyy"); |
} |
this.template = template; |
this.rowEcheance = row; |
this.map = getMapValues(); |
} |
public String getDefaultObject() { |
50,9 → 57,14 |
return value; |
} |
public Map<String, String> getMapValues(SQLRow rowEch, String datePattern) { |
final Map<String, String> map = new HashMap<String, String>(); |
private Map<String, String> getMapValues() { |
String datePattern = this.template.getDateFormat(); |
if (datePattern == null || datePattern.trim().isEmpty()) { |
datePattern = "dd/MM/yyyy"; |
} |
final Map<String, String> map = new HashMap<>(); |
final SQLRow rowSoc = ((ComptaPropsConfiguration) Configuration.getInstance()).getRowSociete(); |
final SQLRow rowSocAdresse = rowSoc.getForeignRow("ID_ADRESSE_COMMON"); |
SQLRow rowUser = rowSoc.getTable().getDBRoot().findTable("USER_COMMON").getRow(UserManager.getUser().getId()); |
84,7 → 96,7 |
map.put("SocieteVille", ville); |
SQLRow rowClient; |
final SQLRow clientRowNX = rowEch.getForeignRow("ID_CLIENT"); |
final SQLRow clientRowNX = this.rowEcheance.getForeignRow("ID_CLIENT"); |
rowClient = clientRowNX; |
SQLRow rowAdresse = rowClient.getForeignRow("ID_ADRESSE"); |
if (!clientRowNX.isForeignEmpty("ID_ADRESSE_F")) { |
118,13 → 130,13 |
DateFormat dateFormat = new SimpleDateFormat(datePattern); |
map.put("RelanceDate", dateFormat.format(d)); |
SQLRow rowFacture = rowEch.getForeignRow("ID_SAISIE_VENTE_FACTURE"); |
SQLRow rowFacture = this.rowEcheance.getForeignRow("ID_SAISIE_VENTE_FACTURE"); |
// Infos facture |
Long lTotal = (Long) rowFacture.getObject("T_TTC"); |
Long lRestant = (Long) rowEch.getObject("MONTANT"); |
Long lVerse = new Long(lTotal.longValue() - lRestant.longValue()); |
Long lRestant = (Long) this.rowEcheance.getObject("MONTANT"); |
Long lVerse = Long.valueOf(lTotal.longValue() - lRestant.longValue()); |
map.put("FactureNumero", rowFacture.getString("NUMERO")); |
map.put("FactureReference", rowFacture.getString("NOM")); |
map.put("FactureTotal", GestionDevise.currencyToString(lTotal.longValue(), true)); |
136,30 → 148,22 |
SQLRow modeRegRow = rowFacture.getForeignRow("ID_MODE_REGLEMENT"); |
Date dateEch = ModeDeReglementSQLElement.calculDate(modeRegRow.getInt("AJOURS"), modeRegRow.getInt("LENJOUR"), dFacture); |
map.put("FactureDateEcheance", dateFormat.format(dateEch)); |
map.put("message", ""); |
return map; |
} |
public String getObject(SQLRow rowEch) { |
SQLPreferences prefs = new SQLPreferences(rowEch.getTable().getDBRoot()); |
String object = prefs.get(MailRelancePreferencePanel.MAIL_RELANCE_OBJET, getDefaultObject()); |
String date = prefs.get(MailRelancePreferencePanel.MAIL_RELANCE_DATE_PATTERN, "dd/MM/yyyy"); |
return fill(rowEch, date, object); |
public String getObject() { |
return fill(this.template.getTitle()); |
} |
public String getValue(SQLRow rowEch) { |
SQLPreferences prefs = new SQLPreferences(rowEch.getTable().getDBRoot()); |
String value = prefs.get(MailRelancePreferencePanel.MAIL_RELANCE, getDefaultValue()); |
String date = prefs.get(MailRelancePreferencePanel.MAIL_RELANCE_DATE_PATTERN, "dd/MM/yyyy"); |
return fill(rowEch, date, value); |
public String getValue() { |
return fill(this.template.getText()); |
} |
private String fill(SQLRow rowEch, String datePattern, String string) { |
Map<String, String> map = getMapValues(rowEch, datePattern); |
private String fill(String string) { |
String result = string; |
for (String key : map.keySet()) { |
result = result.replace("{" + key + "}", map.get(key)); |
for (String key : this.map.keySet()) { |
result = result.replace("{" + key + "}", this.map.get(key)); |
} |
return result; |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/invoice/action/ImportReglementSageAction.java |
---|
New file |
0,0 → 1,76 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.sales.invoice.action; |
import org.openconcerto.erp.core.finance.payment.element.EncaisserMontantSQLElement; |
import org.openconcerto.sql.model.ConnectionHandlerNoSetup; |
import org.openconcerto.sql.model.SQLDataSource; |
import org.openconcerto.sql.utils.SQLUtils; |
import org.openconcerto.ui.SwingThreadUtils; |
import org.openconcerto.utils.ExceptionHandler; |
import java.awt.Component; |
import java.awt.FileDialog; |
import java.awt.Frame; |
import java.awt.event.ActionEvent; |
import java.io.File; |
import java.io.IOException; |
import java.sql.SQLException; |
import javax.swing.AbstractAction; |
import javax.swing.Action; |
import javax.swing.JOptionPane; |
public class ImportReglementSageAction extends AbstractAction { |
private final EncaisserMontantSQLElement elt; |
public ImportReglementSageAction(EncaisserMontantSQLElement elt) { |
super(); |
this.elt = elt; |
this.putValue(Action.NAME, "Import XML des réglements depuis Sage"); |
} |
@Override |
public void actionPerformed(ActionEvent e) { |
final Frame frame = SwingThreadUtils.getAncestorOrSelf(Frame.class, (Component) e.getSource()); |
final FileDialog fd = new FileDialog(frame, "Import XML des réglements Sage", FileDialog.LOAD); |
if (fd.getFile() != null) { |
try { |
SQLUtils.executeAtomic(this.elt.getTable().getDBSystemRoot().getDataSource(), new ConnectionHandlerNoSetup<Object, IOException>() { |
@Override |
public Object handle(final SQLDataSource ds) throws SQLException, IOException { |
ImportReglementSage sageImporter = new ImportReglementSage(ImportReglementSageAction.this.elt); |
try { |
sageImporter.importFromFile(new File(fd.getDirectory(), fd.getFile())); |
} catch (Exception e) { |
e.printStackTrace(); |
new SQLException(e); |
} |
return null; |
} |
}); |
JOptionPane.showMessageDialog(null, "Import des paiements terminés!"); |
} catch (IOException exn) { |
ExceptionHandler.handle(frame, "Erreur lors de la lecture du fichier", exn); |
} catch (SQLException exn) { |
ExceptionHandler.handle(frame, "Erreur lors de l'insertion des paiements dans la base", exn); |
} |
} |
fd.setVisible(true); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/invoice/action/ImportReglementSage.java |
---|
New file |
0,0 → 1,190 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.sales.invoice.action; |
import org.openconcerto.erp.core.finance.payment.element.EncaisserMontantSQLElement; |
import org.openconcerto.erp.core.finance.payment.element.TypeReglementSQLElement; |
import org.openconcerto.sql.model.DBRoot; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.model.SQLRowValuesListFetcher; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.model.Where; |
import java.io.BufferedReader; |
import java.io.File; |
import java.io.FileInputStream; |
import java.io.InputStreamReader; |
import java.math.BigDecimal; |
import java.math.RoundingMode; |
import java.nio.charset.Charset; |
import java.text.DateFormat; |
import java.text.SimpleDateFormat; |
import java.util.ArrayList; |
import java.util.Collection; |
import java.util.HashMap; |
import java.util.List; |
import java.util.Map; |
import javax.swing.JOptionPane; |
import javax.swing.SwingUtilities; |
import org.jdom2.Document; |
import org.jdom2.Element; |
import org.jdom2.input.SAXBuilder; |
public class ImportReglementSage { |
private final DBRoot root; |
private EncaisserMontantSQLElement encaisserSQLElement; |
Map<String, SQLRowValues> mapVf; |
// <Reglements> |
// <Reglement> |
// <Code_Client>0010CHDMVA</Code_Client> |
// <Date_Reglement>28/01/2019</Date_Reglement> |
// <Numero_Facture>FA005088</Numero_Facture> |
// <Montant_Reglement>294.00</Montant_Reglement> |
// <Libelle_Reglement>Aucun</Libelle_Reglement> |
// </Reglement> |
// ... |
// </Reglements> |
public ImportReglementSage(EncaisserMontantSQLElement encaisserSQLElement) { |
this.root = encaisserSQLElement.getTable().getDBRoot(); |
this.encaisserSQLElement = encaisserSQLElement; |
} |
public void importFromFile(File f) throws Exception { |
final BufferedReader xmlReader = new BufferedReader(new InputStreamReader(new FileInputStream(f), Charset.forName("UTF8"))); |
SAXBuilder builder = new SAXBuilder(); |
final Document doc = builder.build(xmlReader); |
Element root = doc.getRootElement(); |
List<Element> reglements = root.getChildren("Reglement"); |
List<String> numeroFacts = new ArrayList<>(reglements.size()); |
for (Element r : reglements) { |
Element n = r.getChild("Numero_Facture"); |
numeroFacts.add(n.getValue()); |
} |
this.mapVf = fetchFactures(numeroFacts); |
for (Element r : reglements) { |
Element n = r.getChild("Numero_Facture"); |
Element d = r.getChild("Date_Reglement"); |
Element m = r.getChild("Montant_Reglement"); |
Element c = r.getChild("Code_Client"); |
createEncaissement(n.getValue(), m.getValue(), d.getValue(), c.getValue()); |
} |
} |
private Map<String, SQLRowValues> fetchFactures(List<String> numerosFactures) { |
final SQLTable tableVf = this.root.getTable("SAISIE_VENTE_FACTURE"); |
SQLRowValues rowValsFact = new SQLRowValues(tableVf); |
rowValsFact.putNulls("DATE", "NUMERO"); |
rowValsFact.putRowValues("ID_MODE_REGLEMENT").putNulls("ID_TYPE_REGLEMENT"); |
rowValsFact.putRowValues("ID_CLIENT").putRowValues("ID_MODE_REGLEMENT").putNulls("ID_TYPE_REGLEMENT"); |
SQLRowValues rowValsEch = new SQLRowValues(this.root.getTable("ECHEANCE_CLIENT")); |
rowValsEch.put("ID_SAISIE_VENTE_FACTURE", rowValsFact); |
rowValsEch.put("REGLE", null); |
rowValsEch.put("MONTANT", null); |
rowValsEch.put("REG_COMPTA", null); |
SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(rowValsFact); |
List<SQLRowValues> res = fetcher.fetch(new Where(tableVf.getField("NUMERO"), numerosFactures)); |
Map<String, SQLRowValues> rowValsVf = new HashMap<>(); |
for (SQLRowValues sqlRowValues : res) { |
rowValsVf.put(sqlRowValues.getString("NUMERO"), sqlRowValues); |
} |
return rowValsVf; |
} |
private void createEncaissement(String numeroFacture, String montant, String dateReglement, String codeClient) throws Exception { |
SQLRowValues rowVals = this.mapVf.get(numeroFacture); |
if (rowVals == null) { |
SwingUtilities.invokeLater(new Runnable() { |
@Override |
public void run() { |
JOptionPane.showMessageDialog(null, "Impossible de trouver la facture numéro " + numeroFacture); |
} |
}); |
} else { |
final Collection<SQLRowValues> referentRows = rowVals.getReferentRows(rowVals.getTable().getTable("ECHEANCE_CLIENT")); |
if (referentRows.size() == 1) { |
SQLRowValues ech = referentRows.iterator().next(); |
if (!ech.getBoolean("REGLE") && !ech.getBoolean("REG_COMPTA")) { |
BigDecimal b = new BigDecimal(montant); |
long montantL = b.movePointRight(2).setScale(0, RoundingMode.HALF_UP).longValue(); |
DateFormat format = new SimpleDateFormat("dd/MM/yyyy"); |
SQLRowValues rowValsEncaisser = new SQLRowValues(this.encaisserSQLElement.getTable()); |
rowValsEncaisser.put("ID_CLIENT", rowVals.getForeignID("ID_CLIENT")); |
rowValsEncaisser.put("NOM", numeroFacture); |
rowValsEncaisser.put("TIERS", codeClient); |
rowValsEncaisser.put("DATE", format.parse(dateReglement)); |
rowValsEncaisser.put("MONTANT", montantL); |
SQLRowAccessor rowValsMdrFact = rowVals.getForeign("ID_MODE_REGLEMENT"); |
int idType = rowValsMdrFact.getForeignID("ID_TYPE_REGLEMENT"); |
SQLRowValues rowValsMdrEnc = new SQLRowValues(rowValsMdrFact.getTable()); |
if (idType == TypeReglementSQLElement.CB || idType == TypeReglementSQLElement.ESPECE || idType == TypeReglementSQLElement.CHEQUE || idType == TypeReglementSQLElement.VIREMENT) { |
rowValsMdrEnc.put("ID_TYPE_REGLEMENT", idType); |
} else { |
rowValsMdrFact = rowVals.getForeign("ID_CLIENT").getForeign("ID_MODE_REGLEMENT"); |
idType = rowValsMdrFact.getForeignID("ID_TYPE_REGLEMENT"); |
if (idType == TypeReglementSQLElement.CB || idType == TypeReglementSQLElement.ESPECE || idType == TypeReglementSQLElement.CHEQUE |
|| idType == TypeReglementSQLElement.VIREMENT) { |
rowValsMdrEnc.put("ID_TYPE_REGLEMENT", idType); |
} else { |
rowValsMdrEnc.put("ID_TYPE_REGLEMENT", TypeReglementSQLElement.VIREMENT); |
} |
} |
rowValsMdrEnc.put("AJOURS", 0); |
rowValsMdrEnc.put("LENJOUR", 0); |
rowValsMdrEnc.put("COMPTANT", Boolean.TRUE); |
rowValsEncaisser.put("ID_MODE_REGLEMENT", rowValsMdrEnc); |
SQLRowValues rowValsEncaisserItem = new SQLRowValues(this.encaisserSQLElement.getTable().getTable("ENCAISSER_MONTANT_ELEMENT")); |
rowValsEncaisserItem.put("ID_ECHEANCE_CLIENT", ech); |
rowValsEncaisserItem.put("ID_ENCAISSER_MONTANT", rowValsEncaisser); |
rowValsEncaisserItem.put("MONTANT_REGLE", montantL); |
rowValsEncaisserItem.put("MONTANT_A_REGLER", ech.getLong("MONTANT")); |
SQLRow rowEncaisser = rowValsEncaisser.commit(); |
this.encaisserSQLElement.regleFacture(rowEncaisser); |
} |
} |
} |
} |
public static void main(String[] args) { |
File f = new File("ExempleReglementSAge.xml"); |
ImportReglementSage i = new ImportReglementSage(null); |
try { |
i.importFromFile(f); |
} catch (Exception e) { |
e.printStackTrace(); |
} |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/invoice/ui/EtatVentesPanel.java |
---|
18,6 → 18,7 |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import org.openconcerto.ui.JDate; |
import org.openconcerto.ui.JLabelBold; |
import org.openconcerto.utils.NoneSelectedButtonGroup; |
import org.openconcerto.utils.Tuple2; |
import java.awt.FlowLayout; |
43,7 → 44,8 |
private JDate du, au; |
private JButton buttonGen = new JButton("Créer"); |
private JButton buttonClose = new JButton("Fermer"); |
JCheckBox boxTicket = new JCheckBox("Uniquement les ventes en caisse"); |
private JCheckBox boxTicket = new JCheckBox("Uniquement les ventes en caisse"); |
private JCheckBox boxFacture = new JCheckBox("Uniquement les ventes sur facture"); |
public EtatVentesPanel() { |
super(new GridBagLayout()); |
120,7 → 122,18 |
c.gridy++; |
c.gridx = 0; |
c.weightx = 1; |
c.gridwidth = GridBagConstraints.REMAINDER; |
this.add(boxFacture, c); |
NoneSelectedButtonGroup grou = new NoneSelectedButtonGroup(); |
grou.add(boxFacture); |
grou.add(boxTicket); |
c.gridy++; |
c.gridx = 0; |
JPanel panelButton = new JPanel(); |
panelButton.add(this.buttonGen); |
panelButton.add(this.buttonClose); |
167,7 → 180,7 |
if (e.getSource() == this.buttonGen) { |
final Date start = this.du.getDate(); |
final Date stop = this.au.getDate(); |
final EtatVentesXmlSheet sheet = new EtatVentesXmlSheet(start, stop, boxTicket.isSelected()); |
final EtatVentesXmlSheet sheet = new EtatVentesXmlSheet(start, stop, boxTicket.isSelected(), boxFacture.isSelected()); |
try { |
// FIXME probleme de rendu avec le viewer |
sheet.createDocumentAsynchronous().get(); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/invoice/ui/GenListeVentePanel.java |
---|
31,6 → 31,8 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionListener; |
import java.util.ArrayList; |
import java.util.Collections; |
import java.util.Comparator; |
import java.util.List; |
import javax.swing.JButton; |
109,16 → 111,40 |
sel.addSelectStar(tableFact); |
sel.setDistinct(true); |
sel.setWhere(new Where(tableFact.getField("DATE"), GenListeVentePanel.this.du.getDate(), GenListeVentePanel.this.au.getDate())); |
List<SQLRow> l = (List<SQLRow>) dataSource.execute(sel.asString(), SQLRowListRSH.createFromSelect(sel, tableFact)); |
List<SQLRow> l = new ArrayList((List<SQLRow>) dataSource.execute(sel.asString(), SQLRowListRSH.createFromSelect(sel, tableFact))); |
Collections.sort(l, new Comparator<SQLRow>() { |
@Override |
public int compare(SQLRow o1, SQLRow o2) { |
int dateComp = o1.getDate("DATE").compareTo(o2.getDate("DATE")); |
if (dateComp == 0) { |
return o1.getString("NUMERO").compareTo(o2.getString("NUMERO")); |
} else { |
return dateComp; |
} |
} |
}); |
SQLSelect sel2 = new SQLSelect(Configuration.getInstance().getBase()); |
sel2.addSelectStar(tableAvoir); |
sel2.setWhere(new Where(tableAvoir.getField("DATE"), GenListeVentePanel.this.du.getDate(), GenListeVentePanel.this.au.getDate())); |
sel2.setDistinct(true); |
List<SQLRow> l2 = (List<SQLRow>) dataSource.execute(sel2.asString(), SQLRowListRSH.createFromSelect(sel2, tableAvoir)); |
List<SQLRow> l2 = new ArrayList((List<SQLRow>) dataSource.execute(sel2.asString(), SQLRowListRSH.createFromSelect(sel2, tableAvoir))); |
Collections.sort(l2, new Comparator<SQLRow>() { |
@Override |
public int compare(SQLRow o1, SQLRow o2) { |
int dateComp = o1.getDate("DATE").compareTo(o2.getDate("DATE")); |
if (dateComp == 0) { |
return o1.getString("NUMERO").compareTo(o2.getString("NUMERO")); |
} else { |
return dateComp; |
} |
} |
}); |
List<SQLRow> lTotal = new ArrayList<SQLRow>(); |
lTotal.addAll(l); |
lTotal.addAll(l2); |
ListeVenteXmlSheet sheet = new ListeVenteXmlSheet(lTotal, GenListeVentePanel.this.du.getDate(), GenListeVentePanel.this.au.getDate(), GenListeVentePanel.this.bar); |
sheet.createDocumentAsynchronous().get(); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/quote/component/DevisSQLComponent.java |
---|
27,6 → 27,7 |
import org.openconcerto.erp.core.common.ui.TotalPanel; |
import org.openconcerto.erp.core.customerrelationship.customer.ui.AddressChoiceUI; |
import org.openconcerto.erp.core.customerrelationship.customer.ui.AdresseType; |
import org.openconcerto.erp.core.customerrelationship.customer.ui.CategorieComptableChoiceUI; |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache; |
import org.openconcerto.erp.core.sales.quote.element.EtatDevisSQLElement; |
import org.openconcerto.erp.core.sales.quote.report.DevisXmlSheet; |
383,6 → 384,23 |
} |
}); |
} |
if (prefs.getBoolean(GestionCommercialeGlobalPreferencePanel.CATEGORIE_COMPTABLE_SPEC, false)) { |
// cat spe |
final CategorieComptableChoiceUI catUI = new CategorieComptableChoiceUI(); |
catUI.addToUI(this, c); |
catUI.getCombo().addModelListener("wantedID", new PropertyChangeListener() { |
@Override |
public void propertyChange(PropertyChangeEvent evt) { |
int wantedID = catUI.getCombo().getWantedID(); |
if (wantedID != SQLRow.NONEXISTANT_ID && wantedID >= SQLRow.MIN_VALID_ID) { |
table.setRowCatComptable(catUI.getCombo().getElement().getTable().getRow(wantedID)); |
} else { |
table.setRowCatComptable(null); |
} |
} |
}); |
} |
if (getTable().contains("ID_CONTACT")) { |
// Contact Client |
c.gridx = 0; |
418,8 → 436,15 |
final SQLRow rowClient = getTable().getForeignTable("ID_CLIENT").getRow(wantedID); |
int idClient = rowClient.getID(); |
comboContact.getRequest().setWhere(new Where(contactElement.getTable().getField("ID_CLIENT"), "=", idClient)); |
if (!isFilling()) { |
table.setClient(rowClient, true); |
} |
} else { |
comboContact.getRequest().setWhere(Where.FALSE); |
if (!isFilling()) { |
table.setClient(null, true); |
} |
DevisSQLComponent.this.table.setTarif(null, false); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/quote/element/DevisSQLElement.java |
---|
48,6 → 48,7 |
import org.openconcerto.sql.model.graph.Path; |
import org.openconcerto.sql.preferences.SQLPreferences; |
import org.openconcerto.sql.request.ListSQLRequest; |
import org.openconcerto.sql.ui.light.CustomRowEditor; |
import org.openconcerto.sql.users.UserManager; |
import org.openconcerto.sql.users.rights.UserRightsManager; |
import org.openconcerto.sql.view.EditFrame; |
63,7 → 64,6 |
import org.openconcerto.ui.light.ActivationOnSelectionControler; |
import org.openconcerto.ui.light.ColumnSpec; |
import org.openconcerto.ui.light.ColumnsSpec; |
import org.openconcerto.ui.light.CustomEditorProvider; |
import org.openconcerto.ui.light.LightController; |
import org.openconcerto.ui.light.LightUIButtonUnmanaged; |
import org.openconcerto.ui.light.LightUIComboBox; |
99,7 → 99,6 |
import java.util.Date; |
import java.util.HashSet; |
import java.util.List; |
import java.util.Map; |
import java.util.Set; |
import javax.swing.AbstractAction; |
767,14 → 766,12 |
} |
@Override |
protected Map<String, CustomEditorProvider> _getDefaultCustomEditorProvider(final Configuration configuration, final SQLRowAccessor sqlRow, final String sessionSecurityToken) |
throws IllegalArgumentException { |
final Map<String, CustomEditorProvider> map = super._getDefaultCustomEditorProvider(configuration, sqlRow, sessionSecurityToken); |
map.put("sales.quote.items.list", new CustomEditorProvider() { |
public List<CustomRowEditor> getCustomRowEditors(Configuration configuration, String sessionToken) { |
List<CustomRowEditor> map = super.getCustomRowEditors(configuration, sessionToken); |
map.add(new CustomRowEditor("sales.quote.items.list") { |
@Override |
public LightUIElement createUIElement(final String id) { |
public LightUIElement createUIElement() { |
final ColumnSpec c1 = new ColumnSpec("sales.quote.item.style", StringWithId.class, "Style", new StringWithId(2, "Normal"), true, new LightUIComboBox("sales.quote.item.style")); |
final ColumnSpec c2 = new ColumnSpec("sales.quote.item.code", String.class, "Code", "", true, new LightUITextField("sales.quote.item.code")); |
final ColumnSpec c3 = new ColumnSpec("sales.quote.item.label", String.class, "Nom", "", true, new LightUITextField("sales.quote.item.name")); |
864,65 → 861,11 |
final ColumnsSpec cSpec = new ColumnsSpec(lId, columnsSpec, possibleColumnIds, null); |
cSpec.setAllowMove(true); |
cSpec.setAllowResize(true); |
final RowSelectionSpec selectionSpec = new RowSelectionSpec(id); |
final TableSpec tSpec = new TableSpec(id, selectionSpec, cSpec); |
final RowSelectionSpec selectionSpec = new RowSelectionSpec(getItemId()); |
final TableSpec tSpec = new TableSpec(getItemId(), selectionSpec, cSpec); |
tSpec.setColumns(cSpec); |
if (sqlRow != null) { |
// send: id,value |
final SQLElement elem = configuration.getDirectory().getElement("DEVIS_ELEMENT"); |
final SQLTable table = elem.getTable(); |
final List<String> fieldsToFetch = new ArrayList<>(); |
for (ColumnSpec cs : columnsSpec) { |
String colId = cs.getId(); |
SQLField f = configuration.getFieldMapper().getSQLFieldForItem(colId); |
if (f != null) { |
fieldsToFetch.add(f.getName()); |
} else { |
throw new IllegalStateException("No field in " + table + " for column id " + colId); |
} |
} |
final Where where = new Where(table.getField("ID_DEVIS"), "=", sqlRow.getID()); |
final ListSQLRequest req = elem.createListRequest(fieldsToFetch, where, configuration.getShowAs()); |
List<SQLRowValues> fetchedRows = req.getValues(); |
List<Row> rows = new ArrayList<>(); |
for (final SQLRowValues vals : fetchedRows) { |
Row r = new Row(vals.getID(), columnsSpec.size()); |
List<Object> values = new ArrayList<>(); |
for (ColumnSpec cs : columnsSpec) { |
String colId = cs.getId(); |
SQLField f = configuration.getFieldMapper().getSQLFieldForItem(colId); |
if (f != null) { |
Object object = vals.getObject(f.getName()); |
if (object instanceof SQLRowValues) { |
SQLRowValues sqlRowValues = (SQLRowValues) object; |
long rowId = sqlRowValues.getIDNumber().longValue(); |
List<SQLField> fieldsToExpand = configuration.getShowAs().getFieldExpand(sqlRowValues.getTable()); |
final StringBuilder b = new StringBuilder(); |
for (SQLField sqlField : fieldsToExpand) { |
b.append(sqlRowValues.getObject(sqlField.getName()).toString()); |
b.append(' '); |
} |
object = new StringWithId(rowId, b.toString().trim()); |
} |
values.add(object); |
} else { |
throw new IllegalStateException("No field in " + table + " for column id " + colId); |
} |
} |
r.setValues(values); |
rows.add(r); |
} |
TableContent tableContent = new TableContent(); |
tableContent.setRows(rows); |
// tableContent.setSpec(new RowSpec()); |
tSpec.setContent(tableContent); |
} |
String id = getItemId(); |
final LightUITable eList = new LightUITable(id); |
eList.setTableSpec(tSpec); |
974,8 → 917,74 |
panel.addChild(listLine); |
return panel; |
} |
@Override |
public void fillFrom(LightUIElement uiElement, SQLRowAccessor sqlRow) { |
LightUIPanel p = (LightUIPanel) uiElement; |
LightUITable ltable = p.getFirstChild(LightUITable.class); |
TableSpec tSpec = ltable.getTableSpec(); |
ColumnsSpec columnsSpec = tSpec.getColumns(); |
// send: id,value |
final SQLElement elem = configuration.getDirectory().getElement("DEVIS_ELEMENT"); |
final SQLTable table = elem.getTable(); |
final List<String> fieldsToFetch = new ArrayList<>(); |
for (ColumnSpec cs : columnsSpec.getColumns()) { |
String colId = cs.getId(); |
SQLField f = configuration.getFieldMapper().getSQLFieldForItem(colId); |
if (f != null) { |
fieldsToFetch.add(f.getName()); |
} else { |
throw new IllegalStateException("No field in " + table + " for column id " + colId); |
} |
} |
final Where where = new Where(table.getField("ID_DEVIS"), "=", sqlRow.getID()); |
final ListSQLRequest req = elem.createListRequest(fieldsToFetch, where, configuration.getShowAs()); |
List<SQLRowValues> fetchedRows = req.getValues(); |
List<Row> rows = new ArrayList<>(); |
for (final SQLRowValues vals : fetchedRows) { |
Row r = new Row(vals.getID(), columnsSpec.getColumns().size()); |
List<Object> values = new ArrayList<>(); |
for (ColumnSpec cs : columnsSpec.getColumns()) { |
String colId = cs.getId(); |
SQLField f = configuration.getFieldMapper().getSQLFieldForItem(colId); |
if (f != null) { |
Object object = vals.getObject(f.getName()); |
if (object instanceof SQLRowValues) { |
SQLRowValues sqlRowValues = (SQLRowValues) object; |
long rowId = sqlRowValues.getIDNumber().longValue(); |
List<SQLField> fieldsToExpand = configuration.getShowAs().getFieldExpand(sqlRowValues.getTable()); |
final StringBuilder b = new StringBuilder(); |
for (SQLField sqlField : fieldsToExpand) { |
b.append(sqlRowValues.getObject(sqlField.getName()).toString()); |
b.append(' '); |
} |
object = new StringWithId(rowId, b.toString().trim()); |
} |
values.add(object); |
} else { |
throw new IllegalStateException("No field in " + table + " for column id " + colId); |
} |
} |
r.setValues(values); |
rows.add(r); |
} |
TableContent tableContent = new TableContent(); |
tableContent.setRows(rows); |
tSpec.setContent(tableContent); |
} |
@Override |
public void store(LightUIElement uiElement, SQLRowValues row) { |
// TODO Auto-generated method stub |
} |
}); |
return map; |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/CustomerProductQtyPriceSQLElement.java |
---|
New file |
0,0 → 1,54 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.sales.product.element; |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement; |
import org.openconcerto.sql.element.SQLComponent; |
import java.util.ArrayList; |
import java.util.List; |
public class CustomerProductQtyPriceSQLElement extends ComptaSQLConfElement { |
public static final String ELEMENT_CODE = "sales.customer.product.qty.price"; |
public CustomerProductQtyPriceSQLElement() { |
super("TARIF_ARTICLE_CLIENT"); |
} |
@Override |
protected String createCode() { |
return ELEMENT_CODE; |
} |
@Override |
protected List<String> getListFields() { |
final List<String> l = new ArrayList<String>(); |
l.add("ID_ARTICLE"); |
l.add("QUANTITE"); |
return l; |
} |
@Override |
protected List<String> getComboFields() { |
final List<String> l = new ArrayList<String>(); |
l.add("QUANTITE"); |
return l; |
} |
@Override |
protected SQLComponent createComponent() { |
return null; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/element/ReferenceArticleSQLElement.java |
---|
14,6 → 14,7 |
package org.openconcerto.erp.core.sales.product.element; |
import org.openconcerto.erp.config.ComptaPropsConfiguration; |
import org.openconcerto.erp.config.update.Updater_1_5; |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement; |
import org.openconcerto.erp.core.edm.AttachmentAction; |
import org.openconcerto.erp.core.finance.tax.model.TaxeCache; |
20,9 → 21,7 |
import org.openconcerto.erp.core.reports.history.ui.HistoriqueArticleFrame; |
import org.openconcerto.erp.core.sales.product.action.InventairePanel; |
import org.openconcerto.erp.core.sales.product.component.ReferenceArticleSQLComponent; |
import org.openconcerto.erp.core.supplychain.stock.element.ComposedItemStockUpdater; |
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement; |
import org.openconcerto.erp.core.supplychain.stock.element.StockItem; |
import org.openconcerto.erp.generationDoc.gestcomm.FicheArticleXmlSheet; |
import org.openconcerto.erp.model.MouseSheetXmlListeListener; |
import org.openconcerto.erp.preferences.DefaultNXProps; |
53,7 → 52,6 |
import org.openconcerto.ui.PanelFrame; |
import org.openconcerto.utils.CollectionUtils; |
import org.openconcerto.utils.DecimalUtils; |
import org.openconcerto.utils.ExceptionHandler; |
import org.openconcerto.utils.ListMap; |
import java.awt.event.ActionEvent; |
221,6 → 219,7 |
l.add("SKU"); |
// if (!prefs.getBoolean(GestionArticleGlobalPreferencePanel.STOCK_MULTI_DEPOT, false)) { |
l.add("GESTION_STOCK"); |
l.add("ID_STOCK"); |
// } |
String val = DefaultNXProps.getInstance().getStringProperty("ArticleService"); |
527,58 → 526,9 |
public void initStock(int id) { |
SQLRow row = getTable().getRow(id); |
SQLSelect sel = new SQLSelect(); |
sel.addSelectStar(getTable().getTable("DEPOT_STOCK")); |
List<SQLRow> rowsDepot = SQLRowListRSH.execute(sel); |
SQLSelect selStock = new SQLSelect(); |
selStock.addSelectStar(getTable().getTable("STOCK")); |
selStock.setWhere(new Where(getTable().getTable("STOCK").getField("ID_ARTICLE"), "=", id)); |
List<SQLRow> rowsStock = SQLRowListRSH.execute(selStock); |
Map<Integer, SQLRow> initedDepot = new HashMap<>(); |
for (SQLRow sqlRow : rowsStock) { |
initedDepot.put(sqlRow.getForeignID("ID_DEPOT_STOCK"), sqlRow); |
Updater_1_5.initStock(row); |
} |
List<StockItem> stockItems = new ArrayList<StockItem>(); |
for (SQLRow sqlRow : rowsDepot) { |
try { |
if (!initedDepot.keySet().contains(sqlRow.getID())) { |
SQLRowValues rowVals = new SQLRowValues(getTable().getTable("STOCK")); |
rowVals.put("ID_ARTICLE", row.getID()); |
rowVals.put("ID_DEPOT_STOCK", sqlRow.getID()); |
SQLRow rowStock = rowVals.commit(); |
if ((row.getObject("ID_DEPOT_STOCK") == null || row.isForeignEmpty("ID_DEPOT_STOCK")) && sqlRow.getID() == DepotStockSQLElement.DEFAULT_ID) { |
row.createEmptyUpdateRow().put("ID_STOCK", rowStock.getID()).put("ID_DEPOT_STOCK", DepotStockSQLElement.DEFAULT_ID).commit(); |
} else if (sqlRow.getID() == row.getForeignID("ID_DEPOT_STOCK")) { |
row.createEmptyUpdateRow().put("ID_STOCK", rowStock.getID()).commit(); |
} |
stockItems.add(new StockItem(row, rowStock)); |
} else { |
SQLRow rowExisting = initedDepot.get(sqlRow.getID()); |
if ((row.getObject("ID_DEPOT_STOCK") == null || row.isForeignEmpty("ID_DEPOT_STOCK")) && sqlRow.getID() == DepotStockSQLElement.DEFAULT_ID) { |
row.createEmptyUpdateRow().put("ID_STOCK", rowExisting.getID()).put("ID_DEPOT_STOCK", DepotStockSQLElement.DEFAULT_ID).commit(); |
} else if (sqlRow.getID() == row.getForeignID("ID_DEPOT_STOCK")) { |
row.createEmptyUpdateRow().put("ID_STOCK", rowExisting.getID()).commit(); |
} |
stockItems.add(new StockItem(row, rowExisting)); |
} |
} catch (SQLException e) { |
ExceptionHandler.handle("Erreur lors de l'initialisation du stock de l'article", e); |
} |
} |
if (row.getReferentRows(getTable().getTable("ARTICLE_ELEMENT").getField("ID_ARTICLE_PARENT")).size() > 0) { |
ComposedItemStockUpdater up = new ComposedItemStockUpdater(getTable().getDBRoot(), stockItems); |
try { |
up.updateNomenclature(stockItems); |
} catch (SQLException e) { |
ExceptionHandler.handle("Erreur lors de l'actualisation du stock!", e); |
} |
} |
} |
@Override |
protected String createCode() { |
return createCodeOfPackage() + ".ref"; |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/action/TransfertStockAction.java |
---|
New file |
0,0 → 1,36 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.sales.product.action; |
import org.openconcerto.erp.action.CreateFrameAbstractAction; |
import org.openconcerto.erp.core.common.ui.PanelFrame; |
import org.openconcerto.sql.Configuration; |
import javax.swing.Action; |
import javax.swing.JFrame; |
public class TransfertStockAction extends CreateFrameAbstractAction { |
private Configuration conf; |
public TransfertStockAction(Configuration conf) { |
super(); |
this.conf = conf; |
this.putValue(Action.NAME, "Transfert de stock"); |
} |
public JFrame createFrame() { |
return new PanelFrame(new TransfertStockPanel(this.conf), "Transfert de stocks"); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/action/TransfertStockPanel.java |
---|
New file |
0,0 → 1,337 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.sales.product.action; |
import org.openconcerto.erp.core.common.ui.NumericTextField; |
import org.openconcerto.erp.core.sales.product.model.ProductComponent; |
import org.openconcerto.erp.core.supplychain.stock.element.ComposedItemStockUpdater; |
import org.openconcerto.erp.core.supplychain.stock.element.StockItem; |
import org.openconcerto.erp.core.supplychain.stock.element.StockItem.TypeStockMouvement; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.element.SQLElement; |
import org.openconcerto.sql.model.DBRoot; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.sqlobject.SQLRequestComboBox; |
import org.openconcerto.sql.utils.SQLUtils; |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import org.openconcerto.ui.JDate; |
import org.openconcerto.utils.ExceptionHandler; |
import org.openconcerto.utils.text.SimpleDocumentListener; |
import java.awt.GridBagConstraints; |
import java.awt.GridBagLayout; |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionListener; |
import java.beans.PropertyChangeEvent; |
import java.beans.PropertyChangeListener; |
import java.math.BigDecimal; |
import java.math.RoundingMode; |
import java.sql.SQLException; |
import java.text.SimpleDateFormat; |
import java.util.ArrayList; |
import java.util.Date; |
import java.util.List; |
import javax.swing.JButton; |
import javax.swing.JFrame; |
import javax.swing.JLabel; |
import javax.swing.JPanel; |
import javax.swing.JTextField; |
import javax.swing.SwingConstants; |
import javax.swing.SwingUtilities; |
import javax.swing.event.DocumentEvent; |
import org.apache.commons.dbutils.ResultSetHandler; |
public class TransfertStockPanel extends JPanel { |
private final String mvtStockTableQuoted; |
private static String defaultLabel = "Transfert de stock"; |
public TransfertStockPanel(Configuration instance) { |
super(new GridBagLayout()); |
final JButton buttonUpdate = new JButton("Mettre à jour"); |
final SQLTable mvtStockTable = instance.getRoot().findTable("MOUVEMENT_STOCK"); |
this.mvtStockTableQuoted = mvtStockTable.getSQLName().quote(); |
final SQLElement articleElt = instance.getDirectory().getElement("ARTICLE"); |
final SQLRequestComboBox comboArticle = new SQLRequestComboBox(); |
comboArticle.uiInit(articleElt.createComboRequest()); |
final SQLElement stockElt = instance.getDirectory().getElement("DEPOT_STOCK"); |
final SQLRequestComboBox comboStockDepart = new SQLRequestComboBox(); |
comboStockDepart.uiInit(stockElt.createComboRequest()); |
final SQLRequestComboBox comboStockArrive = new SQLRequestComboBox(); |
comboStockArrive.uiInit(stockElt.createComboRequest()); |
JLabel qteReel = new JLabel("Quantité", SwingConstants.RIGHT); |
final NumericTextField fieldReel = new NumericTextField(); |
fieldReel.getDocument().addDocumentListener(new SimpleDocumentListener() { |
@Override |
public void update(DocumentEvent e) { |
buttonUpdate.setEnabled( |
fieldReel.getText().trim().length() > 0 && comboArticle.getSelectedRow() != null && comboStockArrive.getSelectedRow() != null && comboStockDepart.getSelectedRow() != null); |
} |
}); |
comboArticle.addModelListener("wantedID", new PropertyChangeListener() { |
@Override |
public void propertyChange(PropertyChangeEvent evt) { |
buttonUpdate.setEnabled( |
fieldReel.getText().trim().length() > 0 && comboArticle.getSelectedRow() != null && comboStockArrive.getSelectedRow() != null && comboStockDepart.getSelectedRow() != null); |
} |
}); |
comboStockArrive.addModelListener("wantedID", new PropertyChangeListener() { |
@Override |
public void propertyChange(PropertyChangeEvent evt) { |
buttonUpdate.setEnabled( |
fieldReel.getText().trim().length() > 0 && comboArticle.getSelectedRow() != null && comboStockArrive.getSelectedRow() != null && comboStockDepart.getSelectedRow() != null); |
} |
}); |
comboStockDepart.addModelListener("wantedID", new PropertyChangeListener() { |
@Override |
public void propertyChange(PropertyChangeEvent evt) { |
buttonUpdate.setEnabled( |
fieldReel.getText().trim().length() > 0 && comboArticle.getSelectedRow() != null && comboStockArrive.getSelectedRow() != null && comboStockDepart.getSelectedRow() != null); |
} |
}); |
GridBagConstraints c = new DefaultGridBagConstraints(); |
this.add(new JLabel("Intitulé"), c); |
final JTextField label = new JTextField(); |
c.gridx++; |
c.gridwidth = 2; |
c.weightx = 1; |
this.add(label, c); |
label.setText(defaultLabel); |
c.gridy++; |
c.gridx = 0; |
c.gridwidth = 1; |
c.weightx = 0; |
this.add(new JLabel("Date", SwingConstants.RIGHT), c); |
final JDate date = new JDate(true); |
c.gridx++; |
c.weightx = 0; |
this.add(date, c); |
c.gridy++; |
c.gridx = 0; |
c.gridwidth = 2; |
c.weightx = 0; |
this.add(new JLabel("Article", SwingConstants.RIGHT), c); |
c.gridx += 2; |
c.gridwidth = 1; |
c.weightx = 1; |
this.add(comboArticle, c); |
c.gridy++; |
c.gridx = 0; |
c.gridwidth = 2; |
c.weightx = 0; |
this.add(new JLabel("Départ", SwingConstants.RIGHT), c); |
c.gridx += 2; |
c.gridwidth = 1; |
c.weightx = 1; |
this.add(comboStockDepart, c); |
c.gridy++; |
c.gridx = 0; |
c.gridwidth = 2; |
c.weightx = 0; |
this.add(new JLabel("Arrivée", SwingConstants.RIGHT), c); |
c.gridx += 2; |
c.gridwidth = 1; |
c.weightx = 1; |
this.add(comboStockArrive, c); |
c.gridy++; |
c.gridx = 0; |
c.gridwidth = 2; |
c.weightx = 0; |
this.add(qteReel, c); |
c.gridx += 2; |
c.gridwidth = 1; |
c.weightx = 1; |
this.add(fieldReel, c); |
c.gridy++; |
c.gridx = 0; |
c.gridwidth = 2; |
c.weightx = 0; |
this.add(qteReel, c); |
c.gridx += 2; |
c.gridwidth = 1; |
c.weightx = 1; |
this.add(fieldReel, c); |
c.gridy++; |
c.gridx = 0; |
JButton buttonCancel = new JButton("Annuler"); |
JPanel pButton = new JPanel(); |
pButton.add(buttonCancel); |
pButton.add(buttonUpdate); |
c.gridwidth = GridBagConstraints.REMAINDER; |
c.anchor = GridBagConstraints.EAST; |
c.weightx = 0; |
c.fill = GridBagConstraints.NONE; |
this.add(pButton, c); |
buttonCancel.addActionListener(new ActionListener() { |
@Override |
public void actionPerformed(ActionEvent e) { |
((JFrame) SwingUtilities.getRoot(TransfertStockPanel.this)).dispose(); |
} |
}); |
buttonUpdate.addActionListener(new ActionListener() { |
@Override |
public void actionPerformed(ActionEvent e) { |
buttonUpdate.setEnabled(false); |
defaultLabel = label.getText(); |
BigDecimal qteReel = fieldReel.getValue(); |
List<String> multipleRequestsHundred = new ArrayList<String>(100); |
boolean usePrice = mvtStockTable.contains("PRICE"); |
List<StockItem> stockItems = new ArrayList<StockItem>(); |
final Date dateValue = date.getValue(); |
final SQLRow selectedRowArticle = comboArticle.getSelectedRow(); |
{ |
// DEPART |
final SQLRow selectedRowDepotDepart = comboStockDepart.getSelectedRow(); |
final SQLRowAccessor rowStockDepart = ProductComponent.findOrCreateStock(selectedRowArticle, selectedRowDepotDepart); |
StockItem item = new StockItem(selectedRowArticle, rowStockDepart); |
if (!item.isStockInit()) { |
SQLRowValues rowVals = new SQLRowValues(mvtStockTable.getTable("STOCK")); |
rowVals.put("ID_ARTICLE", selectedRowArticle.getID()); |
rowVals.put("ID_DEPOT_STOCK", selectedRowDepotDepart.getID()); |
try { |
rowVals.commit(); |
} catch (SQLException e1) { |
// TODO Auto-generated catch block |
e1.printStackTrace(); |
} |
selectedRowArticle.fetchValues(); |
item = new StockItem(selectedRowArticle, rowStockDepart); |
} |
stockItems.add(item); |
double diff = -qteReel.doubleValue(); |
item.updateQty(diff, TypeStockMouvement.REEL); |
multipleRequestsHundred.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, label.getText(), true, usePrice)); |
item.updateQty(diff, TypeStockMouvement.THEORIQUE); |
multipleRequestsHundred.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, label.getText(), false, usePrice)); |
multipleRequestsHundred.add(item.getUpdateRequest()); |
} |
// ARRIVEE |
{ |
final SQLRow selectedRowDepotArrivee = comboStockArrive.getSelectedRow(); |
final SQLRowAccessor rowStockArrivee = ProductComponent.findOrCreateStock(selectedRowArticle, selectedRowDepotArrivee); |
StockItem item = new StockItem(selectedRowArticle, rowStockArrivee); |
if (!item.isStockInit()) { |
SQLRowValues rowVals = new SQLRowValues(mvtStockTable.getTable("STOCK")); |
rowVals.put("ID_ARTICLE", selectedRowArticle.getID()); |
rowVals.put("ID_DEPOT_STOCK", selectedRowDepotArrivee.getID()); |
try { |
rowVals.commit(); |
} catch (SQLException e1) { |
// TODO Auto-generated catch block |
e1.printStackTrace(); |
} |
selectedRowArticle.fetchValues(); |
item = new StockItem(selectedRowArticle, rowStockArrivee); |
} |
stockItems.add(item); |
double diff = qteReel.doubleValue(); |
item.updateQty(diff, TypeStockMouvement.REEL); |
multipleRequestsHundred.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, label.getText(), true, usePrice)); |
item.updateQty(diff, TypeStockMouvement.THEORIQUE); |
multipleRequestsHundred.add(getMvtRequest(dateValue, BigDecimal.ZERO, diff, item, label.getText(), false, usePrice)); |
multipleRequestsHundred.add(item.getUpdateRequest()); |
} |
try { |
final int size = multipleRequestsHundred.size(); |
List<? extends ResultSetHandler> handlers = new ArrayList<ResultSetHandler>(size); |
for (int i = 0; i < size; i++) { |
handlers.add(null); |
} |
SQLUtils.executeMultiple(instance.getRoot().getDBSystemRoot(), multipleRequestsHundred, handlers); |
} catch (SQLException e1) { |
ExceptionHandler.handle("Stock update error", e1); |
} |
final DBRoot root = mvtStockTable.getDBRoot(); |
if (root.contains("ARTICLE_ELEMENT")) { |
// List<StockItem> stockItems = new ArrayList<StockItem>(); |
// for (SQLRowAccessor sqlRowAccessor2 : stocks) { |
// final SQLRow asRow = sqlRowAccessor2.asRow(); |
// asRow.fetchValues(); |
// stockItems.add(new StockItem(asRow)); |
// } |
// Mise à jour des stocks des nomenclatures |
ComposedItemStockUpdater comp = new ComposedItemStockUpdater(root, stockItems); |
try { |
comp.update(); |
} catch (SQLException e1) { |
e1.printStackTrace(); |
} |
} |
// liste.getModel().updateAll(); |
((JFrame) SwingUtilities.getRoot(TransfertStockPanel.this)).dispose(); |
} |
}); |
} |
private String getMvtRequest(Date time, BigDecimal prc, double qteFinal, StockItem item, String label, boolean reel, boolean usePrice) { |
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
String mvtStockQuery = "INSERT INTO " + mvtStockTableQuoted + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"ID_STOCK\",\"NOM\",\"REEL\",\"ORDRE\""; |
if (usePrice && prc != null) { |
mvtStockQuery += ",\"PRICE\""; |
} |
mvtStockQuery += ") VALUES(" + qteFinal + ",'" + dateFormat.format(time) + "'," + item.getArticle().getID() + "," + item.stock.getID() + ",'" + label + "'," + reel |
+ ", (SELECT (MAX(\"ORDRE\")+1) FROM " + mvtStockTableQuoted + ")"; |
if (usePrice && prc != null) { |
mvtStockQuery += "," + prc.setScale(6, RoundingMode.HALF_UP).toString(); |
} |
mvtStockQuery += ")"; |
return mvtStockQuery; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/ui/CustomerProductQtyPriceListTable.java |
---|
New file |
0,0 → 1,120 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.sales.product.ui; |
import org.openconcerto.sql.Configuration; |
import org.openconcerto.sql.element.SQLElement; |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.view.list.RowValuesTable; |
import org.openconcerto.sql.view.list.RowValuesTableControlPanel; |
import org.openconcerto.sql.view.list.RowValuesTableModel; |
import org.openconcerto.sql.view.list.RowValuesTablePanel; |
import org.openconcerto.sql.view.list.RowValuesTableRenderer; |
import org.openconcerto.sql.view.list.SQLTableElement; |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import org.openconcerto.ui.table.PercentTableCellRenderer; |
import java.awt.GridBagConstraints; |
import java.awt.GridBagLayout; |
import java.math.BigDecimal; |
import java.util.List; |
import java.util.Vector; |
import javax.swing.JPanel; |
import javax.swing.JScrollPane; |
import javax.swing.ScrollPaneConstants; |
public class CustomerProductQtyPriceListTable extends RowValuesTablePanel { |
public CustomerProductQtyPriceListTable() { |
init(); |
uiInit(); |
} |
/** |
* |
*/ |
protected void init() { |
final SQLElement e = getSQLElement(); |
final List<SQLTableElement> list = new Vector<SQLTableElement>(); |
final SQLTableElement tableElementClient = new SQLTableElement(e.getTable().getField("ID_ARTICLE")); |
list.add(tableElementClient); |
// final SQLTableElement eQuantity = new SQLTableElement(e.getTable().getField("QUANTITE")) |
// { |
// @Override |
// protected Object getDefaultNullValue() { |
// return BigDecimal.ONE; |
// } |
// }; |
// list.add(eQuantity); |
SQLTableElement eltPourcent = new SQLTableElement(e.getTable().getField("POURCENT_REMISE")); |
list.add(eltPourcent); |
this.model = new RowValuesTableModel(e, list, e.getTable().getField("ID_ARTICLE"), false, this.defaultRowVals); |
this.table = new RowValuesTable(this.model, null); |
eltPourcent.setRenderer(new PercentTableCellRenderer()); |
} |
public SQLElement getSQLElement() { |
return Configuration.getInstance().getDirectory().getElement("TARIF_ARTICLE_CLIENT"); |
} |
public void insertFrom(String field, SQLRowValues row) { |
this.table.insertFrom(field, row); |
} |
protected void uiInit() { |
// Ui init |
this.setLayout(new GridBagLayout()); |
this.setOpaque(false); |
final GridBagConstraints c = new DefaultGridBagConstraints(); |
c.weightx = 1; |
c.gridx = 0; |
final JPanel control = new RowValuesTableControlPanel(this.table); |
control.setOpaque(false); |
this.add(control, c); |
c.gridy++; |
c.fill = GridBagConstraints.BOTH; |
c.weighty = 1; |
c.weightx = 1; |
JScrollPane comp = new JScrollPane(this.table); |
comp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); |
this.add(comp, c); |
this.table.setDefaultRenderer(Long.class, new RowValuesTableRenderer()); |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/ui/DeliveredQtyRowValuesRenderer.java |
---|
45,8 → 45,15 |
public final static Color lightBlack = new Color(192, 192, 192); |
public final static Color lightBlackGrey = new Color(155, 155, 155); |
private final boolean customer; |
public DeliveredQtyRowValuesRenderer() { |
this(true); |
} |
public DeliveredQtyRowValuesRenderer(boolean customer) { |
AlternateTableCellRenderer.setBGColorMap(this, CollectionUtils.createMap(lightBlack, lightBlackGrey, red, redLightGrey, orange, orangeGrey)); |
this.customer = customer; |
} |
@Override |
60,8 → 67,15 |
RowValuesTableModel model = ((RowValuesTable) table).getRowValuesTableModel(); |
SQLRowValues rowVals = model.getRowValuesAt(row); |
Number qte = (Number) rowVals.getObject("QTE"); |
Number qteL = (Number) rowVals.getObject("QTE_LIVREE"); |
Number qte; |
Number qteL; |
if (this.customer) { |
qte = (Number) rowVals.getObject("QTE"); |
qteL = (Number) rowVals.getObject("QTE_LIVREE"); |
} else { |
qte = (Number) rowVals.getObject("QTE_ORIGINE"); |
qteL = (Number) rowVals.getObject("QTE"); |
} |
if (qte != null && qteL != null) { |
if (qte.intValue() < qteL.intValue()) { |
comp.setBackground(red); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/ui/CurrencyWithSymbolRenderer.java |
---|
34,6 → 34,8 |
private final FieldPath fieldPath; |
private final CurrencyConverter c; |
private boolean hideZeroValue = false; |
private String getSymbol(String currencyCode) { |
// Because Java Currency return PLN as Symbol for Zl, we use our own talbe |
return org.openconcerto.erp.core.finance.accounting.model.Currency.getSymbol(currencyCode); |
46,6 → 48,10 |
this(null); |
} |
public void setHideZeroValue(boolean hideZeroValue) { |
this.hideZeroValue = hideZeroValue; |
} |
/** |
* Affiche une valeur monétaire en ajoutant le symbole de la devise du path |
* |
60,8 → 66,13 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
if (value != null) { |
value = GestionDevise.currencyToString((BigDecimal) value); |
BigDecimal amount = (BigDecimal) value; |
if (this.hideZeroValue && amount.signum() == 0) { |
value = ""; |
} else { |
value = GestionDevise.currencyToString(amount); |
if (fieldPath == null) { |
value = value + " " + getSymbol(c.getCompanyCurrencyCode()); |
} else { |
78,7 → 89,8 |
// reprend |
// pas les valeurs de la SQLRow (ex : si on veut récupérer la devise du |
// fournisseur |
// sélectionné, getDistantRow ira chercher la valeur du fournisseur référencé en |
// sélectionné, getDistantRow ira chercher la valeur du fournisseur |
// référencé en |
// BDD |
// et non dans la SQLRow) |
108,6 → 120,7 |
} |
} |
} |
} |
setHorizontalAlignment(SwingConstants.RIGHT); |
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/ui/QteAcommanderRenderer.java |
---|
New file |
0,0 → 1,50 |
/* |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
* |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved. |
* |
* The contents of this file are subject to the terms of the GNU General Public License Version 3 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific |
* language governing permissions and limitations under the License. |
* |
* When distributing the software, include this License Header Notice in each file. |
*/ |
package org.openconcerto.erp.core.sales.product.ui; |
import org.openconcerto.erp.core.common.ui.DeviseNiceTableCellRenderer; |
import org.openconcerto.ui.table.AlternateTableCellRenderer; |
import java.awt.Color; |
import java.awt.Component; |
import javax.swing.JLabel; |
import javax.swing.JTable; |
import javax.swing.SwingConstants; |
public class QteAcommanderRenderer extends DeviseNiceTableCellRenderer { |
private final static Color green = new Color(225, 254, 207); |
private final static Color greenDark = new Color(205, 234, 187); |
public QteAcommanderRenderer() { |
AlternateTableCellRenderer.setBGColorMap(this, green, greenDark); |
} |
@Override |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
((JLabel) comp).setHorizontalAlignment(SwingConstants.RIGHT); |
if (value != null) { |
Float b = (Float) value; |
if (b <= 0) { |
comp.setBackground(green); |
} |
} |
return comp; |
} |
} |
/trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/product/model/ProductHelper.java |
---|
74,6 → 74,44 |
return result; |
} |
/** |
* Fill productComponents with items (SQLrowAccessor of TABLE_ELEMENT) |
* |
* @param items |
* @param productComponents |
* @param qte |
* @param index |
* @param level |
*/ |
public void fillProductComponent(List<? extends SQLRowAccessor> itemsTableElement, List<ProductComponent> productComponents, int qte, int index, int level) { |
if (level > 0) { |
for (int i = index; i < itemsTableElement.size(); i++) { |
SQLRowAccessor r = itemsTableElement.get(i); |
if (!r.getTable().contains("NIVEAU") || r.getInt("NIVEAU") >= level) { |
// On ne calcul pas les stocks pour les éléments ayant des fils (le mouvement de |
// stock |
// des fils impactera les stocks automatiquement) |
if (r.getTable().contains("NIVEAU")) { |
if (i + 1 < itemsTableElement.size()) { |
SQLRowAccessor rNext = itemsTableElement.get(i + 1); |
if (rNext.getInt("NIVEAU") > r.getInt("NIVEAU")) { |
fillProductComponent(itemsTableElement, productComponents, qte * r.getInt("QTE"), i + 1, rNext.getInt("NIVEAU")); |
continue; |
} |
} |
} |
if ((!r.getTable().contains("NIVEAU") || r.getInt("NIVEAU") == level) && r.getForeign("ID_ARTICLE") != null && !r.isForeignEmpty("ID_ARTICLE")) { |
productComponents.add(ProductComponent.createFrom(r, qte, r)); |
} |
} else if (r.getInt("NIVEAU") < level) { |
// BREAK si on sort de l'article composé |
break; |
} |
} |
} |
} |
public BigDecimal getUnitCostForQuantity(SQLRowAccessor rArticle, int qty) { |
Collection<? extends SQLRowAccessor> l = rArticle.getReferentRows(rArticle.getTable().getTable("ARTICLE_PRIX_REVIENT")); |
246,7 → 284,7 |
SQLRowValues rowVals = new SQLRowValues(costTable); |
final SQLRowValues artRowValues = rowVals.putRowValues("ID_ARTICLE").putNulls("ID", "GESTION_STOCK", "CODE", "NOM", "ID_DEPOT_STOCK |