Dépôt officiel du code source de l'ERP OpenConcerto
Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.core.sales.pos.ui;
import org.openconcerto.erp.config.ComptaPropsConfiguration;
import org.openconcerto.erp.core.sales.pos.TicketSheetXML;
import org.openconcerto.erp.core.sales.pos.model.Ticket;
import org.openconcerto.utils.ExceptionHandler;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collections;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
public class TicketClientNamePanel extends JPanel {
public TicketClientNamePanel(CaisseFrame caisseFrame, final Ticket ticket) {
this.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(5, 5, 5, 5);
c.gridx = 0;
c.gridy = 0;
c.weightx = 1;
c.weighty = 0;
c.anchor = GridBagConstraints.NORTHWEST;
c.fill = GridBagConstraints.BOTH;
final POSLabel labelNom = new POSLabel("Nom du client");
this.add(labelNom, c);
// Textfield
c.gridy++;
final JTextField text = new JTextField(30);
text.setFont(labelNom.getFont());
text.setText(ticket.getClient().getFullName());
this.add(text, c);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
text.requestFocus();
}
});
c.gridy++;
this.add(new POSLabel("Adresse"), c);
c.gridy++;
JTextArea tAdresse = new JTextArea(3, 20);
tAdresse.setLineWrap(true);
tAdresse.setFont(labelNom.getFont());
tAdresse.setText(ticket.getClient().getAddr());
this.add(new JScrollPane(tAdresse), c);
c.gridy++;
// Textfield
POSButton b = new POSButton("Imprimer");
c.fill = GridBagConstraints.NONE;
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ticket.getClient().setFullName(text.getText());
ticket.getClient().setAdresse(tAdresse.getText());
printInvoice(ticket);
caisseFrame.showCaisse();
}
});
c.gridy++;
this.add(b, c);
}
private void printInvoice(Ticket ticket) {
final TicketSheetXML bSheet = new TicketSheetXML(ticket, ComptaPropsConfiguration.getInstanceCompta());
try {
bSheet.createDocument();
bSheet.showPrintAndExport(true, false, false, true, false, Collections.emptyList());
} catch (Exception originalExn) {
ExceptionHandler.handle("Erreur lors de la création de la facture", originalExn);
}
}
}