Subversion Repository Public Repository

TransPort_Tracking

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
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bestray.transtracking.dao.impl;

import com.bestray.transtracking.dao.ClientCollectionDao;
import com.bestray.transtracking.dao.mapper.ClientCollectionResultSetExtractor;
import com.bestray.transtracking.dao.mapper.ClientResultSetExtractor;
import com.bestray.transtracking.dao.mapper.EmployeeResultSetExtractor;
import com.bestray.transtracking.dto.ClientCollectionSearchDTO;
import com.bestray.trastrack.domain.ClientCollection;
import com.bestray.trastrack.domain.ClientUser;
import com.bestray.trastrack.domain.CollectionCalcu;
import com.bestray.trastrack.domain.Employee;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.ResultSetExtractor;

/**
 *
 * @author user3
 */
public class ClientCollectionDaoImpl implements ClientCollectionDao {

    private DataSource ds;
    private static final String CLIENT_LIST_QUERY ="SELECT * from client_master ";
    private static final String CLIENT_QUERY ="SELECT * from client_payment_entry ";
    private static final String CLIENT_WHERE =" where client_id = ? ";
    private static final String ORDER_BY = " order by id desc ";
    private static final String EMPLOYEE_LIST_QUERY ="SELECT * from employee_master e";
    public ClientCollectionDaoImpl(DataSource ds){
        this.ds=ds;
    }
    
    public List<ClientCollection> getSearchResults(final ClientCollectionSearchDTO search) throws Exception {
        StringBuffer queryString = new StringBuffer(CLIENT_QUERY);
        queryString.append(" where client_id = ?");
        if(search.getSearchFrom()!=null){
            queryString.append(" and payment_date>=?");
        }
        if(search.getSearchTo()!=null){
            queryString.append(" and payment_date<=?");
        }
        queryString.append(ORDER_BY);
          
         
          JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
                   
           // System.out.println(queryString.toString());   
         return (List<ClientCollection>) jdbcTemplate.query(queryString.toString(),  new PreparedStatementSetter() {

            public void setValues(PreparedStatement ps) throws SQLException {
                int index = 0;
                ps.setLong(++index, search.getClientname());
                if(search.getSearchFrom() != null){
                   // System.out.println(search.getSearchFrom());
                    ps.setDate(++index, new java.sql.Date(search.getSearchFrom().getTime()));
                }
                 if(search.getSearchTo() != null){
                    // System.out.println(search.getSearchTo());
                  ps.setDate(++index, new java.sql.Date(search.getSearchTo().getTime()));
                 }
            }
        } , new ClientCollectionResultSetExtractor());
    }
    
    public void saveCollection(ClientCollection collect) throws Exception{
        JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
        
        String sql = "insert into client_payment_entry (client_id, collection_type_id,amount,recieve_person_id,diposited_at,comment_1,comment_2,payment_date) values(?,?,?,?,?,?,?,?)";      
        jdbcTemplate.update(sql,collect.getClient_id(), collect.getCollection_type_id(), collect.getAmount(), collect.getRecived_person_id(), collect.getDiposited_at(), collect.getComment1(), collect.getComment2(), collect.getPayment_date());

    }
    
    public List<ClientUser> findAllClients() throws Exception{
      
         JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
         
            StringBuffer queryString = new StringBuffer(CLIENT_LIST_QUERY).append("where lock_ind='NO' ").append(" order by name asc ");
          List<ClientUser> clientList = (List<ClientUser>) jdbcTemplate.query(queryString.toString(), new ClientResultSetExtractor());
          return clientList;
    }

    public ClientCollection findCollectionDetails(Long collectionId)throws Exception {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
        StringBuffer queryString = new StringBuffer(CLIENT_QUERY)
               .append("where id = ? ")
               .append(ORDER_BY);
             List<ClientCollection> collectionList = (List<ClientCollection>) jdbcTemplate.query(queryString.toString(), new Object[]{collectionId}, new ClientCollectionResultSetExtractor());
             return   collectionList.size()>0?collectionList.get(0):null;
       
    }

    public void updateCollection(ClientCollection collect) throws Exception{
       JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
       final java.util.Date date= new java.util.Date();
       String sql = "update client_payment_entry set client_id=?, collection_type_id=?, amount=?, recieve_person_id=?, diposited_at=?, comment_1=?, comment_2=?, payment_date=? where id = ?";      
       jdbcTemplate.update(sql, new Object[]{collect.getClient_id(), collect.getCollection_type_id(), collect.getAmount(), collect.getRecived_person_id(), collect.getDiposited_at(), collect.getComment1(), collect.getComment2(), collect.getPayment_date(), collect.getId()});
    }

    public void delete(Long clientId) throws Exception {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
         jdbcTemplate.update("DELETE FROM client_payment_entry WHERE id = ?", new Object[]{clientId});
    }

    public List<Employee> findAllEmployees() throws Exception{
         JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
         StringBuffer queryString = new StringBuffer(EMPLOYEE_LIST_QUERY).append("  where e.lock='NO' ").append(" order by emp_name asc ");
          List<Employee> employeeList = (List<Employee>) jdbcTemplate.query(queryString.toString(), new EmployeeResultSetExtractor());
          return employeeList;
    }

    public CollectionCalcu getTotalPayment(Long clientId) throws Exception {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
        String queryString = " SELECT client_master.`id` AS id, client_master.`name` AS client_name,"
            +" (select COALESCE(sum(vehicle_job_entry.`total_receivable`),0) "
            +" from vehicle_job_entry where vehicle_job_entry.`client_name_id`=client_master.`id`) AS sum_new_job,"
            +" (select COALESCE(sum(client_payment_entry.`amount`),0)"
            +" from client_payment_entry where client_payment_entry.`client_id`=client_master.`id`) AS sum_client_collection"
            +" FROM `client_master` client_master Where client_master.`id`= ? ";
        List<CollectionCalcu> domainList = (List<CollectionCalcu>) jdbcTemplate.query(queryString.toString(), new Object[]{clientId}, new CollectionDomainResultSetExtractor());
        return domainList.size() > 0 ? domainList.get(0) : null;
    }
    public class CollectionDomainResultSetExtractor implements  ResultSetExtractor<Object>{

    public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
        List <CollectionCalcu> payment = new ArrayList<CollectionCalcu>();
        while (rs.next()) {
            CollectionCalcu paymentclient = new CollectionCalcu();
          //  Address address = new Address();
            paymentclient.setId(rs.getLong("id"));
            paymentclient.setClientName(rs.getString("client_name"));
            paymentclient.setSumNewJob(rs.getDouble("sum_new_job"));
            paymentclient.setSumClientCollection(rs.getDouble("sum_client_collection"));
            payment.add(paymentclient);
        }
        return payment;
    }
    }
}

Commits for TransPort_Tracking/TransPortTracking/src/main/java/com/bestray/transtracking/dao/impl/ClientCollectionDaoImpl.java

Diff revisions: vs.
Revision Author Commited Message
1 girijabapi picture girijabapi Sat 28 Jul, 2018 05:29:14 +0000