Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Md. Sofiqul Islam
Added: Nov 21, 2018 6:14 AM
Views: 22
Tags: no tags
  1. package com.coderbd.view;
  2.  
  3. import com.coderbd.domain.Purchase;
  4. import com.coderbd.domain.Sales;
  5. import com.coderbd.domain.Summary;
  6. import com.coderbd.domain.User;
  7. import com.coderbd.service.PurchaseService;
  8. import com.coderbd.service.ReportService;
  9. import com.coderbd.service.SalesService;
  10. import com.coderbd.service.SummaryService;
  11. import com.coderbd.util.MenuFormSalesMan;
  12. import java.text.SimpleDateFormat;
  13. import java.util.Date;
  14. import java.util.List;
  15. import javax.swing.table.DefaultTableModel;
  16.  
  17. /**
  18.  *
  19.  * @author User
  20.  */
  21. public class SalesViewForSalesMan extends javax.swing.JFrame {
  22.  
  23.     public SalesViewForSalesMan() {
  24.         initComponents();
  25.         displaySummaryIntoTable();
  26.         if (rAllSales.isSelected() == true) {
  27.             displaySalesIntoTable();
  28.         }
  29.  
  30.         txtProductId.setVisible(false);
  31.         MenuFormSalesMan.commonMenuForSalesMan(this);
  32.         txtLoginMsg.setText(Login.loggedIn);
  33.     }
  34.  
  35.     public void clearForm() {
  36.  
  37.         txtPName.setText("");
  38.         txtPCode.setText("");
  39.         txtQty.setText("");
  40.         txtUnitPrice.setText("");
  41.         txtTotalPrice.setText("");
  42.         lblMsg.setText("");
  43.     }
  44.  
  45.     public void displaySummaryIntoTable() {
  46.         DefaultTableModel model = (DefaultTableModel) tblSummary.getModel();
  47.         model.setRowCount(0);
  48.         Object[] row = new Object[6];
  49.         List<Summary> summarys = SummaryService.getSummaryList();
  50.         for (int i = 0; i < summarys.size(); i++) {
  51.             row[0] = summarys.get(i).getProductName();
  52.             row[1] = summarys.get(i).getProductCode();
  53.             row[2] = summarys.get(i).getTotalQty();
  54.             row[3] = summarys.get(i).getSoldQty();
  55.             row[4] = summarys.get(i).getAvailableQty();
  56.             row[5] = summarys.get(i).getPurchase().getProductCategory().getName();
  57.             model.addRow(row);
  58.         }
  59.  
  60.     }
  61.  
  62.     public void displaySalesIntoTable() {
  63.         DefaultTableModel model = (DefaultTableModel) tblSales.getModel();
  64.         model.setRowCount(0);
  65.         Object[] row = new Object[7];
  66.         List<Sales> list = ReportService.getSalesByUser(Login.loggedInUserId);
  67.         for (int i = 0; i < list.size(); i++) {
  68.             row[0] = list.get(i).getProductName();
  69.             row[1] = list.get(i).getProductCode();
  70.             row[2] = list.get(i).getQty();
  71.             row[3] = list.get(i).getUnitprice();
  72.             row[4] = list.get(i).getTotalPrice();
  73.             row[5] = list.get(i).getSalesdate();
  74.             row[6] = list.get(i).getPurchase().getProductCategory().getName();
  75.  
  76.             model.addRow(row);
  77.         }
  78.  
  79.     }
  80.  
  81.     /**
  82.      * This method is called from within the constructor to initialize the form.
  83.      * WARNING: Do NOT modify this code. The content of this method is always
  84.      * regenerated by the Form Editor.
  85.      */
  86.     @SuppressWarnings("unchecked")
  87.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  88.     private void initComponents() {
  89.  
  90.         jLabel1 = new javax.swing.JLabel();
  91.         jPanel1 = new javax.swing.JPanel();
  92.         jLabel3 = new javax.swing.JLabel();
  93.         txtLoginMsg = new javax.swing.JLabel();
  94.         jPanel2 = new javax.swing.JPanel();
  95.         jLabel4 = new javax.swing.JLabel();
  96.         jLabel6 = new javax.swing.JLabel();
  97.         txtPName = new javax.swing.JTextField();
  98.         jLabel7 = new javax.swing.JLabel();
  99.         txtPCode = new javax.swing.JTextField();
  100.         btnSearch = new javax.swing.JButton();
  101.         jLabel8 = new javax.swing.JLabel();
  102.         txtUnitPrice = new javax.swing.JTextField();
  103.         jLabel9 = new javax.swing.JLabel();
  104.         txtQty = new javax.swing.JTextField();
  105.         jLabel10 = new javax.swing.JLabel();
  106.         lblMsg = new javax.swing.JLabel();
  107.         btnSales = new javax.swing.JButton();
  108.         jLabel5 = new javax.swing.JLabel();
  109.         btnClear = new javax.swing.JButton();
  110.         txtAvialble = new javax.swing.JLabel();
  111.         txtTotalPrice = new javax.swing.JLabel();
  112.         txtProductId = new javax.swing.JLabel();
  113.         jPanel3 = new javax.swing.JPanel();
  114.         jScrollPane2 = new javax.swing.JScrollPane();
  115.         tblSummary = new javax.swing.JTable();
  116.         jPanel4 = new javax.swing.JPanel();
  117.         jScrollPane1 = new javax.swing.JScrollPane();
  118.         tblSales = new javax.swing.JTable();
  119.         jLabel11 = new javax.swing.JLabel();
  120.         jLabel12 = new javax.swing.JLabel();
  121.         rAllSales = new javax.swing.JRadioButton();
  122.         txtStartDate = new javax.swing.JTextField();
  123.         txtEndDate = new javax.swing.JTextField();
  124.         btnViewSales = new javax.swing.JButton();
  125.         jPanel5 = new javax.swing.JPanel();
  126.         jLabel2 = new javax.swing.JLabel();
  127.  
  128.         jLabel1.setText("jLabel1");
  129.  
  130.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  131.  
  132.         jPanel1.setBackground(new java.awt.Color(255, 255, 204));
  133.  
  134.         jLabel3.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
  135.         jLabel3.setText("Sales & Inventory Giant ~ Sales");
  136.  
  137.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  138.         jPanel1.setLayout(jPanel1Layout);
  139.         jPanel1Layout.setHorizontalGroup(
  140.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  141.             .addGroup(jPanel1Layout.createSequentialGroup()
  142.                 .addGap(18, 18, 18)
  143.                 .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  144.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  145.                 .addComponent(txtLoginMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 530, javax.swing.GroupLayout.PREFERRED_SIZE)
  146.                 .addContainerGap())
  147.         );
  148.         jPanel1Layout.setVerticalGroup(
  149.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  150.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  151.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  152.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  153.                     .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  154.                     .addComponent(txtLoginMsg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  155.                 .addContainerGap())
  156.         );
  157.  
  158.         jPanel2.setBackground(new java.awt.Color(255, 255, 204));
  159.  
  160.         jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  161.         jLabel4.setText("Sell  Products");
  162.  
  163.         jLabel6.setText("Product Name");
  164.  
  165.         jLabel7.setText("Product Code");
  166.  
  167.         btnSearch.setText("Search");
  168.         btnSearch.addActionListener(new java.awt.event.ActionListener() {
  169.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  170.                 btnSearchActionPerformed(evt);
  171.             }
  172.         });
  173.  
  174.         jLabel8.setText("Unit Price");
  175.  
  176.         txtUnitPrice.setText("0");
  177.  
  178.         jLabel9.setText("Sales Qty");
  179.  
  180.         txtQty.setText("0");
  181.         txtQty.addMouseListener(new java.awt.event.MouseAdapter() {
  182.             public void mousePressed(java.awt.event.MouseEvent evt) {
  183.                 txtQtyMousePressed(evt);
  184.             }
  185.         });
  186.  
  187.         jLabel10.setText("Total Price");
  188.  
  189.         btnSales.setBackground(new java.awt.Color(255, 153, 0));
  190.         btnSales.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
  191.         btnSales.setText("Sales");
  192.         btnSales.addActionListener(new java.awt.event.ActionListener() {
  193.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  194.                 btnSalesActionPerformed(evt);
  195.             }
  196.         });
  197.  
  198.         jLabel5.setText("Available Qty");
  199.  
  200.         btnClear.setBackground(new java.awt.Color(255, 153, 0));
  201.         btnClear.setText("Clear");
  202.         btnClear.addActionListener(new java.awt.event.ActionListener() {
  203.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  204.                 btnClearActionPerformed(evt);
  205.             }
  206.         });
  207.  
  208.         txtAvialble.setText("0");
  209.  
  210.         txtTotalPrice.setText("0");
  211.  
  212.         txtProductId.setText("0");
  213.  
  214.         javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
  215.         jPanel2.setLayout(jPanel2Layout);
  216.         jPanel2Layout.setHorizontalGroup(
  217.             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  218.             .addGroup(jPanel2Layout.createSequentialGroup()
  219.                 .addContainerGap()
  220.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  221.                     .addComponent(jLabel4)
  222.                     .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  223.                         .addGroup(jPanel2Layout.createSequentialGroup()
  224.                             .addComponent(btnClear)
  225.                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  226.                             .addComponent(btnSales))
  227.                         .addGroup(jPanel2Layout.createSequentialGroup()
  228.                             .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  229.                                 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
  230.                                     .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  231.                                         .addComponent(jLabel6)
  232.                                         .addComponent(jLabel7)
  233.                                         .addComponent(jLabel8)
  234.                                         .addComponent(jLabel9)
  235.                                         .addComponent(jLabel10))
  236.                                     .addGap(24, 24, 24))
  237.                                 .addGroup(jPanel2Layout.createSequentialGroup()
  238.                                     .addComponent(jLabel5)
  239.                                     .addGap(27, 27, 27)))
  240.                             .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  241.                                 .addComponent(lblMsg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  242.                                 .addComponent(txtPName)
  243.                                 .addGroup(jPanel2Layout.createSequentialGroup()
  244.                                     .addComponent(txtPCode, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
  245.                                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  246.                                     .addComponent(btnSearch))
  247.                                 .addComponent(txtUnitPrice)
  248.                                 .addComponent(txtQty)
  249.                                 .addComponent(txtAvialble, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  250.                                 .addComponent(txtTotalPrice, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  251.                                 .addComponent(txtProductId, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
  252.                 .addContainerGap(209, Short.MAX_VALUE))
  253.         );
  254.         jPanel2Layout.setVerticalGroup(
  255.             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  256.             .addGroup(jPanel2Layout.createSequentialGroup()
  257.                 .addContainerGap()
  258.                 .addComponent(jLabel4)
  259.                 .addGap(4, 4, 4)
  260.                 .addComponent(txtProductId)
  261.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  262.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  263.                     .addComponent(jLabel5)
  264.                     .addComponent(txtAvialble, javax.swing.GroupLayout.DEFAULT_SIZE, 21, Short.MAX_VALUE))
  265.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  266.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  267.                     .addComponent(jLabel6)
  268.                     .addComponent(txtPName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  269.                 .addGap(18, 18, 18)
  270.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  271.                     .addComponent(jLabel7)
  272.                     .addComponent(txtPCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  273.                     .addComponent(btnSearch))
  274.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  275.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  276.                     .addComponent(jLabel8)
  277.                     .addComponent(txtUnitPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  278.                 .addGap(18, 18, 18)
  279.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  280.                     .addComponent(jLabel9)
  281.                     .addComponent(txtQty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  282.                 .addGap(18, 18, 18)
  283.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  284.                     .addComponent(jLabel10)
  285.                     .addComponent(txtTotalPrice, javax.swing.GroupLayout.DEFAULT_SIZE, 21, Short.MAX_VALUE))
  286.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  287.                 .addComponent(lblMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
  288.                 .addGap(18, 18, 18)
  289.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  290.                     .addComponent(btnSales)
  291.                     .addComponent(btnClear))
  292.                 .addContainerGap(59, Short.MAX_VALUE))
  293.         );
  294.  
  295.         jPanel3.setBackground(new java.awt.Color(204, 255, 204));
  296.         jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Store Summary"));
  297.  
  298.         tblSummary.setModel(new javax.swing.table.DefaultTableModel(
  299.             new Object [][] {
  300.  
  301.             },
  302.             new String [] {
  303.                 "Name", "Code", "Total Qty", "Sold Qty", "Available Qty", "Category"
  304.             }
  305.         ));
  306.         jScrollPane2.setViewportView(tblSummary);
  307.  
  308.         javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
  309.         jPanel3.setLayout(jPanel3Layout);
  310.         jPanel3Layout.setHorizontalGroup(
  311.             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  312.             .addGroup(jPanel3Layout.createSequentialGroup()
  313.                 .addContainerGap()
  314.                 .addComponent(jScrollPane2)
  315.                 .addContainerGap())
  316.         );
  317.         jPanel3Layout.setVerticalGroup(
  318.             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  319.             .addGroup(jPanel3Layout.createSequentialGroup()
  320.                 .addContainerGap()
  321.                 .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
  322.                 .addContainerGap())
  323.         );
  324.  
  325.         jPanel4.setBackground(new java.awt.Color(204, 204, 255));
  326.         jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Sales Details Info"));
  327.  
  328.         tblSales.setModel(new javax.swing.table.DefaultTableModel(
  329.             new Object [][] {
  330.  
  331.             },
  332.             new String [] {
  333.                 "Name", "Code", "Qty", "U.P", "T.P", "Date", "Category"
  334.             }
  335.         ));
  336.         jScrollPane1.setViewportView(tblSales);
  337.  
  338.         jLabel11.setText("From Date");
  339.  
  340.         jLabel12.setText("To Date");
  341.  
  342.         rAllSales.setSelected(true);
  343.         rAllSales.setText("All");
  344.  
  345.         txtStartDate.setText("2018-01-15");
  346.  
  347.         txtEndDate.setText("2018-12-31");
  348.  
  349.         btnViewSales.setBackground(new java.awt.Color(255, 153, 0));
  350.         btnViewSales.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
  351.         btnViewSales.setText("View Sales");
  352.         btnViewSales.addActionListener(new java.awt.event.ActionListener() {
  353.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  354.                 btnViewSalesActionPerformed(evt);
  355.             }
  356.         });
  357.  
  358.         javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
  359.         jPanel4.setLayout(jPanel4Layout);
  360.         jPanel4Layout.setHorizontalGroup(
  361.             jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  362.             .addGroup(jPanel4Layout.createSequentialGroup()
  363.                 .addContainerGap()
  364.                 .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  365.                     .addGroup(jPanel4Layout.createSequentialGroup()
  366.                         .addComponent(rAllSales)
  367.                         .addGap(26, 26, 26)
  368.                         .addComponent(jLabel11)
  369.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  370.                         .addComponent(txtStartDate, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
  371.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  372.                         .addComponent(jLabel12)
  373.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  374.                         .addComponent(txtEndDate, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
  375.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  376.                         .addComponent(btnViewSales)
  377.                         .addGap(0, 0, Short.MAX_VALUE))
  378.                     .addComponent(jScrollPane1))
  379.                 .addContainerGap())
  380.         );
  381.         jPanel4Layout.setVerticalGroup(
  382.             jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  383.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
  384.                 .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  385.                     .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  386.                         .addComponent(jLabel12)
  387.                         .addComponent(txtEndDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  388.                         .addComponent(txtStartDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  389.                         .addComponent(btnViewSales))
  390.                     .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  391.                         .addComponent(rAllSales)
  392.                         .addComponent(jLabel11)))
  393.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  394.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
  395.                 .addContainerGap())
  396.         );
  397.  
  398.         jPanel5.setBackground(new java.awt.Color(255, 255, 204));
  399.  
  400.         jLabel2.setText("2018 J2EE Round-37, CCSL, All rights reserved.");
  401.  
  402.         javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
  403.         jPanel5.setLayout(jPanel5Layout);
  404.         jPanel5Layout.setHorizontalGroup(
  405.             jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  406.             .addGroup(jPanel5Layout.createSequentialGroup()
  407.                 .addContainerGap()
  408.                 .addComponent(jLabel2)
  409.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  410.         );
  411.         jPanel5Layout.setVerticalGroup(
  412.             jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  413.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
  414.                 .addContainerGap(22, Short.MAX_VALUE)
  415.                 .addComponent(jLabel2)
  416.                 .addGap(20, 20, 20))
  417.         );
  418.  
  419.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  420.         getContentPane().setLayout(layout);
  421.         layout.setHorizontalGroup(
  422.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  423.             .addGroup(layout.createSequentialGroup()
  424.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  425.                     .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  426.                     .addGroup(layout.createSequentialGroup()
  427.                         .addGap(8, 8, 8)
  428.                         .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  429.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  430.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  431.                             .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  432.                             .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
  433.                     .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  434.                 .addContainerGap())
  435.         );
  436.         layout.setVerticalGroup(
  437.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  438.             .addGroup(layout.createSequentialGroup()
  439.                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  440.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  441.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  442.                     .addGroup(layout.createSequentialGroup()
  443.                         .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  444.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  445.                         .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  446.                     .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  447.                 .addGap(31, 31, 31)
  448.                 .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  449.                 .addGap(10, 10, 10))
  450.         );
  451.  
  452.         pack();
  453.     }// </editor-fold>                        
  454.  
  455.     private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {                                        
  456.         // TODO add your handling code here:
  457.     }                                        
  458.  
  459.     private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {                                          
  460.         // TODO add your handling code here:
  461.         try {
  462.             if (txtPCode.getText().trim().length() >= 5) {
  463.  
  464.                 Summary summary = SummaryService.getSummaryByProductCode(txtPCode.getText().trim());
  465.                 txtAvialble.setText(String.valueOf(summary.getAvailableQty()));
  466.  
  467.                 Purchase purchase = PurchaseService.getProductDetails(txtPCode.getText().trim());
  468.                 txtPName.setText(purchase.getProductName());
  469.                 txtUnitPrice.setText(String.valueOf(Math.round(purchase.getUnitprice() * 1.10)));
  470.                 txtProductId.setText(String.valueOf(purchase.getId()));
  471.             } else {
  472.                 lblMsg.setText("Enter Valid Product Code");
  473.             }
  474.         } catch (Exception e) {
  475.             lblMsg.setText("Enter Valid Product Code");
  476.         }
  477.     }                                        
  478.  
  479.     private void txtQtyMousePressed(java.awt.event.MouseEvent evt) {                                    
  480.         // TODO add your handling code here:
  481.         double price = Double.parseDouble(txtUnitPrice.getText().trim()) * Integer.parseInt(txtQty.getText().trim());
  482.         txtTotalPrice.setText(String.valueOf(price));
  483.     }                                  
  484.  
  485.     private void btnSalesActionPerformed(java.awt.event.ActionEvent evt) {                                        
  486.         // TODO add your handling code here:
  487.         Sales sales = new Sales();
  488.         sales.setProductName(txtPName.getText().trim());
  489.         sales.setProductCode(txtPCode.getText().trim());
  490.         sales.setQty(Integer.parseInt(txtQty.getText().trim()));
  491.         sales.setUnitprice(Double.parseDouble(txtUnitPrice.getText().trim()));
  492.         sales.setTotalPrice(Double.parseDouble(txtTotalPrice.getText().trim()));
  493.         sales.setSalesdate(new Date());
  494.         Purchase purchase = new Purchase();
  495.         purchase.setId(Integer.parseInt(txtProductId.getText().trim()));
  496.         sales.setPurchase(purchase);
  497.         User user = new User();
  498.         user.setId(Login.loggedInUserId);
  499.         sales.setUser(user);
  500.         SalesService.insertForSales(sales);
  501.         clearForm();
  502.         lblMsg.setText("Sales Success!");
  503.         displaySummaryIntoTable();
  504.         displaySalesIntoTable();
  505.     }                                        
  506.  
  507.     private void btnViewSalesActionPerformed(java.awt.event.ActionEvent evt) {                                            
  508.         // TODO add your handling code here:
  509.         DefaultTableModel model = (DefaultTableModel) tblSales.getModel();
  510.         model.setRowCount(0);
  511.         Object[] row = new Object[7];
  512.         try {
  513.             Date sdate = new SimpleDateFormat("yyyy-MM-dd").parse(txtStartDate.getText().trim());
  514.             Date edate = new SimpleDateFormat("yyyy-MM-dd").parse(txtEndDate.getText().trim());
  515.             List<Sales> list = ReportService.getSalesByUserAndDateRange(Login.loggedInUserId, sdate, edate);
  516.             for (int i = 0; i < list.size(); i++) {
  517.                 row[0] = list.get(i).getProductName();
  518.                 row[1] = list.get(i).getProductCode();
  519.                 row[2] = list.get(i).getQty();
  520.                 row[3] = list.get(i).getUnitprice();
  521.                 row[4] = list.get(i).getTotalPrice();
  522.                 row[5] = list.get(i).getSalesdate();
  523.                 row[6] = list.get(i).getPurchase().getProductCategory().getName();
  524.  
  525.                 model.addRow(row);
  526.             }
  527.         } catch (Exception e) {
  528.         }
  529.  
  530.  
  531.     }                                            
  532.  
  533.     /**
  534.      * @param args the command line arguments
  535.      */
  536.     public static void main(String args[]) {
  537.         /* Set the Nimbus look and feel */
  538.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  539.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  540.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  541.          */
  542.         try {
  543.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  544.                 if ("Nimbus".equals(info.getName())) {
  545.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  546.                     break;
  547.                 }
  548.             }
  549.         } catch (ClassNotFoundException ex) {
  550.             java.util.logging.Logger.getLogger(SalesViewForSalesMan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  551.         } catch (InstantiationException ex) {
  552.             java.util.logging.Logger.getLogger(SalesViewForSalesMan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  553.         } catch (IllegalAccessException ex) {
  554.             java.util.logging.Logger.getLogger(SalesViewForSalesMan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  555.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  556.             java.util.logging.Logger.getLogger(SalesViewForSalesMan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  557.         }
  558.         //</editor-fold>
  559.         //</editor-fold>
  560.         //</editor-fold>
  561.         //</editor-fold>
  562.         //</editor-fold>
  563.         //</editor-fold>
  564.         //</editor-fold>
  565.         //</editor-fold>
  566.  
  567.         /* Create and display the form */
  568.         java.awt.EventQueue.invokeLater(new Runnable() {
  569.             public void run() {
  570.                 new SalesViewForSalesMan().setVisible(true);
  571.             }
  572.         });
  573.     }
  574.  
  575.     // Variables declaration - do not modify                    
  576.     private javax.swing.JButton btnClear;
  577.     private javax.swing.JButton btnSales;
  578.     private javax.swing.JButton btnSearch;
  579.     private javax.swing.JButton btnViewSales;
  580.     private javax.swing.JLabel jLabel1;
  581.     private javax.swing.JLabel jLabel10;
  582.     private javax.swing.JLabel jLabel11;
  583.     private javax.swing.JLabel jLabel12;
  584.     private javax.swing.JLabel jLabel2;
  585.     private javax.swing.JLabel jLabel3;
  586.     private javax.swing.JLabel jLabel4;
  587.     private javax.swing.JLabel jLabel5;
  588.     private javax.swing.JLabel jLabel6;
  589.     private javax.swing.JLabel jLabel7;
  590.     private javax.swing.JLabel jLabel8;
  591.     private javax.swing.JLabel jLabel9;
  592.     private javax.swing.JPanel jPanel1;
  593.     private javax.swing.JPanel jPanel2;
  594.     private javax.swing.JPanel jPanel3;
  595.     private javax.swing.JPanel jPanel4;
  596.     private javax.swing.JPanel jPanel5;
  597.     private javax.swing.JScrollPane jScrollPane1;
  598.     private javax.swing.JScrollPane jScrollPane2;
  599.     private javax.swing.JLabel lblMsg;
  600.     private javax.swing.JRadioButton rAllSales;
  601.     private javax.swing.JTable tblSales;
  602.     private javax.swing.JTable tblSummary;
  603.     private javax.swing.JLabel txtAvialble;
  604.     private javax.swing.JTextField txtEndDate;
  605.     private javax.swing.JLabel txtLoginMsg;
  606.     private javax.swing.JTextField txtPCode;
  607.     private javax.swing.JTextField txtPName;
  608.     private javax.swing.JLabel txtProductId;
  609.     private javax.swing.JTextField txtQty;
  610.     private javax.swing.JTextField txtStartDate;
  611.     private javax.swing.JLabel txtTotalPrice;
  612.     private javax.swing.JTextField txtUnitPrice;
  613.     // End of variables declaration                  
  614. }
  615.