package gui;
import hibernateSwingApi.component.TablePanel;
import hibernateSwingApi.hibernate.HibernateManager;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import pojos.Iade;
import pojos.UrunSatis;
import pojos.UrunSatisKasa;
import pojos.YapilanSatis;
import service.PSAUtil;
public class PSASatisDetayEkrani extends JFrame {
private static final long serialVersionUID = 1L;
private static PSASatisDetayEkrani instance;
private JPanel panel;
private TablePanel cTablePanelSatisDetay;
private JLabel cLabelSatisBilgi;
private YapilanSatis yapilanSatis;
private JLabel jLabelToplamIadeTutar;
private JLabel jLabelToplamIadeTutarBilgisi;
private JLabel jLabelUyari;
private JLabel jLabelIadeTL;
private JPanel panel_1;
public static PSASatisDetayEkrani getSatisDetayEkrani(YapilanSatis satis) {
if (satis != null)
instance = new PSASatisDetayEkrani(satis);
return instance;
}
private PSASatisDetayEkrani(YapilanSatis satis) {
yapilanSatis = satis;
initialize();
}
private void initialize() {
setTitle("PSA MERKEZ SATIŞ DETAY EKRANI");
setResizable(false);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setBounds(0, 0, 1000, 580);
setIconImage(PSAUtil.getImageIconViaRelativePath("picture/psaIcon.png")
.getImage());
getContentPane().setLayout(null);
panel = new JPanel();
panel.setBounds(0, 0, 994, 310);
cTablePanelSatisDetay = new TablePanel((String) null,
UrunSatisKasa.class, true, true);
cTablePanelSatisDetay.getTable().setAutoResizeMode(
JTable.AUTO_RESIZE_ALL_COLUMNS);
cTablePanelSatisDetay.setBounds(10, 39, 974, 271);
cTablePanelSatisDetay.setBorder(new LineBorder(new Color(0, 0, 0), 2));
cTablePanelSatisDetay.getTable().setBorder(
new TitledBorder(null, "", TitledBorder.LEADING,
TitledBorder.TOP, null, null));
cLabelSatisBilgi = new JLabel("");
cLabelSatisBilgi.setBounds(10, 8, 569, 20);
cLabelSatisBilgi.setFont(new Font("Tahoma", Font.BOLD, 16));
getContentPane().add(panel);
panel.setLayout(null);
panel.add(cLabelSatisBilgi);
panel.add(cTablePanelSatisDetay);
jLabelUyari = new JLabel(
"NS -> NORMAL SATIŞ IS -> İADE SATIŞ");
jLabelUyari.setFont(new Font("Tahoma", Font.BOLD, 12));
jLabelUyari.setHorizontalAlignment(SwingConstants.CENTER);
jLabelUyari.setBounds(589, 13, 395, 14);
panel.add(jLabelUyari);
panel_1 = new JPanel();
panel_1.setBorder(new LineBorder(new Color(0, 0, 0), 2));
panel_1.setBackground(UIManager.getColor("Button.shadow"));
panel_1.setBounds(111, 489, 709, 52);
getContentPane().add(panel_1);
GridBagLayout gbl_panel_1 = new GridBagLayout();
gbl_panel_1.columnWidths = new int[] { 187, 224, 44, 184, 0 };
gbl_panel_1.rowHeights = new int[] { 25, 0 };
gbl_panel_1.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0,
Double.MIN_VALUE };
gbl_panel_1.rowWeights = new double[] { 1.0, Double.MIN_VALUE };
panel_1.setLayout(gbl_panel_1);
jLabelToplamIadeTutar = new JLabel("TOPLAM İADE TUTAR");
GridBagConstraints gbc_jLabelToplamIadeTutar = new GridBagConstraints();
gbc_jLabelToplamIadeTutar.anchor = GridBagConstraints.WEST;
gbc_jLabelToplamIadeTutar.insets = new Insets(0, 0, 0, 5);
gbc_jLabelToplamIadeTutar.gridx = 1;
gbc_jLabelToplamIadeTutar.gridy = 0;
panel_1.add(jLabelToplamIadeTutar, gbc_jLabelToplamIadeTutar);
jLabelToplamIadeTutar.setHorizontalAlignment(SwingConstants.CENTER);
jLabelToplamIadeTutar.setFont(new Font("Tahoma", Font.BOLD, 14));
jLabelToplamIadeTutarBilgisi = new JLabel("333");
GridBagConstraints gbc_jLabelToplamIadeTutarBilgisi = new GridBagConstraints();
gbc_jLabelToplamIadeTutarBilgisi.insets = new Insets(0, 0, 0, 5);
gbc_jLabelToplamIadeTutarBilgisi.gridx = 2;
gbc_jLabelToplamIadeTutarBilgisi.gridy = 0;
panel_1.add(jLabelToplamIadeTutarBilgisi,
gbc_jLabelToplamIadeTutarBilgisi);
jLabelToplamIadeTutarBilgisi
.setHorizontalAlignment(SwingConstants.CENTER);
jLabelToplamIadeTutarBilgisi.setFont(new Font("Tahoma", Font.BOLD, 14));
jLabelIadeTL = new JLabel("TL");
GridBagConstraints gbc_jLabelIadeTL = new GridBagConstraints();
gbc_jLabelIadeTL.anchor = GridBagConstraints.WEST;
gbc_jLabelIadeTL.gridx = 3;
gbc_jLabelIadeTL.gridy = 0;
panel_1.add(jLabelIadeTL, gbc_jLabelIadeTL);
jLabelIadeTL.setFont(new Font("Tahoma", Font.BOLD, 14));
tabloDoldur(yapilanSatis);
odemeDetayGoster();
initListener();
}
private void odemeDetayGoster() {
OdemeDetayPanel odp = new OdemeDetayPanel();
JPanel odemePanel = odp.initialize(yapilanSatis.getOdemeBilgisi());
odemePanel.setBounds(111, 321, odemePanel.getWidth(),
odemePanel.getHeight());
getContentPane().add(odemePanel);
}
private void initListener() {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
kasaEkranSetEnable();
}
});
}
protected void kasaEkranSetEnable() {
PSAKasaEkrani.getInstance(1).setEnabled(true);
instance.dispose();
}
@SuppressWarnings("unchecked")
private void tabloDoldur(YapilanSatis satis) {
cLabelSatisBilgi.setText(satis.getTarih().toString()
+ " tarihinde yapılan satışın detayları");
List<UrunSatis> satisListesi = (List<UrunSatis>) HibernateManager
.getInstance().getEntitysList(satis, "satisListesi");
List<UrunSatisKasa> convertToUrunSatisKasa = convertToUrunSatisKasa(satisListesi);
cTablePanelSatisDetay.setObjects(convertToUrunSatisKasa);
List<Iade> iadeList = (List<Iade>) HibernateManager.getInstance()
.getEntitysList(satis, "iadeBilgisi");
double toplamIadeTutar = 0.0;
for (int i = 0; i < iadeList.size(); i++) {
double iadeTutar = iadeList.get(i).getTutar();
toplamIadeTutar += iadeTutar;
}
jLabelToplamIadeTutarBilgisi.setText(String.valueOf(toplamIadeTutar));
}
private static List<UrunSatisKasa> convertToUrunSatisKasa(
List<UrunSatis> list) {
List<UrunSatisKasa> kasaList = new LinkedList<>();
for (UrunSatis urunSatis : list) {
UrunSatisKasa kasaUrun = new UrunSatisKasa(urunSatis);
kasaUrun.setSatisDurum(urunSatis.getSatisDurum());
kasaUrun.setSatisId(urunSatis.getSatisId());
kasaUrun.setYapilanSatis(urunSatis.isYapilanSatis());
kasaList.add(kasaUrun);
}
return kasaList;
}
}