*** empty log message ***
[thera-pi.git] / Reha / src / org / therapi / reha / patient / AusfallRechnung.java
blob355d42b4cca8e9d8f959b7571de38734618a3749
1 package org.therapi.reha.patient;
3 import hauptFenster.Reha;
5 import java.awt.AlphaComposite;
6 import java.awt.BorderLayout;
7 import java.awt.Dimension;
8 import java.awt.Graphics;
9 import java.awt.Graphics2D;
10 import java.awt.Point;
11 import java.awt.event.ActionEvent;
12 import java.awt.event.ActionListener;
13 import java.awt.event.KeyEvent;
14 import java.awt.event.WindowEvent;
15 import java.awt.event.WindowListener;
16 import java.text.DecimalFormat;
17 import java.util.Iterator;
18 import java.util.Map;
19 import java.util.Set;
21 import javax.swing.ImageIcon;
22 import javax.swing.JButton;
23 import javax.swing.JComponent;
24 import javax.swing.JOptionPane;
25 import javax.swing.JPanel;
27 import oOorgTools.OOTools;
29 import org.jdesktop.swingworker.SwingWorker;
30 import org.jdesktop.swingx.JXPanel;
32 import CommonTools.SqlInfo;
33 import systemEinstellungen.SystemConfig;
34 import CommonTools.JRtaCheckBox;
35 import systemTools.LeistungTools;
36 import terminKalender.DatFunk;
37 import ag.ion.bion.officelayer.application.OfficeApplicationException;
38 import ag.ion.bion.officelayer.document.DocumentDescriptor;
39 import ag.ion.bion.officelayer.document.IDocument;
40 import ag.ion.bion.officelayer.document.IDocumentDescriptor;
41 import ag.ion.bion.officelayer.document.IDocumentService;
42 import ag.ion.bion.officelayer.text.ITextDocument;
43 import ag.ion.bion.officelayer.text.ITextField;
44 import ag.ion.bion.officelayer.text.ITextFieldService;
45 import ag.ion.bion.officelayer.text.TextException;
46 import ag.ion.noa.NOAException;
48 import com.jgoodies.forms.builder.PanelBuilder;
49 import com.jgoodies.forms.layout.CellConstraints;
50 import com.jgoodies.forms.layout.FormLayout;
52 import dialoge.PinPanel;
53 import dialoge.RehaSmartDialog;
54 import events.RehaTPEvent;
55 import events.RehaTPEventClass;
56 import events.RehaTPEventListener;
58 public class AusfallRechnung extends RehaSmartDialog implements RehaTPEventListener,WindowListener, ActionListener{
59 /**
62 private static final long serialVersionUID = 1L;
64 public JRtaCheckBox[] leistung = {null,null,null,null,null};
66 private RehaTPEventClass rtp = null;
67 private AusfallRechnungHintergrund rgb;
69 public JButton uebernahme;
70 public JButton abbrechen;
71 public String afrNummer;
72 public AusfallRechnung(Point pt){
73 super(null,"AusfallRechnung");
76 pinPanel = new PinPanel();
77 pinPanel.setName("AusfallRechnung");
78 pinPanel.getGruen().setVisible(false);
79 setPinPanel(pinPanel);
80 getSmartTitledPanel().setTitle("Ausfallrechnung erstellen");
82 setSize(300,270);
83 setPreferredSize(new Dimension(300,270));
84 getSmartTitledPanel().setPreferredSize(new Dimension (300,270));
85 setPinPanel(pinPanel);
86 rgb = new AusfallRechnungHintergrund();
87 rgb.setLayout(new BorderLayout());
90 new SwingWorker<Void,Void>(){
92 @Override
93 protected Void doInBackground() throws Exception {
95 rgb.setBackgroundPainter(Reha.thisClass.compoundPainter.get("RezeptGebuehren"));
96 return null;
99 }.execute();
100 rgb.add(getGebuehren(),BorderLayout.CENTER);
102 getSmartTitledPanel().setContentContainer(rgb);
103 getSmartTitledPanel().getContentContainer().setName("AusfallRechnung");
104 setName("AusfallRechnung");
105 setModal(true);
106 //Point lpt = new Point(pt.x-125,pt.y+30);
107 Point lpt = new Point(pt.x-150,pt.y+30);
108 setLocation(lpt);
110 rtp = new RehaTPEventClass();
111 rtp.addRehaTPEventListener((RehaTPEventListener) this);
113 pack();
121 /****************************************************/
123 private JPanel getGebuehren(){ // 1 2 3 4 5 6 7
124 FormLayout lay = new FormLayout("10dlu,fill:0:grow(0.50),right:80dlu,10dlu,80dlu,fill:0:grow(0.50),10dlu",
125 // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
126 "15dlu,p,10dlu,p,2dlu,p,2dlu,p,2dlu,p, 10dlu, p, 20dlu, p ,20dlu");
127 PanelBuilder pb = new PanelBuilder(lay);
128 CellConstraints cc = new CellConstraints();
130 pb.getPanel().setOpaque(false);
132 pb.addLabel("Bitte die Positionen auswählen die Sie berechnen wollen",cc.xyw(2, 2, 4));
134 pb.addLabel("Heilmittel 1",cc.xy(3, 4));
135 String lab = (String)Reha.thisClass.patpanel.vecaktrez.get(48);
136 leistung[0] = new JRtaCheckBox((lab.equals("") ? "----" : lab));
137 leistung[0].setOpaque(false);
138 if(!lab.equals("")){
139 leistung[0].setSelected(true);
140 }else{
141 leistung[0].setSelected(false);
142 leistung[0].setEnabled(false);
144 pb.add(leistung[0],cc.xyw(5, 4, 2));
146 pb.addLabel("Heilmittel 2",cc.xy(3, 6));
147 lab = (String)Reha.thisClass.patpanel.vecaktrez.get(49);
148 leistung[1] = new JRtaCheckBox((lab.equals("") ? "----" : lab));
149 leistung[1].setOpaque(false);
150 if(!lab.equals("")){
152 }else{
153 leistung[1].setSelected(false);
154 leistung[1].setEnabled(false);
156 pb.add(leistung[1],cc.xyw(5, 6, 2));
158 pb.addLabel("Heilmittel 3",cc.xy(3, 8));
159 lab = (String)Reha.thisClass.patpanel.vecaktrez.get(50);
160 leistung[2] = new JRtaCheckBox((lab.equals("") ? "----" : lab));
161 leistung[2].setOpaque(false);
162 if(!lab.equals("")){
164 }else{
165 leistung[2].setSelected(false);
166 leistung[2].setEnabled(false);
168 pb.add(leistung[2],cc.xyw(5, 8, 2));
170 pb.addLabel("Heilmittel 4",cc.xy(3, 10));
171 lab = (String)Reha.thisClass.patpanel.vecaktrez.get(51);
172 leistung[3] = new JRtaCheckBox((lab.equals("") ? "----" : lab));
173 leistung[3].setOpaque(false);
174 if(!lab.equals("")){
176 }else{
177 leistung[3].setSelected(false);
178 leistung[3].setEnabled(false);
180 pb.add(leistung[3],cc.xyw(5, 10, 2));
182 pb.addLabel("Eintragen in Memo",cc.xy(3, 12));
183 leistung[4] = new JRtaCheckBox("Fehldaten");
184 leistung[4].setOpaque(false);
185 leistung[4].setSelected(true);
186 pb.add(leistung[4],cc.xyw(5, 12, 2));
188 uebernahme = new JButton("drucken & buchen");
189 uebernahme.setActionCommand("uebernahme");
190 uebernahme.addActionListener(this);
191 uebernahme.addKeyListener(this);
192 pb.add(uebernahme,cc.xy(3,14));
194 abbrechen = new JButton("abbrechen");
195 abbrechen.setActionCommand("abbrechen");
196 abbrechen.addActionListener(this);
197 abbrechen.addKeyListener(this);
198 pb.add(abbrechen,cc.xy(5,14));
200 pb.getPanel().validate();
201 return pb.getPanel();
203 /****************************************************/
205 public void rehaTPEventOccurred(RehaTPEvent evt) {
206 // TODO Auto-generated method stub
207 try{
208 if(evt.getDetails()[0] != null){
209 if(evt.getDetails()[0].equals(this.getName())){
210 this.setVisible(false);
211 rtp.removeRehaTPEventListener((RehaTPEventListener) this);
212 rtp = null;
213 this.dispose();
214 super.dispose();
215 //System.out.println("****************Ausfallrechnung -> Listener entfernt**************");
218 }catch(NullPointerException ne){
219 //System.out.println("In PatNeuanlage" +evt);
222 public void windowClosed(WindowEvent arg0) {
223 // TODO Auto-generated method stub
224 if(rtp != null){
225 this.setVisible(false);
226 rtp.removeRehaTPEventListener((RehaTPEventListener) this);
227 rtp = null;
228 pinPanel = null;
229 dispose();
230 super.dispose();
231 //System.out.println("****************Ausfallrechnung -> Listener entfernt (Closed)**********");
236 @Override
237 public void actionPerformed(ActionEvent arg0) {
238 // TODO Auto-generated method stub
239 if(arg0.getActionCommand().equals("uebernahme")){
240 macheAFRHmap();
241 new SwingWorker<Void,Void>(){
242 @Override
243 protected Void doInBackground() throws Exception {
244 try{
245 starteAusfallRechnung(Reha.proghome+"vorlagen/"+Reha.aktIK+"/AusfallRechnung.ott");
246 doBuchen();
247 if(leistung[4].isSelected()){
248 macheMemoEintrag();
250 }catch(Exception ex){
251 ex.printStackTrace();
252 JOptionPane.showMessageDialog(null, "Fehler bei der Erstellung der Ausfallrechnung");
254 getInstance().dispose();
255 return null;
257 }.execute();
259 new SwingWorker<Void,Void>(){
260 @Override
261 protected Void doInBackground() throws Exception {
262 if(leistung[4].isSelected()){
263 macheMemoEintrag();
265 return null;
267 }.execute();
268 this.dispose();
271 if(arg0.getActionCommand().equals("abbrechen")){
272 this.dispose();
276 private AusfallRechnung getInstance(){
277 return this;
279 private void doBuchen(){
280 StringBuffer buf = new StringBuffer();
281 buf.append("insert into rgaffaktura set ");
282 buf.append("rnr='"+afrNummer+"', ");
283 buf.append("reznr='"+(String)Reha.thisClass.patpanel.vecaktrez.get(1)+"', ");
284 buf.append("pat_intern='"+(String)Reha.thisClass.patpanel.vecaktrez.get(0)+"', ");
285 buf.append("rgesamt='"+(String)SystemConfig.hmAdrAFRDaten.get("<AFRgesamt>").replace(",",".")+"', ");
286 buf.append("roffen='"+(String)SystemConfig.hmAdrAFRDaten.get("<AFRgesamt>").replace(",",".")+"', ");
287 buf.append("rdatum='"+DatFunk.sDatInSQL(DatFunk.sHeute())+"',");
288 buf.append("ik='"+Reha.aktIK+"'");
289 SqlInfo.sqlAusfuehren(buf.toString());
291 private void macheMemoEintrag(){
292 StringBuffer sb = new StringBuffer();
293 sb.append(DatFunk.sHeute()+" - unentschuldigt oder zu spät abgesagt - Rechnung!! - Rechnung-Nr.: "+SystemConfig.hmAdrAFRDaten.get("<AFRnummer>")+"\n");
294 sb.append(Reha.thisClass.patpanel.pmemo[1].getText());
295 Reha.thisClass.patpanel.pmemo[1].setText(sb.toString());
296 String cmd = "update pat5 set pat_text='"+sb.toString()+"' where pat_intern = '"+Reha.thisClass.patpanel.aktPatID+"'";
297 SqlInfo.sqlAusfuehren(cmd);
299 private void macheAFRHmap(){
300 String mappos = "";
301 String mappreis = "";
302 String mapkurz = "";
303 String maplang = "";
304 String[] inpos = {null,null};
305 String spos = "";
306 String sart = "";
307 Double gesamt = new Double(0.00);
308 int preisgruppe = 0;
309 DecimalFormat df = new DecimalFormat( "0.00" );
311 for(int i = 0 ; i < 4; i++){
312 mappos = "<AFRposition"+(i+1)+">";
313 mappreis = "<AFRpreis"+(i+1)+">";
314 mapkurz = "<AFRkurz"+(i+1)+">";
315 maplang = "<AFRlang"+(i+1)+">";
316 if(leistung[i].isSelected()){
317 Double preis = new Double( (String)Reha.thisClass.patpanel.vecaktrez.get(18+i));
318 String s = df.format( preis);
319 SystemConfig.hmAdrAFRDaten.put(mappos,leistung[i].getText());
320 SystemConfig.hmAdrAFRDaten.put(mappreis,s);
321 gesamt = gesamt+preis;
323 spos = (String)Reha.thisClass.patpanel.vecaktrez.get(8+i);
324 sart = (String)Reha.thisClass.patpanel.vecaktrez.get(1);
325 sart = sart.substring(0,2);
326 preisgruppe = Integer.parseInt(Reha.thisClass.patpanel.vecaktrez.get(41))-1;
327 inpos = LeistungTools.getLeistung(sart, spos,preisgruppe);
328 SystemConfig.hmAdrAFRDaten.put(maplang,inpos[0]);
329 SystemConfig.hmAdrAFRDaten.put(mapkurz,inpos[1]);
330 ////System.out.println(inpos[0]);
331 ////System.out.println(inpos[1]);
333 }else{
334 spos = (String)Reha.thisClass.patpanel.vecaktrez.get(8+i);
335 sart = (String)Reha.thisClass.patpanel.vecaktrez.get(1);
336 sart = sart.substring(0,2);
337 preisgruppe = Integer.parseInt(Reha.thisClass.patpanel.vecaktrez.get(41))-1;
338 inpos = LeistungTools.getLeistung(sart, spos,preisgruppe);
340 SystemConfig.hmAdrAFRDaten.put(mappos,leistung[i].getText());
341 SystemConfig.hmAdrAFRDaten.put(mappreis,"0,00");
342 SystemConfig.hmAdrAFRDaten.put(maplang,(!inpos[0].equals("") ? inpos[0] : "----") );
343 SystemConfig.hmAdrAFRDaten.put(mapkurz,(!inpos[1].equals("") ? inpos[1] : "----") );
348 SystemConfig.hmAdrAFRDaten.put("<AFRgesamt>",df.format( gesamt));
349 /// Hier muß noch die Rechnungsnummer bezogen und eingetragen werden
350 afrNummer = "AFR-"+Integer.toString(SqlInfo.erzeugeNummer("afrnr"));
351 SystemConfig.hmAdrAFRDaten.put("<AFRnummer>",afrNummer);
353 public void keyPressed(KeyEvent event) {
354 if(event.getKeyCode()==10){
355 event.consume();
356 if( ((JComponent)event.getSource()).getName().equals("uebernahme")){
357 //doUebernahme();
359 if( ((JComponent)event.getSource()).getName().equals("abbrechen")){
360 this.dispose();
363 //System.out.println("Return Gedrückt");
365 if(event.getKeyCode()==27){
366 this.dispose();
369 @SuppressWarnings({ "unchecked", "rawtypes" })
370 public static void starteAusfallRechnung(String url){
371 IDocumentService documentService = null;;
372 //System.out.println("Starte Datei -> "+url);
373 if(!Reha.officeapplication.isActive()){
374 Reha.starteOfficeApplication();
376 try {
377 documentService = Reha.officeapplication.getDocumentService();
378 } catch (OfficeApplicationException e) {
379 e.printStackTrace();
380 JOptionPane.showMessageDialog(null, "Fehler im OpenOffice-System - Ausfallrechnung kann nicht erstellt werden");
381 return;
383 IDocumentDescriptor docdescript = new DocumentDescriptor();
384 docdescript.setHidden(false);
385 docdescript.setAsTemplate(true);
386 IDocument document = null;
387 //ITextTable[] tbl = null;
388 try {
389 document = documentService.loadDocument(url,docdescript);
390 } catch (NOAException e) {
392 e.printStackTrace();
394 ITextDocument textDocument = (ITextDocument)document;
395 ITextFieldService textFieldService = textDocument.getTextFieldService();
396 ITextField[] placeholders = null;
397 try {
398 placeholders = textFieldService.getPlaceholderFields();
399 } catch (TextException e) {
400 e.printStackTrace();
402 for (int i = 0; i < placeholders.length; i++) {
403 boolean schonersetzt = false;
404 String placeholderDisplayText = placeholders[i].getDisplayText().toLowerCase();
405 /*****************/
406 Set<?> entries = SystemConfig.hmAdrPDaten.entrySet();
407 Iterator<?> it = entries.iterator();
408 while (it.hasNext()) {
409 Map.Entry<String,String> entry = ((Map.Entry<String,String>) it.next());
410 if(((String)entry.getKey()).toLowerCase().equals(placeholderDisplayText)){
411 placeholders[i].getTextRange().setText(((String)entry.getValue()));
412 schonersetzt = true;
413 break;
416 /*****************/
417 entries = SystemConfig.hmAdrAFRDaten.entrySet();
418 it = entries.iterator();
419 while (it.hasNext() && (!schonersetzt)) {
420 Map.Entry entry = (Map.Entry) it.next();
421 if(((String)entry.getKey()).toLowerCase().equals(placeholderDisplayText)){
422 placeholders[i].getTextRange().setText(((String)entry.getValue()));
423 schonersetzt = true;
424 break;
427 if(!schonersetzt){
428 OOTools.loescheLeerenPlatzhalter(textDocument, placeholders[i]);
430 /*****************/
437 class AusfallRechnungHintergrund extends JXPanel{
441 private static final long serialVersionUID = 1L;
442 ImageIcon hgicon;
443 int icx,icy;
444 AlphaComposite xac1 = null;
445 AlphaComposite xac2 = null;
446 public AusfallRechnungHintergrund(){
447 super();
449 hgicon = new ImageIcon(Reha.proghome+"icons/geld.png");
450 icx = hgicon.getIconWidth()/2;
451 icy = hgicon.getIconHeight()/2;
452 xac1 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.15f);
453 xac2 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1.0f);
457 @Override
458 public void paintComponent( Graphics g ) {
459 super.paintComponent( g );
460 @SuppressWarnings("unused")
461 Graphics2D g2d = (Graphics2D)g;
463 if(hgicon != null){
464 //g2d.setComposite(this.xac1);
465 //g2d.drawImage(hgicon.getImage(), (getWidth()/2)-icx , (getHeight()/2)-icy,null);
466 //g2d.setComposite(this.xac2);