buli
2023-06-05 3962c2bb0435484b60a3e408e4738d792e249a53
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
public with sharing class LexSaleAndDeliveryController {
    // 显示数据条数限制
    private static Integer Select_Limit = 100;
 
    //初始化
    @AuraEnabled
    public static ResponseBodyLWC init() {
        try {
            System.debug('init');
            //经销商id
            String accountid = '';
            //经销商产品分类
            String agencyProType = '';
            //登录用户 ID
            String userinfoId = '';
            //登录者工作地
            String userWorkLocation = '';
 
            ResponseBodyLWC res = new ResponseBodyLWC();
            Map<String, object> data = new Map<String, object>();
            res.entity = data;
            userinfoId = UserInfo.getUserId();
            List<user> Useracc = new List<user>();
            Useracc = [SELECT accountid, Work_Location__c, UserPro_Type__c FROM user WHERE id = :userinfoId];
            accountid = Useracc[0].accountid;
            agencyProType = Useracc[0].UserPro_Type__c;
            if (String.isBlank(Useracc[0].UserPro_Type__c)) {
                agencyProType = 'ET';
            }
            userWorkLocation = Useracc[0].Work_Location__c;
            data.put('userinfoId', userinfoId);
            data.put('accountid', accountid);
            data.put('agencyProType', agencyProType);
            data.put('userWorkLocation', userWorkLocation);
            System.debug(
                'userinfoId = ' +
                userinfoId +
                ' accountid = ' +
                accountid +
                ' agencyProType = ' +
                agencyProType +
                ' userWorkLocation = ' +
                userWorkLocation
            );
            //默认检索显示未完成的指示单
            List<Consumable_order__c> raesList = new List<Consumable_order__c>();
            String soql = 'select Id, Name,ShipmentAccount__c,SummonsStatus_c__c,Billed_Status__c,CreatedDate,Outbound_Date__c,Order_ForCustomerText__c,InvoiceNotPro_total_amount__c,InvoiceNotPro_money__c from Consumable_order__c';
            soql += '  WHERE Order_type__c = \'' + '传票' + '\'  ';
            soql += ' and Order_ProType__c =\'' + agencyProType + '\' ';
            soql += 'and SummonsStatus_c__c != \'' + '已完成' + '\' and Dealer_Info__c =\'' + accountid + '\' ';
            soql += 'and Order_Owner_WorkLocal__c = \'' + userWorkLocation + '\' ';
            soql += 'order by SummonsStatus_c__c';
            System.debug('soql = ' + soql);
            raesList = Database.query(soql);
            System.debug('raesList = ' + raesList);
            data.put('raesList', raesList);
            res.status = 'Success';
            res.code = 200;
            res.msg = '';
            return res;
        } catch (Exception e) {
            return new ResponseBodyLWC('Error', 500, e.getMessage(), '');
        }
    }
 
    // 已出库未开票的出库单
    @AuraEnabled
    public static ResponseBodyLWC searchOrderInstatus(
        String orderDate,
        String deliverDate,
        String accountid,
        String agencyProType,
        String userWorkLocation,
        String category1,
        String category2
    ) {
        try {
            ResponseBodyLWC res = new ResponseBodyLWC();
            Map<String, object> data = new Map<String, object>();
            res.entity = data;
 
            Date cate2 = String.isEmpty(orderDate) ? null : Date.valueOf(orderDate.replace('/', '-'));
            Date cate3 = String.isEmpty(deliverDate) ? null : Date.valueOf(deliverDate.replace('/', '-'));
            // 获得订单一览
            List<Consumable_order__c> raesList = new List<Consumable_order__c>();
            String soql = 'select Id, Name,ShipmentAccount__c,SummonsStatus_c__c,Billed_Status__c,CreatedDate,Outbound_Date__c,Order_ForCustomerText__c,InvoiceNotPro_total_amount__c,InvoiceNotPro_money__c from Consumable_order__c';
            soql += ' WHERE   Order_type__c = \'' + '传票' + '\' ';
            soql += ' and Dealer_Info__c =\'' + accountid + '\' ';
            soql += ' and Order_ProType__c =\'' + agencyProType + '\' ';
            soql += ' and Order_Owner_WorkLocal__c = \'' + userWorkLocation + '\' ';
            if (!String.isBlank(category1)) {
                soql += ' and Name like \'%' + String.escapeSingleQuotes(category1.replaceAll('%', '\\%')) + '%\' ';
            }
            if (!String.isBlank(category2)) {
                soql += ' and ShipmentAccount__c like \'%' + String.escapeSingleQuotes(category2.replaceAll('%', '\\%')) + '%\' ';
            }
            if (cate2 != null) {
                soql += ' and Outbound_Date__c >= :cate2 ';
            }
            if (cate3 != null) {
                soql += ' and Outbound_Date__c <= :cate3 ';
            }
            soql += 'and SummonsForDirction__c != \'' + '互相调货' + '\' ';
            soql += 'and SummonsStatus_c__c = \'' + '已完成' + '\' ';
            soql += 'and Billed_Status__c != \'' + '全部开票' + '\' ';
            soql += 'order by CreatedDate desc limit ' + Select_Limit;
            System.debug('soql = ' + soql);
            raesList = Database.query(soql);
            data.put('raesList', raesList);
            if (raesList.size() > 0) {
                res.msg = '共有' + raesList.size() + '个出库单';
            } else {
                res.msg = '没有搜索到相关出库单。';
            }
            res.status = 'Success';
            res.code = 200;
            return res;
        } catch (Exception e) {
            return new ResponseBodyLWC('Error', 500, e.getMessage(), '');
        }
    }
 
    //还没出库的出库单
    @AuraEnabled
    public static ResponseBodyLWC searchConsumableorderdetails(
        String orderDate,
        String deliverDate,
        String accountid,
        String agencyProType,
        String userWorkLocation,
        String category1,
        String category2
    ) {
        try {
            ResponseBodyLWC res = new ResponseBodyLWC();
            Map<String, object> data = new Map<String, object>();
            res.entity = data;
            Date cate2 = String.isEmpty(orderDate) ? null : Date.valueOf(orderDate.replace('/', '-'));
            Date cate3 = String.isEmpty(deliverDate) ? null : Date.valueOf(deliverDate.replace('/', '-'));
            System.debug('cate2 = ' + cate2);
            System.debug('cate3 = ' + cate3);
            // 获得订单一览
            List<Consumable_order__c> raesList = new List<Consumable_order__c>();
            String soql = 'select Id, Name,ShipmentAccount__c,SummonsStatus_c__c,Billed_Status__c,CreatedDate,Outbound_Date__c,Order_ForCustomerText__c,InvoiceNotPro_total_amount__c,InvoiceNotPro_money__c from Consumable_order__c';
            soql += ' WHERE   Order_type__c = \'' + '传票' + '\' ';
            soql += ' and Dealer_Info__c =\'' + accountid + '\' ';
            soql += ' and Order_ProType__c =\'' + agencyProType + '\' ';
            soql += ' and Order_Owner_WorkLocal__c = \'' + userWorkLocation + '\' ';
            if (!String.isBlank(category1)) {
                soql += ' and Name like \'%' + String.escapeSingleQuotes(category1.replaceAll('%', '\\%')) + '%\' ';
            }
            if (!String.isBlank(category2)) {
                soql += ' and ShipmentAccount__c like \'%' + String.escapeSingleQuotes(category2.replaceAll('%', '\\%')) + '%\' ';
            }
            if (cate2 != null) {
                soql += ' and Order_date__c >= :cate2 ';
            }
            if (cate3 != null) {
                soql += ' and Order_date__c <= :cate3 ';
            }
            soql += 'and SummonsStatus_c__c != \'' + '已完成' + '\' ';
            soql += 'order by SummonsStatus_c__c limit ' + Select_Limit;
            System.debug('soql+++++' + soql);
            raesList = Database.query(soql);
            data.put('raesList', raesList);
            if (raesList.size() > 0) {
                res.msg = '共有' + raesList.size() + '个出库单';
            } else {
                res.msg = '没有搜索到相关出库单。';
            }
            res.status = 'Success';
            res.code = 200;
            return res;
        } catch (Exception e) {
            return new ResponseBodyLWC('Error', 500, e.getMessage(), '');
        }
    }
 
    // 已出库已开票的出库单
    @AuraEnabled
    public static ResponseBodyLWC searchConsumableorFinish(
        String orderDate,
        String deliverDate,
        String accountid,
        String agencyProType,
        String userWorkLocation,
        String category1,
        String category2
    ) {
        try {
            ResponseBodyLWC res = new ResponseBodyLWC();
            Map<String, object> data = new Map<String, object>();
            res.entity = data;
            Date cate2 = String.isEmpty(orderDate) ? null : Date.valueOf(orderDate.replace('/', '-'));
            Date cate3 = String.isEmpty(deliverDate) ? null : Date.valueOf(deliverDate.replace('/', '-'));
            List<Consumable_order__c> raesList = new List<Consumable_order__c>();
            String soql = 'select Id, Name,ShipmentAccount__c,SummonsStatus_c__c,Billed_Status__c,CreatedDate,Outbound_Date__c,Order_ForCustomerText__c,InvoiceNotPro_total_amount__c,InvoiceNotPro_money__c from Consumable_order__c';
            soql += ' WHERE   Order_type__c = \'' + '传票' + '\' ';
            soql += ' and Dealer_Info__c =\'' + accountid + '\' ';
            soql += ' and Order_ProType__c =\'' + agencyProType + '\' ';
            soql += ' and Order_Owner_WorkLocal__c = \'' + userWorkLocation + '\' ';
            if (!String.isBlank(category1)) {
                soql += ' and Name like \'%' + String.escapeSingleQuotes(category1.replaceAll('%', '\\%')) + '%\' ';
            }
            if (!String.isBlank(category2)) {
                soql += ' and ShipmentAccount__c like \'%' + String.escapeSingleQuotes(category2.replaceAll('%', '\\%')) + '%\' ';
            }
            if (cate2 != null) {
                soql += ' and Outbound_Date__c >= :cate2 ';
            }
            if (cate3 != null) {
                soql += ' and Outbound_Date__c <= :cate3 ';
            }
            soql += 'and SummonsStatus_c__c = \'' + '已完成' + '\' ';
            soql += 'and Billed_Status__c = \'' + '全部开票' + '\' ';
            soql += 'order by CreatedDate desc limit ' + Select_Limit;
            raesList = Database.query(soql);
            data.put('raesList', raesList);
            if (raesList.size() > 0) {
                res.msg = '共有' + raesList.size() + '个出库单';
            } else {
                res.msg = '没有搜索到相关出库单。';
            }
            res.status = 'Success';
            res.code = 200;
            return res;
        } catch (Exception e) {
            return new ResponseBodyLWC('Error', 500, e.getMessage(), '');
        }
    }
 
    @AuraEnabled
    public static ResponseBodyLWC cleanUp(String accountid, String agencyProType, String userWorkLocation) {
        try {
            ResponseBodyLWC res = new ResponseBodyLWC();
            Map<String, object> data = new Map<String, object>();
            res.entity = data;
 
            // 获得显示数据
            List<Consumable_order__c> raesList = new List<Consumable_order__c>();
            String soql = 'select Id, Name,ShipmentAccount__c,SummonsStatus_c__c,Billed_Status__c,CreatedDate,Outbound_Date__c,Order_ForCustomerText__c,InvoiceNotPro_total_amount__c,InvoiceNotPro_money__c from Consumable_order__c';
            soql += '  WHERE Order_type__c = \'' + '传票' + '\'  ';
            soql += ' and Order_ProType__c =\'' + agencyProType + '\' ';
            soql += 'and SummonsStatus_c__c != \'' + '已完成' + '\' and Dealer_Info__c =\'' + accountid + '\' ';
            soql += 'and Order_Owner_WorkLocal__c = \'' + userWorkLocation + '\' ';
            soql += 'order by SummonsStatus_c__c';
            System.debug('soql = ' + soql);
            raesList = Database.query(soql);
            data.put('raesList', raesList);
            if (raesList.size() > 0) {
                res.msg = '共有' + raesList.size() + '个出库单';
            } else {
                res.msg = '没有搜索到相关出库单。';
            }
            res.status = 'Success';
            res.code = 200;
            return res;
        } catch (Exception e) {
            return new ResponseBodyLWC('Error', 500, e.getMessage(), '');
        }
    }
}