Ejemplo n.º 1
0
  // Lettre la ligne passée en parametre
  private void actionLettrage(int[] rowIndex) {
    String codeLettre = this.codeLettrage.getText().trim();

    List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);

    long solde = 0;
    for (int i = 0; i < rowIndex.length; i++) {
      int id = this.ecriturePanel.getListe().idFromIndex(rowIndex[i]);
      SQLRow row = this.tableEcr.getRow(id);
      rowsSelected.add(row);

      solde += ((Long) row.getObject("DEBIT")).longValue();
      solde -= ((Long) row.getObject("CREDIT")).longValue();
    }

    if (solde == 0) {

      for (SQLRow row2 : rowsSelected) {

        SQLRowValues rowVals = new SQLRowValues(this.tableEcr);

        // Lettrage
        // On lettre ou relettre la ligne avec le code saisi
        if (codeLettre.length() > 0) {

          // Si la ligne est en brouillard on valide le mouvement associé
          if (this.boxValidEcriture.isSelected() && (!row2.getBoolean("VALIDE"))) {
            EcritureSQLElement.validationEcritures(row2.getInt("ID_MOUVEMENT"));
          }

          rowVals.put("LETTRAGE", codeLettre);
          rowVals.put("DATE_LETTRAGE", this.dateLettrage.getDate());
          try {
            rowVals.update(row2.getID());
          } catch (SQLException e1) {

            e1.printStackTrace();
          }
        }
      }
      // Mise à jour du code de lettrage
      SQLElement elt = Configuration.getInstance().getDirectory().getElement("NUMEROTATION_AUTO");
      SQLRowValues rowVals = elt.getTable().getRow(2).createEmptyUpdateRow();
      rowVals.put("CODE_LETTRAGE", codeLettre);
      try {
        rowVals.update();
      } catch (SQLException e) {
        e.printStackTrace();
      }
      this.codeLettrage.setText(NumerotationAutoSQLElement.getNextCodeLettrage());

      this.model.updateTotauxCompte();
    }
  }
Ejemplo n.º 2
0
  // Pointe la ligne passée en parametre
  private void actionDelettrage(int[] rowIndex) {

    List<SQLRow> rowsSelected = new ArrayList<SQLRow>(rowIndex.length);

    long solde = 0;
    for (int i = 0; i < rowIndex.length; i++) {
      int id = this.ecriturePanel.getListe().idFromIndex(rowIndex[i]);
      SQLRow row = this.tableEcr.getRow(id);
      rowsSelected.add(row);

      solde += ((Long) row.getObject("DEBIT")).longValue();
      solde -= ((Long) row.getObject("CREDIT")).longValue();
    }

    if (solde == 0) {
      for (SQLRow row : rowsSelected) {

        SQLRowValues rowVals = new SQLRowValues(this.tableEcr);

        // Dépointage
        if (row.getString("LETTRAGE").trim().length() != 0) {

          rowVals.put("LETTRAGE", "");
          rowVals.put("DATE_LETTRAGE", null);
          try {
            rowVals.update(row.getID());
          } catch (SQLException e1) {
            e1.printStackTrace();
          }
        }
      }
    }
    this.model.updateTotauxCompte();
  }
Ejemplo n.º 3
0
  @Override
  public int insert(final SQLRow order) {

    final int idDevis;
    // on verifie qu'un devis du meme numero n'a pas été inséré entre temps
    if (this.numeroUniqueDevis.checkValidation()) {

      idDevis = super.insert(order);
      this.table.updateField("ID_DEVIS", idDevis);
      // Création des articles
      this.table.createArticle(idDevis, getElement());

      // generation du document
      try {
        final DevisXmlSheet sheet = new DevisXmlSheet(getTable().getRow(idDevis));
        sheet.createDocumentAsynchronous();
        sheet.showPrintAndExportAsynchronous(
            DevisSQLComponent.this.panelOO.isVisualisationSelected(),
            DevisSQLComponent.this.panelOO.isImpressionSelected(),
            true);
      } catch (Exception e) {
        ExceptionHandler.handle("Impossible de créer le devis", e);
      }

      // incrémentation du numéro auto
      if (NumerotationAutoSQLElement.getNextNumero(DevisSQLElement.class)
          .equalsIgnoreCase(this.numeroUniqueDevis.getText().trim())) {
        final SQLRowValues rowVals = new SQLRowValues(this.tableNum);
        int val =
            this.tableNum
                .getRow(2)
                .getInt(NumerotationAutoSQLElement.getLabelNumberFor(DevisSQLElement.class));
        val++;
        rowVals.put(
            NumerotationAutoSQLElement.getLabelNumberFor(DevisSQLElement.class), new Integer(val));
        try {
          rowVals.update(2);
        } catch (final SQLException e) {
          e.printStackTrace();
        }
      }
    } else {
      idDevis = getSelectedID();
      ExceptionHandler.handle("Impossible d'ajouter, numéro de devis existant.");
      final Object root = SwingUtilities.getRoot(this);
      if (root instanceof EditFrame) {
        final EditFrame frame = (EditFrame) root;
        frame.getPanel().setAlwaysVisible(true);
      }
    }

    return idDevis;
  }
  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();
    }
  }