99import java .util .logging .Level ;
1010import java .util .logging .Logger ;
1111import javax .inject .Inject ;
12+ import openconsignment .common .SqlLoader ;
13+ import openconsignment .common .SqlQuery ;
1214import openconsignment .entity .BillEntity ;
1315import openconsignment .entity .LREntity ;
1416
@@ -23,13 +25,7 @@ public BillRepository(Connection conn) {
2325
2426 public void save (BillEntity billEntity ) throws SQLException {
2527 try {
26- // language=sql
27- String sql =
28- "INSERT INTO `Bill_Entry_Table`(`Supplier Name`,`Buyer Name`,`Bill No.`,`Bill Date`,`Transport`,`LR Date`,`Bill Amount`,`Collection Due`,`Due`) "
29- + "VALUES (?,?,?,?,?,?,?,?,?) ON CONFLICT(`Bill No.`) DO UPDATE SET "
30- + "`Supplier Name`=excluded.`Supplier Name`, `Buyer Name`=excluded.`Buyer Name`, `Bill Date`=excluded.`Bill Date`, "
31- + "`Transport`=excluded.`Transport`, `LR Date`=excluded.`LR Date`, `Bill Amount`=excluded.`Bill Amount`, "
32- + "`Collection Due`=excluded.`Collection Due`, `Due`=excluded.`Due`;" ;
28+ String sql = SqlLoader .load (SqlQuery .BILL_SAVE );
3329
3430 conn .setAutoCommit (false );
3531
@@ -49,7 +45,7 @@ public void save(BillEntity billEntity) throws SQLException {
4945
5046 if (null != billEntity .getLrEntities ()) {
5147 for (LREntity lr : billEntity .getLrEntities ()) {
52- sql = "INSERT INTO `LR_Table`(`Bill No.`,`LR No.`,`PM`) VALUES (?,?,?)" ;
48+ sql = SqlLoader . load ( SqlQuery . BILL_SAVE_LR ) ;
5349 preparedStatement = conn .prepareStatement (sql );
5450 preparedStatement .setString (1 , billEntity .getBillNo ());
5551 preparedStatement .setString (2 , lr .getLrNo ());
@@ -67,7 +63,7 @@ public void save(BillEntity billEntity) throws SQLException {
6763
6864 public BillEntity getBill (String billNo ) throws SQLException {
6965 try {
70- String sql = "select * from `Bill_Entry_Table` where `Bill No.`=? collate nocase" ;
66+ String sql = SqlLoader . load ( SqlQuery . BILL_GET ) ;
7167 PreparedStatement preparedStatement = conn .prepareStatement (sql );
7268 preparedStatement .setString (1 , billNo );
7369 ResultSet billResultSet = preparedStatement .executeQuery ();
@@ -86,7 +82,7 @@ public BillEntity getBill(String billNo) throws SQLException {
8682 .billAmount (billResultSet .getString ("Bill Amount" ))
8783 .build ();
8884
89- sql = "select * from `LR_Table` where `Bill No.`=? collate nocase" ;
85+ sql = SqlLoader . load ( SqlQuery . BILL_GET_LRS ) ;
9086 preparedStatement = conn .prepareStatement (sql );
9187 preparedStatement .setString (1 , billNo );
9288 ResultSet lrPmResultSet = preparedStatement .executeQuery ();
@@ -110,12 +106,12 @@ public BillEntity getBill(String billNo) throws SQLException {
110106 public void deleteBill (String billNo ) throws SQLException {
111107 try {
112108 conn .setAutoCommit (false );
113- String sql = "DELETE FROM `Bill_Entry_Table` where `Bill No.`=? collate nocase" ;
109+ String sql = SqlLoader . load ( SqlQuery . BILL_DELETE ) ;
114110 PreparedStatement preparedStatement = conn .prepareStatement (sql );
115111 preparedStatement .setString (1 , billNo );
116112 preparedStatement .execute ();
117113
118- String sql2 = "DELETE FROM `LR_Table` where `Bill No.`=? collate nocase" ;
114+ String sql2 = SqlLoader . load ( SqlQuery . BILL_DELETE_LRS ) ;
119115 preparedStatement = conn .prepareStatement (sql2 );
120116 preparedStatement .setString (1 , billNo );
121117 preparedStatement .execute ();
@@ -131,7 +127,7 @@ public void deleteBill(String billNo) throws SQLException {
131127 public List <BillEntity > getBills () throws SQLException {
132128 List <BillEntity > res = new ArrayList <>();
133129 try {
134- String sql = "SELECT * FROM `Bill_Entry_Table`;" ;
130+ String sql = SqlLoader . load ( SqlQuery . BILL_GET_ALL ) ;
135131 PreparedStatement ps = conn .prepareStatement (sql );
136132 ResultSet rs = ps .executeQuery ();
137133 while (rs .next ()) {
0 commit comments