public void updateSelection(int[] rowIndex) { System.err.println("Update Selection"); this.creditSelection = 0; this.debitSelection = 0; if (rowIndex != null) { for (int i = 0; i < rowIndex.length; i++) { SQLRow row = tableEcr.getRow(rowIndex[i]); if (row != null) { // if (row.getString("POINTEE").trim().length() == 0) { this.debitSelection += ((Long) row.getObject("DEBIT")).longValue(); this.creditSelection += ((Long) row.getObject("CREDIT")).longValue(); // } /* * else { * * this.debitSelection -= row.getFloat("DEBIT"); this.creditSelection -= * row.getFloat("CREDIT"); } */ } } } this.fireTableDataChanged(); }
public SuppressionEcrituresPanel(final int idMvt) { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); c.weightx = 1; SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete(); SQLTable tableMouvement = base.getTable("MOUVEMENT"); SQLRow rowMvt = tableMouvement.getRow(idMvt); JLabel label = new JLabel("Vous allez supprimer la piéce n°" + rowMvt.getInt("ID_PIECE")); JLabelWarning warning = new JLabelWarning(); JPanel panelLabel = new JPanel(); panelLabel.add(warning); panelLabel.add(label); c.gridwidth = GridBagConstraints.REMAINDER; this.add(panelLabel, c); // TODO afficher les numeros de mouvement implique int[] idS = getMouvement(rowMvt.getInt("ID_PIECE")); if (idS == null) { ExceptionHandler.handle( "Aucun mouvement associé à la piéce n°" + ((rowMvt != null) ? rowMvt.getInt("ID_PIECE") : "mouvement nul")); } else { StringBuffer s = new StringBuffer(); s.append("Elle est composée par les mouvements : ("); JLabel labelMouv = new JLabel(); // c.gridwidth = 1; c.gridy++; c.gridx = 0; this.add(labelMouv, c); s.append(idS[0]); for (int i = 1; i < idS.length; i++) { s.append(", "); s.append(idS[i]); } s.append(')'); labelMouv.setText(s.toString()); } JButton buttonOK = new JButton("OK"); JButton buttonCancel = new JButton("Annuler"); c.gridwidth = 1; c.gridy++; c.gridx = 0; this.add(buttonOK, c); c.gridx++; this.add(buttonCancel, c); buttonOK.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { EcritureSQLElement elt = (EcritureSQLElement) Configuration.getInstance().getDirectory().getElement("ECRITURE"); elt.archiveMouvement(idMvt); ((JFrame) SwingUtilities.getRoot(SuppressionEcrituresPanel.this)).dispose(); } }); buttonCancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ((JFrame) SwingUtilities.getRoot(SuppressionEcrituresPanel.this)).dispose(); } }); }
public static void fixUserCommon(int base) { if (Configuration.getInstance() == null) { Configuration.setInstance(ComptaPropsConfiguration.create()); } Configuration instance = Configuration.getInstance(); SQLTable tableSociete = Configuration.getInstance().getBase().getTable("SOCIETE_COMMON"); String baseName = tableSociete.getRow(base).getString("DATABASE_NAME"); instance.getBase().getDBSystemRoot().getRootsToMap().clear(); try { Set<String> s = new HashSet<String>(); s.add(baseName); instance.getBase().fetchTables(s); } catch (SQLException e) { throw new IllegalStateException("could not access societe base", e); } System.err.println("baseName" + baseName); instance.getSystemRoot().prependToRootPath("Common"); instance.getSystemRoot().prependToRootPath(baseName); SQLSchema baseSQL = instance.getBase().getSchema(baseName); DatabaseMetaData dbMetaDataSociete; try { dbMetaDataSociete = baseSQL.getBase().getDataSource().getConnection().getMetaData(); String[] type = new String[1]; type[0] = "TABLE"; ResultSet rs = dbMetaDataSociete.getTables("", baseSQL.getName(), "%", null); System.err.println("Start " + rs.getFetchSize()); int i = 0; while (rs.next()) { if (rs.getString("TABLE_TYPE") != null && rs.getString("TABLE_TYPE").equalsIgnoreCase("TABLE")) { // System.err.println("FIND TABLE"); // baseSQL.getTableNames(); final SQLTable table = baseSQL.getTable(rs.getString("TABLE_NAME")); Set<SQLField> s = table.getFields(); for (SQLField field : s) { if (field.getName().equalsIgnoreCase("ID_USER_COMMON_CREATE") || field.getName().equalsIgnoreCase("ID_USER_COMMON_MODIFY")) { Object o = field.getDefaultValue(); if (o == null || (o instanceof Integer && ((Integer) o) == 0)) { System.err.println("Bad default on " + field); baseSQL .getBase() .execute( "ALTER TABLE \"" + field.getTable().getSchema().getName() + "\".\"" + field.getTable().getName() + "\" ALTER COLUMN \"" + field.getName() + "\" SET DEFAULT 1;"); baseSQL .getBase() .execute( "UPDATE \"" + field.getTable().getSchema().getName() + "\".\"" + field.getTable().getName() + "\" SET \"" + field.getName() + "\"=1 WHERE \"" + field.getName() + "\"=0 OR \"" + field.getName() + "\" IS NULL;"); } } } } // System.err.println(i++ + " " + rs.getString("TABLE_TYPE")); } rs.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * Affiche si il y a des différences entre les tables de base et baseDefault * * @param base * @param baseDefault */ public static void compareDB(int base, int baseDefault) { try { if (Configuration.getInstance() == null) { Configuration.setInstance(ComptaPropsConfiguration.create()); } Configuration instance = Configuration.getInstance(); SQLTable tableSociete = Configuration.getInstance().getBase().getTable("SOCIETE_COMMON"); String baseName = tableSociete.getRow(base).getString("DATABASE_NAME"); String baseDefaultName = tableSociete.getRow(baseDefault).getString("DATABASE_NAME"); instance.getBase().getDBSystemRoot().getRootsToMap().clear(); try { Set<String> s = new HashSet<String>(); s.add(baseName); s.add(baseDefaultName); instance.getBase().fetchTables(s); } catch (SQLException e) { throw new IllegalStateException("could not access societe base", e); } // instance.getBase().getDBRoot(baseName); // instance.getBase().getDBRoot(baseDefaultName); System.err.println("baseName" + baseName); System.err.println("baseDefault" + baseDefaultName); instance.getSystemRoot().prependToRootPath("Common"); instance.getSystemRoot().prependToRootPath(baseName); instance.getSystemRoot().prependToRootPath(baseDefaultName); SQLSchema baseSQL = instance.getBase().getSchema(baseName); SQLSchema baseSQLDefault = instance.getBase().getSchema(baseDefaultName); DatabaseMetaData dbMetaDataSociete = baseSQL.getBase().getDataSource().getConnection().getMetaData(); DatabaseMetaData dbMetaDataSocieteDefault = baseSQLDefault.getBase().getDataSource().getConnection().getMetaData(); Map<String, Map<String, SQLField>> mapTableSociete = new HashMap<String, Map<String, SQLField>>(); Map<String, Map<String, SQLField>> mapTableSocieteDefault = new HashMap<String, Map<String, SQLField>>(); ResultSet rs = dbMetaDataSociete.getTables("", baseSQL.getName(), "%", null); System.err.println("Start"); while (rs.next()) { // System.err.println(rs.getString("TABLE_NAME") + ", TYPE ::" + // rs.getString("TABLE_TYPE")); if (rs.getString("TABLE_TYPE") != null && rs.getString("TABLE_TYPE").equalsIgnoreCase("TABLE")) { Map<String, SQLField> m = new HashMap<String, SQLField>(); baseSQL.getTableNames(); Set<SQLField> s = baseSQL.getTable(rs.getString("TABLE_NAME")).getFields(); for (SQLField field : s) { m.put(field.getName(), field); } mapTableSociete.put(rs.getString("TABLE_NAME"), m); } } rs.close(); rs = dbMetaDataSocieteDefault.getTables("", baseSQLDefault.getName(), "%", null); while (rs.next()) { // System.err.println(rs.getString("TABLE_NAME") + ", TYPE ::" + // rs.getString("TABLE_TYPE")); if (rs.getString("TABLE_TYPE") != null && rs.getString("TABLE_TYPE").equalsIgnoreCase("TABLE")) { Map<String, SQLField> m = new HashMap<String, SQLField>(); Set<SQLField> s = baseSQLDefault.getTable(rs.getString("TABLE_NAME")).getFields(); for (SQLField field : s) { m.put(field.getName(), field); } mapTableSocieteDefault.put(rs.getString("TABLE_NAME"), m); } } rs.close(); System.err.println("Test 1 " + mapTableSociete.keySet().size()); // On verifie que toutes les tables de la societe sont contenues dans la base default for (String tableName : mapTableSociete.keySet()) { if (!mapTableSocieteDefault.containsKey(tableName)) { System.err.println( "!! **** La table " + tableName + " n'est pas dans la base " + baseDefault); } else { Map<String, SQLField> mSoc = mapTableSociete.get(tableName); Map<String, SQLField> mDef = mapTableSocieteDefault.get(tableName); if (mSoc.keySet().containsAll(mDef.keySet())) { if (mSoc.keySet().size() == mDef.keySet().size()) { System.err.println("Table " + tableName + " --- OK"); compareTypeField(mSoc, mDef); } else { if (mSoc.keySet().size() > mDef.keySet().size()) { for (String fieldName : mDef.keySet()) { mSoc.remove(fieldName); } System.err.println("!! **** Difference Table " + tableName); System.err.println( tableSociete.getRow(baseDefault).getString("DATABASE_NAME") + " Set Column " + mSoc); System.err.println( getAlterTable( mSoc, tableSociete.getRow(baseDefault).getString("DATABASE_NAME"), tableName)); } else { } } } else { // System.err.println("!! **** Difference Table " + tableName); // System.err.println(tableSociete.getRow(base).getString("DATABASE_NAME") + // " Set Column " + mapTableSociete.get(tableName)); // System.err.println(tableSociete.getRow(baseDefault).getString("DATABASE_NAME") // + " Set Column " + mapTableSocieteDefault.get(tableName)); for (String fieldName : mSoc.keySet()) { mDef.remove(fieldName); } System.err.println("!! **** Difference Table " + tableName); System.err.println( tableSociete.getRow(base).getString("DATABASE_NAME") + " Set Column " + mDef); System.err.println( getAlterTable( mDef, tableSociete.getRow(base).getString("DATABASE_NAME"), tableName)); } } } System.err.println("Test 2 " + mapTableSocieteDefault.keySet().size()); // On verifie que toutes les tables de la base default sont contenues dans la base // societe for (Iterator i = mapTableSocieteDefault.keySet().iterator(); i.hasNext(); ) { Object tableName = i.next(); if (!mapTableSociete.containsKey(tableName)) { System.err.println( "!! **** La table " + tableName + " n'est pas dans la base " + baseDefault); } } SQLSchema schem = instance.getBase().getSchema("Common"); } catch (SQLException e) { e.printStackTrace(); } }
private void genereMouvement() throws IllegalArgumentException { SQLRow saisieRow = GenerationMvtSaisieVenteComptoir.saisieVCTable.getRow(this.idSaisieVenteComptoir); SQLRow clientRow = base.getTable("CLIENT").getRow(saisieRow.getInt("ID_CLIENT")); SQLRow taxeRow = base.getTable("TAXE").getRow(saisieRow.getInt("ID_TAXE")); // Calcul des montants PrixTTC prixTTC = new PrixTTC(((Long) saisieRow.getObject("MONTANT_TTC")).longValue()); PrixHT prixHT = new PrixHT(prixTTC.calculLongHT(taxeRow.getFloat("TAUX") / 100)); long service = ((Long) saisieRow.getObject("MONTANT_SERVICE")).longValue(); // iniatilisation des valeurs de la map this.date = (Date) saisieRow.getObject("DATE"); String string = "Vente comptoir "; final String rowLib = saisieRow.getObject("NOM").toString(); if (rowLib != null && rowLib.trim().length() > 0) { string += rowLib.trim(); } else { string += saisieRow.getForeignRow("ID_ARTICLE").getString("NOM"); } this.nom = string; this.mEcritures.put("DATE", this.date); this.mEcritures.put("NOM", this.nom); this.mEcritures.put("ID_JOURNAL", GenerationMvtSaisieVenteComptoir.journal); this.mEcritures.put("ID_MOUVEMENT", new Integer(1)); // on calcule le nouveau numero de mouvement if (this.idMvt == 1) { this.idMvt = getNewMouvement( GenerationMvtSaisieVenteComptoir.source, this.idSaisieVenteComptoir, 1, string); this.mEcritures.put("ID_MOUVEMENT", new Integer(this.idMvt)); } // generation des ecritures + maj des totaux du compte associe // compte Vente if (service != 0) { int idCompteVenteService = rowPrefsCompte.getInt("ID_COMPTE_PCE_VENTE_SERVICE"); if (idCompteVenteService <= 1) { try { idCompteVenteService = ComptePCESQLElement.getIdComptePceDefault("VentesServices"); } catch (Exception e) { e.printStackTrace(); } } this.mEcritures.put("ID_COMPTE_PCE", new Integer(idCompteVenteService)); this.mEcritures.put("DEBIT", new Long(0)); this.mEcritures.put("CREDIT", new Long(service)); ajoutEcriture(); // System.out.println("___________---> Value " + (prixHT.getValue() - service)); if ((prixHT.getLongValue() - service) > 0) { int idCompteVenteProduit = rowPrefsCompte.getInt("ID_COMPTE_PCE_VENTE_PRODUIT"); if (idCompteVenteProduit <= 1) { try { idCompteVenteProduit = ComptePCESQLElement.getIdComptePceDefault("VentesProduits"); } catch (Exception e) { e.printStackTrace(); } } this.mEcritures.put("ID_COMPTE_PCE", new Integer(idCompteVenteProduit)); this.mEcritures.put("DEBIT", new Long(0)); this.mEcritures.put("CREDIT", new Long(prixHT.getLongValue() - service)); ajoutEcriture(); } } else { int idCompteVenteProduit = rowPrefsCompte.getInt("ID_COMPTE_PCE_VENTE_PRODUIT"); if (idCompteVenteProduit <= 1) { try { idCompteVenteProduit = ComptePCESQLElement.getIdComptePceDefault("VentesProduits"); } catch (Exception e) { e.printStackTrace(); } } this.mEcritures.put("ID_COMPTE_PCE", new Integer(idCompteVenteProduit)); this.mEcritures.put("DEBIT", new Long(0)); this.mEcritures.put("CREDIT", new Long(prixHT.getLongValue())); ajoutEcriture(); } // compte TVA long tva = prixTTC.calculLongTVA(taxeRow.getFloat("TAUX") / 100.0); if (tva > 0) { int idCompteTVA = rowPrefsCompte.getInt("ID_COMPTE_PCE_TVA_VENTE"); if (idCompteTVA <= 1) { try { idCompteTVA = ComptePCESQLElement.getIdComptePceDefault("TVACollectee"); } catch (Exception e) { e.printStackTrace(); } } this.mEcritures.put("ID_COMPTE_PCE", new Integer(idCompteTVA)); this.mEcritures.put("DEBIT", new Long(0)); this.mEcritures.put("CREDIT", new Long(tva)); ajoutEcriture(); } // compte Clients int idCompteClient = clientRow.getInt("ID_COMPTE_PCE"); if (idCompteClient <= 1) { idCompteClient = rowPrefsCompte.getInt("ID_COMPTE_PCE_CLIENT"); if (idCompteClient <= 1) { try { idCompteClient = ComptePCESQLElement.getIdComptePceDefault("Clients"); } catch (Exception e) { e.printStackTrace(); } } } this.mEcritures.put("ID_COMPTE_PCE", new Integer(idCompteClient)); this.mEcritures.put("DEBIT", new Long(prixTTC.getLongValue())); this.mEcritures.put("CREDIT", new Long(0)); ajoutEcriture(); // Règlement String s = "Vente comptoir "; final String name = saisieRow.getObject("NOM").toString(); if (name != null && rowLib.trim().length() > 0) { s += name.trim(); } else { s += saisieRow.getForeignRow("ID_ARTICLE").getString("NOM"); } SQLRow modeRegRow = saisieRow.getForeignRow("ID_MODE_REGLEMENT"); new GenerationReglementVenteNG( s, clientRow, prixTTC, this.date, modeRegRow, saisieRow, mvtTable.getRow(this.idMvt)); // On place le nuemro de mouvement associe à la saisie SQLRowValues valSaisieVC = new SQLRowValues(GenerationMvtSaisieVenteComptoir.saisieVCTable); valSaisieVC.put("ID_MOUVEMENT", new Integer(this.idMvt)); try { if (valSaisieVC.getInvalid() == null) { // ajout de l'ecriture valSaisieVC.update(this.idSaisieVenteComptoir); } } catch (SQLException e) { System.err.println( "Erreur à l'insertion dans la table " + valSaisieVC.getTable().getName() + " : " + e); e.printStackTrace(); } }
public void run() { SQLRow rowPrefCompte = tablePrefCompte.getRow(2); this.rowPrefCompteVals.loadAbsolutelyAll(rowPrefCompte); // TVA Coll int idCompteTVACol = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_TVA_VENTE"); if (idCompteTVACol <= 1) { String compte; try { compte = ComptePCESQLElement.getComptePceDefault("TVACollectee"); idCompteTVACol = ComptePCESQLElement.getId(compte); } catch (Exception e) { e.printStackTrace(); } } SQLRow rowCompteTVACol = tableCompte.getRow(idCompteTVACol); // TVA Ded int idCompteTVADed = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_TVA_ACHAT"); if (idCompteTVADed <= 1) { try { String compte = ComptePCESQLElement.getComptePceDefault("TVADeductible"); idCompteTVADed = ComptePCESQLElement.getId(compte); } catch (Exception e) { e.printStackTrace(); } } SQLRow rowCompteTVADed = tableCompte.getRow(idCompteTVADed); // TVA intracomm int idCompteTVAIntra = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_TVA_INTRA"); if (idCompteTVAIntra <= 1) { try { String compte = ComptePCESQLElement.getComptePceDefault("TVAIntraComm"); idCompteTVAIntra = ComptePCESQLElement.getId(compte); } catch (Exception e) { e.printStackTrace(); } } SQLRow rowCompteTVAIntra = tableCompte.getRow(idCompteTVAIntra); // Achats intracomm int idCompteAchatsIntra = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_ACHAT_INTRA"); if (idCompteAchatsIntra <= 1) { try { String compte = ComptePCESQLElement.getComptePceDefault("AchatsIntra"); idCompteAchatsIntra = ComptePCESQLElement.getId(compte); } catch (Exception e) { e.printStackTrace(); } } SQLRow rowCompteAchatIntra = tableCompte.getRow(idCompteAchatsIntra); // TVA immo int idCompteTVAImmo = this.rowPrefCompteVals.getInt("ID_COMPTE_PCE_TVA_IMMO"); if (idCompteTVAImmo <= 1) { try { String compte = ComptePCESQLElement.getComptePceDefault("TVAImmo"); idCompteTVAImmo = ComptePCESQLElement.getId(compte); } catch (Exception e) { e.printStackTrace(); } } SQLRow rowCompteTVAImmo = tableCompte.getRow(idCompteTVAImmo); PdfGenerator_3310 p = new PdfGenerator_3310(); this.m = new HashMap<String, Object>(); long v010 = -this.sommeCompte.soldeCompte(70, 70, true, this.dateDebut, this.dateFin); this.m.put("A01", GestionDevise.round(v010)); // long vA02 = this.sommeCompte.soldeCompte(70, 70, true, this.dateDebut, this.dateFin); this.m.put("A02", ""); long tvaIntra = -this.sommeCompte.sommeCompteFils( rowCompteTVAIntra.getString("NUMERO"), new Date(100, 0, 1), this.dateFin); long achatsIntra = this.sommeCompte.sommeCompteFils( rowCompteAchatIntra.getString("NUMERO"), this.dateDebut, this.dateFin); this.m.put("A03", GestionDevise.round(achatsIntra)); this.m.put("A04", ""); this.m.put("A05", ""); this.m.put("A06", ""); this.m.put("A07", ""); long tvaCol = -this.sommeCompte.sommeCompteFils( rowCompteTVACol.getString("NUMERO"), new Date(100, 0, 1), this.dateFin) + tvaIntra; this.m.put("B08", GestionDevise.round(tvaCol)); this.m.put("B08HT", GestionDevise.round(Math.round(tvaCol / 0.196))); this.m.put("B09", ""); this.m.put("B09HT", ""); this.m.put("B09B", ""); this.m.put("B09BHT", ""); this.m.put("B10", ""); this.m.put("B10HT", ""); this.m.put("B11", ""); this.m.put("B11HT", ""); this.m.put("B12", ""); this.m.put("B12HT", ""); this.m.put("B13", ""); this.m.put("B13HT", ""); this.m.put("B14", ""); this.m.put("B14HT", ""); this.m.put("B15", ""); this.m.put("B16", GestionDevise.round(tvaCol)); this.m.put("B17", GestionDevise.round(tvaIntra)); this.m.put("B18", ""); long tvaImmo = this.sommeCompte.sommeCompteFils( rowCompteTVAImmo.getString("NUMERO"), new Date(100, 0, 1), this.dateFin); this.m.put("B19", GestionDevise.round(tvaImmo)); long tvaAutre = this.sommeCompte.sommeCompteFils( rowCompteTVADed.getString("NUMERO"), new Date(100, 0, 1), this.dateFin); this.m.put("B20", GestionDevise.round(tvaAutre)); this.m.put("B21", ""); this.m.put("B22", ""); this.m.put("B23", ""); long tvaDed = tvaAutre + tvaImmo; this.m.put("B24", GestionDevise.round(tvaDed)); this.m.put("C25", ""); this.m.put("C26", ""); this.m.put("C27", ""); this.m.put("C28", GestionDevise.round(tvaCol - tvaDed)); this.m.put("C29", ""); this.m.put("C30", ""); this.m.put("C31", ""); this.m.put("C32", GestionDevise.round(tvaCol - tvaDed)); p.generateFrom(this.m); SwingUtilities.invokeLater( new Runnable() { public void run() { Map3310.this.bar.setValue(95); } }); SwingUtilities.invokeLater( new Runnable() { public void run() { String file = TemplateNXProps.getInstance().getStringProperty("Location3310PDF") + File.separator + String.valueOf(Calendar.getInstance().get(Calendar.YEAR)) + File.separator + "result_3310_2.pdf"; System.err.println(file); File f = new File(file); Gestion.openPDF(f); Map3310.this.bar.setValue(100); } }); }