List of usage examples for javax.swing JLabel setHorizontalAlignment
@BeanProperty(visualUpdate = true, enumerationValues = { "SwingConstants.LEFT", "SwingConstants.CENTER", "SwingConstants.RIGHT", "SwingConstants.LEADING", "SwingConstants.TRAILING" }, description = "The alignment of the label's content along the X axis.") public void setHorizontalAlignment(int alignment)
From source file:org.nuxeo.launcher.gui.NuxeoFrame.java
protected JComponent buildFooter() { JLabel label = new JLabel(NuxeoLauncherGUI.getMessage("footer.label", new DateTime().toString("Y"))); label.setForeground(Color.WHITE); label.setPreferredSize(new Dimension(470, 16)); label.setFont(new Font(label.getFont().getName(), label.getFont().getStyle(), 9)); label.setHorizontalAlignment(SwingConstants.CENTER); return label; }
From source file:org.openconcerto.erp.core.finance.accounting.ui.AjouterComptePCGtoPCEFrame.java
public AjouterComptePCGtoPCEFrame() { super("Ajouter un compte du plan comptable gnral"); Container f = this.getContentPane(); // instanciation du panel et du menu click droit associ Vector<AbstractAction> actionClickDroitTable = new Vector<AbstractAction>(); actionClickDroitTable.add(new AbstractAction("Ajouter au PCE") { public void actionPerformed(ActionEvent e) { ajoutCompteSelected();/*from ww w. ja v a 2 s . c o m*/ } }); this.planPanel = new PlanComptableGPanel(actionClickDroitTable); this.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(12, 2, 12, 2); c.gridx = 0; c.gridy = 0; c.weightx = 0; c.weighty = 0; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.NORTHWEST; c.gridwidth = 2; c.gridheight = 1; JLabel label = new JLabel("Choississez le ou les comptes ajouter au Plan Comptable Entreprise"); label.setHorizontalAlignment(SwingConstants.CENTER); f.add(label, c); /******************************************************************************************* * * Affichage du plan comptable entreprise ******************************************************************************************/ c.insets = new Insets(0, 0, 0, 0); c.gridwidth = 2; c.gridheight = 1; c.weightx = 1; c.weighty = 1; c.gridy++; f.add(this.planPanel, c); /******************************************************************************************* * * Bouton ajout / fermer ******************************************************************************************/ c.insets = new Insets(2, 2, 1, 2); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; c.gridy++; c.gridx = 0; c.anchor = GridBagConstraints.SOUTHEAST; f.add(this.boutonAjout, c); this.boutonAjout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ajoutCompteSelected(); } }); c.gridx++; f.add(this.boutonClose, c); this.boutonClose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AjouterComptePCGtoPCEFrame.this.setVisible(false); AjouterComptePCGtoPCEFrame.this.dispose(); } }); /* * this.pack(); this.setVisible(true); */ }
From source file:org.openconcerto.erp.core.finance.accounting.ui.GrandLivrePanel.java
/** * Cre le panel d'un onglet associ une classe * /*from w w w.j av a 2 s. c om*/ * @param cc ClasseCompte la classe des comptes * @return JPanel le JPanel associ */ private JPanel initClassePanel(ClasseCompte cc) { final JPanel panelTmp = new JPanel(); long totalDebitClasse = 0; long totalCreditClasse = 0; panelTmp.setLayout(new GridBagLayout()); panelTmp.setOpaque(false); final GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 1, 2); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.NORTHWEST; c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.weightx = 1; c.weighty = 0; // Rcupration des comptes de la classe avec le total SQLBase base = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete(); SQLTable compteTable = base.getTable("COMPTE_PCE"); SQLTable ecritureTable = base.getTable("ECRITURE"); SQLSelect sel = new SQLSelect(base); sel.addSelect(compteTable.getKey()); sel.addSelect(compteTable.getField("NUMERO")); sel.addSelect(compteTable.getField("NOM")); sel.addSelect(ecritureTable.getField("DEBIT"), "SUM"); sel.addSelect(ecritureTable.getField("CREDIT"), "SUM"); String function = "REGEXP"; String match = cc.getTypeNumeroCompte(); if (Configuration.getInstance().getBase().getServer().getSQLSystem() == SQLSystem.POSTGRESQL) { // function = "SIMILAR TO"; function = "~"; // match = cc.getTypeNumeroCompte().replace(".*", "%"); } Where w = new Where(compteTable.getField("NUMERO"), function, match); Where w2 = new Where(ecritureTable.getField("ID_COMPTE_PCE"), "=", compteTable.getKey()); if (!UserManager.getInstance().getCurrentUser().getRights() .haveRight(ComptaUserRight.ACCES_NOT_RESCTRICTED_TO_411)) { // TODO Show Restricted acces in UI w = w.and(new Where(ecritureTable.getField("COMPTE_NUMERO"), "LIKE", "411%")); } sel.setWhere(w.and(w2)); String req = sel.asString() + " GROUP BY \"COMPTE_PCE\".\"ID\",\"COMPTE_PCE\".\"NUMERO\",\"COMPTE_PCE\".\"NOM\" ORDER BY \"COMPTE_PCE\".\"NUMERO\""; System.out.println(req); Object ob = base.getDataSource().execute(req, new ArrayListHandler()); List myList = (List) ob; JLabel labelTotalClasse = new JLabel(); labelTotalClasse.setOpaque(false); if (myList.size() != 0) { /*************************************************************************************** * Cration des Panels de chaque compte **************************************************************************************/ // c.weighty = 1; for (int i = 0; i < myList.size(); i++) { Object[] objTmp = (Object[]) myList.get(i); final Compte compteTmp = new Compte(((Number) objTmp[0]).intValue(), objTmp[1].toString(), objTmp[2].toString(), "", ((Number) objTmp[3]).longValue(), ((Number) objTmp[4]).longValue()); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.weighty = 0; c.gridx = 0; c.gridy++; panelTmp.add(creerComptePanel(compteTmp), c); // calcul du total de la classe totalDebitClasse += compteTmp.getTotalDebit(); totalCreditClasse += compteTmp.getTotalCredit(); } // Total de la classe labelTotalClasse.setText( "Total Classe " + cc.getNom() + " Dbit : " + GestionDevise.currencyToString(totalDebitClasse) + " Crdit : " + GestionDevise.currencyToString(totalCreditClasse)); } else { labelTotalClasse.setHorizontalAlignment(SwingConstants.CENTER); labelTotalClasse.setText("Aucune criture pour la classe " + cc.getNom()); } c.gridy++; c.weighty = 1; panelTmp.add(labelTotalClasse, c); return panelTmp; }
From source file:org.openconcerto.erp.core.finance.accounting.ui.GrandLivrePanel.java
private JPanel creerComptePanel(final Compte compte) { final GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 1, 2); c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.NORTHWEST; c.gridx = GridBagConstraints.RELATIVE; c.gridy = 0;/*from w ww . ja va2 s. c o m*/ c.gridwidth = 1; c.gridheight = 1; c.weightx = 1; c.weighty = 0; // Intitul du compte final JPanel panelCompte = new JPanel(); panelCompte.setOpaque(false); panelCompte.setLayout(new GridBagLayout()); panelCompte.setBorder(BorderFactory.createTitledBorder(compte.getNumero() + " " + compte.getNom())); // Bouton Dtails +/- du compte JButton boutonShow = new JButton("+/-"); boutonShow.setOpaque(false); boutonShow.setHorizontalAlignment(SwingConstants.RIGHT); // Total du Compte JLabel labelCompteDebit = new JLabel( "Total Debit : " + GestionDevise.currencyToString(compte.getTotalDebit())); JLabel labelCompteCredit = new JLabel( " Credit : " + GestionDevise.currencyToString(compte.getTotalCredit())); // labelCompte.setFont(new Font(labelCompte.getFont().getFontName(), Font.BOLD, 12)); labelCompteDebit.setHorizontalAlignment(SwingUtilities.LEFT); labelCompteCredit.setHorizontalAlignment(SwingUtilities.LEFT); JLabel labelTmp = new JLabel(compte.getNumero() + " " + compte.getNom()); labelTmp.setHorizontalAlignment(SwingUtilities.LEFT); panelCompte.add(labelTmp, c); panelCompte.add(labelCompteDebit, c); panelCompte.add(labelCompteCredit, c); c.weightx = 1; c.anchor = GridBagConstraints.NORTHEAST; panelCompte.add(boutonShow, c); boutonShow.addActionListener(new ActionListener() { private boolean isShow = false; private JScrollPane scroll = null; public void actionPerformed(ActionEvent e) { System.err.println(this.isShow); // Afficher la JTable du compte if (!this.isShow) { // if (this.scroll == null) { System.err.println(compte); JTable tableCpt = createJTableCompte(compte); this.scroll = new JScrollPane(tableCpt); // calcul de la taille du JScrollPane Dimension d; System.err.println(tableCpt); if (tableCpt.getPreferredSize().height > 200) { d = new Dimension(this.scroll.getPreferredSize().width, 200); } else { d = new Dimension(this.scroll.getPreferredSize().width, tableCpt.getPreferredSize().height + 30); } this.scroll.setPreferredSize(d); c.gridy++; c.gridwidth = 4; c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.NORTHWEST; panelCompte.add(this.scroll, c); /* * } else { this.scroll.setVisible(true); } */ } else { // if (this.scroll != null) { panelCompte.remove(this.scroll); System.out.println("Hide scrollPane"); // this.scroll.setVisible(false); // this.scroll.repaint(); panelCompte.repaint(); panelCompte.revalidate(); // } } this.isShow = !this.isShow; SwingUtilities.getRoot(panelCompte).repaint(); } }); return panelCompte; }
From source file:org.openconcerto.erp.core.sales.credit.component.AvoirClientSQLComponent.java
private JPanel getBottomPanel() { // UI//from w w w. j a v a2 s . co m final JPanel panel = new JPanel(new GridBagLayout()); panel.setOpaque(false); final GridBagConstraints c = new DefaultGridBagConstraints(); c.anchor = GridBagConstraints.NORTHWEST; c.weightx = 1; // Colonne 1 this.boxAdeduire.setOpaque(false); this.boxAdeduire.setMinimumSize(new Dimension(430, this.boxAdeduire.getPreferredSize().height)); this.boxAdeduire.setPreferredSize(new Dimension(430, this.boxAdeduire.getPreferredSize().height)); panel.add(this.boxAdeduire, c); this.addView("ID_MODE_REGLEMENT", DEC + ";" + SEP); this.eltModeRegl = (ElementSQLObject) this.getView("ID_MODE_REGLEMENT"); c.gridy++; c.fill = GridBagConstraints.NONE; c.weighty = 1; this.eltModeRegl.setOpaque(false); panel.add(this.eltModeRegl, c); // Colonne 2 : port et remise final JPanel panelPortEtRemise = new JPanel(); panelPortEtRemise.setOpaque(false); panelPortEtRemise.setLayout(new GridBagLayout()); final GridBagConstraints cFrais = new DefaultGridBagConstraints(); DeviseField textPortHT = new DeviseField(5); DeviseField textRemiseHT = new DeviseField(5); // Frais de port cFrais.gridheight = 1; cFrais.fill = GridBagConstraints.VERTICAL; cFrais.weighty = 1; cFrais.gridx = 1; // FIXME implmenter la remise et les port pour les avoirs JLabel labelPortHT = new JLabel(getLabelFor("PORT_HT")); labelPortHT.setHorizontalAlignment(SwingConstants.RIGHT); cFrais.gridy++; // panelPortEtRemise.add(labelPortHT, cFrais); cFrais.gridx++; DefaultGridBagConstraints.lockMinimumSize(textPortHT); // panelPortEtRemise.add(textPortHT, cFrais); // Remise JLabel labelRemiseHT = new JLabel(getLabelFor("REMISE_HT")); labelRemiseHT.setHorizontalAlignment(SwingConstants.RIGHT); cFrais.gridy++; cFrais.gridx = 1; // panelPortEtRemise.add(labelRemiseHT, cFrais); cFrais.gridx++; DefaultGridBagConstraints.lockMinimumSize(textRemiseHT); // panelPortEtRemise.add(textRemiseHT, cFrais); cFrais.gridy++; c.gridx++; c.gridy = 0; c.gridheight = 2; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.NORTHWEST; panel.add(panelPortEtRemise, c); // Colonne 3 : totaux final DeviseField fieldHT = new DeviseField(); final DeviseField fieldTVA = new DeviseField(); final DeviseField fieldService = new DeviseField(); final DeviseField fieldTTC = new DeviseField(); // SQL addSQLObject(textPortHT, "PORT_HT"); final DeviseField fieldDevise = new DeviseField(); if (getTable().getFieldsName().contains("T_DEVISE")) addSQLObject(fieldDevise, "T_DEVISE"); addSQLObject(textRemiseHT, "REMISE_HT"); addRequiredSQLObject(fieldHT, "MONTANT_HT"); addRequiredSQLObject(fieldTVA, "MONTANT_TVA"); addRequiredSQLObject(fieldTTC, "MONTANT_TTC"); addRequiredSQLObject(fieldService, "MONTANT_SERVICE"); // JTextField poids = new JTextField(); if (getTable().getFieldsName().contains("T_POIDS")) addSQLObject(poids, "T_POIDS"); final TotalPanel totalTTC = new TotalPanel(this.table, fieldHT, fieldTVA, fieldTTC, textPortHT, textRemiseHT, fieldService, null, fieldDevise, poids, null); totalTTC.setOpaque(false); c.gridx++; c.gridy = 0; c.gridheight = 2; c.fill = GridBagConstraints.BOTH; panel.add(totalTTC, c); // Listeners textPortHT.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void removeUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void insertUpdate(DocumentEvent e) { totalTTC.updateTotal(); } }); textRemiseHT.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void removeUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void insertUpdate(DocumentEvent e) { totalTTC.updateTotal(); } }); return panel; }
From source file:org.openconcerto.erp.core.sales.invoice.component.SaisieVenteFactureSQLComponent.java
public void addViews() { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); this.checkPrevisionnelle = new JCheckBox(); this.checkComplement = new JCheckBox(); this.fieldTTC = new DeviseField(); final ComptaPropsConfiguration comptaPropsConfiguration = ((ComptaPropsConfiguration) Configuration .getInstance());//from www . j a va 2s. co m this.textAvoirTTC = new DeviseField(); // Champ Module c.gridx = 0; c.gridy++; c.gridwidth = GridBagConstraints.REMAINDER; final JPanel addP = ComptaSQLConfElement.createAdditionalPanel(); this.setAdditionalFieldsPanel(new FormLayouter(addP, 1)); this.add(addP, c); c.gridy++; c.gridwidth = 1; if (getTable().contains("ID_POLE_PRODUIT")) { JLabel labelPole = new JLabel(getLabelFor("ID_POLE_PRODUIT")); labelPole.setHorizontalAlignment(SwingConstants.RIGHT); this.add(labelPole, c); c.gridx++; ElementComboBox pole = new ElementComboBox(); this.add(pole, c); this.addSQLObject(pole, "ID_POLE_PRODUIT"); c.gridy++; c.gridwidth = 1; c.gridx = 0; } /******************************************************************************************* * * RENSEIGNEMENTS ******************************************************************************************/ // Ligne 1 : Numero de facture JLabel labelNum = new JLabel(getLabelFor("NUMERO")); labelNum.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 0; c.gridy++; c.weightx = 0; this.add(labelNum, c); this.textNumeroUnique = new JUniqueTextField(16); c.gridx++; c.weightx = 0; c.fill = GridBagConstraints.NONE; DefaultGridBagConstraints.lockMinimumSize(this.textNumeroUnique); this.add(textNumeroUnique, c); // Date c.gridx++; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; this.add(new JLabel(getLabelFor("DATE"), SwingConstants.RIGHT), c); c.gridx++; c.weightx = 1; c.fill = GridBagConstraints.NONE; final JDate dateSaisie = new JDate(true); // listener permettant la mise jour du numro de facture en fonction de la date // slectionne dateSaisie.addValueListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (!isFilling() && dateSaisie.getValue() != null) { final String nextNumero = NumerotationAutoSQLElement .getNextNumero(SaisieVenteFactureSQLElement.class, dateSaisie.getValue()); if (textNumeroUnique.getText().trim().length() > 0 && !nextNumero.equalsIgnoreCase(textNumeroUnique.getText())) { int answer = JOptionPane.showConfirmDialog(SaisieVenteFactureSQLComponent.this, "Voulez vous actualiser le numro de la facture?", "Changement du numro de facture", JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.NO_OPTION) { return; } } textNumeroUnique.setText(nextNumero); } } }); this.add(dateSaisie, c); // Ligne 2 : reference c.gridx = 0; c.gridwidth = 1; c.gridy++; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; JLabel labelLibelle = new JLabel(getLabelFor("NOM")); labelLibelle.setHorizontalAlignment(SwingConstants.RIGHT); this.add(labelLibelle, c); SQLTextCombo textLibelle = new SQLTextCombo(); c.gridx++; c.weightx = 1; c.fill = GridBagConstraints.BOTH; this.add(textLibelle, c); this.addSQLObject(textLibelle, "NOM"); c.fill = GridBagConstraints.HORIZONTAL; this.comboCommercial = new ElementComboBox(false); // Commercial String field; field = "ID_COMMERCIAL"; c.gridx++; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; this.add(new JLabel(getLabelFor(field), SwingConstants.RIGHT), c); c.gridx++; c.weightx = 1; c.fill = GridBagConstraints.NONE; this.add(this.comboCommercial, c); this.addRequiredSQLObject(this.comboCommercial, field); // Client c.gridx = 0; c.gridy++; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c); c.gridx++; c.weightx = 1; c.fill = GridBagConstraints.NONE; this.comboClient = new ElementComboBox(); this.add(this.comboClient, c); if (getTable().contains("ID_ECHEANCIER_CCI")) { // Echeancier c.gridx++; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; this.add(new JLabel(getLabelFor("ID_ECHEANCIER_CCI"), SwingConstants.RIGHT), c); c.gridx++; c.weightx = 1; c.fill = GridBagConstraints.NONE; final ElementComboBox echeancier = new ElementComboBox(); final SQLElement contactElement = Configuration.getInstance().getDirectory() .getElement("ECHEANCIER_CCI"); echeancier.init(contactElement, contactElement.getComboRequest(true)); DefaultGridBagConstraints.lockMinimumSize(echeancier); this.addView(echeancier, "ID_ECHEANCIER_CCI"); selAffaire.addValueListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent arg0) { // TODO Raccord de mthode auto-gnr if (selAffaire.getSelectedRow() != null) { echeancier.getRequest().setWhere(new Where(contactElement.getTable().getField("ID_AFFAIRE"), "=", selAffaire.getSelectedRow().getID())); if (!isFilling()) { SQLRow rowPole = selAffaire.getSelectedRow().getForeignRow("ID_POLE_PRODUIT"); comboCommercial.setValue(rowPole); } } else { echeancier.getRequest().setWhere(null); } } }); this.add(echeancier, c); } this.comboClient.addValueListener(this.changeClientListener); this.comboAdresse = new ElementComboBox(); this.comboAdresse.setAddIconVisible(false); this.comboAdresse.setListIconVisible(false); JLabel labelAdresse = new JLabel(getLabelFor("ID_ADRESSE"), SwingConstants.RIGHT); c.gridy++; c.gridx = 0; c.gridwidth = 1; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; labelAdresse.setHorizontalAlignment(SwingConstants.RIGHT); this.add(labelAdresse, c); c.gridx++; c.fill = GridBagConstraints.NONE; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; this.add(this.comboAdresse, c); // Acompte this.checkAcompte = new JCheckBox(getLabelFor("ACOMPTE")); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; // this.add(this.checkAcompte, c); c.gridwidth = 1; this.addView(this.checkAcompte, "ACOMPTE"); // Compte Service this.checkCompteServiceAuto = new JCheckBox(getLabelFor("COMPTE_SERVICE_AUTO")); this.addSQLObject(this.checkCompteServiceAuto, "COMPTE_SERVICE_AUTO"); this.compteSelService = new ISQLCompteSelector(); this.labelCompteServ = new JLabel("Compte Service"); c.gridy++; c.gridx = 0; c.gridwidth = 1; c.weightx = 0; this.labelCompteServ.setHorizontalAlignment(SwingConstants.RIGHT); this.add(this.labelCompteServ, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; this.add(this.compteSelService, c); String valServ = DefaultNXProps.getInstance().getStringProperty("ArticleService"); Boolean bServ = Boolean.valueOf(valServ); this.checkCompteServiceAuto.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setCompteServiceVisible(!SaisieVenteFactureSQLComponent.this.checkCompteServiceAuto.isSelected()); } }); // FIXME A checker si utile pour Preventec ou KD setCompteServiceVisible(false); // setCompteServiceVisible(!(bServ != null && !bServ.booleanValue())); final JPanel pAcompte = new JPanel(); final DeviseField textAcompteHT = new DeviseField(); pAcompte.add(new JLabel("Acompte HT")); pAcompte.add(textAcompteHT); pAcompte.add(new JLabel("soit")); final JTextField textAcompte = new JTextField(5); pAcompte.add(textAcompte); pAcompte.add(new JLabel("%")); c.gridx = 0; c.gridy++; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; this.add(pAcompte, c); c.anchor = GridBagConstraints.WEST; this.addView(textAcompte, "POURCENT_ACOMPTE"); pAcompte.setVisible(false); /******************************************************************************************* * * DETAILS ******************************************************************************************/ this.tableFacture = new SaisieVenteFactureItemTable(); final ElementComboBox boxTarif = new ElementComboBox(); if (this.getTable().getFieldsName().contains("ID_TARIF")) { // TARIF c.gridy++; c.gridx = 0; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; this.add(new JLabel("Tarif appliquer", SwingConstants.RIGHT), c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.NONE; c.weightx = 1; DefaultGridBagConstraints.lockMinimumSize(boxTarif); this.add(boxTarif, c); this.addView(boxTarif, "ID_TARIF"); boxTarif.addModelListener("wantedID", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { SQLRow selectedRow = boxTarif.getRequest().getPrimaryTable().getRow(boxTarif.getWantedID()); tableFacture.setTarif(selectedRow, false); } }); } c.gridy++; c.gridx = 0; c.weightx = 1; c.weighty = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.BOTH; ITextArea infos = new ITextArea(4, 4); this.add(this.tableFacture, c); // FIXME this.addView(this.tableFacture.getRowValuesTable(), ""); /******************************************************************************************* * * MODE DE REGLEMENT ******************************************************************************************/ JPanel panelBottom = new JPanel(new GridBagLayout()); GridBagConstraints cBottom = new DefaultGridBagConstraints(); cBottom.weightx = 1; cBottom.anchor = GridBagConstraints.NORTHWEST; // Mode de rglement this.addView("ID_MODE_REGLEMENT", REQ + ";" + DEC + ";" + SEP); this.eltModeRegl = (ElementSQLObject) this.getView("ID_MODE_REGLEMENT"); panelBottom.add(this.eltModeRegl, cBottom); /******************************************************************************************* * * FRAIS DE PORT ET REMISE ******************************************************************************************/ JPanel panelFrais = new JPanel(); panelFrais.setLayout(new GridBagLayout()); final GridBagConstraints cFrais = new DefaultGridBagConstraints(); this.textPortHT = new DeviseField(5); DefaultGridBagConstraints.lockMinimumSize(textPortHT); addSQLObject(this.textPortHT, "PORT_HT"); this.textRemiseHT = new DeviseField(5); DefaultGridBagConstraints.lockMinimumSize(textRemiseHT); addSQLObject(this.textRemiseHT, "REMISE_HT"); // Frais de port cFrais.gridheight = 1; cFrais.gridx = 1; SQLRequestComboBox boxTaxePort = new SQLRequestComboBox(false, 8); if (getTable().contains("ID_TAXE_PORT")) { JLabel labelPortHT = new JLabel(getLabelFor("PORT_HT")); labelPortHT.setHorizontalAlignment(SwingConstants.RIGHT); cFrais.gridy++; panelFrais.add(labelPortHT, cFrais); cFrais.gridx++; panelFrais.add(this.textPortHT, cFrais); JLabel labelTaxeHT = new JLabel(getLabelFor("ID_TAXE_PORT")); labelTaxeHT.setHorizontalAlignment(SwingConstants.RIGHT); cFrais.gridx = 1; cFrais.gridy++; panelFrais.add(labelTaxeHT, cFrais); cFrais.gridx++; panelFrais.add(boxTaxePort, cFrais); this.addView(boxTaxePort, "ID_TAXE_PORT", REQ); boxTaxePort.addValueListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { // TODO Raccord de mthode auto-gnr totalTTC.updateTotal(); } }); } // Remise JLabel labelRemiseHT = new JLabel(getLabelFor("REMISE_HT")); labelRemiseHT.setHorizontalAlignment(SwingConstants.RIGHT); cFrais.gridy++; cFrais.gridx = 1; panelFrais.add(labelRemiseHT, cFrais); cFrais.gridx++; panelFrais.add(this.textRemiseHT, cFrais); cFrais.gridy++; cBottom.gridx++; cBottom.weightx = 1; cBottom.anchor = GridBagConstraints.NORTHEAST; cBottom.fill = GridBagConstraints.NONE; panelBottom.add(panelFrais, cBottom); /******************************************************************************************* * * CALCUL DES TOTAUX ******************************************************************************************/ DeviseField fieldHT = new DeviseField(); final DeviseField fieldTVA = new DeviseField(); DeviseField fieldService = new DeviseField(); DeviseField fieldTHA = new DeviseField(); DeviseField fieldDevise = null; if (getTable().getFieldsName().contains("T_DEVISE")) { fieldDevise = new DeviseField(); addSQLObject(fieldDevise, "T_DEVISE"); } // FIXME was required but not displayed for KD addSQLObject(fieldTHA, "T_HA"); addRequiredSQLObject(fieldHT, "T_HT"); addRequiredSQLObject(fieldTVA, "T_TVA"); addRequiredSQLObject(this.fieldTTC, "T_TTC"); addRequiredSQLObject(fieldService, "T_SERVICE"); JTextField poids = new JTextField(); addSQLObject(poids, "T_POIDS"); totalTTC = new TotalPanel(this.tableFacture, fieldHT, fieldTVA, this.fieldTTC, this.textPortHT, this.textRemiseHT, fieldService, fieldTHA, fieldDevise, poids, null, (getTable().contains("ID_TAXE_PORT") ? boxTaxePort : null)); DefaultGridBagConstraints.lockMinimumSize(totalTTC); cBottom.gridx++; cBottom.weightx = 1; cBottom.anchor = GridBagConstraints.EAST; cBottom.fill = GridBagConstraints.HORIZONTAL; panelBottom.add(totalTTC, cBottom); c.anchor = GridBagConstraints.WEST; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy++; c.weighty = 0; this.add(panelBottom, c); // Ligne : Avoir c.gridy++; c.gridx = 0; c.weightx = 1; c.weighty = 0; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; this.add(createPanelAvoir(), c); // Infos c.gridy++; c.gridx = 0; c.gridwidth = 4; c.fill = GridBagConstraints.BOTH; this.add(new TitledSeparator(getLabelFor("INFOS")), c); c.gridy++; final JScrollPane comp = new JScrollPane(infos); infos.setBorder(null); DefaultGridBagConstraints.lockMinimumSize(comp); this.add(comp, c); this.panelOO = new PanelOOSQLComponent(this); c.gridy++; c.gridx = 0; c.weightx = 1; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.NORTHEAST; this.add(this.panelOO, c); this.addSQLObject(this.textAvoirTTC, "T_AVOIR_TTC"); this.addRequiredSQLObject(dateSaisie, "DATE"); this.addRequiredSQLObject(this.comboClient, "ID_CLIENT"); this.addSQLObject(this.comboAdresse, "ID_ADRESSE"); this.addRequiredSQLObject(this.textNumeroUnique, "NUMERO"); this.addSQLObject(infos, "INFOS"); this.addSQLObject(this.checkPrevisionnelle, "PREVISIONNELLE"); this.addSQLObject(this.checkComplement, "COMPLEMENT"); this.addSQLObject(this.selAvoir, "ID_AVOIR_CLIENT"); this.addSQLObject(this.compteSelService, "ID_COMPTE_PCE_SERVICE"); ModeDeReglementSQLComponent modeReglComp; modeReglComp = (ModeDeReglementSQLComponent) this.eltModeRegl.getSQLChild(); this.selAvoir.getRequest().setWhere(new Where(this.tableAvoir.getField("SOLDE"), "=", Boolean.FALSE)); this.selAvoir.fillCombo(); // Selection du compte de service int idCompteVenteService = rowPrefsCompte.getInt("ID_COMPTE_PCE_VENTE_SERVICE"); if (idCompteVenteService <= 1) { try { idCompteVenteService = ComptePCESQLElement.getIdComptePceDefault("VentesServices"); } catch (Exception e) { e.printStackTrace(); } } this.compteSelService.setValue(idCompteVenteService); // Lock DefaultGridBagConstraints.lockMinimumSize(this.comboClient); DefaultGridBagConstraints.lockMinimumSize(this.comboCommercial); DefaultGridBagConstraints.lockMinimumSize(this.comboAdresse); // Listeners this.comboClient.addValueListener(this.listenerModeReglDefaut); this.fieldTTC.getDocument().addDocumentListener(new SimpleDocumentListener() { @Override public void update(DocumentEvent e) { refreshText(); } }); this.selAvoir.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { refreshText(); } }); this.checkAcompte.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { pAcompte.setVisible(SaisieVenteFactureSQLComponent.this.checkAcompte.isSelected()); } }); this.changeClientListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (SaisieVenteFactureSQLComponent.this.comboClient.getValue() != null) { final SQLRow row = SaisieVenteFactureSQLComponent.this.comboClient.getSelectedRow(); final int id = row == null ? SQLRow.NONEXISTANT_ID : row.getID(); SaisieVenteFactureSQLComponent.this.defaultContactRowValues.putForeignID("ID_CLIENT", row); if (row != null) { if (SaisieVenteFactureSQLComponent.this.contact != null) { Where w = new Where( SaisieVenteFactureSQLComponent.this.eltContact.getTable().getField("ID_CLIENT"), "=", SQLRow.NONEXISTANT_ID); w = w.or(new Where( SaisieVenteFactureSQLComponent.this.eltContact.getTable().getField("ID_CLIENT"), "=", id)); SaisieVenteFactureSQLComponent.this.contact.getRequest().setWhere(w); } if (SaisieVenteFactureSQLComponent.this.comboAdresse != null) { Where w = new Where(SaisieVenteFactureSQLComponent.TABLE_ADRESSE.getKey(), "=", row.getInt("ID_ADRESSE")); w = w.or(new Where(SaisieVenteFactureSQLComponent.TABLE_ADRESSE.getKey(), "=", row.getInt("ID_ADRESSE_L"))); w = w.or(new Where(SaisieVenteFactureSQLComponent.TABLE_ADRESSE.getKey(), "=", row.getInt("ID_ADRESSE_F"))); SQLRow rowCli = row; w = w.or(new Where(SaisieVenteFactureSQLComponent.TABLE_ADRESSE.getField("ID_CLIENT"), "=", rowCli.getID())); SaisieVenteFactureSQLComponent.this.comboAdresse.getRequest().setWhere(w); } } else { if (SaisieVenteFactureSQLComponent.this.comboAdresse != null) { SaisieVenteFactureSQLComponent.this.comboAdresse.getRequest().setWhere(null); } } SaisieVenteFactureSQLComponent.this.previousClient = id; } } }; this.changeCompteListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { SQLSelect sel = new SQLSelect(getTable().getBase()); sel.addSelect(SaisieVenteFactureSQLComponent.this.client.getTable().getKey()); Where where = new Where( SaisieVenteFactureSQLComponent.this.client.getTable().getField("ID_COMPTE_PCE"), "=", SaisieVenteFactureSQLComponent.this.compteSel.getValue()); sel.setWhere(where); String req = sel.asString(); List l = getTable().getBase().getDataSource().execute(req); if (l != null) { if (l.size() == 1) { Map<String, Object> m = (Map<String, Object>) l.get(0); Object o = m.get(SaisieVenteFactureSQLComponent.this.client.getTable().getKey().getName()); System.err.println("Only one value match :: " + o); if (o != null) { SaisieVenteFactureSQLComponent.this.comboClient .setValue(Integer.valueOf(((Number) o).intValue())); } } } } }; this.textPortHT.getDocument().addDocumentListener(new SimpleDocumentListener() { @Override public void update(DocumentEvent e) { totalTTC.updateTotal(); } }); this.textRemiseHT.getDocument().addDocumentListener(new SimpleDocumentListener() { @Override public void update(DocumentEvent e) { totalTTC.updateTotal(); } }); this.comboClient.addValueListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (SaisieVenteFactureSQLComponent.this.isFilling()) return; final SQLRow row = ((SQLRequestComboBox) evt.getSource()).getSelectedRow(); if (row != null) { SaisieVenteFactureSQLComponent.this.defaultContactRowValues.putForeignID("ID_CLIENT", row); if (SaisieVenteFactureSQLComponent.this.client.getTable().contains("ID_TARIF")) { SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF"); if (foreignRow != null && !foreignRow.isUndefined() && (boxTarif.getSelectedRow() == null || boxTarif.getSelectedId() != foreignRow.getID()) && JOptionPane.showConfirmDialog(null, "Appliquer les tarifs associs au client?") == JOptionPane.YES_OPTION) { boxTarif.setValue(foreignRow.getID()); // SaisieVenteFactureSQLComponent.this.tableFacture.setTarif(foreignRow, // true); } else { boxTarif.setValue(foreignRow); } } int idCpt = row.getInt("ID_COMPTE_PCE"); if (idCpt <= 1) { // Select Compte client par defaut idCpt = rowPrefsCompte.getInt("ID_COMPTE_PCE_CLIENT"); if (idCpt <= 1) { try { idCpt = ComptePCESQLElement.getIdComptePceDefault("Clients"); } catch (Exception e) { e.printStackTrace(); } } } if (SaisieVenteFactureSQLComponent.this.compteSel != null) { Integer i = SaisieVenteFactureSQLComponent.this.compteSel.getValue(); if (i == null || i.intValue() != idCpt) { SaisieVenteFactureSQLComponent.this.compteSel.setValue(idCpt); } } } } }); }
From source file:org.openconcerto.erp.core.sales.invoice.component.SaisieVenteFactureSQLComponent.java
private JPanel createPanelAvoir() { JPanel panelAvoir = new JPanel(new GridBagLayout()); panelAvoir.setOpaque(false);//www.jav a 2 s.com GridBagConstraints cA = new DefaultGridBagConstraints(); JLabel labelAvoir = new JLabel(getLabelFor("ID_AVOIR_CLIENT")); labelAvoir.setHorizontalAlignment(SwingConstants.RIGHT); cA.weightx = 1; labelAvoir.setHorizontalAlignment(SwingConstants.RIGHT); panelAvoir.add(labelAvoir, cA); cA.weightx = 0; cA.gridx++; this.selAvoir = new ElementComboBox(); this.selAvoir.setAddIconVisible(false); panelAvoir.add(this.selAvoir, cA); final JLabel labelTotalAvoir = new JLabel("Total rgler"); this.textTotalAvoir = new DeviseField(); this.textTotalAvoir.setEditable(false); cA.gridx++; cA.weightx = 0; panelAvoir.add(labelTotalAvoir, cA); cA.gridx++; cA.weightx = 0; panelAvoir.add(this.textTotalAvoir, cA); this.textTotalAvoir.setHorizontalAlignment(SwingConstants.RIGHT); return panelAvoir; }
From source file:org.openconcerto.erp.core.sales.order.component.CommandeClientSQLComponent.java
public void addViews() { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); // Numero du commande c.gridx = 0;// w ww .ja va2 s . co m this.add(new JLabel(getLabelFor("NUMERO"), SwingConstants.RIGHT), c); this.numeroUniqueCommande = new JUniqueTextField(16); c.fill = GridBagConstraints.NONE; c.gridx++; c.weightx = 1; this.add(this.numeroUniqueCommande, c); // Date JLabel labelDate = new JLabel(getLabelFor("DATE")); labelDate.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; this.add(labelDate, c); JDate dateCommande = new JDate(true); c.gridx++; c.fill = GridBagConstraints.NONE; this.add(dateCommande, c); // Champ Module c.gridx = 0; c.gridy++; c.gridwidth = GridBagConstraints.REMAINDER; final JPanel addP = ComptaSQLConfElement.createAdditionalPanel(); this.setAdditionalFieldsPanel(new FormLayouter(addP, 2)); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; this.add(addP, c); c.gridy++; c.gridwidth = 1; this.comboDevis = new ElementComboBox(); // Reference c.gridx = 0; c.gridy++; c.gridwidth = 1; c.gridwidth = 1; c.gridheight = 1; c.fill = GridBagConstraints.HORIZONTAL; JLabel labelObjet = new JLabel(getLabelFor("NOM")); labelObjet.setHorizontalAlignment(SwingConstants.RIGHT); c.weightx = 0; this.add(labelObjet, c); c.gridx++; c.weightx = 1; c.fill = GridBagConstraints.BOTH; this.add(this.textObjet, c); String field; field = "ID_COMMERCIAL"; c.fill = GridBagConstraints.HORIZONTAL; // Commercial JLabel labelCommercial = new JLabel(getLabelFor(field)); labelCommercial.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx++; c.weightx = 0; this.add(labelCommercial, c); this.comboCommercial = new ElementComboBox(false, 25); this.comboCommercial.setListIconVisible(false); c.gridx++; c.fill = GridBagConstraints.NONE; c.weightx = 1; this.add(this.comboCommercial, c); addRequiredSQLObject(this.comboCommercial, field); // Ligne 3: Client c.gridx = 0; c.gridy++; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c); this.comboClient = new ElementComboBox(); c.gridx = GridBagConstraints.RELATIVE; c.gridwidth = 3; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.NONE; this.add(this.comboClient, c); final ElementComboBox boxTarif = new ElementComboBox(); this.comboClient.addValueListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (!isFilling() && comboClient.getValue() != null) { Integer id = comboClient.getValue(); if (id > 1) { SQLRow row = comboClient.getElement().getTable().getRow(id); if (comboClient.getElement().getTable().getFieldsName().contains("ID_TARIF")) { SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF"); if (!foreignRow.isUndefined() && (boxTarif.getSelectedRow() == null || boxTarif.getSelectedId() != foreignRow.getID()) && JOptionPane.showConfirmDialog(null, "Appliquer les tarifs associs au client?") == JOptionPane.YES_OPTION) { boxTarif.setValue(foreignRow.getID()); // SaisieVenteFactureSQLComponent.this.tableFacture.setTarif(foreignRow, // true); } else { boxTarif.setValue(foreignRow.getID()); } // SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF"); // if (foreignRow.isUndefined() && // !row.getForeignRow("ID_DEVISE").isUndefined()) { // SQLRowValues rowValsD = new SQLRowValues(foreignRow.getTable()); // rowValsD.put("ID_DEVISE", row.getObject("ID_DEVISE")); // foreignRow = rowValsD; // // } // table.setTarif(foreignRow, true); } } } } }); // tarif if (this.getTable().getFieldsName().contains("ID_TARIF")) { // TARIF c.gridy++; c.gridx = 0; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; this.add(new JLabel("Tarif appliquer"), c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; this.add(boxTarif, c); this.addView(boxTarif, "ID_TARIF"); boxTarif.addModelListener("wantedID", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { SQLRow selectedRow = boxTarif.getRequest().getPrimaryTable().getRow(boxTarif.getWantedID()); table.setTarif(selectedRow, false); } }); } // Table d'lment this.table = new CommandeClientItemTable(); c.fill = GridBagConstraints.BOTH; c.gridy++; c.gridx = 0; c.weightx = 1; c.weighty = 1; c.gridwidth = GridBagConstraints.REMAINDER; this.add(this.table, c); DeviseField textPortHT = new DeviseField(); DeviseField textRemiseHT = new DeviseField(); // INfos c.gridx = 0; c.gridy++; c.gridheight = 1; c.weighty = 0; c.weightx = 1; c.anchor = GridBagConstraints.WEST; c.gridwidth = 2; this.add(new TitledSeparator(getLabelFor("INFOS")), c); c.gridy++; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.BOTH; final JScrollPane scrollPane = new JScrollPane(this.infos); scrollPane.setBorder(null); this.add(scrollPane, c); // Poids c.gridwidth = 1; DefaultProps props = DefaultNXProps.getInstance(); Boolean b = props.getBooleanValue("ArticleShowPoids"); final JTextField textPoidsTotal = new JTextField(8); if (b) { JPanel panel = new JPanel(); panel.add(new JLabel(getLabelFor("T_POIDS")), c); textPoidsTotal.setEnabled(false); textPoidsTotal.setHorizontalAlignment(JTextField.RIGHT); textPoidsTotal.setDisabledTextColor(Color.BLACK); panel.add(textPoidsTotal, c); panel.setOpaque(false); DefaultGridBagConstraints.lockMinimumSize(panel); c.gridx = 2; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.NORTHEAST; this.add(panel, c); } // Total DeviseField fieldHT = new DeviseField(); DeviseField fieldTVA = new DeviseField(); DeviseField fieldTTC = new DeviseField(); DeviseField fieldDevise = new DeviseField(); DeviseField fieldService = new DeviseField(); DeviseField fieldHA = new DeviseField(); fieldHT.setOpaque(false); fieldHA.setOpaque(false); fieldTVA.setOpaque(false); fieldTTC.setOpaque(false); fieldService.setOpaque(false); addSQLObject(fieldDevise, "T_DEVISE"); addRequiredSQLObject(fieldHT, "T_HT"); addRequiredSQLObject(fieldTVA, "T_TVA"); addRequiredSQLObject(fieldTTC, "T_TTC"); addRequiredSQLObject(fieldService, "T_SERVICE"); if (getTable().contains("PREBILAN")) { addSQLObject(fieldHA, "PREBILAN"); } else if (getTable().contains("T_HA")) { addSQLObject(fieldHA, "T_HA"); } JTextField poids = new JTextField(); // addSQLObject(poids, "T_POIDS"); final TotalPanel totalTTC = new TotalPanel(this.table, fieldHT, fieldTVA, fieldTTC, textPortHT, textRemiseHT, fieldService, fieldHA, fieldDevise, poids, null); c.gridx = GridBagConstraints.RELATIVE; c.gridy--; c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight = 2; c.anchor = GridBagConstraints.NORTHEAST; c.fill = GridBagConstraints.NONE; c.weighty = 0; this.add(totalTTC, c); this.panelOO = new PanelOOSQLComponent(this); c.gridwidth = 1; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.EAST; c.gridx = 0; c.gridy += 3; c.weightx = 0; c.gridwidth = GridBagConstraints.REMAINDER; this.add(this.panelOO, c); textPortHT.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void removeUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void insertUpdate(DocumentEvent e) { totalTTC.updateTotal(); } }); textRemiseHT.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void removeUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void insertUpdate(DocumentEvent e) { totalTTC.updateTotal(); } }); addRequiredSQLObject(this.comboClient, "ID_CLIENT"); addSQLObject(this.textObjet, "NOM"); addSQLObject(textPoidsTotal, "T_POIDS"); addRequiredSQLObject(dateCommande, "DATE"); // addRequiredSQLObject(radioEtat, "ID_ETAT_DEVIS"); addRequiredSQLObject(this.numeroUniqueCommande, "NUMERO"); addSQLObject(this.infos, "INFOS"); addSQLObject(this.comboDevis, "ID_DEVIS"); this.numeroUniqueCommande .setText(NumerotationAutoSQLElement.getNextNumero(CommandeClientSQLElement.class, new Date())); this.table.getModel().addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { textPoidsTotal.setText(String.valueOf(CommandeClientSQLComponent.this.table.getPoidsTotal())); } }); DefaultGridBagConstraints.lockMinimumSize(comboClient); DefaultGridBagConstraints.lockMinimumSize(comboCommercial); DefaultGridBagConstraints.lockMinimumSize(comboDevis); DefaultGridBagConstraints.lockMinimumSize(totalTTC); DefaultGridBagConstraints.lockMaximumSize(totalTTC); DefaultGridBagConstraints.lockMinimumSize(numeroUniqueCommande); }
From source file:org.openconcerto.erp.core.sales.pos.element.SaisieVenteComptoirSQLElement.java
public SQLComponent createComponent() { return new BaseSQLComponent(this) { private final JCheckBox checkService = new JCheckBox("dont "); private SQLSearchableTextCombo textNom; private DeviseField textMontantTTC; private DeviseField textMontantService; private ElementComboBox comboFournisseur; private JTextField textEcheance; private ElementComboBox comboTaxe; private DeviseField textMontantHT; private JCheckBox checkCommande; private JDate dateSaisie; private ElementComboBox nomArticle; private Date dateEch; private JLabel labelEcheancejours = new JLabel("jours"); private ElementComboBox comboAvoir; private ElementComboBox comboClient; private final JLabel labelWarning = new JLabelWarning( "le montant du service ne peut pas dpasser le total HT!"); private ValidState validState = ValidState.getTrueInstance(); // FIXME: use w private Where w; private DocumentListener docTTCListen; private PropertyChangeListener propertyChangeListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if ((nomArticle.getValidState().isValid()) && (!nomArticle.isEmpty()) && !isFilling()) { int idArticle = nomArticle.getValue().intValue(); SQLTable tableArticle = ((ComptaPropsConfiguration) Configuration.getInstance()) .getRootSociete().getTable("ARTICLE"); SQLRow rowArticle = tableArticle.getRow(idArticle); if (rowArticle != null) { comboTaxe.setValue(rowArticle.getInt("ID_TAXE")); textMontantTTC.setText(((BigDecimal) rowArticle.getObject("PV_TTC")).toString()); }/*from w w w .ja v a2s. c o m*/ System.out.println("value article Changed"); } } }; public void addViews() { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); this.docTTCListen = new DocumentListener() { public void changedUpdate(DocumentEvent e) { calculMontant(); } public void removeUpdate(DocumentEvent e) { calculMontant(); } public void insertUpdate(DocumentEvent e) { calculMontant(); } }; /*********************************************************************************** * * RENSEIGNEMENTS **********************************************************************************/ c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight = 1; TitledSeparator sep = new TitledSeparator("Renseignements"); this.add(sep, c); c.insets = new Insets(2, 2, 1, 2); c.gridwidth = 1; // Libell vente JLabel labelNom = new JLabel(getLabelFor("NOM")); labelNom.setHorizontalAlignment(SwingConstants.RIGHT); c.gridy++; c.gridx = 0; c.weightx = 0; this.add(labelNom, c); this.textNom = new SQLSearchableTextCombo(); c.gridx++; c.weightx = 1; c.gridwidth = 2; this.add(this.textNom, c); // Date JLabel labelDate = new JLabel(getLabelFor("DATE")); this.dateSaisie = new JDate(true); c.gridwidth = 1; // c.gridx += 2; c.gridx = 0; c.gridy++; c.weightx = 0; labelDate.setHorizontalAlignment(SwingConstants.RIGHT); this.add(labelDate, c); c.gridx++; c.weightx = 1; this.add(this.dateSaisie, c); // article c.gridy++; c.gridx = 0; this.nomArticle = new ElementComboBox(); JLabel labelNomArticle = new JLabel(getLabelFor("ID_ARTICLE")); c.weightx = 0; labelNomArticle.setHorizontalAlignment(SwingConstants.RIGHT); // this.add(labelNomArticle, c); c.gridx++; c.weightx = 0; c.gridwidth = GridBagConstraints.REMAINDER; // this.add(this.nomArticle, c); this.nomArticle.addValueListener(this.propertyChangeListener); // client this.comboClient = new ElementComboBox(); this.comboClient.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (comboClient.isEmpty()) { w = new Where(getTable().getBase().getTable("AVOIR_CLIENT").getField("ID_CLIENT"), "=", -1); } else { w = new Where(getTable().getBase().getTable("AVOIR_CLIENT").getField("ID_CLIENT"), "=", comboClient.getSelectedId()); } } }); JLabel labelNomClient = new JLabel(getLabelFor("ID_CLIENT")); c.gridy++; c.gridx = 0; c.gridwidth = 1; c.weightx = 0; labelNomClient.setHorizontalAlignment(SwingConstants.RIGHT); this.add(labelNomClient, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 0; this.add(this.comboClient, c); // Selection d'un avoir si le client en possede this.comboAvoir = new ElementComboBox(); JLabel labelAvoirClient = new JLabel(getLabelFor("ID_AVOIR_CLIENT")); c.gridy++; c.gridx = 0; c.gridwidth = 1; c.weightx = 0; labelAvoirClient.setHorizontalAlignment(SwingConstants.RIGHT); // this.add(labelAvoirClient, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 0; // this.add(this.comboAvoir, c); /*********************************************************************************** * * MONTANT **********************************************************************************/ c.gridwidth = GridBagConstraints.REMAINDER; c.gridx = 0; c.gridy++; c.weightx = 1; sep = new TitledSeparator("Montant en Euros"); c.insets = new Insets(10, 2, 1, 2); this.add(sep, c); c.insets = new Insets(2, 2, 1, 2); c.gridwidth = 1; final JLabel labelMontantHT = new JLabel(getLabelFor("MONTANT_HT")); labelMontantHT.setHorizontalAlignment(SwingConstants.RIGHT); this.textMontantHT = new DeviseField(); this.textMontantHT.setEditable(false); this.textMontantHT.setEnabled(false); this.textMontantHT.setFocusable(false); final JLabel labelMontantTTC = new JLabel(getLabelFor("MONTANT_TTC")); labelMontantTTC.setHorizontalAlignment(SwingConstants.RIGHT); this.textMontantTTC = new DeviseField(); this.textMontantTTC.getDocument().addDocumentListener(this.docTTCListen); // Montant HT c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.gridy++; c.gridx = 0; c.gridwidth = 1; this.add(labelMontantHT, c); c.gridx++; c.weightx = 1; this.add(this.textMontantHT, c); // Montant Service c.gridx++; c.weightx = 0; this.add(checkService, c); checkService.addActionListener(new ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { if (isFilling()) return; boolean b = checkService.isSelected(); textMontantService.setEditable(b); textMontantService.setEnabled(b); textMontantService.setFocusable(b); if (!b) { textMontantService.setText(""); // montantServiceValide = true; } else { textMontantService.setText(textMontantHT.getText()); } }; }); this.textMontantService = new DeviseField(); c.gridx++; c.weightx = 1; this.add(this.textMontantService, c); JLabel labelMontantService = new JLabel("de service HT"); c.weightx = 0; c.gridx++; this.add(labelMontantService, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; this.add(this.labelWarning, c); this.labelWarning.setVisible(false); // Choix TVA c.gridy++; c.gridx = 0; c.weightx = 0; c.gridwidth = 1; final JLabel labelTaxe = new JLabel(getLabelFor("ID_TAXE")); labelTaxe.setHorizontalAlignment(SwingUtilities.RIGHT); this.add(labelTaxe, c); c.gridx++; this.comboTaxe = new ElementComboBox(false); c.fill = GridBagConstraints.NONE; this.add(this.comboTaxe, c); c.fill = GridBagConstraints.HORIZONTAL; // Montant TTC c.gridy++; c.gridx = 0; c.weightx = 0; this.add(labelMontantTTC, c); c.gridx++; c.weightx = 0; this.add(this.textMontantTTC, c); /*********************************************************************************** * * MODE DE REGLEMENT **********************************************************************************/ c.gridwidth = GridBagConstraints.REMAINDER; c.gridx = 0; c.gridy++; sep = new TitledSeparator("Mode de rglement"); c.insets = new Insets(10, 2, 1, 2); this.add(sep, c); c.insets = new Insets(2, 2, 1, 2); c.gridx = 0; c.gridy++; c.gridwidth = GridBagConstraints.REMAINDER; this.addView("ID_MODE_REGLEMENT", REQ + ";" + DEC + ";" + SEP); ElementSQLObject eltModeRegl = (ElementSQLObject) this.getView("ID_MODE_REGLEMENT"); this.add(eltModeRegl, c); /*********************************************************************************** * * COMMANDE **********************************************************************************/ c.gridwidth = GridBagConstraints.REMAINDER; c.gridx = 0; c.gridy++; sep = new TitledSeparator("Commande"); c.insets = new Insets(10, 2, 1, 2); this.add(sep, c); c.insets = new Insets(2, 2, 1, 2); this.checkCommande = new JCheckBox("Produit commander"); c.gridx = 0; c.gridy++; c.weightx = 0; c.gridwidth = 2; // this.add(this.checkCommande, c); this.checkCommande.addActionListener(new ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { boolean b = checkCommande.isSelected(); comboFournisseur.setEnabled(b); comboFournisseur.setEditable(b); textEcheance.setEditable(b); textEcheance.setEnabled(b); updateValidState(); }; }); // Fournisseurs JLabel labelFournisseur = new JLabel(getLabelFor("ID_FOURNISSEUR")); c.gridx = 0; c.gridy++; c.weightx = 0; c.gridwidth = 1; labelFournisseur.setHorizontalAlignment(SwingConstants.RIGHT); // this.add(labelFournisseur, c); this.comboFournisseur = new ElementComboBox(); c.gridx++; c.weightx = 1; c.gridwidth = 4; // this.add(this.comboFournisseur, c); // Echeance JLabel labelEcheance = new JLabel("Echeance"); c.gridx = 0; c.gridy++; c.weightx = 0; c.gridwidth = 1; labelEcheance.setHorizontalAlignment(SwingConstants.RIGHT); // this.add(labelEcheance, c); c.gridx++; c.weightx = 1; this.textEcheance = new JTextField(); // this.add(this.textEcheance, c); this.textEcheance.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { calculDate(); } }); c.gridx++; c.weightx = 0; // this.add(this.labelEcheancejours, c); /*********************************************************************************** * * INFORMATIONS COMPLEMENTAIRES **********************************************************************************/ c.gridwidth = GridBagConstraints.REMAINDER; c.gridx = 0; c.gridy++; sep = new TitledSeparator("Informations complmentaires"); c.insets = new Insets(10, 2, 1, 2); // this.add(sep, c); c.insets = new Insets(2, 2, 1, 2); ITextArea textInfos = new ITextArea(); c.gridx = 0; c.gridy++; c.gridheight = GridBagConstraints.REMAINDER; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; // this.add(textInfos, c); this.addSQLObject(this.textNom, "NOM"); this.addRequiredSQLObject(this.comboClient, "ID_CLIENT"); this.addSQLObject(this.nomArticle, "ID_ARTICLE"); this.addRequiredSQLObject(this.textMontantTTC, "MONTANT_TTC"); this.addRequiredSQLObject(this.textMontantHT, "MONTANT_HT"); this.addSQLObject(this.textMontantService, "MONTANT_SERVICE"); this.addRequiredSQLObject(this.dateSaisie, "DATE"); this.addSQLObject(textInfos, "INFOS"); this.addSQLObject(this.comboFournisseur, "ID_FOURNISSEUR"); this.addSQLObject(this.textEcheance, "ECHEANCE"); this.addRequiredSQLObject(this.comboTaxe, "ID_TAXE"); this.addSQLObject(this.comboAvoir, "ID_AVOIR_CLIENT"); this.comboTaxe.setButtonsVisible(false); this.comboTaxe.setValue(2); checkService.setSelected(false); this.textMontantService.setEditable(false); this.textMontantService.setEnabled(false); this.checkCommande.setSelected(false); this.comboFournisseur.setEditable(false); this.comboFournisseur.setEnabled(false); this.textEcheance.setEditable(false); this.textEcheance.setEnabled(false); this.comboTaxe.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { calculMontant(); } }); final SimpleDocumentListener docL = new SimpleDocumentListener() { @Override public void update(DocumentEvent e) { updateValidState(); } }; this.textMontantService.getDocument().addDocumentListener(docL); this.textMontantHT.getDocument().addDocumentListener(docL); this.comboFournisseur.addEmptyListener(new EmptyListener() { @Override public void emptyChange(EmptyObj src, boolean newValue) { updateValidState(); } }); /* * this.nomClient.addValueListener(new PropertyChangeListener() { * * public void propertyChange(PropertyChangeEvent evt) { if (nomClient.isValid()) { * System.err.println("Changed Combo Avoir"); comboAvoir = new ElementComboBox(new * AvoirClientSQLElement(new Where(new * AvoirClientSQLElement().getTable().getField("ID_CLIENT"), "=", * nomClient.getValue()))); if (comboAvoir != null) { comboAvoir.setEnabled(true); } * } else { comboAvoir.setEnabled(false); } } }); */ } @Override public Set<String> getPartialResetNames() { Set<String> s = new HashSet<String>(); s.addAll(super.getPartialResetNames()); s.add("MONTANT_TTC"); s.add("MONTANT_SERVICE"); s.add("MONTANT_HT"); s.add("NOM"); s.add("ID_AVOIR_CLIENT"); s.add("ID_ARTICLE"); s.add("INFOS"); return s; } private void calculMontant() { if (!isFilling()) { float taux; // PrixHT pHT; PrixTTC pTTC; // taux de la TVA selectionnee int idTaxe = this.comboTaxe.getSelectedId(); if (idTaxe > 1) { SQLRow ligneTaxe = getTable().getBase().getTable("TAXE").getRow(idTaxe); if (ligneTaxe != null) { taux = (ligneTaxe.getFloat("TAUX")) / 100.0F; // calcul des montants HT ou TTC if (this.textMontantTTC.getText().trim().length() > 0) { if (this.textMontantTTC.getText().trim().equals("-")) { pTTC = new PrixTTC(0); } else { pTTC = new PrixTTC( GestionDevise.parseLongCurrency(this.textMontantTTC.getText())); } // affichage updateTextHT(GestionDevise.currencyToString(pTTC.calculLongHT(taux))); } else { updateTextHT(""); } } } } } private boolean isMontantServiceValid() { String montant = this.textMontantService.getText().trim(); String montantHT = this.textMontantHT.getText().trim(); boolean b; if (montant.length() == 0) { b = true; } else { if (montantHT.length() == 0) { b = false; } else { b = (GestionDevise.parseLongCurrency(montantHT) >= GestionDevise .parseLongCurrency(montant)); } } this.labelWarning.setVisible(!b); System.err.println("Montant service is valid ? " + b + " --> HT val " + montantHT + " --> service val " + montant); return b; } /* * private void calculMontantHT() { * * float taux; PrixHT pHT; * * if (!this.comboTaxe.isEmpty()) { // taux de la TVA selectionnee SQLRow ligneTaxe = * Configuration.getInstance().getBase().getTable("TAXE").getRow(((Integer) * this.comboTaxe.getValue()).intValue()); taux = (ligneTaxe.getFloat("TAUX")) / 100; // * calcul des montants HT ou TTC if (this.textMontantHT.getText().trim().length() > 0) { * * if (this.textMontantHT.getText().trim().equals("-")) { pHT = new PrixHT(0); } else { * pHT = new PrixHT(Float.parseFloat(this.textMontantHT.getText())); } // affichage * updateTextTTC(String.valueOf(pHT.CalculTTC(taux))); } else updateTextTTC(""); } } */ private void updateTextHT(final String prixHT) { SwingUtilities.invokeLater(new Runnable() { public void run() { textMontantHT.setText(prixHT); } }); } @Override protected SQLRowValues createDefaults() { SQLRowValues vals = new SQLRowValues(this.getTable()); SQLRowAccessor r; try { r = ModeReglementDefautPrefPanel.getDefaultRow(true); SQLElement eltModeReglement = Configuration.getInstance().getDirectory() .getElement("MODE_REGLEMENT"); if (r.getID() > 1) { SQLRowValues rowVals = eltModeReglement.createCopy(r.getID()); System.err.println(rowVals.getInt("ID_TYPE_REGLEMENT")); vals.put("ID_MODE_REGLEMENT", rowVals); } } catch (SQLException e) { System.err.println("Impossible de slectionner le mode de rglement par dfaut du client."); e.printStackTrace(); } return vals; } // private void updateTextTTC(final String prixTTC) { // SwingUtilities.invokeLater(new Runnable() { // // public void run() { // // if (docTTCListen != null) { // // textMontantTTC.getDocument().removeDocumentListener(docTTCListen); // } // // textMontantTTC.setText(prixTTC); // // // textTaxe.setText(prixTVA); // textMontantTTC.getDocument().addDocumentListener(docTTCListen); // } // }); // } private void calculDate() { int aJ = 0; // on rcupre les valeurs saisies if (this.textEcheance.getText().trim().length() != 0) { try { aJ = Integer.parseInt(this.textEcheance.getText()); } catch (Exception e) { System.out.println("Erreur de format sur TextField Ajour " + this.textEcheance.getText()); } } Calendar cal = Calendar.getInstance(); // on fixe le temps sur ToDay + Ajour cal.setTime(new Date()); long tempsMil = aJ * 86400000; cal.setTimeInMillis(cal.getTimeInMillis() + tempsMil); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy"); this.dateEch = cal.getTime(); this.labelEcheancejours.setText("jours, soit le " + dateFormat.format(this.dateEch)); } private void updateValidState() { this.setValidState(this.computeValidState()); } private ValidState computeValidState() { ValidState res = ValidState.getTrueInstance(); if (!this.isMontantServiceValid()) res = res.and(ValidState.createCached(false, this.labelWarning.getText())); if (this.checkCommande.isSelected()) res = res.and(ValidState.createCached(!this.comboFournisseur.isEmpty(), "Fournisseur non renseign")); return res; } private final void setValidState(ValidState validState) { if (!validState.equals(this.validState)) { this.validState = validState; this.fireValidChange(); } } @Override public synchronized ValidState getValidState() { return super.getValidState().and(this.validState); } public int insert(SQLRow order) { // On teste si l'article n'existe pas, on le cre if (this.nomArticle.isEmpty()) { createArticle(); } if (this.textNom.getValue() == null || this.textNom.getValue().trim().length() <= 0) { this.textNom.setValue(this.nomArticle.getTextComp().getText()); } final int id = super.insert(order); // on verifie si le produit est commander if (this.checkCommande.isSelected()) { createCommande(id); } SQLRow rowArt = getTable().getRow(id).getForeignRow("ID_ARTICLE"); if (rowArt != null && !rowArt.isUndefined() && rowArt.getBoolean("GESTION_STOCK")) { Configuration.getInstance().getNonInteractiveSQLExecutor().execute(new Runnable() { @Override public void run() { final SQLRow rowVC = getTable().getRow(id); // Mise jour des stocks final SQLElement eltMvtStock = Configuration.getInstance().getDirectory() .getElement("MOUVEMENT_STOCK"); final SQLRowValues rowVals = new SQLRowValues(eltMvtStock.getTable()); rowVals.put("QTE", -1); rowVals.put("NOM", "Saisie vente comptoir"); rowVals.put("IDSOURCE", id); rowVals.put("SOURCE", getTable().getName()); rowVals.put("ID_ARTICLE", rowVC.getInt("ID_ARTICLE")); rowVals.put("DATE", rowVC.getObject("DATE")); try { final SQLRow row = rowVals.insert(); final ListMap<SQLRow, SQLRowValues> map = ((MouvementStockSQLElement) Configuration .getInstance().getDirectory().getElement("MOUVEMENT_STOCK")) .updateStock(Arrays.asList(row), false); MouvementStockSQLElement.createCommandeF(map, null); } catch (SQLException e) { ExceptionHandler.handle("Erreur lors de la cration des mouvements de stock", e); } } }); } new GenerationMvtSaisieVenteComptoir(id); return id; } private void createCommande(final int id) { System.out.println("Ajout d'une commande"); SQLRow rowSaisie = SaisieVenteComptoirSQLElement.this.getTable().getRow(id); Map<String, Object> m = new HashMap<String, Object>(); // NOM, DATE, ECHEANCE, IDSOURCE, SOURCE, ID_CLI, ID_FOURN, ID_ARTICLE m.put("NOM", rowSaisie.getObject("NOM")); m.put("DATE", rowSaisie.getObject("DATE")); m.put("DATE_ECHEANCE", new java.sql.Date(this.dateEch.getTime())); m.put("IDSOURCE", new Integer(id)); m.put("SOURCE", "SAISIE_VENTE_COMPTOIR"); m.put("ID_CLIENT", rowSaisie.getObject("ID_CLIENT")); m.put("ID_FOURNISSEUR", rowSaisie.getObject("ID_FOURNISSEUR")); m.put("ID_ARTICLE", rowSaisie.getObject("ID_ARTICLE")); SQLTable tableCmd = getTable().getBase().getTable("COMMANDE_CLIENT"); SQLRowValues valCmd = new SQLRowValues(tableCmd, m); try { if (valCmd.getInvalid() == null) { // ajout de l'ecriture valCmd.insert(); } } catch (Exception e) { System.err.println("Erreur l'insertion dans la table " + valCmd.getTable().getName()); e.printStackTrace(); } } private void createArticle() { System.out.println("Cration de l'article"); String tNomArticle = this.nomArticle.getTextComp().getText(); String codeArticle = "";// this.nomArticle.getTextOpt(); if (tNomArticle.trim().length() == 0 && codeArticle.trim().length() == 0) { return; } SQLTable articleTable = getTable().getBase().getTable("ARTICLE"); int idTaxe = this.comboTaxe.getSelectedId(); final BigDecimal prix = StringUtils.getBigDecimalFromUserText(this.textMontantHT.getText()); final BigDecimal prixTTC = StringUtils.getBigDecimalFromUserText(this.textMontantTTC.getText()); if (tNomArticle.trim().length() == 0) { tNomArticle = "Nom Indefini"; } if (codeArticle.trim().length() == 0) { codeArticle = "Indefini"; } SQLRowValues vals = new SQLRowValues(articleTable); vals.put("NOM", tNomArticle); vals.put("CODE", codeArticle); vals.put("PA_HT", prix); vals.put("PV_HT", prix); vals.put("PRIX_METRIQUE_VT_1", prix); vals.put("PRIX_METRIQUE_HA_1", prix); vals.put("PV_TTC", prixTTC); vals.put("ID_UNITE_VENTE", UniteVenteArticleSQLElement.A_LA_PIECE); vals.put("ID_TAXE", new Integer(idTaxe)); vals.put("CREATION_AUTO", Boolean.TRUE); vals.put("GESTION_STOCK", Boolean.FALSE); try { SQLRow row = vals.insert(); this.nomArticle.setValue(row); } catch (SQLException e) { e.printStackTrace(); } } public void update() { if (JOptionPane.showConfirmDialog(this, "Attention en modifiant cette vente comptoir, vous supprimerez les chques et les chances associs. Continuer?", "Modification de vente comptoir", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { // on efface les mouvements de stocks associs SQLRow row = getTable().getRow(this.getSelectedID()); SQLElement eltMvtStock = Configuration.getInstance().getDirectory() .getElement("MOUVEMENT_STOCK"); SQLSelect sel = new SQLSelect(); sel.addSelect(eltMvtStock.getTable().getField("ID")); Where w = new Where(eltMvtStock.getTable().getField("IDSOURCE"), "=", row.getID()); Where w2 = new Where(eltMvtStock.getTable().getField("SOURCE"), "=", getTable().getName()); sel.setWhere(w.and(w2)); List l = (List) eltMvtStock.getTable().getBase().getDataSource().execute(sel.asString(), new ArrayListHandler()); if (l != null) { for (int i = 0; i < l.size(); i++) { Object[] tmp = (Object[]) l.get(i); try { eltMvtStock.archive(((Number) tmp[0]).intValue()); } catch (SQLException e) { e.printStackTrace(); } } } if (this.textNom.getValue() != null && this.textNom.getValue().trim().length() <= 0) { this.textNom.setValue(this.nomArticle.getTextComp().getText()); } // On teste si l'article n'existe pas, on le cre if (this.nomArticle.getValue() == null || Integer.parseInt(this.nomArticle.getValue().toString()) == -1) { createArticle(); } // TODO check echeance, ---> creation article, commande?? super.update(); row = getTable().getRow(this.getSelectedID()); int idMvt = row.getInt("ID_MOUVEMENT"); System.out.println(row.getID() + "__________***************** UPDATE " + idMvt); // on supprime tout ce qui est li la facture EcritureSQLElement eltEcr = (EcritureSQLElement) Configuration.getInstance().getDirectory() .getElement("ECRITURE"); eltEcr.archiveMouvementProfondeur(idMvt, false); SQLRow rowArt = row.getForeignRow("ID_ARTICLE"); if (rowArt != null && !rowArt.isUndefined() && rowArt.getBoolean("GESTION_STOCK")) { // Mise jour des stocks SQLRowValues rowVals = new SQLRowValues(eltMvtStock.getTable()); rowVals.put("QTE", -1); rowVals.put("NOM", "Saisie vente comptoir"); rowVals.put("IDSOURCE", getSelectedID()); rowVals.put("SOURCE", getTable().getName()); rowVals.put("ID_ARTICLE", row.getInt("ID_ARTICLE")); rowVals.put("DATE", row.getObject("DATE")); try { SQLRow rowNew = rowVals.insert(); final ListMap<SQLRow, SQLRowValues> map = ((MouvementStockSQLElement) Configuration .getInstance().getDirectory().getElement("MOUVEMENT_STOCK")) .updateStock(Arrays.asList(rowNew), false); ComptaPropsConfiguration.getInstanceCompta().getNonInteractiveSQLExecutor() .execute(new Runnable() { @Override public void run() { MouvementStockSQLElement.createCommandeF(map, null); } }); } catch (SQLException e) { e.printStackTrace(); } } if (idMvt > 1) { new GenerationMvtSaisieVenteComptoir(this.getSelectedID(), idMvt); } else { new GenerationMvtSaisieVenteComptoir(this.getSelectedID()); } } } @Override public void select(SQLRowAccessor r) { this.textMontantTTC.getDocument().removeDocumentListener(this.docTTCListen); this.nomArticle.rmValueListener(this.propertyChangeListener); super.select(r); checkService.setSelected( r != null && r.getObject("MONTANT_SERVICE") != null && r.getLong("MONTANT_SERVICE") > 0); this.textMontantTTC.getDocument().addDocumentListener(this.docTTCListen); this.nomArticle.addValueListener(this.propertyChangeListener); } @Override public void select(SQLRowAccessor r, Set<String> views) { super.select(r, views); checkService.setSelected( r != null && r.getObject("MONTANT_SERVICE") != null && r.getLong("MONTANT_SERVICE") > 0); } }; }
From source file:org.openconcerto.erp.core.sales.shipment.component.BonDeLivraisonSQLComponent.java
public void addViews() { this.textTotalHT.setOpaque(false); this.textTotalTVA.setOpaque(false); this.textTotalTTC.setOpaque(false); this.selectCommande = new ElementComboBox(); this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); // Champ Module c.gridx = 0;/*from www . ja v a 2s. com*/ c.gridy++; c.gridwidth = GridBagConstraints.REMAINDER; final JPanel addP = ComptaSQLConfElement.createAdditionalPanel(); this.setAdditionalFieldsPanel(new FormLayouter(addP, 2)); this.add(addP, c); c.gridy++; c.gridwidth = 1; // Numero JLabel labelNum = new JLabel(getLabelFor("NUMERO")); labelNum.setHorizontalAlignment(SwingConstants.RIGHT); this.add(labelNum, c); this.textNumeroUnique = new JUniqueTextField(16); c.gridx++; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.NONE; DefaultGridBagConstraints.lockMinimumSize(textNumeroUnique); this.add(this.textNumeroUnique, c); // Date c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; this.add(new JLabel(getLabelFor("DATE"), SwingConstants.RIGHT), c); JDate date = new JDate(true); c.gridx++; c.weightx = 0; c.weighty = 0; c.fill = GridBagConstraints.NONE; this.add(date, c); // Reference c.gridy++; c.gridx = 0; c.fill = GridBagConstraints.HORIZONTAL; this.add(new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT), c); c.gridx++; c.weightx = 1; this.add(this.textNom, c); if (getTable().contains("DATE_LIVRAISON")) { // Date livraison c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; this.add(new JLabel(getLabelFor("DATE_LIVRAISON"), SwingConstants.RIGHT), c); JDate dateLivraison = new JDate(true); c.gridx++; c.weightx = 0; c.weighty = 0; c.fill = GridBagConstraints.NONE; this.add(dateLivraison, c); this.addView(dateLivraison, "DATE_LIVRAISON"); } // Client JLabel labelClient = new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT); c.gridx = 0; c.gridy++; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; c.weighty = 0; this.add(labelClient, c); c.gridx++; c.weightx = 0; c.weighty = 0; c.fill = GridBagConstraints.NONE; this.comboClient = new ElementComboBox(); this.add(this.comboClient, c); if (getTable().contains("SPEC_LIVRAISON")) { // Date livraison c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; this.add(new JLabel(getLabelFor("SPEC_LIVRAISON"), SwingConstants.RIGHT), c); JTextField specLivraison = new JTextField(); c.gridx++; c.weightx = 0; c.weighty = 0; this.add(specLivraison, c); this.addView(specLivraison, "SPEC_LIVRAISON"); } final ElementComboBox boxTarif = new ElementComboBox(); this.comboClient.addValueListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (comboClient.getElement().getTable().contains("ID_TARIF")) { if (BonDeLivraisonSQLComponent.this.isFilling()) return; final SQLRow row = ((SQLRequestComboBox) evt.getSource()).getSelectedRow(); if (row != null) { // SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF"); // if (foreignRow.isUndefined() && // !row.getForeignRow("ID_DEVISE").isUndefined()) { // SQLRowValues rowValsD = new SQLRowValues(foreignRow.getTable()); // rowValsD.put("ID_DEVISE", row.getObject("ID_DEVISE")); // foreignRow = rowValsD; // // } // tableBonItem.setTarif(foreignRow, true); SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF"); if (!foreignRow.isUndefined() && (boxTarif.getSelectedRow() == null || boxTarif.getSelectedId() != foreignRow.getID()) && JOptionPane.showConfirmDialog(null, "Appliquer les tarifs associs au client?") == JOptionPane.YES_OPTION) { boxTarif.setValue(foreignRow.getID()); // SaisieVenteFactureSQLComponent.this.tableFacture.setTarif(foreignRow, // true); } else { boxTarif.setValue(foreignRow.getID()); } } } } }); // Bouton tout livrer JButton boutonAll = new JButton("Tout livrer"); boutonAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { RowValuesTableModel m = BonDeLivraisonSQLComponent.this.tableBonItem.getModel(); // on livre tout les lments for (int i = 0; i < m.getRowCount(); i++) { SQLRowValues rowVals = m.getRowValuesAt(i); Object o = rowVals.getObject("QTE"); int qte = o == null ? 0 : ((Number) o).intValue(); m.putValue(qte, i, "QTE_LIVREE"); } } }); // Tarif if (this.getTable().getFieldsName().contains("ID_TARIF")) { // TARIF c.gridy++; c.gridx = 0; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; this.add(new JLabel("Tarif appliquer"), c); c.gridx++; c.gridwidth = 1; c.weightx = 1; this.add(boxTarif, c); this.addView(boxTarif, "ID_TARIF"); boxTarif.addModelListener("wantedID", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { SQLRow selectedRow = boxTarif.getRequest().getPrimaryTable().getRow(boxTarif.getWantedID()); tableBonItem.setTarif(selectedRow, !isFilling()); } }); } if (getTable().contains("A_ATTENTION")) { // Date livraison c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; this.add(new JLabel(getLabelFor("A_ATTENTION"), SwingConstants.RIGHT), c); JTextField specLivraison = new JTextField(); c.gridx++; c.weightx = 0; c.weighty = 0; this.add(specLivraison, c); this.addView(specLivraison, "A_ATTENTION"); } // Element du bon List<JButton> l = new ArrayList<JButton>(); l.add(boutonAll); this.tableBonItem = new BonDeLivraisonItemTable(l); c.gridx = 0; c.gridy++; c.weightx = 1; c.weighty = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.BOTH; this.add(this.tableBonItem, c); c.anchor = GridBagConstraints.EAST; // Totaux reconfigure(this.textTotalHT); reconfigure(this.textTotalTVA); reconfigure(this.textTotalTTC); // Poids Total c.gridy++; c.gridx = 1; c.weightx = 0; c.weighty = 0; c.anchor = GridBagConstraints.EAST; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; this.addSQLObject(this.textPoidsTotal, "TOTAL_POIDS"); this.addRequiredSQLObject(this.textTotalHT, "TOTAL_HT"); this.addRequiredSQLObject(this.textTotalTVA, "TOTAL_TVA"); this.addRequiredSQLObject(this.textTotalTTC, "TOTAL_TTC"); TotalPanel panelTotal = new TotalPanel(tableBonItem, textTotalHT, textTotalTVA, textTotalTTC, new DeviseField(), new DeviseField(), new DeviseField(), new DeviseField(), new DeviseField(), textPoidsTotal, null); c.gridx = 2; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 0; c.weighty = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; this.add(panelTotal, c); c.anchor = GridBagConstraints.WEST; /******************************************************************************************* * * INFORMATIONS COMPLEMENTAIRES ******************************************************************************************/ c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy++; TitledSeparator sep = new TitledSeparator("Informations complmentaires"); c.insets = new Insets(10, 2, 1, 2); this.add(sep, c); c.insets = new Insets(2, 2, 1, 2); ITextArea textInfos = new ITextArea(4, 4); c.gridx = 0; c.gridy++; c.gridheight = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.BOTH; final JScrollPane scrollPane = new JScrollPane(textInfos); this.add(scrollPane, c); textInfos.setBorder(null); DefaultGridBagConstraints.lockMinimumSize(scrollPane); c.gridx = 0; c.gridy++; c.gridheight = 1; c.gridwidth = 4; c.weightx = 0; c.weighty = 0; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.EAST; this.panelOO = new PanelOOSQLComponent(this); this.add(this.panelOO, c); this.addRequiredSQLObject(date, "DATE"); this.addSQLObject(textInfos, "INFOS"); this.addSQLObject(this.textNom, "NOM"); this.addSQLObject(this.selectCommande, "ID_COMMANDE_CLIENT"); this.addRequiredSQLObject(this.textNumeroUnique, "NUMERO"); this.addRequiredSQLObject(this.comboClient, "ID_CLIENT"); // Doit etre lock a la fin DefaultGridBagConstraints.lockMinimumSize(comboClient); }