-
Notifications
You must be signed in to change notification settings - Fork 0
/
reports.java
731 lines (580 loc) · 19.5 KB
/
reports.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javaGUI.sqlconnection;
import net.proteanit.sql.DbUtils;
import java.awt.Color;
import javax.swing.JComboBox;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
public class reports extends JFrame {
private static JPanel panelMain ;
private JPanel contentPane;
public static double width,height;
private JPanel panelFooter;
private JLabel lblProfit;
private JLabel profitval;
private JLabel lossval;
private JLabel lblLoss;
private JLabel lblClosingStock;
static DateCombo datebox=new DateCombo();
private JComboBox startYear,startMonth,startDate,endYear,endMonth,endDate;
Autocomplete cmpltObj=new Autocomplete();
private JLabel closingstk;
private JLabel lblOpeningStock;
private JLabel openingstk;
private String query1,query2,query3;
PreparedStatement pst1,pst2,pst3;
ResultSet rs1,rs2,rs3;
int starty,startm,startd,endy,endm,endd;
String sDate2,sDate1;
String query;
java.util.Date date2,date1;
public java.sql.Date sqlDate1,sqlDate2;
float closing_stk=0,tax=0,opening_stk=0,sale=0,bill_purchase=0,stk_purchase=0,abnormal=0,expense=0,discount_given=0,discount_receive=0,sale_return=0,purchase_return=0,profit=0,loss=0;
PreparedStatement pst;
ResultSet rs;
int index=0;
public java.sql.Date sqlDate,sqlDate11,sqlDate22;
Connection connection=null;
/**
* Launch the application.
*/
Date minDate,maxDate;
public void boundaryDates()
{
try{
query="select MIN(date) from profitfinder ;";
pst2=connection.prepareStatement(query);
rs2=pst2.executeQuery();
while(rs2.next())
{
minDate=rs2.getDate("date");
System.out.println("minDate:"+ minDate);
JOptionPane.showMessageDialog(null, "MIN DATE:"+minDate);
}
rs2.close();
pst.close();
query="select MAX(date) from profitfinder ;";
pst2=connection.prepareStatement(query);
rs2=pst2.executeQuery();
while(rs2.next())
{
maxDate=rs2.getDate("date");
System.out.println("maxDate:"+ maxDate);
JOptionPane.showMessageDialog(null, "MAX DATE:"+maxDate);
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Date checking error");
e.printStackTrace();
}
}
public void dateIncrement(Date sqlDatett)
{
Calendar c = Calendar.getInstance();
c.setTime(sqlDatett);
System.out.println("sqlDatett :"+sqlDatett);
c.add(Calendar.DATE,+1); // number of days to add
sqlDate22 = new java.sql.Date(c.getTimeInMillis()); // dt is now the new date
}
public void dateDecrement(Date sqlDatet)
{
Calendar c = Calendar.getInstance();
c.setTime(sqlDatet);
c.add(Calendar.DATE,-1); // number of days to add
sqlDate11 = new java.sql.Date(c.getTimeInMillis()); // dt is now the new date
}
public int checkDateO(Date sqlDatet1)
{
/* Date date0=null;
int exist=0;
try{
query="select * from profitfinder where date='"+sqlDatet1+"';";
System.out.println("SQLDATET1 :"+sqlDatet1);
pst2=connection.prepareStatement(query);
rs2=pst2.executeQuery();
if(rs2.next())
{
sqlDate11=sqlDatet1;
System.out.println("FOUND :"+ sqlDatet1);
}else
{
dateDecrement(sqlDatet1);
System.out.println("NOT FOUND :"+ sqlDatet1);
checkDateO(sqlDate11);
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Date checking error");
e.printStackTrace();
}
System.out.println("Opening stock over");
*/
/*String query = "SELECT (count(*) > 0) as found FROM profitfinder WHERE date ='"+sqlDatet1+"'";
try{
pst = connection.prepareStatement(query);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "chec error :"+e);
e.printStackTrace();
}
try (ResultSet rs = pst.executeQuery()) {
// Only expecting a single result
if (rs.next()) {
boolean found = rs.getBoolean(1); // "found" column
if (found) {
sqlDate11=sqlDatet1;
System.out.println("FOUND :"+ sqlDatet1);
// You have rows
} else {
// You have no rows
dateDecrement(sqlDatet1);
System.out.println("NOT FOUND :"+ sqlDatet1);
checkDateO(sqlDate11);
}
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Date checking error");
e.printStackTrace();
}
*/
boundaryDates();
int ch=0;
try{
cmpltObj.date();
String query="select date from profitfinder where date='"+sqlDatet1+"';";
PreparedStatement pst=connection.prepareStatement(query);
ResultSet rs=pst.executeQuery();
while(rs.next())
{
ch=1;
}
pst.close();
rs.close();
if(ch==1)
{
sqlDate11=sqlDatet1;
System.out.println("FOUND :"+ sqlDatet1);
}else
{
dateDecrement(sqlDatet1);
System.out.println("NOT FOUND :"+ sqlDatet1);
if(sqlDatet1.compareTo(minDate)>0)
checkDateO(sqlDate11);
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "ERROR IN CHRCKDATE :"+ e);
e.printStackTrace();
}
return ch;
}
public void checkDateC(Date sqlDatet1)
{
/*Date date0=null;
int exist=0;
try{
query="select * from profitfinder where date='"+sqlDatet1+"'";
pst=connection.prepareStatement(query);
rs=pst.executeQuery();
if(rs.next())
{
exist++;
sqlDate22=sqlDatet1;
System.out.println("SQLDATET1 :"+sqlDate22);
}else
{
index++;
dateIncrement(sqlDatet1);
System.out.println("sQLDATE22 --"+sqlDate22);
checkDateC(sqlDate22);
}
}
catch(Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(null, "checkDateC Error :"+e);
}
*/
//=====================================================================================
/*String query = "SELECT (count(*) > 0) as found FROM profitfinder WHERE date ='"+sqlDatet1+"'";
PreparedStatement pst = connection.prepareStatement(query);
try (ResultSet rs = pst.executeQuery()) {
// Only expecting a single result
if (rs.next()) {
boolean found = rs.getBoolean(1); // "found" column
if (found) {
exist++;
sqlDate22=sqlDatet1;
System.out.println("exist SQLDATET1 :"+sqlDatet1);
// You have rows
} else {
// You have no rows
index++;
dateIncrement(sqlDatet1);
System.out.println("not EXIST sQLDATE22 --"+sqlDate22);
checkDateC(sqlDate22);
}
}
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Date checking error");
e.printStackTrace();
}*/
//============================================================
int ch=0;
try{
cmpltObj.date();
String query="select date from profitfinder where date='"+sqlDatet1+"';";
PreparedStatement pst=connection.prepareStatement(query);
ResultSet rs=pst.executeQuery();
while(rs.next())
{
ch=1;
}
pst.close();
rs.close();
if(ch==1)
{
sqlDate22=sqlDatet1;
System.out.println("FOUND :"+ sqlDatet1);
}else
{
dateIncrement(sqlDatet1);
System.out.println("NOT FOUNDdd :"+ sqlDatet1);
if(maxDate.compareTo(sqlDate22)>0)
checkDateO(sqlDate22);
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "ERROR IN CHRCKDATE :"+ e);
e.printStackTrace();
}
}
public void calculateAll()
{
// fillComboBoxD(dealersBox);
closing_stk=0;
tax=0;
opening_stk=0;
sale=0;
bill_purchase=0;
stk_purchase=0;
abnormal=0;
expense=0;
discount_given=0;
discount_receive=0;
sale_return=0;
purchase_return=0;
profit=0;
loss=0;
getPeriod(startYear,startMonth,startDate,endYear,endMonth,endDate);
Date d1=sqlDate1,d2=sqlDate2;
System.out.println("SQLDATE1 :"+sqlDate1);
System.out.println("SQLDATE2 :"+sqlDate2);
try{
query="select * from allrecord where date between '"+sqlDate1+"' and '"+sqlDate2+"' ORDER BY date DESC";
pst=connection.prepareStatement(query);
rs=pst.executeQuery();
while(rs.next())
{
discount_receive+=Float.parseFloat(rs.getString("discount_receive"));
discount_given+=Float.parseFloat(rs.getString("discount_given"));
expense+=Float.parseFloat(rs.getString("expense"));
abnormal+=Float.parseFloat(rs.getString("abnormal"));
sale_return+=Float.parseFloat(rs.getString("sale_return"));
purchase_return+=Float.parseFloat(rs.getString("purchase_return"));
}
query="select * from profitfinder where date between '"+sqlDate1+"' and '"+sqlDate2+"' ORDER BY date DESC";
pst=connection.prepareStatement(query);
rs=pst.executeQuery();
while(rs.next())
{
tax+=Float.parseFloat(rs.getString("tax"));
stk_purchase+=Float.parseFloat(rs.getString("stockpurchase"));
bill_purchase+=Float.parseFloat(rs.getString("purchase_price"));
sale+=Float.parseFloat(rs.getString("sale_price"));
}
checkDateO(sqlDate1);
checkDateC(sqlDate2);
System.out.println("SQLDATE1 :"+sqlDate11);
System.out.println("SQLDATE2 :"+sqlDate22);
query="select * from profitfinder where date ='"+sqlDate11+"'";
pst=connection.prepareStatement(query);
rs=pst.executeQuery();
while(rs.next())
{
if(d1==sqlDate11)
opening_stk=Float.parseFloat(rs.getString("opening_stk"));
else
opening_stk=Float.parseFloat(rs.getString("closing_stk"));
}
query="select * from profitfinder where date ='"+sqlDate22+"'";
pst=connection.prepareStatement(query);
rs=pst.executeQuery();
while(rs.next())
{
if(d1==sqlDate11)
closing_stk=Float.parseFloat(rs.getString("closing_stk"));
else
closing_stk=Float.parseFloat(rs.getString("opening_stk"));
}
System.out.println("discount_receive:"+discount_receive);
System.out.println("discount_given:"+discount_given);
System.out.println("sale_return:"+sale_return);
System.out.println("expense:"+expense);
System.out.println("abnormal:"+abnormal);
System.out.println("purchase_return:"+purchase_return);
System.out.println("stk_purchase:"+stk_purchase);
System.out.println("bill_purchase:"+bill_purchase);
System.out.println("sale:"+sale);
System.out.println("tax:"+tax);
System.out.println("opening_stk:"+opening_stk);
System.out.println("closing_stk:"+closing_stk);
profit=closing_stk+sale+abnormal-opening_stk-stk_purchase-expense-discount_given+discount_receive+purchase_return-sale_return;
loss= -profit;
System.out.println("profit:"+profit);
System.out.println("loss:"+loss);
if(profit>0)
{
profitval.setText(Float.toString(profit));
lossval.setText("NO LOSS...!");
}else
{
profitval.setText("NO PROFIT...!");
lossval.setText(Float.toString(loss));
}
openingstk.setText(Float.toString(opening_stk));
closingstk.setText(Float.toString(closing_stk));
pst.close();
rs.close();
}
catch(Exception e){
e.printStackTrace();
}
}
//################################### SET DURATION ###########################################
public void getPeriod(JComboBox startYear,JComboBox startMonth,JComboBox startDate,JComboBox endYear,JComboBox endMonth,JComboBox endDate)
{
starty=Integer.parseInt(startYear.getSelectedItem().toString());
// startm=Integer.parseInt(startMonth.getSelectedItem());
startm=Integer.parseInt(startMonth.getSelectedItem().toString());
// startm=Integer.parseInt(startMonth.getSelectedItem().toString());
startd=Integer.parseInt((String)startDate.getSelectedItem());
endy=Integer.parseInt(endYear.getSelectedItem().toString());
endm=Integer.parseInt(endMonth.getSelectedItem().toString());
endd=Integer.parseInt((String) endDate.getSelectedItem());
sDate1=starty+"-"+startm+"-"+startd;
try{
date1=new SimpleDateFormat("yyyy-MM-dd").parse(sDate1);
sDate2=endy+"-"+endm+"-"+endd;
date2=new SimpleDateFormat("yyyy-MM-dd").parse(sDate2);
//==============================
sqlDate1 = new java.sql.Date(date1.getTime());
sqlDate2 = new java.sql.Date(date2.getTime());
boundaryDates();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//################################### SET DURATION ###########################################
/* public void setday()
{
int n;
int year = Calendar.getInstance().get(Calendar.YEAR);
String months[]=(new DateFormatSymbols()).getMonths();
String weeks[]=(new DateFormatSymbols()).getWeekdays();
if(year%4==0)
n=366;
else
n=365;
for(int i=1;i<=n;i++)
dayBox.addItem(i);
for(int i=0;i<12;i++)
monthBox.addItem(months[i]);
for(int i=1;i<8;i++)
weekBox.addItem(weeks[i]);
for(int i=2000;i<2041;i++)
yearBox.addItem(i);
}
//################################### daySelection ###########################################
public void selectDay()
{
}
//################################### monthSelection ###########################################
public void monthSelection()
{
int n=monthBox.getSelectedIndex();
if(n==0)
{
query1="select closing_stk from allrecord where ";
}
}
*/
//######################### MAIN FUNCTION ######################################################
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
width = screenSize.getWidth();
height = screenSize.getHeight();
reports frame = new reports();
frame.setVisible(true);
frame.setSize((int)width,(int)height);
frame.setResizable(true);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
// frame.getRootPane().setDefaultButton(btnSave);
panelMain.setBounds(0, 0, (int)width, (int)height);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public reports() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
width = screenSize.getWidth();
height = screenSize.getHeight();
connection=sqlconnection.dbConnector();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 1353, 1160);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
panelMain = new JPanel();
panelMain.setBounds(0, 0, (int)width, (int)height);
contentPane.add(panelMain);
panelMain.setLayout(null);
JPanel panelHead = new JPanel();
panelHead.setBackground(new Color(189, 183, 107));
panelHead.setBounds(0, 0, 1920, 180);
panelMain.add(panelHead);
panelHead.setLayout(null);
endYear = new JComboBox();
endYear.setBounds(818, 117, 61, 22);
panelHead.add(endYear);
endMonth = new JComboBox();
endMonth.setBounds(899, 117, 61, 22);
panelHead.add(endMonth);
endDate = new JComboBox();
endDate.setBounds(992, 117, 61, 22);
panelHead.add(endDate);
startYear = new JComboBox();
startYear.setBounds(168, 117, 61, 22);
panelHead.add(startYear);
startMonth = new JComboBox();
startMonth.setBounds(254, 117, 61, 22);
panelHead.add(startMonth);
startDate = new JComboBox();
startDate.setBounds(342, 117, 61, 22);
panelHead.add(startDate);
JLabel label_1 = new JLabel("YEAR");
label_1.setFont(new Font("Tahoma", Font.BOLD, 15));
label_1.setBounds(168, 74, 56, 30);
panelHead.add(label_1);
JLabel label_2 = new JLabel("MONTH");
label_2.setFont(new Font("Tahoma", Font.BOLD, 15));
label_2.setBounds(254, 81, 93, 16);
panelHead.add(label_2);
JLabel label_3 = new JLabel("DAY");
label_3.setFont(new Font("Tahoma", Font.BOLD, 15));
label_3.setBounds(347, 81, 56, 16);
panelHead.add(label_3);
JLabel label_4 = new JLabel("YEAR");
label_4.setFont(new Font("Tahoma", Font.BOLD, 15));
label_4.setBounds(818, 81, 56, 16);
panelHead.add(label_4);
JLabel label_5 = new JLabel("MONTH");
label_5.setFont(new Font("Tahoma", Font.BOLD, 15));
label_5.setBounds(904, 81, 93, 16);
panelHead.add(label_5);
JLabel label_7 = new JLabel("DAY");
label_7.setFont(new Font("Tahoma", Font.BOLD, 15));
label_7.setBounds(997, 81, 56, 16);
panelHead.add(label_7);
panelFooter = new JPanel();
panelFooter.setBackground(new Color(238, 232, 170));
panelFooter.setBounds(0, 180, (int)width, (int)height-180);
panelMain.add(panelFooter);
panelFooter.setLayout(null);
lblProfit = new JLabel("Profit :");
lblProfit.setFont(new Font("Tahoma", Font.BOLD, 20));
lblProfit.setBounds(70, 284, 167, 25);
panelFooter.add(lblProfit);
profitval = new JLabel("");
profitval.setFont(new Font("Tahoma", Font.BOLD, 20));
profitval.setBounds(255, 284, 167, 25);
panelFooter.add(profitval);
lossval = new JLabel("");
lossval.setFont(new Font("Tahoma", Font.BOLD, 20));
lossval.setBounds(255, 362, 167, 25);
panelFooter.add(lossval);
lblLoss = new JLabel("Loss :");
lblLoss.setFont(new Font("Tahoma", Font.BOLD, 20));
lblLoss.setBounds(70, 362, 184, 25);
panelFooter.add(lblLoss);
lblClosingStock = new JLabel("Closing Stock :");
lblClosingStock.setFont(new Font("Tahoma", Font.BOLD, 20));
lblClosingStock.setBounds(70, 205, 173, 25);
panelFooter.add(lblClosingStock);
closingstk = new JLabel("");
closingstk.setFont(new Font("Tahoma", Font.BOLD, 20));
closingstk.setBounds(255, 205, 167, 25);
panelFooter.add(closingstk);
lblOpeningStock = new JLabel("Opening Stock :");
lblOpeningStock.setFont(new Font("Tahoma", Font.BOLD, 20));
lblOpeningStock.setBounds(70, 127, 184, 25);
panelFooter.add(lblOpeningStock);
openingstk = new JLabel("");
openingstk.setFont(new Font("Tahoma", Font.BOLD, 20));
openingstk.setBounds(255, 127, 167, 25);
panelFooter.add(openingstk);
JButton SHOW = new JButton("SHOW");
SHOW.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
calculateAll();
}
});
SHOW.setFont(new Font("Tahoma", Font.BOLD, 18));
SHOW.setBounds(377, 546, 97, 36);
panelFooter.add(SHOW);
datebox.historyComponents(startYear,startMonth,startDate,endYear,endMonth,endDate);
datebox.set();
//setduration();
//setday();
}
}